Skip to content

Commit 7695266

Browse files
Fix CloudWatchMeterRegistryTest to be Java 8 compatible
See gh-4775
1 parent 34d72ad commit 7695266

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

implementations/micrometer-registry-cloudwatch2/src/main/java/io/micrometer/cloudwatch2/CloudWatchMeterRegistry.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ void sendMetricData(List<MetricDatum> metricData) throws InterruptedException {
132132
try {
133133
@SuppressWarnings("deprecation")
134134
long readTimeoutMillis = config.readTimeout().toMillis();
135-
boolean success = latch.await(readTimeoutMillis, TimeUnit.MILLISECONDS);
136-
if (!success) {
135+
boolean awaitSuccess = latch.await(readTimeoutMillis, TimeUnit.MILLISECONDS);
136+
if (!awaitSuccess) {
137137
logger.warn("metrics push to cloudwatch took longer than expected");
138138
}
139139
}

implementations/micrometer-registry-cloudwatch2/src/test/java/io/micrometer/cloudwatch2/CloudWatchMeterRegistryTest.java

+15-9
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
import java.util.ArrayList;
2929
import java.util.Arrays;
3030
import java.util.List;
31-
import java.util.concurrent.CompletableFuture;
32-
import java.util.concurrent.TimeUnit;
31+
import java.util.concurrent.*;
3332
import java.util.concurrent.atomic.AtomicReference;
3433
import java.util.function.Predicate;
3534
import java.util.function.Supplier;
@@ -287,8 +286,9 @@ void putMetricDataShouldBeCalledOnPublish() {
287286
@Test
288287
void shouldHandleAbortedExceptionDuringPutMetricDataCallWithoutFailing() {
289288
CloudWatchAsyncClient client = mock(CloudWatchAsyncClient.class);
290-
when(client.putMetricData(isA(PutMetricDataRequest.class)))
291-
.thenReturn(CompletableFuture.failedFuture(AbortedException.create("simulated")));
289+
CompletableFuture<PutMetricDataResponse> future = new CompletableFuture<>();
290+
future.completeExceptionally(AbortedException.create("simulated"));
291+
when(client.putMetricData(isA(PutMetricDataRequest.class))).thenReturn(future);
292292

293293
CloudWatchMeterRegistry registry = new CloudWatchMeterRegistry(config, clock, client);
294294
registry.counter("test").increment();
@@ -300,8 +300,9 @@ void shouldHandleAbortedExceptionDuringPutMetricDataCallWithoutFailing() {
300300
@Test
301301
void shouldHandleExceptionsDuringPutMetricDataCallWithoutFailing() {
302302
CloudWatchAsyncClient client = mock(CloudWatchAsyncClient.class);
303-
when(client.putMetricData(isA(PutMetricDataRequest.class)))
304-
.thenReturn(CompletableFuture.failedFuture(new SocketTimeoutException("simulated")));
303+
CompletableFuture<PutMetricDataResponse> future = new CompletableFuture<>();
304+
future.completeExceptionally(new SocketTimeoutException("simulated"));
305+
when(client.putMetricData(isA(PutMetricDataRequest.class))).thenReturn(future);
305306

306307
CloudWatchMeterRegistry registry = new CloudWatchMeterRegistry(config, clock, client);
307308
registry.counter("test").increment();
@@ -311,11 +312,16 @@ void shouldHandleExceptionsDuringPutMetricDataCallWithoutFailing() {
311312
}
312313

313314
@Test
314-
@SuppressWarnings("deprecation")
315315
void shouldHandleTimeoutsDuringPutMetricDataCallWithoutFailing() {
316316
CloudWatchAsyncClient client = mock(CloudWatchAsyncClient.class);
317-
when(client.putMetricData(isA(PutMetricDataRequest.class))).thenReturn(CompletableFuture.supplyAsync(() -> null,
318-
CompletableFuture.delayedExecutor(config.readTimeout().toMillis() + 1_000, TimeUnit.MILLISECONDS)));
317+
Executor nonExecutingExecutor = new Executor() {
318+
@Override
319+
public void execute(Runnable command) {
320+
// intentionally noop
321+
}
322+
};
323+
when(client.putMetricData(isA(PutMetricDataRequest.class)))
324+
.thenReturn(CompletableFuture.supplyAsync(() -> null, nonExecutingExecutor));
319325

320326
CloudWatchMeterRegistry registry = new CloudWatchMeterRegistry(config, clock, client);
321327
registry.counter("test").increment();

0 commit comments

Comments
 (0)