Search in sources :

Example 41 with QueryId

use of io.trino.spi.QueryId in project trino by trinodb.

the class TestQueues method testResourceGroupManagerWithTwoDashboardQueriesRequestedAtTheSameTime.

@Test(timeOut = 240_000)
public void testResourceGroupManagerWithTwoDashboardQueriesRequestedAtTheSameTime() throws Exception {
    try (DistributedQueryRunner queryRunner = createQueryRunner()) {
        queryRunner.installPlugin(new ResourceGroupManagerPlugin());
        queryRunner.getCoordinator().getResourceGroupManager().get().setConfigurationManager("file", ImmutableMap.of("resource-groups.config-file", getResourceFilePath("resource_groups_config_dashboard.json")));
        QueryId firstDashboardQuery = createDashboardQuery(queryRunner);
        QueryId secondDashboardQuery = createDashboardQuery(queryRunner);
        ImmutableSet<QueryState> queuedOrRunning = ImmutableSet.of(QUEUED, RUNNING);
        waitForQueryState(queryRunner, firstDashboardQuery, queuedOrRunning);
        waitForQueryState(queryRunner, secondDashboardQuery, queuedOrRunning);
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) QueryId(io.trino.spi.QueryId) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) TestQueryRunnerUtil.waitForQueryState(io.trino.execution.TestQueryRunnerUtil.waitForQueryState) Test(org.testng.annotations.Test)

Example 42 with QueryId

use of io.trino.spi.QueryId in project trino by trinodb.

the class TestQueues method testResourceGroupManager.

@Test(timeOut = 240_000)
public void testResourceGroupManager() throws Exception {
    try (DistributedQueryRunner queryRunner = createQueryRunner()) {
        queryRunner.installPlugin(new ResourceGroupManagerPlugin());
        queryRunner.getCoordinator().getResourceGroupManager().get().setConfigurationManager("file", ImmutableMap.of("resource-groups.config-file", getResourceFilePath("resource_groups_config_dashboard.json")));
        // submit first "dashboard" query
        QueryId firstDashboardQuery = createDashboardQuery(queryRunner);
        // wait for the first "dashboard" query to start
        waitForQueryState(queryRunner, firstDashboardQuery, RUNNING);
        // submit second "dashboard" query
        QueryId secondDashboardQuery = createDashboardQuery(queryRunner);
        // wait for the second "dashboard" query to be queued ("dashboard.${USER}" queue strategy only allows one "dashboard" query to be accepted for execution)
        waitForQueryState(queryRunner, secondDashboardQuery, QUEUED);
        // submit first non "dashboard" query
        QueryId firstNonDashboardQuery = createAdHocQuery(queryRunner);
        // wait for the first non "dashboard" query to start
        waitForQueryState(queryRunner, firstNonDashboardQuery, RUNNING);
        // submit second non "dashboard" query
        QueryId secondNonDashboardQuery = createAdHocQuery(queryRunner);
        // wait for the second non "dashboard" query to start
        waitForQueryState(queryRunner, secondNonDashboardQuery, RUNNING);
        // cancel first "dashboard" query, second "dashboard" query and second non "dashboard" query should start running
        cancelQuery(queryRunner, firstDashboardQuery);
        waitForQueryState(queryRunner, firstDashboardQuery, FAILED);
        waitForQueryState(queryRunner, secondDashboardQuery, RUNNING);
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) QueryId(io.trino.spi.QueryId) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) Test(org.testng.annotations.Test)

Example 43 with QueryId

use of io.trino.spi.QueryId in project trino by trinodb.

the class TestQueues method assertResourceGroup.

private void assertResourceGroup(DistributedQueryRunner queryRunner, Session session, String query, ResourceGroupId expectedResourceGroup) throws InterruptedException {
    QueryId queryId = createQuery(queryRunner, session, query);
    waitForQueryState(queryRunner, queryId, ImmutableSet.of(RUNNING, FINISHED));
    Optional<ResourceGroupId> resourceGroupId = queryRunner.getCoordinator().getQueryManager().getFullQueryInfo(queryId).getResourceGroupId();
    assertTrue(resourceGroupId.isPresent(), "Query should have a resource group");
    assertEquals(resourceGroupId.get(), expectedResourceGroup, format("Expected: '%s' resource group, found: %s", expectedResourceGroup, resourceGroupId.get()));
}
Also used : ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) QueryId(io.trino.spi.QueryId)

Example 44 with QueryId

use of io.trino.spi.QueryId in project trino by trinodb.

the class TestQueues method testRejection.

private void testRejection() throws Exception {
    try (DistributedQueryRunner queryRunner = createQueryRunner()) {
        queryRunner.installPlugin(new ResourceGroupManagerPlugin());
        queryRunner.getCoordinator().getResourceGroupManager().get().setConfigurationManager("file", ImmutableMap.of("resource-groups.config-file", getResourceFilePath("resource_groups_config_dashboard.json")));
        QueryId queryId = createQuery(queryRunner, newRejectionSession(), LONG_LASTING_QUERY);
        waitForQueryState(queryRunner, queryId, FAILED);
        DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
        assertEquals(dispatchManager.getQueryInfo(queryId).getErrorCode(), QUERY_REJECTED.toErrorCode());
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) DispatchManager(io.trino.dispatcher.DispatchManager) QueryId(io.trino.spi.QueryId) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin)

Example 45 with QueryId

use of io.trino.spi.QueryId in project trino by trinodb.

the class TestFinalQueryInfo method testFinalQueryInfoSetOnAbort.

@Test(timeOut = 240_000)
public void testFinalQueryInfoSetOnAbort() throws Exception {
    try (DistributedQueryRunner queryRunner = createQueryRunner(TEST_SESSION)) {
        QueryId queryId = startQuery("SELECT COUNT(*) FROM tpch.sf1000.lineitem", queryRunner);
        SettableFuture<QueryInfo> finalQueryInfoFuture = SettableFuture.create();
        queryRunner.getCoordinator().addFinalQueryInfoListener(queryId, finalQueryInfoFuture::set);
        // wait 1s then kill query
        Thread.sleep(1_000);
        queryRunner.getCoordinator().getQueryManager().cancelQuery(queryId);
        // wait for final query info
        QueryInfo finalQueryInfo = tryGetFutureValue(finalQueryInfoFuture, 10, SECONDS).orElseThrow(() -> new AssertionError("Final query info never set"));
        assertTrue(finalQueryInfo.isFinalQueryInfo());
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) QueryId(io.trino.spi.QueryId) Test(org.testng.annotations.Test)

Aggregations

QueryId (io.trino.spi.QueryId)103 Test (org.testng.annotations.Test)70 TaskId (io.trino.execution.TaskId)26 StageId (io.trino.execution.StageId)24 Map (java.util.Map)17 ImmutableMap (com.google.common.collect.ImmutableMap)16 DynamicFilterId (io.trino.sql.planner.plan.DynamicFilterId)15 DistributedQueryRunner (io.trino.testing.DistributedQueryRunner)14 Optional (java.util.Optional)13 Duration (io.airlift.units.Duration)12 Session (io.trino.Session)12 DynamicFilter (io.trino.spi.connector.DynamicFilter)12 Symbol (io.trino.sql.planner.Symbol)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 TestingColumnHandle (io.trino.spi.connector.TestingColumnHandle)11 SymbolAllocator (io.trino.sql.planner.SymbolAllocator)11 Set (java.util.Set)10 AccessDeniedException (io.trino.spi.security.AccessDeniedException)9 Assert.assertEquals (org.testng.Assert.assertEquals)9 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)8