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
Copy file name to clipboardExpand all lines: SUPPORTING_NEW_SERVICES.md
+2-4Lines changed: 2 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
This document outlines how to add support for a new service in `google-cloud`. New services should be submodules located in a folder within the main repository, built using Maven. A new service should contain the following items:
6
6
7
-
* An API layer, with which users will interact. This includes model objects and a service class.
7
+
* An API layer, with which users will interact. This includes model objects and a service class.
8
8
* An SPI layer, which translates google-cloud API calls into RPCs using an autogenerated client library. In almost all use cases, the user will not directly interact with this code. Separating this code from the API layer provides two benefits. First, it allows the API layer to remain stable despite changes to the autogenerated libraries used. Second, it makes testing easier, since the RPC implementation can be substituted with a mock.
9
9
* A test helper class, which allows users to easily interact with a local service emulator (if possible). If there is no emulator available and the service is too complex to create a mock, then a remote test helper should be provided to separate test data from other user data and enable easy cleanup.
10
10
* Tests, including unit tests and integration tests.
@@ -61,9 +61,7 @@ Test helper classes should be located in the package `com.google.cloud.servicena
61
61
There are three types of test helpers:
62
62
* When a local emulator is already available, your test helper should launch that emulator and return service options to connect to that local emulator. This enables both users and our own library to run unit tests easily. An example of this type of helper is `LocalDatastoreHelper`. Google Cloud Datastore provides a script that launches a local datastore, so `LocalDatastoreHelper` launches that script in a separate process when the user calls `start()`.
63
63
64
-
* When there is no local emulator but the service is simple enough to write an emulator, you should do so. The emulator should listen to a port for requests, process those requests, and send responses back, being as true to the actual service as possible. Dependencies in this mock should be as lightweight as possible. Be sure to document differences between your emulator and the actual service. Examples of this type of test helper are `LocalResourceManagerHelper` and `LocalDnsHelper`.
65
-
66
-
* When there is no local emulator and the service is too complex to write a solid emulator, the test helper should contain methods to get options and to help isolate test data from production data. `RemoteStorageHelper` is an example of this type of test helper, since there is no local emulator for Google Cloud Storage (at the time that this was written) and because the Google Cloud Storage API is complex. `RemoteStorageHelper` has methods to:
64
+
* When there is no local emulator, the test helper should contain methods to get options and to help isolate test data from production data. `RemoteStorageHelper` is an example of this type of test helper, since there is no local emulator for Google Cloud Storage (at the time that this was written) and because the Google Cloud Storage API is complex. `RemoteStorageHelper` has methods to:
67
65
* Get service options settings.
68
66
* Create a test bucket with a sufficiently obscure name (to separate the bucket from any of the users other data).
69
67
* Clean up data left over from tests in that test bucket.
This will spawn a server thread that listens to `localhost` at an ephemeral port for DNS requests.
131
-
The `delay` parameter determines if change requests should be processed synchronously
132
-
(value `0`) or in a separate thread with a minimum of delay of `delay` milliseconds.
133
-
134
-
2. In your program, create the DNS service by using the helper's `getOptions()` method.
135
-
For example:
136
-
137
-
```java
138
-
Dns dns =LocalDnsHelper.getOptions().getService();
139
-
```
140
-
141
-
3. Run your tests.
142
-
143
-
4. Stop the DNS emulator.
144
-
145
-
```java
146
-
helper.stop();
147
-
```
148
-
149
-
This method will block until the server thread has been terminated.
150
-
151
115
### Testing code that uses Logging
152
116
153
117
Currently, there isn't an emulator for Stackdriver Logging, so an alternative is to create a test
@@ -251,7 +215,7 @@ Currently, there isn't an emulator for Google Cloud Storage, so an alternative i
251
215
252
216
1. Create a test Google Cloud project.
253
217
254
-
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].
218
+
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].
255
219
256
220
3. Create a `RemoteStorageHelper` object using your project ID and JSON key.
257
221
Here is an example that uses the `RemoteStorageHelper` to create a bucket.
0 commit comments