GcsUtil { @VisibleForTesting @Nullable Bucket getBucket(GcsPath path, BackOff backoff, Sleeper sleeper) throws IOException { Storage.Buckets.Get getBucket = storageClient.buckets().get(path.getBucket()); try { return ResilientOperation.retry( ResilientOperation.getGoogleRequestCallable(getBucket), backoff, new RetryDeterminer<IOException>() { @Override public boolean shouldRetry(IOException e) { if (errorExtractor.itemNotFound(e) || errorExtractor.accessDenied(e)) { return false; } return RetryDeterminer.SOCKET_ERRORS.shouldRetry(e); } }, IOException.class, sleeper); } catch (GoogleJsonResponseException e) { if (errorExtractor.accessDenied(e)) { throw new AccessDeniedException(path.toString(), null, e.getMessage()); } if (errorExtractor.itemNotFound(e)) { throw new FileNotFoundException(e.getMessage()); } throw e; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IOException( String.format( "Error while attempting to verify existence of bucket gs: e); } } private  GcsUtil(
      Storage storageClient,
      HttpRequestInitializer httpRequestInitializer,
      ExecutorService executorService,
      Boolean shouldUseGrpc,
      @Nullable Integer uploadBufferSizeBytes); static String getNonWildcardPrefix(String globExp); static boolean isWildcard(GcsPath spec); List<GcsPath> expand(GcsPath gcsPattern); long fileSize(GcsPath path); StorageObject getObject(GcsPath gcsPath); List<StorageObjectOrIOException> getObjects(List<GcsPath> gcsPaths); Objects listObjects(String bucket, String prefix, @Nullable String pageToken); Objects listObjects(
      String bucket, String prefix, @Nullable String pageToken, @Nullable String delimiter); SeekableByteChannel open(GcsPath path); WritableByteChannel create(GcsPath path, String type); WritableByteChannel create(GcsPath path, String type, Integer uploadBufferSizeBytes); boolean bucketAccessible(GcsPath path); long bucketOwner(GcsPath path); void createBucket(String projectId, Bucket bucket); void copy(Iterable<String> srcFilenames, Iterable<String> destFilenames); void remove(Collection<String> filenames);  }
@Test public void testGetBucket() 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()); when(mockStorage.buckets()).thenReturn(mockStorageObjects); when(mockStorageObjects.get("testbucket")).thenReturn(mockStorageGet); when(mockStorageGet.execute()) .thenThrow(new SocketTimeoutException("SocketException")) .thenReturn(new Bucket()); assertNotNull( gcsUtil.getBucket( GcsPath.fromComponents("testbucket", "testobject"), mockBackOff, new FastNanoClockAndSleeper())); }