Search in sources :

Example 16 with BasicQueryInfo

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")));
}
Also used : QueryId(io.trino.spi.QueryId) QueryError(io.trino.client.QueryError) X_FORWARDED_PORT(com.google.common.net.HttpHeaders.X_FORWARDED_PORT) BasicQueryInfo(io.trino.server.BasicQueryInfo) FullJsonResponseHandler.createFullJsonResponseHandler(io.airlift.http.client.FullJsonResponseHandler.createFullJsonResponseHandler) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.testng.annotations.Test) Closeables.closeAll(io.airlift.testing.Closeables.closeAll) QueryResults(io.trino.client.QueryResults) URI(java.net.URI) Collector(java.util.stream.Collector) TestingTrinoServer(io.trino.server.testing.TestingTrinoServer) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) Splitter(com.google.common.base.Splitter) X_FORWARDED_PROTO(com.google.common.net.HttpHeaders.X_FORWARDED_PROTO) HttpUriBuilder(io.airlift.http.client.HttpUriBuilder) SEE_OTHER(javax.ws.rs.core.Response.Status.SEE_OTHER) JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) Builder.prepareHead(io.airlift.http.client.Request.Builder.prepareHead) QUERY_MAX_MEMORY(io.trino.SystemSessionProperties.QUERY_MAX_MEMORY) ImmutableMap(com.google.common.collect.ImmutableMap) OK(javax.ws.rs.core.Response.Status.OK) MemoryPlugin(io.trino.plugin.memory.MemoryPlugin) BeforeClass(org.testng.annotations.BeforeClass) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Assert.assertNotNull(org.testng.Assert.assertNotNull) Streams(com.google.common.collect.Streams) TestingTrinoClient(io.trino.testing.TestingTrinoClient) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) Stream(java.util.stream.Stream) Optional(java.util.Optional) StaticBodyGenerator.createStaticBodyGenerator(io.airlift.http.client.StaticBodyGenerator.createStaticBodyGenerator) JsonCodec(io.airlift.json.JsonCodec) HttpClient(io.airlift.http.client.HttpClient) IntStream(java.util.stream.IntStream) Assert.assertNull(org.testng.Assert.assertNull) Assert.assertEquals(org.testng.Assert.assertEquals) Function(java.util.function.Function) CONTENT_TYPE(com.google.common.net.HttpHeaders.CONTENT_TYPE) AbstractSequentialIterator(com.google.common.collect.AbstractSequentialIterator) INCOMPATIBLE_CLIENT(io.trino.spi.StandardErrorCode.INCOMPATIBLE_CLIENT) JsonResponse(io.airlift.http.client.FullJsonResponseHandler.JsonResponse) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) Request(io.airlift.http.client.Request) X_FORWARDED_HOST(com.google.common.net.HttpHeaders.X_FORWARDED_HOST) AfterClass(org.testng.annotations.AfterClass) Builder.preparePost(io.airlift.http.client.Request.Builder.preparePost) Builder.prepareGet(io.airlift.http.client.Request.Builder.prepareGet) Language(org.intellij.lang.annotations.Language) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Assert.fail(org.testng.Assert.fail) HASH_PARTITION_COUNT(io.trino.SystemSessionProperties.HASH_PARTITION_COUNT) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) JsonCodec.jsonCodec(io.airlift.json.JsonCodec.jsonCodec) StatusResponseHandler.createStatusResponseHandler(io.airlift.http.client.StatusResponseHandler.createStatusResponseHandler) JOIN_DISTRIBUTION_TYPE(io.trino.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) TimeZoneNotSupportedException(io.trino.spi.type.TimeZoneNotSupportedException) StatusResponse(io.airlift.http.client.StatusResponseHandler.StatusResponse) Collections(java.util.Collections) TRINO_HEADERS(io.trino.client.ProtocolHeaders.TRINO_HEADERS) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryId(io.trino.spi.QueryId) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) QueryResults(io.trino.client.QueryResults) Test(org.testng.annotations.Test)

Example 17 with BasicQueryInfo

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());
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) QueryId(io.trino.spi.QueryId) BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryManager(io.trino.execution.QueryManager) Test(org.testng.annotations.Test)

Example 18 with BasicQueryInfo

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());
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) QueryId(io.trino.spi.QueryId) BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryManager(io.trino.execution.QueryManager) ClientCapabilities(io.trino.client.ClientCapabilities) Session(io.trino.Session) Test(org.testng.annotations.Test)

Example 19 with BasicQueryInfo

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());
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) QueryId(io.trino.spi.QueryId) BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryManager(io.trino.execution.QueryManager) Test(org.testng.annotations.Test)

Example 20 with BasicQueryInfo

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());
    }
}
Also used : SqlTaskManager(io.trino.execution.SqlTaskManager) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) BasicQueryInfo(io.trino.server.BasicQueryInfo) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TestShutdownAction(io.trino.server.testing.TestingTrinoServer.TestShutdownAction) TestingTrinoServer(io.trino.server.testing.TestingTrinoServer) Test(org.testng.annotations.Test)

Aggregations

BasicQueryInfo (io.trino.server.BasicQueryInfo)20 Test (org.testng.annotations.Test)10 QueryId (io.trino.spi.QueryId)7 QueryManager (io.trino.execution.QueryManager)6 DistributedQueryRunner (io.trino.testing.DistributedQueryRunner)5 DispatchManager (io.trino.dispatcher.DispatchManager)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 Session (io.trino.Session)3 TestingTrinoServer (io.trino.server.testing.TestingTrinoServer)3 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 QueryState (io.trino.execution.QueryState)2 ResourceSecurity (io.trino.server.security.ResourceSecurity)2 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 SECONDS (java.util.concurrent.TimeUnit.SECONDS)2 GET (javax.ws.rs.GET)2