@Test
    public void testNoMessageAreSentAfterShutdown() throws InterruptedException, BrokenBarrierException, TimeoutException {
        final AtomicBoolean shutdownIssueDetected = new AtomicBoolean(false);
        final CountDownLatch latch = new CountDownLatch(1);
        ZContext ctx = new ZContext();

        ZMQ.Socket socketOne = ctx.createSocket(ZMQ.PAIR);
        socketOne.bind("inproc://zmsg.test");
        ZMQ.Socket socketTwo = ctx.createSocket(ZMQ.PAIR);
        socketTwo.connect("inproc://zmsg.test");

        final ZDispatcher dispatcher = new ZDispatcher();
        final CyclicBarrier handlersBarrier = new CyclicBarrier(2, new Runnable() {
            @Override
            public void run() {
                if (latch.getCount() == 0) {
                    dispatcher.shutdown();
                }
            }
        });

        ZDispatcher.ZSender senderOne = new ZDispatcher.ZSender();
        dispatcher.registerHandler(socketOne, new ZDispatcher.ZMessageHandler() {
            @Override
            public void handleMessage(ZDispatcher.ZSender sender, ZMsg msg) {
                latch.countDown();
                try {
                    handlersBarrier.await(1, TimeUnit.SECONDS);
                } catch (Exception e) {
                }
            }
        }, senderOne);
        ZDispatcher.ZSender senderTwo = new ZDispatcher.ZSender();
        dispatcher.registerHandler(socketTwo, new ZDispatcher.ZMessageHandler() {

            @Override
            public void handleMessage(ZDispatcher.ZSender sender, ZMsg msg) {
                sender.send(msg);
                shutdownIssueDetected.set(true);
            }
        }, senderTwo);

        ZMsg msg = new ZMsg();
        msg.add(new ZFrame("Hello"));

        senderTwo.send(msg);
        handlersBarrier.await(1, TimeUnit.SECONDS);

        senderOne.send(msg);
        senderOne.send(msg);

        latch.await(1, TimeUnit.SECONDS);
        assertEquals(0, latch.getCount());
        assertFalse(shutdownIssueDetected.get());

        dispatcher.shutdown();
        ctx.destroy();
    }