Search in sources :

Example 1 with Endpoint

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

the class HazelcastClientTest method shouldSwallowNPEFromHazelcast.

@Test
public void shouldSwallowNPEFromHazelcast() throws Throwable {
    // given
    Endpoint endpoint = mock(Endpoint.class);
    when(endpoint.getUuid()).thenReturn("12345");
    HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
    when(hazelcastInstance.getLocalEndpoint()).thenReturn(endpoint);
    when(hazelcastInstance.getMap(anyString())).thenReturn(new HazelcastMap());
    when(hazelcastInstance.getMultiMap(anyString())).thenReturn(new HazelcastMultiMap());
    doThrow(new NullPointerException("boom!!!")).when(hazelcastInstance).shutdown();
    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 no NPE has been thrown
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Endpoint(com.hazelcast.core.Endpoint) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) Test(org.junit.Test)

Example 2 with Endpoint

use of com.hazelcast.core.Endpoint 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 3 with Endpoint

use of com.hazelcast.core.Endpoint 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)

Aggregations

Endpoint (com.hazelcast.core.Endpoint)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 Test (org.junit.Test)3 OnDemandJobScheduler (org.neo4j.test.OnDemandJobScheduler)3 Client (com.hazelcast.core.Client)2 ClientService (com.hazelcast.core.ClientService)2 Cluster (com.hazelcast.core.Cluster)2 IAtomicReference (com.hazelcast.core.IAtomicReference)2 Member (com.hazelcast.core.Member)2 Matchers.anyString (org.mockito.Matchers.anyString)2