Search in sources :

Example 1 with HttpClient

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

the class TestPinotClusterInfoFetcher method testBrokersParsed.

private void testBrokersParsed(boolean useHttps) {
    HttpClient httpClient = new TestingHttpClient(request -> {
        Assert.assertEquals(request.getUri().getScheme(), useHttps ? "https" : "http");
        return TestingResponse.mockResponse(HttpStatus.OK, MediaType.JSON_UTF_8, "{\n" + "  \"tableName\": \"dummy\",\n" + "  \"brokers\": [\n" + "    {\n" + "      \"tableType\": \"offline\",\n" + "      \"instances\": [\n" + "        \"Broker_dummy-broker-host1-datacenter1_6513\",\n" + "        \"Broker_dummy-broker-host2-datacenter1_6513\",\n" + "        \"Broker_dummy-broker-host4-datacenter1_6513\"\n" + "      ]\n" + "    },\n" + "    {\n" + "      \"tableType\": \"realtime\",\n" + "      \"instances\": [\n" + "        \"Broker_dummy-broker-host1-datacenter1_6513\",\n" + "        \"Broker_dummy-broker-host2-datacenter1_6513\",\n" + "        \"Broker_dummy-broker-host3-datacenter1_6513\"\n" + "      ]\n" + "    }\n" + "  ],\n" + "  \"server\": [\n" + "    {\n" + "      \"tableType\": \"offline\",\n" + "      \"instances\": [\n" + "        \"Server_dummy-server-host8-datacenter1_7090\",\n" + "        \"Server_dummy-server-host9-datacenter1_7090\"\n" + "      ]\n" + "    },\n" + "    {\n" + "      \"tableType\": \"realtime\",\n" + "      \"instances\": [\n" + "        \"Server_dummy-server-host7-datacenter1_7090\",\n" + "        \"Server_dummy-server-host4-datacenter1_7090\",\n" + "        \"Server_dummy-server-host5-datacenter1_7090\",\n" + "        \"Server_dummy-server-host6-datacenter1_7090\"\n" + "      ]\n" + "    }\n" + "  ]\n" + "}");
    });
    PinotConfig pinotConfig = new PinotConfig().setMetadataCacheExpiry(new Duration(0, TimeUnit.MILLISECONDS)).setControllerUrls("localhost:7900").setUseHttpsForController(useHttps);
    PinotClusterInfoFetcher pinotClusterInfoFetcher = new PinotClusterInfoFetcher(pinotConfig, new PinotMetrics(), httpClient, MetadataUtil.TABLES_JSON_CODEC, MetadataUtil.BROKERS_FOR_TABLE_JSON_CODEC, MetadataUtil.ROUTING_TABLES_JSON_CODEC, MetadataUtil.ROUTING_TABLES_V2_JSON_CODEC, MetadataUtil.TIME_BOUNDARY_JSON_CODEC, MetadataUtil.INSTANCE_JSON_CODEC);
    ImmutableSet<String> brokers = ImmutableSet.copyOf(pinotClusterInfoFetcher.getAllBrokersForTable("dummy"));
    Assert.assertEquals(ImmutableSet.of("dummy-broker-host1-datacenter1:6513", "dummy-broker-host2-datacenter1:6513", "dummy-broker-host3-datacenter1:6513", "dummy-broker-host4-datacenter1:6513"), brokers);
}
Also used : TestingHttpClient(com.facebook.airlift.http.client.testing.TestingHttpClient) HttpClient(com.facebook.airlift.http.client.HttpClient) TestingHttpClient(com.facebook.airlift.http.client.testing.TestingHttpClient) Duration(io.airlift.units.Duration)

Example 2 with HttpClient

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

the class TestPinotClusterInfoFetcher method testInstanceParsed.

