diff --git a/TESTING.md b/TESTING.md index aecd6140b79f..7ae34db4c4f1 100644 --- a/TESTING.md +++ b/TESTING.md @@ -54,6 +54,40 @@ We recommend that you start the emulator on the remote machine using the [Google gcloud beta emulators datastore start --host-port : ``` +### Testing code that uses DNS + +#### On your machine + +You can test against an in-memory local DNS by following these steps: + +1. Before running your testing code, start the DNS emulator `LocalDnsHelper`. This can be done as follows: + + ```java + long delay = 0; + LocalDnsHelper helper = LocalDnsHelper.create(delay); + helper.start(); + ``` + + This will spawn a server thread that listens to `localhost` at an ephemeral port for DNS requests. + The `delay` parameter determines if change requests should be processed synchronously + (value `0`) or in a separate thread with a minimum of delay of `delay` milliseconds. + +2. In your program, create the DNS service by using the helper's `options()` method. For example: + + ```java + Dns dns = LocalDnsHelper.options().service(); + ``` + +3. Run your tests. + +4. Stop the DNS emulator. + + ```java + helper.stop(); + ``` + + This method will block until the server thread has been terminated. + ### Testing code that uses Storage 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: @@ -84,7 +118,7 @@ Here is an example that clears the bucket created in Step 3 with a timeout of 5 #### On your machine -You can test against a temporary local Resource Manager by following these steps: +You can test against an in-memory local Resource Manager by following these steps: 1. Before running your testing code, start the Resource Manager emulator `LocalResourceManagerHelper`. This can be done as follows: