use of org.neo4j.cluster.com.message.Message 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.Message 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.Message in project neo4j by neo4j.
the class ProposerStateTest method ifProposingWithClosedInstanceThenRetryWithNextInstance.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void ifProposingWithClosedInstanceThenRetryWithNextInstance() throws Throwable {
ProposerContext context = Mockito.mock(ProposerContext.class);
when(context.getLog(any(Class.class))).thenReturn(NullLog.getInstance());
org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId instanceId = new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(42);
PaxosInstanceStore paxosInstanceStore = new PaxosInstanceStore();
// The instance is closed
// the instance
PaxosInstance paxosInstance = new PaxosInstance(paxosInstanceStore, instanceId);
// is closed for that conversation, not really important
paxosInstance.closed(instanceId, "1/15#");
when(context.unbookInstance(instanceId)).thenReturn(Message.internal(ProposerMessage.accepted, "the closed payload"));
// required for
when(context.getPaxosInstance(instanceId)).thenReturn(paxosInstance);
// But in the meantime it was reused and has now (of course) timed out
String theTimedoutPayload = "the timed out payload";
Message message = Message.internal(ProposerMessage.phase1Timeout, theTimedoutPayload);
message.setHeader(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE, instanceId.toString());
// Handle it
MessageHolder mockHolder = mock(MessageHolder.class);
ProposerState.proposer.handle(context, message, mockHolder);
// Verify it was resent as a propose with the same value
verify(mockHolder, times(1)).offer(Matchers.<Message<? extends MessageType>>argThat(new MessageArgumentMatcher().onMessageType(ProposerMessage.propose).withPayload(theTimedoutPayload)));
verify(context, times(1)).unbookInstance(instanceId);
}
use of org.neo4j.cluster.com.message.Message in project neo4j by neo4j.
the class HeartbeatStateTest method shouldIgnoreSuspicionsForOurselvesButKeepTheRest.
@Test
public void shouldIgnoreSuspicionsForOurselvesButKeepTheRest() throws Throwable {
// Given
InstanceId myId = new InstanceId(1);
InstanceId foreignId = new InstanceId(3);
HeartbeatState heartbeat = HeartbeatState.heartbeat;
ClusterConfiguration configuration = new ClusterConfiguration("whatever", NullLogProvider.getInstance(), "cluster://1", "cluster://2");
configuration.joined(myId, URI.create("cluster://1"));
configuration.joined(new InstanceId(2), URI.create("cluster://2"));
Config config = mock(Config.class);
when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
MultiPaxosContext context = new MultiPaxosContext(myId, iterable(new ElectionRole("coordinator")), configuration, Mockito.mock(Executor.class), NullLogProvider.getInstance(), Mockito.mock(ObjectInputStreamFactory.class), Mockito.mock(ObjectOutputStreamFactory.class), Mockito.mock(AcceptorInstanceStore.class), Mockito.mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config);
HeartbeatContext heartbeatContext = context.getHeartbeatContext();
Message received = Message.internal(HeartbeatMessage.suspicions, new HeartbeatMessage.SuspicionsState(asSet(iterable(myId, foreignId))));
received.setHeader(Message.FROM, "cluster://2").setHeader(Message.INSTANCE_ID, "2");
// When
heartbeat.handle(heartbeatContext, received, mock(MessageHolder.class));
// Then
assertThat(heartbeatContext.getSuspicionsOf(myId).size(), equalTo(0));
assertThat(heartbeatContext.getSuspicionsOf(foreignId).size(), equalTo(1));
}
use of org.neo4j.cluster.com.message.Message in project neo4j by neo4j.
the class ElectionStateTest method voteResponseShouldHaveSameVersionAsVoteRequest.
@Test
public void voteResponseShouldHaveSameVersionAsVoteRequest() throws Throwable {
final List<Message> messages = new ArrayList<Message>(1);
MessageHolder holder = new MessageHolder() {
@Override
public void offer(Message<? extends MessageType> message) {
messages.add(message);
}
};
ElectionContext context = mock(ElectionContext.class);
final int version = 14;
Message voteRequest = Message.to(ElectionMessage.vote, URI.create("some://instance"), new ElectionContext.VoteRequest("coordinator", version));
voteRequest.setHeader(Message.FROM, "some://other");
election.handle(context, voteRequest, holder);
assertEquals(1, messages.size());
Message response = messages.get(0);
assertEquals(ElectionMessage.voted, response.getMessageType());
ElectionMessage.VersionedVotedData payload = (ElectionMessage.VersionedVotedData) response.getPayload();
assertEquals(version, payload.getVersion());
}
Aggregations