Search in sources :

Example 6 with TrackingMessageHolder

use of org.neo4j.cluster.com.message.TrackingMessageHolder in project neo4j by neo4j.

the class ProposerStateTest method proposer_proposePhase1TimeoutShouldCarryOnPayload.

@Test
public void proposer_proposePhase1TimeoutShouldCarryOnPayload() throws Throwable {
    // GIVEN
    PaxosInstance instance = mock(PaxosInstance.class);
    ProposerContext context = mock(ProposerContext.class);
    when(context.getPaxosInstance(any(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.class))).thenReturn(instance);
    when(context.getMyId()).thenReturn(new org.neo4j.cluster.InstanceId(0));
    TrackingMessageHolder outgoing = new TrackingMessageHolder();
    String instanceId = "1";
    Serializable payload = "myPayload";
    Message<ProposerMessage> message = to(propose, create("http://something"), payload).setHeader(INSTANCE, instanceId);
    // WHEN
    ProposerState.proposer.handle(context, message, outgoing);
    // THEN
    verify(context).setTimeout(eq(new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(instanceId)), argThat(new MessageArgumentMatcher<>().withPayload(payload)));
}
Also used : Serializable(java.io.Serializable) TrackingMessageHolder(org.neo4j.cluster.com.message.TrackingMessageHolder) Test(org.junit.Test)

Example 7 with TrackingMessageHolder

use of org.neo4j.cluster.com.message.TrackingMessageHolder 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 8 with TrackingMessageHolder

use of org.neo4j.cluster.com.message.TrackingMessageHolder 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 9 with TrackingMessageHolder

use of org.neo4j.cluster.com.message.TrackingMessageHolder in project neo4j by neo4j.

the class ClusterStateTest method shouldSetDiscoveryHeaderProperly.

@Test
public void shouldSetDiscoveryHeaderProperly() throws Throwable {
    // GIVEN
    ClusterContext context = mock(ClusterContext.class);
    when(context.getLog(any(Class.class))).thenReturn(NullLog.getInstance());
    when(context.getUriForId(id(2))).thenReturn(uri(2));
    when(context.getJoiningInstances()).thenReturn(singletonList(uri(2)));
    List<ConfigurationRequestState> discoveredInstances = new LinkedList<>();
    when(context.getDiscoveredInstances()).thenReturn(discoveredInstances);
    TrackingMessageHolder outgoing = new TrackingMessageHolder();
    ClusterMessage.ConfigurationTimeoutState timeoutState = new ClusterMessage.ConfigurationTimeoutState(3);
    Message<ClusterMessage> message = internal(configurationTimeout, timeoutState);
    String discoveryHeader = "1,2,3";
    when(context.generateDiscoveryHeader()).thenReturn(discoveryHeader);
    // WHEN
    // We receive a configuration request from an instance which we haven't contacted
    ClusterState.discovery.handle(context, message, outgoing);
    // THEN
    // It shouldn't be added to the discovered instances
    assertEquals(discoveryHeader, outgoing.first().getHeader(DISCOVERED));
}
Also used : TrackingMessageHolder(org.neo4j.cluster.com.message.TrackingMessageHolder) ConfigurationRequestState(org.neo4j.cluster.protocol.cluster.ClusterMessage.ConfigurationRequestState) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 TrackingMessageHolder (org.neo4j.cluster.com.message.TrackingMessageHolder)9 Serializable (java.io.Serializable)4 URI (java.net.URI)4 InstanceId (org.neo4j.cluster.InstanceId)4 LinkedList (java.util.LinkedList)1 ConfigurationRequestState (org.neo4j.cluster.protocol.cluster.ClusterMessage.ConfigurationRequestState)1 ConfigurationResponseState (org.neo4j.cluster.protocol.cluster.ClusterMessage.ConfigurationResponseState)1