use of org.xbill.DNS.ARecord in project nhin-d by DirectProject.
the class DNSRecordCommands_removeRecords_Test method testRemoveAllExceptARecords_AssertAllExceptARecordRemoved.
public void testRemoveAllExceptARecords_AssertAllExceptARecordRemoved() throws Exception {
new TestPlan() {
private List<Record> recordsToAdd;
private List<Record> expectedRemainingRecords;
@Override
protected List<Record> getRecordsToAdd() throws Exception {
recordsToAdd = new ArrayList<Record>();
recordsToAdd.add(new ARecord(Name.fromString("example.domain.com."), DClass.IN, 3600, InetAddress.getByName("127.0.0.1")));
recordsToAdd.add(new ARecord(Name.fromString("example.domain.com."), DClass.IN, 3600, InetAddress.getByName("127.0.0.2")));
recordsToAdd.add(new MXRecord(Name.fromString("example.domain.com."), DClass.IN, 3600, 1, Name.fromString("mail1.example.domain.com.")));
recordsToAdd.add(new MXRecord(Name.fromString("example2.domain.com."), DClass.IN, 3600, 1, Name.fromString("mail2.exampl2.domain.com.")));
recordsToAdd.add(new SOARecord(Name.fromString("example.domain.com."), DClass.IN, 3600, Name.fromString("ns1.example.domain.com."), Name.fromString("gm2552.example.domain.com."), 1, 3600, 60, 60, 3600));
return recordsToAdd;
}
@Override
protected List<DnsRecord> getRecordsToRemove(List<DnsRecord> addedRecords) throws Exception {
List<DnsRecord> retVal = new ArrayList<DnsRecord>();
expectedRemainingRecords = new ArrayList<Record>();
for (DnsRecord addedRecord : addedRecords) {
if (addedRecord.getType() != Type.A)
retVal.add(addedRecord);
else
expectedRemainingRecords.add(toRecord(addedRecord));
}
return retVal;
}
@Override
protected void doAssertions(List<Record> remainingRecords) throws Exception {
assertNotNull(remainingRecords);
assertEquals(2, remainingRecords.size());
for (Record expectedRemaining : expectedRemainingRecords) {
int index = remainingRecords.indexOf(expectedRemaining);
assertTrue(index >= 0);
Record checkRecord = remainingRecords.get(index);
assertTrue(checkRecord.getType() == Type.A);
assertEquals(checkRecord, expectedRemaining);
}
}
}.perform();
}
use of org.xbill.DNS.ARecord in project jmeter by apache.
the class DNSCacheManager method requestLookup.
/**
* Sends DNS request via system or custom DNS resolver
* @param host Host
* @return array of {@link InetAddress} or null if lookup did not return result
*/
private InetAddress[] requestLookup(String host) throws UnknownHostException {
InetAddress[] addresses = null;
if (isCustomResolver()) {
ExtendedResolver extendedResolver = getResolver();
if (extendedResolver != null) {
if (extendedResolver.getResolvers().length > 0) {
try {
Lookup lookup = new Lookup(host, Type.A);
lookup.setCache(lookupCache);
if (timeoutMs > 0) {
resolver.setTimeout(timeoutMs / 1000, timeoutMs % 1000);
}
lookup.setResolver(resolver);
Record[] records = lookup.run();
if (records == null || records.length == 0) {
throw new UnknownHostException("Failed to resolve host name: " + host);
}
addresses = new InetAddress[records.length];
for (int i = 0; i < records.length; i++) {
addresses[i] = ((ARecord) records[i]).getAddress();
}
} catch (TextParseException tpe) {
log.debug("Failed to create Lookup object: " + tpe);
}
return addresses;
}
} else {
throw new UnknownHostException("Could not resolve host:" + host + ", failed to initialize resolver" + " or no resolver found");
}
}
addresses = systemDefaultDnsResolver.resolve(host);
if (log.isDebugEnabled()) {
log.debug("Cache miss: {} Thread #{}, resolved with system resolver into {}", host, JMeterContextService.getContext().getThreadNum(), Arrays.toString(addresses));
}
return addresses;
}
Aggregations