Search in sources :

Example 16 with TestingTicker

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

the class TestTaskExecutor method testLevelMovement.

@Test(invocationCount = 100)
public void testLevelMovement() {
    TestingTicker ticker = new TestingTicker();
    TaskExecutor taskExecutor = new TaskExecutor(2, 2, 3, 4, TASK_FAIR, ticker);
    taskExecutor.start();
    ticker.increment(20, MILLISECONDS);
    try {
        TaskHandle testTaskHandle = taskExecutor.addTask(new TaskId("test", 0, 0, 0), () -> 0, 10, new Duration(1, MILLISECONDS), OptionalInt.empty());
        Phaser globalPhaser = new Phaser();
        globalPhaser.bulkRegister(3);
        int quantaTimeMills = 500;
        int phasesPerSecond = 1000 / quantaTimeMills;
        int totalPhases = LEVEL_THRESHOLD_SECONDS[LEVEL_THRESHOLD_SECONDS.length - 1] * phasesPerSecond;
        TestingJob driver1 = new TestingJob(ticker, globalPhaser, new Phaser(), new Phaser(), totalPhases, quantaTimeMills);
        TestingJob driver2 = new TestingJob(ticker, globalPhaser, new Phaser(), new Phaser(), totalPhases, quantaTimeMills);
        taskExecutor.enqueueSplits(testTaskHandle, true, ImmutableList.of(driver1, driver2));
        int completedPhases = 0;
        for (int i = 0; i < (LEVEL_THRESHOLD_SECONDS.length - 1); i++) {
            for (; (completedPhases / phasesPerSecond) < LEVEL_THRESHOLD_SECONDS[i + 1]; completedPhases++) {
                globalPhaser.arriveAndAwaitAdvance();
            }
            assertEquals(testTaskHandle.getPriority().getLevel(), i + 1);
        }
        globalPhaser.arriveAndDeregister();
    } finally {
        taskExecutor.stop();
    }
}
Also used : TestingTicker(com.facebook.airlift.testing.TestingTicker) TaskId(com.facebook.presto.execution.TaskId) Duration(io.airlift.units.Duration) Phaser(java.util.concurrent.Phaser) Test(org.testng.annotations.Test)

Example 17 with TestingTicker

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

the class TestTaskExecutor method testUserSpecifiedMaxDriversPerTask.

@Test(timeOut = 30_000)
public void testUserSpecifiedMaxDriversPerTask() {
    MultilevelSplitQueue splitQueue = new MultilevelSplitQueue(2);
    TestingTicker ticker = new TestingTicker();
    // create a task executor with min/max drivers per task to be 2 and 4
    TaskExecutor taskExecutor = new TaskExecutor(4, 16, 2, 4, TASK_FAIR, splitQueue, ticker);
    taskExecutor.start();
    try {
        // overwrite the max drivers per task to be 1
        TaskHandle testTaskHandle = taskExecutor.addTask(new TaskId("test", 0, 0, 0), () -> 0, 10, new Duration(1, MILLISECONDS), OptionalInt.of(1));
        // enqueue all batches of splits
        int batchCount = 4;
        TestingJob[] splits = new TestingJob[4];
        Phaser[] phasers = new Phaser[batchCount];
        for (int batch = 0; batch < batchCount; batch++) {
            phasers[batch] = new Phaser();
            phasers[batch].register();
            TestingJob split = new TestingJob(ticker, new Phaser(), new Phaser(), phasers[batch], 1, 0);
            splits[batch] = split;
            taskExecutor.enqueueSplits(testTaskHandle, false, ImmutableList.of(split));
        }
        // assert that the splits are processed in batches as expected
        for (int batch = 0; batch < batchCount; batch++) {
            // wait until the current batch starts
            waitUntilSplitsStart(ImmutableList.of(splits[batch]));
            // assert that only the splits including and up to the current batch are running and the rest haven't started yet
            assertSplitStates(batch, splits);
            // complete the current batch
            phasers[batch].arriveAndDeregister();
        }
    } finally {
        taskExecutor.stop();
    }
}
Also used : TestingTicker(com.facebook.airlift.testing.TestingTicker) TaskId(com.facebook.presto.execution.TaskId) Duration(io.airlift.units.Duration) Phaser(java.util.concurrent.Phaser) Test(org.testng.annotations.Test)

Example 18 with TestingTicker

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

the class TestBackoff method testStartRequest.

