use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.
the class BufferBuilderTest method shouldFillBufferWithoutResizing.
@Test
public void shouldFillBufferWithoutResizing() {
final int bufferLength = 128;
final byte[] buffer = new byte[bufferLength];
Arrays.fill(buffer, (byte) 7);
final UnsafeBuffer srcBuffer = new UnsafeBuffer(buffer);
final BufferBuilder bufferBuilder = new BufferBuilder(bufferLength);
bufferBuilder.append(srcBuffer, 0, bufferLength);
final byte[] temp = new byte[bufferLength];
bufferBuilder.buffer().getBytes(0, temp, 0, bufferLength);
assertThat(bufferBuilder.limit(), is(bufferLength));
assertThat(bufferBuilder.capacity(), is(bufferLength));
assertArrayEquals(temp, buffer);
}
use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.
the class BufferBuilderTest method shouldResizeWhenBufferJustDoesNotFit.
@Test
public void shouldResizeWhenBufferJustDoesNotFit() {
final int bufferLength = 128;
final byte[] buffer = new byte[bufferLength + 1];
Arrays.fill(buffer, (byte) 7);
final UnsafeBuffer srcBuffer = new UnsafeBuffer(buffer);
final BufferBuilder bufferBuilder = new BufferBuilder(bufferLength);
bufferBuilder.append(srcBuffer, 0, buffer.length);
final byte[] temp = new byte[buffer.length];
bufferBuilder.buffer().getBytes(0, temp, 0, buffer.length);
assertThat(bufferBuilder.limit(), is(buffer.length));
assertThat(bufferBuilder.capacity(), greaterThan(bufferLength));
assertArrayEquals(temp, buffer);
}
use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.
the class BufferBuilderTest method shouldAppendTwoBuffersWithoutResizing.
@Test
public void shouldAppendTwoBuffersWithoutResizing() {
final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[INITIAL_CAPACITY]);
final byte[] bytes = "1111111122222222".getBytes(StandardCharsets.UTF_8);
srcBuffer.putBytes(0, bytes, 0, bytes.length);
bufferBuilder.append(srcBuffer, 0, bytes.length / 2);
bufferBuilder.append(srcBuffer, bytes.length / 2, bytes.length / 2);
final byte[] temp = new byte[bytes.length];
bufferBuilder.buffer().getBytes(0, temp, 0, bytes.length);
assertThat(bufferBuilder.limit(), is(bytes.length));
assertThat(bufferBuilder.capacity(), is(INITIAL_CAPACITY));
assertArrayEquals(temp, bytes);
}
use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.
the class BufferBuilderTest method shouldAppendNothingForZeroLength.
@Test
public void shouldAppendNothingForZeroLength() {
final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[INITIAL_CAPACITY]);
bufferBuilder.append(srcBuffer, 0, 0);
assertThat(bufferBuilder.limit(), is(0));
}
use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.
the class BufferBuilderTest method shouldAppendThenReset.
@Test
public void shouldAppendThenReset() {
final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[INITIAL_CAPACITY]);
bufferBuilder.append(srcBuffer, 0, srcBuffer.capacity());
assertThat(bufferBuilder.limit(), is(srcBuffer.capacity()));
bufferBuilder.reset();
assertThat(bufferBuilder.limit(), is(0));
}
Aggregations