Search in sources :

Example 16 with Duration

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

the class TestDriver method testNormalFinish.

@Test
public void testNormalFinish() {
    List<Type> types = ImmutableList.of(VARCHAR, BIGINT, BIGINT);
    ValuesOperator source = new ValuesOperator(driverContext.addOperatorContext(0, new PlanNodeId("test"), "values"), types, rowPagesBuilder(types).addSequencePage(10, 20, 30, 40).build());
    Operator sink = createSinkOperator(source);
    Driver driver = new Driver(driverContext, source, sink);
    assertSame(driver.getDriverContext(), driverContext);
    assertFalse(driver.isFinished());
    ListenableFuture<?> blocked = driver.processFor(new Duration(1, TimeUnit.SECONDS));
    assertTrue(blocked.isDone());
    assertTrue(driver.isFinished());
    assertTrue(sink.isFinished());
    assertTrue(source.isFinished());
}
Also used : PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) PageConsumerOperator(com.facebook.presto.testing.PageConsumerOperator) Type(com.facebook.presto.spi.type.Type) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Example 17 with Duration

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

the class TestDriver method testBrokenOperatorProcessWhileClosing.

@Test
public void testBrokenOperatorProcessWhileClosing() throws Exception {
    BrokenOperator brokenOperator = new BrokenOperator(driverContext.addOperatorContext(0, new PlanNodeId("test"), "source"), true);
    final Driver driver = new Driver(driverContext, brokenOperator, createSinkOperator(brokenOperator));
    assertSame(driver.getDriverContext(), driverContext);
    // block thread in operator close
    Future<Boolean> driverClose = executor.submit(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            driver.close();
            return true;
        }
    });
    brokenOperator.waitForLocked();
    assertTrue(driver.processFor(new Duration(1, TimeUnit.MILLISECONDS)).isDone());
    assertTrue(driver.isFinished());
    brokenOperator.unlock();
    assertTrue(driverClose.get());
}
Also used : PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) Duration(io.airlift.units.Duration) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test)

Example 18 with Duration

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

the class TestDriver method testBrokenOperatorAddSource.

@Test
public void testBrokenOperatorAddSource() throws Exception {
    PlanNodeId sourceId = new PlanNodeId("source");
    final List<Type> types = ImmutableList.of(VARCHAR, BIGINT, BIGINT);
    // create a table scan operator that does not block, which will cause the driver loop to busy wait
    TableScanOperator source = new NotBlockedTableScanOperator(driverContext.addOperatorContext(99, new PlanNodeId("test"), "values"), sourceId, new PageSourceProvider() {

        @Override
        public ConnectorPageSource createPageSource(Session session, Split split, List<ColumnHandle> columns) {
            return new FixedPageSource(rowPagesBuilder(types).addSequencePage(10, 20, 30, 40).build());
        }
    }, types, ImmutableList.of());
    BrokenOperator brokenOperator = new BrokenOperator(driverContext.addOperatorContext(0, new PlanNodeId("test"), "source"));
    final Driver driver = new Driver(driverContext, source, brokenOperator);
    // block thread in operator processing
    Future<Boolean> driverProcessFor = executor.submit(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return driver.processFor(new Duration(1, TimeUnit.MILLISECONDS)).isDone();
        }
    });
    brokenOperator.waitForLocked();
    assertSame(driver.getDriverContext(), driverContext);
    assertFalse(driver.isFinished());
    // processFor always returns NOT_BLOCKED, because DriveLockResult was not acquired
    assertTrue(driver.processFor(new Duration(1, TimeUnit.MILLISECONDS)).isDone());
    assertFalse(driver.isFinished());
    driver.updateSource(new TaskSource(sourceId, ImmutableSet.of(new ScheduledSplit(0, sourceId, newMockSplit())), true));
    assertFalse(driver.isFinished());
    // processFor always returns NOT_BLOCKED, because DriveLockResult was not acquired
    assertTrue(driver.processFor(new Duration(1, TimeUnit.SECONDS)).isDone());
    assertFalse(driver.isFinished());
    driver.close();
    assertTrue(driver.isFinished());
    try {
        driverProcessFor.get(1, TimeUnit.SECONDS);
        fail("Expected InterruptedException");
    } catch (ExecutionException e) {
        checkArgument(getRootCause(e) instanceof InterruptedException, "Expected root cause exception to be an instance of InterruptedException");
    }
}
Also used : PageSourceProvider(com.facebook.presto.split.PageSourceProvider) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ScheduledSplit(com.facebook.presto.ScheduledSplit) Duration(io.airlift.units.Duration) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) FixedPageSource(com.facebook.presto.spi.FixedPageSource) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) Type(com.facebook.presto.spi.type.Type) ScheduledSplit(com.facebook.presto.ScheduledSplit) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) Split(com.facebook.presto.metadata.Split) ExecutionException(java.util.concurrent.ExecutionException) TaskSource(com.facebook.presto.TaskSource) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 19 with Duration

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

