Search in sources :

Example 6 with Counter

use of io.aeron.Counter in project Aeron by real-logic.

the class ClusterLoggingAgentTest method testClusterEventsLogging.

private void testClusterEventsLogging(final String enabledEvents, final EnumSet<ClusterEventCode> expectedEvents) {
    before(enabledEvents, expectedEvents);
    final Context mediaDriverCtx = new Context().errorHandler(Tests::onError).dirDeleteOnStart(true).threadingMode(ThreadingMode.SHARED);
    final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context().controlRequestChannel("aeron:ipc?term-length=64k").controlRequestStreamId(AeronArchive.Configuration.localControlStreamId()).controlResponseChannel("aeron:ipc?term-length=64k").controlResponseStreamId(AeronArchive.Configuration.localControlStreamId() + 1).controlResponseStreamId(101);
    final Archive.Context archiveCtx = new Archive.Context().errorHandler(Tests::onError).archiveDir(new File(testDir, "archive")).deleteArchiveOnStart(true).recordingEventsEnabled(false).threadingMode(ArchiveThreadingMode.SHARED);
    final ConsensusModule.Context consensusModuleCtx = new ConsensusModule.Context().errorHandler(ClusterTests.errorHandler(0)).clusterDir(new File(testDir, "consensus-module")).archiveContext(aeronArchiveContext.clone()).clusterMemberId(0).clusterMembers("0,localhost:20110,localhost:20220,localhost:20330,localhost:20440,localhost:8010").logChannel("aeron:udp?term-length=256k|control-mode=manual|control=localhost:20550").ingressChannel("aeron:udp?term-length=64k").replicationChannel("aeron:udp?endpoint=localhost:0");
    final ClusteredService clusteredService = mock(ClusteredService.class);
    final ClusteredServiceContainer.Context clusteredServiceCtx = new ClusteredServiceContainer.Context().errorHandler(ClusterTests.errorHandler(0)).archiveContext(aeronArchiveContext.clone()).clusterDir(new File(testDir, "service")).clusteredService(clusteredService);
    clusteredMediaDriver = ClusteredMediaDriver.launch(mediaDriverCtx, archiveCtx, consensusModuleCtx);
    container = ClusteredServiceContainer.launch(clusteredServiceCtx);
    Tests.await(WAIT_LIST::isEmpty);
    final Counter state = clusteredMediaDriver.consensusModule().context().electionStateCounter();
    final Supplier<String> message = () -> ElectionState.get(state).toString();
    while (ElectionState.CLOSED != ElectionState.get(state)) {
        Tests.sleep(1, message);
    }
}
Also used : Context(io.aeron.driver.MediaDriver.Context) AeronArchive(io.aeron.archive.client.AeronArchive) Archive(io.aeron.archive.Archive) ClusteredService(io.aeron.cluster.service.ClusteredService) AeronArchive(io.aeron.archive.client.AeronArchive) ClusterTests(io.aeron.test.cluster.ClusterTests) Tests(io.aeron.test.Tests) Counter(io.aeron.Counter) ConsensusModule(io.aeron.cluster.ConsensusModule) File(java.io.File) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer)

Example 7 with Counter

use of io.aeron.Counter in project Aeron by real-logic.

the class ReplaySession method noNewData.

private boolean noNewData(final long replayPosition, final long oldStopPosition) {
    final Counter limitPosition = this.limitPosition;
    final long currentLimitPosition = limitPosition.get();
    final boolean isCounterClosed = limitPosition.isClosed();
    final long newStopPosition = isCounterClosed ? catalog.stopPosition(recordingId) : currentLimitPosition;
    if (isCounterClosed) {
        if (NULL_POSITION == newStopPosition) {
            replayLimit = oldStopPosition;
        } else if (newStopPosition < replayLimit) {
            replayLimit = newStopPosition;
        }
    }
    if (replayPosition >= replayLimit) {
        state(State.INACTIVE);
    } else if (newStopPosition > oldStopPosition) {
        stopPosition = newStopPosition;
        return false;
    }
    return true;
}
Also used : Counter(io.aeron.Counter)

Example 8 with Counter

use of io.aeron.Counter in project Aeron by real-logic.

the class StartFromTruncatedRecordingLogTest method findLeaderId.

private int findLeaderId() {
    for (int i = 0; i < MEMBER_COUNT; i++) {
        final ConsensusModule.Context context = clusteredMediaDrivers[i].consensusModule().context();
        final Cluster.Role role = Cluster.Role.get(context.clusterNodeRoleCounter());
        final Counter electionStateCounter = context.electionStateCounter();
        if (Cluster.Role.LEADER == role && ElectionState.CLOSED == ElectionState.get(electionStateCounter)) {
            return context.clusterMemberId();
        }
    }
    return NULL_VALUE;
}
Also used : AtomicCounter(org.agrona.concurrent.status.AtomicCounter) Counter(io.aeron.Counter) AeronCluster(io.aeron.cluster.client.AeronCluster) Cluster(io.aeron.cluster.service.Cluster)

Example 9 with Counter

use of io.aeron.Counter in project aeron by real-logic.

the class StartFromTruncatedRecordingLogTest method before.

@BeforeEach
public void before() {
    for (int i = 0; i < MEMBER_COUNT; i++) {
        final AtomicLong atomicLong = new AtomicLong();
        final Counter mockCounter = mock(Counter.class);
        snapshotCounters[i] = atomicLong;
        mockSnapshotCounters[i] = mockCounter;
        when(mockCounter.incrementOrdered()).thenAnswer((invocation) -> atomicLong.getAndIncrement());
        echoServices[i] = new EchoService();
        startNode(i, true);
    }
    clientMediaDriver = MediaDriver.launch(new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).warnIfDirectoryExists(false).dirDeleteOnStart(true));
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicCounter(org.agrona.concurrent.status.AtomicCounter) Counter(io.aeron.Counter) MediaDriver(io.aeron.driver.MediaDriver) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Counter (io.aeron.Counter)9 AtomicCounter (org.agrona.concurrent.status.AtomicCounter)5 Archive (io.aeron.archive.Archive)2 AeronArchive (io.aeron.archive.client.AeronArchive)2 ConsensusModule (io.aeron.cluster.ConsensusModule)2 AeronCluster (io.aeron.cluster.client.AeronCluster)2 Cluster (io.aeron.cluster.service.Cluster)2 ClusteredService (io.aeron.cluster.service.ClusteredService)2 ClusteredServiceContainer (io.aeron.cluster.service.ClusteredServiceContainer)2 MediaDriver (io.aeron.driver.MediaDriver)2 Context (io.aeron.driver.MediaDriver.Context)2 Tests (io.aeron.test.Tests)2 ClusterTests (io.aeron.test.cluster.ClusterTests)2 File (java.io.File)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ReadableCounter (io.aeron.status.ReadableCounter)1 MutableLong (org.agrona.collections.MutableLong)1 CachedEpochClock (org.agrona.concurrent.CachedEpochClock)1 Test (org.junit.Test)1