use of com.hazelcast.core.MembershipListener in project hazelcast by hazelcast.
the class AbstractListenersOnReconnectTest method testListenersTerminateRandomNode.
private void testListenersTerminateRandomNode() {
setupListener();
terminateRandomNode();
HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
final CountDownLatch memberAddedLatch = new CountDownLatch(1);
clientInstanceImpl.getClientClusterService().addMembershipListener(new MembershipListener() {
@Override
public void memberAdded(MembershipEvent membershipEvent) {
memberAddedLatch.countDown();
}
@Override
public void memberRemoved(MembershipEvent membershipEvent) {
}
@Override
public void memberAttributeChanged(MemberAttributeEvent memberAttributeEvent) {
}
});
factory.newHazelcastInstance();
assertOpenEventually(memberAddedLatch);
validateRegistrationsAndListenerFunctionality();
}
use of com.hazelcast.core.MembershipListener in project hazelcast by hazelcast.
the class ClusterMembershipTest method testAddMembershipListener_whenListenerRegisteredTwice.
@Test
public void testAddMembershipListener_whenListenerRegisteredTwice() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance hz1 = factory.newHazelcastInstance();
Cluster cluster = hz1.getCluster();
final MembershipListener membershipListener = mock(MembershipListener.class);
String id1 = cluster.addMembershipListener(membershipListener);
String id2 = cluster.addMembershipListener(membershipListener);
// first we check if the registration id's are different
assertNotEquals(id1, id2);
// an now we make sure that if a member joins the cluster, the same interface gets invoked twice.
HazelcastInstance hz2 = factory.newHazelcastInstance();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
//now we verify that the memberAdded method is called twice.
verify(membershipListener, times(2)).memberAdded(any(MembershipEvent.class));
}
});
}
use of com.hazelcast.core.MembershipListener in project hazelcast by hazelcast.
the class MemberAttributeTest method testAddAttributes.
@Test(timeout = 120000)
public void testAddAttributes() 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("Test2", 321);
// Force sleep to distribute value
assertOpenEventually(latch);
assertNotNull(member.getIntAttribute("Test2"));
assertEquals(321, (int) member.getIntAttribute("Test2"));
h1.shutdown();
h2.shutdown();
}
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