Search in sources :

Example 6 with Cluster

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);
}
Also used : Cluster(com.hazelcast.core.Cluster) AssertTask(com.hazelcast.test.AssertTask)

Example 7 with Cluster

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;
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Cluster(com.hazelcast.core.Cluster) HazelcastUtils.isOldestMember(com.hazelcast.simulator.utils.HazelcastUtils.isOldestMember) Member(com.hazelcast.core.Member) HashSet(java.util.HashSet)

Example 8 with Cluster

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);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InitialMembershipListener(com.hazelcast.core.InitialMembershipListener) Cluster(com.hazelcast.core.Cluster) Member(com.hazelcast.core.Member) InitialMembershipEvent(com.hazelcast.core.InitialMembershipEvent)

Example 9 with Cluster

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Cluster(com.hazelcast.core.Cluster) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 10 with Cluster

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));
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Cluster(com.hazelcast.core.Cluster) AssertTask(com.hazelcast.test.AssertTask) InitialMembershipListener(com.hazelcast.core.InitialMembershipListener) MembershipListener(com.hazelcast.core.MembershipListener) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Cluster (com.hazelcast.core.Cluster)17 HazelcastInstance (com.hazelcast.core.HazelcastInstance)12 Test (org.junit.Test)12 Member (com.hazelcast.core.Member)7 ParallelTest (com.hazelcast.test.annotation.ParallelTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 IAtomicReference (com.hazelcast.core.IAtomicReference)5 OnDemandJobScheduler (org.neo4j.test.OnDemandJobScheduler)5 Endpoint (com.hazelcast.core.Endpoint)3 InitialMembershipListener (com.hazelcast.core.InitialMembershipListener)3 Client (com.hazelcast.core.Client)2 ClientService (com.hazelcast.core.ClientService)2 InitialMembershipEvent (com.hazelcast.core.InitialMembershipEvent)2 MembershipListener (com.hazelcast.core.MembershipListener)2 AssertTask (com.hazelcast.test.AssertTask)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 Matchers.anyString (org.mockito.Matchers.anyString)2 JsonObject (com.eclipsesource.json.JsonObject)1 MembershipAdapter (com.hazelcast.core.MembershipAdapter)1 MembershipEvent (com.hazelcast.core.MembershipEvent)1