Search in sources :

Example 11 with QueryId

use of io.prestosql.spi.QueryId in project hetu-core by openlookeng.

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

Example 12 with QueryId

use of io.prestosql.spi.QueryId in project hetu-core by openlookeng.

the class TestQueryManager method testQueryCpuLimit.

@Test(timeOut = 60_000L)
public void testQueryCpuLimit() throws Exception {
    try (DistributedQueryRunner distributedQueryRunner = TpchQueryRunnerBuilder.builder().setSingleExtraProperty("query.max-cpu-time", "1ms").build()) {
        QueryId queryId = createQuery(distributedQueryRunner, TEST_SESSION, "SELECT COUNT(*) FROM lineitem");
        waitForQueryState(distributedQueryRunner, queryId, FAILED);
        QueryManager queryManager = distributedQueryRunner.getCoordinator().getQueryManager();
        BasicQueryInfo queryInfo = queryManager.getQueryInfo(queryId);
        assertEquals(queryInfo.getState(), FAILED);
        assertEquals(queryInfo.getErrorCode(), EXCEEDED_CPU_LIMIT.toErrorCode());
    }
}
Also used : QueryId(io.prestosql.spi.QueryId) BasicQueryInfo(io.prestosql.server.BasicQueryInfo) QueryManager(io.prestosql.execution.QueryManager) Test(org.testng.annotations.Test)

Example 13 with QueryId

use of io.prestosql.spi.QueryId in project hetu-core by openlookeng.

the class TestStateUpdater method createBasicQueryInfo.

private BasicQueryInfo createBasicQueryInfo() {
    QueryInfo queryInfo = Mockito.mock(QueryInfo.class);
    when(queryInfo.getQueryStats()).then(new Returns(Mockito.mock(QueryStats.class)));
    Duration mockInterval = new Duration(MINIMUM_UPDATE_INTERVAL, MILLISECONDS);
    when(queryInfo.getQueryStats().getQueuedTime()).then(new Returns(mockInterval));
    when(queryInfo.getQueryStats().getElapsedTime()).then(new Returns(mockInterval));
    when(queryInfo.getQueryStats().getExecutionTime()).then(new Returns(mockInterval));
    when(queryInfo.getQueryStats().getRawInputDataSize()).then(new Returns(Mockito.mock(DataSize.class)));
    String mockQueryId = MOCK_QUERY_ID;
    QueryId queryId = new QueryId(mockQueryId);
    when(queryInfo.getQueryId()).then(new Returns(queryId));
    SessionRepresentation sessionRepresentation = TEST_SESSION.toSessionRepresentation();
    when(queryInfo.getSession()).then(new Returns(sessionRepresentation));
    ResourceGroupId resourceGroupId = new ResourceGroupId(GLOBAL_RESOURCE_ID);
    Optional<ResourceGroupId> optionalResourceGroupId = Optional.of(resourceGroupId);
    when(queryInfo.getResourceGroupId()).then(new Returns(optionalResourceGroupId));
    when(queryInfo.getState()).then(new Returns(QueryState.FINISHED));
    URI mockURI = URI.create(URI_LOCALHOST);
    when(queryInfo.getSelf()).then(new Returns(mockURI));
    String mockQuery = QUERY_STRING;
    when(queryInfo.getQuery()).then(new Returns(mockQuery));
    Optional<String> preparedQuery = Optional.of(PREPARED_QUERY_MOCK_DATA);
    when(queryInfo.getPreparedQuery()).then(new Returns(preparedQuery));
    ErrorCode errorCode = new ErrorCode(ERROR_CODE_VALUE_INDEX_TIME_NO_INVOCATION, ERROR_CODE_TEST, USER_ERROR);
    when(queryInfo.getErrorCode()).then(new Returns(errorCode));
    Set<BlockedReason> setBlockedReason = new HashSet<>();
    setBlockedReason.add(BlockedReason.WAITING_FOR_MEMORY);
    when(queryInfo.getQueryStats().getBlockedReasons()).then(new Returns(setBlockedReason));
    when(queryInfo.getQueryStats().getProgressPercentage()).then(new Returns(OptionalDouble.empty()));
    BasicQueryInfo basicQueryInfo = new BasicQueryInfo(queryInfo);
    return basicQueryInfo;
}
Also used : ResourceGroupId(io.prestosql.spi.resourcegroups.ResourceGroupId) BlockedReason(io.prestosql.operator.BlockedReason) QueryId(io.prestosql.spi.QueryId) BasicQueryInfo(io.prestosql.server.BasicQueryInfo) Duration(io.airlift.units.Duration) QueryInfo(io.prestosql.execution.QueryInfo) BasicQueryInfo(io.prestosql.server.BasicQueryInfo) URI(java.net.URI) Returns(org.mockito.internal.stubbing.answers.Returns) ErrorCode(io.prestosql.spi.ErrorCode) SessionRepresentation(io.prestosql.SessionRepresentation) HashSet(java.util.HashSet)

