private static BigQueryException translate(IOException exception) { return new BigQueryException(exception); }
static BaseServiceException translateAndThrow(ExecutionException ex) { BaseServiceException.translate(ex); throw new BigQueryException(UNKNOWN_CODE, ex.getMessage(), ex.getCause()); } }
/** * Translate RetryHelperException to the BigQueryException that caused the error. This method will * always throw an exception. * * @throws BigQueryException when {@code ex} was caused by a {@code BigQueryException} */ static BaseServiceException translateAndThrow(RetryHelperException ex) { BaseServiceException.translate(ex); throw new BigQueryException(UNKNOWN_CODE, ex.getMessage(), ex.getCause()); }
throw exception; throw new BigQueryException(code, message);
@Test public void testTranslateAndThrow() throws Exception { Exception cause = new BigQueryException(503, "message"); RetryHelperException exceptionMock = createMock(RetryHelperException.class); expect(exceptionMock.getCause()).andReturn(cause).times(2);
@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); }
@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)); }
@Test public void testCreateRetryableError() { BigQueryException exception = new BigQueryException(new SocketException("Socket closed")); expect( bigqueryRpcMock.open( new com.google.api.services.bigquery.model.Job() .setJobReference(JOB_INFO.getJobId().toPb()) .setConfiguration(LOAD_CONFIGURATION.toPb()))) .andThrow(exception); expect( bigqueryRpcMock.open( new com.google.api.services.bigquery.model.Job() .setJobReference(JOB_INFO.getJobId().toPb()) .setConfiguration(LOAD_CONFIGURATION.toPb()))) .andReturn(UPLOAD_ID); replay(bigqueryRpcMock); writer = new TableDataWriteChannel(options, JOB_INFO.getJobId(), LOAD_CONFIGURATION); assertTrue(writer.isOpen()); assertNull(writer.getJob()); }
@Test public void testCreateJobNoGet() { String id = "testCreateJobNoGet-id"; JobId jobId = JobId.of(id); String query = "SELECT * in FOO"; Capture<com.google.api.services.bigquery.model.Job> jobCapture = EasyMock.newCapture(); EasyMock.expect( bigqueryRpcMock.create(EasyMock.capture(jobCapture), EasyMock.eq(EMPTY_RPC_OPTIONS))) .andThrow(new BigQueryException(409, "already exists, for some reason")); EasyMock.replay(bigqueryRpcMock); bigquery = options.getService(); try { bigquery.create(JobInfo.of(jobId, QueryJobConfiguration.of(query))); fail("should throw"); } catch (BigQueryException e) { assertThat(jobCapture.getValue().getJobReference().getJobId()).isEqualTo(id); } }
static Entity fromPb(Access access) { if (access.getDomain() != null) { return new Domain(access.getDomain()); } if (access.getGroupByEmail() != null) { return new Group(access.getGroupByEmail()); } if (access.getSpecialGroup() != null) { return new Group(access.getSpecialGroup()); } if (access.getUserByEmail() != null) { return new User(access.getUserByEmail()); } if (access.getView() != null) { return new View(TableId.fromPb(access.getView())); } // Unreachable throw new BigQueryException( BigQueryException.UNKNOWN_CODE, "Unrecognized access configuration"); } }
@Test public void testCreateJobTryGet() { final String id = "testCreateJobTryGet-id"; String query = "SELECT * in FOO"; Supplier<JobId> idProvider = new Supplier<JobId>() { @Override public JobId get() { return JobId.of(id); } }; Capture<com.google.api.services.bigquery.model.Job> jobCapture = EasyMock.newCapture(); EasyMock.expect( bigqueryRpcMock.create(EasyMock.capture(jobCapture), EasyMock.eq(EMPTY_RPC_OPTIONS))) .andThrow(new BigQueryException(409, "already exists, for some reason")); EasyMock.expect( bigqueryRpcMock.getJob( anyString(), EasyMock.eq(id), EasyMock.eq((String) null), EasyMock.eq(EMPTY_RPC_OPTIONS))) .andReturn(newJobPb()); EasyMock.replay(bigqueryRpcMock); bigquery = options.getService(); ((BigQueryImpl) bigquery).create(JobInfo.of(QueryJobConfiguration.of(query)), idProvider); assertThat(jobCapture.getValue().getJobReference().getJobId()).isEqualTo(id); }
.setTemplateSuffix("suffix"); EasyMock.expect(bigqueryRpcMock.insertAll(PROJECT, DATASET, TABLE, requestPb)) .andThrow(new BigQueryException(500, "InternalError")); EasyMock.replay(bigqueryRpcMock); bigquery =
.setErrors(ImmutableList.of(new ErrorProto().setMessage("ErrorMessage"))))); EasyMock.expect(bigqueryRpcMock.insertAll(PROJECT, DATASET, TABLE, requestPb)) .andThrow(new BigQueryException(500, "InternalError")); EasyMock.expect(bigqueryRpcMock.insertAll(PROJECT, DATASET, TABLE, requestPb)) .andReturn(responsePb);
@Test public void testBigQueryException() { BigQueryException exception = new BigQueryException(500, "message"); assertEquals(500, exception.getCode()); assertEquals("message", exception.getMessage()); exception = new BigQueryException(502, "message"); assertEquals(502, exception.getCode()); assertEquals("message", exception.getMessage()); exception = new BigQueryException(503, "message"); assertEquals(503, exception.getCode()); assertEquals("message", exception.getMessage()); exception = new BigQueryException(504, "message"); assertEquals(504, exception.getCode()); assertEquals("message", exception.getMessage()); exception = new BigQueryException(400, "message"); assertEquals(400, exception.getCode()); assertEquals("message", exception.getMessage()); exception = new BigQueryException(504, "message", error); assertEquals(504, exception.getCode()); assertEquals("message", exception.getMessage()); exception = new BigQueryException(cause); assertEquals(BigQueryException.UNKNOWN_CODE, exception.getCode()); assertNull(exception.getReason());
private static BigQueryException translate(IOException exception) { return new BigQueryException(exception); }
private static BigQueryException translate(IOException exception) { return new BigQueryException(exception); }
static BaseServiceException translateAndThrow(ExecutionException ex) { BaseServiceException.translate(ex); throw new BigQueryException(UNKNOWN_CODE, ex.getMessage(), ex.getCause()); } }
/** * Translate RetryHelperException to the BigQueryException that caused the error. This method will * always throw an exception. * * @throws BigQueryException when {@code ex} was caused by a {@code BigQueryException} */ static BaseServiceException translateAndThrow(RetryHelperException ex) { BaseServiceException.translate(ex); throw new BigQueryException(UNKNOWN_CODE, ex.getMessage(), ex.getCause()); }
@Override public JobInfo job(JobInfo jobInfo, JobOption... options) { Job job = client.create(jobInfo, options); while (!job.isDone()) { try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } job = job.reload(); } final BigQueryError error = job.getStatus().getError(); if (error != null) { throw new BigQueryException(0, "BigQuery job failed: " + error); } return job; }
/** * Translate RetryHelperException to the BigQueryException that caused the error. This method will * always throw an exception. * * @throws BigQueryException when {@code ex} was caused by a {@code BigQueryException} * @throws RetryInterruptedException when {@code ex} is a {@code RetryInterruptedException} */ static BaseServiceException translateAndThrow(RetryHelperException ex) { BaseServiceException.translateAndPropagateIfPossible(ex); throw new BigQueryException(UNKNOWN_CODE, ex.getMessage(), ex.getCause()); } }