Search in sources :

Example 41 with TestingTrinoServer

use of io.trino.server.testing.TestingTrinoServer 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

TestingTrinoServer (io.trino.server.testing.TestingTrinoServer)41 Test (org.testng.annotations.Test)33 HttpServerInfo (io.airlift.http.server.HttpServerInfo)28 ImmutableMap (com.google.common.collect.ImmutableMap)16 ImmutableSet (com.google.common.collect.ImmutableSet)14 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)14 Resources (com.google.common.io.Resources)14 AUTHORIZATION (com.google.common.net.HttpHeaders.AUTHORIZATION)14 Key (com.google.inject.Key)14 OptionalBinder.newOptionalBinder (com.google.inject.multibindings.OptionalBinder.newOptionalBinder)14 HttpUriBuilder.uriBuilderFrom (io.airlift.http.client.HttpUriBuilder.uriBuilderFrom)14 HttpServerConfig (io.airlift.http.server.HttpServerConfig)14 TestingHttpServer (io.airlift.http.server.testing.TestingHttpServer)14 JaxrsBinder.jaxrsBinder (io.airlift.jaxrs.JaxrsBinder.jaxrsBinder)14 NodeInfo (io.airlift.node.NodeInfo)14 PemReader (io.airlift.security.pem.PemReader)14 JwsHeader (io.jsonwebtoken.JwsHeader)14 JwtBuilder (io.jsonwebtoken.JwtBuilder)14 Keys.hmacShaKeyFor (io.jsonwebtoken.security.Keys.hmacShaKeyFor)14 OkHttpUtil.setupSsl (io.trino.client.OkHttpUtil.setupSsl)14