|
38 | 38 | import io.netty.handler.ssl.SslProvider; |
39 | 39 | import io.netty.handler.ssl.util.InsecureTrustManagerFactory; |
40 | 40 | import io.netty.handler.ssl.util.SelfSignedCertificate; |
| 41 | +import io.netty.resolver.dns.DnsNameResolver; |
41 | 42 | import io.netty.resolver.dns.DnsNameResolverBuilder; |
42 | 43 | import io.netty.resolver.dns.DnsServerAddressStreamProviders; |
43 | 44 | import io.netty.util.HashedWheelTimer; |
44 | 45 | import io.netty.util.ReferenceCountUtil; |
45 | 46 | import io.netty.util.concurrent.DefaultThreadFactory; |
46 | 47 | import io.netty.util.concurrent.EventExecutor; |
47 | 48 | import io.netty.util.concurrent.FastThreadLocalThread; |
| 49 | +import io.netty.util.concurrent.GenericFutureListener; |
48 | 50 | import io.netty.util.concurrent.GlobalEventExecutor; |
49 | 51 | import io.netty.util.concurrent.ImmediateEventExecutor; |
50 | 52 | import io.netty.util.concurrent.ImmediateExecutor; |
|
58 | 60 | import reactor.blockhound.BlockingOperationError; |
59 | 61 | import reactor.blockhound.integration.BlockHoundIntegration; |
60 | 62 |
|
| 63 | +import java.net.InetAddress; |
61 | 64 | import java.net.InetSocketAddress; |
62 | 65 | import java.util.ArrayList; |
63 | 66 | import java.util.List; |
|
72 | 75 | import java.util.concurrent.Future; |
73 | 76 | import java.util.concurrent.FutureTask; |
74 | 77 | import java.util.concurrent.LinkedBlockingQueue; |
| 78 | +import java.util.concurrent.ThreadFactory; |
75 | 79 | import java.util.concurrent.TimeUnit; |
76 | 80 | import java.util.concurrent.atomic.AtomicLong; |
77 | 81 | import java.util.concurrent.atomic.AtomicReference; |
@@ -435,6 +439,47 @@ public void testUnixResolverDnsServerAddressStreamProvider_ParseEtcResolverSearc |
435 | 439 | } |
436 | 440 | } |
437 | 441 |
|
| 442 | + @Test |
| 443 | + @Timeout(value = 5000, unit = TimeUnit.MILLISECONDS) |
| 444 | + public void testDnsNameResolverAllowsBlockingCalls() throws InterruptedException { |
| 445 | + CountDownLatch latch = new CountDownLatch(1); |
| 446 | + List<Throwable> error = new ArrayList<>(); |
| 447 | + ThreadFactory threadFactory = new ThreadFactory() { |
| 448 | + @Override |
| 449 | + public Thread newThread(Runnable r) { |
| 450 | + Thread t = new DefaultThreadFactory("test").newThread(r); |
| 451 | + t.setUncaughtExceptionHandler((t1, e) -> { |
| 452 | + error.add(e); |
| 453 | + latch.countDown(); |
| 454 | + }); |
| 455 | + return t; |
| 456 | + } |
| 457 | + }; |
| 458 | + EventLoopGroup group = new NioEventLoopGroup(1, threadFactory); |
| 459 | + try (DnsNameResolver resolver = new DnsNameResolverBuilder(group.next()) |
| 460 | + .datagramChannelFactory(NioDatagramChannel::new) |
| 461 | + .build()) { |
| 462 | + resolver.resolve("netty.io").addListener( |
| 463 | + new GenericFutureListener<io.netty.util.concurrent.Future<? super InetAddress>>() { |
| 464 | + @Override |
| 465 | + public void operationComplete(io.netty.util.concurrent.Future<? super InetAddress> future) { |
| 466 | + if (!future.isSuccess()) { |
| 467 | + error.add(future.cause()); |
| 468 | + } |
| 469 | + latch.countDown(); |
| 470 | + } |
| 471 | + }); |
| 472 | + latch.await(); |
| 473 | + for (Throwable t : error) { |
| 474 | + if (t instanceof BlockingOperationError || t.getCause() instanceof BlockingOperationError) { |
| 475 | + fail("BlockingOperationError was thrown: " + t); |
| 476 | + } |
| 477 | + } |
| 478 | + } finally { |
| 479 | + group.shutdownGracefully(); |
| 480 | + } |
| 481 | + } |
| 482 | + |
438 | 483 | private static void doTestParseResolverFilesAllowsBlockingCalls(Callable<Object> callable) |
439 | 484 | throws InterruptedException { |
440 | 485 | SingleThreadEventExecutor executor = |
|