/** * Typesafe Getter for the Integer represented by the provided key with * default value to return if key is not represented. * * @param key The key to get a value for * @param defaultInt Default to return if key is not represented * @return The <code>int</code> value if key is represented, specified * default otherwise */ public int getInt(String key, int defaultInt) { if (!containsKey(key)) { return defaultInt; } return getInt(key); }
@Override public void open(ExecutionContext executionContext) throws ItemStreamException { super.open(executionContext); counter.set(executionContext.getInt(getExecutionContextKey("COUNT"), 0)); }
public void open(ExecutionContext executionContext) throws ItemStreamException { if (executionContext.containsKey(EXPECTED)) { localState.open(executionContext.getInt(EXPECTED), executionContext.getInt(ACTUAL)); if (!waitForResults()) { throw new ItemStreamException("Timed out waiting for back log on open"); } } }
@Override public void open(ExecutionContext executionContext) throws ItemStreamException { if(executionContext.containsKey(CURRENT_INDEX)){ currentIndex = executionContext.getInt(CURRENT_INDEX); } else{ currentIndex = 0; } }
private int extractRecordCount() { return executionContext.getInt(ClassUtils.getShortName(StaxEventItemReader.class) + ".read.count"); }
public void update(ExecutionContext executionContext) { if (!executionContext.containsKey(UPDATE_COUNT_KEY)) { executionContext.putInt(UPDATE_COUNT_KEY, 0); } executionContext.putInt(UPDATE_COUNT_KEY, executionContext.getInt(UPDATE_COUNT_KEY) + 1); }
public void update(ExecutionContext executionContext) { if (!executionContext.containsKey(UPDATE_COUNT_KEY)) { executionContext.putInt(UPDATE_COUNT_KEY, 0); } executionContext.putInt(UPDATE_COUNT_KEY , executionContext.getInt(UPDATE_COUNT_KEY) + 1 ); }
@Test public void testUpdateAndOpenWithState() throws Exception { ExecutionContext executionContext = new ExecutionContext(); writer.update(executionContext); writer.open(executionContext); assertEquals(0, executionContext.getInt(ChunkMessageChannelItemWriter.EXPECTED)); assertEquals(0, executionContext.getInt(ChunkMessageChannelItemWriter.ACTUAL)); }
@Test public void testUpdateAfterDelegateClose() throws Exception { super.setUp(delegate); tested.open(executionContext); tested.update(executionContext); assertEquals(0, executionContext.getInt(tested.getExecutionContextKey("resource.item.count"))); assertEquals(1, executionContext.getInt(tested.getExecutionContextKey("resource.index"))); tested.write(Arrays.asList("1", "2", "3")); tested.update(executionContext); assertEquals(0, executionContext.getInt(tested.getExecutionContextKey("resource.item.count"))); assertEquals(2, executionContext.getInt(tested.getExecutionContextKey("resource.index"))); }
@Test public void testUpdateAfterDelegateClose() throws Exception { this.writer = new MultiResourceItemWriterBuilder<String>().delegate(this.delegate) .resource(new FileSystemResource(this.file)).resourceSuffixCreator(this.suffixCreator) .itemCountLimitPerResource(2).saveState(true).name("foo").build(); this.writer.update(this.executionContext); assertEquals(0, this.executionContext.getInt(this.writer.getExecutionContextKey("resource.item.count"))); assertEquals(1, this.executionContext.getInt(this.writer.getExecutionContextKey("resource.index"))); this.writer.write(Arrays.asList("1", "2", "3")); this.writer.update(this.executionContext); assertEquals(0, this.executionContext.getInt(this.writer.getExecutionContextKey("resource.item.count"))); assertEquals(2, this.executionContext.getInt(this.writer.getExecutionContextKey("resource.index"))); }
@Test public void testSetName() throws Exception { reader.setName("bar"); reader.read(); ExecutionContext context = new ExecutionContext(); reader.update(context); assertEquals(1, context.getInt("bar.read.count")); }
@Test public void testReadAndUpdate() throws Exception { ExecutionContext executionContext = new ExecutionContext(); assertNotNull(reader.read()); reader.update(executionContext); assertEquals(1, executionContext.getInt(reader.getExecutionContextKey("COUNT"))); }
/** * Save restart data and restore from it. */ @Test public void testRestart() throws Exception { source.open(executionContext); source.read(); source.update(executionContext); assertEquals(1, executionContext.getInt(ClassUtils.getShortName(StaxEventItemReader.class) + ".read.count")); List<XMLEvent> expectedAfterRestart = source.read(); source = createNewInputSource(); source.open(executionContext); List<XMLEvent> afterRestart = source.read(); assertEquals(expectedAfterRestart.size(), afterRestart.size()); }
@Test public void testUpdate() throws Exception { reader.read(); ExecutionContext context = new ExecutionContext(); reader.update(context); assertEquals(1, context.size()); assertEquals(1, context.getInt("foo.read.count")); }
@Test public void testCurrentItemCount() throws Exception { reader.setCurrentItemCount(2); reader.open(executionContext); // read some records reader.read(); reader.read(); // get restart data reader.update(executionContext); assertEquals(4, executionContext.getInt(ClassUtils.getShortName(FlatFileItemReader.class) + ".read.count")); // close input reader.close(); }
@Test public void testSaveState() throws Exception { this.ldifReader = new LdifReaderBuilder().resource(context.getResource("classpath:/test.ldif")).name("foo").build(); ExecutionContext executionContext = new ExecutionContext(); firstRead(executionContext); this.ldifReader.update(executionContext); assertEquals("foo.read.count did not have the expected result", 1, executionContext.getInt("foo.read.count")); }
@Test public void testMaxItemCount() throws Exception { reader.setMaxItemCount(2); reader.open(executionContext); // read some records reader.read(); reader.read(); // get restart data reader.update(executionContext); assertNull(reader.read()); assertEquals(2, executionContext.getInt(ClassUtils.getShortName(FlatFileItemReader.class) + ".read.count")); // close input reader.close(); }
@Test public void testSaveState() throws Exception { this.mappingLdifReader = new MappingLdifReaderBuilder<LdapAttributes>() .recordMapper(new TestMapper()) .resource(context.getResource("classpath:/test.ldif")) .name("foo") .build(); ExecutionContext executionContext = new ExecutionContext(); firstRead(executionContext); this.mappingLdifReader.update(executionContext); assertEquals("foo.read.count did not have the expected result", 1, executionContext.getInt("foo.read.count")); }
@Test public void testNormalUsage() { context.putString("1", "testString1"); context.putString("2", "testString2"); context.putLong("3", 3); context.putDouble("4", 4.4); context.putInt("5", 5); assertEquals("testString1", context.getString("1")); assertEquals("testString2", context.getString("2")); assertEquals("defaultString", context.getString("55", "defaultString")); assertEquals(4.4, context.getDouble("4"), 0); assertEquals(5.5, context.getDouble("55", 5.5), 0); assertEquals(3, context.getLong("3")); assertEquals(5, context.getLong("55", 5)); assertEquals(5, context.getInt("5")); assertEquals(6, context.getInt("55", 6)); }
/** * Test restart at end of file. */ @Test public void testRestartAtEndOfFile() throws Exception { source.open(executionContext); assertNotNull(source.read()); assertNotNull(source.read()); assertNull(source.read()); source.update(executionContext); source.close(); assertEquals(3, executionContext.getInt(ClassUtils.getShortName(StaxEventItemReader.class) + ".read.count")); source = createNewInputSource(); source.open(executionContext); assertNull(source.read()); }