Skip to content

Commit 81baaa3

Browse files
committed
test(bigquery): support regional endpoints dynamically in integration tests
1 parent 2413811 commit 81baaa3

13 files changed

Lines changed: 236 additions & 29 deletions

File tree

.kokoro/presubmit/bigquery-graalvm-native-presubmit.cfg

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ env_vars: {
2222
value: "gcloud-devel"
2323
}
2424

25+
env_vars: {
26+
key: "INTEGRATION_TEST_ARGS"
27+
value: "-Dbigquery.endpoint=https://us-east7-bigquery.googleapis.com -Dbigquery.storage.endpoint=us-east7-bigquerystorage.googleapis.com:443"
28+
}
29+
2530
env_vars: {
2631
key: "GOOGLE_APPLICATION_CREDENTIALS"
2732
value: "secret_manager/java-it-service-account"
@@ -40,5 +45,3 @@ env_vars: {
4045
key: "BUILD_SUBDIR"
4146
value: "java-bigquery"
4247
}
43-
44-

.kokoro/presubmit/bigquery-integration.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ env_vars: {
2222
value: "gcloud-devel"
2323
}
2424

25+
env_vars: {
26+
key: "INTEGRATION_TEST_ARGS"
27+
value: "-Dbigquery.endpoint=https://us-east7-bigquery.googleapis.com -Dbigquery.storage.endpoint=us-east7-bigquerystorage.googleapis.com:443"
28+
}
29+
2530
env_vars: {
2631
key: "GOOGLE_APPLICATION_CREDENTIALS"
2732
value: "secret_manager/java-it-service-account"

.kokoro/presubmit/bigquerystorage-graalvm-native-presubmit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ env_vars: {
4444

4545
env_vars: {
4646
key: "INTEGRATION_TEST_ARGS"
47-
value: "-Dit.test=!ITBigQueryWrite*RetryTest -Dsurefire.failIfNoSpecifiedTests=false -Dfailsafe.failIfNoSpecifiedTests=false"
47+
value: "-Dit.test=!ITBigQueryWrite*RetryTest -Dsurefire.failIfNoSpecifiedTests=false -Dfailsafe.failIfNoSpecifiedTests=false -Dbigquery.storage.endpoint=us-east7-bigquerystorage.googleapis.com:443 -Dbigquery.endpoint=https://us-east7-bigquery.googleapis.com"
4848
}

.kokoro/presubmit/bigquerystorage-integration.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ env_vars: {
3939

4040
env_vars: {
4141
key: "INTEGRATION_TEST_ARGS"
42-
value: "-Dit.test=!ITBigQueryWrite*RetryTest -Dsurefire.failIfNoSpecifiedTests=false -Dfailsafe.failIfNoSpecifiedTests=false"
42+
value: "-Dit.test=!ITBigQueryWrite*RetryTest -Dsurefire.failIfNoSpecifiedTests=false -Dfailsafe.failIfNoSpecifiedTests=false -Dbigquery.storage.endpoint=us-east7-bigquerystorage.googleapis.com:443 -Dbigquery.endpoint=https://us-east7-bigquery.googleapis.com"
4343
}

java-bigquery/google-cloud-bigquery/pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
</parent>
1616
<properties>
1717
<site.installationModule>google-cloud-bigquery</site.installationModule>
18+
<bigquery.endpoint></bigquery.endpoint>
19+
<bigquery.storage.endpoint></bigquery.storage.endpoint>
1820
</properties>
1921
<dependencies>
2022
<dependency>
@@ -326,5 +328,22 @@
326328
</build>
327329

328330
</profile>
331+
<profile>
332+
<id>native</id>
333+
<build>
334+
<plugins>
335+
<plugin>
336+
<groupId>org.graalvm.buildtools</groupId>
337+
<artifactId>native-maven-plugin</artifactId>
338+
<configuration>
339+
<environmentVariables>
340+
<BIGQUERY_ENDPOINT>${bigquery.endpoint}</BIGQUERY_ENDPOINT>
341+
<BIGQUERY_STORAGE_ENDPOINT>${bigquery.storage.endpoint}</BIGQUERY_STORAGE_ENDPOINT>
342+
</environmentVariables>
343+
</configuration>
344+
</plugin>
345+
</plugins>
346+
</build>
347+
</profile>
329348
</profiles>
330349
</project>

java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/testing/RemoteBigQueryHelper.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public static RemoteBigQueryHelper create(String projectId, InputStream keyStrea
105105
.setProjectId(projectId)
106106
.setRetrySettings(retrySettings())
107107
.setTransportOptions(transportOptions);
108-
String endpoint = System.getenv("BIGQUERY_ENDPOINT");
108+
String endpoint = System.getProperty("bigquery.endpoint", System.getenv("BIGQUERY_ENDPOINT"));
109109
if (endpoint != null) {
110110
builder.setHost(endpoint);
111111
}
@@ -143,7 +143,7 @@ public static RemoteBigQueryHelper create(BigQueryOptions.Builder bigqueryOption
143143
bigqueryOptionsBuilder
144144
.setRetrySettings(retrySettings())
145145
.setTransportOptions(transportOptions);
146-
String endpoint = System.getenv("BIGQUERY_ENDPOINT");
146+
String endpoint = System.getProperty("bigquery.endpoint", System.getenv("BIGQUERY_ENDPOINT"));
147147
if (endpoint != null) {
148148
builder.setHost(endpoint);
149149
}
@@ -184,4 +184,16 @@ public static BigQueryHelperException translate(Exception ex) {
184184
return new BigQueryHelperException(ex.getMessage(), ex);
185185
}
186186
}
187+
188+
/**
189+
* Helper to check if the provided BigQuery client is configured to target a regional endpoint.
190+
*/
191+
public static boolean isRegionalEndpoint(BigQuery bigquery) {
192+
if (bigquery == null || bigquery.getOptions() == null) {
193+
return false;
194+
}
195+
String host = bigquery.getOptions().getHost();
196+
return host != null
197+
&& (host.contains("-bigquery.googleapis.com") || host.contains(".rep.googleapis.com"));
198+
}
187199
}

java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@
211211
import java.util.logging.Level;
212212
import java.util.logging.Logger;
213213
import org.junit.jupiter.api.AfterAll;
214+
import org.junit.jupiter.api.Assumptions;
214215
import org.junit.jupiter.api.BeforeAll;
215216
import org.junit.jupiter.api.Test;
216217
import org.junit.jupiter.api.Timeout;
@@ -1271,6 +1272,8 @@ void testLosslessMaxTimestampIntegration() throws InterruptedException {
12711272

12721273
@Test
12731274
void testListDatasets() {
1275+
// This test queries public datasets, which are not supported by regional endpoints.
1276+
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
12741277
Page<Dataset> datasets = bigquery.listDatasets("bigquery-public-data");
12751278
Iterator<Dataset> iterator = datasets.iterateAll().iterator();
12761279
Set<String> datasetNames = new HashSet<>();
@@ -2131,6 +2134,8 @@ void testCreateTableWithDefaultValueExpression() {
21312134

21322135
@Test
21332136
void testCreateAndUpdateTableWithPolicyTags() throws IOException {
2137+
// This test queries public datasets, which are not supported by regional endpoints.
2138+
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
21342139
// Set up policy tags in the datacatalog service
21352140
try (PolicyTagManagerClient policyTagManagerClient = PolicyTagManagerClient.create()) {
21362141
CreateTaxonomyRequest createTaxonomyRequest =
@@ -2515,6 +2520,8 @@ void testCreateExternalTable() throws InterruptedException {
25152520

25162521
@Test
25172522
void testSetPermExternalTableSchema() {
2523+
// This test queries public datasets, which are not supported by regional endpoints.
2524+
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
25182525
String tableName = "test_create_external_table_perm";
25192526
TableId tableId = TableId.of(DATASET, tableName);
25202527
ExternalTableDefinition externalTableDefinition =
@@ -2926,6 +2933,8 @@ void testDeleteNonExistingTable() {
29262933

29272934
@Test
29282935
void testDeleteJob() {
2936+
// This test queries public datasets, which are not supported by regional endpoints.
2937+
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
29292938
String query = "SELECT 17 as foo";
29302939
QueryJobConfiguration config = QueryJobConfiguration.of(query);
29312940
String jobName = "jobId_" + UUID.randomUUID().toString();
@@ -3188,6 +3197,8 @@ void testListAllTableData() {
31883197

31893198
@Test
31903199
void testListPageWithStartIndex() {
3200+
// This test queries public datasets, which are not supported by regional endpoints.
3201+
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
31913202
String tableName = "midyear_population_agespecific";
31923203
TableId tableId = TableId.of(PUBLIC_PROJECT, PUBLIC_DATASET, tableName);
31933204
Table table = bigquery.getTable(tableId);
@@ -3659,6 +3670,8 @@ void testQueryStatistics() throws InterruptedException {
36593670

36603671
@Test
36613672
void testExecuteSelectDefaultConnectionSettings() throws SQLException {
3673+
// This test queries public datasets, which are not supported by regional endpoints.
3674+
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
36623675
// Use the default connection settings
36633676
Connection connection = bigquery.createConnection();
36643677
String query = "SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
@@ -3669,6 +3682,8 @@ void testExecuteSelectDefaultConnectionSettings() throws SQLException {
36693682

36703683
@Test
36713684
void testExecuteSelectWithReadApi() throws SQLException {
3685+
// This test queries public datasets, which are not supported by regional endpoints.
3686+
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
36723687
final int rowLimit = 5000;
36733688
final String QUERY =
36743689
"SELECT * FROM bigquery-public-data.new_york_taxi_trips.tlc_yellow_trips_2017 LIMIT %s";
@@ -3699,6 +3714,8 @@ void testExecuteSelectWithReadApi() throws SQLException {
36993714

37003715
@Test
37013716
void testExecuteSelectWithFastQueryReadApi() throws SQLException {
3717+
// This test queries public datasets, which are not supported by regional endpoints.
3718+
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
37023719
final int rowLimit = 5000;
37033720
final String QUERY =
37043721
"SELECT * FROM bigquery-public-data.new_york_taxi_trips.tlc_yellow_trips_2017 LIMIT %s";
@@ -4785,6 +4802,8 @@ void testProjectIDFastSQLQueryWithJobId() {
47854802

47864803
@Test
47874804
void testLocationFastSQLQueryWithJobId() throws InterruptedException {
4805+
// This test queries public datasets, which are not supported by regional endpoints.
4806+
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
47884807
TableId tableIdFastQueryUk = TableId.of(UK_DATASET, "fastquery_testing_table");
47894808
DatasetInfo infoUK =
47904809
DatasetInfo.newBuilder(UK_DATASET)
@@ -4960,6 +4979,8 @@ void testFastDDLQuery() throws InterruptedException {
49604979

49614980
@Test
49624981
void testFastQuerySlowDDL() throws InterruptedException {
4982+
// This test queries public datasets, which are not supported by regional endpoints.
4983+
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
49634984
String tableName = generateRandomName("test_table_fast_query_ddl_slow_");
49644985
// This query take more than 10s to run and should fall back on the old query path
49654986
String slowDdlQuery =
@@ -5061,6 +5082,8 @@ void testQuerySessionSupport() throws InterruptedException {
50615082

50625083
@Test
50635084
void testLoadSessionSupportWriteChannelConfiguration() throws InterruptedException {
5085+
// This test queries public datasets, which are not supported by regional endpoints.
5086+
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
50645087
TableId sessionTableId = TableId.of("_SESSION", "test_temp_destination_table_from_file");
50655088

50665089
WriteChannelConfiguration configuration =
@@ -5288,6 +5311,8 @@ void testTransactionInfo() throws InterruptedException {
52885311
/* TODO(prasmish): replicate the entire test case for executeSelect */
52895312
@Test
52905313
void testScriptStatistics() throws InterruptedException {
5314+
// This test queries public datasets, which are not supported by regional endpoints.
5315+
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
52915316
String script =
52925317
"-- Declare a variable to hold names as an array.\n"
52935318
+ "DECLARE top_names ARRAY<STRING>;\n"
@@ -6541,6 +6566,8 @@ void testCancelJob() throws InterruptedException, TimeoutException {
65416566

65426567
@Test
65436568
void testCancelNonExistingJob() {
6569+
// This test queries public datasets, which are not supported by regional endpoints.
6570+
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
65446571
assertFalse(bigquery.cancel("test_cancel_non_existing_job"));
65456572
}
65466573

@@ -6677,6 +6704,8 @@ void testInsertWithDecimalTargetTypes()
66776704

66786705
@Test
66796706
void testLocation() throws Exception {
6707+
// This test queries public datasets, which are not supported by regional endpoints.
6708+
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
66806709
String location = "EU";
66816710
String wrongLocation = "US";
66826711

@@ -7443,6 +7472,8 @@ void testTableResultJobIdAndQueryId() throws InterruptedException {
74437472

74447473
@Test
74457474
void testStatelessQueriesWithLocation() throws Exception {
7475+
// This test queries public datasets, which are not supported by regional endpoints.
7476+
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
74467477
// This test validates BigQueryOption location is used for stateless query by verifying that the
74477478
// stateless query fails when the BigQueryOption location does not match the dataset location.
74487479
String location = "EU";
@@ -7608,6 +7639,8 @@ void testInvalidUniverseDomainWithMismatchCredentials() {
76087639

76097640
@Test
76107641
void testUniverseDomainWithMatchingDomain() {
7642+
// This test queries public datasets, which are not supported by regional endpoints.
7643+
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
76117644
// Test a valid domain using the default credentials and Google default universe domain.
76127645
RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create();
76137646
BigQueryOptions bigQueryOptions =
@@ -7701,6 +7734,8 @@ void testExternalMetadataCacheModeFailForNonBiglake() {
77017734

77027735
@Test
77037736
void testObjectTable() throws InterruptedException {
7737+
// This test queries public datasets, which are not supported by regional endpoints.
7738+
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
77047739
String tableName = generateRandomName("test_object_table");
77057740
TableId tableId = TableId.of(DATASET, tableName);
77067741

java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITNightlyBigQueryTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import java.util.logging.Logger;
7070
import org.apache.arrow.vector.util.JsonStringArrayList;
7171
import org.junit.jupiter.api.AfterAll;
72+
import org.junit.jupiter.api.Assumptions;
7273
import org.junit.jupiter.api.BeforeAll;
7374
import org.junit.jupiter.api.Test;
7475
import org.junit.jupiter.api.Timeout;
@@ -507,6 +508,8 @@ void testPositionalParams()
507508
// table-not-found exception. Ref: b/241134681 . This exception has been seen while reading data
508509
// in bulk
509510
void testForTableNotFound() throws SQLException {
511+
// This test queries public datasets, which are not supported by regional endpoints.
512+
Assumptions.assumeTrue(!RemoteBigQueryHelper.isRegionalEndpoint(bigquery));
510513
int recordCnt = 50000000; // 5Mil
511514
String query =
512515
String.format(

java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITOpenTelemetryTest.java

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ public void testListDatasetsTraced() {
9494
assertEquals("GET", attrs.get(HttpTracingRequestInitializer.HTTP_REQUEST_METHOD));
9595
assertEquals("DatasetService", attrs.get(AttributeKey.stringKey("bq.rpc.service")));
9696
assertEquals("ListDatasets", attrs.get(AttributeKey.stringKey("bq.rpc.method")));
97-
assertEquals(
98-
"bigquery.googleapis.com", attrs.get(HttpTracingRequestInitializer.SERVER_ADDRESS));
97+
assertEquals(getExpectedHost(), attrs.get(HttpTracingRequestInitializer.SERVER_ADDRESS));
9998
assertEquals(200L, attrs.get(HttpTracingRequestInitializer.HTTP_RESPONSE_STATUS_CODE));
100-
assertEquals("bigquery.googleapis.com", attrs.get(BigQueryTelemetryTracer.URL_DOMAIN));
99+
assertEquals(getExpectedHost(), attrs.get(BigQueryTelemetryTracer.URL_DOMAIN));
101100
assertEquals(
102-
"https://bigquery.googleapis.com/bigquery/v2/projects/"
101+
getExpectedFullHost()
102+
+ "/bigquery/v2/projects/"
103103
+ bigqueryHelper.getOptions().getProjectId()
104104
+ "/datasets?prettyPrint=false",
105105
attrs.get(HttpTracingRequestInitializer.URL_FULL));
@@ -150,13 +150,13 @@ public void testGetDatasetNotFoundTraced() {
150150
"projects/{+projectId}/datasets/{+datasetId}",
151151
attrs.get(BigQueryTelemetryTracer.URL_TEMPLATE));
152152
assertEquals(
153-
"https://bigquery.googleapis.com/bigquery/v2/projects/"
153+
getExpectedFullHost()
154+
+ "/bigquery/v2/projects/"
154155
+ bigqueryHelper.getOptions().getProjectId()
155156
+ "/datasets/non_existent_dataset?prettyPrint=false",
156157
attrs.get(HttpTracingRequestInitializer.URL_FULL));
157-
assertEquals(
158-
"bigquery.googleapis.com", attrs.get(HttpTracingRequestInitializer.SERVER_ADDRESS));
159-
assertEquals("bigquery.googleapis.com", attrs.get(BigQueryTelemetryTracer.URL_DOMAIN));
158+
assertEquals(getExpectedHost(), attrs.get(HttpTracingRequestInitializer.SERVER_ADDRESS));
159+
assertEquals(getExpectedHost(), attrs.get(BigQueryTelemetryTracer.URL_DOMAIN));
160160
assertEquals(
161161
"//bigquery.googleapis.com/projects/"
162162
+ bigqueryHelper.getOptions().getProjectId()
@@ -320,4 +320,35 @@ private void checkGeneralAttributes(Map<AttributeKey<?>, Object> attrs) {
320320
attrs.get(BigQueryTelemetryTracer.GCP_CLIENT_ARTIFACT));
321321
assertNotNull(attrs.get(BigQueryTelemetryTracer.GCP_CLIENT_VERSION));
322322
}
323+
324+
/**
325+
* Returns the expected host header/domain to be matched in telemetry trace assertions.
326+
* Dynamically strips protocol prefixes ("https://", "http://") from the configured BigQuery host
327+
* options, falling back to the default "bigquery.googleapis.com" if not configured.
328+
*/
329+
private static String getExpectedHost() {
330+
String host = bigqueryHelper.getOptions().getHost();
331+
if (host == null || host.isEmpty() || host.equals("https://www.googleapis.com")) {
332+
return "bigquery.googleapis.com";
333+
}
334+
if (host.startsWith("https://")) {
335+
return host.substring("https://".length());
336+
}
337+
if (host.startsWith("http://")) {
338+
return host.substring("http://".length());
339+
}
340+
return host;
341+
}
342+
343+
/**
344+
* Returns the expected full URL host prefix (including the protocol scheme) for URL assertions.
345+
* Defaults to "https://bigquery.googleapis.com" if the host option is not configured.
346+
*/
347+
private static String getExpectedFullHost() {
348+
String host = bigqueryHelper.getOptions().getHost();
349+
if (host == null || host.isEmpty() || host.equals("https://www.googleapis.com")) {
350+
return "https://bigquery.googleapis.com";
351+
}
352+
return host;
353+
}
323354
}

java-bigquerystorage/google-cloud-bigquerystorage/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
</parent>
1616
<properties>
1717
<site.installationModule>google-cloud-bigquerystorage</site.installationModule>
18+
<bigquery.endpoint></bigquery.endpoint>
19+
<bigquery.storage.endpoint></bigquery.storage.endpoint>
1820
</properties>
1921
<dependencyManagement>
2022
<dependencies>
@@ -409,6 +411,10 @@
409411
<buildArg>--no-fallback</buildArg>
410412
<buildArg>--no-server</buildArg>
411413
</buildArgs>
414+
<environmentVariables>
415+
<BIGQUERY_ENDPOINT>${bigquery.endpoint}</BIGQUERY_ENDPOINT>
416+
<BIGQUERY_STORAGE_ENDPOINT>${bigquery.storage.endpoint}</BIGQUERY_STORAGE_ENDPOINT>
417+
</environmentVariables>
412418
</configuration>
413419
</plugin>
414420
</plugins>

0 commit comments

Comments
 (0)