Skip to content

Commit 0fe68bb

Browse files
committed
Migrate tests to JUnit
1 parent baf3e30 commit 0fe68bb

File tree

43 files changed

+485
-228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+485
-228
lines changed

plugin/trino-accumulo/src/test/java/io/trino/plugin/accumulo/TestAccumuloConnectorTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
import io.trino.testing.sql.TestTable;
2222
import org.intellij.lang.annotations.Language;
2323
import org.junit.jupiter.api.Test;
24-
import org.testng.SkipException;
2524

2625
import java.util.Optional;
2726

2827
import static io.trino.plugin.accumulo.AccumuloQueryRunner.createAccumuloQueryRunner;
2928
import static io.trino.spi.type.VarcharType.VARCHAR;
3029
import static io.trino.testing.MaterializedResult.resultBuilder;
3130
import static org.assertj.core.api.Assertions.assertThatThrownBy;
31+
import static org.junit.jupiter.api.Assumptions.abort;
3232
import static org.testng.Assert.assertEquals;
3333
import static org.testng.Assert.assertFalse;
3434
import static org.testng.Assert.assertTrue;
@@ -78,9 +78,10 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
7878
@Override
7979
protected TestTable createTableWithDefaultColumns()
8080
{
81-
throw new SkipException("Accumulo connector does not support column default values");
81+
return abort("Accumulo connector does not support column default values");
8282
}
8383

84+
@Test
8485
@Override
8586
public void testCreateTableAsSelect()
8687
{
@@ -115,6 +116,7 @@ public void testCreateTableAsSelect()
115116
"SELECT 0");
116117
}
117118

119+
@Test
118120
@Override
119121
public void testInsert()
120122
{
@@ -151,6 +153,7 @@ public void testInsert()
151153
assertUpdate("DROP TABLE test_insert");
152154
}
153155

