Tabnine Logo
RepeatTemplate.setCompletionPolicy
Code IndexAdd Tabnine to your IDE (free)

How to use
setCompletionPolicy
method
in
org.springframework.batch.repeat.support.RepeatTemplate

Best Java code snippets using org.springframework.batch.repeat.support.RepeatTemplate.setCompletionPolicy (Showing top 20 results out of 315)

origin: spring-projects/spring-batch

protected RepeatOperations createChunkOperations() {
  RepeatOperations repeatOperations = chunkOperations;
  if (repeatOperations == null) {
    RepeatTemplate repeatTemplate = new RepeatTemplate();
    repeatTemplate.setCompletionPolicy(getChunkCompletionPolicy());
    repeatOperations = repeatTemplate;
  }
  return repeatOperations;
}
origin: spring-projects/spring-batch

  private RepeatOperations createRepeatOperations() {
    RepeatTemplate repeatOperations = new RepeatTemplate();
    repeatOperations.setCompletionPolicy(getChunkCompletionPolicy());
    repeatOperations.setExceptionHandler(getExceptionHandler());
    return repeatOperations;
  }
}
origin: spring-projects/spring-batch

public RepeatTemplate getRepeatTemplate() {
  template = new RepeatTemplate();
  // default stop after more items than exist in dataset
  template.setCompletionPolicy(new SimpleCompletionPolicy(8));
  return template;
}
origin: spring-projects/spring-batch

@Test
public void testReceiveAndExecuteWithCallbackReturningNull() throws Exception {
  RepeatTemplate template = new RepeatTemplate();
  template.setCompletionPolicy(new SimpleCompletionPolicy(2));
  container = getContainer(template);
  Session session = mock(Session.class);
  MessageConsumer consumer = mock(MessageConsumer.class);
  Message message = null;
  // Expect one call to consumer (chunk size is 2 but terminates on
  // first)...
  when(consumer.receive(1000)).thenReturn(message);
  when(session.getTransacted()).thenReturn(false);
  boolean received = doExecute(session, consumer);
  assertFalse("Message not received", received);
}
origin: spring-projects/spring-batch

@Test
public void testReceiveAndExecuteWithCallback() throws Exception {
  RepeatTemplate template = new RepeatTemplate();
  template.setCompletionPolicy(new SimpleCompletionPolicy(2));
  container = getContainer(template);
  container.setMessageListener(new MessageListener() {
    @Override
    public void onMessage(Message arg0) {
    }
  });
  Session session = mock(Session.class);
  MessageConsumer consumer = mock(MessageConsumer.class);
  Message message = mock(Message.class);
  // Expect two calls to consumer (chunk size)...
  when(session.getTransacted()).thenReturn(true);
  when(session.getTransacted()).thenReturn(true);
  when(consumer.receive(1000)).thenReturn(message);
  boolean received = doExecute(session, consumer);
  assertTrue("Message not received", received);
}
origin: spring-projects/spring-batch

@Test
public void testExceptionThrownOnLastItem() throws Exception {
  template.setCompletionPolicy(new SimpleCompletionPolicy(2));
  try {
    template.iterate(new RepeatCallback() {
      @Override
      public RepeatStatus doInIteration(RepeatContext context) throws Exception {
        count++;
        if (count < 2) {
          return RepeatStatus.CONTINUABLE;
        }
        throw new RuntimeException("Barf second try count=" + count);
      }
    });
    fail("Expected exception on last item in batch");
  }
  catch (Exception e) {
    // expected
    assertEquals("Barf second try count=2", e.getMessage());
  }
}
origin: spring-projects/spring-batch

/**
 * Check that a dedicated TerminationPolicy can terminate the batch.
 * 
 * @throws Exception
 */
@Test
public void testEarlyCompletionWithPolicy() throws Exception {
  template.setCompletionPolicy(new SimpleCompletionPolicy(2));
  template.iterate(new ItemReaderRepeatCallback<>(provider, processor));
  assertEquals(2, processor.count);
}
origin: spring-projects/spring-batch

