Skip to content

Commit

Permalink
added comment and modified methods name
Browse files Browse the repository at this point in the history
  • Loading branch information
Praful Makani committed Jan 18, 2019
1 parent 9b5ede8 commit 79c4eea
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class BigQueryOptions extends ServiceOptions<BigQuery, BigQueryOptions> {
private static final String BIGQUERY_SCOPE = "https://www.googleapis.com/auth/bigquery";
private static final Set<String> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 79c4eea

Please sign in to comment.