Search in sources :

Example 86 with InstanceId

use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.

the class ElectionContextTest method testElectionNotOkQuorumFailedTwoInstances.

@Test
public void testElectionNotOkQuorumFailedTwoInstances() {
    Set<InstanceId> failed = new HashSet<InstanceId>();
    failed.add(new InstanceId(2));
    Map<InstanceId, URI> members = new HashMap<InstanceId, URI>();
    members.put(new InstanceId(1), URI.create("server1"));
    members.put(new InstanceId(2), URI.create("server2"));
    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.<ElectionRole, ElectionRole>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 87 with InstanceId

use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.

the class ElectionContextTest method baseTestForElectionOk.

private void baseTestForElectionOk(Set<InstanceId> failed, boolean moreThanQuorum) {
    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"));
    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();
    assertEquals(moreThanQuorum, !toTest.electionOk());
}
Also used : HashMap(java.util.HashMap) InstanceId(org.neo4j.cluster.InstanceId) 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)

Example 88 with InstanceId

use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.

the class ElectionStateTest method electionCompletingMakesItBeForgotten.

@Test
public void electionCompletingMakesItBeForgotten() throws Throwable {
    // Given
    String coordinatorRole = "coordinator";
    InstanceId votingInstance = new InstanceId(2);
    ElectionCredentials voteCredentialComparable = mock(ElectionCredentials.class);
    ElectionContext context = mock(ElectionContext.class);
    when(context.getLog(Mockito.<Class>any())).thenReturn(NullLog.getInstance());
    when(context.getNeededVoteCount()).thenReturn(3);
    when(context.getVoteCount(coordinatorRole)).thenReturn(3);
    when(context.voted(coordinatorRole, votingInstance, voteCredentialComparable, 4)).thenReturn(true);
    MessageHolder holder = mock(MessageHolder.class);
    Message vote = Message.to(ElectionMessage.voted, URI.create("cluster://elector"), new ElectionMessage.VersionedVotedData(coordinatorRole, votingInstance, voteCredentialComparable, 4));
    // When
    election.handle(context, vote, holder);
    // Then
    verify(context, times(1)).forgetElection(coordinatorRole);
}
Also used : MessageHolder(org.neo4j.cluster.com.message.MessageHolder) AtomicBroadcastMessage(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AtomicBroadcastMessage) Message(org.neo4j.cluster.com.message.Message) ClusterMessage(org.neo4j.cluster.protocol.cluster.ClusterMessage) InstanceId(org.neo4j.cluster.InstanceId) Test(org.junit.Test)

Example 89 with InstanceId

use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.

the class ClusterContextTest method testElectionVersionIsResetWhenElectorChangesFromOtherToMe.

@Test
public void testElectionVersionIsResetWhenElectorChangesFromOtherToMe() throws Exception {
    final String coordinatorRole = "coordinator";
    final InstanceId me = new InstanceId(1);
    final InstanceId winner = new InstanceId(2);
    final InstanceId elector = new InstanceId(2);
    HeartbeatContext heartbeatContext = mock(HeartbeatContext.class);
    when(heartbeatContext.getFailed()).thenReturn(Collections.<InstanceId>emptySet());
    Config config = mock(Config.class);
    when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
    MultiPaxosContext multiPaxosContext = new MultiPaxosContext(me, Iterables.iterable(new ElectionRole(coordinatorRole)), mock(ClusterConfiguration.class), new Executor() {

        @Override
        public void execute(Runnable command) {
            command.run();
        }
    }, NullLogProvider.getInstance(), mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(AcceptorInstanceStore.class), mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config);
    ClusterContext context = multiPaxosContext.getClusterContext();
    ElectionContext electionContext = multiPaxosContext.getElectionContext();
    ClusterListener listener = mock(ClusterListener.class);
    context.setLastElectorVersion(5);
    context.setLastElector(elector);
    context.addClusterListener(listener);
    context.elected(coordinatorRole, winner, elector, 6);
    verify(listener, times(1)).elected(coordinatorRole, winner, null);
    electionContext.forgetElection(coordinatorRole);
    long expectedVersion = electionContext.newConfigurationStateChange().getVersion();
    context.elected(coordinatorRole, winner, me, expectedVersion);
    verify(listener, times(2)).elected(coordinatorRole, winner, null);
}
Also used : ElectionContext(org.neo4j.cluster.protocol.election.ElectionContext) InstanceId(org.neo4j.cluster.InstanceId) Config(org.neo4j.kernel.configuration.Config) Timeouts(org.neo4j.cluster.timeout.Timeouts) ElectionRole(org.neo4j.cluster.protocol.election.ElectionRole) Executor(java.util.concurrent.Executor) ElectionCredentialsProvider(org.neo4j.cluster.protocol.election.ElectionCredentialsProvider) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) HeartbeatContext(org.neo4j.cluster.protocol.heartbeat.HeartbeatContext) ObjectInputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory) ObjectOutputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory) AcceptorInstanceStore(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore) Test(org.junit.Test)

