Tabnine Logo
BatchRetryTemplate
Code IndexAdd Tabnine to your IDE (free)

How to use
BatchRetryTemplate
in
org.springframework.batch.core.step.item

Best Java code snippets using org.springframework.batch.core.step.item.BatchRetryTemplate (Showing top 20 results out of 315)

origin: spring-projects/spring-batch

BatchRetryTemplate batchRetryTemplate = new BatchRetryTemplate();
if (backOffPolicy != null) {
  batchRetryTemplate.setBackOffPolicy(backOffPolicy);
batchRetryTemplate.setRetryPolicy(retryPolicyWrapper);
  batchRetryTemplate.setRetryContextCache(retryContextCache);
  batchRetryTemplate.setListeners(retryListeners.toArray(new RetryListener[0]));
origin: spring-projects/spring-batch

@Test(expected = ExhaustedRetryException.class)
public void testExhaustedRetry() throws Exception {
  BatchRetryTemplate template = new BatchRetryTemplate();
  template.setRetryPolicy(new SimpleRetryPolicy(1, Collections
      .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true)));
  RetryCallback<String[], Exception> retryCallback = new RetryCallback<String[], Exception>() {
    @Override
    public String[] doWithRetry(RetryContext context) throws Exception {
      if (count++ < 2) {
        throw new RecoverableException("Recoverable");
      }
      return outputs.toArray(new String[0]);
    }
  };
  outputs = Arrays.asList("a", "b");
  try {
    template.execute(retryCallback, BatchRetryTemplate.createState(outputs));
    fail("Expected RecoverableException");
  }
  catch (RecoverableException e) {
    assertEquals("Recoverable", e.getMessage());
  }
  outputs = Arrays.asList("a", "c");
  template.execute(retryCallback, BatchRetryTemplate.createState(outputs));
}
origin: spring-projects/spring-batch

