Search in sources :

Example 51 with InMemoryClosableChannel

use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.

the class VersionAwareLogEntryReaderTest method shouldReadACheckPointLogEntry.

@Test
public void shouldReadACheckPointLogEntry() throws IOException {
    // given
    LogEntryVersion version = LogEntryVersion.CURRENT;
    final LogPosition logPosition = new LogPosition(42, 43);
    final CheckPoint checkPoint = new CheckPoint(version, logPosition);
    final InMemoryClosableChannel channel = new InMemoryClosableChannel();
    channel.put(version.byteCode());
    channel.put(LogEntryByteCodes.CHECK_POINT);
    channel.putLong(logPosition.getLogVersion());
    channel.putLong(logPosition.getByteOffset());
    // when
    final LogEntry logEntry = logEntryReader.readLogEntry(channel);
    // then
    assertEquals(checkPoint, logEntry);
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.Test)

Example 52 with InMemoryClosableChannel

use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.

the class LogHeaderReaderTest method shouldReadALongString.

@Test
public void shouldReadALongString() throws IOException {
    // given
    // build a string longer than 32k
    int stringSize = 32 * 1024 + 1;
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < stringSize; i++) {
        sb.append("x");
    }
    String lengthyString = sb.toString();
    // we need 3 more bytes for writing the string length
    InMemoryClosableChannel channel = new InMemoryClosableChannel(stringSize + 3);
    IoPrimitiveUtils.write3bLengthAndString(channel, lengthyString);
    // when
    String stringFromChannel = IoPrimitiveUtils.read3bLengthAndString(channel);
    // then
    assertEquals(lengthyString, stringFromChannel);
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) Test(org.junit.Test)

Example 53 with InMemoryClosableChannel

use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.

the class LogHeaderWriterTest method shouldWriteALogHeaderInTheGivenChannel.

@Test
public void shouldWriteALogHeaderInTheGivenChannel() throws IOException {
    // given
    final InMemoryClosableChannel channel = new InMemoryClosableChannel();
    // when
    writeLogHeader(channel, expectedLogVersion, expectedTxId);
    // then
    long encodedLogVersions = channel.getLong();
    assertEquals(encodeLogVersion(expectedLogVersion), encodedLogVersions);
    byte logFormatVersion = decodeLogFormatVersion(encodedLogVersions);
    assertEquals(CURRENT_LOG_VERSION, logFormatVersion);
    long logVersion = decodeLogVersion(encodedLogVersions);
    assertEquals(expectedLogVersion, logVersion);
    long txId = channel.getLong();
    assertEquals(expectedTxId, txId);
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) Test(org.junit.Test)

Example 54 with InMemoryClosableChannel

use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.

the class VersionAwareLogEntryReaderTest method shouldReturnNullWhenLogEntryIsEmpty.

@Test
public void shouldReturnNullWhenLogEntryIsEmpty() throws IOException {
    // given
    LogEntryVersion version = LogEntryVersion.CURRENT;
    final InMemoryClosableChannel channel = new InMemoryClosableChannel();
    channel.put(version.byteCode());
    channel.put(LogEntryByteCodes.EMPTY);
    // when
    final LogEntry logEntry = logEntryReader.readLogEntry(channel);
    // then
    assertNull(logEntry);
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) Test(org.junit.Test)

Example 55 with InMemoryClosableChannel

use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.

the class VersionAwareLogEntryReaderTest method shouldParseOldLogEntryEmptyANdReturnNull.

@Test
public void shouldParseOldLogEntryEmptyANdReturnNull() throws IOException {
    // given
    LogEntryVersion version = LogEntryVersion.V2_1;
    final InMemoryClosableChannel channel = new InMemoryClosableChannel();
    channel.put(version.byteCode());
    channel.put(LogEntryByteCodes.EMPTY);
    // when
    final LogEntry logEntry = logEntryReader.readLogEntry(channel);
    // then
    assertNull(logEntry);
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) Test(org.junit.Test)

Aggregations

InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)66 Test (org.junit.Test)63 Command (org.neo4j.kernel.impl.transaction.command.Command)8 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)5 RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)4 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)3 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)3 CommandReader (org.neo4j.storageengine.api.CommandReader)3 Before (org.junit.Before)2 AddRelationshipCommand (org.neo4j.kernel.impl.index.IndexCommand.AddRelationshipCommand)2 CountsKey (org.neo4j.kernel.impl.store.counts.keys.CountsKey)2 SchemaRecord (org.neo4j.kernel.impl.store.record.SchemaRecord)2 SchemaRuleCommand (org.neo4j.kernel.impl.transaction.command.Command.SchemaRuleCommand)2 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)1 EndOfStreamException (org.neo4j.causalclustering.messaging.EndOfStreamException)1