use of io.aeron.test.InterruptAfter in project Aeron by real-logic.
the class BasicArchiveTest method shouldFindLastMatchingRecordingIdWithFullUri.
@Test
@InterruptAfter(10)
public void shouldFindLastMatchingRecordingIdWithFullUri() {
final String messagePrefix = "Message-Prefix-";
final int messageCount = 10;
final long subscriptionId = aeronArchive.startRecording(RECORDED_CHANNEL, RECORDED_STREAM_ID, LOCAL);
try (Subscription subscription = aeron.addSubscription(RECORDED_CHANNEL, RECORDED_STREAM_ID);
Publication publication = aeron.addPublication(RECORDED_CHANNEL, RECORDED_STREAM_ID)) {
final CountersReader counters = aeron.countersReader();
final int counterId = ArchiveSystemTests.awaitRecordingCounterId(counters, publication.sessionId());
final long recordingId = RecordingPos.getRecordingId(counters, counterId);
offer(publication, messageCount, messagePrefix);
consume(subscription, messageCount, messagePrefix);
final long currentPosition = publication.position();
awaitPosition(counters, counterId, currentPosition);
final long lastMatchingRecording = aeronArchive.findLastMatchingRecording(0, RECORDED_CHANNEL, RECORDED_STREAM_ID, publication.sessionId());
assertEquals(lastMatchingRecording, recordingId);
}
aeronArchive.stopRecording(subscriptionId);
}
use of io.aeron.test.InterruptAfter in project Aeron by real-logic.
the class BasicArchiveTest method shouldReturnNullValueWithFindLastMatchingRecordingIdDoesNotFindTheRecording.
@Test
@InterruptAfter(10)
public void shouldReturnNullValueWithFindLastMatchingRecordingIdDoesNotFindTheRecording() {
final String messagePrefix = "Message-Prefix-";
final int messageCount = 10;
final long subscriptionId = aeronArchive.startRecording(RECORDED_CHANNEL, RECORDED_STREAM_ID, LOCAL);
try (Subscription subscription = aeron.addSubscription(RECORDED_CHANNEL, RECORDED_STREAM_ID);
Publication publication = aeron.addPublication(RECORDED_CHANNEL, RECORDED_STREAM_ID)) {
final CountersReader counters = aeron.countersReader();
final int counterId = ArchiveSystemTests.awaitRecordingCounterId(counters, publication.sessionId());
final long recordingId = RecordingPos.getRecordingId(counters, counterId);
assertNotEquals(RecordingPos.NULL_RECORDING_ID, recordingId);
offer(publication, messageCount, messagePrefix);
consume(subscription, messageCount, messagePrefix);
final long currentPosition = publication.position();
awaitPosition(counters, counterId, currentPosition);
final long lastMatchingRecording = aeronArchive.findLastMatchingRecording(0, RECORDED_CHANNEL, RECORDED_STREAM_ID, publication.sessionId() + 1);
assertEquals(Aeron.NULL_VALUE, lastMatchingRecording);
}
aeronArchive.stopRecording(subscriptionId);
}
use of io.aeron.test.InterruptAfter in project Aeron by real-logic.
the class BasicArchiveTest method purgeRecordingFailsIfThereAreActiveReplays.
@Test
@InterruptAfter(10)
@SuppressWarnings("try")
public void purgeRecordingFailsIfThereAreActiveReplays() {
final String messagePrefix = "Message-Prefix-";
final int messageCount = 10;
final long stopPosition;
final long subscriptionId = aeronArchive.startRecording(RECORDED_CHANNEL, RECORDED_STREAM_ID, LOCAL);
final long recordingIdFromCounter;
final int sessionId;
try (Subscription subscription = aeron.addSubscription(RECORDED_CHANNEL, RECORDED_STREAM_ID);
Publication publication = aeron.addPublication(RECORDED_CHANNEL, RECORDED_STREAM_ID)) {
sessionId = publication.sessionId();
final CountersReader counters = aeron.countersReader();
final int counterId = awaitRecordingCounterId(counters, sessionId);
recordingIdFromCounter = RecordingPos.getRecordingId(counters, counterId);
assertEquals(CommonContext.IPC_CHANNEL, RecordingPos.getSourceIdentity(counters, counterId));
offer(publication, messageCount, messagePrefix);
consume(subscription, messageCount, messagePrefix);
stopPosition = publication.position();
awaitPosition(counters, counterId, stopPosition);
final long joinPosition = subscription.imageBySessionId(sessionId).joinPosition();
assertEquals(joinPosition, aeronArchive.getStartPosition(recordingIdFromCounter));
assertEquals(stopPosition, aeronArchive.getRecordingPosition(recordingIdFromCounter));
assertEquals(NULL_VALUE, aeronArchive.getStopPosition(recordingIdFromCounter));
}
aeronArchive.stopRecording(subscriptionId);
final long recordingId = aeronArchive.findLastMatchingRecording(0, "alias=" + RECORDED_CHANNEL_ALIAS, RECORDED_STREAM_ID, sessionId);
assertEquals(recordingIdFromCounter, recordingId);
assertEquals(stopPosition, aeronArchive.getStopPosition(recordingIdFromCounter));
final long position = 0L;
final long length = stopPosition - position;
try (Subscription ignore = aeronArchive.replay(recordingId, position, length, REPLAY_CHANNEL, REPLAY_STREAM_ID)) {
final ArchiveException exception = assertThrows(ArchiveException.class, () -> aeronArchive.purgeRecording(recordingId));
assertThat(exception.getMessage(), endsWith("error: cannot purge recording with active replay " + recordingId));
final String[] segmentFiles = Catalog.listSegmentFiles(archiveDir, recordingId);
assertNotNull(segmentFiles);
assertNotEquals(0, segmentFiles.length);
for (final String segmentFile : segmentFiles) {
assertTrue(new File(archiveDir, segmentFile).exists());
}
}
}
use of io.aeron.test.InterruptAfter in project Aeron by real-logic.
the class BasicArchiveTest method purgeRecordingFailsIfRecordingIsActive.
@Test
@InterruptAfter(10)
public void purgeRecordingFailsIfRecordingIsActive() {
final String messagePrefix = "Message-Prefix-";
final int messageCount = 10;
final long stopPosition;
final long subscriptionId = aeronArchive.startRecording(RECORDED_CHANNEL, RECORDED_STREAM_ID, LOCAL);
try {
final long recordingIdFromCounter;
final int sessionId;
try (Subscription subscription = aeron.addSubscription(RECORDED_CHANNEL, RECORDED_STREAM_ID);
Publication publication = aeron.addPublication(RECORDED_CHANNEL, RECORDED_STREAM_ID)) {
sessionId = publication.sessionId();
final CountersReader counters = aeron.countersReader();
final int counterId = awaitRecordingCounterId(counters, sessionId);
recordingIdFromCounter = RecordingPos.getRecordingId(counters, counterId);
assertEquals(CommonContext.IPC_CHANNEL, RecordingPos.getSourceIdentity(counters, counterId));
offer(publication, messageCount, messagePrefix);
consume(subscription, messageCount, messagePrefix);
stopPosition = publication.position();
awaitPosition(counters, counterId, stopPosition);
final long joinPosition = subscription.imageBySessionId(sessionId).joinPosition();
assertEquals(joinPosition, aeronArchive.getStartPosition(recordingIdFromCounter));
assertEquals(stopPosition, aeronArchive.getRecordingPosition(recordingIdFromCounter));
assertEquals(NULL_VALUE, aeronArchive.getStopPosition(recordingIdFromCounter));
final long recordingId = aeronArchive.findLastMatchingRecording(0, "alias=" + RECORDED_CHANNEL_ALIAS, RECORDED_STREAM_ID, sessionId);
assertEquals(recordingIdFromCounter, recordingId);
final ArchiveException exception = assertThrows(ArchiveException.class, () -> aeronArchive.purgeRecording(recordingId));
assertThat(exception.getMessage(), endsWith("error: cannot purge active recording " + recordingId));
final String[] segmentFiles = Catalog.listSegmentFiles(archiveDir, recordingId);
assertNotNull(segmentFiles);
assertNotEquals(0, segmentFiles.length);
for (final String segmentFile : segmentFiles) {
assertTrue(new File(archiveDir, segmentFile).exists());
}
}
} finally {
aeronArchive.stopRecording(subscriptionId);
}
}
use of io.aeron.test.InterruptAfter in project Aeron by real-logic.
the class AppointedLeaderTest method shouldConnectAndSendKeepAlive.
@Test
@InterruptAfter(20)
public void shouldConnectAndSendKeepAlive() {
final TestCluster cluster = aCluster().withStaticNodes(3).withAppointedLeader(LEADER_ID).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
assertEquals(LEADER_ID, leader.index());
assertEquals(Cluster.Role.LEADER, leader.role());
cluster.connectClient();
assertTrue(cluster.client().sendKeepAlive());
}
Aggregations