Example usage for io.netty.handler.codec.dns DefaultDnsResponse DefaultDnsResponse

List of usage examples for io.netty.handler.codec.dns DefaultDnsResponse DefaultDnsResponse

Introduction

In this page you can find the example usage for io.netty.handler.codec.dns DefaultDnsResponse DefaultDnsResponse.

Prototype

public DefaultDnsResponse(int id) 

Source Link

Document

Creates a new instance with the DnsOpCode#QUERY opCode and the DnsResponseCode#NOERROR RCODE .

Usage

From source file:com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroupTest.java

License:Apache License

@Test
public void ipV4Only() throws Exception {
    try (TestDnsServer server = new TestDnsServer(ImmutableMap.of(new DefaultDnsQuestion("foo.com.", A),
            new DefaultDnsResponse(0).addRecord(ANSWER, newAddressRecord("foo.com.", "1.1.1.1"))
                    .addRecord(ANSWER, newAddressRecord("unrelated.com", "1.2.3.4"))))) {
        try (DnsAddressEndpointGroup group = new DnsAddressEndpointGroupBuilder("foo.com").port(8080)
                .serverAddresses(server.addr()).resolvedAddressTypes(ResolvedAddressTypes.IPV4_ONLY).build()) {

            assertThat(group.awaitInitialEndpoints())
                    .containsExactly(Endpoint.of("foo.com", 8080).withIpAddr("1.1.1.1"));
        }//  w  w w .  j  a va 2 s . c  o  m
    }
}

From source file:com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroupTest.java

License:Apache License

@Test
public void ipV6Only() throws Exception {
    try (TestDnsServer server = new TestDnsServer(ImmutableMap.of(new DefaultDnsQuestion("bar.com.", AAAA),
            new DefaultDnsResponse(0).addRecord(ANSWER, newAddressRecord("bar.com.", "::1"))
                    .addRecord(ANSWER, newAddressRecord("bar.com.", "::1234:5678:90ab"))
                    .addRecord(ANSWER, newAddressRecord("bar.com.", "2404:6800:4004:806::2013"))))) {
        try (DnsAddressEndpointGroup group = new DnsAddressEndpointGroupBuilder("bar.com").port(8080)
                .serverAddresses(server.addr()).resolvedAddressTypes(ResolvedAddressTypes.IPV6_ONLY).build()) {

            assertThat(group.awaitInitialEndpoints()).containsExactly(
                    Endpoint.of("bar.com", 8080).withIpAddr("2404:6800:4004:806::2013"),
                    Endpoint.of("bar.com", 8080).withIpAddr("::1"),
                    Endpoint.of("bar.com", 8080).withIpAddr("::1234:5678:90ab"));
        }//from  w  ww  .  ja v a 2s  .com
    }
}

From source file:com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroupTest.java

License:Apache License

@Test
public void ipV4AndIpV6() throws Exception {
    try (TestDnsServer server = new TestDnsServer(ImmutableMap.of(new DefaultDnsQuestion("baz.com.", A),
            new DefaultDnsResponse(0).addRecord(ANSWER, newAddressRecord("baz.com.", "1.1.1.1")),
            new DefaultDnsQuestion("baz.com.", AAAA),
            new DefaultDnsResponse(0).addRecord(ANSWER, newAddressRecord("baz.com.", "::1"))))) {
        try (DnsAddressEndpointGroup group = new DnsAddressEndpointGroupBuilder("baz.com").port(8080)
                .serverAddresses(server.addr()).resolvedAddressTypes(ResolvedAddressTypes.IPV4_PREFERRED)
                .build()) {//from  w ww  . j  a v  a  2 s.  com

            assertThat(group.awaitInitialEndpoints()).containsExactly(
                    Endpoint.of("baz.com", 8080).withIpAddr("1.1.1.1"),
                    Endpoint.of("baz.com", 8080).withIpAddr("::1"));
        }
    }
}

From source file:com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroupTest.java

License:Apache License

