use of io.aeron.cluster.codecs.NewLeadershipTermEventDecoder in project Aeron by real-logic.
the class TestCluster method validateRecordingLogWithReplay.
public void validateRecordingLogWithReplay(final int nodeId) {
final TestNode node = node(nodeId);
final ConsensusModule.Context consensusModuleCtx = node.consensusModule().context();
final AeronArchive.Context clone = consensusModuleCtx.archiveContext().clone();
try (AeronArchive aeronArchive = AeronArchive.connect(clone);
RecordingLog recordingLog = new RecordingLog(consensusModuleCtx.clusterDir(), false)) {
final RecordingLog.Entry lastTerm = recordingLog.findLastTerm();
assertNotNull(lastTerm);
final long recordingId = lastTerm.recordingId;
final long recordingPosition = aeronArchive.getRecordingPosition(recordingId);
final Subscription replay = aeronArchive.replay(recordingId, 0, recordingPosition, "aeron:udp?endpoint=localhost:6666", 100001);
final MutableLong position = new MutableLong();
final MessageHeaderDecoder messageHeaderDecoder = new MessageHeaderDecoder();
final NewLeadershipTermEventDecoder newLeadershipTermEventDecoder = new NewLeadershipTermEventDecoder();
while (position.get() < recordingPosition) {
replay.poll((buffer, offset, length, header) -> {
messageHeaderDecoder.wrap(buffer, offset);
if (NewLeadershipTermEventDecoder.TEMPLATE_ID == messageHeaderDecoder.templateId()) {
newLeadershipTermEventDecoder.wrapAndApplyHeader(buffer, offset, messageHeaderDecoder);
final RecordingLog.Entry termEntry = recordingLog.findTermEntry(newLeadershipTermEventDecoder.leadershipTermId());
assertNotNull(termEntry);
assertEquals(newLeadershipTermEventDecoder.termBaseLogPosition(), termEntry.termBaseLogPosition);
if (0 < newLeadershipTermEventDecoder.leadershipTermId()) {
final RecordingLog.Entry previousTermEntry = recordingLog.findTermEntry(newLeadershipTermEventDecoder.leadershipTermId() - 1);
assertNotNull(previousTermEntry);
assertEquals(newLeadershipTermEventDecoder.termBaseLogPosition(), previousTermEntry.logPosition, previousTermEntry.toString());
}
}
position.set(header.position());
}, 10);
}
}
}
use of io.aeron.cluster.codecs.NewLeadershipTermEventDecoder in project aeron by real-logic.
the class TestCluster method validateRecordingLogWithReplay.
public void validateRecordingLogWithReplay(final int nodeId) {
final TestNode node = node(nodeId);
final ConsensusModule.Context consensusModuleCtx = node.consensusModule().context();
final AeronArchive.Context clone = consensusModuleCtx.archiveContext().clone();
try (AeronArchive aeronArchive = AeronArchive.connect(clone);
RecordingLog recordingLog = new RecordingLog(consensusModuleCtx.clusterDir(), false)) {
final RecordingLog.Entry lastTerm = recordingLog.findLastTerm();
assertNotNull(lastTerm);
final long recordingId = lastTerm.recordingId;
final long recordingPosition = aeronArchive.getRecordingPosition(recordingId);
final Subscription replay = aeronArchive.replay(recordingId, 0, recordingPosition, "aeron:udp?endpoint=localhost:6666", 100001);
final MutableLong position = new MutableLong();
final MessageHeaderDecoder messageHeaderDecoder = new MessageHeaderDecoder();
final NewLeadershipTermEventDecoder newLeadershipTermEventDecoder = new NewLeadershipTermEventDecoder();
while (position.get() < recordingPosition) {
replay.poll((buffer, offset, length, header) -> {
messageHeaderDecoder.wrap(buffer, offset);
if (NewLeadershipTermEventDecoder.TEMPLATE_ID == messageHeaderDecoder.templateId()) {
newLeadershipTermEventDecoder.wrapAndApplyHeader(buffer, offset, messageHeaderDecoder);
final RecordingLog.Entry termEntry = recordingLog.findTermEntry(newLeadershipTermEventDecoder.leadershipTermId());
assertNotNull(termEntry);
assertEquals(newLeadershipTermEventDecoder.termBaseLogPosition(), termEntry.termBaseLogPosition);
if (0 < newLeadershipTermEventDecoder.leadershipTermId()) {
final RecordingLog.Entry previousTermEntry = recordingLog.findTermEntry(newLeadershipTermEventDecoder.leadershipTermId() - 1);
assertNotNull(previousTermEntry);
assertEquals(newLeadershipTermEventDecoder.termBaseLogPosition(), previousTermEntry.logPosition, previousTermEntry.toString());
}
}
position.set(header.position());
}, 10);
}
}
}
Aggregations