From 0f7e7a3b18e58f859492968796cbc627f2ad2faf Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 28 Feb 2024 22:04:41 -0500 Subject: [PATCH 01/12] feat: Universe Domain Environment Variable Support --- .github/workflows/ci.yaml | 28 +++++++++++++++++-- .../google/api/gax/rpc/EndpointContext.java | 9 +++++- .../api/gax/rpc/EndpointContextTest.java | 12 ++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5344f99886..9e870836eb 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,7 +21,15 @@ jobs: - name: Unit Tests run: | mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \ - -Dfmt.skip -DenableTestCoverage + -Dfmt.skip -DenableTestCoverage -Dsurefire.failIfNoSpecifiedTests=false \ + -Dtest=\!EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet + - run: echo "GOOGLE_CLOUD_UNIVERSE_DOMAIN=random.com" >> $GITHUB_ENV + - name: EndpointContext Env Var Test + run: | + mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \ + -Dfmt.skip -DenableTestCoverage -Dsurefire.failIfNoSpecifiedTests=false \ + -Dtest=EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet + - run: echo "GOOGLE_CLOUD_UNIVERSE_DOMAIN=" >> $GITHUB_ENV - run: bazelisk version - name: Install Maven modules run: | @@ -63,7 +71,15 @@ jobs: - name: Unit Tests run: | mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \ - -Dfmt.skip -DenableTestCoverage + -Dfmt.skip -DenableTestCoverage -Dsurefire.failIfNoSpecifiedTests=false \ + -Dtest=\!EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet + - run: echo "GOOGLE_CLOUD_UNIVERSE_DOMAIN=random.com" >> $GITHUB_ENV + - name: EndpointContext Env Var Test + run: | + mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \ + -Dfmt.skip -DenableTestCoverage -Dsurefire.failIfNoSpecifiedTests=false \ + -Dtest=EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet + - run: echo "GOOGLE_CLOUD_UNIVERSE_DOMAIN=" >> $GITHUB_ENV - run: bazelisk version - name: Install Maven modules run: | @@ -97,7 +113,13 @@ jobs: # the "jvm" system property. mvn verify --batch-mode --no-transfer-progress -Dcheckstyle.skip \ -Dfmt.skip \ - -Djvm="${JAVA8_HOME}/bin/java" + -Djvm="${JAVA8_HOME}/bin/java" -Dsurefire.failIfNoSpecifiedTests=false \ + -Dtest=\!EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet + export GOOGLE_CLOUD_UNIVERSE_DOMAIN=random.com + mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \ + -Dfmt.skip -DenableTestCoverage -Dsurefire.failIfNoSpecifiedTests=false \ + -Dtest=EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet + - run: echo "GOOGLE_CLOUD_UNIVERSE_DOMAIN=" >> $GITHUB_ENV build-java8-gapic-generator-java: name: "build(8) for gapic-generator-java" diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/EndpointContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/EndpointContext.java index b33a97cd0a..0c1815c5fa 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/EndpointContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/EndpointContext.java @@ -47,6 +47,7 @@ @InternalApi @AutoValue public abstract class EndpointContext { + private static final String GOOGLE_CLOUD_UNIVERSE_DOMAIN = "GOOGLE_CLOUD_UNIVERSE_DOMAIN"; private static final String INVALID_UNIVERSE_DOMAIN_ERROR_TEMPLATE = "The configured universe domain (%s) does not match the universe domain found in the credentials (%s). If you haven't configured the universe domain explicitly, `googleapis.com` is the default."; public static final String UNABLE_TO_RETRIEVE_CREDENTIALS_ERROR_MESSAGE = @@ -213,7 +214,8 @@ private String determineUniverseDomain() { if (universeDomain() != null && universeDomain().isEmpty()) { throw new IllegalArgumentException("The universe domain value cannot be empty."); } - // Override with user set universe domain if provided + // If the universe domain is configured by the user, the universe domain will either be + // from the settings or from the env var. The value from ClientSettings has priority. return universeDomain() != null ? universeDomain() : Credentials.GOOGLE_DEFAULT_UNIVERSE; } @@ -283,6 +285,11 @@ String mtlsEndpointResolver( } public EndpointContext build() throws IOException { + // If the universe domain wasn't configured explicitly in the settings, check the + // environment variable for the value + if (universeDomain() == null) { + setUniverseDomain(System.getenv(GOOGLE_CLOUD_UNIVERSE_DOMAIN)); + } // The Universe Domain is used to resolve the Endpoint. It should be resolved first setResolvedUniverseDomain(determineUniverseDomain()); setResolvedEndpoint(determineEndpoint()); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java index f0dbae60f2..2422e9cc8e 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java @@ -340,6 +340,18 @@ public void endpointContextBuild_gdchFlow_noUniverseDomain_customEndpoint() thro .isEqualTo(Credentials.GOOGLE_DEFAULT_UNIVERSE); } + @Test + public void endpointContextBuild_universeDomainEnvVarSet() throws IOException { + String envVarUniverseDomain = "random.com"; + EndpointContext endpointContext = + defaultEndpointContextBuilder + .setUniverseDomain(null) + .setClientSettingsEndpoint(null) + .build(); + Truth.assertThat(endpointContext.resolvedEndpoint()).isEqualTo("test.random.com:443"); + Truth.assertThat(endpointContext.resolvedUniverseDomain()).isEqualTo(envVarUniverseDomain); + } + @Test public void hasValidUniverseDomain_gdchFlow_anyCredentials() throws IOException { Credentials noCredentials = NoCredentialsProvider.create().getCredentials(); From c61320d7d1151bab40ac20baf7fab2156c6ba948 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 28 Feb 2024 22:26:11 -0500 Subject: [PATCH 02/12] chore: Set Env Var for a single step --- .github/workflows/ci.yaml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9e870836eb..a6c97ee413 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -23,13 +23,13 @@ jobs: mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \ -Dfmt.skip -DenableTestCoverage -Dsurefire.failIfNoSpecifiedTests=false \ -Dtest=\!EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet - - run: echo "GOOGLE_CLOUD_UNIVERSE_DOMAIN=random.com" >> $GITHUB_ENV - name: EndpointContext Env Var Test run: | mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \ -Dfmt.skip -DenableTestCoverage -Dsurefire.failIfNoSpecifiedTests=false \ -Dtest=EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet - - run: echo "GOOGLE_CLOUD_UNIVERSE_DOMAIN=" >> $GITHUB_ENV + env: + GOOGLE_CLOUD_UNIVERSE_DOMAIN: random.com - run: bazelisk version - name: Install Maven modules run: | @@ -73,13 +73,13 @@ jobs: mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \ -Dfmt.skip -DenableTestCoverage -Dsurefire.failIfNoSpecifiedTests=false \ -Dtest=\!EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet - - run: echo "GOOGLE_CLOUD_UNIVERSE_DOMAIN=random.com" >> $GITHUB_ENV - name: EndpointContext Env Var Test run: | mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \ -Dfmt.skip -DenableTestCoverage -Dsurefire.failIfNoSpecifiedTests=false \ -Dtest=EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet - - run: echo "GOOGLE_CLOUD_UNIVERSE_DOMAIN=" >> $GITHUB_ENV + env: + GOOGLE_CLOUD_UNIVERSE_DOMAIN: random.com - run: bazelisk version - name: Install Maven modules run: | @@ -115,11 +115,20 @@ jobs: -Dfmt.skip \ -Djvm="${JAVA8_HOME}/bin/java" -Dsurefire.failIfNoSpecifiedTests=false \ -Dtest=\!EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet + - name: Compile with Java 17 and run tests with Java 8 (Universe Domain Env Var) + shell: bash + run: | + set -x + export JAVA_HOME=$JAVA_HOME + export PATH=${JAVA_HOME}/bin:$PATH + # Maven surefire plugin lets us to specify the JVM when running tests via + # the "jvm" system property. export GOOGLE_CLOUD_UNIVERSE_DOMAIN=random.com mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \ -Dfmt.skip -DenableTestCoverage -Dsurefire.failIfNoSpecifiedTests=false \ -Dtest=EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet - - run: echo "GOOGLE_CLOUD_UNIVERSE_DOMAIN=" >> $GITHUB_ENV + env: + GOOGLE_CLOUD_UNIVERSE_DOMAIN: random.com build-java8-gapic-generator-java: name: "build(8) for gapic-generator-java" From b5aa5c0adaf91a8c15ebd4f35d6ea9e58d8bab91 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Thu, 29 Feb 2024 10:17:39 -0500 Subject: [PATCH 03/12] chore: Update sonar workflow --- .github/workflows/ci.yaml | 9 +++++++++ .github/workflows/sonar.yaml | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a6c97ee413..c06bdf9ac7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,11 +18,14 @@ jobs: distribution: temurin cache: maven - run: java -version + # Run the tests except for `EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet` + # This test requires an Environmental Variable to pass - name: Unit Tests run: | mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \ -Dfmt.skip -DenableTestCoverage -Dsurefire.failIfNoSpecifiedTests=false \ -Dtest=\!EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet + # Only run the `EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet` test - name: EndpointContext Env Var Test run: | mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \ @@ -68,11 +71,14 @@ jobs: distribution: temurin cache: maven - run: java -version + # Run the tests except for `EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet` + # This test requires an Environmental Variable to pass - name: Unit Tests run: | mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \ -Dfmt.skip -DenableTestCoverage -Dsurefire.failIfNoSpecifiedTests=false \ -Dtest=\!EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet + # Only run the `EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet` test - name: EndpointContext Env Var Test run: | mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \ @@ -103,6 +109,8 @@ jobs: with: java-version: 17 distribution: temurin + # Run the tests except for `EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet` + # This test requires an Environmental Variable to pass - name: Compile with Java 17 and run tests with Java 8 shell: bash run: | @@ -115,6 +123,7 @@ jobs: -Dfmt.skip \ -Djvm="${JAVA8_HOME}/bin/java" -Dsurefire.failIfNoSpecifiedTests=false \ -Dtest=\!EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet + # Only run the `EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet` test - name: Compile with Java 17 and run tests with Java 8 (Universe Domain Env Var) shell: bash run: | diff --git a/.github/workflows/sonar.yaml b/.github/workflows/sonar.yaml index 013ff88b36..218c8fb9dd 100644 --- a/.github/workflows/sonar.yaml +++ b/.github/workflows/sonar.yaml @@ -47,6 +47,8 @@ jobs: tar -xf showcase-* ./gapic-showcase run & cd - + # Run the tests except for `EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet` + # This test requires an Environmental Variable to pass. This test is covered in the ci.yaml workflow - name: Build and analyze for full test coverage env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any @@ -58,8 +60,8 @@ jobs: org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \ -Dsonar.projectKey=googleapis_gapic-generator-java \ -Dsonar.organization=googleapis \ - -Dsonar.host.url=https://sonarcloud.io - + -Dsonar.host.url=https://sonarcloud.io \ + -Dtest=\!EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet - name: Build and analyze Showcase Integration Tests Coverage env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any From 41165ec051e3ddfc630aa4d1baf413903d0ec682 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Thu, 29 Feb 2024 10:28:50 -0500 Subject: [PATCH 04/12] chore: Do not fail if test is not found in a different module --- .github/workflows/sonar.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/sonar.yaml b/.github/workflows/sonar.yaml index 218c8fb9dd..5f3fd8f26b 100644 --- a/.github/workflows/sonar.yaml +++ b/.github/workflows/sonar.yaml @@ -61,6 +61,7 @@ jobs: -Dsonar.projectKey=googleapis_gapic-generator-java \ -Dsonar.organization=googleapis \ -Dsonar.host.url=https://sonarcloud.io \ + -Dsurefire.failIfNoSpecifiedTests=false \ -Dtest=\!EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet - name: Build and analyze Showcase Integration Tests Coverage env: From fb6c183188ab6d49e7bcf52e522592778f2ecdda Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Thu, 29 Feb 2024 11:14:24 -0500 Subject: [PATCH 05/12] chore: Create envVarTest maven profile --- .github/workflows/ci.yaml | 36 ++++++++----------- .github/workflows/sonar.yaml | 7 ++-- gax-java/gax/pom.xml | 19 ++++++++++ .../api/gax/rpc/EndpointContextTest.java | 3 ++ 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c06bdf9ac7..f3b587b072 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -23,14 +23,13 @@ jobs: - name: Unit Tests run: | mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \ - -Dfmt.skip -DenableTestCoverage -Dsurefire.failIfNoSpecifiedTests=false \ - -Dtest=\!EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet - # Only run the `EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet` test - - name: EndpointContext Env Var Test + -Dfmt.skip -DenableTestCoverage + # The `envVarTest` profile runs tests that require an environment variable + - name: Env Var Tests run: | mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \ - -Dfmt.skip -DenableTestCoverage -Dsurefire.failIfNoSpecifiedTests=false \ - -Dtest=EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet + -Dfmt.skip -DenableTestCoverage -PenvVarTest + # Set the Env Var for this step only env: GOOGLE_CLOUD_UNIVERSE_DOMAIN: random.com - run: bazelisk version @@ -71,19 +70,16 @@ jobs: distribution: temurin cache: maven - run: java -version - # Run the tests except for `EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet` - # This test requires an Environmental Variable to pass - name: Unit Tests run: | mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \ - -Dfmt.skip -DenableTestCoverage -Dsurefire.failIfNoSpecifiedTests=false \ - -Dtest=\!EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet - # Only run the `EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet` test - - name: EndpointContext Env Var Test + -Dfmt.skip -DenableTestCoverage + # The `envVarTest` profile runs tests that require an environment variable + - name: Env Var Tests run: | mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \ - -Dfmt.skip -DenableTestCoverage -Dsurefire.failIfNoSpecifiedTests=false \ - -Dtest=EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet + -Dfmt.skip -DenableTestCoverage -PenvVarTest + # Set the Env Var for this step only env: GOOGLE_CLOUD_UNIVERSE_DOMAIN: random.com - run: bazelisk version @@ -109,8 +105,6 @@ jobs: with: java-version: 17 distribution: temurin - # Run the tests except for `EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet` - # This test requires an Environmental Variable to pass - name: Compile with Java 17 and run tests with Java 8 shell: bash run: | @@ -121,10 +115,9 @@ jobs: # the "jvm" system property. mvn verify --batch-mode --no-transfer-progress -Dcheckstyle.skip \ -Dfmt.skip \ - -Djvm="${JAVA8_HOME}/bin/java" -Dsurefire.failIfNoSpecifiedTests=false \ - -Dtest=\!EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet - # Only run the `EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet` test - - name: Compile with Java 17 and run tests with Java 8 (Universe Domain Env Var) + -Djvm="${JAVA8_HOME}/bin/java" + # The `envVarTest` profile runs tests that require an environment variable + - name: Compile with Java 17 and run tests with Java 8 (Env Var Tests) shell: bash run: | set -x @@ -135,7 +128,8 @@ jobs: export GOOGLE_CLOUD_UNIVERSE_DOMAIN=random.com mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \ -Dfmt.skip -DenableTestCoverage -Dsurefire.failIfNoSpecifiedTests=false \ - -Dtest=EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet + -PenvVarTest + # Set the Env Var for this step only env: GOOGLE_CLOUD_UNIVERSE_DOMAIN: random.com diff --git a/.github/workflows/sonar.yaml b/.github/workflows/sonar.yaml index 5f3fd8f26b..bb9e8a1fd5 100644 --- a/.github/workflows/sonar.yaml +++ b/.github/workflows/sonar.yaml @@ -47,12 +47,12 @@ jobs: tar -xf showcase-* ./gapic-showcase run & cd - - # Run the tests except for `EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet` - # This test requires an Environmental Variable to pass. This test is covered in the ci.yaml workflow - name: Build and analyze for full test coverage + # Set the Env Vars needed for the test to get coverage on Env Var Tests env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + GOOGLE_CLOUD_UNIVERSE_DOMAIN: random.com run: | mvn -B verify -Dcheckstyle.skip \ -DenableFullTestCoverage \ @@ -61,8 +61,7 @@ jobs: -Dsonar.projectKey=googleapis_gapic-generator-java \ -Dsonar.organization=googleapis \ -Dsonar.host.url=https://sonarcloud.io \ - -Dsurefire.failIfNoSpecifiedTests=false \ - -Dtest=\!EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet + -PenvVarTest - name: Build and analyze Showcase Integration Tests Coverage env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any diff --git a/gax-java/gax/pom.xml b/gax-java/gax/pom.xml index 57fb6f5799..4ddb4081b5 100644 --- a/gax-java/gax/pom.xml +++ b/gax-java/gax/pom.xml @@ -99,8 +99,27 @@ maven-surefire-plugin -Djava.util.logging.SimpleFormatter.format="%1$tY %1$tl:%1$tM:%1$tS.%1$tL %2$s %4$s: %5$s%6$s%n" + + !EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet + + + + envVarTest + + + + org.apache.maven.plugins + maven-surefire-plugin + + EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet + + + + + + \ No newline at end of file diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java index 2422e9cc8e..36a120aca6 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java @@ -340,6 +340,9 @@ public void endpointContextBuild_gdchFlow_noUniverseDomain_customEndpoint() thro .isEqualTo(Credentials.GOOGLE_DEFAULT_UNIVERSE); } + // This Universe Domain should match the `GOOGLE_CLOUD_UNIVERSE_DOMAIN` Env Var + // For this test running locally or in CI, check that the Env Var is set properly. + // This test should only run when the maven profile `EnvVarTest` is enabled. @Test public void endpointContextBuild_universeDomainEnvVarSet() throws IOException { String envVarUniverseDomain = "random.com"; From 1e376f177b307d976e2eb3d9b9ed3476de207ee7 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Thu, 29 Feb 2024 11:16:29 -0500 Subject: [PATCH 06/12] chore: Remove extra comment in ci.yaml --- .github/workflows/ci.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f3b587b072..1de5e7d9bb 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,8 +18,6 @@ jobs: distribution: temurin cache: maven - run: java -version - # Run the tests except for `EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet` - # This test requires an Environmental Variable to pass - name: Unit Tests run: | mvn test --batch-mode --no-transfer-progress -Dcheckstyle.skip \ From b214eea2930eae5b096c955f30943f8742fd9790 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Thu, 29 Feb 2024 11:34:19 -0500 Subject: [PATCH 07/12] chore: Ignore all tests by default for every module --- gapic-generator-java-pom-parent/pom.xml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gapic-generator-java-pom-parent/pom.xml b/gapic-generator-java-pom-parent/pom.xml index 59edf449b9..400701ce93 100644 --- a/gapic-generator-java-pom-parent/pom.xml +++ b/gapic-generator-java-pom-parent/pom.xml @@ -177,6 +177,23 @@ + + envVarTest + + + + org.apache.maven.plugins + maven-surefire-plugin + + + + **/*.java + + + + + + From 60c5b356f146a91c642d8eba65745ee79d5834f3 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Thu, 29 Feb 2024 11:44:41 -0500 Subject: [PATCH 08/12] chore: Do not test Env Var tests for sonar coverage --- .github/workflows/sonar.yaml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/sonar.yaml b/.github/workflows/sonar.yaml index bb9e8a1fd5..585893942e 100644 --- a/.github/workflows/sonar.yaml +++ b/.github/workflows/sonar.yaml @@ -47,12 +47,14 @@ jobs: tar -xf showcase-* ./gapic-showcase run & cd - + # Intentionally do not run the Env Var Tests (no -PenvVarTests) as setting the Env Var + # may alter the results for other tests that use Env Var in the logic. Adding a Sonar + # step for a few tests (env var tests) may be overkill and should be better covered + # when we can upgrade to JUnit 5 (https://github.com/googleapis/sdk-platform-java/issues/1611#issuecomment-1970079325) - name: Build and analyze for full test coverage - # Set the Env Vars needed for the test to get coverage on Env Var Tests env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - GOOGLE_CLOUD_UNIVERSE_DOMAIN: random.com run: | mvn -B verify -Dcheckstyle.skip \ -DenableFullTestCoverage \ @@ -60,8 +62,7 @@ jobs: org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \ -Dsonar.projectKey=googleapis_gapic-generator-java \ -Dsonar.organization=googleapis \ - -Dsonar.host.url=https://sonarcloud.io \ - -PenvVarTest + -Dsonar.host.url=https://sonarcloud.io - name: Build and analyze Showcase Integration Tests Coverage env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any From eecca910292326ade7449daa3326c49486d3b86b Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Thu, 29 Feb 2024 12:58:47 -0500 Subject: [PATCH 09/12] chore: Update docs for envVarTest profile --- gapic-generator-java-pom-parent/pom.xml | 2 +- gax-java/gax/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gapic-generator-java-pom-parent/pom.xml b/gapic-generator-java-pom-parent/pom.xml index 400701ce93..d359072cc4 100644 --- a/gapic-generator-java-pom-parent/pom.xml +++ b/gapic-generator-java-pom-parent/pom.xml @@ -185,7 +185,7 @@ org.apache.maven.plugins maven-surefire-plugin - + **/*.java diff --git a/gax-java/gax/pom.xml b/gax-java/gax/pom.xml index 4ddb4081b5..b8cd924b85 100644 --- a/gax-java/gax/pom.xml +++ b/gax-java/gax/pom.xml @@ -99,7 +99,7 @@ maven-surefire-plugin -Djava.util.logging.SimpleFormatter.format="%1$tY %1$tl:%1$tM:%1$tS.%1$tL %2$s %4$s: %5$s%6$s%n" - + !EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet From 112e790afc6300878bffd9b9c4561f40a7161e2d Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Thu, 29 Feb 2024 16:21:05 -0500 Subject: [PATCH 10/12] chore: Address PR comments --- gax-java/gax/pom.xml | 4 +++- .../com/google/api/gax/rpc/EndpointContext.java | 17 +++++++++-------- .../google/api/gax/rpc/EndpointContextTest.java | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/gax-java/gax/pom.xml b/gax-java/gax/pom.xml index 29114e5c29..5c8350e983 100644 --- a/gax-java/gax/pom.xml +++ b/gax-java/gax/pom.xml @@ -99,8 +99,9 @@ maven-surefire-plugin -Djava.util.logging.SimpleFormatter.format="%1$tY %1$tl:%1$tM:%1$tS.%1$tL %2$s %4$s: %5$s%6$s%n" - + !EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet + !EndpointContextTest#endpointContextBuild_multipleUniverseDomainConfigurations_clientSettingsHasPriority @@ -116,6 +117,7 @@ maven-surefire-plugin EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet + EndpointContextTest#endpointContextBuild_multipleUniverseDomainConfigurations_clientSettingsHasPriority diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/EndpointContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/EndpointContext.java index 0c1815c5fa..5b1f14fdaf 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/EndpointContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/EndpointContext.java @@ -202,21 +202,27 @@ public abstract static class Builder { abstract EndpointContext autoBuild(); private String determineUniverseDomain() { + String universeDomain = universeDomain(); if (usingGDCH()) { // GDC-H has no concept of Universe Domain. User should not set a custom value - if (universeDomain() != null) { + if (universeDomain != null) { throw new IllegalArgumentException( "Universe domain configuration is incompatible with GDC-H"); } return Credentials.GOOGLE_DEFAULT_UNIVERSE; } // Check for "" (empty string) - if (universeDomain() != null && universeDomain().isEmpty()) { + if (universeDomain != null && universeDomain.isEmpty()) { throw new IllegalArgumentException("The universe domain value cannot be empty."); } + // If the universe domain wasn't configured explicitly in the settings, check the + // environment variable for the value + if (universeDomain == null) { + universeDomain = System.getenv(GOOGLE_CLOUD_UNIVERSE_DOMAIN); + } // If the universe domain is configured by the user, the universe domain will either be // from the settings or from the env var. The value from ClientSettings has priority. - return universeDomain() != null ? universeDomain() : Credentials.GOOGLE_DEFAULT_UNIVERSE; + return universeDomain != null ? universeDomain : Credentials.GOOGLE_DEFAULT_UNIVERSE; } /** Determines the fully resolved endpoint and universe domain values */ @@ -285,11 +291,6 @@ String mtlsEndpointResolver( } public EndpointContext build() throws IOException { - // If the universe domain wasn't configured explicitly in the settings, check the - // environment variable for the value - if (universeDomain() == null) { - setUniverseDomain(System.getenv(GOOGLE_CLOUD_UNIVERSE_DOMAIN)); - } // The Universe Domain is used to resolve the Endpoint. It should be resolved first setResolvedUniverseDomain(determineUniverseDomain()); setResolvedEndpoint(determineEndpoint()); diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java index 36a120aca6..f379c754c2 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java @@ -355,6 +355,23 @@ public void endpointContextBuild_universeDomainEnvVarSet() throws IOException { Truth.assertThat(endpointContext.resolvedUniverseDomain()).isEqualTo(envVarUniverseDomain); } + // This Universe Domain should match the `GOOGLE_CLOUD_UNIVERSE_DOMAIN` Env Var + // For this test running locally or in CI, check that the Env Var is set properly. + // This test should only run when the maven profile `EnvVarTest` is enabled. + @Test + public void endpointContextBuild_multipleUniverseDomainConfigurations_clientSettingsHasPriority() + throws IOException { + String envVarUniverseDomain = "envVarUniverseDomain.com"; + EndpointContext endpointContext = + defaultEndpointContextBuilder + .setUniverseDomain(null) + .setClientSettingsEndpoint("clientSettingsUniverseDomain.com") + .build(); + Truth.assertThat(endpointContext.resolvedEndpoint()) + .isEqualTo("test.clientSettingsUniverseDomain.com:443"); + Truth.assertThat(endpointContext.resolvedUniverseDomain()).isEqualTo(envVarUniverseDomain); + } + @Test public void hasValidUniverseDomain_gdchFlow_anyCredentials() throws IOException { Credentials noCredentials = NoCredentialsProvider.create().getCredentials(); From 7d36b39408de71d39727b37932b61bbedb81c86a Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Thu, 29 Feb 2024 16:23:39 -0500 Subject: [PATCH 11/12] chore: Fix test --- .../test/java/com/google/api/gax/rpc/EndpointContextTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java index f379c754c2..7694fe7e0a 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java @@ -364,8 +364,8 @@ public void endpointContextBuild_multipleUniverseDomainConfigurations_clientSett String envVarUniverseDomain = "envVarUniverseDomain.com"; EndpointContext endpointContext = defaultEndpointContextBuilder - .setUniverseDomain(null) - .setClientSettingsEndpoint("clientSettingsUniverseDomain.com") + .setUniverseDomain("clientSettingsUniverseDomain.com") + .setClientSettingsEndpoint(null) .build(); Truth.assertThat(endpointContext.resolvedEndpoint()) .isEqualTo("test.clientSettingsUniverseDomain.com:443"); From 363f0efabd1b8e75ce6802fdbea3ba14cfd70887 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Thu, 29 Feb 2024 16:33:03 -0500 Subject: [PATCH 12/12] chore: Fix test --- gax-java/gax/pom.xml | 6 ++---- .../java/com/google/api/gax/rpc/EndpointContextTest.java | 9 ++++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/gax-java/gax/pom.xml b/gax-java/gax/pom.xml index ebc73c6d48..ff7ca76c2d 100644 --- a/gax-java/gax/pom.xml +++ b/gax-java/gax/pom.xml @@ -100,8 +100,7 @@ -Djava.util.logging.SimpleFormatter.format="%1$tY %1$tl:%1$tM:%1$tS.%1$tL %2$s %4$s: %5$s%6$s%n" - !EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet - !EndpointContextTest#endpointContextBuild_multipleUniverseDomainConfigurations_clientSettingsHasPriority + !EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet+endpointContextBuild_multipleUniverseDomainConfigurations_clientSettingsHasPriority @@ -116,8 +115,7 @@ org.apache.maven.plugins maven-surefire-plugin - EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet - EndpointContextTest#endpointContextBuild_multipleUniverseDomainConfigurations_clientSettingsHasPriority + EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet+endpointContextBuild_multipleUniverseDomainConfigurations_clientSettingsHasPriority diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java index 7694fe7e0a..54b7d0e756 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java @@ -361,15 +361,18 @@ public void endpointContextBuild_universeDomainEnvVarSet() throws IOException { @Test public void endpointContextBuild_multipleUniverseDomainConfigurations_clientSettingsHasPriority() throws IOException { - String envVarUniverseDomain = "envVarUniverseDomain.com"; + // This test has `GOOGLE_CLOUD_UNIVERSE_DOMAIN` = `random.com` + String clientSettingsUniverseDomain = "clientSettingsUniverseDomain.com"; EndpointContext endpointContext = defaultEndpointContextBuilder - .setUniverseDomain("clientSettingsUniverseDomain.com") + .setUniverseDomain(clientSettingsUniverseDomain) .setClientSettingsEndpoint(null) .build(); Truth.assertThat(endpointContext.resolvedEndpoint()) .isEqualTo("test.clientSettingsUniverseDomain.com:443"); - Truth.assertThat(endpointContext.resolvedUniverseDomain()).isEqualTo(envVarUniverseDomain); + // Client Settings Universe Domain (if set) takes priority + Truth.assertThat(endpointContext.resolvedUniverseDomain()) + .isEqualTo(clientSettingsUniverseDomain); } @Test