Skip to content

Commit

Permalink
Assigned project ID to the helper and test.
Browse files Browse the repository at this point in the history
  • Loading branch information
mderka committed Mar 4, 2016
1 parent 1be9ccc commit 4f92e34
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public class LocalDnsHelper {
private long delayChange;
private final HttpServer server;
private final int port;
private String projectId;

/**
* For matching URLs to operations.
Expand Down Expand Up @@ -357,8 +358,9 @@ private Response handleZoneCreate(HttpExchange exchange, String projectId, Strin
}
}

private LocalDnsHelper(long delay) {
private LocalDnsHelper(String projectId, long delay) {
this.delayChange = delay;
this.projectId = projectId;
try {
server = HttpServer.create(new InetSocketAddress(0), 0);
port = server.getAddress().getPort();
Expand All @@ -383,15 +385,15 @@ ConcurrentSkipListMap<String, ProjectContainer> projects() {
*
* @param delay delay for processing changes in ms or 0 for synchronous processing
*/
public static LocalDnsHelper create(Long delay) {
return new LocalDnsHelper(delay);
public static LocalDnsHelper create(String projectId, Long delay) {
return new LocalDnsHelper(projectId, delay);
}

/**
* Returns a {@link DnsOptions} instance that sets the host to use the mock server.
*/
public DnsOptions options() {
return DnsOptions.builder().host("http://localhost:" + port).build();
return DnsOptions.builder().projectId(projectId).host("http://localhost:" + port).build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.gcloud.dns.DnsException;
import com.google.gcloud.dns.DnsOptions;
import com.google.gcloud.spi.DefaultDnsRpc;
import com.google.gcloud.spi.DnsRpc;

Expand Down Expand Up @@ -64,10 +65,11 @@ public class LocalDnsHelperTest {
private static final Change CHANGE2 = new Change();
private static final Change CHANGE_KEEP = new Change();
private static final Change CHANGE_COMPLEX = new Change();
private static final LocalDnsHelper LOCAL_DNS_HELPER = LocalDnsHelper.create(0L); // synchronous
private static final String REAL_PROJECT_ID = "someprojectid";
private static final LocalDnsHelper LOCAL_DNS_HELPER = LocalDnsHelper.create(REAL_PROJECT_ID, 0L);
private static final Map<DnsRpc.Option, ?> EMPTY_RPC_OPTIONS = ImmutableMap.of();
private static final DnsRpc RPC = new DefaultDnsRpc(LOCAL_DNS_HELPER.options());
private static final String REAL_PROJECT_ID = LOCAL_DNS_HELPER.options().projectId();
private static final DnsRpc RPC = new DefaultDnsRpc(LOCAL_DNS_HELPER.options().toBuilder()
.projectId(REAL_PROJECT_ID).build());
private Map<String, Object> optionsMap;

@BeforeClass
Expand Down Expand Up @@ -396,9 +398,10 @@ public void testCreateAndApplyChange() {

@Test
public void testCreateAndApplyChangeWithThreads() {
LocalDnsHelper localDnsThreaded = LocalDnsHelper.create(50L);
LocalDnsHelper localDnsThreaded = LocalDnsHelper.create(REAL_PROJECT_ID, 50L);
localDnsThreaded.start();
DnsRpc rpc = new DefaultDnsRpc(localDnsThreaded.options());
DnsRpc rpc = new DefaultDnsRpc(localDnsThreaded.options().toBuilder()
.projectId(REAL_PROJECT_ID).build());
executeCreateAndApplyChangeTest(rpc);
localDnsThreaded.stop();
}
Expand Down

0 comments on commit 4f92e34

Please sign in to comment.