use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.
the class SenderTest method shouldNotSendUntilStatusMessageReceived.
@Test
public void shouldNotSendUntilStatusMessageReceived() throws Exception {
final UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(PAYLOAD.length));
buffer.putBytes(0, PAYLOAD);
termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null);
sender.doWork();
assertThat(receivedFrames.size(), is(1));
setupHeader.wrap(receivedFrames.remove());
assertThat(setupHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_SETUP));
final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
when(msg.consumptionTermId()).thenReturn(INITIAL_TERM_ID);
when(msg.consumptionTermOffset()).thenReturn(0);
when(msg.receiverWindowLength()).thenReturn(ALIGNED_FRAME_LENGTH);
publication.onStatusMessage(msg, rcvAddress);
// publication.senderPositionLimit(
// flowControl.onStatusMessage(INITIAL_TERM_ID, 0, ALIGNED_FRAME_LENGTH, rcvAddress));
sender.doWork();
assertThat(receivedFrames.size(), is(1));
dataHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));
assertThat(dataHeader.frameLength(), is(FRAME_LENGTH));
assertThat(dataHeader.termId(), is(INITIAL_TERM_ID));
assertThat(dataHeader.streamId(), is(STREAM_ID));
assertThat(dataHeader.sessionId(), is(SESSION_ID));
assertThat(dataHeader.termOffset(), is(offsetOfMessage(1)));
assertThat(dataHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_DATA));
assertThat(dataHeader.flags(), is(DataHeaderFlyweight.BEGIN_AND_END_FLAGS));
assertThat(dataHeader.version(), is((short) HeaderFlyweight.CURRENT_VERSION));
}
use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.
the class SenderTest method shouldBeAbleToSendOnChannel.
@Test
public void shouldBeAbleToSendOnChannel() throws Exception {
final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
when(msg.consumptionTermId()).thenReturn(INITIAL_TERM_ID);
when(msg.consumptionTermOffset()).thenReturn(0);
when(msg.receiverWindowLength()).thenReturn(ALIGNED_FRAME_LENGTH);
publication.onStatusMessage(msg, rcvAddress);
// publication.senderPositionLimit(
// flowControl.onStatusMessage(INITIAL_TERM_ID, 0, ALIGNED_FRAME_LENGTH, rcvAddress));
final UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(PAYLOAD.length));
buffer.putBytes(0, PAYLOAD);
termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null);
sender.doWork();
assertThat(receivedFrames.size(), is(2));
setupHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));
assertThat(setupHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_SETUP));
dataHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));
assertThat(dataHeader.frameLength(), is(FRAME_LENGTH));
assertThat(dataHeader.termId(), is(INITIAL_TERM_ID));
assertThat(dataHeader.streamId(), is(STREAM_ID));
assertThat(dataHeader.sessionId(), is(SESSION_ID));
assertThat(dataHeader.termOffset(), is(offsetOfMessage(1)));
assertThat(dataHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_DATA));
assertThat(dataHeader.flags(), is(DataHeaderFlyweight.BEGIN_AND_END_FLAGS));
assertThat(dataHeader.version(), is((short) HeaderFlyweight.CURRENT_VERSION));
}
use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.
the class SenderTest method shouldSendSetupFrameAfterReceivingStatusMessageWithSetupBit.
@Test
public void shouldSendSetupFrameAfterReceivingStatusMessageWithSetupBit() throws Exception {
final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
when(msg.consumptionTermId()).thenReturn(INITIAL_TERM_ID);
when(msg.consumptionTermOffset()).thenReturn(0);
when(msg.receiverWindowLength()).thenReturn(ALIGNED_FRAME_LENGTH);
publication.onStatusMessage(msg, rcvAddress);
// publication.senderPositionLimit(
// flowControl.onStatusMessage(INITIAL_TERM_ID, 0, ALIGNED_FRAME_LENGTH, rcvAddress));
final UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(PAYLOAD.length));
buffer.putBytes(0, PAYLOAD);
termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null);
sender.doWork();
// setup then data
assertThat(receivedFrames.size(), is(2));
receivedFrames.remove();
receivedFrames.remove();
publication.triggerSendSetupFrame();
sender.doWork();
// setup has been sent already, have to wait
assertThat(receivedFrames.size(), is(0));
currentTimestamp += Configuration.PUBLICATION_SETUP_TIMEOUT_NS + 10;
sender.doWork();
assertThat(receivedFrames.size(), is(1));
setupHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));
assertThat(setupHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_SETUP));
}
Aggregations