use of org.apache.directory.server.dns.messages.ResourceRecord in project vert.x by eclipse.
the class HostnameResolutionTest method testAddressSelection.
private void testAddressSelection(AddressResolverOptions options, int expected) throws Exception {
Function<String, ResourceRecord> createRecord = ipAddress -> new ResourceRecord() {
@Override
public String getDomainName() {
return "vertx.io";
}
@Override
public RecordType getRecordType() {
return RecordType.A;
}
@Override
public RecordClass getRecordClass() {
return RecordClass.IN;
}
@Override
public int getTimeToLive() {
return 100;
}
@Override
public String get(String s) {
return DnsAttribute.IP_ADDRESS.equals(s) ? ipAddress : null;
}
};
Set<ResourceRecord> records = new LinkedHashSet<>();
records.add(createRecord.apply("127.0.0.1"));
records.add(createRecord.apply("127.0.0.2"));
dnsServer.store(question -> records);
AddressResolver resolver = new AddressResolver(vertx, options);
Set<String> resolved = Collections.synchronizedSet(new HashSet<>());
// due to the random nature of netty's round robin algorithm
// the below outcome is generally non-deterministic and will fail once in about 2^100 runs (virtually never)
CountDownLatch latch = new CountDownLatch(100);
for (int i = 0; i < 100; i++) {
resolver.resolveHostname("vertx.io", onSuccess(inetAddress -> {
resolved.add(inetAddress.getHostAddress());
latch.countDown();
}));
}
awaitLatch(latch);
assertEquals(expected, resolved.size());
}
Aggregations