From 79c4eead9f9224c2e94c874ad2434d26d4a043fd Mon Sep 17 00:00:00 2001 From: Praful Makani Date: Fri, 18 Jan 2019 14:41:18 +0530 Subject: [PATCH] added comment and modified methods name --- .../main/java/com/google/cloud/bigquery/BigQueryImpl.java | 7 ++++--- .../java/com/google/cloud/bigquery/BigQueryOptions.java | 1 + .../java/com/google/cloud/bigquery/BigQueryImplTest.java | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java index 7483051b760e..40206e09996a 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java @@ -16,6 +16,7 @@ package com.google.cloud.bigquery; +import static java.net.HttpURLConnection.HTTP_NOT_FOUND; import static com.google.cloud.RetryHelper.runWithRetries; import static com.google.common.base.Preconditions.checkArgument; @@ -294,7 +295,7 @@ public com.google.api.services.bigquery.model.Dataset call() { EXCEPTION_HANDLER, getOptions().getClock()); if (getOptions().getThrowNotFound() && answer == null) { - throw new BigQueryException(404, "Dataset not found"); + throw new BigQueryException(HTTP_NOT_FOUND, "Dataset not found"); } return answer == null ? null : Dataset.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { @@ -486,7 +487,7 @@ public com.google.api.services.bigquery.model.Table call() { EXCEPTION_HANDLER, getOptions().getClock()); if (getOptions().getThrowNotFound() && answer == null) { - throw new BigQueryException(404, "Table not found"); + throw new BigQueryException(HTTP_NOT_FOUND, "Table not found"); } return answer == null ? null : Table.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { @@ -703,7 +704,7 @@ public com.google.api.services.bigquery.model.Job call() { EXCEPTION_HANDLER, getOptions().getClock()); if (getOptions().getThrowNotFound() && answer == null) { - throw new BigQueryException(404, "Job not found"); + throw new BigQueryException(HTTP_NOT_FOUND, "Job not found"); } return answer == null ? null : Job.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryOptions.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryOptions.java index 9119ed14315f..3b49a20fdf07 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryOptions.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryOptions.java @@ -33,6 +33,7 @@ public class BigQueryOptions extends ServiceOptions { private static final String BIGQUERY_SCOPE = "https://www.googleapis.com/auth/bigquery"; private static final Set SCOPES = ImmutableSet.of(BIGQUERY_SCOPE); private static final long serialVersionUID = -2437598817433266049L; + // set the option ThrowNotFound when you want to throw the exception when the value not found private boolean setThrowNotFound; public static class DefaultBigQueryFactory implements BigQueryFactory { diff --git a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java index 0a1b4bc88354..0d1e46cc6ed9 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java +++ b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java @@ -356,7 +356,7 @@ public void testGetDataset() { } @Test - public void testGetDatasetNotFound() { + public void testGetDatasetNotFoundWhenThrowIsEnabled() { EasyMock.expect(bigqueryRpcMock.getDataset(PROJECT, "dataset-not-found", EMPTY_RPC_OPTIONS)) .andThrow(new BigQueryException(404, "Dataset not found")); EasyMock.replay(bigqueryRpcMock); @@ -604,7 +604,7 @@ public void testGetTable() { } @Test - public void testGetTableNotFound() { + public void testGetTableNotFoundWhenThrowIsEnabled() { EasyMock.expect( bigqueryRpcMock.getTable(PROJECT, DATASET, "table-not-found", EMPTY_RPC_OPTIONS)) .andThrow(new BigQueryException(404, "Table not found")); @@ -1203,7 +1203,7 @@ public void testGetJob() { } @Test - public void testGetJobNotFound() { + public void testGetJobNotFoundWhenThrowIsEnabled() { EasyMock.expect(bigqueryRpcMock.getJob(PROJECT, "job-not-found", null, EMPTY_RPC_OPTIONS)) .andThrow(new BigQueryException(404, "Job not found")); EasyMock.replay(bigqueryRpcMock);