use of io.aeron.protocol.StatusMessageFlyweight 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.protocol.StatusMessageFlyweight in project Aeron by real-logic.
the class SenderTest method shouldBeAbleToSendOnChannelTwice.
@Test
public void shouldBeAbleToSendOnChannelTwice() throws Exception {
final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
when(msg.consumptionTermId()).thenReturn(INITIAL_TERM_ID);
when(msg.consumptionTermOffset()).thenReturn(0);
when(msg.receiverWindowLength()).thenReturn(2 * ALIGNED_FRAME_LENGTH);
publication.onStatusMessage(msg, rcvAddress);
// publication.senderPositionLimit(
// flowControl.onStatusMessage(INITIAL_TERM_ID, 0, (2 * ALIGNED_FRAME_LENGTH), rcvAddress));
final UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(PAYLOAD.length));
buffer.putBytes(0, PAYLOAD);
termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null);
sender.doWork();
termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null);
sender.doWork();
assertThat(receivedFrames.size(), is(3));
setupHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));
assertThat(setupHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_SETUP));
dataHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));
assertThat(dataHeader.frameLength(), is(FRAME_LENGTH));
assertThat(dataHeader.termId(), is(INITIAL_TERM_ID));
assertThat(dataHeader.streamId(), is(STREAM_ID));
assertThat(dataHeader.sessionId(), is(SESSION_ID));
assertThat(dataHeader.termOffset(), is(offsetOfMessage(1)));
assertThat(dataHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_DATA));
assertThat(dataHeader.flags(), is(DataHeaderFlyweight.BEGIN_AND_END_FLAGS));
assertThat(dataHeader.version(), is((short) HeaderFlyweight.CURRENT_VERSION));
dataHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));
assertThat(dataHeader.frameLength(), is(FRAME_LENGTH));
assertThat(dataHeader.termId(), is(INITIAL_TERM_ID));
assertThat(dataHeader.streamId(), is(STREAM_ID));
assertThat(dataHeader.sessionId(), is(SESSION_ID));
assertThat(dataHeader.termOffset(), is(offsetOfMessage(2)));
assertThat(dataHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_DATA));
assertThat(dataHeader.flags(), is(DataHeaderFlyweight.BEGIN_AND_END_FLAGS));
assertThat(dataHeader.version(), is((short) HeaderFlyweight.CURRENT_VERSION));
}
use of io.aeron.protocol.StatusMessageFlyweight in project Aeron by real-logic.
the class SenderTest method shouldSendLastDataFrameAsHeartbeatWhenIdle.
@Test
public void shouldSendLastDataFrameAsHeartbeatWhenIdle() throws Exception {
final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
when(msg.consumptionTermId()).thenReturn(INITIAL_TERM_ID);
when(msg.consumptionTermOffset()).thenReturn(0);
when(msg.receiverWindowLength()).thenReturn(ALIGNED_FRAME_LENGTH);
publication.onStatusMessage(msg, rcvAddress);
// publication.senderPositionLimit(
// flowControl.onStatusMessage(INITIAL_TERM_ID, 0, ALIGNED_FRAME_LENGTH, rcvAddress));
final UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(PAYLOAD.length));
buffer.putBytes(0, PAYLOAD);
termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null);
sender.doWork();
// should send ticks
assertThat(receivedFrames.size(), is(2));
// skip setup & data frame
receivedFrames.remove();
receivedFrames.remove();
currentTimestamp += Configuration.PUBLICATION_HEARTBEAT_TIMEOUT_NS - 1;
sender.doWork();
// should not send yet
assertThat(receivedFrames.size(), is(0));
currentTimestamp += 10;
sender.doWork();
// should send ticks
assertThat(receivedFrames.size(), greaterThanOrEqualTo(1));
dataHeader.wrap(receivedFrames.remove());
assertThat(dataHeader.frameLength(), is(0));
assertThat(dataHeader.termOffset(), is(offsetOfMessage(2)));
}
use of io.aeron.protocol.StatusMessageFlyweight in project Aeron by real-logic.
the class SenderTest method shouldNotBeAbleToSendAfterUsingUpYourWindow.
@Test
public void shouldNotBeAbleToSendAfterUsingUpYourWindow() throws Exception {
final UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(PAYLOAD.length));
buffer.putBytes(0, PAYLOAD);
termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null);
final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
when(msg.consumptionTermId()).thenReturn(INITIAL_TERM_ID);
when(msg.consumptionTermOffset()).thenReturn(0);
when(msg.receiverWindowLength()).thenReturn(ALIGNED_FRAME_LENGTH);
publication.onStatusMessage(msg, rcvAddress);
// publication.senderPositionLimit(
// flowControl.onStatusMessage(INITIAL_TERM_ID, 0, ALIGNED_FRAME_LENGTH, rcvAddress));
sender.doWork();
assertThat(receivedFrames.size(), is(2));
// skip setup
receivedFrames.remove();
dataHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));
assertThat(dataHeader.frameLength(), is(FRAME_LENGTH));
assertThat(dataHeader.termId(), is(INITIAL_TERM_ID));
assertThat(dataHeader.streamId(), is(STREAM_ID));
assertThat(dataHeader.sessionId(), is(SESSION_ID));
assertThat(dataHeader.termOffset(), is(offsetOfMessage(1)));
assertThat(dataHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_DATA));
assertThat(dataHeader.flags(), is(DataHeaderFlyweight.BEGIN_AND_END_FLAGS));
assertThat(dataHeader.version(), is((short) HeaderFlyweight.CURRENT_VERSION));
termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null);
sender.doWork();
assertThat(receivedFrames.size(), is(0));
}
use of io.aeron.protocol.StatusMessageFlyweight in project Aeron by real-logic.
the class SenderTest method shouldSendMultipleDataFramesAsHeartbeatsWhenIdle.
@Test
public void shouldSendMultipleDataFramesAsHeartbeatsWhenIdle() {
final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
when(msg.consumptionTermId()).thenReturn(INITIAL_TERM_ID);
when(msg.consumptionTermOffset()).thenReturn(0);
when(msg.receiverWindowLength()).thenReturn(ALIGNED_FRAME_LENGTH);
publication.onStatusMessage(msg, rcvAddress);
// publication.senderPositionLimit(
// flowControl.onStatusMessage(INITIAL_TERM_ID, 0, ALIGNED_FRAME_LENGTH, rcvAddress));
final UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(PAYLOAD.length));
buffer.putBytes(0, PAYLOAD);
termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null);
sender.doWork();
// should send ticks
assertThat(receivedFrames.size(), is(2));
receivedFrames.remove();
// skip setup & data frame
receivedFrames.remove();
currentTimestamp += Configuration.PUBLICATION_HEARTBEAT_TIMEOUT_NS - 1;
sender.doWork();
// should not send yet
assertThat(receivedFrames.size(), is(0));
currentTimestamp += 10;
sender.doWork();
// should send ticks
assertThat(receivedFrames.size(), greaterThanOrEqualTo(1));
dataHeader.wrap(receivedFrames.remove());
assertThat(dataHeader.frameLength(), is(0));
assertThat(dataHeader.termOffset(), is(offsetOfMessage(2)));
currentTimestamp += Configuration.PUBLICATION_HEARTBEAT_TIMEOUT_NS - 1;
sender.doWork();
// should not send yet
assertThat(receivedFrames.size(), is(0));
currentTimestamp += 10;
sender.doWork();
// should send ticks
assertThat(receivedFrames.size(), greaterThanOrEqualTo(1));
dataHeader.wrap(receivedFrames.remove());
assertThat(dataHeader.frameLength(), is(0));
assertThat(dataHeader.termOffset(), is(offsetOfMessage(2)));
}
Aggregations