Search in sources :

Example 6 with TestingTicker

use of com.facebook.airlift.testing.TestingTicker in project presto by prestodb.

the class TestBackoff method testMinTries.

@Test
public void testMinTries() {
    TestingTicker ticker = new TestingTicker();
    ticker.increment(1, NANOSECONDS);
    Backoff backoff = new Backoff(3, new Duration(1, NANOSECONDS), ticker, ImmutableList.of(new Duration(10, MILLISECONDS)));
    ticker.increment(10, MICROSECONDS);
    // verify initial state
    assertEquals(backoff.getFailureCount(), 0);
    assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 0);
    // first failure, should never fail
    assertFalse(backoff.failure());
    assertEquals(backoff.getFailureCount(), 1);
    assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 0);
    ticker.increment(14, SECONDS);
    // second failure under min failures, should not fail
    assertFalse(backoff.failure());
    assertEquals(backoff.getFailureCount(), 2);
    assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 14);
    ticker.increment(1, SECONDS);
    // last try failed
    assertTrue(backoff.failure());
    assertEquals(backoff.getFailureCount(), 3);
    assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 15);
}
Also used : TestingTicker(com.facebook.airlift.testing.TestingTicker) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Example 7 with TestingTicker

use of com.facebook.airlift.testing.TestingTicker in project presto by prestodb.

the class TestBackoff method testDelay.

@Test
public void testDelay() {
    // 1, 2, 4, 8
    TestingTicker ticker = new TestingTicker();
    ticker.increment(1, NANOSECONDS);
    Backoff backoff = new Backoff(1, new Duration(15, SECONDS), ticker, ImmutableList.of(new Duration(0, SECONDS), new Duration(1, SECONDS), new Duration(2, SECONDS), new Duration(4, SECONDS), new Duration(8, SECONDS)));
    assertEquals(backoff.getFailureCount(), 0);
    assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 0);
    assertFalse(backoff.failure());
    assertEquals(backoff.getFailureCount(), 1);
    assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 0);
    long backoffDelay = backoff.getBackoffDelayNanos();
    assertEquals(NANOSECONDS.toSeconds(backoffDelay), 0);
    ticker.increment(backoffDelay, NANOSECONDS);
    assertFalse(backoff.failure());
    assertEquals(backoff.getFailureCount(), 2);
    assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 0);
    backoffDelay = backoff.getBackoffDelayNanos();
    assertEquals(NANOSECONDS.toSeconds(backoffDelay), 1);
    ticker.increment(backoffDelay, NANOSECONDS);
    assertFalse(backoff.failure());
    assertEquals(backoff.getFailureCount(), 3);
    assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 1);
    backoffDelay = backoff.getBackoffDelayNanos();
    assertEquals(NANOSECONDS.toSeconds(backoffDelay), 2);
    ticker.increment(backoffDelay, NANOSECONDS);
    assertFalse(backoff.failure());
    assertEquals(backoff.getFailureCount(), 4);
    assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 3);
    backoffDelay = backoff.getBackoffDelayNanos();
    assertEquals(NANOSECONDS.toSeconds(backoffDelay), 4);
    ticker.increment(backoffDelay, NANOSECONDS);
    assertFalse(backoff.failure());
    assertEquals(backoff.getFailureCount(), 5);
    assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 7);
    backoffDelay = backoff.getBackoffDelayNanos();
    assertEquals(NANOSECONDS.toSeconds(backoffDelay), 8);
    ticker.increment(backoffDelay, NANOSECONDS);
    assertTrue(backoff.failure());
    assertEquals(backoff.getFailureCount(), 6);
    assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 15);
    backoffDelay = backoff.getBackoffDelayNanos();
    assertEquals(NANOSECONDS.toSeconds(backoffDelay), 8);
}
Also used : TestingTicker(com.facebook.airlift.testing.TestingTicker) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Example 8 with TestingTicker

