Search in sources :

Example 1 with CreatePublicationImageCmd

use of io.aeron.driver.cmd.CreatePublicationImageCmd in project Aeron by real-logic.

the class ReceiverTest method shouldCreateRcvTermAndSendSmOnSetup.

@Test(timeout = 10000)
public void shouldCreateRcvTermAndSendSmOnSetup() throws Exception {
    receiverProxy.registerReceiveChannelEndpoint(receiveChannelEndpoint);
    receiverProxy.addSubscription(receiveChannelEndpoint, STREAM_ID);
    receiver.doWork();
    fillSetupFrame(setupHeader);
    receiveChannelEndpoint.onSetupMessage(setupHeader, setupBuffer, SetupFlyweight.HEADER_LENGTH, senderAddress);
    final PublicationImage image = new PublicationImage(CORRELATION_ID, Configuration.IMAGE_LIVENESS_TIMEOUT_NS, receiveChannelEndpoint, senderAddress, SESSION_ID, STREAM_ID, INITIAL_TERM_ID, ACTIVE_TERM_ID, INITIAL_TERM_OFFSET, rawLog, mockFeedbackDelayGenerator, POSITIONS, mockHighestReceivedPosition, mockRebuildPosition, nanoClock, epochClock, mockSystemCounters, SOURCE_ADDRESS, congestionControl, lossReport, true);
    final int messagesRead = toConductorQueue.drain((e) -> {
        final CreatePublicationImageCmd cmd = (CreatePublicationImageCmd) e;
        assertThat(cmd.channelEndpoint().udpChannel(), is(UDP_CHANNEL));
        assertThat(cmd.streamId(), is(STREAM_ID));
        assertThat(cmd.sessionId(), is(SESSION_ID));
        assertThat(cmd.termId(), is(ACTIVE_TERM_ID));
        // pass in new term buffer from conductor, which should trigger SM
        receiverProxy.newPublicationImage(receiveChannelEndpoint, image);
    });
    assertThat(messagesRead, is(1));
    receiver.doWork();
    image.trackRebuild(currentTime + (2 * STATUS_MESSAGE_TIMEOUT), STATUS_MESSAGE_TIMEOUT);
    image.sendPendingStatusMessage();
    final ByteBuffer rcvBuffer = ByteBuffer.allocateDirect(256);
    InetSocketAddress rcvAddress;
    do {
        rcvAddress = (InetSocketAddress) senderChannel.receive(rcvBuffer);
    } while (null == rcvAddress);
    statusHeader.wrap(new UnsafeBuffer(rcvBuffer));
    assertNotNull(rcvAddress);
    assertThat(rcvAddress.getPort(), is(UDP_CHANNEL.remoteData().getPort()));
    assertThat(statusHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_SM));
    assertThat(statusHeader.streamId(), is(STREAM_ID));
    assertThat(statusHeader.sessionId(), is(SESSION_ID));
    assertThat(statusHeader.consumptionTermId(), is(ACTIVE_TERM_ID));
    assertThat(statusHeader.frameLength(), is(StatusMessageFlyweight.HEADER_LENGTH));
}
Also used : CreatePublicationImageCmd(io.aeron.driver.cmd.CreatePublicationImageCmd) InetSocketAddress(java.net.InetSocketAddress) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

CreatePublicationImageCmd (io.aeron.driver.cmd.CreatePublicationImageCmd)1 InetSocketAddress (java.net.InetSocketAddress)1 ByteBuffer (java.nio.ByteBuffer)1 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)1 Test (org.junit.Test)1