Search in sources :

Example 1 with ExhaustedRetryException

use of org.springframework.retry.ExhaustedRetryException in project spring-retry by spring-projects.

the class CircuitBreakerStatisticsTests method testFailedRecoveryCountsAsAbort.

@Test
public void testFailedRecoveryCountsAsAbort() throws Throwable {
    this.retryTemplate.setRetryPolicy(new CircuitBreakerRetryPolicy(new NeverRetryPolicy()));
    this.recovery = new RecoveryCallback<Object>() {

        @Override
        public Object recover(RetryContext context) throws Exception {
            throw new ExhaustedRetryException("Planned exhausted");
        }
    };
    try {
        this.retryTemplate.execute(this.callback, this.recovery, this.state);
        fail("Expected ExhaustedRetryException");
    } catch (ExhaustedRetryException e) {
    // Fine
    }
    MutableRetryStatistics stats = (MutableRetryStatistics) repository.findOne("test");
    assertEquals(1, stats.getStartedCount());
    assertEquals(1, stats.getAbortCount());
    assertEquals(0, stats.getRecoveryCount());
}
Also used : ExhaustedRetryException(org.springframework.retry.ExhaustedRetryException) RetryContext(org.springframework.retry.RetryContext) CircuitBreakerRetryPolicy(org.springframework.retry.policy.CircuitBreakerRetryPolicy) NeverRetryPolicy(org.springframework.retry.policy.NeverRetryPolicy) ExhaustedRetryException(org.springframework.retry.ExhaustedRetryException) Test(org.junit.Test)

Example 2 with ExhaustedRetryException

use of org.springframework.retry.ExhaustedRetryException in project spring-batch by spring-projects.

the class FaultTolerantStepBuilder method getRollbackClassifier.

/**
 * Convenience method to get an exception classifier based on the provided transaction attributes.
 *
 * @return an exception classifier: maps to true if an exception should cause rollback
 */
