Search in sources :

Example 96 with InstanceId

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

the class ClusterContextImplTest method shouldGracefullyHandleEmptyDiscoveryHeader.

@Test
public void shouldGracefullyHandleEmptyDiscoveryHeader() throws Exception {
    // Given
    InstanceId me = new InstanceId(1);
    InstanceId joining = new InstanceId(2);
    CommonContextState commonContextState = mock(CommonContextState.class, RETURNS_MOCKS);
    Timeouts timeouts = mock(Timeouts.class);
    Executor executor = mock(Executor.class);
    HeartbeatContext heartbeatContext = mock(HeartbeatContext.class);
    ClusterContext context = new ClusterContextImpl(me, commonContextState, NullLogProvider.getInstance(), timeouts, executor, mock(ObjectOutputStreamFactory.class), mock(ObjectInputStreamFactory.class), mock(LearnerContext.class), heartbeatContext, mock(Config.class));
    ClusterMessage.ConfigurationRequestState request = mock(ClusterMessage.ConfigurationRequestState.class);
    when(request.getJoiningId()).thenReturn(joining);
    // When
    // Instance 2 contacts us with a request but it is empty
    context.addContactingInstance(request, "");
    // Then
    // The discovery header we generate should still contain that instance
    assertEquals("2", context.generateDiscoveryHeader());
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) Timeouts(org.neo4j.cluster.timeout.Timeouts) Config(org.neo4j.kernel.configuration.Config) ClusterContext(org.neo4j.cluster.protocol.cluster.ClusterContext) LearnerContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.LearnerContext) Executor(java.util.concurrent.Executor) HeartbeatContext(org.neo4j.cluster.protocol.heartbeat.HeartbeatContext) ObjectInputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory) ObjectOutputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory) ClusterMessage(org.neo4j.cluster.protocol.cluster.ClusterMessage) Test(org.junit.Test)

Example 97 with InstanceId

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

the class ClusterContextImplTest method nonElectorFailingMustNotCauseElectorVersionToBeReset.

/*
     * This test ensures that an instance that is marked as failed has its elector version reset. This means that
     * the instance, once it comes back, will still be able to do elections even if it lost state
     */
@Test
public void nonElectorFailingMustNotCauseElectorVersionToBeReset() throws Exception {
    // Given
    InstanceId me = new InstanceId(1);
    InstanceId elector = new InstanceId(2);
    CommonContextState commonContextState = mock(CommonContextState.class, RETURNS_MOCKS);
    Timeouts timeouts = mock(Timeouts.class);
    Executor executor = mock(Executor.class);
    HeartbeatContext heartbeatContext = mock(HeartbeatContext.class);
    ArgumentCaptor<HeartbeatListener> listenerCaptor = ArgumentCaptor.forClass(HeartbeatListener.class);
    ClusterContext context = new ClusterContextImpl(me, commonContextState, NullLogProvider.getInstance(), timeouts, executor, mock(ObjectOutputStreamFactory.class), mock(ObjectInputStreamFactory.class), mock(LearnerContext.class), heartbeatContext, mock(Config.class));
    verify(heartbeatContext).addHeartbeatListener(listenerCaptor.capture());
    HeartbeatListener theListener = listenerCaptor.getValue();
    // This means instance 2 was the elector at version 8
    context.setLastElector(elector);
    context.setLastElectorVersion(8);
    // When
    theListener.failed(new InstanceId(3));
    // Then
    assertEquals(context.getLastElector(), elector);
    assertEquals(context.getLastElectorVersion(), 8);
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) Timeouts(org.neo4j.cluster.timeout.Timeouts) Config(org.neo4j.kernel.configuration.Config) ClusterContext(org.neo4j.cluster.protocol.cluster.ClusterContext) LearnerContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.LearnerContext) HeartbeatListener(org.neo4j.cluster.protocol.heartbeat.HeartbeatListener) Executor(java.util.concurrent.Executor) HeartbeatContext(org.neo4j.cluster.protocol.heartbeat.HeartbeatContext) ObjectInputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory) ObjectOutputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory) Test(org.junit.Test)

