You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Cleans up local gcd helper and docs to be more consistent with other test helpers
* Renames LocalGcdHelper to LocalDatastoreHelper and RemoteGcsHelper to RemoteStorageHelper
* Updates the gcd.sh script version
Copy file name to clipboardExpand all lines: TESTING.md
+34-25Lines changed: 34 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,55 +11,64 @@ This library provides tools to help write tests for code that uses the following
11
11
12
12
#### On your machine
13
13
14
-
You can test against a temporary local datastore by following these steps:
14
+
You can test against a temporary local Datastore by following these steps:
15
15
16
-
1. Start the local datastore emulator using `LocalGcdHelper`. This can be done in two ways:
17
-
- Run `LocalGcdHelper.java`'s `main` method with arguments `START` and (optionally) `--port=<port number>`. This will create a temporary folder on your computer and bind `localhost:<port number>` for communication with the local datastore. The port number is an optional argument. If no port number is specified, port 8080 will be used.
18
-
- Call `LocalGcdHelper.start(<project ID>, <port number>)` before running your tests. Save the `LocalGcdHelper` object returned so that you can stop the emulator later.
16
+
1. Start the local Datastore emulator before running your tests using `LocalDatastoreHelper`'s `create` and `start` methods. This will create a temporary folder on your computer and bind a port for communication with the local Datastore. There is an optional argument for `create`: consistency. The consistency setting controls the fraction of Datastore writes that are immediately visible in global queries.
- If you ran `LocalGcdHelper.java`'s `main` function to start the emulator, run `LocalGcdHelper.java`'s `main` method with arguments `STOP` and (optionally) `--port=<port number>`. If the port is not supplied, the program will attempt to close the last port started.
32
-
- If you ran `LocalGcdHelper.start()` to start the emulator, call the `stop()` method on the `LocalGcdHelper` object returned by `LocalGcdHelper.start()`.
33
+
4. Stop the local datastore emulator by calling the `stop()` method, like so:
34
+
```java
35
+
helper.stop();
36
+
```
33
37
34
38
#### On a remote machine
35
39
36
-
You can test against a remote datastore emulator as well. To do this, set the `DatastoreOptions` project endpoint to the hostname of the remote machine, like the example below.
40
+
You can test against a remote Datastore emulator as well. To do this, set the `DatastoreOptions` project endpoint to the hostname of the remote machine, like the example below.
.projectId("my-project-id") // must match project ID specified on remote machine
41
45
.host("http://<hostname of machine>:<port>")
46
+
.authCredentials(AuthCredentials.noAuth())
42
47
.build();
43
48
Datastore localDatastore = options.service();
44
49
```
45
50
46
-
Note that the remote datastore must be running before your tests are run.
51
+
We recommend that you start the emulator on the remote machine using the [Google Cloud SDK](https://cloud.google.com/sdk/gcloud/reference/beta/emulators/datastore/) from command line, as shown below:
52
+
53
+
```
54
+
gcloud beta emulators datastore start --host-port <hostname of machine>:<port>
55
+
```
47
56
48
57
### Testing code that uses Storage
49
58
50
-
Currently, there isn't an emulator for Google Cloud Storage, so an alternative is to create a test project. `RemoteGcsHelper` contains convenience methods to make setting up and cleaning up the test project easier. To use this class, follow the steps below:
59
+
Currently, there isn't an emulator for Google Cloud Storage, so an alternative is to create a test project. `RemoteStorageHelper` contains convenience methods to make setting up and cleaning up the test project easier. To use this class, follow the steps below:
51
60
52
61
1. Create a test Google Cloud project.
53
62
54
63
2. Download a JSON service account credentials file from the Google Developer's Console. See more about this on the [Google Cloud Platform Storage Authentication page][cloud-platform-storage-authentication].
55
64
56
-
3. Create a `RemoteGcsHelper` object using your project ID and JSON key.
57
-
Here is an example that uses the `RemoteGcsHelper` to create a bucket.
65
+
3. Create a `RemoteStorageHelper` object using your project ID and JSON key.
66
+
Here is an example that uses the `RemoteStorageHelper` to create a bucket.
0 commit comments