Search in sources :

Example 91 with InstanceId

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

the class ClusterMockTest method verifyConfigurations.

public void verifyConfigurations(String description) {
    logger.getLogger().fine("Verify configurations");
    List<URI> members = null;
    Map<String, InstanceId> roles = null;
    Set<InstanceId> failed = null;
    List<AssertionError> errors = new LinkedList<AssertionError>();
    List<TestProtocolServer> protocolServers = network.getServers();
    for (int j = 0; j < protocolServers.size(); j++) {
        StateMachines stateMachines = protocolServers.get(j).getServer().getStateMachines();
        State<?, ?> clusterState = stateMachines.getStateMachine(ClusterMessage.class).getState();
        if (!clusterState.equals(ClusterState.entered)) {
            logger.getLogger().fine("Instance " + (j + 1) + " is not in the cluster (" + clusterState + ")");
            continue;
        }
        ClusterContext context = (ClusterContext) stateMachines.getStateMachine(ClusterMessage.class).getContext();
        HeartbeatContext heartbeatContext = (HeartbeatContext) stateMachines.getStateMachine(HeartbeatMessage.class).getContext();
        ClusterConfiguration clusterConfiguration = context.getConfiguration();
        if (!clusterConfiguration.getMemberURIs().isEmpty()) {
            logger.getLogger().fine("   Server " + (j + 1) + ": Cluster:" + clusterConfiguration.getMemberURIs() + ", Roles:" + clusterConfiguration.getRoles() + ", Failed:" + heartbeatContext.getFailed());
            if (members == null) {
                members = clusterConfiguration.getMemberURIs();
                roles = clusterConfiguration.getRoles();
                failed = heartbeatContext.getFailed();
            } else {
                verifyConfigurations(stateMachines, members, roles, failed, errors);
            }
        }
    }
    assertEquals(description + ": In:" + in + ", Out:" + out, protocolServers.size(), Iterables.count(Iterables.<Cluster, List<Cluster>>flatten(in, out)));
    if (!errors.isEmpty()) {
        for (AssertionError error : errors) {
            logger.getLogger().severe(error.toString());
        }
        throw errors.get(0);
    }
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) StateMachines(org.neo4j.cluster.StateMachines) URI(java.net.URI) LinkedList(java.util.LinkedList) TestProtocolServer(org.neo4j.cluster.TestProtocolServer) HeartbeatContext(org.neo4j.cluster.protocol.heartbeat.HeartbeatContext) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 92 with InstanceId

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

the class ClusterStateTest method joinDeniedResponseShouldContainRespondersConfiguration.

@Test
public void joinDeniedResponseShouldContainRespondersConfiguration() throws Throwable {
    // GIVEN
    ClusterContext context = mock(ClusterContext.class);
    Map<InstanceId, URI> existingMembers = members(1, 2);
    when(context.isCurrentlyAlive(any(InstanceId.class))).thenReturn(true);
    when(context.getMembers()).thenReturn(existingMembers);
    when(context.getConfiguration()).thenReturn(clusterConfiguration(existingMembers));
    when(context.getLog(any(Class.class))).thenReturn(NullLog.getInstance());
    TrackingMessageHolder outgoing = new TrackingMessageHolder();
    Message<ClusterMessage> message = to(configurationRequest, uri(1), configuration(2)).setHeader(Message.FROM, uri(2).toString());
    // WHEN an instance responds to a join request, responding that the joining instance cannot join
    ClusterState.entered.handle(context, message, outgoing);
    // THEN assert that the responding instance sends its configuration along with the response
    Message<ClusterMessage> response = outgoing.single();
    assertTrue(response.getPayload() instanceof ConfigurationResponseState);
    ConfigurationResponseState responseState = response.getPayload();
    assertEquals(existingMembers, responseState.getMembers());
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) TrackingMessageHolder(org.neo4j.cluster.com.message.TrackingMessageHolder) URI(java.net.URI) ConfigurationResponseState(org.neo4j.cluster.protocol.cluster.ClusterMessage.ConfigurationResponseState) Test(org.junit.Test)

Example 93 with InstanceId

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

the class ClusterStateTest method shouldNotDenyJoinToInstanceThatRejoinsBeforeTimingOut.

