Class RemoteStorageHelper

java.lang.Object
com.google.cloud.storage.testing.RemoteStorageHelper

public class RemoteStorageHelper extends Object
Utility to create a remote storage configuration for testing. Storage options can be obtained via the getOptions() ()} method. Returned options have custom ServiceOptions.getRetrySettings(): RetrySettings.getMaxAttempts() is 10, RetrySettings.getMaxRetryDelay() is 30000, RetrySettings.getTotalTimeout() is 120000 and RetrySettings.getInitialRetryDelay() is 250. HttpTransportOptions.getConnectTimeout() and HttpTransportOptions.getReadTimeout() are both set to 60000.
  • Method Details

    • getOptions

      public StorageOptions getOptions()
      Returns a StorageOptions object to be used for testing.
    • cleanBuckets

      public static void cleanBuckets(Storage storage, long olderThan, long timeoutMs)
    • forceDelete

      public static Boolean forceDelete(Storage storage, String bucket, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException
      Deletes a bucket, even if non-empty. Objects in the bucket are listed and deleted until bucket deletion succeeds or timeout expires. To allow for the timeout, this method uses a separate thread to send the delete requests. Use forceDelete(Storage storage, String bucket) if spawning an additional thread is undesirable, such as in the App Engine production runtime.
      Parameters:
      storage - the storage service to be used to issue requests
      bucket - the bucket to be deleted
      timeout - the maximum time to wait
      unit - the time unit of the timeout argument
      Returns:
      true if deletion succeeded, false if timeout expired
      Throws:
      InterruptedException - if the thread deleting the bucket is interrupted while waiting
      ExecutionException - if an exception was thrown while deleting bucket or bucket objects
    • forceDelete

      public static Boolean forceDelete(Storage storage, String bucket, long timeout, TimeUnit unit, String userProject) throws InterruptedException, ExecutionException
      Deletes a bucket, even if non-empty. Objects in the bucket are listed and deleted until bucket deletion succeeds or timeout expires. To allow for the timeout, this method uses a separate thread to send the delete requests. Use forceDelete(Storage storage, String bucket) if spawning an additional thread is undesirable, such as in the App Engine production runtime.
      Parameters:
      storage - the storage service to be used to issue requests
      bucket - the bucket to be deleted
      timeout - the maximum time to wait
      unit - the time unit of the timeout argument
      userProject - the project to bill for requester-pays buckets (or "")
      Returns:
      true if deletion succeeded, false if timeout expired
      Throws:
      InterruptedException - if the thread deleting the bucket is interrupted while waiting
      ExecutionException - if an exception was thrown while deleting bucket or bucket objects
    • forceDelete

      public static void forceDelete(Storage storage, String bucket)
      Deletes a bucket, even if non-empty. This method blocks until the deletion completes or fails.
      Parameters:
      storage - the storage service to be used to issue requests
      bucket - the bucket to be deleted
      Throws:
      StorageException - if an exception is encountered during bucket deletion
    • generateBucketName

      public static String generateBucketName()
      Returns a bucket name generated using a random UUID.
    • create

      public static RemoteStorageHelper create(String projectId, InputStream keyStream) throws RemoteStorageHelper.StorageHelperException
      Creates a RemoteStorageHelper object for the given project id and JSON key input stream.
      Parameters:
      projectId - id of the project to be used for running the tests
      keyStream - input stream for a JSON key
      Returns:
      A RemoteStorageHelper object for the provided options
      Throws:
      RemoteStorageHelper.StorageHelperException - if keyStream is not a valid JSON key stream
    • create

      Creates a RemoteStorageHelper object using default project id and authentication credentials.
      Throws:
      RemoteStorageHelper.StorageHelperException