@InternalApi public class LocalDatastoreHelper extends com.google.cloud.testing.BaseEmulatorHelper<DatastoreOptions>
This class is unstable.
Modifier and Type | Class and Description |
---|---|
static class |
LocalDatastoreHelper.Builder
A builder for
LocalDatastoreHelper objects. |
Modifier and Type | Method and Description |
---|---|
static LocalDatastoreHelper |
create()
Creates a local Datastore helper with a placeholder project ID and the default consistency
setting of 0.9.
|
static LocalDatastoreHelper |
create(double consistency)
Creates a local Datastore helper with the specified settings for project ID and consistency.
|
static LocalDatastoreHelper |
create(double consistency,
int port)
Creates a local Datastore helper with the specified settings for project ID and consistency.
|
static LocalDatastoreHelper |
create(int port)
Creates a local Datastore helper with a placeholder project ID and the default consistency
setting of 0.9.
|
double |
getConsistency()
Returns the consistency setting for the local Datastore emulator.
|
protected List<com.google.cloud.testing.BaseEmulatorHelper.EmulatorRunner> |
getEmulatorRunners() |
Path |
getGcdPath()
Returns the data directory path of the local Datastore emulator.
|
protected Logger |
getLogger() |
DatastoreOptions |
getOptions()
Returns a
DatastoreOptions instance that sets the host to use the Datastore emulator on
localhost. |
DatastoreOptions |
getOptions(String namespace)
Returns a
DatastoreOptions instance that sets the host to use the Datastore emulator on
localhost. |
boolean |
isStoreOnDisk()
Returns
true data persist on disk, otherwise false data not store on disk. |
static LocalDatastoreHelper.Builder |
newBuilder()
Returns a builder for
LocalDatastoreHelper object. |
void |
reset()
Resets the internal state of the Datastore emulator.
|
DatastoreOptions.Builder |
setNamespace(String namespace) |
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. |
void |
stop()
Stops the Datastore emulator.
|
void |
stop(org.threeten.bp.Duration timeout)
Stops the Datastore emulator.
|
LocalDatastoreHelper.Builder |
toBuilder()
Returns a builder for
LocalDatastoreHelper object. |
public LocalDatastoreHelper.Builder toBuilder()
LocalDatastoreHelper
object.public static LocalDatastoreHelper.Builder newBuilder()
LocalDatastoreHelper
object.protected List<com.google.cloud.testing.BaseEmulatorHelper.EmulatorRunner> getEmulatorRunners()
getEmulatorRunners
in class com.google.cloud.testing.BaseEmulatorHelper<DatastoreOptions>
protected Logger getLogger()
getLogger
in class com.google.cloud.testing.BaseEmulatorHelper<DatastoreOptions>
public DatastoreOptions getOptions()
DatastoreOptions
instance that sets the host to use the Datastore emulator on
localhost.getOptions
in class com.google.cloud.testing.BaseEmulatorHelper<DatastoreOptions>
public DatastoreOptions getOptions(String namespace)
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.
public DatastoreOptions.Builder setNamespace(String namespace)
public double getConsistency()
public Path getGcdPath()
public boolean isStoreOnDisk()
true
data persist on disk, otherwise false
data not store on disk.public static LocalDatastoreHelper create(double consistency)
consistency
- 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.public static LocalDatastoreHelper create(double consistency, int port)
consistency
- 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
- 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.public static LocalDatastoreHelper create(int port)
port
- 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.public static LocalDatastoreHelper create()
public void start() throws IOException, InterruptedException
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.
start
in class com.google.cloud.testing.BaseEmulatorHelper<DatastoreOptions>
IOException
InterruptedException
public void reset() throws IOException
When running tests, one might reset()
before each test, so earlier tests would not
affect later ones.
reset
in class com.google.cloud.testing.BaseEmulatorHelper<DatastoreOptions>
IOException
public void stop(org.threeten.bp.Duration timeout) throws IOException, InterruptedException, TimeoutException
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
.
stop
in class com.google.cloud.testing.BaseEmulatorHelper<DatastoreOptions>
timeout
- 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.IOException
InterruptedException
TimeoutException
public void stop() throws IOException, InterruptedException, TimeoutException
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()
.
Copyright © 2023 Google LLC. All rights reserved.