-
Notifications
You must be signed in to change notification settings - Fork 336
feat: add properties to set universe domain and endpoint in bigquery #3158
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
Changes from 9 commits
929844e
bf6887b
e86aa9e
7e1f734
9419b7b
8364de1
a8b8ad2
8e7b4bf
83f0fff
c3ebe7c
4b34ff3
2309417
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
import com.google.auth.oauth2.GoogleCredentials; | ||
import com.google.cloud.bigquery.BigQuery; | ||
import com.google.cloud.bigquery.BigQueryOptions; | ||
import com.google.cloud.bigquery.storage.v1.BigQueryWriteClient; | ||
import com.google.cloud.spring.autoconfigure.core.GcpContextAutoConfiguration; | ||
import com.google.cloud.spring.bigquery.core.BigQueryTemplate; | ||
import org.junit.jupiter.api.Test; | ||
|
@@ -60,6 +61,107 @@ void testSettingBigQueryOptions() { | |
}); | ||
} | ||
|
||
@Test | ||
void testBigQuery_universeDomain() { | ||
this.contextRunner | ||
.withPropertyValues("spring.cloud.gcp.bigquery.universe-domain=myUniverseDomain") | ||
.run( | ||
ctx -> { | ||
BigQueryOptions options = ctx.getBean(BigQuery.class).getOptions(); | ||
assertThat(options.getUniverseDomain()).isEqualTo("myUniverseDomain"); | ||
assertThat(options.getResolvedApiaryHost("bigquery")) | ||
.isEqualTo("https://bigquery.myUniverseDomain/"); | ||
}); | ||
} | ||
|
||
@Test | ||
void testBigQuery_noUniverseDomainAndEndpointSet_useClientDefault() { | ||
this.contextRunner.run( | ||
ctx -> { | ||
BigQueryOptions options = ctx.getBean(BigQuery.class).getOptions(); | ||
assertThat(options.getUniverseDomain()).isNull(); | ||
assertThat(options.getResolvedApiaryHost("bigquery")) | ||
.isEqualTo("https://bigquery.googleapis.com/"); | ||
}); | ||
} | ||
|
||
@Test | ||
void testBigQuery_endpoint() { | ||
this.contextRunner | ||
.withPropertyValues("spring.cloud.gcp.bigquery.endpoint=bigquery.example.com:443") | ||
.run( | ||
ctx -> { | ||
BigQueryOptions options = ctx.getBean(BigQuery.class).getOptions(); | ||
assertThat(options.getResolvedApiaryHost("bigquery")) | ||
.isEqualTo("https://bigquery.example.com"); | ||
}); | ||
} | ||
|
||
@Test | ||
void testBigQuery_bothEndpointAndUniverseDomainSet() { | ||
this.contextRunner | ||
.withPropertyValues("spring.cloud.gcp.bigquery.endpoint=bigquery.example.com:123") | ||
.withPropertyValues("spring.cloud.gcp.bigquery.universe-domain=myUniverseDomain") | ||
.run( | ||
ctx -> { | ||
BigQueryOptions options = ctx.getBean(BigQuery.class).getOptions(); | ||
assertThat(options.getResolvedApiaryHost("bigquery")) | ||
.isEqualTo("https://bigquery.example.com"); | ||
assertThat(options.getUniverseDomain()).isEqualTo("myUniverseDomain"); | ||
}); | ||
} | ||
|
||
@Test | ||
void testBigQueryWrite_universeDomain() { | ||
this.contextRunner | ||
.withPropertyValues("spring.cloud.gcp.bigquery.universe-domain=myUniverseDomain") | ||
.run( | ||
ctx -> { | ||
BigQueryWriteClient writeClient = ctx.getBean(BigQueryWriteClient.class); | ||
assertThat(writeClient.getSettings().getUniverseDomain()) | ||
.isEqualTo("myUniverseDomain"); | ||
}); | ||
} | ||
|
||
@Test | ||
void testBigQueryWrite_endpoint() { | ||
this.contextRunner | ||
.withPropertyValues( | ||
"spring.cloud.gcp.bigquery.endpoint=bigquerystorage.example.com:123") | ||
.run( | ||
ctx -> { | ||
BigQueryWriteClient client = ctx.getBean(BigQueryWriteClient.class); | ||
assertThat(client.getSettings().getEndpoint()) | ||
.isEqualTo("bigquerystorage.example.com:123"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please verify that it's intended to have getEndpoint not return the URI scheme, but getResolvedApiaryHost does return the URI scheme. LGTM There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, returning endpoint with this pattern is intended for Bigquerystorage which will otherwise throw an exception if it doesn't follow a specific convention. For example, passing in
On the other hand bigquery accepts either accepts user-provided endpoint as-is if one is provided or builds the host in the |
||
}); | ||
} | ||
|
||
@Test | ||
void testBigQueryWrite_bothUniverseDomainAndEndpointSet() { | ||
this.contextRunner | ||
.withPropertyValues("spring.cloud.gcp.bigquery.universe-domain=myUniverseDomain") | ||
.withPropertyValues( | ||
"spring.cloud.gcp.bigquery.endpoint=bigquerystorage.example.com:123") | ||
.run( | ||
ctx -> { | ||
BigQueryWriteClient client = ctx.getBean(BigQueryWriteClient.class); | ||
assertThat(client.getSettings().getUniverseDomain()).isEqualTo("myUniverseDomain"); | ||
assertThat(client.getSettings().getEndpoint()) | ||
.isEqualTo("bigquerystorage.example.com:123"); | ||
}); | ||
} | ||
|
||
@Test | ||
void testBigQueryWrite_noUniverseDomainOrEndpointSet_useClientDefault() { | ||
this.contextRunner.run( | ||
ctx -> { | ||
BigQueryWriteClient client = ctx.getBean(BigQueryWriteClient.class); | ||
assertThat(client.getSettings().getUniverseDomain()).isEqualTo("googleapis.com"); | ||
assertThat(client.getSettings().getEndpoint()) | ||
.isEqualTo("bigquerystorage.googleapis.com:443"); | ||
}); | ||
} | ||
|
||
/** Spring Boot config for tests. */ | ||
@AutoConfigurationPackage | ||
static class TestConfiguration { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just do String manipulation is host is basically endpoint without ports? Is there any edge cases can not be handled by String manipulation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Simplified to use String manipulation.