diff --git a/dialogue-apache-hc5-client/src/test/java/com/palantir/dialogue/hc5/ApacheHandshakeTimeoutTest.java b/dialogue-apache-hc5-client/src/test/java/com/palantir/dialogue/hc5/ApacheHandshakeTimeoutTest.java index df5f710ba..df998bf0a 100644 --- a/dialogue-apache-hc5-client/src/test/java/com/palantir/dialogue/hc5/ApacheHandshakeTimeoutTest.java +++ b/dialogue-apache-hc5-client/src/test/java/com/palantir/dialogue/hc5/ApacheHandshakeTimeoutTest.java @@ -20,6 +20,7 @@ import com.google.common.collect.Iterables; import com.google.common.util.concurrent.ForwardingExecutorService; +import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.Uninterruptibles; import com.palantir.conjure.java.client.config.ClientConfiguration; @@ -130,14 +131,13 @@ public void testHandshakeTimeoutFailure() throws Exception { executor.delayNextTask(Duration.ofSeconds(1)); - assertThatThrownBy(noRetryChannel.execute(TestEndpoint.POST, request)::get) - .getCause() - .satisfies(cause -> assertThat(cause) - .isInstanceOf(SafeConnectTimeoutException.class) - .as("Only IOExceptions are retried") - .isInstanceOf(IOException.class) - .as("SocketTimeoutExceptions cannot be retried") - .isNotInstanceOf(SocketTimeoutException.class)); + ListenableFuture response = noRetryChannel.execute(TestEndpoint.POST, request); + assertThatThrownBy(() -> response.get()).getCause().satisfies(cause -> assertThat(cause) + .isInstanceOf(SafeConnectTimeoutException.class) + .as("Only IOExceptions are retried") + .isInstanceOf(IOException.class) + .as("SocketTimeoutExceptions cannot be retried") + .isNotInstanceOf(SocketTimeoutException.class)); } @Test diff --git a/dialogue-apache-hc5-client/src/test/java/com/palantir/dialogue/hc5/NoResponseTest.java b/dialogue-apache-hc5-client/src/test/java/com/palantir/dialogue/hc5/NoResponseTest.java index 7b6a63642..c24d1db52 100644 --- a/dialogue-apache-hc5-client/src/test/java/com/palantir/dialogue/hc5/NoResponseTest.java +++ b/dialogue-apache-hc5-client/src/test/java/com/palantir/dialogue/hc5/NoResponseTest.java @@ -20,6 +20,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; +import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.Uninterruptibles; import com.palantir.conjure.java.client.config.ClientConfiguration; import com.palantir.conjure.java.client.config.ClientConfigurations; @@ -76,8 +77,8 @@ public void testConnectionClosedAfterDelay() { })); try { Channel channel = create(defaultClientConfig(getPort(server))); - assertThatThrownBy(channel.execute(TestEndpoint.POST, request)::get) - .hasCauseInstanceOf(SocketTimeoutException.class); + ListenableFuture response = channel.execute(TestEndpoint.POST, request); + assertThatThrownBy(() -> response.get()).hasCauseInstanceOf(SocketTimeoutException.class); assertThat(requests).as("Request mustn't be retried").hasValue(1); } finally { server.stop(); diff --git a/dialogue-blocking-channels/src/test/java/com/palantir/dialogue/blocking/BlockingChannelAdapterTest.java b/dialogue-blocking-channels/src/test/java/com/palantir/dialogue/blocking/BlockingChannelAdapterTest.java index f64d14637..d5f680034 100644 --- a/dialogue-blocking-channels/src/test/java/com/palantir/dialogue/blocking/BlockingChannelAdapterTest.java +++ b/dialogue-blocking-channels/src/test/java/com/palantir/dialogue/blocking/BlockingChannelAdapterTest.java @@ -91,7 +91,7 @@ public void testFailure() { ListenableFuture result = channel.execute(TestEndpoint.POST, Request.builder().build()); Awaitility.waitAtMost(Duration.ofSeconds(3)).until(result::isDone); - assertThatThrownBy(result::get) + assertThatThrownBy(() -> result.get()) .isInstanceOf(ExecutionException.class) .hasCauseExactlyInstanceOf(SafeRuntimeException.class) .hasRootCauseMessage("expected"); @@ -133,7 +133,7 @@ void testAlreadyShutdown() { channel.execute(TestEndpoint.POST, Request.builder().build()); assertThat(future).isDone(); - assertThatThrownBy(future::get) + assertThatThrownBy(() -> future.get()) .isInstanceOf(ExecutionException.class) .hasCauseInstanceOf(RejectedExecutionException.class); } diff --git a/dialogue-client-verifier/src/test/java/com/palantir/verification/IntegrationTest.java b/dialogue-client-verifier/src/test/java/com/palantir/verification/IntegrationTest.java index 192b23d0b..496a04a2e 100644 --- a/dialogue-client-verifier/src/test/java/com/palantir/verification/IntegrationTest.java +++ b/dialogue-client-verifier/src/test/java/com/palantir/verification/IntegrationTest.java @@ -194,7 +194,7 @@ public void when_thread_is_interrupted_no_requests_are_made() { ListenableFuture future = async.getMyAlias(); assertThat(future).isDone(); assertThat(future).isNotCancelled(); - assertThatThrownBy(future::get).isInstanceOf(InterruptedException.class); + assertThatThrownBy(() -> future.get()).isInstanceOf(InterruptedException.class); assertThat(served).hasValue(0); } diff --git a/dialogue-clients/src/test/java/com/palantir/dialogue/otherpackage/DialogueClientsTest.java b/dialogue-clients/src/test/java/com/palantir/dialogue/otherpackage/DialogueClientsTest.java index 2c7369c8d..1edcb7872 100644 --- a/dialogue-clients/src/test/java/com/palantir/dialogue/otherpackage/DialogueClientsTest.java +++ b/dialogue-clients/src/test/java/com/palantir/dialogue/otherpackage/DialogueClientsTest.java @@ -109,7 +109,7 @@ void getStickyChannels_behaves_when_service_doesnt_exist() { ListenableFuture future = stickyChannels .getStickyChannel() .execute(TestEndpoint.POST, Request.builder().build()); - assertThatThrownBy(future::get) + assertThatThrownBy(() -> future.get()) .describedAs("Nice error message when services doesn't exist") .hasCauseInstanceOf(SafeIllegalStateException.class) .hasMessageContaining("Service not configured"); @@ -125,7 +125,7 @@ void getStickyChannels_behaves_when_just_one_uri() { ListenableFuture future = stickyChannels .getStickyChannel() .execute(TestEndpoint.POST, Request.builder().build()); - assertThatThrownBy(future::get) + assertThatThrownBy(() -> future.get()) .describedAs("Made a real network call") .hasCauseInstanceOf(UnknownHostException.class); } @@ -141,7 +141,7 @@ void getStickyChannels_live_reloads_nicely() { ListenableFuture future = stickyChannels .getStickyChannel() .execute(TestEndpoint.POST, Request.builder().build()); - assertThatThrownBy(future::get) + assertThatThrownBy(() -> future.get()) .describedAs("Nice error message when service exists but has zero uris") .hasCauseInstanceOf(SafeIllegalStateException.class) .hasMessageContaining("Service not configured"); @@ -157,7 +157,7 @@ void getStickyChannels_live_reloads_nicely() { ListenableFuture future2 = stickyChannels .getStickyChannel() .execute(TestEndpoint.POST, Request.builder().build()); - assertThatThrownBy(future2::get) + assertThatThrownBy(() -> future2.get()) .describedAs("Made a real network call") .hasCauseInstanceOf(UnknownHostException.class); } diff --git a/dialogue-core/src/test/java/com/palantir/dialogue/core/ContentDecodingChannelTest.java b/dialogue-core/src/test/java/com/palantir/dialogue/core/ContentDecodingChannelTest.java index 3ce4d1427..4d3d61432 100644 --- a/dialogue-core/src/test/java/com/palantir/dialogue/core/ContentDecodingChannelTest.java +++ b/dialogue-core/src/test/java/com/palantir/dialogue/core/ContentDecodingChannelTest.java @@ -35,6 +35,7 @@ import com.palantir.dialogue.TestResponse; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.InputStream; import java.util.Set; import java.util.zip.GZIPOutputStream; import javax.net.ssl.SSLContext; @@ -120,7 +121,9 @@ public void testDecoding_delayedFailure() throws Exception { .execute(Request.builder().build()) .get(); assertThat(response.headers().get("content-encoding")).isEmpty(); - assertThatThrownBy(response.body()::read).isInstanceOf(IOException.class); + try (InputStream body = response.body()) { + assertThatThrownBy(() -> body.read()).isInstanceOf(IOException.class); + } } @Test diff --git a/dialogue-core/src/test/java/com/palantir/dialogue/core/DialogueChannelTest.java b/dialogue-core/src/test/java/com/palantir/dialogue/core/DialogueChannelTest.java index c5f344fa0..f09518f7d 100644 --- a/dialogue-core/src/test/java/com/palantir/dialogue/core/DialogueChannelTest.java +++ b/dialogue-core/src/test/java/com/palantir/dialogue/core/DialogueChannelTest.java @@ -234,7 +234,7 @@ void test_queue_rejection_is_not_retried() { // Next request should be rejected. ListenableFuture rejected = channel.execute(endpoint, request); assertThat(rejected).isDone(); - assertThatThrownBy(rejected::get) + assertThatThrownBy(() -> rejected.get()) .hasRootCauseExactlyInstanceOf(SafeRuntimeException.class) .hasMessageContaining("queue is full"); } @@ -320,7 +320,7 @@ void constructing_a_client_with_zero_uris_causes_immediate_failures() { .factory(_args -> mockChannel) .build(); ListenableFuture future = channel.execute(endpoint, request); - assertThatThrownBy(future::get).hasRootCauseInstanceOf(SafeIllegalStateException.class); + assertThatThrownBy(() -> future.get()).hasRootCauseInstanceOf(SafeIllegalStateException.class); } @Test diff --git a/dialogue-core/src/test/java/com/palantir/dialogue/core/QueuedChannelTest.java b/dialogue-core/src/test/java/com/palantir/dialogue/core/QueuedChannelTest.java index a5819c87c..a456a456c 100644 --- a/dialogue-core/src/test/java/com/palantir/dialogue/core/QueuedChannelTest.java +++ b/dialogue-core/src/test/java/com/palantir/dialogue/core/QueuedChannelTest.java @@ -101,7 +101,7 @@ public void testReceivesExceptionalResponse() { futureResponse.setException(new IllegalArgumentException()); assertThat(response.isDone()).isTrue(); - assertThatThrownBy(response::get) + assertThatThrownBy(() -> response.get()) .isInstanceOf(ExecutionException.class) .hasCauseInstanceOf(IllegalArgumentException.class); } @@ -139,7 +139,7 @@ public void testQueuedRequestExecutedOnNextSubmission_throws() throws ExecutionE assertThat(completed).isDone(); assertThat(queuedFuture).isDone(); assertThat(completed.get()).isEqualTo(mockResponse); - assertThatThrownBy(queuedFuture::get).hasRootCauseMessage("expected"); + assertThatThrownBy(() -> queuedFuture.get()).hasRootCauseMessage("expected"); verify(delegate, times(1)).maybeExecute(endpoint, request, DO_NOT_SKIP_LIMITS); verify(delegate, times(3)).maybeExecute(endpoint, queuedRequest, DO_NOT_SKIP_LIMITS); } diff --git a/dialogue-core/src/test/java/com/palantir/dialogue/core/RetryingChannelTest.java b/dialogue-core/src/test/java/com/palantir/dialogue/core/RetryingChannelTest.java index f88ab92b1..bb2255fdc 100644 --- a/dialogue-core/src/test/java/com/palantir/dialogue/core/RetryingChannelTest.java +++ b/dialogue-core/src/test/java/com/palantir/dialogue/core/RetryingChannelTest.java @@ -109,7 +109,7 @@ public void testRetriesUpToMaxRetriesAndFails() throws ExecutionException, Inter ClientConfiguration.ServerQoS.AUTOMATIC_RETRY, ClientConfiguration.RetryOnTimeout.DISABLED); ListenableFuture response = retryer.execute(REQUEST); - assertThatThrownBy(response::get) + assertThatThrownBy(() -> response.get()) .hasRootCauseExactlyInstanceOf(SafeIoException.class) .hasRootCauseMessage("FAILED"); } @@ -127,7 +127,7 @@ public void testRetriesMax() { ClientConfiguration.ServerQoS.AUTOMATIC_RETRY, ClientConfiguration.RetryOnTimeout.DISABLED); ListenableFuture response = retryer.execute(REQUEST); - assertThatThrownBy(response::get).hasCauseInstanceOf(SafeIoException.class); + assertThatThrownBy(() -> response.get()).hasCauseInstanceOf(SafeIoException.class); verify(channel, times(4)).execute(REQUEST); } @@ -472,7 +472,7 @@ public void doesNotRetrySocketTimeout() { ClientConfiguration.ServerQoS.AUTOMATIC_RETRY, ClientConfiguration.RetryOnTimeout.DISABLED); ListenableFuture response = retryer.execute(REQUEST); - assertThatThrownBy(response::get).hasRootCauseExactlyInstanceOf(SocketTimeoutException.class); + assertThatThrownBy(() -> response.get()).hasRootCauseExactlyInstanceOf(SocketTimeoutException.class); } @Test @@ -508,7 +508,7 @@ public void doesNotRetryRuntimeException() { ClientConfiguration.ServerQoS.AUTOMATIC_RETRY, ClientConfiguration.RetryOnTimeout.DISABLED); ListenableFuture response = retryer.execute(REQUEST); - assertThatThrownBy(response::get) + assertThatThrownBy(() -> response.get()) .hasRootCauseExactlyInstanceOf(SafeRuntimeException.class) .hasRootCauseMessage("bug"); } @@ -612,7 +612,7 @@ public void close() {} .build()); assertThat(response).isDone(); - assertThatThrownBy(response::get) + assertThatThrownBy(() -> response.get()) .as("requests should not be retried if they are consumed") .hasRootCauseExactlyInstanceOf(SafeIoException.class) .hasRootCauseMessage("FAILED"); diff --git a/dialogue-futures/src/test/java/com/palantir/dialogue/futures/DialogueFuturesTest.java b/dialogue-futures/src/test/java/com/palantir/dialogue/futures/DialogueFuturesTest.java index d45897190..d20c770c8 100644 --- a/dialogue-futures/src/test/java/com/palantir/dialogue/futures/DialogueFuturesTest.java +++ b/dialogue-futures/src/test/java/com/palantir/dialogue/futures/DialogueFuturesTest.java @@ -52,7 +52,7 @@ void testTransform_originalCancel(Transformer transformer) { ListenableFuture doubled = transformer.transform(original, value -> value + value); assertThat(original.cancel(false)).isTrue(); assertThat(doubled).isCancelled(); - assertThatThrownBy(doubled::get).isInstanceOf(CancellationException.class); + assertThatThrownBy(() -> doubled.get()).isInstanceOf(CancellationException.class); } @ParameterizedTest @@ -62,7 +62,7 @@ void testTransform_resultCancel(Transformer transformer) { ListenableFuture doubled = transformer.transform(original, value -> value + value); assertThat(doubled.cancel(false)).isTrue(); assertThat(doubled).isCancelled(); - assertThatThrownBy(doubled::get).isInstanceOf(CancellationException.class); + assertThatThrownBy(() -> doubled.get()).isInstanceOf(CancellationException.class); assertThat(original).isCancelled(); } @@ -90,7 +90,7 @@ void testTransformAsync_originalCancel(Transformer transformer) { assertThat(one.cancel(false)).isTrue(); assertThat(transformed).isCancelled(); assertThat(transformed).isDone(); - assertThatThrownBy(transformed::get).isInstanceOf(CancellationException.class); + assertThatThrownBy(() -> transformed.get()).isInstanceOf(CancellationException.class); assertThat(two).as("The intermediate future is not impacted").isNotDone(); } @@ -106,7 +106,7 @@ void testTransformAsync_intermediateCancel(Transformer transformer) { assertThat(two.cancel(false)).isTrue(); assertThat(transformed).isCancelled(); assertThat(transformed).isDone(); - assertThatThrownBy(transformed::get).isInstanceOf(CancellationException.class); + assertThatThrownBy(() -> transformed.get()).isInstanceOf(CancellationException.class); } @ParameterizedTest @@ -181,7 +181,7 @@ void testCatchingAllAsync_originalCancel() { assertThat(one.cancel(false)).isTrue(); assertThat(transformed).isCancelled(); assertThat(transformed).isDone(); - assertThatThrownBy(transformed::get).isInstanceOf(CancellationException.class); + assertThatThrownBy(() -> transformed.get()).isInstanceOf(CancellationException.class); } @ParameterizedTest @@ -196,7 +196,7 @@ void testCatchingAllAsync_intermediateCancel(Transformer transformer) { assertThat(two.cancel(false)).isTrue(); assertThat(transformed).isCancelled(); assertThat(transformed).isDone(); - assertThatThrownBy(transformed::get).isInstanceOf(CancellationException.class); + assertThatThrownBy(() -> transformed.get()).isInstanceOf(CancellationException.class); } @ParameterizedTest @@ -208,7 +208,7 @@ void testCatchingAllAsync_cancel(Transformer transformer) { assertThat(transformed).isNotDone(); assertThat(transformed.cancel(false)).isTrue(); assertThat(transformed).isDone(); - assertThatThrownBy(transformed::get).isInstanceOf(CancellationException.class); + assertThatThrownBy(() -> transformed.get()).isInstanceOf(CancellationException.class); } @ParameterizedTest @@ -223,7 +223,7 @@ void testCatchingAllAsync_resultCancel_afterFirstSet(Transformer transformer) { assertThat(transformed.cancel(false)).isTrue(); assertThat(one).isNotCancelled(); assertThat(two).isCancelled(); - assertThatThrownBy(transformed::get).isInstanceOf(CancellationException.class); + assertThatThrownBy(() -> transformed.get()).isInstanceOf(CancellationException.class); } @ParameterizedTest diff --git a/dialogue-test-common/src/main/java/com/palantir/dialogue/AbstractChannelTest.java b/dialogue-test-common/src/main/java/com/palantir/dialogue/AbstractChannelTest.java index 8d7dc4565..ac247d314 100644 --- a/dialogue-test-common/src/main/java/com/palantir/dialogue/AbstractChannelTest.java +++ b/dialogue-test-common/src/main/java/com/palantir/dialogue/AbstractChannelTest.java @@ -352,7 +352,7 @@ public void callCancellationIsObservedAsException() throws InterruptedException Thread.sleep(1000); server.enqueue(new MockResponse()); - assertThatThrownBy(call::get).isInstanceOfAny(CancellationException.class); + assertThatThrownBy(() -> call.get()).isInstanceOfAny(CancellationException.class); } // TODO(rfink): How to test that cancellation propagates to the server? @@ -361,7 +361,7 @@ public void callCancellationIsObservedAsException() throws InterruptedException public void connectionErrorsSurfaceAsExceptions() throws IOException { server.shutdown(); ListenableFuture call = channel.execute(endpoint, request); - assertThatThrownBy(call::get).hasCauseInstanceOf(ConnectException.class); + assertThatThrownBy(() -> call.get()).hasCauseInstanceOf(ConnectException.class); } @Test