Search in sources :

Example 31 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 32 with AeronArchive

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

the class RecordingLogTest method shouldIgnoreInvalidTermInRecoveryPlan.

@Test
void shouldIgnoreInvalidTermInRecoveryPlan() {
    final int serviceCount = 1;
    final long removedLeadershipTerm = 11L;
    try (RecordingLog recordingLog = new RecordingLog(tempDir, true)) {
        recordingLog.appendTerm(0L, 9L, 444, 0);
        recordingLog.appendTerm(0L, 10L, 666, 0);
        recordingLog.appendSnapshot(1L, 10L, 666, 777L, 0, 0);
        recordingLog.appendSnapshot(2L, 10L, 666, 777L, 0, SERVICE_ID);
        recordingLog.appendSnapshot(3L, 10L, 666, 888L, 0, 0);
        recordingLog.appendSnapshot(4L, 10L, 666, 888L, 0, SERVICE_ID);
        recordingLog.appendTerm(0L, removedLeadershipTerm, 999, 0);
        final RecordingLog.Entry lastTerm = recordingLog.findLastTerm();
        assertNotNull(lastTerm);
        assertEquals(999L, lastTerm.termBaseLogPosition);
        recordingLog.invalidateEntry(removedLeadershipTerm, 6);
    }
    try (RecordingLog recordingLog = new RecordingLog(tempDir, true)) {
        final AeronArchive mockArchive = mock(AeronArchive.class);
        when(mockArchive.listRecording(anyLong(), any())).thenReturn(1);
        final RecordingLog.RecoveryPlan recoveryPlan = recordingLog.createRecoveryPlan(mockArchive, serviceCount, Aeron.NULL_VALUE);
        assertEquals(0L, recoveryPlan.log.recordingId);
        assertEquals(10L, recoveryPlan.log.leadershipTermId);
        assertEquals(666, recoveryPlan.log.termBaseLogPosition);
        final RecordingLog.Entry lastTerm = recordingLog.findLastTerm();
        assertNotNull(lastTerm);
        assertEquals(0L, lastTerm.recordingId);
        assertEquals(0L, recordingLog.findLastTermRecordingId());
        assertTrue(recordingLog.isUnknown(removedLeadershipTerm));
        assertEquals(NULL_VALUE, recordingLog.getTermTimestamp(removedLeadershipTerm));
        assertThrows(ClusterException.class, () -> recordingLog.getTermEntry(removedLeadershipTerm));
        assertThrows(ClusterException.class, () -> recordingLog.commitLogPosition(removedLeadershipTerm, 99L));
    }
}
Also used : AeronArchive(io.aeron.archive.client.AeronArchive) Test(org.junit.jupiter.api.Test)

Example 33 with AeronArchive

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

the class RecordingLogTest method shouldIgnoreIncompleteSnapshotInRecoveryPlan.

@Test
void shouldIgnoreIncompleteSnapshotInRecoveryPlan() {
    final int serviceCount = 1;
    try (RecordingLog recordingLog = new RecordingLog(tempDir, true)) {
        recordingLog.appendSnapshot(1L, 1L, 0, 777L, 0, 0);
        recordingLog.appendSnapshot(2L, 1L, 0, 777L, 0, SERVICE_ID);
        recordingLog.appendSnapshot(3L, 1L, 0, 888L, 0, 0);
    }
    try (RecordingLog recordingLog = new RecordingLog(tempDir, true)) {
        assertEquals(3, recordingLog.entries().size());
        final AeronArchive mockArchive = mock(AeronArchive.class);
        final RecordingLog.RecoveryPlan recoveryPlan = recordingLog.createRecoveryPlan(mockArchive, serviceCount, Aeron.NULL_VALUE);
        assertEquals(2, recoveryPlan.snapshots.size());
        assertEquals(SERVICE_ID, recoveryPlan.snapshots.get(0).serviceId);
        assertEquals(2L, recoveryPlan.snapshots.get(0).recordingId);
        assertEquals(0, recoveryPlan.snapshots.get(1).serviceId);
        assertEquals(1L, recoveryPlan.snapshots.get(1).recordingId);
    }
}
Also used : AeronArchive(io.aeron.archive.client.AeronArchive) Test(org.junit.jupiter.api.Test)

Example 34 with AeronArchive

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

the class RecordingDescriptorCollectorTest method shouldShouldNotReuseDescriptorIfPoolSizeIsZero.

@Test
void shouldShouldNotReuseDescriptorIfPoolSizeIsZero(@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(0);
        long fromRecordingId = 0;
        int count = aeronArchive.listRecordings(fromRecordingId, 1, collector.reset());
        assertEquals(1, count);
        final RecordingDescriptor desc0 = collector.descriptors().get(0);
        fromRecordingId += count;
        count = aeronArchive.listRecordings(fromRecordingId, 1, collector.reset());
        assertEquals(1, count);
        final RecordingDescriptor desc1 = collector.descriptors().get(0);
        assertNotEquals(desc0.recordingId(), desc1.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 35 with AeronArchive

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

the class RecordingDescriptorCollectorTest method shouldCollectPagesOfRecordingDescriptors.

@Test
@InterruptAfter(10)
void shouldCollectPagesOfRecordingDescriptors(@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))) {
        final int numRecordings = 10;
        createRecordings(aeronArchive, numRecordings);
        final RecordingDescriptorCollector collector = new RecordingDescriptorCollector(3);
        long fromRecordingId = 0;
        int count;
        while (0 < (count = aeronArchive.listRecordings(fromRecordingId, collector.poolSize(), collector.reset()))) {
            final List<RecordingDescriptor> descriptors = collector.descriptors();
            assertThat(count, lessThanOrEqualTo(collector.poolSize()));
            assertThat(descriptors.size(), lessThanOrEqualTo(collector.poolSize()));
            // noinspection OptionalGetWithoutIsPresent
            final long maxRecordingId = descriptors.stream().mapToLong(RecordingDescriptor::recordingId).max().getAsLong();
            fromRecordingId = maxRecordingId + 1;
        }
    }
}
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) InterruptAfter(io.aeron.test.InterruptAfter)

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