GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Auto-port 5.0: DnsAddressResolverGroupTest: Use a mock DNS server ins… · netty/netty@5b13c47

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • resolver-dns/src/test/java/io/netty/resolver/dns
    • DnsAddressResolverGroupTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎resolver-dns/src/test/java/io/netty/resolver/dns/DnsAddressResolverGroupTest.java‎

Copy file name to clipboardExpand all lines: resolver-dns/src/test/java/io/netty/resolver/dns/DnsAddressResolverGroupTest.java
+26-5Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,23 @@
2323
import io.netty.channel.socket.nio.NioDatagramChannel;
2424
import io.netty.resolver.AddressResolver;
2525
import io.netty.resolver.InetSocketAddressResolver;
26-
import io.netty.util.concurrent.Future;
2726
import io.netty.util.concurrent.FutureListener;
2827
import io.netty.util.concurrent.Promise;
28+
import org.apache.directory.server.dns.messages.QuestionRecord;
29+
import org.apache.directory.server.dns.messages.RecordType;
30+
import org.apache.directory.server.dns.messages.ResourceRecord;
31+
import org.apache.directory.server.dns.store.RecordStore;
2932
import org.junit.jupiter.api.Test;
3033

3134
import java.net.InetAddress;
3235
import java.net.InetSocketAddress;
3336
import java.net.SocketAddress;
3437
import java.nio.channels.UnsupportedAddressTypeException;
38+
import java.util.Collections;
39+
import java.util.Set;
3540
import java.util.concurrent.ExecutionException;
3641

42+
import static io.netty.resolver.dns.TestDnsServer.newARecord;
3743
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
3844
import static org.junit.jupiter.api.Assertions.assertSame;
3945
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -71,11 +77,25 @@ public void testUseConfiguredEventLoop() throws InterruptedException {
7177
}
7278

7379
@Test
74-
public void testSharedDNSCacheAcrossEventLoops() throws InterruptedException, ExecutionException {
80+
public void testSharedDNSCacheAcrossEventLoops() throws Exception {
81+
final String hostname = "netty.io";
82+
final String expectedIp = "1.2.3.4";
83+
TestDnsServer dnsServer = new TestDnsServer(new RecordStore() {
84+
@Override
85+
public Set<ResourceRecord> getRecords(QuestionRecord question) {
86+
if (question.getRecordType() == RecordType.A && question.getDomainName().equalsIgnoreCase(hostname)) {
87+
return Collections.singleton(newARecord(hostname, expectedIp));
88+
}
89+
return null;
90+
}
91+
});
92+
dnsServer.start();
7593
MultiThreadIoEventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory());
7694
final EventLoop loop = group.next();
7795
DnsNameResolverBuilder builder = new DnsNameResolverBuilder()
78-
.eventLoop(loop).datagramChannelType(NioDatagramChannel.class);
96+
.eventLoop(loop).datagramChannelType(NioDatagramChannel.class)
97+
.optResourceEnabled(false)
98+
.nameServerProvider(new SingletonDnsServerAddressStreamProvider(dnsServer.localAddress()));
7999
DnsAddressResolverGroup resolverGroup = new DnsAddressResolverGroup(builder);
80100
EventLoopGroup defaultEventLoopGroup = new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory());
81101
EventLoop eventLoop1 = defaultEventLoopGroup.next();
@@ -84,16 +104,17 @@ public void testSharedDNSCacheAcrossEventLoops() throws InterruptedException, Ex
84104
final Promise<InetSocketAddress> promise1 = loop.newPromise();
85105
InetSocketAddressResolver resolver1 = (InetSocketAddressResolver) resolverGroup.getResolver(eventLoop1);
86106
InetAddress address1 =
87-
resolve(resolver1, InetSocketAddress.createUnresolved("netty.io", 80), promise1);
107+
resolve(resolver1, InetSocketAddress.createUnresolved(hostname, 80), promise1);
88108
final Promise<InetSocketAddress> promise2 = loop.newPromise();
89109
InetSocketAddressResolver resolver2 = (InetSocketAddressResolver) resolverGroup.getResolver(eventLoop2);
90110
InetAddress address2 =
91-
resolve(resolver2, InetSocketAddress.createUnresolved("netty.io", 80), promise2);
111+
resolve(resolver2, InetSocketAddress.createUnresolved(hostname, 80), promise2);
92112
assertSame(address1, address2);
93113
} finally {
94114
resolverGroup.close();
95115
group.shutdownGracefully();
96116
defaultEventLoopGroup.shutdownGracefully();
117+
dnsServer.stop();
97118
}
98119
}
99120

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.