Search in sources :

Example 1 with HeaderWriter

use of io.aeron.logbuffer.HeaderWriter 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)

Aggregations

RawLog (io.aeron.driver.buffer.RawLog)1 ReceiveChannelEndpoint (io.aeron.driver.media.ReceiveChannelEndpoint)1 HeaderWriter (io.aeron.logbuffer.HeaderWriter)1 TermAppender (io.aeron.logbuffer.TermAppender)1 StatusMessageFlyweight (io.aeron.protocol.StatusMessageFlyweight)1 InetSocketAddress (java.net.InetSocketAddress)1 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)1 Test (org.junit.Test)1