@Test
public void platformDefault() throws Exception {
    try (TestDnsServer server = new TestDnsServer(ImmutableMap.of(new DefaultDnsQuestion("baz.com.", A),
            new DefaultDnsResponse(0).addRecord(ANSWER, newAddressRecord("baz.com.", "1.1.1.1")),
            new DefaultDnsQuestion("baz.com.", AAAA),
            new DefaultDnsResponse(0).addRecord(ANSWER, newAddressRecord("baz.com.", "::1"))))) {
        try (DnsAddressEndpointGroup group = new DnsAddressEndpointGroupBuilder("baz.com").port(8080)
                .serverAddresses(server.addr()).build()) {

            assertThat(group.awaitInitialEndpoints())
                    .contains(Endpoint.of("baz.com", 8080).withIpAddr("1.1.1.1"));
        }/*from www  .  j  a va 2 s.  co  m*/
    }
}

From source file:com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroupTest.java

License:Apache License

@Test
public void cname() throws Exception {
    try (TestDnsServer server = new TestDnsServer(ImmutableMap.of(new DefaultDnsQuestion("a.com.", A),
            new DefaultDnsResponse(0).addRecord(ANSWER, newBadAddressRecord("a.com.", true))
                    .addRecord(ANSWER, newCnameRecord("a.com.", "b.com."))
                    .addRecord(ANSWER, newAddressRecord("b.com.", "1.1.1.1")),
            new DefaultDnsQuestion("a.com.", AAAA),
            new DefaultDnsResponse(0).addRecord(ANSWER, newBadAddressRecord("a.com.", false))
                    .addRecord(ANSWER, newCnameRecord("a.com.", "b.com."))
                    .addRecord(ANSWER, newAddressRecord("b.com.", "::1"))))) {
        try (DnsAddressEndpointGroup group = new DnsAddressEndpointGroupBuilder("a.com").port(8080)
                .serverAddresses(server.addr()).resolvedAddressTypes(ResolvedAddressTypes.IPV4_PREFERRED)
                .build()) {/*w w  w .ja  v  a  2 s . co  m*/

            assertThat(group.awaitInitialEndpoints()).containsExactly(
                    Endpoint.of("a.com", 8080).withIpAddr("1.1.1.1"),
                    Endpoint.of("a.com", 8080).withIpAddr("::1"));
        }
    }
}

From source file:com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroupTest.java

License:Apache License

@Test
public void mixedLoopbackAddresses() throws Exception {
    try (TestDnsServer server = new TestDnsServer(ImmutableMap.of(new DefaultDnsQuestion("foo.com.", A),
            new DefaultDnsResponse(0).addRecord(ANSWER, newAddressRecord("foo.com.", "127.0.0.1")),
            new DefaultDnsQuestion("foo.com.", AAAA),
            new DefaultDnsResponse(0).addRecord(ANSWER, newAddressRecord("foo.com.", "::1"))))) {
        try (DnsAddressEndpointGroup group = new DnsAddressEndpointGroupBuilder("foo.com").port(8080)
                .serverAddresses(server.addr()).resolvedAddressTypes(ResolvedAddressTypes.IPV4_PREFERRED)
                .build()) {//from www.j a va  2s.c  o  m

            assertThat(group.awaitInitialEndpoints())
                    .containsExactly(Endpoint.of("foo.com", 8080).withIpAddr("127.0.0.1"));
        }
    }
}

From source file:com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroupTest.java

License:Apache License

@Test
public void ipV4MappedOrCompatibleAddresses() throws Exception {
    try (TestDnsServer server = new TestDnsServer(ImmutableMap.of(new DefaultDnsQuestion("bar.com.", AAAA),
            new DefaultDnsResponse(0).addRecord(ANSWER, newCompatibleAddressRecord("bar.com.", "1.1.1.1"))
                    .addRecord(ANSWER, newCompatibleAddressRecord("bar.com.", "1.1.1.2"))
                    .addRecord(ANSWER, newMappedAddressRecord("bar.com.", "1.1.1.1"))
                    .addRecord(ANSWER, newMappedAddressRecord("bar.com.", "1.1.1.3"))))) {
        try (DnsAddressEndpointGroup group = new DnsAddressEndpointGroupBuilder("bar.com").port(8080)
                .serverAddresses(server.addr()).resolvedAddressTypes(ResolvedAddressTypes.IPV6_ONLY).build()) {

            assertThat(group.awaitInitialEndpoints()).containsExactly(
                    Endpoint.of("bar.com", 8080).withIpAddr("1.1.1.1"),
                    Endpoint.of("bar.com", 8080).withIpAddr("1.1.1.2"),
                    Endpoint.of("bar.com", 8080).withIpAddr("1.1.1.3"));
        }//from  ww w.j  a  va  2 s.  c  om
    }
}

