Config config = newConfig();
HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config);
HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config);
HazelcastInstance h3 = Hazelcast.newHazelcastInstance(config);
final String name = generateKeyOwnedBy(h3);
ICountDownLatch countDownLatch = h3.getCountDownLatch(name);
countDownLatch.trySetCount(5);
TestMemberShipListener memberShipListener = new TestMemberShipListener(2);
h3.getCluster().addMembershipListener(memberShipListener);
TestLifeCycleListener lifeCycleListener = new TestLifeCycleListener(1);
h3.getLifecycleService().addLifecycleListener(lifeCycleListener);
countDownLatch.countDown();
closeConnectionBetween(h1, h3);
closeConnectionBetween(h2, h3);
assertOpenEventually(memberShipListener.latch);
assertClusterSizeEventually(2, h1);
assertClusterSizeEventually(2, h2);
assertClusterSizeEventually(1, h3);
ICountDownLatch countDownLatch1 = h1.getCountDownLatch(name);
countDownLatch1.countDown();
countDownLatch.countDown();
countDownLatch.countDown();
assertOpenEventually(lifeCycleListener.latch);
assertClusterSizeEventually(3, h1);
assertClusterSizeEventually(3, h2);
assertClusterSizeEventually(3, h3);
ICountDownLatch countDownLatchTest = h3.getCountDownLatch(name);
assertEquals(3, countDownLatchTest.getCount());
}