@Override public void update(ExecutionContext executionContext) throws ItemStreamException { executionContext.putInt(CURRENT_INDEX, currentIndex); } }
@Override public void update(ExecutionContext executionContext) throws ItemStreamException { super.update(executionContext); if (saveState) { Assert.notNull(executionContext, "ExecutionContext must not be null"); executionContext.putInt(getExecutionContextKey(READ_COUNT), currentItemCount); if (maxItemCount < Integer.MAX_VALUE) { executionContext.putInt(getExecutionContextKey(READ_COUNT_MAX), maxItemCount); } } }
@Override public void update(ExecutionContext executionContext) throws ItemStreamException { super.update(executionContext); executionContext.putInt(getExecutionContextKey("COUNT"), counter.get()); }
@Override public void update(ExecutionContext executionContext) throws ItemStreamException { super.update(executionContext); if (saveState) { if (opened) { delegate.update(executionContext); } executionContext.putInt(getExecutionContextKey(CURRENT_RESOURCE_ITEM_COUNT), currentResourceItemCount); executionContext.putInt(getExecutionContextKey(RESOURCE_INDEX_KEY), resourceIndex); } }
@Override public Map<String, ExecutionContext> partition(int gridSize) { Map<String, ExecutionContext> partition = super.partition(gridSize); int total = 8; // The number of items in the ExampleItemReader int range = total/gridSize; int i = 0; for (ExecutionContext context : partition.values()) { int min = (i++)*range; int max = Math.min(total, i * range); context.putInt("min", min); context.putInt("max", max); } return partition; }
@Override public void update(ExecutionContext executionContext) { super.update(executionContext); executionContext.putInt("counter", count++); } });
/** * Store the current resource index and position in the resource. */ @Override public void update(ExecutionContext executionContext) throws ItemStreamException { super.update(executionContext); if (saveState) { executionContext.putInt(getExecutionContextKey(RESOURCE_KEY), currentResource); delegate.update(executionContext); } }
@Test(expected = ItemStreamException.class) public void testOpenWithErrorInReader() { monitor.setItemReader(new ItemReader<String>() { @Override public String read() throws Exception, UnexpectedInputException, ParseException { throw new IllegalStateException("Expected"); } }); ExecutionContext executionContext = new ExecutionContext(); executionContext.putInt(ChunkMonitor.class.getName() + ".OFFSET", 2); monitor.open(executionContext); }
@Test public void testCurrentItemCountFromContext() throws Exception { reader.setCurrentItemCount(2); executionContext.putInt(reader.getClass().getSimpleName() + ".read.count", 3); reader.open(executionContext); // read some records assertEquals("testLine4", reader.read()); // close input reader.close(); }
@Test public void testOpen() { ExecutionContext executionContext = new ExecutionContext(); executionContext.putInt(ChunkMonitor.class.getName() + ".OFFSET", 2); monitor.open(executionContext); assertEquals(2, count); assertEquals(0, monitor.getOffset()); }
@Test public void testMaxItemCountFromContext() throws Exception { reader.setMaxItemCount(2); executionContext.putInt(reader.getClass().getSimpleName() + ".read.count.max", Integer.MAX_VALUE); reader.open(executionContext); // read some records reader.read(); reader.read(); assertNotNull(reader.read()); // close input reader.close(); }
@Test public void testReadToEndWithMax() throws Exception { ExecutionContext context = new ExecutionContext(); context.putInt("foo.read.count.max", 1); reader.open(context); reader.read(); assertNull(reader.read()); }
@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 testUpdateWithMax() throws Exception { ExecutionContext context = new ExecutionContext(); context.putInt("foo.read.count.max", 1); reader.open(context); reader.update(context); assertEquals(2, context.size()); }
@Test public void testReadAfterOpen() throws Exception { ExecutionContext executionContext = new ExecutionContext(); executionContext.putInt(reader.getExecutionContextKey("COUNT"), 1); reader.open(executionContext); assertNotNull(reader.read()); assertNull(reader.read()); }
@Test public void testReadAfterJumpSecondPage() throws Exception { executionContext.putInt(getName()+".read.count", 3); ((ItemStream)tested).open(executionContext); Foo foo5 = tested.read(); Assert.assertEquals(5, foo5.getValue()); Object o = tested.read(); Assert.assertNull(o); }
@Test public void testReadAfterJumpFirstPage() throws Exception { executionContext.putInt(getName()+".read.count", 2); ((ItemStream)tested).open(executionContext); Foo foo4 = tested.read(); Assert.assertEquals(4, foo4.getValue()); Foo foo5 = tested.read(); Assert.assertEquals(5, foo5.getValue()); Object o = tested.read(); Assert.assertNull(o); }