/** * Tests the results of BATCH-2490 * @throws Exception */ @Test public void testAddressabilityOfSetResults() throws Exception { SimpleStepExecutionSplitter splitter = new SimpleStepExecutionSplitter(jobRepository, true, step.getName(), new SimplePartitioner()); Set<StepExecution> execs = splitter.split(stepExecution, 2); assertEquals(2, execs.size()); StepExecution execution = execs.iterator().next(); execs.remove(execution); assertEquals(1, execs.size()); }
@Test public void testGetStepName() { SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, true, step.getName(), new SimplePartitioner()); assertEquals("step", provider.getStepName()); }
@Test public void testSimpleStepExecutionProviderJobRepositoryStep() throws Exception { SimpleStepExecutionSplitter splitter = new SimpleStepExecutionSplitter(jobRepository, true, step.getName(), new SimplePartitioner()); Set<StepExecution> execs = splitter.split(stepExecution, 2); assertEquals(2, execs.size()); for (StepExecution execution : execs) { assertNotNull("step execution partition is saved", execution.getId()); } }
@Test public void testCompleteStatusSameJobExecution() throws Exception { SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, false, step.getName(), new SimplePartitioner()); Set<StepExecution> split = provider.split(stepExecution, 2); assertEquals(2, split.size()); stepExecution = update(split, stepExecution, BatchStatus.COMPLETED); // If already complete in the same JobExecution we should execute again assertEquals(2, provider.split(stepExecution, 2).size()); }
@Test public void testCompleteStatusAfterFailure() throws Exception { SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, false, step.getName(), new SimplePartitioner()); Set<StepExecution> split = provider.split(stepExecution, 2); assertEquals(2, split.size()); StepExecution nextExecution = update(split, stepExecution, BatchStatus.COMPLETED, false); // If already complete in another JobExecution we don't execute again assertEquals(0, provider.split(nextExecution, 2).size()); }
@Test public void testRememberGridSize() throws Exception { SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, true, step.getName(), new SimplePartitioner()); Set<StepExecution> split = provider.split(stepExecution, 2); assertEquals(2, split.size()); stepExecution = update(split, stepExecution, BatchStatus.FAILED); assertEquals(2, provider.split(stepExecution, 3).size()); }
@Test public void testUnknownStatus() throws Exception { SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, true, step.getName(), new SimplePartitioner()); Set<StepExecution> split = provider.split(stepExecution, 2); assertEquals(2, split.size()); stepExecution = update(split, stepExecution, BatchStatus.UNKNOWN); try { provider.split(stepExecution, 2); } catch (JobExecutionException e) { String message = e.getMessage(); assertTrue("Wrong message: " + message, message.contains("UNKNOWN")); } }
@Test public void testAbandonedStatus() throws Exception { SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, true, step.getName(), new SimplePartitioner()); Set<StepExecution> split = provider.split(stepExecution, 2); assertEquals(2, split.size()); stepExecution = update(split, stepExecution, BatchStatus.ABANDONED); // If not already complete we don't execute again try { provider.split(stepExecution, 2); } catch (JobExecutionException e) { String message = e.getMessage(); assertTrue("Wrong message: " + message, message.contains("ABANDONED")); } }
@Test public void testIncompleteStatus() throws Exception { SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, true, step.getName(), new SimplePartitioner()); Set<StepExecution> split = provider.split(stepExecution, 2); assertEquals(2, split.size()); stepExecution = update(split, stepExecution, BatchStatus.STARTED); // If not already complete we don't execute again try { provider.split(stepExecution, 2); } catch (JobExecutionException e) { String message = e.getMessage(); assertTrue("Wrong message: " + message, message.contains("STARTED")); } }
@Test public void testVanillaStepExecution() throws Exception { step.setStepExecutionSplitter(new SimpleStepExecutionSplitter(jobRepository, true, step.getName(), new SimplePartitioner())); step.setPartitionHandler(new PartitionHandler() { @Override public Collection<StepExecution> handle(StepExecutionSplitter stepSplitter, StepExecution stepExecution) throws Exception { Set<StepExecution> executions = stepSplitter.split(stepExecution, 2); for (StepExecution execution : executions) { execution.setStatus(BatchStatus.COMPLETED); execution.setExitStatus(ExitStatus.COMPLETED); } return executions; } }); step.afterPropertiesSet(); JobExecution jobExecution = jobRepository.createJobExecution("vanillaJob", new JobParameters()); StepExecution stepExecution = jobExecution.createStepExecution("foo"); jobRepository.add(stepExecution); step.execute(stepExecution); // one master and two workers assertEquals(3, stepExecution.getJobExecution().getStepExecutions().size()); assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); }
@Test public void testFailedStepExecution() throws Exception { step.setStepExecutionSplitter(new SimpleStepExecutionSplitter(jobRepository, true, step.getName(), new SimplePartitioner())); step.setPartitionHandler(new PartitionHandler() { @Override public Collection<StepExecution> handle(StepExecutionSplitter stepSplitter, StepExecution stepExecution) throws Exception { Set<StepExecution> executions = stepSplitter.split(stepExecution, 2); for (StepExecution execution : executions) { execution.setStatus(BatchStatus.FAILED); execution.setExitStatus(ExitStatus.FAILED); } return executions; } }); step.afterPropertiesSet(); JobExecution jobExecution = jobRepository.createJobExecution("vanillaJob", new JobParameters()); StepExecution stepExecution = jobExecution.createStepExecution("foo"); jobRepository.add(stepExecution); step.execute(stepExecution); // one master and two workers assertEquals(3, stepExecution.getJobExecution().getStepExecutions().size()); assertEquals(BatchStatus.FAILED, stepExecution.getStatus()); }
@Test public void testStoppedStepExecution() throws Exception { step.setStepExecutionSplitter(new SimpleStepExecutionSplitter(jobRepository, true, step.getName(), new SimplePartitioner())); step.setPartitionHandler(new PartitionHandler() { @Override public Collection<StepExecution> handle(StepExecutionSplitter stepSplitter, StepExecution stepExecution) throws Exception { Set<StepExecution> executions = stepSplitter.split(stepExecution, 2); for (StepExecution execution : executions) { execution.setStatus(BatchStatus.STOPPED); execution.setExitStatus(ExitStatus.STOPPED); } return executions; } }); step.afterPropertiesSet(); JobExecution jobExecution = jobRepository.createJobExecution("vanillaJob", new JobParameters()); StepExecution stepExecution = jobExecution.createStepExecution("foo"); jobRepository.add(stepExecution); step.execute(stepExecution); // one master and two workers assertEquals(3, stepExecution.getJobExecution().getStepExecutions().size()); assertEquals(BatchStatus.STOPPED, stepExecution.getStatus()); }
@Test public void testStepAggregator() throws Exception { step.setStepExecutionAggregator(new DefaultStepExecutionAggregator() { @Override public void aggregate(StepExecution result, Collection<StepExecution> executions) { super.aggregate(result, executions); result.getExecutionContext().put("aggregated", true); } }); step.setStepExecutionSplitter(new SimpleStepExecutionSplitter(jobRepository, true, step.getName(), new SimplePartitioner())); step.setPartitionHandler(new PartitionHandler() { @Override public Collection<StepExecution> handle(StepExecutionSplitter stepSplitter, StepExecution stepExecution) throws Exception { return Arrays.asList(stepExecution); } }); step.afterPropertiesSet(); JobExecution jobExecution = jobRepository.createJobExecution("vanillaJob", new JobParameters()); StepExecution stepExecution = jobExecution.createStepExecution("foo"); jobRepository.add(stepExecution); step.execute(stepExecution); assertEquals(true, stepExecution.getExecutionContext().get("aggregated")); }
@Test public void testRestartStepExecution() throws Exception { final AtomicBoolean started = new AtomicBoolean(false); step.setStepExecutionSplitter(new SimpleStepExecutionSplitter(jobRepository, true, step.getName(), new SimplePartitioner())); step.setPartitionHandler(new PartitionHandler() { @Override
@Test public void testPartitionStepWithProxyHandler() throws Exception { StepParserStepFactoryBean<Object, Object> fb = new StepParserStepFactoryBean<>(); fb.setBeanName("step1"); fb.setAllowStartIfComplete(true); fb.setJobRepository(new JobRepositorySupport()); fb.setStartLimit(5); fb.setListeners(new StepListener[] { new StepExecutionListenerSupport() }); fb.setTaskExecutor(new SyncTaskExecutor()); SimplePartitioner partitioner = new SimplePartitioner(); fb.setPartitioner(partitioner); TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler(); partitionHandler.setStep(new StepSupport("foo")); ProxyFactory factory = new ProxyFactory(partitionHandler); fb.setPartitionHandler((PartitionHandler) factory.getProxy()); Object step = fb.getObject(); assertTrue(step instanceof PartitionStep); Object handler = ReflectionTestUtils.getField(step, "partitionHandler"); assertTrue(handler instanceof Advised); }
@Test public void testPartitionStep() throws Exception { StepParserStepFactoryBean<Object, Object> fb = new StepParserStepFactoryBean<>(); fb.setBeanName("step1"); fb.setAllowStartIfComplete(true); fb.setJobRepository(new JobRepositorySupport()); fb.setStartLimit(5); fb.setListeners(new StepListener[] { new StepExecutionListenerSupport() }); fb.setTaskExecutor(new SyncTaskExecutor()); SimplePartitioner partitioner = new SimplePartitioner(); fb.setPartitioner(partitioner); fb.setStep(new StepSupport("foo")); Object step = fb.getObject(); assertTrue(step instanceof PartitionStep); Object handler = ReflectionTestUtils.getField(step, "partitionHandler"); assertTrue(handler instanceof TaskExecutorPartitionHandler); }