use of io.trino.server.BasicQueryInfo in project trino by trinodb.
the class TestServer method testQuery.
@Test
public void testQuery() {
ImmutableList.Builder<List<Object>> data = ImmutableList.builder();
QueryResults queryResults = postQuery(request -> request.setBodyGenerator(createStaticBodyGenerator("show catalogs", UTF_8)).setHeader(TRINO_HEADERS.requestCatalog(), "catalog").setHeader(TRINO_HEADERS.requestSchema(), "schema").setHeader(TRINO_HEADERS.requestPath(), "path").setHeader(TRINO_HEADERS.requestClientInfo(), "{\"clientVersion\":\"testVersion\"}").addHeader(TRINO_HEADERS.requestSession(), QUERY_MAX_MEMORY + "=1GB").addHeader(TRINO_HEADERS.requestSession(), JOIN_DISTRIBUTION_TYPE + "=partitioned," + HASH_PARTITION_COUNT + " = 43").addHeader(TRINO_HEADERS.requestPreparedStatement(), "foo=select * from bar")).map(JsonResponse::getValue).peek(result -> assertNull(result.getError())).peek(results -> {
if (results.getData() != null) {
data.addAll(results.getData());
}
}).collect(last());
// get the query info
BasicQueryInfo queryInfo = server.getQueryManager().getQueryInfo(new QueryId(queryResults.getId()));
// verify session properties
assertEquals(queryInfo.getSession().getSystemProperties(), ImmutableMap.builder().put(QUERY_MAX_MEMORY, "1GB").put(JOIN_DISTRIBUTION_TYPE, "partitioned").put(HASH_PARTITION_COUNT, "43").buildOrThrow());
// verify client info in session
assertEquals(queryInfo.getSession().getClientInfo().get(), "{\"clientVersion\":\"testVersion\"}");
// verify prepared statements
assertEquals(queryInfo.getSession().getPreparedStatements(), ImmutableMap.builder().put("foo", "select * from bar").buildOrThrow());
List<List<Object>> rows = data.build();
assertEquals(rows, ImmutableList.of(ImmutableList.of("memory"), ImmutableList.of("system")));
}
use of io.trino.server.BasicQueryInfo in project trino by trinodb.
the class TestQueryManager method testQueryCpuLimit.
@Test(timeOut = 60_000L)
public void testQueryCpuLimit() throws Exception {
try (DistributedQueryRunner queryRunner = TpchQueryRunnerBuilder.builder().addExtraProperty("query.max-cpu-time", "1ms").build()) {
QueryId queryId = createQuery(queryRunner, TEST_SESSION, "SELECT COUNT(*) FROM lineitem");
waitForQueryState(queryRunner, queryId, FAILED);
QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
BasicQueryInfo queryInfo = queryManager.getQueryInfo(queryId);
assertEquals(queryInfo.getState(), FAILED);
assertEquals(queryInfo.getErrorCode(), EXCEEDED_CPU_LIMIT.toErrorCode());
}
}
use of io.trino.server.BasicQueryInfo in project trino by trinodb.
the class TestQueryManager method testQueryScanExceededSession.
@Test(timeOut = 60_000L)
public void testQueryScanExceededSession() throws Exception {
try (DistributedQueryRunner queryRunner = TpchQueryRunnerBuilder.builder().build()) {
Session session = testSessionBuilder().setCatalog("tpch").setSchema(TINY_SCHEMA_NAME).setClientCapabilities(stream(ClientCapabilities.values()).map(ClientCapabilities::toString).collect(toImmutableSet())).setSystemProperty("query_max_scan_physical_bytes", "0B").build();
QueryId queryId = createQuery(queryRunner, session, "SELECT * FROM system.runtime.nodes");
waitForQueryState(queryRunner, queryId, FAILED);
QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
BasicQueryInfo queryInfo = queryManager.getQueryInfo(queryId);
assertEquals(queryInfo.getState(), FAILED);
assertEquals(queryInfo.getErrorCode(), EXCEEDED_SCAN_LIMIT.toErrorCode());
}
}
use of io.trino.server.BasicQueryInfo in project trino by trinodb.
the class TestQueryManager method testQueryScanExceeded.
@Test(timeOut = 60_000L)
public void testQueryScanExceeded() throws Exception {
try (DistributedQueryRunner queryRunner = TpchQueryRunnerBuilder.builder().addExtraProperty("query.max-scan-physical-bytes", "0B").build()) {
QueryId queryId = createQuery(queryRunner, TEST_SESSION, "SELECT * FROM system.runtime.nodes");
waitForQueryState(queryRunner, queryId, FAILED);
QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
BasicQueryInfo queryInfo = queryManager.getQueryInfo(queryId);
assertEquals(queryInfo.getState(), FAILED);
assertEquals(queryInfo.getErrorCode(), EXCEEDED_SCAN_LIMIT.toErrorCode());
}
}
use of io.trino.server.BasicQueryInfo in project trino by trinodb.
the class TestGracefulShutdown method testShutdown.
@Test(timeOut = SHUTDOWN_TIMEOUT_MILLIS)
public void testShutdown() throws Exception {
Map<String, String> properties = ImmutableMap.<String, String>builder().put("node-scheduler.include-coordinator", "false").put("shutdown.grace-period", "10s").buildOrThrow();
try (DistributedQueryRunner queryRunner = createQueryRunner(TINY_SESSION, properties)) {
List<ListenableFuture<Void>> queryFutures = new ArrayList<>();
for (int i = 0; i < 5; i++) {
queryFutures.add(Futures.submit(() -> {
queryRunner.execute("SELECT COUNT(*), clerk FROM orders GROUP BY clerk");
}, executor));
}
TestingTrinoServer worker = queryRunner.getServers().stream().filter(server -> !server.isCoordinator()).findFirst().get();
SqlTaskManager taskManager = worker.getTaskManager();
// wait until tasks show up on the worker
while (taskManager.getAllTaskInfo().isEmpty()) {
MILLISECONDS.sleep(500);
}
worker.getGracefulShutdownHandler().requestShutdown();
Futures.allAsList(queryFutures).get();
List<BasicQueryInfo> queryInfos = queryRunner.getCoordinator().getQueryManager().getQueries();
for (BasicQueryInfo info : queryInfos) {
assertEquals(info.getState(), FINISHED);
}
TestShutdownAction shutdownAction = (TestShutdownAction) worker.getShutdownAction();
shutdownAction.waitForShutdownComplete(SHUTDOWN_TIMEOUT_MILLIS);
assertTrue(shutdownAction.isWorkerShutdown());
}
}
Aggregations