Search in sources :

Example 36 with StatusResponseHolder

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();
    }
}
Also used : ReadTimeoutException(org.jboss.netty.handler.timeout.ReadTimeoutException) Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) Duration(org.joda.time.Duration) ExecutionException(java.util.concurrent.ExecutionException) URL(java.net.URL) Test(org.junit.Test)

Example 37 with StatusResponseHolder

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();
    }
}
Also used : ReadTimeoutException(org.jboss.netty.handler.timeout.ReadTimeoutException) Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) Duration(org.joda.time.Duration) ExecutionException(java.util.concurrent.ExecutionException) URL(java.net.URL) Test(org.junit.Test)

Example 38 with StatusResponseHolder

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();
    }
}
Also used : Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) URL(java.net.URL) Test(org.junit.Test)

Example 39 with StatusResponseHolder

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;
}
Also used : CoordinatorDynamicConfig(org.apache.druid.server.coordinator.CoordinatorDynamicConfig) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder)

Example 40 with StatusResponseHolder

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;
}
Also used : Request(org.apache.druid.java.util.http.client.Request) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) ISE(org.apache.druid.java.util.common.ISE) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) URL(java.net.URL)

Aggregations

StatusResponseHolder (org.apache.druid.java.util.http.client.response.StatusResponseHolder)69 URL (java.net.URL)50 Request (org.apache.druid.java.util.http.client.Request)42 ISE (org.apache.druid.java.util.common.ISE)33 ExecutionException (java.util.concurrent.ExecutionException)13 Test (org.junit.Test)12 Lifecycle (org.apache.druid.java.util.common.lifecycle.Lifecycle)10 Map (java.util.Map)8 ArrayList (java.util.ArrayList)6 TypeReference (com.fasterxml.jackson.core.type.TypeReference)5 IOException (java.io.IOException)5 RE (org.apache.druid.java.util.common.RE)5 ChannelException (org.jboss.netty.channel.ChannelException)5 List (java.util.List)4 ExecutorService (java.util.concurrent.ExecutorService)4 Future (java.util.concurrent.Future)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3