java.util.concurrent.ConcurrentHashMap.KeySetView#com.google.api.client.googleapis.json.GoogleJsonResponseException源码实例Demo

下面列出了java.util.concurrent.ConcurrentHashMap.KeySetView#com.google.api.client.googleapis.json.GoogleJsonResponseException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: camel-quarkus   文件: GoogleDriveResource.java
@Path("/read")
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response readFile(@QueryParam("fileId") String fileId) {
    try {
        File response = producerTemplate.requestBody("google-drive://drive-files/get?inBody=fileId", fileId, File.class);
        if (response != null) {
            return Response.ok(response.getTitle()).build();
        } else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    } catch (CamelExecutionException e) {
        Exception exchangeException = e.getExchange().getException();
        if (exchangeException != null && exchangeException.getCause() instanceof GoogleJsonResponseException) {
            GoogleJsonResponseException originalException = (GoogleJsonResponseException) exchangeException.getCause();
            return Response.status(originalException.getStatusCode()).build();
        }
        throw e;
    }
}
 
源代码2 项目: camel-quarkus   文件: GoogleCalendarResource.java
@Path("/read")
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response readCalendar(@QueryParam("calendarId") String calendarId) {
    try {
        Calendar response = producerTemplate.requestBody("google-calendar://calendars/get?inBody=calendarId", calendarId,
                Calendar.class);
        if (response != null) {
            return Response.ok(response.getSummary()).build();
        } else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    } catch (CamelExecutionException e) {
        Exception exchangeException = e.getExchange().getException();
        if (exchangeException != null && exchangeException.getCause() instanceof GoogleJsonResponseException) {
            GoogleJsonResponseException originalException = (GoogleJsonResponseException) exchangeException.getCause();
            return Response.status(originalException.getStatusCode()).build();
        }
        throw e;
    }
}
 
源代码3 项目: camel-quarkus   文件: GoogleCalendarResource.java
@Path("/read/event")
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response readCalendarEvent(@QueryParam("calendarId") String calendarId, @QueryParam("eventId") String eventId) {
    Map<String, Object> headers = new HashMap<>();
    headers.put("CamelGoogleCalendar.calendarId", calendarId);
    headers.put("CamelGoogleCalendar.eventId", eventId);
    try {
        Event response = producerTemplate.requestBodyAndHeaders("google-calendar://events/get", null, headers, Event.class);
        if (response != null) {
            return Response.ok(response.getSummary()).build();
        } else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    } catch (CamelExecutionException e) {
        Exception exchangeException = e.getExchange().getException();
        if (exchangeException != null && exchangeException.getCause() instanceof GoogleJsonResponseException) {
            GoogleJsonResponseException originalException = (GoogleJsonResponseException) exchangeException.getCause();
            return Response.status(originalException.getStatusCode()).build();
        }
        throw e;
    }
}
 
源代码4 项目: connector-sdk   文件: RepositoryDoc.java
private static Optional<RepositoryError> getRepositoryErrorForResponseException(
    IOException exception) {
  if (!(exception instanceof GoogleJsonResponseException)) {
    return Optional.empty();
  }
  GoogleJsonResponseException responseException = (GoogleJsonResponseException) exception;

  if (responseException.getStatusCode() == HTTP_NOT_FOUND
      || responseException.getStatusCode() == HTTP_BAD_REQUEST) {
    return Optional.empty();
  }
  return Optional.of(
      new RepositoryError()
          .setErrorMessage(responseException.getMessage())
          .setType("SERVER_ERROR")
          .setHttpStatusCode(responseException.getStatusCode()));
}
 
源代码5 项目: flo   文件: BigQueryTasksTest.java
@Test
public void lookupLatestDailyShouldBeRunnable() throws Exception {
  final Future<TableId> future = FloRunner.runTask(BigQueryTasks.lookupLatestDaily(
      "foo", "bar", "baz", Date.parse("2018-01-01"), 7)).future();

  try {
    future.get();
    fail("Did not expect to find a non-existent table");
  } catch (ExecutionException e) {
    // Verify that we are getting some well known error here so we know with some
    // certainty that we didn't get a serialization error. Yes, this is quite awful.
    final Throwable rootCause = Throwables.getRootCause(e);
    if (rootCause instanceof NotReady) {
      // Seems we had working credentials and the lookup worked. We're done here.
    } else if (rootCause instanceof GoogleJsonResponseException) {
      // Seems we managed to make a request, so the lookup executed. We're done here.
    } else if (rootCause instanceof IllegalArgumentException &&
        rootCause.getMessage().startsWith("A project ID is required")) {
      // Seems we managed to get as far as trying to instantiate the BigQuery client (in the task process).
      // We're done here.
    } else {
      // Not sure what went wrong here, might be serialization error, so be conservative and fail here.
      throw e;
    }
  }
}
 
