Search in sources :

Example 11 with ResourceRecord

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());
}
Also used : VertxException(io.vertx.core.VertxException) RecordClass(org.apache.directory.server.dns.messages.RecordClass) java.util(java.util) HttpServer(io.vertx.core.http.HttpServer) CompletableFuture(java.util.concurrent.CompletableFuture) VertxTestBase(io.vertx.test.core.VertxTestBase) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) InetAddress(java.net.InetAddress) TestUtils(io.vertx.test.core.TestUtils) JsonObject(io.vertx.core.json.JsonObject) FakeDNSServer(io.vertx.test.fakedns.FakeDNSServer) NetClient(io.vertx.core.net.NetClient) ResourceRecord(org.apache.directory.server.dns.messages.ResourceRecord) VertxImpl(io.vertx.core.impl.VertxImpl) VertxInternal(io.vertx.core.impl.VertxInternal) ChannelInitializer(io.netty.channel.ChannelInitializer) AddressResolver(io.vertx.core.impl.AddressResolver) DnsAttribute(org.apache.directory.server.dns.store.DnsAttribute) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) InetSocketAddress(java.net.InetSocketAddress) UnknownHostException(java.net.UnknownHostException) File(java.io.File) ChannelFuture(io.netty.channel.ChannelFuture) Channel(io.netty.channel.Channel) TimeUnit(java.util.concurrent.TimeUnit) Bootstrap(io.netty.bootstrap.Bootstrap) CountDownLatch(java.util.concurrent.CountDownLatch) NetServerOptions(io.vertx.core.net.NetServerOptions) Buffer(io.vertx.core.buffer.Buffer) NetServer(io.vertx.core.net.NetServer) HttpMethod(io.vertx.core.http.HttpMethod) RecordType(org.apache.directory.server.dns.messages.RecordType) HttpClient(io.vertx.core.http.HttpClient) AddressResolver(io.vertx.core.impl.AddressResolver) CountDownLatch(java.util.concurrent.CountDownLatch) ResourceRecord(org.apache.directory.server.dns.messages.ResourceRecord)

Aggregations

ResourceRecord (org.apache.directory.server.dns.messages.ResourceRecord)11 QuestionRecord (org.apache.directory.server.dns.messages.QuestionRecord)10 RecordStore (org.apache.directory.server.dns.store.RecordStore)10 HashSet (java.util.HashSet)9 LinkedHashSet (java.util.LinkedHashSet)9 Set (java.util.Set)9 Test (org.junit.jupiter.api.Test)7 InetAddress (java.net.InetAddress)6 DefaultDnsQuestion (io.netty.handler.codec.dns.DefaultDnsQuestion)3 InetSocketAddress (java.net.InetSocketAddress)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Bootstrap (io.netty.bootstrap.Bootstrap)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1