Skip to content

Commit db9f1b9

Browse files
committed
Migrate selected Iceberg tests to JUnit
1 parent 82733ce commit db9f1b9

File tree

7 files changed

+83
-60
lines changed

7 files changed

+83
-60
lines changed

plugin/trino-iceberg/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,12 @@
576576
<scope>test</scope>
577577
</dependency>
578578

579+
<dependency>
580+
<groupId>org.junit.jupiter</groupId>
581+
<artifactId>junit-jupiter-params</artifactId>
582+
<scope>test</scope>
583+
</dependency>
584+
579585
<dependency>
580586
<groupId>org.testcontainers</groupId>
581587
<artifactId>postgresql</artifactId>

plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergBucketing.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
import org.apache.iceberg.types.Types.DecimalType;
3131
import org.apache.iceberg.types.Types.DoubleType;
3232
import org.apache.iceberg.types.Types.FloatType;
33-
import org.testng.annotations.DataProvider;
34-
import org.testng.annotations.Test;
33+
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.params.ParameterizedTest;
35+
import org.junit.jupiter.params.provider.MethodSource;
3536

3637
import java.math.BigDecimal;
3738
import java.nio.ByteBuffer;
@@ -187,7 +188,8 @@ public void testBucketingSpecValues()
187188
assertBucketAndHashEquals("binary", ByteBuffer.wrap(new byte[] {0x00, 0x01, 0x02, 0x03}), -188683207 & Integer.MAX_VALUE);
188189
}
189190

190-
@Test(dataProvider = "unsupportedBucketingTypes")
191+
@ParameterizedTest
192+
@MethodSource("unsupportedBucketingTypes")
191193
public void testUnsupportedTypes(Type type)
192194
{
193195
assertThatThrownBy(() -> computeIcebergBucket(type, null, 1))
@@ -197,8 +199,7 @@ public void testUnsupportedTypes(Type type)
197199
.hasMessage("Unsupported type for 'bucket': %s", toTrinoType(type, TYPE_MANAGER));
198200
}
199201

200-
@DataProvider
201-
public Object[][] unsupportedBucketingTypes()
202+
public static Object[][] unsupportedBucketingTypes()
202203
{
203204
return new Object[][] {
204205
{BooleanType.get()},

plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergFileOperations.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@
2929
import io.trino.testing.DistributedQueryRunner;
3030
import org.apache.iceberg.util.ThreadPools;
3131
import org.intellij.lang.annotations.Language;
32-
import org.testng.annotations.DataProvider;
33-
import org.testng.annotations.Test;
32+
import org.junit.jupiter.api.Test;
33+
import org.junit.jupiter.api.parallel.Execution;
34+
import org.junit.jupiter.api.parallel.ExecutionMode;
35+
import org.junit.jupiter.params.ParameterizedTest;
36+
import org.junit.jupiter.params.provider.MethodSource;
3437

3538
import java.io.File;
3639
import java.util.Optional;
@@ -66,7 +69,7 @@
6669
import static java.util.Objects.requireNonNull;
6770
import static java.util.stream.Collectors.toCollection;
6871

69-
@Test(singleThreaded = true) // e.g. trackingFileSystemFactory is shared mutable state
72+
@Execution(ExecutionMode.SAME_THREAD) // e.g. trackingFileSystemFactory is shared mutable state
7073
public class TestIcebergFileOperations
7174
extends AbstractTestQueryFramework
7275
{
@@ -167,7 +170,8 @@ public void testSelect()
167170
.build());
168171
}
169172

170-
@Test(dataProvider = "testSelectWithLimitDataProvider")
173+
@ParameterizedTest
174+
@MethodSource("testSelectWithLimitDataProvider")
171175
public void testSelectWithLimit(int numberOfFiles)
172176
{
173177
assertUpdate("DROP TABLE IF EXISTS test_select_with_limit"); // test is parameterized
@@ -210,7 +214,6 @@ public void testSelectWithLimit(int numberOfFiles)
210214
assertUpdate("DROP TABLE test_select_with_limit");
211215
}
212216

213-
@DataProvider
214217
public Object[][] testSelectWithLimitDataProvider()
215218
{
216219
return new Object[][] {
@@ -594,7 +597,8 @@ public void testRemoveOrphanFiles()
594597
assertUpdate("DROP TABLE " + tableName);
595598
}
596599

597-
@Test(dataProvider = "metadataQueriesTestTableCountDataProvider")
600+
@ParameterizedTest
601+
@MethodSource("metadataQueriesTestTableCountDataProvider")
598602
public void testInformationSchemaColumns(int tables)
599603
{
600604
String schemaName = "test_i_s_columns_schema" + randomNameSuffix();
@@ -636,7 +640,8 @@ public void testInformationSchemaColumns(int tables)
636640
}
637641
}
638642

639-
@Test(dataProvider = "metadataQueriesTestTableCountDataProvider")
643+
@ParameterizedTest
644+
@MethodSource("metadataQueriesTestTableCountDataProvider")
640645
public void testSystemMetadataTableComments(int tables)
641646
{
642647
String schemaName = "test_s_m_table_comments" + randomNameSuffix();
@@ -678,7 +683,6 @@ public void testSystemMetadataTableComments(int tables)
678683
}
679684
}
680685

