Skip to content

Commit 49f51c4

Browse files
committed
LocalDnsHelper adds the default change upon creating a zone.
This now matches the behaviour of the service. Fixes #672.
1 parent a26bd59 commit 49f51c4

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

gcloud-java-dns/src/main/java/com/google/gcloud/dns/testing/LocalDnsHelper.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import java.util.ArrayList;
5757
import java.util.Arrays;
5858
import java.util.HashMap;
59+
import java.util.Iterator;
5960
import java.util.LinkedList;
6061
import java.util.List;
6162
import java.util.Map;
@@ -680,7 +681,15 @@ Response createZone(String projectId, ManagedZone zone, String... fields) {
680681
completeZone.setId(BigInteger.valueOf(Math.abs(ID_GENERATOR.nextLong() % Long.MAX_VALUE)));
681682
completeZone.setNameServers(randomNameservers());
682683
ZoneContainer zoneContainer = new ZoneContainer(completeZone);
683-
zoneContainer.dnsRecords().set(defaultRecords(completeZone));
684+
ImmutableSortedMap<String, ResourceRecordSet> defaultsRecords = defaultRecords(completeZone);
685+
zoneContainer.dnsRecords().set(defaultsRecords);
686+
Change change = new Change();
687+
change.setAdditions(ImmutableList.copyOf(defaultsRecords.values()));
688+
change.setStatus("done");
689+
change.setId("0");
690+
change.setStartTime(ISODateTimeFormat.dateTime().withZoneUTC()
691+
.print(System.currentTimeMillis()));
692+
zoneContainer.changes().add(change);
684693
ProjectContainer projectContainer = findProject(projectId);
685694
ZoneContainer oldValue = projectContainer.zones().putIfAbsent(
686695
completeZone.getName(), zoneContainer);
@@ -718,8 +727,9 @@ Response createChange(String projectId, String zoneName, Change change, String..
718727
completeChange.setDeletions(ImmutableList.copyOf(change.getDeletions()));
719728
}
720729
/* We need to set ID for the change. We are working in concurrent environment. We know that the
721-
element fell on an index between 0 and maxId, so we will reset all IDs in this range (all of
722-
them are valid for the respective objects). */
730+
element fell on an index between 1 and maxId (index 0 is the default change which creates SOA
731+
and NS), so we will reset all IDs between 0 and maxId (all of them are valid for the respective
732+
objects). */
723733
ConcurrentLinkedQueue<Change> changeSequence = zoneContainer.changes();
724734
changeSequence.add(completeChange);
725735
int maxId = changeSequence.size();
@@ -728,7 +738,7 @@ Response createChange(String projectId, String zoneName, Change change, String..
728738
if (index == maxId) {
729739
break;
730740
}
731-
c.setId(String.valueOf(++index));
741+
c.setId(String.valueOf(index++));
732742
}
733743
completeChange.setStatus("pending");
734744
completeChange.setStartTime(ISODateTimeFormat.dateTime().withZoneUTC()

gcloud-java-dns/src/test/java/com/google/gcloud/dns/testing/LocalDnsHelperTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -850,14 +850,14 @@ public void testListChanges() {
850850
RPC.create(ZONE1, EMPTY_RPC_OPTIONS);
851851
Iterable<Change> results = RPC.listChangeRequests(ZONE1.getName(), EMPTY_RPC_OPTIONS).results();
852852
ImmutableList<Change> changes = ImmutableList.copyOf(results);
853-
assertEquals(0, changes.size());
853+
assertEquals(1, changes.size());
854854
// zone has changes
855855
RPC.applyChangeRequest(ZONE1.getName(), CHANGE1, EMPTY_RPC_OPTIONS);
856856
RPC.applyChangeRequest(ZONE1.getName(), CHANGE2, EMPTY_RPC_OPTIONS);
857857
RPC.applyChangeRequest(ZONE1.getName(), CHANGE_KEEP, EMPTY_RPC_OPTIONS);
858858
results = RPC.listChangeRequests(ZONE1.getName(), EMPTY_RPC_OPTIONS).results();
859859
changes = ImmutableList.copyOf(results);
860-
assertEquals(3, changes.size());
860+
assertEquals(4, changes.size());
861861
// error in options
862862
Map<DnsRpc.Option, Object> options = new HashMap<>();
863863
options.put(DnsRpc.Option.PAGE_SIZE, 0);
@@ -881,14 +881,14 @@ public void testListChanges() {
881881
options.put(DnsRpc.Option.PAGE_SIZE, 15);
882882
results = RPC.listChangeRequests(ZONE1.getName(), options).results();
883883
changes = ImmutableList.copyOf(results);
884-
assertEquals(3, changes.size());
884+
assertEquals(4, changes.size());
885885
options = new HashMap<>();
886886
options.put(DnsRpc.Option.SORTING_ORDER, "descending");
887887
results = RPC.listChangeRequests(ZONE1.getName(), options).results();
888888
ImmutableList<Change> descending = ImmutableList.copyOf(results);
889889
results = RPC.listChangeRequests(ZONE1.getName(), EMPTY_RPC_OPTIONS).results();
890890
ImmutableList<Change> ascending = ImmutableList.copyOf(results);
891-
int size = 3;
891+
int size = 4;
892892
assertEquals(size, descending.size());
893893
for (int i = 0; i < size; i++) {
894894
assertEquals(descending.get(i), ascending.get(size - i - 1));

0 commit comments

Comments
 (0)