use of com.hazelcast.core.MembershipListener in project hazelcast by hazelcast.
the class MemberAttributeTest method testRemoveAttributes.
@Test(timeout = 120000)
public void testRemoveAttributes() throws Exception {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance h1 = factory.newHazelcastInstance();
Member m1 = h1.getCluster().getLocalMember();
m1.setIntAttribute("Test", 123);
HazelcastInstance h2 = factory.newHazelcastInstance();
assertEquals(2, h2.getCluster().getMembers().size());
Member member = null;
for (Member m : h2.getCluster().getMembers()) {
if (m == h2.getCluster().getLocalMember())
continue;
member = m;
}
assertNotNull(member);
assertEquals(m1, member);
assertNotNull(member.getIntAttribute("Test"));
assertEquals(123, (int) member.getIntAttribute("Test"));
final CountDownLatch latch = new CountDownLatch(2);
final MembershipListener listener = new LatchMembershipListener(latch);
h2.getCluster().addMembershipListener(listener);
h1.getCluster().addMembershipListener(listener);
m1.removeAttribute("Test");
// Force sleep to distribute value
assertOpenEventually(latch);
assertNull(member.getIntAttribute("Test"));
h1.shutdown();
h2.shutdown();
}
use of com.hazelcast.core.MembershipListener in project hazelcast by hazelcast.
the class MemberAttributeTest method testChangeAttributes.
@Test(timeout = 120000)
public void testChangeAttributes() throws Exception {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance h1 = factory.newHazelcastInstance();
Member m1 = h1.getCluster().getLocalMember();
m1.setIntAttribute("Test", 123);
HazelcastInstance h2 = factory.newHazelcastInstance();
assertEquals(2, h2.getCluster().getMembers().size());
Member member = null;
for (Member m : h2.getCluster().getMembers()) {
if (m == h2.getCluster().getLocalMember())
continue;
member = m;
}
assertNotNull(member);
assertEquals(m1, member);
assertNotNull(member.getIntAttribute("Test"));
assertEquals(123, (int) member.getIntAttribute("Test"));
final CountDownLatch latch = new CountDownLatch(2);
final MembershipListener listener = new LatchMembershipListener(latch);
h2.getCluster().addMembershipListener(listener);
h1.getCluster().addMembershipListener(listener);
m1.setIntAttribute("Test", 321);
// Force sleep to distribute value
assertOpenEventually(latch);
assertNotNull(member.getIntAttribute("Test"));
assertEquals(321, (int) member.getIntAttribute("Test"));
h1.shutdown();
h2.shutdown();
}
Aggregations