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