private TaskletStep getStep(String[] strings) throws Exception { return getStep(strings, 1); }
@Test public void testCommitCount_Uneven() throws Exception { JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters); step = getStep(new String[] { "foo", "bar", "spam" }, 2); step.setTransactionManager(transactionManager); StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext); step.execute(stepExecution); assertEquals(3, processed.size()); assertEquals(3, stepExecution.getReadCount()); assertEquals(3, stepExecution.getWriteCount()); assertEquals(2, stepExecution.getCommitCount()); }
@Test public void testCommitCount_Even() throws Exception { JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters); step = getStep(new String[] { "foo", "bar", "spam", "eggs" }, 2); step.setTransactionManager(transactionManager); StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext); step.execute(stepExecution); assertEquals(4, processed.size()); assertEquals(4, stepExecution.getReadCount()); assertEquals(4, stepExecution.getWriteCount()); assertEquals(3, stepExecution.getCommitCount()); //the empty chunk is the 3rd commit }
@Before public void setUp() throws Exception { transactionManager = new ResourcelessTransactionManager(); RepeatTemplate template = new RepeatTemplate(); template.setCompletionPolicy(new SimpleCompletionPolicy(1)); step = getStep(new String[] { "foo", "bar", "spam" }); step.setStepOperations(template); job = new JobSupport("FOO"); jobInstance = new JobInstance(0L, job.getName()); jobParameters = new JobParameters(); step.setTransactionManager(transactionManager); }
@Test public void testEmptyReader() throws Exception { JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters); StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext); step = getStep(new String[0]); step.setTasklet(new TestingChunkOrientedTasklet<>(getReader(new String[0]), itemWriter, new RepeatTemplate())); step.setStepOperations(new RepeatTemplate()); step.execute(stepExecution); assertEquals(0, processed.size()); assertEquals(0, stepExecution.getReadCount()); // Commit after end of data detected (this leads to the commit count // being one greater than people expect if the commit interval is // commensurate with the total number of items).h assertEquals(1, stepExecution.getCommitCount()); }