use of com.facebook.presto.server.testing.TestingPrestoServer 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);
}
}
}
use of com.facebook.presto.server.testing.TestingPrestoServer in project presto by prestodb.
the class TestServer method setup.
@BeforeMethod
public void setup() throws Exception {
server = new TestingPrestoServer();
client = new JettyHttpClient();
}
use of com.facebook.presto.server.testing.TestingPrestoServer in project presto by prestodb.
the class DistributedQueryRunner method isConnectorVisibleToAllNodes.
private boolean isConnectorVisibleToAllNodes(ConnectorId connectorId) {
if (!externalWorkers.isEmpty()) {
return true;
}
for (TestingPrestoServer server : servers) {
server.refreshNodes();
Set<InternalNode> activeNodesWithConnector = server.getActiveNodesWithConnector(connectorId);
if (activeNodesWithConnector.size() != servers.size()) {
return false;
}
}
return true;
}
use of com.facebook.presto.server.testing.TestingPrestoServer in project presto by prestodb.
the class DistributedQueryRunner method installPlugin.
@Override
public void installPlugin(Plugin plugin) {
long start = nanoTime();
for (TestingPrestoServer server : servers) {
server.installPlugin(plugin);
}
log.info("Installed plugin %s in %s", plugin.getClass().getSimpleName(), nanosSince(start).convertToMostSuccinctTimeUnit());
}
use of com.facebook.presto.server.testing.TestingPrestoServer in project presto by prestodb.
the class DistributedQueryRunner method createCatalog.
@Override
public void createCatalog(String catalogName, String connectorName, Map<String, String> properties) {
long start = nanoTime();
Set<ConnectorId> connectorIds = new HashSet<>();
for (TestingPrestoServer server : servers) {
connectorIds.add(server.createCatalog(catalogName, connectorName, properties));
}
ConnectorId connectorId = getOnlyElement(connectorIds);
log.info("Created catalog %s (%s) in %s", catalogName, connectorId, nanosSince(start));
// wait for all nodes to announce the new catalog
start = nanoTime();
while (!isConnectorVisibleToAllNodes(connectorId)) {
Assertions.assertLessThan(nanosSince(start), new Duration(100, SECONDS), "waiting for connector " + connectorId + " to be initialized in every node");
try {
MILLISECONDS.sleep(10);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
}
log.info("Announced catalog %s (%s) in %s", catalogName, connectorId, nanosSince(start));
}
Aggregations