Search in sources :

Example 1 with RawLog

use of io.aeron.driver.buffer.RawLog in project Aeron by real-logic.

the class DriverConductorTest method shouldTimeoutPublicationWithNoKeepaliveButNotFlushed.

@Test
public void shouldTimeoutPublicationWithNoKeepaliveButNotFlushed() throws Exception {
    driverProxy.addPublication(CHANNEL_4000, STREAM_ID_1);
    driverConductor.doWork();
    final ArgumentCaptor<NetworkPublication> captor = ArgumentCaptor.forClass(NetworkPublication.class);
    verify(senderProxy, times(1)).newNetworkPublication(captor.capture());
    final NetworkPublication publication = captor.getValue();
    final int termId = 101;
    final int index = LogBufferDescriptor.indexByTerm(termId, termId);
    final RawLog rawLog = publication.rawLog();
    final TermAppender appender = new TermAppender(rawLog.termBuffers()[index], rawLog.metaData(), index);
    final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[256]);
    final HeaderWriter headerWriter = new HeaderWriter(createDefaultHeader(publication.sessionId(), STREAM_ID_1, termId));
    final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
    when(msg.consumptionTermId()).thenReturn(termId);
    when(msg.consumptionTermOffset()).thenReturn(0);
    when(msg.receiverWindowLength()).thenReturn(10);
    publication.onStatusMessage(msg, new InetSocketAddress("localhost", 4059));
    appender.appendUnfragmentedMessage(headerWriter, srcBuffer, 0, 256, null);
    doWorkUntil(() -> nanoClock.nanoTime() >= PUBLICATION_LINGER_NS + CLIENT_LIVENESS_TIMEOUT_NS * 2);
    assertTrue(publication.hasReachedEndOfLife());
    verify(senderProxy).removeNetworkPublication(eq(publication));
    assertNull(driverConductor.senderChannelEndpoint(UdpChannel.parse(CHANNEL_4000)));
}
Also used : StatusMessageFlyweight(io.aeron.protocol.StatusMessageFlyweight) InetSocketAddress(java.net.InetSocketAddress) RawLog(io.aeron.driver.buffer.RawLog) TermAppender(io.aeron.logbuffer.TermAppender) HeaderWriter(io.aeron.logbuffer.HeaderWriter) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) Test(org.junit.Test)

Example 2 with RawLog

use of io.aeron.driver.buffer.RawLog in project Aeron by real-logic.

the class DriverConductor method newNetworkPublicationLog.

private RawLog newNetworkPublicationLog(final int sessionId, final int streamId, final int initialTermId, final UdpChannel udpChannel, final long registrationId, final int termBufferLength) {
    final RawLog rawLog = rawLogFactory.newNetworkPublication(udpChannel.canonicalForm(), sessionId, streamId, registrationId, termBufferLength);
    final UnsafeBuffer logMetaData = rawLog.metaData();
    storeDefaultFrameHeader(logMetaData, createDefaultHeader(sessionId, streamId, initialTermId));
    initialiseTailWithTermId(logMetaData, 0, initialTermId);
    initialTermId(logMetaData, initialTermId);
    mtuLength(logMetaData, context.mtuLength());
    correlationId(logMetaData, registrationId);
    timeOfLastStatusMessage(logMetaData, 0);
    return rawLog;
}
Also used : RawLog(io.aeron.driver.buffer.RawLog)

Example 3 with RawLog

use of io.aeron.driver.buffer.RawLog in project Aeron by real-logic.

the class DriverConductor method newIpcPublicationLog.

private RawLog newIpcPublicationLog(final int termBufferLength, final int sessionId, final int streamId, final int initialTermId, final long registrationId) {
    final RawLog rawLog = rawLogFactory.newIpcPublication(sessionId, streamId, registrationId, termBufferLength);
    final UnsafeBuffer logMetaData = rawLog.metaData();
    storeDefaultFrameHeader(logMetaData, createDefaultHeader(sessionId, streamId, initialTermId));
    initialiseTailWithTermId(logMetaData, 0, initialTermId);
    initialTermId(logMetaData, initialTermId);
    mtuLength(logMetaData, computeMaxMessageLength(termBufferLength));
    correlationId(logMetaData, registrationId);
    timeOfLastStatusMessage(logMetaData, 0);
    return rawLog;
}
Also used : RawLog(io.aeron.driver.buffer.RawLog)

Example 4 with RawLog

use of io.aeron.driver.buffer.RawLog in project Aeron by real-logic.

the class DriverConductor method newPublicationImageLog.

private RawLog newPublicationImageLog(final int sessionId, final int streamId, final int initialTermId, final int termBufferLength, final int senderMtuLength, final UdpChannel udpChannel, final long correlationId) {
    final RawLog rawLog = rawLogFactory.newNetworkedImage(udpChannel.canonicalForm(), sessionId, streamId, correlationId, termBufferLength);
    final UnsafeBuffer logMetaData = rawLog.metaData();
    storeDefaultFrameHeader(logMetaData, createDefaultHeader(sessionId, streamId, initialTermId));
    initialTermId(logMetaData, initialTermId);
    mtuLength(logMetaData, senderMtuLength);
    correlationId(logMetaData, correlationId);
    timeOfLastStatusMessage(logMetaData, 0);
    return rawLog;
}
Also used : RawLog(io.aeron.driver.buffer.RawLog)

