Search in sources :

Example 86 with QueryId

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

the class TestEnvironments method testEnvironment2.

@Test(timeOut = 240_000)
public void testEnvironment2() throws Exception {
    String dbConfigUrl = getDbConfigUrl();
    H2ResourceGroupsDao dao = getDao(dbConfigUrl);
    try (DistributedQueryRunner runner = createQueryRunner(dbConfigUrl, dao, TEST_ENVIRONMENT_2)) {
        QueryId firstQuery = createQuery(runner, adhocSession(), LONG_LASTING_QUERY);
        waitForQueryState(runner, firstQuery, RUNNING);
        QueryId secondQuery = createQuery(runner, adhocSession(), LONG_LASTING_QUERY);
        // there is no queueing in TEST_ENVIRONMENT_2, so the second query should fail right away
        waitForQueryState(runner, secondQuery, FAILED);
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) QueryId(io.trino.spi.QueryId) H2ResourceGroupsDao(io.trino.plugin.resourcegroups.db.H2ResourceGroupsDao) Test(org.testng.annotations.Test)

Example 87 with QueryId

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

the class TestQueuesDb method testBasic.

@Test(timeOut = 60_000)
public void testBasic() throws Exception {
    // submit first "dashboard" query
    QueryId firstDashboardQuery = createQuery(queryRunner, dashboardSession(), LONG_LASTING_QUERY);
    // wait for the first "dashboard" query to start
    waitForQueryState(queryRunner, firstDashboardQuery, RUNNING);
    waitForRunningQueryCount(queryRunner, 1);
    // submit second "dashboard" query
    QueryId secondDashboardQuery = createQuery(queryRunner, dashboardSession(), LONG_LASTING_QUERY);
    MILLISECONDS.sleep(2000);
    // 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);
    waitForRunningQueryCount(queryRunner, 1);
    // Update db to allow for 1 more running query in dashboard resource group
    dao.updateResourceGroup(3, "user-${USER}", "1MB", 3, 4, 4, null, null, null, null, null, 1L, TEST_ENVIRONMENT);
    dao.updateResourceGroup(5, "dashboard-${USER}", "1MB", 1, 2, 2, null, null, null, null, null, 3L, TEST_ENVIRONMENT);
    waitForQueryState(queryRunner, secondDashboardQuery, RUNNING);
    QueryId thirdDashboardQuery = createQuery(queryRunner, dashboardSession(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, thirdDashboardQuery, QUEUED);
    waitForRunningQueryCount(queryRunner, 2);
    // submit first non "dashboard" query
    QueryId firstNonDashboardQuery = createQuery(queryRunner, adhocSession(), LONG_LASTING_QUERY);
    // wait for the first non "dashboard" query to start
    waitForQueryState(queryRunner, firstNonDashboardQuery, RUNNING);
    waitForRunningQueryCount(queryRunner, 3);
    // submit second non "dashboard" query
    QueryId secondNonDashboardQuery = createQuery(queryRunner, adhocSession(), LONG_LASTING_QUERY);
    // wait for the second non "dashboard" query to start
    waitForQueryState(queryRunner, secondNonDashboardQuery, RUNNING);
    waitForRunningQueryCount(queryRunner, 4);
    // cancel first "dashboard" query, the second "dashboard" query and second non "dashboard" query should start running
    cancelQuery(queryRunner, firstDashboardQuery);
    waitForQueryState(queryRunner, firstDashboardQuery, FAILED);
    waitForQueryState(queryRunner, thirdDashboardQuery, RUNNING);
    waitForRunningQueryCount(queryRunner, 4);
    waitForCompleteQueryCount(queryRunner, 1);
}
Also used : QueryId(io.trino.spi.QueryId) Test(org.testng.annotations.Test)

Example 88 with QueryId

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

the class TestQueuesDb method testQuerySystemTableResourceGroup.

@Test(timeOut = 60_000)
public void testQuerySystemTableResourceGroup() throws Exception {
    QueryId firstQuery = createQuery(queryRunner, dashboardSession(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, firstQuery, RUNNING);
    MaterializedResult result = queryRunner.execute("SELECT resource_group_id FROM system.runtime.queries WHERE source = 'dashboard'");
    assertEquals(result.getOnlyValue(), ImmutableList.of("global", "user-user", "dashboard-user"));
}
Also used : QueryId(io.trino.spi.QueryId) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 89 with QueryId

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

the class TestQueuesDb method assertResourceGroupWithClientTags.

private void assertResourceGroupWithClientTags(Set<String> clientTags, ResourceGroupId expectedResourceGroup) throws InterruptedException {
    Session session = testSessionBuilder().setCatalog("tpch").setSchema("sf100000").setSource("client_tags").setClientTags(clientTags).build();
    QueryId queryId = createQuery(queryRunner, session, LONG_LASTING_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) TestQueues.createResourceGroupId(io.trino.execution.TestQueues.createResourceGroupId) QueryId(io.trino.spi.QueryId) H2TestUtil.dashboardSession(io.trino.execution.resourcegroups.db.H2TestUtil.dashboardSession) Session(io.trino.Session) H2TestUtil.adhocSession(io.trino.execution.resourcegroups.db.H2TestUtil.adhocSession) H2TestUtil.rejectingSession(io.trino.execution.resourcegroups.db.H2TestUtil.rejectingSession)

Example 90 with QueryId

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

the class TestQueuesDb method testTwoQueriesAtSameTime.

@Test(timeOut = 60_000)
public void testTwoQueriesAtSameTime() throws Exception {
    QueryId firstDashboardQuery = createQuery(queryRunner, dashboardSession(), LONG_LASTING_QUERY);
    QueryId secondDashboardQuery = createQuery(queryRunner, dashboardSession(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, firstDashboardQuery, RUNNING);
    waitForQueryState(queryRunner, secondDashboardQuery, QUEUED);
}
Also used : 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