@Override public void saveExecutionContext(StepExecution stepExecution) { Long executionId = stepExecution.getId(); ExecutionContext executionContext = stepExecution.getExecutionContext(); Assert.notNull(executionId, "ExecutionId must not be null."); Assert.notNull(executionContext, "The ExecutionContext must not be null."); String serializedContext = serializeContext(executionContext); persistSerializedContext(executionId, serializedContext, INSERT_STEP_EXECUTION_CONTEXT); }
@Override public void updateExecutionContext(StepExecution stepExecution) { Assert.state(stepExecution.getId() != null, "StepExecution must already be saved"); saved = stepExecution.getExecutionContext(); }
@BeforeStep public void createOutputNameFromInput(StepExecution stepExecution) { ExecutionContext executionContext = stepExecution.getExecutionContext(); String inputName = stepExecution.getStepName().replace(":", "-"); if (executionContext.containsKey(inputKeyName)) { inputName = executionContext.getString(inputKeyName); } if (!executionContext.containsKey(outputKeyName)) { executionContext.putString(outputKeyName, path + FilenameUtils.getBaseName(inputName) + ".csv"); } }
public StepExecution getStepExecution() { StepExecution execution = MetaDataInstanceFactory.createStepExecution(); execution.getExecutionContext().putString("input.data", "foo,bar"); return execution; }
@Override public void aggregate(StepExecution result, Collection<StepExecution> executions) { super.aggregate(result, executions); result.getExecutionContext().put("aggregated", true); } });
@Override public void beforeStep(StepExecution stepExecution) { assertSame(execution, stepExecution); events.add(getEvent("beforeStep")); stepExecution.getExecutionContext().putString("beforeStep", "beforeStep"); }
@Test public void testGetNamedDateJobParameters() throws Exception { Date date = new Date(); stepExecution.getExecutionContext().put("foo",date); extractor.setKeys(new String[] {"foo(date)"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{foo="+date.getTime()+"}", jobParameters.toString()); }
@Test public void testStepExecutionContext() throws Exception { ExecutionContext executionContext = stepExecution.getExecutionContext(); executionContext.put("foo", "bar"); assertEquals("bar", context.getStepExecutionContext().get("foo")); }
public StepExecution getStepExecution() { // Assert that dependencies are already injected... assertNotNull(reader); // Then create the execution for the step scope... StepExecution execution = MetaDataInstanceFactory.createStepExecution(); execution.getExecutionContext().putString("input.file", "classpath:/org/springframework/batch/test/simple.txt"); return execution; }
@Test public void testBeforeStep() { listener.beforeStep(stepExecution); assertEquals("bar", stepExecution.getExecutionContext().get("foo")); }
private void copy(final StepExecution source, final StepExecution target) { target.setVersion(source.getVersion()); target.setWriteCount(source.getWriteCount()); target.setFilterCount(source.getFilterCount()); target.setCommitCount(source.getCommitCount()); target.setExecutionContext(new ExecutionContext(source.getExecutionContext())); }
@Test public void testSetPath() { listener.setPath("spam/"); listener.createOutputNameFromInput(stepExecution); assertEquals("{outputFile=spam/foo.csv}", stepExecution.getExecutionContext().toString()); }
@Test public void testSimpleProperty() throws Exception { assertEquals("bar", simple.getName()); // Once the step context is set up it should be baked into the proxies // so changing it now should have no effect stepExecution.getExecutionContext().put("foo", "wrong!"); assertEquals("bar", simple.getName()); }
@Test public void testSimpleProperty() throws Exception { assertEquals("bar", simple.getName()); // Once the step context is set up it should be baked into the proxies // so changing it now should have no effect stepExecution.getExecutionContext().put("foo", "wrong!"); assertEquals("bar", simple.getName()); }
@Test public void testGetNamedIntJobParameters() throws Exception { stepExecution.getExecutionContext().putInt("foo",11); extractor.setKeys(new String[] {"foo(int)", "bar"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{foo=11}", jobParameters.toString()); }
@Test public void testGetNamedLongJobParameters() throws Exception { stepExecution.getExecutionContext().putLong("foo",11L); extractor.setKeys(new String[] {"foo(long)", "bar"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{foo=11}", jobParameters.toString()); }
@Test public void testGetNamedLongStringParameters() throws Exception { stepExecution.getExecutionContext().putString("foo","bar"); extractor.setKeys(new String[] {"foo(string)", "bar"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{foo=bar}", jobParameters.toString()); }
@Test public void testSetOutputKeyName() { listener.setPath(""); listener.setOutputKeyName("spam"); listener.createOutputNameFromInput(stepExecution); assertEquals("{spam=foo.csv}", stepExecution.getExecutionContext().toString()); }
@Test public void testSimpleProperty() throws Exception { StepExecution stepExecution = new StepExecution("step", new JobExecution(0L), 123L); ExecutionContext executionContext = stepExecution.getExecutionContext(); executionContext.put("foo", "bar"); StepSynchronizationManager.register(stepExecution); assertEquals("bar", simple.getName()); }
@Test public void testCycle() throws Exception { StepExecution stepExecution = new StepExecution("step", new JobExecution(new JobInstance(123L, "job"), 321L, new JobParameters(), null), 11L); stepExecution.getExecutionContext().put("foo.bar.spam", 123); StepExecution result = getCopy(stepExecution); assertEquals(stepExecution, result); }