Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,13 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
mongodb-version: [4.0.18]
java-version: [1.8]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup Java JDK
uses: actions/[email protected]
# The Java version to make available on the path. Takes a whole or semver Java version, or 1.x syntax (e.g. 1.8 => Java 8.x). Early access versions can be specified in the form of e.g. 14-ea, 14.0.0-ea, or 14.0.0-ea.28
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
- name: Install and Start MongoDB
run: |
wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-${{ matrix.mongodb-version }}.tgz
tar xfz mongodb-linux-x86_64-${{ matrix.mongodb-version }}.tgz
export PATH=`pwd`/mongodb-linux-x86_64-${{ matrix.mongodb-version }}/bin:$PATH
mkdir -p data/db
mongod --dbpath=data/db &
mongod --version
java-version: '21'
distribution: 'temurin'
- name: Run Maven tests
run: mvn test
34 changes: 20 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
</modules>

<properties>
<java.version>1.8</java.version>
<spring.boot.version>2.1.0.RELEASE</spring.boot.version>
<java.version>21</java.version>
<spring.boot.version>3.4.1</spring.boot.version>
</properties>

<dependencyManagement>
Expand All @@ -38,20 +38,27 @@
</exclusions>
</dependency>
<dependency>
<groupId>com.lordofthejars</groupId>
<artifactId>nosqlunit-mongodb</artifactId>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.19.3</version>
<scope>test</scope>
<version>0.14.0</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
<groupId>org.testcontainers</groupId>
<artifactId>mongodb</artifactId>
<version>1.19.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.9</version>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.19.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
Expand Down Expand Up @@ -121,10 +128,9 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<version>3.12.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<release>${java.version}</release>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<encoding>UTF-8</encoding>
Expand Down
9 changes: 7 additions & 2 deletions variation-commons-batch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.lordofthejars</groupId>
<artifactId>nosqlunit-mongodb</artifactId>
<groupId>org.testcontainers</groupId>
<artifactId>mongodb</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,65 +1,40 @@
package uk.ac.ebi.eva.commons.batch.configuration;

import org.springframework.batch.core.configuration.annotation.BatchConfigurer;
import org.springframework.batch.core.configuration.annotation.DefaultBatchConfigurer;
import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.explore.support.JobExplorerFactoryBean;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration;
import org.springframework.batch.core.repository.ExecutionContextSerializer;
import org.springframework.batch.core.repository.dao.Jackson2ExecutionContextStringSerializer;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.vendor.HibernateJpaDialect;
import org.springframework.transaction.PlatformTransactionManager;


import javax.persistence.EntityManagerFactory;
import jakarta.persistence.EntityManagerFactory;
import javax.sql.DataSource;

