@Test
public void testLocalAddressReuse() throws Exception {

    for (int i = 0; i < 2; i ++) {
        Bootstrap cb = new Bootstrap();
        ServerBootstrap sb = new ServerBootstrap();
        cb.group(group1)
          .channel(LocalChannel.class)
          .handler(new TestHandler());
        sb.group(group2)
          .channel(LocalServerChannel.class)
          .childHandler(new ChannelInitializer<LocalChannel>() {
              @Override
              public void initChannel(LocalChannel ch) throws Exception {
                  ch.pipeline().addLast(new TestHandler());
              }
          });
        Channel sc = null;
        Channel cc = null;
        try {
            // Start server
            sc = sb.bind(TEST_ADDRESS).sync().channel();
            final CountDownLatch latch = new CountDownLatch(1);
            // Connect to the server
            cc = cb.connect(sc.localAddress()).sync().channel();
            final Channel ccCpy = cc;
            cc.eventLoop().execute(new Runnable() {
                @Override
                public void run() {
                    // Send a message event up the pipeline.
                    ccCpy.pipeline().fireChannelRead("Hello, World");
                    latch.countDown();
                }
            });
            assertTrue(latch.await(5, SECONDS));
            // Close the channel
            closeChannel(cc);
            closeChannel(sc);
            sc.closeFuture().sync();
            assertNull(String.format(
                    "Expected null, got channel '%s' for local address '%s'",
                    LocalChannelRegistry.get(TEST_ADDRESS), TEST_ADDRESS), LocalChannelRegistry.get(TEST_ADDRESS));
        } finally {
            closeChannel(cc);
            closeChannel(sc);
        }
    }
}