681-
@DataProvider
682686
public Object[][] metadataQueriesTestTableCountDataProvider()
683687
{
684688
return new Object[][] {

plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetastoreAccessOperations.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
import io.trino.testing.AbstractTestQueryFramework;
2323
import io.trino.testing.DistributedQueryRunner;
2424
import org.intellij.lang.annotations.Language;
25-
import org.testng.annotations.DataProvider;
26-
import org.testng.annotations.Test;
25+
import org.junit.jupiter.api.Test;
26+
import org.junit.jupiter.api.parallel.Execution;
27+
import org.junit.jupiter.api.parallel.ExecutionMode;
28+
import org.junit.jupiter.params.ParameterizedTest;
29+
import org.junit.jupiter.params.provider.MethodSource;
2730

2831
import java.io.File;
2932
import java.util.Optional;
@@ -50,7 +53,7 @@
5053
import static io.trino.testing.TestingSession.testSessionBuilder;
5154
import static org.assertj.core.api.Assertions.assertThat;
5255

53-
@Test(singleThreaded = true) // metastore invocation counters shares mutable state so can't be run from many threads simultaneously
56+
@Execution(ExecutionMode.SAME_THREAD) // metastore invocation counters shares mutable state so can't be run from many threads simultaneously
5457
public class TestIcebergMetastoreAccessOperations
5558
extends AbstractTestQueryFramework
5659
{
@@ -326,7 +329,8 @@ public void testUnregisterTable()
326329
.build());
327330
}
328331

329-
@Test(dataProvider = "metadataQueriesTestTableCountDataProvider")
332+
@ParameterizedTest
333+
@MethodSource("metadataQueriesTestTableCountDataProvider")
330334
public void testInformationSchemaColumns(int tables)
331335
{
332336
String schemaName = "test_i_s_columns_schema" + randomNameSuffix();
@@ -371,7 +375,8 @@ public void testInformationSchemaColumns(int tables)
371375
}
372376
}
373377

374-
@Test(dataProvider = "metadataQueriesTestTableCountDataProvider")
378+
@ParameterizedTest
379+
@MethodSource("metadataQueriesTestTableCountDataProvider")
375380
public void testSystemMetadataTableComments(int tables)
376381
{
377382
String schemaName = "test_s_m_table_comments" + randomNameSuffix();
@@ -417,7 +422,6 @@ public void testSystemMetadataTableComments(int tables)
417422
}
418423
}
419424

