Search in sources :

Example 1 with PrefixObjectNameGeneratorModule

use of io.trino.server.PrefixObjectNameGeneratorModule in project trino by trinodb.

the class TestExecutionJmxMetrics method testQueryStats.

@Test(timeOut = 30_000)
public void testQueryStats() throws Exception {
    try (DistributedQueryRunner queryRunner = TpchQueryRunnerBuilder.builder().setAdditionalModule(new PrefixObjectNameGeneratorModule("io.trino")).build()) {
        queryRunner.installPlugin(new ResourceGroupManagerPlugin());
        InternalResourceGroupManager<?> resourceGroupManager = queryRunner.getCoordinator().getResourceGroupManager().orElseThrow(() -> new IllegalStateException("Resource manager not configured"));
        resourceGroupManager.setConfigurationManager("file", ImmutableMap.of("resource-groups.config-file", getClass().getClassLoader().getResource("resource_groups_single_query.json").getPath()));
        MBeanServer mbeanServer = queryRunner.getCoordinator().getMbeanServer();
        QueryId firstDashboardQuery = createQuery(queryRunner, dashboardSession(), LONG_RUNNING_QUERY);
        waitForQueryState(queryRunner, firstDashboardQuery, RUNNING);
        assertEquals(getMbeanAttribute(mbeanServer, "RunningQueries"), 1);
        assertEquals(getMbeanAttribute(mbeanServer, "QueuedQueries"), 0);
        // the second "dashboard" query can't run right away because the resource group has a hardConcurrencyLimit of 1
        QueryId secondDashboardQuery = createQuery(queryRunner, dashboardSession(), LONG_RUNNING_QUERY);
        waitForQueryState(queryRunner, secondDashboardQuery, QUEUED);
        assertEquals(getMbeanAttribute(mbeanServer, "RunningQueries"), 1);
        assertEquals(getMbeanAttribute(mbeanServer, "QueuedQueries"), 1);
        cancelQuery(queryRunner, secondDashboardQuery);
        waitForQueryState(queryRunner, secondDashboardQuery, FAILED);
        assertEquals(getMbeanAttribute(mbeanServer, "RunningQueries"), 1);
        assertEquals(getMbeanAttribute(mbeanServer, "QueuedQueries"), 0);
        // cancel the running query to avoid polluting the logs with meaningless stack traces
        try {
            cancelQuery(queryRunner, firstDashboardQuery);
            waitForQueryState(queryRunner, firstDashboardQuery, FAILED);
        } catch (Exception ignore) {
        }
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) QueryId(io.trino.spi.QueryId) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) PrefixObjectNameGeneratorModule(io.trino.server.PrefixObjectNameGeneratorModule) MBeanServer(javax.management.MBeanServer) Test(org.testng.annotations.Test)

Aggregations

ResourceGroupManagerPlugin (io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin)1 PrefixObjectNameGeneratorModule (io.trino.server.PrefixObjectNameGeneratorModule)1 QueryId (io.trino.spi.QueryId)1 DistributedQueryRunner (io.trino.testing.DistributedQueryRunner)1 MBeanServer (javax.management.MBeanServer)1 Test (org.testng.annotations.Test)1