JAVA-8362: Switch to H2 db

This commit is contained in:
Krzysiek 2021-11-24 23:18:00 +01:00
parent 203f7a16bb
commit 3d391578c8
4 changed files with 6 additions and 44 deletions

View File

@ -22,9 +22,8 @@
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>runtime</scope>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -11,26 +11,20 @@ import org.springframework.batch.core.configuration.annotation.EnableBatchProces
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.launch.support.SimpleJobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.batch.item.file.builder.FlatFileItemReaderBuilder;
import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.ScheduledMethodRunnable;
import javax.sql.DataSource;
import java.util.Date;
import java.util.IdentityHashMap;
import java.util.List;
@ -113,38 +107,12 @@ public class SpringBatchScheduler {
@Bean
public Job job() {
return jobBuilderFactory.get("job")
return jobBuilderFactory
.get("job")
.start(readBooks())
.build();
}
// @Bean
// public JobLauncher jobLauncher() throws Exception {
// SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
// jobLauncher.setJobRepository(jobRepository());
// jobLauncher.afterPropertiesSet();
// return jobLauncher;
// }
// @Bean
// public JobRepository jobRepository() throws Exception {
// JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
// factory.setDataSource(dataSource());
// factory.setDatabaseType("HSQL");
// factory.setTransactionManager(new ResourcelessTransactionManager());
// return factory.getObject();
// }
// @Bean
// public DataSource dataSource() {
// DriverManagerDataSource dataSource = new DriverManagerDataSource();
// dataSource.setDriverClassName("org.hsqldb.jdbc.JDBCDriver");
// dataSource.setUrl("jdbc:hsqldb:mem:testdb");
// dataSource.setUsername("sa");
// dataSource.setPassword("");
// return dataSource;
// }
@Bean
protected Step readBooks() {
return stepBuilderFactory.get("readBooks")

View File

@ -1,8 +1,3 @@
spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver
spring.datasource.url=jdbc:hsqldb:mem:testdb;DB_CLOSE_DELAY=-1;hsqldb.tx=mvcc
spring.datasource.username=sa
spring.datasource.password=
spring.batch.jdbc.initialize-schema=always
#spring.batch.jdbc.initialize-schema=embedded
file.input=coffee-list.csv

View File

@ -29,7 +29,7 @@ public class SpringBatchSchedulerIntegrationTest {
private ApplicationContext context;
@Test
public void stopJobsWhenSchedulerDisabled() throws Exception {
public void stopJobsWhenSchedulerDisabled() {
SpringBatchScheduler schedulerBean = context.getBean(SpringBatchScheduler.class);
await().untilAsserted(() -> Assert.assertEquals(2, schedulerBean.getBatchRunCounter()
.get()));