Search in sources :

Example 1 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 2 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 3 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 4 with ArchiveException

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

the class RecordingWriter method onBlock.

/**
 * {@inheritDoc}
 */
public void onBlock(final DirectBuffer termBuffer, final int termOffset, final int length, final int sessionId, final int termId) {
    try {
        final boolean isPaddingFrame = termBuffer.getShort(typeOffset(termOffset)) == PADDING_FRAME_TYPE;
        final int dataLength = isPaddingFrame ? HEADER_LENGTH : length;
        final ByteBuffer byteBuffer;
        if (null == checksum || isPaddingFrame) {
            byteBuffer = termBuffer.byteBuffer();
            byteBuffer.limit(termOffset + dataLength).position(termOffset);
        } else {
            checksumBuffer.putBytes(0, termBuffer, termOffset, dataLength);
            computeChecksum(checksum, checksumBuffer, dataLength);
            byteBuffer = checksumBuffer.byteBuffer();
            byteBuffer.limit(dataLength).position(0);
        }
        int fileOffset = segmentOffset;
        do {
            fileOffset += recordingFileChannel.write(byteBuffer, fileOffset);
        } while (byteBuffer.remaining() > 0);
        if (forceWrites) {
            recordingFileChannel.force(forceMetadata);
        }
        segmentOffset += length;
        if (segmentOffset >= segmentLength) {
            onFileRollOver();
        }
    } catch (final ClosedByInterruptException ex) {
        close();
        throw new ArchiveException("file closed by interrupt, recording aborted", ex, ArchiveException.GENERIC);
    } catch (final IOException ex) {
        close();
        checkErrorType(ex, length);
    } catch (final Exception ex) {
        close();
        LangUtil.rethrowUnchecked(ex);
    }
}
Also used : ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) IOException(java.io.IOException) ArchiveException(io.aeron.archive.client.ArchiveException) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) ArchiveException(io.aeron.archive.client.ArchiveException)

Example 5 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)

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