Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
6490edc1
Commit
6490edc1
authored
Jun 04, 2021
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
0d904666
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
17 deletions
+13
-17
HttpTraceWebFilterTests.java
.../actuate/trace/http/reactive/HttpTraceWebFilterTests.java
+13
-17
No files found.
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/reactive/HttpTraceWebFilterTests.java
View file @
6490edc1
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
21
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 @@
...
@@ -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 {
...
@@ -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 {
...
@@ -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 {
...
@@ -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 {
...
@@ -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
();
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment