use of com.palantir.dialogue.Response in project dialogue by palantir.
the class ApacheHandshakeTimeoutTest method testHandshakeLongerThanConnectDoesNotTimeout.
@Test
public void testHandshakeLongerThanConnectDoesNotTimeout() throws Exception {
int serverPort = getPort(server);
ClientConfiguration config = ClientConfiguration.builder().from(TestConfigurations.create("https://localhost:" + serverPort)).connectTimeout(Duration.ofMillis(500)).readTimeout(Duration.ofSeconds(2)).writeTimeout(Duration.ofMillis(2)).maxNumRetries(0).build();
Channel channel = create(config);
executor.delayNextTask(Duration.ofSeconds(1));
try (Response response = channel.execute(TestEndpoint.POST, request).get()) {
assertThat(response.code()).isEqualTo(200);
}
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class ApacheHandshakeTimeoutTest method testHandshakeTimeoutIsRetried.
@Test
public void testHandshakeTimeoutIsRetried() throws Exception {
int serverPort = getPort(server);
ClientConfiguration retryingConfig = ClientConfiguration.builder().from(TestConfigurations.create("https://localhost:" + serverPort)).connectTimeout(Duration.ofMillis(500)).readTimeout(Duration.ofMillis(500)).writeTimeout(Duration.ofMillis(500)).maxNumRetries(1).build();
Channel retryChannel = create(retryingConfig);
executor.delayNextTask(Duration.ofSeconds(1));
try (Response response = retryChannel.execute(TestEndpoint.POST, request).get()) {
assertThat(response.code()).isEqualTo(200);
}
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class ApacheHttpClientChannelsTest method countsConnectErrors.
@Test
public void countsConnectErrors() throws Exception {
ClientConfiguration conf = ClientConfiguration.builder().from(TestConfigurations.create("http://unused")).connectTimeout(Duration.ofMillis(1)).build();
try (ApacheHttpClientChannels.CloseableClient client = ApacheHttpClientChannels.createCloseableHttpClient(conf, "testClient")) {
Meter connectionCreateError = DialogueClientMetrics.of(conf.taggedMetricRegistry()).connectionCreateError().clientName("testClient").cause("ConnectTimeoutException").build();
assertThat(connectionCreateError.getCount()).isZero();
// 203.0.113.0/24 is a test network that should never exist
Channel channel = ApacheHttpClientChannels.createSingleUri("http://203.0.113.23", client);
ListenableFuture<Response> future = channel.execute(TestEndpoint.GET, Request.builder().build());
try (Response response = Futures.getUnchecked(future)) {
fail("This request should have failed with an connection timeout! (code: %d)", response.code());
} catch (UncheckedExecutionException exception) {
assertThat(exception.getCause()).isInstanceOf(SafeConnectTimeoutException.class);
}
assertThat(connectionCreateError.getCount()).isEqualTo(1L);
}
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class ApacheHttpClientChannelsTest method metrics.
@Test
public void metrics() throws Exception {
ClientConfiguration conf = TestConfigurations.create("http://unused");
try (ApacheHttpClientChannels.CloseableClient client = ApacheHttpClientChannels.createCloseableHttpClient(conf, "testClient")) {
Channel channel = ApacheHttpClientChannels.createSingleUri("http://neverssl.com", client);
ListenableFuture<Response> future = channel.execute(TestEndpoint.GET, Request.builder().build());
TaggedMetricRegistry metrics = conf.taggedMetricRegistry();
try (Response response = Futures.getUnchecked(future)) {
assertThat(response.code()).isEqualTo(200);
assertThat(poolGaugeValue(metrics, "testClient", "idle")).describedAs("available").isZero();
assertThat(poolGaugeValue(metrics, "testClient", "leased")).describedAs("leased").isEqualTo(1L);
}
assertThat(poolGaugeValue(metrics, "testClient", "idle")).describedAs("available after response closed").isOne();
assertThat(poolGaugeValue(metrics, "testClient", "leased")).describedAs("leased after response closed").isZero();
}
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class SimulationServer method execute.
@Override
public ListenableFuture<Response> execute(Endpoint endpoint, Request request) {
Meter perEndpointRequests = MetricNames.requestMeter(simulation.taggedMetrics(), serverName, endpoint);
activeRequests.inc();
perEndpointRequests.mark();
simulation.metricsReporter().report();
for (ServerHandler handler : handlers) {
long beforeNanos = simulation.clock().read();
Optional<ListenableFuture<Response>> maybeResp = handler.maybeExecute(this, endpoint, request);
if (!maybeResp.isPresent()) {
continue;
}
ListenableFuture<Response> resp = maybeResp.get();
DialogueFutures.addDirectCallback(resp, DialogueFutures.onSuccess(_ignored -> globalResponses.inc()));
resp.addListener(() -> {
activeRequests.dec();
globalServerTimeNanos.inc(simulation.clock().read() - beforeNanos);
}, DialogueFutures.safeDirectExecutor());
if (log.isDebugEnabled()) {
DialogueFutures.addDirectCallback(resp, DialogueFutures.onSuccess(result -> {
log.debug("time={} server={} status={} id={}", Duration.ofNanos(simulation.clock().read()), serverName, result.code(), request != null ? request.headerParams().get(Benchmark.REQUEST_ID_HEADER) : null);
}));
}
return resp;
}
log.error("No handler available for request {}", request);
activeRequests.dec();
return Futures.immediateFailedFuture(new SafeRuntimeException("No handler"));
}
Aggregations