the class TestDriver method testAddSourceFinish.

@Test
public void testAddSourceFinish() {
    PlanNodeId sourceId = new PlanNodeId("source");
    final List<Type> types = ImmutableList.of(VARCHAR, BIGINT, BIGINT);
    TableScanOperator source = new TableScanOperator(driverContext.addOperatorContext(99, new PlanNodeId("test"), "values"), sourceId, new PageSourceProvider() {

        @Override
        public ConnectorPageSource createPageSource(Session session, Split split, List<ColumnHandle> columns) {
            return new FixedPageSource(rowPagesBuilder(types).addSequencePage(10, 20, 30, 40).build());
        }
    }, types, ImmutableList.of());
    PageConsumerOperator sink = createSinkOperator(source);
    Driver driver = new Driver(driverContext, source, sink);
    assertSame(driver.getDriverContext(), driverContext);
    assertFalse(driver.isFinished());
    assertFalse(driver.processFor(new Duration(1, TimeUnit.MILLISECONDS)).isDone());
    assertFalse(driver.isFinished());
    driver.updateSource(new TaskSource(sourceId, ImmutableSet.of(new ScheduledSplit(0, sourceId, newMockSplit())), true));
    assertFalse(driver.isFinished());
    assertTrue(driver.processFor(new Duration(1, TimeUnit.SECONDS)).isDone());
    assertTrue(driver.isFinished());
    assertTrue(sink.isFinished());
    assertTrue(source.isFinished());
}
Also used : PageSourceProvider(com.facebook.presto.split.PageSourceProvider) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ScheduledSplit(com.facebook.presto.ScheduledSplit) Duration(io.airlift.units.Duration) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) FixedPageSource(com.facebook.presto.spi.FixedPageSource) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) PageConsumerOperator(com.facebook.presto.testing.PageConsumerOperator) Type(com.facebook.presto.spi.type.Type) ScheduledSplit(com.facebook.presto.ScheduledSplit) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) Split(com.facebook.presto.metadata.Split) TaskSource(com.facebook.presto.TaskSource) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 20 with Duration

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

the class TestExchangeClient method testHappyPath.

@Test
public void testHappyPath() throws Exception {
    DataSize maxResponseSize = new DataSize(10, Unit.MEGABYTE);
    MockExchangeRequestProcessor processor = new MockExchangeRequestProcessor(maxResponseSize);
    URI location = URI.create("http://localhost:8080");
    processor.addPage(location, createPage(1));
    processor.addPage(location, createPage(2));
    processor.addPage(location, createPage(3));
    processor.setComplete(location);
    @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, executor), executor, deltaMemoryInBytes -> {
    });
    exchangeClient.addLocation(location);
    exchangeClient.noMoreLocations();
    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(1, TimeUnit.SECONDS)));
    assertEquals(exchangeClient.isClosed(), true);
    if (exchangeClient.getStatus().getBufferedPages() != 0) {
        assertEquals(exchangeClient.getStatus().getBufferedPages(), 0);
    }
    assertTrue(exchangeClient.getStatus().getBufferedBytes() == 0);
    // client should have sent only 2 requests: one to get all pages and once to get the done signal
    assertStatus(exchangeClient.getStatus().getPageBufferClientStatuses().get(0), location, "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)

Aggregations

Duration (io.airlift.units.Duration)323 Test (org.testng.annotations.Test)203 DataSize (io.airlift.units.DataSize)66 ImmutableMap (com.google.common.collect.ImmutableMap)42 URI (java.net.URI)40 Map (java.util.Map)22 List (java.util.List)21 ImmutableList (com.google.common.collect.ImmutableList)18 TestingTicker (com.facebook.airlift.testing.TestingTicker)17 Optional (java.util.Optional)17 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)16 Assert.assertEquals (org.testng.Assert.assertEquals)16 Session (com.facebook.presto.Session)15 PrestoException (com.facebook.presto.spi.PrestoException)15 File (java.io.File)15 TaskId (com.facebook.presto.execution.TaskId)14 ImmutableSet (com.google.common.collect.ImmutableSet)14 SECONDS (java.util.concurrent.TimeUnit.SECONDS)13 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 TestingHttpClient (io.airlift.http.client.testing.TestingHttpClient)12