Search in sources :

Example 36 with ArchiveException

use of io.aeron.archive.client.ArchiveException in project aeron by real-logic.

the class ArchiveTest method shouldErrorOnLowSpace.

@Test
@InterruptAfter(10)
public void shouldErrorOnLowSpace() throws IOException {
    final int streamId = 7;
    final String channel = "aeron:ipc";
    final long usableSpace = 100;
    final long threshold = 101;
    final FileStore fileStore = mock(FileStore.class);
    when(fileStore.getUsableSpace()).thenReturn(usableSpace);
    final MediaDriver.Context driverCtx = new MediaDriver.Context().dirDeleteOnStart(true).threadingMode(ThreadingMode.SHARED);
    final Archive.Context archiveCtx = new Archive.Context().archiveFileStore(fileStore).lowStorageSpaceThreshold(threshold).deleteArchiveOnStart(true).threadingMode(SHARED);
    try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtx, archiveCtx);
        AeronArchive archive = AeronArchive.connect()) {
        try {
            archive.startRecording(channel, streamId, LOCAL);
        } catch (final ArchiveException ex) {
            assertEquals(ArchiveException.STORAGE_SPACE, ex.errorCode());
            return;
        }
        fail("Expected exception");
    } finally {
        archiveCtx.deleteDirectory();
        driverCtx.deleteDirectory();
    }
}
Also used : Context(io.aeron.archive.Archive.Context) CommonContext(io.aeron.CommonContext) FileStore(java.nio.file.FileStore) AeronArchive(io.aeron.archive.client.AeronArchive) MediaDriver(io.aeron.driver.MediaDriver) ArchiveException(io.aeron.archive.client.ArchiveException) AeronArchive(io.aeron.archive.client.AeronArchive) Context(io.aeron.archive.Archive.Context) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) InterruptAfter(io.aeron.test.InterruptAfter)

Example 37 with ArchiveException

use of io.aeron.archive.client.ArchiveException in project aeron by real-logic.

the class CatalogTest method shouldThrowArchiveExceptionIfNextRecordingIdIsInvalidWriteableCatalog.

@Test
void shouldThrowArchiveExceptionIfNextRecordingIdIsInvalidWriteableCatalog() throws IOException {
    setNextRecordingId(-1);
    final ArchiveException exception = assertThrows(ArchiveException.class, () -> new Catalog(archiveDir, clock, MIN_CAPACITY, true, null, null));
    assertEquals("ERROR - invalid nextRecordingId: expected value greater or equal to " + (recordingThreeId + 1) + ", was -1", exception.getMessage());
}
Also used : ArchiveException(io.aeron.archive.client.ArchiveException) Catalog(io.aeron.archive.Catalog) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 38 with ArchiveException

use of io.aeron.archive.client.ArchiveException in project aeron by real-logic.

the class ReplaySessionTest method shouldThrowArchiveExceptionIfCrcFails.

@Test
public void shouldThrowArchiveExceptionIfCrcFails() {
    final long length = 4 * FRAME_LENGTH;
    final long correlationId = 1L;
    final Checksum checksum = crc32();
    try (ReplaySession replaySession = replaySession(RECORDING_POSITION + 2 * FRAME_LENGTH, length, correlationId, mockReplayPub, mockControlSession, null, checksum)) {
        when(mockReplayPub.isClosed()).thenReturn(false);
        when(mockReplayPub.isConnected()).thenReturn(false);
        replaySession.doWork();
        assertEquals(ReplaySession.State.INIT, replaySession.state());
        when(mockReplayPub.isConnected()).thenReturn(true);
        final ArchiveException exception = assertThrows(ArchiveException.class, replaySession::doWork);
        assertEquals(ArchiveException.GENERIC, exception.errorCode());
        assertThat(exception.getMessage(), Matchers.startsWith("ERROR - CRC checksum mismatch at offset=0"));
        verify(mockReplayPub, never()).tryClaim(anyInt(), any(BufferClaim.class));
    }
}
Also used : Checksum(io.aeron.archive.checksum.Checksum) ArchiveException(io.aeron.archive.client.ArchiveException) BufferClaim(io.aeron.logbuffer.BufferClaim) Test(org.junit.jupiter.api.Test)

Example 39 with ArchiveException

use of io.aeron.archive.client.ArchiveException in project aeron by real-logic.

the class CatalogTest method growCatalogThrowsArchiveExceptionIfCatalogIsFull.

@Test
void growCatalogThrowsArchiveExceptionIfCatalogIsFull() {
    try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer)) {
        final ArchiveException exception = assertThrows(ArchiveException.class, () -> catalog.growCatalog(CAPACITY, (int) (CAPACITY + 1)));
        assertEquals("ERROR - catalog is full, max capacity reached: " + CAPACITY, exception.getMessage());
    }
}
Also used : ArchiveException(io.aeron.archive.client.ArchiveException) Catalog(io.aeron.archive.Catalog) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 40 with ArchiveException

use of io.aeron.archive.client.ArchiveException in project aeron by real-logic.

the class ReplaySession method notHeaderAligned.

static boolean notHeaderAligned(final FileChannel channel, final UnsafeBuffer buffer, final int segmentOffset, final int termOffset, final int termId, final int streamId) throws IOException {
    final ByteBuffer byteBuffer = buffer.byteBuffer();
    byteBuffer.clear().limit(HEADER_LENGTH);
    if (HEADER_LENGTH != channel.read(byteBuffer, segmentOffset)) {
        throw new ArchiveException("failed to read fragment header");
    }
    return isInvalidHeader(buffer, streamId, termId, termOffset);
}
Also used : ArchiveException(io.aeron.archive.client.ArchiveException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ArchiveException (io.aeron.archive.client.ArchiveException)48 Test (org.junit.jupiter.api.Test)26 File (java.io.File)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 InterruptAfter (io.aeron.test.InterruptAfter)12 Catalog (io.aeron.archive.Catalog)10 IOException (java.io.IOException)10 CountersReader (org.agrona.concurrent.status.CountersReader)10 ByteBuffer (java.nio.ByteBuffer)8 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)8 Context (io.aeron.archive.Archive.Context)6 Checksum (io.aeron.archive.checksum.Checksum)6 AeronArchive (io.aeron.archive.client.AeronArchive)6 MappedByteBuffer (java.nio.MappedByteBuffer)6 Aeron (io.aeron.Aeron)4 CommonContext (io.aeron.CommonContext)4 MediaDriver (io.aeron.driver.MediaDriver)4 FrameDescriptor (io.aeron.logbuffer.FrameDescriptor)4 DataHeaderFlyweight (io.aeron.protocol.DataHeaderFlyweight)4 Authenticator (io.aeron.security.Authenticator)4