use of com.facebook.presto.dispatcher.DispatchManager in project presto by prestodb.
the class AbstractTestDistributedQueries method testQueryLoggingCount.
@Test
public void testQueryLoggingCount() {
QueryManager queryManager = ((DistributedQueryRunner) getQueryRunner()).getCoordinator().getQueryManager();
executeExclusively(() -> {
assertUntilTimeout(() -> assertEquals(queryManager.getQueries().stream().map(BasicQueryInfo::getQueryId).map(queryManager::getFullQueryInfo).filter(info -> !info.isFinalQueryInfo()).collect(toList()), ImmutableList.of()), new Duration(1, MINUTES));
// We cannot simply get the number of completed queries as soon as all the queries are completed, because this counter may not be up-to-date at that point.
// The completed queries counter is updated in a final query info listener, which is called eventually.
// Therefore, here we wait until the value of this counter gets stable.
DispatchManager dispatchManager = ((DistributedQueryRunner) getQueryRunner()).getCoordinator().getDispatchManager();
long beforeCompletedQueriesCount = waitUntilStable(() -> dispatchManager.getStats().getCompletedQueries().getTotalCount(), new Duration(5, SECONDS));
long beforeSubmittedQueriesCount = dispatchManager.getStats().getSubmittedQueries().getTotalCount();
assertUpdate("CREATE TABLE test_query_logging_count AS SELECT 1 foo_1, 2 foo_2_4", 1);
assertQuery("SELECT foo_1, foo_2_4 FROM test_query_logging_count", "SELECT 1, 2");
assertUpdate("DROP TABLE test_query_logging_count");
assertQueryFails("SELECT * FROM test_query_logging_count", ".*Table .* does not exist");
// TODO: Figure out a better way of synchronization
assertUntilTimeout(() -> assertEquals(dispatchManager.getStats().getCompletedQueries().getTotalCount() - beforeCompletedQueriesCount, 4), new Duration(1, MINUTES));
assertEquals(dispatchManager.getStats().getSubmittedQueries().getTotalCount() - beforeSubmittedQueriesCount, 4);
});
}
use of com.facebook.presto.dispatcher.DispatchManager in project presto by prestodb.
the class TestQueryRunnerUtil method createQuery.
public static QueryId createQuery(DistributedQueryRunner queryRunner, int coordinator, Session session, String sql) {
DispatchManager dispatchManager = queryRunner.getCoordinator(coordinator).getDispatchManager();
getFutureValue(dispatchManager.createQuery(session.getQueryId(), "slug", 0, new TestingSessionContext(session), sql));
return session.getQueryId();
}
use of com.facebook.presto.dispatcher.DispatchManager in project presto by prestodb.
the class TestQueryRunnerUtil method waitForQueryState.
public static void waitForQueryState(DistributedQueryRunner queryRunner, int coordinator, QueryId queryId, Set<QueryState> expectedQueryStates) throws InterruptedException {
DispatchManager dispatchManager = queryRunner.getCoordinator(coordinator).getDispatchManager();
waitForQueryState(dispatchManager, queryId, expectedQueryStates);
}
use of com.facebook.presto.dispatcher.DispatchManager in project presto by prestodb.
the class TestMetadataManager method testMetadataIsClearedAfterQueryCanceled.
@Test
public void testMetadataIsClearedAfterQueryCanceled() throws Exception {
DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
QueryId queryId = dispatchManager.createQueryId();
dispatchManager.createQuery(queryId, "slug", 0, new TestingSessionContext(TEST_SESSION), "SELECT * FROM lineitem").get();
// wait until query starts running
while (true) {
BasicQueryInfo queryInfo = dispatchManager.getQueryInfo(queryId);
if (queryInfo.getState().isDone()) {
assertEquals(queryInfo.getState(), FAILED);
throw dispatchManager.getDispatchInfo(queryId).get().getFailureInfo().get().toException();
}
if (queryInfo.getState() == RUNNING) {
break;
}
Thread.sleep(100);
}
// cancel query
dispatchManager.cancelQuery(queryId);
assertEquals(metadataManager.getCatalogsByQueryId().size(), 0);
}
use of com.facebook.presto.dispatcher.DispatchManager in project presto by prestodb.
the class TestQueryManager method testFailQueryPrerun.
@Test(timeOut = 60_000L)
public void testFailQueryPrerun() throws Exception {
DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
// Create 3 running queries to guarantee queueing
createQueries(dispatchManager, 3);
QueryId queryId = dispatchManager.createQueryId();
dispatchManager.createQuery(queryId, "slug", 0, new TestingSessionContext(TEST_SESSION), "SELECT * FROM lineitem").get();
assertNotEquals(dispatchManager.getStats().getQueuedQueries(), 0L, "Expected 0 queued queries, found: " + dispatchManager.getStats().getQueuedQueries());
// wait until it's admitted but fail it before it starts
while (true) {
QueryState state = dispatchManager.getQueryInfo(queryId).getState();
if (state.ordinal() >= RUNNING.ordinal()) {
fail("unexpected query state: " + state);
}
if (state.ordinal() >= QUEUED.ordinal()) {
// cancel query
dispatchManager.failQuery(queryId, new PrestoException(GENERIC_USER_ERROR, "mock exception"));
break;
}
}
QueryState state = dispatchManager.getQueryInfo(queryId).getState();
assertEquals(state, FAILED);
// Give the stats a time to update
Thread.sleep(1000);
assertEquals(queryManager.getStats().getQueuedQueries(), 0);
}
Aggregations