Search in sources :

Example 11 with AeronArchive

use of io.aeron.archive.client.AeronArchive in project Aeron by real-logic.

the class RecordingDescriptorCollectorTest method shouldAllowUserToRetainDescriptorsToPreventReuse.

@Test
void shouldAllowUserToRetainDescriptorsToPreventReuse(@TempDir final Path tempDir) {
    try (MediaDriver mediaDriver = MediaDriver.launch(new MediaDriver.Context().dirDeleteOnStart(true));
        Archive ignore = Archive.launch(new Archive.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()).archiveDir(tempDir.resolve("archive").toFile()).deleteArchiveOnStart(true));
        Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()));
        AeronArchive aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(aeron).ownsAeronClient(false))) {
        createRecordings(aeronArchive, 3);
        final RecordingDescriptorCollector collector = new RecordingDescriptorCollector(1);
        long fromRecordingId = 0;
        int count = aeronArchive.listRecordings(fromRecordingId, collector.poolSize(), collector.reset());
        assertEquals(1, count);
        final RecordingDescriptor desc0 = collector.descriptors().get(0);
        fromRecordingId += count;
        count = aeronArchive.listRecordings(fromRecordingId, collector.poolSize(), collector.reset());
        assertEquals(1, count);
        final RecordingDescriptor desc1 = collector.descriptors().get(0);
        assertEquals(desc0.recordingId(), desc1.recordingId());
        desc1.retain();
        fromRecordingId += count;
        count = aeronArchive.listRecordings(fromRecordingId, collector.poolSize(), collector.reset());
        assertEquals(1, count);
        final RecordingDescriptor desc2 = collector.descriptors().get(0);
        assertNotEquals(desc1.recordingId(), desc2.recordingId());
    }
}
Also used : Archive(io.aeron.archive.Archive) AeronArchive(io.aeron.archive.client.AeronArchive) MediaDriver(io.aeron.driver.MediaDriver) AeronArchive(io.aeron.archive.client.AeronArchive) Aeron(io.aeron.Aeron) SlowTest(io.aeron.test.SlowTest) Test(org.junit.jupiter.api.Test)

Example 12 with AeronArchive

use of io.aeron.archive.client.AeronArchive in project Aeron by real-logic.

the class ClusterTest method shouldRecoverFollowerWhenRecordingStops.

@Test
@InterruptAfter(30)
public void shouldRecoverFollowerWhenRecordingStops() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    cluster.awaitLeader();
    final TestNode follower = cluster.followers().get(0);
    final AeronArchive.Context archiveCtx = new AeronArchive.Context().controlRequestChannel(follower.archive().context().localControlChannel()).controlResponseChannel(follower.archive().context().localControlChannel()).controlRequestStreamId(follower.archive().context().localControlStreamId()).aeronDirectoryName(follower.mediaDriver().aeronDirectoryName());
    try (AeronArchive archive = AeronArchive.connect(archiveCtx)) {
        final int firstRecordingIdIsTheClusterLog = 0;
        assertTrue(archive.tryStopRecordingByIdentity(firstRecordingIdIsTheClusterLog));
    }
    final int messageCount = 10;
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    cluster.awaitServiceMessageCount(follower, messageCount);
}
Also used : TestNode(io.aeron.test.cluster.TestNode) AeronArchive(io.aeron.archive.client.AeronArchive) Test(org.junit.jupiter.api.Test)

Example 13 with AeronArchive

use of io.aeron.archive.client.AeronArchive in project Aeron by real-logic.

the class ClusterTest method shouldEnterElectionWhenRecordingStopsOnLeader.

@Test
@InterruptAfter(30)
public void shouldEnterElectionWhenRecordingStopsOnLeader() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    cluster.connectClient();
    final AeronArchive.Context archiveCtx = new AeronArchive.Context().controlRequestChannel(leader.archive().context().localControlChannel()).controlResponseChannel(leader.archive().context().localControlChannel()).controlRequestStreamId(leader.archive().context().localControlStreamId()).aeronDirectoryName(leader.mediaDriver().aeronDirectoryName());
    try (AeronArchive archive = AeronArchive.connect(archiveCtx)) {
        final int firstRecordingIdIsTheClusterLog = 0;
        assertTrue(archive.tryStopRecordingByIdentity(firstRecordingIdIsTheClusterLog));
    }
    cluster.awaitNewLeadershipEvent(1);
    cluster.followers(2);
}
Also used : TestNode(io.aeron.test.cluster.TestNode) AeronArchive(io.aeron.archive.client.AeronArchive) Test(org.junit.jupiter.api.Test)

Example 14 with AeronArchive

use of io.aeron.archive.client.AeronArchive in project Aeron by real-logic.

the class BasicArchiveTest method before.

@BeforeEach
public void before() {
    final String aeronDirectoryName = CommonContext.generateRandomDirName();
    final MediaDriver.Context driverCtx = new MediaDriver.Context().aeronDirectoryName(aeronDirectoryName).termBufferSparseFile(true).threadingMode(ThreadingMode.SHARED).spiesSimulateConnection(false).dirDeleteOnStart(true);
    archiveDir = new File(SystemUtil.tmpDirName(), "archive");
    final Archive.Context archiveCtx = new Archive.Context().catalogCapacity(CATALOG_CAPACITY).aeronDirectoryName(aeronDirectoryName).deleteArchiveOnStart(true).archiveDir(archiveDir).fileSyncLevel(0).threadingMode(ArchiveThreadingMode.SHARED);
    try {
        driver = TestMediaDriver.launch(driverCtx, systemTestWatcher);
        archive = Archive.launch(archiveCtx);
    } finally {
        systemTestWatcher.dataCollector().add(driverCtx.aeronDirectory());
        systemTestWatcher.dataCollector().add(archiveCtx.archiveDir());
    }
    aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(aeronDirectoryName));
    aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(aeron));
}
Also used : AeronArchive(io.aeron.archive.client.AeronArchive) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) MediaDriver(io.aeron.driver.MediaDriver) File(java.io.File) AeronArchive(io.aeron.archive.client.AeronArchive) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 15 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)

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