protected Classifier<Throwable, Boolean> getRollbackClassifier() {
    Classifier<Throwable, Boolean> classifier = new BinaryExceptionClassifier(noRollbackExceptionClasses, false);
    // (should be pretty uncommon):
    if (!classifier.classify(new ForceRollbackForWriteSkipException("test", new RuntimeException())) || !classifier.classify(new ExhaustedRetryException("test"))) {
        final Classifier<Throwable, Boolean> binary = classifier;
        Collection<Class<? extends Throwable>> types = new HashSet<>();
        types.add(ForceRollbackForWriteSkipException.class);
        types.add(ExhaustedRetryException.class);
        final Classifier<Throwable, Boolean> panic = new BinaryExceptionClassifier(types, true);
        classifier = (Classifier<Throwable, Boolean>) classifiable -> {
            return panic.classify(classifiable) || binary.classify(classifiable);
        };
    }
    return classifier;
}
Also used : ExhaustedRetryException(org.springframework.retry.ExhaustedRetryException) SkipListenerFailedException(org.springframework.batch.core.step.skip.SkipListenerFailedException) StepListener(org.springframework.batch.core.StepListener) ChunkMonitor(org.springframework.batch.core.step.item.ChunkMonitor) OnSkipInProcess(org.springframework.batch.core.annotation.OnSkipInProcess) ChunkProvider(org.springframework.batch.core.step.item.ChunkProvider) ChunkProcessor(org.springframework.batch.core.step.item.ChunkProcessor) TaskletStep(org.springframework.batch.core.step.tasklet.TaskletStep) Map(java.util.Map) FatalStepExecutionException(org.springframework.batch.core.step.FatalStepExecutionException) LimitCheckingItemSkipPolicy(org.springframework.batch.core.step.skip.LimitCheckingItemSkipPolicy) CompositeRetryPolicy(org.springframework.retry.policy.CompositeRetryPolicy) FaultTolerantChunkProcessor(org.springframework.batch.core.step.item.FaultTolerantChunkProcessor) Method(java.lang.reflect.Method) OnSkipInRead(org.springframework.batch.core.annotation.OnSkipInRead) KeyGenerator(org.springframework.batch.core.step.item.KeyGenerator) ItemReader(org.springframework.batch.item.ItemReader) ChunkListener(org.springframework.batch.core.ChunkListener) FaultTolerantChunkProvider(org.springframework.batch.core.step.item.FaultTolerantChunkProvider) Collection(java.util.Collection) Set(java.util.Set) StepListenerFactoryBean(org.springframework.batch.core.listener.StepListenerFactoryBean) SubclassClassifier(org.springframework.classify.SubclassClassifier) List(java.util.List) ForceRollbackForWriteSkipException(org.springframework.batch.core.step.item.ForceRollbackForWriteSkipException) TransactionAttribute(org.springframework.transaction.interceptor.TransactionAttribute) JobInterruptedException(org.springframework.batch.core.JobInterruptedException) ExceptionClassifierRetryPolicy(org.springframework.retry.policy.ExceptionClassifierRetryPolicy) ExceptionClassifierSkipPolicy(org.springframework.batch.core.step.skip.ExceptionClassifierSkipPolicy) HashMap(java.util.HashMap) ItemStream(org.springframework.batch.item.ItemStream) BinaryExceptionClassifier(org.springframework.classify.BinaryExceptionClassifier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BackOffPolicy(org.springframework.retry.backoff.BackOffPolicy) RetryPolicy(org.springframework.retry.RetryPolicy) RepeatOperations(org.springframework.batch.repeat.RepeatOperations) BeanCreationException(org.springframework.beans.factory.BeanCreationException) RetryListener(org.springframework.retry.RetryListener) Tasklet(org.springframework.batch.core.step.tasklet.Tasklet) CompositeSkipPolicy(org.springframework.batch.core.step.skip.CompositeSkipPolicy) ReflectionUtils(org.springframework.batch.support.ReflectionUtils) RetryException(org.springframework.retry.RetryException) ChunkOrientedTasklet(org.springframework.batch.core.step.item.ChunkOrientedTasklet) SkipPolicyFailedException(org.springframework.batch.core.step.skip.SkipPolicyFailedException) LinkedHashSet(java.util.LinkedHashSet) SimpleRetryExceptionHandler(org.springframework.batch.core.step.item.SimpleRetryExceptionHandler) NeverSkipItemSkipPolicy(org.springframework.batch.core.step.skip.NeverSkipItemSkipPolicy) SimpleRetryPolicy(org.springframework.retry.policy.SimpleRetryPolicy) DefaultTransactionAttribute(org.springframework.transaction.interceptor.DefaultTransactionAttribute) BatchRetryTemplate(org.springframework.batch.core.step.item.BatchRetryTemplate) SkipPolicy(org.springframework.batch.core.step.skip.SkipPolicy) Classifier(org.springframework.classify.Classifier) SkipListener(org.springframework.batch.core.SkipListener) NeverRetryPolicy(org.springframework.retry.policy.NeverRetryPolicy) RepeatTemplate(org.springframework.batch.repeat.support.RepeatTemplate) ChunkContext(org.springframework.batch.core.scope.context.ChunkContext) ExhaustedRetryException(org.springframework.retry.ExhaustedRetryException) TransactionException(org.springframework.transaction.TransactionException) RetryContextCache(org.springframework.retry.policy.RetryContextCache) OnSkipInWrite(org.springframework.batch.core.annotation.OnSkipInWrite) NonSkippableReadException(org.springframework.batch.core.step.skip.NonSkippableReadException) StepExecutionListener(org.springframework.batch.core.StepExecutionListener) SkipLimitExceededException(org.springframework.batch.core.step.skip.SkipLimitExceededException) Assert(org.springframework.util.Assert) BinaryExceptionClassifier(org.springframework.classify.BinaryExceptionClassifier) ForceRollbackForWriteSkipException(org.springframework.batch.core.step.item.ForceRollbackForWriteSkipException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 3 with ExhaustedRetryException

use of org.springframework.retry.ExhaustedRetryException in project cwa-server by corona-warn-app.

the class RemoteStatisticJsonFileLoaderTest method shouldUnauthorizedFileException.

@Test
void shouldUnauthorizedFileException() {
    var mockException = mock(S3Exception.class);
    when(mockS3client.getSingleObjectContent(anyString(), anyString())).thenThrow(new ExhaustedRetryException("", mockException));
    var loader = new RemoteStatisticJsonFileLoader(mockS3client, serviceConfig);
    assertThrows(FilePathNotFoundException.class, loader::getFile);
}
Also used : ExhaustedRetryException(org.springframework.retry.ExhaustedRetryException) Test(org.junit.jupiter.api.Test)

Example 4 with ExhaustedRetryException

use of org.springframework.retry.ExhaustedRetryException in project cwa-server by corona-warn-app.

the class RemoteStatisticJsonFileLoaderTest method shouldThrowBucketNotFound.

@Test
void shouldThrowBucketNotFound() {
    var mockException = mock(NoSuchBucketException.class);
    when(mockS3client.getSingleObjectContent(anyString(), anyString())).thenThrow(new ExhaustedRetryException("", mockException));
    var loader = new RemoteStatisticJsonFileLoader(mockS3client, serviceConfig);
    assertThrows(BucketNotFoundException.class, loader::getFile);
}
Also used : ExhaustedRetryException(org.springframework.retry.ExhaustedRetryException) Test(org.junit.jupiter.api.Test)

Example 5 with ExhaustedRetryException

use of org.springframework.retry.ExhaustedRetryException in project cwa-server by corona-warn-app.

the class RemoteStatisticJsonFileLoaderTest method shouldThrowConnectionException.

@Test
void shouldThrowConnectionException() {
    var mockException = mock(SdkClientException.class);
    when(mockS3client.getSingleObjectContent(anyString(), anyString())).thenThrow(new ExhaustedRetryException("", mockException));
    var loader = new RemoteStatisticJsonFileLoader(mockS3client, serviceConfig);
    assertThrows(ConnectionException.class, loader::getFile);
}
Also used : ExhaustedRetryException(org.springframework.retry.ExhaustedRetryException) Test(org.junit.jupiter.api.Test)

Aggregations

ExhaustedRetryException (org.springframework.retry.ExhaustedRetryException)13 Test (org.junit.Test)5 RetryContext (org.springframework.retry.RetryContext)5 Test (org.junit.jupiter.api.Test)4 NeverRetryPolicy (org.springframework.retry.policy.NeverRetryPolicy)4 RetryCallback (org.springframework.retry.RetryCallback)3 RetryException (org.springframework.retry.RetryException)3 SimpleRetryPolicy (org.springframework.retry.policy.SimpleRetryPolicy)3 Method (java.lang.reflect.Method)2 SkipLimitExceededException (org.springframework.batch.core.step.skip.SkipLimitExceededException)2 RetryPolicy (org.springframework.retry.RetryPolicy)2 RetryState (org.springframework.retry.RetryState)2 DefaultRetryState (org.springframework.retry.support.DefaultRetryState)2 Timer (io.micrometer.core.instrument.Timer)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1