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 f9cd1a11281e..3b18ec5ce55b 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 @@ -680,7 +680,15 @@ Response createZone(String projectId, ManagedZone zone, String... fields) { completeZone.setId(BigInteger.valueOf(Math.abs(ID_GENERATOR.nextLong() % Long.MAX_VALUE))); completeZone.setNameServers(randomNameservers()); ZoneContainer zoneContainer = new ZoneContainer(completeZone); - zoneContainer.dnsRecords().set(defaultRecords(completeZone)); + ImmutableSortedMap defaultsRecords = defaultRecords(completeZone); + zoneContainer.dnsRecords().set(defaultsRecords); + Change change = new Change(); + change.setAdditions(ImmutableList.copyOf(defaultsRecords.values())); + change.setStatus("done"); + change.setId("0"); + change.setStartTime(ISODateTimeFormat.dateTime().withZoneUTC() + .print(System.currentTimeMillis())); + zoneContainer.changes().add(change); ProjectContainer projectContainer = findProject(projectId); ZoneContainer oldValue = projectContainer.zones().putIfAbsent( completeZone.getName(), zoneContainer); @@ -718,8 +726,9 @@ Response createChange(String projectId, String zoneName, Change change, String.. completeChange.setDeletions(ImmutableList.copyOf(change.getDeletions())); } /* We need to set ID for the change. We are working in concurrent environment. We know that the - element fell on an index between 0 and maxId, so we will reset all IDs in this range (all of - them are valid for the respective objects). */ + element fell on an index between 1 and maxId (index 0 is the default change which creates SOA + and NS), so we will reset all IDs between 0 and maxId (all of them are valid for the respective + objects). */ ConcurrentLinkedQueue changeSequence = zoneContainer.changes(); changeSequence.add(completeChange); int maxId = changeSequence.size(); @@ -728,7 +737,7 @@ Response createChange(String projectId, String zoneName, Change change, String.. if (index == maxId) { break; } - c.setId(String.valueOf(++index)); + c.setId(String.valueOf(index++)); } completeChange.setStatus("pending"); completeChange.setStartTime(ISODateTimeFormat.dateTime().withZoneUTC() 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 2d049e4ffeea..15fa437eb631 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 @@ -850,14 +850,14 @@ public void testListChanges() { RPC.create(ZONE1, EMPTY_RPC_OPTIONS); Iterable results = RPC.listChangeRequests(ZONE1.getName(), EMPTY_RPC_OPTIONS).results(); ImmutableList changes = ImmutableList.copyOf(results); - assertEquals(0, changes.size()); + assertEquals(1, changes.size()); // zone has changes RPC.applyChangeRequest(ZONE1.getName(), CHANGE1, EMPTY_RPC_OPTIONS); RPC.applyChangeRequest(ZONE1.getName(), CHANGE2, EMPTY_RPC_OPTIONS); RPC.applyChangeRequest(ZONE1.getName(), CHANGE_KEEP, EMPTY_RPC_OPTIONS); results = RPC.listChangeRequests(ZONE1.getName(), EMPTY_RPC_OPTIONS).results(); changes = ImmutableList.copyOf(results); - assertEquals(3, changes.size()); + assertEquals(4, changes.size()); // error in options Map options = new HashMap<>(); options.put(DnsRpc.Option.PAGE_SIZE, 0); @@ -881,14 +881,14 @@ public void testListChanges() { options.put(DnsRpc.Option.PAGE_SIZE, 15); results = RPC.listChangeRequests(ZONE1.getName(), options).results(); changes = ImmutableList.copyOf(results); - assertEquals(3, changes.size()); + assertEquals(4, changes.size()); options = new HashMap<>(); options.put(DnsRpc.Option.SORTING_ORDER, "descending"); results = RPC.listChangeRequests(ZONE1.getName(), options).results(); ImmutableList descending = ImmutableList.copyOf(results); results = RPC.listChangeRequests(ZONE1.getName(), EMPTY_RPC_OPTIONS).results(); ImmutableList ascending = ImmutableList.copyOf(results); - int size = 3; + int size = 4; assertEquals(size, descending.size()); for (int i = 0; i < size; i++) { assertEquals(descending.get(i), ascending.get(size - i - 1));