Skip to content

Commit 6aeff91

Browse files
committed
Polish
1 parent 29bc5d8 commit 6aeff91

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoker/cache/CachingOperationInvokerTests.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,10 +18,10 @@
1818

1919
import java.security.Principal;
2020
import java.time.Duration;
21-
import java.util.Arrays;
2221
import java.util.Collections;
2322
import java.util.HashMap;
2423
import java.util.Map;
24+
import java.util.concurrent.atomic.AtomicInteger;
2525

2626
import org.junit.Test;
2727
import reactor.core.publisher.Flux;
@@ -73,25 +73,25 @@ public void cacheInTtlWithNullParameters() {
7373

7474
@Test
7575
public void cacheInTtlWithMonoResponse() {
76-
MonoOperationInvoker.invocations = 0;
76+
MonoOperationInvoker.invocations = new AtomicInteger();
7777
MonoOperationInvoker target = new MonoOperationInvoker();
7878
InvocationContext context = new InvocationContext(mock(SecurityContext.class), Collections.emptyMap());
7979
CachingOperationInvoker invoker = new CachingOperationInvoker(target, CACHE_TTL);
8080
Object response = ((Mono<?>) invoker.invoke(context)).block();
8181
Object cachedResponse = ((Mono<?>) invoker.invoke(context)).block();
82-
assertThat(MonoOperationInvoker.invocations).isEqualTo(1);
82+
assertThat(MonoOperationInvoker.invocations).hasValue(1);
8383
assertThat(response).isSameAs(cachedResponse);
8484
}
8585

8686
@Test
8787
public void cacheInTtlWithFluxResponse() {
88-
FluxOperationInvoker.invocations = 0;
88+
FluxOperationInvoker.invocations = new AtomicInteger();
8989
FluxOperationInvoker target = new FluxOperationInvoker();
9090
InvocationContext context = new InvocationContext(mock(SecurityContext.class), Collections.emptyMap());
9191
CachingOperationInvoker invoker = new CachingOperationInvoker(target, CACHE_TTL);
9292
Object response = ((Flux<?>) invoker.invoke(context)).blockLast();
9393
Object cachedResponse = ((Flux<?>) invoker.invoke(context)).blockLast();
94-
assertThat(FluxOperationInvoker.invocations).isEqualTo(1);
94+
assertThat(FluxOperationInvoker.invocations).hasValue(1);
9595
assertThat(response).isSameAs(cachedResponse);
9696
}
9797

@@ -154,28 +154,25 @@ public void targetInvokedWhenCacheExpires() throws InterruptedException {
154154

155155
private static class MonoOperationInvoker implements OperationInvoker {
156156

157-
static int invocations;
157+
static AtomicInteger invocations = new AtomicInteger();
158158

159159
@Override
160-
public Object invoke(InvocationContext context) throws MissingParametersException {
160+
public Mono<String> invoke(InvocationContext context) throws MissingParametersException {
161161
return Mono.fromCallable(() -> {
162-
invocations++;
163-
return Mono.just("test");
162+
invocations.incrementAndGet();
163+
return "test";
164164
});
165165
}
166166

167167
}
168168

169169
private static class FluxOperationInvoker implements OperationInvoker {
170170

171-
static int invocations;
171+
static AtomicInteger invocations = new AtomicInteger();
172172

173173
@Override
174-
public Object invoke(InvocationContext context) throws MissingParametersException {
175-
return Flux.fromIterable(() -> {
176-
invocations++;
177-
return Arrays.asList("spring", "boot").iterator();
178-
});
174+
public Flux<String> invoke(InvocationContext context) throws MissingParametersException {
175+
return Flux.just("spring", "boot").hide().doFirst(invocations::incrementAndGet);
179176
}
180177

181178
}

0 commit comments

Comments
 (0)