Search in sources :

Example 51 with AeronArchive

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);
        }
    }
}
Also used : MessageHeaderDecoder(io.aeron.cluster.codecs.MessageHeaderDecoder) MutableLong(org.agrona.collections.MutableLong) NewLeadershipTermEventDecoder(io.aeron.cluster.codecs.NewLeadershipTermEventDecoder) AeronArchive(io.aeron.archive.client.AeronArchive)

Example 52 with AeronArchive

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());
}
Also used : File(java.io.File) AeronArchive(io.aeron.archive.client.AeronArchive) Tests(io.aeron.test.Tests) ArchiveSystemTests(io.aeron.archive.ArchiveSystemTests) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 53 with AeronArchive

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);
        }
    }
}
Also used : AeronArchive(io.aeron.archive.client.AeronArchive) Archive(io.aeron.archive.Archive) ArchivingMediaDriver(io.aeron.archive.ArchivingMediaDriver) MediaDriver(io.aeron.driver.MediaDriver) AeronArchive(io.aeron.archive.client.AeronArchive) File(java.io.File) ArchivingMediaDriver(io.aeron.archive.ArchivingMediaDriver) Tests(io.aeron.test.Tests)

Example 54 with AeronArchive

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);
}
Also used : RecordingDescriptorCollector(io.aeron.samples.archive.RecordingDescriptorCollector) ExclusivePublication(io.aeron.ExclusivePublication) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) AeronArchive(io.aeron.archive.client.AeronArchive) InterruptAfter(io.aeron.test.InterruptAfter) Test(org.junit.jupiter.api.Test)

Aggregations

AeronArchive (io.aeron.archive.client.AeronArchive)54 Test (org.junit.jupiter.api.Test)28 MediaDriver (io.aeron.driver.MediaDriver)26 File (java.io.File)17 Aeron (io.aeron.Aeron)14 CommonContext (io.aeron.CommonContext)12 Context (io.aeron.archive.Archive.Context)12 InterruptAfter (io.aeron.test.InterruptAfter)12 Tests (io.aeron.test.Tests)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Archive (io.aeron.archive.Archive)10 ArchiveException (io.aeron.archive.client.ArchiveException)10 CountersReader (org.agrona.concurrent.status.CountersReader)10 Publication (io.aeron.Publication)8 FileStore (java.nio.file.FileStore)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)8 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)8 ChannelUriStringBuilder (io.aeron.ChannelUriStringBuilder)7 DEDICATED (io.aeron.archive.ArchiveThreadingMode.DEDICATED)6