use of org.neo4j.cluster.com.message.MessageHolder in project neo4j by neo4j.
the class LearnerStateTest method learnerReceivingLearnFailedShouldLogIt.
@Test
public void learnerReceivingLearnFailedShouldLogIt() throws Throwable {
// Given
LearnerState state = LearnerState.learner;
LearnerContext ctx = mock(LearnerContext.class);
MessageHolder outgoing = mock(MessageHolder.class);
InstanceId paxosInstanceIdIAskedFor = new InstanceId(4);
Message<LearnerMessage> theLearnFailure = Message.to(LearnerMessage.learnFailed, URI.create("c:/1")).setHeader(Message.FROM, "c:/2").setHeader(InstanceId.INSTANCE, "4");
when(ctx.getPaxosInstance(paxosInstanceIdIAskedFor)).thenReturn(new PaxosInstance(mock(PaxosInstanceStore.class), paxosInstanceIdIAskedFor));
when(ctx.getMemberURIs()).thenReturn(Collections.singletonList(URI.create("c:/2")));
// When
state.handle(ctx, theLearnFailure, outgoing);
// Then
// verify that the failure was logged
verify(ctx, times(1)).notifyLearnMiss(paxosInstanceIdIAskedFor);
}
use of org.neo4j.cluster.com.message.MessageHolder in project neo4j by neo4j.
the class ProposerStateTest method something.
@Test
public void something() throws Throwable {
Object acceptorValue = new Object();
Object bookedValue = new Object();
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId instanceId = new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(42);
PaxosInstanceStore paxosInstanceStore = new PaxosInstanceStore();
ProposerContext context = Mockito.mock(ProposerContext.class);
when(context.getPaxosInstance(instanceId)).thenReturn(paxosInstanceStore.getPaxosInstance(instanceId));
when(context.getMinimumQuorumSize(Mockito.anyList())).thenReturn(2);
// The instance is closed
// the instance
PaxosInstance paxosInstance = new PaxosInstance(paxosInstanceStore, instanceId);
paxosInstance.propose(2001, Iterables.asList(Iterables.<URI, URI>iterable(create("http://something1"), create("http://something2"), create("http://something3"))));
Message message = Message.to(ProposerMessage.promise, create("http://something1"), new ProposerMessage.PromiseState(2001, acceptorValue));
message.setHeader(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE, instanceId.toString());
MessageHolder mockHolder = mock(MessageHolder.class);
ProposerState.proposer.handle(context, message, mockHolder);
}
use of org.neo4j.cluster.com.message.MessageHolder in project neo4j by neo4j.
the class ElectionStateTest method testElectionRequestIsRejectedIfNoQuorum.
@Test
public void testElectionRequestIsRejectedIfNoQuorum() throws Throwable {
ElectionContext context = mock(ElectionContext.class);
ClusterContext clusterContextMock = mock(ClusterContext.class);
when(context.getLog(Matchers.<Class>any())).thenReturn(NullLog.getInstance());
when(context.electionOk()).thenReturn(false);
when(clusterContextMock.getLog(Matchers.<Class>any())).thenReturn(NullLog.getInstance());
MessageHolder holder = mock(MessageHolder.class);
election.handle(context, Message.<ElectionMessage>internal(performRoleElections), holder);
verifyZeroInteractions(holder);
}
use of org.neo4j.cluster.com.message.MessageHolder in project neo4j by neo4j.
the class AtomicBroadcastStateTest method shouldNotBroadcastWhenHavingNoQuorumNoCoordinator.
@Test
public void shouldNotBroadcastWhenHavingNoQuorumNoCoordinator() throws Throwable {
// GIVEN
AtomicBroadcastContext context = mock(AtomicBroadcastContext.class);
when(context.hasQuorum()).thenReturn(false);
InstanceId coordinator = id(1);
when(context.getCoordinator()).thenReturn(coordinator);
when(context.getUriForId(coordinator)).thenReturn(uri(1));
when(context.getLog(AtomicBroadcastState.class)).thenReturn(NullLog.getInstance());
final List<Message<?>> messages = new ArrayList<>(1);
MessageHolder outgoing = new MessageHolder() {
@Override
public void offer(Message<? extends MessageType> message) {
messages.add(message);
}
};
// WHEN
broadcasting.handle(context, message(1), outgoing);
// THEN
assertEquals(0, messages.size());
}
use of org.neo4j.cluster.com.message.MessageHolder in project neo4j by neo4j.
the class LearnerStateTest method shouldUseLastKnownOnlineClusterMemberAndSetTimeoutForCatchup.
@Test
public void shouldUseLastKnownOnlineClusterMemberAndSetTimeoutForCatchup() throws Throwable {
// Given
LearnerState state = LearnerState.learner;
LearnerContext ctx = mock(LearnerContext.class);
MessageHolder outgoing = mock(MessageHolder.class);
org.neo4j.cluster.InstanceId upToDateClusterMember = new org.neo4j.cluster.InstanceId(1);
// What we know
when(ctx.getLastLearnedInstanceId()).thenReturn(0L);
when(ctx.getPaxosInstance(new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(1L))).thenReturn(new PaxosInstance(null, new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(1L)));
when(ctx.getLastKnownAliveUpToDateInstance()).thenReturn(upToDateClusterMember);
when(ctx.getUriForId(upToDateClusterMember)).thenReturn(new URI("c:/1"));
// What we know the cluster knows
when(ctx.getLastKnownLearnedInstanceInCluster()).thenReturn(1L);
// When
Message<LearnerMessage> message = Message.to(LearnerMessage.catchUp, new URI("c:/2"), 2L).setHeader(Message.FROM, "c:/2").setHeader(Message.INSTANCE_ID, "2");
State newState = state.handle(ctx, message, outgoing);
// Then
assertThat(newState, equalTo((State) LearnerState.learner));
verify(outgoing).offer(Message.to(LearnerMessage.learnRequest, new URI("c:/1"), new LearnerMessage.LearnRequestState()).setHeader(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE, Long.toString(1L)));
verify(ctx).setTimeout("learn", Message.timeout(LearnerMessage.learnTimedout, message));
}
Aggregations