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());
}
}
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;
}
}
}
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());
}
}
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();
}
}
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);
}
}
}
Aggregations