Class LocalDatastoreHelper (2.25.2)

publicclass LocalDatastoreHelperextendsBaseEmulatorHelper<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

Inherited Members

com.google.cloud.testing.BaseEmulatorHelper.findAvailablePort(int)
com.google.cloud.testing.BaseEmulatorHelper.getEmulatorRunners()
com.google.cloud.testing.BaseEmulatorHelper.getLogger()
com.google.cloud.testing.BaseEmulatorHelper.getOptions()
com.google.cloud.testing.BaseEmulatorHelper.getPort()
com.google.cloud.testing.BaseEmulatorHelper.getProjectId()
com.google.cloud.testing.BaseEmulatorHelper.isWindows()
com.google.cloud.testing.BaseEmulatorHelper.reset()
com.google.cloud.testing.BaseEmulatorHelper.sendPostRequest(java.lang.String)
com.google.cloud.testing.BaseEmulatorHelper.start()
com.google.cloud.testing.BaseEmulatorHelper.startProcess(java.lang.String)
com.google.cloud.testing.BaseEmulatorHelper.stop(org.threeten.bp.Duration)
com.google.cloud.testing.BaseEmulatorHelper.stopDuration(java.time.Duration)
com.google.cloud.testing.BaseEmulatorHelper.waitForProcess(org.threeten.bp.Duration)
com.google.cloud.testing.BaseEmulatorHelper.waitForProcessDuration(java.time.Duration)

Static Methods

create()

publicstaticLocalDatastoreHelpercreate()

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)

publicstaticLocalDatastoreHelpercreate(doubleconsistency)

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)

publicstaticLocalDatastoreHelpercreate(doubleconsistency,intport)

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)

publicstaticLocalDatastoreHelpercreate(intport)

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()

publicstaticLocalDatastoreHelper.BuildernewBuilder()

Returns a builder for LocalDatastoreHelper object.

Returns
Type Description
LocalDatastoreHelper.Builder

Methods

getConsistency()

publicdoublegetConsistency()

Returns the consistency setting for the local Datastore emulator.

Returns
Type Description
double

getEmulatorRunners()

protectedList<BaseEmulatorHelper.EmulatorRunner>getEmulatorRunners()
Returns
Type Description
List<com.google.cloud.testing.BaseEmulatorHelper.EmulatorRunner>
Overrides
com.google.cloud.testing.BaseEmulatorHelper.getEmulatorRunners()

getGcdPath()

publicPathgetGcdPath()

Returns the data directory path of the local Datastore emulator.

Returns
Type Description
Path

getLogger()

protectedLoggergetLogger()
Returns
Type Description
Logger
Overrides
com.google.cloud.testing.BaseEmulatorHelper.getLogger()

getOptions()

publicDatastoreOptionsgetOptions()

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)

publicDatastoreOptionsgetOptions(Stringnamespace)

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()

publicbooleanisStoreOnDisk()

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

Returns
Type Description
boolean

reset()

publicvoidreset()

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)

publicDatastoreOptions.BuildersetNamespace(Stringnamespace)
Parameter
Name Description
namespace String
Returns
Type Description
DatastoreOptions.Builder

start()

publicvoidstart()

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()

publicvoidstop()

Stops the Datastore emulator. The same as #stopDuration(java.time.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)

publicvoidstop(Durationtimeout)

This method is obsolete. Use #stopDuration(java.time.Duration) instead

Parameter
Name Description
timeout org.threeten.bp.Duration
Overrides
com.google.cloud.testing.BaseEmulatorHelper.stop(org.threeten.bp.Duration)
Exceptions
Type Description
IOException
InterruptedException
TimeoutException

stopDuration(Duration timeout)

publicvoidstopDuration(Durationtimeout)

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 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.stopDuration(java.time.Duration)
Exceptions
Type Description
IOException
InterruptedException
TimeoutException

toBuilder()

publicLocalDatastoreHelper.BuildertoBuilder()

Returns a builder for LocalDatastoreHelper object.

Returns
Type Description
LocalDatastoreHelper.Builder

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年11月19日 UTC.