File tree Expand file tree Collapse file tree 3 files changed +36
-6
lines changed
sdk-platform-java/gax-java/gax/src
main/java/com/google/api/gax/rpc
test/java/com/google/api/gax/rpc Expand file tree Collapse file tree 3 files changed +36
-6
lines changed Original file line number Diff line number Diff line change @@ -271,12 +271,7 @@ public static ClientContext create(StubSettings settings) throws IOException {
271271 if (watchdogProvider != null && watchdogProvider .shouldAutoClose ()) {
272272 backgroundResources .add (watchdog );
273273 }
274- String serviceName = endpointContext .serviceName ();
275- String universeDomain = endpointContext .resolvedUniverseDomain ();
276- String urlDomain = null ;
277- if (!Strings .isNullOrEmpty (serviceName ) && !Strings .isNullOrEmpty (universeDomain )) {
278- urlDomain = serviceName + "." + universeDomain ;
279- }
274+ String urlDomain = endpointContext .getUrlDomain ();
280275
281276 ApiTracerContext apiTracerContext =
282277 ApiTracerContext .newBuilder ()
Original file line number Diff line number Diff line change @@ -140,6 +140,14 @@ public static EndpointContext getDefaultInstance() {
140140 @ Nullable
141141 public abstract Integer resolvedServerPort ();
142142
143+ @ Nullable
144+ String getUrlDomain () {
145+ if (!Strings .isNullOrEmpty (serviceName ()) && !Strings .isNullOrEmpty (resolvedUniverseDomain ())) {
146+ return serviceName () + "." + resolvedUniverseDomain ();
147+ }
148+ return null ;
149+ }
150+
143151 public abstract Builder toBuilder ();
144152
145153 public static Builder newBuilder () {
Original file line number Diff line number Diff line change @@ -698,4 +698,31 @@ void endpointContextBuild_resolvesInvalidEndpointAndPort() throws Exception {
698698 Truth .assertThat (endpointContext .resolvedServerAddress ()).isNull ();
699699 Truth .assertThat (endpointContext .resolvedServerPort ()).isNull ();
700700 }
701+
702+ @ Test
703+ void getUrlDomain_success () throws IOException {
704+ EndpointContext endpointContext = defaultEndpointContextBuilder .build ();
705+ Truth .assertThat (endpointContext .getUrlDomain ()).isEqualTo ("test.googleapis.com" );
706+ }
707+
708+ @ Test
709+ void getUrlDomain_nullServiceName () throws IOException {
710+ EndpointContext endpointContext =
711+ defaultEndpointContextBuilder .setServiceName (null ).build ();
712+ Truth .assertThat (endpointContext .getUrlDomain ()).isNull ();
713+ }
714+
715+ @ Test
716+ void getUrlDomain_emptyServiceName () throws IOException {
717+ EndpointContext endpointContext =
718+ defaultEndpointContextBuilder .setServiceName ("" ).build ();
719+ Truth .assertThat (endpointContext .getUrlDomain ()).isNull ();
720+ }
721+
722+ @ Test
723+ void getUrlDomain_nonGDUUniverseDomain () throws IOException {
724+ EndpointContext endpointContext =
725+ defaultEndpointContextBuilder .setUniverseDomain ("random.com" ).build ();
726+ Truth .assertThat (endpointContext .getUrlDomain ()).isEqualTo ("test.random.com" );
727+ }
701728}
You can’t perform that action at this time.
0 commit comments