@Test
public void testStartRequest() {
    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);
    assertFalse(backoff.failure());
    assertEquals(backoff.getFailureCount(), 1);
    assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 0);
    assertEquals(backoff.getFailureRequestTimeTotal().roundTo(SECONDS), 0);
    ticker.increment(7, SECONDS);
    backoff.startRequest();
    ticker.increment(7, SECONDS);
    assertFalse(backoff.failure());
    assertEquals(backoff.getFailureCount(), 2);
    assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 14);
    // failed request took 7 seconds.
    assertEquals(backoff.getFailureRequestTimeTotal().roundTo(SECONDS), 7);
    ticker.increment(1, SECONDS);
    backoff.startRequest();
    ticker.increment(1, SECONDS);
    assertTrue(backoff.failure());
    assertEquals(backoff.getFailureCount(), 3);
    assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 16);
    // failed requests took 7+1 seconds.
    assertEquals(backoff.getFailureRequestTimeTotal().roundTo(SECONDS), 8);
}
Also used : TestingTicker(com.facebook.airlift.testing.TestingTicker) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Example 19 with TestingTicker

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

the class TestDatabaseShardManager method testBucketAssignments.

@Test
public void testBucketAssignments() {
    Node node1 = createTestingNode();
    Node node2 = createTestingNode();
    Node node3 = createTestingNode();
    TestingTicker ticker = new TestingTicker();
    MetadataDao metadataDao = dbi.onDemand(MetadataDao.class);
    int bucketCount = 13;
    long distributionId = metadataDao.insertDistribution(null, "test", bucketCount);
    Set<Node> originalNodes = ImmutableSet.of(node1, node2);
    ShardManager shardManager = createShardManager(dbi, () -> originalNodes, ticker);
    shardManager.createBuckets(distributionId, bucketCount);
    List<String> assignments = shardManager.getBucketAssignments(distributionId);
    assertEquals(assignments.size(), bucketCount);
    assertEquals(ImmutableSet.copyOf(assignments), nodeIds(originalNodes));
    Set<Node> newNodes = ImmutableSet.of(node1, node3);
    shardManager = createShardManager(dbi, () -> newNodes, ticker);
    try {
        shardManager.getBucketAssignments(distributionId);
        fail("expected exception");
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), SERVER_STARTING_UP.toErrorCode());
    }
    ticker.increment(2, DAYS);
    assignments = shardManager.getBucketAssignments(distributionId);
    assertEquals(assignments.size(), bucketCount);
    assertEquals(ImmutableSet.copyOf(assignments), nodeIds(newNodes));
    Set<Node> singleNode = ImmutableSet.of(node1);
    shardManager = createShardManager(dbi, () -> singleNode, ticker);
    ticker.increment(2, DAYS);
    assignments = shardManager.getBucketAssignments(distributionId);
    assertEquals(assignments.size(), bucketCount);
    assertEquals(ImmutableSet.copyOf(assignments), nodeIds(singleNode));
}
Also used : TestingTicker(com.facebook.airlift.testing.TestingTicker) Node(com.facebook.presto.spi.Node) InternalNode(com.facebook.presto.metadata.InternalNode) PrestoException(com.facebook.presto.spi.PrestoException) Test(org.testng.annotations.Test)

Example 20 with TestingTicker

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

the class TestAssignmentLimiter method testNotEnoughNodes.

@Test
public void testNotEnoughNodes() throws Exception {
    TestingTicker ticker = new TestingTicker();
    HashSet<Node> nodes = new HashSet<>();
    Node node1 = new InternalNode("node1", new URI("http://127.0.0.1/"), NodeVersion.UNKNOWN, false);
    Node node2 = new InternalNode("node2", new URI("http://127.0.0.2/"), NodeVersion.UNKNOWN, false);
    nodes.add(node1);
    nodes.add(node2);
    AssignmentLimiter limiter = new AssignmentLimiter(() -> nodes, ticker, new Duration(0, SECONDS), new Duration(0, SECONDS), 2);
    ticker.increment(1, SECONDS);
    limiter.checkAssignFrom("node3");
    nodes.remove(node1);
    assertCheckFails(limiter, "node3", RAPTOR_NOT_ENOUGH_NODES);
}
Also used : TestingTicker(com.facebook.airlift.testing.TestingTicker) InternalNode(com.facebook.presto.metadata.InternalNode) Node(com.facebook.presto.spi.Node) Duration(io.airlift.units.Duration) InternalNode(com.facebook.presto.metadata.InternalNode) URI(java.net.URI) HashSet(java.util.HashSet) 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