156+
@Test
154157
@Override // Overridden because we currently do not support arrays with null elements
155158
public void testInsertArray()
156159
{
@@ -297,6 +300,7 @@ protected Optional<DataMappingTestSetup> filterCaseSensitiveDataMappingTestData(
297300
return Optional.of(dataMappingTestSetup);
298301
}
299302

303+
@Test
300304
@Override
301305
public void testCharVarcharComparison()
302306
{

plugin/trino-base-jdbc/src/test/java/io/trino/plugin/jdbc/BaseJdbcConnectorTest.java

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@
4242
import io.trino.testing.sql.TestTable;
4343
import io.trino.testing.sql.TestView;
4444
import org.intellij.lang.annotations.Language;
45-
import org.testng.SkipException;
46-
import org.testng.annotations.AfterClass;
47-
import org.testng.annotations.Test;
45+
import org.junit.jupiter.api.AfterAll;
46+
import org.junit.jupiter.api.Test;
47+
import org.junit.jupiter.api.TestInstance;
48+
import org.junit.jupiter.api.Timeout;
4849

4950
import java.util.ArrayList;
5051
import java.util.List;
@@ -116,15 +117,18 @@
116117
import static java.util.concurrent.TimeUnit.MINUTES;
117118
import static org.assertj.core.api.Assertions.assertThat;
118119
import static org.assertj.core.api.Assertions.assertThatThrownBy;
120+
import static org.junit.jupiter.api.Assumptions.abort;
121+
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
119122

123+
@TestInstance(PER_CLASS)
120124
public abstract class BaseJdbcConnectorTest
121125
extends BaseConnectorTest
122126
{
123127
private final ExecutorService executor = newCachedThreadPool(daemonThreadsNamed(getClass().getName()));
124128

125129
protected abstract SqlExecutor onRemoteDatabase();
126130

127-
@AfterClass(alwaysRun = true)
131+
@AfterAll
128132
public void afterClass()
129133
{
130134
executor.shutdownNow();
@@ -167,7 +171,7 @@ public void testInsertInPresenceOfNotSupportedColumn()
167171
protected TestTable createTableWithUnsupportedColumn()
168172
{
169173
// TODO throw new UnsupportedOperationException();
170-
throw new SkipException("Not implemented");
174+
return abort("Not implemented");
171175
}
172176

173177
// TODO move common tests from connector-specific classes here
@@ -577,7 +581,7 @@ public void testNumericAggregationPushdown()
577581
public void testCountDistinctWithStringTypes()
578582
{
579583
if (!(hasBehavior(SUPPORTS_CREATE_TABLE) && hasBehavior(SUPPORTS_INSERT))) {
580-
throw new SkipException("Unable to CREATE TABLE to test count distinct");
584+
abort("Unable to CREATE TABLE to test count distinct");
581585
}
582586

583587
List<String> rows = Stream.of("a", "b", "A", "B", " a ", "a", "b", " b ", "ą")
@@ -643,7 +647,7 @@ public void testStddevAggregationPushdown()
643647
String schemaName = getSession().getSchema().orElseThrow();
644648
if (!hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN_STDDEV)) {
645649
if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
646-
throw new SkipException("Unable to CREATE TABLE to test aggregation pushdown");
650+
abort("Unable to CREATE TABLE to test aggregation pushdown");
647651
}
648652

649653
try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_stddev_pushdown", ImmutableList.of())) {
@@ -694,7 +698,7 @@ public void testVarianceAggregationPushdown()
694698
String schemaName = getSession().getSchema().orElseThrow();
695699
if (!hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN_VARIANCE)) {
696700
if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
697-
throw new SkipException("Unable to CREATE TABLE to test aggregation pushdown");
701+
abort("Unable to CREATE TABLE to test aggregation pushdown");
698702
}
699703

700704
try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_var_pushdown", ImmutableList.of())) {
@@ -738,7 +742,7 @@ public void testCovarianceAggregationPushdown()
738742
String schemaName = getSession().getSchema().orElseThrow();
739743
if (!hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN_COVARIANCE)) {
740744
if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
741-
throw new SkipException("Unable to CREATE TABLE to test aggregation pushdown");
745+
abort("Unable to CREATE TABLE to test aggregation pushdown");
742746
}
743747

744748
try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_covar_pushdown", ImmutableList.of())) {
@@ -775,7 +779,7 @@ public void testCorrAggregationPushdown()
775779
String schemaName = getSession().getSchema().orElseThrow();
776780
if (!hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN_CORRELATION)) {
777781
if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
778-
throw new SkipException("Unable to CREATE TABLE to test aggregation pushdown");
782+
abort("Unable to CREATE TABLE to test aggregation pushdown");
779783
}
780784

781785
try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_corr_pushdown", ImmutableList.of())) {
@@ -808,7 +812,7 @@ public void testRegrAggregationPushdown()
808812
String schemaName = getSession().getSchema().orElseThrow();
809813
if (!hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN_REGRESSION)) {
810814
if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
811-
throw new SkipException("Unable to CREATE TABLE to test aggregation pushdown");
815+
abort("Unable to CREATE TABLE to test aggregation pushdown");
812816
}
813817

814818
try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_regr_pushdown", ImmutableList.of())) {
@@ -1455,12 +1459,13 @@ protected Session joinPushdownEnabled(Session session)
14551459
.build();
14561460
}
14571461

1458-
@Test(timeOut = 60_000)
1462+
@Test
1463+
@Timeout(60)
14591464
public void testCancellation()
14601465
throws Exception
14611466
{
14621467
if (!hasBehavior(SUPPORTS_CANCELLATION)) {
1463-
throw new SkipException("Cancellation is not supported by given connector");
1468+
abort("Cancellation is not supported by given connector");
14641469
}
14651470

14661471
try (TestView sleepingView = createSleepingView(new Duration(1, MINUTES))) {
@@ -1512,6 +1517,7 @@ protected TestView createSleepingView(Duration minimalSleepDuration)
15121517
throw new UnsupportedOperationException();
15131518
}
15141519

1520+
@Test
15151521
@Override
15161522
public void testUpdateNotNullColumn()
15171523
{
@@ -1538,6 +1544,7 @@ public void testUpdateNotNullColumn()
15381544
}
15391545
}
15401546

