Skip to content

Commit a99d96e

Browse files
krvikashPraveen2112
authored andcommitted
Add and use SystemEnvironmentUtils#isEnvSet method
1 parent 503329a commit a99d96e

File tree

7 files changed

+17
-6
lines changed

7 files changed

+17
-6
lines changed

testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/cli/TestRun.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
import static com.google.common.base.Strings.isNullOrEmpty;
5555
import static com.google.common.collect.ImmutableList.toImmutableList;
56+
import static io.trino.testing.SystemEnvironmentUtils.isEnvSet;
5657
import static io.trino.tests.product.launcher.env.DockerContainer.cleanOrCreateHostPath;
5758
import static io.trino.tests.product.launcher.env.EnvironmentContainers.TESTS;
5859
import static io.trino.tests.product.launcher.env.EnvironmentListener.getStandardListeners;
@@ -335,7 +336,7 @@ private Environment getEnvironment()
335336
unsafelyExposePort(container, 5007); // debug port
336337
}
337338

338-
if (System.getenv("CONTINUOUS_INTEGRATION") != null) {
339+
if (isEnvSet("CONTINUOUS_INTEGRATION")) {
339340
container.withEnv("CONTINUOUS_INTEGRATION", "true");
340341
}
341342

testing/trino-testing-containers/src/main/java/io/trino/testing/containers/TestContainers.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import static com.google.common.base.Preconditions.checkState;
3232
import static com.google.common.base.Strings.padEnd;
3333
import static com.google.common.collect.ImmutableList.toImmutableList;
34+
import static io.trino.testing.SystemEnvironmentUtils.isEnvSet;
3435
import static io.trino.testing.containers.ConditionalPullPolicy.TESTCONTAINERS_NEVER_PULL;
3536
import static java.lang.Boolean.parseBoolean;
3637
import static java.lang.System.getenv;
@@ -72,7 +73,7 @@ public static String getPathFromClassPathResource(String resourcePath)
7273

7374
public static void exposeFixedPorts(GenericContainer<?> container)
7475
{
75-
checkState(System.getenv("CONTINUOUS_INTEGRATION") == null, "" +
76+
checkState(isEnvSet("CONTINUOUS_INTEGRATION"), "" +
7677
"Exposing fixed ports should not be used in regular test code. This could break parallel test execution. " +
7778
"This method is supposed to be invoked from local development helpers only e.g. QueryRunner.main(), " +
7879
"hence it should never run on CI");

testing/trino-testing-services/src/main/java/io/trino/testing/SystemEnvironmentUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ public static String requireEnv(String variable)
2626
{
2727
return requireNonNull(System.getenv(variable), () -> "environment variable not set: " + variable);
2828
}
29+
30+
public static boolean isEnvSet(String variable)
31+
{
32+
return System.getenv(variable) != null;
33+
}
2934
}

testing/trino-testing-services/src/main/java/io/trino/testing/services/junit/LogTestDurationListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import static com.google.common.base.Throwables.getStackTraceAsString;
3838
import static io.airlift.concurrent.Threads.daemonThreadsNamed;
3939
import static io.airlift.units.Duration.nanosSince;
40+
import static io.trino.testing.SystemEnvironmentUtils.isEnvSet;
4041
import static io.trino.testing.services.junit.Listeners.reportListenerFailure;
4142
import static java.lang.String.format;
4243
import static java.lang.management.ManagementFactory.getThreadMXBean;
@@ -73,7 +74,7 @@ private static boolean isEnabled()
7374
if (System.getProperty("LogTestDurationListener.enabled") != null) {
7475
return Boolean.getBoolean("LogTestDurationListener.enabled");
7576
}
76-
if (System.getenv("CONTINUOUS_INTEGRATION") != null) {
77+
if (isEnvSet("CONTINUOUS_INTEGRATION")) {
7778
return true;
7879
}
7980
// For local development, logging durations is not typically useful.

testing/trino-testing-services/src/main/java/io/trino/testng/services/FlakyTestRetryAnalyzer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.regex.Pattern;
2929

3030
import static com.google.common.base.Throwables.getStackTraceAsString;
31+
import static io.trino.testing.SystemEnvironmentUtils.isEnvSet;
3132
import static java.lang.String.format;
3233

3334
public class FlakyTestRetryAnalyzer
@@ -54,7 +55,7 @@ public boolean retry(ITestResult result)
5455

5556
Optional<String> enabledSystemPropertyValue = Optional.ofNullable(System.getProperty(ENABLED_SYSTEM_PROPERTY));
5657
if (!enabledSystemPropertyValue.map(Boolean::parseBoolean)
57-
.orElseGet(() -> System.getenv("CONTINUOUS_INTEGRATION") != null)) {
58+
.orElseGet(() -> isEnvSet("CONTINUOUS_INTEGRATION"))) {
5859
log.info(
5960
"FlakyTestRetryAnalyzer not enabled: " +
6061
"CONTINUOUS_INTEGRATION environment is not detected or " +

testing/trino-testing-services/src/main/java/io/trino/testng/services/LogTestDurationListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import static com.google.common.base.Throwables.getStackTraceAsString;
4040
import static io.airlift.concurrent.Threads.daemonThreadsNamed;
4141
import static io.airlift.units.Duration.nanosSince;
42+
import static io.trino.testing.SystemEnvironmentUtils.isEnvSet;
4243
import static io.trino.testng.services.Listeners.formatTestName;
4344
import static io.trino.testng.services.Listeners.reportListenerFailure;
4445
import static java.lang.String.format;
@@ -79,7 +80,7 @@ private static boolean isEnabled()
7980
if (System.getProperty("LogTestDurationListener.enabled") != null) {
8081
return Boolean.getBoolean("LogTestDurationListener.enabled");
8182
}
82-
if (System.getenv("CONTINUOUS_INTEGRATION") != null) {
83+
if (isEnvSet("CONTINUOUS_INTEGRATION")) {
8384
return true;
8485
}
8586
// LogTestDurationListener does not support concurrent invocations of same test method

testing/trino-testing-services/src/main/java/io/trino/testng/services/ProgressLoggingListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.math.BigDecimal;
2626
import java.math.RoundingMode;
2727

28+
import static io.trino.testing.SystemEnvironmentUtils.isEnvSet;
2829
import static io.trino.testng.services.Listeners.formatTestName;
2930
import static java.lang.String.format;
3031

@@ -47,7 +48,7 @@ private static boolean isEnabled()
4748
if (System.getProperty("ProgressLoggingListener.enabled") != null) {
4849
return Boolean.getBoolean("ProgressLoggingListener.enabled");
4950
}
50-
if (System.getenv("CONTINUOUS_INTEGRATION") != null) {
51+
if (isEnvSet("CONTINUOUS_INTEGRATION")) {
5152
return true;
5253
}
5354
// most often not useful for local development

0 commit comments

Comments
 (0)