use of com.facebook.presto.execution.TestingSessionContext in project presto by prestodb.
the class TestQueryManager method testFailQuery.
@Test(timeOut = 60_000L)
public void testFailQuery() 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) {
QueryState state = dispatchManager.getQueryInfo(queryId).getState();
if (state.isDone()) {
fail("unexpected query state: " + state);
}
if (state == RUNNING) {
break;
}
Thread.sleep(100);
}
// cancel query
QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
queryManager.failQuery(queryId, new PrestoException(GENERIC_INTERNAL_ERROR, "mock exception"));
QueryInfo queryInfo = queryManager.getFullQueryInfo(queryId);
assertEquals(queryInfo.getState(), FAILED);
assertEquals(queryInfo.getErrorCode(), GENERIC_INTERNAL_ERROR.toErrorCode());
assertNotNull(queryInfo.getFailureInfo());
assertEquals(queryInfo.getFailureInfo().getMessage(), "mock exception");
assertEquals(queryManager.getStats().getQueuedQueries(), 0);
}
use of com.facebook.presto.execution.TestingSessionContext 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.execution.TestingSessionContext 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