Search in sources :

Example 26 with TestResponse

use of com.palantir.dialogue.TestResponse in project dialogue by palantir.

the class ConjureBodySerDeTest method testEmptyResponse_list.

@Test
public void testEmptyResponse_list() {
    BodySerDe serde = DefaultConjureRuntime.builder().build().bodySerDe();
    List<String> result = serde.deserializer(new TypeMarker<List<String>>() {
    }).deserialize(new TestResponse().code(204));
    assertThat(result).isEmpty();
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) TypeMarker(com.palantir.dialogue.TypeMarker) BodySerDe(com.palantir.dialogue.BodySerDe) Test(org.junit.jupiter.api.Test)

Example 27 with TestResponse

use of com.palantir.dialogue.TestResponse in project dialogue by palantir.

the class ConjureBodySerDeTest method testEmptyResponse_success.

@Test
public void testEmptyResponse_success() {
    TestResponse response = new TestResponse().code(204);
    BodySerDe serializers = conjureBodySerDe("application/json");
    serializers.emptyBodyDeserializer().deserialize(response);
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) BodySerDe(com.palantir.dialogue.BodySerDe) Test(org.junit.jupiter.api.Test)

Example 28 with TestResponse

use of com.palantir.dialogue.TestResponse in project dialogue by palantir.

the class DefaultClientsTest method testBinaryResponse_inputStreamRemainsUnclosed.

@ParameterizedTest
@EnumSource(CallType.class)
public void testBinaryResponse_inputStreamRemainsUnclosed(CallType callType) throws IOException {
    when(channel.execute(eq(endpoint), any())).thenReturn(responseFuture);
    ListenableFuture<InputStream> future = call(callType, Request.builder().build(), bodySerde.inputStreamDeserializer());
    TestResponse testResponse = new TestResponse().contentType("application/octet-stream");
    responseFuture.set(testResponse);
    try (CloseRecordingInputStream inputStream = (CloseRecordingInputStream) Futures.getUnchecked(future)) {
        assertThat(inputStream.available()).describedAs("Content should be empty").isEqualTo(0);
        inputStream.assertNotClosed();
        assertThat(testResponse.isClosed()).describedAs("Response").isFalse();
    }
    assertThat(testResponse.body().isClosed()).describedAs("User has closed it now").isTrue();
    assertThat(testResponse.isClosed()).describedAs("Response#close was never called, but no big deal because the body is the only resource worth" + " closing").isFalse();
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) CloseRecordingInputStream(com.palantir.dialogue.CloseRecordingInputStream) InputStream(java.io.InputStream) CloseRecordingInputStream(com.palantir.dialogue.CloseRecordingInputStream) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with TestResponse

use of com.palantir.dialogue.TestResponse in project dialogue by palantir.

the class NodeSelectionStrategyChannelTest method updates_strategy_on_response.

@Test
void updates_strategy_on_response() {
    ImmutableList<LimitedChannel> channels = ImmutableList.of(channel1, channel2);
    channel = new NodeSelectionStrategyChannel(strategySelector, DialogueNodeSelectionStrategy.PIN_UNTIL_ERROR_WITHOUT_RESHUFFLE, channelName, pseudo, clock, new DefaultTaggedMetricRegistry(), channels);
    when(channel1.maybeExecute(any(), any(), eq(LimitEnforcement.DEFAULT_ENABLED))).thenReturn(Optional.of(Futures.immediateFuture(new TestResponse().code(200).withHeader("Node-Selection-Strategy", "BALANCED,FOO"))));
    assertThat(channel.maybeExecute(null, Request.builder().build(), LimitEnforcement.DEFAULT_ENABLED)).isPresent();
    verify(strategySelector, times(1)).updateAndGet(eq(ImmutableList.of(DialogueNodeSelectionStrategy.BALANCED, DialogueNodeSelectionStrategy.UNKNOWN)));
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) DefaultTaggedMetricRegistry(com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry) Test(org.junit.jupiter.api.Test)

Example 30 with TestResponse

use of com.palantir.dialogue.TestResponse in project dialogue by palantir.

the class RetryOtherValidatingChannelTest method execute.

private void execute(@Nullable String retryOtherUri) {
    RetryOtherValidatingChannel channel = new RetryOtherValidatingChannel(delegate, ImmutableSet.of("https://host3.palantir.dev:9090/service/api", "https://host1.palantir.dev:9090/service/api").stream().map(RetryOtherValidatingChannel::strictParseHost).collect(Collectors.toSet()), failureReporter);
    Request request = Request.builder().build();
    TestResponse response = TestResponse.withBody(null).code(308);
    if (retryOtherUri != null) {
        response = response.withHeader(HttpHeaders.LOCATION, retryOtherUri);
    }
    when(delegate.execute(TestEndpoint.GET, request)).thenReturn(Futures.immediateFuture(response));
    assertThat(channel.execute(TestEndpoint.GET, request)).succeedsWithin(Duration.ZERO).isEqualTo(response);
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Request(com.palantir.dialogue.Request)

Aggregations

TestResponse (com.palantir.dialogue.TestResponse)31 Test (org.junit.jupiter.api.Test)26 BodySerDe (com.palantir.dialogue.BodySerDe)13 Response (com.palantir.dialogue.Response)13 EndpointChannel (com.palantir.dialogue.EndpointChannel)7 CloseRecordingInputStream (com.palantir.dialogue.CloseRecordingInputStream)4 InputStream (java.io.InputStream)4 Request (com.palantir.dialogue.Request)3 TypeMarker (com.palantir.dialogue.TypeMarker)3 SafeRuntimeException (com.palantir.logsafe.exceptions.SafeRuntimeException)3 IOException (java.io.IOException)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 EnumSource (org.junit.jupiter.params.provider.EnumSource)3 RemoteException (com.palantir.conjure.java.api.errors.RemoteException)2 SerializableError (com.palantir.conjure.java.api.errors.SerializableError)2 ServiceException (com.palantir.conjure.java.api.errors.ServiceException)2 Channel (com.palantir.dialogue.Channel)2 Endpoint (com.palantir.dialogue.Endpoint)2 Random (java.util.Random)2 Meter (com.codahale.metrics.Meter)1