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 14, 2016
1 parent 96e380c commit 61a44c9
Showing 1 changed file with 84 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.gcloud.dns.it;

import static com.google.gcloud.dns.Dns.DnsRecordListOption.type;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -48,8 +49,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 +200,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 +392,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 +412,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 +585,76 @@ public void testCreateChange() {
}
}

@Test
public void testInvalidChangeRequest() {
try {
Zone zone = DNS.create(ZONE1);
DnsRecord validA = DnsRecord.builder("subdomain." + zone.dnsName(), DnsRecord.Type.A)
.records(ImmutableList.of("0.255.1.5"))
.build();
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 delete = ChangeRequest.builder().delete(mismatch).build();
try {
zone.applyChangeRequest(delete);
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;
}
}
delete = delete.toBuilder().deletions(deletions).build();
ChangeRequest addition = ChangeRequest.builder().additions(additions).build();
try {
zone.applyChangeRequest(delete);
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());
}
delete = delete.toBuilder().deletions(ImmutableList.of(validA)).build();
ChangeRequest request = zone.applyChangeRequest(delete);
waitForChangeToComplete(zone.name(), request.id());
zone.delete();
} finally {
clear();
}
}

@Test
public void testListChanges() {
try {
Expand All @@ -596,7 +665,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 +690,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 @@ -845,7 +914,7 @@ public void testListDnsRecords() {
waitForChangeToComplete(ZONE1.name(), change.id());
dnsRecordIterator = DNS.listDnsRecords(ZONE1.name(),
Dns.DnsRecordListOption.dnsName(A_RECORD_ZONE1.name()),
Dns.DnsRecordListOption.type(A_RECORD_ZONE1.type()))
type(A_RECORD_ZONE1.type()))
.iterateAll();
counter = 0;
while (dnsRecordIterator.hasNext()) {
Expand All @@ -858,28 +927,28 @@ public void testListDnsRecords() {
// check wrong arguments
try {
// name is not set
DNS.listDnsRecords(ZONE1.name(), Dns.DnsRecordListOption.type(A_RECORD_ZONE1.type()));
DNS.listDnsRecords(ZONE1.name(), type(A_RECORD_ZONE1.type()));
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(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 61a44c9

Please sign in to comment.