Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
PhongChuong committed Jul 23, 2024
1 parent 5b75c38 commit a2f073b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

@RunWith(MockitoJUnitRunner.class)
public class BigQueryImplTest {

private static final String PROJECT = "project";
private static final String LOCATION = "US";
private static final String OTHER_PROJECT = "otherProject";
Expand Down Expand Up @@ -1597,11 +1598,13 @@ public void testCreateJobFailureShouldRetry() {
@Test
public void testCreateJobWithBigQueryRetryConfigFailureShouldRetry() {
// Validate create job with BigQueryRetryConfig that retries on rate limit error message.
JobOption bigQueryRetryConfigOption = JobOption.bigQueryRetryConfig(BigQueryRetryConfig.newBuilder()
.retryOnMessage(BigQueryErrorMessages.RATE_LIMIT_EXCEEDED_MSG)
.retryOnMessage(BigQueryErrorMessages.JOB_RATE_LIMIT_EXCEEDED_MSG)
.retryOnRegEx(BigQueryErrorMessages.RetryRegExPatterns.RATE_LIMIT_EXCEEDED_REGEX)
.build());
JobOption bigQueryRetryConfigOption =
JobOption.bigQueryRetryConfig(
BigQueryRetryConfig.newBuilder()
.retryOnMessage(BigQueryErrorMessages.RATE_LIMIT_EXCEEDED_MSG)
.retryOnMessage(BigQueryErrorMessages.JOB_RATE_LIMIT_EXCEEDED_MSG)
.retryOnRegEx(BigQueryErrorMessages.RetryRegExPatterns.RATE_LIMIT_EXCEEDED_REGEX)
.build());

Map<BigQueryRpc.Option, ?> bigQueryRpcOptions = optionMap(bigQueryRetryConfigOption);
when(bigqueryRpcMock.create(jobCapture.capture(), eq(bigQueryRpcOptions)))
Expand All @@ -1619,21 +1622,20 @@ public void testCreateJobWithBigQueryRetryConfigFailureShouldRetry() {
.build()
.getService();

((BigQueryImpl) bigquery).create(JobInfo.of(QUERY_JOB_CONFIGURATION_FOR_DMLQUERY), bigQueryRetryConfigOption);
((BigQueryImpl) bigquery)
.create(JobInfo.of(QUERY_JOB_CONFIGURATION_FOR_DMLQUERY), bigQueryRetryConfigOption);
verify(bigqueryRpcMock, times(3)).create(jobCapture.capture(), eq(bigQueryRpcOptions));
}

@Test
public void testCreateJobWithBigQueryRetryConfigFailureShouldNotRetry() {
// Validate create job with BigQueryRetryConfig that does not retry on rate limit error message.
JobOption bigQueryRetryConfigOption = JobOption.bigQueryRetryConfig(BigQueryRetryConfig.newBuilder()
.build());
JobOption bigQueryRetryConfigOption =
JobOption.bigQueryRetryConfig(BigQueryRetryConfig.newBuilder().build());

Map<BigQueryRpc.Option, ?> bigQueryRpcOptions = optionMap(bigQueryRetryConfigOption);
when(bigqueryRpcMock.create(jobCapture.capture(), eq(bigQueryRpcOptions)))
.thenThrow(
new BigQueryException(
400, RATE_LIMIT_ERROR_MSG));
.thenThrow(new BigQueryException(400, RATE_LIMIT_ERROR_MSG));

bigquery = options.getService();
bigquery =
Expand All @@ -1644,7 +1646,8 @@ public void testCreateJobWithBigQueryRetryConfigFailureShouldNotRetry() {
.getService();

try {
((BigQueryImpl) bigquery).create(JobInfo.of(QUERY_JOB_CONFIGURATION_FOR_DMLQUERY), bigQueryRetryConfigOption);
((BigQueryImpl) bigquery)
.create(JobInfo.of(QUERY_JOB_CONFIGURATION_FOR_DMLQUERY), bigQueryRetryConfigOption);
fail("JobException expected");
} catch (BigQueryException e) {
assertNotNull(e.getMessage());
Expand Down Expand Up @@ -1673,7 +1676,8 @@ public void testCreateJobWithRetryOptionsFailureShouldRetry() {
.build()
.getService();

((BigQueryImpl) bigquery).create(JobInfo.of(QUERY_JOB_CONFIGURATION_FOR_DMLQUERY), retryOptions);
((BigQueryImpl) bigquery)
.create(JobInfo.of(QUERY_JOB_CONFIGURATION_FOR_DMLQUERY), retryOptions);
verify(bigqueryRpcMock, times(4)).create(jobCapture.capture(), eq(bigQueryRpcOptions));
}

Expand All @@ -1695,7 +1699,8 @@ public void testCreateJobWithRetryOptionsFailureShouldNotRetry() {
.getService();

try {
((BigQueryImpl) bigquery).create(JobInfo.of(QUERY_JOB_CONFIGURATION_FOR_DMLQUERY), retryOptions);
((BigQueryImpl) bigquery)
.create(JobInfo.of(QUERY_JOB_CONFIGURATION_FOR_DMLQUERY), retryOptions);
fail("JobException expected");
} catch (BigQueryException e) {
assertNotNull(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@
import com.google.cloud.bigquery.TimePartitioning.Type;
import com.google.cloud.bigquery.ViewDefinition;
import com.google.cloud.bigquery.WriteChannelConfiguration;
import com.google.cloud.bigquery.spi.v2.BigQueryRpc;
import com.google.cloud.bigquery.testing.RemoteBigQueryHelper;
import com.google.cloud.datacatalog.v1.CreatePolicyTagRequest;
import com.google.cloud.datacatalog.v1.CreateTaxonomyRequest;
Expand Down Expand Up @@ -5282,8 +5281,10 @@ public void testCreateAndGetJob() throws InterruptedException, TimeoutException
}

@Test
public void testCreateJobAndWaitForWithRetryOptions() throws InterruptedException, TimeoutException {
// Note: This only tests the non failure/retry case. For retry cases, see unit tests with mocked RPC calls.
public void testCreateJobAndWaitForWithRetryOptions()
throws InterruptedException, TimeoutException {
// Note: This only tests the non failure/retry case. For retry cases, see unit tests with mocked
// RPC calls.
QueryJobConfiguration config =
QueryJobConfiguration.newBuilder("SELECT CURRENT_TIMESTAMP() as ts")
.setDefaultDataset(DATASET)
Expand Down

0 comments on commit a2f073b

Please sign in to comment.