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..d4f8c9d6b65e 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.ProductTestEnvUtils.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/EnvMultinodeGcs.java b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvMultinodeGcs.java index 3fab018afb8c..badd1cf5394b 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.ProductTestEnvUtils.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..2222b871ed06 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.ProductTestEnvUtils.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-testing-services/src/main/java/io/trino/testing/ProductTestEnvUtils.java b/testing/trino-testing-services/src/main/java/io/trino/testing/ProductTestEnvUtils.java new file mode 100644 index 000000000000..e2de254813e6 --- /dev/null +++ b/testing/trino-testing-services/src/main/java/io/trino/testing/ProductTestEnvUtils.java @@ -0,0 +1,29 @@ +/* + * 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 ProductTestEnvUtils +{ + private ProductTestEnvUtils() {} + + /** + * 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); + } +}