private void testInstanceParsed(boolean useHttps) {
    HttpClient httpClient = new TestingHttpClient((request) -> {
        Assert.assertEquals(request.getUri().getScheme(), useHttps ? "https" : "http");
        return TestingResponse.mockResponse(HttpStatus.OK, MediaType.JSON_UTF_8, "{\n" + "  \"instanceName\": \"Server_192.168.1.19_8098\",\n" + "  \"hostName\": \"192.168.1.19\",\n" + "  \"enabled\": true,\n" + "  \"port\": \"8098\",\n" + "  \"tags\": [\n" + "    \"DefaultTenant_OFFLINE\",\n" + "    \"DefaultTenant_REALTIME\"\n" + "  ],\n" + "  \"pools\": null,\n" + "  \"grpcPort\": 8090\n" + "}");
    });
    PinotConfig pinotConfig = new PinotConfig().setMetadataCacheExpiry(new Duration(0, TimeUnit.MILLISECONDS)).setControllerUrls("localhost:7900").setUseHttpsForController(useHttps);
    PinotClusterInfoFetcher pinotClusterInfoFetcher = new PinotClusterInfoFetcher(pinotConfig, new PinotMetrics(), httpClient, MetadataUtil.TABLES_JSON_CODEC, MetadataUtil.BROKERS_FOR_TABLE_JSON_CODEC, MetadataUtil.ROUTING_TABLES_JSON_CODEC, MetadataUtil.ROUTING_TABLES_V2_JSON_CODEC, MetadataUtil.TIME_BOUNDARY_JSON_CODEC, MetadataUtil.INSTANCE_JSON_CODEC);
    final PinotClusterInfoFetcher.Instance instance = pinotClusterInfoFetcher.getInstance("Server_192.168.1.19_8098");
    Assert.assertEquals(instance.getInstanceName(), "Server_192.168.1.19_8098");
    Assert.assertEquals(instance.getHostName(), "192.168.1.19");
    Assert.assertEquals(instance.isEnabled(), true);
    Assert.assertEquals(instance.getPort(), 8098);
    Assert.assertEquals(instance.getGrpcPort(), 8090);
    Assert.assertEquals(instance.getPools(), null);
    Assert.assertEquals(instance.getTags().size(), 2);
    Assert.assertEquals(instance.getTags().get(0), "DefaultTenant_OFFLINE");
    Assert.assertEquals(instance.getTags().get(1), "DefaultTenant_REALTIME");
}
Also used : TestingHttpClient(com.facebook.airlift.http.client.testing.TestingHttpClient) HttpClient(com.facebook.airlift.http.client.HttpClient) TestingHttpClient(com.facebook.airlift.http.client.testing.TestingHttpClient) Duration(io.airlift.units.Duration)

Example 3 with HttpClient

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

the class TestGenerateTokenFilter method setup.

@BeforeClass
public void setup() throws Exception {
    server = new TestingPrestoServer(ImmutableList.of(new TestGenerateTokenFilterModule()));
    httpClient = (JettyHttpClient) server.getInstance(Key.get(HttpClient.class, GenerateTokenFilterTest.class));
    // extract the filter
    List<HttpRequestFilter> filters = httpClient.getRequestFilters();
    assertEquals(filters.size(), 2);
    assertInstanceOf(filters.get(1), GenerateTraceTokenRequestFilter.class);
    filter = (GenerateTraceTokenRequestFilter) filters.get(1);
}
Also used : HttpRequestFilter(com.facebook.airlift.http.client.HttpRequestFilter) JettyHttpClient(com.facebook.airlift.http.client.jetty.JettyHttpClient) HttpClient(com.facebook.airlift.http.client.HttpClient) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

HttpClient (com.facebook.airlift.http.client.HttpClient)3 TestingHttpClient (com.facebook.airlift.http.client.testing.TestingHttpClient)2 Duration (io.airlift.units.Duration)2 HttpRequestFilter (com.facebook.airlift.http.client.HttpRequestFilter)1 JettyHttpClient (com.facebook.airlift.http.client.jetty.JettyHttpClient)1 TestingPrestoServer (com.facebook.presto.server.testing.TestingPrestoServer)1 BeforeClass (org.testng.annotations.BeforeClass)1