Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 5366293

Browse files
committed
created tests to verify issue 68 is an issue and added some more to the readme
1 parent 17e9814 commit 5366293

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ RetryConfig config = new RetryConfigBuilder()
157157
.build();
158158
```
159159

160+
NOTE: When using `retryOnSpecificExceptions` and `retryOnAnyExceptionExcluding`, the call executor will also take into account if the encountered exceptions are subclasses of the types you specified. For example, if you tell the configuration to retry on any `IOException`, the executor will retry on a `FileNotFoundException` which is a subclass of `IOException`.
161+
160162
If you do not want to use these built-in mechanisms for retrying on exceptions, you can override them and create custom logic:
161163

162164
```java

src/test/java/com/evanlennick/retry4j/CallExecutorTest_RetryOnAnyExcludingTest.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void setup() {
2323
}
2424

2525
@Test(expectedExceptions = {UnexpectedException.class})
26-
public void verifyRetryOnAnyExcludingThrowsCallFailureException() throws Exception {
26+
public void verifyRetryOnAnyExcludingThrowsCallFailureException() {
2727
Callable<Boolean> callable = () -> {
2828
throw new UnsupportedOperationException();
2929
};
@@ -39,7 +39,7 @@ public void verifyRetryOnAnyExcludingThrowsCallFailureException() throws Excepti
3939
}
4040

4141
@Test(expectedExceptions = {RetriesExhaustedException.class})
42-
public void verifyRetryOnAnyExcludingCallSucceeds() throws Exception {
42+
public void verifyRetryOnAnyExcludingCallSucceeds() {
4343
Callable<Boolean> callable = () -> {
4444
throw new IllegalArgumentException();
4545
};
@@ -55,7 +55,7 @@ public void verifyRetryOnAnyExcludingCallSucceeds() throws Exception {
5555
}
5656

5757
@Test(expectedExceptions = UnexpectedException.class)
58-
public void verifySubclassOfExcludedExceptionThrowsUnexpectedException() throws Exception {
58+
public void verifySubclassOfExcludedExceptionThrowsUnexpectedException() {
5959
Callable<Boolean> callable = () -> {
6060
throw new FileNotFoundException();
6161
};
@@ -71,7 +71,7 @@ public void verifySubclassOfExcludedExceptionThrowsUnexpectedException() throws
7171
}
7272

7373
@Test(expectedExceptions = RetriesExhaustedException.class)
74-
public void verifySuperclassOfExcludedExceptionDoesntThrowUnexpectedException() throws Exception {
74+
public void verifySuperclassOfExcludedExceptionDoesntThrowUnexpectedException() {
7575
Callable<Boolean> callable = () -> {
7676
throw new IOException();
7777
};
@@ -86,4 +86,34 @@ public void verifySuperclassOfExcludedExceptionDoesntThrowUnexpectedException()
8686
new CallExecutor(retryConfig).execute(callable);
8787
}
8888

89+
@Test(expectedExceptions = {UnexpectedException.class})
90+
public void verifyMultipleExceptions_throwFirstExcludedException() {
91+
Callable<Boolean> callable = () -> {
92+
throw new IllegalArgumentException();
93+
};
94+
95+
RetryConfig retryConfig = retryConfigBuilder
96+
.retryOnAnyExceptionExcluding(IllegalArgumentException.class, UnsupportedOperationException.class)
97+
.withMaxNumberOfTries(5)
98+
.withNoWaitBackoff()
99+
.build();
100+
101+
new CallExecutor(retryConfig).execute(callable);
102+
}
103+
104+
@Test(expectedExceptions = {UnexpectedException.class})
105+
public void verifyMultipleExceptions_throwSecondExcludedException() {
106+
Callable<Boolean> callable = () -> {
107+
throw new UnsupportedOperationException();
108+
};
109+
110+
RetryConfig retryConfig = retryConfigBuilder
111+
.retryOnAnyExceptionExcluding(IllegalArgumentException.class, UnsupportedOperationException.class)
112+
.withMaxNumberOfTries(5)
113+
.withNoWaitBackoff()
114+
.build();
115+
116+
new CallExecutor(retryConfig).execute(callable);
117+
}
118+
89119
}

0 commit comments

Comments
 (0)