Search in sources :

Example 11 with Duration

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

the class TestTaskExecutor method test.

@Test(invocationCount = 100)
public void test() throws Exception {
    TestingTicker ticker = new TestingTicker();
    TaskExecutor taskExecutor = new TaskExecutor(4, 8, ticker);
    taskExecutor.start();
    ticker.increment(20, MILLISECONDS);
    try {
        TaskId taskId = new TaskId("test", 0, 0);
        TaskHandle taskHandle = taskExecutor.addTask(taskId, () -> 0, 10, new Duration(1, MILLISECONDS));
        Phaser beginPhase = new Phaser();
        beginPhase.register();
        Phaser verificationComplete = new Phaser();
        verificationComplete.register();
        // add two jobs
        TestingJob driver1 = new TestingJob(beginPhase, verificationComplete, 10);
        ListenableFuture<?> future1 = getOnlyElement(taskExecutor.enqueueSplits(taskHandle, true, ImmutableList.of(driver1)));
        TestingJob driver2 = new TestingJob(beginPhase, verificationComplete, 10);
        ListenableFuture<?> future2 = getOnlyElement(taskExecutor.enqueueSplits(taskHandle, true, ImmutableList.of(driver2)));
        assertEquals(driver1.getCompletedPhases(), 0);
        assertEquals(driver2.getCompletedPhases(), 0);
        // verify worker have arrived but haven't processed yet
        beginPhase.arriveAndAwaitAdvance();
        assertEquals(driver1.getCompletedPhases(), 0);
        assertEquals(driver2.getCompletedPhases(), 0);
        ticker.increment(10, MILLISECONDS);
        assertEquals(taskExecutor.getMaxActiveSplitTime(), 10);
        verificationComplete.arriveAndAwaitAdvance();
        // advance one phase and verify
        beginPhase.arriveAndAwaitAdvance();
        assertEquals(driver1.getCompletedPhases(), 1);
        assertEquals(driver2.getCompletedPhases(), 1);
        verificationComplete.arriveAndAwaitAdvance();
        // add one more job
        TestingJob driver3 = new TestingJob(beginPhase, verificationComplete, 10);
        ListenableFuture<?> future3 = getOnlyElement(taskExecutor.enqueueSplits(taskHandle, false, ImmutableList.of(driver3)));
        // advance one phase and verify
        beginPhase.arriveAndAwaitAdvance();
        assertEquals(driver1.getCompletedPhases(), 2);
        assertEquals(driver2.getCompletedPhases(), 2);
        assertEquals(driver3.getCompletedPhases(), 0);
        verificationComplete.arriveAndAwaitAdvance();
        // advance to the end of the first two task and verify
        beginPhase.arriveAndAwaitAdvance();
        for (int i = 0; i < 7; i++) {
            verificationComplete.arriveAndAwaitAdvance();
            beginPhase.arriveAndAwaitAdvance();
            assertEquals(beginPhase.getPhase(), verificationComplete.getPhase() + 1);
        }
        assertEquals(driver1.getCompletedPhases(), 10);
        assertEquals(driver2.getCompletedPhases(), 10);
        assertEquals(driver3.getCompletedPhases(), 8);
        future1.get(1, TimeUnit.SECONDS);
        future2.get(1, TimeUnit.SECONDS);
        verificationComplete.arriveAndAwaitAdvance();
        // advance two more times and verify
        beginPhase.arriveAndAwaitAdvance();
        verificationComplete.arriveAndAwaitAdvance();
        beginPhase.arriveAndAwaitAdvance();
        assertEquals(driver1.getCompletedPhases(), 10);
        assertEquals(driver2.getCompletedPhases(), 10);
        assertEquals(driver3.getCompletedPhases(), 10);
        future3.get(1, TimeUnit.SECONDS);
        verificationComplete.arriveAndAwaitAdvance();
        assertEquals(driver1.getFirstPhase(), 0);
        assertEquals(driver2.getFirstPhase(), 0);
        assertEquals(driver3.getFirstPhase(), 2);
        assertEquals(driver1.getLastPhase(), 10);
        assertEquals(driver2.getLastPhase(), 10);
        assertEquals(driver3.getLastPhase(), 12);
        // no splits remaining
        ticker.increment(30, MILLISECONDS);
        assertEquals(taskExecutor.getMaxActiveSplitTime(), 0);
    } finally {
        taskExecutor.stop();
    }
}
Also used : TestingTicker(io.airlift.testing.TestingTicker) Duration(io.airlift.units.Duration) Phaser(java.util.concurrent.Phaser) TaskHandle(com.facebook.presto.execution.TaskExecutor.TaskHandle) Test(org.testng.annotations.Test)

