Search in sources :

Example 1 with DnsClientOptions

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

the class DNSTest method testDoNotLogActivity.

@Test
public void testDoNotLogActivity() throws Exception {
    TestLoggerFactory factory = testLogging(new DnsClientOptions().setLogActivity(false));
    assertFalse(factory.hasName("io.netty.handler.logging.LoggingHandler"));
}
Also used : DnsClientOptions(io.vertx.core.dns.DnsClientOptions) TestLoggerFactory(io.vertx.test.netty.TestLoggerFactory) Test(org.junit.Test)

Example 2 with DnsClientOptions

use of io.vertx.core.dns.DnsClientOptions 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 DnsClientOptions

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

the class DNSTest method testUnresolvedDnsServer.

@Test
public void testUnresolvedDnsServer() throws Exception {
    try {
        DnsClient dns = vertx.createDnsClient(new DnsClientOptions().setHost("iamanunresolvablednsserver.com").setPort(53));
        fail();
    } catch (Exception e) {
        assertTrue(e instanceof IllegalArgumentException);
        assertEquals("Cannot resolve the host to a valid ip address", e.getMessage());
    }
}
Also used : DnsClientOptions(io.vertx.core.dns.DnsClientOptions) DnsClient(io.vertx.core.dns.DnsClient) VertxException(io.vertx.core.VertxException) DnsException(io.vertx.core.dns.DnsException) TestUtils.assertNullPointerException(io.vertx.test.core.TestUtils.assertNullPointerException) TestUtils.assertIllegalStateException(io.vertx.test.core.TestUtils.assertIllegalStateException) Test(org.junit.Test)

Example 4 with DnsClientOptions

use of io.vertx.core.dns.DnsClientOptions 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 5 with DnsClientOptions

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

the class DNSTest method testLogActivity.

@Test
public void testLogActivity() throws Exception {
    TestLoggerFactory factory = testLogging(new DnsClientOptions().setLogActivity(true));
    assertTrue(factory.hasName("io.netty.handler.logging.LoggingHandler"));
}
Also used : DnsClientOptions(io.vertx.core.dns.DnsClientOptions) TestLoggerFactory(io.vertx.test.netty.TestLoggerFactory) Test(org.junit.Test)

Aggregations

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