Class DatastoreEmulator (3.1.0)

public class DatastoreEmulator extends Datastore

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() { }

}

Inheritance

java.lang.Object > Datastore > DatastoreEmulator

Methods

clear()

public void clear()

Clears all data in the emulator.

Exceptions
Type Description
DatastoreEmulatorException

if the clear fails

getProjectDirectory()

public synchronized File getProjectDirectory()
Returns
Type Description
File

start()

public synchronized void start()
Exceptions
Type Description
DatastoreEmulatorException

stop()

public synchronized void stop()

Stops the emulator. Multiple calls are allowed.

Exceptions
Type Description
DatastoreEmulatorException

if the emulator cannot be stopped

stopEmulatorInternal()

protected void stopEmulatorInternal()
Exceptions
Type Description
DatastoreEmulatorException