Search in sources :

Example 1 with ReceiveChannelEndpoint

use of io.aeron.driver.media.ReceiveChannelEndpoint in project Aeron by real-logic.

the class DriverConductorTest method shouldNotSendAvailableImageWhileImageNotActiveOnAddSubscription.

@Test
public void shouldNotSendAvailableImageWhileImageNotActiveOnAddSubscription() throws Exception {
    final InetSocketAddress sourceAddress = new InetSocketAddress("localhost", 4400);
    final long subOneId = driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_1);
    driverConductor.doWork();
    final ReceiveChannelEndpoint receiveChannelEndpoint = driverConductor.receiverChannelEndpoint(UdpChannel.parse(CHANNEL_4000));
    assertNotNull(receiveChannelEndpoint);
    receiveChannelEndpoint.openChannel();
    driverConductor.onCreatePublicationImage(SESSION_ID, STREAM_ID_1, 1, 1, 0, TERM_BUFFER_LENGTH, MTU_LENGTH, mock(InetSocketAddress.class), sourceAddress, receiveChannelEndpoint);
    final ArgumentCaptor<PublicationImage> captor = ArgumentCaptor.forClass(PublicationImage.class);
    verify(receiverProxy).newPublicationImage(eq(receiveChannelEndpoint), captor.capture());
    final PublicationImage publicationImage = captor.getValue();
    publicationImage.status(PublicationImage.Status.INACTIVE);
    doWorkUntil(() -> nanoClock.nanoTime() >= IMAGE_LIVENESS_TIMEOUT_NS / 2);
    driverProxy.sendClientKeepalive();
    doWorkUntil(() -> nanoClock.nanoTime() >= IMAGE_LIVENESS_TIMEOUT_NS + 1000);
    final long subTwoId = driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_1);
    driverConductor.doWork();
    final InOrder inOrder = inOrder(mockClientProxy);
    inOrder.verify(mockClientProxy, times(1)).operationSucceeded(subOneId);
    inOrder.verify(mockClientProxy, times(1)).onAvailableImage(eq(publicationImage.correlationId()), eq(STREAM_ID_1), eq(SESSION_ID), any(), any(), anyString());
    inOrder.verify(mockClientProxy, times(1)).onUnavailableImage(eq(publicationImage.correlationId()), eq(STREAM_ID_1), anyString());
    inOrder.verify(mockClientProxy, times(1)).operationSucceeded(subTwoId);
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) InetSocketAddress(java.net.InetSocketAddress) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) Test(org.junit.Test)

Example 2 with ReceiveChannelEndpoint

use of io.aeron.driver.media.ReceiveChannelEndpoint in project Aeron by real-logic.

the class DriverConductorTest method shouldOnlyRemoveSubscriptionMediaEndpointUponRemovalOfAllSubscribers.

@Test
public void shouldOnlyRemoveSubscriptionMediaEndpointUponRemovalOfAllSubscribers() throws Exception {
    final UdpChannel udpChannel = UdpChannel.parse(CHANNEL_4000);
    final long id1 = driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_1);
    final long id2 = driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_2);
    final long id3 = driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_3);
    driverConductor.doWork();
    final ReceiveChannelEndpoint channelEndpoint = driverConductor.receiverChannelEndpoint(udpChannel);
    assertNotNull(channelEndpoint);
    assertThat(channelEndpoint.streamCount(), is(3));
    driverProxy.removeSubscription(id2);
    driverProxy.removeSubscription(id3);
    driverConductor.doWork();
    assertNotNull(driverConductor.receiverChannelEndpoint(udpChannel));
    assertThat(channelEndpoint.streamCount(), is(1));
    driverProxy.removeSubscription(id1);
    driverConductor.doWork();
    assertNull(driverConductor.receiverChannelEndpoint(udpChannel));
}
Also used : UdpChannel(io.aeron.driver.media.UdpChannel) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) Test(org.junit.Test)

Example 3 with ReceiveChannelEndpoint

use of io.aeron.driver.media.ReceiveChannelEndpoint in project Aeron by real-logic.

the class DataPacketDispatcher method onRttMeasurement.

