Search in sources :

Example 16 with ArchiveException

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

the class CatalogTest method shouldThrowArchiveExceptionIfNextRecordingIdIsSmallerThanTheActualLastRecordInTheCatalog.

@Test
void shouldThrowArchiveExceptionIfNextRecordingIdIsSmallerThanTheActualLastRecordInTheCatalog() throws IOException {
    setNextRecordingId(recordingTwoId);
    final ArchiveException exception = assertThrows(ArchiveException.class, () -> new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer));
    assertEquals("ERROR - invalid nextRecordingId: expected value greater or equal to " + (recordingThreeId + 1) + ", was " + recordingTwoId, 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 17 with ArchiveException

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

the class CatalogTest method growCatalogThrowsArchiveExceptionIfRecordingIsTooBig.

@Test
void growCatalogThrowsArchiveExceptionIfRecordingIsTooBig() {
    try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer)) {
        final ArchiveException exception = assertThrows(ArchiveException.class, () -> catalog.growCatalog(CAPACITY * 2, Integer.MAX_VALUE));
        assertEquals("ERROR - recording is too big: total recording length is " + Integer.MAX_VALUE + " bytes, available space is " + (CAPACITY * 2 - 800) + " bytes", 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 18 with ArchiveException

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

the class RecordingWriterTest method onBlockThrowsArchiveExceptionIfCurrentThreadWasInterrupted.

@Test
void onBlockThrowsArchiveExceptionIfCurrentThreadWasInterrupted() throws IOException {
    final Image image = mockImage(0L);
    final RecordingWriter recordingWriter = new RecordingWriter(1, 0, SEGMENT_LENGTH, image, new Context().archiveDir(archiveDir));
    recordingWriter.init();
    assertFalse(Thread.interrupted());
    try {
        Thread.currentThread().interrupt();
        final ArchiveException exception = assertThrows(ArchiveException.class, () -> recordingWriter.onBlock(new UnsafeBuffer(allocate(32)), 0, 10, 5, 8));
        assertEquals(GENERIC, exception.errorCode());
        assertEquals("ERROR - file closed by interrupt, recording aborted", exception.getMessage());
    } finally {
        assertTrue(Thread.interrupted());
    }
}
Also used : Context(io.aeron.archive.Archive.Context) Image(io.aeron.Image) ArchiveException(io.aeron.archive.client.ArchiveException) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test)

Example 19 with ArchiveException

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

the class Catalog method buildIndex.

private void buildIndex(final boolean writable) {
    int offset = firstRecordingDescriptorOffset;
    long recordingId = -1;
    while (offset < capacity) {
        final int frameLength = wrapDescriptorAtOffset(catalogBuffer, offset);
        if (frameLength < 0) {
            break;
        }
        recordingId = recordingId(catalogBuffer);
        if (isValidDescriptor(catalogBuffer)) {
            catalogIndex.add(recordingId, offset);
        }
        offset += frameLength;
    }
    nextRecordingDescriptorOffset = offset;
    if (0 == nextRecordingId) {
        nextRecordingId = recordingId + 1;
    } else if (writable && nextRecordingId < recordingId + 1) {
        throw new ArchiveException("invalid nextRecordingId: expected value greater or equal to " + (recordingId + 1) + ", was " + nextRecordingId);
    }
}
Also used : ArchiveException(io.aeron.archive.client.ArchiveException)

Example 20 with ArchiveException

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

the class RecordingWriter method checkErrorType.

private void checkErrorType(final IOException ex, final int writeLength) {
    final String msg = ex.getMessage();
    boolean isLowStorageSpace = false;
    IOException suppressed = null;
    try {
        isLowStorageSpace = (!Strings.isEmpty(msg) && msg.contains("No space left on device")) || ctx.archiveFileStore().getUsableSpace() < writeLength;
    } catch (final IOException ex2) {
        suppressed = ex2;
    }
    final int errorCode = isLowStorageSpace ? ArchiveException.STORAGE_SPACE : ArchiveException.GENERIC;
    final ArchiveException error = new ArchiveException("java.io.IOException - " + msg, ex, errorCode);
    if (null != suppressed) {
        error.addSuppressed(suppressed);
    }
    throw error;
}
Also used : IOException(java.io.IOException) ArchiveException(io.aeron.archive.client.ArchiveException)

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