コード例 #1
0
  @Test
  public void shouldLateJoinTransmission() {
    final int length = 8;
    final int recordLength = length + HEADER_LENGTH;
    final int recordLengthAligned = align(recordLength, RECORD_ALIGNMENT);
    final long tail = (CAPACITY * 3L) + HEADER_LENGTH + recordLengthAligned;
    final long latestRecord = tail - recordLengthAligned;
    final int recordOffset = (int) latestRecord & (CAPACITY - 1);

    when(buffer.getLongVolatile(TAIL_INTENT_COUNTER_OFFSET)).thenReturn(tail);
    when(buffer.getLongVolatile(TAIL_COUNTER_INDEX)).thenReturn(tail);
    when(buffer.getLong(LATEST_COUNTER_INDEX)).thenReturn(latestRecord);

    when(buffer.getInt(lengthOffset(recordOffset))).thenReturn(recordLength);
    when(buffer.getInt(typeOffset(recordOffset))).thenReturn(MSG_TYPE_ID);

    assertTrue(broadcastReceiver.receiveNext());
    assertThat(broadcastReceiver.typeId(), is(MSG_TYPE_ID));
    assertThat(broadcastReceiver.buffer(), is(buffer));
    assertThat(broadcastReceiver.offset(), is(msgOffset(recordOffset)));
    assertThat(broadcastReceiver.length(), is(length));

    assertTrue(broadcastReceiver.validate());
    assertThat(broadcastReceiver.lappedCount(), is(greaterThan(0L)));
  }
コード例 #2
0
 @Test
 public void shouldNotBeLappedBeforeReception() {
   assertThat(broadcastReceiver.lappedCount(), is(0L));
 }