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();
}
}
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();
}
}
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);
}
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);
}
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");
}
}
Aggregations