Search in sources :

Example 16 with ReceiveChannelEndpoint

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

the class DataPacketDispatcher method onDataPacket.

public int onDataPacket(final ReceiveChannelEndpoint channelEndpoint, final DataHeaderFlyweight header, final UnsafeBuffer buffer, final int length, 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 termId = header.termId();
        final PublicationImage image = imageBySessionIdMap.get(sessionId);
        if (null != image) {
            return image.insertPacket(termId, header.termOffset(), buffer, length);
        } else if (null == ignoredSessionsMap.get(sessionId, streamId)) {
            elicitSetupMessageFromSource(channelEndpoint, srcAddress, streamId, sessionId);
        }
    }
    return 0;
}
Also used : ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint)

Example 17 with ReceiveChannelEndpoint

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

the class DriverConductorTest method shouldSignalInactiveImageWhenImageTimesOut.

@Test
public void shouldSignalInactiveImageWhenImageTimesOut() 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.INACTIVE);
    doWorkUntil(() -> nanoClock.nanoTime() >= IMAGE_LIVENESS_TIMEOUT_NS + 1000);
    verify(mockClientProxy).onUnavailableImage(eq(publicationImage.correlationId()), eq(STREAM_ID_1), anyString());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) Test(org.junit.Test)

Example 18 with ReceiveChannelEndpoint

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

the class DriverConductorTest method shouldCreateImageOnSubscription.

@Test
public void shouldCreateImageOnSubscription() throws Exception {
    final InetSocketAddress sourceAddress = new InetSocketAddress("localhost", 4400);
    final int initialTermId = 1;
    final int activeTermId = 2;
    final int termOffset = 100;
    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, initialTermId, activeTermId, termOffset, 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();
    assertThat(publicationImage.sessionId(), is(SESSION_ID));
    assertThat(publicationImage.streamId(), is(STREAM_ID_1));
    verify(mockClientProxy).onAvailableImage(anyLong(), eq(STREAM_ID_1), eq(SESSION_ID), any(), any(), anyString());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) Test(org.junit.Test)

Example 19 with ReceiveChannelEndpoint

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

the class DriverConductorTest method shouldNotCreateImageOnUnknownSubscription.

@Test
public void shouldNotCreateImageOnUnknownSubscription() 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_2, 1, 1, 0, TERM_BUFFER_LENGTH, MTU_LENGTH, mock(InetSocketAddress.class), sourceAddress, receiveChannelEndpoint);
    verify(receiverProxy, never()).newPublicationImage(any(), any());
    verify(mockClientProxy, never()).onAvailableImage(anyLong(), anyInt(), anyInt(), any(), any(), anyString());
}
Also used : 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