1547+
@Test
15411548
@Override
15421549
public void testUpdateRowType()
15431550
{
@@ -1555,6 +1562,7 @@ public void testUpdateRowType()
15551562
}
15561563
}
15571564

1565+
@Test
15581566
@Override
15591567
public void testUpdateRowConcurrently()
15601568
throws Exception
@@ -1571,6 +1579,7 @@ public void testUpdateRowConcurrently()
15711579
}
15721580
}
15731581

1582+
@Test
15741583
@Override
15751584
public void testUpdateAllValues()
15761585
{
@@ -1586,6 +1595,7 @@ public void testUpdateAllValues()
15861595
}
15871596
}
15881597

1598+
@Test
15891599
@Override
15901600
public void testUpdateWithPredicates()
15911601
{
@@ -1744,6 +1754,7 @@ public void testDeleteWithVarcharGreaterAndLowerPredicate()
17441754
}
17451755
}
17461756

1757+
@Test
17471758
@Override
17481759
public void testDeleteWithComplexPredicate()
17491760
{
@@ -1756,6 +1767,7 @@ public void testDeleteWithComplexPredicate()
17561767
.hasStackTraceContaining("TrinoException: " + MODIFYING_ROWS_MESSAGE);
17571768
}
17581769

1770+
@Test
17591771
@Override
17601772
public void testDeleteWithSubquery()
17611773
{
@@ -1768,6 +1780,7 @@ public void testDeleteWithSubquery()
17681780
.hasStackTraceContaining("TrinoException: " + MODIFYING_ROWS_MESSAGE);
17691781
}
17701782

1783+
@Test
17711784
@Override
17721785
public void testExplainAnalyzeWithDeleteWithSubquery()
17731786
{
@@ -1780,6 +1793,7 @@ public void testExplainAnalyzeWithDeleteWithSubquery()
17801793
.hasStackTraceContaining("TrinoException: " + MODIFYING_ROWS_MESSAGE);
17811794
}
17821795

1796+
@Test
17831797
@Override
17841798
public void testDeleteWithSemiJoin()
17851799
{
@@ -1792,17 +1806,18 @@ public void testDeleteWithSemiJoin()
17921806
.hasStackTraceContaining("TrinoException: " + MODIFYING_ROWS_MESSAGE);
17931807
}
17941808

1809+
@Test
17951810
@Override
17961811
public void testDeleteWithVarcharPredicate()
17971812
{
1798-
throw new SkipException("This is implemented by testDeleteWithVarcharEqualityPredicate");
1813+
abort("This is implemented by testDeleteWithVarcharEqualityPredicate");
17991814
}
18001815

18011816
@Test
18021817
public void testInsertWithoutTemporaryTable()
18031818
{
18041819
if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
1805-
throw new SkipException("CREATE TABLE is required for testing non-transactional write support");
1820+
abort("CREATE TABLE is required for testing non-transactional write support");
18061821
}
18071822
Session session = Session.builder(getSession())
18081823
.setCatalogSessionProperty(getSession().getCatalog().orElseThrow(), "non_transactional_insert", "false")
@@ -1832,7 +1847,7 @@ public void testWriteBatchSizeSessionProperty()
18321847
private void testWriteBatchSizeSessionProperty(int batchSize, int numberOfRows)
18331848
{
18341849
if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
1835-
throw new SkipException("CREATE TABLE is required for write_batch_size test but is not supported");
1850+
abort("CREATE TABLE is required for write_batch_size test but is not supported");
18361851
}
18371852
Session session = Session.builder(getSession())
18381853
.setCatalogSessionProperty(getSession().getCatalog().orElseThrow(), "write_batch_size", Integer.toString(batchSize))
@@ -1861,7 +1876,7 @@ public void testWriteTaskParallelismSessionProperty()
18611876
private void testWriteTaskParallelismSessionProperty(int parallelism, int numberOfRows)
18621877
{
18631878
if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
1864-
throw new SkipException("CREATE TABLE is required for write_parallelism test but is not supported");
1879+
abort("CREATE TABLE is required for write_parallelism test but is not supported");
18651880
}
18661881

