Skip to content

Commit 46b0a85

Browse files
authored
fix: Endpoint resolution uses user set endpoint from ClientSettings (#2429)
* fix: Endpoint resolution uses the user set endpoint * chore: Rename to userSetEndpoint() * chore: Empty commit * chore: Fix showcase tests
1 parent 363e35e commit 46b0a85

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public static ClientContext create(StubSettings settings) throws IOException {
165165
EndpointContext.newBuilder()
166166
.setServiceName(settings.getServiceName())
167167
.setUniverseDomain(settings.getUniverseDomain())
168-
.setClientSettingsEndpoint(settings.getEndpoint())
168+
.setClientSettingsEndpoint(settings.getUserSetEndpoint())
169169
.setTransportChannelProviderEndpoint(
170170
settings.getTransportChannelProvider().getEndpoint())
171171
.setMtlsEndpoint(settings.getMtlsEndpoint())

gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java

+11
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,17 @@ public String getEndpoint() {
157157
return endpoint;
158158
}
159159

160+
/**
161+
* This is an internal api meant to either return the user set endpoint or null. The difference
162+
* between this method and {@link #getEndpoint()}} is that {@link #getEndpoint()} is reimplemented
163+
* by the child class and will return the default service endpoint if the user did not set an
164+
* endpoint (does not return null).
165+
*/
166+
@InternalApi
167+
String getUserSetEndpoint() {
168+
return endpoint;
169+
}
170+
160171
public final String getMtlsEndpoint() {
161172
return mtlsEndpoint;
162173
}

showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITEndpointContext.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,23 @@ public class ITEndpointContext {
2020
public static final String SHOWCASE_DEFAULT_ENDPOINT = "localhost:7469";
2121

2222
// Default (no configuration)
23+
// This test is very similar to `endpointResolution_userConfiguration`. This test is kept
24+
// as future enhancements could allow this test to not have to explicitly set the endpoint.
2325
@Test
2426
public void endpointResolution_default() throws InterruptedException, IOException {
2527
EchoClient echoClient = null;
2628
try {
27-
// The default usage is EchoClient.create(), but for showcase tests run in CI, the
29+
// This is not how a client is created by default:
30+
// 1. The default usage is EchoClient.create(), but for showcase tests run in CI, the
2831
// client must be supplied with Credentials.
32+
// 2. The default configuration does not set an endpoint. Showcase clients do not have
33+
// a serviceName (and this cannot be configured by the user). Set the endpoint
34+
// to simulate the endpointContext creating it with a proper serviceName.
2935
EchoSettings echoSettings =
30-
EchoSettings.newBuilder().setCredentialsProvider(NoCredentialsProvider.create()).build();
36+
EchoSettings.newBuilder()
37+
.setCredentialsProvider(NoCredentialsProvider.create())
38+
.setEndpoint(SHOWCASE_DEFAULT_ENDPOINT)
39+
.build();
3140
echoClient = EchoClient.create(echoSettings);
3241
Truth.assertThat(echoClient.getSettings().getEndpoint()).isEqualTo(SHOWCASE_DEFAULT_ENDPOINT);
3342
} finally {

showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/util/TestClientInitializer.java

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ public static ComplianceClient createGrpcComplianceClient(List<ClientInterceptor
213213
.setChannelConfigurator(ManagedChannelBuilder::usePlaintext)
214214
.setInterceptorProvider(() -> interceptorList)
215215
.build())
216+
.setEndpoint("localhost:7469")
216217
.build();
217218
return ComplianceClient.create(grpcComplianceSettings);
218219
}

0 commit comments

Comments
 (0)