Search in sources :

Example 1 with RecordType

use of org.apache.directory.server.dns.messages.RecordType 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

Bootstrap (io.netty.bootstrap.Bootstrap)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 VertxException (io.vertx.core.VertxException)1 VertxOptions (io.vertx.core.VertxOptions)1 Buffer (io.vertx.core.buffer.Buffer)1 HttpClient (io.vertx.core.http.HttpClient)1 HttpMethod (io.vertx.core.http.HttpMethod)1 HttpServer (io.vertx.core.http.HttpServer)1 AddressResolver (io.vertx.core.impl.AddressResolver)1 VertxImpl (io.vertx.core.impl.VertxImpl)1 VertxInternal (io.vertx.core.impl.VertxInternal)1 JsonObject (io.vertx.core.json.JsonObject)1 NetClient (io.vertx.core.net.NetClient)1 NetServer (io.vertx.core.net.NetServer)1 NetServerOptions (io.vertx.core.net.NetServerOptions)1 TestUtils (io.vertx.test.core.TestUtils)1 VertxTestBase (io.vertx.test.core.VertxTestBase)1 FakeDNSServer (io.vertx.test.fakedns.FakeDNSServer)1