Search in sources :

Example 1 with Cluster

use of com.hazelcast.core.Cluster in project neo4j by neo4j.

the class HazelcastClientTest method shouldNotReconnectWhileHazelcastRemainsAvailable.

@Test
public void shouldNotReconnectWhileHazelcastRemainsAvailable() throws Throwable {
    // given
    HazelcastConnector connector = mock(HazelcastConnector.class);
    OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
    HazelcastClient client = new HazelcastClient(connector, jobScheduler, NullLogProvider.getInstance(), config(), myself);
    HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
    when(connector.connectToHazelcast()).thenReturn(hazelcastInstance);
    when(hazelcastInstance.getAtomicReference(anyString())).thenReturn(mock(IAtomicReference.class));
    when(hazelcastInstance.getSet(anyString())).thenReturn(new HazelcastSet());
    when(hazelcastInstance.getMultiMap(anyString())).thenReturn(new HazelcastMultiMap());
    when(hazelcastInstance.getExecutorService(anyString())).thenReturn(new StubExecutorService());
    com.hazelcast.core.Cluster cluster = mock(Cluster.class);
    when(hazelcastInstance.getCluster()).thenReturn(cluster);
    Set<Member> members = asSet(makeMember(1), makeMember(2));
    when(cluster.getMembers()).thenReturn(members);
    // when
    client.start();
    jobScheduler.runJob();
    CoreTopology topology;
    for (int i = 0; i < 5; i++) {
        topology = client.coreServers();
        assertEquals(members.size(), topology.members().size());
    }
    // then
    verify(connector, times(1)).connectToHazelcast();
}
Also used : OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) Endpoint(com.hazelcast.core.Endpoint) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IAtomicReference(com.hazelcast.core.IAtomicReference) Cluster(com.hazelcast.core.Cluster) Member(com.hazelcast.core.Member) Test(org.junit.Test)

Example 2 with Cluster

use of com.hazelcast.core.Cluster in project hazelcast by hazelcast.

the class ChangeClusterStateRequest method writeResponse.

@Override
public void writeResponse(ManagementCenterService mcs, JsonObject out) throws Exception {
    String resultString = "SUCCESS";
    try {
        Cluster cluster = mcs.getHazelcastInstance().getCluster();
        cluster.changeClusterState(getClusterState(state));
    } catch (Exception e) {
        ILogger logger = mcs.getHazelcastInstance().node.nodeEngine.getLogger(getClass());
        logger.warning("Cluster state can not be changed: ", e);
        resultString = FAILURE + e.getMessage();
    }
    JsonObject result = new JsonObject().add("result", resultString);
    out.add("result", result);
}
Also used : Cluster(com.hazelcast.core.Cluster) JsonObject(com.eclipsesource.json.JsonObject) ILogger(com.hazelcast.logging.ILogger) JsonUtil.getString(com.hazelcast.util.JsonUtil.getString) IOException(java.io.IOException)

Example 3 with Cluster

use of com.hazelcast.core.Cluster in project hazelcast by hazelcast.

the class ClusterMembershipTest method testRemoveMembershipListener.

@Test
public void testRemoveMembershipListener() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance hz1 = factory.newHazelcastInstance();
    Cluster cluster = hz1.getCluster();
    MembershipListener membershipListener = mock(MembershipListener.class);
    String id = cluster.addMembershipListener(membershipListener);
    boolean removed = cluster.removeMembershipListener(id);
    assertTrue(removed);
    // now we add a member
    HazelcastInstance hz2 = factory.newHazelcastInstance();
    // and verify that the listener isn't called.
    verify(membershipListener, never()).memberAdded(any(MembershipEvent.class));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) InitialMembershipEvent(com.hazelcast.core.InitialMembershipEvent) MembershipEvent(com.hazelcast.core.MembershipEvent) Cluster(com.hazelcast.core.Cluster) 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)

Example 4 with Cluster

use of com.hazelcast.core.Cluster in project hazelcast by hazelcast.

the class ClusterMembershipTest method testRemoveMembershipListener_whenNonExistingRegistrationId.

@Test
public void testRemoveMembershipListener_whenNonExistingRegistrationId() {
    HazelcastInstance hz = createHazelcastInstance();
    Cluster cluster = hz.getCluster();
    boolean result = cluster.removeMembershipListener("notexist");
    assertFalse(result);
}
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 5 with Cluster

use of com.hazelcast.core.Cluster in project hazelcast by hazelcast.

the class ClientClusterProxyTest method removeMembershipListener.

@Test
public void removeMembershipListener() throws Exception {
    Cluster cluster = client().getCluster();
    String regId = cluster.addMembershipListener(new MembershipAdapter());
    assertTrue(cluster.removeMembershipListener(regId));
}
Also used : MembershipAdapter(com.hazelcast.core.MembershipAdapter) Cluster(com.hazelcast.core.Cluster) 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