8686
8787class InstantiatingGrpcChannelProviderTest extends AbstractMtlsTransportChannelTest {
8888 private static final String DEFAULT_ENDPOINT = "test.googleapis.com:443" ;
89+ private static final String DEFAULT_MTLS_ENDPOINT = "test.mtls.googleapis.com:443" ;
8990 private static final String API_KEY_HEADER_VALUE = "fake_api_key_2" ;
9091 private static final String API_KEY_AUTH_HEADER_KEY = "x-goog-api-key" ;
9192 private static String originalOSName ;
@@ -205,6 +206,7 @@ void testWithPoolSize() throws IOException {
205206 executor .shutdown ();
206207 EndpointContext endpointContext = Mockito .mock (EndpointContext .class );
207208 Mockito .when (endpointContext .useS2A ()).thenReturn (false );
209+ Mockito .when (endpointContext .mtlsEndpoint ()).thenReturn (DEFAULT_MTLS_ENDPOINT );
208210 TransportChannelProvider provider =
209211 InstantiatingGrpcChannelProvider .newBuilder ()
210212 .build ()
@@ -272,6 +274,7 @@ private void testWithInterceptors(int numChannels) throws Exception {
272274
273275 EndpointContext endpointContext = Mockito .mock (EndpointContext .class );
274276 Mockito .when (endpointContext .useS2A ()).thenReturn (false );
277+ Mockito .when (endpointContext .mtlsEndpoint ()).thenReturn (DEFAULT_MTLS_ENDPOINT );
275278
276279 InstantiatingGrpcChannelProvider channelProvider =
277280 InstantiatingGrpcChannelProvider .newBuilder ()
@@ -309,6 +312,7 @@ void testChannelConfigurator() throws IOException {
309312
310313 EndpointContext endpointContext = Mockito .mock (EndpointContext .class );
311314 Mockito .when (endpointContext .useS2A ()).thenReturn (false );
315+ Mockito .when (endpointContext .mtlsEndpoint ()).thenReturn (DEFAULT_MTLS_ENDPOINT );
312316
313317 // Invoke the provider
314318 InstantiatingGrpcChannelProvider .newBuilder ()
@@ -334,6 +338,7 @@ void testWithGCECredentials() throws IOException {
334338
335339 EndpointContext endpointContext = Mockito .mock (EndpointContext .class );
336340 Mockito .when (endpointContext .useS2A ()).thenReturn (false );
341+ Mockito .when (endpointContext .mtlsEndpoint ()).thenReturn (DEFAULT_MTLS_ENDPOINT );
337342
338343 TransportChannelProvider provider =
339344 InstantiatingGrpcChannelProvider .newBuilder ()
@@ -419,6 +424,7 @@ void testWithNonGCECredentials() throws IOException {
419424
420425 EndpointContext endpointContext = Mockito .mock (EndpointContext .class );
421426 Mockito .when (endpointContext .useS2A ()).thenReturn (false );
427+ Mockito .when (endpointContext .mtlsEndpoint ()).thenReturn (DEFAULT_MTLS_ENDPOINT );
422428
423429 TransportChannelProvider provider =
424430 InstantiatingGrpcChannelProvider .newBuilder ()
@@ -451,6 +457,7 @@ void testWithDirectPathDisabled() throws IOException {
451457
452458 EndpointContext endpointContext = Mockito .mock (EndpointContext .class );
453459 Mockito .when (endpointContext .useS2A ()).thenReturn (false );
460+ Mockito .when (endpointContext .mtlsEndpoint ()).thenReturn (DEFAULT_MTLS_ENDPOINT );
454461
455462 TransportChannelProvider provider =
456463 InstantiatingGrpcChannelProvider .newBuilder ()
@@ -483,6 +490,7 @@ void testWithNoDirectPathFlagSet() throws IOException {
483490
484491 EndpointContext endpointContext = Mockito .mock (EndpointContext .class );
485492 Mockito .when (endpointContext .useS2A ()).thenReturn (false );
493+ Mockito .when (endpointContext .mtlsEndpoint ()).thenReturn (DEFAULT_MTLS_ENDPOINT );
486494
487495 TransportChannelProvider provider =
488496 InstantiatingGrpcChannelProvider .newBuilder ()
@@ -507,6 +515,7 @@ void testWithIPv6Address() throws IOException {
507515
508516 EndpointContext endpointContext = Mockito .mock (EndpointContext .class );
509517 Mockito .when (endpointContext .useS2A ()).thenReturn (false );
518+ Mockito .when (endpointContext .mtlsEndpoint ()).thenReturn (DEFAULT_MTLS_ENDPOINT );
510519
511520 TransportChannelProvider provider =
512521 InstantiatingGrpcChannelProvider .newBuilder ()
@@ -526,6 +535,7 @@ void testWithIPv6Address() throws IOException {
526535 void testWithPrimeChannel () throws IOException {
527536 EndpointContext endpointContext = Mockito .mock (EndpointContext .class );
528537 Mockito .when (endpointContext .useS2A ()).thenReturn (false );
538+ Mockito .when (endpointContext .mtlsEndpoint ()).thenReturn (DEFAULT_MTLS_ENDPOINT );
529539 // create channelProvider with different pool sizes to verify ChannelPrimer is called the
530540 // correct number of times
531541 for (int poolSize = 1 ; poolSize < 5 ; poolSize ++) {
@@ -659,6 +669,7 @@ private void createAndCloseTransportChannel(InstantiatingGrpcChannelProvider pro
659669 InstantiatingGrpcChannelProvider .LOG .addHandler (logHandler );
660670 EndpointContext endpointContext = Mockito .mock (EndpointContext .class );
661671 Mockito .when (endpointContext .useS2A ()).thenReturn (false );
672+ Mockito .when (endpointContext .mtlsEndpoint ()).thenReturn (DEFAULT_MTLS_ENDPOINT );
662673 InstantiatingGrpcChannelProvider provider =
663674 createChannelProviderBuilderForDirectPathLogTests ()
664675 .setAttemptDirectPathXds ()
@@ -706,6 +717,7 @@ void testLogDirectPathMisconfigWrongCredential() throws Exception {
706717 InstantiatingGrpcChannelProvider .LOG .addHandler (logHandler );
707718 EndpointContext endpointContext = Mockito .mock (EndpointContext .class );
708719 Mockito .when (endpointContext .useS2A ()).thenReturn (false );
720+ Mockito .when (endpointContext .mtlsEndpoint ()).thenReturn (DEFAULT_MTLS_ENDPOINT );
709721 InstantiatingGrpcChannelProvider provider =
710722 InstantiatingGrpcChannelProvider .newBuilder ()
711723 .setAttemptDirectPathXds ()
@@ -734,6 +746,7 @@ void testLogDirectPathMisconfigNotOnGCE() throws Exception {
734746 InstantiatingGrpcChannelProvider .LOG .addHandler (logHandler );
735747 EndpointContext endpointContext = Mockito .mock (EndpointContext .class );
736748 Mockito .when (endpointContext .useS2A ()).thenReturn (false );
749+ Mockito .when (endpointContext .mtlsEndpoint ()).thenReturn (DEFAULT_MTLS_ENDPOINT );
737750 InstantiatingGrpcChannelProvider provider =
738751 InstantiatingGrpcChannelProvider .newBuilder ()
739752 .setAttemptDirectPathXds ()
@@ -766,13 +779,16 @@ public void canUseDirectPath_happyPath() throws IOException {
766779 envProvider .getenv (
767780 InstantiatingGrpcChannelProvider .DIRECT_PATH_ENV_DISABLE_DIRECT_PATH ))
768781 .thenReturn ("false" );
782+ EndpointContext endpointContext = Mockito .mock (EndpointContext .class );
783+ Mockito .when (endpointContext .mtlsEndpoint ()).thenReturn (DEFAULT_MTLS_ENDPOINT );
769784 InstantiatingGrpcChannelProvider .Builder builder =
770785 InstantiatingGrpcChannelProvider .newBuilder ()
771786 .setAttemptDirectPath (true )
772787 .setCredentials (computeEngineCredentials )
773788 .setEndpoint (DEFAULT_ENDPOINT )
774789 .setEnvProvider (envProvider )
775- .setHeaderProvider (Mockito .mock (HeaderProvider .class ));
790+ .setHeaderProvider (Mockito .mock (HeaderProvider .class ))
791+ .setEndpointContext (endpointContext );
776792 InstantiatingGrpcChannelProvider provider =
777793 new InstantiatingGrpcChannelProvider (builder , GCE_PRODUCTION_NAME_AFTER_2016 );
778794 Truth .assertThat (provider .canUseDirectPath ()).isTrue ();
@@ -793,6 +809,7 @@ public void canUseDirectPath_directPathEnvVarDisabled() throws IOException {
793809 .thenReturn ("true" );
794810 EndpointContext endpointContext = Mockito .mock (EndpointContext .class );
795811 Mockito .when (endpointContext .useS2A ()).thenReturn (false );
812+ Mockito .when (endpointContext .mtlsEndpoint ()).thenReturn (DEFAULT_MTLS_ENDPOINT );
796813 InstantiatingGrpcChannelProvider .Builder builder =
797814 InstantiatingGrpcChannelProvider .newBuilder ()
798815 .setAttemptDirectPath (true )
0 commit comments