use of com.facebook.airlift.testing.TestingTicker in project presto by prestodb.

the class TestBackoff method testFailureInterval.

@Test
public void testFailureInterval() {
    TestingTicker ticker = new TestingTicker();
    ticker.increment(1, NANOSECONDS);
    Backoff backoff = new Backoff(1, new Duration(15, SECONDS), ticker, ImmutableList.of(new Duration(10, MILLISECONDS)));
    ticker.increment(10, MICROSECONDS);
    // verify initial state
    assertEquals(backoff.getFailureCount(), 0);
    assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 0);
    // first failure, should never fail
    assertFalse(backoff.failure());
    assertEquals(backoff.getFailureCount(), 1);
    assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 0);
    ticker.increment(14, SECONDS);
    // second failure within the limit, should not fail
    assertFalse(backoff.failure());
    assertEquals(backoff.getFailureCount(), 2);
    assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 14);
    ticker.increment(1, SECONDS);
    // final failure after the limit causes failure
    assertTrue(backoff.failure());
    assertEquals(backoff.getFailureCount(), 3);
    assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 15);
}
Also used : TestingTicker(com.facebook.airlift.testing.TestingTicker) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Example 9 with TestingTicker

use of com.facebook.airlift.testing.TestingTicker in project presto by prestodb.

the class TestQueryStateMachine method testPlanningTimeDuration.

@Test
public void testPlanningTimeDuration() {
    TestingTicker mockTicker = new TestingTicker();
    QueryStateMachine stateMachine = createQueryStateMachineWithTicker(mockTicker);
    assertState(stateMachine, WAITING_FOR_PREREQUISITES);
    mockTicker.increment(30, MILLISECONDS);
    stateMachine.beginSemanticAnalyzing();
    assertState(stateMachine, WAITING_FOR_PREREQUISITES);
    mockTicker.increment(30, MILLISECONDS);
    stateMachine.beginColumnAccessPermissionChecking();
    assertState(stateMachine, WAITING_FOR_PREREQUISITES);
    mockTicker.increment(15, MILLISECONDS);
    assertTrue(stateMachine.transitionToQueued());
    assertState(stateMachine, QUEUED);
    mockTicker.increment(30, MILLISECONDS);
    stateMachine.endColumnAccessPermissionChecking();
    assertState(stateMachine, QUEUED);
    mockTicker.increment(25, MILLISECONDS);
    assertTrue(stateMachine.transitionToWaitingForResources());
    assertState(stateMachine, WAITING_FOR_RESOURCES);
    mockTicker.increment(50, MILLISECONDS);
    assertTrue(stateMachine.transitionToDispatching());
    assertState(stateMachine, DISPATCHING);
    mockTicker.increment(100, MILLISECONDS);
    assertTrue(stateMachine.transitionToPlanning());
    assertState(stateMachine, PLANNING);
    mockTicker.increment(200, MILLISECONDS);
    assertTrue(stateMachine.transitionToStarting());
    assertState(stateMachine, STARTING);
    mockTicker.increment(300, MILLISECONDS);
    assertTrue(stateMachine.transitionToRunning());
    assertState(stateMachine, RUNNING);
    mockTicker.increment(400, MILLISECONDS);
    assertTrue(stateMachine.transitionToFinishing());
    tryGetFutureValue(stateMachine.getStateChange(FINISHING), 2, SECONDS);
    assertState(stateMachine, FINISHED);
    QueryStats queryStats = stateMachine.getQueryInfo(Optional.empty()).getQueryStats();
    assertEquals(queryStats.getElapsedTime().toMillis(), 1180);
    assertEquals(queryStats.getWaitingForPrerequisitesTime().toMillis(), 75);
    assertEquals(queryStats.getSemanticAnalyzingTime().toMillis(), 30);
    assertEquals(queryStats.getColumnAccessPermissionCheckingTime().toMillis(), 45);
    assertEquals(queryStats.getQueuedTime().toMillis(), 55);
    assertEquals(queryStats.getResourceWaitingTime().toMillis(), 50);
    assertEquals(queryStats.getDispatchingTime().toMillis(), 100);
    assertEquals(queryStats.getTotalPlanningTime().toMillis(), 200);
    // there is no way to induce finishing time without a transaction and connector
    assertEquals(queryStats.getFinishingTime().toMillis(), 0);
    // query execution time is starts when query transitions to planning
    assertEquals(queryStats.getExecutionTime().toMillis(), 900);
}
Also used : TestingTicker(com.facebook.airlift.testing.TestingTicker) Test(org.testng.annotations.Test)

