Commit 6aeff91f authored by Stephane Nicoll's avatar Stephane Nicoll

Polish

parent 29bc5d84
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 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();
});
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment