Replaces doOnSuccessOrError with doOnSuccess or doOnError

fixes gh-1538
This commit is contained in:
Spencer Gibb
2020-03-13 22:19:35 -04:00
parent a54b9b88e5
commit 2a7426025e
3 changed files with 18 additions and 14 deletions

View File

@@ -70,9 +70,9 @@ public class GatewayMetricsFilter implements GlobalFilter, Ordered {
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
Sample sample = Timer.start(meterRegistry);
return chain.filter(exchange).doOnSuccessOrError((aVoid, ex) -> {
endTimerRespectingCommit(exchange, sample);
});
return chain.filter(exchange)
.doOnSuccess(aVoid -> endTimerRespectingCommit(exchange, sample))
.doOnError(throwable -> endTimerRespectingCommit(exchange, sample));
}
private void endTimerRespectingCommit(ServerWebExchange exchange, Sample sample) {

View File

@@ -238,13 +238,8 @@ public class RetryGatewayFilterFactory
// chain.filter returns a Mono<Void>
Publisher<Void> publisher = chain.filter(exchange)
// .log("retry-filter", Level.INFO)
.doOnSuccessOrError((aVoid, throwable) -> {
int iteration = exchange
.getAttributeOrDefault(RETRY_ITERATION_KEY, -1);
int newIteration = iteration + 1;
trace("setting new iteration in attr %d", () -> newIteration);
exchange.getAttributes().put(RETRY_ITERATION_KEY, newIteration);
});
.doOnSuccess(aVoid -> updateIteration(exchange))
.doOnError(throwable -> updateIteration(exchange));
if (retry != null) {
// retryWhen returns a Mono<Void>
@@ -263,6 +258,13 @@ public class RetryGatewayFilterFactory
};
}
private void updateIteration(ServerWebExchange exchange) {
int iteration = exchange.getAttributeOrDefault(RETRY_ITERATION_KEY, -1);
int newIteration = iteration + 1;
trace("setting new iteration in attr %d", () -> newIteration);
exchange.getAttributes().put(RETRY_ITERATION_KEY, newIteration);
}
@SafeVarargs
private final void trace(String message, Supplier<Object>... argSuppliers) {
if (log.isTraceEnabled()) {

View File

@@ -175,8 +175,9 @@ public class WebSocketIntegrationTests {
.thenMany(session.receive().take(count)
.map(WebSocketMessage::getPayloadAsText))
.subscribeWith(output).doOnNext(s -> logger.debug("inbound " + s))
.then().doOnSuccessOrError((aVoid, ex) -> logger.debug(
"Done with " + (ex != null ? ex.getMessage() : "success")));
.then().doOnSuccess(aVoid -> logger.debug("Done with success"))
.doOnError(ex -> logger.debug(
"Done with " + (ex != null ? ex.getMessage() : "error")));
}).block(Duration.ofMillis(5000));
assertThat(output.collectList().block(Duration.ofMillis(5000)))
@@ -197,8 +198,9 @@ public class WebSocketIntegrationTests {
.thenMany(session.receive().take(count)
.map(WebSocketMessage::getPayloadAsText))
.subscribeWith(output).doOnNext(s -> logger.debug("inbound " + s))
.then().doOnSuccessOrError((aVoid, ex) -> logger.debug(
"Done with " + (ex != null ? ex.getMessage() : "success")));
.then().doOnSuccess(aVoid -> logger.debug("Done with success"))
.doOnError(ex -> logger.debug(
"Done with " + (ex != null ? ex.getMessage() : "error")));
}).block(Duration.ofMillis(5000));
assertThat(output.collectList().block(Duration.ofMillis(5000)))