@Test public void shouldFragmentMessageOverTwoFrames() { final int msgLength = termAppender.maxPayloadLength() + 1; final int headerLength = DEFAULT_HEADER.capacity(); final int frameLength = headerLength + 1; final int requiredCapacity = align(headerLength + 1, FRAME_ALIGNMENT) + termAppender.maxFrameLength(); final UnsafeBuffer buffer = new UnsafeBuffer(new byte[msgLength]); when(metaDataBuffer.getAndAddInt(TERM_TAIL_COUNTER_OFFSET, requiredCapacity)).thenReturn(0); assertThat(termAppender.append(buffer, 0, msgLength), is(requiredCapacity)); int tail = 0; final InOrder inOrder = inOrder(termBuffer, metaDataBuffer); inOrder .verify(metaDataBuffer, times(1)) .getAndAddInt(TERM_TAIL_COUNTER_OFFSET, requiredCapacity); verifyDefaultHeader(inOrder, termBuffer, tail, termAppender.maxFrameLength()); inOrder .verify(termBuffer, times(1)) .putBytes(tail + headerLength, buffer, 0, termAppender.maxPayloadLength()); inOrder.verify(termBuffer, times(1)).putByte(flagsOffset(tail), BEGIN_FRAG); inOrder.verify(termBuffer, times(1)).putInt(termOffsetOffset(tail), tail, LITTLE_ENDIAN); inOrder.verify(termBuffer, times(1)).putIntOrdered(tail, termAppender.maxFrameLength()); tail = termAppender.maxFrameLength(); verifyDefaultHeader(inOrder, termBuffer, tail, frameLength); inOrder .verify(termBuffer, times(1)) .putBytes(tail + headerLength, buffer, termAppender.maxPayloadLength(), 1); inOrder.verify(termBuffer, times(1)).putByte(flagsOffset(tail), END_FRAG); inOrder.verify(termBuffer, times(1)).putInt(termOffsetOffset(tail), tail, LITTLE_ENDIAN); inOrder.verify(termBuffer, times(1)).putIntOrdered(tail, frameLength); }
@Test public void shouldReportMaxFrameLength() { assertThat(termAppender.maxFrameLength(), is(MAX_FRAME_LENGTH)); }