From f770c9b4d1b92551f4983dc91274e31ebf3ca4e5 Mon Sep 17 00:00:00 2001 From: Yuya Ebihara Date: Mon, 7 Oct 2024 11:01:11 +0900 Subject: [PATCH] Migrate TestSystemConnector to integration test --- .../tests/product/TestSystemConnector.java | 124 ------------------ .../metadata/TestSystemMetadataConnector.java | 12 ++ .../runtime/TestSystemRuntimeConnector.java | 7 + 3 files changed, 19 insertions(+), 124 deletions(-) delete mode 100644 testing/trino-product-tests/src/main/java/io/trino/tests/product/TestSystemConnector.java diff --git a/testing/trino-product-tests/src/main/java/io/trino/tests/product/TestSystemConnector.java b/testing/trino-product-tests/src/main/java/io/trino/tests/product/TestSystemConnector.java deleted file mode 100644 index d842fbecb30a..000000000000 --- a/testing/trino-product-tests/src/main/java/io/trino/tests/product/TestSystemConnector.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.trino.tests.product; - -import com.google.common.collect.ImmutableList; -import io.trino.tempto.ProductTest; -import org.testng.annotations.Test; - -import static io.trino.tempto.assertions.QueryAssert.Row.row; -import static io.trino.tests.product.TestGroups.JDBC; -import static io.trino.tests.product.utils.QueryExecutors.onTrino; -import static java.sql.JDBCType.ARRAY; -import static java.sql.JDBCType.BIGINT; -import static java.sql.JDBCType.TIMESTAMP_WITH_TIMEZONE; -import static java.sql.JDBCType.VARCHAR; -import static org.assertj.core.api.Assertions.assertThat; - -public class TestSystemConnector - extends ProductTest -{ - @Test(groups = JDBC) - public void selectRuntimeNodes() - { - String sql = "SELECT node_id, http_uri, node_version, state FROM system.runtime.nodes"; - assertThat(onTrino().executeQuery(sql)) - .hasColumns(VARCHAR, VARCHAR, VARCHAR, VARCHAR) - .hasAnyRows(); - } - - @Test(groups = JDBC) - public void testRuleStats() - { - assertThat(onTrino().executeQuery("SELECT rule_name, invocations, matches, failures FROM system.runtime.optimizer_rule_stats")) - .hasColumns(VARCHAR, BIGINT, BIGINT, BIGINT) - .hasAnyRows(); - } - - @Test(groups = JDBC) - public void selectRuntimeQueries() - { - String sql = "SELECT" + - " query_id," + - " state," + - " user," + - " query," + - " resource_group_id," + - " queued_time_ms," + - " analysis_time_ms," + - " planning_time_ms," + - " created," + - " started," + - " last_heartbeat," + - " \"end\"," + - " error_type," + - " error_code " + - "FROM system.runtime.queries"; - assertThat(onTrino().executeQuery(sql)) - .hasColumns(VARCHAR, VARCHAR, VARCHAR, VARCHAR, ARRAY, - BIGINT, BIGINT, BIGINT, TIMESTAMP_WITH_TIMEZONE, TIMESTAMP_WITH_TIMEZONE, - TIMESTAMP_WITH_TIMEZONE, TIMESTAMP_WITH_TIMEZONE, VARCHAR, VARCHAR) - .hasAnyRows(); - } - - @Test(groups = JDBC) - public void selectRuntimeTasks() - { - String sql = "SELECT" + - " node_id," + - " task_id," + - " stage_id," + - " query_id," + - " state," + - " splits," + - " queued_splits," + - " running_splits," + - " completed_splits," + - " split_scheduled_time_ms," + - " split_cpu_time_ms," + - " split_blocked_time_ms," + - " raw_input_bytes," + - " raw_input_rows," + - " processed_input_bytes," + - " processed_input_rows," + - " output_bytes," + - " output_rows," + - " physical_input_bytes," + - " physical_written_bytes," + - " created," + - " start," + - " last_heartbeat," + - " \"end\" " + - "FROM SYSTEM.runtime.tasks"; - assertThat(onTrino().executeQuery(sql)) - .hasColumns(VARCHAR, VARCHAR, VARCHAR, VARCHAR, VARCHAR, - BIGINT, BIGINT, BIGINT, BIGINT, BIGINT, BIGINT, BIGINT, BIGINT, - BIGINT, BIGINT, BIGINT, BIGINT, BIGINT, BIGINT, BIGINT, - TIMESTAMP_WITH_TIMEZONE, TIMESTAMP_WITH_TIMEZONE, TIMESTAMP_WITH_TIMEZONE, TIMESTAMP_WITH_TIMEZONE) - .hasAnyRows(); - } - - @Test(groups = JDBC) - public void selectMetadataCatalogs() - { - String sql = "select catalog_name, connector_id, connector_name from system.metadata.catalogs"; - assertThat(onTrino().executeQuery(sql)) - .hasColumns(VARCHAR, VARCHAR, VARCHAR) - .contains( - ImmutableList.of( - row("jmx", "jmx", "jmx"), - row("system", "system", "system"), - row("tpch", "tpch", "tpch"))); - } -} diff --git a/testing/trino-tests/src/test/java/io/trino/connector/system/metadata/TestSystemMetadataConnector.java b/testing/trino-tests/src/test/java/io/trino/connector/system/metadata/TestSystemMetadataConnector.java index eab3684da78d..a2a0de6fb36f 100644 --- a/testing/trino-tests/src/test/java/io/trino/connector/system/metadata/TestSystemMetadataConnector.java +++ b/testing/trino-tests/src/test/java/io/trino/connector/system/metadata/TestSystemMetadataConnector.java @@ -34,6 +34,7 @@ import static io.trino.testing.MultisetAssertions.assertMultisetsEqual; import static io.trino.testing.TestingSession.testSessionBuilder; import static java.util.stream.Collectors.joining; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.parallel.ExecutionMode.SAME_THREAD; @Execution(SAME_THREAD) // CountingMockConnector is shared mutable state @@ -72,6 +73,17 @@ protected QueryRunner createQueryRunner() } } + @Test + void testMetadataCatalogs() + { + assertThat(query("SELECT catalog_name, connector_id, connector_name FROM system.metadata.catalogs")) + .matches("VALUES " + + "(CAST('system' AS VARCHAR), CAST('system' AS VARCHAR), CAST('system' AS VARCHAR))," + + "(CAST('test_catalog' AS VARCHAR), CAST('test_catalog' AS VARCHAR), CAST('mock' AS VARCHAR))," + + "(CAST('broken_catalog' AS VARCHAR), CAST('broken_catalog' AS VARCHAR), CAST('failing_mock' AS VARCHAR))," + + "(CAST('tpch' AS VARCHAR), CAST('tpch' AS VARCHAR), CAST('tpch' AS VARCHAR))"); + } + @Test public void testTableCommentsMetadataCalls() { diff --git a/testing/trino-tests/src/test/java/io/trino/connector/system/runtime/TestSystemRuntimeConnector.java b/testing/trino-tests/src/test/java/io/trino/connector/system/runtime/TestSystemRuntimeConnector.java index c262e66af246..e5a386dbacd3 100644 --- a/testing/trino-tests/src/test/java/io/trino/connector/system/runtime/TestSystemRuntimeConnector.java +++ b/testing/trino-tests/src/test/java/io/trino/connector/system/runtime/TestSystemRuntimeConnector.java @@ -114,6 +114,13 @@ public void testRuntimeNodes() "('testversion', false, 'active')"); } + @Test + void testOptimizerRuleStats() + { + assertThat(query("SELECT rule_name, invocations, matches, failures FROM system.runtime.optimizer_rule_stats")) + .result().hasTypes(ImmutableList.of(VARCHAR, BIGINT, BIGINT, BIGINT)); + } + @Test public void testRuntimeQueriesTimestamps() {