Package org.springframework.retry.policy

Examples of org.springframework.retry.policy.SimpleRetryPolicy


  @Test
  public void testExternalRetryRecoveryInBatch() throws Exception {
    assertInitialState();

    retryTemplate.setRetryPolicy(new SimpleRetryPolicy(1, Collections
        .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true)));

    repeatTemplate.setCompletionPolicy(new SimpleCompletionPolicy(2));

    // In a real container this could be an outer retry loop with an
View Full Code Here


   * @return fully configured retry template for item processing phase.
   */
  protected BatchRetryTemplate createRetryOperations() {

    RetryPolicy retryPolicy = this.retryPolicy;
    SimpleRetryPolicy simpleRetryPolicy = null;

    Map<Class<? extends Throwable>, Boolean> map = new HashMap<Class<? extends Throwable>, Boolean>(
        retryableExceptionClasses);
    map.put(ForceRollbackForWriteSkipException.class, true);
    simpleRetryPolicy = new SimpleRetryPolicy(retryLimit, map);

    if (retryPolicy == null) {
      Assert.state(!(retryableExceptionClasses.isEmpty() && retryLimit > 0),
          "If a retry limit is provided then retryable exceptions must also be specified");
      retryPolicy = simpleRetryPolicy;
View Full Code Here

  @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 {
View Full Code Here

  @Test
  public void testExhaustedRetryAfterShuffle() 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 {
View Full Code Here

  @Test
  public void testExhaustedRetryWithRecovery() 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 {
View Full Code Here

   */
  protected RetryTemplate buildRetryTemplateIfRetryEnabled(AbstractBusPropertiesAccessor properties) {
    int maxAttempts = properties.getMaxAttempts(this.defaultMaxAttempts);
    if (maxAttempts > 1) {
      RetryTemplate template = new RetryTemplate();
      SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
      retryPolicy.setMaxAttempts(maxAttempts);
      ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
      backOffPolicy.setInitialInterval(properties.getBackOffInitialInterval(this.defaultBackOffInitialInterval));
      backOffPolicy.setMultiplier(properties.getBackOffMultiplier(this.defaultBackOffMultiplier));
      backOffPolicy.setMaxInterval(properties.getBackOffMaxInterval(this.defaultBackOffMaxInterval));
      template.setRetryPolicy(retryPolicy);
View Full Code Here

        policy.setMaxInterval(3000);
        return policy;
    }

    private SimpleRetryPolicy makeRetryPolicy() {
        SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
        retryPolicy.setMaxAttempts(MAX_RETRIES);
        return retryPolicy;
    }
View Full Code Here

  public void testSuccessfulRetry() throws Throwable {
    for (int x = 1; x <= 10; x++) {
      MockRetryCallback callback = new MockRetryCallback();
      callback.setAttemptsBeforeSuccess(x);
      RetryTemplate retryTemplate = new RetryTemplate();
      retryTemplate.setRetryPolicy(new SimpleRetryPolicy(x, Collections
          .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class,
              true)));
      retryTemplate.execute(callback);
      assertEquals(x, callback.attempts);
    }
View Full Code Here

          }
          return "foo";
        }
      };
      RetryTemplate retryTemplate = new RetryTemplate();
      retryTemplate.setRetryPolicy(new SimpleRetryPolicy(x, Collections
          .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class,
              true)));
      retryTemplate.execute(callback);
      assertEquals(x, attempts.get());
    }
View Full Code Here

  @Test
  public void testSuccessfulRecovery() throws Throwable {
    MockRetryCallback callback = new MockRetryCallback();
    callback.setAttemptsBeforeSuccess(3);
    RetryTemplate retryTemplate = new RetryTemplate();
    retryTemplate.setRetryPolicy(new SimpleRetryPolicy(2,
        Collections.<Class<? extends Throwable>, Boolean> singletonMap(
            Exception.class, true)));
    final Object value = new Object();
    Object result = retryTemplate.execute(callback, new RecoveryCallback<Object>() {
      public Object recover(RetryContext context) throws Exception {
View Full Code Here

TOP

Related Classes of org.springframework.retry.policy.SimpleRetryPolicy

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.