Search in sources :

Example 1 with SqlTaskManager

use of io.trino.execution.SqlTaskManager in project trino by trinodb.

the class TestGracefulShutdown method testShutdown.

@Test(timeOut = SHUTDOWN_TIMEOUT_MILLIS)
public void testShutdown() throws Exception {
    Map<String, String> properties = ImmutableMap.<String, String>builder().put("node-scheduler.include-coordinator", "false").put("shutdown.grace-period", "10s").buildOrThrow();
    try (DistributedQueryRunner queryRunner = createQueryRunner(TINY_SESSION, properties)) {
        List<ListenableFuture<Void>> queryFutures = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            queryFutures.add(Futures.submit(() -> {
                queryRunner.execute("SELECT COUNT(*), clerk FROM orders GROUP BY clerk");
            }, executor));
        }
        TestingTrinoServer worker = queryRunner.getServers().stream().filter(server -> !server.isCoordinator()).findFirst().get();
        SqlTaskManager taskManager = worker.getTaskManager();
        // wait until tasks show up on the worker
        while (taskManager.getAllTaskInfo().isEmpty()) {
            MILLISECONDS.sleep(500);
        }
        worker.getGracefulShutdownHandler().requestShutdown();
        Futures.allAsList(queryFutures).get();
        List<BasicQueryInfo> queryInfos = queryRunner.getCoordinator().getQueryManager().getQueries();
        for (BasicQueryInfo info : queryInfos) {
            assertEquals(info.getState(), FINISHED);
        }
        TestShutdownAction shutdownAction = (TestShutdownAction) worker.getShutdownAction();
        shutdownAction.waitForShutdownComplete(SHUTDOWN_TIMEOUT_MILLIS);
        assertTrue(shutdownAction.isWorkerShutdown());
    }
}
Also used : SqlTaskManager(io.trino.execution.SqlTaskManager) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) BasicQueryInfo(io.trino.server.BasicQueryInfo) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TestShutdownAction(io.trino.server.testing.TestingTrinoServer.TestShutdownAction) TestingTrinoServer(io.trino.server.testing.TestingTrinoServer) Test(org.testng.annotations.Test)

Aggregations

ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SqlTaskManager (io.trino.execution.SqlTaskManager)1 BasicQueryInfo (io.trino.server.BasicQueryInfo)1 TestingTrinoServer (io.trino.server.testing.TestingTrinoServer)1 TestShutdownAction (io.trino.server.testing.TestingTrinoServer.TestShutdownAction)1 DistributedQueryRunner (io.trino.testing.DistributedQueryRunner)1 ArrayList (java.util.ArrayList)1 Test (org.testng.annotations.Test)1