Skip to content

Commit 3ba43c3

Browse files
authored
Revert "chore: add junit5 extension to setup environment variable" (#2817)
Reverts #2799 since `junit-pioneer` is not compatible with Java 8.
1 parent 9f3a6f2 commit 3ba43c3

File tree

8 files changed

+81
-27
lines changed

8 files changed

+81
-27
lines changed

.github/workflows/ci.yaml

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ jobs:
2222
run: |
2323
mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \
2424
-Dfmt.skip -DenableTestCoverage
25+
# The `envVarTest` profile runs tests that require an environment variable
26+
- name: Env Var Tests
27+
run: |
28+
mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \
29+
-Dfmt.skip -DenableTestCoverage -PenvVarTest
30+
# Set the Env Var for this step only
31+
env:
32+
GOOGLE_CLOUD_UNIVERSE_DOMAIN: random.com
2533
- run: bazelisk version
2634
- name: Install Maven modules
2735
run: |
@@ -63,7 +71,15 @@ jobs:
6371
- name: Unit Tests
6472
run: |
6573
mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \
66-
74+
-Dfmt.skip -DenableTestCoverage
75+
# The `envVarTest` profile runs tests that require an environment variable
76+
- name: Env Var Tests
77+
run: |
78+
mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \
79+
-Dfmt.skip -DenableTestCoverage -PenvVarTest
80+
# Set the Env Var for this step only
81+
env:
82+
GOOGLE_CLOUD_UNIVERSE_DOMAIN: random.com
6783
- run: bazelisk version
6884
- name: Install Maven modules
6985
run: |
@@ -95,14 +111,25 @@ jobs:
95111
export PATH=${JAVA_HOME}/bin:$PATH
96112
# Maven surefire plugin lets us to specify the JVM when running tests via
97113
# the "jvm" system property.
98-
mvn org.apache.maven.plugins:maven-surefire-plugin:test \
99-
verify \
100-
--batch-mode \
101-
--no-transfer-progress \
102-
-Dcheckstyle.skip \
114+
mvn verify --batch-mode --no-transfer-progress -Dcheckstyle.skip \
103115
-Dfmt.skip \
104-
-Djvm="${JAVA8_HOME}/bin/java" \
105-
-DargLine="-Djava.util.logging.SimpleFormatter.format='%1$tY %1$tl:%1$tM:%1$tS.%1$tL %2$s %4$s: %5$s%6$s%n'"
116+
-Djvm="${JAVA8_HOME}/bin/java"
117+
# The `envVarTest` profile runs tests that require an environment variable
118+
- name: Compile with Java 17 and run tests with Java 8 (Env Var Tests)
119+
shell: bash
120+
run: |
121+
set -x
122+
export JAVA_HOME=$JAVA_HOME
123+
export PATH=${JAVA_HOME}/bin:$PATH
124+
# Maven surefire plugin lets us to specify the JVM when running tests via
125+
# the "jvm" system property.
126+
export GOOGLE_CLOUD_UNIVERSE_DOMAIN=random.com
127+
mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \
128+
-Dfmt.skip -DenableTestCoverage -Dsurefire.failIfNoSpecifiedTests=false \
129+
-PenvVarTest
130+
# Set the Env Var for this step only
131+
env:
132+
GOOGLE_CLOUD_UNIVERSE_DOMAIN: random.com
106133

107134
build-java8-gapic-generator-java:
108135
name: "build(8) for gapic-generator-java"

.github/workflows/sonar.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ jobs:
4747
tar -xf showcase-*
4848
./gapic-showcase run &
4949
cd -
50+
# Intentionally do not run the Env Var Tests (no -PenvVarTests) as setting the Env Var
51+
# may alter the results for other tests that use Env Var in the logic. Adding a Sonar
52+
# step for a few tests (env var tests) may be overkill and should be better covered
53+
# when we can upgrade to JUnit 5 (https://github.com/googleapis/sdk-platform-java/issues/1611#issuecomment-1970079325)
5054
- name: Build and analyze for full test coverage
5155
env:
5256
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any

gapic-generator-java-pom-parent/pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,23 @@
182182
</plugins>
183183
</build>
184184
</profile>
185+
<profile>
186+
<id>envVarTest</id>
187+
<build>
188+
<plugins>
189+
<plugin>
190+
<groupId>org.apache.maven.plugins</groupId>
191+
<artifactId>maven-surefire-plugin</artifactId>
192+
<configuration>
193+
<!-- Unless overriden in the submodules, this profile run no tests in a submodule -->
194+
<excludes>
195+
<exclude>**/*.java</exclude>
196+
</excludes>
197+
</configuration>
198+
</plugin>
199+
</plugins>
200+
</build>
201+
</profile>
185202
</profiles>
186203
<repositories>
187204
<repository>

gax-java/dependencies.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,3 @@ maven.net_bytebuddy_byte_buddy=net.bytebuddy:byte-buddy:1.14.16
8888
maven.org_objenesis_objenesis=org.objenesis:objenesis:2.6
8989
maven.org_junit_jupiter_junit_jupiter_api=org.junit.jupiter:junit-jupiter-api:5.10.2
9090
maven.org_junit_jupiter_junit_jupiter_params=org.junit.jupiter:junit-jupiter-params:5.10.2
91-
maven.org_junit_pioneer_junit_pioneer=org.junit-pioneer:junit-pioneer:2.2.0

gax-java/gax/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ _TEST_COMPILE_DEPS = [
4141
"@net_bytebuddy_byte_buddy//jar",
4242
"@org_objenesis_objenesis//jar",
4343
"@com_googlecode_java_diff_utils_diffutils//jar",
44-
"@org_junit_pioneer_junit_pioneer//jar",
4544
]
4645

4746
java_library(

gax-java/gax/pom.xml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,32 @@
9999
</configuration>
100100
</plugin>
101101
<plugin>
102+
<!-- Troubleshooting a flaky test in https://github.com/googleapis/sdk-platform-java/issues/1931 -->
102103
<groupId>org.apache.maven.plugins</groupId>
103104
<artifactId>maven-surefire-plugin</artifactId>
104105
<configuration>
105-
<argLine>
106-
-Djava.util.logging.SimpleFormatter.format="%1$tY %1$tl:%1$tM:%1$tS.%1$tL %2$s %4$s: %5$s%6$s%n"
107-
<!-- workaround setup for using junit-pioneer with Java 17 or above,
108-
see https://junit-pioneer.org/docs/environment-variables/#warnings-for-reflective-access -->
109-
--add-opens java.base/java.util=ALL-UNNAMED
110-
--add-opens java.base/java.lang=ALL-UNNAMED
111-
</argLine>
106+
<argLine>-Djava.util.logging.SimpleFormatter.format="%1$tY %1$tl:%1$tM:%1$tS.%1$tL %2$s %4$s: %5$s%6$s%n"</argLine>
107+
<!-- These tests require an Env Var to be set. Use -PenvVarTest to ONLY run these tests -->
108+
<test>!EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet+endpointContextBuild_multipleUniverseDomainConfigurations_clientSettingsHasPriority</test>
112109
</configuration>
113110
</plugin>
114111
</plugins>
115112
</build>
116-
</project>
113+
114+
<profiles>
115+
<profile>
116+
<id>envVarTest</id>
117+
<build>
118+
<plugins>
119+
<plugin>
120+
<groupId>org.apache.maven.plugins</groupId>
121+
<artifactId>maven-surefire-plugin</artifactId>
122+
<configuration>
123+
<test>EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet+endpointContextBuild_multipleUniverseDomainConfigurations_clientSettingsHasPriority</test>
124+
</configuration>
125+
</plugin>
126+
</plugins>
127+
</build>
128+
</profile>
129+
</profiles>
130+
</project>

gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import java.io.IOException;
4141
import org.junit.jupiter.api.BeforeEach;
4242
import org.junit.jupiter.api.Test;
43-
import org.junitpioneer.jupiter.SetEnvironmentVariable;
4443
import org.mockito.Mockito;
4544

4645
class EndpointContextTest {
@@ -338,8 +337,8 @@ void endpointContextBuild_gdchFlow_noUniverseDomain_customEndpoint() throws IOEx
338337

339338
// This Universe Domain should match the `GOOGLE_CLOUD_UNIVERSE_DOMAIN` Env Var
340339
// For this test running locally or in CI, check that the Env Var is set properly.
340+
// This test should only run when the maven profile `EnvVarTest` is enabled.
341341
@Test
342-
@SetEnvironmentVariable(key = EndpointContext.GOOGLE_CLOUD_UNIVERSE_DOMAIN, value = "random.com")
343342
void endpointContextBuild_universeDomainEnvVarSet() throws IOException {
344343
String envVarUniverseDomain = "random.com";
345344
EndpointContext endpointContext =
@@ -353,10 +352,11 @@ void endpointContextBuild_universeDomainEnvVarSet() throws IOException {
353352

354353
// This Universe Domain should match the `GOOGLE_CLOUD_UNIVERSE_DOMAIN` Env Var
355354
// For this test running locally or in CI, check that the Env Var is set properly.
355+
// This test should only run when the maven profile `EnvVarTest` is enabled.
356356
@Test
357-
@SetEnvironmentVariable(key = EndpointContext.GOOGLE_CLOUD_UNIVERSE_DOMAIN, value = "random.com")
358357
void endpointContextBuild_multipleUniverseDomainConfigurations_clientSettingsHasPriority()
359358
throws IOException {
359+
// This test has `GOOGLE_CLOUD_UNIVERSE_DOMAIN` = `random.com`
360360
String clientSettingsUniverseDomain = "clientSettingsUniverseDomain.com";
361361
EndpointContext endpointContext =
362362
defaultEndpointContextBuilder

gax-java/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,6 @@
205205
</exclusions>
206206
<scope>test</scope>
207207
</dependency>
208-
<dependency>
209-
<groupId>org.junit-pioneer</groupId>
210-
<artifactId>junit-pioneer</artifactId>
211-
<version>2.2.0</version>
212-
<scope>test</scope>
213-
</dependency>
214208
</dependencies>
215209

216210
<build>

0 commit comments

Comments
 (0)