Package org.springframework.batch.repeat.support

Examples of org.springframework.batch.repeat.support.RepeatTemplate


    // ... so the interceptor after() is not called:
    assertEquals("[2, 1]", calls.toString());
  }

  public void testOpenInterceptors() throws Exception {
    RepeatTemplate template = new RepeatTemplate();
    final List<Object> calls = new ArrayList<Object>();
    template.setListeners(new RepeatListener[] { new RepeatListenerSupport() {
            @Override
      public void open(RepeatContext context) {
        calls.add("1");
      }
    }, new RepeatListenerSupport() {
            @Override
      public void open(RepeatContext context) {
        calls.add("2");
        context.setCompleteOnly();
      }
    } });
    template.iterate(new RepeatCallback() {
            @Override
      public RepeatStatus doInIteration(RepeatContext context) throws Exception {
        count++;
        return RepeatStatus.CONTINUABLE;
      }
View Full Code Here


    assertEquals(0, count);
    assertEquals("[1, 2]", calls.toString());
  }

  public void testSingleOpenInterceptor() throws Exception {
    RepeatTemplate template = new RepeatTemplate();
    final List<Object> calls = new ArrayList<Object>();
    template.registerListener(new RepeatListenerSupport() {
            @Override
      public void open(RepeatContext context) {
        calls.add("1");
      }
    });
    template.iterate(new RepeatCallback() {
            @Override
      public RepeatStatus doInIteration(RepeatContext context) throws Exception {
        count++;
        context.setCompleteOnly();
        return RepeatStatus.FINISHED;
View Full Code Here

    assertEquals(1, count);
    assertEquals("[1]", calls.toString());
  }

  public void testCloseInterceptors() throws Exception {
    RepeatTemplate template = new RepeatTemplate();
    final List<Object> calls = new ArrayList<Object>();
    template.setListeners(new RepeatListener[] { new RepeatListenerSupport() {
            @Override
      public void close(RepeatContext context) {
        calls.add("1");
      }
    }, new RepeatListenerSupport() {
            @Override
      public void close(RepeatContext context) {
        calls.add("2");
      }
    } });
    template.iterate(new RepeatCallback() {
            @Override
      public RepeatStatus doInIteration(RepeatContext context) throws Exception {
        count++;
        return RepeatStatus.continueIf(count < 2);
      }
View Full Code Here

    assertEquals("[2, 1]", calls.toString());
  }


  public void testOnErrorInterceptors() throws Exception {
    RepeatTemplate template = new RepeatTemplate();
    final List<Object> calls = new ArrayList<Object>();
    template.setListeners(new RepeatListener[] { new RepeatListenerSupport() {
            @Override
      public void onError(RepeatContext context, Throwable t) {
        calls.add("1");
      }
    }, new RepeatListenerSupport() {
            @Override
      public void onError(RepeatContext context, Throwable t) {
        calls.add("2");
      }
    } });
    try {
      template.iterate(new RepeatCallback() {
                @Override
        public RepeatStatus doInIteration(RepeatContext context) throws Exception {
          throw new IllegalStateException("Bogus");
        }
      });
View Full Code Here

    assertEquals(0, count);
    assertEquals("[2, 1]", calls.toString());
  }

  public void testOnErrorInterceptorsPrecedence() throws Exception {
    RepeatTemplate template = new RepeatTemplate();
    final List<Object> calls = new ArrayList<Object>();
    template.setListeners(new RepeatListener[] { new RepeatListenerSupport() {
            @Override
      public void after(RepeatContext context, RepeatStatus result) {
        calls.add("1");
      }
    }, new RepeatListenerSupport() {
            @Override
      public void onError(RepeatContext context, Throwable t) {
        calls.add("2");
      }
    } });
    try {
      template.iterate(new RepeatCallback() {
                @Override
        public RepeatStatus doInIteration(RepeatContext context) throws Exception {
          throw new IllegalStateException("Bogus");
        }
      });
View Full Code Here

  }

  private TaskletStep getStep(String[] strings, int commitInterval) throws Exception {
    TaskletStep step = new TaskletStep("stepName");
    // Only process one item:
    RepeatTemplate template = new RepeatTemplate();
    template.setCompletionPolicy(new SimpleCompletionPolicy(commitInterval));
    step.setTasklet(new TestingChunkOrientedTasklet<String>(getReader(strings), itemWriter, template));
    step.setJobRepository(new JobRepositorySupport());
    step.setTransactionManager(transactionManager);
    return step;
  }
View Full Code Here

  @Before
  public void setUp() throws Exception {

    transactionManager = new ResourcelessTransactionManager();

    RepeatTemplate template = new RepeatTemplate();
    template.setCompletionPolicy(new SimpleCompletionPolicy(1));

    step = getStep(new String[] { "foo", "bar", "spam" });
    step.setStepOperations(template);

    job = new JobSupport("FOO");
View Full Code Here

  public void testEmptyReader() throws Exception {
    JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
    StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
    step = getStep(new String[0]);
    step.setTasklet(new TestingChunkOrientedTasklet<String>(getReader(new String[0]), itemWriter,
        new RepeatTemplate()));
    step.setStepOperations(new RepeatTemplate());
    step.execute(stepExecution);
    assertEquals(0, processed.size());
    assertEquals(0, stepExecution.getReadCount());
    // Commit after end of data detected (this leads to the commit count
    // being one greater than people expect if the commit interval is
View Full Code Here

  public void testStepExecutionUpdates() throws Exception {

    JobExecution jobExecution = new JobExecution(jobInstance, jobParameters);
    StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);

    step.setStepOperations(new RepeatTemplate());

    JobRepositoryStub jobRepository = new JobRepositoryStub();
    step.setJobRepository(jobRepository);

    step.execute(stepExecution);
View Full Code Here

        list.add("afterStepCalled");
        return customStatus;
      }
    } });

    RepeatTemplate stepTemplate = new RepeatTemplate();
    stepTemplate.setCompletionPolicy(new SimpleCompletionPolicy(5));
    step.setStepOperations(stepTemplate);

    JobExecution jobExecution = new JobExecution(jobInstance, jobParameters);
    StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
    step.execute(stepExecution);
View Full Code Here

TOP

Related Classes of org.springframework.batch.repeat.support.RepeatTemplate

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.