# Class LocalDatastoreHelper (3.1.0)

3.1.0 (latest) 2.40.0 2.37.0 2.36.0 2.34.0 2.33.3 2.32.3 2.31.4 2.30.0 2.29.1 2.28.2 2.27.1 2.26.4 2.25.2 2.24.3 2.23.0 2.22.0 2.21.3 2.20.2 2.19.2 2.18.5 2.17.6

    public class LocalDatastoreHelper extends BaseEmulatorHelper<DatastoreOptions>

Utility to start and stop local Google Cloud Datastore emulators.

This class is unstable.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> 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) [Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## 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** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.testing.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` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` 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** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.testing.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` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` 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` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` 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** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.testing.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` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` 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** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.testing.LocalDatastoreHelper` |   |

### newBuilder()

    public static LocalDatastoreHelper.Builder newBuilder()

Returns a builder for `LocalDatastoreHelper` object.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.testing.LocalDatastoreHelper.Builder` |   |

## Methods

### getConsistency()

    public double getConsistency()

Returns the consistency setting for the local Datastore emulator.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### getEmulatorRunners()

    protected List<BaseEmulatorHelper.EmulatorRunner> getEmulatorRunners()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<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** |
| `https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html` |   |

### getGrpcTransportOptions(GrpcTransportOptions grpcTransportOptions) (deprecated)

    public DatastoreOptions getGrpcTransportOptions(GrpcTransportOptions grpcTransportOptions)

Prefer to set the TransportOptions via the Options Builder.

Returns a [DatastoreOptions](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.DatastoreOptions) instance that sets the host to use the Datastore emulator
on localhost. The transportOptions is set to `grpcTransportOptions`.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `grpcTransportOptions` | `com.google.cloud.grpc.GrpcTransportOptions` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.DatastoreOptions` |   |

### getLogger()

    protected Logger getLogger()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/logging/Logger.html` |   |

**Overrides** com.google.cloud.testing.BaseEmulatorHelper.getLogger()

### getOptions()

    public DatastoreOptions getOptions()

Returns a [DatastoreOptions](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.DatastoreOptions) instance that sets the host to use the Datastore emulator on
localhost.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.DatastoreOptions` |   |

**Overrides** com.google.cloud.testing.BaseEmulatorHelper.getOptions()

### getOptions(String namespace)

    public DatastoreOptions getOptions(String namespace)

Returns a [DatastoreOptions](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.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` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.DatastoreOptions` |   |

### isFirestoreInDatastoreMode()

    public boolean isFirestoreInDatastoreMode()

Returns `true` use firestore-in-datastore-mode, otherwise `false` use native mode.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### isStoreOnDisk()

    public boolean isStoreOnDisk()

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### 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** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### setNamespace(String namespace)

    public DatastoreOptions.Builder setNamespace(String namespace)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `namespace` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.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** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/InterruptedException.html` |   |

### stop()

    public void stop()

Stops the Datastore emulator. The same as [#stopDuration(java.time.Duration)](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.testing.LocalDatastoreHelper#com_google_cloud_datastore_testing_LocalDatastoreHelper_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()](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.testing.LocalDatastoreHelper#com_google_cloud_datastore_testing_LocalDatastoreHelper_reset__) before `stop()`.

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/InterruptedException.html` |   |
| `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/TimeoutException.html` |   |

### stop(Duration timeout) (deprecated)

    public void stop(Duration timeout)

**Deprecated.** *Use [#stopDuration(java.time.Duration)](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.testing.LocalDatastoreHelper#com_google_cloud_datastore_testing_LocalDatastoreHelper_stopDuration_java_time_Duration_) instead.*

This method is obsolete. Use [#stopDuration(java.time.Duration)](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.testing.LocalDatastoreHelper#com_google_cloud_datastore_testing_LocalDatastoreHelper_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** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/InterruptedException.html` |   |
| `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/TimeoutException.html` |   |

### stopDuration(Duration timeout)

    public void stopDuration(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()](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.testing.LocalDatastoreHelper#com_google_cloud_datastore_testing_LocalDatastoreHelper_reset__) before `stop`.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `timeout` | `https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html` 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** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/InterruptedException.html` |   |
| `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/TimeoutException.html` |   |

### toBuilder()

    public LocalDatastoreHelper.Builder toBuilder()

Returns a builder for `LocalDatastoreHelper` object.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.testing.LocalDatastoreHelper.Builder` |   |