public class LocalDevelopmentDatastore extends Datastore
Datastore
that provides lifecycle management for a development datastore
server.
In order to use a development datastore for a JUnit 4 test you might do something like this:
public class MyTest { static LocalDevelopmentDatastore datastore; @BeforeClass public static void startLocalDatastore() throws LocalDevelopmentDatastoreException { DatastoreOptions opts = new DatastoreOptions.Builder() .host("http://localhost:8080") .dataset("myapp") .build(); datastore = LocalDevelopmentDatastoreFactory.get().create(opts); datastore.start("/usr/local/gcdsdk", "myapp"); } @Before public void setUp() throws LocalDevelopmentDatastoreException { datastore.clearDatastore(); } @AfterClass public static void stopLocalDatastore() throws LocalDevelopmentDatastoreException { datastore.stopDatastore(); } @Test public void testFoo1() { } @Test public void testFoo2() { } }
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears all data in the Datastore.
|
void |
start(String sdkPath,
String dataset,
String... cmdLineOptions)
Starts the local datastore.
|
void |
stop()
Stops the local datastore.
|
allocateIds, beginTransaction, commit, getRpcCount, lookup, resetRpcCount, rollback, runQuery
public void clear() throws LocalDevelopmentDatastoreException
public void start(String sdkPath, String dataset, String... cmdLineOptions) throws LocalDevelopmentDatastoreException
stop()
. Note that
receiving an exception does not indicate that the server did not start. We recommend calling
stop()
to ensure the server is not running regardless of the result of this method.sdkPath
- The path to the GCD SDK, eg /usr/local/dev/gcddataset
- The name of the GCD datasetcmdLineOptions
- Command line options to pass to the script that launches the dev serverLocalDevelopmentDatastoreException
- If start(java.lang.String, java.lang.String, java.lang.String...)
has already been called or the
server does not start successfully.public void stop() throws LocalDevelopmentDatastoreException
Copyright © 2013. All Rights Reserved.