Skip to content

Commit

Permalink
Add and use SystemEnvironmentUtils#isEnvSet method
Browse files Browse the repository at this point in the history
  • Loading branch information
krvikash authored and Praveen2112 committed Dec 19, 2024
1 parent 503329a commit a99d96e
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,7 +55,7 @@ public boolean retry(ITestResult result)

Optional<String> 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 " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down

0 comments on commit a99d96e

Please sign in to comment.