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
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
cleanBuckets
(Storage storage, long olderThan, long timeoutMs) static RemoteStorageHelper
create()
Creates aRemoteStorageHelper
object using default project id and authentication credentials.static RemoteStorageHelper
create
(String projectId, InputStream keyStream) Creates aRemoteStorageHelper
object for the given project id and JSON key input stream.static void
forceDelete
(Storage storage, String bucket) Deletes a bucket, even if non-empty.static Boolean
forceDelete
(Storage storage, String bucket, long timeout, TimeUnit unit) Deletes a bucket, even if non-empty.static Boolean
forceDelete
(Storage storage, String bucket, long timeout, TimeUnit unit, String userProject) Deletes a bucket, even if non-empty.static String
Returns a bucket name generated using a random UUID.Returns aStorageOptions
object to be used for testing.
-
Method Details
-
getOptions
Returns aStorageOptions
object 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 ortimeout
expires. 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 ortimeout
expires. 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 aRemoteStorageHelper
object 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
RemoteStorageHelper
object for the provided options - Throws:
RemoteStorageHelper.StorageHelperException
- ifkeyStream
is not a valid JSON key stream
-
create
Creates aRemoteStorageHelper
object using default project id and authentication credentials.
-