Skip to content

Commit a63cf34

Browse files
author
Robert Winkler
committed
Issue ReactiveX#368: Fixed failing RetryAutoConfigurationTest because Spring context was not cleared.
1 parent 1516c9a commit a63cf34

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

resilience4j-spring-boot2/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationTest.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,22 @@
1515
*/
1616
package io.github.resilience4j.retry;
1717

18-
import static org.assertj.core.api.Assertions.assertThat;
19-
20-
import java.io.IOException;
21-
import java.util.Map;
22-
import java.util.concurrent.CompletionStage;
23-
import java.util.concurrent.ExecutionException;
24-
import java.util.concurrent.TimeUnit;
25-
import java.util.concurrent.TimeoutException;
26-
2718
import org.junit.Test;
2819
import org.junit.runner.RunWith;
2920
import org.springframework.beans.factory.annotation.Autowired;
3021
import org.springframework.boot.test.context.SpringBootTest;
3122
import org.springframework.boot.test.web.client.TestRestTemplate;
3223
import org.springframework.http.ResponseEntity;
24+
import org.springframework.test.annotation.DirtiesContext;
3325
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
3426

27+
import java.io.IOException;
28+
import java.util.Map;
29+
import java.util.concurrent.CompletionStage;
30+
import java.util.concurrent.ExecutionException;
31+
import java.util.concurrent.TimeUnit;
32+
import java.util.concurrent.TimeoutException;
33+
3534
import io.github.resilience4j.circuitbreaker.IgnoredException;
3635
import io.github.resilience4j.retry.autoconfigure.RetryProperties;
3736
import io.github.resilience4j.retry.configure.RetryAspect;
@@ -40,6 +39,8 @@
4039
import io.github.resilience4j.service.test.RetryDummyService;
4140
import io.github.resilience4j.service.test.TestApplication;
4241

42+
import static org.assertj.core.api.Assertions.assertThat;
43+
4344
@RunWith(SpringJUnit4ClassRunner.class)
4445
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
4546
classes = TestApplication.class)
@@ -68,6 +69,7 @@ public class RetryAutoConfigurationTest {
6869
* that the Retry logic is properly handled
6970
*/
7071
@Test
72+
@DirtiesContext
7173
public void testRetryAutoConfiguration() throws IOException {
7274
assertThat(retryRegistry).isNotNull();
7375
assertThat(retryProperties).isNotNull();
@@ -116,6 +118,7 @@ public void testRetryAutoConfiguration() throws IOException {
116118
* that the Async Retry logic is properly handled
117119
*/
118120
@Test
121+
@DirtiesContext
119122
public void testRetryAutoConfigurationAsync() throws Throwable {
120123
assertThat(asyncRetryRegistry).isNotNull();
121124

@@ -150,10 +153,10 @@ public void testRetryAutoConfigurationAsync() throws Throwable {
150153

151154
// expect retry-event actuator endpoint recorded both events
152155
ResponseEntity<RetryEventsEndpointResponse> retryEventList = restTemplate.getForEntity("/actuator/retryevents", RetryEventsEndpointResponse.class);
153-
assertThat(retryEventList.getBody().getRetryEvents()).hasSize(6);
156+
assertThat(retryEventList.getBody().getRetryEvents()).hasSize(3);
154157

155158
retryEventList = restTemplate.getForEntity("/actuator/retryevents/retryBackendA", RetryEventsEndpointResponse.class);
156-
assertThat(retryEventList.getBody().getRetryEvents()).hasSize(6);
159+
assertThat(retryEventList.getBody().getRetryEvents()).hasSize(3);
157160

158161
assertThat(retry.getRetryConfig().getExceptionPredicate().test(new IOException())).isTrue();
159162
assertThat(retry.getRetryConfig().getExceptionPredicate().test(new IgnoredException())).isFalse();

0 commit comments

Comments
 (0)