@Override protected StepContext createNewContext(StepExecution execution, BatchPropertyContext propertyContext) { StepContext context; if(propertyContext != null) { context = new StepContext(execution, propertyContext); } else { context = new StepContext(execution); } return context; }
@Test public void testNullStepExecution() { try { context = new StepContext(null); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { // expected } }
@Test public void testEqualsContextWithSameStepExecution() { assertEquals(new StepContext(stepExecution), context); }
@Test public void testGetPartitionPlan() { Properties partitionPropertyValues = new Properties(); partitionPropertyValues.put("key1", "value1"); propertyContext.setStepProperties(stepExecution.getStepName(), partitionPropertyValues); context = new StepContext(stepExecution, propertyContext); Map<String, Object> plan = context.getPartitionPlan(); assertEquals("value1", plan.get("key1")); }
@Test public void testGetStepExecution() { context = new StepContext(stepExecution); assertNotNull(context.getStepExecution()); }
@Test(expected = IllegalStateException.class) public void testIllegalContextId() throws Exception { context = new StepContext(new StepExecution("foo", new JobExecution(0L))); context.getId(); }
@Test public void testJobParameters() throws Exception { JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").toJobParameters(); JobInstance instance = stepExecution.getJobExecution().getJobInstance(); stepExecution = new StepExecution("step", new JobExecution(instance, jobParameters)); context = new StepContext(stepExecution); assertEquals("bar", context.getJobParameters().get("foo")); }
@Test public void testStopped() throws Exception { initializeTasklet(); tasklet.setJobExplorer(jobExplorer); tasklet.afterPropertiesSet(); tasklet.beforeStep(stepExecution); JobExecution stoppedJobExecution = new JobExecution(stepExecution.getJobExecution()); stoppedJobExecution.setStatus(BatchStatus.STOPPING); when(jobExplorer.getJobExecution(1L)).thenReturn(stepExecution.getJobExecution(), stepExecution.getJobExecution(), stoppedJobExecution); String command = isRunningOnWindows() ? "ping 127.0.0.1 -n 5" : "sleep 15"; tasklet.setCommand(command); tasklet.setTerminationCheckInterval(10); tasklet.afterPropertiesSet(); StepContribution contribution = stepExecution.createStepContribution(); StepContext stepContext = new StepContext(stepExecution); ChunkContext chunkContext = new ChunkContext(stepContext); tasklet.execute(contribution, chunkContext); assertEquals(ExitStatus.STOPPED.getExitCode(), contribution.getExitStatus().getExitCode()); }
@Override protected StepContext createNewContext(StepExecution execution, BatchPropertyContext propertyContext) { StepContext context; if(propertyContext != null) { context = new StepContext(execution, propertyContext); } else { context = new StepContext(execution); } return context; }
@Override protected StepContext createNewContext(StepExecution execution, BatchPropertyContext propertyContext) { StepContext context; if(propertyContext != null) { context = new StepContext(execution, propertyContext); } else { context = new StepContext(execution); } return context; }
@Override protected StepContext createNewContext(StepExecution execution, BatchPropertyContext propertyContext) { StepContext context; if(propertyContext != null) { context = new StepContext(execution, propertyContext); } else { context = new StepContext(execution); } return context; }
/** * Register a context with the current thread - always put a matching * {@link #close()} call in a finally block to ensure that the correct * context is available in the enclosing block. * * @param stepExecution the step context to register * @return a new {@link StepContext} or the current one if it has the same * {@link StepExecution} */ public static StepContext register(StepExecution stepExecution) { if (stepExecution == null) { return null; } getCurrent().push(stepExecution); StepContext context; synchronized (contexts) { context = contexts.get(stepExecution); if (context == null) { context = new StepContext(stepExecution); contexts.put(stepExecution, context); } } increment(); return context; }