Search in sources :

Example 16 with Cluster

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

the class HazelcastClientTest method shouldReturnEmptyTopologyIfUnableToConnectToHazelcast.

@Test
public void shouldReturnEmptyTopologyIfUnableToConnectToHazelcast() throws Throwable {
    // given
    HazelcastConnector connector = mock(HazelcastConnector.class);
    LogProvider logProvider = mock(LogProvider.class);
    Log log = mock(Log.class);
    when(logProvider.getLog(any(Class.class))).thenReturn(log);
    HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
    when(connector.connectToHazelcast()).thenThrow(new IllegalStateException());
    when(hazelcastInstance.getAtomicReference(anyString())).thenReturn(mock(IAtomicReference.class));
    when(hazelcastInstance.getSet(anyString())).thenReturn(new HazelcastSet());
    OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
    HazelcastClient client = new HazelcastClient(connector, jobScheduler, logProvider, config(), myself);
    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 = client.coreServers();
    assertEquals(0, topology.members().size());
}
Also used : Log(org.neo4j.logging.Log) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) NullLogProvider(org.neo4j.logging.NullLogProvider) LogProvider(org.neo4j.logging.LogProvider) 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 17 with Cluster

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

the class HazelcastUtilsTest method testGetHazelcastAddress_withClientWorker_oldHazelcastVersion.

@Test
public void testGetHazelcastAddress_withClientWorker_oldHazelcastVersion() {
    Cluster cluster = mock(Cluster.class);
    when(cluster.getLocalMember()).thenThrow(new UnsupportedOperationException("Client has no local member!"));
    hazelcastInstance = mock(HazelcastInstance.class);
    when(hazelcastInstance.getLocalEndpoint()).thenThrow(new NoSuchMethodError("expected exception"));
    when(hazelcastInstance.getCluster()).thenReturn(cluster);
    String address = getHazelcastAddress("javaclient", "172.16.16.1", hazelcastInstance);
    assertEquals("client:172.16.16.1", address);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Cluster(com.hazelcast.core.Cluster) 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