use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.
the class RawLogFactoryTest method shouldCreateCorrectLengthAndZeroedFilesForImage.
@Test
public void shouldCreateCorrectLengthAndZeroedFilesForImage() throws Exception {
final String canonicalForm = udpChannel.canonicalForm();
final int imageTermBufferMaxLength = TERM_BUFFER_LENGTH / 2;
final RawLog rawLog = rawLogFactory.newNetworkedImage(canonicalForm, SESSION_ID, STREAM_ID, CREATION_ID, imageTermBufferMaxLength);
assertThat(rawLog.termLength(), is(imageTermBufferMaxLength));
final UnsafeBuffer[] termBuffers = rawLog.termBuffers();
assertThat(termBuffers.length, is(PARTITION_COUNT));
for (final UnsafeBuffer termBuffer : termBuffers) {
assertThat(termBuffer.capacity(), is(imageTermBufferMaxLength));
assertThat(termBuffer.getByte(0), is((byte) 0));
assertThat(termBuffer.getByte(imageTermBufferMaxLength - 1), is((byte) 0));
}
final UnsafeBuffer metaData = rawLog.metaData();
assertThat(metaData.capacity(), is(LogBufferDescriptor.LOG_META_DATA_LENGTH));
assertThat(metaData.getByte(0), is((byte) 0));
assertThat(metaData.getByte(LogBufferDescriptor.LOG_META_DATA_LENGTH - 1), is((byte) 0));
rawLog.close();
}
use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.
the class RawLogFactoryTest method shouldCreateCorrectLengthAndZeroedFilesForPublication.
@Test
public void shouldCreateCorrectLengthAndZeroedFilesForPublication() throws Exception {
final String canonicalForm = udpChannel.canonicalForm();
final RawLog rawLog = rawLogFactory.newNetworkPublication(canonicalForm, SESSION_ID, STREAM_ID, CREATION_ID, TERM_BUFFER_LENGTH);
assertThat(rawLog.termLength(), is(TERM_BUFFER_LENGTH));
final UnsafeBuffer[] termBuffers = rawLog.termBuffers();
assertThat(termBuffers.length, is(PARTITION_COUNT));
for (final UnsafeBuffer termBuffer : termBuffers) {
assertThat(termBuffer.capacity(), is(TERM_BUFFER_LENGTH));
assertThat(termBuffer.getByte(0), is((byte) 0));
assertThat(termBuffer.getByte(TERM_BUFFER_LENGTH - 1), is((byte) 0));
}
final UnsafeBuffer metaData = rawLog.metaData();
assertThat(metaData.capacity(), is(LogBufferDescriptor.LOG_META_DATA_LENGTH));
assertThat(metaData.getByte(0), is((byte) 0));
assertThat(metaData.getByte(LogBufferDescriptor.LOG_META_DATA_LENGTH - 1), is((byte) 0));
rawLog.close();
}
use of org.agrona.concurrent.UnsafeBuffer 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 org.agrona.concurrent.UnsafeBuffer 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 org.agrona.concurrent.UnsafeBuffer 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));
}
Aggregations