Skip to content

Commit aea8597

Browse files
committed
Merge branch '2.3.x' into 2.4.x
2 parents 0da0d2d + 6490edc commit aea8597

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/reactive/HttpTraceWebFilterTests.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,11 +17,11 @@
1717
package org.springframework.boot.actuate.trace.http.reactive;
1818

1919
import java.security.Principal;
20-
import java.time.Duration;
2120
import java.util.EnumSet;
2221

2322
import org.junit.jupiter.api.Test;
2423
import reactor.core.publisher.Mono;
24+
import reactor.test.StepVerifier;
2525

2626
import org.springframework.boot.actuate.trace.http.HttpExchangeTracer;
2727
import org.springframework.boot.actuate.trace.http.HttpTrace.Session;
@@ -55,16 +55,15 @@ class HttpTraceWebFilterTests {
5555
@Test
5656
void filterTracesExchange() {
5757
executeFilter(MockServerWebExchange.from(MockServerHttpRequest.get("https://api.example.com")),
58-
(exchange) -> Mono.empty()).block(Duration.ofSeconds(30));
58+
(exchange) -> Mono.empty());
5959
assertThat(this.repository.findAll()).hasSize(1);
6060
}
6161

6262
@Test
6363
void filterCapturesSessionIdWhenSessionIsUsed() {
64-
executeFilter(MockServerWebExchange.from(MockServerHttpRequest.get("https://api.example.com")), (exchange) -> {
65-
exchange.getSession().block(Duration.ofSeconds(30)).getAttributes().put("a", "alpha");
66-
return Mono.empty();
67-
}).block(Duration.ofSeconds(30));
64+
executeFilter(MockServerWebExchange.from(MockServerHttpRequest.get("https://api.example.com")),
65+
(exchange) -> exchange.getSession().doOnNext((session) -> session.getAttributes().put("a", "alpha"))
66+
.then());
6867
assertThat(this.repository.findAll()).hasSize(1);
6968
Session session = this.repository.findAll().get(0).getSession();
7069
assertThat(session).isNotNull();
@@ -73,10 +72,8 @@ void filterCapturesSessionIdWhenSessionIsUsed() {
7372

7473
@Test
7574
void filterDoesNotCaptureIdOfUnusedSession() {
76-
executeFilter(MockServerWebExchange.from(MockServerHttpRequest.get("https://api.example.com")), (exchange) -> {
77-
exchange.getSession().block(Duration.ofSeconds(30));
78-
return Mono.empty();
79-
}).block(Duration.ofSeconds(30));
75+
executeFilter(MockServerWebExchange.from(MockServerHttpRequest.get("https://api.example.com")),
76+
(exchange) -> exchange.getSession().then());
8077
assertThat(this.repository.findAll()).hasSize(1);
8178
Session session = this.repository.findAll().get(0).getSession();
8279
assertThat(session).isNull();
@@ -95,19 +92,18 @@ public <T extends Principal> Mono<T> getPrincipal() {
9592
return Mono.just((T) principal);
9693
}
9794

98-
}, (exchange) -> {
99-
exchange.getSession().block(Duration.ofSeconds(30)).getAttributes().put("a", "alpha");
100-
return Mono.empty();
101-
}).block(Duration.ofSeconds(30));
95+
}, (exchange) -> exchange.getSession().doOnNext((session) -> session.getAttributes().put("a", "alpha")).then());
10296
assertThat(this.repository.findAll()).hasSize(1);
10397
org.springframework.boot.actuate.trace.http.HttpTrace.Principal tracedPrincipal = this.repository.findAll()
10498
.get(0).getPrincipal();
10599
assertThat(tracedPrincipal).isNotNull();
106100
assertThat(tracedPrincipal.getName()).isEqualTo("alice");
107101
}
108102

109-
private Mono<Void> executeFilter(ServerWebExchange exchange, WebFilterChain chain) {
110-
return this.filter.filter(exchange, chain).then(Mono.defer(() -> exchange.getResponse().setComplete()));
103+
private void executeFilter(ServerWebExchange exchange, WebFilterChain chain) {
104+
StepVerifier.create(
105+
this.filter.filter(exchange, chain).then(Mono.defer(() -> exchange.getResponse().setComplete())))
106+
.verifyComplete();
111107
}
112108

113109
}

0 commit comments

Comments
 (0)