Search in sources :

Example 6 with QueryState

use of io.trino.execution.QueryState in project trino by trinodb.

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.createNew(), TestingSessionContext.fromSession(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 TrinoException(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");
}
Also used : DispatchManager(io.trino.dispatcher.DispatchManager) QueryId(io.trino.spi.QueryId) QueryManager(io.trino.execution.QueryManager) TrinoException(io.trino.spi.TrinoException) QueryState(io.trino.execution.QueryState) TestQueryRunnerUtil.waitForQueryState(io.trino.execution.TestQueryRunnerUtil.waitForQueryState) BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryInfo(io.trino.execution.QueryInfo) Test(org.testng.annotations.Test)

Aggregations

QueryState (io.trino.execution.QueryState)6 ImmutableList (com.google.common.collect.ImmutableList)2 BasicQueryInfo (io.trino.server.BasicQueryInfo)2 ResourceSecurity (io.trino.server.security.ResourceSecurity)2 Connection (java.sql.Connection)2 Statement (java.sql.Statement)2 GET (javax.ws.rs.GET)2 Test (org.testng.annotations.Test)2 FailureInfo (io.trino.client.FailureInfo)1 QueryError (io.trino.client.QueryError)1 DispatchManager (io.trino.dispatcher.DispatchManager)1 ExecutionFailureInfo (io.trino.execution.ExecutionFailureInfo)1 QueryInfo (io.trino.execution.QueryInfo)1 QueryManager (io.trino.execution.QueryManager)1 TestQueryRunnerUtil.waitForQueryState (io.trino.execution.TestQueryRunnerUtil.waitForQueryState)1 ErrorCode (io.trino.spi.ErrorCode)1 QueryId (io.trino.spi.QueryId)1 TrinoException (io.trino.spi.TrinoException)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1