Class LocalDatastoreHelper (2.4.0)

public class LocalDatastoreHelper extends BaseEmulatorHelper<DatastoreOptions>

Utility to start and stop local Google Cloud Datastore emulators.

This class is unstable.

Inheritance

java.lang.Object > com.google.cloud.testing.BaseEmulatorHelper > LocalDatastoreHelper

Static Methods

create()

public static LocalDatastoreHelper create()

Creates a local Datastore helper with a placeholder project ID and the default consistency setting of 0.9. Consistency refers to the fraction of Datastore writes that are immediately visible to global queries, with 0.0 meaning no writes are immediately visible and 1.0 meaning all writes are immediately visible.

Returns
TypeDescription
LocalDatastoreHelper

create(double consistency)

public static LocalDatastoreHelper create(double consistency)

Creates a local Datastore helper with the specified settings for project ID and consistency.

Parameter
NameDescription
consistencydouble

the fraction of Datastore writes that are immediately visible to global queries, with 0.0 meaning no writes are immediately visible and 1.0 meaning all writes are immediately visible. Note that setting this to 1.0 may mask incorrect assumptions about the consistency of non-ancestor queries; non-ancestor queries are eventually consistent.

Returns
TypeDescription
LocalDatastoreHelper

create(double consistency, int port)

public static LocalDatastoreHelper create(double consistency, int port)

Creates a local Datastore helper with the specified settings for project ID and consistency.

Parameters
NameDescription
consistencydouble

the fraction of Datastore writes that are immediately visible to global queries, with 0.0 meaning no writes are immediately visible and 1.0 meaning all writes are immediately visible. Note that setting this to 1.0 may mask incorrect assumptions about the consistency of non-ancestor queries; non-ancestor queries are eventually consistent.

portint

the port to be used to start the emulator service. Note that setting this to 0 the emulator will search for a free random port.

Returns
TypeDescription
LocalDatastoreHelper

create(int port)

public static LocalDatastoreHelper create(int port)

Creates a local Datastore helper with a placeholder project ID and the default consistency setting of 0.9.

Parameter
NameDescription
portint

the port to be used to start the emulator service. Note that setting this to 0 the emulator will search for a free random port.

Returns
TypeDescription
LocalDatastoreHelper

newBuilder()

public static LocalDatastoreHelper.Builder newBuilder()

Returns a builder for LocalDatastoreHelper object.

Returns
TypeDescription
LocalDatastoreHelper.Builder

Methods

getConsistency()

public double getConsistency()

Returns the consistency setting for the local Datastore emulator.

Returns
TypeDescription
double

getEmulatorRunners()

protected List<BaseEmulatorHelper.EmulatorRunner> getEmulatorRunners()
Returns
TypeDescription
List<com.google.cloud.testing.BaseEmulatorHelper.EmulatorRunner>
Overrides
com.google.cloud.testing.BaseEmulatorHelper.getEmulatorRunners()

getGcdPath()

public Path getGcdPath()

Returns the data directory path of the local Datastore emulator.

Returns
TypeDescription
Path

getLogger()

protected Logger getLogger()
Returns
TypeDescription
Logger
Overrides
com.google.cloud.testing.BaseEmulatorHelper.getLogger()

getOptions()

public DatastoreOptions getOptions()

Returns a DatastoreOptions instance that sets the host to use the Datastore emulator on localhost.

Returns
TypeDescription
DatastoreOptions
Overrides
com.google.cloud.testing.BaseEmulatorHelper.getOptions()

getOptions(String namespace)

public DatastoreOptions getOptions(String namespace)

Returns a DatastoreOptions instance that sets the host to use the Datastore emulator on localhost. The default namespace is set to namespace.

Parameter
NameDescription
namespaceString
Returns
TypeDescription
DatastoreOptions

isStoreOnDisk()

public boolean isStoreOnDisk()

Returns true data persist on disk, otherwise false data not store on disk.

Returns
TypeDescription
boolean

reset()

public void reset()

Resets the internal state of the Datastore emulator.

When running tests, one might reset() before each test, so earlier tests would not affect later ones.

Overrides
com.google.cloud.testing.BaseEmulatorHelper.reset()
Exceptions
TypeDescription
IOException

start()

public void start()

Starts the local Datastore emulator through gcloud, downloads and caches the zip file if user does not have gcloud or a compatible emulator version installed.

Currently the emulator does not persist any state across runs.

Overrides
com.google.cloud.testing.BaseEmulatorHelper.start()
Exceptions
TypeDescription
IOException
InterruptedException

stop()

public void stop()

Stops the Datastore emulator. The same as #stop(Duration) but with timeout duration of 20 seconds.

It is important to stop the emulator. Since the emulator runs in its own process, not stopping it might cause it to become orphan.

It is not required to call #reset() before stop().

Exceptions
TypeDescription
IOException
InterruptedException
TimeoutException

stop(Duration timeout)

public void stop(Duration timeout)

Stops the Datastore emulator.

It is important to stop the emulator. Since the emulator runs in its own process, not stopping it might cause it to become orphan.

It is not required to call #reset() before stop.

Parameter
NameDescription
timeoutorg.threeten.bp.Duration

The duration to wait for the emulator process to stop. It is recommended to set this value high to ensure proper shutdown, like 5 seconds or more.

Overrides
com.google.cloud.testing.BaseEmulatorHelper.stop(org.threeten.bp.Duration)
Exceptions
TypeDescription
IOException
InterruptedException
TimeoutException

toBuilder()

public LocalDatastoreHelper.Builder toBuilder()

Returns a builder for LocalDatastoreHelper object.

Returns
TypeDescription
LocalDatastoreHelper.Builder