use of io.aeron.archive.client.AeronArchive 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.archive.client.AeronArchive in project aeron by real-logic.
the class ReplayMergeTest method before.
@BeforeEach
public void before() {
final File archiveDir = new File(SystemUtil.tmpDirName(), "archive");
driver = TestMediaDriver.launch(mediaDriverContext.termBufferSparseFile(true).publicationTermBufferLength(TERM_LENGTH).threadingMode(ThreadingMode.SHARED).spiesSimulateConnection(false).imageLivenessTimeoutNs(TimeUnit.SECONDS.toNanos(10)).dirDeleteOnStart(true), systemTestWatcher);
archive = Archive.launch(new Archive.Context().catalogCapacity(CATALOG_CAPACITY).aeronDirectoryName(mediaDriverContext.aeronDirectoryName()).archiveDir(archiveDir).recordingEventsEnabled(false).threadingMode(ArchiveThreadingMode.SHARED).deleteArchiveOnStart(true));
aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriverContext.aeronDirectoryName()));
aeronArchive = AeronArchive.connect(new AeronArchive.Context().errorHandler(Tests::onError).controlRequestChannel(archive.context().localControlChannel()).controlRequestStreamId(archive.context().localControlStreamId()).controlResponseChannel(archive.context().localControlChannel()).aeron(aeron));
systemTestWatcher.dataCollector().add(Paths.get(mediaDriverContext.aeronDirectoryName()));
systemTestWatcher.dataCollector().add(archiveDir.toPath());
}
use of io.aeron.archive.client.AeronArchive in project aeron by real-logic.
the class ArchiveLoggingAgentTest method testArchiveLogging.
@SuppressWarnings("try")
private void testArchiveLogging(final String enabledEvents, final EnumSet<ArchiveEventCode> expectedEvents) {
before(enabledEvents, expectedEvents);
final MediaDriver.Context mediaDriverCtx = new MediaDriver.Context().errorHandler(Tests::onError).dirDeleteOnStart(true).threadingMode(ThreadingMode.SHARED);
final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context().controlRequestChannel("aeron:udp?term-length=64k|endpoint=localhost:8010").controlRequestStreamId(100).controlResponseChannel("aeron:udp?term-length=64k|endpoint=localhost:0").controlResponseStreamId(101);
final Archive.Context archiveCtx = new Archive.Context().errorHandler(Tests::onError).archiveDir(new File(testDir, "archive")).deleteArchiveOnStart(true).recordingEventsEnabled(false).controlChannel(aeronArchiveContext.controlRequestChannel()).controlStreamId(aeronArchiveContext.controlRequestStreamId()).localControlStreamId(aeronArchiveContext.controlRequestStreamId()).recordingEventsChannel(aeronArchiveContext.recordingEventsChannel()).threadingMode(ArchiveThreadingMode.SHARED);
try (ArchivingMediaDriver ignore1 = ArchivingMediaDriver.launch(mediaDriverCtx, archiveCtx)) {
try (AeronArchive ignore2 = AeronArchive.connect(aeronArchiveContext)) {
Tests.await(WAIT_LIST::isEmpty);
}
}
}
use of io.aeron.archive.client.AeronArchive in project aeron by real-logic.
the class ArchiveDeleteAndRestartTest method recordAndReplayExclusivePublication.
@InterruptAfter(10)
@Test
public void recordAndReplayExclusivePublication() {
final UnsafeBuffer buffer = new UnsafeBuffer(new byte[1024]);
buffer.setMemory(0, buffer.capacity(), (byte) 'z');
AeronArchive aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(client));
final String uri = "aeron:ipc?term-length=16m|init-term-id=502090867|term-offset=0|term-id=502090867";
final ExclusivePublication recordedPublication1 = client.addExclusivePublication(uri, STREAM_ID);
final long subscriptionId = aeronArchive.startRecording(uri, STREAM_ID, SourceLocation.LOCAL);
for (int i = 0; i < 10; i++) {
while (recordedPublication1.offer(buffer, 0, 1024) < 0) {
Tests.yieldingIdle("Failed to offer data");
}
}
final long position1 = recordedPublication1.position();
final RecordingDescriptorCollector collector = new RecordingDescriptorCollector(10);
while (aeronArchive.listRecordings(0, Integer.MAX_VALUE, collector.reset()) < 1) {
Tests.yieldingIdle("Didn't find recording");
}
while (position1 != aeronArchive.getRecordingPosition(collector.descriptors().get(0).recordingId())) {
Tests.yieldingIdle("Failed to record data");
}
recordedPublication1.close();
aeronArchive.stopRecording(subscriptionId);
while (position1 != aeronArchive.getStopPosition(collector.descriptors().get(0).recordingId())) {
Tests.yieldingIdle("Failed to stop recording");
}
aeronArchive.close();
archive.close();
archive.context().deleteDirectory();
archive = Archive.launch(archiveContext.clone());
aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(client));
final ExclusivePublication recordedPublication2 = client.addExclusivePublication(uri, STREAM_ID);
aeronArchive.startRecording(uri, STREAM_ID, SourceLocation.LOCAL);
for (int i = 0; i < 10; i++) {
while (recordedPublication2.offer(buffer, 0, 1024) < 0) {
Tests.yieldingIdle("Failed to offer data");
}
}
while (aeronArchive.listRecordings(0, Integer.MAX_VALUE, collector.reset()) < 1) {
Tests.yieldingIdle("Didn't find recording");
}
assertEquals(1, aeronArchive.listRecordings(0, Integer.MAX_VALUE, collector.reset()), collector.descriptors()::toString);
}
Aggregations