Skip to content

Commit

Permalink
Added sleep and renamed change completion check.
Browse files Browse the repository at this point in the history
  • Loading branch information
mderka committed Mar 1, 2016
1 parent 75269ff commit c29b405
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions gcloud-java-dns/src/test/java/com/google/gcloud/dns/ITDnsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,20 @@ public class ITDnsTest {
.description(ZONE_DESCRIPTION1)
.dnsName(ZONE_DNS_NAME1)
.build();
public static final ZoneInfo ZONE_NAME_ERROR =
ZoneInfo.builder(ZONE_NAME_TOO_LONG)
.description(ZONE_DESCRIPTION1)
.dnsName(ZONE_DNS_NAME1)
.build();
public static final ZoneInfo ZONE_MISSING_DESCRIPTION =
ZoneInfo.builder(ZONE_NAME1)
.dnsName(ZONE_DNS_NAME1)
.build();
public static final ZoneInfo ZONE_MISSING_DNS_NAME =
ZoneInfo.builder(ZONE_NAME1)
.description(ZONE_DESCRIPTION1)
.build();
public static final ZoneInfo ZONE_DNS_NO_PERIOD =
ZoneInfo.builder(ZONE_NAME1)
.description(ZONE_DESCRIPTION1)
.dnsName(ZONE_DNS_NAME_NO_PERIOD)
.build();
public static final ZoneInfo ZONE_NAME_ERROR = ZoneInfo.builder(ZONE_NAME_TOO_LONG)
.description(ZONE_DESCRIPTION1)
.dnsName(ZONE_DNS_NAME1)
.build();
public static final ZoneInfo ZONE_MISSING_DESCRIPTION = ZoneInfo.builder(ZONE_NAME1)
.dnsName(ZONE_DNS_NAME1)
.build();
public static final ZoneInfo ZONE_MISSING_DNS_NAME = ZoneInfo.builder(ZONE_NAME1)
.description(ZONE_DESCRIPTION1)
.build();
public static final ZoneInfo ZONE_DNS_NO_PERIOD = ZoneInfo.builder(ZONE_NAME1)
.description(ZONE_DESCRIPTION1)
.dnsName(ZONE_DNS_NAME_NO_PERIOD)
.build();
public static final DnsRecord A_RECORD_ZONE1 =
DnsRecord.builder("www." + ZONE1.dnsName(), DnsRecord.Type.A)
.records(ImmutableList.of("123.123.55.1"))
Expand Down Expand Up @@ -116,7 +112,7 @@ public static void clear() {
if (!toDelete.isEmpty()) {
ChangeRequest deletion =
zone.applyChangeRequest(ChangeRequest.builder().deletions(toDelete).build());
checkChangeComplete(zone.name(), deletion.id());
waitUntilComplete(zone.name(), deletion.id());
}
zone.delete();
}
Expand Down Expand Up @@ -150,12 +146,17 @@ private static void assertEqChangesIgnoreStatus(ChangeRequest expected, ChangeRe
assertEquals(unifiedEx, unifiedAct);
}

private static void checkChangeComplete(String zoneName, String changeId) {
private static void waitUntilComplete(String zoneName, String changeId) {
while (true) {
ChangeRequest changeRequest = DNS.getChangeRequest(zoneName, changeId,
Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.STATUS));
if (ChangeRequest.Status.DONE.equals(changeRequest.status())) {
break;
return;
}
try {
Thread.sleep(10);
} catch (InterruptedException e) {
fail("Thread was interrupted while waiting for change proceesing.");
}
}
}
Expand Down Expand Up @@ -529,7 +530,6 @@ public void testDeleteZone() {
}
}


