use of com.google.cloud.dns.DnsBatch in project google-cloud-java by GoogleCloudPlatform.
the class ITDnsTest method testBatchCombined.
@Test
public void testBatchCombined() {
// the results are validated in the other test methods
try {
DNS.create(ZONE1);
DnsBatch batch = DNS.batch();
DnsBatchResult<Zone> zoneResult = batch.getZone(ZONE_NAME1);
DnsBatchResult<ChangeRequest> changeRequestResult = batch.getChangeRequest(ZONE_NAME1, "0");
DnsBatchResult<Page<RecordSet>> pageResult = batch.listRecordSets(ZONE_NAME1);
DnsBatchResult<ProjectInfo> projectResult = batch.getProject();
assertFalse(zoneResult.completed());
try {
zoneResult.get();
fail("this should be submitted first");
} catch (IllegalStateException ex) {
// expected
}
batch.submit();
assertNotNull(zoneResult.get().getCreationTimeMillis());
assertEquals(ZONE1.getDnsName(), zoneResult.get().getDnsName());
assertEquals(ZONE1.getDescription(), zoneResult.get().getDescription());
assertFalse(zoneResult.get().getNameServers().isEmpty());
// we did not set it
assertNull(zoneResult.get().getNameServerSet());
assertNotNull(zoneResult.get().getGeneratedId());
assertNotNull(projectResult.get().getQuota());
assertEquals(2, Iterables.size(pageResult.get().getValues()));
assertNotNull(changeRequestResult.get());
} finally {
DNS.delete(ZONE1.getName());
}
}
use of com.google.cloud.dns.DnsBatch in project google-cloud-java by GoogleCloudPlatform.
the class ITDnsTest method testListChangesBatch.
@Test
public void testListChangesBatch() {
try {
DnsBatch batch = DNS.batch();
DnsBatchResult<Page<ChangeRequest>> result = batch.listChangeRequests(ZONE1.getName());
batch.submit();
try {
result.get();
fail("Zone does not exist yet");
} catch (DnsException ex) {
// expected
assertEquals(404, ex.getCode());
assertFalse(ex.isRetryable());
}
// zone exists but has no changes
DNS.create(ZONE1);
batch = DNS.batch();
result = batch.listChangeRequests(ZONE1.getName());
batch.submit();
// default change creating SOA and NS
assertEquals(1, Iterables.size(result.get().getValues()));
// zone has changes
ChangeRequest change = DNS.applyChangeRequest(ZONE1.getName(), CHANGE_ADD_ZONE1);
waitForChangeToComplete(ZONE1.getName(), change.getGeneratedId());
change = DNS.applyChangeRequest(ZONE1.getName(), CHANGE_DELETE_ZONE1);
waitForChangeToComplete(ZONE1.getName(), change.getGeneratedId());
batch = DNS.batch();
result = batch.listChangeRequests(ZONE1.getName());
DnsBatchResult<Page<ChangeRequest>> errorPageSize = batch.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.pageSize(0));
DnsBatchResult<Page<ChangeRequest>> errorPageNegative = batch.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.pageSize(-1));
DnsBatchResult<Page<ChangeRequest>> resultAscending = batch.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.ASCENDING));
DnsBatchResult<Page<ChangeRequest>> resultDescending = batch.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.DESCENDING));
DnsBatchResult<Page<ChangeRequest>> resultAdditions = batch.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.ASCENDING), Dns.ChangeRequestListOption.fields(ChangeRequestField.ADDITIONS));
DnsBatchResult<Page<ChangeRequest>> resultDeletions = batch.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.ASCENDING), Dns.ChangeRequestListOption.fields(ChangeRequestField.DELETIONS));
DnsBatchResult<Page<ChangeRequest>> resultId = batch.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.ASCENDING), Dns.ChangeRequestListOption.fields(ChangeRequestField.ID));
DnsBatchResult<Page<ChangeRequest>> resultTime = batch.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.ASCENDING), Dns.ChangeRequestListOption.fields(ChangeRequestField.START_TIME));
DnsBatchResult<Page<ChangeRequest>> resultStatus = batch.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.ASCENDING), Dns.ChangeRequestListOption.fields(ChangeRequestField.STATUS));
batch.submit();
assertEquals(3, Iterables.size(result.get().getValues()));
// error in options
try {
errorPageSize.get();
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.getCode());
assertFalse(ex.isRetryable());
}
try {
errorPageNegative.get();
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.getCode());
assertFalse(ex.isRetryable());
}
// sorting order
ImmutableList<ChangeRequest> ascending = ImmutableList.copyOf(resultAscending.get().iterateAll());
ImmutableList<ChangeRequest> descending = ImmutableList.copyOf(resultDescending.get().iterateAll());
int size = 3;
assertEquals(size, descending.size());
assertEquals(size, ascending.size());
for (int i = 0; i < size; i++) {
assertEquals(descending.get(i), ascending.get(size - i - 1));
}
// field options
change = Iterables.get(resultAdditions.get().getValues(), 1);
assertEquals(CHANGE_ADD_ZONE1.getAdditions(), change.getAdditions());
assertTrue(change.getDeletions().isEmpty());
assertNotNull(change.getGeneratedId());
assertNull(change.getStartTimeMillis());
assertNull(change.status());
change = Iterables.get(resultDeletions.get().getValues(), 2);
assertTrue(change.getAdditions().isEmpty());
assertNotNull(change.getDeletions());
assertNotNull(change.getGeneratedId());
assertNull(change.getStartTimeMillis());
assertNull(change.status());
change = Iterables.get(resultId.get().getValues(), 1);
assertTrue(change.getAdditions().isEmpty());
assertTrue(change.getDeletions().isEmpty());
assertNotNull(change.getGeneratedId());
assertNull(change.getStartTimeMillis());
assertNull(change.status());
change = Iterables.get(resultTime.get().getValues(), 1);
assertTrue(change.getAdditions().isEmpty());
assertTrue(change.getDeletions().isEmpty());
assertNotNull(change.getGeneratedId());
assertNotNull(change.getStartTimeMillis());
assertNull(change.status());
change = Iterables.get(resultStatus.get().getValues(), 1);
assertTrue(change.getAdditions().isEmpty());
assertTrue(change.getDeletions().isEmpty());
assertNotNull(change.getGeneratedId());
assertNull(change.getStartTimeMillis());
assertEquals(ChangeRequest.Status.DONE, change.status());
} finally {
clear();
}
}
use of com.google.cloud.dns.DnsBatch in project google-cloud-java by GoogleCloudPlatform.
the class ITDnsTest method testListZonesBatch.
@Test
public void testListZonesBatch() {
try {
DnsBatch batch = DNS.batch();
DnsBatchResult<Page<Zone>> result = batch.listZones();
batch.submit();
List<Zone> zones = filter(result.get().iterateAll().iterator());
assertEquals(0, zones.size());
// some zones exists
Zone firstZone = DNS.create(ZONE1);
batch = DNS.batch();
result = batch.listZones();
batch.submit();
zones = filter(result.get().iterateAll().iterator());
assertEquals(1, zones.size());
assertEquals(firstZone, zones.get(0));
Zone created = DNS.create(ZONE_EMPTY_DESCRIPTION);
batch = DNS.batch();
result = batch.listZones();
DnsBatchResult<Page<Zone>> zeroSizeError = batch.listZones(Dns.ZoneListOption.pageSize(0));
DnsBatchResult<Page<Zone>> negativeSizeError = batch.listZones(Dns.ZoneListOption.pageSize(-1));
DnsBatchResult<Page<Zone>> okSize = batch.listZones(Dns.ZoneListOption.pageSize(1));
DnsBatchResult<Page<Zone>> nameError = batch.listZones(Dns.ZoneListOption.dnsName("aaaaa"));
DnsBatchResult<Page<Zone>> okName = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()));
DnsBatchResult<Page<Zone>> idResult = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.ZONE_ID));
DnsBatchResult<Page<Zone>> timeResult = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.CREATION_TIME));
DnsBatchResult<Page<Zone>> dnsNameResult = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.DNS_NAME));
DnsBatchResult<Page<Zone>> descriptionResult = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.DESCRIPTION));
DnsBatchResult<Page<Zone>> nameServersResult = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.NAME_SERVERS));
DnsBatchResult<Page<Zone>> nameServerSetResult = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.NAME_SERVER_SET));
DnsBatchResult<Page<Zone>> combinationResult = batch.listZones(Dns.ZoneListOption.fields(ZoneField.ZONE_ID, ZoneField.DESCRIPTION), Dns.ZoneListOption.pageSize(1));
batch.submit();
zones = filter(result.get().iterateAll().iterator());
assertEquals(2, zones.size());
assertTrue(zones.contains(firstZone));
assertTrue(zones.contains(created));
// error in options
try {
zeroSizeError.get();
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.getCode());
assertFalse(ex.isRetryable());
}
try {
negativeSizeError.get();
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.getCode());
assertFalse(ex.isRetryable());
}
// ok size
assertEquals(1, Iterables.size(okSize.get().getValues()));
// dns name problems
try {
nameError.get();
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.getCode());
assertFalse(ex.isRetryable());
}
// ok name
zones = filter(okName.get().iterateAll().iterator());
assertEquals(1, zones.size());
// field options
Iterator<Zone> zoneIterator = idResult.get().iterateAll().iterator();
Zone zone = zoneIterator.next();
assertNull(zone.getCreationTimeMillis());
assertNotNull(zone.getName());
assertNull(zone.getDnsName());
assertNull(zone.getDescription());
assertNull(zone.getNameServerSet());
assertTrue(zone.getNameServers().isEmpty());
assertNotNull(zone.getGeneratedId());
assertFalse(zoneIterator.hasNext());
zoneIterator = timeResult.get().iterateAll().iterator();
zone = zoneIterator.next();
assertNotNull(zone.getCreationTimeMillis());
assertNotNull(zone.getName());
assertNull(zone.getDnsName());
assertNull(zone.getDescription());
assertNull(zone.getNameServerSet());
assertTrue(zone.getNameServers().isEmpty());
assertNull(zone.getGeneratedId());
assertFalse(zoneIterator.hasNext());
zoneIterator = dnsNameResult.get().iterateAll().iterator();
zone = zoneIterator.next();
assertNull(zone.getCreationTimeMillis());
assertNotNull(zone.getName());
assertNotNull(zone.getDnsName());
assertNull(zone.getDescription());
assertNull(zone.getNameServerSet());
assertTrue(zone.getNameServers().isEmpty());
assertNull(zone.getGeneratedId());
assertFalse(zoneIterator.hasNext());
zoneIterator = descriptionResult.get().iterateAll().iterator();
zone = zoneIterator.next();
assertNull(zone.getCreationTimeMillis());
assertNotNull(zone.getName());
assertNull(zone.getDnsName());
assertNotNull(zone.getDescription());
assertNull(zone.getNameServerSet());
assertTrue(zone.getNameServers().isEmpty());
assertNull(zone.getGeneratedId());
assertFalse(zoneIterator.hasNext());
zoneIterator = nameServersResult.get().iterateAll().iterator();
zone = zoneIterator.next();
assertNull(zone.getCreationTimeMillis());
assertNotNull(zone.getName());
assertNull(zone.getDnsName());
assertNull(zone.getDescription());
assertNull(zone.getNameServerSet());
assertFalse(zone.getNameServers().isEmpty());
assertNull(zone.getGeneratedId());
assertFalse(zoneIterator.hasNext());
zoneIterator = nameServerSetResult.get().iterateAll().iterator();
zone = zoneIterator.next();
assertNull(zone.getCreationTimeMillis());
assertNotNull(zone.getName());
assertNull(zone.getDnsName());
assertNull(zone.getDescription());
// we cannot set it using google-cloud
assertNull(zone.getNameServerSet());
assertTrue(zone.getNameServers().isEmpty());
assertNull(zone.getGeneratedId());
assertFalse(zoneIterator.hasNext());
// several combined
zones = filter(combinationResult.get().iterateAll().iterator());
assertEquals(2, zones.size());
for (Zone current : zones) {
assertNull(current.getCreationTimeMillis());
assertNotNull(current.getName());
assertNull(current.getDnsName());
assertNotNull(current.getDescription());
assertNull(current.getNameServerSet());
assertTrue(zone.getNameServers().isEmpty());
assertNotNull(current.getGeneratedId());
}
} finally {
DNS.delete(ZONE1.getName());
DNS.delete(ZONE_EMPTY_DESCRIPTION.getName());
}
}
use of com.google.cloud.dns.DnsBatch in project google-cloud-java by GoogleCloudPlatform.
the class ITDnsTest method testCreateZoneWithErrorsBatch.
@Test
public void testCreateZoneWithErrorsBatch() {
try {
DnsBatch batch = DNS.batch();
DnsBatchResult<Zone> nameErrorResult = batch.createZone(ZONE_NAME_ERROR);
DnsBatchResult<Zone> noPeriodResult = batch.createZone(ZONE_DNS_NO_PERIOD);
batch.submit();
try {
nameErrorResult.get();
fail("Zone name is too long. The service returns an error.");
} catch (DnsException ex) {
// expected
assertFalse(ex.isRetryable());
}
try {
noPeriodResult.get();
fail("Zone name is missing a period. The service returns an error.");
} catch (DnsException ex) {
// expected
assertFalse(ex.isRetryable());
}
} finally {
DNS.delete(ZONE_NAME_ERROR.getName());
DNS.delete(ZONE_DNS_NO_PERIOD.getName());
}
}
use of com.google.cloud.dns.DnsBatch in project google-cloud-java by GoogleCloudPlatform.
the class ITDnsTest method testCreateValidZoneBatch.
@Test
public void testCreateValidZoneBatch() {
try {
DnsBatch batch = DNS.batch();
DnsBatchResult<Zone> completeZoneResult = batch.createZone(ZONE1);
DnsBatchResult<Zone> partialZoneResult = batch.createZone(ZONE_EMPTY_DESCRIPTION);
batch.submit();
Zone created = completeZoneResult.get();
assertEquals(ZONE1.getDescription(), created.getDescription());
assertEquals(ZONE1.getDnsName(), created.getDnsName());
assertEquals(ZONE1.getName(), created.getName());
assertNotNull(created.getCreationTimeMillis());
assertNotNull(created.getNameServers());
assertNull(created.getNameServerSet());
assertNotNull(created.getGeneratedId());
Zone retrieved = DNS.getZone(ZONE1.getName());
assertEquals(created, retrieved);
created = partialZoneResult.get();
assertEquals(ZONE_EMPTY_DESCRIPTION.getDescription(), created.getDescription());
assertEquals(ZONE_EMPTY_DESCRIPTION.getDnsName(), created.getDnsName());
assertEquals(ZONE_EMPTY_DESCRIPTION.getName(), created.getName());
assertNotNull(created.getCreationTimeMillis());
assertNotNull(created.getNameServers());
assertNull(created.getNameServerSet());
assertNotNull(created.getGeneratedId());
retrieved = DNS.getZone(ZONE_EMPTY_DESCRIPTION.getName());
assertEquals(created, retrieved);
} finally {
DNS.delete(ZONE1.getName());
DNS.delete(ZONE_EMPTY_DESCRIPTION.getName());
}
}
Aggregations