Skip to content

Commit ce215f8

Browse files
authored
---
yaml --- r: 8977 b: refs/heads/lesv-patch-1 c: b5fb39c h: refs/heads/master i: 8975: 6f71b0d
1 parent 6202420 commit ce215f8

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
@@ -66,7 +66,7 @@ refs/tags/v0.22.0: 18b298fe4bfe8ec2f20b0e0bf7ffdcce5cc3c5fe
6666
refs/heads/vam-google-patch-1: d0c8fee3a4074d0bf7360ce8c4f7f7223d0ee7b9
6767
refs/heads/vam-google-patch-CODEOWNERS: 2ac1616e25229e51d08a984708ef1918f91a35ee
6868
refs/heads/danoscarmike-patch-1: 7342a9916bce4ed00002c7202e2a16c5d46afaea
69-
refs/heads/lesv-patch-1: c572f05d606edd53e8bc2820c32d99652350c208
69+
refs/heads/lesv-patch-1: b5fb39c8b6c795cb3ce009c41a5632fb209166e8
7070
refs/heads/ml-update-branch: 079dd6610017f5c51b9d1938c12d6d55b61513cf
7171
refs/heads/vkedia-patch-2: 7d8241388a9769a5c069334761b06c7012c878e7
7272
refs/heads/vkedia-patch-3: 4d128043acaa7db9160faf439d2ca6104e8a88cb

branches/lesv-patch-1/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)