Search in sources :

Example 26 with UnsafeBuffer

use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.

the class TermRebuilderTest method shouldInsertLastFrameIntoBuffer.

@Test
public void shouldInsertLastFrameIntoBuffer() {
    final int frameLength = BitUtil.align(256, FRAME_ALIGNMENT);
    final int srcOffset = 0;
    final int tail = TERM_BUFFER_CAPACITY - frameLength;
    final int termOffset = tail;
    final UnsafeBuffer packet = new UnsafeBuffer(ByteBuffer.allocateDirect(frameLength));
    packet.putShort(typeOffset(srcOffset), (short) PADDING_FRAME_TYPE, LITTLE_ENDIAN);
    packet.putInt(srcOffset, frameLength, LITTLE_ENDIAN);
    TermRebuilder.insert(termBuffer, termOffset, packet, frameLength);
    verify(termBuffer).putBytes(tail + HEADER_LENGTH, packet, srcOffset + HEADER_LENGTH, frameLength - HEADER_LENGTH);
}
Also used : UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.Test)

Example 27 with UnsafeBuffer

use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.

the class TermRebuilderTest method shouldInsertIntoEmptyBuffer.

@Test
public void shouldInsertIntoEmptyBuffer() {
    final UnsafeBuffer packet = new UnsafeBuffer(ByteBuffer.allocateDirect(256));
    final int termOffset = 0;
    final int srcOffset = 0;
    final int length = 256;
    packet.putInt(srcOffset, length, LITTLE_ENDIAN);
    TermRebuilder.insert(termBuffer, termOffset, packet, length);
    final InOrder inOrder = inOrder(termBuffer);
    inOrder.verify(termBuffer).putBytes(termOffset + HEADER_LENGTH, packet, srcOffset + HEADER_LENGTH, length - HEADER_LENGTH);
    inOrder.verify(termBuffer).putLong(termOffset + 24, packet.getLong(24));
    inOrder.verify(termBuffer).putLong(termOffset + 16, packet.getLong(16));
    inOrder.verify(termBuffer).putLong(termOffset + 8, packet.getLong(8));
    inOrder.verify(termBuffer).putLongOrdered(termOffset, packet.getLong(0));
}
Also used : InOrder(org.mockito.InOrder) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.Test)

Example 28 with UnsafeBuffer

use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.

the class TermRebuilderTest method shouldFillGapButNotMoveTailOrHwm.

@Test
public void shouldFillGapButNotMoveTailOrHwm() {
    final int frameLength = 50;
    final int alignedFrameLength = BitUtil.align(frameLength, FRAME_ALIGNMENT);
    final int srcOffset = 0;
    final UnsafeBuffer packet = new UnsafeBuffer(ByteBuffer.allocateDirect(alignedFrameLength));
    final int termOffset = alignedFrameLength * 2;
    TermRebuilder.insert(termBuffer, termOffset, packet, alignedFrameLength);
    verify(termBuffer).putBytes((alignedFrameLength * 2) + HEADER_LENGTH, packet, srcOffset + HEADER_LENGTH, alignedFrameLength - HEADER_LENGTH);
}
Also used : UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.Test)

Example 29 with UnsafeBuffer

use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.

the class FragmentAssemblerTest method shouldPassThroughUnfragmentedMessage.

@Test
public void shouldPassThroughUnfragmentedMessage() {
    when(header.flags()).thenReturn(FrameDescriptor.UNFRAGMENTED);
    final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[128]);
    final int offset = 8;
    final int length = 32;
    adapter.onFragment(srcBuffer, offset, length, header);
    verify(delegateFragmentHandler, times(1)).onFragment(srcBuffer, offset, length, header);
}
Also used : UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.Test)

Example 30 with UnsafeBuffer

use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.

the class ImageTest method setUp.

@Before
public void setUp() {
    dataHeader.wrap(rcvBuffer);
    for (int i = 0; i < PARTITION_COUNT; i++) {
        termBuffers[i] = new UnsafeBuffer(allocateDirect(TERM_BUFFER_LENGTH));
    }
    final UnsafeBuffer logMetaDataBuffer = new UnsafeBuffer(allocateDirect(LOG_META_DATA_LENGTH));
    when(logBuffers.termBuffers()).thenReturn(termBuffers);
    when(logBuffers.termLength()).thenReturn(TERM_BUFFER_LENGTH);
    when(logBuffers.metaDataBuffer()).thenReturn(logMetaDataBuffer);
}
Also used : UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Before(org.junit.Before)

Aggregations

UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)78 Test (org.junit.Test)42 StatusMessageFlyweight (io.aeron.protocol.StatusMessageFlyweight)8 MediaDriver (io.aeron.driver.MediaDriver)7 MutableDirectBuffer (org.agrona.MutableDirectBuffer)6 Header (io.aeron.logbuffer.Header)5 InOrder (org.mockito.InOrder)5 MappedByteBuffer (java.nio.MappedByteBuffer)4 Theory (org.junit.experimental.theories.Theory)4 ReceiveChannelEndpoint (io.aeron.driver.media.ReceiveChannelEndpoint)3 File (java.io.File)3 Date (java.util.Date)3 DirectBuffer (org.agrona.DirectBuffer)3 Before (org.junit.Before)3 DataPoint (org.junit.experimental.theories.DataPoint)3 SendChannelEndpoint (io.aeron.driver.media.SendChannelEndpoint)2 BufferClaim (io.aeron.logbuffer.BufferClaim)2 FragmentHandler (io.aeron.logbuffer.FragmentHandler)2 PrintStream (java.io.PrintStream)2 InetSocketAddress (java.net.InetSocketAddress)2