18671882
Session session = Session.builder(getSession())

plugin/trino-base-jdbc/src/test/java/io/trino/plugin/jdbc/TestJdbcConnectorTest.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
import io.trino.testing.TestingConnectorBehavior;
2121
import io.trino.testing.sql.JdbcSqlExecutor;
2222
import io.trino.testing.sql.TestTable;
23-
import org.testng.SkipException;
24-
import org.testng.annotations.Test;
23+
import org.junit.jupiter.api.Test;
24+
import org.junit.jupiter.api.TestInstance;
25+
import org.junit.jupiter.api.parallel.Execution;
26+
import org.junit.jupiter.api.parallel.ExecutionMode;
2527

2628
import java.util.Map;
2729
import java.util.Optional;
@@ -37,10 +39,13 @@
3739
import static java.util.Locale.ENGLISH;
3840
import static org.assertj.core.api.Assertions.assertThat;
3941
import static org.assertj.core.api.Assertions.assertThatThrownBy;
42+
import static org.junit.jupiter.api.Assumptions.abort;
43+
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
4044

4145
// Single-threaded because H2 DDL operations can sometimes take a global lock, leading to apparent deadlocks
4246
// like in https://github.com/trinodb/trino/issues/7209.
43-
@Test(singleThreaded = true)
47+
@TestInstance(PER_CLASS)
48+
@Execution(ExecutionMode.SAME_THREAD)
4449
public class TestJdbcConnectorTest
4550
extends BaseJdbcConnectorTest
4651
{
@@ -75,8 +80,8 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
7580
};
7681
}
7782

83+
@Test
7884
@Override
79-
@org.junit.jupiter.api.Test
8085
public void testLargeIn()
8186
{
8287
// This test should pass with H2, but takes too long (currently over a mninute) and is not that important
@@ -121,19 +126,21 @@ protected Optional<DataMappingTestSetup> filterDataMappingSmokeTestData(DataMapp
121126
return Optional.of(dataMappingTestSetup);
122127
}
123128

129+
@Test
124130
@Override
125131
public void testDeleteWithLike()
126132
{
127133
assertThatThrownBy(super::testDeleteWithLike)
128134
.hasStackTraceContaining("TrinoException: " + MODIFYING_ROWS_MESSAGE);
129135
}
130136

137+
@Test
131138
@Override
132139
public void testReadMetadataWithRelationsConcurrentModifications()
133140
{
134141
// Under concurrently, H2 sometimes returns null table name in DatabaseMetaData.getTables's ResultSet
135142
// See https://github.com/trinodb/trino/issues/16658 for more information
136-
throw new SkipException("Skipped due to H2 problems");
143+
abort("Skipped due to H2 problems");
137144
}
138145

139146
@Test
@@ -252,6 +259,7 @@ public void testTableWithOnlyUnsupportedColumns()
252259
}
253260
}
254261

262+
@Test
255263
@Override
256264
public void testNativeQueryColumnAlias()
257265
{
@@ -271,11 +279,12 @@ protected void verifyAddNotNullColumnToNonEmptyTableFailurePermissible(Throwable
271279
assertThat(e).hasMessageContaining("NULL not allowed for column");
272280
}
273281

282+
@Test
274283
@Override
275284
public void testAddColumnConcurrently()
276285
{
277286
// TODO: Difficult to determine whether the exception is concurrent issue or not from the error message
278-
throw new SkipException("TODO: Enable this test after finding the failure cause");
287+
abort("TODO: Enable this test after finding the failure cause");
279288
}
280289

281290
@Override

0 commit comments

Comments
 (0)