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