@Test
public void testCreateChange() {
try {
Expand All @@ -542,9 +542,9 @@ public void testCreateChange() {
assertTrue(ImmutableList.of(ChangeRequest.Status.PENDING, ChangeRequest.Status.DONE)
.contains(created.status()));
assertEqChangesIgnoreStatus(created, DNS.getChangeRequest(ZONE1.name(), "1"));
checkChangeComplete(ZONE1.name(), "1");
waitUntilComplete(ZONE1.name(), "1");
DNS.applyChangeRequest(ZONE1.name(), CHANGE_DELETE_ZONE1);
checkChangeComplete(ZONE1.name(), "2");
waitUntilComplete(ZONE1.name(), "2");
// with options
created = DNS.applyChangeRequest(ZONE1.name(), CHANGE_ADD_ZONE1,
Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.ID));
Expand All @@ -553,29 +553,29 @@ public void testCreateChange() {
assertTrue(created.deletions().isEmpty());
assertEquals("3", created.id());
assertNull(created.status());
checkChangeComplete(ZONE1.name(), "3");
waitUntilComplete(ZONE1.name(), "3");
DNS.applyChangeRequest(ZONE1.name(), CHANGE_DELETE_ZONE1);
checkChangeComplete(ZONE1.name(), "4");
waitUntilComplete(ZONE1.name(), "4");
created = DNS.applyChangeRequest(ZONE1.name(), CHANGE_ADD_ZONE1,
Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.STATUS));
assertTrue(created.additions().isEmpty());
assertNull(created.startTimeMillis());
assertTrue(created.deletions().isEmpty());
assertEquals("5", created.id());
assertNotNull(created.status());
checkChangeComplete(ZONE1.name(), "5");
waitUntilComplete(ZONE1.name(), "5");
DNS.applyChangeRequest(ZONE1.name(), CHANGE_DELETE_ZONE1);
checkChangeComplete(ZONE1.name(), "6");
waitUntilComplete(ZONE1.name(), "6");
created = DNS.applyChangeRequest(ZONE1.name(), CHANGE_ADD_ZONE1,
Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.START_TIME));
assertTrue(created.additions().isEmpty());
assertNotNull(created.startTimeMillis());
assertTrue(created.deletions().isEmpty());
assertEquals("7", created.id());
assertNull(created.status());
checkChangeComplete(ZONE1.name(), "7");
waitUntilComplete(ZONE1.name(), "7");
DNS.applyChangeRequest(ZONE1.name(), CHANGE_DELETE_ZONE1);
checkChangeComplete(ZONE1.name(), "8");
waitUntilComplete(ZONE1.name(), "8");
created = DNS.applyChangeRequest(ZONE1.name(), CHANGE_ADD_ZONE1,
Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.ADDITIONS));
assertEquals(CHANGE_ADD_ZONE1.additions(), created.additions());
Expand All @@ -584,16 +584,16 @@ public void testCreateChange() {
assertEquals("9", created.id());
assertNull(created.status());
// finishes with delete otherwise we cannot delete the zone
checkChangeComplete(ZONE1.name(), "9");
waitUntilComplete(ZONE1.name(), "9");
created = DNS.applyChangeRequest(ZONE1.name(), CHANGE_DELETE_ZONE1,
Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.DELETIONS));
checkChangeComplete(ZONE1.name(), "10");
waitUntilComplete(ZONE1.name(), "10");
assertEquals(CHANGE_DELETE_ZONE1.deletions(), created.deletions());
assertNull(created.startTimeMillis());
assertTrue(created.additions().isEmpty());
assertEquals("10", created.id());
assertNull(created.status());
checkChangeComplete(ZONE1.name(), "10");
waitUntilComplete(ZONE1.name(), "10");
} finally {
clear();
}
Expand All @@ -618,13 +618,13 @@ public void testListChanges() {
assertEquals(1, changes.size()); // default change creating SOA and NS
// zone has changes
ChangeRequest change = DNS.applyChangeRequest(ZONE1.name(), CHANGE_ADD_ZONE1);
checkChangeComplete(ZONE1.name(), change.id());
waitUntilComplete(ZONE1.name(), change.id());
change = DNS.applyChangeRequest(ZONE1.name(), CHANGE_DELETE_ZONE1);
checkChangeComplete(ZONE1.name(), change.id());
waitUntilComplete(ZONE1.name(), change.id());
change = DNS.applyChangeRequest(ZONE1.name(), CHANGE_ADD_ZONE1);
checkChangeComplete(ZONE1.name(), change.id());
waitUntilComplete(ZONE1.name(), change.id());
change = DNS.applyChangeRequest(ZONE1.name(), CHANGE_DELETE_ZONE1);
checkChangeComplete(ZONE1.name(), change.id());
waitUntilComplete(ZONE1.name(), change.id());
changes = ImmutableList.copyOf(DNS.listChangeRequests(ZONE1.name()).iterateAll());
assertEquals(5, changes.size());
// error in options
Expand Down Expand Up @@ -846,7 +846,7 @@ public void testListDnsRecords() {
assertEquals(1, ImmutableList.copyOf(dnsRecordPage.values().iterator()).size());
// test name filter
ChangeRequest change = DNS.applyChangeRequest(ZONE1.name(), CHANGE_ADD_ZONE1);
checkChangeComplete(ZONE1.name(), change.id());
waitUntilComplete(ZONE1.name(), change.id());
dnsRecordIterator = DNS.listDnsRecords(ZONE1.name(),
Dns.DnsRecordListOption.dnsName(A_RECORD_ZONE1.name())).iterateAll();
counter = 0;
Expand All @@ -858,7 +858,7 @@ public void testListDnsRecords() {
}
assertEquals(2, counter);
// test type filter
checkChangeComplete(ZONE1.name(), change.id());
waitUntilComplete(ZONE1.name(), change.id());
dnsRecordIterator = DNS.listDnsRecords(ZONE1.name(),
Dns.DnsRecordListOption.dnsName(A_RECORD_ZONE1.name()),
Dns.DnsRecordListOption.type(A_RECORD_ZONE1.type()))
Expand Down Expand Up @@ -897,7 +897,7 @@ public void testListDnsRecords() {
assertEquals(400, ex.code());
// todo(mderka) test retry functionality when available
}
checkChangeComplete(ZONE1.name(), change.id());
waitUntilComplete(ZONE1.name(), change.id());
} finally {
clear();
}
Expand Down

0 comments on commit c29b405

Please sign in to comment.