Package com.google.datastore.v1.client
Class DatastoreEmulator
- java.lang.Object
-
- com.google.datastore.v1.client.Datastore
-
- com.google.datastore.v1.client.DatastoreEmulator
-
public class DatastoreEmulator extends Datastore
An extension toDatastore
that provides lifecycle management for a datastore emulator.In order to use the emulator for a JUnit 4 test you might do something like this:
public class MyTest { static DatastoreEmulator datastore; @BeforeClass public static void startEmulator() throws DatastoreEmulatorException { DatastoreOptions options = new DatastoreOptions.Builder() .localHost("localhost:8080") .projectId("my-project-id") .build(); datastore = DatastoreEmulatorFactory.get().create(options); datastore.start("/usr/local/cloud-datastore-emulator", "my-project-id"); } @Before public void setUp() throws DatastoreEmulatorException { datastore.clear(); } @AfterClass public static void stopEmulator() throws DatastoreEmulatorException { datastore.stop(); } @Test public void testFoo1() { } @Test public void testFoo2() { } }
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
clear()
Clears all data in the emulator.File
getProjectDirectory()
void
start()
void
start(String emulatorDir, String projectId, String... commandLineOptions)
Deprecated.prefer setting options in the emulator options and calling {#start()}.void
stop()
Stops the emulator.protected void
stopEmulatorInternal()
-
Methods inherited from class com.google.datastore.v1.client.Datastore
allocateIds, beginTransaction, commit, getRpcCount, lookup, reserveIds, resetRpcCount, rollback, runAggregationQuery, runQuery
-
-
-
-
Method Detail
-
clear
public void clear() throws DatastoreEmulatorException
Clears all data in the emulator.- Throws:
DatastoreEmulatorException
- if the clear fails
-
start
@Deprecated public void start(String emulatorDir, String projectId, String... commandLineOptions) throws DatastoreEmulatorException
Deprecated.prefer setting options in the emulator options and calling {#start()}.Starts the emulator. It is the caller's responsibility to callstop()
. Note that receiving an exception does not indicate that the server did not start. We recommend callingstop()
to ensure the server is not running regardless of the result of this method.- Parameters:
emulatorDir
- The path to the emulator directory, e.g. /usr/local/cloud-datastore-emulatorprojectId
- The project IDcommandLineOptions
- Command line options to pass to the emulator on startup- Throws:
DatastoreEmulatorException
- Ifstart(java.lang.String, java.lang.String, java.lang.String...)
has already been called or the server does not start successfully.
-
start
public void start() throws DatastoreEmulatorException
- Throws:
DatastoreEmulatorException
-
stop
public void stop() throws DatastoreEmulatorException
Stops the emulator. Multiple calls are allowed.- Throws:
DatastoreEmulatorException
- if the emulator cannot be stopped
-
stopEmulatorInternal
protected void stopEmulatorInternal() throws DatastoreEmulatorException
- Throws:
DatastoreEmulatorException
-
getProjectDirectory
public File getProjectDirectory()
-
-