Search in sources :

Example 76 with UnsafeBuffer

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

Example 77 with UnsafeBuffer

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

Example 78 with UnsafeBuffer

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

Aggregations

UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)78 Test (org.junit.Test)42 StatusMessageFlyweight (io.aeron.protocol.StatusMessageFlyweight)8 MediaDriver (io.aeron.driver.MediaDriver)7 MutableDirectBuffer (org.agrona.MutableDirectBuffer)6 Header (io.aeron.logbuffer.Header)5 InOrder (org.mockito.InOrder)5 MappedByteBuffer (java.nio.MappedByteBuffer)4 Theory (org.junit.experimental.theories.Theory)4 ReceiveChannelEndpoint (io.aeron.driver.media.ReceiveChannelEndpoint)3 File (java.io.File)3 Date (java.util.Date)3 DirectBuffer (org.agrona.DirectBuffer)3 Before (org.junit.Before)3 DataPoint (org.junit.experimental.theories.DataPoint)3 SendChannelEndpoint (io.aeron.driver.media.SendChannelEndpoint)2 BufferClaim (io.aeron.logbuffer.BufferClaim)2 FragmentHandler (io.aeron.logbuffer.FragmentHandler)2 PrintStream (java.io.PrintStream)2 InetSocketAddress (java.net.InetSocketAddress)2