Search in sources :

Example 31 with TestingPrestoServer

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

the class TestGracefulShutdown method testCoordinatorShutdown.

@Test(timeOut = SHUTDOWN_TIMEOUT_MILLIS)
public void testCoordinatorShutdown() throws Exception {
    try (DistributedQueryRunner queryRunner = createQueryRunner(TINY_SESSION, ImmutableMap.of())) {
        TestingPrestoServer coordinator = queryRunner.getServers().stream().filter(TestingPrestoServer::isCoordinator).findFirst().get();
        coordinator.getGracefulShutdownHandler().requestShutdown();
        TestShutdownAction shutdownAction = (TestShutdownAction) coordinator.getShutdownAction();
        shutdownAction.waitForShutdownComplete(SHUTDOWN_TIMEOUT_MILLIS);
        assertTrue(shutdownAction.isShutdown());
    }
}
Also used : TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) TestShutdownAction(com.facebook.presto.server.testing.TestingPrestoServer.TestShutdownAction) Test(org.testng.annotations.Test)

Example 32 with TestingPrestoServer

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

the class TestGracefulShutdown method testShutdown.

@Test(timeOut = SHUTDOWN_TIMEOUT_MILLIS, dataProvider = "testServerInfo")
public void testShutdown(String serverInstanceType, Map<String, String> properties) throws Exception {
    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")));
        }
        boolean isCoordinatorInstance = serverInstanceType.equals(COORDINATOR);
        TestingPrestoServer testServer = queryRunner.getServers().stream().filter(server -> server.isCoordinator() == isCoordinatorInstance).findFirst().get();
        if (!isCoordinatorInstance) {
            TaskManager taskManager = testServer.getTaskManager();
            while (taskManager.getAllTaskInfo().isEmpty()) {
                MILLISECONDS.sleep(500);
            }
        }
        testServer.getGracefulShutdownHandler().requestShutdown();
        Futures.allAsList(queryFutures).get();
        List<BasicQueryInfo> queryInfos = queryRunner.getCoordinator().getQueryManager().getQueries();
        for (BasicQueryInfo info : queryInfos) {
            assertEquals(info.getState(), FINISHED);
        }
        TestShutdownAction shutdownAction = (TestShutdownAction) testServer.getShutdownAction();
        shutdownAction.waitForShutdownComplete(SHUTDOWN_TIMEOUT_MILLIS);
        assertTrue(shutdownAction.isShutdown());
    }
}
Also used : TaskManager(com.facebook.presto.execution.TaskManager) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) 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) Test(org.testng.annotations.Test)

Example 33 with TestingPrestoServer

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

the class TestServerInfoResource method testServerShutdownFollowedByInactive.

@Test(timeOut = SHUTDOWN_TIMEOUT_MILLIS)
public void testServerShutdownFollowedByInactive() throws Exception {
    try (DistributedQueryRunner queryRunner = createQueryRunner(TINY_SESSION, ImmutableMap.of())) {
        TestingPrestoServer coordinator = queryRunner.getServers().stream().filter(TestingPrestoServer::isCoordinator).findFirst().get();
        ServerInfoResource serverInfoResource = coordinator.getServerInfoResource();
        serverInfoResource.updateState(NodeState.SHUTTING_DOWN);
        Response response = serverInfoResource.updateState(NodeState.INACTIVE);
        assertEquals(response.getStatus(), BAD_REQUEST.getStatusCode());
        assertEquals(response.getEntity(), "Cluster is shutting down");
    }
}
Also used : Response(javax.ws.rs.core.Response) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) ServerInfoResource(com.facebook.presto.server.ServerInfoResource) Test(org.testng.annotations.Test)

Example 34 with TestingPrestoServer

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

the class TestServerInfoResource method testServerInactiveThenActive.

@Test(timeOut = SHUTDOWN_TIMEOUT_MILLIS)
public void testServerInactiveThenActive() throws Exception {
    try (DistributedQueryRunner queryRunner = createQueryRunner(TINY_SESSION, ImmutableMap.of())) {
        TestingPrestoServer coordinator = queryRunner.getServers().stream().filter(TestingPrestoServer::isCoordinator).findFirst().get();
        ServerInfoResource serverInfoResource = coordinator.getServerInfoResource();
        Response response = serverInfoResource.updateState(NodeState.INACTIVE);
        assertEquals(response.getStatus(), 200);
        NodeState nodeState = serverInfoResource.getServerState();
        assertTrue(nodeState == NodeState.INACTIVE);
        response = serverInfoResource.updateState(NodeState.ACTIVE);
        assertEquals(response.getStatus(), 200);
        nodeState = serverInfoResource.getServerState();
        assertTrue(nodeState == NodeState.ACTIVE);
    }
}
Also used : Response(javax.ws.rs.core.Response) NodeState(com.facebook.presto.spi.NodeState) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) ServerInfoResource(com.facebook.presto.server.ServerInfoResource) Test(org.testng.annotations.Test)

Example 35 with TestingPrestoServer

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

the class TestServerInfoResource method testServerActive.

@Test(timeOut = SHUTDOWN_TIMEOUT_MILLIS)
public void testServerActive() throws Exception {
    try (DistributedQueryRunner queryRunner = createQueryRunner(TINY_SESSION, ImmutableMap.of())) {
        TestingPrestoServer coordinator = queryRunner.getServers().stream().filter(TestingPrestoServer::isCoordinator).findFirst().get();
        ServerInfoResource serverInfoResource = coordinator.getServerInfoResource();
        NodeState nodeState = serverInfoResource.getServerState();
        assertTrue(nodeState == NodeState.ACTIVE);
    }
}
Also used : NodeState(com.facebook.presto.spi.NodeState) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) ServerInfoResource(com.facebook.presto.server.ServerInfoResource) Test(org.testng.annotations.Test)

Aggregations

TestingPrestoServer (com.facebook.presto.server.testing.TestingPrestoServer)47 Test (org.testng.annotations.Test)19 BeforeClass (org.testng.annotations.BeforeClass)16 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)13 ArrayList (java.util.ArrayList)9 JettyHttpClient (com.facebook.airlift.http.client.jetty.JettyHttpClient)7 FileResourceGroupConfigurationManagerFactory (com.facebook.presto.resourceGroups.FileResourceGroupConfigurationManagerFactory)6 NodeState (com.facebook.presto.spi.NodeState)6 QueryId (com.facebook.presto.spi.QueryId)6 Future (java.util.concurrent.Future)6 ServerInfoResource (com.facebook.presto.server.ServerInfoResource)5 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)4 TpchPlugin (com.facebook.presto.tpch.TpchPlugin)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)4 Response (javax.ws.rs.core.Response)4 Request (com.facebook.airlift.http.client.Request)3 TaskManager (com.facebook.presto.execution.TaskManager)3 BlackHolePlugin (com.facebook.presto.plugin.blackhole.BlackHolePlugin)3 TestShutdownAction (com.facebook.presto.server.testing.TestingPrestoServer.TestShutdownAction)3