use of io.aeron.cluster.service.ClusteredService in project aeron by real-logic.
the class ClusterNodeTest method launchEchoService.
private ClusteredServiceContainer launchEchoService() {
final ClusteredService echoService = new StubClusteredService() {
public void onSessionMessage(final long clusterSessionId, final long correlationId, final long timestampMs, final DirectBuffer buffer, final int offset, final int length, final Header header) {
final ClientSession session = cluster.getClientSession(clusterSessionId);
while (session.offer(correlationId, buffer, offset, length) < 0) {
TestUtil.checkInterruptedStatus();
Thread.yield();
}
}
};
return ClusteredServiceContainer.launch(new ClusteredServiceContainer.Context().clusteredService(echoService).errorHandler(Throwable::printStackTrace).deleteDirOnStart(true));
}
use of io.aeron.cluster.service.ClusteredService in project aeron by real-logic.
the class MultiNodeTest method shouldBecomeFollowerStaticThreeNodeConfigWithElectionFromPreviousLog.
@Test(timeout = 10_000L)
public void shouldBecomeFollowerStaticThreeNodeConfigWithElectionFromPreviousLog() {
final long position = ConsensusModuleHarness.makeRecordingLog(10, 100, null, new ConsensusModule.Context());
final ClusteredService mockService = mock(ClusteredService.class);
final ConsensusModule.Context context = new ConsensusModule.Context().clusterMembers(THREE_NODE_MEMBERS).memberStatusChannel("aeron:udp?endpoint=localhost:9020").appointedLeaderId(1);
try (ConsensusModuleHarness harness = new ConsensusModuleHarness(context, mockService, mockMemberStatusListeners, false, true)) {
harness.memberStatusPublisher().requestVote(harness.memberStatusPublication(1), 1, 0, position, 1);
harness.awaitMemberStatusMessage(1);
verify(mockMemberStatusListeners[1]).onVote(1, 0, position, 1, 0, true);
final int logSessionId = 123456;
final ChannelUri channelUri = ChannelUri.parse(context.logChannel());
channelUri.put(CommonContext.ENDPOINT_PARAM_NAME, harness.member(0).logEndpoint());
channelUri.put(CommonContext.SESSION_ID_PARAM_NAME, Integer.toString(logSessionId));
final Publication logPublication = harness.aeron().addExclusivePublication(channelUri.toString(), context.logStreamId());
harness.memberStatusPublisher().commitPosition(harness.memberStatusPublication(1), position, 1, 1, logSessionId);
harness.awaitMemberStatusMessage(1);
verify(mockMemberStatusListeners[1]).onAppendedPosition(position, 1, 0);
harness.awaitServiceOnStart();
harness.awaitServiceOnMessageCounter(10);
verify(mockService, times(10)).onSessionMessage(anyLong(), anyLong(), anyLong(), any(), anyInt(), eq(100), any());
}
}
use of io.aeron.cluster.service.ClusteredService in project aeron by real-logic.
the class MultiNodeTest method shouldBecomeLeaderStaticThreeNodeConfigWithElection.
@Test(timeout = 10_000L)
public void shouldBecomeLeaderStaticThreeNodeConfigWithElection() {
final ClusteredService mockService = mock(ClusteredService.class);
final ConsensusModule.Context context = new ConsensusModule.Context().clusterMembers(THREE_NODE_MEMBERS).memberStatusChannel("aeron:udp?endpoint=localhost:9020").appointedLeaderId(0);
try (ConsensusModuleHarness harness = new ConsensusModuleHarness(context, mockService, mockMemberStatusListeners, true, true)) {
harness.awaitMemberStatusMessage(1);
harness.awaitMemberStatusMessage(2);
verify(mockMemberStatusListeners[1]).onRequestVote(0, 0, 0, 0);
verify(mockMemberStatusListeners[2]).onRequestVote(0, 0, 0, 0);
harness.memberStatusPublisher().vote(harness.memberStatusPublication(1), 0, 0, 0, 0, 1, true);
harness.memberStatusPublisher().vote(harness.memberStatusPublication(2), 0, 0, 0, 0, 2, true);
harness.awaitMemberStatusMessage(1);
harness.awaitMemberStatusMessage(2);
verify(mockMemberStatusListeners[1]).onCommitPosition(eq(0L), eq(0L), eq(0), anyInt());
verify(mockMemberStatusListeners[2]).onCommitPosition(eq(0L), eq(0L), eq(0), anyInt());
harness.memberStatusPublisher().appendedPosition(harness.memberStatusPublication(1), 0, 0, 1);
harness.memberStatusPublisher().appendedPosition(harness.memberStatusPublication(2), 0, 0, 2);
harness.awaitServiceOnStart();
}
}
use of io.aeron.cluster.service.ClusteredService in project aeron by real-logic.
the class MultiNodeTest method shouldBecomeLeaderStaticThreeNodeConfigWithElectionFromPreviousLog.
@Test(timeout = 10_000L)
public void shouldBecomeLeaderStaticThreeNodeConfigWithElectionFromPreviousLog() {
final long position = ConsensusModuleHarness.makeRecordingLog(10, 100, null, new ConsensusModule.Context());
final ClusteredService mockService = mock(ClusteredService.class);
final ConsensusModule.Context context = new ConsensusModule.Context().clusterMembers(THREE_NODE_MEMBERS).memberStatusChannel("aeron:udp?endpoint=localhost:9020").appointedLeaderId(0);
try (ConsensusModuleHarness harness = new ConsensusModuleHarness(context, mockService, mockMemberStatusListeners, false, true)) {
harness.awaitMemberStatusMessage(1);
harness.awaitMemberStatusMessage(2);
verify(mockMemberStatusListeners[1]).onRequestVote(1, 0, position, 0);
verify(mockMemberStatusListeners[2]).onRequestVote(1, 0, position, 0);
harness.memberStatusPublisher().vote(harness.memberStatusPublication(1), 1, 0, position, 0, 1, true);
harness.memberStatusPublisher().vote(harness.memberStatusPublication(2), 1, 0, position, 0, 2, true);
harness.awaitMemberStatusMessage(1);
harness.awaitMemberStatusMessage(2);
verify(mockMemberStatusListeners[1]).onCommitPosition(eq(position), eq(1L), eq(0), anyInt());
verify(mockMemberStatusListeners[2]).onCommitPosition(eq(position), eq(1L), eq(0), anyInt());
harness.memberStatusPublisher().appendedPosition(harness.memberStatusPublication(1), position, 1, 1);
harness.memberStatusPublisher().appendedPosition(harness.memberStatusPublication(2), position, 1, 2);
harness.awaitServiceOnStart();
harness.awaitServiceOnMessageCounter(10);
verify(mockService, times(10)).onSessionMessage(anyLong(), anyLong(), anyLong(), any(), anyInt(), eq(100), any());
}
}
use of io.aeron.cluster.service.ClusteredService in project aeron by real-logic.
the class SingleNodeTest method shouldBeAbleToLoadUpFromPreviousLog.
@Test(timeout = 10_000L)
public void shouldBeAbleToLoadUpFromPreviousLog() {
ConsensusModuleHarness.makeRecordingLog(10, 100, null, new ConsensusModule.Context());
final ClusteredService mockService = mock(ClusteredService.class);
try (ConsensusModuleHarness harness = new ConsensusModuleHarness(new ConsensusModule.Context(), mockService, null, false, true)) {
harness.awaitServiceOnStart();
harness.awaitServiceOnMessageCounter(10);
verify(mockService, times(10)).onSessionMessage(anyLong(), anyLong(), anyLong(), any(), anyInt(), eq(100), any());
}
}
Aggregations