diff --git a/gax-java/gax-grpc/pom.xml b/gax-java/gax-grpc/pom.xml
index b25e7088149..1bdca58764f 100644
--- a/gax-java/gax-grpc/pom.xml
+++ b/gax-java/gax-grpc/pom.xml
@@ -128,6 +128,16 @@
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ --add-opens java.base/java.util=ALL-UNNAMED
+ --add-opens java.base/java.lang=ALL-UNNAMED
+
+
+
\ No newline at end of file
diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java
index e30a4620c74..cd3eed190a8 100644
--- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java
+++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java
@@ -776,13 +776,6 @@ public Builder setAttemptDirectPathXds() {
return this;
}
- /** Used by tests to configure the `DIRECT_PATH_ENV_DISABLE_DIRECT_PATH` Env Var */
- @VisibleForTesting
- Builder setEnvProvider(EnvironmentProvider envProvider) {
- this.envProvider = envProvider;
- return this;
- }
-
@VisibleForTesting
Builder setSystemProductName(String systemProductName) {
this.systemProductName = systemProductName;
diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java
index ec994c2d00a..0daddd66294 100644
--- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java
+++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java
@@ -40,7 +40,6 @@
import com.google.api.gax.rpc.HeaderProvider;
import com.google.api.gax.rpc.TransportChannel;
import com.google.api.gax.rpc.TransportChannelProvider;
-import com.google.api.gax.rpc.internal.EnvironmentProvider;
import com.google.api.gax.rpc.mtls.AbstractMtlsTransportChannelTest;
import com.google.api.gax.rpc.mtls.MtlsProvider;
import com.google.auth.Credentials;
@@ -71,6 +70,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junitpioneer.jupiter.SetEnvironmentVariable;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.threeten.bp.Duration;
@@ -78,7 +78,6 @@
class InstantiatingGrpcChannelProviderTest extends AbstractMtlsTransportChannelTest {
private static final String DEFAULT_ENDPOINT = "test.googleapis.com:443";
private static String originalOSName;
- private EnvironmentProvider envProvider;
private ComputeEngineCredentials computeEngineCredentials;
@BeforeAll
@@ -89,12 +88,6 @@ public static void setupClass() {
@BeforeEach
public void setup() throws IOException {
System.setProperty("os.name", "Linux");
- // These mocks are the default mocks used to enable DirectPath
- envProvider = Mockito.mock(EnvironmentProvider.class);
- Mockito.when(
- envProvider.getenv(
- InstantiatingGrpcChannelProvider.DIRECT_PATH_ENV_DISABLE_DIRECT_PATH))
- .thenReturn("false");
computeEngineCredentials = Mockito.mock(ComputeEngineCredentials.class);
}
@@ -668,7 +661,6 @@ void testLogDirectPathMisconfigNotOnGCE() throws Exception {
public void canUseDirectPath_happyPath() {
InstantiatingGrpcChannelProvider provider =
InstantiatingGrpcChannelProvider.newBuilder()
- .setEnvProvider(envProvider)
.setAttemptDirectPath(true)
.setCredentials(computeEngineCredentials)
.setEndpoint(DEFAULT_ENDPOINT)
@@ -678,15 +670,12 @@ public void canUseDirectPath_happyPath() {
}
@Test
+ @SetEnvironmentVariable(
+ key = InstantiatingGrpcChannelProvider.DIRECT_PATH_ENV_DISABLE_DIRECT_PATH,
+ value = "true")
public void canUseDirectPath_directPathEnvVarDisabled() {
- EnvironmentProvider envProvider = Mockito.mock(EnvironmentProvider.class);
- Mockito.when(
- envProvider.getenv(
- InstantiatingGrpcChannelProvider.DIRECT_PATH_ENV_DISABLE_DIRECT_PATH))
- .thenReturn("true");
InstantiatingGrpcChannelProvider provider =
InstantiatingGrpcChannelProvider.newBuilder()
- .setEnvProvider(envProvider)
.setAttemptDirectPath(true)
.setCredentials(computeEngineCredentials)
.setEndpoint(DEFAULT_ENDPOINT)
@@ -697,15 +686,8 @@ public void canUseDirectPath_directPathEnvVarDisabled() {
@Test
public void canUseDirectPath_directPathEnvVarNotSet_attemptDirectPathIsTrue() {
- EnvironmentProvider envProvider = Mockito.mock(EnvironmentProvider.class);
- // If system property is not set, then System.getProperty() returns null
- Mockito.when(
- envProvider.getenv(
- InstantiatingGrpcChannelProvider.DIRECT_PATH_ENV_DISABLE_DIRECT_PATH))
- .thenReturn(null);
InstantiatingGrpcChannelProvider provider =
InstantiatingGrpcChannelProvider.newBuilder()
- .setEnvProvider(envProvider)
.setAttemptDirectPath(true)
.setCredentials(computeEngineCredentials)
.setEndpoint(DEFAULT_ENDPOINT)
@@ -716,14 +698,8 @@ public void canUseDirectPath_directPathEnvVarNotSet_attemptDirectPathIsTrue() {
@Test
public void canUseDirectPath_directPathEnvVarNotSet_attemptDirectPathIsFalse() {
- EnvironmentProvider envProvider = Mockito.mock(EnvironmentProvider.class);
- Mockito.when(
- envProvider.getenv(
- InstantiatingGrpcChannelProvider.DIRECT_PATH_ENV_DISABLE_DIRECT_PATH))
- .thenReturn(null);
InstantiatingGrpcChannelProvider provider =
InstantiatingGrpcChannelProvider.newBuilder()
- .setEnvProvider(envProvider)
.setAttemptDirectPath(false)
.setCredentials(computeEngineCredentials)
.setEndpoint(DEFAULT_ENDPOINT)
@@ -733,11 +709,13 @@ public void canUseDirectPath_directPathEnvVarNotSet_attemptDirectPathIsFalse() {
}
@Test
+ @SetEnvironmentVariable(
+ key = InstantiatingGrpcChannelProvider.DIRECT_PATH_ENV_DISABLE_DIRECT_PATH,
+ value = "false")
public void canUseDirectPath_nonComputeCredentials() {
Credentials credentials = Mockito.mock(Credentials.class);
InstantiatingGrpcChannelProvider provider =
InstantiatingGrpcChannelProvider.newBuilder()
- .setEnvProvider(envProvider)
.setAttemptDirectPath(true)
.setCredentials(credentials)
.setEndpoint(DEFAULT_ENDPOINT)
@@ -747,11 +725,13 @@ public void canUseDirectPath_nonComputeCredentials() {
}
@Test
+ @SetEnvironmentVariable(
+ key = InstantiatingGrpcChannelProvider.DIRECT_PATH_ENV_DISABLE_DIRECT_PATH,
+ value = "false")
public void canUseDirectPath_isNotOnComputeEngine_invalidOsNameSystemProperty() {
System.setProperty("os.name", "Not Linux");
InstantiatingGrpcChannelProvider provider =
InstantiatingGrpcChannelProvider.newBuilder()
- .setEnvProvider(envProvider)
.setAttemptDirectPath(true)
.setCredentials(computeEngineCredentials)
.setEndpoint(DEFAULT_ENDPOINT)
@@ -761,10 +741,12 @@ public void canUseDirectPath_isNotOnComputeEngine_invalidOsNameSystemProperty()
}
@Test
+ @SetEnvironmentVariable(
+ key = InstantiatingGrpcChannelProvider.DIRECT_PATH_ENV_DISABLE_DIRECT_PATH,
+ value = "false")
public void canUseDirectPath_isNotOnComputeEngine_invalidSystemProductName() {
InstantiatingGrpcChannelProvider provider =
InstantiatingGrpcChannelProvider.newBuilder()
- .setEnvProvider(envProvider)
.setAttemptDirectPath(true)
.setCredentials(computeEngineCredentials)
.setEndpoint(DEFAULT_ENDPOINT)
@@ -774,10 +756,12 @@ public void canUseDirectPath_isNotOnComputeEngine_invalidSystemProductName() {
}
@Test
+ @SetEnvironmentVariable(
+ key = InstantiatingGrpcChannelProvider.DIRECT_PATH_ENV_DISABLE_DIRECT_PATH,
+ value = "false")
public void canUseDirectPath_isNotOnComputeEngine_unableToGetSystemProductName() {
InstantiatingGrpcChannelProvider provider =
InstantiatingGrpcChannelProvider.newBuilder()
- .setEnvProvider(envProvider)
.setAttemptDirectPath(true)
.setCredentials(computeEngineCredentials)
.setEndpoint(DEFAULT_ENDPOINT)
@@ -787,11 +771,13 @@ public void canUseDirectPath_isNotOnComputeEngine_unableToGetSystemProductName()
}
@Test
+ @SetEnvironmentVariable(
+ key = InstantiatingGrpcChannelProvider.DIRECT_PATH_ENV_DISABLE_DIRECT_PATH,
+ value = "false")
public void canUseDirectPath_nonGDUUniverseDomain() {
String nonGDUEndpoint = "test.random.com:443";
InstantiatingGrpcChannelProvider provider =
InstantiatingGrpcChannelProvider.newBuilder()
- .setEnvProvider(envProvider)
.setAttemptDirectPath(true)
.setCredentials(computeEngineCredentials)
.setEndpoint(nonGDUEndpoint)
diff --git a/gax-java/pom.xml b/gax-java/pom.xml
index 9adaacbbff2..f850f2872bd 100644
--- a/gax-java/pom.xml
+++ b/gax-java/pom.xml
@@ -189,6 +189,12 @@
mockito-junit-jupiter
test
+
+ org.junit-pioneer
+ junit-pioneer
+ 2.2.0
+ test
+
com.google.truth
truth