Skip to content

Commit 194ad6e

Browse files
authored
---
yaml --- r: 8691 b: refs/heads/master c: b5fb39c h: refs/heads/master i: 8689: 095adb8 8687: 0b962bf
1 parent e0e3a30 commit 194ad6e

2 files changed

Lines changed: 34 additions & 8 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: c572f05d606edd53e8bc2820c32d99652350c208
2+
refs/heads/master: b5fb39c8b6c795cb3ce009c41a5632fb209166e8
33
refs/heads/travis: 47e4fee4fd5af9b2a8ce46f23c72ec95f9b195b2
44
refs/heads/gh-pages: 6daca92127d91b7c2c99490080ecf8a13fa94cde
55
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

trunk/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/LocalDatastoreHelper.java

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
import com.google.cloud.datastore.DatastoreOptions;
2323
import com.google.cloud.testing.BaseEmulatorHelper;
2424
import com.google.common.collect.ImmutableList;
25-
26-
import org.threeten.bp.Duration;
27-
2825
import java.io.IOException;
2926
import java.net.MalformedURLException;
3027
import java.net.URL;
@@ -40,11 +37,12 @@
4037
import java.util.concurrent.TimeoutException;
4138
import java.util.logging.Level;
4239
import java.util.logging.Logger;
40+
import org.threeten.bp.Duration;
4341

4442
/**
45-
* Utility to start and stop local Google Cloud Datastore process.
46-
*
47-
* Internal testing use only
43+
* Utility to start and stop local Google Cloud Datastore emulators.
44+
*
45+
* <p>This class is unstable.
4846
*/
4947
@InternalApi
5048
public class LocalDatastoreHelper extends BaseEmulatorHelper<DatastoreOptions> {
@@ -185,6 +183,8 @@ public static LocalDatastoreHelper create() {
185183
/**
186184
* Starts the local Datastore emulator through {@code gcloud}, downloads and caches the zip file
187185
* if user does not have {@code gcloud} or a compatible emulator version installed.
186+
*
187+
* <p>Currently the emulator does not persist any state across runs.
188188
*/
189189
@Override
190190
public void start() throws IOException, InterruptedException {
@@ -193,21 +193,47 @@ public void start() throws IOException, InterruptedException {
193193
}
194194

195195
/**
196-
* Reset the internal state of the Datastore emulator.
196+
* Resets the internal state of the Datastore emulator.
197+
*
198+
* <p>When running tests, one might {@code reset()} before each test, so earlier tests would not
199+
* affect later ones.
197200
*/
201+
@Override
198202
public void reset() throws IOException {
199203
sendPostRequest("/reset");
200204
}
201205

202206
/**
203207
* Stops the Datastore emulator.
208+
*
209+
* <p>It is important to stop the emulator. Since the emulator runs in its own process, not
210+
* stopping it might cause it to become orphan.
211+
*
212+
* <p>It is not required to call {@link #reset()} before {@code stop}.
213+
*
214+
* @param timeout The duration to wait for the emulator process to stop. It is recommended to set
215+
* this value high to ensure proper shutdown, like 5 seconds or more.
204216
*/
217+
@Override
205218
public void stop(Duration timeout) throws IOException, InterruptedException, TimeoutException {
206219
sendPostRequest("/shutdown");
207220
waitForProcess(timeout);
208221
deleteRecursively(gcdPath);
209222
}
210223

224+
/**
225+
* Stops the Datastore emulator. The same as {@link stop(Duration)} but with timeout duration of
226+
* 20 seconds.
227+
*
228+
* <p>It is important to stop the emulator. Since the emulator runs in its own process, not
229+
* stopping it might cause it to become orphan.
230+
*
231+
* <p>It is not required to call {@link #reset()} before {@code stop()}.
232+
*/
233+
public void stop() throws IOException, InterruptedException, TimeoutException {
234+
stop(Duration.ofSeconds(20));
235+
}
236+
211237
private static void deleteRecursively(Path path) throws IOException {
212238
if (path == null || !Files.exists(path)) {
213239
return;

0 commit comments

Comments
 (0)