源代码6 项目: pubsub   文件: GCEComputeResourceController.java
@Override
protected void stopAction() throws Exception {
  log.info("Cleaning up compute resource_controllers.");
  compute.instanceGroupManagers().delete(project, params.getZone(), instanceName()).execute();
  boolean managerExists = true;
  while (managerExists) {
    try {
      compute.instanceGroupManagers().get(project, params.getZone(), instanceName()).execute();
    } catch (GoogleJsonResponseException e) {
      if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
        managerExists = false;
      } else {
        throw e;
      }
    }
    Thread.sleep(1000);
  }
  compute.instanceTemplates().delete(project, instanceName());
  log.info("Cleaned up compute resource_controllers.");
}
 
源代码7 项目: connector-sdk   文件: RepositoryDocTest.java
@Test(expected = IOException.class)
public void execute_indexItemNotFound_notPushedToQueue_throwsIOException() throws Exception {
  Item item = new Item().setName("id1").setAcl(getCustomerAcl());
  RepositoryDoc doc = new RepositoryDoc.Builder().setItem(item).build();
  doAnswer(
          invocation -> {
            SettableFuture<Operation> updateFuture = SettableFuture.create();
            updateFuture.setException(
                new GoogleJsonResponseException(
                    new HttpResponseException.Builder(
                        HTTP_NOT_FOUND, "not found", new HttpHeaders()),
                    new GoogleJsonError()));
            return updateFuture;
          })
      .when(mockIndexingService)
      .indexItem(item, RequestMode.UNSPECIFIED);
  try {
    doc.execute(mockIndexingService);
  } finally {
    InOrder inOrder = inOrder(mockIndexingService);
    inOrder.verify(mockIndexingService).indexItem(item, RequestMode.UNSPECIFIED);
    inOrder.verifyNoMoreInteractions();
    assertEquals("id1", doc.getItem().getName());
  }
}
 
@Override
public void execute() throws IOException {
  try {
    ProductStatus productStatus =
        content
            .productstatuses()
            .get(this.config.getMerchantId(), ExampleProductFactory.sampleProductId())
            .execute();
    ProductstatusUtils.printProductStatus(productStatus);
  } catch (GoogleJsonResponseException e) {
    if (e.getDetails().getCode() == 404) {
      System.out.println(
          "The item was not found. Try running "
              + "shopping.content.v2.samples.products.ProductInsertSample first.");
    } else {
      checkGoogleJsonResponseException(e);
    }
  }
}
 
源代码9 项目: connector-sdk   文件: AsyncRequest.java
/**
 * Wrapper on {@link JsonBatchCallback#onFailure} to record failure while executing batched
 * request.
 */
@Override
public void onFailure(GoogleJsonError error, HttpHeaders responseHeaders) {
  if (event != null) {
    event.failure();
    event = null;
  } else {
    operationStats.event(request.requestToExecute.getClass().getName()).failure();
  }
  logger.log(Level.WARNING, "Request failed with error {0}", error);
  if (request.retryPolicy.isRetryableStatusCode(error.getCode())) {
    if (request.getRetries() < request.retryPolicy.getMaxRetryLimit()) {
      request.setStatus(Status.RETRYING);
      request.incrementRetries();
      return;
    }
  }
  GoogleJsonResponseException exception =
      new GoogleJsonResponseException(
          new Builder(error.getCode(), error.getMessage(), responseHeaders), error);
  fail(exception);
}
 
源代码10 项目: connector-sdk   文件: TestUtils.java
/**
 * Waits for the item with the given ID to be deleted.
 *
 * @throws org.awaitility.core.ConditionTimeoutException if the item is not deleted before the
 *     timeout
 */
