diff --git a/lib/trino-filesystem-azure/pom.xml b/lib/trino-filesystem-azure/pom.xml index 8cc67d7b6144..e67100cd4db4 100644 --- a/lib/trino-filesystem-azure/pom.xml +++ b/lib/trino-filesystem-azure/pom.xml @@ -178,6 +178,12 @@ test + + io.trino + trino-testing-services + test + + org.assertj assertj-core diff --git a/lib/trino-filesystem-azure/src/test/java/io/trino/filesystem/azure/AbstractTestAzureFileSystem.java b/lib/trino-filesystem-azure/src/test/java/io/trino/filesystem/azure/AbstractTestAzureFileSystem.java index 5b5afa9dc3c4..5d87efbc5623 100644 --- a/lib/trino-filesystem-azure/src/test/java/io/trino/filesystem/azure/AbstractTestAzureFileSystem.java +++ b/lib/trino-filesystem-azure/src/test/java/io/trino/filesystem/azure/AbstractTestAzureFileSystem.java @@ -53,11 +53,6 @@ public abstract class AbstractTestAzureFileSystem { private final EncryptionKey key = EncryptionKey.randomAes256(); - protected static String getRequiredEnvironmentVariable(String name) - { - return requireNonNull(System.getenv(name), "Environment variable not set: " + name); - } - protected enum AccountKind { HIERARCHICAL, FLAT diff --git a/lib/trino-filesystem-azure/src/test/java/io/trino/filesystem/azure/TestAzureFileSystemGen2Flat.java b/lib/trino-filesystem-azure/src/test/java/io/trino/filesystem/azure/TestAzureFileSystemGen2Flat.java index cc3233764284..def79fb20435 100644 --- a/lib/trino-filesystem-azure/src/test/java/io/trino/filesystem/azure/TestAzureFileSystemGen2Flat.java +++ b/lib/trino-filesystem-azure/src/test/java/io/trino/filesystem/azure/TestAzureFileSystemGen2Flat.java @@ -20,6 +20,7 @@ import java.io.IOException; import static io.trino.filesystem.azure.AbstractTestAzureFileSystem.AccountKind.FLAT; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; @TestInstance(Lifecycle.PER_CLASS) class TestAzureFileSystemGen2Flat @@ -29,6 +30,6 @@ class TestAzureFileSystemGen2Flat void setup() throws IOException { - initializeWithAccessKey(getRequiredEnvironmentVariable("ABFS_FLAT_ACCOUNT"), getRequiredEnvironmentVariable("ABFS_FLAT_ACCESS_KEY"), FLAT); + initializeWithAccessKey(requireEnv("ABFS_FLAT_ACCOUNT"), requireEnv("ABFS_FLAT_ACCESS_KEY"), FLAT); } } diff --git a/lib/trino-filesystem-azure/src/test/java/io/trino/filesystem/azure/TestAzureFileSystemGen2Hierarchical.java b/lib/trino-filesystem-azure/src/test/java/io/trino/filesystem/azure/TestAzureFileSystemGen2Hierarchical.java index 5efb95e40ec1..d8423e00c2b5 100644 --- a/lib/trino-filesystem-azure/src/test/java/io/trino/filesystem/azure/TestAzureFileSystemGen2Hierarchical.java +++ b/lib/trino-filesystem-azure/src/test/java/io/trino/filesystem/azure/TestAzureFileSystemGen2Hierarchical.java @@ -20,6 +20,7 @@ import java.io.IOException; import static io.trino.filesystem.azure.AbstractTestAzureFileSystem.AccountKind.HIERARCHICAL; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; @TestInstance(Lifecycle.PER_CLASS) class TestAzureFileSystemGen2Hierarchical @@ -29,6 +30,6 @@ class TestAzureFileSystemGen2Hierarchical void setup() throws IOException { - initializeWithAccessKey(getRequiredEnvironmentVariable("ABFS_HIERARCHICAL_ACCOUNT"), getRequiredEnvironmentVariable("ABFS_HIERARCHICAL_ACCESS_KEY"), HIERARCHICAL); + initializeWithAccessKey(requireEnv("ABFS_HIERARCHICAL_ACCOUNT"), requireEnv("ABFS_HIERARCHICAL_ACCESS_KEY"), HIERARCHICAL); } } diff --git a/lib/trino-filesystem-azure/src/test/java/io/trino/filesystem/azure/TestAzureFileSystemOAuthGen2Flat.java b/lib/trino-filesystem-azure/src/test/java/io/trino/filesystem/azure/TestAzureFileSystemOAuthGen2Flat.java index 82c3ac4efb55..ff70e01f44c5 100644 --- a/lib/trino-filesystem-azure/src/test/java/io/trino/filesystem/azure/TestAzureFileSystemOAuthGen2Flat.java +++ b/lib/trino-filesystem-azure/src/test/java/io/trino/filesystem/azure/TestAzureFileSystemOAuthGen2Flat.java @@ -20,6 +20,7 @@ import java.io.IOException; import static io.trino.filesystem.azure.AbstractTestAzureFileSystem.AccountKind.FLAT; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; @TestInstance(Lifecycle.PER_CLASS) public class TestAzureFileSystemOAuthGen2Flat @@ -29,10 +30,10 @@ public class TestAzureFileSystemOAuthGen2Flat void setup() throws IOException { - String account = getRequiredEnvironmentVariable("ABFS_FLAT_ACCOUNT"); - String tenantId = getRequiredEnvironmentVariable("ABFS_OAUTH_TENANT_ID"); - String clientId = getRequiredEnvironmentVariable("ABFS_OAUTH_CLIENT_ID"); - String clientSecret = getRequiredEnvironmentVariable("ABFS_OAUTH_CLIENT_SECRET"); + String account = requireEnv("ABFS_FLAT_ACCOUNT"); + String tenantId = requireEnv("ABFS_OAUTH_TENANT_ID"); + String clientId = requireEnv("ABFS_OAUTH_CLIENT_ID"); + String clientSecret = requireEnv("ABFS_OAUTH_CLIENT_SECRET"); initializeWithOAuth(account, tenantId, clientId, clientSecret, FLAT); } } diff --git a/lib/trino-filesystem-azure/src/test/java/io/trino/filesystem/azure/TestAzureFileSystemOAuthGen2Hierarchical.java b/lib/trino-filesystem-azure/src/test/java/io/trino/filesystem/azure/TestAzureFileSystemOAuthGen2Hierarchical.java index 0276a6542b25..1ac28bed2d84 100644 --- a/lib/trino-filesystem-azure/src/test/java/io/trino/filesystem/azure/TestAzureFileSystemOAuthGen2Hierarchical.java +++ b/lib/trino-filesystem-azure/src/test/java/io/trino/filesystem/azure/TestAzureFileSystemOAuthGen2Hierarchical.java @@ -20,6 +20,7 @@ import java.io.IOException; import static io.trino.filesystem.azure.AbstractTestAzureFileSystem.AccountKind.HIERARCHICAL; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; @TestInstance(Lifecycle.PER_CLASS) public class TestAzureFileSystemOAuthGen2Hierarchical @@ -29,10 +30,10 @@ public class TestAzureFileSystemOAuthGen2Hierarchical void setup() throws IOException { - String account = getRequiredEnvironmentVariable("ABFS_HIERARCHICAL_ACCOUNT"); - String tenantId = getRequiredEnvironmentVariable("ABFS_OAUTH_TENANT_ID"); - String clientId = getRequiredEnvironmentVariable("ABFS_OAUTH_CLIENT_ID"); - String clientSecret = getRequiredEnvironmentVariable("ABFS_OAUTH_CLIENT_SECRET"); + String account = requireEnv("ABFS_HIERARCHICAL_ACCOUNT"); + String tenantId = requireEnv("ABFS_OAUTH_TENANT_ID"); + String clientId = requireEnv("ABFS_OAUTH_CLIENT_ID"); + String clientSecret = requireEnv("ABFS_OAUTH_CLIENT_SECRET"); initializeWithOAuth(account, tenantId, clientId, clientSecret, HIERARCHICAL); } } diff --git a/lib/trino-filesystem-gcs/src/test/java/io/trino/filesystem/gcs/AbstractTestGcsFileSystem.java b/lib/trino-filesystem-gcs/src/test/java/io/trino/filesystem/gcs/AbstractTestGcsFileSystem.java index d17b1d64571a..128f634fb3f1 100644 --- a/lib/trino-filesystem-gcs/src/test/java/io/trino/filesystem/gcs/AbstractTestGcsFileSystem.java +++ b/lib/trino-filesystem-gcs/src/test/java/io/trino/filesystem/gcs/AbstractTestGcsFileSystem.java @@ -35,7 +35,6 @@ import static com.google.cloud.storage.Storage.BlobTargetOption.doesNotExist; import static io.trino.filesystem.encryption.EncryptionKey.randomAes256; import static java.nio.charset.StandardCharsets.UTF_8; -import static java.util.Objects.requireNonNull; import static org.assertj.core.api.Assertions.assertThat; @TestInstance(TestInstance.Lifecycle.PER_CLASS) @@ -48,11 +47,6 @@ public abstract class AbstractTestGcsFileSystem private Storage storage; private GcsFileSystemFactory gcsFileSystemFactory; - protected static String getRequiredEnvironmentVariable(String name) - { - return requireNonNull(System.getenv(name), "Environment variable not set: " + name); - } - protected void initialize(String gcpCredentialKey) throws IOException { diff --git a/lib/trino-filesystem-gcs/src/test/java/io/trino/filesystem/gcs/TestGcsFileSystem.java b/lib/trino-filesystem-gcs/src/test/java/io/trino/filesystem/gcs/TestGcsFileSystem.java index 177e1390de20..0213d77c32af 100644 --- a/lib/trino-filesystem-gcs/src/test/java/io/trino/filesystem/gcs/TestGcsFileSystem.java +++ b/lib/trino-filesystem-gcs/src/test/java/io/trino/filesystem/gcs/TestGcsFileSystem.java @@ -20,6 +20,7 @@ import java.io.IOException; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static java.nio.charset.StandardCharsets.UTF_8; @TestInstance(TestInstance.Lifecycle.PER_CLASS) @@ -30,7 +31,7 @@ public class TestGcsFileSystem void setup() throws IOException { - initialize(getRequiredEnvironmentVariable("GCP_CREDENTIALS_KEY")); + initialize(requireEnv("GCP_CREDENTIALS_KEY")); } @Test diff --git a/lib/trino-filesystem-s3/pom.xml b/lib/trino-filesystem-s3/pom.xml index 30d9336b5f62..4d767d05c5ca 100644 --- a/lib/trino-filesystem-s3/pom.xml +++ b/lib/trino-filesystem-s3/pom.xml @@ -239,6 +239,12 @@ test + + io.trino + trino-testing-services + test + + org.assertj assertj-core diff --git a/lib/trino-filesystem-s3/src/test/java/io/trino/filesystem/s3/TestS3FileSystemAwsS3.java b/lib/trino-filesystem-s3/src/test/java/io/trino/filesystem/s3/TestS3FileSystemAwsS3.java index 200732d4499c..5d578543aedb 100644 --- a/lib/trino-filesystem-s3/src/test/java/io/trino/filesystem/s3/TestS3FileSystemAwsS3.java +++ b/lib/trino-filesystem-s3/src/test/java/io/trino/filesystem/s3/TestS3FileSystemAwsS3.java @@ -29,7 +29,7 @@ import java.util.List; import static com.google.common.collect.Iterables.getOnlyElement; -import static java.util.Objects.requireNonNull; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static org.assertj.core.api.Assertions.assertThat; public class TestS3FileSystemAwsS3 @@ -43,10 +43,10 @@ public class TestS3FileSystemAwsS3 @Override protected void initEnvironment() { - accessKey = environmentVariable("AWS_ACCESS_KEY_ID"); - secretKey = environmentVariable("AWS_SECRET_ACCESS_KEY"); - region = environmentVariable("AWS_REGION"); - bucket = environmentVariable("EMPTY_S3_BUCKET"); + accessKey = requireEnv("AWS_ACCESS_KEY_ID"); + secretKey = requireEnv("AWS_SECRET_ACCESS_KEY"); + region = requireEnv("AWS_REGION"); + bucket = requireEnv("EMPTY_S3_BUCKET"); } @Override @@ -75,11 +75,6 @@ protected S3FileSystemFactory createS3FileSystemFactory() .setStreamingPartSize(DataSize.valueOf("5.5MB")), new S3FileSystemStats()); } - private static String environmentVariable(String name) - { - return requireNonNull(System.getenv(name), "Environment variable not set: " + name); - } - @Test void testS3FileIteratorFileEntryTags() throws IOException diff --git a/lib/trino-filesystem-s3/src/test/java/io/trino/filesystem/s3/TestS3FileSystemAwsS3WithSseCustomerKey.java b/lib/trino-filesystem-s3/src/test/java/io/trino/filesystem/s3/TestS3FileSystemAwsS3WithSseCustomerKey.java index 7dcdaba12f8e..3de274317995 100644 --- a/lib/trino-filesystem-s3/src/test/java/io/trino/filesystem/s3/TestS3FileSystemAwsS3WithSseCustomerKey.java +++ b/lib/trino-filesystem-s3/src/test/java/io/trino/filesystem/s3/TestS3FileSystemAwsS3WithSseCustomerKey.java @@ -33,7 +33,7 @@ import java.util.function.Function; import static io.trino.filesystem.s3.S3FileSystemConfig.S3SseType.CUSTOMER; -import static java.util.Objects.requireNonNull; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; public class TestS3FileSystemAwsS3WithSseCustomerKey extends AbstractTestS3FileSystem @@ -49,10 +49,10 @@ public class TestS3FileSystemAwsS3WithSseCustomerKey @Override protected void initEnvironment() { - accessKey = environmentVariable("AWS_ACCESS_KEY_ID"); - secretKey = environmentVariable("AWS_SECRET_ACCESS_KEY"); - region = environmentVariable("AWS_REGION"); - bucket = environmentVariable("EMPTY_S3_BUCKET"); + accessKey = requireEnv("AWS_ACCESS_KEY_ID"); + secretKey = requireEnv("AWS_SECRET_ACCESS_KEY"); + region = requireEnv("AWS_REGION"); + bucket = requireEnv("EMPTY_S3_BUCKET"); s3SseCustomerKey = S3SseCustomerKey.onAes256(CUSTOMER_KEY); } @@ -109,11 +109,6 @@ protected S3FileSystemFactory createS3FileSystemFactory() new S3FileSystemStats()); } - private static String environmentVariable(String name) - { - return requireNonNull(System.getenv(name), "Environment variable not set: " + name); - } - private static String generateCustomerKey() { try { diff --git a/lib/trino-hdfs/src/test/java/io/trino/hdfs/s3/TestTrinoS3FileSystemAwsS3.java b/lib/trino-hdfs/src/test/java/io/trino/hdfs/s3/TestTrinoS3FileSystemAwsS3.java index 413836858627..69b5e96bd53f 100644 --- a/lib/trino-hdfs/src/test/java/io/trino/hdfs/s3/TestTrinoS3FileSystemAwsS3.java +++ b/lib/trino-hdfs/src/test/java/io/trino/hdfs/s3/TestTrinoS3FileSystemAwsS3.java @@ -15,7 +15,7 @@ import org.apache.hadoop.conf.Configuration; -import static java.util.Objects.requireNonNull; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; /** * Tests file system operations on AWS S3 storage. @@ -31,8 +31,8 @@ public class TestTrinoS3FileSystemAwsS3 public TestTrinoS3FileSystemAwsS3() { - bucketName = requireNonNull(System.getenv("S3_BUCKET"), "Environment S3_BUCKET was not set"); - s3Endpoint = requireNonNull(System.getenv("S3_BUCKET_ENDPOINT"), "Environment S3_BUCKET_ENDPOINT was not set"); + bucketName = requireEnv("S3_BUCKET"); + s3Endpoint = requireEnv("S3_BUCKET_ENDPOINT"); } @Override diff --git a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakeTableWithCustomLocationUsingGlueMetastore.java b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakeTableWithCustomLocationUsingGlueMetastore.java index 8deee1b2a95e..37f0fdfab526 100644 --- a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakeTableWithCustomLocationUsingGlueMetastore.java +++ b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakeTableWithCustomLocationUsingGlueMetastore.java @@ -24,8 +24,8 @@ import static com.google.common.io.MoreFiles.deleteRecursively; import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE; import static io.trino.plugin.hive.metastore.glue.TestingGlueHiveMetastore.createTestingGlueHiveMetastore; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.testing.TestingNames.randomNameSuffix; -import static java.util.Objects.requireNonNull; import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; @TestInstance(PER_CLASS) @@ -45,7 +45,7 @@ protected QueryRunner createQueryRunner() schema = "test_tables_with_custom_location" + randomNameSuffix(); return DeltaLakeQueryRunner.builder(schema) .addDeltaProperty("hive.metastore", "glue") - .addDeltaProperty("hive.metastore.glue.region", requireNonNull(System.getenv("AWS_REGION"), "AWS_REGION is null")) + .addDeltaProperty("hive.metastore.glue.region", requireEnv("AWS_REGION")) .addDeltaProperty("hive.metastore.glue.default-warehouse-dir", warehouseDir.toUri().toString()) .build(); } diff --git a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/metastore/glue/TestDeltaLakeRegisterTableProcedureWithGlue.java b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/metastore/glue/TestDeltaLakeRegisterTableProcedureWithGlue.java index d190234723a6..d67d92431355 100644 --- a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/metastore/glue/TestDeltaLakeRegisterTableProcedureWithGlue.java +++ b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/metastore/glue/TestDeltaLakeRegisterTableProcedureWithGlue.java @@ -25,8 +25,8 @@ import static com.google.common.io.MoreFiles.deleteRecursively; import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE; import static io.trino.plugin.hive.metastore.glue.TestingGlueHiveMetastore.createTestingGlueHiveMetastore; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.testing.TestingNames.randomNameSuffix; -import static java.util.Objects.requireNonNull; public class TestDeltaLakeRegisterTableProcedureWithGlue extends BaseDeltaLakeRegisterTableProcedureTest @@ -44,7 +44,7 @@ protected QueryRunner createQueryRunner() schema = "test_delta_lake_register_table" + randomNameSuffix(); return DeltaLakeQueryRunner.builder(schema) .addDeltaProperty("hive.metastore", "glue") - .addDeltaProperty("hive.metastore.glue.region", requireNonNull(System.getenv("AWS_REGION"), "AWS_REGION is null")) + .addDeltaProperty("hive.metastore.glue.region", requireEnv("AWS_REGION")) .addDeltaProperty("hive.metastore.glue.default-warehouse-dir", warehouseDir.toUri().toString()) .addDeltaProperty("delta.unique-table-location", "true") .addDeltaProperty("delta.register-table-procedure.enabled", "true") diff --git a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/metastore/glue/TestDeltaLakeViewsGlueMetastore.java b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/metastore/glue/TestDeltaLakeViewsGlueMetastore.java index f5b694bbf34c..beeebb49ec41 100644 --- a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/metastore/glue/TestDeltaLakeViewsGlueMetastore.java +++ b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/metastore/glue/TestDeltaLakeViewsGlueMetastore.java @@ -30,9 +30,9 @@ import static com.google.common.io.MoreFiles.deleteRecursively; import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE; import static io.trino.plugin.hive.metastore.glue.TestingGlueHiveMetastore.createTestingGlueHiveMetastore; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.testing.TestingNames.randomNameSuffix; import static java.lang.String.format; -import static java.util.Objects.requireNonNull; import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; @TestInstance(PER_CLASS) @@ -52,7 +52,7 @@ protected QueryRunner createQueryRunner() schema = "test_delta_lake_glue_views_" + randomNameSuffix(); return DeltaLakeQueryRunner.builder(schema) .addDeltaProperty("hive.metastore", "glue") - .addDeltaProperty("hive.metastore.glue.region", requireNonNull(System.getenv("AWS_REGION"), "AWS_REGION is null")) + .addDeltaProperty("hive.metastore.glue.region", requireEnv("AWS_REGION")) .addDeltaProperty("hive.metastore.glue.default-warehouse-dir", warehouseDir.toUri().toString()) .build(); } diff --git a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/metastore/glue/TestDeltaS3AndGlueMetastoreTest.java b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/metastore/glue/TestDeltaS3AndGlueMetastoreTest.java index 865857a32851..c66ddbb7dbfa 100644 --- a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/metastore/glue/TestDeltaS3AndGlueMetastoreTest.java +++ b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/metastore/glue/TestDeltaS3AndGlueMetastoreTest.java @@ -25,7 +25,7 @@ import static com.google.common.collect.Iterables.getOnlyElement; import static io.trino.plugin.hive.metastore.glue.TestingGlueHiveMetastore.createTestingGlueHiveMetastore; -import static java.util.Objects.requireNonNull; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static org.assertj.core.api.Assertions.assertThat; public class TestDeltaS3AndGlueMetastoreTest @@ -33,7 +33,7 @@ public class TestDeltaS3AndGlueMetastoreTest { public TestDeltaS3AndGlueMetastoreTest() { - super("partitioned_by", "location", requireNonNull(System.getenv("S3_BUCKET"), "Environment variable not set: S3_BUCKET")); + super("partitioned_by", "location", requireEnv("S3_BUCKET")); } @Override diff --git a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveS3AndGlueMetastoreTest.java b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveS3AndGlueMetastoreTest.java index b602f01cb00d..cf5076c377d9 100644 --- a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveS3AndGlueMetastoreTest.java +++ b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveS3AndGlueMetastoreTest.java @@ -33,10 +33,10 @@ import static io.trino.plugin.hive.TestingHiveUtils.getConnectorService; import static io.trino.spi.security.SelectedRole.Type.ROLE; import static io.trino.testing.MaterializedResult.resultBuilder; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.testing.TestingNames.randomNameSuffix; import static io.trino.testing.TestingSession.testSessionBuilder; import static java.lang.String.format; -import static java.util.Objects.requireNonNull; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -45,7 +45,7 @@ public class TestHiveS3AndGlueMetastoreTest { public TestHiveS3AndGlueMetastoreTest() { - super("partitioned_by", "external_location", requireNonNull(System.getenv("S3_BUCKET"), "Environment S3_BUCKET was not set")); + super("partitioned_by", "external_location", requireEnv("S3_BUCKET")); } @Override diff --git a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/metastore/thrift/TestUnityMetastore.java b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/metastore/thrift/TestUnityMetastore.java index 16afc1bad2b6..c3799770bd74 100644 --- a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/metastore/thrift/TestUnityMetastore.java +++ b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/metastore/thrift/TestUnityMetastore.java @@ -27,7 +27,7 @@ import static io.trino.plugin.hive.TestingThriftHiveMetastoreBuilder.testingThriftHiveMetastoreBuilder; import static io.trino.plugin.hive.metastore.thrift.ThriftHttpMetastoreConfig.AuthenticationMode.BEARER; -import static java.util.Objects.requireNonNull; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static org.assertj.core.api.Assertions.assertThat; final class TestUnityMetastore @@ -36,9 +36,9 @@ final class TestUnityMetastore void test() throws Exception { - String databricksHost = requireNonNull(System.getenv("DATABRICKS_HOST"), "Environment variable not set: DATABRICKS_HOST"); - String databricksToken = requireNonNull(System.getenv("DATABRICKS_TOKEN"), "Environment variable not set: DATABRICKS_TOKEN"); - String databricksCatalogName = requireNonNull(System.getenv("DATABRICKS_UNITY_CATALOG_NAME"), "Environment variable not set: DATABRICKS_UNITY_CATALOG_NAME"); + String databricksHost = requireEnv("DATABRICKS_HOST"); + String databricksToken = requireEnv("DATABRICKS_TOKEN"); + String databricksCatalogName = requireEnv("DATABRICKS_UNITY_CATALOG_NAME"); URI metastoreUri = URI.create("https://%s:443/api/2.0/unity-hms-proxy/metadata" .formatted(databricksHost)); ThriftHttpMetastoreConfig config = new ThriftHttpMetastoreConfig() diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/catalog/glue/TestIcebergGlueCatalogConnectorSmokeTest.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/catalog/glue/TestIcebergGlueCatalogConnectorSmokeTest.java index 9dec58090118..d7adfe595aa4 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/catalog/glue/TestIcebergGlueCatalogConnectorSmokeTest.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/catalog/glue/TestIcebergGlueCatalogConnectorSmokeTest.java @@ -57,10 +57,10 @@ import static io.trino.plugin.hive.metastore.glue.v1.converter.GlueToTrinoConverter.getTableParameters; import static io.trino.plugin.hive.metastore.glue.v1.converter.GlueToTrinoConverter.getTableType; import static io.trino.plugin.iceberg.IcebergTestUtils.checkParquetFileSorting; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.testing.TestingConnectorSession.SESSION; import static io.trino.testing.TestingNames.randomNameSuffix; import static java.lang.String.format; -import static java.util.Objects.requireNonNull; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; @@ -82,7 +82,7 @@ public class TestIcebergGlueCatalogConnectorSmokeTest public TestIcebergGlueCatalogConnectorSmokeTest() { super(FileFormat.PARQUET); - this.bucketName = requireNonNull(System.getenv("S3_BUCKET"), "Environment S3_BUCKET was not set"); + this.bucketName = requireEnv("S3_BUCKET"); this.schemaName = "test_iceberg_smoke_" + randomNameSuffix(); glueClient = AWSGlueAsyncClientBuilder.defaultClient(); diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/catalog/glue/TestIcebergS3AndGlueMetastoreTest.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/catalog/glue/TestIcebergS3AndGlueMetastoreTest.java index 044f41f71ef1..48f2b0d1f94a 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/catalog/glue/TestIcebergS3AndGlueMetastoreTest.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/catalog/glue/TestIcebergS3AndGlueMetastoreTest.java @@ -28,8 +28,8 @@ import java.util.stream.Collectors; import static io.trino.plugin.hive.metastore.glue.TestingGlueHiveMetastore.createTestingGlueHiveMetastore; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.testing.TestingNames.randomNameSuffix; -import static java.util.Objects.requireNonNull; import static org.assertj.core.api.Assertions.assertThat; public class TestIcebergS3AndGlueMetastoreTest @@ -37,7 +37,7 @@ public class TestIcebergS3AndGlueMetastoreTest { public TestIcebergS3AndGlueMetastoreTest() { - super("partitioning", "location", requireNonNull(System.getenv("S3_BUCKET"), "Environment S3_BUCKET was not set")); + super("partitioning", "location", requireEnv("S3_BUCKET")); } @Override diff --git a/plugin/trino-password-authenticators/src/test/java/io/trino/plugin/password/salesforce/TestSalesforceBasicAuthenticator.java b/plugin/trino-password-authenticators/src/test/java/io/trino/plugin/password/salesforce/TestSalesforceBasicAuthenticator.java index 5689cb9b2438..bb40dac86d77 100644 --- a/plugin/trino-password-authenticators/src/test/java/io/trino/plugin/password/salesforce/TestSalesforceBasicAuthenticator.java +++ b/plugin/trino-password-authenticators/src/test/java/io/trino/plugin/password/salesforce/TestSalesforceBasicAuthenticator.java @@ -24,14 +24,13 @@ import java.security.Principal; import java.util.concurrent.TimeUnit; -import static com.google.common.base.Strings.emptyToNull; import static com.google.common.net.MediaType.ANY_TEXT_TYPE; import static io.airlift.http.client.HttpStatus.OK; import static io.airlift.http.client.testing.TestingResponse.mockResponse; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.assertj.core.api.Fail.fail; import static org.junit.jupiter.api.Assumptions.abort; public class TestSalesforceBasicAuthenticator @@ -182,15 +181,9 @@ public void createAuthenticatedPrincipalRealSuccess() abort("Skipping real tests."); } - String org = System.getenv("SALESFORCE_TEST_ORG"); - if (emptyToNull(org) == null) { - fail("Must set SALESFORCE_TEST_ORG environment variable."); - } - String username = System.getenv("SALESFORCE_TEST_USERNAME"); - String password = System.getenv("SALESFORCE_TEST_PASSWORD"); - if (emptyToNull(username) == null || emptyToNull(password) == null) { - fail("Must set SALESFORCE_TEST_USERNAME and SALESFORCE_TEST_PASSWORD environment variables."); - } + String org = requireEnv("SALESFORCE_TEST_ORG"); + String username = requireEnv("SALESFORCE_TEST_USERNAME"); + String password = requireEnv("SALESFORCE_TEST_PASSWORD"); SalesforceConfig config = new SalesforceConfig() .setAllowedOrganizations(org); @@ -213,11 +206,8 @@ public void createAuthenticatedPrincipalRealWrongOrg() abort("Skipping real tests."); } - String username = System.getenv("SALESFORCE_TEST_USERNAME"); - String password = System.getenv("SALESFORCE_TEST_PASSWORD"); - if (emptyToNull(username) == null || emptyToNull(password) == null) { - fail("Must set SALESFORCE_TEST_USERNAME and SALESFORCE_TEST_PASSWORD environment variables."); - } + String username = requireEnv("SALESFORCE_TEST_USERNAME"); + String password = requireEnv("SALESFORCE_TEST_PASSWORD"); String org = "NotMyOrg"; SalesforceConfig config = new SalesforceConfig() @@ -240,11 +230,8 @@ public void createAuthenticatedPrincipalRealAllOrgs() abort("Skipping real tests."); } - String username = System.getenv("SALESFORCE_TEST_USERNAME"); - String password = System.getenv("SALESFORCE_TEST_PASSWORD"); - if (emptyToNull(username) == null || emptyToNull(password) == null) { - fail("Must set SALESFORCE_TEST_USERNAME and SALESFORCE_TEST_PASSWORD environment variables."); - } + String username = requireEnv("SALESFORCE_TEST_USERNAME"); + String password = requireEnv("SALESFORCE_TEST_PASSWORD"); SalesforceConfig config = new SalesforceConfig() .setAllowedOrganizations("all"); @@ -268,15 +255,8 @@ public void createAuthenticatedPrincipalRealBadPassword() abort("Skipping real tests."); } - String org = System.getenv("SALESFORCE_TEST_ORG"); - if (emptyToNull(org) == null) { - fail("Must set SALESFORCE_TEST_ORG environment variable."); - } - String username = System.getenv("SALESFORCE_TEST_USERNAME"); - String password = System.getenv("SALESFORCE_TEST_PASSWORD"); - if (emptyToNull(username) == null || emptyToNull(password) == null) { - fail("Must set SALESFORCE_TEST_USERNAME and SALESFORCE_TEST_PASSWORD environment variables."); - } + String org = requireEnv("SALESFORCE_TEST_ORG"); + String username = requireEnv("SALESFORCE_TEST_USERNAME"); SalesforceConfig config = new SalesforceConfig() .setAllowedOrganizations(org); diff --git a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/cli/TestRun.java b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/cli/TestRun.java index 27c05f8bbc68..7d938caa9dc4 100644 --- a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/cli/TestRun.java +++ b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/cli/TestRun.java @@ -53,6 +53,7 @@ import static com.google.common.base.Strings.isNullOrEmpty; import static com.google.common.collect.ImmutableList.toImmutableList; +import static io.trino.testing.SystemEnvironmentUtils.isEnvSet; import static io.trino.tests.product.launcher.env.DockerContainer.cleanOrCreateHostPath; import static io.trino.tests.product.launcher.env.EnvironmentContainers.TESTS; import static io.trino.tests.product.launcher.env.EnvironmentListener.getStandardListeners; @@ -335,7 +336,7 @@ private Environment getEnvironment() unsafelyExposePort(container, 5007); // debug port } - if (System.getenv("CONTINUOUS_INTEGRATION") != null) { + if (isEnvSet("CONTINUOUS_INTEGRATION")) { container.withEnv("CONTINUOUS_INTEGRATION", "true"); } diff --git a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/AbstractSinglenodeDeltaLakeDatabricks.java b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/AbstractSinglenodeDeltaLakeDatabricks.java index ef7666f5cbb1..651a9a3edc6a 100644 --- a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/AbstractSinglenodeDeltaLakeDatabricks.java +++ b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/AbstractSinglenodeDeltaLakeDatabricks.java @@ -21,6 +21,7 @@ import java.io.File; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.tests.product.launcher.env.EnvironmentContainers.COORDINATOR; import static io.trino.tests.product.launcher.env.EnvironmentContainers.TESTS; import static io.trino.tests.product.launcher.env.EnvironmentContainers.configureTempto; @@ -51,10 +52,10 @@ public AbstractSinglenodeDeltaLakeDatabricks(Standard standard, DockerFiles dock public void extendEnvironment(Environment.Builder builder) { String databricksTestJdbcUrl = databricksTestJdbcUrl(); - String databricksTestLogin = requireNonNull(System.getenv("DATABRICKS_LOGIN"), "Environment DATABRICKS_LOGIN was not set"); - String databricksTestToken = requireNonNull(System.getenv("DATABRICKS_TOKEN"), "Environment DATABRICKS_TOKEN was not set"); - String awsRegion = requireNonNull(System.getenv("AWS_REGION"), "Environment AWS_REGION was not set"); - String s3Bucket = requireNonNull(System.getenv("S3_BUCKET"), "Environment S3_BUCKET was not set"); + String databricksTestLogin = requireEnv("DATABRICKS_LOGIN"); + String databricksTestToken = requireEnv("DATABRICKS_TOKEN"); + String awsRegion = requireEnv("AWS_REGION"); + String s3Bucket = requireEnv("S3_BUCKET"); DockerFiles.ResourceProvider configDir = dockerFiles.getDockerFilesHostDirectory("conf/environment/singlenode-delta-lake-databricks"); builder.configureContainer(COORDINATOR, dockerContainer -> exportAWSCredentials(dockerContainer) diff --git a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvMultinodeAzure.java b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvMultinodeAzure.java index d31e6892a939..c46ef68e7356 100644 --- a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvMultinodeAzure.java +++ b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvMultinodeAzure.java @@ -34,6 +34,7 @@ import java.nio.file.Path; import java.nio.file.attribute.PosixFilePermissions; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.testing.TestingNames.randomNameSuffix; import static io.trino.tests.product.launcher.docker.ContainerUtil.forSelectedPorts; import static io.trino.tests.product.launcher.env.EnvironmentContainers.COORDINATOR; @@ -203,9 +204,4 @@ private Path getTemptoConfiguration(String schema) throw new UncheckedIOException(e); } } - - private static String requireEnv(String variable) - { - return requireNonNull(System.getenv(variable), () -> "environment variable not set: " + variable); - } } diff --git a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvMultinodeDatabricksHttpHms.java b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvMultinodeDatabricksHttpHms.java index 7a5317b0195c..ce0c8b48115b 100644 --- a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvMultinodeDatabricksHttpHms.java +++ b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvMultinodeDatabricksHttpHms.java @@ -23,6 +23,7 @@ import java.io.File; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.tests.product.launcher.env.EnvironmentContainers.TESTS; import static io.trino.tests.product.launcher.env.EnvironmentContainers.configureTempto; import static io.trino.tests.product.launcher.env.EnvironmentContainers.isTrinoContainer; @@ -50,18 +51,18 @@ public EnvMultinodeDatabricksHttpHms(StandardMultinode standardMultinode, Docker @Override public void extendEnvironment(Environment.Builder builder) { - String databricksTestJdbcUrl = requireNonNull(getEnvVariable("DATABRICKS_UNITY_JDBC_URL"), "Environment DATABRICKS_UNITY_JDBC_URL was not set"); - String databricksTestLogin = requireNonNull(getEnvVariable("DATABRICKS_LOGIN"), "Environment DATABRICKS_LOGIN was not set"); - String databricksTestToken = requireNonNull(getEnvVariable("DATABRICKS_TOKEN"), "Environment DATABRICKS_TOKEN was not set"); - String awsRegion = requireNonNull(getEnvVariable("AWS_REGION"), "Environment AWS_REGION was not set"); + String databricksTestJdbcUrl = requireEnv("DATABRICKS_UNITY_JDBC_URL"); + String databricksTestLogin = requireEnv("DATABRICKS_LOGIN"); + String databricksTestToken = requireEnv("DATABRICKS_TOKEN"); + String awsRegion = requireEnv("AWS_REGION"); builder.configureContainers(container -> { if (isTrinoContainer(container.getLogicalName())) { exportAwsCredentials(container) .withEnv("AWS_REGION", awsRegion) .withEnv("DATABRICKS_TOKEN", databricksTestToken) - .withEnv("DATABRICKS_HOST", getEnvVariable("DATABRICKS_HOST")) - .withEnv("DATABRICKS_UNITY_CATALOG_NAME", getEnvVariable("DATABRICKS_UNITY_CATALOG_NAME")); + .withEnv("DATABRICKS_HOST", requireEnv("DATABRICKS_HOST")) + .withEnv("DATABRICKS_UNITY_CATALOG_NAME", requireEnv("DATABRICKS_UNITY_CATALOG_NAME")); } }); @@ -69,8 +70,8 @@ public void extendEnvironment(Environment.Builder builder) .withEnv("DATABRICKS_JDBC_URL", databricksTestJdbcUrl) .withEnv("DATABRICKS_LOGIN", databricksTestLogin) .withEnv("DATABRICKS_TOKEN", databricksTestToken) - .withEnv("DATABRICKS_UNITY_CATALOG_NAME", getEnvVariable("DATABRICKS_UNITY_CATALOG_NAME")) - .withEnv("DATABRICKS_UNITY_EXTERNAL_LOCATION", getEnvVariable("DATABRICKS_UNITY_EXTERNAL_LOCATION")) + .withEnv("DATABRICKS_UNITY_CATALOG_NAME", requireEnv("DATABRICKS_UNITY_CATALOG_NAME")) + .withEnv("DATABRICKS_UNITY_EXTERNAL_LOCATION", requireEnv("DATABRICKS_UNITY_EXTERNAL_LOCATION")) .withCopyFileToContainer( forHostPath(DATABRICKS_JDBC_PROVIDER.getAbsolutePath()), "/docker/jdbc/databricks-jdbc.jar")); @@ -83,15 +84,6 @@ public void extendEnvironment(Environment.Builder builder) configureTempto(builder, configDir); } - private static String getEnvVariable(String name) - { - String credentialValue = System.getenv(name); - if (credentialValue == null) { - throw new IllegalStateException(format("Environment variable %s not set", name)); - } - return credentialValue; - } - private DockerContainer exportAwsCredentials(DockerContainer container) { container = exportAwsCredential(container, "TRINO_AWS_ACCESS_KEY_ID", "AWS_ACCESS_KEY_ID", true); diff --git a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvMultinodeGcs.java b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvMultinodeGcs.java index 3fab018afb8c..19091983dd4d 100644 --- a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvMultinodeGcs.java +++ b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvMultinodeGcs.java @@ -37,6 +37,7 @@ import java.util.Base64; import java.util.UUID; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.tests.product.launcher.docker.ContainerUtil.forSelectedPorts; import static io.trino.tests.product.launcher.env.EnvironmentContainers.COORDINATOR; import static io.trino.tests.product.launcher.env.EnvironmentContainers.HADOOP; @@ -188,9 +189,4 @@ private Path getHiveSiteOverrideXml(String gcpStorageBucket) throw new UncheckedIOException(e); } } - - private static String requireEnv(String variable) - { - return requireNonNull(System.getenv(variable), () -> "environment variable not set: " + variable); - } } diff --git a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvMultinodeSnowflake.java b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvMultinodeSnowflake.java index ac5694a0b835..ab1933931999 100644 --- a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvMultinodeSnowflake.java +++ b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvMultinodeSnowflake.java @@ -20,6 +20,7 @@ import io.trino.tests.product.launcher.env.common.Standard; import io.trino.tests.product.launcher.env.common.TestsEnvironment; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.tests.product.launcher.env.EnvironmentContainers.isTrinoContainer; import static io.trino.tests.product.launcher.env.common.Standard.CONTAINER_TRINO_JVM_CONFIG; import static java.util.Objects.requireNonNull; @@ -57,9 +58,4 @@ public void extendEnvironment(Environment.Builder builder) builder.addConnector("snowflake", forHostPath(configDir.getPath("snowflake.properties"))); } - - private static String requireEnv(String variable) - { - return requireNonNull(System.getenv(variable), () -> "environment variable not set: " + variable); - } } diff --git a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks104.java b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks104.java index 65d8196523c3..cf204d8d18ab 100644 --- a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks104.java +++ b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks104.java @@ -18,7 +18,7 @@ import io.trino.tests.product.launcher.env.common.Standard; import io.trino.tests.product.launcher.env.common.TestsEnvironment; -import static java.util.Objects.requireNonNull; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; @TestsEnvironment public class EnvSinglenodeDeltaLakeDatabricks104 @@ -33,6 +33,6 @@ public EnvSinglenodeDeltaLakeDatabricks104(Standard standard, DockerFiles docker @Override String databricksTestJdbcUrl() { - return requireNonNull(System.getenv("DATABRICKS_104_JDBC_URL"), "Environment DATABRICKS_104_JDBC_URL was not set"); + return requireEnv("DATABRICKS_104_JDBC_URL"); } } diff --git a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks113.java b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks113.java index d8248cec2d60..54ea27443fbe 100644 --- a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks113.java +++ b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks113.java @@ -18,7 +18,7 @@ import io.trino.tests.product.launcher.env.common.Standard; import io.trino.tests.product.launcher.env.common.TestsEnvironment; -import static java.util.Objects.requireNonNull; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; @TestsEnvironment public class EnvSinglenodeDeltaLakeDatabricks113 @@ -33,6 +33,6 @@ public EnvSinglenodeDeltaLakeDatabricks113(Standard standard, DockerFiles docker @Override String databricksTestJdbcUrl() { - return requireNonNull(System.getenv("DATABRICKS_113_JDBC_URL"), "Environment DATABRICKS_113_JDBC_URL was not set"); + return requireEnv("DATABRICKS_113_JDBC_URL"); } } diff --git a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks122.java b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks122.java index 0435b226bfb1..586fd0f7ee24 100644 --- a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks122.java +++ b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks122.java @@ -18,7 +18,7 @@ import io.trino.tests.product.launcher.env.common.Standard; import io.trino.tests.product.launcher.env.common.TestsEnvironment; -import static java.util.Objects.requireNonNull; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; @TestsEnvironment public class EnvSinglenodeDeltaLakeDatabricks122 @@ -33,6 +33,6 @@ public EnvSinglenodeDeltaLakeDatabricks122(Standard standard, DockerFiles docker @Override String databricksTestJdbcUrl() { - return requireNonNull(System.getenv("DATABRICKS_122_JDBC_URL"), "Environment DATABRICKS_122_JDBC_URL was not set"); + return requireEnv("DATABRICKS_122_JDBC_URL"); } } diff --git a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks133.java b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks133.java index e054cec92822..b1da087a8653 100644 --- a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks133.java +++ b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks133.java @@ -18,7 +18,7 @@ import io.trino.tests.product.launcher.env.common.Standard; import io.trino.tests.product.launcher.env.common.TestsEnvironment; -import static java.util.Objects.requireNonNull; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; @TestsEnvironment public class EnvSinglenodeDeltaLakeDatabricks133 @@ -33,6 +33,6 @@ public EnvSinglenodeDeltaLakeDatabricks133(Standard standard, DockerFiles docker @Override String databricksTestJdbcUrl() { - return requireNonNull(System.getenv("DATABRICKS_133_JDBC_URL"), "Environment DATABRICKS_133_JDBC_URL was not set"); + return requireEnv("DATABRICKS_133_JDBC_URL"); } } diff --git a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks143.java b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks143.java index 06b70041a58b..bec3c502b8b6 100644 --- a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks143.java +++ b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks143.java @@ -18,7 +18,7 @@ import io.trino.tests.product.launcher.env.common.Standard; import io.trino.tests.product.launcher.env.common.TestsEnvironment; -import static java.util.Objects.requireNonNull; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; @TestsEnvironment public class EnvSinglenodeDeltaLakeDatabricks143 @@ -33,6 +33,6 @@ public EnvSinglenodeDeltaLakeDatabricks143(Standard standard, DockerFiles docker @Override String databricksTestJdbcUrl() { - return requireNonNull(System.getenv("DATABRICKS_143_JDBC_URL"), "Environment DATABRICKS_143_JDBC_URL was not set"); + return requireEnv("DATABRICKS_143_JDBC_URL"); } } diff --git a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks154.java b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks154.java index ea427a21c71b..37bb6d41eeb7 100644 --- a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks154.java +++ b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks154.java @@ -18,7 +18,7 @@ import io.trino.tests.product.launcher.env.common.Standard; import io.trino.tests.product.launcher.env.common.TestsEnvironment; -import static java.util.Objects.requireNonNull; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; @TestsEnvironment public class EnvSinglenodeDeltaLakeDatabricks154 @@ -33,6 +33,6 @@ public EnvSinglenodeDeltaLakeDatabricks154(Standard standard, DockerFiles docker @Override String databricksTestJdbcUrl() { - return requireNonNull(System.getenv("DATABRICKS_154_JDBC_URL"), "Environment DATABRICKS_154_JDBC_URL was not set"); + return requireEnv("DATABRICKS_154_JDBC_URL"); } } diff --git a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks91.java b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks91.java index 0f9b61613109..cf85d7118b53 100644 --- a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks91.java +++ b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeDeltaLakeDatabricks91.java @@ -18,7 +18,7 @@ import io.trino.tests.product.launcher.env.common.Standard; import io.trino.tests.product.launcher.env.common.TestsEnvironment; -import static java.util.Objects.requireNonNull; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; @TestsEnvironment public class EnvSinglenodeDeltaLakeDatabricks91 @@ -33,6 +33,6 @@ public EnvSinglenodeDeltaLakeDatabricks91(Standard standard, DockerFiles dockerF @Override String databricksTestJdbcUrl() { - return requireNonNull(System.getenv("DATABRICKS_91_JDBC_URL"), "Environment DATABRICKS_91_JDBC_URL was not set"); + return requireEnv("DATABRICKS_91_JDBC_URL"); } } diff --git a/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/BaseTestDeltaLakeS3Storage.java b/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/BaseTestDeltaLakeS3Storage.java index a0ec14e63776..5feaca425845 100644 --- a/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/BaseTestDeltaLakeS3Storage.java +++ b/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/BaseTestDeltaLakeS3Storage.java @@ -16,7 +16,7 @@ import io.trino.tempto.BeforeMethodWithContext; import io.trino.tempto.ProductTest; -import static java.util.Objects.requireNonNull; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; public abstract class BaseTestDeltaLakeS3Storage extends ProductTest @@ -26,6 +26,6 @@ public abstract class BaseTestDeltaLakeS3Storage @BeforeMethodWithContext public void setUp() { - bucketName = requireNonNull(System.getenv("S3_BUCKET"), "Environment variable not set: S3_BUCKET"); + bucketName = requireEnv("S3_BUCKET"); } } diff --git a/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/S3ClientFactory.java b/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/S3ClientFactory.java index c81171488413..ca372999c91a 100644 --- a/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/S3ClientFactory.java +++ b/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/S3ClientFactory.java @@ -25,9 +25,9 @@ import com.amazonaws.services.s3.model.Region; import io.trino.testing.minio.MinioClient; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.testing.minio.MinioClient.DEFAULT_MINIO_ACCESS_KEY; import static io.trino.testing.minio.MinioClient.DEFAULT_MINIO_SECRET_KEY; -import static java.util.Objects.requireNonNull; final class S3ClientFactory { @@ -45,7 +45,7 @@ public AmazonS3 createS3Client(String serverType) private AmazonS3 createAwsS3Client() { - String region = requireNonNull(System.getenv("AWS_REGION"), "AWS_REGION is null"); + String region = requireEnv("AWS_REGION"); return AmazonS3Client.builder().withRegion(region).build(); } diff --git a/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/TestDeltaLakeAlluxioCaching.java b/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/TestDeltaLakeAlluxioCaching.java index ce75707232ec..ee3e8ee772f3 100644 --- a/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/TestDeltaLakeAlluxioCaching.java +++ b/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/TestDeltaLakeAlluxioCaching.java @@ -19,12 +19,12 @@ import io.trino.tests.product.utils.CachingTestUtils.CacheStats; import org.testng.annotations.Test; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.tests.product.TestGroups.DELTA_LAKE_ALLUXIO_CACHING; import static io.trino.tests.product.TestGroups.PROFILE_SPECIFIC_TESTS; import static io.trino.tests.product.utils.CachingTestUtils.getCacheStats; import static io.trino.tests.product.utils.QueryAssertions.assertEventually; import static io.trino.tests.product.utils.QueryExecutors.onTrino; -import static java.util.Objects.requireNonNull; import static java.util.concurrent.TimeUnit.SECONDS; import static org.assertj.core.api.Assertions.assertThat; @@ -36,7 +36,7 @@ public class TestDeltaLakeAlluxioCaching @BeforeMethodWithContext public void setUp() { - bucketName = requireNonNull(System.getenv("S3_BUCKET"), "Environment variable not set: S3_BUCKET"); + bucketName = requireEnv("S3_BUCKET"); } @Test(groups = {DELTA_LAKE_ALLUXIO_CACHING, PROFILE_SPECIFIC_TESTS}) diff --git a/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/TestDeltaLakeAzure.java b/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/TestDeltaLakeAzure.java index 97c8816c9465..115dbe334887 100644 --- a/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/TestDeltaLakeAzure.java +++ b/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/TestDeltaLakeAzure.java @@ -19,10 +19,10 @@ import io.trino.tests.product.BaseTestTableFormats; import org.testng.annotations.Test; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.tests.product.TestGroups.DELTA_LAKE_AZURE; import static io.trino.tests.product.TestGroups.PROFILE_SPECIFIC_TESTS; import static java.lang.String.format; -import static java.util.Objects.requireNonNull; public class TestDeltaLakeAzure extends BaseTestTableFormats @@ -35,8 +35,8 @@ public class TestDeltaLakeAzure @BeforeMethodWithContext public void setUp() { - String container = requireNonNull(System.getenv("ABFS_CONTAINER"), "Environment variable not set: ABFS_CONTAINER"); - String account = requireNonNull(System.getenv("ABFS_ACCOUNT"), "Environment variable not set: ABFS_ACCOUNT"); + String container = requireEnv("ABFS_CONTAINER"); + String account = requireEnv("ABFS_ACCOUNT"); schemaLocation = format("abfs://%s@%s.dfs.core.windows.net/%s", container, account, schema); } diff --git a/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/TestDeltaLakeDatabricksUnityCompatibility.java b/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/TestDeltaLakeDatabricksUnityCompatibility.java index 5c9cec3d33ef..8dbb1fdf9e32 100644 --- a/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/TestDeltaLakeDatabricksUnityCompatibility.java +++ b/testing/trino-product-tests/src/main/java/io/trino/tests/product/deltalake/TestDeltaLakeDatabricksUnityCompatibility.java @@ -25,6 +25,7 @@ import static io.trino.tempto.assertions.QueryAssert.Row.row; import static io.trino.tempto.assertions.QueryAssert.assertQueryFailure; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.testing.TestingNames.randomNameSuffix; import static io.trino.tests.product.TestGroups.DATABRICKS_UNITY_HTTP_HMS; import static io.trino.tests.product.TestGroups.PROFILE_SPECIFIC_TESTS; @@ -34,7 +35,6 @@ import static io.trino.tests.product.utils.QueryExecutors.onTrino; import static java.lang.String.format; import static java.util.Locale.ENGLISH; -import static java.util.Objects.requireNonNull; import static org.assertj.core.api.Assertions.assertThat; public class TestDeltaLakeDatabricksUnityCompatibility @@ -47,8 +47,8 @@ public class TestDeltaLakeDatabricksUnityCompatibility @BeforeMethodWithContext public void setUp() { - unityCatalogName = requireNonNull(System.getenv("DATABRICKS_UNITY_CATALOG_NAME"), "Environment variable not set: DATABRICKS_UNITY_CATALOG_NAME"); - externalLocationPath = requireNonNull(System.getenv("DATABRICKS_UNITY_EXTERNAL_LOCATION"), "Environment variable not set: DATABRICKS_UNITY_EXTERNAL_LOCATION"); + unityCatalogName = requireEnv("DATABRICKS_UNITY_CATALOG_NAME"); + externalLocationPath = requireEnv("DATABRICKS_UNITY_EXTERNAL_LOCATION"); onDelta().executeQuery(format("CREATE SCHEMA %s.%s", unityCatalogName, schemaName)); } diff --git a/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestAbfsSyncPartitionMetadata.java b/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestAbfsSyncPartitionMetadata.java index 20b1a0339730..37ef181ba5c6 100644 --- a/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestAbfsSyncPartitionMetadata.java +++ b/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestAbfsSyncPartitionMetadata.java @@ -21,13 +21,13 @@ import org.testng.annotations.Test; import static com.google.common.base.Preconditions.checkArgument; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.tests.product.TestGroups.AZURE; import static io.trino.tests.product.utils.HadoopTestUtils.RETRYABLE_FAILURES_ISSUES; import static io.trino.tests.product.utils.HadoopTestUtils.RETRYABLE_FAILURES_MATCH; import static io.trino.tests.product.utils.QueryExecutors.onHive; import static io.trino.tests.product.utils.QueryExecutors.onTrino; import static java.lang.String.format; -import static java.util.Objects.requireNonNull; import static org.apache.parquet.Strings.isNullOrEmpty; public class TestAbfsSyncPartitionMetadata @@ -53,8 +53,8 @@ public void tearDown() @Override protected String schemaLocation() { - String container = requireNonNull(System.getenv("ABFS_CONTAINER"), "Environment variable not set: ABFS_CONTAINER"); - String account = requireNonNull(System.getenv("ABFS_ACCOUNT"), "Environment variable not set: ABFS_ACCOUNT"); + String container = requireEnv("ABFS_CONTAINER"); + String account = requireEnv("ABFS_ACCOUNT"); return format("abfs://%s@%s.dfs.core.windows.net/%s", container, account, schema); } diff --git a/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestAzureBlobFileSystem.java b/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestAzureBlobFileSystem.java index e816b3428542..090da1d5d554 100644 --- a/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestAzureBlobFileSystem.java +++ b/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestAzureBlobFileSystem.java @@ -26,6 +26,7 @@ import java.util.List; import static io.trino.tempto.assertions.QueryAssert.Row.row; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.testing.TestingNames.randomNameSuffix; import static io.trino.tests.product.TestGroups.AZURE; import static io.trino.tests.product.utils.HadoopTestUtils.RETRYABLE_FAILURES_ISSUES; @@ -33,7 +34,6 @@ import static io.trino.tests.product.utils.QueryExecutors.onHive; import static io.trino.tests.product.utils.QueryExecutors.onTrino; import static java.lang.String.format; -import static java.util.Objects.requireNonNull; import static org.assertj.core.api.Assertions.assertThat; public class TestAzureBlobFileSystem @@ -47,8 +47,8 @@ public class TestAzureBlobFileSystem @BeforeMethodWithContext public void setUp() { - String container = requireNonNull(System.getenv("ABFS_CONTAINER"), "Environment variable not set: ABFS_CONTAINER"); - String account = requireNonNull(System.getenv("ABFS_ACCOUNT"), "Environment variable not set: ABFS_ACCOUNT"); + String container = requireEnv("ABFS_CONTAINER"); + String account = requireEnv("ABFS_ACCOUNT"); schemaLocation = format("abfs://%s@%s.dfs.core.windows.net/%s", container, account, schema); onHive().executeQuery("dfs -rm -f -r " + schemaLocation); diff --git a/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestHiveAzure.java b/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestHiveAzure.java index b8586917cc91..0b163e47e2af 100644 --- a/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestHiveAzure.java +++ b/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestHiveAzure.java @@ -19,10 +19,10 @@ import io.trino.tests.product.BaseTestTableFormats; import org.testng.annotations.Test; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.tests.product.TestGroups.AZURE; import static io.trino.tests.product.TestGroups.PROFILE_SPECIFIC_TESTS; import static java.lang.String.format; -import static java.util.Objects.requireNonNull; public class TestHiveAzure extends BaseTestTableFormats @@ -35,8 +35,8 @@ public class TestHiveAzure @BeforeMethodWithContext public void setUp() { - String container = requireNonNull(System.getenv("ABFS_CONTAINER"), "Environment variable not set: ABFS_CONTAINER"); - String account = requireNonNull(System.getenv("ABFS_ACCOUNT"), "Environment variable not set: ABFS_ACCOUNT"); + String container = requireEnv("ABFS_CONTAINER"); + String account = requireEnv("ABFS_ACCOUNT"); schemaLocation = format("abfs://%s@%s.dfs.core.windows.net/%s", container, account, schema); } diff --git a/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestHiveDatabricksUnityCompatibility.java b/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestHiveDatabricksUnityCompatibility.java index a3bd6e9579b0..84cb24502b8e 100644 --- a/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestHiveDatabricksUnityCompatibility.java +++ b/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestHiveDatabricksUnityCompatibility.java @@ -20,6 +20,7 @@ import org.testng.annotations.Test; import static io.trino.tempto.assertions.QueryAssert.Row.row; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.testing.TestingNames.randomNameSuffix; import static io.trino.tests.product.TestGroups.DATABRICKS_UNITY_HTTP_HMS; import static io.trino.tests.product.TestGroups.PROFILE_SPECIFIC_TESTS; @@ -28,7 +29,6 @@ import static io.trino.tests.product.utils.QueryExecutors.onDelta; import static io.trino.tests.product.utils.QueryExecutors.onTrino; import static java.lang.String.format; -import static java.util.Objects.requireNonNull; import static org.assertj.core.api.Assertions.assertThat; public class TestHiveDatabricksUnityCompatibility @@ -41,8 +41,8 @@ public class TestHiveDatabricksUnityCompatibility @BeforeMethodWithContext public void setUp() { - unityCatalogName = requireNonNull(System.getenv("DATABRICKS_UNITY_CATALOG_NAME"), "Environment variable not set: DATABRICKS_UNITY_CATALOG_NAME"); - externalLocationPath = requireNonNull(System.getenv("DATABRICKS_UNITY_EXTERNAL_LOCATION"), "Environment variable not set: DATABRICKS_UNITY_EXTERNAL_LOCATION"); + unityCatalogName = requireEnv("DATABRICKS_UNITY_CATALOG_NAME"); + externalLocationPath = requireEnv("DATABRICKS_UNITY_EXTERNAL_LOCATION"); String schemaLocation = format("%s/%s", externalLocationPath, schemaName); onDelta().executeQuery("CREATE SCHEMA " + unityCatalogName + "." + schemaName + " MANAGED LOCATION '" + schemaLocation + "'"); } diff --git a/testing/trino-product-tests/src/main/java/io/trino/tests/product/hudi/TestHudiSparkCompatibility.java b/testing/trino-product-tests/src/main/java/io/trino/tests/product/hudi/TestHudiSparkCompatibility.java index 91c0702c0068..c42783245eaf 100644 --- a/testing/trino-product-tests/src/main/java/io/trino/tests/product/hudi/TestHudiSparkCompatibility.java +++ b/testing/trino-product-tests/src/main/java/io/trino/tests/product/hudi/TestHudiSparkCompatibility.java @@ -23,6 +23,7 @@ import static io.trino.tempto.assertions.QueryAssert.Row.row; import static io.trino.tempto.assertions.QueryAssert.assertQueryFailure; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.testing.TestingNames.randomNameSuffix; import static io.trino.tests.product.TestGroups.HIVE_HUDI_REDIRECTIONS; import static io.trino.tests.product.TestGroups.HUDI; @@ -30,7 +31,6 @@ import static io.trino.tests.product.utils.QueryExecutors.onHudi; import static io.trino.tests.product.utils.QueryExecutors.onTrino; import static java.lang.String.format; -import static java.util.Objects.requireNonNull; import static org.assertj.core.api.Assertions.assertThat; public class TestHudiSparkCompatibility @@ -44,7 +44,7 @@ public class TestHudiSparkCompatibility @BeforeMethodWithContext public void setUp() { - bucketName = requireNonNull(System.getenv("S3_BUCKET"), "Environment variable not set: S3_BUCKET"); + bucketName = requireEnv("S3_BUCKET"); } @Test(groups = {HUDI, PROFILE_SPECIFIC_TESTS}) diff --git a/testing/trino-product-tests/src/main/java/io/trino/tests/product/iceberg/TestIcebergAlluxioCaching.java b/testing/trino-product-tests/src/main/java/io/trino/tests/product/iceberg/TestIcebergAlluxioCaching.java index 4fa903cc1731..8ee6e3a9e424 100644 --- a/testing/trino-product-tests/src/main/java/io/trino/tests/product/iceberg/TestIcebergAlluxioCaching.java +++ b/testing/trino-product-tests/src/main/java/io/trino/tests/product/iceberg/TestIcebergAlluxioCaching.java @@ -19,12 +19,12 @@ import io.trino.tests.product.utils.CachingTestUtils.CacheStats; import org.testng.annotations.Test; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.tests.product.TestGroups.ICEBERG_ALLUXIO_CACHING; import static io.trino.tests.product.TestGroups.PROFILE_SPECIFIC_TESTS; import static io.trino.tests.product.utils.CachingTestUtils.getCacheStats; import static io.trino.tests.product.utils.QueryAssertions.assertEventually; import static io.trino.tests.product.utils.QueryExecutors.onTrino; -import static java.util.Objects.requireNonNull; import static java.util.concurrent.TimeUnit.SECONDS; import static org.assertj.core.api.Assertions.assertThat; @@ -36,7 +36,7 @@ public class TestIcebergAlluxioCaching @BeforeMethodWithContext public void setUp() { - bucketName = requireNonNull(System.getenv("S3_BUCKET"), "Environment variable not set: S3_BUCKET"); + bucketName = requireEnv("S3_BUCKET"); } @Test(groups = {ICEBERG_ALLUXIO_CACHING, PROFILE_SPECIFIC_TESTS}) diff --git a/testing/trino-product-tests/src/main/java/io/trino/tests/product/iceberg/TestIcebergAzure.java b/testing/trino-product-tests/src/main/java/io/trino/tests/product/iceberg/TestIcebergAzure.java index e689e1dcb84a..6fe56c3dfb6f 100644 --- a/testing/trino-product-tests/src/main/java/io/trino/tests/product/iceberg/TestIcebergAzure.java +++ b/testing/trino-product-tests/src/main/java/io/trino/tests/product/iceberg/TestIcebergAzure.java @@ -19,10 +19,10 @@ import io.trino.tests.product.BaseTestTableFormats; import org.testng.annotations.Test; +import static io.trino.testing.SystemEnvironmentUtils.requireEnv; import static io.trino.tests.product.TestGroups.ICEBERG_AZURE; import static io.trino.tests.product.TestGroups.PROFILE_SPECIFIC_TESTS; import static java.lang.String.format; -import static java.util.Objects.requireNonNull; public class TestIcebergAzure extends BaseTestTableFormats @@ -35,8 +35,8 @@ public class TestIcebergAzure @BeforeMethodWithContext public void setUp() { - String container = requireNonNull(System.getenv("ABFS_CONTAINER"), "Environment variable not set: ABFS_CONTAINER"); - String account = requireNonNull(System.getenv("ABFS_ACCOUNT"), "Environment variable not set: ABFS_ACCOUNT"); + String container = requireEnv("ABFS_CONTAINER"); + String account = requireEnv("ABFS_ACCOUNT"); schemaLocation = format("abfs://%s@%s.dfs.core.windows.net/%s", container, account, schema); } diff --git a/testing/trino-testing-containers/src/main/java/io/trino/testing/containers/TestContainers.java b/testing/trino-testing-containers/src/main/java/io/trino/testing/containers/TestContainers.java index 03330b35f54c..9f9e0886fd34 100644 --- a/testing/trino-testing-containers/src/main/java/io/trino/testing/containers/TestContainers.java +++ b/testing/trino-testing-containers/src/main/java/io/trino/testing/containers/TestContainers.java @@ -31,6 +31,7 @@ import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Strings.padEnd; import static com.google.common.collect.ImmutableList.toImmutableList; +import static io.trino.testing.SystemEnvironmentUtils.isEnvSet; import static io.trino.testing.containers.ConditionalPullPolicy.TESTCONTAINERS_NEVER_PULL; import static java.lang.Boolean.parseBoolean; import static java.lang.System.getenv; @@ -72,7 +73,7 @@ public static String getPathFromClassPathResource(String resourcePath) public static void exposeFixedPorts(GenericContainer container) { - checkState(System.getenv("CONTINUOUS_INTEGRATION") == null, "" + + checkState(isEnvSet("CONTINUOUS_INTEGRATION"), "" + "Exposing fixed ports should not be used in regular test code. This could break parallel test execution. " + "This method is supposed to be invoked from local development helpers only e.g. QueryRunner.main(), " + "hence it should never run on CI"); diff --git a/testing/trino-testing-services/src/main/java/io/trino/testing/SystemEnvironmentUtils.java b/testing/trino-testing-services/src/main/java/io/trino/testing/SystemEnvironmentUtils.java new file mode 100644 index 000000000000..0f866033cf56 --- /dev/null +++ b/testing/trino-testing-services/src/main/java/io/trino/testing/SystemEnvironmentUtils.java @@ -0,0 +1,34 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.trino.testing; + +import static java.util.Objects.requireNonNull; + +public final class SystemEnvironmentUtils +{ + private SystemEnvironmentUtils() {} + + /** + * Get the named environment variable, throwing an exception if it is not set. + */ + public static String requireEnv(String variable) + { + return requireNonNull(System.getenv(variable), () -> "environment variable not set: " + variable); + } + + public static boolean isEnvSet(String variable) + { + return System.getenv(variable) != null; + } +} diff --git a/testing/trino-testing-services/src/main/java/io/trino/testing/services/junit/LogTestDurationListener.java b/testing/trino-testing-services/src/main/java/io/trino/testing/services/junit/LogTestDurationListener.java index 33127d251bb2..8263d6196b3c 100644 --- a/testing/trino-testing-services/src/main/java/io/trino/testing/services/junit/LogTestDurationListener.java +++ b/testing/trino-testing-services/src/main/java/io/trino/testing/services/junit/LogTestDurationListener.java @@ -37,6 +37,7 @@ import static com.google.common.base.Throwables.getStackTraceAsString; import static io.airlift.concurrent.Threads.daemonThreadsNamed; import static io.airlift.units.Duration.nanosSince; +import static io.trino.testing.SystemEnvironmentUtils.isEnvSet; import static io.trino.testing.services.junit.Listeners.reportListenerFailure; import static java.lang.String.format; import static java.lang.management.ManagementFactory.getThreadMXBean; @@ -73,7 +74,7 @@ private static boolean isEnabled() if (System.getProperty("LogTestDurationListener.enabled") != null) { return Boolean.getBoolean("LogTestDurationListener.enabled"); } - if (System.getenv("CONTINUOUS_INTEGRATION") != null) { + if (isEnvSet("CONTINUOUS_INTEGRATION")) { return true; } // For local development, logging durations is not typically useful. diff --git a/testing/trino-testing-services/src/main/java/io/trino/testng/services/FlakyTestRetryAnalyzer.java b/testing/trino-testing-services/src/main/java/io/trino/testng/services/FlakyTestRetryAnalyzer.java index 849403bea407..8ff39a4f6a98 100644 --- a/testing/trino-testing-services/src/main/java/io/trino/testng/services/FlakyTestRetryAnalyzer.java +++ b/testing/trino-testing-services/src/main/java/io/trino/testng/services/FlakyTestRetryAnalyzer.java @@ -28,6 +28,7 @@ import java.util.regex.Pattern; import static com.google.common.base.Throwables.getStackTraceAsString; +import static io.trino.testing.SystemEnvironmentUtils.isEnvSet; import static java.lang.String.format; public class FlakyTestRetryAnalyzer @@ -54,7 +55,7 @@ public boolean retry(ITestResult result) Optional enabledSystemPropertyValue = Optional.ofNullable(System.getProperty(ENABLED_SYSTEM_PROPERTY)); if (!enabledSystemPropertyValue.map(Boolean::parseBoolean) - .orElseGet(() -> System.getenv("CONTINUOUS_INTEGRATION") != null)) { + .orElseGet(() -> isEnvSet("CONTINUOUS_INTEGRATION"))) { log.info( "FlakyTestRetryAnalyzer not enabled: " + "CONTINUOUS_INTEGRATION environment is not detected or " + diff --git a/testing/trino-testing-services/src/main/java/io/trino/testng/services/LogTestDurationListener.java b/testing/trino-testing-services/src/main/java/io/trino/testng/services/LogTestDurationListener.java index f5e0e4d726b7..25a933487715 100644 --- a/testing/trino-testing-services/src/main/java/io/trino/testng/services/LogTestDurationListener.java +++ b/testing/trino-testing-services/src/main/java/io/trino/testng/services/LogTestDurationListener.java @@ -39,6 +39,7 @@ import static com.google.common.base.Throwables.getStackTraceAsString; import static io.airlift.concurrent.Threads.daemonThreadsNamed; import static io.airlift.units.Duration.nanosSince; +import static io.trino.testing.SystemEnvironmentUtils.isEnvSet; import static io.trino.testng.services.Listeners.formatTestName; import static io.trino.testng.services.Listeners.reportListenerFailure; import static java.lang.String.format; @@ -79,7 +80,7 @@ private static boolean isEnabled() if (System.getProperty("LogTestDurationListener.enabled") != null) { return Boolean.getBoolean("LogTestDurationListener.enabled"); } - if (System.getenv("CONTINUOUS_INTEGRATION") != null) { + if (isEnvSet("CONTINUOUS_INTEGRATION")) { return true; } // LogTestDurationListener does not support concurrent invocations of same test method diff --git a/testing/trino-testing-services/src/main/java/io/trino/testng/services/ProgressLoggingListener.java b/testing/trino-testing-services/src/main/java/io/trino/testng/services/ProgressLoggingListener.java index 3f61b2496044..8a0011e699ee 100644 --- a/testing/trino-testing-services/src/main/java/io/trino/testng/services/ProgressLoggingListener.java +++ b/testing/trino-testing-services/src/main/java/io/trino/testng/services/ProgressLoggingListener.java @@ -25,6 +25,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; +import static io.trino.testing.SystemEnvironmentUtils.isEnvSet; import static io.trino.testng.services.Listeners.formatTestName; import static java.lang.String.format; @@ -47,7 +48,7 @@ private static boolean isEnabled() if (System.getProperty("ProgressLoggingListener.enabled") != null) { return Boolean.getBoolean("ProgressLoggingListener.enabled"); } - if (System.getenv("CONTINUOUS_INTEGRATION") != null) { + if (isEnvSet("CONTINUOUS_INTEGRATION")) { return true; } // most often not useful for local development