Search in sources :

Example 1 with TestShutdownAction

use of com.facebook.presto.server.testing.TestingPrestoServer.TestShutdownAction in project presto by prestodb.

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").build();
    try (DistributedQueryRunner queryRunner = createQueryRunner(TINY_SESSION, properties)) {
        List<ListenableFuture<?>> queryFutures = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            queryFutures.add(executor.submit(() -> queryRunner.execute("SELECT COUNT(*), clerk FROM orders GROUP BY clerk")));
        }
        TestingPrestoServer worker = queryRunner.getServers().stream().filter(server -> !server.isCoordinator()).findFirst().get();
        TaskManager 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<QueryInfo> queryInfos = queryRunner.getCoordinator().getQueryManager().getAllQueryInfo();
        for (QueryInfo info : queryInfos) {
            assertEquals(info.getState(), FINISHED);
        }
        TestShutdownAction shutdownAction = (TestShutdownAction) worker.getShutdownAction();
        shutdownAction.waitForShutdownComplete(SHUTDOWN_TIMEOUT_MILLIS);
        assertTrue(shutdownAction.isWorkerShutdown());
    }
}
Also used : TaskManager(com.facebook.presto.execution.TaskManager) ArrayList(java.util.ArrayList) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TestShutdownAction(com.facebook.presto.server.testing.TestingPrestoServer.TestShutdownAction) QueryInfo(com.facebook.presto.execution.QueryInfo) Test(org.testng.annotations.Test)

Aggregations

QueryInfo (com.facebook.presto.execution.QueryInfo)1 TaskManager (com.facebook.presto.execution.TaskManager)1 TestingPrestoServer (com.facebook.presto.server.testing.TestingPrestoServer)1 TestShutdownAction (com.facebook.presto.server.testing.TestingPrestoServer.TestShutdownAction)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 ArrayList (java.util.ArrayList)1 Test (org.testng.annotations.Test)1