// TODO(jlacey): Resolve this one-off to support the verifier repository (as of commit 20b0d95)
// into a consistent design.
public void waitUntilDeleted(String itemId, Duration timeout, Duration pollInterval) {
  Awaitility.await()
      .atMost(timeout)
      .pollInterval(pollInterval)
      .until(() -> {
        try {
          service.getItem(itemId);
          return false;
        } catch (GoogleJsonResponseException e) {
          if (e.getStatusCode() == HTTP_NOT_FOUND) {
            return true;
          }
          throw e;
        }
      });
}
 
@Test
public void registerMetric_rethrowsException() throws Exception {
  ByteArrayInputStream inputStream = new ByteArrayInputStream("".getBytes(UTF_8));
  HttpResponse response = GoogleJsonResponseExceptionHelper.createHttpResponse(400, inputStream);
  HttpResponseException.Builder httpResponseExceptionBuilder =
      new HttpResponseException.Builder(response);
  httpResponseExceptionBuilder.setStatusCode(404);
  GoogleJsonResponseException exception =
      new GoogleJsonResponseException(httpResponseExceptionBuilder, null);
  when(metricDescriptorCreate.execute()).thenThrow(exception);
  StackdriverWriter writer =
      new StackdriverWriter(client, PROJECT, MONITORED_RESOURCE, MAX_QPS, MAX_POINTS_PER_REQUEST);

  assertThrows(GoogleJsonResponseException.class, () -> writer.registerMetric(metric));
  assertThat(exception.getStatusCode()).isEqualTo(404);
}
 
源代码12 项目: flo   文件: BigQueryTasksTest.java
@Test
public void lookupShouldBeRunnable() throws Exception {
  final Future<TableId> future = FloRunner.runTask(BigQueryTasks.lookup(
      "non-existent-project", "non-existent-dataset", "non-existent-table")).future();

  try {
    future.get();
    fail("Did not expect to find a non-existent table");
  } catch (ExecutionException e) {
    // Verify that we are getting some well known error here so we know with some
    // certainty that we didn't get a serialization error. Yes, this is quite awful.
    final Throwable rootCause = Throwables.getRootCause(e);
    if (rootCause instanceof NotReady) {
      // Seems we had working credentials and the lookup worked. We're done here.
    } else if (rootCause instanceof GoogleJsonResponseException) {
      // Seems we managed to make a request, so the lookup executed. We're done here.
    } else if (rootCause instanceof IllegalArgumentException &&
        rootCause.getMessage().startsWith("A project ID is required")) {
      // Seems we managed to get as far as trying to instantiate the BigQuery client (in the task process).
      // We're done here.
    } else {
      // Not sure what went wrong here, might be serialization error, so be conservative and fail here.
      throw e;
    }
  }
}
 
源代码13 项目: digdag   文件: BqDdlOperatorFactory.java
@Override
protected TaskResult run(BqClient bq, String projectId)

{
    List<BqOperation> operations = Stream.of(
            params.getListOrEmpty("delete_datasets", JsonNode.class).stream().map(this::deleteDataset),
            params.getListOrEmpty("empty_datasets", JsonNode.class).stream().map(this::emptyDataset),
            params.getListOrEmpty("create_datasets", JsonNode.class).stream().map(this::createDataset),
            params.getListOrEmpty("delete_tables", JsonNode.class).stream().map(this::deleteTable),
            params.getListOrEmpty("empty_tables", JsonNode.class).stream().map(this::emptyTable),
            params.getListOrEmpty("create_tables", JsonNode.class).stream().map(this::createTable))
            .flatMap(s -> s)
            .collect(Collectors.toList());

    int operation = state.params().get("operation", int.class, 0);
    for (int i = operation; i < operations.size(); i++) {
        state.params().set("operation", i);
        BqOperation o = operations.get(i);
        pollingRetryExecutor(state, "request")
                .retryUnless(GoogleJsonResponseException.class, Gcp::isDeterministicException)
                .withErrorMessage("BiqQuery DDL operation failed")
                .runAction(s -> o.perform(bq, projectId));
    }

    return TaskResult.empty(request);
}
 
