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();
}
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);
}
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();
}
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)));
}
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);
}
Aggregations