|
16 | 16 |
|
17 | 17 | package io.github.resilience4j.retry.transformer;
|
18 | 18 |
|
19 |
| -import io.github.resilience4j.retry.Retry; |
20 |
| -import io.github.resilience4j.retry.RetryConfig; |
21 |
| -import io.github.resilience4j.test.HelloWorldService; |
22 |
| -import io.reactivex.*; |
| 19 | +import static org.assertj.core.api.Assertions.assertThat; |
| 20 | +import static org.mockito.BDDMockito.given; |
| 21 | +import static org.mockito.Mockito.doNothing; |
| 22 | +import static org.mockito.Mockito.doThrow; |
| 23 | + |
| 24 | +import java.io.IOException; |
| 25 | + |
| 26 | +import javax.xml.ws.WebServiceException; |
| 27 | + |
23 | 28 | import org.junit.Before;
|
24 | 29 | import org.junit.Test;
|
25 | 30 | import org.mockito.BDDMockito;
|
26 | 31 | import org.mockito.Mockito;
|
27 | 32 |
|
28 |
| -import javax.xml.ws.WebServiceException; |
29 |
| -import java.io.IOException; |
30 |
| - |
31 |
| -import static org.assertj.core.api.Assertions.assertThat; |
32 |
| -import static org.mockito.BDDMockito.given; |
33 |
| -import static org.mockito.Mockito.doNothing; |
34 |
| -import static org.mockito.Mockito.doThrow; |
| 33 | +import io.github.resilience4j.retry.Retry; |
| 34 | +import io.github.resilience4j.retry.RetryConfig; |
| 35 | +import io.github.resilience4j.test.HelloWorldService; |
| 36 | +import io.reactivex.Completable; |
| 37 | +import io.reactivex.Flowable; |
| 38 | +import io.reactivex.Maybe; |
| 39 | +import io.reactivex.Observable; |
| 40 | +import io.reactivex.Single; |
35 | 41 |
|
36 | 42 | public class RetryTransformerTest {
|
37 | 43 |
|
@@ -80,6 +86,57 @@ public void returnOnCompleteUsingSingle() {
|
80 | 86 | assertThat(metrics.getNumberOfFailedCallsWithoutRetryAttempt()).isEqualTo(0);
|
81 | 87 | }
|
82 | 88 |
|
| 89 | + |
| 90 | + @Test(expected = StackOverflowError.class) |
| 91 | + public void shouldNotRetryUsingSingleStackOverFlow() { |
| 92 | + //Given |
| 93 | + RetryConfig config = RetryConfig.ofDefaults(); |
| 94 | + Retry retry = Retry.of("testName", config); |
| 95 | + RetryTransformer<Object> retryTransformer = RetryTransformer.of(retry); |
| 96 | + |
| 97 | + given(helloWorldService.returnHelloWorld()) |
| 98 | + .willThrow(new StackOverflowError("BAM!")); |
| 99 | + |
| 100 | + //When |
| 101 | + Single.fromCallable(helloWorldService::returnHelloWorld) |
| 102 | + .compose(retryTransformer) |
| 103 | + .test(); |
| 104 | + |
| 105 | + |
| 106 | + //Then |
| 107 | + BDDMockito.then(helloWorldService).should(Mockito.times(1)).returnHelloWorld(); |
| 108 | + Retry.Metrics metrics = retry.getMetrics(); |
| 109 | + |
| 110 | + assertThat(metrics.getNumberOfFailedCallsWithoutRetryAttempt()).isEqualTo(0); |
| 111 | + assertThat(metrics.getNumberOfFailedCallsWithRetryAttempt()).isEqualTo(0); |
| 112 | + } |
| 113 | + |
| 114 | + @Test |
| 115 | + public void shouldNotRetryWhenItThrowErrorSingle() { |
| 116 | + //Given |
| 117 | + RetryConfig config = RetryConfig.ofDefaults(); |
| 118 | + Retry retry = Retry.of("testName", config); |
| 119 | + RetryTransformer<Object> retryTransformer = RetryTransformer.of(retry); |
| 120 | + |
| 121 | + given(helloWorldService.returnHelloWorld()) |
| 122 | + .willThrow(new Error("BAM!")); |
| 123 | + |
| 124 | + //When |
| 125 | + Single.fromCallable(helloWorldService::returnHelloWorld) |
| 126 | + .compose(retryTransformer) |
| 127 | + .test() |
| 128 | + .assertError(Error.class) |
| 129 | + .assertNotComplete() |
| 130 | + .assertSubscribed(); |
| 131 | + //Then |
| 132 | + BDDMockito.then(helloWorldService).should(Mockito.times(1)).returnHelloWorld(); |
| 133 | + Retry.Metrics metrics = retry.getMetrics(); |
| 134 | + |
| 135 | + assertThat(metrics.getNumberOfFailedCallsWithRetryAttempt()).isEqualTo(0); |
| 136 | + assertThat(metrics.getNumberOfFailedCallsWithoutRetryAttempt()).isEqualTo(0); |
| 137 | + } |
| 138 | + |
| 139 | + |
83 | 140 | @Test
|
84 | 141 | public void returnOnErrorUsingSingle() {
|
85 | 142 | //Given
|
|
0 commit comments