Skip to content

Commit

Permalink
Added integration test for invalid change request.
Browse files Browse the repository at this point in the history
Also added checks for the exceptions being non-retryable.
Closes googleapis#673.
  • Loading branch information
mderka committed Mar 15, 2016
1 parent 96e380c commit 6dac63f
Showing 1 changed file with 78 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@

public class ITDnsTest {

// todo(mderka) Implement test for creating invalid change when DnsException is finished. #673

private static final String PREFIX = "gcldjvit-";
private static final Dns DNS = DnsOptions.builder().build().service();
private static final String ZONE_NAME1 = (PREFIX + UUID.randomUUID()).substring(0, 32);
Expand Down Expand Up @@ -201,14 +199,14 @@ public void testCreateZoneWithErrors() {
fail("Zone name is missing a period. The service returns an error.");
} catch (DnsException ex) {
// expected
// todo(mderka) test non-retryable when implemented within #593
assertFalse(ex.retryable());
}
try {
DNS.create(ZONE_DNS_NO_PERIOD);
fail("Zone name is missing a period. The service returns an error.");
} catch (DnsException ex) {
// expected
// todo(mderka) test non-retryable when implemented within #593
assertFalse(ex.retryable());
}
} finally {
DNS.delete(ZONE_NAME_ERROR.name());
Expand Down Expand Up @@ -393,15 +391,15 @@ public void testListZones() {
} catch (DnsException ex) {
// expected
assertEquals(400, ex.code());
// todo(mderka) test not-retryable
assertFalse(ex.retryable());
}
try {
DNS.listZones(Dns.ZoneListOption.pageSize(-1));
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.code());
// todo(mderka) test not-retryable
assertFalse(ex.retryable());
}
// ok size
zones = filter(DNS.listZones(Dns.ZoneListOption.pageSize(1000)).iterateAll());
Expand All @@ -413,7 +411,7 @@ public void testListZones() {
} catch (DnsException ex) {
// expected
assertEquals(400, ex.code());
// todo(mderka) test not-retryable
assertFalse(ex.retryable());
}
// ok name
zones = filter(DNS.listZones(Dns.ZoneListOption.dnsName(ZONE1.dnsName())).iterateAll());
Expand Down Expand Up @@ -586,6 +584,73 @@ public void testCreateChange() {
}
}

@Test
public void testInvalidChangeRequest() {
Zone zone = DNS.create(ZONE1);
DnsRecord validA = DnsRecord.builder("subdomain." + zone.dnsName(), DnsRecord.Type.A)
.records(ImmutableList.of("0.255.1.5"))
.build();
try {
ChangeRequest validChange = ChangeRequest.builder().add(validA).build();
zone.applyChangeRequest(validChange);
try {
zone.applyChangeRequest(validChange);
fail();
} catch (DnsException ex) {
// expected
assertFalse(ex.retryable());
assertEquals(409, ex.code());
}
// delete with field mismatch
DnsRecord mismatch = validA.toBuilder().ttl(20, TimeUnit.SECONDS).build();
ChangeRequest deletion = ChangeRequest.builder().delete(mismatch).build();
try {
zone.applyChangeRequest(deletion);
fail();
} catch (DnsException ex) {
// expected
assertEquals(412, ex.code());
assertFalse(ex.retryable());
}
// delete and add SOA
Iterator<DnsRecord> recordIterator = zone.listDnsRecords().iterateAll();
LinkedList<DnsRecord> deletions = new LinkedList<>();
LinkedList<DnsRecord> additions = new LinkedList<>();
while (recordIterator.hasNext()) {
DnsRecord record = recordIterator.next();
if (record.type() == DnsRecord.Type.SOA) {
deletions.add(record);
DnsRecord copy = record.toBuilder().name("x." + record.name()).build();
additions.add(copy);
break;
}
}
deletion = deletion.toBuilder().deletions(deletions).build();
ChangeRequest addition = ChangeRequest.builder().additions(additions).build();
try {
zone.applyChangeRequest(deletion);
fail();
} catch (DnsException ex) {
// expected
assertFalse(ex.retryable());
assertEquals(400, ex.code());
}
try {
zone.applyChangeRequest(addition);
fail();
} catch (DnsException ex) {
// expected
assertFalse(ex.retryable());
assertEquals(400, ex.code());
}
} finally {
ChangeRequest deletion = ChangeRequest.builder().delete(validA).build();
ChangeRequest request = zone.applyChangeRequest(deletion);
waitForChangeToComplete(zone.name(), request.id());
zone.delete();
}
}

@Test
public void testListChanges() {
try {
Expand All @@ -596,7 +661,7 @@ public void testListChanges() {
} catch (DnsException ex) {
// expected
assertEquals(404, ex.code());
// todo(mderka) test retry functionality
assertFalse(ex.retryable());
}
// zone exists but has no changes
DNS.create(ZONE1);
Expand All @@ -621,15 +686,15 @@ public void testListChanges() {
} catch (DnsException ex) {
// expected
assertEquals(400, ex.code());
// todo(mderka) test retry functionality
assertFalse(ex.retryable());
}
try {
DNS.listChangeRequests(ZONE1.name(), Dns.ChangeRequestListOption.pageSize(-1));
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.code());
// todo(mderka) test retry functionality
assertFalse(ex.retryable());
}
// sorting order
ImmutableList<ChangeRequest> ascending = ImmutableList.copyOf(DNS.listChangeRequests(
Expand Down Expand Up @@ -863,23 +928,23 @@ public void testListDnsRecords() {
} catch (DnsException ex) {
// expected
assertEquals(400, ex.code());
// todo(mderka) test retry functionality when available
assertFalse(ex.retryable());
}
try {
DNS.listDnsRecords(ZONE1.name(), Dns.DnsRecordListOption.pageSize(0));
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.code());
// todo(mderka) test retry functionality when available
assertFalse(ex.retryable());
}
try {
DNS.listDnsRecords(ZONE1.name(), Dns.DnsRecordListOption.pageSize(-1));
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.code());
// todo(mderka) test retry functionality when available
assertFalse(ex.retryable());
}
waitForChangeToComplete(ZONE1.name(), change.id());
} finally {
Expand Down

0 comments on commit 6dac63f

Please sign in to comment.