|
27 | 27 | import java.util.List; |
28 | 28 | import java.util.Locale; |
29 | 29 | import java.util.Map; |
30 | | -import java.util.concurrent.ConcurrentHashMap; |
31 | | -import java.util.concurrent.atomic.AtomicInteger; |
32 | 30 | import java.util.function.Predicate; |
33 | 31 |
|
34 | 32 | import com.github.benmanes.caffeine.cache.Caffeine; |
|
41 | 39 | import jakarta.servlet.ServletRequest; |
42 | 40 | import jakarta.servlet.ServletResponse; |
43 | 41 | import jakarta.servlet.http.HttpServletRequest; |
44 | | -import org.apache.commons.logging.Log; |
45 | | -import org.apache.commons.logging.LogFactory; |
46 | 42 | import org.assertj.core.api.Assertions; |
47 | 43 | import org.junit.jupiter.api.Test; |
48 | 44 | import org.junit.jupiter.api.extension.ExtendWith; |
|
83 | 79 | import org.springframework.util.LinkedMultiValueMap; |
84 | 80 | import org.springframework.util.MultiValueMap; |
85 | 81 | import org.springframework.util.StreamUtils; |
86 | | -import org.springframework.web.bind.annotation.GetMapping; |
87 | 82 | import org.springframework.web.bind.annotation.PostMapping; |
88 | 83 | import org.springframework.web.bind.annotation.RequestBody; |
89 | | -import org.springframework.web.bind.annotation.RequestParam; |
90 | 84 | import org.springframework.web.bind.annotation.RestController; |
91 | 85 | import org.springframework.web.servlet.function.HandlerFunction; |
92 | 86 | import org.springframework.web.servlet.function.RouterFunction; |
|
121 | 115 | import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.addRequestHeader; |
122 | 116 | import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.addRequestHeadersIfNotPresent; |
123 | 117 | import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.addRequestParameter; |
124 | | -import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.prefixPath; |
125 | 118 | import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.redirectTo; |
126 | 119 | import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.removeRequestHeader; |
127 | 120 | import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.rewritePath; |
|
130 | 123 | import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.setRequestHostHeader; |
131 | 124 | import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.stripPrefix; |
132 | 125 | import static org.springframework.cloud.gateway.server.mvc.filter.LoadBalancerFilterFunctions.lb; |
133 | | -import static org.springframework.cloud.gateway.server.mvc.filter.RetryFilterFunctions.retry; |
134 | 126 | import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route; |
135 | 127 | import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.forward; |
136 | 128 | import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http; |
@@ -398,20 +390,6 @@ public void circuitBreakerInvalidFallbackThrowsException() { |
398 | 390 | // @formatter:on |
399 | 391 | } |
400 | 392 |
|
401 | | - @Test |
402 | | - public void retryWorks() { |
403 | | - restClient.get().uri("/retry?key=get").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("3"); |
404 | | - // test for: java.lang.IllegalArgumentException: You have already selected another |
405 | | - // retry policy |
406 | | - restClient.get() |
407 | | - .uri("/retry?key=get2") |
408 | | - .exchange() |
409 | | - .expectStatus() |
410 | | - .isOk() |
411 | | - .expectBody(String.class) |
412 | | - .isEqualTo("3"); |
413 | | - } |
414 | | - |
415 | 393 | @Test |
416 | 394 | public void rateLimitWorks() { |
417 | 395 | restClient.get().uri("/anything/ratelimit").exchange().expectStatus().isOk(); |
@@ -1014,11 +992,6 @@ TestHandler testHandler() { |
1014 | 992 | return new TestHandler(); |
1015 | 993 | } |
1016 | 994 |
|
1017 | | - @Bean |
1018 | | - RetryController retryController() { |
1019 | | - return new RetryController(); |
1020 | | - } |
1021 | | - |
1022 | 995 | @Bean |
1023 | 996 | EventController eventController() { |
1024 | 997 | return new EventController(); |
@@ -1203,19 +1176,6 @@ public RouterFunction<ServerResponse> gatewayRouterFunctionsCircuitBreakerNoFall |
1203 | 1176 | // @formatter:on |
1204 | 1177 | } |
1205 | 1178 |
|
1206 | | - @Bean |
1207 | | - public RouterFunction<ServerResponse> gatewayRouterFunctionsRetry() { |
1208 | | - // @formatter:off |
1209 | | - return route("testretry") |
1210 | | - .route(path("/retry"), http()) |
1211 | | - .before(new LocalServerPortUriResolver()) |
1212 | | - .filter(retry(3)) |
1213 | | - //.filter(retry(config -> config.setRetries(3).setSeries(Set.of(HttpStatus.Series.SERVER_ERROR)).setMethods(Set.of(HttpMethod.GET, HttpMethod.POST)))) |
1214 | | - .filter(prefixPath("/do")) |
1215 | | - .build(); |
1216 | | - // @formatter:on |
1217 | | - } |
1218 | | - |
1219 | 1179 | @Bean |
1220 | 1180 | public RouterFunction<ServerResponse> gatewayRouterFunctionsRateLimit() { |
1221 | 1181 | // @formatter:off |
@@ -1699,37 +1659,6 @@ public ResponseEntity<Event> messageChannelEvents(@RequestBody Event e) { |
1699 | 1659 |
|
1700 | 1660 | } |
1701 | 1661 |
|
1702 | | - @RestController |
1703 | | - protected static class RetryController { |
1704 | | - |
1705 | | - Log log = LogFactory.getLog(getClass()); |
1706 | | - |
1707 | | - ConcurrentHashMap<String, AtomicInteger> map = new ConcurrentHashMap<>(); |
1708 | | - |
1709 | | - @GetMapping("/do/retry") |
1710 | | - public ResponseEntity<String> retry(@RequestParam("key") String key, |
1711 | | - @RequestParam(name = "count", defaultValue = "3") int count, |
1712 | | - @RequestParam(name = "failStatus", required = false) Integer failStatus) { |
1713 | | - AtomicInteger num = getCount(key); |
1714 | | - int i = num.incrementAndGet(); |
1715 | | - log.warn("Retry count: " + i); |
1716 | | - String body = String.valueOf(i); |
1717 | | - if (i < count) { |
1718 | | - HttpStatus httpStatus = HttpStatus.INTERNAL_SERVER_ERROR; |
1719 | | - if (failStatus != null) { |
1720 | | - httpStatus = HttpStatus.resolve(failStatus); |
1721 | | - } |
1722 | | - return ResponseEntity.status(httpStatus).header("X-Retry-Count", body).body("temporarily broken"); |
1723 | | - } |
1724 | | - return ResponseEntity.status(HttpStatus.OK).header("X-Retry-Count", body).body(body); |
1725 | | - } |
1726 | | - |
1727 | | - AtomicInteger getCount(String key) { |
1728 | | - return map.computeIfAbsent(key, s -> new AtomicInteger()); |
1729 | | - } |
1730 | | - |
1731 | | - } |
1732 | | - |
1733 | 1662 | protected static class TestHandler implements HandlerFunction<ServerResponse> { |
1734 | 1663 |
|
1735 | 1664 | @Override |
|
0 commit comments