TEST_F(ClusterTest, testClusterListeners) {
                HazelcastServer instance(*g_srvFactory);
                std::auto_ptr<HazelcastClient> hazelcastClient(getNewClient());
                Cluster cluster = hazelcastClient->getCluster();
                util::CountDownLatch memberAdded(1);
                util::CountDownLatch memberAddedInit(2);
                util::CountDownLatch memberRemoved(1);
                util::CountDownLatch memberRemovedInit(1);
                util::CountDownLatch attributeLatch(7);
                util::CountDownLatch attributeLatchInit(7);

                SampleInitialListener sampleInitialListener(memberAddedInit, attributeLatchInit, memberRemovedInit);
                SampleListenerInClusterTest sampleListener(memberAdded, attributeLatch, memberRemoved);

                cluster.addMembershipListener(&sampleInitialListener);
                cluster.addMembershipListener(&sampleListener);

                HazelcastServer instance2(*g_srvFactory);

                ASSERT_TRUE(attributeLatchInit.await(30));
                ASSERT_TRUE(attributeLatch.await(30));
                ASSERT_TRUE(memberAdded.await(30));
                ASSERT_TRUE(memberAddedInit.await(30));

                instance2.shutdown();

                ASSERT_TRUE(memberRemoved.await(30));
                ASSERT_TRUE(memberRemovedInit.await(30));

                instance.shutdown();

                cluster.removeMembershipListener(&sampleInitialListener);
                cluster.removeMembershipListener(&sampleListener);
            }
            void ClusterTest::testClusterListeners() {
                HazelcastServer instance(hazelcastInstanceFactory);
                std::auto_ptr<HazelcastClient> hazelcastClient(getNewClient());
                Cluster cluster = hazelcastClient->getCluster();
                util::CountDownLatch memberAdded(1);
                util::CountDownLatch memberAddedInit(2);
                util::CountDownLatch memberRemoved(1);
                util::CountDownLatch memberRemovedInit(1);
                util::CountDownLatch attributeLatch(7);
                util::CountDownLatch attributeLatchInit(7);

                SampleInitialListener sampleInitialListener(memberAddedInit, attributeLatchInit, memberRemovedInit);
                SampleListenerInClusterTest sampleListener(memberAdded, attributeLatch, memberRemoved);

                cluster.addMembershipListener(&sampleInitialListener);
                cluster.addMembershipListener(&sampleListener);

                HazelcastServer instance2(hazelcastInstanceFactory);

                assertTrue(attributeLatchInit.await(30), "attributeLatchInit");
                assertTrue(attributeLatch.await(30), "attributeLatch");
                assertTrue(memberAdded.await(30), "memberAdded");
                assertTrue(memberAddedInit.await(30), "memberAddedInit");

                instance2.shutdown();

                assertTrue(memberRemoved.await(30), "memberRemoved");
                assertTrue(memberRemovedInit.await(30), "memberRemovedInit");

                instance.shutdown();

                cluster.removeMembershipListener(&sampleInitialListener);
                cluster.removeMembershipListener(&sampleListener);
            }