use of com.palantir.dialogue.TestResponse in project dialogue by palantir.
the class ConjureBodySerDeTest method testEmptyResponse_list_raw.
@Test
@SuppressWarnings("rawtypes")
public void testEmptyResponse_list_raw() {
BodySerDe serde = DefaultConjureRuntime.builder().build().bodySerDe();
List result = serde.deserializer(new TypeMarker<List>() {
}).deserialize(new TestResponse().code(204));
assertThat(result).isEmpty();
}
use of com.palantir.dialogue.TestResponse in project dialogue by palantir.
the class DefaultClientsTest method testOptionalBinaryResponse_inputStreamRemainsUnclosed.
@ParameterizedTest
@EnumSource(CallType.class)
public void testOptionalBinaryResponse_inputStreamRemainsUnclosed(CallType callType) throws IOException {
when(channel.execute(eq(endpoint), any())).thenReturn(responseFuture);
ListenableFuture<Optional<InputStream>> future = call(callType, Request.builder().build(), bodySerde.optionalInputStreamDeserializer());
TestResponse testResponse = new TestResponse().contentType("application/octet-stream");
responseFuture.set(testResponse);
Optional<InputStream> maybeInputStream = Futures.getUnchecked(future);
try (CloseRecordingInputStream inputStream = (CloseRecordingInputStream) maybeInputStream.get()) {
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();
}
use of com.palantir.dialogue.TestResponse in project dialogue by palantir.
the class ContentDecodingChannelTest method testDecoding.
@Test
public void testDecoding() throws Exception {
byte[] expected = new byte[] { 1, 2, 3, 4 };
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (GZIPOutputStream compressor = new GZIPOutputStream(out)) {
compressor.write(expected);
} catch (IOException e) {
throw new IllegalStateException(e);
}
Response response = new ContentDecodingChannel(_request -> Futures.immediateFuture(new TestResponse(out.toByteArray()).withHeader("content-encoding", "gzip").withHeader("content-length", Integer.toString(out.size())))).execute(Request.builder().build()).get();
assertThat(response.headers().get("content-encoding")).isEmpty();
assertThat(ByteStreams.toByteArray(response.body())).containsExactly(expected);
}
use of com.palantir.dialogue.TestResponse in project dialogue by palantir.
the class ContentDecodingChannelTest method testDecoding_delayedFailure.
@Test
public void testDecoding_delayedFailure() throws Exception {
Response response = new ContentDecodingChannel(_request -> Futures.immediateFuture(// Will fail because it's not valid gzip content
new TestResponse(new byte[] { 1, 2, 3, 4 }).withHeader("content-encoding", "gzip"))).execute(Request.builder().build()).get();
assertThat(response.headers().get("content-encoding")).isEmpty();
assertThatThrownBy(response.body()::read).isInstanceOf(IOException.class);
}
use of com.palantir.dialogue.TestResponse in project dialogue by palantir.
the class RetryingChannelTest method retries_500s_for_put.
@Test
public void retries_500s_for_put() throws Exception {
when(channel.execute(any())).thenReturn(Futures.immediateFuture(new TestResponse().code(500))).thenReturn(Futures.immediateFuture(new TestResponse().code(200)));
EndpointChannel retryer = new RetryingChannel(channel, TestEndpoint.PUT, "my-channel", 3, Duration.ZERO, ClientConfiguration.ServerQoS.AUTOMATIC_RETRY, ClientConfiguration.RetryOnTimeout.DISABLED);
ListenableFuture<Response> response = retryer.execute(REQUEST);
assertThat(response).isDone();
assertThat(response.get().code()).isEqualTo(200);
verify(channel, times(2)).execute(REQUEST);
}
Aggregations