/** * Check if a step execution is startable. * @param stepExecution the step execution to check * @param context the execution context of the step * @return true if the step execution is startable, false otherwise * @throws JobExecutionException if unable to check if the step execution is startable */ protected boolean isStartable(StepExecution stepExecution, ExecutionContext context) throws JobExecutionException { return getStartable(stepExecution, context); }
private StepExecution update(Set<StepExecution> split, StepExecution stepExecution, BatchStatus status) throws Exception { return update(split, stepExecution, status, true); }
/** * @see PartitionHandler#handle(StepExecutionSplitter, StepExecution) */ @Override public Collection<StepExecution> handle(final StepExecutionSplitter stepSplitter, final StepExecution masterStepExecution) throws Exception { final Set<StepExecution> stepExecutions = stepSplitter.split(masterStepExecution, gridSize); return doHandle(masterStepExecution, stepExecutions); }
@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 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 testAggregateNull() { aggregator.aggregate(result, null); }
@Before public void setUp() throws Exception { handler.setStep(new StepSupport() { @Override public void execute(StepExecution stepExecution) throws JobInterruptedException { count++; stepExecutions.add(stepExecution.getStepName()); } }); handler.afterPropertiesSet(); }
@Before public void setUp() throws Exception { MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean(); jobRepository = factory.getObject(); step.setJobRepository(jobRepository); step.setName("partitioned"); }
@Test(expected = IllegalStateException.class) public void testMissingResource() { partitioner.setResources(new Resource[] { new FileSystemResource("does-not-exist") }); partitioner.partition(0); }
@Override public Map<String, ExecutionContext> partition(int gridSize) { Map<String, ExecutionContext> partitions = super.partition(gridSize); int i = 0; for (ExecutionContext context : partitions.values()) { context.put(PARTITION_KEY, PARTITION_KEY + (i++)); } return partitions; }
@Before public void setUp() { ResourceArrayPropertyEditor editor = new ResourceArrayPropertyEditor(); editor.setAsText("classpath:jsrBaseContext.xml"); partitioner.setResources((Resource[]) editor.getValue()); }
@Test public void testAggregateNull() { aggregator.aggregate(result, null); }
@Override public void aggregate(StepExecution result, Collection<StepExecution> executions) { super.aggregate(result, executions); result.getExecutionContext().put("aggregated", true); } });
@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 testAggregateEmpty() { aggregator.aggregate(result, Collections.<StepExecution> emptySet()); }
@Test public void testAggregateEmpty() { aggregator.aggregate(result, Collections.<StepExecution> emptySet()); }
@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")); } }