Search in sources :

Example 71 with Duration

use of io.airlift.units.Duration in project presto by prestodb.

the class TestExchangeClient method testAddLocation.

@Test(timeOut = 10000)
public void testAddLocation() throws Exception {
    DataSize maxResponseSize = new DataSize(10, Unit.MEGABYTE);
    MockExchangeRequestProcessor processor = new MockExchangeRequestProcessor(maxResponseSize);
    @SuppressWarnings("resource") ExchangeClient exchangeClient = new ExchangeClient(new DataSize(32, Unit.MEGABYTE), maxResponseSize, 1, new Duration(1, TimeUnit.MINUTES), new Duration(1, TimeUnit.MINUTES), new TestingHttpClient(processor, newCachedThreadPool(daemonThreadsNamed("test-%s"))), executor, deltaMemoryInBytes -> {
    });
    URI location1 = URI.create("http://localhost:8081/foo");
    processor.addPage(location1, createPage(1));
    processor.addPage(location1, createPage(2));
    processor.addPage(location1, createPage(3));
    processor.setComplete(location1);
    exchangeClient.addLocation(location1);
    assertEquals(exchangeClient.isClosed(), false);
    assertPageEquals(exchangeClient.getNextPage(new Duration(1, TimeUnit.SECONDS)), createPage(1));
    assertEquals(exchangeClient.isClosed(), false);
    assertPageEquals(exchangeClient.getNextPage(new Duration(1, TimeUnit.SECONDS)), createPage(2));
    assertEquals(exchangeClient.isClosed(), false);
    assertPageEquals(exchangeClient.getNextPage(new Duration(1, TimeUnit.SECONDS)), createPage(3));
    assertNull(exchangeClient.getNextPage(new Duration(10, MILLISECONDS)));
    assertEquals(exchangeClient.isClosed(), false);
    URI location2 = URI.create("http://localhost:8082/bar");
    processor.addPage(location2, createPage(4));
    processor.addPage(location2, createPage(5));
    processor.addPage(location2, createPage(6));
    processor.setComplete(location2);
    exchangeClient.addLocation(location2);
    assertEquals(exchangeClient.isClosed(), false);
    assertPageEquals(exchangeClient.getNextPage(new Duration(1, TimeUnit.SECONDS)), createPage(4));
    assertEquals(exchangeClient.isClosed(), false);
    assertPageEquals(exchangeClient.getNextPage(new Duration(1, TimeUnit.SECONDS)), createPage(5));
    assertEquals(exchangeClient.isClosed(), false);
    assertPageEquals(exchangeClient.getNextPage(new Duration(1, TimeUnit.SECONDS)), createPage(6));
    assertNull(exchangeClient.getNextPage(new Duration(10, MILLISECONDS)));
    assertEquals(exchangeClient.isClosed(), false);
    exchangeClient.noMoreLocations();
    // receive a final GONE response, so just spin until it's closed or the test times out.
    while (!exchangeClient.isClosed()) {
        Thread.sleep(1);
    }
    ImmutableMap<URI, PageBufferClientStatus> statuses = uniqueIndex(exchangeClient.getStatus().getPageBufferClientStatuses(), PageBufferClientStatus::getUri);
    assertStatus(statuses.get(location1), location1, "closed", 3, 3, 3, "not scheduled");
    assertStatus(statuses.get(location2), location2, "closed", 3, 3, 3, "not scheduled");
}
Also used : DataSize(io.airlift.units.DataSize) TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) Duration(io.airlift.units.Duration) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 72 with Duration

use of io.airlift.units.Duration in project presto by prestodb.

the class TestExchangeOperator method setUp.

@SuppressWarnings("resource")
@BeforeClass
public void setUp() throws Exception {
    executor = newScheduledThreadPool(4, daemonThreadsNamed("test-%s"));
    httpClient = new TestingHttpClient(new HttpClientHandler(taskBuffers), executor);
    exchangeClientSupplier = (systemMemoryUsageListener) -> new ExchangeClient(new DataSize(32, MEGABYTE), new DataSize(10, MEGABYTE), 3, new Duration(1, TimeUnit.MINUTES), new Duration(1, TimeUnit.MINUTES), httpClient, executor, systemMemoryUsageListener);
}
Also used : TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) DataSize(io.airlift.units.DataSize) Duration(io.airlift.units.Duration) BeforeClass(org.testng.annotations.BeforeClass)

