Class LocalDatastoreHelper (2.22.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
Type Description
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
Name Description
consistency double

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
Type Description
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
Name Description
consistency double

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.

port int

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
Type Description
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
Name Description
port int

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
Type Description
LocalDatastoreHelper

newBuilder()

public static LocalDatastoreHelper.Builder newBuilder()

Returns a builder for LocalDatastoreHelper object.

Returns
Type Description
LocalDatastoreHelper.Builder

Methods

getConsistency()

public double getConsistency()

Returns the consistency setting for the local Datastore emulator.

Returns
Type Description
double

getEmulatorRunners()

protected List<BaseEmulatorHelper.EmulatorRunner> getEmulatorRunners()
Returns
Type Description
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
Type Description
Path

getLogger()

protected Logger getLogger()
Returns
Type Description
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
Type Description
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.

Please use setNamespace and then build() instead.

Parameter
Name Description
namespace String
Returns
Type Description
DatastoreOptions

isStoreOnDisk()

public boolean isStoreOnDisk()

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

Returns
Type Description
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
Type Description
IOException

setNamespace(String namespace)

public DatastoreOptions.Builder setNamespace(String namespace)
Parameter
Name Description
namespace String
Returns
Type Description
DatastoreOptions.Builder

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
Type Description
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
Type Description
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
Name Description
timeout org.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
Type Description
IOException
InterruptedException
TimeoutException

toBuilder()

public LocalDatastoreHelper.Builder toBuilder()

Returns a builder for LocalDatastoreHelper object.

Returns
Type Description
LocalDatastoreHelper.Builder