1717package org .springframework .boot .actuate .endpoint .invoker .cache ;
1818
1919import java .security .Principal ;
20+ import java .time .Duration ;
2021import java .util .Arrays ;
2122import java .util .Collections ;
2223import java .util .HashMap ;
4849 */
4950public class CachingOperationInvokerTests {
5051
52+ private static final long CACHE_TTL = Duration .ofHours (1 ).toMillis ();
53+
5154 @ Test
5255 public void createInstanceWithTtlSetToZero () {
5356 assertThatIllegalArgumentException ()
@@ -73,7 +76,7 @@ public void cacheInTtlWithMonoResponse() {
7376 MonoOperationInvoker .invocations = 0 ;
7477 MonoOperationInvoker target = new MonoOperationInvoker ();
7578 InvocationContext context = new InvocationContext (mock (SecurityContext .class ), Collections .emptyMap ());
76- CachingOperationInvoker invoker = new CachingOperationInvoker (target , 500L );
79+ CachingOperationInvoker invoker = new CachingOperationInvoker (target , CACHE_TTL );
7780 Object response = ((Mono <?>) invoker .invoke (context )).block ();
7881 Object cachedResponse = ((Mono <?>) invoker .invoke (context )).block ();
7982 assertThat (MonoOperationInvoker .invocations ).isEqualTo (1 );
@@ -85,7 +88,7 @@ public void cacheInTtlWithFluxResponse() {
8588 FluxOperationInvoker .invocations = 0 ;
8689 FluxOperationInvoker target = new FluxOperationInvoker ();
8790 InvocationContext context = new InvocationContext (mock (SecurityContext .class ), Collections .emptyMap ());
88- CachingOperationInvoker invoker = new CachingOperationInvoker (target , 500L );
91+ CachingOperationInvoker invoker = new CachingOperationInvoker (target , CACHE_TTL );
8992 Object response = ((Flux <?>) invoker .invoke (context )).blockLast ();
9093 Object cachedResponse = ((Flux <?>) invoker .invoke (context )).blockLast ();
9194 assertThat (FluxOperationInvoker .invocations ).isEqualTo (1 );
@@ -97,7 +100,7 @@ private void assertCacheIsUsed(Map<String, Object> parameters) {
97100 Object expected = new Object ();
98101 InvocationContext context = new InvocationContext (mock (SecurityContext .class ), parameters );
99102 given (target .invoke (context )).willReturn (expected );
100- CachingOperationInvoker invoker = new CachingOperationInvoker (target , 500L );
103+ CachingOperationInvoker invoker = new CachingOperationInvoker (target , CACHE_TTL );
101104 Object response = invoker .invoke (context );
102105 assertThat (response ).isSameAs (expected );
103106 verify (target , times (1 )).invoke (context );
@@ -114,7 +117,7 @@ public void targetAlwaysInvokedWithParameters() {
114117 parameters .put ("something" , null );
115118 InvocationContext context = new InvocationContext (mock (SecurityContext .class ), parameters );
116119 given (target .invoke (context )).willReturn (new Object ());
117- CachingOperationInvoker invoker = new CachingOperationInvoker (target , 500L );
120+ CachingOperationInvoker invoker = new CachingOperationInvoker (target , CACHE_TTL );
118121 invoker .invoke (context );
119122 invoker .invoke (context );
120123 invoker .invoke (context );
@@ -129,7 +132,7 @@ public void targetAlwaysInvokedWithPrincipal() {
129132 given (securityContext .getPrincipal ()).willReturn (mock (Principal .class ));
130133 InvocationContext context = new InvocationContext (securityContext , parameters );
131134 given (target .invoke (context )).willReturn (new Object ());
132- CachingOperationInvoker invoker = new CachingOperationInvoker (target , 500L );
135+ CachingOperationInvoker invoker = new CachingOperationInvoker (target , CACHE_TTL );
133136 invoker .invoke (context );
134137 invoker .invoke (context );
135138 invoker .invoke (context );
0 commit comments