Search in sources :

Example 66 with Monitors

use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.

the class TestBlockLogBuffer method readOnlyOneFullBlock.

@Test
public void readOnlyOneFullBlock() throws Exception {
    byte[] bytes = new byte[256];
    ChannelBuffer wrappedBuffer = ChannelBuffers.wrappedBuffer(bytes);
    wrappedBuffer.resetWriterIndex();
    BlockLogBuffer buffer = new BlockLogBuffer(wrappedBuffer, new Monitors().newMonitor(ByteCounterMonitor.class));
    byte[] bytesValue = new byte[255];
    bytesValue[0] = 1;
    bytesValue[254] = -1;
    buffer.put(bytesValue, bytesValue.length);
    buffer.close();
    ReadableByteChannel reader = new BlockLogReader(wrappedBuffer);
    ByteBuffer verificationBuffer = ByteBuffer.wrap(new byte[1000]);
    reader.read(verificationBuffer);
    verificationBuffer.flip();
    byte[] actualBytes = new byte[bytesValue.length];
    verificationBuffer.get(actualBytes);
    assertThat(actualBytes, new ArrayMatches<byte[]>(bytesValue));
}
Also used : ByteCounterMonitor(org.neo4j.kernel.monitoring.ByteCounterMonitor) ReadableByteChannel(java.nio.channels.ReadableByteChannel) BlockLogBuffer(org.neo4j.com.BlockLogBuffer) BlockLogReader(org.neo4j.com.BlockLogReader) Monitors(org.neo4j.kernel.monitoring.Monitors) ByteBuffer(java.nio.ByteBuffer) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 67 with Monitors

use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.

the class TestBlockLogBuffer method canReaderReallyLargeByteArray.

@Test
public void canReaderReallyLargeByteArray() throws Exception {
    byte[] bytes = new byte[650];
    ChannelBuffer wrappedBuffer = ChannelBuffers.wrappedBuffer(bytes);
    wrappedBuffer.resetWriterIndex();
    BlockLogBuffer buffer = new BlockLogBuffer(wrappedBuffer, new Monitors().newMonitor(ByteCounterMonitor.class));
    byte[] bytesValue = new byte[600];
    bytesValue[1] = 1;
    bytesValue[99] = 2;
    bytesValue[199] = 3;
    bytesValue[299] = 4;
    bytesValue[399] = 5;
    bytesValue[499] = 6;
    bytesValue[599] = 7;
    buffer.put(bytesValue, bytesValue.length);
    buffer.close();
    byte[] actual;
    BlockLogReader reader = new BlockLogReader(wrappedBuffer);
    ByteBuffer verificationBuffer = ByteBuffer.wrap(new byte[1000]);
    reader.read(verificationBuffer);
    verificationBuffer.flip();
    actual = new byte[255];
    verificationBuffer.get(actual);
    assertThat(actual, new ArrayMatches<byte[]>(Arrays.copyOfRange(bytesValue, 0, 255)));
    actual = new byte[255];
    verificationBuffer.get(actual);
    assertThat(actual, new ArrayMatches<byte[]>(Arrays.copyOfRange(bytesValue, 255, 510)));
    actual = new byte[90];
    verificationBuffer.get(actual);
    assertThat(actual, new ArrayMatches<byte[]>(Arrays.copyOfRange(bytesValue, 510, 600)));
}
Also used : ByteCounterMonitor(org.neo4j.kernel.monitoring.ByteCounterMonitor) BlockLogBuffer(org.neo4j.com.BlockLogBuffer) BlockLogReader(org.neo4j.com.BlockLogReader) Monitors(org.neo4j.kernel.monitoring.Monitors) ByteBuffer(java.nio.ByteBuffer) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 68 with Monitors

use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.

the class TestBlockLogBuffer method onlyOneFullBlock.

