Search in sources :

Example 16 with BlockLogBuffer

use of org.neo4j.com.BlockLogBuffer in project graphdb by neo4j-attic.

the class TestBlockLogBuffer method onlyOneNonFullBlock.

@Test
public void onlyOneNonFullBlock() throws IOException {
    byte[] bytes = new byte[255];
    ChannelBuffer wrappedBuffer = ChannelBuffers.wrappedBuffer(bytes);
    wrappedBuffer.resetWriterIndex();
    BlockLogBuffer buffer = new BlockLogBuffer(wrappedBuffer);
    byte byteValue = 5;
    int intValue = 1234;
    long longValue = 574853;
    float floatValue = 304985.5f;
    double doubleValue = 48493.22d;
    final byte[] bytesValue = new byte[] { 1, 5, 2, 6, 3 };
    final char[] charsValue = "This is chars".toCharArray();
    buffer.put(byteValue);
    buffer.putInt(intValue);
    buffer.putLong(longValue);
    buffer.putFloat(floatValue);
    buffer.putDouble(doubleValue);
    buffer.put(bytesValue);
    buffer.put(charsValue);
    buffer.done();
    ByteBuffer verificationBuffer = ByteBuffer.wrap(bytes);
    assertEquals(56, verificationBuffer.get());
    assertEquals(byteValue, verificationBuffer.get());
    assertEquals(intValue, verificationBuffer.getInt());
    assertEquals(longValue, verificationBuffer.getLong());
    assertEquals(floatValue, verificationBuffer.getFloat(), 0.0);
    assertEquals(doubleValue, verificationBuffer.getDouble(), 0.0);
    byte[] actualBytes = new byte[bytesValue.length];
    verificationBuffer.get(actualBytes);
    assertThat(actualBytes, new ArrayMatches<byte[]>(bytesValue));
    char[] actualChars = new char[charsValue.length];
    verificationBuffer.asCharBuffer().get(actualChars);
    assertThat(actualChars, new ArrayMatches<char[]>(charsValue));
}
Also used : BlockLogBuffer(org.neo4j.com.BlockLogBuffer) ByteBuffer(java.nio.ByteBuffer) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 17 with BlockLogBuffer

use of org.neo4j.com.BlockLogBuffer in project graphdb by neo4j-attic.

the class TestBlockLogBuffer method readSmallPortions.

@Test
public void readSmallPortions() throws IOException {
    byte[] bytes = new byte[255];
    ChannelBuffer wrappedBuffer = ChannelBuffers.wrappedBuffer(bytes);
    wrappedBuffer.resetWriterIndex();
    BlockLogBuffer buffer = new BlockLogBuffer(wrappedBuffer);
    byte byteValue = 5;
    int intValue = 1234;
    long longValue = 574853;
    buffer.put(byteValue);
    buffer.putInt(intValue);
    buffer.putLong(longValue);
    buffer.done();
    ReadableByteChannel reader = new BlockLogReader(wrappedBuffer);
    ByteBuffer verificationBuffer = ByteBuffer.wrap(new byte[1]);
    reader.read(verificationBuffer);
    verificationBuffer.flip();
    assertEquals(byteValue, verificationBuffer.get());
    verificationBuffer = ByteBuffer.wrap(new byte[4]);
    reader.read(verificationBuffer);
    verificationBuffer.flip();
    assertEquals(intValue, verificationBuffer.getInt());
    verificationBuffer = ByteBuffer.wrap(new byte[8]);
    reader.read(verificationBuffer);
    verificationBuffer.flip();
    assertEquals(longValue, verificationBuffer.getLong());
}
Also used : ReadableByteChannel(java.nio.channels.ReadableByteChannel) BlockLogBuffer(org.neo4j.com.BlockLogBuffer) BlockLogReader(org.neo4j.com.BlockLogReader) ByteBuffer(java.nio.ByteBuffer) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Aggregations

BlockLogBuffer (org.neo4j.com.BlockLogBuffer)17 ByteBuffer (java.nio.ByteBuffer)16 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)16 Test (org.junit.Test)16 BlockLogReader (org.neo4j.com.BlockLogReader)8 ByteCounterMonitor (org.neo4j.kernel.monitoring.ByteCounterMonitor)8 Monitors (org.neo4j.kernel.monitoring.Monitors)8 ReadableByteChannel (java.nio.channels.ReadableByteChannel)6