Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
carterkozak committed Jan 2, 2024
1 parent 302cb68 commit de0129b
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testFailure() {
ListenableFuture<Response> 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");
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void when_thread_is_interrupted_no_requests_are_made() {
ListenableFuture<AliasOfOptional> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void getStickyChannels_behaves_when_service_doesnt_exist() {
ListenableFuture<Response> 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");
Expand All @@ -125,7 +125,7 @@ void getStickyChannels_behaves_when_just_one_uri() {
ListenableFuture<Response> future = stickyChannels
.getStickyChannel()
.execute(TestEndpoint.POST, Request.builder().build());
assertThatThrownBy(future::get)
assertThatThrownBy(() -> future.get())
.describedAs("Made a real network call")
.hasCauseInstanceOf(UnknownHostException.class);
}
Expand All @@ -141,7 +141,7 @@ void getStickyChannels_live_reloads_nicely() {
ListenableFuture<Response> 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");
Expand All @@ -157,7 +157,7 @@ void getStickyChannels_live_reloads_nicely() {
ListenableFuture<Response> future2 = stickyChannels
.getStickyChannel()
.execute(TestEndpoint.POST, Request.builder().build());
assertThatThrownBy(future2::get)
assertThatThrownBy(() -> future2.get())
.describedAs("Made a real network call")
.hasCauseInstanceOf(UnknownHostException.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ void test_queue_rejection_is_not_retried() {
// Next request should be rejected.
ListenableFuture<Response> rejected = channel.execute(endpoint, request);
assertThat(rejected).isDone();
assertThatThrownBy(rejected::get)
assertThatThrownBy(() -> rejected.get())
.hasRootCauseExactlyInstanceOf(SafeRuntimeException.class)
.hasMessageContaining("queue is full");
}
Expand Down Expand Up @@ -320,7 +320,7 @@ void constructing_a_client_with_zero_uris_causes_immediate_failures() {
.factory(_args -> mockChannel)
.build();
ListenableFuture<Response> future = channel.execute(endpoint, request);
assertThatThrownBy(future::get).hasRootCauseInstanceOf(SafeIllegalStateException.class);
assertThatThrownBy(() -> future.get()).hasRootCauseInstanceOf(SafeIllegalStateException.class);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void testRetriesUpToMaxRetriesAndFails() throws ExecutionException, Inter
ClientConfiguration.ServerQoS.AUTOMATIC_RETRY,
ClientConfiguration.RetryOnTimeout.DISABLED);
ListenableFuture<Response> response = retryer.execute(REQUEST);
assertThatThrownBy(response::get)
assertThatThrownBy(() -> response.get())
.hasRootCauseExactlyInstanceOf(SafeIoException.class)
.hasRootCauseMessage("FAILED");
}
Expand All @@ -127,7 +127,7 @@ public void testRetriesMax() {
ClientConfiguration.ServerQoS.AUTOMATIC_RETRY,
ClientConfiguration.RetryOnTimeout.DISABLED);
ListenableFuture<Response> response = retryer.execute(REQUEST);
assertThatThrownBy(response::get).hasCauseInstanceOf(SafeIoException.class);
assertThatThrownBy(() -> response.get()).hasCauseInstanceOf(SafeIoException.class);
verify(channel, times(4)).execute(REQUEST);
}

Expand Down Expand Up @@ -472,7 +472,7 @@ public void doesNotRetrySocketTimeout() {
ClientConfiguration.ServerQoS.AUTOMATIC_RETRY,
ClientConfiguration.RetryOnTimeout.DISABLED);
ListenableFuture<Response> response = retryer.execute(REQUEST);
assertThatThrownBy(response::get).hasRootCauseExactlyInstanceOf(SocketTimeoutException.class);
assertThatThrownBy(() -> response.get()).hasRootCauseExactlyInstanceOf(SocketTimeoutException.class);
}

@Test
Expand Down Expand Up @@ -508,7 +508,7 @@ public void doesNotRetryRuntimeException() {
ClientConfiguration.ServerQoS.AUTOMATIC_RETRY,
ClientConfiguration.RetryOnTimeout.DISABLED);
ListenableFuture<Response> response = retryer.execute(REQUEST);
assertThatThrownBy(response::get)
assertThatThrownBy(() -> response.get())
.hasRootCauseExactlyInstanceOf(SafeRuntimeException.class)
.hasRootCauseMessage("bug");
}
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void testTransform_originalCancel(Transformer transformer) {
ListenableFuture<String> 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
Expand All @@ -62,7 +62,7 @@ void testTransform_resultCancel(Transformer transformer) {
ListenableFuture<String> 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();
}

Expand Down Expand Up @@ -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();
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -361,7 +361,7 @@ public void callCancellationIsObservedAsException() throws InterruptedException
public void connectionErrorsSurfaceAsExceptions() throws IOException {
server.shutdown();
ListenableFuture<Response> call = channel.execute(endpoint, request);
assertThatThrownBy(call::get).hasCauseInstanceOf(ConnectException.class);
assertThatThrownBy(() -> call.get()).hasCauseInstanceOf(ConnectException.class);
}

@Test
Expand Down

0 comments on commit de0129b

Please sign in to comment.