@Override public StepExecution call() throws Exception { step.execute(stepExecution); return stepExecution; } });
@Override public StepExecution call() throws Exception { step.execute(stepExecution); return stepExecution; } });
@Around("execution(void org.springframework.batch.core.Step+.execute(*)) && target(step) && args(stepExecution)") public void execute(Step step, StepExecution stepExecution) throws JobInterruptedException { StepSynchronizationManager.register(stepExecution); try { step.execute(stepExecution); } finally { StepSynchronizationManager.release(); } }
@Override public void afterPropertiesSet() throws Exception { StepExecution stepExecution = new StepExecution("step", new JobExecution(1L), 0L); step.execute(stepExecution); // expect no errors }
private StepExecution execute(Step step) throws Exception { JobExecution jobExecution = jobRepository.createJobExecution( "job" + Math.random(), new JobParameters()); StepExecution stepExecution = jobExecution.createStepExecution("step"); jobRepository.add(stepExecution); step.execute(stepExecution); return stepExecution; }
protected void runStep(Step step) throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobInterruptedException { JobExecution jobExecution = repository.createJobExecution("job1", new JobParameters()); stepExecution = new StepExecution("step1", jobExecution); repository.add(stepExecution); step.execute(stepExecution); }
protected void runStep(Step step) throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobInterruptedException { JobExecution jobExecution = repository.createJobExecution("job1", new JobParameters()); stepExecution = new StepExecution("step1", jobExecution); repository.add(stepExecution); step.execute(stepExecution); }
@Test public void testProxiedScopedProxy() throws Exception { assertNotNull(nested); nested.execute(new StepExecution("step", new JobExecution(0L), 1L)); assertEquals(4, TestAdvice.names.size()); assertEquals("bar", TestAdvice.names.get(0)); assertEquals(1, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "destroyed")); }
@Test public void testVanillaIteration() throws Exception { factory.setItemReader(new ListItemReader<>(Arrays.asList(StringUtils .commaDelimitedListToStringArray("1,2,3,4,5,6")))); Step step = factory.getObject(); StepExecution stepExecution = getStepExecution(step); step.execute(stepExecution); waitForResults(6, 10); assertEquals(6, TestItemWriter.count); assertEquals(6, stepExecution.getReadCount()); }
@Test public void testSkipInProcessor() throws Exception { processor.setFailures("4"); factory.setCommitInterval(30); Step step = factory.getObject(); step.execute(stepExecution); assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); assertEquals("[1, 2, 3, 4, 1, 2, 3, 5]", processor.getProcessed().toString()); assertEquals("[1, 2, 3, 5]", processor.getCommitted().toString()); assertEquals("[1, 2, 3, 5]", writer.getWritten().toString()); assertEquals("[1, 2, 3, 5]", writer.getCommitted().toString()); }
@Test public void testMultipleSkipsInProcessor() throws Exception { processor.setFailures("2", "4"); factory.setCommitInterval(30); Step step = factory.getObject(); step.execute(stepExecution); assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); assertEquals("[1, 3, 5]", processor.getCommitted().toString()); assertEquals("[1, 3, 5]", writer.getWritten().toString()); assertEquals("[1, 3, 5]", writer.getCommitted().toString()); assertEquals("[1, 2, 1, 3, 4, 1, 3, 5]", processor.getProcessed().toString()); }
@Test public void testBeforeChunkListenerException() throws Exception{ factory.setListeners(new StepListener []{new ExceptionThrowingChunkListener(1)}); Step step = factory.getObject(); step.execute(stepExecution); assertEquals(FAILED, stepExecution.getStatus()); assertEquals(FAILED.toString(), stepExecution.getExitStatus().getExitCode()); assertTrue(stepExecution.getCommitCount() == 0);//Make sure exception was thrown in after, not before Throwable e = stepExecution.getFailureExceptions().get(0); assertThat(e, instanceOf(FatalStepExecutionException.class)); assertThat(e.getCause(), instanceOf(IllegalArgumentException.class)); }
@Test public void testSkipInWriterNonTransactionalProcessor() throws Exception { writer.setFailures("4"); factory.setCommitInterval(30); factory.setProcessorTransactional(false); Step step = factory.getObject(); step.execute(stepExecution); assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); assertEquals("[1, 2, 3, 5]", writer.getCommitted().toString()); assertEquals("[1, 2, 3, 4, 1, 2, 3, 4, 5]", writer.getWritten().toString()); assertEquals("[1, 2, 3, 4, 5]", processor.getProcessed().toString()); }
@Test public void testMultipleSkipsInWriterNonTransactionalProcessor() throws Exception { writer.setFailures("2", "4"); factory.setCommitInterval(30); factory.setProcessorTransactional(false); Step step = factory.getObject(); step.execute(stepExecution); assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); assertEquals("[1, 3, 5]", writer.getCommitted().toString()); assertEquals("[1, 2, 1, 2, 3, 4, 5]", writer.getWritten().toString()); assertEquals("[1, 2, 3, 4, 5]", processor.getProcessed().toString()); }
@Test public void testRefScopedProxy() throws Exception { assertNotNull(ref); ref.execute(new StepExecution("step", new JobExecution(0L), 1L)); assertEquals(4, TestAdvice.names.size()); assertEquals("spam", TestAdvice.names.get(0)); assertEquals(2, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "destroyed")); assertEquals(1, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "bar:destroyed")); assertEquals(1, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "spam:destroyed")); }
@Test public void testDisposableInnerScopedProxy() throws Exception { assertNotNull(nested); nested.execute(new StepExecution("step", new JobExecution(0L), 1L)); assertEquals(1, StringUtils.countOccurrencesOf(TestDisposableCollaborator.message, "destroyed")); }
@Test public void testNestedProxyTargetClassTrue() throws Exception { nestedProxyTargetClassTrue.execute(new StepExecution("foo", new JobExecution(11L), 31L)); String parent = (String) TestStep.getContext().getAttribute("parent"); assertEquals("bar", parent); assertTrue("Scoped proxy not created", ((String) TestStep.getContext().getAttribute("parent.class")) .matches(CGLIB_PROXY_TO_STRING_REGEX)); }
@Test public void testScopeCreation() throws Exception { vanilla.execute(new StepExecution("foo", new JobExecution(11L), 12L)); assertNotNull(TestStep.getContext()); assertNull(StepSynchronizationManager.getContext()); }
@Test public void testScopedProxyForReference() throws Exception { enhanced.execute(new StepExecution("foo", new JobExecution(11L), 123L)); assertTrue(TestStep.getContext().attributeNames().length > 0); String collaborator = (String) TestStep.getContext().getAttribute("collaborator"); assertNotNull(collaborator); assertEquals("bar", collaborator); }
@Test public void testExecutionContext() throws Exception { StepExecution stepExecution = new StepExecution("foo", new JobExecution(11L), 1L); ExecutionContext executionContext = new ExecutionContext(); executionContext.put("name", "spam"); stepExecution.setExecutionContext(executionContext); proxied.execute(stepExecution); assertTrue(TestStep.getContext().attributeNames().length > 0); String collaborator = (String) TestStep.getContext().getAttribute("collaborator"); assertNotNull(collaborator); assertEquals("bar", collaborator); }