public class SpringBoot1CompatibilityConfiguration {
/**
* Spring Batch configuration for JPA/Hibernate compatibility.
*
* Updated for Spring Batch 5.x which removes BatchConfigurer and DefaultBatchConfigurer.
* Extend this class and override getDataSource() to provide your DataSource.
*/
public abstract class SpringBoot1CompatibilityConfiguration extends DefaultBatchConfiguration {

private final EntityManagerFactory entityManagerFactory;

protected SpringBoot1CompatibilityConfiguration(EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory;
}

// Due to the bug here: https://github.com/spring-projects/spring-batch/issues/1289#issue-538711146
// BatchConfigurer seems to override the transaction manager that is already present in the ExecutionContext
// This leads to issues like https://github.com/spring-projects/spring-batch/issues/961#issue-538704176
// Therefore, we have to "re-assert" to Spring Boot that we intend to use
// a JPA Transaction manager by putting back in the ExecutionContext
private static JpaTransactionManager getTransactionManager(DataSource dataSource, EntityManagerFactory entityManagerFactory) {
@Override
public PlatformTransactionManager getTransactionManager() {
final JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
jpaTransactionManager.setDataSource(dataSource);
jpaTransactionManager.setDataSource(getDataSource());
jpaTransactionManager.setJpaDialect(new HibernateJpaDialect());
jpaTransactionManager.setEntityManagerFactory(entityManagerFactory);
return jpaTransactionManager;
}

public static BatchConfigurer getSpringBoot1CompatibleBatchConfigurer(DataSource dataSource,
EntityManagerFactory entityManagerFactory)
throws Exception {
final JpaTransactionManager transactionManager = getTransactionManager(dataSource, entityManagerFactory);
final SpringBoot1CompatibleSerializer serializer = new SpringBoot1CompatibleSerializer();
return new DefaultBatchConfigurer(dataSource) {

@Override
protected JobRepository createJobRepository() throws Exception {

JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(dataSource);
factory.setTransactionManager(transactionManager);
factory.setSerializer(serializer);
factory.afterPropertiesSet();
return factory.getObject();
}

@Override
protected JobExplorer createJobExplorer() throws Exception {
JobExplorerFactoryBean jobExplorerFactoryBean = new JobExplorerFactoryBean();
jobExplorerFactoryBean.setSerializer(serializer);
jobExplorerFactoryBean.setDataSource(dataSource);
jobExplorerFactoryBean.afterPropertiesSet();
return jobExplorerFactoryBean.getObject();
}

@Override
public PlatformTransactionManager getTransactionManager() {
return transactionManager;
}
};
@Override
protected ExecutionContextSerializer getExecutionContextSerializer() {
return new Jackson2ExecutionContextStringSerializer();
}
}
Original file line number Diff line number Diff line change
@@ -1,49 +1,29 @@
package uk.ac.ebi.eva.commons.batch.configuration;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import com.fasterxml.jackson.core.JsonProcessingException;

import org.springframework.batch.core.repository.ExecutionContextSerializer;
import org.springframework.batch.core.repository.dao.Jackson2ExecutionContextStringSerializer;
import org.springframework.batch.core.repository.dao.XStreamExecutionContextStringSerializer;


/**
* ExecutionContext serialization/deserialization from Job repository changed in mechanism
* from XStream to Jackson in Spring Boot 2 (which includes the Spring Batch 4 library)
* - see https://docs.spring.io/spring-batch/docs/4.0.4.RELEASE/reference/html/whatsnew.html#whatsNewSerialization
*
* This class enables reading ExecutionContext entries written by Spring Boot 1.5 (Spring Batch 3)
* as well as Spring Boot 2.1 (Spring Batch 4) and write entries in Spring Boot 2 (Spring Batch 4) format
* ExecutionContext serializer using Jackson.
*
* Adapted from https://stackoverflow.com/a/55375553
* Note: XStreamExecutionContextStringSerializer has been removed in Spring Batch 5.x.
* This class now only supports Jackson-based serialization format.
* Legacy XStream-serialized data will need to be migrated separately if still present.
*/
public class SpringBoot1CompatibleSerializer implements ExecutionContextSerializer {
private final XStreamExecutionContextStringSerializer xStream = new XStreamExecutionContextStringSerializer();
private final Jackson2ExecutionContextStringSerializer jackson = new Jackson2ExecutionContextStringSerializer();

public SpringBoot1CompatibleSerializer() throws Exception {
xStream.afterPropertiesSet();
public SpringBoot1CompatibleSerializer() {
}

@Override
public Map<String, Object> deserialize(InputStream inputStream) throws IOException {
InputStream repeatableInputStream = ensureMarkSupported(inputStream);
repeatableInputStream.mark(Integer.MAX_VALUE);

try {
return jackson.deserialize(repeatableInputStream);
} catch (JsonProcessingException e) {
repeatableInputStream.reset();
return xStream.deserialize(repeatableInputStream);
}
}

private static InputStream ensureMarkSupported(InputStream in) {
return in.markSupported() ? in : new BufferedInputStream(in);
return jackson.deserialize(inputStream);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import uk.ac.ebi.eva.commons.core.models.factories.VariantVcfFactory;
import uk.ac.ebi.eva.commons.core.models.pipeline.Variant;

import javax.annotation.Nullable;
import jakarta.annotation.Nullable;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import uk.ac.ebi.eva.commons.core.models.Aggregation;

import javax.annotation.Nullable;
import jakarta.annotation.Nullable;
import java.io.File;
import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import uk.ac.ebi.eva.commons.batch.exception.NoParametersHaveBeenPassedException;
import uk.ac.ebi.eva.commons.batch.exception.NoPreviousJobExecutionException;

import java.util.Date;
import java.time.LocalDateTime;
import java.util.Objects;

/**
Expand Down Expand Up @@ -60,7 +60,7 @@ public static void markLastJobAsFailed(JobRepository jobRepository, String jobNa
throw new NoPreviousJobExecutionException(jobName, jobParameters);
}

Date currentTime = new Date();
LocalDateTime currentTime = LocalDateTime.now();
lastJobExecution.setEndTime(currentTime);
lastJobExecution.setStatus(BatchStatus.FAILED);
lastJobExecution.setExitStatus(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
*/
package uk.ac.ebi.eva.commons.batch.io;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.test.MetaDataInstanceFactory;

Expand All @@ -30,12 +29,14 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.zip.GZIPInputStream;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* {@link AggregatedVcfReader}
Expand All @@ -54,17 +55,21 @@ public class AggregatedVcfReaderTest {

private static final String INPUT_FILE_PATH_EVS = "/input-files/vcf/aggregated.evs.vcf.gz";

@Rule
public TemporaryFolder temporaryFolderRule = new TemporaryFolder();
@TempDir
Path temporaryFolder;

@Test(expected = IllegalArgumentException.class)
@Test
public void shouldThrowOnInvalidAggregation() throws IOException {
new AggregatedVcfReader(FILE_ID, STUDY_ID, Aggregation.NONE, null, FileUtils.getResourceFile(INPUT_FILE_PATH));
assertThrows(IllegalArgumentException.class, () -> {
new AggregatedVcfReader(FILE_ID, STUDY_ID, Aggregation.NONE, null, FileUtils.getResourceFile(INPUT_FILE_PATH));
});
}

@Test(expected = IllegalArgumentException.class)
@Test
public void shouldThrowOnNullAggregation() throws IOException {
new AggregatedVcfReader(FILE_ID, STUDY_ID, null, null, FileUtils.getResourceFile(INPUT_FILE_PATH));
assertThrows(IllegalArgumentException.class, () -> {
new AggregatedVcfReader(FILE_ID, STUDY_ID, null, null, FileUtils.getResourceFile(INPUT_FILE_PATH));
});
}

@Test
Expand Down Expand Up @@ -104,7 +109,7 @@ public void testUncompressedVcf() throws Exception {

// uncompress the input VCF into a temporal file
File input = FileUtils.getResourceFile(INPUT_FILE_PATH);
File tempFile = temporaryFolderRule.newFile();
File tempFile = temporaryFolder.resolve("tempFile.vcf").toFile();
CompressionHelper.uncompress(input.getAbsolutePath(), tempFile);

AggregatedVcfReader vcfReader = new AggregatedVcfReader(FILE_ID, STUDY_ID, Aggregation.BASIC,
Expand Down
Loading