use of com.facebook.presto.client.ServerInfo in project presto by prestodb.
the class QueryExecutor method getServerInfo.
public ServerInfo getServerInfo(URI server) {
HttpUrl url = HttpUrl.get(server);
if (url == null) {
throw new ClientException("Invalid server URL: " + server);
}
url = url.newBuilder().encodedPath("/v1/info").build();
Request request = new Request.Builder().url(url).build();
JsonResponse<ServerInfo> response = JsonResponse.execute(SERVER_INFO_CODEC, httpClient, request);
if (!response.hasValue()) {
throw new RuntimeException(format("Request to %s failed: %s [Error: %s]", server, response, response.getResponseBody()));
}
return response.getValue();
}
use of com.facebook.presto.client.ServerInfo in project presto by prestodb.
the class TestQueryExecutor method testGetServerInfo.
@Test
public void testGetServerInfo() throws Exception {
ServerInfo expected = new ServerInfo(UNKNOWN, "test", true, false, Optional.of(Duration.valueOf("2m")));
server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, "application/json").setBody(SERVER_INFO_CODEC.toJson(expected)));
QueryExecutor executor = new QueryExecutor(new OkHttpClient());
ServerInfo actual = executor.getServerInfo(server.url("/v1/info").uri());
assertEquals(actual.getEnvironment(), "test");
assertEquals(actual.getUptime(), Optional.of(Duration.valueOf("2m")));
assertEquals(server.getRequestCount(), 1);
assertEquals(server.takeRequest().getPath(), "/v1/info");
}
Aggregations