use of com.google.cloud.dns.DnsBatch in project google-cloud-java by GoogleCloudPlatform.
the class ITDnsTest method testGetZoneBatch.
@Test
public void testGetZoneBatch() {
try {
DNS.create(ZONE1, Dns.ZoneOption.fields(ZoneField.NAME));
DnsBatch batch = DNS.batch();
DnsBatchResult<Zone> timeResult = batch.getZone(ZONE1.getName(), Dns.ZoneOption.fields(ZoneField.CREATION_TIME));
DnsBatchResult<Zone> descriptionResult = batch.getZone(ZONE1.getName(), Dns.ZoneOption.fields(ZoneField.DESCRIPTION));
DnsBatchResult<Zone> dnsNameResult = batch.getZone(ZONE1.getName(), Dns.ZoneOption.fields(ZoneField.DNS_NAME));
DnsBatchResult<Zone> nameResult = batch.getZone(ZONE1.getName(), Dns.ZoneOption.fields(ZoneField.NAME));
DnsBatchResult<Zone> nameServerSetResult = batch.getZone(ZONE1.getName(), Dns.ZoneOption.fields(ZoneField.NAME_SERVER_SET));
DnsBatchResult<Zone> nameServersResult = batch.getZone(ZONE1.getName(), Dns.ZoneOption.fields(ZoneField.NAME_SERVERS));
DnsBatchResult<Zone> idResult = batch.getZone(ZONE1.getName(), Dns.ZoneOption.fields(ZoneField.ZONE_ID));
DnsBatchResult<Zone> combinationResult = batch.getZone(ZONE1.getName(), Dns.ZoneOption.fields(ZoneField.ZONE_ID, ZoneField.NAME_SERVERS, ZoneField.NAME_SERVER_SET, ZoneField.DESCRIPTION));
batch.submit();
Zone created = timeResult.get();
// always returned
assertEquals(ZONE1.getName(), created.getName());
assertNotNull(created.getCreationTimeMillis());
assertNull(created.getDescription());
assertNull(created.getDnsName());
// never returns null
assertTrue(created.getNameServers().isEmpty());
assertNull(created.getNameServerSet());
assertNull(created.getGeneratedId());
created = descriptionResult.get();
// always returned
assertEquals(ZONE1.getName(), created.getName());
assertNull(created.getCreationTimeMillis());
assertEquals(ZONE1.getDescription(), created.getDescription());
assertNull(created.getDnsName());
// never returns null
assertTrue(created.getNameServers().isEmpty());
assertNull(created.getNameServerSet());
assertNull(created.getGeneratedId());
created = dnsNameResult.get();
// always returned
assertEquals(ZONE1.getName(), created.getName());
assertNull(created.getCreationTimeMillis());
assertEquals(ZONE1.getDnsName(), created.getDnsName());
assertNull(created.getDescription());
// never returns null
assertTrue(created.getNameServers().isEmpty());
assertNull(created.getNameServerSet());
assertNull(created.getGeneratedId());
created = nameResult.get();
// always returned
assertEquals(ZONE1.getName(), created.getName());
assertNull(created.getCreationTimeMillis());
assertNull(created.getDnsName());
assertNull(created.getDescription());
// never returns null
assertTrue(created.getNameServers().isEmpty());
assertNull(created.getNameServerSet());
assertNull(created.getGeneratedId());
created = nameServerSetResult.get();
// always returned
assertEquals(ZONE1.getName(), created.getName());
assertNull(created.getCreationTimeMillis());
assertNull(created.getDnsName());
assertNull(created.getDescription());
// never returns null
assertTrue(created.getNameServers().isEmpty());
// we did not set it
assertNull(created.getNameServerSet());
assertNull(created.getGeneratedId());
created = nameServersResult.get();
// always returned
assertEquals(ZONE1.getName(), created.getName());
assertNull(created.getCreationTimeMillis());
assertNull(created.getDnsName());
assertNull(created.getDescription());
assertFalse(created.getNameServers().isEmpty());
assertNull(created.getNameServerSet());
assertNull(created.getGeneratedId());
created = idResult.get();
// always returned
assertEquals(ZONE1.getName(), created.getName());
assertNull(created.getCreationTimeMillis());
assertNull(created.getDnsName());
assertNull(created.getDescription());
assertNotNull(created.getNameServers());
// never returns null
assertTrue(created.getNameServers().isEmpty());
assertNotNull(created.getGeneratedId());
// combination of multiple things
created = combinationResult.get();
// always returned
assertEquals(ZONE1.getName(), created.getName());
assertNull(created.getCreationTimeMillis());
assertNull(created.getDnsName());
assertEquals(ZONE1.getDescription(), created.getDescription());
assertFalse(created.getNameServers().isEmpty());
// we did not set it
assertNull(created.getNameServerSet());
assertNotNull(created.getGeneratedId());
} finally {
DNS.delete(ZONE1.getName());
}
}
use of com.google.cloud.dns.DnsBatch in project google-cloud-java by GoogleCloudPlatform.
the class ITDnsTest method testGetChangeBatch.
@Test
public void testGetChangeBatch() {
try {
Zone zone = DNS.create(ZONE1, Dns.ZoneOption.fields(ZoneField.NAME));
ChangeRequest created = zone.applyChangeRequest(CHANGE_ADD_ZONE1);
waitForChangeToComplete(zone.getName(), created.getGeneratedId());
DnsBatch batch = DNS.batch();
DnsBatchResult<ChangeRequest> completeResult = batch.getChangeRequest(zone.getName(), created.getGeneratedId());
DnsBatchResult<ChangeRequest> idResult = batch.getChangeRequest(zone.getName(), created.getGeneratedId(), Dns.ChangeRequestOption.fields(ChangeRequestField.ID));
DnsBatchResult<ChangeRequest> statusResult = batch.getChangeRequest(zone.getName(), created.getGeneratedId(), Dns.ChangeRequestOption.fields(ChangeRequestField.STATUS));
DnsBatchResult<ChangeRequest> timeResult = batch.getChangeRequest(zone.getName(), created.getGeneratedId(), Dns.ChangeRequestOption.fields(ChangeRequestField.START_TIME));
DnsBatchResult<ChangeRequest> additionsResult = batch.getChangeRequest(zone.getName(), created.getGeneratedId(), Dns.ChangeRequestOption.fields(ChangeRequestField.ADDITIONS));
batch.submit();
assertEqChangesIgnoreStatus(created, completeResult.get());
// with options
ChangeRequest retrieved = idResult.get();
assertEquals(created.getGeneratedId(), retrieved.getGeneratedId());
assertEquals(0, retrieved.getAdditions().size());
assertEquals(0, retrieved.getDeletions().size());
assertNull(retrieved.getStartTimeMillis());
assertNull(retrieved.status());
retrieved = statusResult.get();
assertEquals(created.getGeneratedId(), retrieved.getGeneratedId());
assertEquals(0, retrieved.getAdditions().size());
assertEquals(0, retrieved.getDeletions().size());
assertNull(retrieved.getStartTimeMillis());
assertEquals(ChangeRequestInfo.Status.DONE, retrieved.status());
retrieved = timeResult.get();
assertEquals(created.getGeneratedId(), retrieved.getGeneratedId());
assertEquals(0, retrieved.getAdditions().size());
assertEquals(0, retrieved.getDeletions().size());
assertEquals(created.getStartTimeMillis(), retrieved.getStartTimeMillis());
assertNull(retrieved.status());
retrieved = additionsResult.get();
assertEquals(created.getGeneratedId(), retrieved.getGeneratedId());
assertEquals(2, retrieved.getAdditions().size());
assertTrue(retrieved.getAdditions().contains(A_RECORD_ZONE1));
assertTrue(retrieved.getAdditions().contains(AAAA_RECORD_ZONE1));
assertEquals(0, retrieved.getDeletions().size());
assertNull(retrieved.getStartTimeMillis());
assertNull(retrieved.status());
// finishes with delete otherwise we cannot delete the zone
created = zone.applyChangeRequest(CHANGE_DELETE_ZONE1, Dns.ChangeRequestOption.fields(ChangeRequestField.DELETIONS));
batch = DNS.batch();
DnsBatchResult<ChangeRequest> deletionsResult = batch.getChangeRequest(zone.getName(), created.getGeneratedId(), Dns.ChangeRequestOption.fields(ChangeRequestField.DELETIONS));
batch.submit();
retrieved = deletionsResult.get();
assertEquals(created.getGeneratedId(), retrieved.getGeneratedId());
assertEquals(0, retrieved.getAdditions().size());
assertEquals(2, retrieved.getDeletions().size());
assertTrue(retrieved.getDeletions().contains(AAAA_RECORD_ZONE1));
assertTrue(retrieved.getDeletions().contains(A_RECORD_ZONE1));
assertNull(retrieved.getStartTimeMillis());
assertNull(retrieved.status());
waitForChangeToComplete(zone.getName(), created.getGeneratedId());
} finally {
clear();
}
}
use of com.google.cloud.dns.DnsBatch in project google-cloud-java by GoogleCloudPlatform.
the class ITDnsTest method testCreateChangeBatch.
@Test
public void testCreateChangeBatch() {
try {
DNS.create(ZONE1, Dns.ZoneOption.fields(ZoneField.NAME));
DnsBatch batch = DNS.batch();
DnsBatchResult<ChangeRequest> result = batch.applyChangeRequest(ZONE1.getName(), CHANGE_ADD_ZONE1);
batch.submit();
ChangeRequest created = result.get();
assertEquals(CHANGE_ADD_ZONE1.getAdditions(), created.getAdditions());
assertNotNull(created.getStartTimeMillis());
assertTrue(created.getDeletions().isEmpty());
assertNotNull(created.getGeneratedId());
assertTrue(ImmutableList.of(ChangeRequest.Status.PENDING, ChangeRequest.Status.DONE).contains(created.status()));
assertEqChangesIgnoreStatus(created, DNS.getChangeRequest(ZONE1.getName(), "1"));
waitForChangeToComplete(created);
created = DNS.applyChangeRequest(ZONE1.getName(), CHANGE_DELETE_ZONE1);
waitForChangeToComplete(created);
// with options
batch = DNS.batch();
result = batch.applyChangeRequest(ZONE1.getName(), CHANGE_ADD_ZONE1, Dns.ChangeRequestOption.fields(ChangeRequestField.ID));
batch.submit();
created = result.get();
assertTrue(created.getAdditions().isEmpty());
assertNull(created.getStartTimeMillis());
assertTrue(created.getDeletions().isEmpty());
assertNotNull(created.getGeneratedId());
assertNull(created.status());
waitForChangeToComplete(created);
created = DNS.applyChangeRequest(ZONE1.getName(), CHANGE_DELETE_ZONE1);
waitForChangeToComplete(created);
batch = DNS.batch();
result = batch.applyChangeRequest(ZONE1.getName(), CHANGE_ADD_ZONE1, Dns.ChangeRequestOption.fields(ChangeRequestField.STATUS));
batch.submit();
created = result.get();
assertTrue(created.getAdditions().isEmpty());
assertNull(created.getStartTimeMillis());
assertTrue(created.getDeletions().isEmpty());
assertNotNull(created.getGeneratedId());
assertNotNull(created.status());
waitForChangeToComplete(created);
created = DNS.applyChangeRequest(ZONE1.getName(), CHANGE_DELETE_ZONE1);
waitForChangeToComplete(created);
batch = DNS.batch();
result = batch.applyChangeRequest(ZONE1.getName(), CHANGE_ADD_ZONE1, Dns.ChangeRequestOption.fields(ChangeRequestField.START_TIME));
batch.submit();
created = result.get();
assertTrue(created.getAdditions().isEmpty());
assertNotNull(created.getStartTimeMillis());
assertTrue(created.getDeletions().isEmpty());
assertNotNull(created.getGeneratedId());
assertNull(created.status());
waitForChangeToComplete(created);
created = DNS.applyChangeRequest(ZONE1.getName(), CHANGE_DELETE_ZONE1);
waitForChangeToComplete(created);
batch = DNS.batch();
result = batch.applyChangeRequest(ZONE1.getName(), CHANGE_ADD_ZONE1, Dns.ChangeRequestOption.fields(ChangeRequestField.ADDITIONS));
batch.submit();
created = result.get();
assertEquals(CHANGE_ADD_ZONE1.getAdditions(), created.getAdditions());
assertNull(created.getStartTimeMillis());
assertTrue(created.getDeletions().isEmpty());
assertNotNull(created.getGeneratedId());
assertNull(created.status());
// finishes with delete otherwise we cannot delete the zone
waitForChangeToComplete(created);
batch = DNS.batch();
result = batch.applyChangeRequest(ZONE1.getName(), CHANGE_DELETE_ZONE1, Dns.ChangeRequestOption.fields(ChangeRequestField.DELETIONS));
batch.submit();
created = result.get();
waitForChangeToComplete(created);
assertEquals(CHANGE_DELETE_ZONE1.getDeletions(), created.getDeletions());
assertNull(created.getStartTimeMillis());
assertTrue(created.getAdditions().isEmpty());
assertNotNull(created.getGeneratedId());
assertNull(created.status());
waitForChangeToComplete(created);
} finally {
clear();
}
}
use of com.google.cloud.dns.DnsBatch in project google-cloud-java by GoogleCloudPlatform.
the class ITDnsTest method testListDnsRecordSetsBatch.
@Test
public void testListDnsRecordSetsBatch() {
try {
Zone zone = DNS.create(ZONE1);
DnsBatch batch = DNS.batch();
DnsBatchResult<Page<RecordSet>> result = batch.listRecordSets(zone.getName());
batch.submit();
ImmutableList<RecordSet> recordSets = ImmutableList.copyOf(result.get().iterateAll());
assertEquals(2, recordSets.size());
ImmutableList<RecordSet.Type> defaultRecords = ImmutableList.of(RecordSet.Type.NS, RecordSet.Type.SOA);
for (RecordSet recordSet : recordSets) {
assertTrue(defaultRecords.contains(recordSet.getType()));
}
// field options
batch = DNS.batch();
DnsBatchResult<Page<RecordSet>> ttlResult = batch.listRecordSets(zone.getName(), Dns.RecordSetListOption.fields(RecordSetField.TTL));
DnsBatchResult<Page<RecordSet>> nameResult = batch.listRecordSets(zone.getName(), Dns.RecordSetListOption.fields(RecordSetField.NAME));
DnsBatchResult<Page<RecordSet>> recordsResult = batch.listRecordSets(zone.getName(), Dns.RecordSetListOption.fields(RecordSetField.DNS_RECORDS));
DnsBatchResult<Page<RecordSet>> pageSizeResult = batch.listRecordSets(zone.getName(), Dns.RecordSetListOption.fields(RecordSetField.TYPE), Dns.RecordSetListOption.pageSize(1));
batch.submit();
Iterator<RecordSet> recordSetIterator = ttlResult.get().iterateAll().iterator();
int counter = 0;
while (recordSetIterator.hasNext()) {
RecordSet recordSet = recordSetIterator.next();
assertEquals(recordSets.get(counter).getTtl(), recordSet.getTtl());
assertEquals(recordSets.get(counter).getName(), recordSet.getName());
assertEquals(recordSets.get(counter).getType(), recordSet.getType());
assertTrue(recordSet.getRecords().isEmpty());
counter++;
}
assertEquals(2, counter);
recordSetIterator = nameResult.get().iterateAll().iterator();
counter = 0;
while (recordSetIterator.hasNext()) {
RecordSet recordSet = recordSetIterator.next();
assertEquals(recordSets.get(counter).getName(), recordSet.getName());
assertEquals(recordSets.get(counter).getType(), recordSet.getType());
assertTrue(recordSet.getRecords().isEmpty());
assertNull(recordSet.getTtl());
counter++;
}
assertEquals(2, counter);
recordSetIterator = recordsResult.get().iterateAll().iterator();
counter = 0;
while (recordSetIterator.hasNext()) {
RecordSet recordSet = recordSetIterator.next();
assertEquals(recordSets.get(counter).getRecords(), recordSet.getRecords());
assertEquals(recordSets.get(counter).getName(), recordSet.getName());
assertEquals(recordSets.get(counter).getType(), recordSet.getType());
assertNull(recordSet.getTtl());
counter++;
}
assertEquals(2, counter);
// also test paging
recordSetIterator = pageSizeResult.get().iterateAll().iterator();
counter = 0;
while (recordSetIterator.hasNext()) {
RecordSet recordSet = recordSetIterator.next();
assertEquals(recordSets.get(counter).getType(), recordSet.getType());
assertEquals(recordSets.get(counter).getName(), recordSet.getName());
assertTrue(recordSet.getRecords().isEmpty());
assertNull(recordSet.getTtl());
counter++;
}
assertEquals(2, counter);
// test page size
Page<RecordSet> recordSetPage = pageSizeResult.get();
assertEquals(1, ImmutableList.copyOf(recordSetPage.getValues().iterator()).size());
// test name filter
ChangeRequest change = DNS.applyChangeRequest(ZONE1.getName(), CHANGE_ADD_ZONE1);
waitForChangeToComplete(ZONE1.getName(), change.getGeneratedId());
batch = DNS.batch();
result = batch.listRecordSets(ZONE1.getName(), Dns.RecordSetListOption.dnsName(A_RECORD_ZONE1.getName()));
batch.submit();
recordSetIterator = result.get().iterateAll().iterator();
counter = 0;
while (recordSetIterator.hasNext()) {
RecordSet recordSet = recordSetIterator.next();
assertTrue(ImmutableList.of(A_RECORD_ZONE1.getType(), AAAA_RECORD_ZONE1.getType()).contains(recordSet.getType()));
counter++;
}
assertEquals(2, counter);
// test type filter
batch = DNS.batch();
result = batch.listRecordSets(ZONE1.getName(), Dns.RecordSetListOption.dnsName(A_RECORD_ZONE1.getName()), Dns.RecordSetListOption.type(A_RECORD_ZONE1.getType()));
batch.submit();
recordSetIterator = result.get().iterateAll().iterator();
counter = 0;
while (recordSetIterator.hasNext()) {
RecordSet recordSet = recordSetIterator.next();
assertEquals(A_RECORD_ZONE1, recordSet);
counter++;
}
assertEquals(1, counter);
batch = DNS.batch();
DnsBatchResult<Page<RecordSet>> noNameError = batch.listRecordSets(ZONE1.getName(), Dns.RecordSetListOption.type(A_RECORD_ZONE1.getType()));
DnsBatchResult<Page<RecordSet>> zeroSizeError = batch.listRecordSets(ZONE1.getName(), Dns.RecordSetListOption.pageSize(0));
DnsBatchResult<Page<RecordSet>> negativeSizeError = batch.listRecordSets(ZONE1.getName(), Dns.RecordSetListOption.pageSize(-1));
batch.submit();
// check wrong arguments
try {
// name is not set
noNameError.get();
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.getCode());
assertFalse(ex.isRetryable());
}
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());
}
waitForChangeToComplete(ZONE1.getName(), change.getGeneratedId());
} finally {
clear();
}
}
use of com.google.cloud.dns.DnsBatch in project google-cloud-java by GoogleCloudPlatform.
the class ITDnsTest method testCreateZoneWithOptionsBatch.
@Test
public void testCreateZoneWithOptionsBatch() {
try {
DnsBatch batch = DNS.batch();
DnsBatchResult<Zone> batchResult = batch.createZone(ZONE1, Dns.ZoneOption.fields(ZoneField.CREATION_TIME));
batch.submit();
Zone created = batchResult.get();
// always returned
assertEquals(ZONE1.getName(), created.getName());
assertNotNull(created.getCreationTimeMillis());
assertNull(created.getDescription());
assertNull(created.getDnsName());
// never returns null
assertTrue(created.getNameServers().isEmpty());
assertNull(created.getNameServerSet());
assertNull(created.getGeneratedId());
created.delete();
batch = DNS.batch();
batchResult = batch.createZone(ZONE1, Dns.ZoneOption.fields(ZoneField.DESCRIPTION));
batch.submit();
created = batchResult.get();
// always returned
assertEquals(ZONE1.getName(), created.getName());
assertNull(created.getCreationTimeMillis());
assertEquals(ZONE1.getDescription(), created.getDescription());
assertNull(created.getDnsName());
// never returns null
assertTrue(created.getNameServers().isEmpty());
assertNull(created.getNameServerSet());
assertNull(created.getGeneratedId());
created.delete();
batch = DNS.batch();
batchResult = batch.createZone(ZONE1, Dns.ZoneOption.fields(ZoneField.DNS_NAME));
batch.submit();
created = batchResult.get();
// always returned
assertEquals(ZONE1.getName(), created.getName());
assertNull(created.getCreationTimeMillis());
assertEquals(ZONE1.getDnsName(), created.getDnsName());
assertNull(created.getDescription());
// never returns null
assertTrue(created.getNameServers().isEmpty());
assertNull(created.getNameServerSet());
assertNull(created.getGeneratedId());
created.delete();
batch = DNS.batch();
batchResult = batch.createZone(ZONE1, Dns.ZoneOption.fields(ZoneField.NAME));
batch.submit();
created = batchResult.get();
// always returned
assertEquals(ZONE1.getName(), created.getName());
assertNull(created.getCreationTimeMillis());
assertNull(created.getDnsName());
assertNull(created.getDescription());
// never returns null
assertTrue(created.getNameServers().isEmpty());
assertNull(created.getNameServerSet());
assertNull(created.getGeneratedId());
created.delete();
batch = DNS.batch();
batchResult = batch.createZone(ZONE1, Dns.ZoneOption.fields(ZoneField.NAME_SERVER_SET));
batch.submit();
created = batchResult.get();
// always returned
assertEquals(ZONE1.getName(), created.getName());
assertNull(created.getCreationTimeMillis());
assertNull(created.getDnsName());
assertNull(created.getDescription());
// never returns null
assertTrue(created.getNameServers().isEmpty());
// we did not set it
assertNull(created.getNameServerSet());
assertNull(created.getGeneratedId());
created.delete();
batch = DNS.batch();
batchResult = batch.createZone(ZONE1, Dns.ZoneOption.fields(ZoneField.NAME_SERVERS));
batch.submit();
created = batchResult.get();
// always returned
assertEquals(ZONE1.getName(), created.getName());
assertNull(created.getCreationTimeMillis());
assertNull(created.getDnsName());
assertNull(created.getDescription());
assertFalse(created.getNameServers().isEmpty());
assertNull(created.getNameServerSet());
assertNull(created.getGeneratedId());
created.delete();
batch = DNS.batch();
batchResult = batch.createZone(ZONE1, Dns.ZoneOption.fields(ZoneField.ZONE_ID));
batch.submit();
created = batchResult.get();
// always returned
assertEquals(ZONE1.getName(), created.getName());
assertNull(created.getCreationTimeMillis());
assertNull(created.getDnsName());
assertNull(created.getDescription());
assertNotNull(created.getNameServers());
// never returns null
assertTrue(created.getNameServers().isEmpty());
assertNotNull(created.getGeneratedId());
created.delete();
batch = DNS.batch();
batchResult = batch.createZone(ZONE1, Dns.ZoneOption.fields(ZoneField.ZONE_ID, ZoneField.NAME_SERVERS, ZoneField.NAME_SERVER_SET, ZoneField.DESCRIPTION));
batch.submit();
// combination of multiple things
created = batchResult.get();
// always returned
assertEquals(ZONE1.getName(), created.getName());
assertNull(created.getCreationTimeMillis());
assertNull(created.getDnsName());
assertEquals(ZONE1.getDescription(), created.getDescription());
assertFalse(created.getNameServers().isEmpty());
// we did not set it
assertNull(created.getNameServerSet());
assertNotNull(created.getGeneratedId());
} finally {
DNS.delete(ZONE1.getName());
}
}
Aggregations