JAVA-8362: Switch to H2 db
This commit is contained in:
parent
203f7a16bb
commit
3d391578c8
|
@ -22,9 +22,8 @@
|
||||||
<artifactId>spring-boot-starter-batch</artifactId>
|
<artifactId>spring-boot-starter-batch</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hsqldb</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>hsqldb</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|
|
@ -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.JobBuilderFactory;
|
||||||
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
|
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
|
||||||
import org.springframework.batch.core.launch.JobLauncher;
|
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.ItemWriter;
|
||||||
import org.springframework.batch.item.file.FlatFileItemReader;
|
import org.springframework.batch.item.file.FlatFileItemReader;
|
||||||
import org.springframework.batch.item.file.builder.FlatFileItemReaderBuilder;
|
import org.springframework.batch.item.file.builder.FlatFileItemReaderBuilder;
|
||||||
import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
|
||||||
import org.springframework.scheduling.TaskScheduler;
|
import org.springframework.scheduling.TaskScheduler;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||||
import org.springframework.scheduling.support.ScheduledMethodRunnable;
|
import org.springframework.scheduling.support.ScheduledMethodRunnable;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -113,38 +107,12 @@ public class SpringBatchScheduler {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Job job() {
|
public Job job() {
|
||||||
return jobBuilderFactory.get("job")
|
return jobBuilderFactory
|
||||||
|
.get("job")
|
||||||
.start(readBooks())
|
.start(readBooks())
|
||||||
.build();
|
.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
|
@Bean
|
||||||
protected Step readBooks() {
|
protected Step readBooks() {
|
||||||
return stepBuilderFactory.get("readBooks")
|
return stepBuilderFactory.get("readBooks")
|
||||||
|
|
|
@ -1,8 +1,3 @@
|
||||||
spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver
|
#spring.batch.jdbc.initialize-schema=embedded
|
||||||
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
|
|
||||||
|
|
||||||
file.input=coffee-list.csv
|
file.input=coffee-list.csv
|
|
@ -29,7 +29,7 @@ public class SpringBatchSchedulerIntegrationTest {
|
||||||
private ApplicationContext context;
|
private ApplicationContext context;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void stopJobsWhenSchedulerDisabled() throws Exception {
|
public void stopJobsWhenSchedulerDisabled() {
|
||||||
SpringBatchScheduler schedulerBean = context.getBean(SpringBatchScheduler.class);
|
SpringBatchScheduler schedulerBean = context.getBean(SpringBatchScheduler.class);
|
||||||
await().untilAsserted(() -> Assert.assertEquals(2, schedulerBean.getBatchRunCounter()
|
await().untilAsserted(() -> Assert.assertEquals(2, schedulerBean.getBatchRunCounter()
|
||||||
.get()));
|
.get()));
|
||||||
|
|
Loading…
Reference in New Issue