GeezerVison is showing github.com — improve LocalDatastoreHelper docs. · Issue #2800 · googleapis/google-cloud-java
improve LocalDatastoreHelper docs. #2800Labels priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. DescriptionIt would be nice to improve the javadocs for
http://googlecloudplatform.github.io/google-cloud-java/0.9.2/apidocs/com/google/cloud/datastore/testing/LocalDatastoreHelper.html
Especially the docs for reset look like generated docs string :). Please tell when one would call reset.
E.g. Does this setup for junit make sense? What bout including the code snippet into the docs?
private static final LocalDatastoreHelper datastoreHelper = ...
@BeforeClass
public static void setUpOnce() throws Exception {
datastoreHelper.start();
}
@AfterClass
public static void tearDownOnce() throws Exception {
datastoreHelper.stop(Duration.ofSeconds(5));
}
@Before
public void setUp() throws Exception {
datastoreHelper.reset();
}
For start()/stop() it would be interesting to be explicit and tell if there is going to be any state (e.g. should I call reset() before calling stop()). Activitypongad commented on Jan 24, 2018 @ensonic I believe LocalDatastoreHelper has been deprecated. My reasoning (others might have different opinions) was that it's difficult to managed the emulator process, especially dealing with its I/O.
That said, the emulator isn't very well documented. @jabubake Do you happen to know who owns the emulator's documentations? If nothing else, we should probably document the reset and shutdown endpoints. I think it can be done in a cross-language way. ensonic commented on Jan 24, 2018 Is there a replacement for LocalDatastoreHelper? I found this quite useful (together with the LocalStorageHelper) to run unit tests not against real instances.
You say the 'emulator process is difficult to manage', what are the issues. If you deprecate this helper, people will attempt to replicate the code and run into the same issues, right? At some point one needs to setup the emu.
An alternative would be to have a LocalDatastoreHelper that works more like the LocalStorageHelper, where one would load test data from e.g. json files. pongad commented on Jan 25, 2018 @garrettjonesgoogle for visibility.
It's possible to start the emulator process yourself with gcloud beta emulators datastore start.
I'll explain my reasoning a little more.
In the current implementation, the helper tries to find the emulator installed on your machine. Failing that, it downloads the emulator itself and runs it. I humbly opine it reaches uncomfortably far behind the user's back. This is a reason to change the helper though, and not necessarily one for deprecating it altogether.
About process control; this argument is a little long, but I promise it's not a rant :). Emulators could print diagnostic messages to stdout/stderr. (I'm not 100% sure about datastore, but pubsub does.) IIUC, there's currently no way for users to see these, as the helper swallows all of them. Of course, we could provide an InputStream that user code can read from. But then if you don't read from the stream, the emulator gets stuck. We could provide a way to optionally read. By that point though, we would have re-implemented (or at least re-exposed) most of the Java's Process API. Shutting down the emulator was also a frequent cause of deadlocks in the past, though I believe I fixed the most frequent causes: races between the emulator process and the thread reading the stdout. Essentially, the helper tries to hide the fact that there's an emulator process running, but it's not doing a very good job.
However, the shell already works well (or, at least, better). It's trivial to store logs (gcloud beta emulators datastore start &> /tmp/emulog.txt) and initiate shutdown (curl -XPOST $DATASTORE_EMULATOR_HOST/shutdown). I think the client libraries can help by making connecting to already-running emulators easier, etc. However, I think we should avoid creating a "thick abstraction". IMHO, it doesn't provide enough value over other tools programmers have at their disposal.
Am I making any sense?
The Datastore does allow you to load test data from disk. It doesn't document any specific format though. It's possible for you to get the emulator to a state you want once, then copy the data files for subsequent testing. jabubake commented on Jan 25, 2018 @pongad : I agree, it would be good if the Datastore library could be dependent on an environment variable consistent w/ the Pub/Sub emulator support in google-cloud-java.
I'll look into updating the emulator docs. Un-assigning myself from this ticket. ensonic commented on Jan 26, 2018 Thanks for all the explanations. I agree that there is no easy solutions. From the users perspective I am looking for an 'easy' way to run tests on a developer machine and on CI. On CI it is realative easy to bring up the emulators, since one usually runs the CI actions as a script. For developers right now it is bazel test /... and so far the LocalDatastoreHelper served us well. added type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed on Jan 30, 2018pongad commented on Jan 30, 2018 An update. Here's is my current thinking, it's not an official plan yet. cc @igorbernstein2
I'll treat this is documentation bug. We'll fix the docs, but won't stabilize the surface of the emulator helper yet.
BigTable also needs an emulator. Igor, let's iterate on the emulator design. I hope we can decide on one that works for both APIs. igorbernstein2 commented on Jan 30, 2018 I'll send over a design doc by early next week ensonic commented on Jan 31, 2018 Thanks. Better docs are always a good step. I'd welcome, discussing the future testing support in a ticket to give others a chance to comment too. added a commit that references this issue on Feb 5, 2018This issue will close once commit b5fb39c is merged into the 'main' branch.b5fb39c
MetadataMetadatapriority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. DevelopmentNo branches or pull requestsIssue actions
|