List of usage examples for org.springframework.batch.core StepExecution StepExecution
public StepExecution(String stepName, JobExecution jobExecution)
From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapStepExecutionDao.java
/** * Returns a copy of {@link StepExecution}, by adding new Objects for every field(no references are passed) * /*from w ww. j a va 2s. co m*/ * @param original StepExecution to be copied * @return StepExecution copy */ private static StepExecution copy(StepExecution original) { StepExecution copy = new StepExecution(original.getStepName(), original.getJobExecution()); copy.setCommitCount(original.getCommitCount()); if (original.getEndTime() != null) { copy.setEndTime((Date) original.getEndTime().clone()); } //Warning: no deep copy if (original.getExitStatus() != null) { copy.setExitStatus(new ExitStatus(original.getExitStatus().getExitCode(), original.getExitStatus().getExitDescription())); } copy.setFilterCount(original.getFilterCount()); copy.setId(original.getId()); if (original.getLastUpdated() != null) { copy.setLastUpdated((Date) original.getLastUpdated().clone()); } copy.setProcessSkipCount(original.getProcessSkipCount()); copy.setReadCount(original.getReadCount()); copy.setReadSkipCount(original.getReadSkipCount()); copy.setRollbackCount(original.getRollbackCount()); if (original.getStartTime() != null) { copy.setStartTime((Date) original.getStartTime().clone()); } if (original.getStatus() != null) { copy.setStatus(BatchStatus.valueOf(original.getStatus().name())); } if (original.isTerminateOnly()) { copy.setTerminateOnly(); } copy.setVersion(original.getVersion()); copy.setWriteCount(original.getWriteCount()); copy.setWriteSkipCount(original.getWriteSkipCount()); return copy; }
From source file:com.javaetmoi.core.batch.test.EndTasklet.java
private StepExecution getUnpartitionedStepResume(JobExecution jobExecution) { StepExecution result = new StepExecution("resume", jobExecution); new DefaultStepExecutionAggregator().aggregate(result, getUnpartitionedStepExecution(jobExecution)); return result; }
From source file:org.springframework.cloud.dataflow.server.support.StepExecutionJacksonMixInTests.java
private StepExecution getStepExecution() { JobExecution jobExecution = new JobExecution(1L, null, "hi"); final StepExecution stepExecution = new StepExecution("step1", jobExecution); jobExecution.createStepExecution("step1"); final ExecutionContext executionContext = stepExecution.getExecutionContext(); executionContext.putInt("counter", 1234); executionContext.putDouble("myDouble", 1.123456d); executionContext.putLong("Josh", 4444444444L); executionContext.putString("awesomeString", "Yep"); executionContext.put("hello", "world"); executionContext.put("counter2", 9999); return stepExecution; }
From source file:org.obiba.onyx.core.etl.participant.impl.AppointmentListUpdateListenerTest.java
@Test public void testAfterUpdateCompleted() { Map<String, JobParameter> jobParameterMap = new HashMap<String, JobParameter>(); jobParameterMap.put("date", new JobParameter(new Date())); JobInstance job = new JobInstance(1l, new JobParameters(jobParameterMap), "jobTest"); StepExecution stepExecution = new StepExecution("compltion", new JobExecution(job)); stepExecution.setExitStatus(ExitStatus.COMPLETED); ExecutionContext context = new ExecutionContext(); context.put("fileName", "fileName.xls"); stepExecution.setExecutionContext(context); appointmentManagementServiceMock.saveAppointmentUpdateStats((AppointmentUpdateStats) EasyMock.anyObject()); replay(appointmentManagementServiceMock); appointmentListUpdateListener.afterUpdateCompleted(stepExecution); verify(appointmentManagementServiceMock); }
From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapStepExecutionDao.java
@Override public void updateStepExecution(StepExecution stepExecution) { Assert.notNull(stepExecution.getJobExecutionId()); //If the job execution data doesn't exist, can't update if (!executionsByJobExecutionId.containsKey(stepExecution.getJobExecutionId())) { return;//from w w w .j a v a2 s .c o m } Map<Long, StepExecution> executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId()); Assert.notNull(executions, "step executions for given job execution are expected to be already saved"); final StepExecution persistedExecution = executionsByStepExecutionId.get(stepExecution.getId()); Assert.notNull(persistedExecution, "step execution is expected to be already saved"); synchronized (stepExecution) { if (!persistedExecution.getVersion().equals(stepExecution.getVersion())) { throw new OptimisticLockingFailureException("Attempt to update step execution id=" + stepExecution.getId() + " with wrong version (" + stepExecution.getVersion() + "), where current version is " + persistedExecution.getVersion()); } stepExecution.incrementVersion(); StepExecution copy = new StepExecution(stepExecution.getStepName(), stepExecution.getJobExecution()); copy(stepExecution, copy); executions.put(stepExecution.getId(), copy); executionsByStepExecutionId.put(stepExecution.getId(), copy); } }
From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanNonBufferingTests.java
/** * Check items causing errors are skipped as expected. */// www. ja v a 2 s . c o m @Test public void testSkip() throws Exception { @SuppressWarnings("unchecked") SkipListener<Integer, String> skipListener = mock(SkipListener.class); skipListener.onSkipInWrite("3", exception); skipListener.onSkipInWrite("4", exception); factory.setListeners(new SkipListener[] { skipListener }); Step step = factory.getObject(); StepExecution stepExecution = new StepExecution(step.getName(), jobExecution); step.execute(stepExecution); assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); assertEquals(2, stepExecution.getSkipCount()); assertEquals(0, stepExecution.getReadSkipCount()); assertEquals(2, stepExecution.getWriteSkipCount()); // only one exception caused rollback, and only once in this case // because all items in that chunk were skipped immediately assertEquals(1, stepExecution.getRollbackCount()); assertFalse(writer.written.contains("4")); List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("1,2,5")); assertEquals(expectedOutput, writer.written); // 5 items + 1 rollbacks reading 2 items each time assertEquals(7, stepExecution.getReadCount()); }
From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanRetryTests.java
@Test public void testProcessAllItemsWhenErrorInWriterTransformationWhenReaderTransactional() throws Exception { final int RETRY_LIMIT = 3; final List<String> ITEM_LIST = TransactionAwareProxyFactory .createTransactionalList(Arrays.asList("1", "2", "3")); FaultTolerantStepFactoryBean<String, Integer> factory = new FaultTolerantStepFactoryBean<String, Integer>(); factory.setBeanName("step"); factory.setJobRepository(repository); factory.setTransactionManager(new ResourcelessTransactionManager()); ItemWriter<Integer> failingWriter = new ItemWriter<Integer>() { @Override//from w w w . j ava2 s .c om public void write(List<? extends Integer> data) throws Exception { int count = 0; for (Integer item : data) { if (count++ == 2) { throw new Exception("Planned failure in writer"); } written.add(item); } } }; ItemProcessor<String, Integer> processor = new ItemProcessor<String, Integer>() { @Override public Integer process(String item) throws Exception { processed.add(item); return Integer.parseInt(item); } }; ItemReader<String> reader = new ListItemReader<String>( TransactionAwareProxyFactory.createTransactionalList(ITEM_LIST)); factory.setCommitInterval(3); factory.setRetryLimit(RETRY_LIMIT); factory.setSkipLimit(1); factory.setIsReaderTransactionalQueue(true); @SuppressWarnings("unchecked") Map<Class<? extends Throwable>, Boolean> exceptionMap = getExceptionMap(Exception.class); factory.setSkippableExceptionClasses(exceptionMap); factory.setRetryableExceptionClasses(exceptionMap); factory.setItemReader(reader); factory.setItemProcessor(processor); factory.setItemWriter(failingWriter); Step step = factory.getObject(); StepExecution stepExecution = new StepExecution(step.getName(), jobExecution); repository.add(stepExecution); step.execute(stepExecution); /* * Each chunk tried up to RETRY_LIMIT, then the scan processes each item * once, identifying the skip as it goes */ assertEquals((RETRY_LIMIT + 1) * ITEM_LIST.size(), processed.size()); }
From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanRetryTests.java
@Test public void testProcessAllItemsWhenErrorInWriter() throws Exception { final int RETRY_LIMIT = 3; final List<String> ITEM_LIST = Arrays.asList("a", "b", "c"); ItemWriter<String> failingWriter = new ItemWriter<String>() { @Override/*from w ww. ja v a 2 s.co m*/ public void write(List<? extends String> data) throws Exception { int count = 0; for (String item : data) { if (count++ == 2) { throw new Exception("Planned failure in writer"); } written.add(item); } } }; ItemProcessor<String, String> processor = new ItemProcessor<String, String>() { @Override public String process(String item) throws Exception { processed.add(item); return item; } }; ItemReader<String> reader = new ListItemReader<String>(ITEM_LIST); factory.setCommitInterval(3); factory.setRetryLimit(RETRY_LIMIT); factory.setSkipLimit(1); @SuppressWarnings("unchecked") Map<Class<? extends Throwable>, Boolean> exceptionMap = getExceptionMap(Exception.class); factory.setSkippableExceptionClasses(exceptionMap); factory.setItemReader(reader); factory.setItemProcessor(processor); factory.setItemWriter(failingWriter); Step step = factory.getObject(); StepExecution stepExecution = new StepExecution(step.getName(), jobExecution); repository.add(stepExecution); step.execute(stepExecution); assertEquals(ExitStatus.COMPLETED.getExitCode(), stepExecution.getExitStatus().getExitCode()); /* * Each chunk tried up to RETRY_LIMIT, then the scan processes each item * once, identifying the skip as it goes */ assertEquals((RETRY_LIMIT + 1) * ITEM_LIST.size(), processed.size()); }
From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanRetryTests.java
@Test public void testNoItemsReprocessedWhenErrorInWriterAndProcessorNotTransactional() throws Exception { ItemWriter<String> failingWriter = new ItemWriter<String>() { @Override/*from w ww. j a va 2s . com*/ public void write(List<? extends String> data) throws Exception { int count = 0; for (String item : data) { if (count++ == 2) { throw new Exception("Planned failure in writer"); } written.add(item); } } }; ItemProcessor<String, String> processor = new ItemProcessor<String, String>() { @Override public String process(String item) throws Exception { processed.add(item); return item; } }; ItemReader<String> reader = new ListItemReader<String>(Arrays.asList("a", "b", "c")); factory.setProcessorTransactional(false); factory.setCommitInterval(3); factory.setRetryLimit(3); factory.setSkippableExceptionClasses(new HashMap<Class<? extends Throwable>, Boolean>()); factory.setItemReader(reader); factory.setItemProcessor(processor); factory.setItemWriter(failingWriter); Step step = factory.getObject(); StepExecution stepExecution = new StepExecution(step.getName(), jobExecution); repository.add(stepExecution); step.execute(stepExecution); assertEquals(3, processed.size()); // Initial try only, then cached }
From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanRetryTests.java
/** * N.B. this doesn't really test retry, since the retry is only on write * failures, but it does test that read errors are re-presented for another * try when the retryLimit is high enough (it is used to build an exception * handler)./* w ww . java 2 s. c om*/ * * @throws Exception */ @SuppressWarnings("unchecked") @Test public void testSuccessfulRetryWithReadFailure() throws Exception { ItemReader<String> provider = new ListItemReader<String>(Arrays.asList("a", "b", "c")) { @Override public String read() { String item = super.read(); provided.add(item); count++; if (count == 2) { throw new RuntimeException("Temporary error - retry for success."); } return item; } }; factory.setItemReader(provider); factory.setRetryLimit(10); factory.setSkippableExceptionClasses(getExceptionMap()); Step step = factory.getObject(); StepExecution stepExecution = new StepExecution(step.getName(), jobExecution); repository.add(stepExecution); step.execute(stepExecution); assertEquals(0, stepExecution.getSkipCount()); // [a, b with error] assertEquals(2, provided.size()); // [a] assertEquals(1, processed.size()); // [] assertEquals(0, recovered.size()); assertEquals(1, stepExecution.getReadCount()); assertEquals(0, stepExecution.getReadSkipCount()); }