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();
}
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));
}
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);
}
}
}
}
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());
}
}
}
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());
}
Aggregations