diff --git a/plugin/trino-iceberg/pom.xml b/plugin/trino-iceberg/pom.xml index 51bb22aa68609..47353e1a5d695 100644 --- a/plugin/trino-iceberg/pom.xml +++ b/plugin/trino-iceberg/pom.xml @@ -576,6 +576,12 @@ test + + org.junit.jupiter + junit-jupiter-params + test + + org.testcontainers postgresql diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergBucketing.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergBucketing.java index 7e838208c6cc4..fc51c86be43af 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergBucketing.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergBucketing.java @@ -30,8 +30,9 @@ import org.apache.iceberg.types.Types.DecimalType; import org.apache.iceberg.types.Types.DoubleType; import org.apache.iceberg.types.Types.FloatType; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.math.BigDecimal; import java.nio.ByteBuffer; @@ -187,7 +188,8 @@ public void testBucketingSpecValues() assertBucketAndHashEquals("binary", ByteBuffer.wrap(new byte[] {0x00, 0x01, 0x02, 0x03}), -188683207 & Integer.MAX_VALUE); } - @Test(dataProvider = "unsupportedBucketingTypes") + @ParameterizedTest + @MethodSource("unsupportedBucketingTypes") public void testUnsupportedTypes(Type type) { assertThatThrownBy(() -> computeIcebergBucket(type, null, 1)) @@ -197,8 +199,7 @@ public void testUnsupportedTypes(Type type) .hasMessage("Unsupported type for 'bucket': %s", toTrinoType(type, TYPE_MANAGER)); } - @DataProvider - public Object[][] unsupportedBucketingTypes() + public static Object[][] unsupportedBucketingTypes() { return new Object[][] { {BooleanType.get()}, diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetadataFileOperations.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergFileOperations.java similarity index 97% rename from plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetadataFileOperations.java rename to plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergFileOperations.java index eddd2a409eaeb..85e39e03ebe8b 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetadataFileOperations.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergFileOperations.java @@ -29,8 +29,11 @@ import io.trino.testing.DistributedQueryRunner; import org.apache.iceberg.util.ThreadPools; import org.intellij.lang.annotations.Language; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.io.File; import java.util.Optional; @@ -49,14 +52,14 @@ import static io.trino.plugin.hive.metastore.file.TestingFileHiveMetastore.createTestingFileHiveMetastore; import static io.trino.plugin.iceberg.IcebergQueryRunner.ICEBERG_CATALOG; import static io.trino.plugin.iceberg.IcebergSessionProperties.COLLECT_EXTENDED_STATISTICS_ON_WRITE; -import static io.trino.plugin.iceberg.TestIcebergMetadataFileOperations.FileType.DATA; -import static io.trino.plugin.iceberg.TestIcebergMetadataFileOperations.FileType.MANIFEST; -import static io.trino.plugin.iceberg.TestIcebergMetadataFileOperations.FileType.METADATA_JSON; -import static io.trino.plugin.iceberg.TestIcebergMetadataFileOperations.FileType.SNAPSHOT; -import static io.trino.plugin.iceberg.TestIcebergMetadataFileOperations.FileType.STATS; -import static io.trino.plugin.iceberg.TestIcebergMetadataFileOperations.FileType.fromFilePath; -import static io.trino.plugin.iceberg.TestIcebergMetadataFileOperations.Scope.ALL_FILES; -import static io.trino.plugin.iceberg.TestIcebergMetadataFileOperations.Scope.METADATA_FILES; +import static io.trino.plugin.iceberg.TestIcebergFileOperations.FileType.DATA; +import static io.trino.plugin.iceberg.TestIcebergFileOperations.FileType.MANIFEST; +import static io.trino.plugin.iceberg.TestIcebergFileOperations.FileType.METADATA_JSON; +import static io.trino.plugin.iceberg.TestIcebergFileOperations.FileType.SNAPSHOT; +import static io.trino.plugin.iceberg.TestIcebergFileOperations.FileType.STATS; +import static io.trino.plugin.iceberg.TestIcebergFileOperations.FileType.fromFilePath; +import static io.trino.plugin.iceberg.TestIcebergFileOperations.Scope.ALL_FILES; +import static io.trino.plugin.iceberg.TestIcebergFileOperations.Scope.METADATA_FILES; import static io.trino.testing.MultisetAssertions.assertMultisetsEqual; import static io.trino.testing.TestingNames.randomNameSuffix; import static io.trino.testing.TestingSession.testSessionBuilder; @@ -66,8 +69,8 @@ import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.toCollection; -@Test(singleThreaded = true) // e.g. trackingFileSystemFactory is shared mutable state -public class TestIcebergMetadataFileOperations +@Execution(ExecutionMode.SAME_THREAD) // e.g. trackingFileSystemFactory is shared mutable state +public class TestIcebergFileOperations extends AbstractTestQueryFramework { private static final int MAX_PREFIXES_COUNT = 10; @@ -167,7 +170,8 @@ public void testSelect() .build()); } - @Test(dataProvider = "testSelectWithLimitDataProvider") + @ParameterizedTest + @MethodSource("testSelectWithLimitDataProvider") public void testSelectWithLimit(int numberOfFiles) { assertUpdate("DROP TABLE IF EXISTS test_select_with_limit"); // test is parameterized @@ -210,7 +214,6 @@ public void testSelectWithLimit(int numberOfFiles) assertUpdate("DROP TABLE test_select_with_limit"); } - @DataProvider public Object[][] testSelectWithLimitDataProvider() { return new Object[][] { @@ -594,7 +597,8 @@ public void testRemoveOrphanFiles() assertUpdate("DROP TABLE " + tableName); } - @Test(dataProvider = "metadataQueriesTestTableCountDataProvider") + @ParameterizedTest + @MethodSource("metadataQueriesTestTableCountDataProvider") public void testInformationSchemaColumns(int tables) { String schemaName = "test_i_s_columns_schema" + randomNameSuffix(); @@ -636,7 +640,8 @@ public void testInformationSchemaColumns(int tables) } } - @Test(dataProvider = "metadataQueriesTestTableCountDataProvider") + @ParameterizedTest + @MethodSource("metadataQueriesTestTableCountDataProvider") public void testSystemMetadataTableComments(int tables) { String schemaName = "test_s_m_table_comments" + randomNameSuffix(); @@ -678,7 +683,6 @@ public void testSystemMetadataTableComments(int tables) } } - @DataProvider public Object[][] metadataQueriesTestTableCountDataProvider() { return new Object[][] { diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetastoreAccessOperations.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetastoreAccessOperations.java index 5a759f9185322..58beead75d31c 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetastoreAccessOperations.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetastoreAccessOperations.java @@ -22,8 +22,11 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.DistributedQueryRunner; import org.intellij.lang.annotations.Language; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.io.File; import java.util.Optional; @@ -50,7 +53,7 @@ import static io.trino.testing.TestingSession.testSessionBuilder; import static org.assertj.core.api.Assertions.assertThat; -@Test(singleThreaded = true) // metastore invocation counters shares mutable state so can't be run from many threads simultaneously +@Execution(ExecutionMode.SAME_THREAD) // metastore invocation counters shares mutable state so can't be run from many threads simultaneously public class TestIcebergMetastoreAccessOperations extends AbstractTestQueryFramework { @@ -326,7 +329,8 @@ public void testUnregisterTable() .build()); } - @Test(dataProvider = "metadataQueriesTestTableCountDataProvider") + @ParameterizedTest + @MethodSource("metadataQueriesTestTableCountDataProvider") public void testInformationSchemaColumns(int tables) { String schemaName = "test_i_s_columns_schema" + randomNameSuffix(); @@ -371,7 +375,8 @@ public void testInformationSchemaColumns(int tables) } } - @Test(dataProvider = "metadataQueriesTestTableCountDataProvider") + @ParameterizedTest + @MethodSource("metadataQueriesTestTableCountDataProvider") public void testSystemMetadataTableComments(int tables) { String schemaName = "test_s_m_table_comments" + randomNameSuffix(); @@ -417,7 +422,6 @@ public void testSystemMetadataTableComments(int tables) } } - @DataProvider public Object[][] metadataQueriesTestTableCountDataProvider() { return new Object[][] { diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMigrateProcedure.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMigrateProcedure.java index 4fcf249e78da4..10dcb3c5193cd 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMigrateProcedure.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMigrateProcedure.java @@ -19,8 +19,9 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.DistributedQueryRunner; import io.trino.testing.QueryRunner; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.nio.file.Files; import java.nio.file.Path; @@ -47,14 +48,15 @@ protected QueryRunner createQueryRunner() DistributedQueryRunner queryRunner = IcebergQueryRunner.builder().setMetastoreDirectory(dataDirectory.toFile()).build(); queryRunner.installPlugin(new TestingHivePlugin()); queryRunner.createCatalog("hive", "hive", ImmutableMap.builder() - .put("hive.metastore", "file") - .put("hive.metastore.catalog.dir", dataDirectory.toString()) - .put("hive.security", "allow-all") + .put("hive.metastore", "file") + .put("hive.metastore.catalog.dir", dataDirectory.toString()) + .put("hive.security", "allow-all") .buildOrThrow()); return queryRunner; } - @Test(dataProvider = "fileFormats") + @ParameterizedTest + @MethodSource("fileFormats") public void testMigrateTable(IcebergFileFormat fileFormat) { String tableName = "test_migrate_" + randomNameSuffix(); @@ -78,7 +80,8 @@ public void testMigrateTable(IcebergFileFormat fileFormat) assertUpdate("DROP TABLE " + tableName); } - @Test(dataProvider = "fileFormats") + @ParameterizedTest + @MethodSource("fileFormats") public void testMigrateTableWithTinyintType(IcebergFileFormat fileFormat) { String tableName = "test_migrate_tinyint" + randomNameSuffix(); @@ -105,7 +108,8 @@ public void testMigrateTableWithTinyintType(IcebergFileFormat fileFormat) assertUpdate("DROP TABLE " + tableName); } - @Test(dataProvider = "fileFormats") + @ParameterizedTest + @MethodSource("fileFormats") public void testMigrateTableWithSmallintType(IcebergFileFormat fileFormat) { String tableName = "test_migrate_smallint" + randomNameSuffix(); @@ -132,7 +136,6 @@ public void testMigrateTableWithSmallintType(IcebergFileFormat fileFormat) assertUpdate("DROP TABLE " + tableName); } - @DataProvider public static Object[][] fileFormats() { return Stream.of(IcebergFileFormat.values()) diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergRegisterTableProcedure.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergRegisterTableProcedure.java index 701480917dbfe..e739d576b140a 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergRegisterTableProcedure.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergRegisterTableProcedure.java @@ -32,10 +32,11 @@ import org.apache.iceberg.Table; import org.apache.iceberg.hadoop.HadoopTables; import org.apache.iceberg.types.Types; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -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.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; import java.io.File; import java.io.IOException; @@ -43,7 +44,6 @@ import java.nio.file.Path; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Stream; import static com.google.common.base.Verify.verify; import static com.google.common.io.MoreFiles.deleteRecursively; @@ -80,28 +80,21 @@ protected QueryRunner createQueryRunner() .build(); } - @BeforeClass + @BeforeAll public void initFileSystem() { fileSystem = getFileSystemFactory(getDistributedQueryRunner()).create(SESSION); } - @AfterClass(alwaysRun = true) + @AfterAll public void tearDown() throws IOException { deleteRecursively(metastoreDir.toPath(), ALLOW_INSECURE); } - @DataProvider - public static Object[][] fileFormats() - { - return Stream.of(IcebergFileFormat.values()) - .map(icebergFileFormat -> new Object[] {icebergFileFormat}) - .toArray(Object[][]::new); - } - - @Test(dataProvider = "fileFormats") + @ParameterizedTest + @EnumSource(IcebergFileFormat.class) public void testRegisterTableWithTableLocation(IcebergFileFormat icebergFileFormat) { String tableName = "test_register_table_with_table_location_" + icebergFileFormat.name().toLowerCase(ENGLISH) + "_" + randomNameSuffix(); @@ -123,7 +116,8 @@ public void testRegisterTableWithTableLocation(IcebergFileFormat icebergFileForm assertUpdate(format("DROP TABLE %s", tableName)); } - @Test(dataProvider = "fileFormats") + @ParameterizedTest + @EnumSource(IcebergFileFormat.class) public void testRegisterPartitionedTable(IcebergFileFormat icebergFileFormat) { String tableName = "test_register_partitioned_table_" + icebergFileFormat.name().toLowerCase(ENGLISH) + "_" + randomNameSuffix(); @@ -145,7 +139,8 @@ public void testRegisterPartitionedTable(IcebergFileFormat icebergFileFormat) assertUpdate("DROP TABLE " + tableName); } - @Test(dataProvider = "fileFormats") + @ParameterizedTest + @EnumSource(IcebergFileFormat.class) public void testRegisterTableWithComments(IcebergFileFormat icebergFileFormat) { String tableName = "test_register_table_with_comments_" + icebergFileFormat.name().toLowerCase(ENGLISH) + "_" + randomNameSuffix(); @@ -171,7 +166,8 @@ public void testRegisterTableWithComments(IcebergFileFormat icebergFileFormat) assertUpdate(format("DROP TABLE %s", tableName)); } - @Test(dataProvider = "fileFormats") + @ParameterizedTest + @EnumSource(IcebergFileFormat.class) public void testRegisterTableWithShowCreateTable(IcebergFileFormat icebergFileFormat) { String tableName = "test_register_table_with_show_create_table_" + icebergFileFormat.name().toLowerCase(ENGLISH) + "_" + randomNameSuffix(); @@ -191,7 +187,8 @@ public void testRegisterTableWithShowCreateTable(IcebergFileFormat icebergFileFo assertUpdate(format("DROP TABLE %s", tableName)); } - @Test(dataProvider = "fileFormats") + @ParameterizedTest + @EnumSource(IcebergFileFormat.class) public void testRegisterTableWithReInsert(IcebergFileFormat icebergFileFormat) { String tableName = "test_register_table_with_re_insert_" + icebergFileFormat.name().toLowerCase(ENGLISH) + "_" + randomNameSuffix(); @@ -215,7 +212,8 @@ public void testRegisterTableWithReInsert(IcebergFileFormat icebergFileFormat) assertUpdate(format("DROP TABLE %s", tableName)); } - @Test(dataProvider = "fileFormats") + @ParameterizedTest + @EnumSource(IcebergFileFormat.class) public void testRegisterTableWithDroppedTable(IcebergFileFormat icebergFileFormat) { String tableName = "test_register_table_with_dropped_table_" + icebergFileFormat.name().toLowerCase(ENGLISH) + "_" + randomNameSuffix(); @@ -233,7 +231,8 @@ public void testRegisterTableWithDroppedTable(IcebergFileFormat icebergFileForma ".*No versioned metadata file exists at location.*"); } - @Test(dataProvider = "fileFormats") + @ParameterizedTest + @EnumSource(IcebergFileFormat.class) public void testRegisterTableWithDifferentTableName(IcebergFileFormat icebergFileFormat) { String tableName = "test_register_table_with_different_table_name_old_" + icebergFileFormat.name().toLowerCase(ENGLISH) + "_" + randomNameSuffix(); @@ -258,7 +257,8 @@ public void testRegisterTableWithDifferentTableName(IcebergFileFormat icebergFil assertUpdate(format("DROP TABLE %s", tableNameNew)); } - @Test(dataProvider = "fileFormats") + @ParameterizedTest + @EnumSource(IcebergFileFormat.class) public void testRegisterTableWithMetadataFile(IcebergFileFormat icebergFileFormat) { String tableName = "test_register_table_with_metadata_file_" + icebergFileFormat.name().toLowerCase(ENGLISH) + "_" + randomNameSuffix(); diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergStatistics.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergStatistics.java index 30bb2574bb8b5..b3b96f258f896 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergStatistics.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergStatistics.java @@ -17,10 +17,11 @@ import com.google.common.math.IntMath; import io.trino.Session; import io.trino.testing.AbstractTestQueryFramework; -import io.trino.testing.DataProviders; import io.trino.testing.QueryRunner; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ValueSource; import java.util.List; @@ -53,7 +54,8 @@ protected QueryRunner createQueryRunner() .build(); } - @Test(dataProviderClass = DataProviders.class, dataProvider = "trueFalse") + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void testAnalyze(boolean collectOnStatsOnWrites) { Session writeSession = withStatsOnWrite(getSession(), collectOnStatsOnWrites); @@ -172,7 +174,8 @@ public void testAnalyzeWithSchemaEvolution() assertUpdate("DROP TABLE " + tableName); } - @Test(dataProviderClass = DataProviders.class, dataProvider = "trueFalse") + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void testAnalyzePartitioned(boolean collectOnStatsOnWrites) { Session writeSession = withStatsOnWrite(getSession(), collectOnStatsOnWrites); @@ -298,7 +301,8 @@ public void testAnalyzeEmpty() assertUpdate("DROP TABLE " + tableName); } - @Test(dataProvider = "testCollectStatisticsOnWriteDataProvider") + @ParameterizedTest + @MethodSource("testCollectStatisticsOnWriteDataProvider") public void testCollectStatisticsOnWrite(boolean collectOnStatsOnCreateTable, boolean partitioned) { String tableName = "test_collect_stats_insert_" + collectOnStatsOnCreateTable + partitioned; @@ -353,7 +357,8 @@ public void testCollectStatisticsOnWrite(boolean collectOnStatsOnCreateTable, bo assertUpdate("DROP TABLE " + tableName); } - @Test(dataProvider = "testCollectStatisticsOnWriteDataProvider") + @ParameterizedTest + @MethodSource("testCollectStatisticsOnWriteDataProvider") public void testCollectStatisticsOnWriteToEmptyTable(boolean collectOnStatsOnCreateTable, boolean partitioned) { String tableName = "test_collect_stats_insert_into_empty_" + collectOnStatsOnCreateTable + partitioned; @@ -389,13 +394,13 @@ public void testCollectStatisticsOnWriteToEmptyTable(boolean collectOnStatsOnCre assertUpdate("DROP TABLE " + tableName); } - @DataProvider public Object[][] testCollectStatisticsOnWriteDataProvider() { return cartesianProduct(trueFalse(), trueFalse()); } - @Test(dataProviderClass = DataProviders.class, dataProvider = "trueFalse") + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void testAnalyzeAfterStatsDrift(boolean withOptimize) { String tableName = "test_analyze_stats_drift_" + withOptimize; diff --git a/testing/trino-testing-services/src/main/java/io/trino/testng/services/ReportBadTestAnnotations.java b/testing/trino-testing-services/src/main/java/io/trino/testng/services/ReportBadTestAnnotations.java index 0c9470c50127a..8ee1d334927dc 100644 --- a/testing/trino-testing-services/src/main/java/io/trino/testng/services/ReportBadTestAnnotations.java +++ b/testing/trino-testing-services/src/main/java/io/trino/testng/services/ReportBadTestAnnotations.java @@ -204,7 +204,7 @@ private static boolean isTestAnnotated(Method method) private static boolean isJUnitAnnotation(Class clazz) { - return clazz.getPackage().getName().startsWith("org.junit.jupiter.api"); + return clazz.getPackage().getName().startsWith("org.junit.jupiter."); } @VisibleForTesting