mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Merge pull request #19193 from dreis2211
* pr/19193: Increase cache ttl in CachingOperationInvokerTests Closes gh-19193
This commit is contained in:
commit
a5b9c0f3e8
@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.actuate.endpoint.invoker.cache;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -48,6 +49,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
*/
|
||||
public class CachingOperationInvokerTests {
|
||||
|
||||
private static final long CACHE_TTL = Duration.ofHours(1).toMillis();
|
||||
|
||||
@Test
|
||||
public void createInstanceWithTtlSetToZero() {
|
||||
assertThatIllegalArgumentException()
|
||||
@ -73,7 +76,7 @@ public class CachingOperationInvokerTests {
|
||||
MonoOperationInvoker.invocations = 0;
|
||||
MonoOperationInvoker target = new MonoOperationInvoker();
|
||||
InvocationContext context = new InvocationContext(mock(SecurityContext.class), Collections.emptyMap());
|
||||
CachingOperationInvoker invoker = new CachingOperationInvoker(target, 500L);
|
||||
CachingOperationInvoker invoker = new CachingOperationInvoker(target, CACHE_TTL);
|
||||
Object response = ((Mono<?>) invoker.invoke(context)).block();
|
||||
Object cachedResponse = ((Mono<?>) invoker.invoke(context)).block();
|
||||
assertThat(MonoOperationInvoker.invocations).isEqualTo(1);
|
||||
@ -85,7 +88,7 @@ public class CachingOperationInvokerTests {
|
||||
FluxOperationInvoker.invocations = 0;
|
||||
FluxOperationInvoker target = new FluxOperationInvoker();
|
||||
InvocationContext context = new InvocationContext(mock(SecurityContext.class), Collections.emptyMap());
|
||||
CachingOperationInvoker invoker = new CachingOperationInvoker(target, 500L);
|
||||
CachingOperationInvoker invoker = new CachingOperationInvoker(target, CACHE_TTL);
|
||||
Object response = ((Flux<?>) invoker.invoke(context)).blockLast();
|
||||
Object cachedResponse = ((Flux<?>) invoker.invoke(context)).blockLast();
|
||||
assertThat(FluxOperationInvoker.invocations).isEqualTo(1);
|
||||
@ -97,7 +100,7 @@ public class CachingOperationInvokerTests {
|
||||
Object expected = new Object();
|
||||
InvocationContext context = new InvocationContext(mock(SecurityContext.class), parameters);
|
||||
given(target.invoke(context)).willReturn(expected);
|
||||
CachingOperationInvoker invoker = new CachingOperationInvoker(target, 500L);
|
||||
CachingOperationInvoker invoker = new CachingOperationInvoker(target, CACHE_TTL);
|
||||
Object response = invoker.invoke(context);
|
||||
assertThat(response).isSameAs(expected);
|
||||
verify(target, times(1)).invoke(context);
|
||||
@ -114,7 +117,7 @@ public class CachingOperationInvokerTests {
|
||||
parameters.put("something", null);
|
||||
InvocationContext context = new InvocationContext(mock(SecurityContext.class), parameters);
|
||||
given(target.invoke(context)).willReturn(new Object());
|
||||
CachingOperationInvoker invoker = new CachingOperationInvoker(target, 500L);
|
||||
CachingOperationInvoker invoker = new CachingOperationInvoker(target, CACHE_TTL);
|
||||
invoker.invoke(context);
|
||||
invoker.invoke(context);
|
||||
invoker.invoke(context);
|
||||
@ -129,7 +132,7 @@ public class CachingOperationInvokerTests {
|
||||
given(securityContext.getPrincipal()).willReturn(mock(Principal.class));
|
||||
InvocationContext context = new InvocationContext(securityContext, parameters);
|
||||
given(target.invoke(context)).willReturn(new Object());
|
||||
CachingOperationInvoker invoker = new CachingOperationInvoker(target, 500L);
|
||||
CachingOperationInvoker invoker = new CachingOperationInvoker(target, CACHE_TTL);
|
||||
invoker.invoke(context);
|
||||
invoker.invoke(context);
|
||||
invoker.invoke(context);
|
||||
|
Loading…
Reference in New Issue
Block a user