From d17630f4f2ec8cb8a0b5266a1b915ed145fbf323 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Wed, 3 Jul 2019 15:23:03 -0400 Subject: [PATCH] Verify body is still sent during post retry --- ...yGatewayFilterFactoryIntegrationTests.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java index f81d5b200..f5511e037 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java @@ -46,6 +46,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -83,7 +84,7 @@ public class RetryGatewayFilterFactoryIntegrationTests extends BaseWebClientTest @Test public void retryFilterPost() { - testClient.post().uri("/retry?key=post") + testClient.post().uri("/retrypost?key=post&expectedbody=Hello") .header(HttpHeaders.HOST, "www.retryjava.org").syncBody("Hello") .exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("3"); } @@ -119,7 +120,7 @@ public class RetryGatewayFilterFactoryIntegrationTests extends BaseWebClientTest @RequestMapping("/httpbin/retryalwaysfail") public ResponseEntity retryalwaysfail(@RequestParam("key") String key, @RequestParam(name = "count", defaultValue = "3") int count) { - AtomicInteger num = map.computeIfAbsent(key, s -> new AtomicInteger()); + AtomicInteger num = getCount(key); int i = num.incrementAndGet(); log.warn("Retry count: " + i); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) @@ -127,10 +128,24 @@ public class RetryGatewayFilterFactoryIntegrationTests extends BaseWebClientTest .body("permanently broken"); } + @RequestMapping("/httpbin/retrypost") + public ResponseEntity retry(@RequestParam("key") String key, + @RequestParam(name = "count", defaultValue = "3") int count, + @RequestParam("expectedbody") String expectedbody, @RequestBody String body) { + ResponseEntity response = retry(key, count); + if (!expectedbody.equals(body)) { + AtomicInteger num = getCount(key); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .header("X-Retry-Count", String.valueOf(num)) + .body("bodys did not match on try" + num); + } + return response; + } + @RequestMapping("/httpbin/retry") public ResponseEntity retry(@RequestParam("key") String key, @RequestParam(name = "count", defaultValue = "3") int count) { - AtomicInteger num = map.computeIfAbsent(key, s -> new AtomicInteger()); + AtomicInteger num = getCount(key); int i = num.incrementAndGet(); log.warn("Retry count: " + i); String body = String.valueOf(i); @@ -142,6 +157,10 @@ public class RetryGatewayFilterFactoryIntegrationTests extends BaseWebClientTest .body(body); } + AtomicInteger getCount(@RequestParam("key") String key) { + return map.computeIfAbsent(key, s -> new AtomicInteger()); + } + @Bean public RouteLocator hystrixRouteLocator(RouteLocatorBuilder builder) { return builder.routes()