private StepExecution update(Set<StepExecution> split, StepExecution stepExecution, BatchStatus status) throws Exception { return update(split, stepExecution, status, true); }
@Test public void testRememberPartitionNames() throws Exception { class CustomPartitioner implements Partitioner, PartitionNameProvider { @Override public Map<String, ExecutionContext> partition(int gridSize) { return Collections.singletonMap("foo", new ExecutionContext()); } @Override public Collection<String> getPartitionNames(int gridSize) { return Arrays.asList("foo"); } } SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, true, step.getName(), new CustomPartitioner()); Set<StepExecution> split = provider.split(stepExecution, 2); assertEquals(1, split.size()); assertEquals("step:foo", split.iterator().next().getStepName()); stepExecution = update(split, stepExecution, BatchStatus.FAILED); split = provider.split(stepExecution, 2); assertEquals("step:foo", split.iterator().next().getStepName()); }
@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")); } }