From 9a7cf10d16253d165253218ae8345f22e6d480c8 Mon Sep 17 00:00:00 2001 From: Martin Traverso Date: Sat, 30 Sep 2023 16:06:02 -0700 Subject: [PATCH] Migrate tests to JUnit --- .../io/trino/memory/TestMemoryTracking.java | 25 ++- .../operator/TestDistinctLimitOperator.java | 9 +- .../trino/operator/TestExchangeOperator.java | 30 ++-- .../io/trino/operator/TestGroupByHash.java | 2 +- plugin/trino-ml/pom.xml | 37 +---- .../ml/TestEvaluateClassifierPredictions.java | 10 +- .../plugin/ml/TestFeatureTransformations.java | 11 +- .../plugin/ml/TestLearnAggregations.java | 12 +- .../io/trino/plugin/ml/TestMLQueries.java | 2 +- .../plugin/ml/TestModelSerialization.java | 60 ++++--- plugin/trino-redis/pom.xml | 6 + .../AbstractTestMinimalFunctionality.java | 13 +- .../redis/TestMinimalFunctionality.java | 3 +- ...tMinimalFunctionalityWithoutKeyPrefix.java | 3 +- .../redis/TestRedisConnectorConfig.java | 2 +- .../redis/TestRedisDistributedHash.java | 2 +- .../trino/plugin/redis/TestRedisPlugin.java | 2 +- service/trino-proxy/pom.xml | 4 +- .../io/trino/proxy/TestJwtHandlerConfig.java | 2 +- .../java/io/trino/proxy/TestProxyConfig.java | 2 +- .../java/io/trino/proxy/TestProxyServer.java | 53 ++++--- service/trino-verifier/pom.xml | 14 +- .../verifier/TestDatabaseEventClient.java | 106 ++++++------- .../java/io/trino/verifier/TestShadowing.java | 59 +++---- .../java/io/trino/verifier/TestValidator.java | 22 +-- .../io/trino/verifier/TestVerifierConfig.java | 2 +- .../verifier/TestVerifierRewriteQueries.java | 20 +-- testing/trino-benchmark-queries/pom.xml | 4 +- .../io/trino/benchmark/queries/TestDummy.java | 2 +- testing/trino-benchmark/pom.xml | 10 +- .../benchmark/BenchmarkInequalityJoin.java | 2 +- .../io/trino/benchmark/TestBenchmarks.java | 2 +- testing/trino-benchto-benchmarks/pom.xml | 4 +- .../java/io/trino/benchmarks/TestDummy.java | 2 +- testing/trino-server-dev/pom.xml | 4 +- .../server/TestDevelopmentLoaderConfig.java | 2 +- testing/trino-testing-containers/pom.xml | 4 +- .../test/java/io/trino/server/TestDummy.java | 2 +- testing/trino-testing-kafka/pom.xml | 4 +- .../test/java/io/trino/server/TestDummy.java | 2 +- testing/trino-testing-resources/pom.xml | 4 +- .../io/trino/testing/resources/TestDummy.java | 2 +- testing/trino-tests/pom.xml | 20 +-- .../BenchmarkInformationSchema.java | 2 +- .../system/runtime/TestKillQuery.java | 18 ++- .../io/trino/execution/TestBeginQuery.java | 20 +-- .../execution/TestCompletedEventWarnings.java | 14 +- .../execution/TestConnectorEventListener.java | 13 +- .../TestDeprecatedFunctionWarning.java | 13 +- .../execution/TestErrorThrowableInQuery.java | 2 +- .../TestEventListenerWithSplits.java | 3 +- .../execution/TestExecutionJmxMetrics.java | 6 +- .../trino/execution/TestFinalQueryInfo.java | 6 +- .../execution/TestPendingStageState.java | 17 +- .../io/trino/execution/TestQueryTracker.java | 14 +- .../java/io/trino/execution/TestQueues.java | 28 ++-- .../TestRefreshMaterializedView.java | 38 +++-- .../TestSetSessionAuthorization.java | 2 +- .../trino/execution/TestStatementStats.java | 2 +- .../trino/execution/TestTableRedirection.java | 2 +- .../test/java/io/trino/execution/TestTry.java | 2 +- .../TestUserImpersonationAccessControl.java | 2 +- .../java/io/trino/execution/TestWarnings.java | 13 +- .../TestResourceGroupIntegration.java | 2 +- .../resourcegroups/db/TestEnvironments.java | 10 +- .../resourcegroups/db/TestQueuesDb.java | 39 +++-- .../db/TestResourceGroupDbIntegration.java | 2 +- .../memory/TestClusterMemoryLeakDetector.java | 2 +- .../io/trino/memory/TestMemoryManager.java | 108 +++++++------ .../memory/TestMemorySessionProperties.java | 6 +- .../io/trino/security/TestAccessControl.java | 147 ++++++++++++++---- .../TestAccessControlTableRedirection.java | 2 +- ...ViewsWithFileBasedSystemAccessControl.java | 2 +- .../security/TestSystemSecurityMetadata.java | 15 +- .../tests/TestDictionaryAggregation.java | 2 +- .../tests/TestExcludeColumnsFunction.java | 2 +- .../TestGetTableStatisticsOperations.java | 21 ++- .../io/trino/tests/TestGracefulShutdown.java | 19 ++- .../tests/TestInformationSchemaConnector.java | 16 +- .../tests/TestLateMaterializationQueries.java | 2 +- .../java/io/trino/tests/TestLocalQueries.java | 2 +- .../io/trino/tests/TestMetadataManager.java | 14 +- .../io/trino/tests/TestMockConnector.java | 2 +- .../io/trino/tests/TestProcedureCall.java | 14 +- .../io/trino/tests/TestProcedureCreation.java | 2 +- .../java/io/trino/tests/TestQueryManager.java | 27 ++-- .../trino/tests/TestRepartitionQueries.java | 2 +- .../io/trino/tests/TestSequenceFunction.java | 2 +- .../test/java/io/trino/tests/TestServer.java | 10 +- .../tests/TestTableFunctionInvocation.java | 2 +- .../java/io/trino/tests/TestTablesample.java | 13 +- .../java/io/trino/tests/TestUnionQueries.java | 2 +- .../tests/TestVerifyTrinoTestsTestSetup.java | 2 +- .../tests/tpch/TestTpchDistributedStats.java | 13 +- .../trino/tests/tpch/TestTpchLocalStats.java | 13 +- .../tpch/TestTpchTableScanRedirection.java | 9 +- 96 files changed, 777 insertions(+), 549 deletions(-) diff --git a/core/trino-main/src/test/java/io/trino/memory/TestMemoryTracking.java b/core/trino-main/src/test/java/io/trino/memory/TestMemoryTracking.java index 84ec369fcc55..4aeec8b14afc 100644 --- a/core/trino-main/src/test/java/io/trino/memory/TestMemoryTracking.java +++ b/core/trino-main/src/test/java/io/trino/memory/TestMemoryTracking.java @@ -32,10 +32,10 @@ import io.trino.spi.QueryId; import io.trino.spiller.SpillSpaceTracker; import io.trino.sql.planner.plan.PlanNodeId; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import java.util.List; import java.util.concurrent.ExecutorService; @@ -48,11 +48,12 @@ import static java.util.concurrent.Executors.newCachedThreadPool; import static java.util.concurrent.Executors.newScheduledThreadPool; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_METHOD; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; -@Test(singleThreaded = true) +@TestInstance(PER_METHOD) public class TestMemoryTracking { private static final DataSize queryMaxMemory = DataSize.of(1, GIGABYTE); @@ -70,14 +71,7 @@ public class TestMemoryTracking private ExecutorService notificationExecutor; private ScheduledExecutorService yieldExecutor; - @BeforeClass - public void setUp() - { - notificationExecutor = newCachedThreadPool(daemonThreadsNamed("local-query-runner-executor-%s")); - yieldExecutor = newScheduledThreadPool(2, daemonThreadsNamed("local-query-runner-scheduler-%s")); - } - - @AfterClass(alwaysRun = true) + @AfterEach public void tearDown() { notificationExecutor.shutdownNow(); @@ -90,9 +84,12 @@ public void tearDown() memoryPool = null; } - @BeforeMethod + @BeforeEach public void setUpTest() { + notificationExecutor = newCachedThreadPool(daemonThreadsNamed("local-query-runner-executor-%s")); + yieldExecutor = newScheduledThreadPool(2, daemonThreadsNamed("local-query-runner-scheduler-%s")); + memoryPool = new MemoryPool(memoryPoolSize); queryContext = new QueryContext( new QueryId("test_query"), diff --git a/core/trino-main/src/test/java/io/trino/operator/TestDistinctLimitOperator.java b/core/trino-main/src/test/java/io/trino/operator/TestDistinctLimitOperator.java index aa996285d18f..6856f7e70d84 100644 --- a/core/trino-main/src/test/java/io/trino/operator/TestDistinctLimitOperator.java +++ b/core/trino-main/src/test/java/io/trino/operator/TestDistinctLimitOperator.java @@ -22,8 +22,9 @@ import io.trino.sql.gen.JoinCompiler; import io.trino.sql.planner.plan.PlanNodeId; import io.trino.testing.MaterializedResult; -import org.testng.annotations.AfterClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import java.util.List; import java.util.Optional; @@ -43,15 +44,17 @@ import static io.trino.testing.TestingTaskContext.createTaskContext; import static java.util.concurrent.Executors.newCachedThreadPool; import static java.util.concurrent.Executors.newScheduledThreadPool; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; import static org.testng.Assert.assertEquals; +@TestInstance(PER_CLASS) public class TestDistinctLimitOperator { private final ExecutorService executor = newCachedThreadPool(daemonThreadsNamed(getClass().getSimpleName() + "-%s")); private final ScheduledExecutorService scheduledExecutor = newScheduledThreadPool(2, daemonThreadsNamed(getClass().getSimpleName() + "-scheduledExecutor-%s")); private final JoinCompiler joinCompiler = new JoinCompiler(new TypeOperators()); - @AfterClass(alwaysRun = true) + @AfterAll public void tearDown() { executor.shutdownNow(); diff --git a/core/trino-main/src/test/java/io/trino/operator/TestExchangeOperator.java b/core/trino-main/src/test/java/io/trino/operator/TestExchangeOperator.java index a4accb42faa2..6f97e5130ed5 100644 --- a/core/trino-main/src/test/java/io/trino/operator/TestExchangeOperator.java +++ b/core/trino-main/src/test/java/io/trino/operator/TestExchangeOperator.java @@ -34,10 +34,10 @@ import io.trino.spi.type.Type; import io.trino.split.RemoteSplit; import io.trino.sql.planner.plan.PlanNodeId; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import java.util.ArrayList; import java.util.List; @@ -57,11 +57,12 @@ import static io.trino.spi.type.VarcharType.VARCHAR; import static io.trino.testing.TestingTaskContext.createTaskContext; import static java.util.concurrent.Executors.newScheduledThreadPool; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; -@Test(singleThreaded = true) +@TestInstance(PER_CLASS) public class TestExchangeOperator { private static final List TYPES = ImmutableList.of(VARCHAR); @@ -81,7 +82,7 @@ public class TestExchangeOperator private ExecutorService pageBufferClientCallbackExecutor; @SuppressWarnings("resource") - @BeforeClass + @BeforeAll public void setUp() { scheduler = newScheduledThreadPool(4, daemonThreadsNamed(getClass().getSimpleName() + "-%s")); @@ -104,7 +105,7 @@ public void setUp() taskFailureListener); } - @AfterClass(alwaysRun = true) + @AfterAll public void tearDown() { httpClient.close(); @@ -120,17 +121,12 @@ public void tearDown() pageBufferClientCallbackExecutor = null; } - @BeforeMethod - public void setUpMethod() - { - // the test class is single-threaded, so there should be no ongoing loads and invalidation should be effective - taskBuffers.invalidateAll(); - } - @Test public void testSimple() throws Exception { + taskBuffers.invalidateAll(); + SourceOperator operator = createExchangeOperator(); operator.addSplit(newRemoteSplit(TASK_1_ID)); @@ -159,6 +155,8 @@ private static Split newRemoteSplit(TaskId taskId) public void testWaitForClose() throws Exception { + taskBuffers.invalidateAll(); + SourceOperator operator = createExchangeOperator(); operator.addSplit(newRemoteSplit(TASK_1_ID)); @@ -195,6 +193,8 @@ public void testWaitForClose() public void testWaitForNoMoreSplits() throws Exception { + taskBuffers.invalidateAll(); + SourceOperator operator = createExchangeOperator(); // add a buffer location containing one page and close the buffer @@ -228,6 +228,8 @@ public void testWaitForNoMoreSplits() public void testFinish() throws Exception { + taskBuffers.invalidateAll(); + SourceOperator operator = createExchangeOperator(); operator.addSplit(newRemoteSplit(TASK_1_ID)); diff --git a/core/trino-main/src/test/java/io/trino/operator/TestGroupByHash.java b/core/trino-main/src/test/java/io/trino/operator/TestGroupByHash.java index 6edaafa07bb0..a0becc743c18 100644 --- a/core/trino-main/src/test/java/io/trino/operator/TestGroupByHash.java +++ b/core/trino-main/src/test/java/io/trino/operator/TestGroupByHash.java @@ -29,7 +29,7 @@ import io.trino.spi.type.TypeOperators; import io.trino.sql.gen.JoinCompiler; import io.trino.testing.TestingSession; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; diff --git a/plugin/trino-ml/pom.xml b/plugin/trino-ml/pom.xml index abe84a74edf3..d9f06ed6c2bd 100644 --- a/plugin/trino-ml/pom.xml +++ b/plugin/trino-ml/pom.xml @@ -130,36 +130,15 @@ - org.testng - testng + org.assertj + assertj-core test - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - - org.apache.maven.surefire - surefire-junit-platform - ${dep.plugin.surefire.version} - - - org.apache.maven.surefire - surefire-testng - ${dep.plugin.surefire.version} - - - org.junit.jupiter - junit-jupiter-engine - ${dep.junit.version} - - - - - + + org.junit.jupiter + junit-jupiter-api + test + + diff --git a/plugin/trino-ml/src/test/java/io/trino/plugin/ml/TestEvaluateClassifierPredictions.java b/plugin/trino-ml/src/test/java/io/trino/plugin/ml/TestEvaluateClassifierPredictions.java index cbbfa1b8855c..bb58185011d3 100644 --- a/plugin/trino-ml/src/test/java/io/trino/plugin/ml/TestEvaluateClassifierPredictions.java +++ b/plugin/trino-ml/src/test/java/io/trino/plugin/ml/TestEvaluateClassifierPredictions.java @@ -22,7 +22,7 @@ import io.trino.spi.Page; import io.trino.spi.block.Block; import io.trino.spi.block.BlockBuilder; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.OptionalInt; @@ -32,7 +32,7 @@ import static io.trino.spi.type.VarcharType.VARCHAR; import static io.trino.sql.analyzer.TypeSignatureProvider.fromTypes; import static io.trino.sql.planner.plan.AggregationNode.Step.SINGLE; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestEvaluateClassifierPredictions { @@ -49,8 +49,10 @@ public void testEvaluateClassifierPredictions() String output = VARCHAR.getSlice(block, 0).toStringUtf8(); List parts = ImmutableList.copyOf(Splitter.on('\n').omitEmptyStrings().split(output)); - assertEquals(parts.size(), 7, output); - assertEquals(parts.get(0), "Accuracy: 1/2 (50.00%)"); + assertThat(parts.size()) + .describedAs(output) + .isEqualTo(7); + assertThat(parts.get(0)).isEqualTo("Accuracy: 1/2 (50.00%)"); } private static Page getPage() diff --git a/plugin/trino-ml/src/test/java/io/trino/plugin/ml/TestFeatureTransformations.java b/plugin/trino-ml/src/test/java/io/trino/plugin/ml/TestFeatureTransformations.java index 47c8c8627b20..3356b5b41856 100644 --- a/plugin/trino-ml/src/test/java/io/trino/plugin/ml/TestFeatureTransformations.java +++ b/plugin/trino-ml/src/test/java/io/trino/plugin/ml/TestFeatureTransformations.java @@ -15,7 +15,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.HashSet; @@ -23,8 +23,7 @@ import java.util.Set; import static io.trino.plugin.ml.TestUtils.getDataset; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class TestFeatureTransformations { @@ -43,11 +42,11 @@ public void testUnitNormalizer() } } // Make sure there is a feature that needs to be normalized - assertTrue(valueGreaterThanOne); + assertThat(valueGreaterThanOne).isTrue(); transformation.train(dataset); for (FeatureVector vector : transformation.transform(dataset).getDatapoints()) { for (double value : vector.getFeatures().values()) { - assertTrue(value <= 1); + assertThat(value <= 1).isTrue(); } } } @@ -69,6 +68,6 @@ public void testUnitNormalizerSimple() for (FeatureVector vector : transformation.transform(dataset).getDatapoints()) { featureValues.addAll(vector.getFeatures().values()); } - assertEquals(featureValues, ImmutableSet.of(0.0, 0.5, 1.0)); + assertThat(featureValues).isEqualTo(ImmutableSet.of(0.0, 0.5, 1.0)); } } diff --git a/plugin/trino-ml/src/test/java/io/trino/plugin/ml/TestLearnAggregations.java b/plugin/trino-ml/src/test/java/io/trino/plugin/ml/TestLearnAggregations.java index 8d32ca88b4af..49a6790e6d09 100644 --- a/plugin/trino-ml/src/test/java/io/trino/plugin/ml/TestLearnAggregations.java +++ b/plugin/trino-ml/src/test/java/io/trino/plugin/ml/TestLearnAggregations.java @@ -28,7 +28,7 @@ import io.trino.spi.type.Type; import io.trino.sql.PlannerContext; import io.trino.transaction.TransactionManager; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.OptionalInt; import java.util.Random; @@ -45,8 +45,7 @@ import static io.trino.testing.StructuralTestUtil.mapBlockOf; import static io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager; import static io.trino.type.InternalTypeManager.TESTING_TYPE_MANAGER; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class TestLearnAggregations { @@ -90,8 +89,11 @@ private static void assertLearnClassifier(Aggregator aggregator) Block block = finalOut.build(); Slice slice = aggregator.getType().getSlice(block, 0); Model deserialized = ModelUtils.deserialize(slice); - assertNotNull(deserialized, "deserialization failed"); - assertTrue(deserialized instanceof Classifier, "deserialized model is not a classifier"); + assertThat(deserialized) + .describedAs("deserialization failed") + .isNotNull(); + + assertThat(deserialized).isInstanceOf(Classifier.class); } private static Page getPage() diff --git a/plugin/trino-ml/src/test/java/io/trino/plugin/ml/TestMLQueries.java b/plugin/trino-ml/src/test/java/io/trino/plugin/ml/TestMLQueries.java index 76e935e54db0..86560c37ad25 100644 --- a/plugin/trino-ml/src/test/java/io/trino/plugin/ml/TestMLQueries.java +++ b/plugin/trino-ml/src/test/java/io/trino/plugin/ml/TestMLQueries.java @@ -19,7 +19,7 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.LocalQueryRunner; import io.trino.testing.QueryRunner; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.trino.plugin.tpch.TpchMetadata.TINY_SCHEMA_NAME; import static io.trino.testing.TestingSession.testSessionBuilder; diff --git a/plugin/trino-ml/src/test/java/io/trino/plugin/ml/TestModelSerialization.java b/plugin/trino-ml/src/test/java/io/trino/plugin/ml/TestModelSerialization.java index 4242eda8b2b3..6ab4b39f84cc 100644 --- a/plugin/trino-ml/src/test/java/io/trino/plugin/ml/TestModelSerialization.java +++ b/plugin/trino-ml/src/test/java/io/trino/plugin/ml/TestModelSerialization.java @@ -14,12 +14,10 @@ package io.trino.plugin.ml; import io.airlift.slice.Slice; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.trino.plugin.ml.TestUtils.getDataset; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class TestModelSerialization { @@ -30,8 +28,12 @@ public void testSvmClassifier() model.train(getDataset()); Slice serialized = ModelUtils.serialize(model); Model deserialized = ModelUtils.deserialize(serialized); - assertNotNull(deserialized, "deserialization failed"); - assertTrue(deserialized instanceof SvmClassifier, "deserialized model is not a svm"); + assertThat(deserialized) + .describedAs("deserialization failed") + .isNotNull(); + assertThat(deserialized) + .describedAs("deserialized model is not a svm") + .isInstanceOf(SvmClassifier.class); } @Test @@ -41,8 +43,12 @@ public void testSvmRegressor() model.train(getDataset()); Slice serialized = ModelUtils.serialize(model); Model deserialized = ModelUtils.deserialize(serialized); - assertNotNull(deserialized, "deserialization failed"); - assertTrue(deserialized instanceof SvmRegressor, "deserialized model is not a svm"); + assertThat(deserialized) + .describedAs("deserialization failed") + .isNotNull(); + assertThat(deserialized) + .describedAs("deserialized model is not a svm") + .isInstanceOf(SvmRegressor.class); } @Test @@ -52,8 +58,12 @@ public void testRegressorFeatureTransformer() model.train(getDataset()); Slice serialized = ModelUtils.serialize(model); Model deserialized = ModelUtils.deserialize(serialized); - assertNotNull(deserialized, "deserialization failed"); - assertTrue(deserialized instanceof RegressorFeatureTransformer, "deserialized model is not a regressor feature transformer"); + assertThat(deserialized) + .describedAs("deserialization failed") + .isNotNull(); + assertThat(deserialized) + .describedAs("deserialized model is not a regressor feature transformer") + .isInstanceOf(RegressorFeatureTransformer.class); } @Test @@ -63,8 +73,12 @@ public void testClassifierFeatureTransformer() model.train(getDataset()); Slice serialized = ModelUtils.serialize(model); Model deserialized = ModelUtils.deserialize(serialized); - assertNotNull(deserialized, "deserialization failed"); - assertTrue(deserialized instanceof ClassifierFeatureTransformer, "deserialized model is not a classifier feature transformer"); + assertThat(deserialized) + .describedAs("deserialization failed") + .isNotNull(); + assertThat(deserialized) + .describedAs("deserialized model is not a classifier feature transformer") + .isInstanceOf(ClassifierFeatureTransformer.class); } @Test @@ -74,19 +88,23 @@ public void testVarcharClassifierAdapter() model.train(getDataset()); Slice serialized = ModelUtils.serialize(model); Model deserialized = ModelUtils.deserialize(serialized); - assertNotNull(deserialized, "deserialization failed"); - assertTrue(deserialized instanceof StringClassifierAdapter, "deserialized model is not a varchar classifier adapter"); + assertThat(deserialized) + .describedAs("deserialization failed") + .isNotNull(); + assertThat(deserialized) + .describedAs("deserialized model is not a varchar classifier adapter") + .isInstanceOf(StringClassifierAdapter.class); } @Test public void testSerializationIds() { - assertEquals((int) ModelUtils.MODEL_SERIALIZATION_IDS.get(SvmClassifier.class), 1); - assertEquals((int) ModelUtils.MODEL_SERIALIZATION_IDS.get(SvmRegressor.class), 2); - assertEquals((int) ModelUtils.MODEL_SERIALIZATION_IDS.get(FeatureVectorUnitNormalizer.class), 3); - assertEquals((int) ModelUtils.MODEL_SERIALIZATION_IDS.get(ClassifierFeatureTransformer.class), 4); - assertEquals((int) ModelUtils.MODEL_SERIALIZATION_IDS.get(RegressorFeatureTransformer.class), 5); - assertEquals((int) ModelUtils.MODEL_SERIALIZATION_IDS.get(FeatureUnitNormalizer.class), 6); - assertEquals((int) ModelUtils.MODEL_SERIALIZATION_IDS.get(StringClassifierAdapter.class), 7); + assertThat((int) ModelUtils.MODEL_SERIALIZATION_IDS.get(SvmClassifier.class)).isEqualTo(1); + assertThat((int) ModelUtils.MODEL_SERIALIZATION_IDS.get(SvmRegressor.class)).isEqualTo(2); + assertThat((int) ModelUtils.MODEL_SERIALIZATION_IDS.get(FeatureVectorUnitNormalizer.class)).isEqualTo(3); + assertThat((int) ModelUtils.MODEL_SERIALIZATION_IDS.get(ClassifierFeatureTransformer.class)).isEqualTo(4); + assertThat((int) ModelUtils.MODEL_SERIALIZATION_IDS.get(RegressorFeatureTransformer.class)).isEqualTo(5); + assertThat((int) ModelUtils.MODEL_SERIALIZATION_IDS.get(FeatureUnitNormalizer.class)).isEqualTo(6); + assertThat((int) ModelUtils.MODEL_SERIALIZATION_IDS.get(StringClassifierAdapter.class)).isEqualTo(7); } } diff --git a/plugin/trino-redis/pom.xml b/plugin/trino-redis/pom.xml index 0a1661d26ab3..d9bae3b10c80 100644 --- a/plugin/trino-redis/pom.xml +++ b/plugin/trino-redis/pom.xml @@ -193,6 +193,12 @@ test + + org.junit.jupiter + junit-jupiter-api + test + + org.testcontainers testcontainers diff --git a/plugin/trino-redis/src/test/java/io/trino/plugin/redis/AbstractTestMinimalFunctionality.java b/plugin/trino-redis/src/test/java/io/trino/plugin/redis/AbstractTestMinimalFunctionality.java index 140e20fea29c..d20b74b9eed0 100644 --- a/plugin/trino-redis/src/test/java/io/trino/plugin/redis/AbstractTestMinimalFunctionality.java +++ b/plugin/trino-redis/src/test/java/io/trino/plugin/redis/AbstractTestMinimalFunctionality.java @@ -20,9 +20,9 @@ import io.trino.spi.connector.SchemaTableName; import io.trino.sql.query.QueryAssertions; import io.trino.testing.StandaloneQueryRunner; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; import redis.clients.jedis.Jedis; import java.util.Map; @@ -32,8 +32,9 @@ import static io.trino.plugin.redis.util.RedisTestUtils.installRedisPlugin; import static io.trino.plugin.redis.util.RedisTestUtils.loadSimpleTableDescription; import static io.trino.testing.TestingSession.testSessionBuilder; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; -@Test(singleThreaded = true) +@TestInstance(PER_CLASS) public abstract class AbstractTestMinimalFunctionality { protected static final Session SESSION = testSessionBuilder() @@ -50,7 +51,7 @@ public abstract class AbstractTestMinimalFunctionality protected abstract Map connectorProperties(); - @BeforeClass + @BeforeAll public void startRedis() throws Exception { @@ -76,7 +77,7 @@ public void startRedis() populateData(1000); } - @AfterClass(alwaysRun = true) + @AfterAll public void stopRedis() { clearData(); diff --git a/plugin/trino-redis/src/test/java/io/trino/plugin/redis/TestMinimalFunctionality.java b/plugin/trino-redis/src/test/java/io/trino/plugin/redis/TestMinimalFunctionality.java index 0d28825e9443..9545e4bac910 100644 --- a/plugin/trino-redis/src/test/java/io/trino/plugin/redis/TestMinimalFunctionality.java +++ b/plugin/trino-redis/src/test/java/io/trino/plugin/redis/TestMinimalFunctionality.java @@ -17,7 +17,7 @@ import io.trino.metadata.QualifiedObjectName; import io.trino.metadata.TableHandle; import io.trino.security.AllowAllAccessControl; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.Map; import java.util.Optional; @@ -27,7 +27,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.testng.Assert.assertTrue; -@Test(singleThreaded = true) public class TestMinimalFunctionality extends AbstractTestMinimalFunctionality { diff --git a/plugin/trino-redis/src/test/java/io/trino/plugin/redis/TestMinimalFunctionalityWithoutKeyPrefix.java b/plugin/trino-redis/src/test/java/io/trino/plugin/redis/TestMinimalFunctionalityWithoutKeyPrefix.java index d6297e694947..72ecdcfab6b4 100644 --- a/plugin/trino-redis/src/test/java/io/trino/plugin/redis/TestMinimalFunctionalityWithoutKeyPrefix.java +++ b/plugin/trino-redis/src/test/java/io/trino/plugin/redis/TestMinimalFunctionalityWithoutKeyPrefix.java @@ -14,7 +14,7 @@ package io.trino.plugin.redis; import com.google.common.collect.ImmutableMap; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.Map; @@ -22,7 +22,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -@Test(singleThreaded = true) public class TestMinimalFunctionalityWithoutKeyPrefix extends AbstractTestMinimalFunctionality { diff --git a/plugin/trino-redis/src/test/java/io/trino/plugin/redis/TestRedisConnectorConfig.java b/plugin/trino-redis/src/test/java/io/trino/plugin/redis/TestRedisConnectorConfig.java index 57703516c73b..15b3d22183b2 100644 --- a/plugin/trino-redis/src/test/java/io/trino/plugin/redis/TestRedisConnectorConfig.java +++ b/plugin/trino-redis/src/test/java/io/trino/plugin/redis/TestRedisConnectorConfig.java @@ -15,7 +15,7 @@ import com.google.common.collect.ImmutableMap; import io.airlift.units.Duration; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.Map; diff --git a/plugin/trino-redis/src/test/java/io/trino/plugin/redis/TestRedisDistributedHash.java b/plugin/trino-redis/src/test/java/io/trino/plugin/redis/TestRedisDistributedHash.java index 85b3adee745a..588fdb156197 100644 --- a/plugin/trino-redis/src/test/java/io/trino/plugin/redis/TestRedisDistributedHash.java +++ b/plugin/trino-redis/src/test/java/io/trino/plugin/redis/TestRedisDistributedHash.java @@ -18,7 +18,7 @@ import io.trino.sql.planner.plan.FilterNode; import io.trino.testing.AbstractTestQueries; import io.trino.testing.QueryRunner; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.trino.plugin.redis.RedisQueryRunner.createRedisQueryRunner; import static org.assertj.core.api.Assertions.assertThat; diff --git a/plugin/trino-redis/src/test/java/io/trino/plugin/redis/TestRedisPlugin.java b/plugin/trino-redis/src/test/java/io/trino/plugin/redis/TestRedisPlugin.java index 1d09a94026a3..1ca0df8aac7b 100644 --- a/plugin/trino-redis/src/test/java/io/trino/plugin/redis/TestRedisPlugin.java +++ b/plugin/trino-redis/src/test/java/io/trino/plugin/redis/TestRedisPlugin.java @@ -17,7 +17,7 @@ import io.trino.spi.connector.Connector; import io.trino.spi.connector.ConnectorFactory; import io.trino.testing.TestingConnectorContext; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static com.google.common.collect.Iterables.getOnlyElement; import static io.airlift.testing.Assertions.assertInstanceOf; diff --git a/service/trino-proxy/pom.xml b/service/trino-proxy/pom.xml index f900281479e6..27922f0337fd 100644 --- a/service/trino-proxy/pom.xml +++ b/service/trino-proxy/pom.xml @@ -195,8 +195,8 @@ - org.testng - testng + org.junit.jupiter + junit-jupiter-api test diff --git a/service/trino-proxy/src/test/java/io/trino/proxy/TestJwtHandlerConfig.java b/service/trino-proxy/src/test/java/io/trino/proxy/TestJwtHandlerConfig.java index 1e46f5263cb8..194d4de9a8fa 100644 --- a/service/trino-proxy/src/test/java/io/trino/proxy/TestJwtHandlerConfig.java +++ b/service/trino-proxy/src/test/java/io/trino/proxy/TestJwtHandlerConfig.java @@ -14,7 +14,7 @@ package io.trino.proxy; import com.google.common.collect.ImmutableMap; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.file.Files; diff --git a/service/trino-proxy/src/test/java/io/trino/proxy/TestProxyConfig.java b/service/trino-proxy/src/test/java/io/trino/proxy/TestProxyConfig.java index 61b91223ce65..1166e9791854 100644 --- a/service/trino-proxy/src/test/java/io/trino/proxy/TestProxyConfig.java +++ b/service/trino-proxy/src/test/java/io/trino/proxy/TestProxyConfig.java @@ -14,7 +14,7 @@ package io.trino.proxy; import com.google.common.collect.ImmutableMap; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.net.URI; diff --git a/service/trino-proxy/src/test/java/io/trino/proxy/TestProxyServer.java b/service/trino-proxy/src/test/java/io/trino/proxy/TestProxyServer.java index 565569883684..1c179d875f70 100644 --- a/service/trino-proxy/src/test/java/io/trino/proxy/TestProxyServer.java +++ b/service/trino-proxy/src/test/java/io/trino/proxy/TestProxyServer.java @@ -29,9 +29,11 @@ import io.trino.plugin.blackhole.BlackHolePlugin; import io.trino.plugin.tpch.TpchPlugin; import io.trino.server.testing.TestingTrinoServer; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.Timeout; import java.io.IOException; import java.net.URI; @@ -56,11 +58,9 @@ import static java.util.concurrent.Executors.newCachedThreadPool; import static java.util.concurrent.TimeUnit.SECONDS; import static org.assertj.core.api.Assertions.assertThat; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; +@TestInstance(PER_CLASS) public class TestProxyServer { private Path sharedSecretFile; @@ -69,7 +69,7 @@ public class TestProxyServer private HttpServerInfo httpServerInfo; private ExecutorService executorService; - @BeforeClass + @BeforeAll public void setupServer() throws Exception { @@ -108,7 +108,7 @@ public void setupServer() setupTestTable(); } - @AfterClass(alwaysRun = true) + @AfterAll public void tearDownServer() throws IOException { @@ -125,7 +125,7 @@ public void testMetadata() throws Exception { try (Connection connection = createConnection()) { - assertEquals(connection.getMetaData().getDatabaseProductVersion(), "testversion"); + assertThat(connection.getMetaData().getDatabaseProductVersion()).isEqualTo("testversion"); } } @@ -142,8 +142,8 @@ public void testQuery() count++; sum += rs.getLong("n"); } - assertEquals(count, 15000); - assertEquals(sum, (count / 2) * (1 + count)); + assertThat(count).isEqualTo(15000); + assertThat(sum).isEqualTo((count / 2) * (1 + count)); } } @@ -167,7 +167,8 @@ public void testSetSession() } } - @Test(timeOut = 10_000) + @Test + @Timeout(10) public void testCancel() throws Exception { @@ -195,20 +196,21 @@ public void testCancel() // start query and make sure it is not finished queryStarted.await(10, SECONDS); - assertNotNull(queryId.get()); - assertFalse(getQueryState(queryId.get()).isDone()); + assertThat(queryId.get()).isNotNull(); + assertThat(getQueryState(queryId.get()).isDone()).isFalse(); // cancel the query from this test thread statement.cancel(); // make sure the query was aborted queryFinished.await(10, SECONDS); - assertNotNull(queryFailure.get()); - assertEquals(getQueryState(queryId.get()), FAILED); + assertThat(queryFailure.get()).isNotNull(); + assertThat(getQueryState(queryId.get())).isEqualTo(FAILED); } } - @Test(timeOut = 10_000) + @Test + @Timeout(10) public void testPartialCancel() throws Exception { @@ -216,8 +218,8 @@ public void testPartialCancel() Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery("SELECT count(*) FROM blackhole.test.slow")) { statement.unwrap(TrinoStatement.class).partialCancel(); - assertTrue(resultSet.next()); - assertEquals(resultSet.getLong(1), 0); + assertThat(resultSet.next()).isTrue(); + assertThat(resultSet.getLong(1)).isEqualTo(0); } } @@ -228,7 +230,9 @@ private QueryState getQueryState(String queryId) try (Connection connection = createConnection(); Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery(sql)) { - assertTrue(rs.next(), "query not found"); + assertThat(rs.next()) + .describedAs("query not found") + .isTrue(); return QueryState.valueOf(rs.getString("state")); } } @@ -238,14 +242,15 @@ private void setupTestTable() { try (Connection connection = createConnection(); Statement statement = connection.createStatement()) { - assertEquals(statement.executeUpdate("CREATE SCHEMA blackhole.test"), 0); - assertEquals(statement.executeUpdate("CREATE TABLE blackhole.test.slow (x bigint) " + + assertThat(statement.executeUpdate("CREATE SCHEMA blackhole.test")).isEqualTo(0); + assertThat(statement.executeUpdate("CREATE TABLE blackhole.test.slow (x bigint) " + "WITH (" + " split_count = 1, " + " pages_per_split = 1, " + " rows_per_page = 1, " + " page_processing_delay = '1m'" + - ")"), 0); + ")")) + .isEqualTo(0); } } diff --git a/service/trino-verifier/pom.xml b/service/trino-verifier/pom.xml index 01093c9e5672..82b61b75410f 100644 --- a/service/trino-verifier/pom.xml +++ b/service/trino-verifier/pom.xml @@ -142,14 +142,20 @@ - org.testcontainers - mysql + org.assertj + assertj-core + test + + + + org.junit.jupiter + junit-jupiter-api test - org.testng - testng + org.testcontainers + mysql test diff --git a/service/trino-verifier/src/test/java/io/trino/verifier/TestDatabaseEventClient.java b/service/trino-verifier/src/test/java/io/trino/verifier/TestDatabaseEventClient.java index 9eca4f8cada9..be4875b7f8b4 100644 --- a/service/trino-verifier/src/test/java/io/trino/verifier/TestDatabaseEventClient.java +++ b/service/trino-verifier/src/test/java/io/trino/verifier/TestDatabaseEventClient.java @@ -17,10 +17,11 @@ import io.airlift.json.JsonCodecFactory; import org.jdbi.v3.core.Jdbi; import org.jdbi.v3.sqlobject.SqlObjectPlugin; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import org.testcontainers.containers.MySQLContainer; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; import java.sql.Connection; import java.sql.DriverManager; @@ -30,11 +31,10 @@ import java.util.List; import static java.lang.String.format; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; +@TestInstance(PER_CLASS) public class TestDatabaseEventClient { private static final VerifierQueryEvent FULL_EVENT = new VerifierQueryEvent( @@ -98,7 +98,7 @@ public class TestDatabaseEventClient private JsonCodec> codec; private DatabaseEventClient eventClient; - @BeforeClass + @BeforeAll public void setup() { mysqlContainer = new MySQLContainer<>("mysql:8.0.30"); @@ -120,7 +120,7 @@ private static String getJdbcUrl(MySQLContainer container) container.getPassword()); } - @AfterClass(alwaysRun = true) + @AfterAll public void teardown() { if (mysqlContainer != null) { @@ -142,28 +142,28 @@ public void testFull() try (Statement statement = connection.createStatement()) { statement.execute("SELECT * FROM verifier_query_events WHERE suite = 'suite_full'"); try (ResultSet resultSet = statement.getResultSet()) { - assertTrue(resultSet.next()); - assertEquals(resultSet.getString("suite"), "suite_full"); - assertEquals(resultSet.getString("run_id"), "runid"); - assertEquals(resultSet.getString("source"), "source"); - assertEquals(resultSet.getString("name"), "name"); - assertTrue(resultSet.getBoolean("failed")); - assertEquals(resultSet.getString("test_catalog"), "testcatalog"); - assertEquals(resultSet.getString("test_schema"), "testschema"); - assertEquals(resultSet.getString("test_setup_query_ids_json"), codec.toJson(FULL_EVENT.getTestSetupQueryIds())); - assertEquals(resultSet.getString("test_query_id"), "TEST_QUERY_ID"); - assertEquals(resultSet.getString("test_teardown_query_ids_json"), codec.toJson(FULL_EVENT.getTestTeardownQueryIds())); - assertEquals(resultSet.getDouble("test_cpu_time_seconds"), 1.1); - assertEquals(resultSet.getDouble("test_wall_time_seconds"), 2.2); - assertEquals(resultSet.getString("control_catalog"), "controlcatalog"); - assertEquals(resultSet.getString("control_schema"), "controlschema"); - assertEquals(resultSet.getString("control_setup_query_ids_json"), codec.toJson(FULL_EVENT.getControlSetupQueryIds())); - assertEquals(resultSet.getString("control_query_id"), "CONTROL_QUERY_ID"); - assertEquals(resultSet.getString("control_teardown_query_ids_json"), codec.toJson(FULL_EVENT.getControlTeardownQueryIds())); - assertEquals(resultSet.getDouble("control_cpu_time_seconds"), 3.3); - assertEquals(resultSet.getDouble("control_wall_time_seconds"), 4.4); - assertEquals(resultSet.getString("error_message"), "error message"); - assertFalse(resultSet.next()); + assertThat(resultSet.next()).isTrue(); + assertThat(resultSet.getString("suite")).isEqualTo("suite_full"); + assertThat(resultSet.getString("run_id")).isEqualTo("runid"); + assertThat(resultSet.getString("source")).isEqualTo("source"); + assertThat(resultSet.getString("name")).isEqualTo("name"); + assertThat(resultSet.getBoolean("failed")).isTrue(); + assertThat(resultSet.getString("test_catalog")).isEqualTo("testcatalog"); + assertThat(resultSet.getString("test_schema")).isEqualTo("testschema"); + assertThat(resultSet.getString("test_setup_query_ids_json")).isEqualTo(codec.toJson(FULL_EVENT.getTestSetupQueryIds())); + assertThat(resultSet.getString("test_query_id")).isEqualTo("TEST_QUERY_ID"); + assertThat(resultSet.getString("test_teardown_query_ids_json")).isEqualTo(codec.toJson(FULL_EVENT.getTestTeardownQueryIds())); + assertThat(resultSet.getDouble("test_cpu_time_seconds")).isEqualTo(1.1); + assertThat(resultSet.getDouble("test_wall_time_seconds")).isEqualTo(2.2); + assertThat(resultSet.getString("control_catalog")).isEqualTo("controlcatalog"); + assertThat(resultSet.getString("control_schema")).isEqualTo("controlschema"); + assertThat(resultSet.getString("control_setup_query_ids_json")).isEqualTo(codec.toJson(FULL_EVENT.getControlSetupQueryIds())); + assertThat(resultSet.getString("control_query_id")).isEqualTo("CONTROL_QUERY_ID"); + assertThat(resultSet.getString("control_teardown_query_ids_json")).isEqualTo(codec.toJson(FULL_EVENT.getControlTeardownQueryIds())); + assertThat(resultSet.getDouble("control_cpu_time_seconds")).isEqualTo(3.3); + assertThat(resultSet.getDouble("control_wall_time_seconds")).isEqualTo(4.4); + assertThat(resultSet.getString("error_message")).isEqualTo("error message"); + assertThat(resultSet.next()).isFalse(); } } } @@ -179,28 +179,28 @@ public void testMinimal() try (Statement statement = connection.createStatement()) { statement.execute("SELECT * FROM verifier_query_events WHERE suite = 'suite_minimal'"); try (ResultSet resultSet = statement.getResultSet()) { - assertTrue(resultSet.next()); - assertEquals(resultSet.getString("suite"), "suite_minimal"); - assertNull(resultSet.getString("run_id")); - assertNull(resultSet.getString("source")); - assertNull(resultSet.getString("name")); - assertFalse(resultSet.getBoolean("failed")); - assertNull(resultSet.getString("test_catalog")); - assertNull(resultSet.getString("test_schema")); - assertNull(resultSet.getString("test_setup_query_ids_json")); - assertNull(resultSet.getString("test_query_id")); - assertNull(resultSet.getString("test_teardown_query_ids_json")); - assertNull(resultSet.getObject("test_cpu_time_seconds")); - assertNull(resultSet.getObject("test_wall_time_seconds")); - assertNull(resultSet.getString("control_catalog")); - assertNull(resultSet.getString("control_schema")); - assertNull(resultSet.getString("control_setup_query_ids_json")); - assertNull(resultSet.getString("control_query_id")); - assertNull(resultSet.getString("control_teardown_query_ids_json")); - assertNull(resultSet.getObject("control_cpu_time_seconds")); - assertNull(resultSet.getObject("control_wall_time_seconds")); - assertNull(resultSet.getString("error_message")); - assertFalse(resultSet.next()); + assertThat(resultSet.next()).isTrue(); + assertThat(resultSet.getString("suite")).isEqualTo("suite_minimal"); + assertThat(resultSet.getString("run_id")).isNull(); + assertThat(resultSet.getString("source")).isNull(); + assertThat(resultSet.getString("name")).isNull(); + assertThat(resultSet.getBoolean("failed")).isFalse(); + assertThat(resultSet.getString("test_catalog")).isNull(); + assertThat(resultSet.getString("test_schema")).isNull(); + assertThat(resultSet.getString("test_setup_query_ids_json")).isNull(); + assertThat(resultSet.getString("test_query_id")).isNull(); + assertThat(resultSet.getString("test_teardown_query_ids_json")).isNull(); + assertThat(resultSet.getObject("test_cpu_time_seconds")).isNull(); + assertThat(resultSet.getObject("test_wall_time_seconds")).isNull(); + assertThat(resultSet.getString("control_catalog")).isNull(); + assertThat(resultSet.getString("control_schema")).isNull(); + assertThat(resultSet.getString("control_setup_query_ids_json")).isNull(); + assertThat(resultSet.getString("control_query_id")).isNull(); + assertThat(resultSet.getString("control_teardown_query_ids_json")).isNull(); + assertThat(resultSet.getObject("control_cpu_time_seconds")).isNull(); + assertThat(resultSet.getObject("control_wall_time_seconds")).isNull(); + assertThat(resultSet.getString("error_message")).isNull(); + assertThat(resultSet.next()).isFalse(); } } } diff --git a/service/trino-verifier/src/test/java/io/trino/verifier/TestShadowing.java b/service/trino-verifier/src/test/java/io/trino/verifier/TestShadowing.java index 9ccca009fb2a..47fdcb4a4b86 100644 --- a/service/trino-verifier/src/test/java/io/trino/verifier/TestShadowing.java +++ b/service/trino-verifier/src/test/java/io/trino/verifier/TestShadowing.java @@ -29,8 +29,9 @@ import io.trino.sql.tree.Table; import org.jdbi.v3.core.Handle; import org.jdbi.v3.core.Jdbi; -import org.testng.annotations.AfterClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import java.util.Optional; @@ -40,10 +41,10 @@ import static io.trino.verifier.QueryType.READ; import static io.trino.verifier.VerifyCommand.statementToQueryType; import static java.util.concurrent.TimeUnit.SECONDS; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; +@TestInstance(PER_CLASS) public class TestShadowing { private static final String CATALOG = "TEST_REWRITE"; @@ -57,7 +58,7 @@ public TestShadowing() handle = Jdbi.open(URL); } - @AfterClass(alwaysRun = true) + @AfterAll public void close() { handle.close(); @@ -72,22 +73,22 @@ public void testCreateTableAsSelect() Query query = new Query(CATALOG, SCHEMA, ImmutableList.of(), "CREATE TABLE my_test_table AS SELECT 1 column1, CAST('2.0' AS DOUBLE) column2 LIMIT 1", ImmutableList.of(), null, null, ImmutableMap.of()); QueryRewriter rewriter = new QueryRewriter(parser, URL, QualifiedName.of("tmp_"), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), 1, new Duration(10, SECONDS)); Query rewrittenQuery = rewriter.shadowQuery(query); - assertEquals(rewrittenQuery.getPreQueries().size(), 1); - assertEquals(rewrittenQuery.getPostQueries().size(), 1); + assertThat(rewrittenQuery.getPreQueries().size()).isEqualTo(1); + assertThat(rewrittenQuery.getPostQueries().size()).isEqualTo(1); CreateTableAsSelect createTableAs = (CreateTableAsSelect) parser.createStatement(rewrittenQuery.getPreQueries().get(0)); - assertEquals(createTableAs.getName().getParts().size(), 1); - assertTrue(createTableAs.getName().getSuffix().startsWith("tmp_")); - assertFalse(createTableAs.getName().getSuffix().contains("my_test_table")); + assertThat(createTableAs.getName().getParts().size()).isEqualTo(1); + assertThat(createTableAs.getName().getSuffix().startsWith("tmp_")).isTrue(); + assertThat(createTableAs.getName().getSuffix().contains("my_test_table")).isFalse(); - assertEquals(statementToQueryType(parser, rewrittenQuery.getQuery()), READ); + assertThat(statementToQueryType(parser, rewrittenQuery.getQuery())).isEqualTo(READ); Table table = new Table(createTableAs.getName()); SingleColumn column1 = new SingleColumn(new FunctionCall(QualifiedName.of("checksum"), ImmutableList.of(new Identifier("COLUMN1")))); SingleColumn column2 = new SingleColumn(new FunctionCall(QualifiedName.of("checksum"), ImmutableList.of(new FunctionCall(QualifiedName.of("round"), ImmutableList.of(new Identifier("COLUMN2"), new LongLiteral("1")))))); - assertEquals(parser.createStatement(rewrittenQuery.getQuery()), simpleQuery(selectList(column1, column2), table)); + assertThat(parser.createStatement(rewrittenQuery.getQuery())).isEqualTo(simpleQuery(selectList(column1, column2), table)); - assertEquals(parser.createStatement(rewrittenQuery.getPostQueries().get(0)), new DropTable(createTableAs.getName(), true)); + assertThat(parser.createStatement(rewrittenQuery.getPostQueries().get(0))).isEqualTo(new DropTable(createTableAs.getName(), true)); } @Test @@ -99,12 +100,12 @@ public void testCreateTableAsSelectDifferentCatalog() Query query = new Query(CATALOG, SCHEMA, ImmutableList.of(), "CREATE TABLE public.my_test_table2 AS SELECT 1 column1, 2E0 column2", ImmutableList.of(), null, null, ImmutableMap.of()); QueryRewriter rewriter = new QueryRewriter(parser, URL, QualifiedName.of("other_catalog", "other_schema", "tmp_"), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), 1, new Duration(10, SECONDS)); Query rewrittenQuery = rewriter.shadowQuery(query); - assertEquals(rewrittenQuery.getPreQueries().size(), 1); + assertThat(rewrittenQuery.getPreQueries().size()).isEqualTo(1); CreateTableAsSelect createTableAs = (CreateTableAsSelect) parser.createStatement(rewrittenQuery.getPreQueries().get(0)); - assertEquals(createTableAs.getName().getParts().size(), 3); - assertEquals(createTableAs.getName().getPrefix().get(), QualifiedName.of("other_catalog", "other_schema")); - assertTrue(createTableAs.getName().getSuffix().startsWith("tmp_")); - assertFalse(createTableAs.getName().getSuffix().contains("my_test_table")); + assertThat(createTableAs.getName().getParts().size()).isEqualTo(3); + assertThat(createTableAs.getName().getPrefix().get()).isEqualTo(QualifiedName.of("other_catalog", "other_schema")); + assertThat(createTableAs.getName().getSuffix().startsWith("tmp_")).isTrue(); + assertThat(createTableAs.getName().getSuffix().contains("my_test_table")).isFalse(); } @Test @@ -117,24 +118,24 @@ public void testInsert() QueryRewriter rewriter = new QueryRewriter(parser, URL, QualifiedName.of("other_catalog", "other_schema", "tmp_"), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), 1, new Duration(10, SECONDS)); Query rewrittenQuery = rewriter.shadowQuery(query); - assertEquals(rewrittenQuery.getPreQueries().size(), 2); + assertThat(rewrittenQuery.getPreQueries().size()).isEqualTo(2); CreateTable createTable = (CreateTable) parser.createStatement(rewrittenQuery.getPreQueries().get(0)); - assertEquals(createTable.getName().getParts().size(), 3); - assertEquals(createTable.getName().getPrefix().get(), QualifiedName.of("other_catalog", "other_schema")); - assertTrue(createTable.getName().getSuffix().startsWith("tmp_")); - assertFalse(createTable.getName().getSuffix().contains("test_insert_table")); + assertThat(createTable.getName().getParts().size()).isEqualTo(3); + assertThat(createTable.getName().getPrefix().get()).isEqualTo(QualifiedName.of("other_catalog", "other_schema")); + assertThat(createTable.getName().getSuffix().startsWith("tmp_")).isTrue(); + assertThat(createTable.getName().getSuffix().contains("test_insert_table")).isFalse(); Insert insert = (Insert) parser.createStatement(rewrittenQuery.getPreQueries().get(1)); - assertEquals(insert.getTarget(), createTable.getName()); - assertEquals(insert.getColumns(), Optional.of(ImmutableList.of(identifier("b"), identifier("a"), identifier("c")))); + assertThat(insert.getTarget()).isEqualTo(createTable.getName()); + assertThat(insert.getColumns()).isEqualTo(Optional.of(ImmutableList.of(identifier("b"), identifier("a"), identifier("c")))); Table table = new Table(createTable.getName()); SingleColumn columnA = new SingleColumn(new FunctionCall(QualifiedName.of("checksum"), ImmutableList.of(new Identifier("A")))); SingleColumn columnB = new SingleColumn(new FunctionCall(QualifiedName.of("checksum"), ImmutableList.of(new FunctionCall(QualifiedName.of("round"), ImmutableList.of(new Identifier("B"), new LongLiteral("1")))))); SingleColumn columnC = new SingleColumn(new FunctionCall(QualifiedName.of("checksum"), ImmutableList.of(new Identifier("C")))); - assertEquals(parser.createStatement(rewrittenQuery.getQuery()), simpleQuery(selectList(columnA, columnB, columnC), table)); + assertThat(parser.createStatement(rewrittenQuery.getQuery())).isEqualTo(simpleQuery(selectList(columnA, columnB, columnC), table)); - assertEquals(rewrittenQuery.getPostQueries().size(), 1); - assertEquals(parser.createStatement(rewrittenQuery.getPostQueries().get(0)), new DropTable(createTable.getName(), true)); + assertThat(rewrittenQuery.getPostQueries().size()).isEqualTo(1); + assertThat(parser.createStatement(rewrittenQuery.getPostQueries().get(0))).isEqualTo(new DropTable(createTable.getName(), true)); } } diff --git a/service/trino-verifier/src/test/java/io/trino/verifier/TestValidator.java b/service/trino-verifier/src/test/java/io/trino/verifier/TestValidator.java index 4d146925745f..ae5b844b2c67 100644 --- a/service/trino-verifier/src/test/java/io/trino/verifier/TestValidator.java +++ b/service/trino-verifier/src/test/java/io/trino/verifier/TestValidator.java @@ -13,25 +13,25 @@ */ package io.trino.verifier; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.trino.verifier.Validator.precisionCompare; import static java.lang.Double.NaN; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestValidator { @Test public void testDoubleComparison() { - assertEquals(precisionCompare(0.9045, 0.9045000000000001, 3), 0); - assertEquals(precisionCompare(0.9045, 0.9045000000000001, 2), 0); - assertEquals(precisionCompare(0.9041, 0.9042, 3), 0); - assertEquals(precisionCompare(0.9041, 0.9042, 4), 0); - assertEquals(precisionCompare(0.9042, 0.9041, 4), 0); - assertEquals(precisionCompare(-0.9042, -0.9041, 4), 0); - assertEquals(precisionCompare(-0.9042, -0.9041, 3), 0); - assertEquals(precisionCompare(0.899, 0.901, 3), 0); - assertEquals(precisionCompare(NaN, NaN, 4), Double.compare(NaN, NaN)); + assertThat(precisionCompare(0.9045, 0.9045000000000001, 3)).isEqualTo(0); + assertThat(precisionCompare(0.9045, 0.9045000000000001, 2)).isEqualTo(0); + assertThat(precisionCompare(0.9041, 0.9042, 3)).isEqualTo(0); + assertThat(precisionCompare(0.9041, 0.9042, 4)).isEqualTo(0); + assertThat(precisionCompare(0.9042, 0.9041, 4)).isEqualTo(0); + assertThat(precisionCompare(-0.9042, -0.9041, 4)).isEqualTo(0); + assertThat(precisionCompare(-0.9042, -0.9041, 3)).isEqualTo(0); + assertThat(precisionCompare(0.899, 0.901, 3)).isEqualTo(0); + assertThat(precisionCompare(NaN, NaN, 4)).isEqualTo(Double.compare(NaN, NaN)); } } diff --git a/service/trino-verifier/src/test/java/io/trino/verifier/TestVerifierConfig.java b/service/trino-verifier/src/test/java/io/trino/verifier/TestVerifierConfig.java index ddda7a582666..89e7afedd7bc 100644 --- a/service/trino-verifier/src/test/java/io/trino/verifier/TestVerifierConfig.java +++ b/service/trino-verifier/src/test/java/io/trino/verifier/TestVerifierConfig.java @@ -17,7 +17,7 @@ import com.google.common.collect.ImmutableMap; import io.airlift.units.Duration; import org.joda.time.DateTime; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.Map; import java.util.concurrent.TimeUnit; diff --git a/service/trino-verifier/src/test/java/io/trino/verifier/TestVerifierRewriteQueries.java b/service/trino-verifier/src/test/java/io/trino/verifier/TestVerifierRewriteQueries.java index f1e093d11e74..0c2bb1542f04 100644 --- a/service/trino-verifier/src/test/java/io/trino/verifier/TestVerifierRewriteQueries.java +++ b/service/trino-verifier/src/test/java/io/trino/verifier/TestVerifierRewriteQueries.java @@ -19,16 +19,18 @@ import io.trino.sql.parser.SqlParser; import org.jdbi.v3.core.Handle; import org.jdbi.v3.core.Jdbi; -import org.testng.annotations.AfterClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import java.util.List; import java.util.concurrent.TimeUnit; import static io.trino.verifier.VerifyCommand.rewriteQueries; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; -@Test(singleThreaded = true) +@TestInstance(PER_CLASS) public class TestVerifierRewriteQueries { private static final String CATALOG = "TEST_VERIFIER_REWRITE_QUERIES"; @@ -83,7 +85,7 @@ public TestVerifierRewriteQueries() queryPairs = builder.build(); } - @AfterClass(alwaysRun = true) + @AfterAll public void close() { handle.close(); @@ -95,7 +97,7 @@ public void testSingleThread() config.setControlGateway(URL); config.setThreadCount(1); List rewrittenQueries = rewriteQueries(parser, config, queryPairs); - assertEquals(rewrittenQueries.size(), queryPairs.size()); + assertThat(rewrittenQueries.size()).isEqualTo(queryPairs.size()); } @Test @@ -104,7 +106,7 @@ public void testMultipleThreads() config.setControlGateway(URL); config.setThreadCount(5); List rewrittenQueries = rewriteQueries(parser, config, queryPairs); - assertEquals(rewrittenQueries.size(), queryPairs.size()); + assertThat(rewrittenQueries.size()).isEqualTo(queryPairs.size()); } @Test @@ -124,7 +126,7 @@ public void testQueryRewriteException() .addAll(queryPairs) .add(new QueryPair(QUERY_SUITE, QUERY_NAME, invalidQuery, invalidQuery)) .build()); - assertEquals(rewrittenQueries.size(), queryPairs.size()); + assertThat(rewrittenQueries.size()).isEqualTo(queryPairs.size()); } @Test @@ -132,6 +134,6 @@ public void testSQLException() { config.setControlGateway("invalid:url"); List rewrittenQueries = rewriteQueries(parser, config, queryPairs); - assertEquals(rewrittenQueries.size(), 0); + assertThat(rewrittenQueries.size()).isEqualTo(0); } } diff --git a/testing/trino-benchmark-queries/pom.xml b/testing/trino-benchmark-queries/pom.xml index f8825e9c7077..c4ae35b8c599 100644 --- a/testing/trino-benchmark-queries/pom.xml +++ b/testing/trino-benchmark-queries/pom.xml @@ -16,8 +16,8 @@ - org.testng - testng + org.junit.jupiter + junit-jupiter-api test diff --git a/testing/trino-benchmark-queries/src/test/java/io/trino/benchmark/queries/TestDummy.java b/testing/trino-benchmark-queries/src/test/java/io/trino/benchmark/queries/TestDummy.java index 7a74cf01fc90..2dc18a4a44c9 100644 --- a/testing/trino-benchmark-queries/src/test/java/io/trino/benchmark/queries/TestDummy.java +++ b/testing/trino-benchmark-queries/src/test/java/io/trino/benchmark/queries/TestDummy.java @@ -13,7 +13,7 @@ */ package io.trino.benchmark.queries; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; public class TestDummy { diff --git a/testing/trino-benchmark/pom.xml b/testing/trino-benchmark/pom.xml index 05c8de2550c2..e2a6c38d7d5f 100644 --- a/testing/trino-benchmark/pom.xml +++ b/testing/trino-benchmark/pom.xml @@ -123,20 +123,20 @@ - org.openjdk.jmh - jmh-core + org.junit.jupiter + junit-jupiter-api test org.openjdk.jmh - jmh-generator-annprocess + jmh-core test - org.testng - testng + org.openjdk.jmh + jmh-generator-annprocess test diff --git a/testing/trino-benchmark/src/test/java/io/trino/benchmark/BenchmarkInequalityJoin.java b/testing/trino-benchmark/src/test/java/io/trino/benchmark/BenchmarkInequalityJoin.java index a877305dc3ad..1b79e398ac36 100644 --- a/testing/trino-benchmark/src/test/java/io/trino/benchmark/BenchmarkInequalityJoin.java +++ b/testing/trino-benchmark/src/test/java/io/trino/benchmark/BenchmarkInequalityJoin.java @@ -14,6 +14,7 @@ package io.trino.benchmark; import io.trino.spi.Page; +import org.junit.jupiter.api.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; @@ -25,7 +26,6 @@ import org.openjdk.jmh.annotations.TearDown; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.runner.RunnerException; -import org.testng.annotations.Test; import java.util.List; diff --git a/testing/trino-benchmark/src/test/java/io/trino/benchmark/TestBenchmarks.java b/testing/trino-benchmark/src/test/java/io/trino/benchmark/TestBenchmarks.java index 1d61d6c08080..23ba20f9d5a2 100644 --- a/testing/trino-benchmark/src/test/java/io/trino/benchmark/TestBenchmarks.java +++ b/testing/trino-benchmark/src/test/java/io/trino/benchmark/TestBenchmarks.java @@ -14,7 +14,7 @@ package io.trino.benchmark; import io.trino.testing.LocalQueryRunner; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.trino.benchmark.BenchmarkQueryRunner.createLocalQueryRunner; import static io.trino.benchmark.BenchmarkSuite.createBenchmarks; diff --git a/testing/trino-benchto-benchmarks/pom.xml b/testing/trino-benchto-benchmarks/pom.xml index c81e80d3f749..5dcb9e69ca0e 100644 --- a/testing/trino-benchto-benchmarks/pom.xml +++ b/testing/trino-benchto-benchmarks/pom.xml @@ -45,8 +45,8 @@ - org.testng - testng + org.junit.jupiter + junit-jupiter-api test diff --git a/testing/trino-benchto-benchmarks/src/test/java/io/trino/benchmarks/TestDummy.java b/testing/trino-benchto-benchmarks/src/test/java/io/trino/benchmarks/TestDummy.java index f91752b76233..182018cfc54b 100644 --- a/testing/trino-benchto-benchmarks/src/test/java/io/trino/benchmarks/TestDummy.java +++ b/testing/trino-benchto-benchmarks/src/test/java/io/trino/benchmarks/TestDummy.java @@ -13,7 +13,7 @@ */ package io.trino.benchmarks; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; public class TestDummy { diff --git a/testing/trino-server-dev/pom.xml b/testing/trino-server-dev/pom.xml index 1330062ffafc..640062e6c071 100644 --- a/testing/trino-server-dev/pom.xml +++ b/testing/trino-server-dev/pom.xml @@ -69,8 +69,8 @@ - org.testng - testng + org.junit.jupiter + junit-jupiter-api test diff --git a/testing/trino-server-dev/src/test/java/io/trino/server/TestDevelopmentLoaderConfig.java b/testing/trino-server-dev/src/test/java/io/trino/server/TestDevelopmentLoaderConfig.java index 6b7f6ff9b323..176d095e1ced 100644 --- a/testing/trino-server-dev/src/test/java/io/trino/server/TestDevelopmentLoaderConfig.java +++ b/testing/trino-server-dev/src/test/java/io/trino/server/TestDevelopmentLoaderConfig.java @@ -16,7 +16,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import io.airlift.resolver.ArtifactResolver; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.Map; diff --git a/testing/trino-testing-containers/pom.xml b/testing/trino-testing-containers/pom.xml index 6bf9bc414c40..034276c31326 100644 --- a/testing/trino-testing-containers/pom.xml +++ b/testing/trino-testing-containers/pom.xml @@ -73,8 +73,8 @@ - org.testng - testng + org.junit.jupiter + junit-jupiter-api test diff --git a/testing/trino-testing-containers/src/test/java/io/trino/server/TestDummy.java b/testing/trino-testing-containers/src/test/java/io/trino/server/TestDummy.java index dea00f6fd596..b560df431cb6 100644 --- a/testing/trino-testing-containers/src/test/java/io/trino/server/TestDummy.java +++ b/testing/trino-testing-containers/src/test/java/io/trino/server/TestDummy.java @@ -13,7 +13,7 @@ */ package io.trino.server; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; public class TestDummy { diff --git a/testing/trino-testing-kafka/pom.xml b/testing/trino-testing-kafka/pom.xml index cff5340c8a66..b8a50cad1125 100644 --- a/testing/trino-testing-kafka/pom.xml +++ b/testing/trino-testing-kafka/pom.xml @@ -68,8 +68,8 @@ - org.testng - testng + org.junit.jupiter + junit-jupiter-api test diff --git a/testing/trino-testing-kafka/src/test/java/io/trino/server/TestDummy.java b/testing/trino-testing-kafka/src/test/java/io/trino/server/TestDummy.java index dea00f6fd596..b560df431cb6 100644 --- a/testing/trino-testing-kafka/src/test/java/io/trino/server/TestDummy.java +++ b/testing/trino-testing-kafka/src/test/java/io/trino/server/TestDummy.java @@ -13,7 +13,7 @@ */ package io.trino.server; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; public class TestDummy { diff --git a/testing/trino-testing-resources/pom.xml b/testing/trino-testing-resources/pom.xml index 7ab6d9247569..8ab17ffbf1dc 100644 --- a/testing/trino-testing-resources/pom.xml +++ b/testing/trino-testing-resources/pom.xml @@ -17,8 +17,8 @@ - org.testng - testng + org.junit.jupiter + junit-jupiter-api test diff --git a/testing/trino-testing-resources/src/test/java/io/trino/testing/resources/TestDummy.java b/testing/trino-testing-resources/src/test/java/io/trino/testing/resources/TestDummy.java index 4abc29842741..572eb22c42e4 100644 --- a/testing/trino-testing-resources/src/test/java/io/trino/testing/resources/TestDummy.java +++ b/testing/trino-testing-resources/src/test/java/io/trino/testing/resources/TestDummy.java @@ -13,7 +13,7 @@ */ package io.trino.testing.resources; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; public class TestDummy { diff --git a/testing/trino-tests/pom.xml b/testing/trino-tests/pom.xml index e59fde5179c3..1a3a24ce8621 100644 --- a/testing/trino-tests/pom.xml +++ b/testing/trino-tests/pom.xml @@ -419,21 +419,21 @@ maven-surefire-plugin - - org.apache.maven.surefire - surefire-junit-platform - ${dep.plugin.surefire.version} - + + + + + org.apache.maven.surefire surefire-testng ${dep.plugin.surefire.version} - - org.junit.jupiter - junit-jupiter-engine - ${dep.junit.version} - + + + + + diff --git a/testing/trino-tests/src/test/java/io/trino/connector/informationschema/BenchmarkInformationSchema.java b/testing/trino-tests/src/test/java/io/trino/connector/informationschema/BenchmarkInformationSchema.java index 339686f2698e..3c1ecd4b2d7a 100644 --- a/testing/trino-tests/src/test/java/io/trino/connector/informationschema/BenchmarkInformationSchema.java +++ b/testing/trino-tests/src/test/java/io/trino/connector/informationschema/BenchmarkInformationSchema.java @@ -23,6 +23,7 @@ import io.trino.testing.DistributedQueryRunner; import io.trino.testing.MaterializedResult; import io.trino.testing.QueryRunner; +import org.junit.jupiter.api.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; @@ -35,7 +36,6 @@ import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.TearDown; import org.openjdk.jmh.annotations.Warmup; -import org.testng.annotations.Test; import java.util.List; import java.util.Map; diff --git a/testing/trino-tests/src/test/java/io/trino/connector/system/runtime/TestKillQuery.java b/testing/trino-tests/src/test/java/io/trino/connector/system/runtime/TestKillQuery.java index 0998b23e52b7..0bd75bd08db0 100644 --- a/testing/trino-tests/src/test/java/io/trino/connector/system/runtime/TestKillQuery.java +++ b/testing/trino-tests/src/test/java/io/trino/connector/system/runtime/TestKillQuery.java @@ -19,8 +19,12 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.DistributedQueryRunner; import io.trino.testing.QueryRunner; -import org.testng.annotations.AfterClass; -import org.testng.annotations.Test; +import io.trino.testng.services.ManageTestResources; +import io.trino.testng.services.ReportOrphanedExecutors; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.Timeout; import java.util.Optional; import java.util.concurrent.ExecutionException; @@ -39,12 +43,15 @@ import static java.lang.String.format; import static java.util.UUID.randomUUID; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; import static org.testng.Assert.assertFalse; -@Test(singleThreaded = true) +@TestInstance(PER_CLASS) public class TestKillQuery extends AbstractTestQueryFramework { + @ManageTestResources.Suppress(because = "Not a TestNG test class") + @ReportOrphanedExecutors.Suppress(because = "Not a TestNG test class") private final ExecutorService executor = Executors.newSingleThreadScheduledExecutor(threadsNamed(TestKillQuery.class.getSimpleName())); @Override @@ -62,13 +69,14 @@ protected QueryRunner createQueryRunner() return queryRunner; } - @AfterClass(alwaysRun = true) + @AfterAll public void tearDown() { executor.shutdownNow(); } - @Test(timeOut = 60_000) + @Test + @Timeout(60) public void testKillQuery() { killQuery(queryId -> format("CALL system.runtime.kill_query('%s', 'because')", queryId), "Message: because"); diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestBeginQuery.java b/testing/trino-tests/src/test/java/io/trino/execution/TestBeginQuery.java index 8c881ba74a71..8ddc1b5df3ad 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestBeginQuery.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestBeginQuery.java @@ -41,8 +41,7 @@ import io.trino.testing.TestingPageSinkProvider; import io.trino.testing.TestingSplitManager; import io.trino.testing.TestingTransactionHandle; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.Map; @@ -52,7 +51,6 @@ import static java.util.Objects.requireNonNull; import static org.testng.Assert.assertEquals; -@Test(singleThreaded = true) public class TestBeginQuery extends AbstractTestQueryFramework { @@ -77,21 +75,19 @@ protected QueryRunner createQueryRunner() .build(); } - @AfterMethod(alwaysRun = true) - public void afterMethod() - { - metadata.clear(); - } - @Test public void testCreateTableAsSelect() { + metadata.clear(); + assertBeginQuery("CREATE TABLE nation AS SELECT * FROM tpch.tiny.nation"); } @Test public void testCreateTableAsSelectSameConnector() { + metadata.clear(); + assertBeginQuery("CREATE TABLE nation AS SELECT * FROM tpch.tiny.nation"); assertBeginQuery("CREATE TABLE nation_copy AS SELECT * FROM nation"); } @@ -99,6 +95,8 @@ public void testCreateTableAsSelectSameConnector() @Test public void testInsert() { + metadata.clear(); + assertBeginQuery("CREATE TABLE nation AS SELECT * FROM tpch.tiny.nation"); assertBeginQuery("INSERT INTO nation SELECT * FROM tpch.tiny.nation"); assertBeginQuery("INSERT INTO nation VALUES (12345, 'name', 54321, 'comment')"); @@ -107,6 +105,8 @@ public void testInsert() @Test public void testInsertSelectSameConnector() { + metadata.clear(); + assertBeginQuery("CREATE TABLE nation AS SELECT * FROM tpch.tiny.nation"); assertBeginQuery("INSERT INTO nation SELECT * FROM nation"); } @@ -114,6 +114,8 @@ public void testInsertSelectSameConnector() @Test public void testSelect() { + metadata.clear(); + assertBeginQuery("CREATE TABLE nation AS SELECT * FROM tpch.tiny.nation"); assertBeginQuery("SELECT * FROM nation"); } diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestCompletedEventWarnings.java b/testing/trino-tests/src/test/java/io/trino/execution/TestCompletedEventWarnings.java index 3c6e4e2e5f6e..356645ff703d 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestCompletedEventWarnings.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestCompletedEventWarnings.java @@ -24,9 +24,10 @@ import io.trino.testing.TestingWarningCollector; import io.trino.testing.TestingWarningCollectorConfig; import org.intellij.lang.annotations.Language; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import java.io.IOException; import java.util.List; @@ -35,9 +36,10 @@ import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.ImmutableSet.toImmutableSet; import static io.trino.SessionTestUtils.TEST_SESSION; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; import static org.testng.Assert.fail; -@Test(singleThreaded = true) +@TestInstance(PER_CLASS) public class TestCompletedEventWarnings { private static final int TEST_WARNINGS = 5; @@ -47,7 +49,7 @@ public class TestCompletedEventWarnings private Closer closer; private EventsAwaitingQueries queries; - @BeforeClass + @BeforeAll public void setUp() throws Exception { @@ -61,7 +63,7 @@ public void setUp() queries = new EventsAwaitingQueries(generatedEvents, queryRunner); } - @AfterClass(alwaysRun = true) + @AfterAll public void tearDown() throws IOException { diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestConnectorEventListener.java b/testing/trino-tests/src/test/java/io/trino/execution/TestConnectorEventListener.java index a54b7f18a464..13b0022c4996 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestConnectorEventListener.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestConnectorEventListener.java @@ -19,14 +19,17 @@ import io.trino.spi.Plugin; import io.trino.spi.connector.ConnectorFactory; import io.trino.testing.DistributedQueryRunner; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import java.io.IOException; import static io.trino.SessionTestUtils.TEST_SESSION; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; +@TestInstance(PER_CLASS) public class TestConnectorEventListener { private final EventsCollector generatedEvents = new EventsCollector(); @@ -34,7 +37,7 @@ public class TestConnectorEventListener private Closer closer; private EventsAwaitingQueries queries; - @BeforeClass + @BeforeAll public void setUp() throws Exception { @@ -58,7 +61,7 @@ public Iterable getConnectorFactories() queries = new EventsAwaitingQueries(generatedEvents, queryRunner); } - @AfterClass(alwaysRun = true) + @AfterAll public void tearDown() throws IOException { diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestDeprecatedFunctionWarning.java b/testing/trino-tests/src/test/java/io/trino/execution/TestDeprecatedFunctionWarning.java index 9994780ec88e..e0fc5b0e985c 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestDeprecatedFunctionWarning.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestDeprecatedFunctionWarning.java @@ -35,9 +35,10 @@ import io.trino.testing.DistributedQueryRunner; import io.trino.testing.QueryRunner; import org.intellij.lang.annotations.Language; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import java.util.List; import java.util.Set; @@ -45,8 +46,10 @@ import static com.google.common.collect.ImmutableSet.toImmutableSet; import static io.trino.spi.type.DoubleType.DOUBLE; import static io.trino.testing.TestingSession.testSessionBuilder; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; import static org.testng.Assert.fail; +@TestInstance(PER_CLASS) public class TestDeprecatedFunctionWarning { private static final WarningCode DEPRECATED_FUNCTION_WARNING_CODE = StandardWarningCode.DEPRECATED_FUNCTION.toWarningCode(); @@ -54,7 +57,7 @@ public class TestDeprecatedFunctionWarning private QueryRunner queryRunner; - @BeforeClass + @BeforeAll public void setUp() throws Exception { @@ -71,7 +74,7 @@ public void setUp() queryRunner.installPlugin(new DeprecatedFunctionsPlugin()); } - @AfterClass(alwaysRun = true) + @AfterAll public void tearDown() { queryRunner.close(); diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestErrorThrowableInQuery.java b/testing/trino-tests/src/test/java/io/trino/execution/TestErrorThrowableInQuery.java index 1832a1717583..7d5db6e258da 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestErrorThrowableInQuery.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestErrorThrowableInQuery.java @@ -27,7 +27,7 @@ import io.trino.spi.connector.SchemaTableName; import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.DistributedQueryRunner; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.trino.spi.StandardErrorCode.NOT_FOUND; import static io.trino.spi.type.BigintType.BIGINT; diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerWithSplits.java b/testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerWithSplits.java index 902464d5dc29..f854b4998d27 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerWithSplits.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerWithSplits.java @@ -35,7 +35,7 @@ import io.trino.testing.DistributedQueryRunner; import io.trino.testing.QueryRunner; import org.intellij.lang.annotations.Language; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.Optional; @@ -51,7 +51,6 @@ import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; -@Test(singleThreaded = true) public class TestEventListenerWithSplits extends AbstractTestQueryFramework { diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestExecutionJmxMetrics.java b/testing/trino-tests/src/test/java/io/trino/execution/TestExecutionJmxMetrics.java index 129473fc8463..37622b73c5bb 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestExecutionJmxMetrics.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestExecutionJmxMetrics.java @@ -21,7 +21,8 @@ import io.trino.spi.QueryId; import io.trino.testing.DistributedQueryRunner; import io.trino.tests.tpch.TpchQueryRunnerBuilder; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import javax.management.MBeanServer; import javax.management.ObjectName; @@ -39,7 +40,8 @@ public class TestExecutionJmxMetrics { private static final String LONG_RUNNING_QUERY = "SELECT COUNT(*) FROM tpch.sf100000.lineitem"; - @Test(timeOut = 30_000) + @Test + @Timeout(30) public void testQueryStats() throws Exception { diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestFinalQueryInfo.java b/testing/trino-tests/src/test/java/io/trino/execution/TestFinalQueryInfo.java index 0020855ba339..d0590d58d928 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestFinalQueryInfo.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestFinalQueryInfo.java @@ -23,7 +23,8 @@ import io.trino.testing.DistributedQueryRunner; import okhttp3.Call; import okhttp3.OkHttpClient; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.time.ZoneId; import java.util.Locale; @@ -38,7 +39,8 @@ public class TestFinalQueryInfo { - @Test(timeOut = 240_000) + @Test + @Timeout(240) public void testFinalQueryInfoSetOnAbort() throws Exception { diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestPendingStageState.java b/testing/trino-tests/src/test/java/io/trino/execution/TestPendingStageState.java index 245e3fd4b76f..dd98f0667d8f 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestPendingStageState.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestPendingStageState.java @@ -18,9 +18,11 @@ import io.trino.spi.QueryId; import io.trino.testing.DistributedQueryRunner; import io.trino.tests.tpch.TpchQueryRunnerBuilder; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.Timeout; import static io.trino.SessionTestUtils.TEST_SESSION; import static io.trino.execution.QueryRunnerUtil.createQuery; @@ -29,13 +31,15 @@ import static io.trino.plugin.tpch.TpchConnectorFactory.TPCH_SPLITS_PER_NODE; import static io.trino.testing.assertions.Assert.assertEventually; import static java.util.concurrent.TimeUnit.SECONDS; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; import static org.testng.Assert.assertEquals; +@TestInstance(PER_CLASS) public class TestPendingStageState { private DistributedQueryRunner queryRunner; - @BeforeClass + @BeforeAll public void setup() throws Exception { @@ -43,7 +47,8 @@ public void setup() queryRunner.createCatalog("tpch", "tpch", ImmutableMap.of(TPCH_SPLITS_PER_NODE, "10000")); } - @Test(timeOut = 30_000) + @Test + @Timeout(30) public void testPendingState() throws Exception { @@ -67,7 +72,7 @@ public void testPendingState() assertEquals(queryInfo.getOutputStage().get().getSubStages().get(0).getState(), StageState.PENDING); } - @AfterClass(alwaysRun = true) + @AfterAll public void tearDown() { if (queryRunner != null) { diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestQueryTracker.java b/testing/trino-tests/src/test/java/io/trino/execution/TestQueryTracker.java index e4b3f6d8562a..6e1d3bfe17e4 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestQueryTracker.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestQueryTracker.java @@ -22,8 +22,10 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.DistributedQueryRunner; import io.trino.testing.QueryRunner; -import org.testng.annotations.AfterClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.Timeout; import java.util.concurrent.CountDownLatch; @@ -31,17 +33,18 @@ import static io.trino.spi.type.VarcharType.VARCHAR; import static io.trino.testing.TestingSession.testSessionBuilder; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; // Tests need to finish before strict timeouts. Any background work // may make them flaky -@Test(singleThreaded = true) +@TestInstance(PER_CLASS) public class TestQueryTracker extends AbstractTestQueryFramework { private final CountDownLatch freeze = new CountDownLatch(1); private final CountDownLatch interrupted = new CountDownLatch(1); - @AfterClass(alwaysRun = true) + @AfterAll public void unfreeze() { freeze.countDown(); @@ -77,7 +80,8 @@ public Iterable getConnectorFactories() return queryRunner; } - @Test(timeOut = 10_000) + @Test + @Timeout(10) public void testInterruptApplyFilter() throws InterruptedException { diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestQueues.java b/testing/trino-tests/src/test/java/io/trino/execution/TestQueues.java index 9f7d4787b13e..af9dea4ef84c 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestQueues.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestQueues.java @@ -26,7 +26,8 @@ import io.trino.spi.session.ResourceEstimates; import io.trino.testing.DistributedQueryRunner; import io.trino.tests.tpch.TpchQueryRunnerBuilder; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.util.Optional; import java.util.Set; @@ -51,12 +52,12 @@ import static org.testng.Assert.assertTrue; // run single threaded to avoid creating multiple query runners at once -@Test(singleThreaded = true) public class TestQueues { private static final String LONG_LASTING_QUERY = "SELECT COUNT(*) FROM lineitem"; - @Test(timeOut = 240_000) + @Test + @Timeout(240) public void testResourceGroupManager() throws Exception { @@ -95,7 +96,8 @@ public void testResourceGroupManager() } } - @Test(timeOut = 240_000) + @Test + @Timeout(240) public void testExceedSoftLimits() throws Exception { @@ -159,7 +161,8 @@ private QueryId createScheduledQuery(DistributedQueryRunner queryRunner) return createQuery(queryRunner, newSession("scheduled", ImmutableSet.of(), null), LONG_LASTING_QUERY); } - @Test(timeOut = 240_000) + @Test + @Timeout(240) public void testResourceGroupManagerWithTwoDashboardQueriesRequestedAtTheSameTime() throws Exception { @@ -176,7 +179,8 @@ public void testResourceGroupManagerWithTwoDashboardQueriesRequestedAtTheSameTim } } - @Test(timeOut = 240_000) + @Test + @Timeout(240) public void testResourceGroupManagerWithTooManyQueriesScheduled() throws Exception { @@ -195,14 +199,16 @@ public void testResourceGroupManagerWithTooManyQueriesScheduled() } } - @Test(timeOut = 240_000) + @Test + @Timeout(240) public void testResourceGroupManagerRejection() throws Exception { testRejection(); } - @Test(timeOut = 240_000) + @Test + @Timeout(240) public void testClientTagsBasedSelection() throws Exception { @@ -216,7 +222,8 @@ public void testClientTagsBasedSelection() } } - @Test(timeOut = 240_000) + @Test + @Timeout(240) public void testSelectorResourceEstimateBasedSelection() throws Exception { @@ -272,7 +279,8 @@ public void testSelectorResourceEstimateBasedSelection() } } - @Test(timeOut = 240_000) + @Test + @Timeout(240) public void testQueryTypeBasedSelection() throws Exception { diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestRefreshMaterializedView.java b/testing/trino-tests/src/test/java/io/trino/execution/TestRefreshMaterializedView.java index e73181d26677..54dc8bac7694 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestRefreshMaterializedView.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestRefreshMaterializedView.java @@ -30,11 +30,13 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.DistributedQueryRunner; import io.trino.testing.QueryRunner; +import io.trino.testng.services.ManageTestResources; +import io.trino.testng.services.ReportOrphanedExecutors; import org.intellij.lang.annotations.Language; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.Timeout; import java.util.Optional; @@ -50,30 +52,26 @@ import static java.util.concurrent.Executors.newCachedThreadPool; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; -@Test(singleThreaded = true) +@TestInstance(PER_CLASS) public class TestRefreshMaterializedView extends AbstractTestQueryFramework { - private ListeningExecutorService executorService; + @ManageTestResources.Suppress(because = "Not a TestNG test class") + @ReportOrphanedExecutors.Suppress(because = "Not a TestNG test class") + private final ListeningExecutorService executorService = listeningDecorator(newCachedThreadPool()); private SettableFuture startRefreshMaterializedView; private SettableFuture finishRefreshMaterializedView; private SettableFuture refreshInterrupted; - @BeforeClass - public void setUp() - { - executorService = listeningDecorator(newCachedThreadPool()); - } - - @AfterClass(alwaysRun = true) + @AfterAll public void shutdown() { executorService.shutdownNow(); } - @BeforeMethod - public void resetState() + private void resetState() { startRefreshMaterializedView = SettableFuture.create(); finishRefreshMaterializedView = SettableFuture.create(); @@ -120,9 +118,12 @@ protected QueryRunner createQueryRunner() return queryRunner; } - @Test(timeOut = 30_000) + @Test + @Timeout(30) public void testDelegateRefreshMaterializedViewToConnector() { + resetState(); + ListenableFuture queryFuture = assertUpdateAsync("REFRESH MATERIALIZED VIEW mock.default.delegate_refresh_to_connector"); // wait for connector to start refreshing MV @@ -142,9 +143,12 @@ public void testDelegateRefreshMaterializedViewToConnector() getFutureValue(queryFuture); } - @Test(timeOut = 30_000) + @Test + @Timeout(30) public void testDelegateRefreshMaterializedViewToConnectorWithCancellation() { + resetState(); + ListenableFuture queryFuture = assertUpdateAsync("REFRESH MATERIALIZED VIEW mock.default.delegate_refresh_to_connector"); // wait for connector to start refreshing MV diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestSetSessionAuthorization.java b/testing/trino-tests/src/test/java/io/trino/execution/TestSetSessionAuthorization.java index 71f1b52298e2..6c9698436094 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestSetSessionAuthorization.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestSetSessionAuthorization.java @@ -23,7 +23,7 @@ import io.trino.testing.DistributedQueryRunner; import io.trino.testing.QueryRunner; import okhttp3.OkHttpClient; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.io.File; import java.time.ZoneId; diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestStatementStats.java b/testing/trino-tests/src/test/java/io/trino/execution/TestStatementStats.java index 07d31e80fd0b..f51dd6c53fdd 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestStatementStats.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestStatementStats.java @@ -19,7 +19,7 @@ import io.trino.testing.DistributedQueryRunner; import io.trino.testing.MaterializedResult; import io.trino.tests.tpch.TpchQueryRunnerBuilder; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.trino.testing.TestingSession.testSessionBuilder; import static org.testng.Assert.assertEquals; diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestTableRedirection.java b/testing/trino-tests/src/test/java/io/trino/execution/TestTableRedirection.java index 8330fce9a817..aa79d1f96388 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestTableRedirection.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestTableRedirection.java @@ -32,7 +32,7 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.DistributedQueryRunner; import io.trino.testing.QueryRunner; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.List; diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestTry.java b/testing/trino-tests/src/test/java/io/trino/execution/TestTry.java index 12ffe185654e..177dbd4bfbb4 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestTry.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestTry.java @@ -17,7 +17,7 @@ import com.google.common.collect.ImmutableMap; import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.QueryRunner; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.trino.plugin.memory.MemoryQueryRunner.createMemoryQueryRunner; import static org.assertj.core.api.Assertions.assertThat; diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestUserImpersonationAccessControl.java b/testing/trino-tests/src/test/java/io/trino/execution/TestUserImpersonationAccessControl.java index 1ea757e6bb05..89a842f6133a 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestUserImpersonationAccessControl.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestUserImpersonationAccessControl.java @@ -24,7 +24,7 @@ import io.trino.testing.QueryRunner; import jakarta.annotation.Nullable; import okhttp3.OkHttpClient; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.io.File; import java.time.ZoneId; diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestWarnings.java b/testing/trino-tests/src/test/java/io/trino/execution/TestWarnings.java index f5ab18d75e74..f886ba32c278 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestWarnings.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestWarnings.java @@ -19,23 +19,26 @@ import io.trino.testing.QueryRunner; import io.trino.tests.tpch.TpchQueryRunnerBuilder; import org.intellij.lang.annotations.Language; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import java.util.List; import java.util.Set; import static com.google.common.collect.ImmutableSet.toImmutableSet; import static io.trino.spi.connector.StandardWarningCode.TOO_MANY_STAGES; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; import static org.testng.Assert.fail; +@TestInstance(PER_CLASS) public class TestWarnings { private static final int STAGE_COUNT_WARNING_THRESHOLD = 20; private QueryRunner queryRunner; - @BeforeClass + @BeforeAll public void setUp() throws Exception { @@ -44,7 +47,7 @@ public void setUp() .build(); } - @AfterClass(alwaysRun = true) + @AfterAll public void tearDown() { queryRunner.close(); diff --git a/testing/trino-tests/src/test/java/io/trino/execution/resourcegroups/TestResourceGroupIntegration.java b/testing/trino-tests/src/test/java/io/trino/execution/resourcegroups/TestResourceGroupIntegration.java index afe848876ad7..730297b6d24b 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/resourcegroups/TestResourceGroupIntegration.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/resourcegroups/TestResourceGroupIntegration.java @@ -19,7 +19,7 @@ import io.trino.spi.resourcegroups.ResourceGroupId; import io.trino.testing.DistributedQueryRunner; import io.trino.tests.tpch.TpchQueryRunnerBuilder; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/testing/trino-tests/src/test/java/io/trino/execution/resourcegroups/db/TestEnvironments.java b/testing/trino-tests/src/test/java/io/trino/execution/resourcegroups/db/TestEnvironments.java index 196cb1f75972..e826087d2ed8 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/resourcegroups/db/TestEnvironments.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/resourcegroups/db/TestEnvironments.java @@ -16,7 +16,8 @@ import io.trino.plugin.resourcegroups.db.H2ResourceGroupsDao; import io.trino.spi.QueryId; import io.trino.testing.DistributedQueryRunner; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import static io.trino.execution.QueryRunnerUtil.createQuery; import static io.trino.execution.QueryRunnerUtil.waitForQueryState; @@ -29,12 +30,12 @@ import static io.trino.execution.resourcegroups.db.H2TestUtil.getDao; import static io.trino.execution.resourcegroups.db.H2TestUtil.getDbConfigUrl; -@Test(singleThreaded = true) public class TestEnvironments { private static final String LONG_LASTING_QUERY = "SELECT COUNT(*) FROM lineitem"; - @Test(timeOut = 240_000) + @Test + @Timeout(240) public void testEnvironment1() throws Exception { @@ -48,7 +49,8 @@ public void testEnvironment1() } } - @Test(timeOut = 240_000) + @Test + @Timeout(240) public void testEnvironment2() throws Exception { diff --git a/testing/trino-tests/src/test/java/io/trino/execution/resourcegroups/db/TestQueuesDb.java b/testing/trino-tests/src/test/java/io/trino/execution/resourcegroups/db/TestQueuesDb.java index 8a9a503a1b57..7fe884b5ea74 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/resourcegroups/db/TestQueuesDb.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/resourcegroups/db/TestQueuesDb.java @@ -27,9 +27,11 @@ import io.trino.spi.resourcegroups.ResourceGroupId; import io.trino.testing.DistributedQueryRunner; import io.trino.testing.MaterializedResult; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.Timeout; import java.util.Optional; import java.util.Set; @@ -62,11 +64,12 @@ import static io.trino.testing.TestingSession.testSessionBuilder; import static java.lang.String.format; import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_METHOD; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; // run single threaded to avoid creating multiple query runners at once -@Test(singleThreaded = true) +@TestInstance(PER_METHOD) public class TestQueuesDb { // Copy of TestQueues with tests for db reconfiguration of resource groups @@ -74,7 +77,7 @@ public class TestQueuesDb private DistributedQueryRunner queryRunner; private H2ResourceGroupsDao dao; - @BeforeMethod + @BeforeEach public void setup() throws Exception { @@ -83,14 +86,15 @@ public void setup() queryRunner = createQueryRunner(dbConfigUrl, dao); } - @AfterMethod(alwaysRun = true) + @AfterEach public void tearDown() { queryRunner.close(); queryRunner = null; } - @Test(timeOut = 60_000) + @Test + @Timeout(60) public void testRunningQuery() throws Exception { @@ -106,7 +110,8 @@ public void testRunningQuery() } } - @Test(timeOut = 60_000) + @Test + @Timeout(60) public void testBasic() throws Exception { @@ -146,7 +151,8 @@ public void testBasic() waitForCompleteQueryCount(queryRunner, 1); } - @Test(timeOut = 60_000) + @Test + @Timeout(60) public void testTwoQueriesAtSameTime() throws Exception { @@ -156,7 +162,8 @@ public void testTwoQueriesAtSameTime() waitForQueryState(queryRunner, secondDashboardQuery, QUEUED); } - @Test(timeOut = 90_000) + @Test + @Timeout(90) public void testTooManyQueries() throws Exception { @@ -193,7 +200,8 @@ public void testTooManyQueries() waitForQueryState(queryRunner, thirdDashboardQuery, QUEUED); } - @Test(timeOut = 60_000) + @Test + @Timeout(60) public void testRejection() throws Exception { @@ -218,7 +226,8 @@ public void testRejection() waitForQueryState(queryRunner, queryId, FAILED); } - @Test(timeOut = 60_000) + @Test + @Timeout(60) public void testQuerySystemTableResourceGroup() throws Exception { @@ -228,7 +237,8 @@ public void testQuerySystemTableResourceGroup() assertEquals(result.getOnlyValue(), ImmutableList.of("global", "user-user", "dashboard-user")); } - @Test(timeOut = 60_000) + @Test + @Timeout(60) public void testSelectorPriority() throws Exception { @@ -260,7 +270,8 @@ public void testSelectorPriority() assertEquals(basicQueryInfo.getErrorCode(), QUERY_QUEUE_FULL.toErrorCode()); } - @Test(timeOut = 60_000) + @Test + @Timeout(60) public void testQueryExecutionTimeLimit() throws Exception { diff --git a/testing/trino-tests/src/test/java/io/trino/execution/resourcegroups/db/TestResourceGroupDbIntegration.java b/testing/trino-tests/src/test/java/io/trino/execution/resourcegroups/db/TestResourceGroupDbIntegration.java index 80b757d0543b..e5951316f024 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/resourcegroups/db/TestResourceGroupDbIntegration.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/resourcegroups/db/TestResourceGroupDbIntegration.java @@ -14,7 +14,7 @@ package io.trino.execution.resourcegroups.db; import io.trino.testing.DistributedQueryRunner; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.trino.execution.resourcegroups.TestResourceGroupIntegration.waitForGlobalResourceGroup; import static io.trino.execution.resourcegroups.db.H2TestUtil.getSimpleQueryRunner; diff --git a/testing/trino-tests/src/test/java/io/trino/memory/TestClusterMemoryLeakDetector.java b/testing/trino-tests/src/test/java/io/trino/memory/TestClusterMemoryLeakDetector.java index 6e7ad5525573..850955491a20 100644 --- a/testing/trino-tests/src/test/java/io/trino/memory/TestClusterMemoryLeakDetector.java +++ b/testing/trino-tests/src/test/java/io/trino/memory/TestClusterMemoryLeakDetector.java @@ -25,7 +25,7 @@ import io.trino.spi.QueryId; import io.trino.spi.resourcegroups.ResourceGroupId; import org.joda.time.DateTime; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.net.URI; import java.util.Optional; diff --git a/testing/trino-tests/src/test/java/io/trino/memory/TestMemoryManager.java b/testing/trino-tests/src/test/java/io/trino/memory/TestMemoryManager.java index 0b644bb74de8..dbcfe9f703dc 100644 --- a/testing/trino-tests/src/test/java/io/trino/memory/TestMemoryManager.java +++ b/testing/trino-tests/src/test/java/io/trino/memory/TestMemoryManager.java @@ -26,9 +26,11 @@ import io.trino.testing.QueryRunner; import io.trino.tests.tpch.TpchQueryRunnerBuilder; import org.intellij.lang.annotations.Language; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.Timeout; import java.nio.file.Paths; import java.util.ArrayList; @@ -53,14 +55,14 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; -// run single threaded to avoid creating multiple query runners at once -@Test(singleThreaded = true) +@TestInstance(PER_CLASS) public class TestMemoryManager { private static final Session SESSION = testSessionBuilder() @@ -76,20 +78,21 @@ public class TestMemoryManager private ExecutorService executor; - @BeforeClass + @BeforeAll public void setUp() { executor = newCachedThreadPool(); } - @AfterClass(alwaysRun = true) + @AfterAll public void shutdown() { executor.shutdownNow(); executor = null; } - @Test(timeOut = 240_000) + @Test + @Timeout(240) public void testResourceOverCommit() throws Exception { @@ -111,7 +114,8 @@ public void testResourceOverCommit() } } - @Test(timeOut = 240_000) + @Test + @Timeout(240) public void testOutOfMemoryKiller() throws Exception { @@ -187,7 +191,8 @@ private void waitForQueryToBeKilled(DistributedQueryRunner queryRunner) } } - @Test(timeOut = 240_000) + @Test + @Timeout(240) public void testNoLeak() throws Exception { @@ -215,7 +220,8 @@ private void testNoLeak(@Language("SQL") String query) } } - @Test(timeOut = 240_000) + @Test + @Timeout(240) public void testClusterPools() throws Exception { @@ -302,50 +308,62 @@ private static boolean isBlockedWaitingForMemory(BasicQueryInfo info) return stats.isFullyBlocked() || stats.getRunningDrivers() == 0; } - @Test(timeOut = 60_000, expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = ".*Query exceeded distributed user memory limit of 1kB.*") + @Test + @Timeout(60) public void testQueryUserMemoryLimit() - throws Exception { - Map properties = ImmutableMap.builder() - .put("task.max-partial-aggregation-memory", "1B") - .put("query.max-memory", "1kB") - .put("query.max-total-memory", "1GB") - .buildOrThrow(); - try (QueryRunner queryRunner = createQueryRunner(SESSION, properties)) { - queryRunner.execute(SESSION, "SELECT COUNT(*), repeat(orderstatus, 1000) FROM orders GROUP BY 2"); - } + assertThatThrownBy(() -> { + Map properties = ImmutableMap.builder() + .put("task.max-partial-aggregation-memory", "1B") + .put("query.max-memory", "1kB") + .put("query.max-total-memory", "1GB") + .buildOrThrow(); + try (QueryRunner queryRunner = createQueryRunner(SESSION, properties)) { + queryRunner.execute(SESSION, "SELECT COUNT(*), repeat(orderstatus, 1000) FROM orders GROUP BY 2"); + } + }) + .isInstanceOf(RuntimeException.class) + .hasMessageContaining("Query exceeded distributed user memory limit of 1kB"); } - @Test(timeOut = 60_000, expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = ".*Query exceeded distributed total memory limit of 120MB.*") + @Test + @Timeout(60) public void testQueryTotalMemoryLimit() - throws Exception { - Map properties = ImmutableMap.builder() - // Relatively high memory limit is required, so that the table scan memory usage alone does not cause the query to fail. - .put("query.max-memory", "120MB") - .put("query.max-total-memory", "120MB") - // The user memory enforcement is tested in testQueryTotalMemoryLimit(). - // Total memory = user memory + revocable memory. - .put("spill-enabled", "true") - .put("spiller-spill-path", Paths.get(System.getProperty("java.io.tmpdir"), "trino", "spills", randomUUID().toString()).toString()) - .put("spiller-max-used-space-threshold", "1.0") - .buildOrThrow(); - try (QueryRunner queryRunner = createQueryRunner(SESSION, properties)) { - queryRunner.execute(SESSION, "SELECT * FROM tpch.sf10.orders ORDER BY orderkey"); - } + assertThatThrownBy(() -> { + Map properties = ImmutableMap.builder() + // Relatively high memory limit is required, so that the table scan memory usage alone does not cause the query to fail. + .put("query.max-memory", "120MB") + .put("query.max-total-memory", "120MB") + // The user memory enforcement is tested in testQueryTotalMemoryLimit(). + // Total memory = user memory + revocable memory. + .put("spill-enabled", "true") + .put("spiller-spill-path", Paths.get(System.getProperty("java.io.tmpdir"), "trino", "spills", randomUUID().toString()).toString()) + .put("spiller-max-used-space-threshold", "1.0") + .buildOrThrow(); + try (QueryRunner queryRunner = createQueryRunner(SESSION, properties)) { + queryRunner.execute(SESSION, "SELECT * FROM tpch.sf10.orders ORDER BY orderkey"); + } + }) + .isInstanceOf(RuntimeException.class) + .hasMessageContaining("Query exceeded distributed total memory limit of 120MB"); } - @Test(timeOut = 60_000, expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = ".*Query exceeded per-node memory limit of 1kB.*") + @Test + @Timeout(60) public void testQueryMemoryPerNodeLimit() - throws Exception { - Map properties = ImmutableMap.builder() - .put("task.max-partial-aggregation-memory", "1B") - .put("query.max-memory-per-node", "1kB") - .buildOrThrow(); - try (QueryRunner queryRunner = createQueryRunner(SESSION, properties)) { - queryRunner.execute(SESSION, "SELECT COUNT(*), repeat(orderstatus, 1000) FROM orders GROUP BY 2"); - } + assertThatThrownBy(() -> { + Map properties = ImmutableMap.builder() + .put("task.max-partial-aggregation-memory", "1B") + .put("query.max-memory-per-node", "1kB") + .buildOrThrow(); + try (QueryRunner queryRunner = createQueryRunner(SESSION, properties)) { + queryRunner.execute(SESSION, "SELECT COUNT(*), repeat(orderstatus, 1000) FROM orders GROUP BY 2"); + } + }) + .isInstanceOf(RuntimeException.class) + .hasMessageContaining("Query exceeded per-node memory limit of 1kB"); } public static DistributedQueryRunner createQueryRunner(Session session, Map extraProperties) diff --git a/testing/trino-tests/src/test/java/io/trino/memory/TestMemorySessionProperties.java b/testing/trino-tests/src/test/java/io/trino/memory/TestMemorySessionProperties.java index ab5094a5e97e..2c7ddb5896d1 100644 --- a/testing/trino-tests/src/test/java/io/trino/memory/TestMemorySessionProperties.java +++ b/testing/trino-tests/src/test/java/io/trino/memory/TestMemorySessionProperties.java @@ -17,7 +17,8 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.QueryRunner; import io.trino.tests.tpch.TpchQueryRunnerBuilder; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import static io.trino.SystemSessionProperties.QUERY_MAX_MEMORY_PER_NODE; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -34,7 +35,8 @@ protected QueryRunner createQueryRunner() return TpchQueryRunnerBuilder.builder().setNodeCount(2).build(); } - @Test(timeOut = 240_000) + @Test + @Timeout(240) public void testSessionQueryMemoryPerNodeLimit() { assertQuery(sql); diff --git a/testing/trino-tests/src/test/java/io/trino/security/TestAccessControl.java b/testing/trino-tests/src/test/java/io/trino/security/TestAccessControl.java index 8bf57f2374ea..fa632c237d7e 100644 --- a/testing/trino-tests/src/test/java/io/trino/security/TestAccessControl.java +++ b/testing/trino-tests/src/test/java/io/trino/security/TestAccessControl.java @@ -49,16 +49,15 @@ import io.trino.spi.security.TrinoPrincipal; import io.trino.spi.security.ViewExpression; import io.trino.testing.AbstractTestQueryFramework; -import io.trino.testing.DataProviders; import io.trino.testing.DistributedQueryRunner; import io.trino.testing.QueryRunner; import io.trino.testing.TestingAccessControlManager; import io.trino.testing.TestingAccessControlManager.TestingPrivilege; import io.trino.testing.TestingGroupProvider; import io.trino.testing.TestingSession; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Optional; @@ -109,7 +108,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -@Test(singleThreaded = true) // Test is stateful, see @BeforeMethod public class TestAccessControl extends AbstractTestQueryFramework { @@ -246,8 +244,7 @@ public Map apply(Connector return queryRunner; } - @BeforeMethod - public void reset() + private void reset() { systemAccessControl.set(new DefaultSystemAccessControl()); requireNonNull(systemSecurityMetadata, "systemSecurityMetadata is null") @@ -259,6 +256,8 @@ public void reset() @Test public void testAccessControl() { + reset(); + assertAccessDenied("SELECT * FROM orders", "Cannot execute query", privilege("query", EXECUTE_QUERY)); assertAccessDenied("INSERT INTO orders SELECT * FROM orders", "Cannot insert into table .*.orders.*", privilege("orders", INSERT_TABLE)); assertAccessDenied("DELETE FROM orders", "Cannot delete from table .*.orders.*", privilege("orders", DELETE_TABLE)); @@ -331,6 +330,8 @@ public void testAccessControl() @Test public void testViewColumnAccessControl() { + reset(); + Session viewOwnerSession = TestingSession.testSessionBuilder() .setIdentity(Identity.ofUser("test_view_access_owner")) .setCatalog(getSession().getCatalog()) @@ -429,6 +430,8 @@ public void testViewColumnAccessControl() @Test public void testViewOwnersRoleGrants() { + reset(); + String viewOwner = "view_owner"; TrinoPrincipal viewOwnerPrincipal = new TrinoPrincipal(USER, viewOwner); String viewName = "test_view_column_access_" + randomNameSuffix(); @@ -469,6 +472,8 @@ public void testViewOwnersRoleGrants() @Test public void testJoinBaseTableWithView() { + reset(); + String viewOwner = "view_owner"; TrinoPrincipal viewOwnerPrincipal = new TrinoPrincipal(USER, viewOwner); String viewName = "test_join_base_table_with_view_" + randomNameSuffix(); @@ -511,6 +516,8 @@ public void testJoinBaseTableWithView() @Test public void testViewFunctionAccessControl() { + reset(); + Session viewOwnerSession = TestingSession.testSessionBuilder() .setIdentity(Identity.ofUser("test_view_access_owner")) .setCatalog(getSession().getCatalog()) @@ -557,6 +564,8 @@ public void testViewFunctionAccessControl() @Test public void testFunctionAccessControl() { + reset(); + assertAccessDenied( "SELECT reverse('a')", "Cannot execute function reverse", @@ -570,6 +579,8 @@ public void testFunctionAccessControl() @Test public void testTableFunctionRequiredColumns() { + reset(); + assertAccessDenied( "SELECT * FROM TABLE(exclude_columns(TABLE(nation), descriptor(regionkey, comment)))", "Cannot select from columns \\[nationkey, name] in table .*.nation.*", @@ -579,6 +590,8 @@ public void testTableFunctionRequiredColumns() @Test public void testAnalyzeAccessControl() { + reset(); + assertAccessAllowed("ANALYZE nation"); assertAccessDenied("ANALYZE nation", "Cannot ANALYZE \\(missing insert privilege\\) table .*.nation.*", privilege("nation", INSERT_TABLE)); assertAccessDenied("ANALYZE nation", "Cannot select from columns \\[.*] in table or view .*.nation", privilege("nation", SELECT_COLUMN)); @@ -588,6 +601,8 @@ public void testAnalyzeAccessControl() @Test public void testMetadataFilterColumns() { + reset(); + getQueryRunner().getAccessControl().deny(privilege("nation.regionkey", SELECT_COLUMN)); assertThat(query("SELECT column_name FROM information_schema.columns WHERE table_catalog = CURRENT_CATALOG AND table_schema = CURRENT_SCHEMA and table_name = 'nation'")) @@ -600,6 +615,8 @@ public void testMetadataFilterColumns() @Test public void testCommentView() { + reset(); + String viewName = "comment_view" + randomNameSuffix(); assertUpdate("CREATE VIEW " + viewName + " COMMENT 'old comment' AS SELECT * FROM orders"); assertAccessDenied("COMMENT ON VIEW " + viewName + " IS 'new comment'", "Cannot comment view to .*", privilege(viewName, COMMENT_VIEW)); @@ -609,46 +626,54 @@ public void testCommentView() @Test public void testCommentOnRedirectedTable() { + reset(); + String query = "SELECT * FROM system.metadata.table_comments WHERE catalog_name = 'mock' AND schema_name = 'default' AND table_name LIKE 'redirected%'"; assertQuery(query, "VALUES ('mock', 'default', 'redirected_source', 'this is a redirected table')"); getQueryRunner().getAccessControl().denyTables(schemaTableName -> !schemaTableName.getTableName().equals("redirected_target")); assertQueryReturnsEmptyResult(query); } - @Test(dataProviderClass = DataProviders.class, dataProvider = "trueFalse") - public void testViewWithTableFunction(boolean securityDefiner) + @Test + public void testViewWithTableFunction() { - Session viewOwner = getSession(); - Session otherUser = Session.builder(getSession()) - .setIdentity(Identity.ofUser(getSession().getUser() + "-someone-else")) - .build(); + reset(); + + for (boolean securityDefiner : Arrays.asList(true, false)) { + Session viewOwner = getSession(); + Session otherUser = Session.builder(getSession()) + .setIdentity(Identity.ofUser(getSession().getUser() + "-someone-else")) + .build(); + + String viewName = "memory.default.definer_view_with_ptf"; + assertUpdate(viewOwner, "CREATE VIEW " + viewName + " SECURITY " + (securityDefiner ? "DEFINER" : "INVOKER") + " AS SELECT * FROM TABLE (jdbc.system.query('SELECT ''from h2'', monthname(CAST(''2005-09-10'' AS date))'))"); + String viewValues = "VALUES ('from h2', 'September') "; + + assertThat(query(viewOwner, "TABLE " + viewName)).matches(viewValues); + assertThat(query(otherUser, "TABLE " + viewName)).matches(viewValues); + + TestingPrivilege grantExecute = TestingAccessControlManager.privilege("jdbc.system.query", GRANT_EXECUTE_FUNCTION); + assertAccessAllowed(viewOwner, "TABLE " + viewName, grantExecute); + if (securityDefiner) { + assertAccessDenied( + otherUser, + "TABLE " + viewName, + "View owner does not have sufficient privileges: 'user' cannot grant 'jdbc.system.query' execution to user 'user-someone-else'", + grantExecute); + } + else { + assertAccessAllowed(otherUser, "TABLE " + viewName, grantExecute); + } - String viewName = "memory.default.definer_view_with_ptf"; - assertUpdate(viewOwner, "CREATE VIEW " + viewName + " SECURITY " + (securityDefiner ? "DEFINER" : "INVOKER") + " AS SELECT * FROM TABLE (jdbc.system.query('SELECT ''from h2'', monthname(CAST(''2005-09-10'' AS date))'))"); - String viewValues = "VALUES ('from h2', 'September') "; - - assertThat(query(viewOwner, "TABLE " + viewName)).matches(viewValues); - assertThat(query(otherUser, "TABLE " + viewName)).matches(viewValues); - - TestingPrivilege grantExecute = TestingAccessControlManager.privilege("jdbc.system.query", GRANT_EXECUTE_FUNCTION); - assertAccessAllowed(viewOwner, "TABLE " + viewName, grantExecute); - if (securityDefiner) { - assertAccessDenied( - otherUser, - "TABLE " + viewName, - "View owner does not have sufficient privileges: 'user' cannot grant 'jdbc.system.query' execution to user 'user-someone-else'", - grantExecute); + assertUpdate("DROP VIEW " + viewName); } - else { - assertAccessAllowed(otherUser, "TABLE " + viewName, grantExecute); - } - - assertUpdate("DROP VIEW " + viewName); } @Test public void testCommentColumnView() { + reset(); + String viewName = "comment_view" + randomNameSuffix(); assertUpdate("CREATE VIEW " + viewName + " AS SELECT * FROM orders"); assertAccessDenied("COMMENT ON COLUMN " + viewName + ".orderkey IS 'new order key comment'", "Cannot comment column to .*", privilege(viewName, COMMENT_COLUMN)); @@ -658,6 +683,8 @@ public void testCommentColumnView() @Test public void testCommentColumnMaterializedView() { + reset(); + String viewName = "comment_materialized_view" + randomNameSuffix(); assertUpdate("CREATE MATERIALIZED VIEW mock.default." + viewName + " AS SELECT * FROM orders"); assertAccessDenied("COMMENT ON COLUMN mock.default." + viewName + ".column_0 IS 'new comment'", "Cannot comment column to .*", privilege(viewName, COMMENT_COLUMN)); @@ -667,6 +694,8 @@ public void testCommentColumnMaterializedView() @Test public void testSetColumnType() { + reset(); + String tableName = "test_set_colun_type" + randomNameSuffix(); assertUpdate("CREATE TABLE " + tableName + " AS SELECT * FROM orders", 0); @@ -677,6 +706,8 @@ public void testSetColumnType() @Test public void testSetTableProperties() { + reset(); + assertAccessDenied("ALTER TABLE orders SET PROPERTIES field_length = 32", "Cannot set table properties to .*.orders.*", privilege("orders", SET_TABLE_PROPERTIES)); assertThatThrownBy(() -> getQueryRunner().execute(getSession(), "ALTER TABLE orders SET PROPERTIES field_length = 32")) .hasMessageContaining("This connector does not support setting table properties"); @@ -685,6 +716,8 @@ public void testSetTableProperties() @Test public void testDeleteAccessControl() { + reset(); + assertAccessDenied("DELETE FROM orders WHERE orderkey < 12", "Cannot select from columns \\[orderkey] in table or view .*.orders.*", privilege("orders.orderkey", SELECT_COLUMN)); assertAccessAllowed("DELETE FROM orders WHERE orderkey < 12", privilege("orders" + ".orderdate", SELECT_COLUMN)); assertAccessAllowed("DELETE FROM orders", privilege("orders", SELECT_COLUMN)); @@ -693,12 +726,16 @@ public void testDeleteAccessControl() @Test public void testTruncateAccessControl() { + reset(); + assertAccessAllowed("TRUNCATE TABLE orders", privilege("orders", SELECT_COLUMN)); } @Test public void testUpdateAccessControl() { + reset(); + assertAccessDenied("UPDATE orders SET orderkey=123", "Cannot update columns \\[orderkey] in table .*", privilege("orders", UPDATE_TABLE)); assertAccessDenied("UPDATE orders SET orderkey=123 WHERE custkey < 12", "Cannot select from columns \\[custkey] in table or view .*.default.orders", privilege("orders.custkey", SELECT_COLUMN)); assertAccessAllowed("UPDATE orders SET orderkey=123", privilege("orders", SELECT_COLUMN)); @@ -707,6 +744,8 @@ public void testUpdateAccessControl() @Test public void testMergeAccessControl() { + reset(); + String catalogName = getSession().getCatalog().orElseThrow(); String schemaName = getSession().getSchema().orElseThrow(); @@ -764,6 +803,8 @@ WHEN NOT MATCHED THEN INSERT VALUES (null, null, null, null, null, null, null, n @Test public void testNonQueryAccessControl() { + reset(); + assertAccessDenied("SET SESSION " + QUERY_MAX_MEMORY + " = '10MB'", "Cannot set system session property " + QUERY_MAX_MEMORY, privilege(QUERY_MAX_MEMORY, SET_SESSION)); @@ -791,6 +832,8 @@ public void testNonQueryAccessControl() @Test public void testDescribe() { + reset(); + assertAccessDenied("DESCRIBE orders", "Cannot show columns of table default.orders", privilege("orders", SHOW_COLUMNS)); getQueryRunner().getAccessControl().deny(privilege("orders.orderkey", SELECT_COLUMN)); assertQuery( @@ -810,6 +853,8 @@ public void testDescribe() @Test public void testDescribeForViews() { + reset(); + String viewName = "describe_orders_view" + randomNameSuffix(); assertUpdate("CREATE VIEW " + viewName + " AS SELECT * FROM orders"); assertAccessDenied("DESCRIBE " + viewName, "Cannot show columns of table default.*", privilege(viewName, SHOW_COLUMNS)); @@ -832,6 +877,8 @@ public void testDescribeForViews() @Test public void testNoCatalogIsNeededInSessionForShowRoles() { + reset(); + Session session = testSessionBuilder() .setIdentity(Identity.forUser("alice") .withConnectorRoles(ImmutableMap.of("mock", new SelectedRole(ROLE, Optional.of("alice_role")))) @@ -846,6 +893,8 @@ public void testNoCatalogIsNeededInSessionForShowRoles() @Test public void testShowRolesWithLegacyCatalogRoles() { + reset(); + Session session = testSessionBuilder() .setCatalog("mock") .setIdentity(Identity.forUser("alice") @@ -862,6 +911,8 @@ public void testShowRolesWithLegacyCatalogRoles() @Test public void testEmptyRoles() { + reset(); + assertQueryReturnsEmptyResult("SHOW ROLES"); assertQueryReturnsEmptyResult("SHOW ROLE GRANTS"); assertQueryReturnsEmptyResult("SHOW CURRENT ROLES"); @@ -871,18 +922,24 @@ public void testEmptyRoles() @Test public void testSetViewAuthorizationWithSecurityDefiner() { + reset(); + assertQuerySucceeds("ALTER VIEW mock.default.test_view_definer SET AUTHORIZATION some_other_user"); } @Test public void testSetViewAuthorizationWithSecurityInvoker() { + reset(); + assertQuerySucceeds("ALTER VIEW mock.default.test_view_invoker SET AUTHORIZATION some_other_user"); } @Test public void testSystemMetadataAnalyzePropertiesFilteringValues() { + reset(); + getQueryRunner().getAccessControl().denyCatalogs(catalog -> !catalog.equals("mock")); assertQueryReturnsEmptyResult("SELECT * FROM system.metadata.analyze_properties"); } @@ -890,6 +947,8 @@ public void testSystemMetadataAnalyzePropertiesFilteringValues() @Test public void testSystemMetadataMaterializedViewPropertiesFilteringValues() { + reset(); + getQueryRunner().getAccessControl().denyCatalogs(catalog -> !catalog.equals("mock")); assertQueryReturnsEmptyResult("SELECT * FROM system.metadata.materialized_view_properties"); } @@ -897,6 +956,8 @@ public void testSystemMetadataMaterializedViewPropertiesFilteringValues() @Test public void testSystemMetadataSchemaPropertiesFilteringValues() { + reset(); + getQueryRunner().getAccessControl().denyCatalogs(catalog -> !catalog.equals("mock")); assertQueryReturnsEmptyResult("SELECT * FROM system.metadata.schema_properties"); } @@ -904,6 +965,8 @@ public void testSystemMetadataSchemaPropertiesFilteringValues() @Test public void testSystemMetadataTablePropertiesFilteringValues() { + reset(); + getQueryRunner().getAccessControl().denyCatalogs(catalog -> !catalog.equals("blackhole") && !catalog.equals("mock")); assertQueryReturnsEmptyResult("SELECT * FROM system.metadata.table_properties"); } @@ -911,6 +974,8 @@ public void testSystemMetadataTablePropertiesFilteringValues() @Test public void testSystemMetadataColumnPropertiesFilteringValues() { + reset(); + getQueryRunner().getAccessControl().denyCatalogs(catalog -> !catalog.equals("mock")); assertQueryReturnsEmptyResult("SELECT * FROM system.metadata.column_properties"); } @@ -918,6 +983,8 @@ public void testSystemMetadataColumnPropertiesFilteringValues() @Test public void testUseStatementAccessControl() { + reset(); + Session session = testSessionBuilder() .setCatalog(Optional.empty()) .setSchema(Optional.empty()) @@ -932,6 +999,8 @@ public void testUseStatementAccessControl() @Test public void testUseStatementAccessControlWithDeniedCatalog() { + reset(); + getQueryRunner().getAccessControl().denyCatalogs(catalog -> !catalog.equals("tpch")); assertThatThrownBy(() -> getQueryRunner().execute("USE tpch.tiny")) .hasMessageMatching("Access Denied: Cannot access catalog tpch"); @@ -942,6 +1011,8 @@ public void testUseStatementAccessControlWithDeniedCatalog() @Test public void testUseStatementAccessControlWithDeniedSchema() { + reset(); + getQueryRunner().getAccessControl().denySchemas(schema -> !schema.equals("tiny")); assertThatThrownBy(() -> getQueryRunner().execute("USE tpch.tiny")) .hasMessageMatching("Access Denied: Cannot access schema: tpch.tiny"); @@ -950,6 +1021,8 @@ public void testUseStatementAccessControlWithDeniedSchema() @Test public void testPropertiesAccessControl() { + reset(); + systemAccessControl.set(new DenySetPropertiesSystemAccessControl()); assertAccessDenied( "CREATE TABLE mock.default.new_table (pk bigint) WITH (double_table_property = 0.0)", // default value @@ -1034,6 +1107,8 @@ public void testPropertiesAccessControl() @Test public void testPropertiesAccessControlIsSkippedWhenUsingDefaults() { + reset(); + systemAccessControl.set(new DenySetPropertiesSystemAccessControl()); systemAccessControl.set(new DenySetPropertiesSystemAccessControl()); assertAccessAllowed("CREATE TABLE mock.default.new_table (pk bigint)"); @@ -1044,6 +1119,8 @@ public void testPropertiesAccessControlIsSkippedWhenUsingDefaults() @Test public void testAccessControlWithGroupsAndColumnMask() { + reset(); + groupProvider.setUserGroups(ImmutableMap.of(getSession().getUser(), ImmutableSet.of("group"))); TestingAccessControlManager accessControlManager = getQueryRunner().getAccessControl(); accessControlManager.denyIdentityTable((identity, table) -> (identity.getGroups().contains("group") && "orders".equals(table))); @@ -1059,6 +1136,8 @@ public void testAccessControlWithGroupsAndColumnMask() @Test public void testAccessControlWithGroupsAndRowFilter() { + reset(); + groupProvider.setUserGroups(ImmutableMap.of(getSession().getUser(), ImmutableSet.of("group"))); TestingAccessControlManager accessControlManager = getQueryRunner().getAccessControl(); accessControlManager.denyIdentityTable((identity, table) -> (identity.getGroups().contains("group") && "nation".equals(table))); @@ -1073,6 +1152,8 @@ public void testAccessControlWithGroupsAndRowFilter() @Test public void testAccessControlWithRolesAndColumnMask() { + reset(); + String role = "role"; String user = "user"; Session session = Session.builder(getSession()) @@ -1095,6 +1176,8 @@ public void testAccessControlWithRolesAndColumnMask() @Test public void testAccessControlWithRolesAndRowFilter() { + reset(); + String role = "role"; String user = "user"; Session session = Session.builder(getSession()) diff --git a/testing/trino-tests/src/test/java/io/trino/security/TestAccessControlTableRedirection.java b/testing/trino-tests/src/test/java/io/trino/security/TestAccessControlTableRedirection.java index 8f69817bd644..bb6154d57392 100644 --- a/testing/trino-tests/src/test/java/io/trino/security/TestAccessControlTableRedirection.java +++ b/testing/trino-tests/src/test/java/io/trino/security/TestAccessControlTableRedirection.java @@ -31,7 +31,7 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.DistributedQueryRunner; import io.trino.testing.QueryRunner; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.Map; import java.util.Optional; diff --git a/testing/trino-tests/src/test/java/io/trino/security/TestFunctionsInViewsWithFileBasedSystemAccessControl.java b/testing/trino-tests/src/test/java/io/trino/security/TestFunctionsInViewsWithFileBasedSystemAccessControl.java index 1fee011186db..19704cc42bb0 100644 --- a/testing/trino-tests/src/test/java/io/trino/security/TestFunctionsInViewsWithFileBasedSystemAccessControl.java +++ b/testing/trino-tests/src/test/java/io/trino/security/TestFunctionsInViewsWithFileBasedSystemAccessControl.java @@ -24,7 +24,7 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.DistributedQueryRunner; import io.trino.testing.QueryRunner; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.Map; diff --git a/testing/trino-tests/src/test/java/io/trino/security/TestSystemSecurityMetadata.java b/testing/trino-tests/src/test/java/io/trino/security/TestSystemSecurityMetadata.java index ce5a207456d9..0136d6bf0f1e 100644 --- a/testing/trino-tests/src/test/java/io/trino/security/TestSystemSecurityMetadata.java +++ b/testing/trino-tests/src/test/java/io/trino/security/TestSystemSecurityMetadata.java @@ -20,20 +20,17 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.DistributedQueryRunner; import io.trino.testing.QueryRunner; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static com.google.inject.multibindings.OptionalBinder.newOptionalBinder; import static io.trino.testing.TestingSession.testSessionBuilder; -@Test(singleThreaded = true) // singleThreaded is because TestingSystemSecurityMetadata is stateful and is shared between tests public class TestSystemSecurityMetadata extends AbstractTestQueryFramework { private final TestingSystemSecurityMetadata securityMetadata = new TestingSystemSecurityMetadata(); - @BeforeMethod - public void reset() + private void reset() { securityMetadata.reset(); } @@ -59,6 +56,8 @@ protected QueryRunner createQueryRunner() @Test public void testNoSystemRoles() { + reset(); + assertQueryReturnsEmptyResult("SHOW ROLES"); assertQueryReturnsEmptyResult("SHOW CURRENT ROLES"); assertQueryReturnsEmptyResult("SHOW ROLE GRANTS"); @@ -68,6 +67,8 @@ public void testNoSystemRoles() @Test public void testRoleCreationAndDeletion() { + reset(); + assertQueryReturnsEmptyResult("SHOW ROLES"); assertQuerySucceeds("CREATE ROLE role1"); @@ -80,6 +81,8 @@ public void testRoleCreationAndDeletion() @Test public void testRoleGrant() { + reset(); + Session alice = user("alice"); Session aliceWithRole = user("alice", "role1"); @@ -122,6 +125,8 @@ public void testRoleGrant() @Test public void testTransitiveRoleGrant() { + reset(); + Session alice = user("alice"); Session aliceWithRole = user("alice", "role2"); diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestDictionaryAggregation.java b/testing/trino-tests/src/test/java/io/trino/tests/TestDictionaryAggregation.java index daca464ea087..c45cbe27a408 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestDictionaryAggregation.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestDictionaryAggregation.java @@ -18,7 +18,7 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.LocalQueryRunner; import io.trino.testing.QueryRunner; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.trino.SystemSessionProperties.DICTIONARY_AGGREGATION; import static io.trino.SystemSessionProperties.JOIN_REORDERING_STRATEGY; diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestExcludeColumnsFunction.java b/testing/trino-tests/src/test/java/io/trino/tests/TestExcludeColumnsFunction.java index 439445cf1eb6..774e0d3df022 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestExcludeColumnsFunction.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestExcludeColumnsFunction.java @@ -17,7 +17,7 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.DistributedQueryRunner; import io.trino.testing.QueryRunner; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.trino.testing.TestingSession.testSessionBuilder; import static org.assertj.core.api.Assertions.assertThat; diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestGetTableStatisticsOperations.java b/testing/trino-tests/src/test/java/io/trino/tests/TestGetTableStatisticsOperations.java index f854548a2e55..0ad410498f4e 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestGetTableStatisticsOperations.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestGetTableStatisticsOperations.java @@ -24,23 +24,27 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.LocalQueryRunner; import io.trino.testing.QueryRunner; +import io.trino.testng.services.ManageTestResources; import io.trino.tracing.TracingMetadata; import org.intellij.lang.annotations.Language; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import static io.trino.execution.querystats.PlanOptimizersStatsCollector.createPlanOptimizersStatsCollector; import static io.trino.sql.planner.LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED; import static io.trino.testing.TestingSession.testSessionBuilder; import static io.trino.transaction.TransactionBuilder.transaction; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; -@Test(singleThreaded = true) // counting metadata is a shared mutable state +@TestInstance(PER_CLASS) public class TestGetTableStatisticsOperations extends AbstractTestQueryFramework { + @ManageTestResources.Suppress(because = "Not a TestNG test class") private LocalQueryRunner localQueryRunner; + @ManageTestResources.Suppress(because = "Not a TestNG test class") private InMemorySpanExporter spanExporter; @Override @@ -62,7 +66,7 @@ protected QueryRunner createQueryRunner() return localQueryRunner; } - @AfterClass(alwaysRun = true) + @AfterAll public void tearDown() { localQueryRunner.close(); @@ -70,8 +74,7 @@ public void tearDown() spanExporter = null; } - @BeforeMethod - public void resetCounters() + private void resetCounters() { spanExporter.reset(); } @@ -79,6 +82,8 @@ public void resetCounters() @Test public void testTwoWayJoin() { + resetCounters(); + planDistributedQuery("SELECT * " + "FROM tpch.tiny.orders o, tpch.tiny.lineitem l " + "WHERE o.orderkey = l.orderkey"); @@ -88,6 +93,8 @@ public void testTwoWayJoin() @Test public void testThreeWayJoin() { + resetCounters(); + planDistributedQuery("SELECT * " + "FROM tpch.tiny.customer c, tpch.tiny.orders o, tpch.tiny.lineitem l " + "WHERE o.orderkey = l.orderkey AND c.custkey = o.custkey"); diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestGracefulShutdown.java b/testing/trino-tests/src/test/java/io/trino/tests/TestGracefulShutdown.java index 9a949f3e7c8e..511b52a9da5c 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestGracefulShutdown.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestGracefulShutdown.java @@ -24,13 +24,16 @@ import io.trino.server.testing.TestingTrinoServer; import io.trino.server.testing.TestingTrinoServer.TestShutdownAction; import io.trino.testing.DistributedQueryRunner; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.Timeout; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; import static com.google.common.collect.MoreCollectors.onlyElement; import static io.trino.execution.QueryState.FINISHED; @@ -39,10 +42,11 @@ import static java.util.concurrent.Executors.newCachedThreadPool; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; -@Test(singleThreaded = true) +@TestInstance(PER_CLASS) public class TestGracefulShutdown { private static final long SHUTDOWN_TIMEOUT_MILLIS = 240_000; @@ -53,19 +57,20 @@ public class TestGracefulShutdown private ListeningExecutorService executor; - @BeforeClass + @BeforeAll public void setUp() { executor = MoreExecutors.listeningDecorator(newCachedThreadPool()); } - @AfterClass(alwaysRun = true) + @AfterAll public void shutdown() { executor.shutdownNow(); } - @Test(timeOut = SHUTDOWN_TIMEOUT_MILLIS) + @Test + @Timeout(value = SHUTDOWN_TIMEOUT_MILLIS, unit = TimeUnit.MILLISECONDS) public void testShutdown() throws Exception { diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestInformationSchemaConnector.java b/testing/trino-tests/src/test/java/io/trino/tests/TestInformationSchemaConnector.java index 3ef1df90ec99..12b98e5a9a00 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestInformationSchemaConnector.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestInformationSchemaConnector.java @@ -26,9 +26,12 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.CountingMockConnector; import io.trino.testing.DistributedQueryRunner; +import io.trino.testng.services.ManageTestResources; import org.intellij.lang.annotations.Language; -import org.testng.annotations.AfterClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.Timeout; import java.util.stream.IntStream; import java.util.stream.Stream; @@ -37,13 +40,15 @@ import static io.trino.testing.MultisetAssertions.assertMultisetsEqual; import static io.trino.testing.TestingSession.testSessionBuilder; import static java.util.stream.Collectors.joining; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; -@Test(singleThreaded = true) +@TestInstance(PER_CLASS) public class TestInformationSchemaConnector extends AbstractTestQueryFramework { private static final int MAX_PREFIXES_COUNT = 10; + @ManageTestResources.Suppress(because = "Not a TestNG test class") private CountingMockConnector countingMockConnector; @Override @@ -73,7 +78,7 @@ protected DistributedQueryRunner createQueryRunner() } } - @AfterClass(alwaysRun = true) + @AfterAll public void cleanUp() { countingMockConnector = null; // closed by closeAfterClass @@ -155,7 +160,8 @@ public void testLimit() assertQuery("SELECT count(*) FROM (SELECT * FROM test_catalog.information_schema.tables LIMIT 1000)", "VALUES 1000"); } - @Test(timeOut = 60_000) + @Test + @Timeout(60) public void testMetadataCalls() { assertMetadataCalls( diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestLateMaterializationQueries.java b/testing/trino-tests/src/test/java/io/trino/tests/TestLateMaterializationQueries.java index e97f3025e861..65b18bc48389 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestLateMaterializationQueries.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestLateMaterializationQueries.java @@ -22,7 +22,7 @@ import io.trino.testing.QueryRunner; import io.trino.tests.tpch.TpchQueryRunnerBuilder; import org.intellij.lang.annotations.Language; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.trino.SystemSessionProperties.FILTERING_SEMI_JOIN_TO_INNER; import static io.trino.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE; diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestLocalQueries.java b/testing/trino-tests/src/test/java/io/trino/tests/TestLocalQueries.java index 0b77e3daf21f..3de29535bd5c 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestLocalQueries.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestLocalQueries.java @@ -19,7 +19,7 @@ import io.trino.testing.AbstractTestQueries; import io.trino.testing.LocalQueryRunner; import io.trino.testing.QueryRunner; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.trino.SystemSessionProperties.PUSH_PARTIAL_AGGREGATION_THROUGH_JOIN; import static io.trino.plugin.tpch.TpchMetadata.TINY_SCHEMA_NAME; diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestMetadataManager.java b/testing/trino-tests/src/test/java/io/trino/tests/TestMetadataManager.java index b883f3429532..733c362d309d 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestMetadataManager.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestMetadataManager.java @@ -34,9 +34,10 @@ import io.trino.tracing.TracingMetadata; import io.trino.transaction.TransactionBuilder; import org.intellij.lang.annotations.Language; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import java.util.List; import java.util.Optional; @@ -47,6 +48,7 @@ import static io.trino.spi.type.BigintType.BIGINT; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; import static org.testng.Assert.assertEquals; /** @@ -55,13 +57,13 @@ * while registering catalog -> query Id mapping. * This mapping has to be manually cleaned when query finishes execution (Metadata#cleanupQuery method). */ -@Test(singleThreaded = true) +@TestInstance(PER_CLASS) public class TestMetadataManager { private DistributedQueryRunner queryRunner; private MetadataManager metadataManager; - @BeforeClass + @BeforeAll public void setUp() throws Exception { @@ -92,7 +94,7 @@ public Iterable getConnectorFactories() metadataManager = (MetadataManager) ((TracingMetadata) queryRunner.getMetadata()).getDelegate(); } - @AfterClass(alwaysRun = true) + @AfterAll public void tearDown() { queryRunner.close(); diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestMockConnector.java b/testing/trino-tests/src/test/java/io/trino/tests/TestMockConnector.java index fd2333469752..344af1e06caf 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestMockConnector.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestMockConnector.java @@ -36,7 +36,7 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.DistributedQueryRunner; import io.trino.testing.QueryRunner; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.Optional; diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestProcedureCall.java b/testing/trino-tests/src/test/java/io/trino/tests/TestProcedureCall.java index 1ec93d57e26e..6b48e1144a15 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestProcedureCall.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestProcedureCall.java @@ -23,9 +23,10 @@ import io.trino.testing.TestingProcedures; import io.trino.tests.tpch.TpchQueryRunnerBuilder; import org.intellij.lang.annotations.Language; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import java.util.List; @@ -33,10 +34,11 @@ import static java.lang.String.format; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; -@Test(singleThreaded = true) +@TestInstance(PER_CLASS) public class TestProcedureCall extends AbstractTestQueryFramework { @@ -53,7 +55,7 @@ protected QueryRunner createQueryRunner() return TpchQueryRunnerBuilder.builder().build(); } - @BeforeClass + @BeforeAll public void setUp() { DistributedQueryRunner queryRunner = getDistributedQueryRunner(); @@ -69,7 +71,7 @@ public void setUp() queryRunner.createCatalog(TESTING_CATALOG, "mock"); } - @AfterClass(alwaysRun = true) + @AfterAll public void tearDown() { tester = null; diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestProcedureCreation.java b/testing/trino-tests/src/test/java/io/trino/tests/TestProcedureCreation.java index a424cca56245..c5fc0e30c374 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestProcedureCreation.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestProcedureCreation.java @@ -16,7 +16,7 @@ import com.google.common.collect.ImmutableList; import io.trino.spi.connector.ConnectorSession; import io.trino.spi.procedure.Procedure; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestQueryManager.java b/testing/trino-tests/src/test/java/io/trino/tests/TestQueryManager.java index b89ad0ca78b9..4a22efe0e071 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestQueryManager.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestQueryManager.java @@ -27,9 +27,11 @@ import io.trino.testing.DistributedQueryRunner; import io.trino.testing.TestingSessionContext; import io.trino.tests.tpch.TpchQueryRunnerBuilder; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.Timeout; import static com.google.common.collect.ImmutableSet.toImmutableSet; import static io.trino.SessionTestUtils.TEST_SESSION; @@ -43,30 +45,32 @@ import static io.trino.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR; import static io.trino.testing.TestingSession.testSessionBuilder; import static java.util.Arrays.stream; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.fail; -@Test(singleThreaded = true) +@TestInstance(PER_CLASS) public class TestQueryManager { private DistributedQueryRunner queryRunner; - @BeforeClass + @BeforeAll public void setUp() throws Exception { queryRunner = TpchQueryRunnerBuilder.builder().build(); } - @AfterClass(alwaysRun = true) + @AfterAll public void tearDown() { queryRunner.close(); queryRunner = null; } - @Test(timeOut = 60_000L) + @Test + @Timeout(60) public void testFailQuery() throws Exception { @@ -102,7 +106,8 @@ public void testFailQuery() assertEquals(queryInfo.getFailureInfo().getMessage(), "mock exception"); } - @Test(timeOut = 60_000L) + @Test + @Timeout(60) public void testQueryCpuLimit() throws Exception { @@ -116,7 +121,8 @@ public void testQueryCpuLimit() } } - @Test(timeOut = 60_000L) + @Test + @Timeout(60) public void testQueryScanExceeded() throws Exception { @@ -130,7 +136,8 @@ public void testQueryScanExceeded() } } - @Test(timeOut = 60_000L) + @Test + @Timeout(60) public void testQueryScanExceededSession() throws Exception { diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestRepartitionQueries.java b/testing/trino-tests/src/test/java/io/trino/tests/TestRepartitionQueries.java index 0833486b2c17..2e7a179a2022 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestRepartitionQueries.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestRepartitionQueries.java @@ -16,7 +16,7 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.QueryRunner; import io.trino.tests.tpch.TpchQueryRunnerBuilder; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static java.lang.String.format; diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestSequenceFunction.java b/testing/trino-tests/src/test/java/io/trino/tests/TestSequenceFunction.java index 344ea7c7089c..1be55965f674 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestSequenceFunction.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestSequenceFunction.java @@ -16,7 +16,7 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.DistributedQueryRunner; import io.trino.testing.QueryRunner; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.trino.operator.table.Sequence.SequenceFunctionSplit.DEFAULT_SPLIT_SIZE; import static io.trino.testing.TestingSession.testSessionBuilder; diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestServer.java b/testing/trino-tests/src/test/java/io/trino/tests/TestServer.java index a40997cb325a..1769da31ffc5 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestServer.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestServer.java @@ -34,9 +34,9 @@ import io.trino.spi.type.TimeZoneNotSupportedException; import io.trino.testing.TestingTrinoClient; import org.intellij.lang.annotations.Language; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.net.URI; import java.util.Collections; @@ -91,7 +91,7 @@ public class TestServer private TestingTrinoServer server; private HttpClient client; - @BeforeClass + @BeforeAll public void setup() { server = TestingTrinoServer.builder() @@ -104,7 +104,7 @@ public void setup() client = new JettyHttpClient(); } - @AfterClass(alwaysRun = true) + @AfterAll public void tearDown() throws Exception { diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestTableFunctionInvocation.java b/testing/trino-tests/src/test/java/io/trino/tests/TestTableFunctionInvocation.java index 3d61716b244b..7fc083b47128 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestTableFunctionInvocation.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestTableFunctionInvocation.java @@ -29,7 +29,7 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.DistributedQueryRunner; import io.trino.testing.QueryRunner; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.Optional; diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestTablesample.java b/testing/trino-tests/src/test/java/io/trino/tests/TestTablesample.java index aa52f5b3a7ef..76f4a5a68646 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestTablesample.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestTablesample.java @@ -18,22 +18,25 @@ import io.trino.plugin.tpch.TpchConnectorFactory; import io.trino.sql.query.QueryAssertions; import io.trino.testing.LocalQueryRunner; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import static io.trino.SessionTestUtils.TEST_SESSION; import static io.trino.spi.StandardErrorCode.INVALID_ARGUMENTS; import static io.trino.spi.StandardErrorCode.TYPE_MISMATCH; import static io.trino.testing.assertions.TrinoExceptionAssert.assertTrinoExceptionThrownBy; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; +@TestInstance(PER_CLASS) public class TestTablesample { private LocalQueryRunner queryRunner; private QueryAssertions assertions; - @BeforeClass + @BeforeAll public void setUp() throws Exception { @@ -42,7 +45,7 @@ public void setUp() assertions = new QueryAssertions(queryRunner); } - @AfterClass(alwaysRun = true) + @AfterAll public void tearDown() throws Exception { diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestUnionQueries.java b/testing/trino-tests/src/test/java/io/trino/tests/TestUnionQueries.java index 1480483d5670..b50ce6045505 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestUnionQueries.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestUnionQueries.java @@ -22,7 +22,7 @@ import io.trino.testing.QueryRunner; import io.trino.tests.tpch.TpchQueryRunnerBuilder; import org.intellij.lang.annotations.Language; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.trino.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE; import static io.trino.SystemSessionProperties.JOIN_REORDERING_STRATEGY; diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestVerifyTrinoTestsTestSetup.java b/testing/trino-tests/src/test/java/io/trino/tests/TestVerifyTrinoTestsTestSetup.java index 665ab02df9ac..6a890243f18a 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestVerifyTrinoTestsTestSetup.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestVerifyTrinoTestsTestSetup.java @@ -13,7 +13,7 @@ */ package io.trino.tests; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.time.ZoneId; import java.util.Locale; diff --git a/testing/trino-tests/src/test/java/io/trino/tests/tpch/TestTpchDistributedStats.java b/testing/trino-tests/src/test/java/io/trino/tests/tpch/TestTpchDistributedStats.java index 08b2544f085e..b44fae88bf80 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/tpch/TestTpchDistributedStats.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/tpch/TestTpchDistributedStats.java @@ -18,9 +18,10 @@ import io.trino.testing.DistributedQueryRunner; import io.trino.testing.statistics.StatisticsAssertion; import io.trino.tpch.TpchTable; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import static io.trino.SystemSessionProperties.COLLECT_PLAN_STATISTICS_FOR_ALL_QUERIES; import static io.trino.plugin.tpch.TpchConnectorFactory.TPCH_COLUMN_NAMING_PROPERTY; @@ -31,12 +32,14 @@ import static io.trino.testing.statistics.MetricComparisonStrategies.relativeError; import static io.trino.testing.statistics.Metrics.OUTPUT_ROW_COUNT; import static io.trino.testing.statistics.Metrics.distinctValuesCount; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; +@TestInstance(PER_CLASS) public class TestTpchDistributedStats { private StatisticsAssertion statisticsAssertion; - @BeforeClass + @BeforeAll public void setup() throws Exception { @@ -52,7 +55,7 @@ public void setup() statisticsAssertion = new StatisticsAssertion(runner); } - @AfterClass(alwaysRun = true) + @AfterAll public void tearDown() { statisticsAssertion.close(); diff --git a/testing/trino-tests/src/test/java/io/trino/tests/tpch/TestTpchLocalStats.java b/testing/trino-tests/src/test/java/io/trino/tests/tpch/TestTpchLocalStats.java index dc3e2f621ae3..5595dd78506b 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/tpch/TestTpchLocalStats.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/tpch/TestTpchLocalStats.java @@ -19,9 +19,10 @@ import io.trino.plugin.tpch.TpchConnectorFactory; import io.trino.testing.LocalQueryRunner; import io.trino.testing.statistics.StatisticsAssertion; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import static io.trino.SystemSessionProperties.COLLECT_PLAN_STATISTICS_FOR_ALL_QUERIES; import static io.trino.plugin.tpch.TpchConnectorFactory.TPCH_COLUMN_NAMING_PROPERTY; @@ -36,12 +37,14 @@ import static io.trino.testing.statistics.Metrics.highValue; import static io.trino.testing.statistics.Metrics.lowValue; import static io.trino.testing.statistics.Metrics.nullsFraction; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; +@TestInstance(PER_CLASS) public class TestTpchLocalStats { private StatisticsAssertion statisticsAssertion; - @BeforeClass + @BeforeAll public void setUp() { Session defaultSession = testSessionBuilder() @@ -59,7 +62,7 @@ public void setUp() statisticsAssertion = new StatisticsAssertion(queryRunner); } - @AfterClass(alwaysRun = true) + @AfterAll public void tearDown() { statisticsAssertion.close(); diff --git a/testing/trino-tests/src/test/java/io/trino/tests/tpch/TestTpchTableScanRedirection.java b/testing/trino-tests/src/test/java/io/trino/tests/tpch/TestTpchTableScanRedirection.java index a8fb3672ec22..7a8abdb94886 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/tpch/TestTpchTableScanRedirection.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/tpch/TestTpchTableScanRedirection.java @@ -17,7 +17,8 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.DistributedQueryRunner; import io.trino.testing.QueryRunner; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import static org.testng.Assert.assertEquals; @@ -40,7 +41,8 @@ protected QueryRunner createQueryRunner() return queryRunner; } - @Test(timeOut = 20_000) + @Test + @Timeout(20) public void testTableScanRedirection() { // select orderstatus, count(*) from tpch.tiny.orders group by 1 @@ -52,7 +54,8 @@ public void testTableScanRedirection() assertEquals(computeActual("SELECT * FROM tpch.tiny.orders WHERE orderstatus IN ('O', 'F')").getRowCount(), 7333L); } - @Test(timeOut = 20_000) + @Test + @Timeout(20) public void testTableScanRedirectionWithCoercion() { assertUpdate("CREATE TABLE memory.test.nation AS SELECT * FROM (VALUES '42') t(nationkey)", 1L);