Example 98 with InstanceId

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

the class HeartbeatContextImplTest method shouldFailAndAliveBothNotifyHeartbeatListenerInDelayedDirectExecutor.

@Test
public void shouldFailAndAliveBothNotifyHeartbeatListenerInDelayedDirectExecutor() throws Throwable {
    // Given
    InstanceId me = new InstanceId(1);
    InstanceId failedMachine = new InstanceId(2);
    InstanceId goodMachine = new InstanceId(3);
    Timeouts timeouts = mock(Timeouts.class);
    CommonContextState commonState = mock(CommonContextState.class);
    ClusterConfiguration configuration = mock(ClusterConfiguration.class);
    when(commonState.configuration()).thenReturn(configuration);
    when(configuration.getMembers()).thenReturn(members(3));
    when(configuration.getMemberIds()).thenReturn(ids(3));
    final List<Runnable> runnables = new ArrayList<>();
    HeartbeatContext context = new HeartbeatContextImpl(me, commonState, NullLogProvider.getInstance(), timeouts, new DelayedDirectExecutor(NullLogProvider.getInstance()) {

        @Override
        public synchronized void execute(Runnable command) {
            runnables.add(command);
        }
    });
    context.addHeartbeatListener(mock(HeartbeatListener.class));
    context.suspicions(goodMachine, new HashSet<>(singletonList(failedMachine)));
    // fail
    context.suspect(failedMachine);
    // alive
    context.alive(failedMachine);
    // Then
    // fail + alive
    assertEquals(2, runnables.size());
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) Timeouts(org.neo4j.cluster.timeout.Timeouts) ArrayList(java.util.ArrayList) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) DelayedDirectExecutor(org.neo4j.cluster.DelayedDirectExecutor) HeartbeatListener(org.neo4j.cluster.protocol.heartbeat.HeartbeatListener) HeartbeatContext(org.neo4j.cluster.protocol.heartbeat.HeartbeatContext) Test(org.junit.Test)

Example 99 with InstanceId

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

the class ProposerContextImplTest method limitedAcceptors.

private int limitedAcceptors(int maxAcceptors, List<InstanceId> alive) {
    CommonContextState commonContextState = new CommonContextState(null, maxAcceptors);
    HeartbeatContext heartbeatContext = mock(HeartbeatContext.class);
    when(heartbeatContext.getAlive()).thenReturn(alive);
    // when
    ProposerContextImpl proposerContext = new ProposerContextImpl(new InstanceId(1), commonContextState, null, null, null, heartbeatContext);
    return proposerContext.getAcceptors().size();
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) HeartbeatContext(org.neo4j.cluster.protocol.heartbeat.HeartbeatContext)

Example 100 with InstanceId

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

the class ProposerContextImplTest method shouldCalculateMajorityOfAcceptors.

@Test
public void shouldCalculateMajorityOfAcceptors() throws Exception {
    ProposerContextImpl proposerContext = new ProposerContextImpl(new InstanceId(1), null, null, null, null, null);
    assertEquals(1, proposerContext.getMinimumQuorumSize(acceptorUris(1)));
    assertEquals(2, proposerContext.getMinimumQuorumSize(acceptorUris(2)));
    assertEquals(2, proposerContext.getMinimumQuorumSize(acceptorUris(3)));
    assertEquals(3, proposerContext.getMinimumQuorumSize(acceptorUris(4)));
    assertEquals(3, proposerContext.getMinimumQuorumSize(acceptorUris(5)));
    assertEquals(4, proposerContext.getMinimumQuorumSize(acceptorUris(6)));
    assertEquals(4, proposerContext.getMinimumQuorumSize(acceptorUris(7)));
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) 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