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
ed571bab
Commit
ed571bab
authored
Dec 05, 2019
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.1.x' into 2.2.x
Closes gh-19313
parents
9b0569cf
a5b9c0f3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
+9
-6
CachingOperationInvokerTests.java
.../endpoint/invoker/cache/CachingOperationInvokerTests.java
+9
-6
No files found.
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoker/cache/CachingOperationInvokerTests.java
View file @
ed571bab
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
package
org
.
springframework
.
boot
.
actuate
.
endpoint
.
invoker
.
cache
;
package
org
.
springframework
.
boot
.
actuate
.
endpoint
.
invoker
.
cache
;
import
java.security.Principal
;
import
java.security.Principal
;
import
java.time.Duration
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -49,6 +50,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
...
@@ -49,6 +50,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
*/
*/
class
CachingOperationInvokerTests
{
class
CachingOperationInvokerTests
{
private
static
final
long
CACHE_TTL
=
Duration
.
ofHours
(
1
).
toMillis
();
@Test
@Test
void
createInstanceWithTtlSetToZero
()
{
void
createInstanceWithTtlSetToZero
()
{
assertThatIllegalArgumentException
()
assertThatIllegalArgumentException
()
...
@@ -74,7 +77,7 @@ class CachingOperationInvokerTests {
...
@@ -74,7 +77,7 @@ class CachingOperationInvokerTests {
MonoOperationInvoker
.
invocations
=
0
;
MonoOperationInvoker
.
invocations
=
0
;
MonoOperationInvoker
target
=
new
MonoOperationInvoker
();
MonoOperationInvoker
target
=
new
MonoOperationInvoker
();
InvocationContext
context
=
new
InvocationContext
(
mock
(
SecurityContext
.
class
),
Collections
.
emptyMap
());
InvocationContext
context
=
new
InvocationContext
(
mock
(
SecurityContext
.
class
),
Collections
.
emptyMap
());
CachingOperationInvoker
invoker
=
new
CachingOperationInvoker
(
target
,
500
L
);
CachingOperationInvoker
invoker
=
new
CachingOperationInvoker
(
target
,
CACHE_TT
L
);
Object
response
=
((
Mono
<?>)
invoker
.
invoke
(
context
)).
block
();
Object
response
=
((
Mono
<?>)
invoker
.
invoke
(
context
)).
block
();
Object
cachedResponse
=
((
Mono
<?>)
invoker
.
invoke
(
context
)).
block
();
Object
cachedResponse
=
((
Mono
<?>)
invoker
.
invoke
(
context
)).
block
();
assertThat
(
MonoOperationInvoker
.
invocations
).
isEqualTo
(
1
);
assertThat
(
MonoOperationInvoker
.
invocations
).
isEqualTo
(
1
);
...
@@ -86,7 +89,7 @@ class CachingOperationInvokerTests {
...
@@ -86,7 +89,7 @@ class CachingOperationInvokerTests {
FluxOperationInvoker
.
invocations
=
0
;
FluxOperationInvoker
.
invocations
=
0
;
FluxOperationInvoker
target
=
new
FluxOperationInvoker
();
FluxOperationInvoker
target
=
new
FluxOperationInvoker
();
InvocationContext
context
=
new
InvocationContext
(
mock
(
SecurityContext
.
class
),
Collections
.
emptyMap
());
InvocationContext
context
=
new
InvocationContext
(
mock
(
SecurityContext
.
class
),
Collections
.
emptyMap
());
CachingOperationInvoker
invoker
=
new
CachingOperationInvoker
(
target
,
500
L
);
CachingOperationInvoker
invoker
=
new
CachingOperationInvoker
(
target
,
CACHE_TT
L
);
Object
response
=
((
Flux
<?>)
invoker
.
invoke
(
context
)).
blockLast
();
Object
response
=
((
Flux
<?>)
invoker
.
invoke
(
context
)).
blockLast
();
Object
cachedResponse
=
((
Flux
<?>)
invoker
.
invoke
(
context
)).
blockLast
();
Object
cachedResponse
=
((
Flux
<?>)
invoker
.
invoke
(
context
)).
blockLast
();
assertThat
(
FluxOperationInvoker
.
invocations
).
isEqualTo
(
1
);
assertThat
(
FluxOperationInvoker
.
invocations
).
isEqualTo
(
1
);
...
@@ -98,7 +101,7 @@ class CachingOperationInvokerTests {
...
@@ -98,7 +101,7 @@ class CachingOperationInvokerTests {
Object
expected
=
new
Object
();
Object
expected
=
new
Object
();
InvocationContext
context
=
new
InvocationContext
(
mock
(
SecurityContext
.
class
),
parameters
);
InvocationContext
context
=
new
InvocationContext
(
mock
(
SecurityContext
.
class
),
parameters
);
given
(
target
.
invoke
(
context
)).
willReturn
(
expected
);
given
(
target
.
invoke
(
context
)).
willReturn
(
expected
);
CachingOperationInvoker
invoker
=
new
CachingOperationInvoker
(
target
,
500
L
);
CachingOperationInvoker
invoker
=
new
CachingOperationInvoker
(
target
,
CACHE_TT
L
);
Object
response
=
invoker
.
invoke
(
context
);
Object
response
=
invoker
.
invoke
(
context
);
assertThat
(
response
).
isSameAs
(
expected
);
assertThat
(
response
).
isSameAs
(
expected
);
verify
(
target
,
times
(
1
)).
invoke
(
context
);
verify
(
target
,
times
(
1
)).
invoke
(
context
);
...
@@ -115,7 +118,7 @@ class CachingOperationInvokerTests {
...
@@ -115,7 +118,7 @@ class CachingOperationInvokerTests {
parameters
.
put
(
"something"
,
null
);
parameters
.
put
(
"something"
,
null
);
InvocationContext
context
=
new
InvocationContext
(
mock
(
SecurityContext
.
class
),
parameters
);
InvocationContext
context
=
new
InvocationContext
(
mock
(
SecurityContext
.
class
),
parameters
);
given
(
target
.
invoke
(
context
)).
willReturn
(
new
Object
());
given
(
target
.
invoke
(
context
)).
willReturn
(
new
Object
());
CachingOperationInvoker
invoker
=
new
CachingOperationInvoker
(
target
,
500
L
);
CachingOperationInvoker
invoker
=
new
CachingOperationInvoker
(
target
,
CACHE_TT
L
);
invoker
.
invoke
(
context
);
invoker
.
invoke
(
context
);
invoker
.
invoke
(
context
);
invoker
.
invoke
(
context
);
invoker
.
invoke
(
context
);
invoker
.
invoke
(
context
);
...
@@ -130,7 +133,7 @@ class CachingOperationInvokerTests {
...
@@ -130,7 +133,7 @@ class CachingOperationInvokerTests {
given
(
securityContext
.
getPrincipal
()).
willReturn
(
mock
(
Principal
.
class
));
given
(
securityContext
.
getPrincipal
()).
willReturn
(
mock
(
Principal
.
class
));
InvocationContext
context
=
new
InvocationContext
(
securityContext
,
parameters
);
InvocationContext
context
=
new
InvocationContext
(
securityContext
,
parameters
);
given
(
target
.
invoke
(
context
)).
willReturn
(
new
Object
());
given
(
target
.
invoke
(
context
)).
willReturn
(
new
Object
());
CachingOperationInvoker
invoker
=
new
CachingOperationInvoker
(
target
,
500
L
);
CachingOperationInvoker
invoker
=
new
CachingOperationInvoker
(
target
,
CACHE_TT
L
);
invoker
.
invoke
(
context
);
invoker
.
invoke
(
context
);
invoker
.
invoke
(
context
);
invoker
.
invoke
(
context
);
invoker
.
invoke
(
context
);
invoker
.
invoke
(
context
);
...
@@ -164,7 +167,7 @@ class CachingOperationInvokerTests {
...
@@ -164,7 +167,7 @@ class CachingOperationInvokerTests {
Collections
.
emptyMap
());
Collections
.
emptyMap
());
given
(
target
.
invoke
(
contextV2
)).
willReturn
(
expectedV2
);
given
(
target
.
invoke
(
contextV2
)).
willReturn
(
expectedV2
);
given
(
target
.
invoke
(
contextV3
)).
willReturn
(
expectedV3
);
given
(
target
.
invoke
(
contextV3
)).
willReturn
(
expectedV3
);
CachingOperationInvoker
invoker
=
new
CachingOperationInvoker
(
target
,
500
L
);
CachingOperationInvoker
invoker
=
new
CachingOperationInvoker
(
target
,
CACHE_TT
L
);
Object
response
=
invoker
.
invoke
(
contextV2
);
Object
response
=
invoker
.
invoke
(
contextV2
);
assertThat
(
response
).
isSameAs
(
expectedV2
);
assertThat
(
response
).
isSameAs
(
expectedV2
);
verify
(
target
,
times
(
1
)).
invoke
(
contextV2
);
verify
(
target
,
times
(
1
)).
invoke
(
contextV2
);
...
...
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