Package com.google.cloud.storage.testing
Class RemoteStorageHelper
java.lang.Object
com.google.cloud.storage.testing.RemoteStorageHelper
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.-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcleanBuckets(Storage storage, long olderThan, long timeoutMs) static RemoteStorageHelpercreate()Creates aRemoteStorageHelperobject using default project id and authentication credentials.static RemoteStorageHelpercreate(String projectId, InputStream keyStream) Creates aRemoteStorageHelperobject for the given project id and JSON key input stream.static voidforceDelete(Storage storage, String bucket) Deletes a bucket, even if non-empty.static BooleanforceDelete(Storage storage, String bucket, long timeout, TimeUnit unit) Deletes a bucket, even if non-empty.static BooleanforceDelete(Storage storage, String bucket, long timeout, TimeUnit unit, String userProject) Deletes a bucket, even if non-empty.static StringReturns a bucket name generated using a random UUID.Returns aStorageOptionsobject to be used for testing.
-
Method Details
-
getOptions
Returns aStorageOptionsobject to be used for testing. -
cleanBuckets
-
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 ortimeoutexpires. To allow for the timeout, this method uses a separate thread to send the delete requests. UseforceDelete(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 requestsbucket- the bucket to be deletedtimeout- the maximum time to waitunit- 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 waitingExecutionException- 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 ortimeoutexpires. To allow for the timeout, this method uses a separate thread to send the delete requests. UseforceDelete(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 requestsbucket- the bucket to be deletedtimeout- the maximum time to waitunit- the time unit of the timeout argumentuserProject- 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 waitingExecutionException- if an exception was thrown while deleting bucket or bucket objects
-
forceDelete
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 requestsbucket- the bucket to be deleted- Throws:
StorageException- if an exception is encountered during bucket deletion
-
generateBucketName
Returns a bucket name generated using a random UUID. -
create
public static RemoteStorageHelper create(String projectId, InputStream keyStream) throws RemoteStorageHelper.StorageHelperException Creates aRemoteStorageHelperobject for the given project id and JSON key input stream.- Parameters:
projectId- id of the project to be used for running the testskeyStream- input stream for a JSON key- Returns:
- A
RemoteStorageHelperobject for the provided options - Throws:
RemoteStorageHelper.StorageHelperException- ifkeyStreamis not a valid JSON key stream
-
create
Creates aRemoteStorageHelperobject using default project id and authentication credentials.
-