Search in sources :

Example 1 with StringResponse

use of com.facebook.airlift.http.client.StringResponseHandler.StringResponse in project presto by prestodb.

the class TestGenerateTokenFilter method testTraceToken.

@Test
public void testTraceToken() {
    Request request = prepareGet().setUri(server.getBaseUrl().resolve("/testing/echo_token")).build();
    StringResponse response = httpClient.execute(request, createStringResponseHandler());
    assertEquals(response.getStatusCode(), SC_OK);
    assertEquals(response.getBody(), filter.getLastToken());
}
Also used : Request(com.facebook.airlift.http.client.Request) StringResponse(com.facebook.airlift.http.client.StringResponseHandler.StringResponse) Test(org.testng.annotations.Test)

Example 2 with StringResponse

use of com.facebook.airlift.http.client.StringResponseHandler.StringResponse in project presto by prestodb.

the class ClusterSizeFetcher method fetchClusterSize.

private int fetchClusterSize() {
    Request request = prepareGet().setUri(nodeResourceUri).setHeader(CONTENT_TYPE, APPLICATION_JSON).build();
    StringResponse response = httpClient.execute(request, createStringResponseHandler());
    checkState(response.getStatusCode() == OK.getStatusCode(), "Invalid response: %s %s", response.getStatusCode(), response.getStatusMessage());
    List<Map<String, Object>> values;
    try {
        values = new JsonObjectMapperProvider().get().readValue(response.getBody(), new TypeReference<List<Map<String, Object>>>() {
        });
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return values.size();
}
Also used : JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) Request(com.facebook.airlift.http.client.Request) UncheckedIOException(java.io.UncheckedIOException) StringResponse(com.facebook.airlift.http.client.StringResponseHandler.StringResponse) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Map(java.util.Map)

Aggregations

Request (com.facebook.airlift.http.client.Request)2 StringResponse (com.facebook.airlift.http.client.StringResponseHandler.StringResponse)2 JsonObjectMapperProvider (com.facebook.airlift.json.JsonObjectMapperProvider)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Map (java.util.Map)1 Test (org.testng.annotations.Test)1