Search in sources :

Example 6 with StatusMessageFlyweight

use of io.aeron.protocol.StatusMessageFlyweight in project Aeron by real-logic.

the class SenderTest method shouldNotSendSetupFrameAfterReceivingStatusMessage.

@Test
public void shouldNotSendSetupFrameAfterReceivingStatusMessage() throws Exception {
    final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
    when(msg.consumptionTermId()).thenReturn(INITIAL_TERM_ID);
    when(msg.consumptionTermOffset()).thenReturn(0);
    when(msg.receiverWindowLength()).thenReturn(0);
    publication.onStatusMessage(msg, rcvAddress);
    //        publication.senderPositionLimit(flowControl.onStatusMessage(msg, rcvAddress, ));
    sender.doWork();
    assertThat(receivedFrames.size(), is(1));
    receivedFrames.remove();
    currentTimestamp += Configuration.PUBLICATION_SETUP_TIMEOUT_NS + 10;
    sender.doWork();
    assertThat(receivedFrames.size(), is(1));
    dataHeader.wrap(receivedFrames.remove());
    // heartbeat
    assertThat(dataHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_DATA));
    assertThat(dataHeader.frameLength(), is(0));
    assertThat(dataHeader.termOffset(), is(offsetOfMessage(1)));
}
Also used : StatusMessageFlyweight(io.aeron.protocol.StatusMessageFlyweight) Test(org.junit.Test)

Example 7 with StatusMessageFlyweight

use of io.aeron.protocol.StatusMessageFlyweight 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));
}
Also used : StatusMessageFlyweight(io.aeron.protocol.StatusMessageFlyweight) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.Test)

Example 8 with StatusMessageFlyweight

use of io.aeron.protocol.StatusMessageFlyweight 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));
}
Also used : StatusMessageFlyweight(io.aeron.protocol.StatusMessageFlyweight) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.Test)

Example 9 with StatusMessageFlyweight

use of io.aeron.protocol.StatusMessageFlyweight 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));
}
Also used : StatusMessageFlyweight(io.aeron.protocol.StatusMessageFlyweight) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.Test)

Aggregations

StatusMessageFlyweight (io.aeron.protocol.StatusMessageFlyweight)9 Test (org.junit.Test)9 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)8 RawLog (io.aeron.driver.buffer.RawLog)1 ReceiveChannelEndpoint (io.aeron.driver.media.ReceiveChannelEndpoint)1 HeaderWriter (io.aeron.logbuffer.HeaderWriter)1 TermAppender (io.aeron.logbuffer.TermAppender)1 InetSocketAddress (java.net.InetSocketAddress)1