Search in sources :

Example 21 with TestingTicker

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

the class TestAssignmentLimiter method testLimiter.

@Test
public void testLimiter() {
    TestingTicker ticker = new TestingTicker();
    AssignmentLimiter limiter = new AssignmentLimiter(ImmutableSet::of, ticker, new Duration(5, MINUTES), new Duration(10, MINUTES), 0);
    // 4:00
    assertCheckFails(limiter, "A", RAPTOR_REASSIGNMENT_DELAY);
    // 4:01
    ticker.increment(1, MINUTES);
    assertCheckFails(limiter, "A", RAPTOR_REASSIGNMENT_DELAY);
    assertCheckFails(limiter, "B", RAPTOR_REASSIGNMENT_DELAY);
    // 4:05
    ticker.increment(4, MINUTES);
    limiter.checkAssignFrom("A");
    assertCheckFails(limiter, "B", RAPTOR_REASSIGNMENT_DELAY);
    // 4:06
    ticker.increment(1, MINUTES);
    assertCheckFails(limiter, "B", RAPTOR_REASSIGNMENT_THROTTLE);
    assertCheckFails(limiter, "C", RAPTOR_REASSIGNMENT_DELAY);
    // 4:14
    ticker.increment(8, MINUTES);
    assertCheckFails(limiter, "B", RAPTOR_REASSIGNMENT_THROTTLE);
    assertCheckFails(limiter, "C", RAPTOR_REASSIGNMENT_THROTTLE);
    // 4:15
    ticker.increment(1, MINUTES);
    limiter.checkAssignFrom("B");
    assertCheckFails(limiter, "C", RAPTOR_REASSIGNMENT_THROTTLE);
    // 4:24
    ticker.increment(9, MINUTES);
    assertCheckFails(limiter, "C", RAPTOR_REASSIGNMENT_THROTTLE);
    // 4:25
    ticker.increment(1, MINUTES);
    limiter.checkAssignFrom("A");
    // 4:30
    ticker.increment(5, MINUTES);
    limiter.checkAssignFrom("A");
    limiter.checkAssignFrom("B");
    limiter.checkAssignFrom("C");
}
Also used : TestingTicker(com.facebook.airlift.testing.TestingTicker) ImmutableSet(com.google.common.collect.ImmutableSet) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

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