diff --git a/gcloud-java-dns/src/main/java/com/google/gcloud/dns/testing/LocalDnsHelper.java b/gcloud-java-dns/src/main/java/com/google/gcloud/dns/testing/LocalDnsHelper.java index 4eca683f1a08..48df7bc20f50 100644 --- a/gcloud-java-dns/src/main/java/com/google/gcloud/dns/testing/LocalDnsHelper.java +++ b/gcloud-java-dns/src/main/java/com/google/gcloud/dns/testing/LocalDnsHelper.java @@ -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. @@ -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(); @@ -383,15 +385,15 @@ ConcurrentSkipListMap 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(); } /** diff --git a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/testing/LocalDnsHelperTest.java b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/testing/LocalDnsHelperTest.java index 489b935d7e50..d8e77605173f 100644 --- a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/testing/LocalDnsHelperTest.java +++ b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/testing/LocalDnsHelperTest.java @@ -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; @@ -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 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 optionsMap; @BeforeClass @@ -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(); }