Package org.springframework.batch.core

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


        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

    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

  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

   * @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

    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

    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

  @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

   * later.
   *
   * @see ItemProcessor#process(Object)
   */
  public Future<O> process(final I item) throws Exception {
    final StepExecution stepExecution = getStepExecution();
    FutureTask<O> task = new FutureTask<O>(new Callable<O>() {
      public O call() throws Exception {
        if (stepExecution != null) {
          StepSynchronizationManager.register(stepExecution);
        }
View Full Code Here

  private StepExecution getStepExecution() {
    StepContext context = StepSynchronizationManager.getContext();
    if (context==null) {
      return null;
    }
    StepExecution stepExecution = context.getStepExecution();
    return stepExecution;
  }
View Full Code Here

TOP

Related Classes of org.springframework.batch.core.StepExecution

Copyright © 2018 www.massapicom. 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.