@Test
public void testNonTransactionalReceiveAndExecuteWithCallbackThrowingException() throws Exception {
  RepeatTemplate template = new RepeatTemplate();
  template.setCompletionPolicy(new SimpleCompletionPolicy(2));
  container = getContainer(template);
  container.setSessionTransacted(false);
  boolean received = doTestWithException(new IllegalStateException("No way!"), false, 2);
  assertTrue("Message not received but listener not transactional so this should be true", received);
}
origin: spring-projects/spring-batch

@Test
public void testTransactionalReceiveAndExecuteWithCallbackThrowingException() throws Exception {
  RepeatTemplate template = new RepeatTemplate();
  template.setCompletionPolicy(new SimpleCompletionPolicy(2));
  container = getContainer(template);
  container.setSessionTransacted(true);
  try {
    boolean received = doTestWithException(new IllegalStateException("No way!"), true, 2);
    assertFalse("Message received", received);
    fail("Expected IllegalStateException");
  } catch (IllegalStateException e) {
    assertEquals("No way!", e.getMessage());
  }
}
origin: spring-projects/spring-batch

public void testInterceptorChainWithRetry() throws Exception {
  ((Advised) service).addAdvice(interceptor);
  final List<Object> list = new ArrayList<>();
  ((Advised) service).addAdvice(new MethodInterceptor() {
    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
      list.add("chain");
      return invocation.proceed();
    }
  });
  RepeatTemplate template = new RepeatTemplate();
  template.setCompletionPolicy(new SimpleCompletionPolicy(2));
  interceptor.setRepeatOperations(template);
  service.service();
  assertEquals(2, target.count);
  assertEquals(2, list.size());
}
origin: spring-projects/spring-batch

@Test
public void testNonTransactionalReceiveAndExecuteWithCallbackThrowingError() throws Exception {
  RepeatTemplate template = new RepeatTemplate();
  template.setCompletionPolicy(new SimpleCompletionPolicy(2));
  container = getContainer(template);
  container.setSessionTransacted(false);
  try {
    boolean received = doTestWithException(new RuntimeException("No way!"), false, 2);
    assertTrue("Message not received but listener not transactional so this should be true", received);
  }
  catch (RuntimeException e) {
    assertEquals("No way!", e.getMessage());
    fail("Unexpected Error - should be swallowed");
  }
}
origin: spring-projects/spring-batch

public void testVoidServiceSunnyDay() throws Exception {
  ((Advised) service).addAdvice(interceptor);
  RepeatTemplate template = new RepeatTemplate();
  // N.B. the default completion policy results in an infinite loop, so we
  // need to set the chunk size.
  template.setCompletionPolicy(new SimpleCompletionPolicy(2));
  interceptor.setRepeatOperations(template);
  service.alternate();
  assertEquals(2, target.count);
}
origin: spring-projects/spring-batch

public void testCallbackWithBoolean() throws Exception {
  RepeatTemplate template = new RepeatTemplate();
  // N.B. the default completion policy results in an infinite loop, so we
  // need to set the chunk size.
  template.setCompletionPolicy(new SimpleCompletionPolicy(2));
  interceptor.setRepeatOperations(template);
  ((Advised) service).addAdvice(interceptor);
  assertTrue(service.isContinuable());
  assertEquals(2, target.count);
}
origin: spring-projects/spring-batch

@Test
public void testStepToCompletion() throws Exception {
  RepeatTemplate template = new RepeatTemplate();
  // process all items:
  template.setCompletionPolicy(new DefaultResultCompletionPolicy());
  step.setStepOperations(template);
  JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
  StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
  step.execute(stepExecution);
  assertEquals(3, processed.size());
  assertEquals(3, stepExecution.getReadCount());
}
origin: spring-projects/spring-batch

@Before
public void onSetUp() throws Exception {
  step = new TaskletStep("stepName");
  step.setJobRepository(jobRepository);
  step.setTransactionManager(transactionManager);
  // Only process one item:
  chunkOperations = new RepeatTemplate();
  chunkOperations.setCompletionPolicy(new SimpleCompletionPolicy(1));
  job = new JobSupport("FOO");
  step.setTransactionManager(transactionManager);
}
origin: spring-projects/spring-batch

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<>(getReader(strings), itemWriter, template));
  step.setJobRepository(new JobRepositorySupport());
  step.setTransactionManager(transactionManager);
  return step;
}
origin: spring-projects/spring-batch

