Merge branch '2.3.x' into 2.4.x

pull/26775/head
Stephane Nicoll 4 years ago
commit aea8597114

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,11 +17,11 @@
package org.springframework.boot.actuate.trace.http.reactive; package org.springframework.boot.actuate.trace.http.reactive;
import java.security.Principal; import java.security.Principal;
import java.time.Duration;
import java.util.EnumSet; import java.util.EnumSet;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import org.springframework.boot.actuate.trace.http.HttpExchangeTracer; import org.springframework.boot.actuate.trace.http.HttpExchangeTracer;
import org.springframework.boot.actuate.trace.http.HttpTrace.Session; import org.springframework.boot.actuate.trace.http.HttpTrace.Session;
@ -55,16 +55,15 @@ class HttpTraceWebFilterTests {
@Test @Test
void filterTracesExchange() { void filterTracesExchange() {
executeFilter(MockServerWebExchange.from(MockServerHttpRequest.get("https://api.example.com")), executeFilter(MockServerWebExchange.from(MockServerHttpRequest.get("https://api.example.com")),
(exchange) -> Mono.empty()).block(Duration.ofSeconds(30)); (exchange) -> Mono.empty());
assertThat(this.repository.findAll()).hasSize(1); assertThat(this.repository.findAll()).hasSize(1);
} }
@Test @Test
void filterCapturesSessionIdWhenSessionIsUsed() { void filterCapturesSessionIdWhenSessionIsUsed() {
executeFilter(MockServerWebExchange.from(MockServerHttpRequest.get("https://api.example.com")), (exchange) -> { executeFilter(MockServerWebExchange.from(MockServerHttpRequest.get("https://api.example.com")),
exchange.getSession().block(Duration.ofSeconds(30)).getAttributes().put("a", "alpha"); (exchange) -> exchange.getSession().doOnNext((session) -> session.getAttributes().put("a", "alpha"))
return Mono.empty(); .then());
}).block(Duration.ofSeconds(30));
assertThat(this.repository.findAll()).hasSize(1); assertThat(this.repository.findAll()).hasSize(1);
Session session = this.repository.findAll().get(0).getSession(); Session session = this.repository.findAll().get(0).getSession();
assertThat(session).isNotNull(); assertThat(session).isNotNull();
@ -73,10 +72,8 @@ class HttpTraceWebFilterTests {
@Test @Test
void filterDoesNotCaptureIdOfUnusedSession() { void filterDoesNotCaptureIdOfUnusedSession() {
executeFilter(MockServerWebExchange.from(MockServerHttpRequest.get("https://api.example.com")), (exchange) -> { executeFilter(MockServerWebExchange.from(MockServerHttpRequest.get("https://api.example.com")),
exchange.getSession().block(Duration.ofSeconds(30)); (exchange) -> exchange.getSession().then());
return Mono.empty();
}).block(Duration.ofSeconds(30));
assertThat(this.repository.findAll()).hasSize(1); assertThat(this.repository.findAll()).hasSize(1);
Session session = this.repository.findAll().get(0).getSession(); Session session = this.repository.findAll().get(0).getSession();
assertThat(session).isNull(); assertThat(session).isNull();
@ -95,10 +92,7 @@ class HttpTraceWebFilterTests {
return Mono.just((T) principal); return Mono.just((T) principal);
} }
}, (exchange) -> { }, (exchange) -> exchange.getSession().doOnNext((session) -> session.getAttributes().put("a", "alpha")).then());
exchange.getSession().block(Duration.ofSeconds(30)).getAttributes().put("a", "alpha");
return Mono.empty();
}).block(Duration.ofSeconds(30));
assertThat(this.repository.findAll()).hasSize(1); assertThat(this.repository.findAll()).hasSize(1);
org.springframework.boot.actuate.trace.http.HttpTrace.Principal tracedPrincipal = this.repository.findAll() org.springframework.boot.actuate.trace.http.HttpTrace.Principal tracedPrincipal = this.repository.findAll()
.get(0).getPrincipal(); .get(0).getPrincipal();
@ -106,8 +100,10 @@ class HttpTraceWebFilterTests {
assertThat(tracedPrincipal.getName()).isEqualTo("alice"); assertThat(tracedPrincipal.getName()).isEqualTo("alice");
} }
private Mono<Void> executeFilter(ServerWebExchange exchange, WebFilterChain chain) { private void executeFilter(ServerWebExchange exchange, WebFilterChain chain) {
return this.filter.filter(exchange, chain).then(Mono.defer(() -> exchange.getResponse().setComplete())); StepVerifier.create(
this.filter.filter(exchange, chain).then(Mono.defer(() -> exchange.getResponse().setComplete())))
.verifyComplete();
} }
} }

Loading…
Cancel
Save