Class LocalDatastoreHelper

java.lang.Object
com.google.cloud.testing.BaseEmulatorHelper<DatastoreOptions>
com.google.cloud.datastore.testing.LocalDatastoreHelper

@InternalApi public class LocalDatastoreHelper extends com.google.cloud.testing.BaseEmulatorHelper<DatastoreOptions>
Utility to start and stop local Google Cloud Datastore emulators.

This class is unstable.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A builder for LocalDatastoreHelper objects.

    Nested classes/interfaces inherited from class com.google.cloud.testing.BaseEmulatorHelper

    com.google.cloud.testing.BaseEmulatorHelper.DownloadableEmulatorRunner, com.google.cloud.testing.BaseEmulatorHelper.EmulatorRunner, com.google.cloud.testing.BaseEmulatorHelper.GcloudEmulatorRunner
  • Field Summary

    Fields inherited from class com.google.cloud.testing.BaseEmulatorHelper

    DEFAULT_HOST, DEFAULT_PORT, PROJECT_ID_PREFIX
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a local Datastore helper with a placeholder project ID and the default consistency setting of 0.9.
    create(double consistency)
    Creates a local Datastore helper with the specified settings for project ID and consistency.
    create(double consistency, int port)
    Creates a local Datastore helper with the specified settings for project ID and consistency.
    create(int port)
    Creates a local Datastore helper with a placeholder project ID and the default consistency setting of 0.9.
    double
    Returns the consistency setting for the local Datastore emulator.
    protected List<com.google.cloud.testing.BaseEmulatorHelper.EmulatorRunner>
     
    Returns the data directory path of the local Datastore emulator.
    getGrpcTransportOptions(com.google.cloud.grpc.GrpcTransportOptions grpcTransportOptions)
    Returns a DatastoreOptions instance that sets the host to use the Datastore emulator on localhost.
    protected Logger
     
    Returns a DatastoreOptions instance that sets the host to use the Datastore emulator on localhost.
    getOptions(String namespace)
    Returns a DatastoreOptions instance that sets the host to use the Datastore emulator on localhost.
    boolean
    Returns true use firestore-in-datastore-mode, otherwise false use native mode.
    boolean
    Returns true data persist on disk, otherwise false data not store on disk.
    Returns a builder for LocalDatastoreHelper object.
    void
    Resets the internal state of the Datastore emulator.
    setNamespace(String namespace)
     
    void
    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
    Stops the Datastore emulator.
    void
    stop(org.threeten.bp.Duration timeout)
    This method is obsolete.
    void
    Stops the Datastore emulator.
    Returns a builder for LocalDatastoreHelper object.

    Methods inherited from class com.google.cloud.testing.BaseEmulatorHelper

    findAvailablePort, getPort, getProjectId, isWindows, sendPostRequest, startProcess, waitForProcess, waitForProcessDuration

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • toBuilder

      public LocalDatastoreHelper.Builder toBuilder()
      Returns a builder for LocalDatastoreHelper object.
    • newBuilder

      public static LocalDatastoreHelper.Builder newBuilder()
      Returns a builder for LocalDatastoreHelper object.
    • getEmulatorRunners

      protected List<com.google.cloud.testing.BaseEmulatorHelper.EmulatorRunner> getEmulatorRunners()
      Specified by:
      getEmulatorRunners in class com.google.cloud.testing.BaseEmulatorHelper<DatastoreOptions>
    • getLogger

      protected Logger getLogger()
      Specified by:
      getLogger in class com.google.cloud.testing.BaseEmulatorHelper<DatastoreOptions>
    • getOptions

      public DatastoreOptions getOptions()
      Returns a DatastoreOptions instance that sets the host to use the Datastore emulator on localhost.
      Specified by:
      getOptions in class com.google.cloud.testing.BaseEmulatorHelper<DatastoreOptions>
    • getOptions

      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.

    • getGrpcTransportOptions

      public DatastoreOptions getGrpcTransportOptions(com.google.cloud.grpc.GrpcTransportOptions grpcTransportOptions)
      Returns a DatastoreOptions instance that sets the host to use the Datastore emulator on localhost. The transportOptions is set to grpcTransportOptions.
    • setNamespace

      public DatastoreOptions.Builder setNamespace(String namespace)
    • getConsistency

      public double getConsistency()
      Returns the consistency setting for the local Datastore emulator.
    • getGcdPath

      public Path getGcdPath()
      Returns the data directory path of the local Datastore emulator.
    • isStoreOnDisk

      public boolean isStoreOnDisk()
      Returns true data persist on disk, otherwise false data not store on disk.
    • isFirestoreInDatastoreMode

      public boolean isFirestoreInDatastoreMode()
      Returns true use firestore-in-datastore-mode, otherwise false use native mode.
    • create

      public static LocalDatastoreHelper create(double consistency)
      Creates a local Datastore helper with the specified settings for project ID and consistency.
      Parameters:
      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.
    • create

      public static LocalDatastoreHelper create(double consistency, int port)
      Creates a local Datastore helper with the specified settings for project ID and consistency.
      Parameters:
      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.
    • create

      public static LocalDatastoreHelper create(int port)
      Creates a local Datastore helper with a placeholder project ID and the default consistency setting of 0.9.
      Parameters:
      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.
    • 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.
    • start

      public void start() throws IOException, InterruptedException
      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.

      Specified by:
      start in class com.google.cloud.testing.BaseEmulatorHelper<DatastoreOptions>
      Throws:
      IOException
      InterruptedException
    • reset

      public void reset() throws IOException
      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.

      Specified by:
      reset in class com.google.cloud.testing.BaseEmulatorHelper<DatastoreOptions>
      Throws:
      IOException
    • stop

      @ObsoleteApi("Use stopDuration(java.time.Duration) instead") public void stop(org.threeten.bp.Duration timeout) throws IOException, InterruptedException, TimeoutException
      This method is obsolete. Use stopDuration(java.time.Duration) instead
      Specified by:
      stop in class com.google.cloud.testing.BaseEmulatorHelper<DatastoreOptions>
      Throws:
      IOException
      InterruptedException
      TimeoutException
    • stopDuration

      public void stopDuration(Duration timeout) throws IOException, InterruptedException, TimeoutException
      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.

      Overrides:
      stopDuration in class com.google.cloud.testing.BaseEmulatorHelper<DatastoreOptions>
      Parameters:
      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.
      Throws:
      IOException
      InterruptedException
      TimeoutException
    • stop

      public void stop() throws IOException, InterruptedException, TimeoutException
      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().

      Throws:
      IOException
      InterruptedException
      TimeoutException