Examples of StepExecution


Examples of org.springframework.batch.core.StepExecution

    @Test
    public void testExecute() throws JobInterruptedException {
        Step step = createTestStep("testExecute");
        JobExecution jobData = TestDummyJobRepository.createJobExecutionInstance(step.getName());
        StepExecution stepData = new StepExecution(step.getName(), jobData);
        step.execute(stepData);
        assertOperationDetails(getLastEntered(), "execute", step.getName());
    }
View Full Code Here

Examples of org.springframework.batch.core.StepExecution

        return createFlowExecutor(createStepExecution(jobName, stepName));
    }

    protected StepExecution createStepExecution(String jobName, String stepName) {
        JobExecution jobExecution = createJobExecution(jobName);
        StepExecution stepExecution = Mockito.mock(StepExecution.class);
        Mockito.when(stepExecution.getStepName()).thenReturn(stepName);
        Mockito.when(stepExecution.getJobExecution()).thenReturn(jobExecution);
        return stepExecution;
    }
View Full Code Here

Examples of org.springframework.batch.core.StepExecution

            public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
                return RepeatStatus.FINISHED;
            }
        };
        StepContribution contribution = Mockito.mock(StepContribution.class);
        StepExecution stepExecution = createStepExecution("testExecuteJob", "testExecuteStep");
        StepContext stepContext = Mockito.mock(StepContext.class);
        Mockito.when(stepContext.getStepExecution()).thenReturn(stepExecution);

        ChunkContext chunkContext = Mockito.mock(ChunkContext.class);
        Mockito.when(chunkContext.getStepContext()).thenReturn(stepContext);
        tasklet.execute(contribution, chunkContext);

        Operation op = assertOperationDetails(getFirstEntered(), "execute", stepExecution.getStepName());
        assertOperationPath(op, stepExecution);
    }
View Full Code Here

Examples of org.springframework.batch.core.StepExecution

        assertOperationPath(op, null, stepName);
    }

    @Test
    public void testAbandonStepExecution() {
        StepExecution stepExec = createStepExecution("testAbandonJobExecution", "testAbandonStepExecution");
        FlowExecutor executor = createFlowExecutor(stepExec);
        executor.abandonStepExecution();

        Operation op = assertOperationDetails(getFirstEntered(), "abandonStepExecution", stepExec.getStepName());
        assertOperationPath(op, stepExec);
    }
View Full Code Here

Examples of org.springframework.batch.core.StepExecution

    this.jdbcTemplate = new JdbcTemplate(dataSource);
  }

  @Before
  public void onSetUpBeforeTransaction() throws Exception {
    StepExecution stepExecution = new StepExecution("stepName", new JobExecution(new JobInstance(12L,
        "testJob"), new JobParameters()));
    writer.beforeStep(stepExecution);
  }
View Full Code Here

Examples of org.springframework.batch.core.StepExecution

  public static <T> T getValueFromJob(JobExecution jobExecution, String key) {
    return (T) jobExecution.getExecutionContext().get(key);
  }

  public static <T> T getValueFromStepInJob(JobExecution jobExecution, String stepName, String key) {
    StepExecution stepExecution = null;
    List<String> stepNames = new ArrayList<String>();
    for (StepExecution candidate : jobExecution.getStepExecutions()) {
      String name = candidate.getStepName();
      stepNames.add(name);
      if (name.equals(stepName)) {
        stepExecution = candidate;
      }
    }
    if (stepExecution == null) {
      throw new IllegalArgumentException("No such step in this job execution: " + stepName + " not in "
          + stepNames);
    }
    @SuppressWarnings("unchecked")
    T result = (T) stepExecution.getExecutionContext().get(key);
    return result;
  }
View Full Code Here

Examples of org.springframework.batch.core.StepExecution

   * @throws Exception if there is a problem
   * @see TestExecutionListener#prepareTestInstance(TestContext)
   */
  @Override
  public void prepareTestInstance(TestContext testContext) throws Exception {
    StepExecution stepExecution = getStepExecution(testContext);

    if (stepExecution != null) {
      Method method = TestContext.class.getMethod(SET_ATTRIBUTE_METHOD_NAME, String.class, Object.class);
      ReflectionUtils.invokeMethod(method, testContext, STEP_EXECUTION, stepExecution);
    }
View Full Code Here

Examples of org.springframework.batch.core.StepExecution

    this.jdbcTemplate = new JdbcTemplate(dataSource);
  }

  @BeforeTransaction
  public void onSetUpBeforeTransaction() throws Exception {
    StepExecution stepExecution = new StepExecution("stepName", new JobExecution(new JobInstance(jobId,
        "testJob"), new JobParameters()));
    writer.beforeStep(stepExecution);
    writer.write(Arrays.asList("FOO", "BAR", "SPAM", "BUCKET"));
    reader.beforeStep(stepExecution);
  }
View Full Code Here

Examples of org.springframework.batch.core.StepExecution

    Method hasAttributeMethod = TestContext.class.getMethod(HAS_ATTRIBUTE_METHOD_NAME, String.class);
    Boolean hasAttribute = (Boolean) ReflectionUtils.invokeMethod(hasAttributeMethod, testContext, STEP_EXECUTION);

    if (hasAttribute) {
      Method method = TestContext.class.getMethod(GET_ATTRIBUTE_METHOD_NAME, String.class);
      StepExecution stepExecution = (StepExecution) ReflectionUtils.invokeMethod(method, testContext, STEP_EXECUTION);

      StepSynchronizationManager.register(stepExecution);
    }
  }
View Full Code Here

Examples of org.springframework.batch.core.StepExecution

  @ServiceActivator
  public StepExecution handle(StepExecutionRequest request) {

    Long jobExecutionId = request.getJobExecutionId();
    Long stepExecutionId = request.getStepExecutionId();
    StepExecution stepExecution = jobExplorer.getStepExecution(jobExecutionId, stepExecutionId);
    if (stepExecution == null) {
      throw new NoSuchStepException("No StepExecution could be located for this request: " + request);
    }

    String stepName = request.getStepName();
    Step step = stepLocator.getStep(stepName);
    if (step == null) {
      throw new NoSuchStepException(String.format("No Step with name [%s] could be located.", stepName));
    }

    try {
      step.execute(stepExecution);
    }
    catch (JobInterruptedException e) {
      stepExecution.setStatus(BatchStatus.STOPPED);
      // The receiver should update the stepExecution in repository
    }
    catch (Throwable e) {
      stepExecution.addFailureException(e);
      stepExecution.setStatus(BatchStatus.FAILED);
      // The receiver should update the stepExecution in repository
    }

    return stepExecution;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.