List of usage examples for org.springframework.batch.core StepExecution getReadCount
public int getReadCount()
From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanTests.java
private void assertStepExecutionsAreEqual(StepExecution expected, StepExecution actual) { assertEquals(expected.getId(), actual.getId()); assertEquals(expected.getStartTime(), actual.getStartTime()); assertEquals(expected.getEndTime(), actual.getEndTime()); assertEquals(expected.getSkipCount(), actual.getSkipCount()); assertEquals(expected.getCommitCount(), actual.getCommitCount()); assertEquals(expected.getReadCount(), actual.getReadCount()); assertEquals(expected.getWriteCount(), actual.getWriteCount()); assertEquals(expected.getFilterCount(), actual.getFilterCount()); assertEquals(expected.getWriteSkipCount(), actual.getWriteSkipCount()); assertEquals(expected.getReadSkipCount(), actual.getReadSkipCount()); assertEquals(expected.getProcessSkipCount(), actual.getProcessSkipCount()); assertEquals(expected.getRollbackCount(), actual.getRollbackCount()); assertEquals(expected.getExitStatus(), actual.getExitStatus()); assertEquals(expected.getLastUpdated(), actual.getLastUpdated()); assertEquals(expected.getExitStatus(), actual.getExitStatus()); assertEquals(expected.getJobExecutionId(), actual.getJobExecutionId()); }
From source file:org.springframework.batch.core.step.tasklet.AsyncTaskletStepTests.java
/** * StepExecution should be updated after every chunk commit. *//*from w w w . j av a 2 s .c o m*/ @Test public void testStepExecutionUpdates() throws Exception { items = new ArrayList<String>(Arrays.asList(StringUtils.commaDelimitedListToStringArray( "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25"))); setUp(); JobExecution jobExecution = jobRepository.createJobExecution("JOB", new JobParameters()); StepExecution stepExecution = jobExecution.createStepExecution(step.getName()); step.execute(stepExecution); assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); // assertEquals(25, stepExecution.getReadCount()); // assertEquals(25, processed.size()); assertTrue(stepExecution.getReadCount() >= 25); assertTrue(processed.size() >= 25); // System.err.println(stepExecution.getCommitCount()); // System.err.println(processed); // Check commit count didn't spin out of control waiting for other // threads to finish... assertTrue("Not enough commits: " + stepExecution.getCommitCount(), stepExecution.getCommitCount() > processed.size() / 2); assertTrue("Too many commits: " + stepExecution.getCommitCount(), stepExecution.getCommitCount() <= processed.size() / 2 + throttleLimit + 1); }
From source file:org.springframework.batch.core.step.tasklet.AsyncTaskletStepTests.java
/** * StepExecution should fail immediately on error. *///from w ww. j av a 2 s . c o m @Test public void testStepExecutionFails() throws Exception { throttleLimit = 1; concurrencyLimit = 1; items = Arrays.asList("one", "fail", "three", "four"); setUp(); JobExecution jobExecution = jobRepository.createJobExecution("JOB", new JobParameters()); StepExecution stepExecution = jobExecution.createStepExecution(step.getName()); step.execute(stepExecution); assertEquals(BatchStatus.FAILED, stepExecution.getStatus()); assertEquals(2, stepExecution.getReadCount()); assertEquals(2, processed.size()); }
From source file:org.springframework.batch.core.step.tasklet.AsyncTaskletStepTests.java
/** * StepExecution should fail immediately on error in processor. *//*www. j a v a 2 s .com*/ @Test public void testStepExecutionFailsWithProcessor() throws Exception { throttleLimit = 1; concurrencyLimit = 1; items = Arrays.asList("one", "barf", "three", "four"); itemProcessor = new ItemProcessor<String, String>() { @Override public String process(String item) throws Exception { logger.info("Item: " + item); processed.add(item); if (item.equals("barf")) { throw new RuntimeException("Planned processor error"); } return item; } }; setUp(); JobExecution jobExecution = jobRepository.createJobExecution("JOB", new JobParameters()); StepExecution stepExecution = jobExecution.createStepExecution(step.getName()); step.execute(stepExecution); assertEquals(BatchStatus.FAILED, stepExecution.getStatus()); assertEquals(2, stepExecution.getReadCount()); assertEquals(2, processed.size()); }
From source file:org.springframework.batch.core.step.tasklet.AsyncTaskletStepTests.java
/** * StepExecution should fail immediately on error. *//*w w w . j a v a2 s. com*/ @Test public void testStepExecutionFailsOnLastItem() throws Exception { throttleLimit = 1; concurrencyLimit = 1; items = Arrays.asList("one", "two", "three", "fail"); setUp(); JobExecution jobExecution = jobRepository.createJobExecution("JOB", new JobParameters()); StepExecution stepExecution = jobExecution.createStepExecution(step.getName()); step.execute(stepExecution); assertEquals(BatchStatus.FAILED, stepExecution.getStatus()); assertEquals(4, stepExecution.getReadCount()); assertEquals(4, processed.size()); }
From source file:org.springframework.batch.core.test.football.FootballJobIntegrationTests.java
@Test public void testLaunchJob() throws Exception { JobExecution execution = jobLauncher.run(job, new JobParametersBuilder().addLong("commit.interval", 10L).toJobParameters()); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); for (StepExecution stepExecution : execution.getStepExecutions()) { logger.info("Processed: " + stepExecution); if (stepExecution.getStepName().equals("playerload")) { // The effect of the retries assertEquals(new Double(Math.ceil(stepExecution.getReadCount() / 10. + 1)).intValue(), stepExecution.getCommitCount()); }/*from ww w . j a v a2s . c om*/ } }
From source file:org.springframework.batch.core.test.football.FootballJobSkipIntegrationTests.java
@Test public void testLaunchJob() throws Exception { try {/*from w ww . ja va 2s. c om*/ if (databaseType == DatabaseType.POSTGRES || databaseType == DatabaseType.ORACLE) { // Extra special test for these platforms (would have failed // the job with UNKNOWN status in Batch 2.0): jdbcTemplate.update("SET CONSTRAINTS ALL DEFERRED"); } } catch (Exception e) { // Ignore (wrong platform) } JobExecution execution = jobLauncher.run(job, new JobParametersBuilder().addLong("skip.limit", 0L).toJobParameters()); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); for (StepExecution stepExecution : execution.getStepExecutions()) { logger.info("Processed: " + stepExecution); } // They all skip on the second execution because of a primary key // violation long retryLimit = 2L; execution = jobLauncher.run(job, new JobParametersBuilder().addLong("skip.limit", 100000L) .addLong("retry.limit", retryLimit).toJobParameters()); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); for (StepExecution stepExecution : execution.getStepExecutions()) { logger.info("Processed: " + stepExecution); if (stepExecution.getStepName().equals("playerload")) { // The effect of the retries is to increase the number of // rollbacks int commitInterval = stepExecution.getReadCount() / (stepExecution.getCommitCount() - 1); // Account for the extra empty commit if the read count is // commensurate with the commit interval int effectiveCommitCount = stepExecution.getReadCount() % commitInterval == 0 ? stepExecution.getCommitCount() - 1 : stepExecution.getCommitCount(); long expectedRollbacks = Math.max(1, retryLimit) * effectiveCommitCount + stepExecution.getReadCount(); assertEquals(expectedRollbacks, stepExecution.getRollbackCount()); assertEquals(stepExecution.getReadCount(), stepExecution.getWriteSkipCount()); } } }