Skip to content

Commit

Permalink
Migrate tests to JUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
martint committed Nov 16, 2023
1 parent 5618fce commit 9e944eb
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 167 deletions.
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 @@ -49,9 +49,13 @@
import io.trino.spi.predicate.TupleDomain;
import io.trino.spi.predicate.ValueSet;
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 @@ -112,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 @@ -136,7 +143,7 @@ public class TestCachingHiveMetastore
private CachingHiveMetastore statsOnlyCacheMetastore;
private ThriftMetastoreStats stats;

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

@AfterClass(alwaysRun = true)
@AfterAll
public void tearDown()
{
executor.shutdownNow();
Expand Down Expand Up @@ -357,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 @@ -927,7 +935,8 @@ public void testCachingHiveMetastoreCreationViaMemoize()
assertEquals(metastore.getDatabaseNamesStats().getRequestCount(), 0);
}

@Test(timeOut = 60_000)
@Test
@Timeout(60)
public void testLoadAfterInvalidate()
throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io.trino.spi.type.Type;
import io.trino.testing.MaterializedResult;
import io.trino.testing.MaterializedRow;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.time.LocalDateTime;
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@
import java.util.Map;

import static io.trino.testing.TestingConnectorSession.SESSION;
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.CONCURRENT;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

@TestInstance(PER_CLASS)
@Execution(CONCURRENT)
Expand Down Expand Up @@ -70,55 +68,55 @@ public void testTableDefinition()
KinesisMetadata metadata = (KinesisMetadata) connector.getMetadata(SESSION, new ConnectorTransactionHandle() {});
SchemaTableName tblName = new SchemaTableName("prod", "test_table");
KinesisTableHandle tableHandle = metadata.getTableHandle(SESSION, tblName);
assertNotNull(metadata);
assertThat(metadata).isNotNull();
SchemaTableName tableSchemaName = tableHandle.toSchemaTableName();
assertEquals(tableSchemaName.getSchemaName(), "prod");
assertEquals(tableSchemaName.getTableName(), "test_table");
assertEquals(tableHandle.getStreamName(), "test_kinesis_stream");
assertEquals(tableHandle.getMessageDataFormat(), "json");
assertThat(tableSchemaName.getSchemaName()).isEqualTo("prod");
assertThat(tableSchemaName.getTableName()).isEqualTo("test_table");
assertThat(tableHandle.getStreamName()).isEqualTo("test_kinesis_stream");
assertThat(tableHandle.getMessageDataFormat()).isEqualTo("json");
Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(SESSION, tableHandle);
assertEquals(columnHandles.size(), 14);
assertEquals(columnHandles.values().stream().filter(x -> ((KinesisColumnHandle) x).isInternal()).count(), 10);
assertThat(columnHandles.size()).isEqualTo(14);
assertThat(columnHandles.values().stream().filter(x -> ((KinesisColumnHandle) x).isInternal()).count()).isEqualTo(10);
}

@Test
public void testRelatedObjects()
{
KinesisMetadata metadata = (KinesisMetadata) connector.getMetadata(SESSION, new ConnectorTransactionHandle() {});
assertNotNull(metadata);
assertThat(metadata).isNotNull();

SchemaTableName tblName = new SchemaTableName("prod", "test_table");
List<String> schemas = metadata.listSchemaNames(null);
assertEquals(schemas.size(), 1);
assertEquals(schemas.get(0), "prod");
assertThat(schemas.size()).isEqualTo(1);
assertThat(schemas.get(0)).isEqualTo("prod");

KinesisTableHandle tblHandle = metadata.getTableHandle(null, tblName);
assertNotNull(tblHandle);
assertEquals(tblHandle.getSchemaName(), "prod");
assertEquals(tblHandle.getTableName(), "test_table");
assertEquals(tblHandle.getStreamName(), "test_kinesis_stream");
assertEquals(tblHandle.getMessageDataFormat(), "json");
assertThat(tblHandle).isNotNull();
assertThat(tblHandle.getSchemaName()).isEqualTo("prod");
assertThat(tblHandle.getTableName()).isEqualTo("test_table");
assertThat(tblHandle.getStreamName()).isEqualTo("test_kinesis_stream");
assertThat(tblHandle.getMessageDataFormat()).isEqualTo("json");

ConnectorTableMetadata tblMeta = metadata.getTableMetadata(null, tblHandle);
assertNotNull(tblMeta);
assertEquals(tblMeta.getTable().getSchemaName(), "prod");
assertEquals(tblMeta.getTable().getTableName(), "test_table");
assertThat(tblMeta).isNotNull();
assertThat(tblMeta.getTable().getSchemaName()).isEqualTo("prod");
assertThat(tblMeta.getTable().getTableName()).isEqualTo("test_table");
List<ColumnMetadata> columnList = tblMeta.getColumns();
assertNotNull(columnList);
assertThat(columnList).isNotNull();

boolean foundServiceType = false;
boolean foundPartitionKey = false;
for (ColumnMetadata column : columnList) {
if (column.getName().equals("service_type")) {
foundServiceType = true;
assertEquals(column.getType().getDisplayName(), "varchar(20)");
assertThat(column.getType().getDisplayName()).isEqualTo("varchar(20)");
}
if (column.getName().equals("_partition_key")) {
foundPartitionKey = true;
assertEquals(column.getType().getDisplayName(), "varchar");
assertThat(column.getType().getDisplayName()).isEqualTo("varchar");
}
}
assertTrue(foundServiceType);
assertTrue(foundPartitionKey);
assertThat(foundServiceType).isTrue();
assertThat(foundPartitionKey).isTrue();
}
}
Loading

0 comments on commit 9e944eb

Please sign in to comment.