Package com.google.cloud.spanner.testing
Class RemoteSpannerHelper
- java.lang.Object
-
- com.google.cloud.spanner.testing.RemoteSpannerHelper
-
public class RemoteSpannerHelper extends Object
Utility that provides access to a Cloud Spanner instance to use for tests, and allows uniquely named test databases to be created within that instance.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedRemoteSpannerHelper(SpannerOptions options, InstanceId instanceId, Spanner client)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidcleanUp()Deletes all the databases created viacreateTestDatabase.static RemoteSpannerHelpercreate(InstanceId instanceId)Creates aRemoteSpannerHelperbound to the given instance ID.static RemoteSpannerHelpercreate(SpannerOptions options, InstanceId instanceId)Creates aRemoteSpannerHelperfor the given option and bound to the given instance ID.DatabasecreateTestDatabase(Dialect dialect, Iterable<String> statements)Creates a test database defined bystatementsin the test instance.DatabasecreateTestDatabase(Iterable<String> statements)DatabasecreateTestDatabase(String... statements)Creates a test database defined bystatements.BatchClientgetBatchClient(Database db)SpannergetClient()DatabaseClientgetDatabaseClient(Database db)InstanceIdgetInstanceId()SpannerOptionsgetOptions()StringgetUniqueBackupId()Returns a backup id which is guaranteed to be unique within the context of this environment.StringgetUniqueDatabaseId()Returns a database id which is guaranteed to be unique within the context of this environment.StringgetUniqueDatabaseRole()Returns a database role name which is guaranteed to be unique within the context of this environment.booleanisEmulator()Deprecated.useEmulatorSpannerHelper.isUsingEmulator()instead.
-
-
-
Constructor Detail
-
RemoteSpannerHelper
protected RemoteSpannerHelper(SpannerOptions options, InstanceId instanceId, Spanner client)
-
-
Method Detail
-
getOptions
public SpannerOptions getOptions()
-
isEmulator
@Deprecated public boolean isEmulator()
Deprecated.useEmulatorSpannerHelper.isUsingEmulator()instead.Checks whether the emulator is being used.- Returns:
- true if the emulator is being used. Returns false otherwise.
-
getClient
public Spanner getClient()
-
getDatabaseClient
public DatabaseClient getDatabaseClient(Database db)
-
getBatchClient
public BatchClient getBatchClient(Database db)
-
getInstanceId
public InstanceId getInstanceId()
-
createTestDatabase
public Database createTestDatabase(String... statements) throws SpannerException
Creates a test database defined bystatements. ACREATE DATABASE ...statement should not be included; an appropriate name will be chosen and the statement generated accordingly.- Throws:
SpannerException
-
getUniqueDatabaseId
public String getUniqueDatabaseId()
Returns a database id which is guaranteed to be unique within the context of this environment.
-
getUniqueDatabaseRole
public String getUniqueDatabaseRole()
Returns a database role name which is guaranteed to be unique within the context of this environment.
-
getUniqueBackupId
public String getUniqueBackupId()
Returns a backup id which is guaranteed to be unique within the context of this environment.
-
createTestDatabase
public Database createTestDatabase(Dialect dialect, Iterable<String> statements) throws SpannerException
Creates a test database defined bystatementsin the test instance. ACREATE DATABASE ...statement should not be included; an appropriate name will be chosen and the statement generated accordingly.- Throws:
SpannerException
-
createTestDatabase
public Database createTestDatabase(Iterable<String> statements) throws SpannerException
- Throws:
SpannerException
-
cleanUp
public void cleanUp()
Deletes all the databases created viacreateTestDatabase. Shuts down the client.
-
create
public static RemoteSpannerHelper create(InstanceId instanceId)
Creates aRemoteSpannerHelperbound to the given instance ID. All databases created using this will be created in the given instance.
-
create
public static RemoteSpannerHelper create(SpannerOptions options, InstanceId instanceId)
Creates aRemoteSpannerHelperfor the given option and bound to the given instance ID. All databases created using this will be created in the given instance.
-
-