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);
}
}
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;
}
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;
}
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));
}
Aggregations