8000 fix remaining tests to mock endpointContext.resolvedEndpoint(). · rmehta19/sdk-platform-java@4ee2ee9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4ee2ee9

Browse files
committed
fix remaining tests to mock endpointContext.resolvedEndpoint().
1 parent 926faca commit 4ee2ee9

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,22 +377,30 @@ void testDirectPathDisallowNullCredentials() throws IOException {
377377

378378
@Test
379379
void testDirectPathWithGDUEndpoint() {
380+
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
381+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn(DEFAULT_ENDPOINT);
382+
380383
InstantiatingGrpcChannelProvider provider =
381384
InstantiatingGrpcChannelProvider.newBuilder()
382385
.setAttemptDirectPath(true)
383386
.setAttemptDirectPathXds()
384387
.setEndpoint(DEFAULT_ENDPOINT)
388+
.setEndpointContext(endpointContext)
385389
.build();
386390
assertThat(provider.canUseDirectPathWithUniverseDomain()).isTrue();
387391
}
388392

389393
@Test
390394
void testDirectPathWithNonGDUEndpoint() {
395+
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
396+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn("test.random.com:443");
397+
391398
InstantiatingGrpcChannelProvider provider =
392399
InstantiatingGrpcChannelProvider.newBuilder()
393400
.setAttemptDirectPath(true)
394401
.setAttemptDirectPathXds()
395402
.setEndpoint("test.random.com:443")
403+
.setEndpointContext(endpointContext)
396404
.build();
397405
assertThat(provider.canUseDirectPathWithUniverseDomain()).isFalse();
398406
}
@@ -830,11 +838,14 @@ public void canUseDirectPath_directPathEnvVarDisabled() throws IOException {
830838
@Test
831839
public void canUseDirectPath_directPathEnvVarNotSet_attemptDirectPathIsTrue() {
832840
System.setProperty("os.name", "Linux");
841+
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
842+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn(DEFAULT_ENDPOINT);
833843
InstantiatingGrpcChannelProvider.Builder builder =
834844
InstantiatingGrpcChannelProvider.newBuilder()
835845
.setAttemptDirectPath(true)
836846
.setCredentials(computeEngineCredentials)
837-
.setEndpoint(DEFAULT_ENDPOINT);
847+
.setEndpoint(DEFAULT_ENDPOINT)
848+
.setEndpointContext(endpointContext);
838849
InstantiatingGrpcChannelProvider provider =
839850
new InstantiatingGrpcChannelProvider(builder, GCE_PRODUCTION_NAME_AFTER_2016);
840851
Truth.assertThat(provider.canUseDirectPath()).isTrue();
@@ -938,11 +949,14 @@ public void canUseDirectPath_nonGDUUniverseDomain() {
938949
InstantiatingGrpcChannelProvider.DIRECT_PATH_ENV_DISABLE_DIRECT_PATH))
939950
.thenReturn("false");
940951
String nonGDUEndpoint = "test.random.com:443";
952+
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
953+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn(nonGDUEndpoint);
941954
InstantiatingGrpcChannelProvider.Builder builder =
942955
InstantiatingGrpcChannelProvider.newBuilder()
943956
.setAttemptDirectPath(true)
944957
.setCredentials(computeEngineCredentials)
945958
.setEndpoint(nonGDUEndpoint)
959+
.setEndpointContext(endpointContext)
946960
.setEnvProvider(envProvider);
947961
InstantiatingGrpcChannelProvider provider =
948962
new InstantiatingGrpcChannelProvider(builder, GCE_PRODUCTION_NAME_AFTER_2016);

gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonClientInterceptorTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,12 @@ public static void destroy() {
159159
@BeforeEach
160160
void setUp() throws IOException {
161161
interceptor = new CapturingClientInterceptor();
162+
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
163+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn("google.com:443");
162164
channel =
163165
InstantiatingHttpJsonChannelProvider.newBuilder()
164166
.setEndpoint("google.com:443")
167+
.setEndpointContext(endpointContext)
165168
.setExecutor(executorService)
166169
.setHttpTransport(MOCK_SERVICE)
167170
.setHeaderProvider(() -> Collections.singletonMap("header-key", "headerValue"))

gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/InstantiatingHttpJsonChannelProviderTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import static com.google.common.truth.Truth.assertThat;
3333
import static org.junit.jupiter.api.Assertions.assertEquals;
3434

35+
import com.google.api.gax.rpc.EndpointContext;
3536
import com.google.api.gax.rpc.HeaderProvider;
3637
import com.google.api.gax.rpc.TransportChannelProvider;
3738
import com.google.api.gax.rpc.mtls.AbstractMtlsTransportChannelTest;
@@ -56,8 +57,12 @@ void basicTest() throws IOException {
5657
ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1);
5758
executor.shutdown();
5859

60+
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
61+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn(DEFAULT_ENDPOINT);
62+
5963
TransportChannelProvider provider = InstantiatingHttpJsonChannelProvider.newBuilder().build();
6064

65+
provider = provider.withEndpointContext(endpointContext);
6166
assertThat(provider.needsEndpoint()).isTrue();
6267
provider = provider.withEndpoint(DEFAULT_ENDPOINT);
6368
assertThat(provider.needsEndpoint()).isFalse();
@@ -107,8 +112,13 @@ void basicTest() throws IOException {
107112
// if not provided by the TransportChannelProvider
108113
@Test
109114
void managedChannelUsesDefaultChannelExecutor() throws IOException {
115+
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
116+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn(DEFAULT_ENDPOINT);
110117
InstantiatingHttpJsonChannelProvider instantiatingHttpJsonChannelProvider =
111-
InstantiatingHttpJsonChannelProvider.newBuilder().setEndpoint(DEFAULT_ENDPOINT).build();
118+
InstantiatingHttpJsonChannelProvider.newBuilder()
119+
.setEndpoint(DEFAULT_ENDPOINT)
120+
.setEndpointContext(endpointContext)
121+
.build();
112122
instantiatingHttpJsonChannelProvider =
113123
(InstantiatingHttpJsonChannelProvider)
114124
instantiatingHttpJsonChannelProvider.withHeaders(DEFAULT_HEADER_MAP);
@@ -132,9 +142,13 @@ void managedChannelUsesCustomExecutor() throws IOException {
132142
ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1);
133143
executor.shutdown();
134144

145+
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
146+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn(DEFAULT_ENDPOINT);
147+
135148
InstantiatingHttpJsonChannelProvider instantiatingHttpJsonChannelProvider =
136149
InstantiatingHttpJsonChannelProvider.newBuilder()
137150
.setEndpoint(DEFAULT_ENDPOINT)
151+
.setEndpointContext(endpointContext)
138152
.setExecutor(executor)
139153
.build();
140154
instantiatingHttpJsonChannelProvider =

0 commit comments

Comments
 (0)
0