420-
@DataProvider
421425
public Object[][] metadataQueriesTestTableCountDataProvider()
422426
{
423427
return new Object[][] {

plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMigrateProcedure.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
import io.trino.testing.AbstractTestQueryFramework;
2020
import io.trino.testing.DistributedQueryRunner;
2121
import io.trino.testing.QueryRunner;
22-
import org.testng.annotations.DataProvider;
23-
import org.testng.annotations.Test;
22+
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.params.ParameterizedTest;
24+
import org.junit.jupiter.params.provider.MethodSource;
2425

2526
import java.nio.file.Files;
2627
import java.nio.file.Path;
@@ -47,14 +48,15 @@ protected QueryRunner createQueryRunner()
4748
DistributedQueryRunner queryRunner = IcebergQueryRunner.builder().setMetastoreDirectory(dataDirectory.toFile()).build();
4849
queryRunner.installPlugin(new TestingHivePlugin());
4950
queryRunner.createCatalog("hive", "hive", ImmutableMap.<String, String>builder()
50-
.put("hive.metastore", "file")
51-
.put("hive.metastore.catalog.dir", dataDirectory.toString())
52-
.put("hive.security", "allow-all")
51+
.put("hive.metastore", "file")
52+
.put("hive.metastore.catalog.dir", dataDirectory.toString())
53+
.put("hive.security", "allow-all")
5354
.buildOrThrow());
5455
return queryRunner;
5556
}
5657

57-
@Test(dataProvider = "fileFormats")
58+
@ParameterizedTest
59+
@MethodSource("fileFormats")
5860
public void testMigrateTable(IcebergFileFormat fileFormat)
5961
{
6062
String tableName = "test_migrate_" + randomNameSuffix();
@@ -78,7 +80,8 @@ public void testMigrateTable(IcebergFileFormat fileFormat)
7880
assertUpdate("DROP TABLE " + tableName);
7981
}
8082

81-
@Test(dataProvider = "fileFormats")
83+
@ParameterizedTest
84+
@MethodSource("fileFormats")
8285
public void testMigrateTableWithTinyintType(IcebergFileFormat fileFormat)
8386
{
8487
String tableName = "test_migrate_tinyint" + randomNameSuffix();
@@ -105,7 +108,8 @@ public void testMigrateTableWithTinyintType(IcebergFileFormat fileFormat)
105108
assertUpdate("DROP TABLE " + tableName);
106109
}
107110

108-
@Test(dataProvider = "fileFormats")
111+
@ParameterizedTest
112+
@MethodSource("fileFormats")
109113
public void testMigrateTableWithSmallintType(IcebergFileFormat fileFormat)
110114
{
111115
String tableName = "test_migrate_smallint" + randomNameSuffix();
@@ -132,7 +136,6 @@ public void testMigrateTableWithSmallintType(IcebergFileFormat fileFormat)
132136
assertUpdate("DROP TABLE " + tableName);
133137
}
134138

135-
@DataProvider
136139
public static Object[][] fileFormats()
137140
{
138141
return Stream.of(IcebergFileFormat.values())

plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergRegisterTableProcedure.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@
3232
import org.apache.iceberg.Table;
3333
import org.apache.iceberg.hadoop.HadoopTables;
3434
import org.apache.iceberg.types.Types;
35-
import org.testng.annotations.AfterClass;
36-
import org.testng.annotations.BeforeClass;
37-
import org.testng.annotations.DataProvider;
38-
import org.testng.annotations.Test;
35+
import org.junit.jupiter.api.AfterAll;
36+
import org.junit.jupiter.api.BeforeAll;
37+
import org.junit.jupiter.api.Test;
38+
import org.junit.jupiter.params.ParameterizedTest;
39+
import org.junit.jupiter.params.provider.EnumSource;
3940

4041
import java.io.File;
4142
import java.io.IOException;
4243
import java.nio.file.Files;
4344
import java.nio.file.Path;
4445
import java.util.regex.Matcher;
4546
import java.util.regex.Pattern;
46-
import java.util.stream.Stream;
4747

4848
import static com.google.common.base.Verify.verify;
4949
import static com.google.common.io.MoreFiles.deleteRecursively;
@@ -80,28 +80,21 @@ protected QueryRunner createQueryRunner()
8080
.build();
8181
}
8282

83-
@BeforeClass
83+
@BeforeAll
8484
public void initFileSystem()
8585
{
8686
fileSystem = getFileSystemFactory(getDistributedQueryRunner()).create(SESSION);
8787
}
8888

89-
@AfterClass(alwaysRun = true)
89+
@AfterAll
9090
public void tearDown()
9191
throws IOException
9292
{
9393
deleteRecursively(metastoreDir.toPath(), ALLOW_INSECURE);
9494
}
9595

96-
@DataProvider
97-
public static Object[][] fileFormats()
98-
{
99-
return Stream.of(IcebergFileFormat.values())
100-
.map(icebergFileFormat -> new Object[] {icebergFileFormat})
101-
.toArray(Object[][]::new);
102-
}
103-
104-
@Test(dataProvider = "fileFormats")
96+
@ParameterizedTest
97+
@EnumSource(IcebergFileFormat.class)
10598
public void testRegisterTableWithTableLocation(IcebergFileFormat icebergFileFormat)
10699
{
107100
String tableName = "test_register_table_with_table_location_" + icebergFileFormat.name().toLowerCase(ENGLISH) + "_" + randomNameSuffix();
@@ -123,7 +116,8 @@ public void testRegisterTableWithTableLocation(IcebergFileFormat icebergFileForm
123116
assertUpdate(format("DROP TABLE %s", tableName));
124117
}
125118

126-
@Test(dataProvider = "fileFormats")
119+
@ParameterizedTest
120+
@EnumSource(IcebergFileFormat.class)
127121
public void testRegisterPartitionedTable(IcebergFileFormat icebergFileFormat)
128122
{
129123
String tableName = "test_register_partitioned_table_" + icebergFileFormat.name().toLowerCase(ENGLISH) + "_" + randomNameSuffix();
@@ -145,7 +139,8 @@ public void testRegisterPartitionedTable(IcebergFileFormat icebergFileFormat)
145139
assertUpdate("DROP TABLE " + tableName);
146140
}
147141

148-
@Test(dataProvider = "fileFormats")
142+
@ParameterizedTest
143+
@EnumSource(IcebergFileFormat.class)
149144
public void testRegisterTableWithComments(IcebergFileFormat icebergFileFormat)
150145
{
151146
String tableName = "test_register_table_with_comments_" + icebergFileFormat.name().toLowerCase(ENGLISH) + "_" + randomNameSuffix();
@@ -171,7 +166,8 @@ public void testRegisterTableWithComments(IcebergFileFormat icebergFileFormat)
171166
assertUpdate(format("DROP TABLE %s", tableName));
172167
}
173168

174-
@Test(dataProvider = "fileFormats")
169+
@ParameterizedTest
170+
@EnumSource(IcebergFileFormat.class)
175171
public void testRegisterTableWithShowCreateTable(IcebergFileFormat icebergFileFormat)
176172
{
177173
String tableName = "test_register_table_with_show_create_table_" + icebergFileFormat.name().toLowerCase(ENGLISH) + "_" + randomNameSuffix();
@@ -191,7 +187,8 @@ public void testRegisterTableWithShowCreateTable(IcebergFileFormat icebergFileFo
191187
assertUpdate(format("DROP TABLE %s", tableName));
192188
}
193189

194-
@Test(dataProvider = "fileFormats")
190+
@ParameterizedTest
191+
@EnumSource(IcebergFileFormat.class)
195192
public void testRegisterTableWithReInsert(IcebergFileFormat icebergFileFormat)
196193
{
197194
String tableName = "test_register_table_with_re_insert_" + icebergFileFormat.name().toLowerCase(ENGLISH) + "_" + randomNameSuffix();
@@ -215,7 +212,8 @@ public void testRegisterTableWithReInsert(IcebergFileFormat icebergFileFormat)
215212
assertUpdate(format("DROP TABLE %s", tableName));
216213
}
217214

218-
@Test(dataProvider = "fileFormats")
215+
@ParameterizedTest
216+
@EnumSource(IcebergFileFormat.class)
219217
public void testRegisterTableWithDroppedTable(IcebergFileFormat icebergFileFormat)
220218
{
221219
String tableName = "test_register_table_with_dropped_table_" + icebergFileFormat.name().toLowerCase(ENGLISH) + "_" + randomNameSuffix();
@@ -233,7 +231,8 @@ public void testRegisterTableWithDroppedTable(IcebergFileFormat icebergFileForma
233231
".*No versioned metadata file exists at location.*");
234232
}
235233

236-
@Test(dataProvider = "fileFormats")
234+
@ParameterizedTest
235+
@EnumSource(IcebergFileFormat.class)
237236
public void testRegisterTableWithDifferentTableName(IcebergFileFormat icebergFileFormat)
238237
{
239238
String tableName = "test_register_table_with_different_table_name_old_" + icebergFileFormat.name().toLowerCase(ENGLISH) + "_" + randomNameSuffix();
@@ -258,7 +257,8 @@ public void testRegisterTableWithDifferentTableName(IcebergFileFormat icebergFil
258257
assertUpdate(format("DROP TABLE %s", tableNameNew));
259258
}
260259

261-
@Test(dataProvider = "fileFormats")
260+
@ParameterizedTest
261+
@EnumSource(IcebergFileFormat.class)
262262
public void testRegisterTableWithMetadataFile(IcebergFileFormat icebergFileFormat)
263263
{
264264
String tableName = "test_register_table_with_metadata_file_" + icebergFileFormat.name().toLowerCase(ENGLISH) + "_" + randomNameSuffix();

0 commit comments

Comments
 (0)