Search in sources :

Example 1 with READ_ONLY

use of java.nio.channels.FileChannel.MapMode.READ_ONLY in project aeron by real-logic.

the class SystemTests method verifyLossOccurredForStream.

static void verifyLossOccurredForStream(final String aeronDirectoryName, final int streamId) throws IOException {
    final File lossReportFile = LossReportUtil.file(aeronDirectoryName);
    assertTrue(lossReportFile.exists());
    MappedByteBuffer mappedByteBuffer = null;
    try (RandomAccessFile file = new RandomAccessFile(lossReportFile, "r");
        FileChannel channel = file.getChannel()) {
        mappedByteBuffer = channel.map(READ_ONLY, 0, channel.size());
        final AtomicBuffer buffer = new UnsafeBuffer(mappedByteBuffer);
        final LossReportReader.EntryConsumer lossEntryConsumer = mock(LossReportReader.EntryConsumer.class);
        LossReportReader.read(buffer, lossEntryConsumer);
        verify(lossEntryConsumer).accept(longThat((l) -> l > 0), longThat((l) -> l > 0), anyLong(), anyLong(), anyInt(), eq(streamId), any(), any());
    } finally {
        BufferUtil.free(mappedByteBuffer);
    }
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Tests(io.aeron.test.Tests) ArgumentMatchers(org.mockito.ArgumentMatchers) StringDescription(org.hamcrest.StringDescription) LossReportUtil(io.aeron.driver.reports.LossReportUtil) BufferUtil(org.agrona.BufferUtil) LossReportReader(io.aeron.driver.reports.LossReportReader) org.agrona.concurrent(org.agrona.concurrent) ErrorConsumer(org.agrona.concurrent.errors.ErrorConsumer) ArrayList(java.util.ArrayList) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) java.io(java.io) Matcher(org.hamcrest.Matcher) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ErrorLogReader(org.agrona.concurrent.errors.ErrorLogReader) FileChannel(java.nio.channels.FileChannel) READ_ONLY(java.nio.channels.FileChannel.MapMode.READ_ONLY) MappedByteBuffer(java.nio.MappedByteBuffer) Mockito.mock(org.mockito.Mockito.mock) MappedByteBuffer(java.nio.MappedByteBuffer) FileChannel(java.nio.channels.FileChannel) LossReportReader(io.aeron.driver.reports.LossReportReader)

Example 2 with READ_ONLY

use of java.nio.channels.FileChannel.MapMode.READ_ONLY in project Aeron by real-logic.

the class SystemTests method verifyLossOccurredForStream.

static void verifyLossOccurredForStream(final String aeronDirectoryName, final int streamId) throws IOException {
    final File lossReportFile = LossReportUtil.file(aeronDirectoryName);
    assertTrue(lossReportFile.exists());
    MappedByteBuffer mappedByteBuffer = null;
    try (RandomAccessFile file = new RandomAccessFile(lossReportFile, "r");
        FileChannel channel = file.getChannel()) {
        mappedByteBuffer = channel.map(READ_ONLY, 0, channel.size());
        final AtomicBuffer buffer = new UnsafeBuffer(mappedByteBuffer);
        final LossReportReader.EntryConsumer lossEntryConsumer = mock(LossReportReader.EntryConsumer.class);
        LossReportReader.read(buffer, lossEntryConsumer);
        verify(lossEntryConsumer).accept(longThat((l) -> l > 0), longThat((l) -> l > 0), anyLong(), anyLong(), anyInt(), eq(streamId), any(), any());
    } finally {
        BufferUtil.free(mappedByteBuffer);
    }
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Tests(io.aeron.test.Tests) ArgumentMatchers(org.mockito.ArgumentMatchers) StringDescription(org.hamcrest.StringDescription) LossReportUtil(io.aeron.driver.reports.LossReportUtil) BufferUtil(org.agrona.BufferUtil) LossReportReader(io.aeron.driver.reports.LossReportReader) org.agrona.concurrent(org.agrona.concurrent) ErrorConsumer(org.agrona.concurrent.errors.ErrorConsumer) ArrayList(java.util.ArrayList) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) java.io(java.io) Matcher(org.hamcrest.Matcher) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ErrorLogReader(org.agrona.concurrent.errors.ErrorLogReader) FileChannel(java.nio.channels.FileChannel) READ_ONLY(java.nio.channels.FileChannel.MapMode.READ_ONLY) MappedByteBuffer(java.nio.MappedByteBuffer) Mockito.mock(org.mockito.Mockito.mock) MappedByteBuffer(java.nio.MappedByteBuffer) FileChannel(java.nio.channels.FileChannel) LossReportReader(io.aeron.driver.reports.LossReportReader)

Aggregations

LossReportReader (io.aeron.driver.reports.LossReportReader)2 LossReportUtil (io.aeron.driver.reports.LossReportUtil)2 Tests (io.aeron.test.Tests)2 java.io (java.io)2 MappedByteBuffer (java.nio.MappedByteBuffer)2 FileChannel (java.nio.channels.FileChannel)2 READ_ONLY (java.nio.channels.FileChannel.MapMode.READ_ONLY)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 BufferUtil (org.agrona.BufferUtil)2 org.agrona.concurrent (org.agrona.concurrent)2 ErrorConsumer (org.agrona.concurrent.errors.ErrorConsumer)2 ErrorLogReader (org.agrona.concurrent.errors.ErrorLogReader)2 Matcher (org.hamcrest.Matcher)2 StringDescription (org.hamcrest.StringDescription)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2 Assertions.fail (org.junit.jupiter.api.Assertions.fail)2 ArgumentMatchers (org.mockito.ArgumentMatchers)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.verify (org.mockito.Mockito.verify)2