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());
}
}
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());
}
}
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");
}
}
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);
}
}
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);
}
}
Aggregations