Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,17 @@ public static RemoteBigQueryHelper create(String projectId, InputStream keyStrea
.setConnectTimeout(CONNECT_TIMEOUT_IN_MS)
.setReadTimeout(CONNECT_TIMEOUT_IN_MS)
.build();
BigQueryOptions bigqueryOptions =
BigQueryOptions.Builder builder =
BigQueryOptions.newBuilder()
.setCredentials(ServiceAccountCredentials.fromStream(keyStream))
.setProjectId(projectId)
.setRetrySettings(retrySettings())
.setTransportOptions(transportOptions)
.build();
return new RemoteBigQueryHelper(bigqueryOptions);
.setTransportOptions(transportOptions);
String endpoint = System.getenv("BIGQUERY_ENDPOINT");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this already set somewhere in the config?

qq, do we need to use an env var for our ITs? Would it be possible to just hardcode the regional endpoint for all ITs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the questions.

Is this already set somewhere in the config?

No, this is not set. I'm planning on setting it for the kokoro jobs for IT envs, once this PR is merged.

qq, do we need to use an env var for our ITs? Would it be possible to just hardcode the regional endpoint for all ITs?

Using env var rather than hardcoding would be preferrable, in order to have the flexibility to change it or override it easily.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

got it, sounds good

if (endpoint != null) {
builder.setHost(endpoint);
}
return new RemoteBigQueryHelper(builder.build());
} catch (IOException ex) {
if (log.isLoggable(Level.WARNING)) {
log.log(Level.WARNING, ex.getMessage());
Expand Down Expand Up @@ -140,6 +143,10 @@ public static RemoteBigQueryHelper create(BigQueryOptions.Builder bigqueryOption
bigqueryOptionsBuilder
.setRetrySettings(retrySettings())
.setTransportOptions(transportOptions);
String endpoint = System.getenv("BIGQUERY_ENDPOINT");
if (endpoint != null) {
builder.setHost(endpoint);
}
return new RemoteBigQueryHelper(builder.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class ITBigQueryBigDecimalByteStringEncoderTest {

@BeforeAll
static void beforeAll() throws IOException {
client = BigQueryWriteClient.create();
client = com.google.cloud.bigquery.storage.v1.it.util.Helper.createBigQueryWriteClient();

RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create();
bigquery = bigqueryHelper.getOptions().getService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ITBigQueryStorageLongRunningTest {
static void beforeAll() throws IOException {
Assumptions.assumeTrue(
Boolean.getBoolean(LONG_TESTS_ENABLED_PROPERTY), LONG_TESTS_DISABLED_MESSAGE);
client = BigQueryReadClient.create();
client = com.google.cloud.bigquery.storage.v1.it.util.Helper.createBigQueryReadClient();
parentProjectId = String.format("projects/%s", ServiceOptions.getDefaultProjectId());

LOG.info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ public CompletableResultCode shutdown() {

@BeforeAll
static void beforeAll() throws IOException, DescriptorValidationException, InterruptedException {
readClient = BigQueryReadClient.create();
readClient = com.google.cloud.bigquery.storage.v1.it.util.Helper.createBigQueryReadClient();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we import these

projectName = ServiceOptions.getDefaultProjectId();
parentProjectId = String.format("projects/%s", projectName);

Expand Down Expand Up @@ -1598,7 +1598,7 @@ void testStructAndArraySqlTypes() throws InterruptedException, IOException {
@Test
void testSimpleReadWithBackgroundExecutorProvider() throws IOException {
BigQueryReadSettings bigQueryReadSettings =
BigQueryReadSettings.newBuilder()
com.google.cloud.bigquery.storage.v1.it.util.Helper.createBigQueryReadSettingsBuilder()
.setBackgroundExecutorProvider(
InstantiatingExecutorProvider.newBuilder().setExecutorThreadCount(14).build())
.build();
Expand Down Expand Up @@ -1761,7 +1761,7 @@ void testSimpleReadWithOtelTracing() throws IOException {
OpenTelemetry otel = OpenTelemetrySdk.builder().setTracerProvider(tracerProvider).build();

BigQueryReadSettings otelSettings =
BigQueryReadSettings.newBuilder()
com.google.cloud.bigquery.storage.v1.it.util.Helper.createBigQueryReadSettingsBuilder()
.setEnableOpenTelemetryTracing(true)
.setOpenTelemetryTracerProvider(tracerProvider)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,12 @@ public StringWithSecondsNanos(String fooParam, long secondsParam, int nanosParam

@BeforeAll
static void beforeAll() throws IOException {
readClient = BigQueryReadClient.create();
readClient = com.google.cloud.bigquery.storage.v1.it.util.Helper.createBigQueryReadClient();

BigQueryWriteSettings settings =
BigQueryWriteSettings.newBuilder().setHeaderProvider(USER_AGENT_HEADER_PROVIDER).build();
com.google.cloud.bigquery.storage.v1.it.util.Helper.createBigQueryWriteSettingsBuilder()
.setHeaderProvider(USER_AGENT_HEADER_PROVIDER)
.build();
writeClient = BigQueryWriteClient.create(settings);
parentProjectId = String.format("projects/%s", ServiceOptions.getDefaultProjectId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ITBigQueryTimeEncoderTest {

@BeforeAll
static void beforeAll() throws IOException {
client = BigQueryWriteClient.create();
client = com.google.cloud.bigquery.storage.v1.it.util.Helper.createBigQueryWriteClient();

RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create();
bigquery = bigqueryHelper.getOptions().getService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ITBigQueryWriteNonQuotaRetryTest {

@BeforeAll
static void beforeAll() throws IOException {
client = BigQueryWriteClient.create();
client = com.google.cloud.bigquery.storage.v1.it.util.Helper.createBigQueryWriteClient();

RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create();
bigquery = bigqueryHelper.getOptions().getService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class ITBigQueryWriteQuotaRetryTest {

@BeforeAll
static void beforeAll() throws IOException {
client = BigQueryWriteClient.create();
client = com.google.cloud.bigquery.storage.v1.it.util.Helper.createBigQueryWriteClient();

RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create();
bigquery = bigqueryHelper.getOptions().getService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import com.google.cloud.bigquery.storage.v1.AppendRowsResponse;
import com.google.cloud.bigquery.storage.v1.AvroSerializationOptions;
import com.google.cloud.bigquery.storage.v1.BigQueryReadClient;
import com.google.cloud.bigquery.storage.v1.BigQueryReadSettings;
import com.google.cloud.bigquery.storage.v1.BigQueryWriteClient;
import com.google.cloud.bigquery.storage.v1.BigQueryWriteSettings;
import com.google.cloud.bigquery.storage.v1.CreateReadSessionRequest;
import com.google.cloud.bigquery.storage.v1.DataFormat;
import com.google.cloud.bigquery.storage.v1.ReadRowsRequest;
Expand Down Expand Up @@ -201,4 +204,44 @@ record -> {
});
return rows;
}

/**
* Returns a {@link BigQueryReadSettings.Builder} configured with potential endpoint overrides for
* testing.
*/
public static BigQueryReadSettings.Builder createBigQueryReadSettingsBuilder() {
BigQueryReadSettings.Builder builder = BigQueryReadSettings.newBuilder();
String endpoint = System.getenv("BIGQUERY_STORAGE_ENDPOINT");
if (endpoint != null) {
builder.setEndpoint(endpoint);
}
return builder;
}

/**
* Returns a {@link BigQueryReadClient} configured with potential endpoint overrides for testing.
*/
public static BigQueryReadClient createBigQueryReadClient() throws IOException {
return BigQueryReadClient.create(createBigQueryReadSettingsBuilder().build());
}

/**
* Returns a {@link BigQueryWriteSettings.Builder} configured with potential endpoint overrides
* for testing.
*/
public static BigQueryWriteSettings.Builder createBigQueryWriteSettingsBuilder() {
BigQueryWriteSettings.Builder builder = BigQueryWriteSettings.newBuilder();
String endpoint = System.getenv("BIGQUERY_STORAGE_ENDPOINT");
if (endpoint != null) {
builder.setEndpoint(endpoint);
}
return builder;
}

/**
* Returns a {@link BigQueryWriteClient} configured with potential endpoint overrides for testing.
*/
public static BigQueryWriteClient createBigQueryWriteClient() throws IOException {
return BigQueryWriteClient.create(createBigQueryWriteSettingsBuilder().build());
}
}
Loading