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 integration tests with RetrySettings enabled. #2275

Merged
merged 32 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
408f82e
Add integration tests with RetrySettings enabled.
Oct 13, 2023
ab069b5
Fix formatting
Oct 13, 2023
51f1f51
Add quota and non-quota e2e tests.
Oct 30, 2023
8c82567
Cleanup
Oct 30, 2023
d904fa6
Merge branch 'googleapis:main' into retry-tests
egreco12 Oct 31, 2023
9abfa88
Revert sample changes to keep this branch only for e2e tests
Oct 31, 2023
3bea4df
Remove additional retry-specific sample code
Oct 31, 2023
97614b1
Remove backoff-related retry settings for non quota tests
Oct 31, 2023
52cb39e
Update kokoro build to ignore retry tests until retry-specific Kokoro…
Oct 31, 2023
9e8506e
Run format
Oct 31, 2023
872acff
Wrap -Dtest args
Oct 31, 2023
610f032
Fix integration command
Oct 31, 2023
18f442c
Fix integration command
Oct 31, 2023
0bbc3ff
Remove -Dtest arg
Nov 1, 2023
f39a19d
Fix integration test to ignore retry tests
Nov 3, 2023
5401143
Use list instead of regex for ignoring retry tests when integration t…
Nov 3, 2023
5984f9f
Fix typo in integration test command
Nov 3, 2023
8f11c10
Merge branch 'googleapis:main' into retry-tests
egreco12 Nov 6, 2023
5e86a16
Merge branch 'googleapis:main' into retry-tests
egreco12 Nov 6, 2023
8a44d41
Fix ignore retry test settings
Nov 8, 2023
8432f80
Add debug logs to see why test fails in github
Nov 8, 2023
385d3ea
Remove log
Nov 8, 2023
1de97ce
Add additional retry-based logging
Nov 8, 2023
3e2ed81
Remove unused profile
Nov 8, 2023
a46d327
Add more debugging logs for connection worker test
Nov 8, 2023
4b0d1e1
rearrange builder order
Nov 8, 2023
fdf20d6
Remove debug log
Nov 8, 2023
d083ac0
Directly add streamwriter to list in connection worker pool test
Nov 8, 2023
b341de5
Merge branch 'googleapis:main' into retry-tests
egreco12 Nov 8, 2023
7e29b8e
Refactor retry tests into helper class
Nov 9, 2023
4803de7
Fix file headers
Nov 9, 2023
057cf8c
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Nov 13, 2023
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
3 changes: 3 additions & 0 deletions .kokoro/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ integration)
-DtrimStackTrace=false \
-Dclirr.skip=true \
-Denforcer.skip=true \
-Dit.test=!ITBigQueryWrite*RetryTest \
-Dsurefire.failIfNoSpecifiedTests=false \
-Dfailsafe.failIfNoSpecifiedTests=false \
-fae \
verify
RETURN_CODE=$?
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ If you are using Maven without the BOM, add this to your dependencies:
If you are using Gradle 5.x or later, add this to your dependencies:

