Search in sources :

Example 1 with TestingSessionContext

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);
}
Also used : DispatchManager(com.facebook.presto.dispatcher.DispatchManager) TestingSessionContext(com.facebook.presto.execution.TestingSessionContext) QueryId(com.facebook.presto.spi.QueryId) QueryManager(com.facebook.presto.execution.QueryManager) PrestoException(com.facebook.presto.spi.PrestoException) TestQueryRunnerUtil.waitForQueryState(com.facebook.presto.execution.TestQueryRunnerUtil.waitForQueryState) QueryState(com.facebook.presto.execution.QueryState) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) QueryInfo(com.facebook.presto.execution.QueryInfo) Test(org.testng.annotations.Test)

Example 2 with TestingSessionContext

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);
}
Also used : DispatchManager(com.facebook.presto.dispatcher.DispatchManager) TestingSessionContext(com.facebook.presto.execution.TestingSessionContext) QueryId(com.facebook.presto.spi.QueryId) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) Test(org.testng.annotations.Test)

Example 3 with TestingSessionContext

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);
}
Also used : DispatchManager(com.facebook.presto.dispatcher.DispatchManager) TestingSessionContext(com.facebook.presto.execution.TestingSessionContext) QueryId(com.facebook.presto.spi.QueryId) QueryManager(com.facebook.presto.execution.QueryManager) PrestoException(com.facebook.presto.spi.PrestoException) TestQueryRunnerUtil.waitForQueryState(com.facebook.presto.execution.TestQueryRunnerUtil.waitForQueryState) QueryState(com.facebook.presto.execution.QueryState) Test(org.testng.annotations.Test)

Aggregations

DispatchManager (com.facebook.presto.dispatcher.DispatchManager)3 TestingSessionContext (com.facebook.presto.execution.TestingSessionContext)3 QueryId (com.facebook.presto.spi.QueryId)3 Test (org.testng.annotations.Test)3 QueryManager (com.facebook.presto.execution.QueryManager)2 QueryState (com.facebook.presto.execution.QueryState)2 TestQueryRunnerUtil.waitForQueryState (com.facebook.presto.execution.TestQueryRunnerUtil.waitForQueryState)2 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)2 PrestoException (com.facebook.presto.spi.PrestoException)2 QueryInfo (com.facebook.presto.execution.QueryInfo)1