17
17
package org .springframework .boot .actuate .endpoint .invoker .cache ;
18
18
19
19
import java .security .Principal ;
20
+ import java .time .Duration ;
20
21
import java .util .Arrays ;
21
22
import java .util .Collections ;
22
23
import java .util .HashMap ;
48
49
*/
49
50
public class CachingOperationInvokerTests {
50
51
52
+ private static final long CACHE_TTL = Duration .ofHours (1 ).toMillis ();
53
+
51
54
@ Test
52
55
public void createInstanceWithTtlSetToZero () {
53
56
assertThatIllegalArgumentException ()
@@ -73,7 +76,7 @@ public void cacheInTtlWithMonoResponse() {
73
76
MonoOperationInvoker .invocations = 0 ;
74
77
MonoOperationInvoker target = new MonoOperationInvoker ();
75
78
InvocationContext context = new InvocationContext (mock (SecurityContext .class ), Collections .emptyMap ());
76
- CachingOperationInvoker invoker = new CachingOperationInvoker (target , 500L );
79
+ CachingOperationInvoker invoker = new CachingOperationInvoker (target , CACHE_TTL );
77
80
Object response = ((Mono <?>) invoker .invoke (context )).block ();
78
81
Object cachedResponse = ((Mono <?>) invoker .invoke (context )).block ();
79
82
assertThat (MonoOperationInvoker .invocations ).isEqualTo (1 );
@@ -85,7 +88,7 @@ public void cacheInTtlWithFluxResponse() {
85
88
FluxOperationInvoker .invocations = 0 ;
86
89
FluxOperationInvoker target = new FluxOperationInvoker ();
87
90
InvocationContext context = new InvocationContext (mock (SecurityContext .class ), Collections .emptyMap ());
88
- CachingOperationInvoker invoker = new CachingOperationInvoker (target , 500L );
91
+ CachingOperationInvoker invoker = new CachingOperationInvoker (target , CACHE_TTL );
89
92
Object response = ((Flux <?>) invoker .invoke (context )).blockLast ();
90
93
Object cachedResponse = ((Flux <?>) invoker .invoke (context )).blockLast ();
91
94
assertThat (FluxOperationInvoker .invocations ).isEqualTo (1 );
@@ -97,7 +100,7 @@ private void assertCacheIsUsed(Map<String, Object> parameters) {
97
100
Object expected = new Object ();
98
101
InvocationContext context = new InvocationContext (mock (SecurityContext .class ), parameters );
99
102
given (target .invoke (context )).willReturn (expected );
100
- CachingOperationInvoker invoker = new CachingOperationInvoker (target , 500L );
103
+ CachingOperationInvoker invoker = new CachingOperationInvoker (target , CACHE_TTL );
101
104
Object response = invoker .invoke (context );
102
105
assertThat (response ).isSameAs (expected );
103
106
verify (target , times (1 )).invoke (context );
@@ -114,7 +117,7 @@ public void targetAlwaysInvokedWithParameters() {
114
117
parameters .put ("something" , null );
115
118
InvocationContext context = new InvocationContext (mock (SecurityContext .class ), parameters );
116
119
given (target .invoke (context )).willReturn (new Object ());
117
- CachingOperationInvoker invoker = new CachingOperationInvoker (target , 500L );
120
+ CachingOperationInvoker invoker = new CachingOperationInvoker (target , CACHE_TTL );
118
121
invoker .invoke (context );
119
122
invoker .invoke (context );
120
123
invoker .invoke (context );
@@ -129,7 +132,7 @@ public void targetAlwaysInvokedWithPrincipal() {
129
132
given (securityContext .getPrincipal ()).willReturn (mock (Principal .class ));
130
133
InvocationContext context = new InvocationContext (securityContext , parameters );
131
134
given (target .invoke (context )).willReturn (new Object ());
132
- CachingOperationInvoker invoker = new CachingOperationInvoker (target , 500L );
135
+ CachingOperationInvoker invoker = new CachingOperationInvoker (target , CACHE_TTL );
133
136
invoker .invoke (context );
134
137
invoker .invoke (context );
135
138
invoker .invoke (context );
0 commit comments