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 ;
4950 */
5051class CachingOperationInvokerTests {
5152
53+ private static final long CACHE_TTL = Duration .ofHours (1 ).toMillis ();
54+
5255 @ Test
5356 void createInstanceWithTtlSetToZero () {
5457 assertThatIllegalArgumentException ()
@@ -74,7 +77,7 @@ void cacheInTtlWithMonoResponse() {
7477 MonoOperationInvoker .invocations = 0 ;
7578 MonoOperationInvoker target = new MonoOperationInvoker ();
7679 InvocationContext context = new InvocationContext (mock (SecurityContext .class ), Collections .emptyMap ());
77- CachingOperationInvoker invoker = new CachingOperationInvoker (target , 500L );
80+ CachingOperationInvoker invoker = new CachingOperationInvoker (target , CACHE_TTL );
7881 Object response = ((Mono <?>) invoker .invoke (context )).block ();
7982 Object cachedResponse = ((Mono <?>) invoker .invoke (context )).block ();
8083 assertThat (MonoOperationInvoker .invocations ).isEqualTo (1 );
@@ -86,7 +89,7 @@ void cacheInTtlWithFluxResponse() {
8689 FluxOperationInvoker .invocations = 0 ;
8790 FluxOperationInvoker target = new FluxOperationInvoker ();
8891 InvocationContext context = new InvocationContext (mock (SecurityContext .class ), Collections .emptyMap ());
89- CachingOperationInvoker invoker = new CachingOperationInvoker (target , 500L );
92+ CachingOperationInvoker invoker = new CachingOperationInvoker (target , CACHE_TTL );
9093 Object response = ((Flux <?>) invoker .invoke (context )).blockLast ();
9194 Object cachedResponse = ((Flux <?>) invoker .invoke (context )).blockLast ();
9295 assertThat (FluxOperationInvoker .invocations ).isEqualTo (1 );
@@ -98,7 +101,7 @@ private void assertCacheIsUsed(Map<String, Object> parameters) {
98101 Object expected = new Object ();
99102 InvocationContext context = new InvocationContext (mock (SecurityContext .class ), parameters );
100103 given (target .invoke (context )).willReturn (expected );
101- CachingOperationInvoker invoker = new CachingOperationInvoker (target , 500L );
104+ CachingOperationInvoker invoker = new CachingOperationInvoker (target , CACHE_TTL );
102105 Object response = invoker .invoke (context );
103106 assertThat (response ).isSameAs (expected );
104107 verify (target , times (1 )).invoke (context );
@@ -115,7 +118,7 @@ void targetAlwaysInvokedWithParameters() {
115118 parameters .put ("something" , null );
116119 InvocationContext context = new InvocationContext (mock (SecurityContext .class ), parameters );
117120 given (target .invoke (context )).willReturn (new Object ());
118- CachingOperationInvoker invoker = new CachingOperationInvoker (target , 500L );
121+ CachingOperationInvoker invoker = new CachingOperationInvoker (target , CACHE_TTL );
119122 invoker .invoke (context );
120123 invoker .invoke (context );
121124 invoker .invoke (context );
@@ -130,7 +133,7 @@ void targetAlwaysInvokedWithPrincipal() {
130133 given (securityContext .getPrincipal ()).willReturn (mock (Principal .class ));
131134 InvocationContext context = new InvocationContext (securityContext , parameters );
132135 given (target .invoke (context )).willReturn (new Object ());
133- CachingOperationInvoker invoker = new CachingOperationInvoker (target , 500L );
136+ CachingOperationInvoker invoker = new CachingOperationInvoker (target , CACHE_TTL );
134137 invoker .invoke (context );
135138 invoker .invoke (context );
136139 invoker .invoke (context );
@@ -164,7 +167,7 @@ void targetInvokedWithDifferentApiVersion() {
164167 Collections .emptyMap ());
165168 given (target .invoke (contextV2 )).willReturn (expectedV2 );
166169 given (target .invoke (contextV3 )).willReturn (expectedV3 );
167- CachingOperationInvoker invoker = new CachingOperationInvoker (target , 500L );
170+ CachingOperationInvoker invoker = new CachingOperationInvoker (target , CACHE_TTL );
168171 Object response = invoker .invoke (contextV2 );
169172 assertThat (response ).isSameAs (expectedV2 );
170173 verify (target , times (1 )).invoke (contextV2 );
0 commit comments