Search in sources :

Example 1 with ClusteredService

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));
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Header(io.aeron.logbuffer.Header) ClientSession(io.aeron.cluster.service.ClientSession) ClusteredService(io.aeron.cluster.service.ClusteredService)

Example 2 with ClusteredService

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());
    }
}
Also used : ChannelUri(io.aeron.ChannelUri) Publication(io.aeron.Publication) ClusteredService(io.aeron.cluster.service.ClusteredService) Test(org.junit.Test)

Example 3 with ClusteredService

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();
    }
}
Also used : ClusteredService(io.aeron.cluster.service.ClusteredService) Test(org.junit.Test)

Example 4 with ClusteredService

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());
    }
}
Also used : ClusteredService(io.aeron.cluster.service.ClusteredService) Test(org.junit.Test)

Example 5 with ClusteredService

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());
    }
}
Also used : ClusteredService(io.aeron.cluster.service.ClusteredService) Test(org.junit.Test)

Aggregations

ClusteredService (io.aeron.cluster.service.ClusteredService)21 ClientSession (io.aeron.cluster.service.ClientSession)13 ClusteredServiceContainer (io.aeron.cluster.service.ClusteredServiceContainer)12 StubClusteredService (io.aeron.test.cluster.StubClusteredService)12 Header (io.aeron.logbuffer.Header)10 DirectBuffer (org.agrona.DirectBuffer)10 ExpandableArrayBuffer (org.agrona.ExpandableArrayBuffer)9 Archive (io.aeron.archive.Archive)8 ClusterTests (io.aeron.test.cluster.ClusterTests)8 AtomicLong (java.util.concurrent.atomic.AtomicLong)8 Test (org.junit.jupiter.api.Test)8 Image (io.aeron.Image)7 Publication (io.aeron.Publication)7 ExclusivePublication (io.aeron.ExclusivePublication)6 ArchiveThreadingMode (io.aeron.archive.ArchiveThreadingMode)6 CLUSTER_MEMBERS (io.aeron.cluster.ClusterTestConstants.CLUSTER_MEMBERS)6 INGRESS_ENDPOINTS (io.aeron.cluster.ClusterTestConstants.INGRESS_ENDPOINTS)6 AeronCluster (io.aeron.cluster.client.AeronCluster)6 Cluster (io.aeron.cluster.service.Cluster)6 MediaDriver (io.aeron.driver.MediaDriver)6