Search in sources :

Example 1 with TestingResponse

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

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

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

Example 4 with TestingResponse

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

the class TestPageBufferClient method testInvalidResponses.

@Test
public void testInvalidResponses() throws Exception {
    DataSize expectedMaxSize = new DataSize(10, Unit.MEGABYTE);
    CyclicBarrier beforeRequest = new CyclicBarrier(1);
    CyclicBarrier afterRequest = new CyclicBarrier(1);
    StaticRequestProcessor processor = new StaticRequestProcessor(beforeRequest, afterRequest);
    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 not found response and verify response was ignored
    processor.setResponse(new TestingResponse(HttpStatus.NOT_FOUND, ImmutableListMultimap.of(CONTENT_TYPE, PRESTO_PAGES), new byte[0]));
    client.scheduleRequest(expectedMaxSize);
    requestComplete.await(10, TimeUnit.SECONDS);
    assertEquals(callback.getPages().size(), 0);
    assertEquals(callback.getCompletedRequests(), 1);
    assertEquals(callback.getFinishedBuffers(), 0);
    assertEquals(callback.getFailedBuffers(), 1);
    assertInstanceOf(callback.getFailure(), PageTransportErrorException.class);
    assertContains(callback.getFailure().getCause().getMessage(), "Expected response code to be 200, but was 404 Not Found");
    assertStatus(client, location, "queued", 0, 1, 1, 1, "not scheduled");
    // send invalid content type response and verify response was ignored
    callback.resetStats();
    processor.setResponse(new TestingResponse(HttpStatus.OK, ImmutableListMultimap.of(CONTENT_TYPE, "INVALID_TYPE"), new byte[0]));
    client.scheduleRequest(expectedMaxSize);
    requestComplete.await(10, TimeUnit.SECONDS);
    assertEquals(callback.getPages().size(), 0);
    assertEquals(callback.getCompletedRequests(), 1);
    assertEquals(callback.getFinishedBuffers(), 0);
    assertEquals(callback.getFailedBuffers(), 1);
    assertInstanceOf(callback.getFailure(), PageTransportErrorException.class);
    assertContains(callback.getFailure().getCause().getMessage(), "Expected application/x-presto-pages response from server but got INVALID_TYPE");
    assertStatus(client, location, "queued", 0, 2, 2, 2, "not scheduled");
    // send unexpected content type response and verify response was ignored
    callback.resetStats();
    processor.setResponse(new TestingResponse(HttpStatus.OK, ImmutableListMultimap.of(CONTENT_TYPE, "text/plain"), new byte[0]));
    client.scheduleRequest(expectedMaxSize);
    requestComplete.await(10, TimeUnit.SECONDS);
    assertEquals(callback.getPages().size(), 0);
    assertEquals(callback.getCompletedRequests(), 1);
    assertEquals(callback.getFinishedBuffers(), 0);
    assertEquals(callback.getFailedBuffers(), 1);
    assertInstanceOf(callback.getFailure(), PageTransportErrorException.class);
    assertContains(callback.getFailure().getCause().getMessage(), "Expected application/x-presto-pages response from server but got text/plain");
    assertStatus(client, location, "queued", 0, 3, 3, 3, "not scheduled");
    // close client and verify
    client.close();
    requestComplete.await(10, TimeUnit.SECONDS);
    assertStatus(client, location, "closed", 0, 3, 4, 3, "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 TestingResponse

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

the class TestFullSmileResponseHandler method testMissingContentType.

@Test
public void testMissingContentType() {
    SmileResponse<User> response = handler.handle(null, new TestingResponse(OK, ImmutableListMultimap.of(), "hello".getBytes(UTF_8)));
    assertFalse(response.hasValue());
    assertNull(response.getException());
    assertNull(response.getSmileBytes());
    assertEquals(response.getResponseBytes(), "hello".getBytes(UTF_8));
    assertTrue(response.getHeaders().isEmpty());
}
Also used : TestingResponse(com.facebook.airlift.http.client.testing.TestingResponse) Test(org.testng.annotations.Test)

Aggregations

TestingResponse (com.facebook.airlift.http.client.testing.TestingResponse)7 URI (java.net.URI)5 Test (org.testng.annotations.Test)5 TestingHttpClient (com.facebook.airlift.http.client.testing.TestingHttpClient)4 DataSize (io.airlift.units.DataSize)4 Duration (io.airlift.units.Duration)3 CyclicBarrier (java.util.concurrent.CyclicBarrier)3 DynamicSliceOutput (io.airlift.slice.DynamicSliceOutput)2 ServiceDescriptor (com.facebook.airlift.discovery.client.ServiceDescriptor)1 ServiceDescriptor.serviceDescriptor (com.facebook.airlift.discovery.client.ServiceDescriptor.serviceDescriptor)1 ServiceSelector (com.facebook.airlift.discovery.client.ServiceSelector)1 DEFAULT_POOL (com.facebook.airlift.discovery.client.ServiceSelectorConfig.DEFAULT_POOL)1 HttpClient (com.facebook.airlift.http.client.HttpClient)1 HttpStatus (com.facebook.airlift.http.client.HttpStatus)1 OK (com.facebook.airlift.http.client.HttpStatus.OK)1 NodeConfig (com.facebook.airlift.node.NodeConfig)1 NodeInfo (com.facebook.airlift.node.NodeInfo)1 Assertions.assertEqualsIgnoreOrder (com.facebook.airlift.testing.Assertions.assertEqualsIgnoreOrder)1 NodeVersion (com.facebook.presto.client.NodeVersion)1 Page (com.facebook.presto.common.Page)1