Migrate resolver-dns tests to JUnit 5 (#11326)
Motivation: JUnit 5 is more expressive, extensible, and composable in many ways, and it's better able to run tests in parallel. Modifications: Use JUnit5 in tests Result: Related to https://github.com/netty/netty/issues/10757
This commit is contained in:
parent
fd111e22d9
commit
cd4249218c
@ -21,7 +21,7 @@ import io.netty.channel.EventLoopGroup;
|
|||||||
import io.netty.channel.local.LocalHandler;
|
import io.netty.channel.local.LocalHandler;
|
||||||
import io.netty.channel.nio.NioHandler;
|
import io.netty.channel.nio.NioHandler;
|
||||||
import io.netty.util.NetUtil;
|
import io.netty.util.NetUtil;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
@ -29,7 +29,8 @@ import java.util.Comparator;
|
|||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class DefaultAuthoritativeDnsServerCacheTest {
|
public class DefaultAuthoritativeDnsServerCacheTest {
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ import io.netty.channel.EventLoopGroup;
|
|||||||
import io.netty.channel.local.LocalHandler;
|
import io.netty.channel.local.LocalHandler;
|
||||||
import io.netty.channel.nio.NioHandler;
|
import io.netty.channel.nio.NioHandler;
|
||||||
import io.netty.util.NetUtil;
|
import io.netty.util.NetUtil;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -30,10 +30,10 @@ import java.util.concurrent.Callable;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
|
|
||||||
public class DefaultDnsCacheTest {
|
public class DefaultDnsCacheTest {
|
||||||
|
|
||||||
|
@ -20,12 +20,14 @@ import io.netty.channel.EventLoop;
|
|||||||
import io.netty.channel.EventLoopGroup;
|
import io.netty.channel.EventLoopGroup;
|
||||||
import io.netty.channel.local.LocalHandler;
|
import io.netty.channel.local.LocalHandler;
|
||||||
import io.netty.channel.nio.NioHandler;
|
import io.netty.channel.nio.NioHandler;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class DefaultDnsCnameCacheTest {
|
public class DefaultDnsCnameCacheTest {
|
||||||
|
|
||||||
|
@ -24,14 +24,14 @@ import io.netty.resolver.AddressResolver;
|
|||||||
import io.netty.util.concurrent.Future;
|
import io.netty.util.concurrent.Future;
|
||||||
import io.netty.util.concurrent.FutureListener;
|
import io.netty.util.concurrent.FutureListener;
|
||||||
import io.netty.util.concurrent.Promise;
|
import io.netty.util.concurrent.Promise;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.nio.channels.UnsupportedAddressTypeException;
|
import java.nio.channels.UnsupportedAddressTypeException;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class DnsAddressResolverGroupTest {
|
public class DnsAddressResolverGroupTest {
|
||||||
@Test
|
@Test
|
||||||
|
@ -22,8 +22,8 @@ import io.netty.channel.socket.nio.NioDatagramChannel;
|
|||||||
import io.netty.handler.codec.dns.DefaultDnsOptEcsRecord;
|
import io.netty.handler.codec.dns.DefaultDnsOptEcsRecord;
|
||||||
import io.netty.util.internal.SocketUtils;
|
import io.netty.util.internal.SocketUtils;
|
||||||
import io.netty.util.concurrent.Future;
|
import io.netty.util.concurrent.Future;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -34,7 +34,7 @@ public class DnsNameResolverClientSubnetTest {
|
|||||||
|
|
||||||
// See https://www.gsic.uva.es/~jnisigl/dig-edns-client-subnet.html
|
// See https://www.gsic.uva.es/~jnisigl/dig-edns-client-subnet.html
|
||||||
// Ignore as this needs to query real DNS servers.
|
// Ignore as this needs to query real DNS servers.
|
||||||
@Ignore
|
@Disabled
|
||||||
@Test
|
@Test
|
||||||
public void testSubnetQuery() throws Exception {
|
public void testSubnetQuery() throws Exception {
|
||||||
EventLoopGroup group = new MultithreadEventLoopGroup(1, NioHandler.newFactory());
|
EventLoopGroup group = new MultithreadEventLoopGroup(1, NioHandler.newFactory());
|
||||||
|
@ -66,11 +66,9 @@ import org.apache.directory.server.dns.store.DnsAttribute;
|
|||||||
import org.apache.directory.server.dns.store.RecordStore;
|
import org.apache.directory.server.dns.store.RecordStore;
|
||||||
import org.apache.mina.core.buffer.IoBuffer;
|
import org.apache.mina.core.buffer.IoBuffer;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.AfterClass;
|
import org.junit.jupiter.api.AfterAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -108,6 +106,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import org.junit.jupiter.api.Timeout;
|
||||||
|
|
||||||
import static io.netty.handler.codec.dns.DnsRecordType.A;
|
import static io.netty.handler.codec.dns.DnsRecordType.A;
|
||||||
import static io.netty.handler.codec.dns.DnsRecordType.AAAA;
|
import static io.netty.handler.codec.dns.DnsRecordType.AAAA;
|
||||||
@ -123,14 +122,15 @@ import static org.hamcrest.Matchers.greaterThan;
|
|||||||
import static org.hamcrest.Matchers.hasSize;
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class DnsNameResolverTest {
|
public class DnsNameResolverTest {
|
||||||
|
|
||||||
@ -347,9 +347,6 @@ public class DnsNameResolverTest {
|
|||||||
private static final TestDnsServer dnsServer = new TestDnsServer(DOMAINS_ALL);
|
private static final TestDnsServer dnsServer = new TestDnsServer(DOMAINS_ALL);
|
||||||
private static final EventLoopGroup group = new MultithreadEventLoopGroup(1, NioHandler.newFactory());
|
private static final EventLoopGroup group = new MultithreadEventLoopGroup(1, NioHandler.newFactory());
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException expectedException = ExpectedException.none();
|
|
||||||
|
|
||||||
private static DnsNameResolverBuilder newResolver(boolean decodeToUnicode) {
|
private static DnsNameResolverBuilder newResolver(boolean decodeToUnicode) {
|
||||||
return newResolver(decodeToUnicode, null);
|
return newResolver(decodeToUnicode, null);
|
||||||
}
|
}
|
||||||
@ -389,12 +386,12 @@ public class DnsNameResolverTest {
|
|||||||
.resolvedAddressTypes(resolvedAddressTypes);
|
.resolvedAddressTypes(resolvedAddressTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void init() throws Exception {
|
public static void init() throws Exception {
|
||||||
dnsServer.start();
|
dnsServer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterAll
|
||||||
public static void destroy() {
|
public static void destroy() {
|
||||||
dnsServer.stop();
|
dnsServer.stop();
|
||||||
group.shutdownGracefully();
|
group.shutdownGracefully();
|
||||||
@ -462,11 +459,11 @@ public class DnsNameResolverTest {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (overriddenHostnames.contains(resolvedEntry.getKey())) {
|
if (overriddenHostnames.contains(resolvedEntry.getKey())) {
|
||||||
assertEquals("failed to resolve " + resolvedEntry.getKey(),
|
assertEquals(overriddenIP, resolvedEntry.getValue().getHostAddress(),
|
||||||
overriddenIP, resolvedEntry.getValue().getHostAddress());
|
"failed to resolve " + resolvedEntry.getKey());
|
||||||
} else {
|
} else {
|
||||||
assertNotEquals("failed to resolve " + resolvedEntry.getKey(),
|
assertNotEquals(overriddenIP, resolvedEntry.getValue().getHostAddress(),
|
||||||
overriddenIP, resolvedEntry.getValue().getHostAddress());
|
"failed to resolve " + resolvedEntry.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@ -525,12 +522,14 @@ public class DnsNameResolverTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = DEFAULT_TEST_TIMEOUT_MS)
|
@Test
|
||||||
|
@Timeout(value = DEFAULT_TEST_TIMEOUT_MS, unit = TimeUnit.MILLISECONDS)
|
||||||
public void testNonCachedResolveEmptyHostName() throws Exception {
|
public void testNonCachedResolveEmptyHostName() throws Exception {
|
||||||
testNonCachedResolveEmptyHostName("");
|
testNonCachedResolveEmptyHostName("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = DEFAULT_TEST_TIMEOUT_MS)
|
@Test
|
||||||
|
@Timeout(value = DEFAULT_TEST_TIMEOUT_MS, unit = TimeUnit.MILLISECONDS)
|
||||||
public void testNonCachedResolveNullHostName() throws Exception {
|
public void testNonCachedResolveNullHostName() throws Exception {
|
||||||
testNonCachedResolveEmptyHostName(null);
|
testNonCachedResolveEmptyHostName(null);
|
||||||
}
|
}
|
||||||
@ -545,12 +544,14 @@ public class DnsNameResolverTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = DEFAULT_TEST_TIMEOUT_MS)
|
@Test
|
||||||
|
@Timeout(value = DEFAULT_TEST_TIMEOUT_MS, unit = TimeUnit.MILLISECONDS)
|
||||||
public void testNonCachedResolveAllEmptyHostName() throws Exception {
|
public void testNonCachedResolveAllEmptyHostName() throws Exception {
|
||||||
testNonCachedResolveAllEmptyHostName("");
|
testNonCachedResolveAllEmptyHostName("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = DEFAULT_TEST_TIMEOUT_MS)
|
@Test
|
||||||
|
@Timeout(value = DEFAULT_TEST_TIMEOUT_MS, unit = TimeUnit.MILLISECONDS)
|
||||||
public void testNonCachedResolveAllNullHostName() throws Exception {
|
public void testNonCachedResolveAllNullHostName() throws Exception {
|
||||||
testNonCachedResolveAllEmptyHostName(null);
|
testNonCachedResolveAllEmptyHostName(null);
|
||||||
}
|
}
|
||||||
@ -721,8 +722,8 @@ public class DnsNameResolverTest {
|
|||||||
if (observer != null) {
|
if (observer != null) {
|
||||||
Object o = observer.events.poll();
|
Object o = observer.events.poll();
|
||||||
if (o instanceof QueryCancelledEvent) {
|
if (o instanceof QueryCancelledEvent) {
|
||||||
assertTrue("unexpected type: " + observer.question,
|
assertTrue(observer.question.type() == CNAME || observer.question.type() == AAAA,
|
||||||
observer.question.type() == CNAME || observer.question.type() == AAAA);
|
"unexpected type: " + observer.question);
|
||||||
} else if (o instanceof QueryWrittenEvent) {
|
} else if (o instanceof QueryWrittenEvent) {
|
||||||
QueryFailedEvent failedEvent = (QueryFailedEvent) observer.events.poll();
|
QueryFailedEvent failedEvent = (QueryFailedEvent) observer.events.poll();
|
||||||
} else if (!(o instanceof QueryFailedEvent)) {
|
} else if (!(o instanceof QueryFailedEvent)) {
|
||||||
@ -1141,12 +1142,14 @@ public class DnsNameResolverTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = DEFAULT_TEST_TIMEOUT_MS)
|
@Test
|
||||||
|
@Timeout(value = DEFAULT_TEST_TIMEOUT_MS, unit = TimeUnit.MILLISECONDS)
|
||||||
public void secondDnsServerShouldBeUsedBeforeCNAMEFirstServerNotStarted() throws IOException {
|
public void secondDnsServerShouldBeUsedBeforeCNAMEFirstServerNotStarted() throws IOException {
|
||||||
secondDnsServerShouldBeUsedBeforeCNAME(false);
|
secondDnsServerShouldBeUsedBeforeCNAME(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = DEFAULT_TEST_TIMEOUT_MS)
|
@Test
|
||||||
|
@Timeout(value = DEFAULT_TEST_TIMEOUT_MS, unit = TimeUnit.MILLISECONDS)
|
||||||
public void secondDnsServerShouldBeUsedBeforeCNAMEFirstServerFailResolve() throws IOException {
|
public void secondDnsServerShouldBeUsedBeforeCNAMEFirstServerFailResolve() throws IOException {
|
||||||
secondDnsServerShouldBeUsedBeforeCNAME(true);
|
secondDnsServerShouldBeUsedBeforeCNAME(true);
|
||||||
}
|
}
|
||||||
@ -1205,7 +1208,8 @@ public class DnsNameResolverTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = DEFAULT_TEST_TIMEOUT_MS)
|
@Test
|
||||||
|
@Timeout(value = DEFAULT_TEST_TIMEOUT_MS, unit = TimeUnit.MILLISECONDS)
|
||||||
public void aAndAAAAQueryShouldTryFirstDnsServerBeforeSecond() throws IOException {
|
public void aAndAAAAQueryShouldTryFirstDnsServerBeforeSecond() throws IOException {
|
||||||
final String knownHostName = "netty.io";
|
final String knownHostName = "netty.io";
|
||||||
final TestDnsServer dnsServer1 = new TestDnsServer(Collections.singleton("notnetty.com"));
|
final TestDnsServer dnsServer1 = new TestDnsServer(Collections.singleton("notnetty.com"));
|
||||||
@ -2146,7 +2150,8 @@ public class DnsNameResolverTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 3000)
|
@Test
|
||||||
|
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
|
||||||
public void testTimeoutNotCached() {
|
public void testTimeoutNotCached() {
|
||||||
DnsCache cache = new DnsCache() {
|
DnsCache cache = new DnsCache() {
|
||||||
@Override
|
@Override
|
||||||
@ -2256,7 +2261,6 @@ public class DnsNameResolverTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFollowCNAMELoop() throws Throwable {
|
public void testFollowCNAMELoop() throws Throwable {
|
||||||
expectedException.expect(UnknownHostException.class);
|
|
||||||
TestDnsServer dnsServer2 = new TestDnsServer(question -> {
|
TestDnsServer dnsServer2 = new TestDnsServer(question -> {
|
||||||
Set<ResourceRecord> records = new LinkedHashSet<>(4);
|
Set<ResourceRecord> records = new LinkedHashSet<>(4);
|
||||||
|
|
||||||
@ -2278,7 +2282,7 @@ public class DnsNameResolverTest {
|
|||||||
return records;
|
return records;
|
||||||
});
|
});
|
||||||
dnsServer2.start();
|
dnsServer2.start();
|
||||||
DnsNameResolver resolver = null;
|
DnsNameResolver[] resolver = new DnsNameResolver[1];
|
||||||
try {
|
try {
|
||||||
DnsNameResolverBuilder builder = newResolver()
|
DnsNameResolverBuilder builder = newResolver()
|
||||||
.recursionDesired(false)
|
.recursionDesired(false)
|
||||||
@ -2286,22 +2290,23 @@ public class DnsNameResolverTest {
|
|||||||
.maxQueriesPerResolve(16)
|
.maxQueriesPerResolve(16)
|
||||||
.nameServerProvider(new SingletonDnsServerAddressStreamProvider(dnsServer2.localAddress()));
|
.nameServerProvider(new SingletonDnsServerAddressStreamProvider(dnsServer2.localAddress()));
|
||||||
|
|
||||||
resolver = builder.build();
|
resolver[0] = builder.build();
|
||||||
resolver.resolveAll("somehost.netty.io").syncUninterruptibly().getNow();
|
final CompletionException completion = assertThrows(CompletionException.class,
|
||||||
|
() -> resolver[0].resolveAll("somehost.netty.io").syncUninterruptibly().getNow());
|
||||||
|
assertTrue(completion.getCause() instanceof UnknownHostException);
|
||||||
} catch (CompletionException e) {
|
} catch (CompletionException e) {
|
||||||
throw e.getCause();
|
throw e.getCause();
|
||||||
} finally {
|
} finally {
|
||||||
dnsServer2.stop();
|
dnsServer2.stop();
|
||||||
if (resolver != null) {
|
if (resolver[0] != null) {
|
||||||
resolver.close();
|
resolver[0].close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCNAMELoopInCache() throws Throwable {
|
public void testCNAMELoopInCache() throws Throwable {
|
||||||
expectedException.expect(UnknownHostException.class);
|
DnsNameResolver[] resolver = new DnsNameResolver[1];
|
||||||
DnsNameResolver resolver = null;
|
|
||||||
try {
|
try {
|
||||||
DnsNameResolverBuilder builder = newResolver()
|
DnsNameResolverBuilder builder = newResolver()
|
||||||
.recursionDesired(false)
|
.recursionDesired(false)
|
||||||
@ -2309,33 +2314,33 @@ public class DnsNameResolverTest {
|
|||||||
.maxQueriesPerResolve(16)
|
.maxQueriesPerResolve(16)
|
||||||
.nameServerProvider(new SingletonDnsServerAddressStreamProvider(dnsServer.localAddress()));
|
.nameServerProvider(new SingletonDnsServerAddressStreamProvider(dnsServer.localAddress()));
|
||||||
|
|
||||||
resolver = builder.build();
|
resolver[0] = builder.build();
|
||||||
// Add a CNAME loop into the cache
|
// Add a CNAME loop into the cache
|
||||||
String name = "somehost.netty.io.";
|
String name = "somehost.netty.io.";
|
||||||
String name2 = "cname.netty.io.";
|
String name2 = "cname.netty.io.";
|
||||||
|
|
||||||
resolver.cnameCache().cache(name, name2, Long.MAX_VALUE, resolver.executor());
|
resolver[0].cnameCache().cache(name, name2, Long.MAX_VALUE, resolver[0].executor());
|
||||||
resolver.cnameCache().cache(name2, name, Long.MAX_VALUE, resolver.executor());
|
resolver[0].cnameCache().cache(name2, name, Long.MAX_VALUE, resolver[0].executor());
|
||||||
resolver.resolve(name).syncUninterruptibly().getNow();
|
final CompletionException completion = assertThrows(CompletionException.class,
|
||||||
} catch (CompletionException e) {
|
() -> resolver[0].resolve(name).syncUninterruptibly().getNow());
|
||||||
throw e.getCause();
|
assertTrue(completion.getCause() instanceof UnknownHostException);
|
||||||
} finally {
|
} finally {
|
||||||
if (resolver != null) {
|
if (resolver[0] != null) {
|
||||||
resolver.close();
|
resolver[0].close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSearchDomainQueryFailureForSingleAddressTypeCompletes() throws Throwable {
|
public void testSearchDomainQueryFailureForSingleAddressTypeCompletes() throws Throwable {
|
||||||
expectedException.expect(UnknownHostException.class);
|
assertThrows(UnknownHostException.class,
|
||||||
testSearchDomainQueryFailureCompletes(ResolvedAddressTypes.IPV4_ONLY);
|
() -> testSearchDomainQueryFailureCompletes(ResolvedAddressTypes.IPV4_ONLY));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSearchDomainQueryFailureForMultipleAddressTypeCompletes() throws Throwable {
|
public void testSearchDomainQueryFailureForMultipleAddressTypeCompletes() throws Throwable {
|
||||||
expectedException.expect(UnknownHostException.class);
|
assertThrows(UnknownHostException.class,
|
||||||
testSearchDomainQueryFailureCompletes(ResolvedAddressTypes.IPV4_PREFERRED);
|
() -> testSearchDomainQueryFailureCompletes(ResolvedAddressTypes.IPV4_PREFERRED));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testSearchDomainQueryFailureCompletes(ResolvedAddressTypes types) throws Throwable {
|
private void testSearchDomainQueryFailureCompletes(ResolvedAddressTypes types) throws Throwable {
|
||||||
@ -2352,7 +2357,8 @@ public class DnsNameResolverTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 2000L)
|
@Test
|
||||||
|
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
|
||||||
public void testCachesClearedOnClose() throws Exception {
|
public void testCachesClearedOnClose() throws Exception {
|
||||||
final CountDownLatch resolveLatch = new CountDownLatch(1);
|
final CountDownLatch resolveLatch = new CountDownLatch(1);
|
||||||
final CountDownLatch authoritativeLatch = new CountDownLatch(1);
|
final CountDownLatch authoritativeLatch = new CountDownLatch(1);
|
||||||
@ -2524,13 +2530,13 @@ public class DnsNameResolverTest {
|
|||||||
.cnameCache(new DnsCnameCache() {
|
.cnameCache(new DnsCnameCache() {
|
||||||
@Override
|
@Override
|
||||||
public String get(String hostname) {
|
public String get(String hostname) {
|
||||||
assertTrue(hostname, hostname.endsWith("."));
|
assertTrue(hostname.endsWith("."), hostname);
|
||||||
return cache.get(hostname);
|
return cache.get(hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cache(String hostname, String cname, long originalTtl, EventLoop loop) {
|
public void cache(String hostname, String cname, long originalTtl, EventLoop loop) {
|
||||||
assertTrue(hostname, hostname.endsWith("."));
|
assertTrue(hostname.endsWith("."), hostname);
|
||||||
cache.put(hostname, cname);
|
cache.put(hostname, cname);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2787,7 +2793,8 @@ public class DnsNameResolverTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 2000)
|
@Test
|
||||||
|
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
|
||||||
public void testDropAAAAResolveFast() throws IOException {
|
public void testDropAAAAResolveFast() throws IOException {
|
||||||
String host = "somehost.netty.io";
|
String host = "somehost.netty.io";
|
||||||
TestDnsServer dnsServer2 = new TestDnsServer(Collections.singleton(host));
|
TestDnsServer dnsServer2 = new TestDnsServer(Collections.singleton(host));
|
||||||
@ -2812,7 +2819,8 @@ public class DnsNameResolverTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 2000)
|
@Test
|
||||||
|
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
|
||||||
public void testDropAAAAResolveAllFast() throws IOException {
|
public void testDropAAAAResolveAllFast() throws IOException {
|
||||||
final String host = "somehost.netty.io";
|
final String host = "somehost.netty.io";
|
||||||
TestDnsServer dnsServer2 = new TestDnsServer(question -> {
|
TestDnsServer dnsServer2 = new TestDnsServer(question -> {
|
||||||
@ -2855,17 +2863,20 @@ public class DnsNameResolverTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 5000)
|
@Test
|
||||||
|
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
|
||||||
public void testTruncatedWithoutTcpFallback() throws IOException {
|
public void testTruncatedWithoutTcpFallback() throws IOException {
|
||||||
testTruncated0(false, false);
|
testTruncated0(false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 5000)
|
@Test
|
||||||
|
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
|
||||||
public void testTruncatedWithTcpFallback() throws IOException {
|
public void testTruncatedWithTcpFallback() throws IOException {
|
||||||
testTruncated0(true, false);
|
testTruncated0(true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 5000)
|
@Test
|
||||||
|
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
|
||||||
public void testTruncatedWithTcpFallbackBecauseOfMtu() throws IOException {
|
public void testTruncatedWithTcpFallbackBecauseOfMtu() throws IOException {
|
||||||
testTruncated0(true, true);
|
testTruncated0(true, true);
|
||||||
}
|
}
|
||||||
@ -3205,7 +3216,8 @@ public class DnsNameResolverTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 2000)
|
@Test
|
||||||
|
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
|
||||||
public void testSrvWithCnameNotCached() throws Exception {
|
public void testSrvWithCnameNotCached() throws Exception {
|
||||||
final AtomicBoolean alias = new AtomicBoolean();
|
final AtomicBoolean alias = new AtomicBoolean();
|
||||||
TestDnsServer dnsServer2 = new TestDnsServer(new RecordStore() {
|
TestDnsServer dnsServer2 = new TestDnsServer(new RecordStore() {
|
||||||
|
@ -16,11 +16,11 @@
|
|||||||
package io.netty.resolver.dns;
|
package io.netty.resolver.dns;
|
||||||
|
|
||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
import io.netty.channel.embedded.EmbeddedChannel;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class DnsResolveContextTest {
|
public class DnsResolveContextTest {
|
||||||
|
|
||||||
|
@ -12,16 +12,18 @@
|
|||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
* License for the specific language governing permissions and limitations
|
* License for the specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/package io.netty.resolver.dns;
|
*/
|
||||||
|
package io.netty.resolver.dns;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
|
|
||||||
public class DnsServerAddressStreamProvidersTest {
|
public class DnsServerAddressStreamProvidersTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUseCorrectProvider() {
|
public void testUseCorrectProvider() {
|
||||||
Assert.assertSame(DnsServerAddressStreamProviders.unixDefault(),
|
assertSame(DnsServerAddressStreamProviders.unixDefault(),
|
||||||
DnsServerAddressStreamProviders.platformDefault());
|
DnsServerAddressStreamProviders.platformDefault());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package io.netty.resolver.dns;
|
package io.netty.resolver.dns;
|
||||||
|
|
||||||
import io.netty.util.NetUtil;
|
import io.netty.util.NetUtil;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.resolver.dns;
|
package io.netty.resolver.dns;
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.Inet6Address;
|
import java.net.Inet6Address;
|
||||||
@ -28,8 +28,7 @@ import java.util.Arrays;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
|
||||||
public class NameServerComparatorTest {
|
public class NameServerComparatorTest {
|
||||||
|
|
||||||
@ -44,7 +43,7 @@ public class NameServerComparatorTest {
|
|||||||
private static InetSocketAddress UNRESOLVED2;
|
private static InetSocketAddress UNRESOLVED2;
|
||||||
private static InetSocketAddress UNRESOLVED3;
|
private static InetSocketAddress UNRESOLVED3;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void before() throws UnknownHostException {
|
public static void before() throws UnknownHostException {
|
||||||
IPV4ADDRESS1 = new InetSocketAddress(InetAddress.getByAddress("ns1", new byte[] { 10, 0, 0, 1 }), 53);
|
IPV4ADDRESS1 = new InetSocketAddress(InetAddress.getByAddress("ns1", new byte[] { 10, 0, 0, 1 }), 53);
|
||||||
IPV4ADDRESS2 = new InetSocketAddress(InetAddress.getByAddress("ns2", new byte[] { 10, 0, 0, 2 }), 53);
|
IPV4ADDRESS2 = new InetSocketAddress(InetAddress.getByAddress("ns2", new byte[] { 10, 0, 0, 2 }), 53);
|
||||||
|
@ -16,8 +16,7 @@
|
|||||||
package io.netty.resolver.dns;
|
package io.netty.resolver.dns;
|
||||||
|
|
||||||
import io.netty.channel.socket.InternetProtocolFamily;
|
import io.netty.channel.socket.InternetProtocolFamily;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
@ -26,6 +25,8 @@ import java.util.Arrays;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class PreferredAddressTypeComparatorTest {
|
public class PreferredAddressTypeComparatorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -44,7 +45,7 @@ public class PreferredAddressTypeComparatorTest {
|
|||||||
ipv6Address2, ipv4Address3, ipv6Address3);
|
ipv6Address2, ipv4Address3, ipv6Address3);
|
||||||
Collections.sort(addressList, ipv4);
|
Collections.sort(addressList, ipv4);
|
||||||
|
|
||||||
Assert.assertEquals(Arrays.asList(ipv4Address1, ipv4Address2, ipv4Address3, ipv6Address1,
|
assertEquals(Arrays.asList(ipv4Address1, ipv4Address2, ipv4Address3, ipv6Address1,
|
||||||
ipv6Address2, ipv6Address3), addressList);
|
ipv6Address2, ipv6Address3), addressList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +65,7 @@ public class PreferredAddressTypeComparatorTest {
|
|||||||
ipv6Address2, ipv4Address3, ipv6Address3);
|
ipv6Address2, ipv4Address3, ipv6Address3);
|
||||||
Collections.sort(addressList, ipv4);
|
Collections.sort(addressList, ipv4);
|
||||||
|
|
||||||
Assert.assertEquals(Arrays.asList(ipv6Address1,
|
assertEquals(Arrays.asList(ipv6Address1,
|
||||||
ipv6Address2, ipv6Address3, ipv4Address1, ipv4Address2, ipv4Address3), addressList);
|
ipv6Address2, ipv6Address3, ipv4Address1, ipv4Address2, ipv4Address3), addressList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,9 @@ import io.netty.channel.MultithreadEventLoopGroup;
|
|||||||
import io.netty.channel.nio.NioHandler;
|
import io.netty.channel.nio.NioHandler;
|
||||||
import io.netty.channel.socket.nio.NioDatagramChannel;
|
import io.netty.channel.socket.nio.NioDatagramChannel;
|
||||||
import io.netty.util.concurrent.Future;
|
import io.netty.util.concurrent.Future;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
@ -38,9 +38,9 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
|||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
import static org.hamcrest.core.StringContains.containsString;
|
import static org.hamcrest.core.StringContains.containsString;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class SearchDomainTest {
|
public class SearchDomainTest {
|
||||||
|
|
||||||
@ -57,12 +57,12 @@ public class SearchDomainTest {
|
|||||||
private EventLoopGroup group;
|
private EventLoopGroup group;
|
||||||
private DnsNameResolver resolver;
|
private DnsNameResolver resolver;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
public void before() {
|
||||||
group = new MultithreadEventLoopGroup(1, NioHandler.newFactory());
|
group = new MultithreadEventLoopGroup(1, NioHandler.newFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
if (dnsServer != null) {
|
if (dnsServer != null) {
|
||||||
dnsServer.stop();
|
dnsServer.stop();
|
||||||
|
@ -16,29 +16,26 @@
|
|||||||
package io.netty.resolver.dns;
|
package io.netty.resolver.dns;
|
||||||
|
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
import org.junit.rules.TemporaryFolder;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import static io.netty.resolver.dns.UnixResolverDnsServerAddressStreamProvider.parseEtcResolverOptions;
|
import static io.netty.resolver.dns.UnixResolverDnsServerAddressStreamProvider.parseEtcResolverOptions;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class UnixResolverDnsServerAddressStreamProviderTest {
|
public class UnixResolverDnsServerAddressStreamProviderTest {
|
||||||
@Rule
|
|
||||||
public final TemporaryFolder folder = new TemporaryFolder();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultLookupShouldReturnResultsIfOnlySingleFileSpecified() throws Exception {
|
public void defaultLookupShouldReturnResultsIfOnlySingleFileSpecified(@TempDir Path tempDir) throws Exception {
|
||||||
File f = buildFile("domain linecorp.local\n" +
|
File f = buildFile(tempDir, "domain linecorp.local\n" +
|
||||||
"nameserver 127.0.0.2\n" +
|
"nameserver 127.0.0.2\n" +
|
||||||
"nameserver 127.0.0.3\n");
|
"nameserver 127.0.0.3\n");
|
||||||
UnixResolverDnsServerAddressStreamProvider p =
|
UnixResolverDnsServerAddressStreamProvider p =
|
||||||
@ -50,8 +47,9 @@ public class UnixResolverDnsServerAddressStreamProviderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nameServerAddressStreamShouldBeRotationalWhenRotationOptionsIsPresent() throws Exception {
|
public void nameServerAddressStreamShouldBeRotationalWhenRotationOptionsIsPresent(
|
||||||
File f = buildFile("options rotate\n" +
|
@TempDir Path tempDir) throws Exception {
|
||||||
|
File f = buildFile(tempDir, "options rotate\n" +
|
||||||
"domain linecorp.local\n" +
|
"domain linecorp.local\n" +
|
||||||
"nameserver 127.0.0.2\n" +
|
"nameserver 127.0.0.2\n" +
|
||||||
"nameserver 127.0.0.3\n" +
|
"nameserver 127.0.0.3\n" +
|
||||||
@ -81,8 +79,9 @@ public class UnixResolverDnsServerAddressStreamProviderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nameServerAddressStreamShouldAlwaysStartFromTheTopWhenRotationOptionsIsAbsent() throws Exception {
|
public void nameServerAddressStreamShouldAlwaysStartFromTheTopWhenRotationOptionsIsAbsent(
|
||||||
File f = buildFile("domain linecorp.local\n" +
|
@TempDir Path tempDir) throws Exception {
|
||||||
|
File f = buildFile(tempDir, "domain linecorp.local\n" +
|
||||||
"nameserver 127.0.0.2\n" +
|
"nameserver 127.0.0.2\n" +
|
||||||
"nameserver 127.0.0.3\n" +
|
"nameserver 127.0.0.3\n" +
|
||||||
"nameserver 127.0.0.4\n");
|
"nameserver 127.0.0.4\n");
|
||||||
@ -106,11 +105,11 @@ public class UnixResolverDnsServerAddressStreamProviderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultReturnedWhenNoBetterMatch() throws Exception {
|
public void defaultReturnedWhenNoBetterMatch(@TempDir Path tempDir) throws Exception {
|
||||||
File f = buildFile("domain linecorp.local\n" +
|
File f = buildFile(tempDir, "domain linecorp.local\n" +
|
||||||
"nameserver 127.0.0.2\n" +
|
"nameserver 127.0.0.2\n" +
|
||||||
"nameserver 127.0.0.3\n");
|
"nameserver 127.0.0.3\n");
|
||||||
File f2 = buildFile("domain squarecorp.local\n" +
|
File f2 = buildFile(tempDir, "domain squarecorp.local\n" +
|
||||||
"nameserver 127.0.0.4\n" +
|
"nameserver 127.0.0.4\n" +
|
||||||
"nameserver 127.0.0.5\n");
|
"nameserver 127.0.0.5\n");
|
||||||
UnixResolverDnsServerAddressStreamProvider p =
|
UnixResolverDnsServerAddressStreamProvider p =
|
||||||
@ -122,11 +121,11 @@ public class UnixResolverDnsServerAddressStreamProviderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void moreRefinedSelectionReturnedWhenMatch() throws Exception {
|
public void moreRefinedSelectionReturnedWhenMatch(@TempDir Path tempDir) throws Exception {
|
||||||
File f = buildFile("domain linecorp.local\n" +
|
File f = buildFile(tempDir, "domain linecorp.local\n" +
|
||||||
"nameserver 127.0.0.2\n" +
|
"nameserver 127.0.0.2\n" +
|
||||||
"nameserver 127.0.0.3\n");
|
"nameserver 127.0.0.3\n");
|
||||||
File f2 = buildFile("domain dc1.linecorp.local\n" +
|
File f2 = buildFile(tempDir, "domain dc1.linecorp.local\n" +
|
||||||
"nameserver 127.0.0.4\n" +
|
"nameserver 127.0.0.4\n" +
|
||||||
"nameserver 127.0.0.5\n");
|
"nameserver 127.0.0.5\n");
|
||||||
UnixResolverDnsServerAddressStreamProvider p =
|
UnixResolverDnsServerAddressStreamProvider p =
|
||||||
@ -138,96 +137,96 @@ public class UnixResolverDnsServerAddressStreamProviderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ndotsOptionIsParsedIfPresent() throws IOException {
|
public void ndotsOptionIsParsedIfPresent(@TempDir Path tempDir) throws IOException {
|
||||||
File f = buildFile("search localdomain\n" +
|
File f = buildFile(tempDir, "search localdomain\n" +
|
||||||
"nameserver 127.0.0.11\n" +
|
"nameserver 127.0.0.11\n" +
|
||||||
"options ndots:0\n");
|
"options ndots:0\n");
|
||||||
assertEquals(0, parseEtcResolverOptions(f).ndots());
|
assertEquals(0, parseEtcResolverOptions(f).ndots());
|
||||||
|
|
||||||
f = buildFile("search localdomain\n" +
|
f = buildFile(tempDir, "search localdomain\n" +
|
||||||
"nameserver 127.0.0.11\n" +
|
"nameserver 127.0.0.11\n" +
|
||||||
"options ndots:123 foo:goo\n");
|
"options ndots:123 foo:goo\n");
|
||||||
assertEquals(123, parseEtcResolverOptions(f).ndots());
|
assertEquals(123, parseEtcResolverOptions(f).ndots());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultValueReturnedIfNdotsOptionsNotPresent() throws IOException {
|
public void defaultValueReturnedIfNdotsOptionsNotPresent(@TempDir Path tempDir) throws IOException {
|
||||||
File f = buildFile("search localdomain\n" +
|
File f = buildFile(tempDir, "search localdomain\n" +
|
||||||
"nameserver 127.0.0.11\n");
|
"nameserver 127.0.0.11\n");
|
||||||
assertEquals(1, parseEtcResolverOptions(f).ndots());
|
assertEquals(1, parseEtcResolverOptions(f).ndots());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void timeoutOptionIsParsedIfPresent() throws IOException {
|
public void timeoutOptionIsParsedIfPresent(@TempDir Path tempDir) throws IOException {
|
||||||
File f = buildFile("search localdomain\n" +
|
File f = buildFile(tempDir, "search localdomain\n" +
|
||||||
"nameserver 127.0.0.11\n" +
|
"nameserver 127.0.0.11\n" +
|
||||||
"options timeout:0\n");
|
"options timeout:0\n");
|
||||||
assertEquals(0, parseEtcResolverOptions(f).timeout());
|
assertEquals(0, parseEtcResolverOptions(f).timeout());
|
||||||
|
|
||||||
f = buildFile("search localdomain\n" +
|
f = buildFile(tempDir, "search localdomain\n" +
|
||||||
"nameserver 127.0.0.11\n" +
|
"nameserver 127.0.0.11\n" +
|
||||||
"options foo:bar timeout:124\n");
|
"options foo:bar timeout:124\n");
|
||||||
assertEquals(124, parseEtcResolverOptions(f).timeout());
|
assertEquals(124, parseEtcResolverOptions(f).timeout());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultValueReturnedIfTimeoutOptionsIsNotPresent() throws IOException {
|
public void defaultValueReturnedIfTimeoutOptionsIsNotPresent(@TempDir Path tempDir) throws IOException {
|
||||||
File f = buildFile("search localdomain\n" +
|
File f = buildFile(tempDir, "search localdomain\n" +
|
||||||
"nameserver 127.0.0.11\n");
|
"nameserver 127.0.0.11\n");
|
||||||
assertEquals(5, parseEtcResolverOptions(f).timeout());
|
assertEquals(5, parseEtcResolverOptions(f).timeout());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void attemptsOptionIsParsedIfPresent() throws IOException {
|
public void attemptsOptionIsParsedIfPresent(@TempDir Path tempDir) throws IOException {
|
||||||
File f = buildFile("search localdomain\n" +
|
File f = buildFile(tempDir, "search localdomain\n" +
|
||||||
"nameserver 127.0.0.11\n" +
|
"nameserver 127.0.0.11\n" +
|
||||||
"options attempts:0\n");
|
"options attempts:0\n");
|
||||||
assertEquals(0, parseEtcResolverOptions(f).attempts());
|
assertEquals(0, parseEtcResolverOptions(f).attempts());
|
||||||
|
|
||||||
f = buildFile("search localdomain\n" +
|
f = buildFile(tempDir, "search localdomain\n" +
|
||||||
"nameserver 127.0.0.11\n" +
|
"nameserver 127.0.0.11\n" +
|
||||||
"options foo:bar attempts:12\n");
|
"options foo:bar attempts:12\n");
|
||||||
assertEquals(12, parseEtcResolverOptions(f).attempts());
|
assertEquals(12, parseEtcResolverOptions(f).attempts());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultValueReturnedIfAttemptsOptionsIsNotPresent() throws IOException {
|
public void defaultValueReturnedIfAttemptsOptionsIsNotPresent(@TempDir Path tempDir) throws IOException {
|
||||||
File f = buildFile("search localdomain\n" +
|
File f = buildFile(tempDir, "search localdomain\n" +
|
||||||
"nameserver 127.0.0.11\n");
|
"nameserver 127.0.0.11\n");
|
||||||
assertEquals(16, parseEtcResolverOptions(f).attempts());
|
assertEquals(16, parseEtcResolverOptions(f).attempts());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyEtcResolverDirectoryDoesNotThrow() throws IOException {
|
public void emptyEtcResolverDirectoryDoesNotThrow(@TempDir Path tempDir) throws IOException {
|
||||||
File f = buildFile("domain linecorp.local\n" +
|
File f = buildFile(tempDir, "domain linecorp.local\n" +
|
||||||
"nameserver 127.0.0.2\n" +
|
"nameserver 127.0.0.2\n" +
|
||||||
"nameserver 127.0.0.3\n");
|
"nameserver 127.0.0.3\n");
|
||||||
UnixResolverDnsServerAddressStreamProvider p =
|
UnixResolverDnsServerAddressStreamProvider p =
|
||||||
new UnixResolverDnsServerAddressStreamProvider(f, folder.newFolder().listFiles());
|
new UnixResolverDnsServerAddressStreamProvider(f, tempDir.resolve("netty-empty").toFile().listFiles());
|
||||||
|
|
||||||
DnsServerAddressStream stream = p.nameServerAddressStream("somehost");
|
DnsServerAddressStream stream = p.nameServerAddressStream("somehost");
|
||||||
assertHostNameEquals("127.0.0.2", stream.next());
|
assertHostNameEquals("127.0.0.2", stream.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void searchDomainsWithOnlyDomain() throws IOException {
|
public void searchDomainsWithOnlyDomain(@TempDir Path tempDir) throws IOException {
|
||||||
File f = buildFile("domain linecorp.local\n" +
|
File f = buildFile(tempDir, "domain linecorp.local\n" +
|
||||||
"nameserver 127.0.0.2\n");
|
"nameserver 127.0.0.2\n");
|
||||||
List<String> domains = UnixResolverDnsServerAddressStreamProvider.parseEtcResolverSearchDomains(f);
|
List<String> domains = UnixResolverDnsServerAddressStreamProvider.parseEtcResolverSearchDomains(f);
|
||||||
assertEquals(Collections.singletonList("linecorp.local"), domains);
|
assertEquals(Collections.singletonList("linecorp.local"), domains);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void searchDomainsWithOnlySearch() throws IOException {
|
public void searchDomainsWithOnlySearch(@TempDir Path tempDir) throws IOException {
|
||||||
File f = buildFile("search linecorp.local\n" +
|
File f = buildFile(tempDir, "search linecorp.local\n" +
|
||||||
"nameserver 127.0.0.2\n");
|
"nameserver 127.0.0.2\n");
|
||||||
List<String> domains = UnixResolverDnsServerAddressStreamProvider.parseEtcResolverSearchDomains(f);
|
List<String> domains = UnixResolverDnsServerAddressStreamProvider.parseEtcResolverSearchDomains(f);
|
||||||
assertEquals(Collections.singletonList("linecorp.local"), domains);
|
assertEquals(Collections.singletonList("linecorp.local"), domains);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void searchDomainsWithMultipleSearch() throws IOException {
|
public void searchDomainsWithMultipleSearch(@TempDir Path tempDir) throws IOException {
|
||||||
File f = buildFile("search linecorp.local\n" +
|
File f = buildFile(tempDir, "search linecorp.local\n" +
|
||||||
"search squarecorp.local\n" +
|
"search squarecorp.local\n" +
|
||||||
"nameserver 127.0.0.2\n");
|
"nameserver 127.0.0.2\n");
|
||||||
List<String> domains = UnixResolverDnsServerAddressStreamProvider.parseEtcResolverSearchDomains(f);
|
List<String> domains = UnixResolverDnsServerAddressStreamProvider.parseEtcResolverSearchDomains(f);
|
||||||
@ -235,24 +234,24 @@ public class UnixResolverDnsServerAddressStreamProviderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void searchDomainsWithMultipleSearchSeperatedByWhitespace() throws IOException {
|
public void searchDomainsWithMultipleSearchSeperatedByWhitespace(@TempDir Path tempDir) throws IOException {
|
||||||
File f = buildFile("search linecorp.local squarecorp.local\n" +
|
File f = buildFile(tempDir, "search linecorp.local squarecorp.local\n" +
|
||||||
"nameserver 127.0.0.2\n");
|
"nameserver 127.0.0.2\n");
|
||||||
List<String> domains = UnixResolverDnsServerAddressStreamProvider.parseEtcResolverSearchDomains(f);
|
List<String> domains = UnixResolverDnsServerAddressStreamProvider.parseEtcResolverSearchDomains(f);
|
||||||
assertEquals(Arrays.asList("linecorp.local", "squarecorp.local"), domains);
|
assertEquals(Arrays.asList("linecorp.local", "squarecorp.local"), domains);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void searchDomainsWithMultipleSearchSeperatedByTab() throws IOException {
|
public void searchDomainsWithMultipleSearchSeperatedByTab(@TempDir Path tempDir) throws IOException {
|
||||||
File f = buildFile("search linecorp.local\tsquarecorp.local\n" +
|
File f = buildFile(tempDir, "search linecorp.local\tsquarecorp.local\n" +
|
||||||
"nameserver 127.0.0.2\n");
|
"nameserver 127.0.0.2\n");
|
||||||
List<String> domains = UnixResolverDnsServerAddressStreamProvider.parseEtcResolverSearchDomains(f);
|
List<String> domains = UnixResolverDnsServerAddressStreamProvider.parseEtcResolverSearchDomains(f);
|
||||||
assertEquals(Arrays.asList("linecorp.local", "squarecorp.local"), domains);
|
assertEquals(Arrays.asList("linecorp.local", "squarecorp.local"), domains);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void searchDomainsPrecedence() throws IOException {
|
public void searchDomainsPrecedence(@TempDir Path tempDir) throws IOException {
|
||||||
File f = buildFile("domain linecorp.local\n" +
|
File f = buildFile(tempDir, "domain linecorp.local\n" +
|
||||||
"search squarecorp.local\n" +
|
"search squarecorp.local\n" +
|
||||||
"nameserver 127.0.0.2\n");
|
"nameserver 127.0.0.2\n");
|
||||||
List<String> domains = UnixResolverDnsServerAddressStreamProvider.parseEtcResolverSearchDomains(f);
|
List<String> domains = UnixResolverDnsServerAddressStreamProvider.parseEtcResolverSearchDomains(f);
|
||||||
@ -260,8 +259,8 @@ public class UnixResolverDnsServerAddressStreamProviderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ignoreInvalidEntries() throws Exception {
|
public void ignoreInvalidEntries(@TempDir Path tempDir) throws Exception {
|
||||||
File f = buildFile("domain netty.local\n" +
|
File f = buildFile(tempDir, "domain netty.local\n" +
|
||||||
"nameserver nil\n" +
|
"nameserver nil\n" +
|
||||||
"nameserver 127.0.0.3\n");
|
"nameserver 127.0.0.3\n");
|
||||||
UnixResolverDnsServerAddressStreamProvider p =
|
UnixResolverDnsServerAddressStreamProvider p =
|
||||||
@ -272,20 +271,15 @@ public class UnixResolverDnsServerAddressStreamProviderTest {
|
|||||||
assertHostNameEquals("127.0.0.3", stream.next());
|
assertHostNameEquals("127.0.0.3", stream.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
private File buildFile(String contents) throws IOException {
|
private File buildFile(Path tempDir, String contents) throws IOException {
|
||||||
File f = folder.newFile();
|
Path path = tempDir.resolve("netty-dns-" + UUID.randomUUID().toString().substring(24) + ".txt");
|
||||||
OutputStream out = new FileOutputStream(f);
|
Files.write(path, contents.getBytes(CharsetUtil.UTF_8));
|
||||||
try {
|
return path.toFile();
|
||||||
out.write(contents.getBytes(CharsetUtil.UTF_8));
|
|
||||||
} finally {
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
return f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ignoreComments() throws Exception {
|
public void ignoreComments(@TempDir Path tempDir) throws Exception {
|
||||||
File f = buildFile("domain linecorp.local\n" +
|
File f = buildFile(tempDir, "domain linecorp.local\n" +
|
||||||
"nameserver 127.0.0.2 #somecomment\n");
|
"nameserver 127.0.0.2 #somecomment\n");
|
||||||
UnixResolverDnsServerAddressStreamProvider p =
|
UnixResolverDnsServerAddressStreamProvider p =
|
||||||
new UnixResolverDnsServerAddressStreamProvider(f, null);
|
new UnixResolverDnsServerAddressStreamProvider(f, null);
|
||||||
@ -295,6 +289,6 @@ public class UnixResolverDnsServerAddressStreamProviderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void assertHostNameEquals(String expectedHostname, InetSocketAddress next) {
|
private static void assertHostNameEquals(String expectedHostname, InetSocketAddress next) {
|
||||||
assertEquals("unexpected hostname: " + next, expectedHostname, next.getHostString());
|
assertEquals(expectedHostname, next.getHostString(), "unexpected hostname: " + next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user