mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish
This commit is contained in:
parent
0d904666a7
commit
6490edc16d
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 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();
|
||||||
@ -94,10 +91,7 @@ class HttpTraceWebFilterTests {
|
|||||||
return Mono.just(principal);
|
return Mono.just(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();
|
||||||
@ -105,8 +99,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…
Reference in New Issue
Block a user