Package com.google.datastore.v1.client
Class DatastoreEmulator
java.lang.Object
com.google.datastore.v1.client.Datastore
com.google.datastore.v1.client.DatastoreEmulator
An extension to
Datastore 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
Methods inherited from class com.google.datastore.v1.client.Datastore
allocateIds, beginTransaction, commit, getRpcCount, lookup, reserveIds, resetRpcCount, rollback, runAggregationQuery, runQuery
-
Method Details
-
clear
Clears all data in the emulator.- Throws:
DatastoreEmulatorException- if the clear fails
-
start
- Throws:
DatastoreEmulatorException
-
stop
Stops the emulator. Multiple calls are allowed.- Throws:
DatastoreEmulatorException- if the emulator cannot be stopped
-
stopEmulatorInternal
- Throws:
DatastoreEmulatorException
-
getProjectDirectory
-