Search in sources :

Example 1 with ArchiveDescriptorDecoder

use of io.aeron.archiver.messages.ArchiveDescriptorDecoder in project Aeron by real-logic.

the class ArchiveFileUtil method printMetaFile.

static void printMetaFile(final File metaFile) throws IOException {
    final ArchiveDescriptorDecoder formatDecoder = archiveMetaFileFormatDecoder(metaFile);
    System.out.println("streamInstanceId: " + formatDecoder.streamInstanceId());
    System.out.println("termBufferLength: " + formatDecoder.termBufferLength());
    System.out.println("start time: " + new Date(formatDecoder.startTime()));
    System.out.println("initialTermId: " + formatDecoder.initialTermId());
    System.out.println("initial term offset: " + formatDecoder.initialTermOffset());
    System.out.println("last term: " + formatDecoder.lastTermId());
    System.out.println("last term offset: " + formatDecoder.lastTermOffset());
    System.out.println("end time: " + new Date(formatDecoder.endTime()));
    System.out.println("source: " + formatDecoder.source());
    System.out.println("sessionId: " + formatDecoder.sessionId());
    System.out.println("channel: " + formatDecoder.channel());
    System.out.println("streamId: " + formatDecoder.streamId());
    IoUtil.unmap(formatDecoder.buffer().byteBuffer());
}
Also used : ArchiveDescriptorDecoder(io.aeron.archiver.messages.ArchiveDescriptorDecoder) Date(java.util.Date)

Example 2 with ArchiveDescriptorDecoder

use of io.aeron.archiver.messages.ArchiveDescriptorDecoder in project Aeron by real-logic.

the class ArchiveFileUtil method archiveMetaFileFormatDecoder.

static ArchiveDescriptorDecoder archiveMetaFileFormatDecoder(final File metaFile) throws IOException {
    try (RandomAccessFile randomAccessFile = new RandomAccessFile(metaFile, "rw");
        FileChannel metadataFileChannel = randomAccessFile.getChannel()) {
        final MappedByteBuffer metaDataBuffer = metadataFileChannel.map(FileChannel.MapMode.READ_WRITE, 0, ArchiveIndex.INDEX_RECORD_SIZE);
        final ArchiveDescriptorDecoder decoder = new ArchiveDescriptorDecoder();
        return decoder.wrap(new UnsafeBuffer(metaDataBuffer), ArchiveIndex.INDEX_FRAME_LENGTH, ArchiveDescriptorDecoder.BLOCK_LENGTH, ArchiveDescriptorDecoder.SCHEMA_VERSION);
    }
}
Also used : MappedByteBuffer(java.nio.MappedByteBuffer) FileChannel(java.nio.channels.FileChannel) ArchiveDescriptorDecoder(io.aeron.archiver.messages.ArchiveDescriptorDecoder) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Example 3 with ArchiveDescriptorDecoder

use of io.aeron.archiver.messages.ArchiveDescriptorDecoder in project Aeron by real-logic.

the class ImageArchivingSessionTest method shouldRecordFragmentsFromImage.

@Test
public void shouldRecordFragmentsFromImage() throws IOException {
    final EpochClock epochClock = Mockito.mock(EpochClock.class);
    when(epochClock.time()).thenReturn(42L);
    final ImageArchivingSession session = new ImageArchivingSession(proxy, index, tempFolderForTest, image, epochClock);
    Assert.assertEquals(streamInstanceId, session.streamInstanceId());
    // setup the mock image to pass on the mock log buffer
    when(image.rawPoll(any(), anyInt())).thenAnswer(invocation -> {
        final RawBlockHandler handle = invocation.getArgument(0);
        if (handle == null) {
            return 0;
        }
        handle.onBlock(mockLogBufferChannel, 0, mockLogBufferMapped, termOffset, 100, sessionId, 0);
        return 100;
    });
    // expecting session to proxy the available data from the image
    Assert.assertNotEquals("Expect some work", 0, session.doWork());
    // We now evaluate the output of the archiver...
    // meta data exists and is as expected
    final File archiveMetaFile = new File(tempFolderForTest, archiveMetaFileName(session.streamInstanceId()));
    Assert.assertTrue(archiveMetaFile.exists());
    final ArchiveDescriptorDecoder metaData = ArchiveFileUtil.archiveMetaFileFormatDecoder(archiveMetaFile);
    Assert.assertEquals(streamInstanceId, metaData.streamInstanceId());
    Assert.assertEquals(termBufferLength, metaData.termBufferLength());
    Assert.assertEquals(initialTermId, metaData.initialTermId());
    Assert.assertEquals(termOffset, metaData.initialTermOffset());
    Assert.assertEquals(initialTermId, metaData.lastTermId());
    Assert.assertEquals(streamId, metaData.streamId());
    Assert.assertEquals(termOffset + 100, metaData.lastTermOffset());
    Assert.assertEquals(42L, metaData.startTime());
    Assert.assertEquals(-1L, metaData.endTime());
    Assert.assertEquals(source, metaData.source());
    Assert.assertEquals(channel, metaData.channel());
    // data exists and is as expected
    final File archiveDataFile = new File(tempFolderForTest, archiveDataFileName(session.streamInstanceId(), 0));
    Assert.assertTrue(archiveDataFile.exists());
    final StreamInstanceArchiveFragmentReader reader = new StreamInstanceArchiveFragmentReader(session.streamInstanceId(), tempFolderForTest);
    final int polled = reader.poll((buffer, offset, length, header) -> {
        Assert.assertEquals(100, header.frameLength());
        Assert.assertEquals(termOffset + DataHeaderFlyweight.HEADER_LENGTH, offset);
        Assert.assertEquals(100 - DataHeaderFlyweight.HEADER_LENGTH, length);
    });
    Assert.assertEquals(1, polled);
    // next poll has no data
    when(image.rawPoll(any(), anyInt())).thenReturn(0);
    Assert.assertEquals("Expect no work", 0, session.doWork());
    // image is closed
    when(image.isClosed()).thenReturn(true);
    when(epochClock.time()).thenReturn(128L);
    Assert.assertNotEquals("Expect some work", 0, session.doWork());
    Assert.assertTrue(session.isDone());
    Assert.assertEquals(128L, metaData.endTime());
    IoUtil.unmap(metaData.buffer().byteBuffer());
}
Also used : ArchiveDescriptorDecoder(io.aeron.archiver.messages.ArchiveDescriptorDecoder) RawBlockHandler(io.aeron.logbuffer.RawBlockHandler)

Aggregations

ArchiveDescriptorDecoder (io.aeron.archiver.messages.ArchiveDescriptorDecoder)3 RawBlockHandler (io.aeron.logbuffer.RawBlockHandler)1 MappedByteBuffer (java.nio.MappedByteBuffer)1 FileChannel (java.nio.channels.FileChannel)1 Date (java.util.Date)1 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)1