Beispiel #1
0
  @Test
  public void shouldPadLogAndTripWhenAppendingWithInsufficientRemainingCapacityIncludingHeader() {
    final int headerLength = DEFAULT_HEADER.capacity();
    final int msgLength = 120;
    final int requiredFrameSize = align(headerLength + msgLength, FRAME_ALIGNMENT);
    final int tailValue =
        termAppender.termBuffer().capacity()
            - (requiredFrameSize + (headerLength - FRAME_ALIGNMENT));
    final UnsafeBuffer buffer = new UnsafeBuffer(new byte[128]);
    final int frameLength = TERM_BUFFER_LENGTH - tailValue;

    when(metaDataBuffer.getAndAddInt(TERM_TAIL_COUNTER_OFFSET, requiredFrameSize))
        .thenReturn(tailValue);

    assertThat(termAppender.append(buffer, 0, msgLength), is(TermAppender.TRIPPED));

    final InOrder inOrder = inOrder(termBuffer, metaDataBuffer);
    inOrder
        .verify(metaDataBuffer, times(1))
        .getAndAddInt(TERM_TAIL_COUNTER_OFFSET, requiredFrameSize);
    verifyDefaultHeader(inOrder, termBuffer, tailValue, frameLength);
    inOrder
        .verify(termBuffer, times(1))
        .putShort(typeOffset(tailValue), (short) PADDING_FRAME_TYPE, LITTLE_ENDIAN);
    inOrder
        .verify(termBuffer, times(1))
        .putInt(termOffsetOffset(tailValue), tailValue, LITTLE_ENDIAN);
    inOrder.verify(termBuffer, times(1)).putIntOrdered(tailValue, frameLength);
  }
Beispiel #2
0
 @Test
 public void shouldReportCapacity() {
   assertThat(termAppender.termBuffer().capacity(), is(TERM_BUFFER_LENGTH));
 }