Search in sources :

Example 1 with TestingHttpClient

use of com.facebook.airlift.http.client.testing.TestingHttpClient 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 TestingHttpClient

use of com.facebook.airlift.http.client.testing.TestingHttpClient 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 TestingHttpClient

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

the class TestDiscoveryNodeManager method setup.

@BeforeMethod
public void setup() {
    testHttpClient = new TestingHttpClient(input -> new TestingResponse(OK, ArrayListMultimap.create(), ACTIVE.name().getBytes()));
    expectedVersion = new NodeVersion("1");
    coordinator = new InternalNode(UUID.randomUUID().toString(), URI.create("https://192.0.2.8"), expectedVersion, true);
    resourceManager = new InternalNode(UUID.randomUUID().toString(), URI.create("https://192.0.2.9"), expectedVersion, false, true);
    currentNode = new InternalNode(nodeInfo.getNodeId(), URI.create("http://192.0.1.1"), expectedVersion, false);
    activeNodes = ImmutableSet.of(currentNode, new InternalNode(UUID.randomUUID().toString(), URI.create("http://192.0.2.1:8080"), expectedVersion, false), new InternalNode(UUID.randomUUID().toString(), URI.create("http://192.0.2.3"), expectedVersion, false), coordinator, resourceManager);
    inactiveNodes = ImmutableSet.of(new InternalNode(UUID.randomUUID().toString(), URI.create("https://192.0.3.9"), NodeVersion.UNKNOWN, false), new InternalNode(UUID.randomUUID().toString(), URI.create("https://192.0.4.9"), new NodeVersion("2"), false));
    selector.announceNodes(activeNodes, inactiveNodes);
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Iterables(com.google.common.collect.Iterables) ServiceDescriptor(com.facebook.airlift.discovery.client.ServiceDescriptor) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TestingDriftClient(com.facebook.presto.operator.TestingDriftClient) NodeInfo(com.facebook.airlift.node.NodeInfo) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) NodeVersion(com.facebook.presto.client.NodeVersion) ACTIVE(com.facebook.presto.spi.NodeState.ACTIVE) DEFAULT_POOL(com.facebook.airlift.discovery.client.ServiceSelectorConfig.DEFAULT_POOL) ImmutableList(com.google.common.collect.ImmutableList) Assert.assertNotSame(org.testng.Assert.assertNotSame) TestingHttpClient(com.facebook.airlift.http.client.testing.TestingHttpClient) OK(com.facebook.airlift.http.client.HttpStatus.OK) TestingResponse(com.facebook.airlift.http.client.testing.TestingResponse) ServiceSelector(com.facebook.airlift.discovery.client.ServiceSelector) URI(java.net.URI) ImmutableSet(com.google.common.collect.ImmutableSet) Assertions.assertEqualsIgnoreOrder(com.facebook.airlift.testing.Assertions.assertEqualsIgnoreOrder) InternalCommunicationConfig(com.facebook.presto.server.InternalCommunicationConfig) ServiceDescriptor.serviceDescriptor(com.facebook.airlift.discovery.client.ServiceDescriptor.serviceDescriptor) BeforeMethod(org.testng.annotations.BeforeMethod) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) UUID(java.util.UUID) GuardedBy(javax.annotation.concurrent.GuardedBy) HttpClient(com.facebook.airlift.http.client.HttpClient) NodeConfig(com.facebook.airlift.node.NodeConfig) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) List(java.util.List) NoOpFailureDetector(com.facebook.presto.failureDetector.NoOpFailureDetector) Optional(java.util.Optional) INACTIVE(com.facebook.presto.spi.NodeState.INACTIVE) NodeVersion(com.facebook.presto.client.NodeVersion) TestingResponse(com.facebook.airlift.http.client.testing.TestingResponse) TestingHttpClient(com.facebook.airlift.http.client.testing.TestingHttpClient) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with TestingHttpClient

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

the class TestPageBufferClient method testLifecycle.

