Search in sources :

Example 51 with UnsafeBuffer

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);
}
Also used : UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.Test)

Example 52 with UnsafeBuffer

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);
}
Also used : UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.Test)

Example 53 with UnsafeBuffer

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);
}
Also used : UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.Test)

Example 54 with UnsafeBuffer

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));
}
Also used : UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.Test)

Example 55 with UnsafeBuffer

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));
}
Also used : UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.Test)

Aggregations

UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)78 Test (org.junit.Test)42 StatusMessageFlyweight (io.aeron.protocol.StatusMessageFlyweight)8 MediaDriver (io.aeron.driver.MediaDriver)7 MutableDirectBuffer (org.agrona.MutableDirectBuffer)6 Header (io.aeron.logbuffer.Header)5 InOrder (org.mockito.InOrder)5 MappedByteBuffer (java.nio.MappedByteBuffer)4 Theory (org.junit.experimental.theories.Theory)4 ReceiveChannelEndpoint (io.aeron.driver.media.ReceiveChannelEndpoint)3 File (java.io.File)3 Date (java.util.Date)3 DirectBuffer (org.agrona.DirectBuffer)3 Before (org.junit.Before)3 DataPoint (org.junit.experimental.theories.DataPoint)3 SendChannelEndpoint (io.aeron.driver.media.SendChannelEndpoint)2 BufferClaim (io.aeron.logbuffer.BufferClaim)2 FragmentHandler (io.aeron.logbuffer.FragmentHandler)2 PrintStream (java.io.PrintStream)2 InetSocketAddress (java.net.InetSocketAddress)2