public static void main(String[] args) throws IOException {
  CommandLine parsedArgs = BaseOption.parseOptions(args);
  File configPath = null;
  if (!NO_CONFIG.isSet(parsedArgs)) {
    configPath = BaseOption.checkedConfigPath(parsedArgs);
  }
  ContentConfig config = ContentConfig.load(configPath);

  ShoppingContent.Builder builder = createStandardBuilder(parsedArgs, config);
  ShoppingContent content = createService(builder);
  ShoppingContent sandbox = createSandboxContentService(builder);
  retrieveConfiguration(content, config);

  try {
    new ShippingsettingsWorkflow(content, sandbox, config).execute();
  } catch (GoogleJsonResponseException e) {
    checkGoogleJsonResponseException(e);
  }
}
 
源代码15 项目: policyscanner   文件: GCSFilesSource.java
/**
 * Constructor for GCSFileSource.
 * @param bucket The bucket where the configuration files reside.
 * @param repository The root directory where the files reside.
 * @throws GeneralSecurityException Thrown if there's a permissions error using the GCS API.
 * @throws IOException Thrown if there's a IO error using the GCS API.
 */
public GCSFilesSource(String bucket, String repository)
    throws GeneralSecurityException, IOException {
  this.bucket = bucket;
  this.repository = repository;

  try {
    // test that the bucket actually exists.
    getStorageApiStub().buckets().get(bucket).execute();
  } catch (GoogleJsonResponseException gjre) {
    String msgFormat = new StringBuilder()
        .append("Can't access bucket \"gs://%s\".\n\n")
        .append("1. Check that your appengine-web.xml has the correct environment variables.\n")
        .append("2. Check your project IAM settings: the Compute Engine service account should\n")
        .append("   have Editor access (or at least Storage Object Creator) if you're running\n")
        .append("   on production. If you are running this locally, your user account or group\n")
        .append("   should be granted Storage Object Creator.\n")
        .append("3. Try re-authing your application-default credentials with this command:\n\n")
        .append("   $ gcloud auth application-default login\n\n")
        .append("More details:\n%s").toString();
    String message = String.format(msgFormat, bucket, gjre.getContent());
    throw new BucketAccessException(message);
  }
}
 
public static void main(String[] args) throws IOException {
  CommandLine parsedArgs = BaseOption.parseOptions(args);
  File configPath = null;
  if (!NO_CONFIG.isSet(parsedArgs)) {
    configPath = BaseOption.checkedConfigPath(parsedArgs);
  }
  ContentConfig config = ContentConfig.load(configPath);

  ShoppingContent.Builder builder = createStandardBuilder(parsedArgs, config);
  ShoppingContent content = createService(builder);
  ShoppingContent sandbox = createSandboxContentService(builder);
  retrieveConfiguration(content, config);

  try {
    new AccountWorkflow(content, sandbox, config).execute();
  } catch (GoogleJsonResponseException e) {
    checkGoogleJsonResponseException(e);
  }
}
 
源代码17 项目: science-journal   文件: GoogleDriveApiImpl.java
@Override
public boolean getFileExists(String fileId) throws IOException {
  try {
    File file =
        driveApi
            .files()
            .get(fileId)
            .execute();
    if (file == null || file.getLabels() == null) {
      return false;
    }
    return !file.getLabels().getTrashed();
  } catch (GoogleJsonResponseException e) {
    // Drive will return a GoogleJsonResponseException if the file is not found.
    return false;
  }
}
 
源代码18 项目: styx   文件: Authenticator.java
private boolean resolveProjectAccess(String projectId) throws IOException {
  final GetAncestryResponse ancestry;
  var request = cloudResourceManager.projects().getAncestry(projectId, new GetAncestryRequest());
  try {
    ancestry = executeWithRetries(request, retryWaitStrategy, retryStopStrategy);
  } catch (GoogleJsonResponseException e) {
    if (e.getStatusCode() == 404) {
      logger.debug("Project {} doesn't exist", projectId, e);
      return false;
    }

    logger.info("Cannot get project with id {}", projectId, e);
    return false;
  }
  if (ancestry.getAncestor() == null) {
    return false;
  }
  return resolveAccess(ancestry.getAncestor());
}
 
@Override
public void execute() throws IOException {
  try {
    ShippingSettings newSettings = ExampleShippingSettingsFactory.create();

    content
        .shippingsettings()
        .update(config.getMerchantId(), config.getMerchantId(), newSettings)
        .execute();
    ShippingSettings response =
        content.shippingsettings().get(config.getMerchantId(), config.getMerchantId()).execute();
    System.out.println("Set the following shipping information:");
    ShippingsettingsUtils.printShippingSettings(response);
  } catch (GoogleJsonResponseException e) {
    checkGoogleJsonResponseException(e);
  }
}
 
