use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class JankyServersTest method testHttpSilentServerWithGlobalTimeout.
@Test
public void testHttpSilentServerWithGlobalTimeout() throws Throwable {
final Lifecycle lifecycle = new Lifecycle();
try {
final HttpClientConfig config = HttpClientConfig.builder().withReadTimeout(new Duration(100)).build();
final HttpClient client = HttpClientInit.createClient(config, lifecycle);
final ListenableFuture<StatusResponseHolder> future = client.go(new Request(HttpMethod.GET, new URL(StringUtils.format("http://localhost:%d/", silentServerSocket.getLocalPort()))), StatusResponseHandler.getInstance());
Throwable e = null;
try {
future.get();
} catch (ExecutionException e1) {
e = e1.getCause();
}
Assert.assertTrue("ReadTimeoutException thrown by 'get'", e instanceof ReadTimeoutException);
} finally {
lifecycle.stop();
}
}
use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class JankyServersTest method testHttpSilentServerWithRequestTimeout.
@Test
public void testHttpSilentServerWithRequestTimeout() throws Throwable {
final Lifecycle lifecycle = new Lifecycle();
try {
final HttpClientConfig config = HttpClientConfig.builder().withReadTimeout(new Duration(86400L * 365)).build();
final HttpClient client = HttpClientInit.createClient(config, lifecycle);
final ListenableFuture<StatusResponseHolder> future = client.go(new Request(HttpMethod.GET, new URL(StringUtils.format("http://localhost:%d/", silentServerSocket.getLocalPort()))), StatusResponseHandler.getInstance(), new Duration(100L));
Throwable e = null;
try {
future.get();
} catch (ExecutionException e1) {
e = e1.getCause();
}
Assert.assertTrue("ReadTimeoutException thrown by 'get'", e instanceof ReadTimeoutException);
} finally {
lifecycle.stop();
}
}
use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class JankyServersTest method testHttpEchoServer.
@Test
public void testHttpEchoServer() throws Throwable {
final Lifecycle lifecycle = new Lifecycle();
try {
final HttpClientConfig config = HttpClientConfig.builder().build();
final HttpClient client = HttpClientInit.createClient(config, lifecycle);
final ListenableFuture<StatusResponseHolder> response = client.go(new Request(HttpMethod.GET, new URL(StringUtils.format("http://localhost:%d/", echoServerSocket.getLocalPort()))), StatusResponseHandler.getInstance());
expectedException.expect(ExecutionException.class);
expectedException.expectMessage("java.lang.IllegalArgumentException: invalid version format: GET");
response.get();
} finally {
lifecycle.stop();
}
}
use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class CoordinatorResourceTestClient method getDynamicConfig.
public CoordinatorDynamicConfig getDynamicConfig() {
String url = StringUtils.format("%sconfig", getCoordinatorURL());
CoordinatorDynamicConfig config;
try {
StatusResponseHolder response = makeRequest(HttpMethod.GET, url);
config = jsonMapper.readValue(response.getContent(), CoordinatorDynamicConfig.class);
} catch (Exception e) {
throw new RuntimeException(e);
}
return config;
}
use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class CoordinatorResourceTestClient method initializeLookups.
public Map<String, Object> initializeLookups(String filePath) throws Exception {
String url = StringUtils.format("%slookups/config", getCoordinatorURL());
StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, new URL(url)).setContent("application/json", jsonMapper.writeValueAsBytes(ImmutableMap.of())), responseHandler).get();
if (!response.getStatus().equals(HttpResponseStatus.ACCEPTED)) {
throw new ISE("Error while querying[%s] status[%s] content[%s]", url, response.getStatus(), response.getContent());
}
StatusResponseHolder response2 = httpClient.go(new Request(HttpMethod.POST, new URL(url)).setContent("application/json", jsonMapper.writeValueAsBytes(jsonMapper.readValue(CoordinatorResourceTestClient.class.getResourceAsStream(filePath), new TypeReference<Map<Object, Object>>() {
}))), responseHandler).get();
if (!response2.getStatus().equals(HttpResponseStatus.ACCEPTED)) {
throw new ISE("Error while querying[%s] status[%s] content[%s]", url, response2.getStatus(), response2.getContent());
}
Map<String, Object> results2 = jsonMapper.readValue(response.getContent(), new TypeReference<Map<String, Object>>() {
});
return results2;
}
Aggregations