Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate tests to JUnit #19773

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions lib/trino-hdfs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -271,24 +271,6 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<dependencies>
<!-- allow both JUnit and TestNG -->
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit-platform</artifactId>
<version>${dep.plugin.surefire.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>${dep.plugin.surefire.version}</version>
</dependency>
</dependencies>
</plugin>

<plugin>
<groupId>ca.vanzyl.provisio.maven.plugins</groupId>
<artifactId>provisio-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.RawLocalFileSystem;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.parallel.Execution;

import java.io.File;
import java.io.IOException;
Expand All @@ -33,18 +35,21 @@

import static io.airlift.testing.Closeables.closeAll;
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.SAME_THREAD;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertSame;
import static org.testng.Assert.assertTrue;

@Test(singleThreaded = true) // e.g. test methods operate on shared, mutated tempFile
@TestInstance(PER_CLASS)
@Execution(SAME_THREAD) // e.g. test methods operate on shared, mutated tempFile
public class TestFSDataInputStreamTail
{
private File tempRoot;
private Path tempFile;
private RawLocalFileSystem fs;

@BeforeClass
@BeforeAll
public void setUp()
throws Exception
{
Expand All @@ -54,15 +59,15 @@ public void setUp()
tempFile = new Path(Files.createTempFile(tempRoot.toPath(), "tempfile", "txt").toUri());
}

@BeforeMethod
@BeforeEach
public void truncateTempFile()
throws Exception
{
// Truncate contents
fs.truncate(tempFile, 0);
}

@AfterClass(alwaysRun = true)
@AfterAll
public void tearDown()
throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.gaul.modernizer_maven_annotations.SuppressModernizer;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.parallel.Execution;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -38,15 +40,18 @@
import static io.trino.plugin.base.security.UserNameProvider.SIMPLE_USER_NAME_PROVIDER;
import static java.util.Objects.requireNonNull;
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.SAME_THREAD;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotSame;
import static org.testng.Assert.assertSame;

@Test(singleThreaded = true)
@TestInstance(PER_CLASS)
@Execution(SAME_THREAD)
public class TestFileSystemCache
{
@BeforeMethod(alwaysRun = true)
@AfterClass(alwaysRun = true)
@BeforeEach
@AfterAll
public void cleanup()
throws IOException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@
import io.trino.spi.predicate.Range;
import io.trino.spi.predicate.TupleDomain;
import io.trino.spi.predicate.ValueSet;
import io.trino.testing.DataProviders;
import org.apache.thrift.TException;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
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.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -113,12 +116,15 @@
import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.function.Function.identity;
import static org.assertj.core.api.Assertions.assertThat;
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.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

@Test(singleThreaded = true)
@TestInstance(PER_CLASS)
@Execution(SAME_THREAD)
public class TestCachingHiveMetastore
{
private static final Logger log = Logger.get(TestCachingHiveMetastore.class);
Expand All @@ -137,7 +143,7 @@ public class TestCachingHiveMetastore
private CachingHiveMetastore statsOnlyCacheMetastore;
private ThriftMetastoreStats stats;

@BeforeMethod
@BeforeEach
public void setUp()
{
mockClient = new MockThriftMetastoreClient();
Expand All @@ -150,7 +156,7 @@ public void setUp()
stats = ((ThriftHiveMetastore) thriftHiveMetastore).getStats();
}

@AfterClass(alwaysRun = true)
@AfterAll
public void tearDown()
{
executor.shutdownNow();
Expand Down Expand Up @@ -358,7 +364,8 @@ public void testGetPartitionThenGetPartitions()
* here simulated with an explicit invalidation.
*/
// Repeat test with invocationCount for better test coverage, since the tested aspect is inherently non-deterministic.
@Test(timeOut = 60_000, invocationCount = 20)
@RepeatedTest(20)
@Timeout(60)
public void testGetPartitionThenGetPartitionsRacingWithInvalidation()
throws Exception
{
Expand Down Expand Up @@ -928,8 +935,16 @@ public void testCachingHiveMetastoreCreationViaMemoize()
assertEquals(metastore.getDatabaseNamesStats().getRequestCount(), 0);
}

@Test(timeOut = 60_000, dataProviderClass = DataProviders.class, dataProvider = "trueFalse")
public void testLoadAfterInvalidate(boolean invalidateAll)
@Test
@Timeout(60)
public void testLoadAfterInvalidate()
throws Exception
{
testLoadAfterInvalidate(true);
testLoadAfterInvalidate(false);
}

private void testLoadAfterInvalidate(boolean invalidateAll)
throws Exception
{
// State
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
import io.trino.spi.type.Type;
import io.trino.testing.MaterializedResult;
import io.trino.testing.MaterializedRow;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.time.LocalDateTime;
Expand All @@ -41,8 +40,16 @@

public class TestTimestampMicros
{
@Test(dataProvider = "testTimestampMicrosDataProvider")
public void testTimestampMicros(HiveTimestampPrecision timestampPrecision, LocalDateTime expected)
@Test
public void testTimestampMicros()
throws Exception
{
testTimestampMicros(HiveTimestampPrecision.MILLISECONDS, LocalDateTime.parse("2020-10-12T16:26:02.907"));
testTimestampMicros(HiveTimestampPrecision.MICROSECONDS, LocalDateTime.parse("2020-10-12T16:26:02.906668"));
testTimestampMicros(HiveTimestampPrecision.NANOSECONDS, LocalDateTime.parse("2020-10-12T16:26:02.906668"));
}

private void testTimestampMicros(HiveTimestampPrecision timestampPrecision, LocalDateTime expected)
throws Exception
{
File parquetFile = new File(Resources.getResource("issue-5483.parquet").toURI());
Expand All @@ -55,8 +62,16 @@ public void testTimestampMicros(HiveTimestampPrecision timestampPrecision, Local
}
}

@Test(dataProvider = "testTimestampMicrosDataProvider")
public void testTimestampMicrosAsTimestampWithTimeZone(HiveTimestampPrecision timestampPrecision, LocalDateTime expected)
@Test
public void testTimestampMicrosAsTimestampWithTimeZone()
throws Exception
{
testTimestampMicrosAsTimestampWithTimeZone(HiveTimestampPrecision.MILLISECONDS, LocalDateTime.parse("2020-10-12T16:26:02.907"));
testTimestampMicrosAsTimestampWithTimeZone(HiveTimestampPrecision.MICROSECONDS, LocalDateTime.parse("2020-10-12T16:26:02.906668"));
testTimestampMicrosAsTimestampWithTimeZone(HiveTimestampPrecision.NANOSECONDS, LocalDateTime.parse("2020-10-12T16:26:02.906668"));
}

private void testTimestampMicrosAsTimestampWithTimeZone(HiveTimestampPrecision timestampPrecision, LocalDateTime expected)
throws Exception
{
File parquetFile = new File(Resources.getResource("issue-5483.parquet").toURI());
Expand All @@ -68,13 +83,4 @@ public void testTimestampMicrosAsTimestampWithTimeZone(HiveTimestampPrecision ti
.containsOnly(new MaterializedRow(List.of(expected.atZone(ZoneId.of("UTC")))));
}
}

@DataProvider
public static Object[][] testTimestampMicrosDataProvider()
{
return new Object[][] {
{HiveTimestampPrecision.MILLISECONDS, LocalDateTime.parse("2020-10-12T16:26:02.907")},
{HiveTimestampPrecision.MICROSECONDS, LocalDateTime.parse("2020-10-12T16:26:02.906668")},
{HiveTimestampPrecision.NANOSECONDS, LocalDateTime.parse("2020-10-12T16:26:02.906668")}};
}
}
19 changes: 0 additions & 19 deletions plugin/trino-kinesis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,6 @@
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -221,19 +215,6 @@
<kinesis.test-table-description-location>s3://S3-LOC</kinesis.test-table-description-location>
</systemPropertyVariables>
</configuration>
<dependencies>
<!-- allow both JUnit and TestNG -->
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit-platform</artifactId>
<version>${dep.plugin.surefire.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>${dep.plugin.surefire.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.basepom.maven</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
import static com.google.common.collect.Iterables.getOnlyElement;
import static io.trino.spi.transaction.IsolationLevel.READ_COMMITTED;
import static io.trino.testing.TestingConnectorSession.SESSION;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;

/**
* Test that the plug in API is satisfied and all of the required objects can be created.
Expand All @@ -51,16 +50,16 @@ public void testCreateConnector()
.put("kinesis.secret-key", TestUtils.noneToBlank(secretKey))
.put("bootstrap.quiet", "true")
.buildOrThrow(), new TestingConnectorContext());
assertNotNull(c);
assertThat(c).isNotNull();

// Verify that the key objects have been created on the connector
assertNotNull(c.getRecordSetProvider());
assertNotNull(c.getSplitManager());
assertThat(c.getRecordSetProvider()).isNotNull();
assertThat(c.getSplitManager()).isNotNull();
ConnectorMetadata md = c.getMetadata(SESSION, KinesisTransactionHandle.INSTANCE);
assertNotNull(md);
assertThat(md).isNotNull();

ConnectorTransactionHandle handle = c.beginTransaction(READ_COMMITTED, true, true);
assertTrue(handle instanceof KinesisTransactionHandle);
assertThat(handle instanceof KinesisTransactionHandle).isTrue();

c.shutdown();
}
Expand Down
Loading
Loading