源代码20 项目: nomulus   文件: UpdateSnapshotViewAction.java
private static void updateTable(Bigquery bigquery, Table table) throws IOException {
  TableReference ref = table.getTableReference();
  try {
    bigquery
        .tables()
        .update(ref.getProjectId(), ref.getDatasetId(), ref.getTableId(), table)
        .execute();
  } catch (GoogleJsonResponseException e) {
    if (e.getDetails() != null && e.getDetails().getCode() == 404) {
      bigquery.tables().insert(ref.getProjectId(), ref.getDatasetId(), table).execute();
    } else {
      logger.atWarning().withCause(e).log(
          "UpdateSnapshotViewAction failed, caught exception %s", e.getDetails());
    }
  }
}
 
@Test
public void shouldHandleTooManyKeysCreated() throws IOException {
  when(serviceAccountKeyManager.serviceAccountExists(anyString())).thenReturn(true);

  final GoogleJsonResponseException resourceExhausted = new GoogleJsonResponseException(
      new HttpResponseException.Builder(429, "RESOURCE_EXHAUSTED", new HttpHeaders()),
      new GoogleJsonError().set("status", "RESOURCE_EXHAUSTED"));

  doThrow(resourceExhausted).when(serviceAccountKeyManager).createJsonKey(any());
  doThrow(resourceExhausted).when(serviceAccountKeyManager).createP12Key(any());

  exception.expect(InvalidExecutionException.class);
  exception.expectMessage(String.format(
      "Maximum number of keys on service account reached: %s. Styx requires 4 keys to operate.",
      SERVICE_ACCOUNT));

  sut.ensureServiceAccountKeySecret(WORKFLOW_ID.toString(), SERVICE_ACCOUNT);
}
 
源代码22 项目: beam   文件: PubsubHelper.java
/**
 * Create a topic from short name. Delete it if it already exists. Ensure the topic will be
 * deleted on cleanup. Return full topic name.
 */
public TopicPath createTopic(String shortTopic) throws IOException {
  TopicPath topic = PubsubClient.topicPathFromName(project, shortTopic);
  while (true) {
    try {
      NexmarkUtils.console("create topic %s", topic);
      pubsubClient.createTopic(topic);
      createdTopics.add(topic);
      return topic;
    } catch (GoogleJsonResponseException ex) {
      NexmarkUtils.console("attempting to cleanup topic %s", topic);
      pubsubClient.deleteTopic(topic);
      try {
        if (!BackOffUtils.next(sleeper, backOff)) {
          NexmarkUtils.console("too many retries for creating topic %s", topic);
          throw ex;
        }
      } catch (InterruptedException in) {
        throw new IOException(in);
      }
    }
  }
}
 
源代码23 项目: digdag   文件: BqClient.java
void createTable(String projectId, Table table)
        throws IOException
{
    String datasetId = table.getTableReference().getDatasetId();
    try {
        client.tables().insert(projectId, datasetId, table)
                .execute();
    }
    catch (GoogleJsonResponseException e) {
        if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_CONFLICT) {
            logger.debug("Table already exists: {}:{}.{}", projectId, datasetId, table.getTableReference().getTableId());
        }
        else {
            throw e;
        }
    }
}
 
protected <T extends GenericJson> T retryFailures(
    AbstractGoogleClientRequest<T> request, BackOff backOff) throws IOException {
  while (true) {
    try {
      return request.execute();
    } catch (GoogleJsonResponseException e) {
      try {
        long nextPause = backOff.nextBackOffMillis();
        if (nextPause == BackOff.STOP) {
          throw e;
        }
        System.out.printf("Operation failed, retrying in %f seconds.%n", nextPause / 1000.0);
        BackOffUtils.next(Sleeper.DEFAULT, backOff);
      } catch (InterruptedException ie) {
        // Just go straight into retry if interrupted.
      }
    }
  }
}
 
源代码25 项目: eip   文件: PubSubWrapper.java
/**
 * Sets up a subscription to projects/<code>appName</code>/subscriptions/<code>subName</code>.
 * Ignores error if the subscription already exists.
 * <p/>
 * See <a href="https://cloud.google.com/pubsub/subscriber">cloud.google.com/pubsub/subscriber</a>
 */
