Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Universe Domain to ClientSettings #2331

Merged
merged 3 commits into from Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -93,6 +93,10 @@ public final ApiClock getClock() {
return stubSettings.getClock();
}

public final String getUniverseDomain() {
return stubSettings.getUniverseDomain();
}

public final String getEndpoint() {
return stubSettings.getEndpoint();
}
Expand Down Expand Up @@ -125,6 +129,7 @@ public String toString() {
.add("headerProvider", getHeaderProvider())
.add("internalHeaderProvider", getInternalHeaderProvider())
.add("clock", getClock())
.add("universeDomain", getUniverseDomain())
.add("endpoint", getEndpoint())
.add("quotaProjectId", getQuotaProjectId())
.add("watchdogProvider", getWatchdogProvider())
Expand Down Expand Up @@ -241,6 +246,12 @@ public B setClock(ApiClock clock) {
return self();
}

/** Sets the Universe Domain to configure the resolved endpoint */
public B setUniverseDomain(String universeDomain) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably where showcase tests can help us find issues earlier. Can you please add a few showcase tests to verify that universe domain set through ClientSettings and StubSettings can be used for resolving endpoints?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've decided to park this. I'll create an issue to investigate aligning the stubsettings and clientsettings.

stubSettings.setUniverseDomain(universeDomain);
return self();
}

