Search in sources :

Example 1 with DnsClientImpl

use of io.vertx.core.dns.impl.DnsClientImpl in project vert.x by eclipse.

the class DNSTest method testResolveA.

@Test
public void testResolveA() throws Exception {
    final String ip = "10.0.0.1";
    dnsServer.testResolveA(ip);
    DnsClient dns = prepareDns();
    dns.resolveA("vertx.io", onSuccess(result -> {
        assertFalse(result.isEmpty());
        assertEquals(1, result.size());
        assertEquals(ip, result.get(0));
        ((DnsClientImpl) dns).inProgressQueries(num -> {
            assertEquals(0, (int) num);
            testComplete();
        });
    }));
    await();
}
Also used : VertxException(io.vertx.core.VertxException) DnsException(io.vertx.core.dns.DnsException) DnsMessage(org.apache.directory.server.dns.messages.DnsMessage) DnsClientImpl(io.vertx.core.dns.impl.DnsClientImpl) TestLoggerFactory(io.vertx.test.netty.TestLoggerFactory) Vertx(io.vertx.core.Vertx) DnsClientOptions(io.vertx.core.dns.DnsClientOptions) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) TestUtils.assertNullPointerException(io.vertx.test.core.TestUtils.assertNullPointerException) InetSocketAddress(java.net.InetSocketAddress) Function(java.util.function.Function) VertxTestBase(io.vertx.test.core.VertxTestBase) SrvRecord(io.vertx.core.dns.SrvRecord) DnsClient(io.vertx.core.dns.DnsClient) List(java.util.List) TestUtils(io.vertx.test.core.TestUtils) DeploymentOptions(io.vertx.core.DeploymentOptions) AbstractVerticle(io.vertx.core.AbstractVerticle) DnsResponseCode(io.vertx.core.dns.DnsResponseCode) MxRecord(io.vertx.core.dns.MxRecord) FakeDNSServer(io.vertx.test.fakedns.FakeDNSServer) TestUtils.assertIllegalStateException(io.vertx.test.core.TestUtils.assertIllegalStateException) DnsClient(io.vertx.core.dns.DnsClient) Test(org.junit.Test)

Example 2 with DnsClientImpl

use of io.vertx.core.dns.impl.DnsClientImpl in project vert.x by eclipse.

the class DNSTest method testRecursionNotDesired.

@Test
public void testRecursionNotDesired() throws Exception {
    final String ip = "10.0.0.1";
    dnsServer.testResolveA(ip);
    DnsClient dns = prepareDns(new DnsClientOptions().setRecursionDesired(false));
    dns.resolveA("vertx.io", onSuccess(result -> {
        assertFalse(result.isEmpty());
        assertEquals(1, result.size());
        assertEquals(ip, result.get(0));
        DnsMessage msg = dnsServer.pollMessage();
        assertFalse(msg.isRecursionDesired());
        ((DnsClientImpl) dns).inProgressQueries(num -> {
            assertEquals(0, (int) num);
            testComplete();
        });
    }));
    await();
}
Also used : DnsClientOptions(io.vertx.core.dns.DnsClientOptions) VertxException(io.vertx.core.VertxException) DnsException(io.vertx.core.dns.DnsException) DnsMessage(org.apache.directory.server.dns.messages.DnsMessage) DnsClientImpl(io.vertx.core.dns.impl.DnsClientImpl) TestLoggerFactory(io.vertx.test.netty.TestLoggerFactory) Vertx(io.vertx.core.Vertx) DnsClientOptions(io.vertx.core.dns.DnsClientOptions) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) TestUtils.assertNullPointerException(io.vertx.test.core.TestUtils.assertNullPointerException) InetSocketAddress(java.net.InetSocketAddress) Function(java.util.function.Function) VertxTestBase(io.vertx.test.core.VertxTestBase) SrvRecord(io.vertx.core.dns.SrvRecord) DnsClient(io.vertx.core.dns.DnsClient) List(java.util.List) TestUtils(io.vertx.test.core.TestUtils) DeploymentOptions(io.vertx.core.DeploymentOptions) AbstractVerticle(io.vertx.core.AbstractVerticle) DnsResponseCode(io.vertx.core.dns.DnsResponseCode) MxRecord(io.vertx.core.dns.MxRecord) FakeDNSServer(io.vertx.test.fakedns.FakeDNSServer) TestUtils.assertIllegalStateException(io.vertx.test.core.TestUtils.assertIllegalStateException) DnsClient(io.vertx.core.dns.DnsClient) DnsMessage(org.apache.directory.server.dns.messages.DnsMessage) Test(org.junit.Test)

Example 3 with DnsClientImpl

use of io.vertx.core.dns.impl.DnsClientImpl in project vert.x by eclipse.

the class VertxImpl method createDnsClient.

@Override
public DnsClient createDnsClient(DnsClientOptions options) {
    String host = options.getHost();
    int port = options.getPort();
    if (host == null || port < 0) {
        DnsResolverProvider provider = new DnsResolverProvider(this, addressResolverOptions);
        InetSocketAddress address = provider.nameServerAddresses().get(0);
        // provide the host and port
        options = new DnsClientOptions(options).setHost(address.getAddress().getHostAddress()).setPort(address.getPort());
    }
    return new DnsClientImpl(this, options);
}
Also used : DnsClientOptions(io.vertx.core.dns.DnsClientOptions) DnsClientImpl(io.vertx.core.dns.impl.DnsClientImpl) InetSocketAddress(java.net.InetSocketAddress) DnsResolverProvider(io.vertx.core.impl.resolver.DnsResolverProvider)

Example 4 with DnsClientImpl

use of io.vertx.core.dns.impl.DnsClientImpl in project vert.x by eclipse.

