Search in sources :

Example 1 with TermAppender

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

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

Example 3 with TermAppender

use of io.aeron.logbuffer.TermAppender in project aeron by real-logic.

the class SenderTest method setUp.

@Before
public void setUp() {
    final SendChannelEndpoint mockSendChannelEndpoint = mock(SendChannelEndpoint.class);
    when(mockSendChannelEndpoint.udpChannel()).thenReturn(udpChannel);
    when(mockSendChannelEndpoint.send(any())).thenAnswer(saveByteBufferAnswer);
    when(mockSystemCounters.get(any())).thenReturn(mock(AtomicCounter.class));
    final CachedNanoClock mockCachedNanoClock = mock(CachedNanoClock.class);
    when(mockCachedNanoClock.nanoTime()).thenAnswer((invocation) -> currentTimestamp);
    sender = new Sender(new MediaDriver.Context().cachedEpochClock(new CachedEpochClock()).cachedNanoClock(mockCachedNanoClock).controlTransportPoller(mockTransportPoller).systemCounters(mockSystemCounters).senderCommandQueue(senderCommandQueue).nanoClock(() -> currentTimestamp));
    LogBufferDescriptor.initialiseTailWithTermId(rawLog.metaData(), 0, INITIAL_TERM_ID);
    termAppenders = new TermAppender[PARTITION_COUNT];
    for (int i = 0; i < PARTITION_COUNT; i++) {
        termAppenders[i] = new TermAppender(rawLog.termBuffers()[i], rawLog.metaData(), i);
    }
    publication = new NetworkPublication(1, mockSendChannelEndpoint, () -> currentTimestamp, rawLog, mock(Position.class), new AtomicLongPosition(), new AtomicLongPosition(), SESSION_ID, STREAM_ID, INITIAL_TERM_ID, MAX_FRAME_LENGTH, mockSystemCounters, flowControl, mockRetransmitHandler, new NetworkPublicationThreadLocals(), Configuration.PUBLICATION_UNBLOCK_TIMEOUT_NS, Configuration.PUBLICATION_CONNECTION_TIMEOUT_NS, Configuration.PUBLICATION_LINGER_NS, false, false);
    senderCommandQueue.offer(new NewPublicationCmd(publication));
}
Also used : SendChannelEndpoint(io.aeron.driver.media.SendChannelEndpoint) CachedNanoClock(org.agrona.concurrent.CachedNanoClock) TermAppender(io.aeron.logbuffer.TermAppender) AtomicCounter(org.agrona.concurrent.status.AtomicCounter) CachedEpochClock(org.agrona.concurrent.CachedEpochClock) AtomicLongPosition(org.agrona.concurrent.status.AtomicLongPosition) SendChannelEndpoint(io.aeron.driver.media.SendChannelEndpoint) NewPublicationCmd(io.aeron.driver.cmd.NewPublicationCmd) Before(org.junit.Before)

Example 4 with TermAppender

use of io.aeron.logbuffer.TermAppender in project Aeron by real-logic.

the class SenderTest method setUp.

