public void open(ExecutionContext executionContext) throws ItemStreamException { index = (int) executionContext.getLong("POSITION", 0); }
/** * Typesafe Getter for the Long 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 defaultLong Default to return if key is not represented * @return The <code>long</code> value if key is represented, specified * default otherwise */ public long getLong(String key, long defaultLong) { if (!containsKey(key)) { return defaultLong; } return getLong(key); }
@Override public void open(ExecutionContext executionContext) throws ItemStreamException { super.open(executionContext); index = (int) executionContext.getLong(getExecutionContextKey("POSITION"), min); }
int splitSize = (int) context.getLong(key, gridSize); context.putLong(key, splitSize);
key = key.replace("(long)", ""); if (executionContext.containsKey(key)) { builder.addLong(key, executionContext.getLong(key));
@Transactional @Test public void testUpdateStepContext() { ExecutionContext ctx = new ExecutionContext(Collections.<String, Object> singletonMap("key", "value")); stepExecution.setExecutionContext(ctx); contextDao.saveExecutionContext(stepExecution); ctx.putLong("longKey", 7); contextDao.updateExecutionContext(stepExecution); ExecutionContext retrieved = contextDao.getExecutionContext(stepExecution); assertEquals(ctx, retrieved); assertEquals(7, retrieved.getLong("longKey")); }
startAtPosition = executionContext.getLong(getExecutionContextKey(RESTART_DATA_NAME)); currentRecordCount = executionContext.getLong(getExecutionContextKey(WRITE_STATISTICS_NAME)); if (executionContext.containsKey(getExecutionContextKey(UNCLOSED_HEADER_CALLBACK_ELEMENTS_NAME))) { unclosedHeaderCallbackElements = (List<QName>) executionContext
@Transactional @Test public void testUpdateContext() { ExecutionContext ctx = new ExecutionContext(Collections .<String, Object> singletonMap("key", "value")); jobExecution.setExecutionContext(ctx); contextDao.saveExecutionContext(jobExecution); ctx.putLong("longKey", 7); contextDao.updateExecutionContext(jobExecution); ExecutionContext retrieved = contextDao.getExecutionContext(jobExecution); assertEquals(ctx, retrieved); assertEquals(7, retrieved.getLong("longKey")); }
@Test public void testRestart() throws Exception { this.writer.open(this.executionContext); // write some lines this.writer.write(Collections.singletonList(this.trade1)); // get restart data this.writer.update(this.executionContext); // close template this.writer.close(); // init with correct data this.writer.open(this.executionContext); // write more lines this.writer.write(Collections.singletonList(this.trade2)); // get statistics this.writer.update(this.executionContext); // close template this.writer.close(); // verify what was written to the file assertFileEquals( new File(EXPECTED_FILE_DIRECTORY+ "expected-trades.json"), this.resource.getFile()); // 2 lines were written to the file in total assertEquals(2, this.executionContext.getLong("tradesItemWriter.written")); }
assertEquals(2, this.executionContext.getLong("tradesItemWriter.written"));
@Test public void testDefaultStreamContext() throws Exception { writer = new FlatFileItemWriter<>(); writer.setResource(new FileSystemResource(outputFile)); writer.setLineAggregator(new PassThroughLineAggregator<>()); writer.afterPropertiesSet(); writer.setSaveState(true); writer.open(executionContext); writer.update(executionContext); assertNotNull(executionContext); assertEquals(2, executionContext.entrySet().size()); assertEquals(0, executionContext.getLong(ClassUtils.getShortName(FlatFileItemWriter.class) + ".current.count")); }
assertEquals(8, executionContext.getLong(ClassUtils.getShortName(FlatFileItemWriter.class) + ".written"));
assertEquals(8, executionContext.getLong(ClassUtils.getShortName(FlatFileItemWriter.class) + ".written"));
/** * Count of 'records written so far' is returned as statistics. */ @Test public void testStreamContext() throws Exception { writer.open(executionContext); final int NUMBER_OF_RECORDS = 10; assertFalse(executionContext.containsKey(ClassUtils.getShortName(StaxEventItemWriter.class) + ".record.count")); for (int i = 1; i <= NUMBER_OF_RECORDS; i++) { writer.write(items); writer.update(executionContext); long writeStatistics = executionContext.getLong(ClassUtils.getShortName(StaxEventItemWriter.class) + ".record.count"); assertEquals(i, writeStatistics); } }
assertEquals(8, executionContext.getLong(ClassUtils.getShortName(FlatFileItemWriter.class) + ".written"));
@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)); }
/** * STEP参数取得 * * @param exitStatus */ public long getLongStepParameter(String key) { return this.getExecutionContext().getLong(key); }
/** * STEP参数取得 * * @param exitStatus */ public long getLongStepParameter(String key) { return this.stepExecution.getJobExecution().getExecutionContext().getLong(key); }
@BeforeStep void beforeChunk(StepExecution execution) { ExecutionContext jobExecutionContext = execution.getJobExecution().getExecutionContext(); lastTimestamp = jobExecutionContext.getLong(BWMetaImporterConstants.HBASE_LAST_TIMESTAMP, 0l); }
synchronized private void modifyCounter(String metricName, Long value) { StepExecution stepExecution = getStepExecution(); Long oldValue = 0L; if (stepExecution.getExecutionContext().containsKey(metricName)) { oldValue = stepExecution.getExecutionContext().getLong(metricName); } stepExecution.getExecutionContext().put(metricName, oldValue + value); }