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
6aeff91f
Commit
6aeff91f
authored
Feb 20, 2020
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
29bc5d84
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
16 deletions
+13
-16
CachingOperationInvokerTests.java
.../endpoint/invoker/cache/CachingOperationInvokerTests.java
+13
-16
No files found.
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoker/cache/CachingOperationInvokerTests.java
View file @
6aeff91f
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -18,10 +18,10 @@ package org.springframework.boot.actuate.endpoint.invoker.cache;
...
@@ -18,10 +18,10 @@ package org.springframework.boot.actuate.endpoint.invoker.cache;
import
java.security.Principal
;
import
java.security.Principal
;
import
java.time.Duration
;
import
java.time.Duration
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
org.junit.Test
;
import
org.junit.Test
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Flux
;
...
@@ -73,25 +73,25 @@ public class CachingOperationInvokerTests {
...
@@ -73,25 +73,25 @@ public class CachingOperationInvokerTests {
@Test
@Test
public
void
cacheInTtlWithMonoResponse
()
{
public
void
cacheInTtlWithMonoResponse
()
{
MonoOperationInvoker
.
invocations
=
0
;
MonoOperationInvoker
.
invocations
=
new
AtomicInteger
()
;
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
,
CACHE_TTL
);
CachingOperationInvoker
invoker
=
new
CachingOperationInvoker
(
target
,
CACHE_TTL
);
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
).
hasValue
(
1
);
assertThat
(
response
).
isSameAs
(
cachedResponse
);
assertThat
(
response
).
isSameAs
(
cachedResponse
);
}
}
@Test
@Test
public
void
cacheInTtlWithFluxResponse
()
{
public
void
cacheInTtlWithFluxResponse
()
{
FluxOperationInvoker
.
invocations
=
0
;
FluxOperationInvoker
.
invocations
=
new
AtomicInteger
()
;
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
,
CACHE_TTL
);
CachingOperationInvoker
invoker
=
new
CachingOperationInvoker
(
target
,
CACHE_TTL
);
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
).
hasValue
(
1
);
assertThat
(
response
).
isSameAs
(
cachedResponse
);
assertThat
(
response
).
isSameAs
(
cachedResponse
);
}
}
...
@@ -154,13 +154,13 @@ public class CachingOperationInvokerTests {
...
@@ -154,13 +154,13 @@ public class CachingOperationInvokerTests {
private
static
class
MonoOperationInvoker
implements
OperationInvoker
{
private
static
class
MonoOperationInvoker
implements
OperationInvoker
{
static
int
invocations
;
static
AtomicInteger
invocations
=
new
AtomicInteger
()
;
@Override
@Override
public
Object
invoke
(
InvocationContext
context
)
throws
MissingParametersException
{
public
Mono
<
String
>
invoke
(
InvocationContext
context
)
throws
MissingParametersException
{
return
Mono
.
fromCallable
(()
->
{
return
Mono
.
fromCallable
(()
->
{
invocations
++
;
invocations
.
incrementAndGet
()
;
return
Mono
.
just
(
"test"
)
;
return
"test"
;
});
});
}
}
...
@@ -168,14 +168,11 @@ public class CachingOperationInvokerTests {
...
@@ -168,14 +168,11 @@ public class CachingOperationInvokerTests {
private
static
class
FluxOperationInvoker
implements
OperationInvoker
{
private
static
class
FluxOperationInvoker
implements
OperationInvoker
{
static
int
invocations
;
static
AtomicInteger
invocations
=
new
AtomicInteger
()
;
@Override
@Override
public
Object
invoke
(
InvocationContext
context
)
throws
MissingParametersException
{
public
Flux
<
String
>
invoke
(
InvocationContext
context
)
throws
MissingParametersException
{
return
Flux
.
fromIterable
(()
->
{
return
Flux
.
just
(
"spring"
,
"boot"
).
hide
().
doFirst
(
invocations:
:
incrementAndGet
);
invocations
++;
return
Arrays
.
asList
(
"spring"
,
"boot"
).
iterator
();
});
}
}
}
}
...
...
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