use of org.neo4j.cluster.com.message.TrackingMessageHolder in project neo4j by neo4j.
the class ClusterStateTest method joinDeniedTimeoutShouldBeHandledWithExceptionIncludingConfiguration.
@Test
public void joinDeniedTimeoutShouldBeHandledWithExceptionIncludingConfiguration() throws Throwable {
// GIVEN
ClusterContext context = mock(ClusterContext.class);
Map<InstanceId, URI> existingMembers = members(1, 2);
when(context.getLog(any(Class.class))).thenReturn(NullLog.getInstance());
when(context.getJoiningInstances()).thenReturn(Collections.<URI>emptyList());
when(context.hasJoinBeenDenied()).thenReturn(true);
when(context.getJoinDeniedConfigurationResponseState()).thenReturn(configurationResponseState(existingMembers));
TrackingMessageHolder outgoing = new TrackingMessageHolder();
// WHEN the join denial actually takes effect (signaled by a join timeout locally)
ClusterState.joining.handle(context, to(ClusterMessage.joiningTimeout, uri(2)).setHeader(Message.CONVERSATION_ID, "bla"), outgoing);
// THEN assert that the failure contains the received configuration
Message<? extends MessageType> response = outgoing.single();
ClusterEntryDeniedException deniedException = response.getPayload();
assertEquals(existingMembers, deniedException.getConfigurationResponseState().getMembers());
}
use of org.neo4j.cluster.com.message.TrackingMessageHolder in project neo4j by neo4j.
the class ClusterStateTest method joinDeniedHandlingShouldKeepResponseConfiguration.
@Test
public void joinDeniedHandlingShouldKeepResponseConfiguration() throws Throwable {
// GIVEN
ClusterContext context = mock(ClusterContext.class);
when(context.getLog(any(Class.class))).thenReturn(NullLog.getInstance());
TrackingMessageHolder outgoing = new TrackingMessageHolder();
Map<InstanceId, URI> members = members(1, 2);
// WHEN a joining instance receives a denial to join
ClusterState.discovery.handle(context, to(joinDenied, uri(2), configurationResponseState(members)), outgoing);
// THEN assert that the response contains the configuration
verify(context).joinDenied(argThat(new ConfigurationResponseStateMatcher().withMembers(members)));
}
use of org.neo4j.cluster.com.message.TrackingMessageHolder in project neo4j by neo4j.
the class ProposerStateTest method proposer_promiseShouldCarryOnPayloadToPhase2Timeout.
@SuppressWarnings("unchecked")
@Test
public void proposer_promiseShouldCarryOnPayloadToPhase2Timeout() throws Throwable {
// GIVEN
String instanceId = "1";
Serializable payload = "myPayload";
PaxosInstance instance = new PaxosInstance(mock(PaxosInstanceStore.class), new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(instanceId));
instance.propose(1, asList(create("http://some-guy")));
// don't blame me for making it package access.
instance.value_2 = payload;
ProposerContext context = mock(ProposerContext.class);
when(context.getPaxosInstance(any(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.class))).thenReturn(instance);
when(context.getMinimumQuorumSize(anyList())).thenReturn(1);
TrackingMessageHolder outgoing = new TrackingMessageHolder();
Message<ProposerMessage> message = to(promise, create("http://something"), new ProposerMessage.PromiseState(1, 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)));
}
use of org.neo4j.cluster.com.message.TrackingMessageHolder in project neo4j by neo4j.
the class ProposerStateTest method proposer_rejectAcceptShouldCarryOnPayload.
@Test
public void proposer_rejectAcceptShouldCarryOnPayload() throws Throwable {
// GIVEN
String instanceId = "1";
PaxosInstance instance = new PaxosInstance(mock(PaxosInstanceStore.class), new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(instanceId));
Serializable payload = "myPayload";
instance.propose(1, asList(create("http://some-guy")));
instance.ready(payload, true);
instance.pending();
ProposerContext context = mock(ProposerContext.class);
when(context.getLog(any(Class.class))).thenReturn(NullLog.getInstance());
when(context.getPaxosInstance(any(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.class))).thenReturn(instance);
when(context.getMyId()).thenReturn(new org.neo4j.cluster.InstanceId(parseInt(instanceId)));
TrackingMessageHolder outgoing = new TrackingMessageHolder();
Message<ProposerMessage> message = to(rejectAccept, create("http://something"), new ProposerMessage.RejectAcceptState()).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)));
}
use of org.neo4j.cluster.com.message.TrackingMessageHolder in project neo4j by neo4j.
the class ProposerStateTest method proposer_phase1TimeoutShouldCarryOnPayload.
@Test
public void proposer_phase1TimeoutShouldCarryOnPayload() throws Throwable {
// GIVEN
PaxosInstance instance = mock(PaxosInstance.class);
when(instance.isState(State.p1_pending)).thenReturn(true);
ProposerContext context = mock(ProposerContext.class);
when(context.getPaxosInstance(any(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.class))).thenReturn(instance);
TrackingMessageHolder outgoing = new TrackingMessageHolder();
String instanceId = "1";
Serializable payload = "myPayload";
Message<ProposerMessage> message = to(phase1Timeout, 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)));
}
Aggregations