Skip to content

Commit 8b5bc32

Browse files
committed
add unit-test
Signed-off-by: jiangyuan <[email protected]>
1 parent 9eb9165 commit 8b5bc32

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactory.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ public GatewayFilter apply(RetryConfig retryConfig) {
173173
}
174174
JitterConfig jitter = retryConfig.getJitter();
175175
if (jitter != null) {
176-
statusCodeRepeat = statusCodeRepeat.jitter(getJitter(jitter));
176+
exceptionRetry = exceptionRetry.jitter(getJitter(jitter));
177177
}
178178
Duration timeout = retryConfig.getTimeout();
179179
if (timeout != null) {
180-
statusCodeRepeat = statusCodeRepeat.timeout(timeout);
180+
exceptionRetry = exceptionRetry.timeout(timeout);
181181
}
182182
}
183183

@@ -357,6 +357,11 @@ public RetryConfig setJitter(JitterConfig jitter) {
357357
return this;
358358
}
359359

360+
public RetryConfig setJitter(double randomFactor) {
361+
this.jitter = new JitterConfig(randomFactor);
362+
return this;
363+
}
364+
360365
public BackoffConfig getBackoff() {
361366
return backoff;
362367
}

spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ public void retryWithBackoffJitterTimeout() {
121121
// @formatter:on
122122
}
123123

124+
@Test
125+
public void retryWithBackoffTimeout() {
126+
// backoff > timeout
127+
testClient.get()
128+
.uri("/retry?key=retry-with-backoff-timeout&count=3")
129+
.header(HttpHeaders.HOST, "www.retrywithbackofftimeout.org")
130+
.exchange()
131+
.expectStatus()
132+
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
133+
}
134+
124135
@Test
125136
public void retryFilterGetJavaDsl() {
126137
testClient.get()
@@ -375,6 +386,16 @@ public RouteLocator hystrixRouteLocator(RouteLocatorBuilder builder) {
375386
r -> r.host("**.retrywithbackoff.org").filters(f -> f.prefixPath("/httpbin").retry(config -> {
376387
config.setRetries(2).setBackoff(Duration.ofMillis(100), null, 2, true);
377388
})).uri(uri))
389+
.route("retry_with_backoff_jitter_timeout_test",
390+
r -> r.host("**.retrywithbackoffjittertimeout.org").filters(f -> f.prefixPath("/httpbin").retry(config -> {
391+
config.setRetries(3).setBackoff(Duration.ofMillis(50), Duration.ofMillis(100), 2, true)
392+
.setJitter(0.1).setTimeout(Duration.ofMillis(1000));
393+
})).uri(uri))
394+
.route("retry_with_backoff_timeout_test",
395+
r -> r.host("**.retrywithbackofftimeout.org").filters(f -> f.prefixPath("/httpbin").retry(config -> {
396+
config.setRetries(3).setBackoff(Duration.ofMillis(100), null, 2, true)
397+
.setTimeout(Duration.ofMillis(100));
398+
})).uri(uri))
378399

379400
.route("retry_with_loadbalancer",
380401
r -> r.host("**.retrywithloadbalancer.org")

spring-cloud-gateway-server/src/test/resources/application-retrytests.yml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,3 @@ spring:
2929
- name: Retry
3030
args:
3131
methods: GET,POST
32-
# =====================================
33-
- id: retry_with_backoff_jitter_timeout_test
34-
uri: ${test.uri}
35-
predicates:
36-
- Host=**.retrywithbackoffjittertimeout.org
37-
filters:
38-
- name: Retry
39-
args:
40-
retries: 3
41-
statuses: INTERNAL_SERVER_ERROR
42-
methods: GET
43-
backoff:
44-
firstBackoff: 10ms
45-
maxBackoff: 50ms
46-
factor: 2
47-
basedOnPreviousValue: false
48-
jitter:
49-
randomFactor: 0.5
50-
timeout: 200ms

0 commit comments

Comments
 (0)