@@ -48,6 +48,7 @@ private DnsNameResolverBuilder newResolver() {
48
48
49
49
private TestDnsServer dnsServer ;
50
50
private EventLoopGroup group ;
51
+ private DnsNameResolver resolver ;
51
52
52
53
@ Before
53
54
public void before () {
@@ -60,6 +61,9 @@ public void destroy() {
60
61
dnsServer .stop ();
61
62
dnsServer = null ;
62
63
}
64
+ if (resolver != null ) {
65
+ resolver .close ();
66
+ }
63
67
group .shutdownGracefully ();
64
68
}
65
69
@@ -77,7 +81,7 @@ public void testResolve() throws Exception {
77
81
dnsServer = new TestDnsServer (store );
78
82
dnsServer .start ();
79
83
80
- DnsNameResolver resolver = newResolver ().searchDomains (Collections .singletonList ("foo.com" )).build ();
84
+ resolver = newResolver ().searchDomains (Collections .singletonList ("foo.com" )).build ();
81
85
82
86
String a = "host1.foo.com" ;
83
87
String resolved = assertResolve (resolver , a );
@@ -124,7 +128,7 @@ public void testResolveAll() throws Exception {
124
128
dnsServer = new TestDnsServer (store );
125
129
dnsServer .start ();
126
130
127
- DnsNameResolver resolver = newResolver ().searchDomains (Collections .singletonList ("foo.com" )).build ();
131
+ resolver = newResolver ().searchDomains (Collections .singletonList ("foo.com" )).build ();
128
132
129
133
String a = "host1.foo.com" ;
130
134
List <String > resolved = assertResolveAll (resolver , a );
@@ -169,7 +173,7 @@ public void testMultipleSearchDomain() throws Exception {
169
173
dnsServer = new TestDnsServer (store );
170
174
dnsServer .start ();
171
175
172
- DnsNameResolver resolver = newResolver ().searchDomains (Arrays .asList ("foo.com" , "bar.com" )).build ();
176
+ resolver = newResolver ().searchDomains (Arrays .asList ("foo.com" , "bar.com" )).build ();
173
177
174
178
// "host1" resolves via the "foo.com" search path
175
179
String resolved = assertResolve (resolver , "host1" );
@@ -198,7 +202,7 @@ public void testSearchDomainWithNdots2() throws Exception {
198
202
dnsServer = new TestDnsServer (store );
199
203
dnsServer .start ();
200
204
201
- DnsNameResolver resolver = newResolver ().searchDomains (Collections .singleton ("foo.com" )).ndots (2 ).build ();
205
+ resolver = newResolver ().searchDomains (Collections .singleton ("foo.com" )).ndots (2 ).build ();
202
206
203
207
String resolved = assertResolve (resolver , "host1.sub" );
204
208
assertEquals (store .getAddress ("host1.sub.foo.com" ), resolved );
@@ -208,6 +212,32 @@ public void testSearchDomainWithNdots2() throws Exception {
208
212
assertEquals (store .getAddress ("host2.sub.foo.com" ), resolved );
209
213
}
210
214
215
+ @ Test
216
+ public void testSearchDomainWithNdots0 () throws Exception {
217
+ Set <String > domains = new HashSet <String >();
218
+ domains .add ("host1" );
219
+ domains .add ("host1.foo.com" );
220
+ domains .add ("host2.foo.com" );
221
+
222
+ TestDnsServer .MapRecordStoreA store = new TestDnsServer .MapRecordStoreA (domains );
223
+ dnsServer = new TestDnsServer (store );
224
+ dnsServer .start ();
225
+
226
+ resolver = newResolver ().searchDomains (Collections .singleton ("foo.com" )).ndots (0 ).build ();
227
+
228
+ // "host1" resolves directly as ndots = 0
229
+ String resolved = assertResolve (resolver , "host1" );
230
+ assertEquals (store .getAddress ("host1" ), resolved );
231
+
232
+ // "host1.foo.com" resolves to host1.foo
233
+ resolved = assertResolve (resolver , "host1.foo.com" );
234
+ assertEquals (store .getAddress ("host1.foo.com" ), resolved );
235
+
236
+ // "host2" resolves to host2.foo.com with the foo.com search domain
237
+ resolved = assertResolve (resolver , "host2" );
238
+ assertEquals (store .getAddress ("host2.foo.com" ), resolved );
239
+ }
240
+
211
241
private void assertNotResolve (DnsNameResolver resolver , String inetHost ) throws InterruptedException {
212
242
Future <InetAddress > fut = resolver .resolve (inetHost );
213
243
assertTrue (fut .await (10 , TimeUnit .SECONDS ));
0 commit comments