Skip to content

Commit 5e9753e

Browse files
committed
add toString info
Signed-off-by: joecqupt <[email protected]>
1 parent 8b5bc32 commit 5e9753e

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.springframework.cloud.gateway.support.HasRouteId;
4343
import org.springframework.cloud.gateway.support.ServerWebExchangeUtils;
4444
import org.springframework.cloud.gateway.support.TimeoutException;
45+
import org.springframework.core.style.ToStringCreator;
4546
import org.springframework.http.HttpMethod;
4647
import org.springframework.http.HttpStatus;
4748
import org.springframework.http.HttpStatus.Series;
@@ -135,7 +136,6 @@ public GatewayFilter apply(RetryConfig retryConfig) {
135136
}
136137
}
137138

138-
139139
Retry<ServerWebExchange> exceptionRetry = null;
140140
if (!retryConfig.getExceptions().isEmpty()) {
141141
Predicate<RetryContext<ServerWebExchange>> retryContextPredicate = context -> {
@@ -196,6 +196,9 @@ public String toString() {
196196
.append("statuses", retryConfig.getStatuses())
197197
.append("methods", retryConfig.getMethods())
198198
.append("exceptions", retryConfig.getExceptions())
199+
.append("backoff", retryConfig.getBackoff())
200+
.append("jitter", retryConfig.getJitter())
201+
.append("timeout", retryConfig.getTimeout())
199202
.toString();
200203
}
201204
};
@@ -490,6 +493,15 @@ public void setBasedOnPreviousValue(boolean basedOnPreviousValue) {
490493
this.basedOnPreviousValue = basedOnPreviousValue;
491494
}
492495

496+
@Override
497+
public String toString() {
498+
return new ToStringCreator(this).append("firstBackoff", firstBackoff)
499+
.append("maxBackoff", maxBackoff)
500+
.append("factor", factor)
501+
.append("basedOnPreviousValue", basedOnPreviousValue)
502+
.toString();
503+
}
504+
493505
}
494506

495507
public static class JitterConfig {
@@ -516,6 +528,12 @@ public void setRandomFactor(double randomFactor) {
516528
this.randomFactor = randomFactor;
517529
}
518530

531+
@Override
532+
public String toString() {
533+
return new ToStringCreator(this).append("randomFactor", randomFactor).toString();
534+
535+
}
536+
519537
}
520538

521539
}

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ public void retryWithBackoffJitterTimeout() {
125125
public void retryWithBackoffTimeout() {
126126
// backoff > timeout
127127
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);
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);
133133
}
134134

135135
@Test
@@ -386,16 +386,21 @@ public RouteLocator hystrixRouteLocator(RouteLocatorBuilder builder) {
386386
r -> r.host("**.retrywithbackoff.org").filters(f -> f.prefixPath("/httpbin").retry(config -> {
387387
config.setRetries(2).setBackoff(Duration.ofMillis(100), null, 2, true);
388388
})).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))
389+
.route("retry_with_backoff_jitter_timeout_test", r -> r.host("**.retrywithbackoffjittertimeout.org")
390+
.filters(f -> f.prefixPath("/httpbin").retry(config -> {
391+
config.setRetries(3)
392+
.setBackoff(Duration.ofMillis(50), Duration.ofMillis(100), 2, true)
393+
.setJitter(0.1)
394+
.setTimeout(Duration.ofMillis(1000));
395+
}))
396+
.uri(uri))
397+
.route("retry_with_backoff_timeout_test", r -> r.host("**.retrywithbackofftimeout.org")
398+
.filters(f -> f.prefixPath("/httpbin").retry(config -> {
399+
config.setRetries(3)
400+
.setBackoff(Duration.ofMillis(100), null, 2, true)
401+
.setTimeout(Duration.ofMillis(100));
402+
}))
403+
.uri(uri))
399404

400405
.route("retry_with_loadbalancer",
401406
r -> r.host("**.retrywithloadbalancer.org")

0 commit comments

Comments
 (0)