TEST_F(ClusterTest, testListenersWhenClusterDown) { HazelcastServer instance(*g_srvFactory); std::auto_ptr<ClientConfig> clientConfig(getConfig()); clientConfig->setAttemptPeriod(1000 * 10).setConnectionAttemptLimit(100).setLogLevel(FINEST); HazelcastClient hazelcastClient(*clientConfig); util::CountDownLatch countDownLatch(1); DummyListenerClusterTest listener(countDownLatch); IMap<std::string, std::string> m = hazelcastClient.getMap<std::string, std::string>( "testListenersWhenClusterDown"); m.addEntryListener(listener, true); instance.shutdown(); util::CountDownLatch lifecycleLatch(1); LclForClusterTest lifecycleListener(lifecycleLatch); hazelcastClient.addLifecycleListener(&lifecycleListener); HazelcastServer instance2(*g_srvFactory); ASSERT_TRUE(lifecycleLatch.await(120)); // Let enough time for the client to re-register the failed listeners util::sleep(1); m.put("sample", "entry"); ASSERT_TRUE(countDownLatch.await(60)); ASSERT_TRUE(hazelcastClient.removeLifecycleListener(&lifecycleListener)); }
void ClusterTest::testListenersWhenClusterDown() { HazelcastServer instance(hazelcastInstanceFactory); std::auto_ptr<ClientConfig> clientConfig(getConfig()); clientConfig->setAttemptPeriod(1000 * 10).setConnectionAttemptLimit(100).setLogLevel(FINEST); HazelcastClient hazelcastClient(*clientConfig); util::CountDownLatch countDownLatch(1); DummyListenerClusterTest listener(countDownLatch); IMap<std::string, std::string> m = hazelcastClient.getMap<std::string, std::string>("testListenersWhenClusterDown"); m.addEntryListener(listener, true); instance.shutdown(); util::CountDownLatch lifecycleLatch(1); LclForClusterTest lifecycleListener(lifecycleLatch); hazelcastClient.addLifecycleListener(&lifecycleListener); HazelcastServer instance2(hazelcastInstanceFactory); assertTrue(lifecycleLatch.await(120), "Lifecycle latch await timed out!"); m.put("sample", "entry"); assertTrue(countDownLatch.await(60), "Await timed out !"); assertTrue(hazelcastClient.removeLifecycleListener(&lifecycleListener), "Listener could not removed"); }