From source file:com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroupTest.java

License:Apache License

@Test
public void noPort() throws Exception {
    try (TestDnsServer server = new TestDnsServer(ImmutableMap.of(new DefaultDnsQuestion("no-port.com.", A),
            new DefaultDnsResponse(0).addRecord(ANSWER, newAddressRecord("no-port.com", "1.1.1.1"))))) {
        try (DnsAddressEndpointGroup group = new DnsAddressEndpointGroupBuilder("no-port.com")
                .serverAddresses(server.addr()).resolvedAddressTypes(ResolvedAddressTypes.IPV4_ONLY).build()) {

            assertThat(group.awaitInitialEndpoints())
                    .containsExactly(Endpoint.of("no-port.com").withIpAddr("1.1.1.1"));
        }//from  ww w.  ja  v a  2s.  c  o m
    }
}

From source file:com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroupTest.java

License:Apache License

@Test
public void backoff() throws Exception {
    try (TestDnsServer server = new TestDnsServer(ImmutableMap.of())) { // Respond nothing.
        try (DnsAddressEndpointGroup group = new DnsAddressEndpointGroupBuilder("backoff.com")
                .serverAddresses(server.addr()).resolvedAddressTypes(ResolvedAddressTypes.IPV4_PREFERRED)
                .backoff(Backoff.fixed(500)).build()) {

            await().untilAsserted(() -> assertThat(group.attemptsSoFar).isGreaterThan(2));
            assertThat(group.endpoints()).isEmpty();

            // Start to respond correctly.
            server.setResponses(ImmutableMap.of(new DefaultDnsQuestion("backoff.com.", A),
                    new DefaultDnsResponse(0).addRecord(ANSWER, newAddressRecord("backoff.com", "1.1.1.1")),
                    new DefaultDnsQuestion("backoff.com.", AAAA),
                    new DefaultDnsResponse(0).addRecord(ANSWER, newAddressRecord("backoff.com", "::1"))));
            assertThat(group.awaitInitialEndpoints()).containsExactly(
                    Endpoint.of("backoff.com").withIpAddr("1.1.1.1"),
                    Endpoint.of("backoff.com").withIpAddr("::1"));
        }// w  w  w . j av a 2 s . c  o  m
    }
}

From source file:com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroupTest.java

License:Apache License

@Test
public void backoffOnEmptyResponse() throws Exception {
    try (TestDnsServer server = new TestDnsServer(ImmutableMap.of(
            // Respond with empty records.
            new DefaultDnsQuestion("empty.com.", A), new DefaultDnsResponse(0),
            new DefaultDnsQuestion("empty.com.", AAAA), new DefaultDnsResponse(0)))) {
        try (DnsAddressEndpointGroup group = new DnsAddressEndpointGroupBuilder("empty.com")
                .serverAddresses(server.addr()).resolvedAddressTypes(ResolvedAddressTypes.IPV4_PREFERRED)
                .backoff(Backoff.fixed(500)).build()) {

            await().untilAsserted(() -> assertThat(group.attemptsSoFar).isGreaterThan(2));
            assertThat(group.endpoints()).isEmpty();

            // Start to respond correctly.
            server.setResponses(ImmutableMap.of(new DefaultDnsQuestion("empty.com.", A),
                    new DefaultDnsResponse(0).addRecord(ANSWER, newAddressRecord("empty.com", "1.1.1.1")),
                    new DefaultDnsQuestion("empty.com.", AAAA),
                    new DefaultDnsResponse(0).addRecord(ANSWER, newAddressRecord("empty.com", "::1"))));
            assertThat(group.awaitInitialEndpoints()).containsExactly(
                    Endpoint.of("empty.com").withIpAddr("1.1.1.1"), Endpoint.of("empty.com").withIpAddr("::1"));
        }//w  w  w.j  a  va 2 s.  co  m
    }
}