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)));
}
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)));
}
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));
}
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));
}
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());
}
Aggregations