    @Test
    public void testWatchEvent() throws Exception {

        try (TestingServer testingServer = new TestingServer(2229, tmpDir.newFolder());) {
            testingServer.start();
            try (ZooKeeperGroupMembershipHandler peer1 = new ZooKeeperGroupMembershipHandler(testingServer.getConnectString(),
                    6000, false /*acl */, peerId1, Collections.EMPTY_MAP, new Properties());
                    ZooKeeperGroupMembershipHandler peer2 = new ZooKeeperGroupMembershipHandler(testingServer.getConnectString(),
                            6000, false /*acl */, peerId2, Collections.EMPTY_MAP, new Properties())) {
                peer1.start();
                peer2.start();
                List<String> peersFrom1 = peer1.getPeers();
                List<String> peersFrom2 = peer2.getPeers();
                assertEquals(Arrays.asList(peerId1, peerId2), peersFrom1);
                assertEquals(Arrays.asList(peerId1, peerId2), peersFrom2);

                AtomicInteger eventFired2 = new AtomicInteger();;
                peer2.watchEvent("foo", new GroupMembershipHandler.EventCallback() {
                    @Override
                    public void eventFired(String eventId) {
                        eventFired2.incrementAndGet();
                    }

                    @Override
                    public void reconnected() {

                    }
                });

                peer1.fireEvent("foo");

                TestUtils.waitForCondition(() -> {
                    return eventFired2.get() >= 1;
                }, 100);
                assertTrue(eventFired2.get() >= 1);
                eventFired2.set(0);

                try (ZooKeeperGroupMembershipHandler peer3 = new ZooKeeperGroupMembershipHandler(testingServer.getConnectString(),
                        6000, false /*acl */, peerId3, Collections.EMPTY_MAP, new Properties())) {
                    peer3.start();

                    AtomicInteger eventFired3 = new AtomicInteger();
                    peer3.watchEvent("foo", new GroupMembershipHandler.EventCallback() {
                        @Override
                        public void eventFired(String eventId) {
                            eventFired3.incrementAndGet();
                        }

                        @Override
                        public void reconnected() {

                        }
                    });

                    peer1.fireEvent("foo");

                    TestUtils.waitForCondition(() -> {
                        return (eventFired2.get() >= 1
                                && eventFired3.get() >= 1);
                    }, 100);
                    assertTrue(eventFired3.get() >= 1);
                    assertTrue(eventFired2.get() >= 1);

                    eventFired3.set(0);
                    eventFired2.set(0);

                    peer3.fireEvent("foo");

                    for (int i = 0; i < 10; i++) {
                        if (eventFired2.get() >= 1
                                && eventFired3.get() >= 1) {
                            break;
                        }
                        Thread.sleep(100);
                    }
                    assertTrue(eventFired3.get() == 0); // self events are not fired
                    assertTrue(eventFired2.get() > 0);
                }

            }
        }
    }