@Test
public void onlyOneFullBlock() throws Exception {
    byte[] bytes = new byte[256];
    ChannelBuffer wrappedBuffer = ChannelBuffers.wrappedBuffer(bytes);
    wrappedBuffer.resetWriterIndex();
    BlockLogBuffer buffer = new BlockLogBuffer(wrappedBuffer, new Monitors().newMonitor(ByteCounterMonitor.class));
    byte[] bytesValue = new byte[255];
    bytesValue[0] = 1;
    bytesValue[254] = -1;
    buffer.put(bytesValue, bytesValue.length);
    buffer.close();
    ByteBuffer verificationBuffer = ByteBuffer.wrap(bytes);
    assertEquals((byte) 255, verificationBuffer.get());
    byte[] actualBytes = new byte[bytesValue.length];
    verificationBuffer.get(actualBytes);
    assertThat(actualBytes, new ArrayMatches<byte[]>(bytesValue));
}
Also used : ByteCounterMonitor(org.neo4j.kernel.monitoring.ByteCounterMonitor) BlockLogBuffer(org.neo4j.com.BlockLogBuffer) Monitors(org.neo4j.kernel.monitoring.Monitors) ByteBuffer(java.nio.ByteBuffer) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 69 with Monitors

use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.

the class TestBlockLogBuffer method readOnlyOneNonFullBlock.

@Test
public void readOnlyOneNonFullBlock() throws IOException {
    byte[] bytes = new byte[255];
    ChannelBuffer wrappedBuffer = ChannelBuffers.wrappedBuffer(bytes);
    wrappedBuffer.resetWriterIndex();
    BlockLogBuffer buffer = new BlockLogBuffer(wrappedBuffer, new Monitors().newMonitor(ByteCounterMonitor.class));
    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 };
    buffer.put(byteValue);
    buffer.putInt(intValue);
    buffer.putLong(longValue);
    buffer.putFloat(floatValue);
    buffer.putDouble(doubleValue);
    buffer.put(bytesValue, bytesValue.length);
    buffer.close();
    ReadableByteChannel reader = new BlockLogReader(wrappedBuffer);
    ByteBuffer verificationBuffer = ByteBuffer.wrap(new byte[1000]);
    reader.read(verificationBuffer);
    verificationBuffer.flip();
    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));
}
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) ByteCounterMonitor(org.neo4j.kernel.monitoring.ByteCounterMonitor) Monitors(org.neo4j.kernel.monitoring.Monitors) Test(org.junit.Test)

Example 70 with Monitors

use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.

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, new Monitors().newMonitor(ByteCounterMonitor.class));
    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 };
    buffer.put(byteValue);
    buffer.putInt(intValue);
    buffer.putLong(longValue);
    buffer.putFloat(floatValue);
    buffer.putDouble(doubleValue);
    buffer.put(bytesValue, bytesValue.length);
    buffer.close();
    ByteBuffer verificationBuffer = ByteBuffer.wrap(bytes);
    assertEquals(30, 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));
}
Also used : ByteCounterMonitor(org.neo4j.kernel.monitoring.ByteCounterMonitor) BlockLogBuffer(org.neo4j.com.BlockLogBuffer) Monitors(org.neo4j.kernel.monitoring.Monitors) ByteBuffer(java.nio.ByteBuffer) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Aggregations

Monitors (org.neo4j.kernel.monitoring.Monitors)79 Test (org.junit.Test)53 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)12 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)11 File (java.io.File)10 ByteBuffer (java.nio.ByteBuffer)9 StoreId (org.neo4j.causalclustering.identity.StoreId)9 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)9 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)9 ByteCounterMonitor (org.neo4j.kernel.monitoring.ByteCounterMonitor)9 IOException (java.io.IOException)8 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)8 BlockLogBuffer (org.neo4j.com.BlockLogBuffer)8 Config (org.neo4j.kernel.configuration.Config)8 PageCache (org.neo4j.io.pagecache.PageCache)7 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)7 DependencyResolver (org.neo4j.graphdb.DependencyResolver)6 URI (java.net.URI)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)5