List of usage examples for io.netty.resolver ResolvedAddressTypes IPV4_ONLY
ResolvedAddressTypes IPV4_ONLY
To view the source code for io.netty.resolver ResolvedAddressTypes IPV4_ONLY.
Click Source Link
From source file:com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroup.java
License:Apache License
private static List<DnsQuestion> newQuestions(String hostname, @Nullable ResolvedAddressTypes resolvedAddressTypes) { if (resolvedAddressTypes == null) { if (NetUtil.isIpV4StackPreferred()) { resolvedAddressTypes = ResolvedAddressTypes.IPV4_ONLY; } else {/*from ww w. j av a2 s . com*/ resolvedAddressTypes = ResolvedAddressTypes.IPV4_PREFERRED; } } final ImmutableList.Builder<DnsQuestion> builder = ImmutableList.builder(); switch (resolvedAddressTypes) { case IPV4_ONLY: case IPV4_PREFERRED: case IPV6_PREFERRED: builder.add(new DefaultDnsQuestion(hostname, DnsRecordType.A)); break; } switch (resolvedAddressTypes) { case IPV6_ONLY: case IPV4_PREFERRED: case IPV6_PREFERRED: builder.add(new DefaultDnsQuestion(hostname, DnsRecordType.AAAA)); break; } return builder.build(); }
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")); }//from w w w .j av a 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. jav a2s .c om*/ } }