From 37e7b18a1c4627a94fb6e61a6f7e37cb2f6dab03 Mon Sep 17 00:00:00 2001 From: Martin Traverso Date: Tue, 14 Nov 2023 13:30:18 -0800 Subject: [PATCH 1/3] Remove unnecessary data provider --- .../io/trino/execution/TestNodeScheduler.java | 35 +++-- .../hive/coercions/TestDecimalCoercers.java | 66 +++++----- ...TestTrinoS3FileSystemAccessOperations.java | 120 +++++++++--------- .../BaseIcebergMaterializedViewTest.java | 90 ++++++------- .../plugin/ignite/TestIgniteTypeMapping.java | 42 +++--- .../plugin/kafka/TestKafkaSecurityConfig.java | 32 ++--- ...TestMillisecondsJsonDateTimeFormatter.java | 56 ++++---- .../TestSecondsJsonDateTimeFormatter.java | 58 ++++----- .../plugin/kinesis/TestRecordAccess.java | 22 ++-- .../mariadb/TestMariaDbTypeMapping.java | 58 +++++---- 10 files changed, 268 insertions(+), 311 deletions(-) diff --git a/core/trino-main/src/test/java/io/trino/execution/TestNodeScheduler.java b/core/trino-main/src/test/java/io/trino/execution/TestNodeScheduler.java index 4d35bf58773d..e6a1caa32fd4 100644 --- a/core/trino-main/src/test/java/io/trino/execution/TestNodeScheduler.java +++ b/core/trino-main/src/test/java/io/trino/execution/TestNodeScheduler.java @@ -49,7 +49,6 @@ import io.trino.util.FinalizerService; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.net.InetAddress; @@ -652,27 +651,27 @@ public void testEquateDistribution() assertEquals(assignment.get(node4).size(), 4); } - @DataProvider - public static Object[][] equateDistributionTestParameters() + @Test + public void testEquateDistributionConsistentHashing() { - return new Object[][] { - {5, 10, 0.00}, - {5, 20, 0.055}, - {10, 50, 0.00}, - {10, 100, 0.045}, - {10, 200, 0.090}, - {50, 550, 0.045}, - {50, 600, 0.047}, - {50, 700, 0.045}, - {100, 550, 0.036}, - {100, 600, 0.054}, - {100, 1000, 0.039}, - {100, 1500, 0.045}}; + testEquateDistributionConsistentHashing(5, 10, 0.00); + testEquateDistributionConsistentHashing(5, 20, 0.055); + testEquateDistributionConsistentHashing(10, 50, 0.00); + testEquateDistributionConsistentHashing(10, 100, 0.045); + testEquateDistributionConsistentHashing(10, 200, 0.090); + testEquateDistributionConsistentHashing(50, 550, 0.045); + testEquateDistributionConsistentHashing(50, 600, 0.047); + testEquateDistributionConsistentHashing(50, 700, 0.045); + testEquateDistributionConsistentHashing(100, 550, 0.036); + testEquateDistributionConsistentHashing(100, 600, 0.054); + testEquateDistributionConsistentHashing(100, 1000, 0.039); + testEquateDistributionConsistentHashing(100, 1500, 0.045); } - @Test(dataProvider = "equateDistributionTestParameters") - public void testEquateDistributionConsistentHashing(int numberOfNodes, int numberOfSplits, double misassignedSplitsRatio) + private void testEquateDistributionConsistentHashing(int numberOfNodes, int numberOfSplits, double misassignedSplitsRatio) { + setUp(); + ImmutableList.Builder nodesBuilder = ImmutableList.builder(); for (int i = 0; i < numberOfNodes; ++i) { InternalNode node = new InternalNode("node" + i, URI.create("http://10.0.0.1:" + (i + 10)), NodeVersion.UNKNOWN, false); diff --git a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/coercions/TestDecimalCoercers.java b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/coercions/TestDecimalCoercers.java index dbd7b87cb697..4e08b96884f2 100644 --- a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/coercions/TestDecimalCoercers.java +++ b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/coercions/TestDecimalCoercers.java @@ -17,7 +17,6 @@ import io.trino.spi.type.DecimalParseResult; import io.trino.spi.type.Decimals; import io.trino.spi.type.Type; -import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static io.trino.plugin.hive.HiveTimestampPrecision.NANOSECONDS; @@ -34,8 +33,37 @@ public class TestDecimalCoercers { - @Test(dataProvider = "dataProvider") - public void testDecimalToIntCoercion(String decimalString, Type coercedType, Object expectedValue) + @Test + public void testDecimalToIntCoercion() + { + testDecimalToIntCoercion("12.120000000000000000", TINYINT, 12L); + testDecimalToIntCoercion("-12.120000000000000000", TINYINT, -12L); + testDecimalToIntCoercion("12.120", TINYINT, 12L); + testDecimalToIntCoercion("-12.120", TINYINT, -12L); + testDecimalToIntCoercion("141.120000000000000000", TINYINT, null); + testDecimalToIntCoercion("-141.120", TINYINT, null); + testDecimalToIntCoercion("130.120000000000000000", SMALLINT, 130L); + testDecimalToIntCoercion("-130.120000000000000000", SMALLINT, -130L); + testDecimalToIntCoercion("130.120", SMALLINT, 130L); + testDecimalToIntCoercion("-130.120", SMALLINT, -130L); + testDecimalToIntCoercion("66000.30120000000000000", SMALLINT, null); + testDecimalToIntCoercion("-66000.120", SMALLINT, null); + testDecimalToIntCoercion("33000.12000000000000000", INTEGER, 33000L); + testDecimalToIntCoercion("-33000.12000000000000000", INTEGER, -33000L); + testDecimalToIntCoercion("33000.120", INTEGER, 33000L); + testDecimalToIntCoercion("-33000.120", INTEGER, -33000L); + testDecimalToIntCoercion("3300000000.1200000000000", INTEGER, null); + testDecimalToIntCoercion("3300000000.120", INTEGER, null); + testDecimalToIntCoercion("3300000000.1200000000000", BIGINT, 3300000000L); + testDecimalToIntCoercion("-3300000000.120000000000", BIGINT, -3300000000L); + testDecimalToIntCoercion("3300000000.12", BIGINT, 3300000000L); + testDecimalToIntCoercion("-3300000000.12", BIGINT, -3300000000L); + testDecimalToIntCoercion("330000000000000000000.12000000000", BIGINT, null); + testDecimalToIntCoercion("-330000000000000000000.12000000000", BIGINT, null); + testDecimalToIntCoercion("3300000", INTEGER, 3300000L); + } + + private void testDecimalToIntCoercion(String decimalString, Type coercedType, Object expectedValue) { DecimalParseResult parseResult = Decimals.parse(decimalString); @@ -48,38 +76,6 @@ public void testDecimalToIntCoercion(String decimalString, Type coercedType, Obj assertDecimalToIntCoercion(parseResult.getType(), parseResult.getObject(), coercedType, expectedValue); } - @DataProvider - public static Object[][] dataProvider() - { - return new Object[][] { - {"12.120000000000000000", TINYINT, 12L}, - {"-12.120000000000000000", TINYINT, -12L}, - {"12.120", TINYINT, 12L}, - {"-12.120", TINYINT, -12L}, - {"141.120000000000000000", TINYINT, null}, - {"-141.120", TINYINT, null}, - {"130.120000000000000000", SMALLINT, 130L}, - {"-130.120000000000000000", SMALLINT, -130L}, - {"130.120", SMALLINT, 130L}, - {"-130.120", SMALLINT, -130L}, - {"66000.30120000000000000", SMALLINT, null}, - {"-66000.120", SMALLINT, null}, - {"33000.12000000000000000", INTEGER, 33000L}, - {"-33000.12000000000000000", INTEGER, -33000L}, - {"33000.120", INTEGER, 33000L}, - {"-33000.120", INTEGER, -33000L}, - {"3300000000.1200000000000", INTEGER, null}, - {"3300000000.120", INTEGER, null}, - {"3300000000.1200000000000", BIGINT, 3300000000L}, - {"-3300000000.120000000000", BIGINT, -3300000000L}, - {"3300000000.12", BIGINT, 3300000000L}, - {"-3300000000.12", BIGINT, -3300000000L}, - {"330000000000000000000.12000000000", BIGINT, null}, - {"-330000000000000000000.12000000000", BIGINT, null}, - {"3300000", INTEGER, 3300000L}, - }; - } - private void assertDecimalToIntCoercion(Type fromType, Object valueToBeCoerced, Type toType, Object expectedValue) { Block coercedValue = createCoercer(TESTING_TYPE_MANAGER, toHiveType(fromType), toHiveType(toType), new CoercionUtils.CoercionContext(NANOSECONDS, false)).orElseThrow() diff --git a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/s3/TestTrinoS3FileSystemAccessOperations.java b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/s3/TestTrinoS3FileSystemAccessOperations.java index e094ef14ea7b..960f6b54d324 100644 --- a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/s3/TestTrinoS3FileSystemAccessOperations.java +++ b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/s3/TestTrinoS3FileSystemAccessOperations.java @@ -36,16 +36,13 @@ import io.trino.testing.containers.Minio; import org.intellij.lang.annotations.Language; import org.testng.annotations.AfterClass; -import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.io.File; -import java.util.Arrays; import static com.google.common.base.Preconditions.checkArgument; import static io.trino.plugin.hive.HiveQueryRunner.TPCH_SCHEMA; import static io.trino.plugin.hive.HiveTestUtils.HDFS_FILE_SYSTEM_FACTORY; -import static io.trino.testing.DataProviders.toDataProvider; import static io.trino.testing.MultisetAssertions.assertMultisetsEqual; import static io.trino.testing.TestingNames.randomNameSuffix; import static io.trino.testing.containers.Minio.MINIO_ACCESS_KEY; @@ -111,63 +108,67 @@ public void tearDown() minio = null; } - @Test(dataProvider = "storageFormats") - public void testSelectWithFilter(StorageFormat format) + @Test + public void testSelectWithFilter() { - assertUpdate("DROP TABLE IF EXISTS test_select_from_where"); - String tableLocation = randomTableLocation("test_select_from_where"); - - assertUpdate("CREATE TABLE test_select_from_where WITH (format = '" + format + "', external_location = '" + tableLocation + "') AS SELECT 2 AS age", 1); - - assertFileSystemAccesses( - withSmallFileThreshold(getSession(), DataSize.valueOf("1MB")), // large enough threshold for single request of small file - "SELECT * FROM test_select_from_where WHERE age = 2", - ImmutableMultiset.builder() - .add("S3.GetObject") - .add("S3.ListObjectsV2") - .build()); - - assertFileSystemAccesses( - withSmallFileThreshold(getSession(), DataSize.valueOf("10B")), // disables single request for small file - "SELECT * FROM test_select_from_where WHERE age = 2", - ImmutableMultiset.builder() - .addCopies("S3.GetObject", occurrences(format, 3, 2)) - .add("S3.ListObjectsV2") - .build()); - - assertUpdate("DROP TABLE test_select_from_where"); + for (StorageFormat format : StorageFormat.values()) { + assertUpdate("DROP TABLE IF EXISTS test_select_from_where"); + String tableLocation = randomTableLocation("test_select_from_where"); + + assertUpdate("CREATE TABLE test_select_from_where WITH (format = '" + format + "', external_location = '" + tableLocation + "') AS SELECT 2 AS age", 1); + + assertFileSystemAccesses( + withSmallFileThreshold(getSession(), DataSize.valueOf("1MB")), // large enough threshold for single request of small file + "SELECT * FROM test_select_from_where WHERE age = 2", + ImmutableMultiset.builder() + .add("S3.GetObject") + .add("S3.ListObjectsV2") + .build()); + + assertFileSystemAccesses( + withSmallFileThreshold(getSession(), DataSize.valueOf("10B")), // disables single request for small file + "SELECT * FROM test_select_from_where WHERE age = 2", + ImmutableMultiset.builder() + .addCopies("S3.GetObject", occurrences(format, 3, 2)) + .add("S3.ListObjectsV2") + .build()); + + assertUpdate("DROP TABLE test_select_from_where"); + } } - @Test(dataProvider = "storageFormats") - public void testSelectPartitionTable(StorageFormat format) + @Test + public void testSelectPartitionTable() { - assertUpdate("DROP TABLE IF EXISTS test_select_from_partition"); - String tableLocation = randomTableLocation("test_select_from_partition"); - - assertUpdate("CREATE TABLE test_select_from_partition (data int, key varchar)" + - "WITH (partitioned_by = ARRAY['key'], format = '" + format + "', external_location = '" + tableLocation + "')"); - assertUpdate("INSERT INTO test_select_from_partition VALUES (1, 'part1'), (2, 'part2')", 2); - - assertFileSystemAccesses("SELECT * FROM test_select_from_partition", - ImmutableMultiset.builder() - .addCopies("S3.GetObject", 2) - .addCopies("S3.ListObjectsV2", 2) - .build()); - - assertFileSystemAccesses("SELECT * FROM test_select_from_partition WHERE key = 'part1'", - ImmutableMultiset.builder() - .add("S3.GetObject") - .add("S3.ListObjectsV2") - .build()); - - assertUpdate("INSERT INTO test_select_from_partition VALUES (11, 'part1')", 1); - assertFileSystemAccesses("SELECT * FROM test_select_from_partition WHERE key = 'part1'", - ImmutableMultiset.builder() - .addCopies("S3.GetObject", 2) - .addCopies("S3.ListObjectsV2", 1) - .build()); - - assertUpdate("DROP TABLE test_select_from_partition"); + for (StorageFormat format : StorageFormat.values()) { + assertUpdate("DROP TABLE IF EXISTS test_select_from_partition"); + String tableLocation = randomTableLocation("test_select_from_partition"); + + assertUpdate("CREATE TABLE test_select_from_partition (data int, key varchar)" + + "WITH (partitioned_by = ARRAY['key'], format = '" + format + "', external_location = '" + tableLocation + "')"); + assertUpdate("INSERT INTO test_select_from_partition VALUES (1, 'part1'), (2, 'part2')", 2); + + assertFileSystemAccesses("SELECT * FROM test_select_from_partition", + ImmutableMultiset.builder() + .addCopies("S3.GetObject", 2) + .addCopies("S3.ListObjectsV2", 2) + .build()); + + assertFileSystemAccesses("SELECT * FROM test_select_from_partition WHERE key = 'part1'", + ImmutableMultiset.builder() + .add("S3.GetObject") + .add("S3.ListObjectsV2") + .build()); + + assertUpdate("INSERT INTO test_select_from_partition VALUES (11, 'part1')", 1); + assertFileSystemAccesses("SELECT * FROM test_select_from_partition WHERE key = 'part1'", + ImmutableMultiset.builder() + .addCopies("S3.GetObject", 2) + .addCopies("S3.ListObjectsV2", 1) + .build()); + + assertUpdate("DROP TABLE test_select_from_partition"); + } } private static String randomTableLocation(String tableName) @@ -195,13 +196,6 @@ private Multiset getOperations() .collect(toCollection(HashMultiset::create)); } - @DataProvider - public static Object[][] storageFormats() - { - return Arrays.stream(StorageFormat.values()) - .collect(toDataProvider()); - } - private static int occurrences(StorageFormat tableType, int orcValue, int parquetValue) { checkArgument(!(orcValue == parquetValue), "No need to use Occurrences when ORC and Parquet"); diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergMaterializedViewTest.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergMaterializedViewTest.java index 7c0d00556143..c4f0e04e68ee 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergMaterializedViewTest.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergMaterializedViewTest.java @@ -27,7 +27,6 @@ import org.apache.iceberg.TableMetadataParser; import org.assertj.core.api.Condition; import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.nio.file.Path; @@ -598,8 +597,23 @@ public void testNestedMaterializedViews() assertUpdate("DROP MATERIALIZED VIEW materialized_view_level2"); } - @Test(dataProvider = "testBucketPartitioningDataProvider") - public void testBucketPartitioning(String dataType, String exampleValue) + @Test + public void testBucketPartitioning() + { + testBucketPartitioning("integer", "20050909"); + testBucketPartitioning("bigint", "200509091331001234"); + testBucketPartitioning("decimal(8,5)", "DECIMAL '876.54321'"); + testBucketPartitioning("decimal(28,21)", "DECIMAL '1234567.890123456789012345678'"); + testBucketPartitioning("date", "DATE '2005-09-09'"); + testBucketPartitioning("time(6)", "TIME '13:31:00.123456'"); + testBucketPartitioning("timestamp(6)", "TIMESTAMP '2005-09-10 13:31:00.123456'"); + testBucketPartitioning("timestamp(6) with time zone", "TIMESTAMP '2005-09-10 13:00:00.123456 Europe/Warsaw'"); + testBucketPartitioning("varchar", "VARCHAR 'Greetings from Warsaw!'"); + testBucketPartitioning("uuid", "UUID '406caec7-68b9-4778-81b2-a12ece70c8b1'"); + testBucketPartitioning("varbinary", "X'66696E6465706920726F636B7321'"); + } + + private void testBucketPartitioning(String dataType, String exampleValue) { // validate the example value type assertThat(query("SELECT " + exampleValue)) @@ -622,27 +636,17 @@ public void testBucketPartitioning(String dataType, String exampleValue) } } - @DataProvider - public Object[][] testBucketPartitioningDataProvider() + @Test + public void testTruncatePartitioning() { - // Iceberg supports bucket partitioning on int, long, decimal, date, time, timestamp, timestamptz, string, uuid, fixed, binary - return new Object[][] { - {"integer", "20050909"}, - {"bigint", "200509091331001234"}, - {"decimal(8,5)", "DECIMAL '876.54321'"}, - {"decimal(28,21)", "DECIMAL '1234567.890123456789012345678'"}, - {"date", "DATE '2005-09-09'"}, - {"time(6)", "TIME '13:31:00.123456'"}, - {"timestamp(6)", "TIMESTAMP '2005-09-10 13:31:00.123456'"}, - {"timestamp(6) with time zone", "TIMESTAMP '2005-09-10 13:00:00.123456 Europe/Warsaw'"}, - {"varchar", "VARCHAR 'Greetings from Warsaw!'"}, - {"uuid", "UUID '406caec7-68b9-4778-81b2-a12ece70c8b1'"}, - {"varbinary", "X'66696E6465706920726F636B7321'"}, - }; + testTruncatePartitioning("integer", "20050909"); + testTruncatePartitioning("bigint", "200509091331001234"); + testTruncatePartitioning("decimal(8,5)", "DECIMAL '876.54321'"); + testTruncatePartitioning("decimal(28,21)", "DECIMAL '1234567.890123456789012345678'"); + testTruncatePartitioning("varchar", "VARCHAR 'Greetings from Warsaw!'"); } - @Test(dataProvider = "testTruncatePartitioningDataProvider") - public void testTruncatePartitioning(String dataType, String exampleValue) + private void testTruncatePartitioning(String dataType, String exampleValue) { // validate the example value type assertThat(query("SELECT " + exampleValue)) @@ -665,21 +669,23 @@ public void testTruncatePartitioning(String dataType, String exampleValue) } } - @DataProvider - public Object[][] testTruncatePartitioningDataProvider() + @Test + public void testTemporalPartitioning() { - // Iceberg supports truncate partitioning on int, long, decimal, string - return new Object[][] { - {"integer", "20050909"}, - {"bigint", "200509091331001234"}, - {"decimal(8,5)", "DECIMAL '876.54321'"}, - {"decimal(28,21)", "DECIMAL '1234567.890123456789012345678'"}, - {"varchar", "VARCHAR 'Greetings from Warsaw!'"}, - }; + testTemporalPartitioning("year", "date", "DATE '2005-09-09'"); + testTemporalPartitioning("year", "timestamp(6)", "TIMESTAMP '2005-09-10 13:31:00.123456'"); + testTemporalPartitioning("year", "timestamp(6) with time zone", "TIMESTAMP '2005-09-10 13:00:00.123456 Europe/Warsaw'"); + testTemporalPartitioning("month", "date", "DATE '2005-09-09'"); + testTemporalPartitioning("month", "timestamp(6)", "TIMESTAMP '2005-09-10 13:31:00.123456'"); + testTemporalPartitioning("month", "timestamp(6) with time zone", "TIMESTAMP '2005-09-10 13:00:00.123456 Europe/Warsaw'"); + testTemporalPartitioning("day", "date", "DATE '2005-09-09'"); + testTemporalPartitioning("day", "timestamp(6)", "TIMESTAMP '2005-09-10 13:31:00.123456'"); + testTemporalPartitioning("day", "timestamp(6) with time zone", "TIMESTAMP '2005-09-10 13:00:00.123456 Europe/Warsaw'"); + testTemporalPartitioning("hour", "timestamp(6)", "TIMESTAMP '2005-09-10 13:31:00.123456'"); + testTemporalPartitioning("hour", "timestamp(6) with time zone", "TIMESTAMP '2005-09-10 13:00:00.123456 Europe/Warsaw'"); } - @Test(dataProvider = "testTemporalPartitioningDataProvider") - public void testTemporalPartitioning(String partitioning, String dataType, String exampleValue) + private void testTemporalPartitioning(String partitioning, String dataType, String exampleValue) { // validate the example value type assertThat(query("SELECT " + exampleValue)) @@ -702,24 +708,6 @@ public void testTemporalPartitioning(String partitioning, String dataType, Strin } } - @DataProvider - public Object[][] testTemporalPartitioningDataProvider() - { - return new Object[][] { - {"year", "date", "DATE '2005-09-09'"}, - {"year", "timestamp(6)", "TIMESTAMP '2005-09-10 13:31:00.123456'"}, - {"year", "timestamp(6) with time zone", "TIMESTAMP '2005-09-10 13:00:00.123456 Europe/Warsaw'"}, - {"month", "date", "DATE '2005-09-09'"}, - {"month", "timestamp(6)", "TIMESTAMP '2005-09-10 13:31:00.123456'"}, - {"month", "timestamp(6) with time zone", "TIMESTAMP '2005-09-10 13:00:00.123456 Europe/Warsaw'"}, - {"day", "date", "DATE '2005-09-09'"}, - {"day", "timestamp(6)", "TIMESTAMP '2005-09-10 13:31:00.123456'"}, - {"day", "timestamp(6) with time zone", "TIMESTAMP '2005-09-10 13:00:00.123456 Europe/Warsaw'"}, - {"hour", "timestamp(6)", "TIMESTAMP '2005-09-10 13:31:00.123456'"}, - {"hour", "timestamp(6) with time zone", "TIMESTAMP '2005-09-10 13:00:00.123456 Europe/Warsaw'"}, - }; - } - @Test public void testMaterializedViewSnapshotSummariesHaveTrinoQueryId() { diff --git a/plugin/trino-ignite/src/test/java/io/trino/plugin/ignite/TestIgniteTypeMapping.java b/plugin/trino-ignite/src/test/java/io/trino/plugin/ignite/TestIgniteTypeMapping.java index 37db793f4d5d..09ac97347e42 100644 --- a/plugin/trino-ignite/src/test/java/io/trino/plugin/ignite/TestIgniteTypeMapping.java +++ b/plugin/trino-ignite/src/test/java/io/trino/plugin/ignite/TestIgniteTypeMapping.java @@ -29,7 +29,6 @@ import io.trino.testing.sql.TrinoSqlExecutor; import org.intellij.lang.annotations.Language; import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.time.LocalDate; @@ -289,8 +288,18 @@ private static SqlDataTypeTest binaryTest(String inputType) .addRoundTrip(inputType, "X'000000000000'", VARBINARY, "X'000000000000'"); } - @Test(dataProvider = "sessionZonesDataProvider") - public void testDate(ZoneId sessionZone) + @Test + public void testDate() + { + testDate(UTC); + testDate(jvmZone); + // using two non-JVM zones so that we don't need to worry what Ignite system zone is + testDate(vilnius); + testDate(kathmandu); + testDate(TestingSession.DEFAULT_TIME_ZONE_KEY.getZoneId()); + } + + private void testDate(ZoneId sessionZone) { Session session = Session.builder(getSession()) .setTimeZoneKey(TimeZoneKey.getTimeZoneKey(sessionZone.getId())) @@ -314,8 +323,18 @@ public void testDate(ZoneId sessionZone) .execute(getQueryRunner(), session, igniteCreateAndInsert("test_date")); } - @Test(dataProvider = "sessionZonesDataProvider") - public void testUnsupportedDateRange(ZoneId sessionZone) + @Test + public void testUnsupportedDateRange() + { + testUnsupportedDateRange(UTC); + testUnsupportedDateRange(jvmZone); + // using two non-JVM zones so that we don't need to worry what Ignite system zone is + testUnsupportedDateRange(vilnius); + testUnsupportedDateRange(kathmandu); + testUnsupportedDateRange(TestingSession.DEFAULT_TIME_ZONE_KEY.getZoneId()); + } + + private void testUnsupportedDateRange(ZoneId sessionZone) { Session session = Session.builder(getSession()) .setTimeZoneKey(TimeZoneKey.getTimeZoneKey(sessionZone.getId())) @@ -404,19 +423,6 @@ public void testUnboundedVarchar() .execute(getQueryRunner(), trinoCreateAndInsert("test_unbounded_varchar")); } - @DataProvider - public Object[][] sessionZonesDataProvider() - { - return new Object[][] { - {UTC}, - {jvmZone}, - // using two non-JVM zones so that we don't need to worry what Ignite system zone is - {vilnius}, - {kathmandu}, - {TestingSession.DEFAULT_TIME_ZONE_KEY.getZoneId()}, - }; - } - private DataSetup trinoCreateAndInsert(String tableNamePrefix) { return trinoCreateAndInsert(createSession(), tableNamePrefix); diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaSecurityConfig.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaSecurityConfig.java index aec686861aee..391f3cf5d95f 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaSecurityConfig.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaSecurityConfig.java @@ -14,8 +14,6 @@ package io.trino.plugin.kafka; import com.google.common.collect.ImmutableMap; -import org.apache.kafka.common.security.auth.SecurityProtocol; -import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.util.Map; @@ -49,33 +47,31 @@ public void testExplicitPropertyMappings() assertFullMapping(properties, expected); } - @Test(dataProvider = "validSecurityProtocols") - public void testValidSecurityProtocols(SecurityProtocol securityProtocol) + @Test + public void testValidSecurityProtocols() { new KafkaSecurityConfig() - .setSecurityProtocol(securityProtocol) + .setSecurityProtocol(PLAINTEXT) .validate(); - } - @DataProvider(name = "validSecurityProtocols") - public Object[][] validSecurityProtocols() - { - return new Object[][] {{PLAINTEXT}, {SSL}}; + new KafkaSecurityConfig() + .setSecurityProtocol(SSL) + .validate(); } - @Test(dataProvider = "invalidSecurityProtocols") - public void testInvalidSecurityProtocol(SecurityProtocol securityProtocol) + @Test + public void testInvalidSecurityProtocol() { assertThatThrownBy(() -> new KafkaSecurityConfig() - .setSecurityProtocol(securityProtocol) + .setSecurityProtocol(SASL_PLAINTEXT) .validate()) .isInstanceOf(IllegalStateException.class) .hasMessage("Only PLAINTEXT and SSL security protocols are supported. See 'kafka.config.resources' if other security protocols are needed"); - } - @DataProvider(name = "invalidSecurityProtocols") - public Object[][] invalidSecurityProtocols() - { - return new Object[][] {{SASL_PLAINTEXT}, {SASL_SSL}}; + assertThatThrownBy(() -> new KafkaSecurityConfig() + .setSecurityProtocol(SASL_SSL) + .validate()) + .isInstanceOf(IllegalStateException.class) + .hasMessage("Only PLAINTEXT and SSL security protocols are supported. See 'kafka.config.resources' if other security protocols are needed"); } } diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestMillisecondsJsonDateTimeFormatter.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestMillisecondsJsonDateTimeFormatter.java index b19ab1021ffa..bc6613ae6cdc 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestMillisecondsJsonDateTimeFormatter.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestMillisecondsJsonDateTimeFormatter.java @@ -16,7 +16,6 @@ import io.trino.plugin.kafka.encoder.json.format.JsonDateTimeFormatter; import io.trino.spi.type.SqlTimestampWithTimeZone; import io.trino.spi.type.TimeZoneKey; -import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.time.LocalDateTime; @@ -42,56 +41,47 @@ private static JsonDateTimeFormatter getFormatter() return MILLISECONDS_SINCE_EPOCH.getFormatter(Optional.empty()); } - @Test(dataProvider = "testTimeProvider") - public void testTime(LocalTime time) + @Test + public void testTime() + { + testTime(LocalTime.of(15, 36, 25, 123000000)); + testTime(LocalTime.of(15, 36, 25, 0)); + } + + private void testTime(LocalTime time) { String formatted = getFormatter().formatTime(sqlTimeOf(3, time), 3); assertEquals(Long.parseLong(formatted), time.getLong(MILLI_OF_DAY)); } - @DataProvider - public Object[][] testTimeProvider() + @Test + public void testTimestamp() { - return new Object[][] { - {LocalTime.of(15, 36, 25, 123000000)}, - {LocalTime.of(15, 36, 25, 0)}, - }; + testTimestamp(LocalDateTime.of(2020, 8, 18, 12, 38, 29, 123000000)); + testTimestamp(LocalDateTime.of(1970, 1, 1, 0, 0, 0, 0)); + testTimestamp(LocalDateTime.of(1800, 8, 18, 12, 38, 29, 123000000)); } - @Test(dataProvider = "testTimestampProvider") - public void testTimestamp(LocalDateTime dateTime) + private void testTimestamp(LocalDateTime dateTime) { String formattedStr = getFormatter().formatTimestamp(sqlTimestampOf(3, dateTime)); assertEquals(Long.parseLong(formattedStr), DAYS.toMillis(dateTime.getLong(EPOCH_DAY)) + scaleNanosToMillis(dateTime.getLong(NANO_OF_DAY))); } - @DataProvider - public Object[][] testTimestampProvider() + @Test + public void testTimestampWithTimeZone() { - return new Object[][] { - {LocalDateTime.of(2020, 8, 18, 12, 38, 29, 123000000)}, - {LocalDateTime.of(1970, 1, 1, 0, 0, 0, 0)}, - {LocalDateTime.of(1800, 8, 18, 12, 38, 29, 123000000)}, - }; + testTimestampWithTimeZone(ZonedDateTime.of(2020, 8, 18, 12, 38, 29, 123000000, UTC_KEY.getZoneId())); + testTimestampWithTimeZone(ZonedDateTime.of(2020, 8, 18, 12, 38, 29, 123000000, TimeZoneKey.getTimeZoneKey("America/New_York").getZoneId())); + testTimestampWithTimeZone(ZonedDateTime.of(1800, 8, 18, 12, 38, 29, 123000000, UTC_KEY.getZoneId())); + testTimestampWithTimeZone(ZonedDateTime.of(2020, 8, 18, 12, 38, 29, 123000000, TimeZoneKey.getTimeZoneKey("Asia/Hong_Kong").getZoneId())); + testTimestampWithTimeZone(ZonedDateTime.of(2020, 8, 18, 12, 38, 29, 123000000, TimeZoneKey.getTimeZoneKey("Africa/Mogadishu").getZoneId())); + testTimestampWithTimeZone(ZonedDateTime.of(1970, 1, 1, 0, 0, 0, 0, UTC_KEY.getZoneId())); } - @Test(dataProvider = "testTimestampWithTimeZoneProvider") - public void testTimestampWithTimeZone(ZonedDateTime zonedDateTime) + private void testTimestampWithTimeZone(ZonedDateTime zonedDateTime) { String formattedStr = getFormatter().formatTimestampWithZone(SqlTimestampWithTimeZone.fromInstant(3, zonedDateTime.toInstant(), zonedDateTime.getZone())); assertEquals(Long.parseLong(formattedStr), zonedDateTime.toInstant().toEpochMilli()); } - - @DataProvider - public Object[][] testTimestampWithTimeZoneProvider() - { - return new Object[][] { - {ZonedDateTime.of(2020, 8, 18, 12, 38, 29, 123000000, UTC_KEY.getZoneId())}, - {ZonedDateTime.of(2020, 8, 18, 12, 38, 29, 123000000, TimeZoneKey.getTimeZoneKey("America/New_York").getZoneId())}, - {ZonedDateTime.of(1800, 8, 18, 12, 38, 29, 123000000, UTC_KEY.getZoneId())}, - {ZonedDateTime.of(2020, 8, 18, 12, 38, 29, 123000000, TimeZoneKey.getTimeZoneKey("Asia/Hong_Kong").getZoneId())}, - {ZonedDateTime.of(2020, 8, 18, 12, 38, 29, 123000000, TimeZoneKey.getTimeZoneKey("Africa/Mogadishu").getZoneId())}, - {ZonedDateTime.of(1970, 1, 1, 0, 0, 0, 0, UTC_KEY.getZoneId())}, - }; - } } diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestSecondsJsonDateTimeFormatter.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestSecondsJsonDateTimeFormatter.java index 4ec50a540041..954e593c22e8 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestSecondsJsonDateTimeFormatter.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestSecondsJsonDateTimeFormatter.java @@ -16,7 +16,6 @@ import io.trino.plugin.kafka.encoder.json.format.JsonDateTimeFormatter; import io.trino.spi.type.SqlTimestampWithTimeZone; import io.trino.spi.type.TimeZoneKey; -import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.time.LocalDateTime; @@ -38,57 +37,48 @@ private static JsonDateTimeFormatter getFormatter() return SECONDS_SINCE_EPOCH.getFormatter(Optional.empty()); } - @Test(dataProvider = "testTimeProvider") - public void testTime(LocalTime time) + @Test + public void testTime() + { + testTime(LocalTime.of(15, 36, 25, 0)); + testTime(LocalTime.of(0, 0, 0, 0)); + testTime(LocalTime.of(23, 59, 59, 0)); + } + + private void testTime(LocalTime time) { String formatted = getFormatter().formatTime(sqlTimeOf(3, time), 3); assertEquals(Long.parseLong(formatted), time.toSecondOfDay()); } - @DataProvider - public Object[][] testTimeProvider() + @Test + public void testTimestamp() { - return new Object[][] { - {LocalTime.of(15, 36, 25, 0)}, - {LocalTime.of(0, 0, 0, 0)}, - {LocalTime.of(23, 59, 59, 0)}, - }; + testTimestamp(LocalDateTime.of(2020, 8, 18, 12, 38, 29, 0)); + testTimestamp(LocalDateTime.of(1970, 1, 1, 0, 0, 0, 0)); + testTimestamp(LocalDateTime.of(1800, 8, 18, 12, 38, 29, 0)); } - @Test(dataProvider = "testTimestampProvider") - public void testTimestamp(LocalDateTime dateTime) + private void testTimestamp(LocalDateTime dateTime) { String formatted = getFormatter().formatTimestamp(sqlTimestampOf(3, dateTime)); assertEquals(Long.parseLong(formatted), dateTime.toEpochSecond(UTC)); } - @DataProvider - public Object[][] testTimestampProvider() + @Test + public void testTimestampWithTimeZone() { - return new Object[][] { - {LocalDateTime.of(2020, 8, 18, 12, 38, 29, 0)}, - {LocalDateTime.of(1970, 1, 1, 0, 0, 0, 0)}, - {LocalDateTime.of(1800, 8, 18, 12, 38, 29, 0)}, - }; + testTimestampWithTimeZone(ZonedDateTime.of(2020, 8, 18, 12, 38, 29, 123000000, UTC_KEY.getZoneId())); + testTimestampWithTimeZone(ZonedDateTime.of(2020, 8, 18, 12, 38, 29, 123000000, TimeZoneKey.getTimeZoneKey("America/New_York").getZoneId())); + testTimestampWithTimeZone(ZonedDateTime.of(1800, 8, 18, 12, 38, 29, 123000000, UTC_KEY.getZoneId())); + testTimestampWithTimeZone(ZonedDateTime.of(2020, 8, 19, 12, 23, 41, 123000000, TimeZoneKey.getTimeZoneKey("Asia/Hong_Kong").getZoneId())); + testTimestampWithTimeZone(ZonedDateTime.of(2020, 8, 19, 12, 23, 41, 123000000, TimeZoneKey.getTimeZoneKey("Africa/Mogadishu").getZoneId())); + testTimestampWithTimeZone(ZonedDateTime.of(1970, 1, 1, 0, 0, 0, 0, UTC_KEY.getZoneId())); } - @Test(dataProvider = "testTimestampWithTimeZoneProvider") - public void testTimestampWithTimeZone(ZonedDateTime zonedDateTime) + private void testTimestampWithTimeZone(ZonedDateTime zonedDateTime) { String formattedStr = getFormatter().formatTimestampWithZone(SqlTimestampWithTimeZone.fromInstant(3, zonedDateTime.toInstant(), zonedDateTime.getZone())); assertEquals(Long.parseLong(formattedStr), zonedDateTime.toEpochSecond()); } - - @DataProvider - public Object[][] testTimestampWithTimeZoneProvider() - { - return new Object[][] { - {ZonedDateTime.of(2020, 8, 18, 12, 38, 29, 123000000, UTC_KEY.getZoneId())}, - {ZonedDateTime.of(2020, 8, 18, 12, 38, 29, 123000000, TimeZoneKey.getTimeZoneKey("America/New_York").getZoneId())}, - {ZonedDateTime.of(1800, 8, 18, 12, 38, 29, 123000000, UTC_KEY.getZoneId())}, - {ZonedDateTime.of(2020, 8, 19, 12, 23, 41, 123000000, TimeZoneKey.getTimeZoneKey("Asia/Hong_Kong").getZoneId())}, - {ZonedDateTime.of(2020, 8, 19, 12, 23, 41, 123000000, TimeZoneKey.getTimeZoneKey("Africa/Mogadishu").getZoneId())}, - {ZonedDateTime.of(1970, 1, 1, 0, 0, 0, 0, UTC_KEY.getZoneId())}, - }; - } } diff --git a/plugin/trino-kinesis/src/test/java/io/trino/plugin/kinesis/TestRecordAccess.java b/plugin/trino-kinesis/src/test/java/io/trino/plugin/kinesis/TestRecordAccess.java index 2eadc67aa8f0..767bf5c03c05 100644 --- a/plugin/trino-kinesis/src/test/java/io/trino/plugin/kinesis/TestRecordAccess.java +++ b/plugin/trino-kinesis/src/test/java/io/trino/plugin/kinesis/TestRecordAccess.java @@ -29,7 +29,6 @@ import io.trino.testing.StandaloneQueryRunner; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.io.ByteArrayOutputStream; @@ -183,8 +182,15 @@ public void testStreamHasData() log.info("Completed second test (select counts)"); } - @Test(dataProvider = "testJsonStreamProvider") - public void testJsonStream(int uncompressedMessages, int compressedMessages, String streamName) + @Test + public void testJsonStream() + { + testJsonStream(4, 0, jsonStreamName); + testJsonStream(0, 4, jsonGzipCompressStreamName); + testJsonStream(2, 2, jsonAutomaticCompressStreamName); + } + + private void testJsonStream(int uncompressedMessages, int compressedMessages, String streamName) { // Simple case: add a few specific items, query object and internal fields: if (uncompressedMessages > 0) { @@ -210,14 +216,4 @@ public void testJsonStream(int uncompressedMessages, int compressedMessages, Str log.info("ROW: %s", row); } } - - @DataProvider - public Object[][] testJsonStreamProvider() - { - return new Object[][] { - {4, 0, jsonStreamName}, - {0, 4, jsonGzipCompressStreamName}, - {2, 2, jsonAutomaticCompressStreamName}, - }; - } } diff --git a/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/TestMariaDbTypeMapping.java b/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/TestMariaDbTypeMapping.java index 53a20a263773..4c6e4d1f5641 100644 --- a/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/TestMariaDbTypeMapping.java +++ b/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/TestMariaDbTypeMapping.java @@ -29,7 +29,6 @@ import io.trino.testing.sql.TestTable; import io.trino.testing.sql.TrinoSqlExecutor; import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.math.RoundingMode; @@ -350,8 +349,14 @@ public void testDecimalExceedingPrecisionMaxWithNonExceedingIntegerValues() } } - @Test(dataProvider = "testDecimalExceedingPrecisionMaxProvider") - public void testDecimalExceedingPrecisionMaxWithSupportedValues(int typePrecision, int typeScale) + @Test + public void testDecimalExceedingPrecisionMaxWithSupportedValues() + { + testDecimalExceedingPrecisionMaxWithSupportedValues(40, 8); + testDecimalExceedingPrecisionMaxWithSupportedValues(50, 10); + } + + private void testDecimalExceedingPrecisionMaxWithSupportedValues(int typePrecision, int typeScale) { try (TestTable testTable = new TestTable( server::execute, @@ -401,15 +406,6 @@ public void testDecimalExceedingPrecisionMaxWithSupportedValues(int typePrecisio } } - @DataProvider - public Object[][] testDecimalExceedingPrecisionMaxProvider() - { - return new Object[][] { - {40, 8}, - {50, 10}, - }; - } - private Session sessionWithDecimalMappingAllowOverflow(RoundingMode roundingMode, int scale) { return Session.builder(getSession()) @@ -588,8 +584,17 @@ public void testBinary() .execute(getQueryRunner(), mariaDbCreateAndInsert("tpch.test_binary")); } - @Test(dataProvider = "sessionZonesDataProvider") - public void testDate(ZoneId sessionZone) + @Test + public void testDate() + { + testDate(UTC); + testDate(jvmZone); + testDate(vilnius); + testDate(kathmandu); + testDate(TestingSession.DEFAULT_TIME_ZONE_KEY.getZoneId()); + } + + private void testDate(ZoneId sessionZone) { Session session = Session.builder(getSession()) .setTimeZoneKey(TimeZoneKey.getTimeZoneKey(sessionZone.getId())) @@ -736,8 +741,17 @@ private void testUnsupportedDataType(String databaseDataType) /** * Read {@code TIMESTAMP}s inserted by MariaDb as Trino {@code TIMESTAMP}s */ - @Test(dataProvider = "sessionZonesDataProvider") - public void testTimestamp(ZoneId sessionZone) + @Test + public void testTimestamp() + { + testTimestamp(UTC); + testTimestamp(jvmZone); + testTimestamp(vilnius); + testTimestamp(kathmandu); + testTimestamp(TestingSession.DEFAULT_TIME_ZONE_KEY.getZoneId()); + } + + private void testTimestamp(ZoneId sessionZone) { Session session = Session.builder(getSession()) .setTimeZoneKey(TimeZoneKey.getTimeZoneKey(sessionZone.getId())) @@ -856,18 +870,6 @@ public void testTimestampCoercion() .execute(getQueryRunner(), trinoCreateAndInsert("test_timestamp_coercion")); } - @DataProvider - public Object[][] sessionZonesDataProvider() - { - return new Object[][] { - {UTC}, - {jvmZone}, - {vilnius}, - {kathmandu}, - {TestingSession.DEFAULT_TIME_ZONE_KEY.getZoneId()}, - }; - } - private DataSetup trinoCreateAsSelect(String tableNamePrefix) { return trinoCreateAsSelect(getSession(), tableNamePrefix); From 5e4ed89e853a8905e5f4de5fe20c0023b6559ad8 Mon Sep 17 00:00:00 2001 From: Martin Traverso Date: Tue, 14 Nov 2023 13:31:37 -0800 Subject: [PATCH 2/3] Migrate tests to JUnit --- .../io/trino/execution/TestNodeScheduler.java | 21 ++++--- .../hive/coercions/TestDecimalCoercers.java | 2 +- .../BaseIcebergMaterializedViewTest.java | 12 +++- .../iceberg/TestIcebergMaterializedView.java | 2 +- ...estIcebergGlueCatalogMaterializedView.java | 10 +++- plugin/trino-ignite/pom.xml | 28 ---------- .../TestIgniteCaseInsensitiveMapping.java | 20 +++---- .../trino/plugin/ignite/TestIgniteClient.java | 10 ++-- .../plugin/ignite/TestIgniteTypeMapping.java | 6 +- plugin/trino-kafka/pom.xml | 23 -------- .../plugin/kafka/TestKafkaConnectorTest.java | 8 +-- .../plugin/kafka/TestKafkaFilterManager.java | 27 +++++---- .../kafka/TestKafkaIntegrationPushDown.java | 6 +- .../trino/plugin/kafka/TestKafkaPlugin.java | 8 +-- .../plugin/kafka/TestKafkaSecurityConfig.java | 2 +- .../kafka/TestMinimalFunctionality.java | 4 +- .../json/TestCustomJsonDateTimeFormatter.java | 12 ++-- .../TestISO8601JsonDateTimeFormatter.java | 12 ++-- ...TestMillisecondsJsonDateTimeFormatter.java | 10 ++-- .../TestRFC2822JsonDateTimeFormatter.java | 6 +- .../TestSecondsJsonDateTimeFormatter.java | 10 ++-- .../encoder/raw/TestRawEncoderMapping.java | 4 +- ...ithSchemaRegistryMinimalFunctionality.java | 5 +- .../kafka/protobuf/TestProtobufEncoder.java | 10 ++-- ...estAvroConfluentContentSchemaProvider.java | 5 +- .../TestAvroConfluentRowDecoder.java | 16 +++--- .../confluent/TestAvroSchemaConverter.java | 16 +++--- ...chemaRegistryTableDescriptionSupplier.java | 9 ++- ...entSchemaRegistryMinimalFunctionality.java | 7 +-- .../kafka/utils/TestPropertiesUtils.java | 4 +- .../plugin/kinesis/TestRecordAccess.java | 17 ++++-- plugin/trino-mariadb/pom.xml | 28 ---------- .../mariadb/BaseMariaDbConnectorTest.java | 5 +- .../BaseMariaDbTableStatisticsTest.java | 55 ++++++++++++------- .../plugin/mariadb/TestMariaDbClient.java | 10 ++-- .../plugin/mariadb/TestMariaDbJdbcConfig.java | 17 +++--- .../mariadb/TestMariaDbTypeMapping.java | 12 +++- 37 files changed, 206 insertions(+), 253 deletions(-) diff --git a/core/trino-main/src/test/java/io/trino/execution/TestNodeScheduler.java b/core/trino-main/src/test/java/io/trino/execution/TestNodeScheduler.java index e6a1caa32fd4..e95f4e21e67b 100644 --- a/core/trino-main/src/test/java/io/trino/execution/TestNodeScheduler.java +++ b/core/trino-main/src/test/java/io/trino/execution/TestNodeScheduler.java @@ -47,9 +47,12 @@ import io.trino.sql.planner.plan.PlanNodeId; import io.trino.testing.TestingSession; import io.trino.util.FinalizerService; -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 org.junit.jupiter.api.parallel.Execution; import java.net.InetAddress; import java.net.URI; @@ -84,11 +87,14 @@ import static java.util.concurrent.Executors.newCachedThreadPool; import static java.util.concurrent.Executors.newScheduledThreadPool; import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_METHOD; +import static org.junit.jupiter.api.parallel.ExecutionMode.SAME_THREAD; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; -@Test(singleThreaded = true) +@TestInstance(PER_METHOD) +@Execution(SAME_THREAD) public class TestNodeScheduler { private FinalizerService finalizerService; @@ -102,7 +108,7 @@ public class TestNodeScheduler private ScheduledExecutorService remoteTaskScheduledExecutor; private Session session; - @BeforeMethod + @BeforeEach public void setUp() { session = TestingSession.testSessionBuilder().build(); @@ -134,7 +140,7 @@ private void setUpNodes() new InternalNode("other3", URI.create("http://10.0.0.1:13"), NodeVersion.UNKNOWN, false)); } - @AfterMethod(alwaysRun = true) + @AfterEach public void tearDown() { remoteTaskExecutor.shutdown(); @@ -172,7 +178,8 @@ public void testScheduleLocal() assertEquals(assignment.getValue(), split); } - @Test(timeOut = 60 * 1000) + @Test + @Timeout(60) public void testTopologyAwareScheduling() { NodeTaskMap nodeTaskMap = new NodeTaskMap(finalizerService); diff --git a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/coercions/TestDecimalCoercers.java b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/coercions/TestDecimalCoercers.java index 4e08b96884f2..dadfea248de9 100644 --- a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/coercions/TestDecimalCoercers.java +++ b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/coercions/TestDecimalCoercers.java @@ -17,7 +17,7 @@ import io.trino.spi.type.DecimalParseResult; import io.trino.spi.type.Decimals; import io.trino.spi.type.Type; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import static io.trino.plugin.hive.HiveTimestampPrecision.NANOSECONDS; import static io.trino.plugin.hive.HiveType.toHiveType; diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergMaterializedViewTest.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergMaterializedViewTest.java index c4f0e04e68ee..45b0e5ed2246 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergMaterializedViewTest.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergMaterializedViewTest.java @@ -26,8 +26,10 @@ import org.apache.iceberg.TableMetadata; import org.apache.iceberg.TableMetadataParser; import org.assertj.core.api.Condition; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.parallel.Execution; import java.nio.file.Path; import java.util.Optional; @@ -46,8 +48,12 @@ import static org.assertj.core.api.Assertions.anyOf; 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.junit.jupiter.api.parallel.ExecutionMode.CONCURRENT; import static org.testng.Assert.assertEquals; +@TestInstance(PER_CLASS) +@Execution(CONCURRENT) public abstract class BaseIcebergMaterializedViewTest extends AbstractTestQueryFramework { @@ -55,7 +61,7 @@ public abstract class BaseIcebergMaterializedViewTest protected abstract String getStorageMetadataLocation(String materializedViewName); - @BeforeClass + @BeforeAll public void setUp() { assertUpdate("CREATE TABLE base_table1(_bigint BIGINT, _date DATE) WITH (partitioning = ARRAY['_date'])"); diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMaterializedView.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMaterializedView.java index c694902ccd80..7b8a2aa6dd71 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMaterializedView.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMaterializedView.java @@ -18,7 +18,7 @@ import io.trino.plugin.hive.metastore.Table; import io.trino.sql.tree.ExplainType; import io.trino.testing.DistributedQueryRunner; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.io.File; import java.nio.file.Files; diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/catalog/glue/TestIcebergGlueCatalogMaterializedView.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/catalog/glue/TestIcebergGlueCatalogMaterializedView.java index f3d54ce2deed..5bb341e92173 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/catalog/glue/TestIcebergGlueCatalogMaterializedView.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/catalog/glue/TestIcebergGlueCatalogMaterializedView.java @@ -28,7 +28,9 @@ import io.trino.plugin.iceberg.IcebergQueryRunner; import io.trino.plugin.iceberg.SchemaInitializer; import io.trino.testing.QueryRunner; -import org.testng.annotations.AfterClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.parallel.Execution; import java.io.File; import java.nio.file.Files; @@ -40,7 +42,11 @@ import static io.trino.plugin.hive.metastore.glue.converter.GlueToTrinoConverter.getTableParameters; import static io.trino.testing.TestingNames.randomNameSuffix; import static org.apache.iceberg.BaseMetastoreTableOperations.METADATA_LOCATION_PROP; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; +import static org.junit.jupiter.api.parallel.ExecutionMode.CONCURRENT; +@TestInstance(PER_CLASS) +@Execution(CONCURRENT) public class TestIcebergGlueCatalogMaterializedView extends BaseIcebergMaterializedViewTest { @@ -85,7 +91,7 @@ protected String getStorageMetadataLocation(String materializedViewName) return getTableParameters(table).get(METADATA_LOCATION_PROP); } - @AfterClass(alwaysRun = true) + @AfterAll public void cleanup() { cleanUpSchema(schemaName); diff --git a/plugin/trino-ignite/pom.xml b/plugin/trino-ignite/pom.xml index fdd28fc8cfad..e38de38ee251 100644 --- a/plugin/trino-ignite/pom.xml +++ b/plugin/trino-ignite/pom.xml @@ -231,36 +231,8 @@ testcontainers test - - - org.testng - testng - 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.apache.maven.surefire - surefire-junit-platform - ${dep.plugin.surefire.version} - - - org.apache.maven.surefire - surefire-testng - ${dep.plugin.surefire.version} - - - io.trino trino-maven-plugin diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaConnectorTest.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaConnectorTest.java index 15374d28cf09..f4451fc375c8 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaConnectorTest.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaConnectorTest.java @@ -67,8 +67,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assumptions.abort; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; public class TestKafkaConnectorTest extends BaseConnectorTest @@ -380,7 +378,7 @@ public void testReadAllDataTypes() public void testInsert() { // Override because the base test uses CREATE TABLE AS SELECT statement that is unsupported in Kafka connector - assertFalse(hasBehavior(SUPPORTS_CREATE_TABLE_WITH_DATA)); + assertThat(hasBehavior(SUPPORTS_CREATE_TABLE_WITH_DATA)).isFalse(); String query = "SELECT phone, custkey, acctbal FROM customer"; @@ -504,7 +502,9 @@ public void testJsonDateTimeFormatsRoundTrip() Object actual = computeScalar("SELECT " + field.getFieldName() + " FROM write_test." + testCase.getTopicName()); Object expected = computeScalar("SELECT " + field.getFieldValue()); try { - assertEquals(actual, expected, "Equality assertion failed for field: " + field.getFieldName()); + assertThat(actual) + .describedAs("Equality assertion failed for field: " + field.getFieldName()) + .isEqualTo(expected); } catch (AssertionError e) { throw new AssertionError(format("Equality assertion failed for field '%s'\n%s", field.getFieldName(), e.getMessage()), e); diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaFilterManager.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaFilterManager.java index a54ba4be6622..3808c5074736 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaFilterManager.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaFilterManager.java @@ -23,8 +23,7 @@ import static io.trino.spi.predicate.Domain.multipleValues; import static io.trino.spi.type.BigintType.BIGINT; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class TestKafkaFilterManager { @@ -34,39 +33,39 @@ public void testFilterValuesByDomain() Set source = Set.of(1L, 2L, 3L, 4L, 5L, 6L); Domain testDomain = Domain.singleValue(BIGINT, 1L); - assertEquals(KafkaFilterManager.filterValuesByDomain(testDomain, source), Set.of(1L)); + assertThat(KafkaFilterManager.filterValuesByDomain(testDomain, source)).isEqualTo(Set.of(1L)); testDomain = multipleValues(BIGINT, ImmutableList.of(3L, 8L)); - assertEquals(KafkaFilterManager.filterValuesByDomain(testDomain, source), Set.of(3L)); + assertThat(KafkaFilterManager.filterValuesByDomain(testDomain, source)).isEqualTo(Set.of(3L)); testDomain = Domain.create(SortedRangeSet.copyOf(BIGINT, ImmutableList.of( Range.range(BIGINT, 2L, true, 4L, true))), false); - assertEquals(KafkaFilterManager.filterValuesByDomain(testDomain, source), Set.of(2L, 3L, 4L)); + assertThat(KafkaFilterManager.filterValuesByDomain(testDomain, source)).isEqualTo(Set.of(2L, 3L, 4L)); } @Test public void testFilterRangeByDomain() { Domain testDomain = Domain.singleValue(BIGINT, 1L); - assertTrue(KafkaFilterManager.filterRangeByDomain(testDomain).isPresent()); - assertEquals(KafkaFilterManager.filterRangeByDomain(testDomain).get().getBegin(), 1L); - assertEquals(KafkaFilterManager.filterRangeByDomain(testDomain).get().getEnd(), 2L); + assertThat(KafkaFilterManager.filterRangeByDomain(testDomain).isPresent()).isTrue(); + assertThat(KafkaFilterManager.filterRangeByDomain(testDomain).get().getBegin()).isEqualTo(1L); + assertThat(KafkaFilterManager.filterRangeByDomain(testDomain).get().getEnd()).isEqualTo(2L); testDomain = multipleValues(BIGINT, ImmutableList.of(3L, 8L)); - assertTrue(KafkaFilterManager.filterRangeByDomain(testDomain).isPresent()); - assertEquals(KafkaFilterManager.filterRangeByDomain(testDomain).get().getBegin(), 3L); - assertEquals(KafkaFilterManager.filterRangeByDomain(testDomain).get().getEnd(), 9L); + assertThat(KafkaFilterManager.filterRangeByDomain(testDomain).isPresent()).isTrue(); + assertThat(KafkaFilterManager.filterRangeByDomain(testDomain).get().getBegin()).isEqualTo(3L); + assertThat(KafkaFilterManager.filterRangeByDomain(testDomain).get().getEnd()).isEqualTo(9L); testDomain = Domain.create(SortedRangeSet.copyOf(BIGINT, ImmutableList.of( Range.range(BIGINT, 2L, true, 4L, true))), false); - assertTrue(KafkaFilterManager.filterRangeByDomain(testDomain).isPresent()); - assertEquals(KafkaFilterManager.filterRangeByDomain(testDomain).get().getBegin(), 2L); - assertEquals(KafkaFilterManager.filterRangeByDomain(testDomain).get().getEnd(), 5L); + assertThat(KafkaFilterManager.filterRangeByDomain(testDomain).isPresent()).isTrue(); + assertThat(KafkaFilterManager.filterRangeByDomain(testDomain).get().getBegin()).isEqualTo(2L); + assertThat(KafkaFilterManager.filterRangeByDomain(testDomain).get().getEnd()).isEqualTo(5L); } } diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaIntegrationPushDown.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaIntegrationPushDown.java index 8bb8504af691..e07510367b53 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaIntegrationPushDown.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaIntegrationPushDown.java @@ -40,8 +40,8 @@ import static io.trino.testing.assertions.Assert.assertEventually; import static java.lang.String.format; import static java.util.Objects.requireNonNull; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.parallel.ExecutionMode.SAME_THREAD; -import static org.testng.Assert.assertEquals; @Execution(SAME_THREAD) public class TestKafkaIntegrationPushDown @@ -92,7 +92,7 @@ public void testPartitionPushDown() assertEventually(() -> { MaterializedResultWithQueryId queryResult = getDistributedQueryRunner().executeWithQueryId(getSession(), sql); - assertEquals(getQueryInfo(getDistributedQueryRunner(), queryResult).getQueryStats().getProcessedInputPositions(), MESSAGE_NUM / 2); + assertThat(getQueryInfo(getDistributedQueryRunner(), queryResult).getQueryStats().getProcessedInputPositions()).isEqualTo(MESSAGE_NUM / 2); }); } @@ -155,7 +155,7 @@ private void assertProcessedInputPositions(String sql, long expectedProcessedInp DistributedQueryRunner queryRunner = getDistributedQueryRunner(); assertEventually(() -> { MaterializedResultWithQueryId queryResult = queryRunner.executeWithQueryId(session, sql); - assertEquals(getQueryInfo(queryRunner, queryResult).getQueryStats().getProcessedInputPositions(), expectedProcessedInputPositions); + assertThat(getQueryInfo(queryRunner, queryResult).getQueryStats().getProcessedInputPositions()).isEqualTo(expectedProcessedInputPositions); }); } diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaPlugin.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaPlugin.java index cdd40c58607a..5564583e159b 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaPlugin.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaPlugin.java @@ -28,8 +28,8 @@ import static com.google.common.collect.Iterables.getOnlyElement; import static io.airlift.testing.Assertions.assertInstanceOf; import static org.apache.kafka.common.security.auth.SecurityProtocol.SSL; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.testng.Assert.assertNotNull; public class TestKafkaPlugin { @@ -52,7 +52,7 @@ public void testSpinup() .put("bootstrap.quiet", "true") .buildOrThrow(), new TestingConnectorContext()); - assertNotNull(connector); + assertThat(connector).isNotNull(); connector.shutdown(); } @@ -89,7 +89,7 @@ public void testSslSpinup() .put("bootstrap.quiet", "true") .buildOrThrow(), new TestingConnectorContext()); - assertNotNull(connector); + assertThat(connector).isNotNull(); connector.shutdown(); } @@ -198,7 +198,7 @@ public void testConfigResourceSpinup() .put("bootstrap.quiet", "true") .buildOrThrow(), new TestingConnectorContext()); - assertNotNull(connector); + assertThat(connector).isNotNull(); connector.shutdown(); } diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaSecurityConfig.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaSecurityConfig.java index 391f3cf5d95f..381d03e96963 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaSecurityConfig.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaSecurityConfig.java @@ -14,7 +14,7 @@ package io.trino.plugin.kafka; import com.google.common.collect.ImmutableMap; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.Map; diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestMinimalFunctionality.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestMinimalFunctionality.java index d8208e3edcee..33f8dacbc65c 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestMinimalFunctionality.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestMinimalFunctionality.java @@ -27,8 +27,8 @@ import static io.trino.plugin.kafka.util.TestUtils.createEmptyTopicDescription; import static java.util.UUID.randomUUID; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.parallel.ExecutionMode.SAME_THREAD; -import static org.testng.Assert.assertTrue; @Execution(SAME_THREAD) public class TestMinimalFunctionality @@ -54,7 +54,7 @@ protected QueryRunner createQueryRunner() @Test public void testTopicExists() { - assertTrue(getQueryRunner().listTables(getSession(), "kafka", "default").contains(QualifiedObjectName.valueOf("kafka.default." + topicName))); + assertThat(getQueryRunner().listTables(getSession(), "kafka", "default").contains(QualifiedObjectName.valueOf("kafka.default." + topicName))).isTrue(); } @Test diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestCustomJsonDateTimeFormatter.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestCustomJsonDateTimeFormatter.java index 66abeb2f2088..67593dd0d5a3 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestCustomJsonDateTimeFormatter.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestCustomJsonDateTimeFormatter.java @@ -31,7 +31,7 @@ import static io.trino.testing.DateTimeTestingUtils.sqlTimeWithTimeZoneOf; import static io.trino.testing.DateTimeTestingUtils.sqlTimestampOf; import static io.trino.testing.DateTimeTestingUtils.sqlTimestampWithTimeZoneOf; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestCustomJsonDateTimeFormatter { @@ -43,31 +43,31 @@ private static JsonDateTimeFormatter getFormatter(String formatHint) private static void testDate(SqlDate value, String formatHint, String expectedLiteral) { String actualLiteral = getFormatter(formatHint).formatDate(value); - assertEquals(actualLiteral, expectedLiteral); + assertThat(actualLiteral).isEqualTo(expectedLiteral); } private static void testTime(SqlTime value, String formatHint, int precision, String expectedLiteral) { String actualLiteral = getFormatter(formatHint).formatTime(value, precision); - assertEquals(actualLiteral, expectedLiteral); + assertThat(actualLiteral).isEqualTo(expectedLiteral); } private static void testTimeWithTZ(SqlTimeWithTimeZone value, String formatHint, String expectedLiteral) { String actualLiteral = getFormatter(formatHint).formatTimeWithZone(value); - assertEquals(actualLiteral, expectedLiteral); + assertThat(actualLiteral).isEqualTo(expectedLiteral); } private static void testTimestamp(SqlTimestamp value, String formatHint, String expectedLiteral) { String actualLiteral = getFormatter(formatHint).formatTimestamp(value); - assertEquals(actualLiteral, expectedLiteral); + assertThat(actualLiteral).isEqualTo(expectedLiteral); } private static void testTimestampWithTZ(SqlTimestampWithTimeZone value, String formatHint, String expectedLiteral) { String actualLiteral = getFormatter(formatHint).formatTimestampWithZone(value); - assertEquals(actualLiteral, expectedLiteral); + assertThat(actualLiteral).isEqualTo(expectedLiteral); } @Test diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestISO8601JsonDateTimeFormatter.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestISO8601JsonDateTimeFormatter.java index 5718547fa4b4..44eef07302e5 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestISO8601JsonDateTimeFormatter.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestISO8601JsonDateTimeFormatter.java @@ -31,7 +31,7 @@ import static io.trino.testing.DateTimeTestingUtils.sqlTimeWithTimeZoneOf; import static io.trino.testing.DateTimeTestingUtils.sqlTimestampOf; import static io.trino.testing.DateTimeTestingUtils.sqlTimestampWithTimeZoneOf; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestISO8601JsonDateTimeFormatter { @@ -43,31 +43,31 @@ private static JsonDateTimeFormatter getFormatter() private static void testDate(SqlDate value, String expectedLiteral) { String actualLiteral = getFormatter().formatDate(value); - assertEquals(actualLiteral, expectedLiteral); + assertThat(actualLiteral).isEqualTo(expectedLiteral); } private static void testTime(SqlTime value, int precision, String expectedLiteral) { String actualLiteral = getFormatter().formatTime(value, precision); - assertEquals(actualLiteral, expectedLiteral); + assertThat(actualLiteral).isEqualTo(expectedLiteral); } private static void testTimeWithTZ(SqlTimeWithTimeZone value, String expectedLiteral) { String actualLiteral = getFormatter().formatTimeWithZone(value); - assertEquals(actualLiteral, expectedLiteral); + assertThat(actualLiteral).isEqualTo(expectedLiteral); } private static void testTimestamp(SqlTimestamp value, String expectedLiteral) { String actualLiteral = getFormatter().formatTimestamp(value); - assertEquals(actualLiteral, expectedLiteral); + assertThat(actualLiteral).isEqualTo(expectedLiteral); } private static void testTimestampWithTZ(SqlTimestampWithTimeZone value, String expectedLiteral) { String actualLiteral = getFormatter().formatTimestampWithZone(value); - assertEquals(actualLiteral, expectedLiteral); + assertThat(actualLiteral).isEqualTo(expectedLiteral); } @Test diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestMillisecondsJsonDateTimeFormatter.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestMillisecondsJsonDateTimeFormatter.java index bc6613ae6cdc..889782e82047 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestMillisecondsJsonDateTimeFormatter.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestMillisecondsJsonDateTimeFormatter.java @@ -16,7 +16,7 @@ import io.trino.plugin.kafka.encoder.json.format.JsonDateTimeFormatter; import io.trino.spi.type.SqlTimestampWithTimeZone; import io.trino.spi.type.TimeZoneKey; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.time.LocalDateTime; import java.time.LocalTime; @@ -32,7 +32,7 @@ import static java.time.temporal.ChronoField.MILLI_OF_DAY; import static java.time.temporal.ChronoField.NANO_OF_DAY; import static java.util.concurrent.TimeUnit.DAYS; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestMillisecondsJsonDateTimeFormatter { @@ -51,7 +51,7 @@ public void testTime() private void testTime(LocalTime time) { String formatted = getFormatter().formatTime(sqlTimeOf(3, time), 3); - assertEquals(Long.parseLong(formatted), time.getLong(MILLI_OF_DAY)); + assertThat(Long.parseLong(formatted)).isEqualTo(time.getLong(MILLI_OF_DAY)); } @Test @@ -65,7 +65,7 @@ public void testTimestamp() private void testTimestamp(LocalDateTime dateTime) { String formattedStr = getFormatter().formatTimestamp(sqlTimestampOf(3, dateTime)); - assertEquals(Long.parseLong(formattedStr), DAYS.toMillis(dateTime.getLong(EPOCH_DAY)) + scaleNanosToMillis(dateTime.getLong(NANO_OF_DAY))); + assertThat(Long.parseLong(formattedStr)).isEqualTo(DAYS.toMillis(dateTime.getLong(EPOCH_DAY)) + scaleNanosToMillis(dateTime.getLong(NANO_OF_DAY))); } @Test @@ -82,6 +82,6 @@ public void testTimestampWithTimeZone() private void testTimestampWithTimeZone(ZonedDateTime zonedDateTime) { String formattedStr = getFormatter().formatTimestampWithZone(SqlTimestampWithTimeZone.fromInstant(3, zonedDateTime.toInstant(), zonedDateTime.getZone())); - assertEquals(Long.parseLong(formattedStr), zonedDateTime.toInstant().toEpochMilli()); + assertThat(Long.parseLong(formattedStr)).isEqualTo(zonedDateTime.toInstant().toEpochMilli()); } } diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestRFC2822JsonDateTimeFormatter.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestRFC2822JsonDateTimeFormatter.java index a185cd838ea0..3b206c81f185 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestRFC2822JsonDateTimeFormatter.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestRFC2822JsonDateTimeFormatter.java @@ -25,7 +25,7 @@ import static io.trino.spi.type.TimeZoneKey.UTC_KEY; import static io.trino.testing.DateTimeTestingUtils.sqlTimestampOf; import static io.trino.testing.DateTimeTestingUtils.sqlTimestampWithTimeZoneOf; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestRFC2822JsonDateTimeFormatter { @@ -37,13 +37,13 @@ private static JsonDateTimeFormatter getFormatter() private static void testTimestamp(SqlTimestamp value, String expectedLiteral) { String actualLiteral = getFormatter().formatTimestamp(value); - assertEquals(actualLiteral, expectedLiteral); + assertThat(actualLiteral).isEqualTo(expectedLiteral); } private static void testTimestampWithTZ(SqlTimestampWithTimeZone value, String expectedLiteral) { String actualLiteral = getFormatter().formatTimestampWithZone(value); - assertEquals(actualLiteral, expectedLiteral); + assertThat(actualLiteral).isEqualTo(expectedLiteral); } @Test diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestSecondsJsonDateTimeFormatter.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestSecondsJsonDateTimeFormatter.java index 954e593c22e8..922966e89377 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestSecondsJsonDateTimeFormatter.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestSecondsJsonDateTimeFormatter.java @@ -16,7 +16,7 @@ import io.trino.plugin.kafka.encoder.json.format.JsonDateTimeFormatter; import io.trino.spi.type.SqlTimestampWithTimeZone; import io.trino.spi.type.TimeZoneKey; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.time.LocalDateTime; import java.time.LocalTime; @@ -28,7 +28,7 @@ import static io.trino.testing.DateTimeTestingUtils.sqlTimeOf; import static io.trino.testing.DateTimeTestingUtils.sqlTimestampOf; import static java.time.ZoneOffset.UTC; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestSecondsJsonDateTimeFormatter { @@ -48,7 +48,7 @@ public void testTime() private void testTime(LocalTime time) { String formatted = getFormatter().formatTime(sqlTimeOf(3, time), 3); - assertEquals(Long.parseLong(formatted), time.toSecondOfDay()); + assertThat(Long.parseLong(formatted)).isEqualTo(time.toSecondOfDay()); } @Test @@ -62,7 +62,7 @@ public void testTimestamp() private void testTimestamp(LocalDateTime dateTime) { String formatted = getFormatter().formatTimestamp(sqlTimestampOf(3, dateTime)); - assertEquals(Long.parseLong(formatted), dateTime.toEpochSecond(UTC)); + assertThat(Long.parseLong(formatted)).isEqualTo(dateTime.toEpochSecond(UTC)); } @Test @@ -79,6 +79,6 @@ public void testTimestampWithTimeZone() private void testTimestampWithTimeZone(ZonedDateTime zonedDateTime) { String formattedStr = getFormatter().formatTimestampWithZone(SqlTimestampWithTimeZone.fromInstant(3, zonedDateTime.toInstant(), zonedDateTime.getZone())); - assertEquals(Long.parseLong(formattedStr), zonedDateTime.toEpochSecond()); + assertThat(Long.parseLong(formattedStr)).isEqualTo(zonedDateTime.toEpochSecond()); } } diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/raw/TestRawEncoderMapping.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/raw/TestRawEncoderMapping.java index 2ad35a35dfe5..19751718c3c6 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/raw/TestRawEncoderMapping.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/raw/TestRawEncoderMapping.java @@ -33,7 +33,7 @@ import static io.trino.spi.type.BigintType.BIGINT; import static io.trino.spi.type.VarcharType.createUnboundedVarcharType; import static io.trino.spi.type.VarcharType.createVarcharType; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestRawEncoderMapping { @@ -78,6 +78,6 @@ public void testMapping() rowEncoder.appendColumnValue(varArrayBlock, 0); rowEncoder.appendColumnValue(varArrayBlock, 0); - assertEquals(buf.array(), rowEncoder.toByteArray()); + assertThat(buf.array()).isEqualTo(rowEncoder.toByteArray()); } } diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/protobuf/TestKafkaProtobufWithSchemaRegistryMinimalFunctionality.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/protobuf/TestKafkaProtobufWithSchemaRegistryMinimalFunctionality.java index 5501062c9c23..4e8fa7acafd3 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/protobuf/TestKafkaProtobufWithSchemaRegistryMinimalFunctionality.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/protobuf/TestKafkaProtobufWithSchemaRegistryMinimalFunctionality.java @@ -66,7 +66,6 @@ import static org.apache.kafka.clients.producer.ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.parallel.ExecutionMode.SAME_THREAD; -import static org.testng.Assert.assertTrue; @Execution(SAME_THREAD) public class TestKafkaProtobufWithSchemaRegistryMinimalFunctionality @@ -433,13 +432,13 @@ private void waitUntilTableExists(String tableName) .withMaxAttempts(10) .withDelay(Duration.ofMillis(100)) .build()) - .run(() -> assertTrue(schemaExists())); + .run(() -> assertThat(schemaExists()).isTrue()); Failsafe.with( RetryPolicy.builder() .withMaxAttempts(10) .withDelay(Duration.ofMillis(100)) .build()) - .run(() -> assertTrue(tableExists(tableName))); + .run(() -> assertThat(tableExists(tableName)).isTrue()); } private boolean schemaExists() diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/protobuf/TestProtobufEncoder.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/protobuf/TestProtobufEncoder.java index 8e4c38d5d4c6..41dc2fae1c8e 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/protobuf/TestProtobufEncoder.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/protobuf/TestProtobufEncoder.java @@ -72,7 +72,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.stream.Collectors.joining; import static java.util.stream.IntStream.range; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestProtobufEncoder { @@ -158,7 +158,7 @@ private void testAllDataTypes(String stringData, Integer integerData, Long longD rowEncoder.appendColumnValue(nativeValueToBlock(createTimestampType(6), sqlTimestamp.getEpochMicros()), 0); rowEncoder.appendColumnValue(nativeValueToBlock(VARBINARY, wrappedBuffer(bytesData)), 0); - assertEquals(messageBuilder.build().toByteArray(), rowEncoder.toByteArray()); + assertThat(messageBuilder.build().toByteArray()).isEqualTo(rowEncoder.toByteArray()); } @Test @@ -278,7 +278,7 @@ private void testStructuralDataTypes(String stringData, Integer integerData, Lon }); rowEncoder.appendColumnValue(rowBlockBuilder.build(), 0); - assertEquals(messageBuilder.build().toByteArray(), rowEncoder.toByteArray()); + assertThat(messageBuilder.build().toByteArray()).isEqualTo(rowEncoder.toByteArray()); } @Test @@ -419,7 +419,7 @@ private void testNestedStructuralDataTypes(String stringData, Integer integerDat rowEncoder.appendColumnValue(nestedBlockBuilder.build(), 0); - assertEquals(messageBuilder.build().toByteArray(), rowEncoder.toByteArray()); + assertThat(messageBuilder.build().toByteArray()).isEqualTo(rowEncoder.toByteArray()); } @Test @@ -506,7 +506,7 @@ private void testRowFlattening(String stringData, Integer integerData, Long long rowEncoder.appendColumnValue(nativeValueToBlock(createTimestampType(6), sqlTimestamp.getEpochMicros()), 0); rowEncoder.appendColumnValue(nativeValueToBlock(VARBINARY, wrappedBuffer(bytesData)), 0); - assertEquals(messageBuilder.build().toByteArray(), rowEncoder.toByteArray()); + assertThat(messageBuilder.build().toByteArray()).isEqualTo(rowEncoder.toByteArray()); } private Timestamp getTimestamp(SqlTimestamp sqlTimestamp) diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/schema/confluent/TestAvroConfluentContentSchemaProvider.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/schema/confluent/TestAvroConfluentContentSchemaProvider.java index 0888c7831d04..625b2bfea582 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/schema/confluent/TestAvroConfluentContentSchemaProvider.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/schema/confluent/TestAvroConfluentContentSchemaProvider.java @@ -32,7 +32,6 @@ import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.testng.Assert.assertEquals; public class TestAvroConfluentContentSchemaProvider { @@ -48,8 +47,8 @@ public void testAvroConfluentSchemaProvider() mockSchemaRegistryClient.register(SUBJECT_NAME, schema); AvroConfluentContentSchemaProvider avroConfluentSchemaProvider = new AvroConfluentContentSchemaProvider(mockSchemaRegistryClient); KafkaTableHandle tableHandle = new KafkaTableHandle("default", TOPIC, TOPIC, AvroRowDecoderFactory.NAME, AvroRowDecoderFactory.NAME, Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(SUBJECT_NAME), ImmutableList.of(), TupleDomain.all()); - assertEquals(avroConfluentSchemaProvider.getMessage(tableHandle), Optional.of(schema).map(Schema::toString)); - assertEquals(avroConfluentSchemaProvider.getKey(tableHandle), Optional.empty()); + assertThat(avroConfluentSchemaProvider.getMessage(tableHandle)).isEqualTo(Optional.of(schema).map(Schema::toString)); + assertThat(avroConfluentSchemaProvider.getKey(tableHandle)).isEqualTo(Optional.empty()); KafkaTableHandle invalidTableHandle = new KafkaTableHandle("default", TOPIC, TOPIC, AvroRowDecoderFactory.NAME, AvroRowDecoderFactory.NAME, Optional.empty(), Optional.empty(), Optional.empty(), Optional.of("another-schema"), ImmutableList.of(), TupleDomain.all()); assertThatThrownBy(() -> avroConfluentSchemaProvider.getMessage(invalidTableHandle)) .isInstanceOf(TrinoException.class) diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/schema/confluent/TestAvroConfluentRowDecoder.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/schema/confluent/TestAvroConfluentRowDecoder.java index 87d69e9ffc3b..5a7861eb0f28 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/schema/confluent/TestAvroConfluentRowDecoder.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/schema/confluent/TestAvroConfluentRowDecoder.java @@ -53,9 +53,7 @@ import static io.trino.spi.type.VarbinaryType.VARBINARY; import static io.trino.spi.type.VarcharType.VARCHAR; import static java.lang.String.format; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class TestAvroConfluentRowDecoder { @@ -171,7 +169,7 @@ private static void assertRowsAreEqual(Optional nonNullSchema = schema.getTypes().stream() .filter(type -> type.getType() != Schema.Type.NULL) .findFirst(); - assertTrue(nonNullSchema.isPresent()); + assertThat(nonNullSchema.isPresent()).isTrue(); if (expected == null) { expected = getOnlyElement(schema.getFields()).defaultVal(); diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/schema/confluent/TestAvroSchemaConverter.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/schema/confluent/TestAvroSchemaConverter.java index 600eeb4ff5c3..6371105a3a79 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/schema/confluent/TestAvroSchemaConverter.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/schema/confluent/TestAvroSchemaConverter.java @@ -42,8 +42,8 @@ import static io.trino.spi.type.RealType.REAL; import static io.trino.spi.type.VarbinaryType.VARBINARY; import static io.trino.spi.type.VarcharType.VARCHAR; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.testng.Assert.assertEquals; public class TestAvroSchemaConverter { @@ -101,7 +101,7 @@ public void testConvertSchema() .add(new RowType.Field(Optional.of("nested_map"), createType(new ArrayType(VARCHAR)))) .build())) .build(); - assertEquals(types, expected); + assertThat(types).isEqualTo(expected); } @Test @@ -174,7 +174,7 @@ public void testTypesWithDefaults() .add(new RowType.Field(Optional.of("nested_map"), createType(new ArrayType(VARCHAR)))) .build())) .build(); - assertEquals(types, expected); + assertThat(types).isEqualTo(expected); } @Test @@ -227,7 +227,7 @@ public void testNullableColumns() .add(new RowType.Field(Optional.of("nested_map"), createType(new ArrayType(VARCHAR)))) .build())) .build(); - assertEquals(types, expected); + assertThat(types).isEqualTo(expected); } @Test @@ -261,7 +261,7 @@ public void testSimpleSchema() Schema schema = Schema.create(Schema.Type.LONG); AvroSchemaConverter avroSchemaConverter = new AvroSchemaConverter(new TestingTypeManager(), IGNORE); List types = avroSchemaConverter.convertAvroSchema(schema); - assertEquals(getOnlyElement(types), BIGINT); + assertThat(getOnlyElement(types)).isEqualTo(BIGINT); } @Test @@ -280,7 +280,7 @@ public void testEmptyFieldStrategy() List typesForIgnoreStrategy = ImmutableList.of(INTEGER); - assertEquals(new AvroSchemaConverter(new TestingTypeManager(), IGNORE).convertAvroSchema(schema), typesForIgnoreStrategy); + assertThat(new AvroSchemaConverter(new TestingTypeManager(), IGNORE).convertAvroSchema(schema)).isEqualTo(typesForIgnoreStrategy); assertThatThrownBy(() -> new AvroSchemaConverter(new TestingTypeManager(), FAIL).convertAvroSchema(schema)) .isInstanceOf(IllegalStateException.class) @@ -293,7 +293,7 @@ public void testEmptyFieldStrategy() .add(createType(RowType.from(ImmutableList.of(new RowType.Field(Optional.of(DUMMY_FIELD_NAME), BOOLEAN))))) .build(); - assertEquals(new AvroSchemaConverter(new TestingTypeManager(), MARK).convertAvroSchema(schema), typesForAddDummyStrategy); + assertThat(new AvroSchemaConverter(new TestingTypeManager(), MARK).convertAvroSchema(schema)).isEqualTo(typesForAddDummyStrategy); } @Test @@ -323,7 +323,7 @@ public void testEmptyFieldStrategyForEmptySchema() .add(createType(RowType.from(ImmutableList.of(new RowType.Field(Optional.of(DUMMY_FIELD_NAME), BOOLEAN))))) .build(); - assertEquals(new AvroSchemaConverter(new TestingTypeManager(), MARK).convertAvroSchema(schema), typesForAddDummyStrategy); + assertThat(new AvroSchemaConverter(new TestingTypeManager(), MARK).convertAvroSchema(schema)).isEqualTo(typesForAddDummyStrategy); } private static Type createType(Type valueType) diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/schema/confluent/TestConfluentSchemaRegistryTableDescriptionSupplier.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/schema/confluent/TestConfluentSchemaRegistryTableDescriptionSupplier.java index ebb91aab8ff5..ed8cccb9c7be 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/schema/confluent/TestConfluentSchemaRegistryTableDescriptionSupplier.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/schema/confluent/TestConfluentSchemaRegistryTableDescriptionSupplier.java @@ -41,7 +41,6 @@ import static java.util.concurrent.TimeUnit.SECONDS; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.testng.Assert.assertTrue; public class TestConfluentSchemaRegistryTableDescriptionSupplier { @@ -58,7 +57,7 @@ public void testTopicDescription() String subject = topicName + "-value"; SCHEMA_REGISTRY_CLIENT.register(subject, getAvroSchema(schemaTableName.getTableName(), "")); - assertTrue(tableDescriptionSupplier.listTables().contains(schemaTableName)); + assertThat(tableDescriptionSupplier.listTables().contains(schemaTableName)).isTrue(); assertThat(getKafkaTopicDescription(tableDescriptionSupplier, schemaTableName)) .isEqualTo( @@ -83,7 +82,7 @@ public void testCaseInsensitiveSubjectMapping() SCHEMA_REGISTRY_CLIENT.register(subject, getAvroSchema(schemaTableName.getTableName(), "")); - assertTrue(tableDescriptionSupplier.listTables().contains(schemaTableName)); + assertThat(tableDescriptionSupplier.listTables().contains(schemaTableName)).isTrue(); assertThat(getKafkaTopicDescription(tableDescriptionSupplier, schemaTableName)) .isEqualTo( @@ -108,7 +107,7 @@ public void testAmbiguousSubject() SCHEMA_REGISTRY_CLIENT.register(topicName + "-key", getAvroSchema(schemaTableName.getTableName(), "")); SCHEMA_REGISTRY_CLIENT.register(topicName.toUpperCase(ENGLISH) + "-key", getAvroSchema(schemaTableName.getTableName(), "")); - assertTrue(tableDescriptionSupplier.listTables().contains(schemaTableName)); + assertThat(tableDescriptionSupplier.listTables().contains(schemaTableName)).isTrue(); assertThatThrownBy(() -> tableDescriptionSupplier.getTopicDescription( @@ -132,7 +131,7 @@ public void testOverriddenSubject() String overriddenSubject = "overriddenSubject"; SCHEMA_REGISTRY_CLIENT.register(overriddenSubject, getAvroSchema(schemaTableName.getTableName(), "overridden_")); - assertTrue(tableDescriptionSupplier.listTables().contains(schemaTableName)); + assertThat(tableDescriptionSupplier.listTables().contains(schemaTableName)).isTrue(); assertThat(getKafkaTopicDescription(tableDescriptionSupplier, schemaTableName)) .isEqualTo( diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/schema/confluent/TestKafkaWithConfluentSchemaRegistryMinimalFunctionality.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/schema/confluent/TestKafkaWithConfluentSchemaRegistryMinimalFunctionality.java index 728814b0da97..6d2be2698508 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/schema/confluent/TestKafkaWithConfluentSchemaRegistryMinimalFunctionality.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/schema/confluent/TestKafkaWithConfluentSchemaRegistryMinimalFunctionality.java @@ -55,7 +55,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.parallel.ExecutionMode.SAME_THREAD; -import static org.testng.Assert.assertTrue; @Execution(SAME_THREAD) public class TestKafkaWithConfluentSchemaRegistryMinimalFunctionality @@ -244,7 +243,7 @@ public void testUnsupportedFormat() .put(VALUE_SERIALIZER_CLASS_CONFIG, KafkaJsonSchemaSerializer.class.getName()) .buildOrThrow()); - assertTrue(tableExists(topicName)); + assertThat(tableExists(topicName)).isTrue(); String errorMessage = "Not supported schema: JSON"; assertThatThrownBy(() -> getQueryRunner().execute("SHOW COLUMNS FROM " + toDoubleQuoted(topicName))) @@ -368,13 +367,13 @@ private void waitUntilTableExists(String tableName) .withMaxAttempts(10) .withDelay(Duration.ofMillis(100)) .build()) - .run(() -> assertTrue(schemaExists())); + .run(() -> assertThat(schemaExists()).isTrue()); Failsafe.with( RetryPolicy.builder() .withMaxAttempts(10) .withDelay(Duration.ofMillis(100)) .build()) - .run(() -> assertTrue(tableExists(tableName))); + .run(() -> assertThat(tableExists(tableName)).isTrue()); } private boolean schemaExists() diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/utils/TestPropertiesUtils.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/utils/TestPropertiesUtils.java index e9328d52dc95..5744251a2306 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/utils/TestPropertiesUtils.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/utils/TestPropertiesUtils.java @@ -27,7 +27,7 @@ import java.util.Properties; import static io.trino.plugin.kafka.utils.PropertiesUtils.readProperties; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestPropertiesUtils { @@ -57,7 +57,7 @@ public void testReadPropertiesOverwritten() Map result = readProperties(Arrays.asList(firstFile, secondFile)); - assertEquals(result, expected); + assertThat(result).isEqualTo(expected); } private File writePropertiesToFile(Properties properties) diff --git a/plugin/trino-kinesis/src/test/java/io/trino/plugin/kinesis/TestRecordAccess.java b/plugin/trino-kinesis/src/test/java/io/trino/plugin/kinesis/TestRecordAccess.java index 767bf5c03c05..b00f2d35bee2 100644 --- a/plugin/trino-kinesis/src/test/java/io/trino/plugin/kinesis/TestRecordAccess.java +++ b/plugin/trino-kinesis/src/test/java/io/trino/plugin/kinesis/TestRecordAccess.java @@ -27,9 +27,11 @@ import io.trino.testing.MaterializedResult; import io.trino.testing.MaterializedRow; 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.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.parallel.Execution; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -44,6 +46,8 @@ import static io.trino.transaction.TransactionBuilder.transaction; import static java.lang.String.format; import static java.nio.charset.StandardCharsets.UTF_8; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; +import static org.junit.jupiter.api.parallel.ExecutionMode.SAME_THREAD; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; @@ -54,7 +58,8 @@ * the plug in without requiring an actual Kinesis connection. It uses the mock * kinesis client so no AWS activity will occur. */ -@Test(singleThreaded = true) +@TestInstance(PER_CLASS) +@Execution(SAME_THREAD) public class TestRecordAccess { private static final Logger log = Logger.get(TestRecordAccess.class); @@ -71,7 +76,7 @@ public class TestRecordAccess private StandaloneQueryRunner queryRunner; private MockKinesisClient mockClient; - @BeforeClass + @BeforeAll public void start() { dummyStreamName = "test123"; @@ -82,7 +87,7 @@ public void start() mockClient = TestUtils.installKinesisPlugin(queryRunner); } - @AfterClass(alwaysRun = true) + @AfterAll public void stop() { queryRunner.close(); diff --git a/plugin/trino-mariadb/pom.xml b/plugin/trino-mariadb/pom.xml index 35f782cf91fd..8f8b8ce15e84 100644 --- a/plugin/trino-mariadb/pom.xml +++ b/plugin/trino-mariadb/pom.xml @@ -203,33 +203,5 @@ testcontainers test - - - org.testng - testng - 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} - - - - - diff --git a/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/BaseMariaDbConnectorTest.java b/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/BaseMariaDbConnectorTest.java index 347ebe78610e..cb09c5dbec89 100644 --- a/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/BaseMariaDbConnectorTest.java +++ b/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/BaseMariaDbConnectorTest.java @@ -30,7 +30,6 @@ import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.testng.Assert.assertFalse; public abstract class BaseMariaDbConnectorTest extends BaseJdbcConnectorTest @@ -294,10 +293,10 @@ public void testInsertIntoNotNullColumn() public void testNativeQueryCreateStatement() { // Override because MariaDB returns a ResultSet metadata with no columns for CREATE statement. - assertFalse(getQueryRunner().tableExists(getSession(), "numbers")); + assertThat(getQueryRunner().tableExists(getSession(), "numbers")).isFalse(); assertThatThrownBy(() -> query("SELECT * FROM TABLE(system.query(query => 'CREATE TABLE tpch.numbers(n INTEGER)'))")) .hasMessageContaining("descriptor has no fields"); - assertFalse(getQueryRunner().tableExists(getSession(), "numbers")); + assertThat(getQueryRunner().tableExists(getSession(), "numbers")).isFalse(); } @Test diff --git a/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/BaseMariaDbTableStatisticsTest.java b/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/BaseMariaDbTableStatisticsTest.java index c764453dfb06..a4c726df17b1 100644 --- a/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/BaseMariaDbTableStatisticsTest.java +++ b/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/BaseMariaDbTableStatisticsTest.java @@ -42,9 +42,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.withinPercentage; import static org.junit.jupiter.api.Assumptions.abort; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; public abstract class BaseMariaDbTableStatisticsTest extends BaseJdbcTableStatisticsTest @@ -161,17 +158,29 @@ public void testAllNulls() } if ((columnName.equals("orderpriority") || columnName.equals("comment")) && varcharNdvToExpected.apply(2) == null) { - assertNull(row.getField(2), "NDV for " + columnName); - assertNull(row.getField(3), "null fraction for " + columnName); + assertThat(row.getField(2)) + .describedAs("NDV for " + columnName) + .isNull(); + assertThat(row.getField(3)) + .describedAs("null fraction for " + columnName) + .isNull(); } else { - assertNotNull(row.getField(2), "NDV for " + columnName); + assertThat(row.getField(2)) + .describedAs("NDV for " + columnName) + .isNotNull(); assertThat((Double) row.getField(2)).as("NDV for " + columnName).isBetween(0.0, 2.0); - assertEquals(row.getField(3), nullFractionToExpected.apply(1.0), "null fraction for " + columnName); + assertThat(row.getField(3)) + .describedAs("null fraction for " + columnName) + .isEqualTo(nullFractionToExpected.apply(1.0)); } - assertNull(row.getField(4), "min"); - assertNull(row.getField(5), "max"); + assertThat(row.getField(4)) + .describedAs("min") + .isNull(); + assertThat(row.getField(5)) + .describedAs("max") + .isNull(); } double cardinality = getTableCardinalityFromStats(statsResult); if (cardinality != 15.0) { @@ -359,7 +368,7 @@ protected void assertColumnStats(MaterializedResult statsResult, Map columnNdvs, Map columnNullFractions) { - assertEquals(columnNdvs.keySet(), columnNullFractions.keySet()); + assertThat(columnNdvs.keySet()).isEqualTo(columnNullFractions.keySet()); List reportedColumns = stream(statsResult) .map(row -> row.getField(0)) // column name .filter(Objects::nonNull) @@ -390,7 +399,9 @@ protected void assertColumnStats(MaterializedResult statsResult, Map ndvAssertion = assertThat(distinctCount).as("NDV for " + columnName); if (expectedNdv == null) { ndvAssertion.isNull(); - assertNull(nullsFraction, "null fraction for " + columnName); + assertThat(nullsFraction) + .describedAs("null fraction for " + columnName) + .isNull(); } else { ndvAssertion.isBetween(expectedNdv * 0.5, min(expectedNdv * 4.0, tableCardinality)); // [-50%, +300%] but no more than row count @@ -405,21 +416,25 @@ protected void assertColumnStats(MaterializedResult statsResult, Map columnMapping = JDBC_CLIENT.toColumnMapping(SESSION, null, result.get().getJdbcTypeHandle()); - assertTrue(columnMapping.isPresent(), "No mapping for: " + result.get().getJdbcTypeHandle()); - assertEquals(columnMapping.get().getType(), aggregateFunction.getOutputType()); + assertThat(columnMapping.isPresent()) + .describedAs("No mapping for: " + result.get().getJdbcTypeHandle()) + .isTrue(); + assertThat(columnMapping.get().getType()).isEqualTo(aggregateFunction.getOutputType()); } } } diff --git a/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/TestMariaDbJdbcConfig.java b/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/TestMariaDbJdbcConfig.java index ae18de64de00..cab9fe1f9250 100644 --- a/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/TestMariaDbJdbcConfig.java +++ b/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/TestMariaDbJdbcConfig.java @@ -15,18 +15,17 @@ import org.junit.jupiter.api.Test; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class TestMariaDbJdbcConfig { @Test public void testIsUrlValid() { - assertTrue(isUrlValid("jdbc:mariadb://example.net:3306")); - assertTrue(isUrlValid("jdbc:mariadb://example.net:3306/")); - assertFalse(isUrlValid("jdbc:notmariadb://example.net:3306")); - assertFalse(isUrlValid("jdbc:notmariadb://example.net:3306/")); + assertThat(isUrlValid("jdbc:mariadb://example.net:3306")).isTrue(); + assertThat(isUrlValid("jdbc:mariadb://example.net:3306/")).isTrue(); + assertThat(isUrlValid("jdbc:notmariadb://example.net:3306")).isFalse(); + assertThat(isUrlValid("jdbc:notmariadb://example.net:3306/")).isFalse(); } private static boolean isUrlValid(String url) @@ -39,9 +38,9 @@ private static boolean isUrlValid(String url) @Test public void testIsUrlWithoutDatabase() { - assertTrue(isUrlWithoutDatabase("jdbc:mariadb://example.net:3306")); - assertTrue(isUrlWithoutDatabase("jdbc:mariadb://example.net:3306/")); - assertFalse(isUrlWithoutDatabase("jdbc:mariadb://example.net:3306/somedatabase")); + assertThat(isUrlWithoutDatabase("jdbc:mariadb://example.net:3306")).isTrue(); + assertThat(isUrlWithoutDatabase("jdbc:mariadb://example.net:3306/")).isTrue(); + assertThat(isUrlWithoutDatabase("jdbc:mariadb://example.net:3306/somedatabase")).isFalse(); } private static boolean isUrlWithoutDatabase(String url) diff --git a/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/TestMariaDbTypeMapping.java b/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/TestMariaDbTypeMapping.java index 4c6e4d1f5641..ad153999d3c9 100644 --- a/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/TestMariaDbTypeMapping.java +++ b/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/TestMariaDbTypeMapping.java @@ -28,8 +28,10 @@ import io.trino.testing.sql.SqlExecutor; import io.trino.testing.sql.TestTable; import io.trino.testing.sql.TrinoSqlExecutor; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.parallel.Execution; import java.math.RoundingMode; import java.time.LocalDate; @@ -64,10 +66,14 @@ import static java.math.RoundingMode.UNNECESSARY; import static java.time.ZoneOffset.UTC; import static java.util.Arrays.asList; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; +import static org.junit.jupiter.api.parallel.ExecutionMode.CONCURRENT; /** * @see MariaDB data types */ +@TestInstance(PER_CLASS) +@Execution(CONCURRENT) public class TestMariaDbTypeMapping extends AbstractTestQueryFramework { @@ -79,7 +85,7 @@ public class TestMariaDbTypeMapping // minutes offset change since 1970-01-01, no DST private final ZoneId kathmandu = ZoneId.of("Asia/Kathmandu"); - @BeforeClass + @BeforeAll public void setUp() { checkState(jvmZone.getId().equals("America/Bahia_Banderas"), "This test assumes certain JVM time zone"); From 1a6bd2e8aa9e4e5e84bc3db8d65947da3a80c937 Mon Sep 17 00:00:00 2001 From: Martin Traverso Date: Tue, 14 Nov 2023 14:14:22 -0800 Subject: [PATCH 3/3] Remove unused method --- .../mariadb/TestMariaDbCaseInsensitiveMapping.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/TestMariaDbCaseInsensitiveMapping.java b/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/TestMariaDbCaseInsensitiveMapping.java index b8a9241c7a0a..698227f8e23c 100644 --- a/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/TestMariaDbCaseInsensitiveMapping.java +++ b/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/TestMariaDbCaseInsensitiveMapping.java @@ -18,7 +18,6 @@ import io.trino.plugin.jdbc.BaseCaseInsensitiveMappingTest; import io.trino.testing.QueryRunner; import io.trino.testing.sql.SqlExecutor; -import org.junit.jupiter.api.Test; import java.nio.file.Path; @@ -70,12 +69,4 @@ protected String quoted(String name) name = name.replace(identifierQuote, identifierQuote + identifierQuote); return identifierQuote + name + identifierQuote; } - - @Test - public void forceTestNgToRespectSingleThreaded() - { - // TODO: Remove after updating TestNG to 7.4.0+ (https://github.com/trinodb/trino/issues/8571) - // TestNG doesn't enforce @Test(singleThreaded = true) when tests are defined in base class. According to - // https://github.com/cbeust/testng/issues/2361#issuecomment-688393166 a workaround it to add a dummy test to the leaf test class. - } }