@SuppressWarnings("unchecked") @Nullable public static <T> T getValueFromJob(JobExecution jobExecution, String key) { return (T) jobExecution.getExecutionContext().get(key); }
@Override public void open(ExecutionContext executionContext) { if (executionContext.containsKey(TOTAL_AMOUNT_KEY)) { this.totalPrice = (BigDecimal) executionContext.get(TOTAL_AMOUNT_KEY); } else { // // Fresh run. Disregard old state. // this.totalPrice = BigDecimal.ZERO; } }
@SuppressWarnings("unchecked") @Nullable public static <T> T getValueFromStep(StepExecution stepExecution, String key) { return (T) stepExecution.getExecutionContext().get(key); }
protected boolean isFlowContinued(State state, FlowExecutionStatus status, StepExecution stepExecution) { boolean continued = true; continued = state != null && status!=FlowExecutionStatus.STOPPED; if(stepExecution != null) { Boolean reRun = (Boolean) stepExecution.getExecutionContext().get("batch.restart"); Boolean executed = (Boolean) stepExecution.getExecutionContext().get("batch.executed"); if((executed == null || !executed) && reRun != null && reRun && status == FlowExecutionStatus.STOPPED && !state.getName().endsWith(stepExecution.getStepName()) ) { continued = true; } } return continued; }
@Override public Serializable getPersistentUserData() { return (Serializable) stepExecution.getExecutionContext().get(executionContextUserSupport.getKey(PERSISTENT_USER_DATA_KEY)); }
@Override public Serializable getPersistentUserData() { return (Serializable) stepExecution.getExecutionContext().get(executionContextUserSupport.getKey(PERSISTENT_USER_DATA_KEY)); }
@Override @SuppressWarnings("unchecked") public void open(ExecutionContext executionContext) { if (isSaveState()) { startAfterValues = (Map<String, Object>) executionContext.get(getExecutionContextKey(START_AFTER_VALUE)); if(startAfterValues == null) { startAfterValues = new LinkedHashMap<>(); } } super.open(executionContext); }
@Override public void open(ExecutionContext executionContext) throws ItemStreamException { try { String executionContextKey = getExecutionContextKey(checkpointKey); Serializable checkpoint = (Serializable) executionContext.get(executionContextKey); doOpen(checkpoint); } catch (Exception e) { throw new ItemStreamException(e); } }
@Test(expected=ItemStreamException.class) public void testOpenException() throws Exception { when(executionContext.get("jsrWriter.writer.checkpoint")).thenReturn("checkpoint"); doThrow(new Exception("expected")).when(delegate).open("checkpoint"); adapter.open(executionContext); }
@Test(expected=ItemStreamException.class) public void testOpenException() throws Exception { when(executionContext.get("jsrReader.reader.checkpoint")).thenReturn("checkpoint"); doThrow(new Exception("expected")).when(delegate).open("checkpoint"); adapter.open(executionContext); }
@Test public void testOpen() throws Exception { when(executionContext.get("jsrReader.reader.checkpoint")).thenReturn("checkpoint"); adapter.open(executionContext); verify(delegate).open("checkpoint"); }
@Test public void testOpen() throws Exception { when(executionContext.get("jsrWriter.writer.checkpoint")).thenReturn("checkpoint"); adapter.open(executionContext); verify(delegate).open("checkpoint"); }
@Test public void testGetNull() { assertNull(context.get("does not exist")); }
@Test public void testBeforeStep() { listener.beforeStep(stepExecution); assertEquals("bar", stepExecution.getExecutionContext().get("foo")); }
private void validateLaunchWithoutSkips(JobExecution jobExecution) { // Step1: 5 input records => 5 written to output assertEquals(5, JdbcTestUtils.countRowsInTable((JdbcTemplate) jdbcTemplate, "TRADE")); // Step2: 5 input records => 5 written to output assertEquals(5, jdbcTemplate.queryForObject("SELECT COUNT(*) from TRADE where VERSION=?", Integer.class, 1).intValue()); // Neither step contained skips assertEquals(0, JdbcTestUtils.countRowsInTable((JdbcTemplate) jdbcTemplate, "ERROR_LOG")); assertEquals(new BigDecimal("270.75"), jobExecution.getExecutionContext().get(TradeWriter.TOTAL_AMOUNT_KEY)); }
/** * Putting null value is equivalent to removing the entry for the given key. */ @Test public void testPutNull() { context.put("1", null); assertNull(context.get("1")); assertFalse(context.containsKey("1")); }
@Test public void testDefaultHandlerStep() throws Exception { assertNotNull(job1); JobExecution jobExecution = jobRepository.createJobExecution(job1.getName(), new JobParameters()); job1.execute(jobExecution); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); Collections.sort(savedStepNames); assertEquals("[step1:partition0, step1:partition1]", savedStepNames.toString()); List<String> stepNames = getStepNames(jobExecution); assertEquals(3, stepNames.size()); assertEquals("[s1, step1:partition0, step1:partition1]", stepNames.toString()); assertEquals("bar", jobExecution.getExecutionContext().get("foo")); }
@Override public void beforeStep(StepExecution stepExecution) { this.jobName = stepExecution.getJobExecution().getJobInstance().getJobName().trim(); this.stepName = (String) stepExecution.getJobExecution().getExecutionContext().get("stepName"); this.stepExecution = stepExecution; stepExecution.getJobExecution().getExecutionContext().remove("stepName"); }
@Test public void testPersistentUserData() { String data = "saved data"; stepContext.setPersistentUserData(data); assertEquals(data, stepContext.getPersistentUserData()); assertEquals(data, executionContext.get(executionContextUserSupport.getKey("batch_jsr_persistentUserData"))); }
@Test public void testSaveUpdate() throws Exception { StepExecution stepExecution = new StepExecution("step", new JobExecution(11L)); stepExecution.setId(123L); stepExecution.getExecutionContext().put("foo", "bar"); dao.saveExecutionContext(stepExecution); ExecutionContext executionContext = dao.getExecutionContext(stepExecution); assertEquals("bar", executionContext.get("foo")); }