add toString info

Signed-off-by: joecqupt <joe469391363@gmail.com>
This commit is contained in:
joecqupt
2025-03-15 13:47:18 +08:00
parent 8b5bc32456
commit 5e9753efb6
2 changed files with 39 additions and 16 deletions

View File

@@ -42,6 +42,7 @@ import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.support.HasRouteId;
import org.springframework.cloud.gateway.support.ServerWebExchangeUtils;
import org.springframework.cloud.gateway.support.TimeoutException;
import org.springframework.core.style.ToStringCreator;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatus.Series;
@@ -135,7 +136,6 @@ public class RetryGatewayFilterFactory extends AbstractGatewayFilterFactory<Retr
}
}
Retry<ServerWebExchange> exceptionRetry = null;
if (!retryConfig.getExceptions().isEmpty()) {
Predicate<RetryContext<ServerWebExchange>> retryContextPredicate = context -> {
@@ -196,6 +196,9 @@ public class RetryGatewayFilterFactory extends AbstractGatewayFilterFactory<Retr
.append("statuses", retryConfig.getStatuses())
.append("methods", retryConfig.getMethods())
.append("exceptions", retryConfig.getExceptions())
.append("backoff", retryConfig.getBackoff())
.append("jitter", retryConfig.getJitter())
.append("timeout", retryConfig.getTimeout())
.toString();
}
};
@@ -490,6 +493,15 @@ public class RetryGatewayFilterFactory extends AbstractGatewayFilterFactory<Retr
this.basedOnPreviousValue = basedOnPreviousValue;
}
@Override
public String toString() {
return new ToStringCreator(this).append("firstBackoff", firstBackoff)
.append("maxBackoff", maxBackoff)
.append("factor", factor)
.append("basedOnPreviousValue", basedOnPreviousValue)
.toString();
}
}
public static class JitterConfig {
@@ -516,6 +528,12 @@ public class RetryGatewayFilterFactory extends AbstractGatewayFilterFactory<Retr
this.randomFactor = randomFactor;
}
@Override
public String toString() {
return new ToStringCreator(this).append("randomFactor", randomFactor).toString();
}
}
}

View File

@@ -125,11 +125,11 @@ public class RetryGatewayFilterFactoryIntegrationTests extends BaseWebClientTest
public void retryWithBackoffTimeout() {
// backoff > timeout
testClient.get()
.uri("/retry?key=retry-with-backoff-timeout&count=3")
.header(HttpHeaders.HOST, "www.retrywithbackofftimeout.org")
.exchange()
.expectStatus()
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
.uri("/retry?key=retry-with-backoff-timeout&count=3")
.header(HttpHeaders.HOST, "www.retrywithbackofftimeout.org")
.exchange()
.expectStatus()
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
}
@Test
@@ -386,16 +386,21 @@ public class RetryGatewayFilterFactoryIntegrationTests extends BaseWebClientTest
r -> r.host("**.retrywithbackoff.org").filters(f -> f.prefixPath("/httpbin").retry(config -> {
config.setRetries(2).setBackoff(Duration.ofMillis(100), null, 2, true);
})).uri(uri))
.route("retry_with_backoff_jitter_timeout_test",
r -> r.host("**.retrywithbackoffjittertimeout.org").filters(f -> f.prefixPath("/httpbin").retry(config -> {
config.setRetries(3).setBackoff(Duration.ofMillis(50), Duration.ofMillis(100), 2, true)
.setJitter(0.1).setTimeout(Duration.ofMillis(1000));
})).uri(uri))
.route("retry_with_backoff_timeout_test",
r -> r.host("**.retrywithbackofftimeout.org").filters(f -> f.prefixPath("/httpbin").retry(config -> {
config.setRetries(3).setBackoff(Duration.ofMillis(100), null, 2, true)
.setTimeout(Duration.ofMillis(100));
})).uri(uri))
.route("retry_with_backoff_jitter_timeout_test", r -> r.host("**.retrywithbackoffjittertimeout.org")
.filters(f -> f.prefixPath("/httpbin").retry(config -> {
config.setRetries(3)
.setBackoff(Duration.ofMillis(50), Duration.ofMillis(100), 2, true)
.setJitter(0.1)
.setTimeout(Duration.ofMillis(1000));
}))
.uri(uri))
.route("retry_with_backoff_timeout_test", r -> r.host("**.retrywithbackofftimeout.org")
.filters(f -> f.prefixPath("/httpbin").retry(config -> {
config.setRetries(3)
.setBackoff(Duration.ofMillis(100), null, 2, true)
.setTimeout(Duration.ofMillis(100));
}))
.uri(uri))
.route("retry_with_loadbalancer",
r -> r.host("**.retrywithloadbalancer.org")