Example 12 with Duration

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

the class TestTaskExecutor method testTaskHandle.

@Test
public void testTaskHandle() throws Exception {
    TaskExecutor taskExecutor = new TaskExecutor(4, 8);
    taskExecutor.start();
    try {
        TaskId taskId = new TaskId("test", 0, 0);
        TaskHandle taskHandle = taskExecutor.addTask(taskId, () -> 0, 10, new Duration(1, MILLISECONDS));
        Phaser beginPhase = new Phaser();
        beginPhase.register();
        Phaser verificationComplete = new Phaser();
        verificationComplete.register();
        TestingJob driver1 = new TestingJob(beginPhase, verificationComplete, 10);
        TestingJob driver2 = new TestingJob(beginPhase, verificationComplete, 10);
        // force enqueue a split
        taskExecutor.enqueueSplits(taskHandle, true, ImmutableList.of(driver1));
        assertEquals(taskHandle.getRunningSplits(), 0);
        // normal enqueue a split
        taskExecutor.enqueueSplits(taskHandle, false, ImmutableList.of(driver2));
        assertEquals(taskHandle.getRunningSplits(), 1);
        // let the split continue to run
        beginPhase.arriveAndDeregister();
        verificationComplete.arriveAndDeregister();
    } finally {
        taskExecutor.stop();
    }
}
Also used : Duration(io.airlift.units.Duration) Phaser(java.util.concurrent.Phaser) TaskHandle(com.facebook.presto.execution.TaskExecutor.TaskHandle) Test(org.testng.annotations.Test)

Example 13 with Duration

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

the class TestQueryStateMachine method testStarting.

@Test
public void testStarting() throws InterruptedException {
    QueryStateMachine stateMachine = createQueryStateMachine();
    assertTrue(stateMachine.transitionToStarting());
    assertState(stateMachine, STARTING);
    assertFalse(stateMachine.transitionToPlanning());
    assertState(stateMachine, STARTING);
    assertFalse(stateMachine.transitionToStarting());
    assertState(stateMachine, STARTING);
    assertTrue(stateMachine.transitionToRunning());
    assertState(stateMachine, RUNNING);
    stateMachine = createQueryStateMachine();
    stateMachine.transitionToStarting();
    assertTrue(stateMachine.transitionToFinishing());
    stateMachine.waitForStateChange(FINISHING, new Duration(2, TimeUnit.SECONDS));
    assertState(stateMachine, FINISHED);
    stateMachine = createQueryStateMachine();
    stateMachine.transitionToStarting();
    assertTrue(stateMachine.transitionToFailed(FAILED_CAUSE));
    assertState(stateMachine, FAILED, FAILED_CAUSE);
}
Also used : Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Example 14 with Duration

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

the class TestQueryStateMachine method testPlanning.

@Test
public void testPlanning() throws InterruptedException {
    QueryStateMachine stateMachine = createQueryStateMachine();
    assertTrue(stateMachine.transitionToPlanning());
    assertState(stateMachine, PLANNING);
    assertFalse(stateMachine.transitionToPlanning());
    assertState(stateMachine, PLANNING);
    assertTrue(stateMachine.transitionToStarting());
    assertState(stateMachine, STARTING);
    stateMachine = createQueryStateMachine();
    stateMachine.transitionToPlanning();
    assertTrue(stateMachine.transitionToRunning());
    assertState(stateMachine, RUNNING);
    stateMachine = createQueryStateMachine();
    stateMachine.transitionToPlanning();
    assertTrue(stateMachine.transitionToFinishing());
    stateMachine.waitForStateChange(FINISHING, new Duration(2, TimeUnit.SECONDS));
    assertState(stateMachine, FINISHED);
    stateMachine = createQueryStateMachine();
    stateMachine.transitionToPlanning();
    assertTrue(stateMachine.transitionToFailed(FAILED_CAUSE));
    assertState(stateMachine, FAILED, FAILED_CAUSE);
}
Also used : Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Example 15 with Duration

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

the class TestDriver method testBrokenOperatorCloseWhileProcessing.

@Test
public void testBrokenOperatorCloseWhileProcessing() throws Exception {
    BrokenOperator brokenOperator = new BrokenOperator(driverContext.addOperatorContext(0, new PlanNodeId("test"), "source"), false);
    final Driver driver = new Driver(driverContext, brokenOperator, createSinkOperator(brokenOperator));
    assertSame(driver.getDriverContext(), driverContext);
    // 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();
    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 : PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) Duration(io.airlift.units.Duration) ExecutionException(java.util.concurrent.ExecutionException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) 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