Package org.springframework.batch.repeat

Examples of org.springframework.batch.repeat.RepeatStatus


        // Before starting a new transaction, check for
        // interruption.
        interruptionPolicy.checkInterrupted(stepExecution);

        RepeatStatus result;
        try {
          result = new TransactionTemplate(transactionManager, transactionAttribute)
          .execute(new ChunkTransactionCallback(chunkContext, semaphore));
        }
        catch (UncheckedTransactionException e) {
View Full Code Here


    @Override
    public RepeatStatus doInTransaction(TransactionStatus status) {
      TransactionSynchronizationManager.registerSynchronization(this);

      RepeatStatus result = RepeatStatus.CONTINUABLE;

      StepContribution contribution = stepExecution.createStepContribution();

      chunkListener.beforeChunk(chunkContext);
View Full Code Here

   * @throws Exception
   */
  @Test
  public void testEarlyCompletionWithContext() throws Exception {

    RepeatStatus result = template.iterate(new ItemReaderRepeatCallback<Trade>(provider, processor) {

            @Override
      public RepeatStatus doInIteration(RepeatContext context) throws Exception {
        RepeatStatus result = super.doInIteration(context);
        if (processor.count >= 2) {
          context.setCompleteOnly();
          // If we return null the batch will terminate anyway
          // without an exception...
        }
        return result;
      }
    });

    // 2 items were processed before completion signalled
    assertEquals(2, processor.count);

    // Not all items processed
    assertTrue(result.isContinuable());

  }
View Full Code Here

   * @throws Exception
   */
  @Test
  public void testEarlyCompletionWithContextTerminated() throws Exception {

    RepeatStatus result = template.iterate(new ItemReaderRepeatCallback<Trade>(provider, processor) {

            @Override
      public RepeatStatus doInIteration(RepeatContext context) throws Exception {
        RepeatStatus result = super.doInIteration(context);
        if (processor.count >= 2) {
          context.setTerminateOnly();
          // If we return null the batch will terminate anyway
          // without an exception...
        }
        return result;
      }
    });

    // 2 items were processed before completion signalled
    assertEquals(2, processor.count);

    // Not all items processed
    assertTrue(result.isContinuable());

  }
View Full Code Here

   * Test that a result is returned from the batch.
   * @throws Exception
   */
  @Test
  public void testResult() throws Exception {
    RepeatStatus result = template.iterate(new ItemReaderRepeatCallback<Trade>(provider, processor));
    assertEquals(NUMBER_OF_ITEMS, processor.count);
    // We are complete - do not expect to be called again
    assertFalse(result.isContinuable());
  }
View Full Code Here

  @Test
  public void testEarlyCompletionWithSessionAndException() throws Exception {

    template.setCompletionPolicy(new SimpleCompletionPolicy(4));

    RepeatStatus result = RepeatStatus.FINISHED;

    try {
      result = template.iterate(new ItemReaderRepeatCallback<Trade>(provider, processor) {

                @Override
        public RepeatStatus doInIteration(RepeatContext context) throws Exception {
          RepeatStatus result = super.doInIteration(context);
          if (processor.count >= 2) {
            context.setCompleteOnly();
            throw new RuntimeException("Barf second try count=" + processor.count);
          }
          return result;
        }
      });
      fail("Expected exception on last item in batch");
    }
    catch (RuntimeException e) {
      // expected
      assertEquals("Barf second try count=2", e.getMessage());
    }

    // 2 items were processed before completion signalled
    assertEquals(2, processor.count);

    System.err.println(result);

    // An exception was thrown by the template so result is still false
    assertFalse(result.isContinuable());

  }
View Full Code Here

    final RepeatTemplate chunkTemplate = new RepeatTemplate();
    // The policy is resettable so we only have to resolve this dependency
    // once
    chunkTemplate.setCompletionPolicy(new SimpleCompletionPolicy(2));

    RepeatStatus result = repeatTemplate.iterate(new NestedRepeatCallback(chunkTemplate, callback) {

            @Override
      public RepeatStatus doInIteration(RepeatContext context) throws Exception {
        count++; // for test assertion
        return super.doInIteration(context);
      }

    });

    assertEquals(NUMBER_OF_ITEMS, processor.count);
    // The chunk executes 3 times because the last one
    // returns false. We terminate the main batch when
    // we encounter a partially empty chunk.
    assertEquals(3, count);
    assertFalse(result.isContinuable());

  }
View Full Code Here

    // The policy is resettable so we only have to resolve this dependency
    // once
    chunkTemplate.setCompletionPolicy(new SimpleCompletionPolicy(2));
    chunkTemplate.setTaskExecutor(new SimpleAsyncTaskExecutor());

    RepeatStatus result = repeatTemplate.iterate(new NestedRepeatCallback(chunkTemplate, callback) {

            @Override
      public RepeatStatus doInIteration(RepeatContext context) throws Exception {
        count++; // for test assertion
        return super.doInIteration(context);
      }

    });

    assertEquals(NUMBER_OF_ITEMS, processor.count);
    assertFalse(result.isContinuable());
    assertTrue("Expected at least 3 chunks but found: "+count, count>=3);

  }
View Full Code Here

      chunker.reset();
      template.iterate(new ItemReaderRepeatCallback<Trade>(truncated, processor) {

                @Override
        public RepeatStatus doInIteration(RepeatContext context) throws Exception {
          RepeatStatus result = super.doInIteration(context);
          if (!result.isContinuable() && chunker.first()) {
            chunker.set();
          }
          chunker.increment();
          return result;
        }
View Full Code Here

   *
   */
  private static class ResultHolderComparator implements Comparator<ResultHolder> {
        @Override
    public int compare(ResultHolder h1, ResultHolder h2) {
      RepeatStatus result1 = h1.getResult();
      RepeatStatus result2 = h2.getResult();
      if (result1 == null && result2 == null) {
        return 0;
      }
      if (result1 == null) {
        return -1;
      }
      else if (result2 == null) {
        return 1;
      }
      if ((result1.isContinuable() && result2.isContinuable())
          || (!result1.isContinuable() && !result2.isContinuable())) {
        return 0;
      }
      if (result1.isContinuable()) {
        return -1;
      }
View Full Code Here

TOP

Related Classes of org.springframework.batch.repeat.RepeatStatus

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.