Skip to content

Commit

Permalink
Added DNS to testing documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
mderka committed Apr 14, 2016
1 parent 13ab36f commit 88aecea
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <hostname of machine>:<port>
```

### Testing code that uses DNS

#### On your machine

You can test against a temporary 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 delay of `delay` milliseconds.

2. In your program, create and use a DNS service object whose host is set to `localhost` at the appropriate port. 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:
Expand Down

0 comments on commit 88aecea

Please sign in to comment.