@Test public void shouldBeAbleToAddSingleSpy() { final long id = driverProxy.addSubscription(spyForChannel(CHANNEL_4000), STREAM_ID_1); driverConductor.doWork(); verify(receiverProxy, never()).registerReceiveChannelEndpoint(any()); verify(receiverProxy, never()).addSubscription(any(), eq(STREAM_ID_1)); verify(mockClientProxy).onSubscriptionReady(eq(id), anyInt()); assertNull(driverConductor.receiverChannelEndpoint(UdpChannel.parse(CHANNEL_4000))); }
void cleanupSubscriptionLink(final SubscriptionLink subscription) { final ReceiveChannelEndpoint channelEndpoint = subscription.channelEndpoint(); if (null != channelEndpoint) { if (subscription.hasSessionId()) { if (0 == channelEndpoint.decRefToStreamAndSession(subscription.streamId(), subscription.sessionId())) { receiverProxy.removeSubscription(channelEndpoint, subscription.streamId()); } } else { if (0 == channelEndpoint.decRefToStream(subscription.streamId())) { receiverProxy.removeSubscription(channelEndpoint, subscription.streamId()); } } if (channelEndpoint.shouldBeClosed()) { channelEndpoint.closeStatusIndicator(); receiveChannelEndpointByChannelMap.remove(channelEndpoint.udpChannel().canonicalForm()); receiverProxy.closeReceiveChannelEndpoint(channelEndpoint); } } }
@Test public void shouldNotCreateImageOnUnknownSubscription() { 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(driverConductorProxy); driverConductor.onCreatePublicationImage( SESSION_ID, STREAM_ID_2, 1, 1, 0, TERM_BUFFER_LENGTH, MTU_LENGTH, 0, mock(InetSocketAddress.class), sourceAddress, receiveChannelEndpoint); verify(receiverProxy, never()).newPublicationImage(any(), any()); verify(mockClientProxy, never()).onAvailableImage( anyLong(), anyInt(), anyInt(), anyLong(), anyInt(), anyString(), anyString()); }
public void newPublicationImage(final ReceiveChannelEndpoint channelEndpoint, final PublicationImage image) { if (notConcurrent()) { receiver.onNewPublicationImage(channelEndpoint, image); } else { offer(() -> receiver.onNewPublicationImage(channelEndpoint, image)); } }
@Test public void shouldUseUniqueChannelEndpointOnAddSubscriptionWithNoDistinguishingCharacteristics() { final long id1 = driverProxy.addSubscription(CHANNEL_SUB_CONTROL_MODE_MANUAL, STREAM_ID_1); final long id2 = driverProxy.addSubscription(CHANNEL_SUB_CONTROL_MODE_MANUAL, STREAM_ID_1); driverConductor.doWork(); verify(receiverProxy, times(2)).registerReceiveChannelEndpoint(any()); driverProxy.removeSubscription(id1); driverProxy.removeSubscription(id2); driverConductor.doWork(); verify(receiverProxy, times(2)).closeReceiveChannelEndpoint(any()); verify(mockErrorHandler, never()).onError(any()); }
@Test public void shouldInsertDataIntoLogAfterInitialExchange() receiverProxy.registerReceiveChannelEndpoint(receiveChannelEndpoint); receiverProxy.addSubscription(receiveChannelEndpoint, STREAM_ID); true); receiverProxy.newPublicationImage(receiveChannelEndpoint, image); });
private ReceiveChannelEndpoint getOrCreateReceiveChannelEndpoint(final UdpChannel udpChannel) { ReceiveChannelEndpoint channelEndpoint = findExistingReceiveChannelEndpoint(udpChannel); if (null == channelEndpoint) { channelEndpoint = ctx.receiveChannelEndpointSupplier().newInstance( udpChannel, new DataPacketDispatcher(ctx.driverConductorProxy(), receiverProxy.receiver()), ReceiveChannelStatus.allocate(tempBuffer, countersManager, udpChannel.originalUriString()), ctx); receiveChannelEndpointByChannelMap.put(udpChannel.canonicalForm(), channelEndpoint); receiverProxy.registerReceiveChannelEndpoint(channelEndpoint); } return channelEndpoint; }
@Test public void shouldTimeoutSubscription() { driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_1); driverConductor.doWork(); final ReceiveChannelEndpoint receiveChannelEndpoint = driverConductor.receiverChannelEndpoint(UdpChannel.parse(CHANNEL_4000)); assertNotNull(receiveChannelEndpoint); verify(receiverProxy).addSubscription(eq(receiveChannelEndpoint), eq(STREAM_ID_1)); doWorkUntil(() -> nanoClock.nanoTime() >= CLIENT_LIVENESS_TIMEOUT_NS * 2); verify(mockClientProxy, times(1)) .onClientTimeout(driverProxy.clientId()); verify(receiverProxy, times(1)) .removeSubscription(eq(receiveChannelEndpoint), eq(STREAM_ID_1)); assertNull(driverConductor.receiverChannelEndpoint(UdpChannel.parse(CHANNEL_4000))); }
.driverConductorProxy(driverConductorProxy); receiverProxy = new ReceiverProxy( ThreadingMode.DEDICATED, ctx.receiverCommandQueue(), mock(AtomicCounter.class)); receiverProxy.receiver(receiver);
@Test public void shouldErrorOnRemoveSubscriptionOnUnknownRegistrationId() { final long id1 = driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_1); driverProxy.removeSubscription(id1 + 100); driverConductor.doWork(); final InOrder inOrder = inOrder(receiverProxy, mockClientProxy); inOrder.verify(receiverProxy).addSubscription(any(), anyInt()); inOrder.verify(mockClientProxy).onSubscriptionReady(eq(id1), anyInt()); inOrder.verify(mockClientProxy).onError(anyLong(), eq(UNKNOWN_SUBSCRIPTION), anyString()); inOrder.verifyNoMoreInteractions(); verify(mockErrorHandler).onError(any(Throwable.class)); }
receiverProxy = new ReceiverProxy( threadingMode, receiverCommandQueue(), systemCounters.get(RECEIVER_PROXY_FAILS)); senderProxy = new SenderProxy(
final Sender sender = new Sender(ctx); ctx.receiverProxy().receiver(receiver); ctx.senderProxy().sender(sender); ctx.driverConductorProxy().driverConductor(conductor);
@Test public void shouldOnlyCloseReceiveChannelEndpointOnceWithMultipleSubscriptions() { final long id1 = driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_1); final long id2 = driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_2); driverProxy.removeSubscription(id1); driverProxy.removeSubscription(id2); doWorkUntil(() -> { driverProxy.sendClientKeepalive(); return (CLIENT_LIVENESS_TIMEOUT_NS * 2) - nanoClock.nanoTime() <= 0; }); verify(receiverProxy, times(1)).closeReceiveChannelEndpoint(any()); }
void onAddRcvDestination(final long registrationId, final String destinationChannel, final long correlationId) { ReceiveChannelEndpoint receiveChannelEndpoint = null; for (int i = 0, size = subscriptionLinks.size(); i < size; i++) { final SubscriptionLink subscriptionLink = subscriptionLinks.get(i); if (registrationId == subscriptionLink.registrationId()) { receiveChannelEndpoint = subscriptionLink.channelEndpoint(); break; } } if (null == receiveChannelEndpoint) { throw new ControlProtocolException(UNKNOWN_SUBSCRIPTION, "unknown subscription: " + registrationId); } receiveChannelEndpoint.validateAllowsDestinationControl(); final UdpChannel destinationUdpChannel = UdpChannel.parse(destinationChannel); final ReceiveDestinationUdpTransport transport = new ReceiveDestinationUdpTransport(destinationUdpChannel, ctx); receiverProxy.addDestination(receiveChannelEndpoint, transport); clientProxy.operationSucceeded(correlationId); }
public void addSubscription(final ReceiveChannelEndpoint mediaEndpoint, final int streamId) { if (notConcurrent()) { receiver.onAddSubscription(mediaEndpoint, streamId); } else { offer(() -> receiver.onAddSubscription(mediaEndpoint, streamId)); } }
align(DataHeaderFlyweight.HEADER_LENGTH + FAKE_PAYLOAD.length, FrameDescriptor.FRAME_ALIGNMENT); receiverProxy.registerReceiveChannelEndpoint(receiveChannelEndpoint); receiverProxy.addSubscription(receiveChannelEndpoint, STREAM_ID); true); receiverProxy.newPublicationImage(receiveChannelEndpoint, image); });
private ReceiveChannelEndpoint getOrCreateReceiveChannelEndpoint(final UdpChannel udpChannel) { ReceiveChannelEndpoint channelEndpoint = findExistingReceiveChannelEndpoint(udpChannel); if (null == channelEndpoint) { channelEndpoint = ctx.receiveChannelEndpointSupplier().newInstance( udpChannel, new DataPacketDispatcher(ctx.driverConductorProxy(), receiverProxy.receiver()), ReceiveChannelStatus.allocate(tempBuffer, countersManager, udpChannel.originalUriString()), ctx); receiveChannelEndpointByChannelMap.put(udpChannel.canonicalForm(), channelEndpoint); receiverProxy.registerReceiveChannelEndpoint(channelEndpoint); } return channelEndpoint; }
@Test public void shouldUseExistingChannelEndpointOnAddSubscriptionWithSameTagId() { final long id1 = driverProxy.addSubscription(CHANNEL_4000_TAG_ID_1, STREAM_ID_1); final long id2 = driverProxy.addSubscription(CHANNEL_TAG_ID_1, STREAM_ID_1); driverConductor.doWork(); verify(mockErrorHandler, never()).onError(any()); verify(receiverProxy).registerReceiveChannelEndpoint(any()); driverProxy.removeSubscription(id1); driverProxy.removeSubscription(id2); driverConductor.doWork(); verify(receiverProxy).closeReceiveChannelEndpoint(any()); }
@Test public void shouldNotTimeoutSubscriptionOnKeepAlive() { driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_1); driverConductor.doWork(); final ReceiveChannelEndpoint receiveChannelEndpoint = driverConductor.receiverChannelEndpoint(UdpChannel.parse(CHANNEL_4000)); assertNotNull(receiveChannelEndpoint); verify(receiverProxy).addSubscription(eq(receiveChannelEndpoint), eq(STREAM_ID_1)); doWorkUntil(() -> nanoClock.nanoTime() >= CLIENT_LIVENESS_TIMEOUT_NS); driverProxy.sendClientKeepalive(); doWorkUntil(() -> nanoClock.nanoTime() >= CLIENT_LIVENESS_TIMEOUT_NS + 1000); driverProxy.sendClientKeepalive(); doWorkUntil(() -> nanoClock.nanoTime() >= CLIENT_LIVENESS_TIMEOUT_NS * 2); verify(receiverProxy, never()).removeSubscription(any(), anyInt()); assertNotNull(driverConductor.receiverChannelEndpoint(UdpChannel.parse(CHANNEL_4000))); }
void onAddNetworkSubscription( final String channel, final int streamId, final long registrationId, final long clientId) { final UdpChannel udpChannel = UdpChannel.parse(channel); final SubscriptionParams params = SubscriptionParams.getSubscriptionParams(udpChannel.channelUri(), ctx); checkForClashingSubscription(params, udpChannel, streamId); final ReceiveChannelEndpoint channelEndpoint = getOrCreateReceiveChannelEndpoint(udpChannel); if (params.hasSessionId) { if (1 == channelEndpoint.incRefToStreamAndSession(streamId, params.sessionId)) { receiverProxy.addSubscription(channelEndpoint, streamId, params.sessionId); } } else { if (1 == channelEndpoint.incRefToStream(streamId)) { receiverProxy.addSubscription(channelEndpoint, streamId); } } final AeronClient client = getOrAddClient(clientId); final SubscriptionLink subscription = new NetworkSubscriptionLink( registrationId, channelEndpoint, streamId, channel, client, params); subscriptionLinks.add(subscription); clientProxy.onSubscriptionReady(registrationId, channelEndpoint.statusIndicatorCounterId()); linkMatchingImages(subscription); }