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

      @ObsoleteApi("This method is obsolete because of a potential security risk. Use the create() variant with Credential parameter instead") public static RemoteStorageHelper create(String projectId, InputStream keyStream) throws RemoteStorageHelper.StorageHelperException
      This method is obsolete because of a potential security risk. Use the create(String, GoogleCredentials) method instead.

      If you know that you will be loading credential configurations of a specific type, it is recommended to use a credential-type-specific `fromStream()` method. This will ensure that an unexpected credential type with potential for malicious intent is not loaded unintentionally. You might still have to do validation for certain credential types. Please follow the recommendation for that method.

      If you are loading your credential configuration from an untrusted source and have not mitigated the risks (e.g. by validating the configuration yourself), make these changes as soon as possible to prevent security risks to your environment.

      Regardless of the method used, it is always your responsibility to validate configurations received from external sources.

      See the for more details.

      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

      public static RemoteStorageHelper create(String projectId, com.google.auth.oauth2.GoogleCredentials credentials)
      Creates a RemoteStorageHelper object for the given project id and Credential.
      Parameters:
      projectId - id of the project to be used for running the tests
      credentials - GoogleCredential to set to StorageOptions
      Returns:
      A RemoteStorageHelper object for the provided options
    • create

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