use of com.hazelcast.core.Cluster in project hazelcast by hazelcast.
the class AbstractClockTest method assertClusterSizeAlways.
protected static void assertClusterSizeAlways(final int expected, HazelcastInstance hz) {
final Cluster cluster = hz.getCluster();
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals("Cluster should be stable when system clock changes!", expected, cluster.getMembers().size());
}
}, JUMP_AFTER_SECONDS * 2);
}
use of com.hazelcast.core.Cluster in project hazelcast-simulator by hazelcast.
the class HazelcastUtilsTest method createMockHazelcastInstance.
private HazelcastInstance createMockHazelcastInstance(Member member, boolean returnMember, Exception getClusterException) {
Set<Member> memberSet = new HashSet<Member>();
memberSet.add(member);
Cluster cluster = mock(Cluster.class);
when(cluster.getMembers()).thenReturn(memberSet);
when(cluster.getLocalMember()).thenReturn(returnMember ? member : null);
HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
when(hazelcastInstance.getLocalEndpoint()).thenReturn(returnMember ? member : null);
if (getClusterException == null) {
when(hazelcastInstance.getCluster()).thenReturn(cluster);
} else {
when(hazelcastInstance.getCluster()).thenReturn(cluster).thenThrow(getClusterException);
}
return hazelcastInstance;
}
use of com.hazelcast.core.Cluster in project hazelcast by hazelcast.
the class ClientClusterServiceImpl method initMembershipListener.
private void initMembershipListener(MembershipListener listener) {
if (listener instanceof InitialMembershipListener) {
Cluster cluster = client.getCluster();
Collection<Member> memberCollection = members.get().values();
LinkedHashSet<Member> members = new LinkedHashSet<Member>(memberCollection);
InitialMembershipEvent event = new InitialMembershipEvent(cluster, members);
((InitialMembershipListener) listener).init(event);
}
}
use of com.hazelcast.core.Cluster in project hazelcast by hazelcast.
the class ClusterMembershipTest method testAddMembershipListener_whenNullListener.
@Test(expected = NullPointerException.class)
public void testAddMembershipListener_whenNullListener() {
HazelcastInstance hz = createHazelcastInstance();
Cluster cluster = hz.getCluster();
cluster.addMembershipListener(null);
}
use of com.hazelcast.core.Cluster 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));
}
});
}
Aggregations