Search in sources :

Example 1 with TaskHandle

use of com.facebook.presto.execution.TaskExecutor.TaskHandle 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 2 with TaskHandle

use of com.facebook.presto.execution.TaskExecutor.TaskHandle 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)

Aggregations

TaskHandle (com.facebook.presto.execution.TaskExecutor.TaskHandle)2 Duration (io.airlift.units.Duration)2 Phaser (java.util.concurrent.Phaser)2 Test (org.testng.annotations.Test)2 TestingTicker (io.airlift.testing.TestingTicker)1