AMQP-334 Support Unwrapping Exceptions for Retry
With Spring AMQP, the exception thrown to the RetryTemplate is a ListenerExecutionFailedException with the business exception in the cause. This means Exception categorization does not work. Provide a retry policy/classifier that can examine exception causes until a match is found. If so configured, the retry policy should categorize exceptions by traversing the cause if the current exception is not itself categorized.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -56,6 +56,15 @@ public class BinaryExceptionClassifierTests {
|
||||
assertTrue(new BinaryExceptionClassifier(set).classify(new IllegalStateException("Foo")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassifyExactMatchInCause() {
|
||||
Collection<Class<? extends Throwable>> set = Collections
|
||||
.<Class<? extends Throwable>> singleton(IllegalStateException.class);
|
||||
BinaryExceptionClassifier binaryExceptionClassifier = new BinaryExceptionClassifier(set);
|
||||
binaryExceptionClassifier.setTraverseCauses(true);
|
||||
assertTrue(binaryExceptionClassifier.classify(new RuntimeException(new IllegalStateException("Foo"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypesProvidedInConstructor() {
|
||||
classifier = new BinaryExceptionClassifier(Collections
|
||||
@@ -69,4 +78,12 @@ public class BinaryExceptionClassifierTests {
|
||||
.<Class<? extends Throwable>> singleton(IllegalStateException.class), false);
|
||||
assertFalse(classifier.classify(new IllegalStateException("Foo")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypesProvidedInConstructorWithNonDefaultInCause() {
|
||||
classifier = new BinaryExceptionClassifier(Collections
|
||||
.<Class<? extends Throwable>> singleton(IllegalStateException.class), false);
|
||||
classifier.setTraverseCauses(true);
|
||||
assertFalse(classifier.classify(new RuntimeException(new RuntimeException(new IllegalStateException("Foo")))));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user