public B setEndpoint(String endpoint) {
stubSettings.setEndpoint(endpoint);
return self();
Expand Down Expand Up @@ -321,6 +332,11 @@ public ApiClock getClock() {
return stubSettings.getClock();
}

/** Gets the Universe Domain that was previously set on this Builder */
public String getUniverseDomain() {
return stubSettings.getUniverseDomain();
}

public String getEndpoint() {
return stubSettings.getEndpoint();
}
Expand Down Expand Up @@ -364,6 +380,7 @@ public String toString() {
.add("headerProvider", getHeaderProvider())
.add("internalHeaderProvider", getInternalHeaderProvider())
.add("clock", getClock())
.add("universeDomain", getUniverseDomain())
.add("endpoint", getEndpoint())
.add("quotaProjectId", getQuotaProjectId())
.add("watchdogProvider", getWatchdogProvider())
Expand Down
Expand Up @@ -544,6 +544,11 @@ public ApiClock getClock() {
return clock;
}

/** Gets the custom Universe Domain that was previously set on this Builder */
public String getUniverseDomain() {
lqiu96 marked this conversation as resolved.
Show resolved Hide resolved
return universeDomain;
}

public String getEndpoint() {
return endpoint;
}
Expand Down
Expand Up @@ -121,6 +121,7 @@ public void testEmptyBuilder() throws Exception {
.isInstanceOf(InstantiatingWatchdogProvider.class);
Truth.assertThat(builder.getWatchdogCheckInterval()).isGreaterThan(Duration.ZERO);
Truth.assertThat(builder.getQuotaProjectId()).isNull();
Truth.assertThat(builder.getUniverseDomain()).isNull();

FakeClientSettings settings = builder.build();
Truth.assertThat(settings.getExecutorProvider())
Expand All @@ -139,6 +140,7 @@ public void testEmptyBuilder() throws Exception {
.isInstanceOf(InstantiatingWatchdogProvider.class);
Truth.assertThat(settings.getWatchdogCheckInterval()).isGreaterThan(Duration.ZERO);
Truth.assertThat((settings.getQuotaProjectId())).isSameInstanceAs(builder.getQuotaProjectId());
Truth.assertThat(settings.getUniverseDomain()).isSameInstanceAs(builder.getUniverseDomain());

String settingsString = settings.toString();
Truth.assertThat(settingsString).contains("executorProvider");
Expand All @@ -150,6 +152,7 @@ public void testEmptyBuilder() throws Exception {
Truth.assertThat(settingsString).contains("watchdogProvider");
Truth.assertThat(settingsString).contains("watchdogCheckInterval");
Truth.assertThat(settingsString).contains(("quotaProjectId"));
Truth.assertThat(settingsString).contains("universeDomain");
}

@Test
Expand All @@ -165,6 +168,7 @@ public void testBuilder() throws Exception {
WatchdogProvider watchdogProvider = Mockito.mock(WatchdogProvider.class);
Duration watchdogCheckInterval = Duration.ofSeconds(13);
String quotaProjectId = "test_quota_project_id";
String universeDomain = "test.com";

builder.setExecutorProvider(executorProvider);
builder.setTransportChannelProvider(transportProvider);
Expand All @@ -175,6 +179,7 @@ public void testBuilder() throws Exception {
builder.setWatchdogProvider(watchdogProvider);
builder.setWatchdogCheckInterval(watchdogCheckInterval);
builder.setQuotaProjectId(quotaProjectId);
builder.setUniverseDomain(universeDomain);

// For backward compatibility, backgroundExecutorProvider is set to executorProvider
Truth.assertThat(builder.getExecutorProvider()).isSameInstanceAs(executorProvider);
Expand All @@ -187,6 +192,7 @@ public void testBuilder() throws Exception {
Truth.assertThat(builder.getWatchdogProvider()).isSameInstanceAs(watchdogProvider);
Truth.assertThat(builder.getWatchdogCheckInterval()).isSameInstanceAs(watchdogCheckInterval);
Truth.assertThat(builder.getQuotaProjectId()).isEqualTo(quotaProjectId);
Truth.assertThat(builder.getUniverseDomain()).isSameInstanceAs(universeDomain);

String builderString = builder.toString();
Truth.assertThat(builderString).contains("executorProvider");
Expand All @@ -199,6 +205,7 @@ public void testBuilder() throws Exception {
Truth.assertThat(builderString).contains("watchdogProvider");
Truth.assertThat(builderString).contains("watchdogCheckInterval");
Truth.assertThat(builderString).contains("quotaProjectId");
Truth.assertThat(builderString).contains("universeDomain");
}

@Test
Expand All @@ -213,6 +220,7 @@ public void testBuilderFromClientContext() throws Exception {
Duration.ZERO,
Mockito.mock(ScheduledExecutorService.class));
Duration watchdogCheckInterval = Duration.ofSeconds(12);
String universeDomain = "test.com";

ClientContext clientContext =
ClientContext.newBuilder()
Expand All @@ -225,6 +233,7 @@ public void testBuilderFromClientContext() throws Exception {
.setStreamWatchdog(watchdog)
.setStreamWatchdogCheckInterval(watchdogCheckInterval)
.setQuotaProjectId(QUOTA_PROJECT_ID_FROM_CONTEXT)
.setUniverseDomain(universeDomain)
.build();

FakeClientSettings.Builder builder = new FakeClientSettings.Builder(clientContext);
Expand All @@ -244,6 +253,7 @@ public void testBuilderFromClientContext() throws Exception {
Truth.assertThat(builder.getWatchdogProvider().getWatchdog()).isSameInstanceAs(watchdog);
Truth.assertThat(builder.getWatchdogCheckInterval()).isEqualTo(watchdogCheckInterval);
Truth.assertThat(builder.getQuotaProjectId()).isEqualTo(QUOTA_PROJECT_ID_FROM_CONTEXT);
Truth.assertThat(builder.getUniverseDomain()).isEqualTo(universeDomain);
}

@Test
Expand All @@ -259,6 +269,7 @@ public void testBuilderFromSettings() throws Exception {
WatchdogProvider watchdogProvider = Mockito.mock(WatchdogProvider.class);
Duration watchdogCheckInterval = Duration.ofSeconds(14);
String quotaProjectId = "test_builder_from_settings_quotaProjectId";
String universeDomain = "test.com";

builder.setExecutorProvider(executorProvider);
builder.setTransportChannelProvider(transportProvider);
Expand All @@ -269,6 +280,7 @@ public void testBuilderFromSettings() throws Exception {
builder.setWatchdogProvider(watchdogProvider);
builder.setWatchdogCheckInterval(watchdogCheckInterval);
builder.setQuotaProjectId(quotaProjectId);
builder.setUniverseDomain(universeDomain);

FakeClientSettings settings = builder.build();
FakeClientSettings.Builder newBuilder = new FakeClientSettings.Builder(settings);
Expand All @@ -284,6 +296,7 @@ public void testBuilderFromSettings() throws Exception {
Truth.assertThat(newBuilder.getWatchdogProvider()).isSameInstanceAs(watchdogProvider);
Truth.assertThat(newBuilder.getWatchdogCheckInterval()).isEqualTo(watchdogCheckInterval);
Truth.assertThat(newBuilder.getQuotaProjectId()).isEqualTo(quotaProjectId);
Truth.assertThat(newBuilder.getUniverseDomain()).isEqualTo(universeDomain);
}

@Test
Expand Down