use of com.palantir.dialogue.CloseRecordingInputStream 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.CloseRecordingInputStream in project dialogue by palantir.
the class BinaryEncodingTest method testBinary.
@Test
public void testBinary() throws IOException {
TestResponse response = new TestResponse().code(200).contentType("application/octet-stream");
BodySerDe serializers = new ConjureBodySerDe(ImmutableList.of(WeightedEncoding.of(new ConjureBodySerDeTest.StubEncoding("application/json"))), ErrorDecoder.INSTANCE, Encodings.emptyContainerDeserializer(), DefaultConjureRuntime.DEFAULT_SERDE_CACHE_SPEC);
InputStream deserialized = serializers.inputStreamDeserializer().deserialize(response);
assertThat(deserialized.available()).isEqualTo(0);
CloseRecordingInputStream rawInputStream = response.body();
rawInputStream.assertNotClosed();
assertThat(response.isClosed()).describedAs("response is unclosed initially").isFalse();
deserialized.close();
assertThat(response.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.CloseRecordingInputStream in project dialogue by palantir.
the class BinaryEncodingTest method testBinary_optional_present.
@Test
public void testBinary_optional_present() throws IOException {
TestResponse response = new TestResponse().code(200).contentType("application/octet-stream");
BodySerDe serializers = new ConjureBodySerDe(ImmutableList.of(WeightedEncoding.of(new ConjureBodySerDeTest.StubEncoding("application/json"))), ErrorDecoder.INSTANCE, Encodings.emptyContainerDeserializer(), DefaultConjureRuntime.DEFAULT_SERDE_CACHE_SPEC);
Optional<InputStream> maybe = serializers.optionalInputStreamDeserializer().deserialize(response);
assertThat(maybe).isPresent();
InputStream deserialized = maybe.get();
assertThat(deserialized.available()).isEqualTo(0);
CloseRecordingInputStream rawInputStream = response.body();
rawInputStream.assertNotClosed();
assertThat(response.isClosed()).describedAs("response is unclosed initially").isFalse();
deserialized.close();
assertThat(response.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.CloseRecordingInputStream 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();
}
Aggregations