.setCredentials(ServiceAccountCredentials.fromStream(keyStream)) .setProjectId(projectId) .setRetrySettings(retrySettings()) .setTransportOptions(transportOptions) .build();
@Test public void testRuntimeException() { String exceptionMessage = "Artificial runtime exception"; EasyMock.expect(bigqueryRpcMock.getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) .andThrow(new RuntimeException(exceptionMessage)); EasyMock.replay(bigqueryRpcMock); bigquery = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); thrown.expect(BigQueryException.class); thrown.expectMessage(exceptionMessage); bigquery.getDataset(DATASET); }
@Test public void testRetryableException() { EasyMock.expect(bigqueryRpcMock.getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) .andThrow(new BigQueryException(500, "InternalError")) .andReturn(DATASET_INFO_WITH_PROJECT.toPb()); EasyMock.replay(bigqueryRpcMock); bigquery = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); Dataset dataset = bigquery.getDataset(DATASET); assertEquals( new Dataset(bigquery, new DatasetInfo.BuilderImpl(DATASET_INFO_WITH_PROJECT)), dataset); }
.setCredentials(ServiceAccountCredentials.fromStream(keyStream)) .setProjectId(projectId) .setRetrySettings(retrySettings()) .setTransportOptions(transportOptions) .build();
/** * Creates a {@code RemoteBigQueryHelper} object using default project id and authentication * credentials. */ public static RemoteBigQueryHelper create() { HttpTransportOptions transportOptions = BigQueryOptions.getDefaultHttpTransportOptions(); transportOptions = transportOptions .toBuilder() .setConnectTimeout(connectTimeout) .setReadTimeout(connectTimeout) .build(); BigQueryOptions bigqueryOptions = BigQueryOptions.newBuilder() .setRetrySettings(retrySettings()) .setTransportOptions(transportOptions) .build(); return new RemoteBigQueryHelper(bigqueryOptions); }
options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService();
options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService();
/** * Creates a {@code RemoteBigQueryHelper} object using default project id and authentication * credentials. */ public static RemoteBigQueryHelper create() { HttpTransportOptions transportOptions = BigQueryOptions.getDefaultHttpTransportOptions(); transportOptions = transportOptions .toBuilder() .setConnectTimeout(connectTimeout) .setReadTimeout(connectTimeout) .build(); BigQueryOptions bigqueryOptions = BigQueryOptions.newBuilder() .setRetrySettings(retrySettings()) .setTransportOptions(transportOptions) .build(); return new RemoteBigQueryHelper(bigqueryOptions); }
@Test public void testNonRetryableException() { String exceptionMessage = "Not Implemented"; EasyMock.expect(bigqueryRpcMock.getDataset(PROJECT, DATASET, EMPTY_RPC_OPTIONS)) .andThrow(new BigQueryException(501, exceptionMessage)); EasyMock.replay(bigqueryRpcMock); bigquery = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); thrown.expect(BigQueryException.class); thrown.expectMessage(exceptionMessage); bigquery.getDataset(DatasetId.of(DATASET)); }
@Override protected BigQueryOptions getServiceOptions(ProcessContext context, GoogleCredentials credentials) { final String projectId = context.getProperty(PROJECT_ID).evaluateAttributeExpressions().getValue(); final Integer retryCount = Integer.valueOf(context.getProperty(RETRY_COUNT).getValue()); final BigQueryOptions.Builder builder = BigQueryOptions.newBuilder(); if (!StringUtils.isBlank(projectId)) { builder.setProjectId(projectId); } return builder.setCredentials(credentials) .setRetrySettings(RetrySettings.newBuilder().setMaxAttempts(retryCount).build()) .setTransportOptions(getTransportOptions(context)) .build(); }
@Test public void testQueryDryRun() throws Exception { // https://github.com/googleapis/google-cloud-java/issues/2479 EasyMock.replay(bigqueryRpcMock); thrown.expect(UnsupportedOperationException.class); options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService() .query(QueryJobConfiguration.newBuilder("foo").setDryRun(true).build()); } }
private BigQueryOptions createBigQueryOptionsForProjectWithLocation( String project, BigQueryRpcFactory rpcFactory) { return BigQueryOptions.newBuilder() .setProjectId(project) .setLocation(LOCATION) .setServiceRpcFactory(rpcFactory) .setRetrySettings(ServiceOptions.getNoRetrySettings()) .build(); }
private BigQueryOptions createBigQueryOptionsForProject( String project, BigQueryRpcFactory rpcFactory) { return BigQueryOptions.newBuilder() .setProjectId(project) .setServiceRpcFactory(rpcFactory) .setRetrySettings(ServiceOptions.getNoRetrySettings()) .build(); }