Subscription subscribeTopic(String subscriptionName, String topicName) throws IOException {
    String sub = getSubscription(subscriptionName);
    Subscription subscription = new Subscription()
            .setName(sub)
            .setAckDeadlineSeconds(15)
            .setTopic(getTopic(topicName));
    try {
        return pubsub.projects().subscriptions().create(sub, subscription).execute();
    } catch (GoogleJsonResponseException e) {
        if (e.getStatusCode() == HttpURLConnection.HTTP_CONFLICT) {
            return subscription;
        } else {
            throw e;
        }
    }
}
 
public static void main(String[] args) throws IOException {
  CommandLine parsedArgs = BaseOption.parseOptions(args);
  File configPath = null;
  if (!NO_CONFIG.isSet(parsedArgs)) {
    configPath = BaseOption.checkedConfigPath(parsedArgs);
  }
  ContentConfig config = ContentConfig.load(configPath);

  ShoppingContent.Builder builder = createStandardBuilder(parsedArgs, config);
  ShoppingContent content = createService(builder);
  ShoppingContent sandbox = createSandboxContentService(builder);
  retrieveConfiguration(content, config);

  try {
    new ProductsWorkflow(content, sandbox, config).execute();
  } catch (GoogleJsonResponseException e) {
    checkGoogleJsonResponseException(e);
  }
}
 
public static void main(String[] args) throws IOException {
  CommandLine parsedArgs = BaseOption.parseOptions(args);
  File configPath = null;
  if (!NO_CONFIG.isSet(parsedArgs)) {
    configPath = BaseOption.checkedConfigPath(parsedArgs);
  }
  ContentConfig config = ContentConfig.load(configPath);

  ShoppingContent.Builder builder = createStandardBuilder(parsedArgs, config);
  ShoppingContent content = createService(builder);
  ShoppingContent sandbox = createSandboxContentService(builder);
  retrieveConfiguration(content, config);

  try {
    new ProductstatusesWorkflow(content, sandbox, config).execute();
  } catch (GoogleJsonResponseException e) {
    checkGoogleJsonResponseException(e);
  }
}
 
public static GoogleJsonResponseException createJsonResponseException(
    GoogleJsonError e, HttpHeaders responseHeaders) {
  if (e != null) {
    return new GoogleJsonResponseException(
        new HttpResponseException.Builder(e.getCode(), e.getMessage(), responseHeaders), e);
  }
  return null;
}
 
源代码29 项目: digdag   文件: BqClient.java
void deleteTable(String projectId, String datasetId, String tableId)
        throws IOException
{
    try {
        client.tables().delete(projectId, datasetId, tableId).execute();
    }
    catch (GoogleJsonResponseException e) {
        if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
            // Already deleted
            return;
        }
        throw e;
    }
}
 
源代码30 项目: beam   文件: GcsUtilTest.java
@Test
public void testBucketDoesNotExistBecauseOfAccessError() throws IOException {
  GcsOptions pipelineOptions = gcsOptionsWithTestCredential();
  GcsUtil gcsUtil = pipelineOptions.getGcsUtil();

  Storage mockStorage = Mockito.mock(Storage.class);
  gcsUtil.setStorageClient(mockStorage);

  Storage.Buckets mockStorageObjects = Mockito.mock(Storage.Buckets.class);
  Storage.Buckets.Get mockStorageGet = Mockito.mock(Storage.Buckets.Get.class);

  BackOff mockBackOff = BackOffAdapter.toGcpBackOff(FluentBackoff.DEFAULT.backoff());
  GoogleJsonResponseException expectedException =
      googleJsonResponseException(
          HttpStatusCodes.STATUS_CODE_FORBIDDEN,
          "Waves hand mysteriously",
          "These aren't the buckets you're looking for");

  when(mockStorage.buckets()).thenReturn(mockStorageObjects);
  when(mockStorageObjects.get("testbucket")).thenReturn(mockStorageGet);
  when(mockStorageGet.execute()).thenThrow(expectedException);

  assertFalse(
      gcsUtil.bucketAccessible(
          GcsPath.fromComponents("testbucket", "testobject"),
          mockBackOff,
          new FastNanoClockAndSleeper()));
}