Example 73 with Duration

use of io.airlift.units.Duration in project presto by prestodb.

the class TestOperatorStats method testAddMergeable.

@Test
public void testAddMergeable() {
    OperatorStats actual = MERGEABLE.add(MERGEABLE, MERGEABLE);
    assertEquals(actual.getOperatorId(), 41);
    assertEquals(actual.getOperatorType(), "test");
    assertEquals(actual.getTotalDrivers(), 3 * 1);
    assertEquals(actual.getAddInputCalls(), 3 * 2);
    assertEquals(actual.getAddInputWall(), new Duration(3 * 3, NANOSECONDS));
    assertEquals(actual.getAddInputCpu(), new Duration(3 * 4, NANOSECONDS));
    assertEquals(actual.getAddInputUser(), new Duration(3 * 5, NANOSECONDS));
    assertEquals(actual.getInputDataSize(), new DataSize(3 * 6, BYTE));
    assertEquals(actual.getInputPositions(), 3 * 7);
    assertEquals(actual.getSumSquaredInputPositions(), 3 * 8.0);
    assertEquals(actual.getGetOutputCalls(), 3 * 9);
    assertEquals(actual.getGetOutputWall(), new Duration(3 * 10, NANOSECONDS));
    assertEquals(actual.getGetOutputCpu(), new Duration(3 * 11, NANOSECONDS));
    assertEquals(actual.getGetOutputUser(), new Duration(3 * 12, NANOSECONDS));
    assertEquals(actual.getOutputDataSize(), new DataSize(3 * 13, BYTE));
    assertEquals(actual.getOutputPositions(), 3 * 14);
    assertEquals(actual.getBlockedWall(), new Duration(3 * 15, NANOSECONDS));
    assertEquals(actual.getFinishCalls(), 3 * 16);
    assertEquals(actual.getFinishWall(), new Duration(3 * 17, NANOSECONDS));
    assertEquals(actual.getFinishCpu(), new Duration(3 * 18, NANOSECONDS));
    assertEquals(actual.getFinishUser(), new Duration(3 * 19, NANOSECONDS));
    assertEquals(actual.getMemoryReservation(), new DataSize(3 * 20, BYTE));
    assertEquals(actual.getSystemMemoryReservation(), new DataSize(3 * 21, BYTE));
    assertEquals(actual.getInfo().getClass(), PartitionedOutputInfo.class);
    assertEquals(((PartitionedOutputInfo) actual.getInfo()).getPagesAdded(), 3 * MERGEABLE_INFO.getPagesAdded());
}
Also used : DataSize(io.airlift.units.DataSize) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Example 74 with Duration

use of io.airlift.units.Duration in project presto by prestodb.

the class TestOperatorStats method assertExpectedOperatorStats.

public static void assertExpectedOperatorStats(OperatorStats actual) {
    assertEquals(actual.getOperatorId(), 41);
    assertEquals(actual.getOperatorType(), "test");
    assertEquals(actual.getTotalDrivers(), 1);
    assertEquals(actual.getAddInputCalls(), 2);
    assertEquals(actual.getAddInputWall(), new Duration(3, NANOSECONDS));
    assertEquals(actual.getAddInputCpu(), new Duration(4, NANOSECONDS));
    assertEquals(actual.getAddInputUser(), new Duration(5, NANOSECONDS));
    assertEquals(actual.getInputDataSize(), new DataSize(6, BYTE));
    assertEquals(actual.getInputPositions(), 7);
    assertEquals(actual.getSumSquaredInputPositions(), 8.0);
    assertEquals(actual.getGetOutputCalls(), 9);
    assertEquals(actual.getGetOutputWall(), new Duration(10, NANOSECONDS));
    assertEquals(actual.getGetOutputCpu(), new Duration(11, NANOSECONDS));
    assertEquals(actual.getGetOutputUser(), new Duration(12, NANOSECONDS));
    assertEquals(actual.getOutputDataSize(), new DataSize(13, BYTE));
    assertEquals(actual.getOutputPositions(), 14);
    assertEquals(actual.getBlockedWall(), new Duration(15, NANOSECONDS));
    assertEquals(actual.getFinishCalls(), 16);
    assertEquals(actual.getFinishWall(), new Duration(17, NANOSECONDS));
    assertEquals(actual.getFinishCpu(), new Duration(18, NANOSECONDS));
    assertEquals(actual.getFinishUser(), new Duration(19, NANOSECONDS));
    assertEquals(actual.getMemoryReservation(), new DataSize(20, BYTE));
    assertEquals(actual.getSystemMemoryReservation(), new DataSize(21, BYTE));
    assertEquals(actual.getInfo().getClass(), ExchangeClientStatus.class);
    assertEquals(((ExchangeClientStatus) actual.getInfo()).getAverageBytesPerRequest(), NON_MERGEABLE_INFO.getAverageBytesPerRequest());
}
Also used : DataSize(io.airlift.units.DataSize) Duration(io.airlift.units.Duration)