Example 90 with InstanceId

use of org.neo4j.cluster.InstanceId in project neo4j by neo4j.

the class ClusterContextTest method testElectionVersionIsUpdatedOnElectionFromSelfAndProperlyIgnoredIfOld.

@Test
public void testElectionVersionIsUpdatedOnElectionFromSelfAndProperlyIgnoredIfOld() throws Exception {
    final String coordinatorRole = "coordinator";
    final InstanceId me = new InstanceId(1);
    final InstanceId winner = new InstanceId(2);
    HeartbeatContext heartbeatContext = mock(HeartbeatContext.class);
    when(heartbeatContext.getFailed()).thenReturn(Collections.<InstanceId>emptySet());
    Config config = mock(Config.class);
    when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
    MultiPaxosContext multiPaxosContext = new MultiPaxosContext(me, Iterables.<ElectionRole, ElectionRole>iterable(new ElectionRole(coordinatorRole)), mock(ClusterConfiguration.class), new Executor() {

        @Override
        public void execute(Runnable command) {
            command.run();
        }
    }, NullLogProvider.getInstance(), mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(AcceptorInstanceStore.class), mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config);
    ClusterContext context = multiPaxosContext.getClusterContext();
    ElectionContext electionContext = multiPaxosContext.getElectionContext();
    ClusterListener listener = mock(ClusterListener.class);
    context.addClusterListener(listener);
    electionContext.forgetElection(coordinatorRole);
    long expectedVersion = electionContext.newConfigurationStateChange().getVersion();
    context.elected(coordinatorRole, winner, me, expectedVersion);
    assertEquals(1, expectedVersion);
    verify(listener, times(1)).elected(coordinatorRole, winner, null);
    electionContext.forgetElection(coordinatorRole);
    expectedVersion = electionContext.newConfigurationStateChange().getVersion();
    context.elected(coordinatorRole, winner, me, expectedVersion);
    assertEquals(2, expectedVersion);
    verify(listener, times(2)).elected(coordinatorRole, winner, null);
    context.elected(coordinatorRole, winner, me, expectedVersion - 1);
    verifyNoMoreInteractions(listener);
}
Also used : ElectionContext(org.neo4j.cluster.protocol.election.ElectionContext) InstanceId(org.neo4j.cluster.InstanceId) Config(org.neo4j.kernel.configuration.Config) Timeouts(org.neo4j.cluster.timeout.Timeouts) ElectionRole(org.neo4j.cluster.protocol.election.ElectionRole) Executor(java.util.concurrent.Executor) ElectionCredentialsProvider(org.neo4j.cluster.protocol.election.ElectionCredentialsProvider) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) HeartbeatContext(org.neo4j.cluster.protocol.heartbeat.HeartbeatContext) ObjectInputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory) ObjectOutputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory) AcceptorInstanceStore(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore) Test(org.junit.Test)

Aggregations

InstanceId (org.neo4j.cluster.InstanceId)154 Test (org.junit.Test)129 URI (java.net.URI)47 Config (org.neo4j.kernel.configuration.Config)37 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)36 Timeouts (org.neo4j.cluster.timeout.Timeouts)32 Executor (java.util.concurrent.Executor)28 ClusterContext (org.neo4j.cluster.protocol.cluster.ClusterContext)28 ObjectInputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory)27 ObjectOutputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory)27 HeartbeatContext (org.neo4j.cluster.protocol.heartbeat.HeartbeatContext)27 MultiPaxosContext (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext)24 AcceptorInstanceStore (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore)18 MessageHolder (org.neo4j.cluster.com.message.MessageHolder)16 Message (org.neo4j.cluster.com.message.Message)15 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)13 ClusterMemberAvailability (org.neo4j.cluster.member.ClusterMemberAvailability)13 ClusterMemberEvents (org.neo4j.cluster.member.ClusterMemberEvents)12 ClusterMemberListener (org.neo4j.cluster.member.ClusterMemberListener)12