@BeforeEach
public void setUp() {
    final SendChannelEndpoint mockSendChannelEndpoint = mock(SendChannelEndpoint.class);
    when(mockSendChannelEndpoint.udpChannel()).thenReturn(udpChannel);
    when(mockSendChannelEndpoint.send(any())).thenAnswer(saveByteBufferAnswer);
    when(mockSystemCounters.get(any())).thenReturn(mock(AtomicCounter.class));
    final MediaDriver.Context ctx = new MediaDriver.Context().cachedEpochClock(new CachedEpochClock()).cachedNanoClock(nanoClock).senderCachedNanoClock(nanoClock).receiverCachedNanoClock(nanoClock).controlTransportPoller(mockTransportPoller).systemCounters(mockSystemCounters).senderCommandQueue(senderCommandQueue).nanoClock(nanoClock).errorHandler(errorHandler);
    sender = new Sender(ctx);
    LogBufferDescriptor.initialiseTailWithTermId(rawLog.metaData(), 0, INITIAL_TERM_ID);
    termAppenders = new TermAppender[PARTITION_COUNT];
    for (int i = 0; i < PARTITION_COUNT; i++) {
        termAppenders[i] = new TermAppender(rawLog.termBuffers()[i], rawLog.metaData(), i);
    }
    final PublicationParams params = new PublicationParams();
    params.entityTag = 101;
    params.mtuLength = MAX_FRAME_LENGTH;
    params.lingerTimeoutNs = Configuration.publicationLingerTimeoutNs();
    params.signalEos = true;
    publication = new NetworkPublication(1, ctx, params, mockSendChannelEndpoint, rawLog, Configuration.producerWindowLength(TERM_BUFFER_LENGTH, Configuration.publicationTermWindowLength()), new AtomicLongPosition(), new AtomicLongPosition(), new AtomicLongPosition(), new AtomicLongPosition(), mock(AtomicCounter.class), SESSION_ID, STREAM_ID, INITIAL_TERM_ID, flowControl, mockRetransmitHandler, new NetworkPublicationThreadLocals(), false);
    senderCommandQueue.offer(() -> sender.onNewNetworkPublication(publication));
}
Also used : SendChannelEndpoint(io.aeron.driver.media.SendChannelEndpoint) TermAppender(io.aeron.logbuffer.TermAppender) AtomicCounter(org.agrona.concurrent.status.AtomicCounter) CachedEpochClock(org.agrona.concurrent.CachedEpochClock) AtomicLongPosition(org.agrona.concurrent.status.AtomicLongPosition) SendChannelEndpoint(io.aeron.driver.media.SendChannelEndpoint) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with TermAppender

use of io.aeron.logbuffer.TermAppender 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);
    assertEquals(NetworkPublication.State.ACTIVE, publication.state());
    doWorkUntil(() -> nanoClock.nanoTime() >= CLIENT_LIVENESS_TIMEOUT_NS * 1.25, (timeNs) -> {
        publication.onStatusMessage(msg, new InetSocketAddress("localhost", 4059));
        publication.updateHasReceivers(timeNs);
    });
    assertThat(publication.state(), Matchers.anyOf(is(NetworkPublication.State.DRAINING), is(NetworkPublication.State.LINGER)));
    final long endTime = nanoClock.nanoTime() + publicationConnectionTimeoutNs() + DEFAULT_TIMER_INTERVAL_NS;
    doWorkUntil(() -> nanoClock.nanoTime() >= endTime, publication::updateHasReceivers);
    assertThat(publication.state(), Matchers.anyOf(is(NetworkPublication.State.LINGER), is(NetworkPublication.State.DONE)));
    nanoClock.advance(DEFAULT_TIMER_INTERVAL_NS + PUBLICATION_LINGER_TIMEOUT_NS);
    driverConductor.doWork();
    assertEquals(NetworkPublication.State.DONE, publication.state());
    verify(senderProxy).removeNetworkPublication(eq(publication));
    verify(senderProxy).registerSendChannelEndpoint(any());
}
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.jupiter.api.Test)

Aggregations

TermAppender (io.aeron.logbuffer.TermAppender)5 RawLog (io.aeron.driver.buffer.RawLog)3 ReceiveChannelEndpoint (io.aeron.driver.media.ReceiveChannelEndpoint)3 HeaderWriter (io.aeron.logbuffer.HeaderWriter)3 StatusMessageFlyweight (io.aeron.protocol.StatusMessageFlyweight)3 InetSocketAddress (java.net.InetSocketAddress)3 SendChannelEndpoint (io.aeron.driver.media.SendChannelEndpoint)2 CachedEpochClock (org.agrona.concurrent.CachedEpochClock)2 AtomicCounter (org.agrona.concurrent.status.AtomicCounter)2 AtomicLongPosition (org.agrona.concurrent.status.AtomicLongPosition)2 Test (org.junit.Test)2 NewPublicationCmd (io.aeron.driver.cmd.NewPublicationCmd)1 CachedNanoClock (org.agrona.concurrent.CachedNanoClock)1 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)1 Before (org.junit.Before)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1