Example 75 with Duration

use of io.airlift.units.Duration in project presto by prestodb.

the class TestPipelineStats method assertExpectedPipelineStats.

public static void assertExpectedPipelineStats(PipelineStats actual) {
    assertEquals(actual.getFirstStartTime(), new DateTime(100, UTC));
    assertEquals(actual.getLastStartTime(), new DateTime(101, UTC));
    assertEquals(actual.getLastEndTime(), new DateTime(102, UTC));
    assertEquals(actual.isInputPipeline(), true);
    assertEquals(actual.isOutputPipeline(), false);
    assertEquals(actual.getTotalDrivers(), 1);
    assertEquals(actual.getQueuedDrivers(), 2);
    assertEquals(actual.getQueuedPartitionedDrivers(), 1);
    assertEquals(actual.getRunningDrivers(), 3);
    assertEquals(actual.getRunningPartitionedDrivers(), 2);
    assertEquals(actual.getCompletedDrivers(), 4);
    assertEquals(actual.getMemoryReservation(), new DataSize(5, BYTE));
    assertEquals(actual.getSystemMemoryReservation(), new DataSize(6, BYTE));
    assertEquals(actual.getQueuedTime().getCount(), 7.0);
    assertEquals(actual.getElapsedTime().getCount(), 8.0);
    assertEquals(actual.getTotalScheduledTime(), new Duration(9, NANOSECONDS));
    assertEquals(actual.getTotalCpuTime(), new Duration(10, NANOSECONDS));
    assertEquals(actual.getTotalUserTime(), new Duration(11, NANOSECONDS));
    assertEquals(actual.getTotalBlockedTime(), new Duration(12, NANOSECONDS));
    assertEquals(actual.getRawInputDataSize(), new DataSize(13, BYTE));
    assertEquals(actual.getRawInputPositions(), 14);
    assertEquals(actual.getProcessedInputDataSize(), new DataSize(15, BYTE));
    assertEquals(actual.getProcessedInputPositions(), 16);
    assertEquals(actual.getOutputDataSize(), new DataSize(17, BYTE));
    assertEquals(actual.getOutputPositions(), 18);
    assertEquals(actual.getOperatorSummaries().size(), 1);
    assertExpectedOperatorStats(actual.getOperatorSummaries().get(0));
    assertEquals(actual.getDrivers().size(), 1);
    assertExpectedDriverStats(actual.getDrivers().get(0));
}
Also used : DataSize(io.airlift.units.DataSize) Duration(io.airlift.units.Duration) DateTime(org.joda.time.DateTime)

Aggregations

Duration (io.airlift.units.Duration)124 Test (org.testng.annotations.Test)66 DataSize (io.airlift.units.DataSize)35 URI (java.net.URI)12 TestingHttpClient (io.airlift.http.client.testing.TestingHttpClient)11 Session (com.facebook.presto.Session)9 DateTime (org.joda.time.DateTime)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 ImmutableSet (com.google.common.collect.ImmutableSet)8 TestingTicker (io.airlift.testing.TestingTicker)8 List (java.util.List)8 PrestoException (com.facebook.presto.spi.PrestoException)7 ImmutableList (com.google.common.collect.ImmutableList)7 File (java.io.File)6 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)5 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 CyclicBarrier (java.util.concurrent.CyclicBarrier)5 Produces (javax.ws.rs.Produces)5 Type (com.facebook.presto.spi.type.Type)4 IOException (java.io.IOException)4