Search in sources :

Example 16 with OnDemandJobScheduler

use of org.neo4j.test.OnDemandJobScheduler in project neo4j by neo4j.

the class MembershipWaiterTest method shouldTimeoutIfMemberButNotCaughtUp.

@Test
public void shouldTimeoutIfMemberButNotCaughtUp() throws Exception {
    OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
    MembershipWaiter waiter = new MembershipWaiter(member(0), jobScheduler, () -> dbHealth, 1, NullLogProvider.getInstance());
    ExposedRaftState raftState = RaftStateBuilder.raftState().votingMembers(member(0), member(1)).leaderCommit(0).build().copy();
    RaftMachine raft = mock(RaftMachine.class);
    when(raft.state()).thenReturn(raftState);
    CompletableFuture<Boolean> future = waiter.waitUntilCaughtUpMember(raft);
    jobScheduler.runJob();
    jobScheduler.runJob();
    try {
        future.get(10, MILLISECONDS);
        fail("Should have timed out.");
    } catch (TimeoutException e) {
    // expected
    }
}
Also used : RaftMachine(org.neo4j.causalclustering.core.consensus.RaftMachine) ExposedRaftState(org.neo4j.causalclustering.core.consensus.state.ExposedRaftState) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 17 with OnDemandJobScheduler

use of org.neo4j.test.OnDemandJobScheduler 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 18 with OnDemandJobScheduler

use of org.neo4j.test.OnDemandJobScheduler 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 19 with OnDemandJobScheduler

use of org.neo4j.test.OnDemandJobScheduler 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)

Example 20 with OnDemandJobScheduler

use of org.neo4j.test.OnDemandJobScheduler 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)

Aggregations

OnDemandJobScheduler (org.neo4j.test.OnDemandJobScheduler)20 Test (org.junit.Test)12 LogProvider (org.neo4j.logging.LogProvider)9 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 File (java.io.File)6 DummyRaftableContentSerializer (org.neo4j.causalclustering.core.consensus.log.DummyRaftableContentSerializer)6 Cluster (com.hazelcast.core.Cluster)5 IAtomicReference (com.hazelcast.core.IAtomicReference)5 Member (com.hazelcast.core.Member)5 RaftMachine (org.neo4j.causalclustering.core.consensus.RaftMachine)5 ExposedRaftState (org.neo4j.causalclustering.core.consensus.state.ExposedRaftState)5 Endpoint (com.hazelcast.core.Endpoint)4 TimeoutException (java.util.concurrent.TimeoutException)3 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)3 Client (com.hazelcast.core.Client)2 ClientService (com.hazelcast.core.ClientService)2 Matchers.anyString (org.mockito.Matchers.anyString)2 InMemoryRaftLog (org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog)2 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)2 CoreReplicatedContentMarshal (org.neo4j.causalclustering.messaging.CoreReplicatedContentMarshal)2