Example 5 with RawLog

use of io.aeron.driver.buffer.RawLog in project aeron by real-logic.

the class DriverConductorTest method shouldTimeoutPublicationWithNoKeepaliveButNotDrained.

@Test
public void shouldTimeoutPublicationWithNoKeepaliveButNotDrained() {
    driverProxy.addPublication(CHANNEL_4000, STREAM_ID_1);
    driverConductor.doWork();
    final ArgumentCaptor<NetworkPublication> captor = ArgumentCaptor.forClass(NetworkPublication.class);
    verify(senderProxy, times(1)).newNetworkPublication(captor.capture());
    final NetworkPublication publication = captor.getValue();
    final int termId = 101;
    final int index = LogBufferDescriptor.indexByTerm(termId, termId);
    final RawLog rawLog = publication.rawLog();
    LogBufferDescriptor.rawTail(rawLog.metaData(), index, LogBufferDescriptor.packTail(termId, 0));
    final TermAppender appender = new TermAppender(rawLog.termBuffers()[index], rawLog.metaData(), index);
    final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[256]);
    final HeaderWriter headerWriter = HeaderWriter.newInstance(createDefaultHeader(SESSION_ID, STREAM_ID_1, termId));
    final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
    when(msg.consumptionTermId()).thenReturn(termId);
    when(msg.consumptionTermOffset()).thenReturn(0);
    when(msg.receiverWindowLength()).thenReturn(10);
    publication.onStatusMessage(msg, new InetSocketAddress("localhost", 4059));
    appender.appendUnfragmentedMessage(headerWriter, srcBuffer, 0, 256, null, termId);
    assertThat(publication.state(), is(NetworkPublication.State.ACTIVE));
    doWorkUntil(() -> nanoClock.nanoTime() >= CLIENT_LIVENESS_TIMEOUT_NS * 2, (timeNs) -> {
        publication.onStatusMessage(msg, new InetSocketAddress("localhost", 4059));
        publication.updateHasReceivers(timeNs);
    });
    assertThat(publication.state(), anyOf(is(NetworkPublication.State.DRAINING), is(NetworkPublication.State.LINGER)));
    final long endTime = nanoClock.nanoTime() + PUBLICATION_CONNECTION_TIMEOUT_NS + TIMER_INTERVAL_NS;
    doWorkUntil(() -> nanoClock.nanoTime() >= endTime, publication::updateHasReceivers);
    assertThat(publication.state(), anyOf(is(NetworkPublication.State.LINGER), is(NetworkPublication.State.CLOSING)));
    currentTimeNs += TIMER_INTERVAL_NS + PUBLICATION_LINGER_NS;
    driverConductor.doWork();
    assertThat(publication.state(), is(NetworkPublication.State.CLOSING));
    verify(senderProxy).removeNetworkPublication(eq(publication));
    assertNull(driverConductor.senderChannelEndpoint(UdpChannel.parse(CHANNEL_4000)));
}
Also used : StatusMessageFlyweight(io.aeron.protocol.StatusMessageFlyweight) InetSocketAddress(java.net.InetSocketAddress) RawLog(io.aeron.driver.buffer.RawLog) TermAppender(io.aeron.logbuffer.TermAppender) HeaderWriter(io.aeron.logbuffer.HeaderWriter) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) Test(org.junit.Test)

Aggregations

RawLog (io.aeron.driver.buffer.RawLog)18 ReceiveChannelEndpoint (io.aeron.driver.media.ReceiveChannelEndpoint)9 SendChannelEndpoint (io.aeron.driver.media.SendChannelEndpoint)6 InetSocketAddress (java.net.InetSocketAddress)4 InvalidChannelException (io.aeron.driver.exceptions.InvalidChannelException)3 ControlProtocolException (io.aeron.exceptions.ControlProtocolException)3 HeaderWriter (io.aeron.logbuffer.HeaderWriter)3 TermAppender (io.aeron.logbuffer.TermAppender)3 StatusMessageFlyweight (io.aeron.protocol.StatusMessageFlyweight)3 UnsafeBufferPosition (org.agrona.concurrent.status.UnsafeBufferPosition)3 UdpChannel (io.aeron.driver.media.UdpChannel)2 AtomicCounter (org.agrona.concurrent.status.AtomicCounter)2 Position (org.agrona.concurrent.status.Position)2 Test (org.junit.Test)2 Aeron (io.aeron.Aeron)1 ChannelUri (io.aeron.ChannelUri)1 SPY_QUALIFIER (io.aeron.ChannelUri.SPY_QUALIFIER)1 CommonContext (io.aeron.CommonContext)1 FORCE_TRUE (io.aeron.CommonContext.InferableBoolean.FORCE_TRUE)1 INFER (io.aeron.CommonContext.InferableBoolean.INFER)1