@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");
  jobInstance = new JobInstance(0L, job.getName());
  jobParameters = new JobParameters();
  step.setTransactionManager(transactionManager);
}
origin: spring-projects/spring-batch

/**
 * Chunking using a dedicated TerminationPolicy. Transactions would be laid
 * on at the level of chunkTemplate.execute() or the surrounding callback.
 */
@Test
public void testChunkedBatchWithTerminationPolicy() throws Exception {
  RepeatTemplate repeatTemplate = new RepeatTemplate();
  final RepeatCallback callback = new ItemReaderRepeatCallback<>(provider, processor);
  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());
}
origin: spring-projects/spring-batch

@Test
public void testAfterStep() throws Exception {
  final ExitStatus customStatus = new ExitStatus("COMPLETED_CUSTOM");
  step.setStepExecutionListeners(new StepExecutionListener[] { new StepExecutionListenerSupport() {
    @Override
    public ExitStatus afterStep(StepExecution stepExecution) {
      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);
  assertEquals(1, list.size());
  ExitStatus returnedStatus = stepExecution.getExitStatus();
  assertEquals(customStatus.getExitCode(), returnedStatus.getExitCode());
  assertEquals(customStatus.getExitDescription(), returnedStatus.getExitDescription());
}
origin: spring-projects/spring-batch

@Before
public void init() throws Exception {
  maxActive = dataSource.getMaxTotal();
  maxIdle = dataSource.getMaxIdle();
  // Force deadlock with batch waiting for DB pool and vice versa
  dataSource.setMaxTotal(1);
  dataSource.setMaxIdle(1);
  step = new TaskletStep("stepName");
  step.setJobRepository(jobRepository);
  step.setTransactionManager(transactionManager);
  // Only process one item:
  chunkOperations = new RepeatTemplate();
  chunkOperations.setCompletionPolicy(new SimpleCompletionPolicy(1));
  job = new JobSupport("FOO");
  TaskExecutorRepeatTemplate repeatTemplate = new TaskExecutorRepeatTemplate();
  repeatTemplate.setThrottleLimit(2);
  repeatTemplate.setTaskExecutor(new SimpleAsyncTaskExecutor());
  step.setStepOperations(repeatTemplate);
  step.setTransactionManager(transactionManager);
}
org.springframework.batch.repeat.supportRepeatTemplatesetCompletionPolicy

Javadoc

Setter for policy to decide when the batch is complete. The default is to complete normally when the callback returns a RepeatStatus which is not marked as continuable, and abnormally when the callback throws an exception (but the decision to re-throw the exception is deferred to the ExceptionHandler).

Popular methods of RepeatTemplate

  • <init>
  • setExceptionHandler
  • iterate
  • createInternalState
    Create an internal state object that is used to store data needed internally in the scope of an iter
  • doHandle
  • executeAfterInterceptors
    Convenience method to execute after interceptors on a callback result.
  • executeInternal
    Internal convenience method to loop over interceptors and batch callbacks.
  • getNextResult
    Get the next completed result, possibly executing several callbacks until one finally finishes. Norm
  • isComplete
    Delegate to the CompletionPolicy.
  • isMarkedComplete
  • rethrow
    Re-throws the original throwable if it is unchecked, wraps checked exceptions into RepeatException.
  • start
    Delegate to the CompletionPolicy.
  • rethrow,
  • start,
  • unwrapIfRethrown,
  • update,
  • waitForResults,
  • registerListener,
  • setListeners

Popular in Java

  • Parsing JSON documents to java classes using gson
  • requestLocationUpdates (LocationManager)
  • getApplicationContext (Context)
  • setContentView (Activity)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • FileNotFoundException (java.io)
    Thrown when a file specified by a program cannot be found.
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • LoggerFactory (org.slf4j)
    The LoggerFactory is a utility class producing Loggers for various logging APIs, most notably for lo
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now