Class DatastoreEmulator


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