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");
}
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());
}
}
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;
}
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);
}
}
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());
}
Aggregations