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()
.localHost("localhost:8080")
.projectId("my-project-id")
.build();
datastore = LocalDevelopmentDatastoreFactory.get().create(opts);
datastore.start("/usr/local/gcd-sdk", "my-project-id");
}
@Before
public void setUp() throws LocalDevelopmentDatastoreException {
datastore.clear();
}
@AfterClass
public static void stopLocalDatastore() throws LocalDevelopmentDatastoreException {
datastore.stop();
}
@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 projectId,
String... cmdLineOptions)
Starts the local datastore.
|
void |
stop()
Stops the local datastore.
|
allocateIds, beginTransaction, commit, getRpcCount, lookup, resetRpcCount, rollback, runQuerypublic void clear()
throws LocalDevelopmentDatastoreException
public void start(String sdkPath, String projectId, 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/gcdprojectId - The GCD project IDcmdLineOptions - 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 © 2016. All rights reserved.