@Override public RemotePartitioningWorkerStepBuilder repository(JobRepository jobRepository) { super.repository(jobRepository); return this; }
/** * Creates a step builder and initializes its job repository and transaction manager. Note that if the builder is * used to create a @Bean definition then the name of the step and the bean name might be different. * * @param name the name of the step * @return a step builder */ public StepBuilder get(String name) { StepBuilder builder = new StepBuilder(name).repository(jobRepository).transactionManager( transactionManager); return builder; }
@Test public void test() throws Exception { JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution( "step"); jobRepository.add(execution); PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); TaskletStepBuilder builder = new StepBuilder("step").repository(jobRepository) .transactionManager(transactionManager).tasklet((contribution, chunkContext) -> null); builder.build().execute(execution); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); }
@Test public void testFunctions() throws Exception { JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution("step"); jobRepository.add(execution); PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); List<Long> items = new ArrayList<Long>() {{ add(1L); add(2L); add(3L); }}; ItemReader<Long> reader = new ListItemReader<>(items); ListItemWriter<String> itemWriter = new ListItemWriter<>(); @SuppressWarnings("unchecked") SimpleStepBuilder<Object, String> builder = new StepBuilder("step") .repository(jobRepository) .transactionManager(transactionManager) .<Object, String>chunk(3) .reader(reader) .processor((Function<Object, String>) s -> s.toString()) .writer(itemWriter) .listener(new AnnotationBasedStepExecutionListener()); builder.build().execute(execution); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); List<? extends String> writtenItems = itemWriter.getWrittenItems(); assertEquals("1", writtenItems.get(0)); assertEquals("2", writtenItems.get(1)); assertEquals("3", writtenItems.get(2)); }
@Test public void testAnnotationBasedChunkListenerForTaskletStep() throws Exception { JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution("step"); jobRepository.add(execution); PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); TaskletStepBuilder builder = new StepBuilder("step") .repository(jobRepository) .transactionManager(transactionManager) .tasklet((contribution, chunkContext) -> null) .listener(new AnnotationBasedChunkListener()); builder.build().execute(execution); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); assertEquals(1, AnnotationBasedChunkListener.beforeChunkCount); assertEquals(1, AnnotationBasedChunkListener.afterChunkCount); }
@Test public void testAnnotationBasedChunkListenerForJobStepBuilder() throws Exception { JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution("step"); jobRepository.add(execution); PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); SimpleJob job = new SimpleJob("job"); job.setJobRepository(jobRepository); JobStepBuilder builder = new StepBuilder("step") .repository(jobRepository) .transactionManager(transactionManager) .job(job) .listener(new AnnotationBasedChunkListener()); builder.build().execute(execution); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); // it makes no sense to register a ChunkListener on a step which is not of type tasklet, so it should not be invoked assertEquals(0, AnnotationBasedChunkListener.beforeChunkCount); assertEquals(0, AnnotationBasedChunkListener.afterChunkCount); }
@Test public void testAnnotationBasedChunkListenerForSimpleTaskletStep() throws Exception { JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution("step"); jobRepository.add(execution); PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); SimpleStepBuilder<Object, Object> builder = new StepBuilder("step") .repository(jobRepository) .transactionManager(transactionManager) .chunk(5) .reader(new DummyItemReader()) .writer(new DummyItemWriter()) .listener(new AnnotationBasedChunkListener()); builder.build().execute(execution); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); assertEquals(1, AnnotationBasedChunkListener.beforeChunkCount); assertEquals(1, AnnotationBasedChunkListener.afterChunkCount); }
@Test public void testAnnotationBasedChunkListenerForFaultTolerantTaskletStep() throws Exception { JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution("step"); jobRepository.add(execution); PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); SimpleStepBuilder<Object, Object> builder = new StepBuilder("step") .repository(jobRepository) .transactionManager(transactionManager) .chunk(5) .reader(new DummyItemReader()) .writer(new DummyItemWriter()) .faultTolerant() .listener(new AnnotationBasedChunkListener()); // TODO should this return FaultTolerantStepBuilder? builder.build().execute(execution); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); assertEquals(1, AnnotationBasedChunkListener.beforeChunkCount); assertEquals(1, AnnotationBasedChunkListener.afterChunkCount); }
@Test public void testListeners() throws Exception { JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution("step"); jobRepository.add(execution); PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); TaskletStepBuilder builder = new StepBuilder("step") .repository(jobRepository) .transactionManager(transactionManager) .listener(new InterfaceBasedStepExecutionListener()) .listener(new AnnotationBasedStepExecutionListener()) .tasklet((contribution, chunkContext) -> null); builder.build().execute(execution); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); assertEquals(1, InterfaceBasedStepExecutionListener.beforeStepCount); assertEquals(1, InterfaceBasedStepExecutionListener.afterStepCount); assertEquals(1, AnnotationBasedStepExecutionListener.beforeStepCount); assertEquals(1, AnnotationBasedStepExecutionListener.afterStepCount); assertEquals(1, AnnotationBasedStepExecutionListener.beforeChunkCount); assertEquals(1, AnnotationBasedStepExecutionListener.afterChunkCount); }
.repository(jobRepository) .transactionManager(transactionManager) .<String, String>chunk(3)
/** * Creates a step builder and initializes its job repository and transaction manager. Note that if the builder is * used to create a @Bean definition then the name of the step and the bean name might be different. * * @param name the name of the step * @return a step builder */ public StepBuilder get(String name) { StepBuilder builder = new StepBuilder(name).repository(jobRepository).transactionManager( transactionManager); return builder; }
/** * Creates a step builder and initializes its job repository and transaction manager. Note that if the builder is * used to create a @Bean definition then the name of the step and the bean name might be different. * * @param name the name of the step * @return a step builder */ public StepBuilder get(String name) { StepBuilder builder = new StepBuilder(name).repository(jobRepository).transactionManager( transactionManager); return builder; }
/** * Creates a step builder and initializes its job repository and transaction manager. Note that if the builder is * used to create a @Bean definition then the name of the step and the bean name might be different. * * @param name the name of the step * @return a step builder */ public StepBuilder get(String name) { StepBuilder builder = new StepBuilder(name).repository(jobRepository).transactionManager( transactionManager); return builder; }
public SimpleStepBuilder<I,O> get(String name) { SimpleStepBuilder<I,O> builder = new StepBuilder(name) .repository(jobRepository) .transactionManager(transactionManager) .<I,O>chunk(completionPolicy)