```Groovy
implementation platform('com.google.cloud:libraries-bom:26.26.0')
implementation platform('com.google.cloud:libraries-bom:26.27.0')

implementation 'com.google.cloud:google-cloud-bigquerystorage'
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -985,14 +985,14 @@ private Boolean retryOnRetryableError(Code errorCode, AppendRequestAndResponse r
Long offset =
requestWrapper.message.hasOffset() ? requestWrapper.message.getOffset().getValue() : -1;
if (isDefaultStreamName(streamName) || offset == -1) {
log.fine(
log.info(
GaoleMeng marked this conversation as resolved.
Show resolved Hide resolved
String.format(
"Retrying default stream message in stream %s for in-stream error: %s, retry count:"
+ " %s",
streamName, errorCode, requestWrapper.retryCount));
addMessageToFrontOfWaitingQueue(requestWrapper);
} else {
log.fine(
log.info(
String.format(
"Retrying exclusive message in stream %s at offset %d for in-stream error: %s, retry"
+ " count: %s",
Expand Down Expand Up @@ -1089,6 +1089,7 @@ private void requestCallback(AppendRowsResponse response) {
// Retries need to happen on the same thread as queue locking may occur
if (response.hasError()) {
if (retryOnRetryableError(Code.values()[response.getError().getCode()], requestWrapper)) {
log.info("Attempting to retry on error: " + response.getError().toString());
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,15 @@ public void testCloseExternalClient()
// Create some stream writers.
List<StreamWriter> streamWriterList = new ArrayList<>();
for (int i = 0; i < 4; i++) {
StreamWriter sw =
streamWriterList.add(
StreamWriter.newBuilder(
String.format("projects/p1/datasets/d1/tables/t%s/streams/_default", i),
externalClient)
.setEnableConnectionPool(true)
.setWriterSchema(createProtoSchema())
.setTraceId(TEST_TRACE_ID)
.setEnableConnectionPool(true)
.build();
streamWriterList.add(sw);
.setLocation("us")
.build());
}

for (long i = 0; i < appendCount; i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
egreco12 marked this conversation as resolved.
Show resolved Hide resolved
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.bigquery.storage.v1.it;

import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.DatasetInfo;
import com.google.cloud.bigquery.Field;
import com.google.cloud.bigquery.LegacySQLTypeName;
import com.google.cloud.bigquery.Schema;
import com.google.cloud.bigquery.StandardTableDefinition;
import com.google.cloud.bigquery.TableId;
import com.google.cloud.bigquery.TableInfo;
import com.google.cloud.bigquery.storage.v1.BigQueryWriteClient;
import com.google.cloud.bigquery.storage.v1.WriteStream;
import com.google.cloud.bigquery.testing.RemoteBigQueryHelper;
import com.google.protobuf.Descriptors.DescriptorValidationException;
import java.io.IOException;
import java.util.logging.Logger;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

/** Integration tests for BigQuery Write API. */
public class ITBigQueryWriteNonQuotaRetryTest {
egreco12 marked this conversation as resolved.
Show resolved Hide resolved
private static final Logger LOG = Logger.getLogger(ITBigQueryWriteQuotaRetryTest.class.getName());
private static final String DATASET = RemoteBigQueryHelper.generateDatasetName();
private static final String TABLE = "testtable";
private static final String DESCRIPTION = "BigQuery Write Java manual client test dataset";
// This project is configured on the server to inject INTERNAL in-stream errors every
// 10 messages. This is done to verify in-stream message retries.
private static final String NON_QUOTA_RETRY_PROJECT_ID = "bq-write-api-java-retry-test";
egreco12 marked this conversation as resolved.
Show resolved Hide resolved
GaoleMeng marked this conversation as resolved.
Show resolved Hide resolved
private static BigQueryWriteClient client;
private static BigQuery bigquery;

@BeforeClass
public static void beforeClass() throws IOException {
client = BigQueryWriteClient.create();

RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create();
bigquery = bigqueryHelper.getOptions().getService();
DatasetInfo datasetInfo =
DatasetInfo.newBuilder(/* datasetId = */ DATASET).setDescription(DESCRIPTION).build();
bigquery.create(datasetInfo);
LOG.info("Created test dataset: " + DATASET);
TableInfo tableInfo =
TableInfo.newBuilder(
TableId.of(DATASET, TABLE),
StandardTableDefinition.of(
Schema.of(
Field.newBuilder("foo", LegacySQLTypeName.STRING)
.setMode(Field.Mode.NULLABLE)
.build())))
.build();
bigquery.create(tableInfo);
}

@AfterClass
public static void afterClass() {
if (client != null) {
client.close();
}

if (bigquery != null) {
RemoteBigQueryHelper.forceDelete(bigquery, DATASET);
LOG.info("Deleted test dataset: " + DATASET);
}
}

@Test
public void testJsonStreamWriterCommittedStreamWithNonQuotaRetry()
throws IOException, InterruptedException, DescriptorValidationException {
WriteRetryTestUtil.runExclusiveRetryTest(
bigquery,
client,
DATASET,
NON_QUOTA_RETRY_PROJECT_ID,
WriteStream.Type.COMMITTED,
/* requestCount=*/ 901,
/* rowBatchSize=*/ 1);
}

@Test
public void testJsonStreamWriterDefaultStreamWithNonQuotaRetry()
throws IOException, InterruptedException, DescriptorValidationException {
WriteRetryTestUtil.runDefaultRetryTest(
bigquery,
client,
DATASET,
NON_QUOTA_RETRY_PROJECT_ID,
/* requestCount=*/ 901,
/* rowBatchSize=*/ 1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.bigquery.storage.v1.it;

import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.DatasetInfo;
import com.google.cloud.bigquery.Field;
import com.google.cloud.bigquery.LegacySQLTypeName;
import com.google.cloud.bigquery.Schema;
import com.google.cloud.bigquery.StandardTableDefinition;
import com.google.cloud.bigquery.TableId;
import com.google.cloud.bigquery.TableInfo;
import com.google.cloud.bigquery.storage.v1.BigQueryWriteClient;
import com.google.cloud.bigquery.storage.v1.WriteStream;
import com.google.cloud.bigquery.testing.RemoteBigQueryHelper;
import com.google.protobuf.Descriptors.DescriptorValidationException;
import java.io.IOException;
import java.util.logging.Logger;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

/** Integration tests for BigQuery Write API. */
public class ITBigQueryWriteQuotaRetryTest {
private static final Logger LOG = Logger.getLogger(ITBigQueryWriteQuotaRetryTest.class.getName());
private static final String DATASET = RemoteBigQueryHelper.generateDatasetName();
private static final String TABLE = "testtable";
private static final String DESCRIPTION = "BigQuery Write Java manual client test dataset";
// This project is configured on the server to inject RESOURCE_EXHAUSTED in-stream errors every
// 10 messages. This is done to verify in-stream message retries.
private static final String QUOTA_RETRY_PROJECT_ID = "bq-writeapi-java-quota-retry";
private static BigQueryWriteClient client;
private static BigQuery bigquery;

@BeforeClass
public static void beforeClass() throws IOException {
client = BigQueryWriteClient.create();

RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create();
bigquery = bigqueryHelper.getOptions().getService();
DatasetInfo datasetInfo =
DatasetInfo.newBuilder(/* datasetId = */ DATASET).setDescription(DESCRIPTION).build();
bigquery.create(datasetInfo);
LOG.info("Created test dataset: " + DATASET);
TableInfo tableInfo =
TableInfo.newBuilder(
TableId.of(DATASET, TABLE),
StandardTableDefinition.of(
Schema.of(
Field.newBuilder("foo", LegacySQLTypeName.STRING)
.setMode(Field.Mode.NULLABLE)
.build())))
.build();
bigquery.create(tableInfo);
}

@AfterClass
public static void afterClass() {
if (client != null) {
client.close();
}

if (bigquery != null) {
RemoteBigQueryHelper.forceDelete(bigquery, DATASET);
LOG.info("Deleted test dataset: " + DATASET);
}
}

@Test
public void testJsonStreamWriterCommittedStreamWithQuotaRetry()
throws IOException, InterruptedException, DescriptorValidationException {
WriteRetryTestUtil.runExclusiveRetryTest(
bigquery,
client,
DATASET,
QUOTA_RETRY_PROJECT_ID,
WriteStream.Type.COMMITTED,
/* requestCount=*/ 901,
/* rowBatchSize=*/ 1);
}

@Test
public void testJsonStreamWriterDefaultStreamWithQuotaRetry()
throws IOException, InterruptedException, DescriptorValidationException {
WriteRetryTestUtil.runDefaultRetryTest(
bigquery,
client,
DATASET,
QUOTA_RETRY_PROJECT_ID,
/* requestCount=*/ 901,
/* rowBatchSize=*/ 1);
}
}
Loading
Loading