@Test
public void shouldNotDenyJoinToInstanceThatRejoinsBeforeTimingOut() throws Throwable {
    // GIVEN
    ClusterContext context = mock(ClusterContext.class);
    Map<InstanceId, URI> existingMembers = members(1, 2);
    when(context.isCurrentlyAlive(id(2))).thenReturn(true);
    when(context.getMembers()).thenReturn(existingMembers);
    when(context.getConfiguration()).thenReturn(clusterConfiguration(existingMembers));
    when(context.getLog(any(Class.class))).thenReturn(NullLog.getInstance());
    when(context.getUriForId(id(2))).thenReturn(uri(2));
    TrackingMessageHolder outgoing = new TrackingMessageHolder();
    Message<ClusterMessage> message = to(configurationRequest, uri(1), configuration(2)).setHeader(Message.FROM, uri(2).toString());
    // WHEN the join denial actually takes effect (signaled by a join timeout locally)
    ClusterState.entered.handle(context, message, outgoing);
    // THEN assert that the failure contains the received configuration
    Message<? extends MessageType> response = outgoing.single();
    assertEquals(ClusterMessage.configurationResponse, response.getMessageType());
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) TrackingMessageHolder(org.neo4j.cluster.com.message.TrackingMessageHolder) URI(java.net.URI) Test(org.junit.Test)

Example 94 with InstanceId

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

the class ClusterContextImplTest method instanceEnteringTheClusterMustBeRemovedAsElector.

/*
     * This test ensures that an instance that enters the cluster has its elector version reset. That means that
     * if it was the elector before its version is now reset so results can be applied. This and the previous tests
     * actually perform the same things at different events, one covering for the other.
     */
@Test
public void instanceEnteringTheClusterMustBeRemovedAsElector() throws Exception {
    // Given
    InstanceId me = new InstanceId(1);
    InstanceId elector = new InstanceId(2);
    CommonContextState commonContextState = mock(CommonContextState.class, RETURNS_MOCKS);
    ClusterContext context = new ClusterContextImpl(me, commonContextState, NullLogProvider.getInstance(), mock(Timeouts.class), mock(Executor.class), mock(ObjectOutputStreamFactory.class), mock(ObjectInputStreamFactory.class), mock(LearnerContext.class), mock(HeartbeatContext.class), mock(Config.class));
    // This means instance 2 was the elector at version 8
    context.setLastElector(elector);
    context.setLastElectorVersion(8);
    // When
    context.joined(elector, URI.create("cluster://elector"));
    // Then
    assertEquals(context.getLastElector(), InstanceId.NONE);
    assertEquals(context.getLastElectorVersion(), -1);
}
Also used : Executor(java.util.concurrent.Executor) InstanceId(org.neo4j.cluster.InstanceId) Timeouts(org.neo4j.cluster.timeout.Timeouts) Config(org.neo4j.kernel.configuration.Config) HeartbeatContext(org.neo4j.cluster.protocol.heartbeat.HeartbeatContext) ClusterContext(org.neo4j.cluster.protocol.cluster.ClusterContext) ObjectInputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory) LearnerContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.LearnerContext) ObjectOutputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory) Test(org.junit.Test)

Example 95 with InstanceId

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

the class ClusterContextImplTest method nonElectorLeavingTheClusterMustNotAffectElectorInformation.

/*
     * This test ensures that an instance that cleanly leaves the cluster but is not the elector has no effect on
     * elector id and last version
     */
@Test
public void nonElectorLeavingTheClusterMustNotAffectElectorInformation() throws Throwable {
    // Given
    InstanceId me = new InstanceId(1);
    InstanceId elector = new InstanceId(2);
    InstanceId other = new InstanceId(3);
    ClusterConfiguration clusterConfiguration = mock(ClusterConfiguration.class);
    when(clusterConfiguration.getUriForId(other)).thenReturn(URI.create("cluster://instance2"));
    CommonContextState commonContextState = mock(CommonContextState.class);
    when(commonContextState.configuration()).thenReturn(clusterConfiguration);
    ClusterContext context = new ClusterContextImpl(me, commonContextState, NullLogProvider.getInstance(), mock(Timeouts.class), mock(Executor.class), mock(ObjectOutputStreamFactory.class), mock(ObjectInputStreamFactory.class), mock(LearnerContext.class), mock(HeartbeatContext.class), mock(Config.class));
    // This means instance 2 was the elector at version 8
    context.setLastElector(elector);
    context.setLastElectorVersion(8);
    // When
    context.left(other);
    // Then
    assertEquals(context.getLastElector(), elector);
    assertEquals(context.getLastElectorVersion(), 8);
}
Also used : Executor(java.util.concurrent.Executor) InstanceId(org.neo4j.cluster.InstanceId) Timeouts(org.neo4j.cluster.timeout.Timeouts) Config(org.neo4j.kernel.configuration.Config) HeartbeatContext(org.neo4j.cluster.protocol.heartbeat.HeartbeatContext) ClusterContext(org.neo4j.cluster.protocol.cluster.ClusterContext) ObjectInputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory) LearnerContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.LearnerContext) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) ObjectOutputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory) 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