public void onRttMeasurement(final ReceiveChannelEndpoint channelEndpoint, final RttMeasurementFlyweight header, final InetSocketAddress srcAddress) {
    final int streamId = header.streamId();
    final Int2ObjectHashMap<PublicationImage> imageBySessionIdMap = sessionsByStreamIdMap.get(streamId);
    if (null != imageBySessionIdMap) {
        final int sessionId = header.sessionId();
        final PublicationImage image = imageBySessionIdMap.get(sessionId);
        if (null != image) {
            if (RttMeasurementFlyweight.REPLY_FLAG == (header.flags() & RttMeasurementFlyweight.REPLY_FLAG)) {
                // TODO: check rate limit
                final InetSocketAddress controlAddress = channelEndpoint.isMulticast() ? channelEndpoint.udpChannel().remoteControl() : srcAddress;
                channelEndpoint.sendRttMeasurement(controlAddress, sessionId, streamId, header.echoTimestamp(), 0, false);
            } else {
                image.onRttMeasurement(header, srcAddress);
            }
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint)

Example 4 with ReceiveChannelEndpoint

use of io.aeron.driver.media.ReceiveChannelEndpoint in project Aeron by real-logic.

the class DataPacketDispatcher method onSetupMessage.

public void onSetupMessage(final ReceiveChannelEndpoint channelEndpoint, final SetupFlyweight header, final UnsafeBuffer buffer, final InetSocketAddress srcAddress) {
    final int streamId = header.streamId();
    final Int2ObjectHashMap<PublicationImage> imageBySessionIdMap = sessionsByStreamIdMap.get(streamId);
    if (null != imageBySessionIdMap) {
        final int sessionId = header.sessionId();
        final int initialTermId = header.initialTermId();
        final int activeTermId = header.activeTermId();
        final PublicationImage image = imageBySessionIdMap.get(sessionId);
        if (null == image && isNotAlreadyInProgressOrOnCoolDown(streamId, sessionId)) {
            if (channelEndpoint.isMulticast() && channelEndpoint.multicastTtl() < header.ttl()) {
                channelEndpoint.possibleTtlAsymmetryEncountered();
            }
            createPublicationImage(channelEndpoint, srcAddress, streamId, sessionId, initialTermId, activeTermId, header.termOffset(), header.termLength(), header.mtuLength());
        }
    }
}
Also used : ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint)

Example 5 with ReceiveChannelEndpoint

use of io.aeron.driver.media.ReceiveChannelEndpoint in project Aeron by real-logic.

the class DriverConductorTest method shouldAlwaysGiveNetworkPublicationCorrelationIdToClientCallbacks.

@Test
public void shouldAlwaysGiveNetworkPublicationCorrelationIdToClientCallbacks() throws Exception {
    final InetSocketAddress sourceAddress = new InetSocketAddress("localhost", 4400);
    driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_1);
    driverConductor.doWork();
    final ReceiveChannelEndpoint receiveChannelEndpoint = driverConductor.receiverChannelEndpoint(UdpChannel.parse(CHANNEL_4000));
    assertNotNull(receiveChannelEndpoint);
    receiveChannelEndpoint.openChannel();
    driverConductor.onCreatePublicationImage(SESSION_ID, STREAM_ID_1, 1, 1, 0, TERM_BUFFER_LENGTH, MTU_LENGTH, mock(InetSocketAddress.class), sourceAddress, receiveChannelEndpoint);
    final ArgumentCaptor<PublicationImage> captor = ArgumentCaptor.forClass(PublicationImage.class);
    verify(receiverProxy).newPublicationImage(eq(receiveChannelEndpoint), captor.capture());
    final PublicationImage publicationImage = captor.getValue();
    publicationImage.status(PublicationImage.Status.ACTIVE);
    driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_1);
    driverConductor.doWork();
    publicationImage.status(PublicationImage.Status.INACTIVE);
    doWorkUntil(() -> nanoClock.nanoTime() >= IMAGE_LIVENESS_TIMEOUT_NS + 1000);
    final InOrder inOrder = inOrder(mockClientProxy);
    inOrder.verify(mockClientProxy, times(2)).onAvailableImage(eq(publicationImage.correlationId()), eq(STREAM_ID_1), eq(SESSION_ID), any(), any(), anyString());
    inOrder.verify(mockClientProxy, times(1)).onUnavailableImage(eq(publicationImage.correlationId()), eq(STREAM_ID_1), anyString());
}
Also used : InOrder(org.mockito.InOrder) InetSocketAddress(java.net.InetSocketAddress) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) Test(org.junit.Test)

Aggregations

ReceiveChannelEndpoint (io.aeron.driver.media.ReceiveChannelEndpoint)19 Test (org.junit.Test)9 SendChannelEndpoint (io.aeron.driver.media.SendChannelEndpoint)6 InetSocketAddress (java.net.InetSocketAddress)6 UdpChannel (io.aeron.driver.media.UdpChannel)4 Position (org.agrona.concurrent.status.Position)2 ReadablePosition (org.agrona.concurrent.status.ReadablePosition)2 InOrder (org.mockito.InOrder)2 RawLog (io.aeron.driver.buffer.RawLog)1 ControlProtocolException (io.aeron.driver.exceptions.ControlProtocolException)1 ArrayList (java.util.ArrayList)1