the class DNSTest method testResolveAIpV6.

@Test
public void testResolveAIpV6() throws Exception {
    final String ip = "10.0.0.1";
    dnsServer.testResolveA(ip).ipAddress("::1");
    // force the fake dns server to Ipv6
    DnsClient dns = prepareDns();
    dns.resolveA("vertx.io", onSuccess(result -> {
        assertFalse(result.isEmpty());
        assertEquals(1, result.size());
        assertEquals(ip, result.get(0));
        ((DnsClientImpl) dns).inProgressQueries(num -> {
            assertEquals(0, (int) num);
            testComplete();
        });
    }));
    await();
}
Also used : VertxException(io.vertx.core.VertxException) DnsException(io.vertx.core.dns.DnsException) DnsMessage(org.apache.directory.server.dns.messages.DnsMessage) DnsClientImpl(io.vertx.core.dns.impl.DnsClientImpl) TestLoggerFactory(io.vertx.test.netty.TestLoggerFactory) Vertx(io.vertx.core.Vertx) DnsClientOptions(io.vertx.core.dns.DnsClientOptions) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) TestUtils.assertNullPointerException(io.vertx.test.core.TestUtils.assertNullPointerException) InetSocketAddress(java.net.InetSocketAddress) Function(java.util.function.Function) VertxTestBase(io.vertx.test.core.VertxTestBase) SrvRecord(io.vertx.core.dns.SrvRecord) DnsClient(io.vertx.core.dns.DnsClient) List(java.util.List) TestUtils(io.vertx.test.core.TestUtils) DeploymentOptions(io.vertx.core.DeploymentOptions) AbstractVerticle(io.vertx.core.AbstractVerticle) DnsResponseCode(io.vertx.core.dns.DnsResponseCode) MxRecord(io.vertx.core.dns.MxRecord) FakeDNSServer(io.vertx.test.fakedns.FakeDNSServer) TestUtils.assertIllegalStateException(io.vertx.test.core.TestUtils.assertIllegalStateException) DnsClient(io.vertx.core.dns.DnsClient) Test(org.junit.Test)

Example 5 with DnsClientImpl

use of io.vertx.core.dns.impl.DnsClientImpl in project vert.x by eclipse.

the class DNSTest method testTimeout.

@Test
public void testTimeout() throws Exception {
    DnsClient dns = vertx.createDnsClient(new DnsClientOptions().setHost("localhost").setPort(10000).setQueryTimeout(5000));
    dns.lookup("vertx.io", onFailure(result -> {
        assertEquals(VertxException.class, result.getClass());
        assertEquals("DNS query timeout for vertx.io.", result.getMessage());
        ((DnsClientImpl) dns).inProgressQueries(num -> {
            assertEquals(0, (int) num);
            testComplete();
        });
    }));
    await();
}
Also used : DnsClientOptions(io.vertx.core.dns.DnsClientOptions) VertxException(io.vertx.core.VertxException) DnsException(io.vertx.core.dns.DnsException) DnsMessage(org.apache.directory.server.dns.messages.DnsMessage) DnsClientImpl(io.vertx.core.dns.impl.DnsClientImpl) TestLoggerFactory(io.vertx.test.netty.TestLoggerFactory) Vertx(io.vertx.core.Vertx) DnsClientOptions(io.vertx.core.dns.DnsClientOptions) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) TestUtils.assertNullPointerException(io.vertx.test.core.TestUtils.assertNullPointerException) InetSocketAddress(java.net.InetSocketAddress) Function(java.util.function.Function) VertxTestBase(io.vertx.test.core.VertxTestBase) SrvRecord(io.vertx.core.dns.SrvRecord) DnsClient(io.vertx.core.dns.DnsClient) List(java.util.List) TestUtils(io.vertx.test.core.TestUtils) DeploymentOptions(io.vertx.core.DeploymentOptions) AbstractVerticle(io.vertx.core.AbstractVerticle) DnsResponseCode(io.vertx.core.dns.DnsResponseCode) MxRecord(io.vertx.core.dns.MxRecord) FakeDNSServer(io.vertx.test.fakedns.FakeDNSServer) TestUtils.assertIllegalStateException(io.vertx.test.core.TestUtils.assertIllegalStateException) VertxException(io.vertx.core.VertxException) DnsClient(io.vertx.core.dns.DnsClient) Test(org.junit.Test)

Aggregations

DnsClientOptions (io.vertx.core.dns.DnsClientOptions)6 DnsClientImpl (io.vertx.core.dns.impl.DnsClientImpl)6 InetSocketAddress (java.net.InetSocketAddress)6 AbstractVerticle (io.vertx.core.AbstractVerticle)5 DeploymentOptions (io.vertx.core.DeploymentOptions)5 Vertx (io.vertx.core.Vertx)5 VertxException (io.vertx.core.VertxException)5 VertxOptions (io.vertx.core.VertxOptions)5 DnsClient (io.vertx.core.dns.DnsClient)5 DnsException (io.vertx.core.dns.DnsException)5 DnsResponseCode (io.vertx.core.dns.DnsResponseCode)5 MxRecord (io.vertx.core.dns.MxRecord)5 SrvRecord (io.vertx.core.dns.SrvRecord)5 TestUtils (io.vertx.test.core.TestUtils)5 TestUtils.assertIllegalStateException (io.vertx.test.core.TestUtils.assertIllegalStateException)5 TestUtils.assertNullPointerException (io.vertx.test.core.TestUtils.assertNullPointerException)5 VertxTestBase (io.vertx.test.core.VertxTestBase)5 FakeDNSServer (io.vertx.test.fakedns.FakeDNSServer)5 TestLoggerFactory (io.vertx.test.netty.TestLoggerFactory)5 List (java.util.List)5