Skip to content

Commit

Permalink
LocalDnsHelper adds the default change upon creating a zone.
Browse files Browse the repository at this point in the history
This now matches the behaviour of the service. Fixes googleapis#672.
  • Loading branch information
mderka committed Mar 14, 2016
1 parent a26bd59 commit 49f51c4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -680,7 +681,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<String, ResourceRecordSet> 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);
Expand Down Expand Up @@ -718,8 +727,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<Change> changeSequence = zoneContainer.changes();
changeSequence.add(completeChange);
int maxId = changeSequence.size();
Expand All @@ -728,7 +738,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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,14 +850,14 @@ public void testListChanges() {
RPC.create(ZONE1, EMPTY_RPC_OPTIONS);
Iterable<Change> results = RPC.listChangeRequests(ZONE1.getName(), EMPTY_RPC_OPTIONS).results();
ImmutableList<Change> 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<DnsRpc.Option, Object> options = new HashMap<>();
options.put(DnsRpc.Option.PAGE_SIZE, 0);
Expand All @@ -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<Change> descending = ImmutableList.copyOf(results);
results = RPC.listChangeRequests(ZONE1.getName(), EMPTY_RPC_OPTIONS).results();
ImmutableList<Change> 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));
Expand Down

0 comments on commit 49f51c4

Please sign in to comment.