batchRetryTemplate.execute(retryCallback, batchRecoveryCallback,
    BatchRetryTemplate.createState(getInputKeys(inputs), rollbackClassifier));
  batchRetryTemplate.execute(retryCallback, recoveryCallback, new DefaultRetryState(inputs,
      rollbackClassifier));
  if (!batchRetryTemplate.canRetry(context)) {
origin: spring-projects/spring-batch

batchRetryTemplate.execute(retryCallback, recoveryCallback);
origin: spring-projects/spring-batch

@Test
public void testSuccessfulAttempt() throws Exception {
  BatchRetryTemplate template = new BatchRetryTemplate();
  String result = template.execute(new RetryCallback<String, Exception>() {
    @Override
    public String doWithRetry(RetryContext context) throws Exception {
      assertTrue("Wrong context type: " + context.getClass().getSimpleName(), context.getClass()
          .getSimpleName().contains("Batch"));
      return "2";
    }
  }, Arrays.<RetryState> asList(new DefaultRetryState("1")));
  assertEquals("2", result);
}
origin: spring-projects/spring-batch

@Before
public void setUp() {
  batchRetryTemplate = new BatchRetryTemplate();
  processor = new FaultTolerantChunkProcessor<>(
      new PassThroughItemProcessor<>(),
      new ItemWriter<String>() {
        @Override
        public void write(List<? extends String> items)
            throws Exception {
          if (items.contains("fail")) {
            throw new RuntimeException("Planned failure!");
          }
          list.addAll(items);
        }
      }, batchRetryTemplate);
  batchRetryTemplate.setRetryPolicy(new NeverRetryPolicy());
}
origin: org.springframework.batch/org.springframework.batch.core

batchRetryTemplate.execute(retryCallback, batchRecoveryCallback, BatchRetryTemplate.createState(
    getInputKeys(inputs), rollbackClassifier));
batchRetryTemplate.execute(retryCallback, recoveryCallback, new DefaultRetryState(inputs,
    rollbackClassifier));
origin: spring-projects/spring-batch

@Test
// BATCH-2663
public void testFilterCountOnSkipInWriteWithRetry() throws Exception {
  SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
  retryPolicy.setMaxAttempts(3);
  batchRetryTemplate.setRetryPolicy(retryPolicy);
  processor.setWriteSkipPolicy(new AlwaysSkipItemSkipPolicy());
  processor.setItemProcessor(new ItemProcessor<String, String>() {
    @Override
    public String process(String item) throws Exception {
      if (item.equals("1")) {
        return null;
      }
      return item;
    }
  });
  Chunk<String> inputs = new Chunk<>(Arrays.asList("fail", "1", "2"));
  processAndExpectPlannedRuntimeException(inputs); // (first attempt) Process fail, 1, 2
  // item 1 is filtered out so it is removed from the chunk => now inputs = [fail, 2]
  processAndExpectPlannedRuntimeException(inputs); // (first retry) Process fail, 2
  processAndExpectPlannedRuntimeException(inputs); // (second retry) Process fail, 2
  // retry exhausted (maxAttempts = 3) => now scanning
  processAndExpectPlannedRuntimeException(inputs); // (scanning) Process fail
  processor.process(contribution, inputs); // (scanning) Process 2
  assertEquals(1, list.size());
  assertEquals("[2]", list.toString());
  assertEquals(1, contribution.getWriteSkipCount());
  assertEquals(3, contribution.getFilterCount());
}
origin: spring-projects/spring-batch

return batchRetryTemplate.execute(retryCallback, recoveryCallback);
origin: spring-projects/spring-batch

@Test
public void testUnSuccessfulAttemptAndRetry() throws Exception {
  BatchRetryTemplate template = new BatchRetryTemplate();
  RetryCallback<String[], Exception> retryCallback = new RetryCallback<String[], Exception>() {
    @Override
    public String[] doWithRetry(RetryContext context) throws Exception {
      assertEquals(count, context.getRetryCount());
      if (count++ == 0) {
        throw new RecoverableException("Recoverable");
      }
      return new String[] { "a", "b" };
    }
  };
  List<RetryState> states = Arrays.<RetryState> asList(new DefaultRetryState("1"), new DefaultRetryState("2"));
  try {
    template.execute(retryCallback, states);
    fail("Expected RecoverableException");
  }
  catch (RecoverableException e) {
    assertEquals("Recoverable", e.getMessage());
  }
  String[] result = template.execute(retryCallback, states);
  assertEquals("[a, b]", Arrays.toString(result));
}
origin: spring-projects/spring-batch

SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
retryPolicy.setMaxAttempts(2);
batchRetryTemplate.setRetryPolicy(retryPolicy);
processor.setWriteSkipPolicy(new LimitCheckingItemSkipPolicy(1,
    Collections.<Class<? extends Throwable>, Boolean> singletonMap(
origin: org.springframework.batch/org.springframework.batch.core

BatchRetryTemplate batchRetryTemplate = new BatchRetryTemplate();
if (backOffPolicy != null) {
  batchRetryTemplate.setBackOffPolicy(backOffPolicy);
batchRetryTemplate.setRetryPolicy(retryPolicyWrapper);
    batchRetryTemplate.setRetryContextCache(new MapRetryContextCache(cacheCapacity));
  batchRetryTemplate.setRetryContextCache(retryContextCache);
  batchRetryTemplate.setListeners(retryListeners);
origin: spring-projects/spring-batch

@Test
public void testExhaustedRetryAfterShuffle() throws Exception {
  BatchRetryTemplate template = new BatchRetryTemplate();
  template.setRetryPolicy(new SimpleRetryPolicy(1, Collections
      .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true)));
    template.execute(retryCallback, BatchRetryTemplate.createState(outputs));
    fail("Expected RecoverableException");
    template.execute(retryCallback, BatchRetryTemplate.createState(outputs));
    fail("Expected ExhaustedRetryException");
  String[] result = template.execute(retryCallback, BatchRetryTemplate.createState(outputs));
  assertEquals("[d, c]", Arrays.toString(result));
    template.execute(retryCallback, BatchRetryTemplate.createState(outputs));
    fail("Expected ExhaustedRetryException");
  result = template.execute(retryCallback, BatchRetryTemplate.createState(outputs));
  assertEquals("[e, f]", Arrays.toString(result));
origin: org.springframework.batch/spring-batch-core

batchRetryTemplate.execute(retryCallback, batchRecoveryCallback,
    BatchRetryTemplate.createState(getInputKeys(inputs), rollbackClassifier));
  batchRetryTemplate.execute(retryCallback, recoveryCallback, new DefaultRetryState(inputs,
      rollbackClassifier));
  if (!batchRetryTemplate.canRetry(context)) {
origin: spring-projects/spring-batch

return batchRetryTemplate.execute(retryCallback, recoveryCallback);
origin: spring-projects/spring-batch

SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
retryPolicy.setMaxAttempts(2);
batchRetryTemplate.setRetryPolicy(retryPolicy);
processor.setWriteSkipPolicy(new AlwaysSkipItemSkipPolicy());
processor.setItemWriter(new ItemWriter<String>() {
origin: org.springframework.batch/spring-batch-core

BatchRetryTemplate batchRetryTemplate = new BatchRetryTemplate();
if (backOffPolicy != null) {
  batchRetryTemplate.setBackOffPolicy(backOffPolicy);
batchRetryTemplate.setRetryPolicy(retryPolicyWrapper);
  batchRetryTemplate.setRetryContextCache(retryContextCache);
  batchRetryTemplate.setListeners(retryListeners.toArray(new RetryListener[0]));
origin: spring-projects/spring-batch

@Test
public void testExhaustedRetryWithRecovery() throws Exception {
  BatchRetryTemplate template = new BatchRetryTemplate();
  template.setRetryPolicy(new SimpleRetryPolicy(1, Collections
      .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true)));
    template.execute(retryCallback, recoveryCallback, BatchRetryTemplate.createState(outputs));
    fail("Expected RecoverableException");
  String[] result = template.execute(retryCallback, recoveryCallback, BatchRetryTemplate.createState(outputs));
  assertEquals("[r:b, r:c]", Arrays.toString(result));
origin: org.springframework.batch.core/org.motechproject.org.springframework.batch.core

batchRetryTemplate.execute(retryCallback, batchRecoveryCallback,
    BatchRetryTemplate.createState(getInputKeys(inputs), rollbackClassifier));
  batchRetryTemplate.execute(retryCallback, recoveryCallback, new DefaultRetryState(inputs,
      rollbackClassifier));
  if (!batchRetryTemplate.canRetry(context)) {
origin: spring-projects/spring-batch

O output = batchRetryTemplate.execute(retryCallback, recoveryCallback, new DefaultRetryState(
    getInputKey(item), rollbackClassifier));
if (output != null) {
org.springframework.batch.core.step.itemBatchRetryTemplate

Javadoc

A special purpose retry template that deals specifically with multi-valued stateful retry. This is useful in the case where the operation to be retried operates on multiple items, and when it fails there is no way to decide which (if any) of the items was responsible. The RetryState used in the execute methods is composite, and when a failure occurs, all of the keys in the composite are "tarred with the same brush". Subsequent attempts to execute with any of the keys that have failed previously results in a new attempt and the previous state is used to check the RetryPolicy. If one of the failed items eventually succeeds then the others in the current composite for that attempt will be cleared from the context cache (as normal), but there may still be entries in the cache for the original failed items. This might mean that an item that did not cause a failure is never retried because other items in the same batch fail fatally first.

Most used methods

  • <init>
  • createState
  • execute
  • setRetryPolicy
  • setBackOffPolicy
  • setListeners
  • setRetryContextCache
  • canRetry

Popular in Java

  • Updating database using SQL prepared statement
  • startActivity (Activity)
  • onRequestPermissionsResult (Fragment)
  • getResourceAsStream (ClassLoader)
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • JFileChooser (javax.swing)
  • JTable (javax.swing)
  • Github Copilot alternatives
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