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();
}
}
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());
}
}
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());
}
}
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);
}
}
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);
}
}
Aggregations