Search in sources :

Example 1 with SafeLoggable

use of com.palantir.logsafe.SafeLoggable in project dialogue by palantir.

the class ApacheHttpClientChannelsTest method close_doesnt_fail_inflight_requests.

@Test
public void close_doesnt_fail_inflight_requests() throws Exception {
    ClientConfiguration conf = TestConfigurations.create("http://foo");
    Channel channel;
    try (ApacheHttpClientChannels.CloseableClient client = ApacheHttpClientChannels.createCloseableHttpClient(conf, "client")) {
        channel = ApacheHttpClientChannels.createSingleUri("http://foo", client);
        ListenableFuture<Response> response = channel.execute(TestEndpoint.POST, Request.builder().build());
        assertThatThrownBy(() -> Futures.getUnchecked(response)).getCause().isInstanceOfSatisfying(UnknownHostException.class, throwable -> assertThat(throwable.getSuppressed()[0]).satisfies(diagnosticThrowable -> assertThat(diagnosticThrowable.getStackTrace()).as("Diagnostic exception should have an empty stack trace").isEmpty()).isInstanceOfSatisfying(SafeLoggable.class, safeLoggable -> {
            assertThat(Lists.transform(safeLoggable.getArgs(), Arg::getName)).as("Expected a diagnostic exception").containsExactlyInAnyOrder("durationMillis", "connectTimeout", "socketTimeout", "clientName", "serviceName", "endpointName", "requestTraceId", "requestSpanId", "hostIndex");
        }));
    }
    ListenableFuture<Response> again = channel.execute(TestEndpoint.POST, Request.builder().build());
    assertThatThrownBy(() -> Futures.getUnchecked(again)).hasCauseInstanceOf(UnknownHostException.class);
}
Also used : Response(com.palantir.dialogue.Response) AbstractChannelTest(com.palantir.dialogue.AbstractChannelTest) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ClientConfiguration(com.palantir.conjure.java.client.config.ClientConfiguration) TestEndpoint(com.palantir.dialogue.TestEndpoint) Meter(com.codahale.metrics.Meter) OptionalLong(java.util.OptionalLong) Lists(com.google.common.collect.Lists) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) HttpHeaders(com.google.common.net.HttpHeaders) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Duration(java.time.Duration) Map(java.util.Map) Arg(com.palantir.logsafe.Arg) Request(com.palantir.dialogue.Request) OutputStream(java.io.OutputStream) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) RequestBody(com.palantir.dialogue.RequestBody) MoreCollectors(com.google.common.collect.MoreCollectors) Metric(com.codahale.metrics.Metric) IOException(java.io.IOException) SafeLoggable(com.palantir.logsafe.SafeLoggable) Channel(com.palantir.dialogue.Channel) HttpMethod(com.palantir.dialogue.HttpMethod) TaggedMetricRegistry(com.palantir.tritium.metrics.registry.TaggedMetricRegistry) UnknownHostException(java.net.UnknownHostException) TestConfigurations(com.palantir.dialogue.TestConfigurations) Test(org.junit.jupiter.api.Test) Futures(com.google.common.util.concurrent.Futures) Assertions.fail(org.assertj.core.api.Assertions.fail) Optional(java.util.Optional) Gauge(com.codahale.metrics.Gauge) Response(com.palantir.dialogue.Response) SafeLoggable(com.palantir.logsafe.SafeLoggable) Channel(com.palantir.dialogue.Channel) Arg(com.palantir.logsafe.Arg) ClientConfiguration(com.palantir.conjure.java.client.config.ClientConfiguration) AbstractChannelTest(com.palantir.dialogue.AbstractChannelTest) Test(org.junit.jupiter.api.Test)

Aggregations

Gauge (com.codahale.metrics.Gauge)1 Meter (com.codahale.metrics.Meter)1 Metric (com.codahale.metrics.Metric)1 Lists (com.google.common.collect.Lists)1 MoreCollectors (com.google.common.collect.MoreCollectors)1 HttpHeaders (com.google.common.net.HttpHeaders)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 ClientConfiguration (com.palantir.conjure.java.client.config.ClientConfiguration)1 AbstractChannelTest (com.palantir.dialogue.AbstractChannelTest)1 Channel (com.palantir.dialogue.Channel)1 HttpMethod (com.palantir.dialogue.HttpMethod)1 Request (com.palantir.dialogue.Request)1 RequestBody (com.palantir.dialogue.RequestBody)1 Response (com.palantir.dialogue.Response)1 TestConfigurations (com.palantir.dialogue.TestConfigurations)1 TestEndpoint (com.palantir.dialogue.TestEndpoint)1 Arg (com.palantir.logsafe.Arg)1 SafeLoggable (com.palantir.logsafe.SafeLoggable)1