Search in sources :

Example 11 with Cluster

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

the class ClusterMembershipTest method testRemoveMembershipListener_whenNullListener.

@Test(expected = NullPointerException.class)
public void testRemoveMembershipListener_whenNullListener() {
    HazelcastInstance hz = createHazelcastInstance();
    Cluster cluster = hz.getCluster();
    cluster.removeMembershipListener(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 12 with Cluster

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

the class HazelcastTestSupport method checkPartitionCountGreaterOrEqualMemberCount.

private static void checkPartitionCountGreaterOrEqualMemberCount(HazelcastInstance instance) {
    Cluster cluster = instance.getCluster();
    int memberCount = cluster.getMembers().size();
    InternalPartitionService internalPartitionService = getPartitionService(instance);
    int partitionCount = internalPartitionService.getPartitionCount();
    if (partitionCount < memberCount) {
        throw new UnsupportedOperationException("Partition count should be equal or greater than member count!");
    }
}
Also used : InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Cluster(com.hazelcast.core.Cluster)

Example 13 with Cluster

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

the class HazelcastClientTest method shouldRegisterReadReplicaInTopology.

@Test
public void shouldRegisterReadReplicaInTopology() throws Throwable {
    // given
    com.hazelcast.core.Cluster cluster = mock(Cluster.class);
    Set<Member> members = asSet(makeMember(1));
    when(cluster.getMembers()).thenReturn(members);
    Endpoint endpoint = mock(Endpoint.class);
    when(endpoint.getUuid()).thenReturn("12345");
    Client client = mock(Client.class);
    final String clientId = "12345";
    when(client.getUuid()).thenReturn(clientId);
    ClientService clientService = mock(ClientService.class);
    when(clientService.getConnectedClients()).thenReturn(asSet(client));
    HazelcastMap hazelcastMap = new HazelcastMap();
    HazelcastMultiMap hazelcastMultiMap = new HazelcastMultiMap();
    HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
    when(hazelcastInstance.getAtomicReference(anyString())).thenReturn(mock(IAtomicReference.class));
    when(hazelcastInstance.getMap(anyString())).thenReturn(hazelcastMap);
    when(hazelcastInstance.getMultiMap(anyString())).thenReturn(hazelcastMultiMap);
    when(hazelcastInstance.getLocalEndpoint()).thenReturn(endpoint);
    when(hazelcastInstance.getExecutorService(anyString())).thenReturn(new StubExecutorService());
    when(hazelcastInstance.getCluster()).thenReturn(cluster);
    when(hazelcastInstance.getClientService()).thenReturn(clientService);
    HazelcastConnector connector = mock(HazelcastConnector.class);
    when(connector.connectToHazelcast()).thenReturn(hazelcastInstance);
    OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
    HazelcastClient hazelcastClient = new HazelcastClient(connector, jobScheduler, NullLogProvider.getInstance(), config(), myself);
    // when
    hazelcastClient.start();
    jobScheduler.runJob();
    // then
    assertEquals(1, hazelcastMap.size());
}
Also used : ClientService(com.hazelcast.core.ClientService) Matchers.anyString(org.mockito.Matchers.anyString) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Endpoint(com.hazelcast.core.Endpoint) IAtomicReference(com.hazelcast.core.IAtomicReference) Cluster(com.hazelcast.core.Cluster) Client(com.hazelcast.core.Client) Member(com.hazelcast.core.Member) Test(org.junit.Test)

Example 14 with Cluster

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

the class HazelcastClientTest method shouldRemoveReadReplicasOnGracefulShutdown.

@Test
public void shouldRemoveReadReplicasOnGracefulShutdown() throws Throwable {
    // given
    com.hazelcast.core.Cluster cluster = mock(Cluster.class);
    Set<Member> members = asSet(makeMember(1));
    when(cluster.getMembers()).thenReturn(members);
    Endpoint endpoint = mock(Endpoint.class);
    when(endpoint.getUuid()).thenReturn("12345");
    Client client = mock(Client.class);
    final String clientId = "12345";
    when(client.getUuid()).thenReturn(clientId);
    ClientService clientService = mock(ClientService.class);
    when(clientService.getConnectedClients()).thenReturn(asSet(client));
    HazelcastMap hazelcastMap = new HazelcastMap();
    HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
    when(hazelcastInstance.getAtomicReference(anyString())).thenReturn(mock(IAtomicReference.class));
    when(hazelcastInstance.getMap(anyString())).thenReturn(hazelcastMap);
    when(hazelcastInstance.getMultiMap(anyString())).thenReturn(new HazelcastMultiMap());
    when(hazelcastInstance.getLocalEndpoint()).thenReturn(endpoint);
    when(hazelcastInstance.getExecutorService(anyString())).thenReturn(new StubExecutorService());
    when(hazelcastInstance.getCluster()).thenReturn(cluster);
    when(hazelcastInstance.getClientService()).thenReturn(clientService);
    HazelcastConnector connector = mock(HazelcastConnector.class);
    when(connector.connectToHazelcast()).thenReturn(hazelcastInstance);
    OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
    HazelcastClient hazelcastClient = new HazelcastClient(connector, jobScheduler, NullLogProvider.getInstance(), config(), myself);
    hazelcastClient.start();
    jobScheduler.runJob();
    // when
    hazelcastClient.stop();
    // then
    assertEquals(0, hazelcastMap.size());
}
Also used : ClientService(com.hazelcast.core.ClientService) Matchers.anyString(org.mockito.Matchers.anyString) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Endpoint(com.hazelcast.core.Endpoint) IAtomicReference(com.hazelcast.core.IAtomicReference) Cluster(com.hazelcast.core.Cluster) Client(com.hazelcast.core.Client) Member(com.hazelcast.core.Member) Test(org.junit.Test)

Example 15 with Cluster

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

the class HazelcastClientTest method shouldReturnTopologyUsingHazelcastMembers.

@Test
public void shouldReturnTopologyUsingHazelcastMembers() 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());
    com.hazelcast.core.Cluster cluster = mock(Cluster.class);
    when(hazelcastInstance.getCluster()).thenReturn(cluster);
    when(hazelcastInstance.getExecutorService(anyString())).thenReturn(new StubExecutorService());
    Set<Member> members = asSet(makeMember(1), makeMember(2));
    when(cluster.getMembers()).thenReturn(members);
    // when
    client.start();
    jobScheduler.runJob();
    CoreTopology topology = client.coreServers();
    // then
    assertEquals(members.size(), topology.members().size());
}
Also used : OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IAtomicReference(com.hazelcast.core.IAtomicReference) Cluster(com.hazelcast.core.Cluster) Member(com.hazelcast.core.Member) Test(org.junit.Test)

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