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 Oct 27, 2023
1 parent 2f77b4d commit 1e03f76
Show file tree
Hide file tree
Showing 18 changed files with 209 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
import org.apache.hadoop.fs.LocatedFileStatus;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.RemoteIterator;
import org.testng.SkipException;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import javax.crypto.spec.SecretKeySpec;

Expand Down Expand Up @@ -111,6 +110,7 @@
import static java.nio.file.Files.createTempFile;
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;
import static org.testng.Assert.assertNull;
Expand Down Expand Up @@ -477,7 +477,7 @@ public void testCreateWithStagingDirectorySymlink()
Files.createSymbolicLink(link, staging);
}
catch (UnsupportedOperationException e) {
throw new SkipException("Filesystem does not support symlinks", e);
abort("Filesystem does not support symlinks");
}

try (TrinoS3FileSystem fs = new TrinoS3FileSystem()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
import io.trino.testing.datatype.SqlDataTypeTest;
import io.trino.testing.sql.TrinoSqlExecutor;
import org.intellij.lang.annotations.Language;
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 java.time.LocalDate;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -67,7 +68,9 @@
import static java.lang.String.format;
import static java.time.ZoneOffset.UTC;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;

@TestInstance(PER_CLASS)
public class TestCassandraTypeMapping
extends AbstractTestQueryFramework
{
Expand Down Expand Up @@ -98,7 +101,7 @@ public class TestCassandraTypeMapping
private CassandraServer server;
private CassandraSession session;

@BeforeClass
@BeforeAll
public void setUp()
{
checkState(jvmZone.getId().equals("America/Bahia_Banderas"), "This test assumes certain JVM time zone");
Expand Down Expand Up @@ -146,7 +149,7 @@ protected QueryRunner createQueryRunner()
ImmutableList.of());
}

@AfterClass(alwaysRun = true)
@AfterAll
public void cleanUp()
{
session.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
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 java.time.LocalDate;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -56,7 +57,9 @@
import static io.trino.type.IpAddressType.IPADDRESS;
import static java.lang.String.format;
import static java.time.ZoneOffset.UTC;
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;

@TestInstance(PER_CLASS)
public abstract class BaseClickHouseTypeMapping
extends AbstractTestQueryFramework
{
Expand All @@ -70,7 +73,7 @@ public abstract class BaseClickHouseTypeMapping

protected TestingClickHouseServer clickhouseServer;

@BeforeClass
@BeforeAll
public void setUp()
{
checkState(jvmZone.getId().equals("America/Bahia_Banderas"), "This test assumes certain JVM time zone");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@
package io.trino.plugin.hive;

import io.trino.hdfs.azure.HiveAzureConfig;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;

import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;

@TestInstance(PER_CLASS)
public class TestHiveFileSystemAbfsAccessKey
extends AbstractTestHiveFileSystemAbfs
{
private String accessKey;

@Parameters({
"hive.hadoop2.metastoreHost",
"hive.hadoop2.metastorePort",
"hive.hadoop2.databaseName",
"hive.hadoop2.abfs.container",
"hive.hadoop2.abfs.account",
"hive.hadoop2.abfs.accessKey",
"hive.hadoop2.abfs.testDirectory",
})
@BeforeClass
public void setup(String host, int port, String databaseName, String container, String account, String accessKey, String testDirectory)
@BeforeAll
public void setup()
{
this.accessKey = checkParameter(accessKey, "access key");
super.setup(host, port, databaseName, container, account, testDirectory);
this.accessKey = checkParameter(System.getProperty("hive.hadoop2.abfs.accessKey"), "access key");
super.setup(
System.getProperty("hive.hadoop2.metastoreHost"),
Integer.getInteger("hive.hadoop2.metastorePort"),
System.getProperty("hive.hadoop2.databaseName"),
System.getProperty("hive.hadoop2.abfs.container"),
System.getProperty("hive.hadoop2.abfs.account"),
System.getProperty("hive.hadoop2.abfs.testDirectory"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,32 @@
package io.trino.plugin.hive;

import io.trino.hdfs.azure.HiveAzureConfig;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;

import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;

@TestInstance(PER_CLASS)
public class TestHiveFileSystemAbfsOAuth
extends AbstractTestHiveFileSystemAbfs
{
private String endpoint;
private String clientId;
private String secret;

@Parameters({
"hive.hadoop2.metastoreHost",
"hive.hadoop2.metastorePort",
"hive.hadoop2.databaseName",
"test.hive.azure.abfs.container",
"test.hive.azure.abfs.storage-account",
"test.hive.azure.abfs.test-directory",
"test.hive.azure.abfs.oauth.endpoint",
"test.hive.azure.abfs.oauth.client-id",
"test.hive.azure.abfs.oauth.secret",
})
@BeforeClass
public void setup(
String host,
int port,
String databaseName,
String container,
String account,
String testDirectory,
String clientEndpoint,
String clientId,
String clientSecret)
@BeforeAll
public void setup()
{
this.endpoint = checkParameter(clientEndpoint, "endpoint");
this.clientId = checkParameter(clientId, "client ID");
this.secret = checkParameter(clientSecret, "secret");
super.setup(host, port, databaseName, container, account, testDirectory);
this.endpoint = checkParameter(System.getProperty("test.hive.azure.abfs.oauth.endpoint"), "endpoint");
this.clientId = checkParameter(System.getProperty("test.hive.azure.abfs.oauth.client-id"), "client ID");
this.secret = checkParameter(System.getProperty("test.hive.azure.abfs.oauth.secret"), "secret");
super.setup(
System.getProperty("hive.hadoop2.metastoreHost"),
Integer.getInteger("hive.hadoop2.metastorePort"),
System.getProperty("hive.hadoop2.databaseName"),
System.getProperty("test.hive.azure.abfs.container"),
System.getProperty("test.hive.azure.abfs.storage-account"),
System.getProperty("test.hive.azure.abfs.test-directory"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,22 @@
import io.trino.hdfs.azure.TrinoAzureConfigurationInitializer;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import java.io.FileNotFoundException;
import java.util.UUID;

import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import static org.testng.util.Strings.isNullOrEmpty;

@TestInstance(PER_CLASS)
public class TestHiveFileSystemAdl
extends AbstractTestHiveFileSystem
{
Expand All @@ -46,19 +48,18 @@ public class TestHiveFileSystemAdl
private String refreshUrl;
private String testDirectory;

@Parameters({
"hive.hadoop2.metastoreHost",
"hive.hadoop2.metastorePort",
"hive.hadoop2.databaseName",
"hive.hadoop2.adl.name",
"hive.hadoop2.adl.clientId",
"hive.hadoop2.adl.credential",
"hive.hadoop2.adl.refreshUrl",
"hive.hadoop2.adl.testDirectory",
})
@BeforeClass
public void setup(String host, int port, String databaseName, String dataLakeName, String clientId, String credential, String refreshUrl, String testDirectory)
@BeforeAll
public void setup()
{
String host = System.getProperty("hive.hadoop2.metastoreHost");
int port = Integer.getInteger("hive.hadoop2.metastorePort");
String databaseName = System.getProperty("hive.hadoop2.databaseName");
String dataLakeName = System.getProperty("hive.hadoop2.adl.name");
String clientId = System.getProperty("hive.hadoop2.adl.clientId");
String credential = System.getProperty("hive.hadoop2.adl.credential");
String refreshUrl = System.getProperty("hive.hadoop2.adl.refreshUrl");
String testDirectory = System.getProperty("hive.hadoop2.adl.testDirectory");

checkArgument(!isNullOrEmpty(host), "expected non empty host");
checkArgument(!isNullOrEmpty(databaseName), "expected non empty databaseName");
checkArgument(!isNullOrEmpty(dataLakeName), "expected non empty dataLakeName");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
import io.trino.plugin.hive.metastore.Table;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import java.util.Arrays;
import java.util.List;
Expand All @@ -59,9 +59,11 @@
import static java.io.InputStream.nullInputStream;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
import static org.testng.Assert.assertFalse;
import static org.testng.util.Strings.isNullOrEmpty;

@TestInstance(PER_CLASS)
public class TestHiveFileSystemS3
extends AbstractTestHiveFileSystem
{
Expand All @@ -72,19 +74,18 @@ public class TestHiveFileSystemS3
private String testDirectory;
private AmazonS3 s3Client;

@Parameters({
"hive.hadoop2.metastoreHost",
"hive.hadoop2.metastorePort",
"hive.hadoop2.databaseName",
"hive.hadoop2.s3.endpoint",
"hive.hadoop2.s3.awsAccessKey",
"hive.hadoop2.s3.awsSecretKey",
"hive.hadoop2.s3.writableBucket",
"hive.hadoop2.s3.testDirectory",
})
@BeforeClass
public void setup(String host, int port, String databaseName, String s3endpoint, String awsAccessKey, String awsSecretKey, String writableBucket, String testDirectory)
@BeforeAll
public void setup()
{
String host = System.getProperty("hive.hadoop2.metastoreHost");
int port = Integer.getInteger("hive.hadoop2.metastorePort");
String databaseName = System.getProperty("hive.hadoop2.databaseName");
String s3endpoint = System.getProperty("hive.hadoop2.s3.endpoint");
String awsAccessKey = System.getProperty("hive.hadoop2.s3.awsAccessKey");
String awsSecretKey = System.getProperty("hive.hadoop2.s3.awsSecretKey");
String writableBucket = System.getProperty("hive.hadoop2.s3.writableBucket");
String testDirectory = System.getProperty("hive.hadoop2.s3.testDirectory");

checkArgument(!isNullOrEmpty(host), "Expected non empty host");
checkArgument(!isNullOrEmpty(databaseName), "Expected non empty databaseName");
checkArgument(!isNullOrEmpty(awsAccessKey), "Expected non empty awsAccessKey");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
import io.trino.hdfs.azure.HiveAzureConfig;
import io.trino.hdfs.azure.TrinoAzureConfigurationInitializer;
import org.apache.hadoop.fs.Path;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;

import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
import static org.testng.util.Strings.isNullOrEmpty;

@TestInstance(PER_CLASS)
public class TestHiveFileSystemWasb
extends AbstractTestHiveFileSystem
{
Expand All @@ -37,18 +39,17 @@ public class TestHiveFileSystemWasb
private String accessKey;
private String testDirectory;

@Parameters({
"hive.hadoop2.metastoreHost",
"hive.hadoop2.metastorePort",
"hive.hadoop2.databaseName",
"hive.hadoop2.wasb.container",
"hive.hadoop2.wasb.account",
"hive.hadoop2.wasb.accessKey",
"hive.hadoop2.wasb.testDirectory",
})
@BeforeClass
public void setup(String host, int port, String databaseName, String container, String account, String accessKey, String testDirectory)
@BeforeAll
public void setup()
{
String host = System.getProperty("hive.hadoop2.metastoreHost");
int port = Integer.getInteger("hive.hadoop2.metastorePort");
String databaseName = System.getProperty("hive.hadoop2.databaseName");
String container = System.getProperty("hive.hadoop2.wasb.container");
String account = System.getProperty("hive.hadoop2.wasb.account");
String accessKey = System.getProperty("hive.hadoop2.wasb.accessKey");
String testDirectory = System.getProperty("hive.hadoop2.wasb.testDirectory");

checkArgument(!isNullOrEmpty(host), "expected non empty host");
checkArgument(!isNullOrEmpty(databaseName), "expected non empty databaseName");
checkArgument(!isNullOrEmpty(container), "expected non empty container");
Expand Down
Loading

0 comments on commit 1e03f76

Please sign in to comment.