Example 14 with QueryId

use of io.prestosql.spi.QueryId in project hetu-core by openlookeng.

the class TestEnvironments method testEnvironment2.

@Test(timeOut = 240_000)
public void testEnvironment2() throws Exception {
    String dbConfigUrl = getDbConfigUrl();
    H2ResourceGroupsDao dao = getDao(dbConfigUrl);
    try (DistributedQueryRunner runner = createQueryRunner(dbConfigUrl, dao, TEST_ENVIRONMENT_2)) {
        QueryId firstQuery = createQuery(runner, adhocSession(), LONG_LASTING_QUERY);
        waitForQueryState(runner, firstQuery, RUNNING);
        QueryId secondQuery = createQuery(runner, adhocSession(), LONG_LASTING_QUERY);
        // there is no queueing in TEST_ENVIRONMENT_2, so the second query should fail right away
        waitForQueryState(runner, secondQuery, FAILED);
    }
}
Also used : DistributedQueryRunner(io.prestosql.tests.DistributedQueryRunner) QueryId(io.prestosql.spi.QueryId) H2ResourceGroupsDao(io.prestosql.plugin.resourcegroups.db.H2ResourceGroupsDao) Test(org.testng.annotations.Test)

Example 15 with QueryId

use of io.prestosql.spi.QueryId in project hetu-core by openlookeng.

the class TestQueuesDb method testSelectorPriority.

@Test(timeOut = 60_000)
public void testSelectorPriority() throws Exception {
    InternalResourceGroupManager<?> manager = queryRunner.getCoordinator().getResourceGroupManager().get();
    QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
    DbResourceGroupConfigurationManager dbConfigurationManager = (DbResourceGroupConfigurationManager) manager.getConfigurationManager();
    QueryId firstQuery = createQuery(queryRunner, dashboardSession(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, firstQuery, RUNNING);
    Optional<ResourceGroupId> resourceGroup = queryManager.getFullQueryInfo(firstQuery).getResourceGroupId();
    assertTrue(resourceGroup.isPresent());
    assertEquals(resourceGroup.get().toString(), "global.user-user.dashboard-user");
    // create a new resource group that rejects all queries submitted to it
    // Hetu: add parameters softReservedMemory and hardReservedConcurrency
    dao.insertResourceGroup(8, "reject-all-queries", "1MB", "1MB", 0, 0, 0, 0, null, null, null, null, null, "RECENT_QUERIES", 3L, TEST_ENVIRONMENT);
    // add a new selector that has a higher priority than the existing dashboard selector and that routes queries to the "reject-all-queries" resource group
    dao.insertSelector(8, 200, "user.*", "(?i).*dashboard.*", null, null, null);
    // reload the configuration
    dbConfigurationManager.load();
    QueryId secondQuery = createQuery(queryRunner, dashboardSession(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, secondQuery, FAILED);
    DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
    BasicQueryInfo basicQueryInfo = dispatchManager.getQueryInfo(secondQuery);
    assertEquals(basicQueryInfo.getErrorCode(), QUERY_QUEUE_FULL.toErrorCode());
}
Also used : DbResourceGroupConfigurationManager(io.prestosql.plugin.resourcegroups.db.DbResourceGroupConfigurationManager) ResourceGroupId(io.prestosql.spi.resourcegroups.ResourceGroupId) TestQueues.createResourceGroupId(io.prestosql.execution.TestQueues.createResourceGroupId) DispatchManager(io.prestosql.dispatcher.DispatchManager) QueryId(io.prestosql.spi.QueryId) BasicQueryInfo(io.prestosql.server.BasicQueryInfo) QueryManager(io.prestosql.execution.QueryManager) Test(org.testng.annotations.Test)

Aggregations

QueryId (io.prestosql.spi.QueryId)100 Test (org.testng.annotations.Test)69 TaskId (io.prestosql.execution.TaskId)25 DataSize (io.airlift.units.DataSize)18 Session (io.prestosql.Session)18 PrestoException (io.prestosql.spi.PrestoException)13 MemoryPoolId (io.prestosql.spi.memory.MemoryPoolId)13 DistributedQueryRunner (io.prestosql.tests.DistributedQueryRunner)13 NoOpFailureDetector (io.prestosql.failuredetector.NoOpFailureDetector)11 List (java.util.List)11 Map (java.util.Map)11 ImmutableMap (com.google.common.collect.ImmutableMap)10 InternalNode (io.prestosql.metadata.InternalNode)10 PlanNodeId (io.prestosql.spi.plan.PlanNodeId)10 ImmutableList (com.google.common.collect.ImmutableList)9 TestingGcMonitor (io.airlift.stats.TestingGcMonitor)9 ArrayList (java.util.ArrayList)9 Duration (io.airlift.units.Duration)8 Optional (java.util.Optional)8 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)7