Search in sources :

Example 1 with PartialResultQueryManager

use of com.facebook.presto.execution.PartialResultQueryManager in project presto by prestodb.

the class TestPartialResultQueryTaskTracker method testPartialResultQueryTaskTracker.

@Test
public void testPartialResultQueryTaskTracker() throws Exception {
    PartialResultQueryTaskTracker tracker = new PartialResultQueryTaskTracker(partialResultQueryManager, 0.50, 2.0, warningCollector);
    InternalNode node1 = new InternalNode(UUID.randomUUID().toString(), URI.create("https://192.0.2.8"), new NodeVersion("1"), false, false);
    InternalNode node2 = new InternalNode(UUID.randomUUID().toString(), URI.create("https://192.0.2.9"), new NodeVersion("1"), false, false);
    TaskId taskId1 = new TaskId("test1", 1, 0, 1);
    TaskId taskId2 = new TaskId("test2", 2, 0, 1);
    RemoteTask task1 = taskFactory.createTableScanTask(taskId1, node1, ImmutableList.of(), new NodeTaskMap.NodeStatsTracker(delta -> {
    }, delta -> {
    }, (age, delta) -> {
    }));
    RemoteTask task2 = taskFactory.createTableScanTask(taskId2, node2, ImmutableList.of(), new NodeTaskMap.NodeStatsTracker(delta -> {
    }, delta -> {
    }, (age, delta) -> {
    }));
    tracker.trackTask(task1);
    tracker.trackTask(task2);
    // Assert that completion ratio is 0.0 since the tasks did not complete yet
    assertEquals(0.0, tracker.getTaskCompletionRatio());
    tracker.completeTaskScheduling();
    tracker.recordTaskFinish(task1.getTaskInfo());
    // Assert that completion ratio is 0.5 since we have set that task1 finished in above line
    assertEquals(0.5, tracker.getTaskCompletionRatio());
    // Assert that the query is added to query manager, queue size = 1 since the query reached minCompletion ratio of 0.5 and is eligible for partial results
    assertEquals(1, partialResultQueryManager.getQueueSize());
    // Sleep for 2 seconds so that we give enough time for query manager to cancel tasks and complete the query with partial results
    Thread.sleep(2000);
    assertEquals(0, partialResultQueryManager.getQueueSize());
    // Assert that partial result warning is set correctly
    assertEquals(1, warningCollector.getWarnings().size());
    PrestoWarning prestoWarning = warningCollector.getWarnings().get(0);
    // Assert that warning code is set to PARTIAL_RESULT_WARNING
    assertEquals(PARTIAL_RESULT_WARNING.toWarningCode(), prestoWarning.getWarningCode());
    // Assert that completion percent of 50.00 is specified correctly in the warning message
    assertEquals("Partial results are returned. Only 50.00 percent of the data is read.", prestoWarning.getMessage());
}
Also used : NodeVersion(com.facebook.presto.client.NodeVersion) WarningCollector(com.facebook.presto.spi.WarningCollector) AfterClass(org.testng.annotations.AfterClass) NodeTaskMap(com.facebook.presto.execution.NodeTaskMap) PARTIAL_RESULT_WARNING(com.facebook.presto.spi.StandardWarningCode.PARTIAL_RESULT_WARNING) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) NodeVersion(com.facebook.presto.client.NodeVersion) UUID(java.util.UUID) NORMAL(com.facebook.presto.execution.warnings.WarningHandlingLevel.NORMAL) MockRemoteTaskFactory(com.facebook.presto.execution.MockRemoteTaskFactory) InternalNode(com.facebook.presto.metadata.InternalNode) Threads.daemonThreadsNamed(com.facebook.airlift.concurrent.Threads.daemonThreadsNamed) RemoteTask(com.facebook.presto.execution.RemoteTask) WarningCollectorConfig(com.facebook.presto.execution.warnings.WarningCollectorConfig) ImmutableList(com.google.common.collect.ImmutableList) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) TaskId(com.facebook.presto.execution.TaskId) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) PrestoWarning(com.facebook.presto.spi.PrestoWarning) DefaultWarningCollector(com.facebook.presto.execution.warnings.DefaultWarningCollector) URI(java.net.URI) ExecutorService(java.util.concurrent.ExecutorService) PartialResultQueryManager(com.facebook.presto.execution.PartialResultQueryManager) TaskId(com.facebook.presto.execution.TaskId) NodeTaskMap(com.facebook.presto.execution.NodeTaskMap) PrestoWarning(com.facebook.presto.spi.PrestoWarning) RemoteTask(com.facebook.presto.execution.RemoteTask) InternalNode(com.facebook.presto.metadata.InternalNode) Test(org.testng.annotations.Test)

Aggregations

Threads.daemonThreadsNamed (com.facebook.airlift.concurrent.Threads.daemonThreadsNamed)1 NodeVersion (com.facebook.presto.client.NodeVersion)1 MockRemoteTaskFactory (com.facebook.presto.execution.MockRemoteTaskFactory)1 NodeTaskMap (com.facebook.presto.execution.NodeTaskMap)1 PartialResultQueryManager (com.facebook.presto.execution.PartialResultQueryManager)1 RemoteTask (com.facebook.presto.execution.RemoteTask)1 TaskId (com.facebook.presto.execution.TaskId)1 DefaultWarningCollector (com.facebook.presto.execution.warnings.DefaultWarningCollector)1 WarningCollectorConfig (com.facebook.presto.execution.warnings.WarningCollectorConfig)1 NORMAL (com.facebook.presto.execution.warnings.WarningHandlingLevel.NORMAL)1 InternalNode (com.facebook.presto.metadata.InternalNode)1 PrestoWarning (com.facebook.presto.spi.PrestoWarning)1 PARTIAL_RESULT_WARNING (com.facebook.presto.spi.StandardWarningCode.PARTIAL_RESULT_WARNING)1 WarningCollector (com.facebook.presto.spi.WarningCollector)1 ImmutableList (com.google.common.collect.ImmutableList)1 URI (java.net.URI)1 UUID (java.util.UUID)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors.newCachedThreadPool (java.util.concurrent.Executors.newCachedThreadPool)1 Executors.newScheduledThreadPool (java.util.concurrent.Executors.newScheduledThreadPool)1