Search in sources :

Example 11 with ClusterContext

use of org.neo4j.cluster.protocol.cluster.ClusterContext in project neo4j by neo4j.

the class ElectionContextTest method testElectionNotOkQuorumFailedFourInstances.

@Test
public void testElectionNotOkQuorumFailedFourInstances() {
    Set<InstanceId> failed = new HashSet<InstanceId>();
    failed.add(new InstanceId(2));
    failed.add(new InstanceId(3));
    Map<InstanceId, URI> members = new HashMap<InstanceId, URI>();
    members.put(new InstanceId(1), URI.create("server1"));
    members.put(new InstanceId(2), URI.create("server2"));
    members.put(new InstanceId(3), URI.create("server3"));
    members.put(new InstanceId(4), URI.create("server4"));
    Config config = mock(Config.class);
    when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
    ClusterConfiguration clusterConfiguration = mock(ClusterConfiguration.class);
    when(clusterConfiguration.getMembers()).thenReturn(members);
    ClusterContext clusterContext = mock(ClusterContext.class);
    when(clusterContext.getConfiguration()).thenReturn(clusterConfiguration);
    MultiPaxosContext context = new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole("coordinator")), clusterConfiguration, mock(Executor.class), NullLogProvider.getInstance(), mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(AcceptorInstanceStore.class), mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config);
    context.getHeartbeatContext().getFailed().addAll(failed);
    ElectionContext toTest = context.getElectionContext();
    assertFalse(toTest.electionOk());
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) HashMap(java.util.HashMap) Config(org.neo4j.kernel.configuration.Config) Timeouts(org.neo4j.cluster.timeout.Timeouts) ClusterContext(org.neo4j.cluster.protocol.cluster.ClusterContext) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) URI(java.net.URI) Executor(java.util.concurrent.Executor) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) ObjectInputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory) ObjectOutputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory) AcceptorInstanceStore(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with ClusterContext

use of org.neo4j.cluster.protocol.cluster.ClusterContext in project neo4j by neo4j.

the class ElectionContextTest method testElectionNotOkQuorumFailedFiveInstances.

@Test
public void testElectionNotOkQuorumFailedFiveInstances() {
    Set<InstanceId> failed = new HashSet<InstanceId>();
    failed.add(new InstanceId(2));
    failed.add(new InstanceId(3));
    failed.add(new InstanceId(4));
    Map<InstanceId, URI> members = new HashMap<InstanceId, URI>();
    members.put(new InstanceId(1), URI.create("server1"));
    members.put(new InstanceId(2), URI.create("server2"));
    members.put(new InstanceId(3), URI.create("server3"));
    members.put(new InstanceId(4), URI.create("server4"));
    members.put(new InstanceId(5), URI.create("server5"));
    Config config = mock(Config.class);
    when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
    ClusterConfiguration clusterConfiguration = mock(ClusterConfiguration.class);
    when(clusterConfiguration.getMembers()).thenReturn(members);
    ClusterContext clusterContext = mock(ClusterContext.class);
    when(clusterContext.getConfiguration()).thenReturn(clusterConfiguration);
    MultiPaxosContext context = new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole("coordinator")), clusterConfiguration, mock(Executor.class), NullLogProvider.getInstance(), mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(AcceptorInstanceStore.class), mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config);
    context.getHeartbeatContext().getFailed().addAll(failed);
    ElectionContext toTest = context.getElectionContext();
    assertFalse(toTest.electionOk());
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) HashMap(java.util.HashMap) Config(org.neo4j.kernel.configuration.Config) Timeouts(org.neo4j.cluster.timeout.Timeouts) ClusterContext(org.neo4j.cluster.protocol.cluster.ClusterContext) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) URI(java.net.URI) Executor(java.util.concurrent.Executor) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) ObjectInputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory) ObjectOutputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory) AcceptorInstanceStore(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with ClusterContext

use of org.neo4j.cluster.protocol.cluster.ClusterContext in project neo4j by neo4j.

the class ElectionStateTest method testElectionRequestIsRejectedIfNoQuorum.

@Test
public void testElectionRequestIsRejectedIfNoQuorum() throws Throwable {
    ElectionContext context = mock(ElectionContext.class);
    ClusterContext clusterContextMock = mock(ClusterContext.class);
    when(context.getLog(Matchers.<Class>any())).thenReturn(NullLog.getInstance());
    when(context.electionOk()).thenReturn(false);
    when(clusterContextMock.getLog(Matchers.<Class>any())).thenReturn(NullLog.getInstance());
    MessageHolder holder = mock(MessageHolder.class);
    election.handle(context, Message.<ElectionMessage>internal(performRoleElections), holder);
    verifyZeroInteractions(holder);
}
Also used : MessageHolder(org.neo4j.cluster.com.message.MessageHolder) ClusterContext(org.neo4j.cluster.protocol.cluster.ClusterContext) Test(org.junit.Test)

Example 14 with ClusterContext

use of org.neo4j.cluster.protocol.cluster.ClusterContext in project neo4j by neo4j.

the class DefaultWinnerStrategyTest method shouldNotPickAWinnerIfAllVotesAreForIneligibleCandidates.

@Test
public void shouldNotPickAWinnerIfAllVotesAreForIneligibleCandidates() {
    // given
    InstanceId instanceOne = new InstanceId(1);
    InstanceId instanceTwo = new InstanceId(2);
    ClusterContext clusterContext = mock(ClusterContext.class);
    final Log log = mock(Log.class);
    LogProvider logProvider = new LogProvider() {

        @Override
        public Log getLog(Class loggingClass) {
            return log;
        }

        @Override
        public Log getLog(String name) {
            return log;
        }
    };
    when(clusterContext.getLog(DefaultWinnerStrategy.class)).thenReturn(logProvider.getLog(DefaultWinnerStrategy.class));
    // when
    Collection<Vote> votes = Arrays.asList(new Vote(instanceOne, new NotElectableElectionCredentials()), new Vote(instanceTwo, new NotElectableElectionCredentials()));
    DefaultWinnerStrategy strategy = new DefaultWinnerStrategy(clusterContext);
    org.neo4j.cluster.InstanceId winner = strategy.pickWinner(votes);
    // then
    assertNull(winner);
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) InstanceId(org.neo4j.cluster.InstanceId) Log(org.neo4j.logging.Log) ClusterContext(org.neo4j.cluster.protocol.cluster.ClusterContext) LogProvider(org.neo4j.logging.LogProvider) NotElectableElectionCredentials(org.neo4j.cluster.protocol.election.NotElectableElectionCredentials) Test(org.junit.Test)

Example 15 with ClusterContext

use of org.neo4j.cluster.protocol.cluster.ClusterContext in project neo4j by neo4j.

the class SnapshotStateTest method baseNoSendTest.

public void baseNoSendTest(Map<InstanceId, URI> extraMembers) throws Throwable {
    URI me = URI.create("cluster://me");
    Map<InstanceId, URI> members = new HashMap<InstanceId, URI>();
    final InstanceId myId = new InstanceId(1);
    members.put(myId, me);
    members.putAll(extraMembers);
    ClusterConfiguration clusterConfiguration = mock(ClusterConfiguration.class);
    when(clusterConfiguration.getMembers()).thenReturn(members);
    when(clusterConfiguration.getElected(ClusterConfiguration.COORDINATOR)).thenReturn(myId);
    when(clusterConfiguration.getUriForId(myId)).thenReturn(me);
    ClusterContext clusterContext = mock(ClusterContext.class);
    when(clusterContext.getConfiguration()).thenReturn(clusterConfiguration);
    when(clusterContext.getMyId()).thenReturn(myId);
    SnapshotContext context = mock(SnapshotContext.class);
    when(context.getClusterContext()).thenReturn(clusterContext);
    when(context.getSnapshotProvider()).thenReturn(mock(SnapshotProvider.class));
    Message<SnapshotMessage> message = Message.to(SnapshotMessage.refreshSnapshot, me);
    MessageHolder outgoing = mock(MessageHolder.class);
    SnapshotState newState = (SnapshotState) SnapshotState.ready.handle(context, message, outgoing);
    assertThat(newState, equalTo(SnapshotState.ready));
    Mockito.verifyZeroInteractions(outgoing);
}
Also used : MessageHolder(org.neo4j.cluster.com.message.MessageHolder) HashMap(java.util.HashMap) InstanceId(org.neo4j.cluster.InstanceId) ClusterContext(org.neo4j.cluster.protocol.cluster.ClusterContext) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) URI(java.net.URI)

Aggregations

ClusterContext (org.neo4j.cluster.protocol.cluster.ClusterContext)30 Test (org.junit.Test)27 InstanceId (org.neo4j.cluster.InstanceId)27 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)17 Executor (java.util.concurrent.Executor)16 ObjectInputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory)16 ObjectOutputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory)16 Timeouts (org.neo4j.cluster.timeout.Timeouts)16 Config (org.neo4j.kernel.configuration.Config)16 URI (java.net.URI)13 HeartbeatContext (org.neo4j.cluster.protocol.heartbeat.HeartbeatContext)13 MessageHolder (org.neo4j.cluster.com.message.MessageHolder)10 LearnerContext (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.LearnerContext)9 HashMap (java.util.HashMap)7 AcceptorInstanceStore (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore)7 MultiPaxosContext (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext)7 Message (org.neo4j.cluster.com.message.Message)6 LinkedList (java.util.LinkedList)4 MessageType (org.neo4j.cluster.com.message.MessageType)4 HashSet (java.util.HashSet)3