Search in sources :

Example 21 with Archive

use of io.aeron.archive.Archive 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 22 with Archive

use of io.aeron.archive.Archive 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)

Example 23 with Archive

use of io.aeron.archive.Archive 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 24 with Archive

use of io.aeron.archive.Archive in project aeron by real-logic.

the class ArchiveCreator method main.

/**
 * Main method for launching the process.
 *
 * @param args passed to the process.
 */
@SuppressWarnings("try")
public static void main(final String[] args) {
    final String archiveDirName = Archive.Configuration.archiveDirName();
    final File archiveDir = ARCHIVE_DIR_DEFAULT.equals(archiveDirName) ? new File("archive") : new File(archiveDirName);
    final MediaDriver.Context driverContext = new MediaDriver.Context().publicationTermBufferLength(TERM_LENGTH).termBufferSparseFile(true).threadingMode(ThreadingMode.SHARED).errorHandler(Throwable::printStackTrace).spiesSimulateConnection(true).dirDeleteOnStart(true);
    final Archive.Context archiveContext = new Archive.Context().catalogCapacity(CATALOG_CAPACITY).segmentFileLength(SEGMENT_LENGTH).deleteArchiveOnStart(true).archiveDir(archiveDir).fileSyncLevel(0).threadingMode(ArchiveThreadingMode.SHARED);
    System.out.println("Creating basic archive at " + archiveContext.archiveDir());
    try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverContext, archiveContext);
        Aeron aeron = Aeron.connect();
        AeronArchive aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(aeron))) {
        createRecording(aeron, aeronArchive, 0, (SEGMENT_LENGTH * 5L) + 1);
        createRecording(aeron, aeronArchive, (long) TERM_LENGTH + (FrameDescriptor.FRAME_ALIGNMENT * 2), (SEGMENT_LENGTH * 3L) + 1);
    } catch (final Exception ex) {
        ex.printStackTrace();
    }
}
Also used : Archive(io.aeron.archive.Archive) AeronArchive(io.aeron.archive.client.AeronArchive) MediaDriver(io.aeron.driver.MediaDriver) ArchivingMediaDriver(io.aeron.archive.ArchivingMediaDriver) File(java.io.File) ArchivingMediaDriver(io.aeron.archive.ArchivingMediaDriver) AeronArchive(io.aeron.archive.client.AeronArchive) Aeron(io.aeron.Aeron)

Example 25 with Archive

use of io.aeron.archive.Archive 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)

Aggregations

Archive (io.aeron.archive.Archive)25 MediaDriver (io.aeron.driver.MediaDriver)20 AeronArchive (io.aeron.archive.client.AeronArchive)17 File (java.io.File)13 Test (org.junit.jupiter.api.Test)10 Aeron (io.aeron.Aeron)8 ClusteredServiceContainer (io.aeron.cluster.service.ClusteredServiceContainer)8 SlowTest (io.aeron.test.SlowTest)8 CommonContext (io.aeron.CommonContext)7 ArchivingMediaDriver (io.aeron.archive.ArchivingMediaDriver)6 Tests (io.aeron.test.Tests)6 AtomicCounter (org.agrona.concurrent.status.AtomicCounter)6 Counter (io.aeron.Counter)4 ArchiveThreadingMode (io.aeron.archive.ArchiveThreadingMode)4 AeronCluster (io.aeron.cluster.client.AeronCluster)4 EgressListener (io.aeron.cluster.client.EgressListener)4 ClientSession (io.aeron.cluster.service.ClientSession)4 ThreadingMode (io.aeron.driver.ThreadingMode)4 Header (io.aeron.logbuffer.Header)4 InterruptAfter (io.aeron.test.InterruptAfter)4