Search in sources :

Example 61 with InterruptAfter

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);
}
Also used : CountersReader(org.agrona.concurrent.status.CountersReader) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 62 with InterruptAfter

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);
}
Also used : CountersReader(org.agrona.concurrent.status.CountersReader) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 63 with InterruptAfter

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());
        }
    }
}
Also used : ArchiveException(io.aeron.archive.client.ArchiveException) File(java.io.File) CountersReader(org.agrona.concurrent.status.CountersReader) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 64 with InterruptAfter

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);
    }
}
Also used : ArchiveException(io.aeron.archive.client.ArchiveException) File(java.io.File) CountersReader(org.agrona.concurrent.status.CountersReader) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 65 with InterruptAfter

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());
}
Also used : TestCluster(io.aeron.test.cluster.TestCluster) TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Aggregations

InterruptAfter (io.aeron.test.InterruptAfter)304 Test (org.junit.jupiter.api.Test)240 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)90 MediaDriver (io.aeron.driver.MediaDriver)74 TestNode (io.aeron.test.cluster.TestNode)72 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)68 Tests (io.aeron.test.Tests)66 CountersReader (org.agrona.concurrent.status.CountersReader)64 MethodSource (org.junit.jupiter.params.provider.MethodSource)62 SlowTest (io.aeron.test.SlowTest)60 InterruptingTestCallback (io.aeron.test.InterruptingTestCallback)58 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)58 TestMediaDriver (io.aeron.test.driver.TestMediaDriver)54 TestCluster (io.aeron.test.cluster.TestCluster)52 ThreadingMode (io.aeron.driver.ThreadingMode)50 MutableInteger (org.agrona.collections.MutableInteger)50 DirectBuffer (org.agrona.DirectBuffer)48 SystemTestWatcher (io.aeron.test.SystemTestWatcher)46 MutableLong (org.agrona.collections.MutableLong)46 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)46