@Test
public void testLifecycle() throws Exception {
    DataSize expectedMaxSize = new DataSize(10, Unit.MEGABYTE);
    CyclicBarrier beforeRequest = new CyclicBarrier(2);
    CyclicBarrier afterRequest = new CyclicBarrier(2);
    StaticRequestProcessor processor = new StaticRequestProcessor(beforeRequest, afterRequest);
    processor.setResponse(new TestingResponse(HttpStatus.NO_CONTENT, ImmutableListMultimap.of(), new byte[0]));
    CyclicBarrier requestComplete = new CyclicBarrier(2);
    TestingClientCallback callback = new TestingClientCallback(requestComplete);
    URI location = URI.create("http://localhost:8080");
    PageBufferClient client = new PageBufferClient(new HttpRpcShuffleClient(new TestingHttpClient(processor, scheduler), location), new Duration(1, TimeUnit.MINUTES), true, location, Optional.empty(), callback, scheduler, pageBufferClientCallbackExecutor);
    assertStatus(client, location, "queued", 0, 0, 0, 0, "not scheduled");
    client.scheduleRequest(expectedMaxSize);
    beforeRequest.await(10, TimeUnit.SECONDS);
    assertStatus(client, location, "running", 0, 1, 0, 0, "processing request");
    assertEquals(client.isRunning(), true);
    afterRequest.await(10, TimeUnit.SECONDS);
    requestComplete.await(10, TimeUnit.SECONDS);
    assertStatus(client, location, "queued", 0, 1, 1, 1, "not scheduled");
    client.close();
    beforeRequest.await(10, TimeUnit.SECONDS);
    assertStatus(client, location, "closed", 0, 1, 1, 1, "processing request");
    afterRequest.await(10, TimeUnit.SECONDS);
    requestComplete.await(10, TimeUnit.SECONDS);
    assertStatus(client, location, "closed", 0, 1, 2, 1, "not scheduled");
}
Also used : TestingResponse(com.facebook.airlift.http.client.testing.TestingResponse) DataSize(io.airlift.units.DataSize) TestingHttpClient(com.facebook.airlift.http.client.testing.TestingHttpClient) Duration(io.airlift.units.Duration) URI(java.net.URI) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.testng.annotations.Test)

Example 5 with TestingHttpClient

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

the class TestPageBufferClient method testCloseDuringPendingRequest.

@Test
public void testCloseDuringPendingRequest() throws Exception {
    DataSize expectedMaxSize = new DataSize(10, Unit.MEGABYTE);
    CyclicBarrier beforeRequest = new CyclicBarrier(2);
    CyclicBarrier afterRequest = new CyclicBarrier(2);
    StaticRequestProcessor processor = new StaticRequestProcessor(beforeRequest, afterRequest);
    processor.setResponse(new TestingResponse(HttpStatus.NO_CONTENT, ImmutableListMultimap.of(), new byte[0]));
    CyclicBarrier requestComplete = new CyclicBarrier(2);
    TestingClientCallback callback = new TestingClientCallback(requestComplete);
    URI location = URI.create("http://localhost:8080");
    PageBufferClient client = new PageBufferClient(new HttpRpcShuffleClient(new TestingHttpClient(processor, scheduler), location), new Duration(1, TimeUnit.MINUTES), true, location, Optional.empty(), callback, scheduler, pageBufferClientCallbackExecutor);
    assertStatus(client, location, "queued", 0, 0, 0, 0, "not scheduled");
    // send request
    client.scheduleRequest(expectedMaxSize);
    beforeRequest.await(10, TimeUnit.SECONDS);
    assertStatus(client, location, "running", 0, 1, 0, 0, "processing request");
    assertEquals(client.isRunning(), true);
    // request is pending, now close it
    client.close();
    try {
        requestComplete.await(10, TimeUnit.SECONDS);
    } catch (BrokenBarrierException ignored) {
    }
    try {
        afterRequest.await(10, TimeUnit.SECONDS);
    } catch (BrokenBarrierException ignored) {
        afterRequest.reset();
    }
    // client.close() triggers a DELETE request, so wait for it to finish
    beforeRequest.await(10, TimeUnit.SECONDS);
    afterRequest.await(10, TimeUnit.SECONDS);
    requestComplete.await(10, TimeUnit.SECONDS);
    assertStatus(client, location, "closed", 0, 1, 2, 1, "not scheduled");
}
Also used : TestingResponse(com.facebook.airlift.http.client.testing.TestingResponse) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) DataSize(io.airlift.units.DataSize) TestingHttpClient(com.facebook.airlift.http.client.testing.TestingHttpClient) Duration(io.airlift.units.Duration) URI(java.net.URI) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.testng.annotations.Test)

Aggregations

TestingHttpClient (com.facebook.airlift.http.client.testing.TestingHttpClient)12 Duration (io.airlift.units.Duration)7 URI (java.net.URI)6 Test (org.testng.annotations.Test)6 TestingResponse (com.facebook.airlift.http.client.testing.TestingResponse)5 DataSize (io.airlift.units.DataSize)5 CyclicBarrier (java.util.concurrent.CyclicBarrier)5 HttpClient (com.facebook.airlift.http.client.HttpClient)3 Page (com.facebook.presto.common.Page)2 InternalCommunicationConfig (com.facebook.presto.server.InternalCommunicationConfig)2 SerializedPage (com.facebook.presto.spi.page.SerializedPage)2 List (java.util.List)2 Optional (java.util.Optional)2 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)2 Assert.assertEquals (org.testng.Assert.assertEquals)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 Bootstrap (com.facebook.airlift.bootstrap.Bootstrap)1 Threads.daemonThreadsNamed (com.facebook.airlift.concurrent.Threads.daemonThreadsNamed)1 ConfigBinder.configBinder (com.facebook.airlift.configuration.ConfigBinder.configBinder)1 ServiceDescriptor (com.facebook.airlift.discovery.client.ServiceDescriptor)1