Skip to content

Commit 527c656

Browse files
mderkaaozarov
authored andcommitted
Added DNS helper to testing documentation. (#926)
Added DNS to testing documentation.
1 parent 7d7b799 commit 527c656

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

TESTING.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,40 @@ We recommend that you start the emulator on the remote machine using the [Google
5454
gcloud beta emulators datastore start --host-port <hostname of machine>:<port>
5555
```
5656

57+
### Testing code that uses DNS
58+
59+
#### On your machine
60+
61+
You can test against an in-memory local DNS by following these steps:
62+
63+
1. Before running your testing code, start the DNS emulator `LocalDnsHelper`. This can be done as follows:
64+
65+
```java
66+
long delay = 0;
67+
LocalDnsHelper helper = LocalDnsHelper.create(delay);
68+
helper.start();
69+
```
70+
71+
This will spawn a server thread that listens to `localhost` at an ephemeral port for DNS requests.
72+
The `delay` parameter determines if change requests should be processed synchronously
73+
(value `0`) or in a separate thread with a minimum of delay of `delay` milliseconds.
74+
75+
2. In your program, create the DNS service by using the helper's `options()` method. For example:
76+
77+
```java
78+
Dns dns = LocalDnsHelper.options().service();
79+
```
80+
81+
3. Run your tests.
82+
83+
4. Stop the DNS emulator.
84+
85+
```java
86+
helper.stop();
87+
```
88+
89+
This method will block until the server thread has been terminated.
90+
5791
### Testing code that uses Storage
5892

5993
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
84118

85119
#### On your machine
86120

87-
You can test against a temporary local Resource Manager by following these steps:
121+
You can test against an in-memory local Resource Manager by following these steps:
88122

89123
1. Before running your testing code, start the Resource Manager emulator `LocalResourceManagerHelper`. This can be done as follows:
90124

0 commit comments

Comments
 (0)