use of com.facebook.presto.spi.security.SelectedRole.Type.ALL in project presto by prestodb.
the class TestHiveRecoverableExecution method testRecoverableGroupedExecution.
private void testRecoverableGroupedExecution(DistributedQueryRunner queryRunner, int writerConcurrency, boolean optimizedPartitionUpdateSerializationEnabled, List<String> preQueries, @Language("SQL") String queryWithoutFailure, @Language("SQL") String queryWithFailure, int expectedUpdateCount, List<String> postQueries) throws Exception {
waitUntilAllNodesAreHealthy(queryRunner, new Duration(10, SECONDS));
Session recoverableSession = createRecoverableSession(writerConcurrency, optimizedPartitionUpdateSerializationEnabled);
for (@Language("SQL") String postQuery : postQueries) {
queryRunner.execute(recoverableSession, postQuery);
}
try {
for (@Language("SQL") String preQuery : preQueries) {
queryRunner.execute(recoverableSession, preQuery);
}
// test no failure case
Stopwatch noRecoveryStopwatch = Stopwatch.createStarted();
assertEquals(queryRunner.execute(recoverableSession, queryWithoutFailure).getUpdateCount(), OptionalLong.of(expectedUpdateCount));
log.info("Query with no recovery took %sms", noRecoveryStopwatch.elapsed(MILLISECONDS));
// cancel all queries and tasks to make sure we are dealing only with a single running query
cancelAllQueries(queryRunner);
cancelAllTasks(queryRunner);
// test failure case
Stopwatch recoveryStopwatch = Stopwatch.createStarted();
ListenableFuture<MaterializedResult> result = executor.submit(() -> queryRunner.execute(recoverableSession, queryWithFailure));
List<TestingPrestoServer> workers = queryRunner.getServers().stream().filter(server -> !server.isCoordinator()).collect(toList());
shuffle(workers);
TestingPrestoServer worker1 = workers.get(0);
// kill worker1 right away, to make sure recoverable execution works in cases when the task hasn't been yet submitted
worker1.stopResponding();
// kill worker2 only after the task has been scheduled
TestingPrestoServer worker2 = workers.get(1);
sleep(1000);
worker2.stopResponding();
assertEquals(result.get(1000, SECONDS).getUpdateCount(), OptionalLong.of(expectedUpdateCount));
log.info("Query with recovery took %sms", recoveryStopwatch.elapsed(MILLISECONDS));
} finally {
queryRunner.getServers().forEach(TestingPrestoServer::startResponding);
cancelAllQueries(queryRunner);
cancelAllTasks(queryRunner);
for (@Language("SQL") String postQuery : postQueries) {
queryRunner.execute(recoverableSession, postQuery);
}
}
}
Aggregations