|
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 |
|
|
80 | 76 | import org.springframework.util.LinkedMultiValueMap; |
81 | 77 | import org.springframework.util.MultiValueMap; |
82 | 78 | import org.springframework.util.StreamUtils; |
83 | | -import org.springframework.web.bind.annotation.GetMapping; |
84 | 79 | import org.springframework.web.bind.annotation.PostMapping; |
85 | 80 | import org.springframework.web.bind.annotation.RequestBody; |
86 | | -import org.springframework.web.bind.annotation.RequestParam; |
87 | 81 | import org.springframework.web.bind.annotation.RestController; |
88 | 82 | import org.springframework.web.servlet.function.HandlerFunction; |
89 | 83 | import org.springframework.web.servlet.function.RouterFunction; |
|
118 | 112 | import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.addRequestHeader; |
119 | 113 | import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.addRequestHeadersIfNotPresent; |
120 | 114 | import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.addRequestParameter; |
121 | | -import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.prefixPath; |
122 | 115 | import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.redirectTo; |
123 | 116 | import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.removeRequestHeader; |
124 | 117 | import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.rewritePath; |
|
127 | 120 | import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.setRequestHostHeader; |
128 | 121 | import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.stripPrefix; |
129 | 122 | import static org.springframework.cloud.gateway.server.mvc.filter.LoadBalancerFilterFunctions.lb; |
130 | | -import static org.springframework.cloud.gateway.server.mvc.filter.RetryFilterFunctions.retry; |
131 | 123 | import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route; |
132 | 124 | import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.forward; |
133 | 125 | import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http; |
@@ -394,20 +386,6 @@ public void circuitBreakerInvalidFallbackThrowsException() { |
394 | 386 | // @formatter:on |
395 | 387 | } |
396 | 388 |
|
397 | | - @Test |
398 | | - public void retryWorks() { |
399 | | - restClient.get().uri("/retry?key=get").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("3"); |
400 | | - // test for: java.lang.IllegalArgumentException: You have already selected another |
401 | | - // retry policy |
402 | | - restClient.get() |
403 | | - .uri("/retry?key=get2") |
404 | | - .exchange() |
405 | | - .expectStatus() |
406 | | - .isOk() |
407 | | - .expectBody(String.class) |
408 | | - .isEqualTo("3"); |
409 | | - } |
410 | | - |
411 | 389 | @Test |
412 | 390 | public void rateLimitWorks() { |
413 | 391 | restClient.get().uri("/anything/ratelimit").exchange().expectStatus().isOk(); |
@@ -1005,11 +983,6 @@ TestHandler testHandler() { |
1005 | 983 | return new TestHandler(); |
1006 | 984 | } |
1007 | 985 |
|
1008 | | - @Bean |
1009 | | - RetryController retryController() { |
1010 | | - return new RetryController(); |
1011 | | - } |
1012 | | - |
1013 | 986 | @Bean |
1014 | 987 | EventController eventController() { |
1015 | 988 | return new EventController(); |
@@ -1194,19 +1167,6 @@ public RouterFunction<ServerResponse> gatewayRouterFunctionsCircuitBreakerNoFall |
1194 | 1167 | // @formatter:on |
1195 | 1168 | } |
1196 | 1169 |
|
1197 | | - @Bean |
1198 | | - public RouterFunction<ServerResponse> gatewayRouterFunctionsRetry() { |
1199 | | - // @formatter:off |
1200 | | - return route("testretry") |
1201 | | - .route(path("/retry"), http()) |
1202 | | - .before(new LocalServerPortUriResolver()) |
1203 | | - .filter(retry(3)) |
1204 | | - //.filter(retry(config -> config.setRetries(3).setSeries(Set.of(HttpStatus.Series.SERVER_ERROR)).setMethods(Set.of(HttpMethod.GET, HttpMethod.POST)))) |
1205 | | - .filter(prefixPath("/do")) |
1206 | | - .build(); |
1207 | | - // @formatter:on |
1208 | | - } |
1209 | | - |
1210 | 1170 | @Bean |
1211 | 1171 | public RouterFunction<ServerResponse> gatewayRouterFunctionsRateLimit() { |
1212 | 1172 | // @formatter:off |
@@ -1690,37 +1650,6 @@ public ResponseEntity<Event> messageChannelEvents(@RequestBody Event e) { |
1690 | 1650 |
|
1691 | 1651 | } |
1692 | 1652 |
|
1693 | | - @RestController |
1694 | | - protected static class RetryController { |
1695 | | - |
1696 | | - Log log = LogFactory.getLog(getClass()); |
1697 | | - |
1698 | | - ConcurrentHashMap<String, AtomicInteger> map = new ConcurrentHashMap<>(); |
1699 | | - |
1700 | | - @GetMapping("/do/retry") |
1701 | | - public ResponseEntity<String> retry(@RequestParam("key") String key, |
1702 | | - @RequestParam(name = "count", defaultValue = "3") int count, |
1703 | | - @RequestParam(name = "failStatus", required = false) Integer failStatus) { |
1704 | | - AtomicInteger num = getCount(key); |
1705 | | - int i = num.incrementAndGet(); |
1706 | | - log.warn("Retry count: " + i); |
1707 | | - String body = String.valueOf(i); |
1708 | | - if (i < count) { |
1709 | | - HttpStatus httpStatus = HttpStatus.INTERNAL_SERVER_ERROR; |
1710 | | - if (failStatus != null) { |
1711 | | - httpStatus = HttpStatus.resolve(failStatus); |
1712 | | - } |
1713 | | - return ResponseEntity.status(httpStatus).header("X-Retry-Count", body).body("temporarily broken"); |
1714 | | - } |
1715 | | - return ResponseEntity.status(HttpStatus.OK).header("X-Retry-Count", body).body(body); |
1716 | | - } |
1717 | | - |
1718 | | - AtomicInteger getCount(String key) { |
1719 | | - return map.computeIfAbsent(key, s -> new AtomicInteger()); |
1720 | | - } |
1721 | | - |
1722 | | - } |
1723 | | - |
1724 | 1653 | protected static class TestHandler implements HandlerFunction<ServerResponse> { |
1725 | 1654 |
|
1726 | 1655 | @Override |
|
0 commit comments