Example 10 with TestingTicker

use of com.facebook.airlift.testing.TestingTicker in project presto by prestodb.

the class TestQueryStateMachine method assertAllTimeSpentInWaitingForPrerequisites.

private void assertAllTimeSpentInWaitingForPrerequisites(QueryState expectedState, Consumer<QueryStateMachine> stateTransition) {
    TestingTicker ticker = new TestingTicker();
    QueryStateMachine stateMachine = createQueryStateMachineWithTicker(ticker);
    ticker.increment(7, MILLISECONDS);
    stateTransition.accept(stateMachine);
    assertEquals(stateMachine.getQueryState(), expectedState);
    QueryStats queryStats = stateMachine.getQueryInfo(Optional.empty()).getQueryStats();
    assertEquals(queryStats.getWaitingForPrerequisitesTime(), new Duration(7, MILLISECONDS));
    assertEquals(queryStats.getQueuedTime(), new Duration(0, MILLISECONDS));
    assertEquals(queryStats.getResourceWaitingTime(), new Duration(0, MILLISECONDS));
    assertEquals(queryStats.getSemanticAnalyzingTime(), new Duration(0, MILLISECONDS));
    assertEquals(queryStats.getColumnAccessPermissionCheckingTime(), new Duration(0, MILLISECONDS));
    assertEquals(queryStats.getDispatchingTime(), new Duration(0, MILLISECONDS));
    assertEquals(queryStats.getTotalPlanningTime(), new Duration(0, MILLISECONDS));
    assertEquals(queryStats.getExecutionTime(), new Duration(0, MILLISECONDS));
    assertEquals(queryStats.getFinishingTime(), new Duration(0, MILLISECONDS));
}
Also used : TestingTicker(com.facebook.airlift.testing.TestingTicker) Duration(io.airlift.units.Duration)

Aggregations

TestingTicker (com.facebook.airlift.testing.TestingTicker)21 Test (org.testng.annotations.Test)19 Duration (io.airlift.units.Duration)16 TaskId (com.facebook.presto.execution.TaskId)7 Phaser (java.util.concurrent.Phaser)7 Page (com.facebook.presto.common.Page)4 ExpressionProfiler (com.facebook.presto.sql.gen.ExpressionProfiler)3 Optional (java.util.Optional)3 InternalNode (com.facebook.presto.metadata.InternalNode)2 Node (com.facebook.presto.spi.Node)2 List (java.util.List)2 Threads.daemonThreadsNamed (com.facebook.airlift.concurrent.Threads.daemonThreadsNamed)1 HttpStatus (com.facebook.airlift.http.client.HttpStatus)1 Request (com.facebook.airlift.http.client.Request)1 Response (com.facebook.airlift.http.client.Response)1 TestingHttpClient (com.facebook.airlift.http.client.testing.TestingHttpClient)1 TestingResponse (com.facebook.airlift.http.client.testing.TestingResponse)1 Assertions.assertContains (com.facebook.airlift.testing.Assertions.assertContains)1 Assertions.assertInstanceOf (com.facebook.airlift.testing.Assertions.assertInstanceOf)1 PRESTO_PAGES (com.facebook.presto.PrestoMediaTypes.PRESTO_PAGES)1