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