Search in sources :

Example 21 with InMemoryClosableChannel

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

the class VersionAwareLogEntryReaderTest method shouldReadAStartLogEntry.

@Test
public void shouldReadAStartLogEntry() throws IOException {
    // given
    LogEntryVersion version = LogEntryVersion.CURRENT;
    final LogEntryStart start = new LogEntryStart(version, 1, 2, 3, 4, new byte[] { 5 }, new LogPosition(0, 31));
    final InMemoryClosableChannel channel = new InMemoryClosableChannel();
    // version
    channel.put(version.byteCode());
    // type
    channel.put(LogEntryByteCodes.TX_START);
    channel.putInt(start.getMasterId());
    channel.putInt(start.getLocalId());
    channel.putLong(start.getTimeWritten());
    channel.putLong(start.getLastCommittedTxWhenTransactionStarted());
    channel.putInt(start.getAdditionalHeader().length);
    channel.put(start.getAdditionalHeader(), start.getAdditionalHeader().length);
    // when
    final LogEntry logEntry = logEntryReader.readLogEntry(channel);
    // then
    assertEquals(start, logEntry);
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.Test)

Example 22 with InMemoryClosableChannel

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

the class VersionAwareLogEntryReaderTest method shouldParseAnOldCommandLogEntry.

@Test
public void shouldParseAnOldCommandLogEntry() throws IOException {
    // given
    LogEntryVersion version = LogEntryVersion.V2_1;
    Command.NodeCommand nodeCommand = new Command.NodeCommand(new NodeRecord(10), new NodeRecord(10));
    final LogEntryCommand command = new LogEntryCommand(version, nodeCommand);
    final InMemoryClosableChannel channel = new InMemoryClosableChannel();
    channel.put(version.byteCode());
    channel.put(LogEntryByteCodes.COMMAND);
    // ignored data
    // identifier ignored
    channel.putInt(42);
    // actual used data
    nodeCommand.serialize(channel);
    // when
    final LogEntry logEntry = logEntryReader.readLogEntry(channel);
    // then
    assertTrue(logEntry instanceof IdentifiableLogEntry);
    assertEquals(command, ((IdentifiableLogEntry) logEntry).getEntry());
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) Command(org.neo4j.kernel.impl.transaction.command.Command) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) Test(org.junit.Test)

Example 23 with InMemoryClosableChannel

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

the class InMemoryCountsStoreCountsSnapshotSerializerIntegrationTest method smallWorkloadOnInMemoryLogTest.

@Test
public void smallWorkloadOnInMemoryLogTest() throws IOException {
    //GIVEN
    InMemoryClosableChannel tempChannel = new InMemoryClosableChannel();
    Map<CountsKey, long[]> map = CountsStoreMapGenerator.simpleCountStoreMap(1);
    CountsSnapshot countsSnapshot = new CountsSnapshot(1, map);
    //WHEN
    serialize(tempChannel, countsSnapshot);
    CountsSnapshot recovered = deserialize(tempChannel);
    //THEN
    Assert.assertEquals(countsSnapshot.getTxId(), recovered.getTxId());
    for (Map.Entry<CountsKey, long[]> pair : countsSnapshot.getMap().entrySet()) {
        long[] value = recovered.getMap().get(pair.getKey());
        Assert.assertNotNull(value);
        Assert.assertArrayEquals(value, pair.getValue());
    }
    for (Map.Entry<CountsKey, long[]> pair : recovered.getMap().entrySet()) {
        long[] value = countsSnapshot.getMap().get(pair.getKey());
        Assert.assertNotNull(value);
        Assert.assertArrayEquals(value, pair.getValue());
    }
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) CountsKey(org.neo4j.kernel.impl.store.counts.keys.CountsKey) Map(java.util.Map) Test(org.junit.Test)

Example 24 with InMemoryClosableChannel

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

the class InMemoryCountsStoreCountsSnapshotSerializerTest method setup.

@Before
public void setup() throws IOException {
    logChannel = new InMemoryClosableChannel();
    countsSnapshot = new CountsSnapshot(1, new ConcurrentHashMap<>());
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Before(org.junit.Before)

Example 25 with InMemoryClosableChannel

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

the class InMemoryCountsStoreSnapshotDeserializerTest method correctlyDeserializeTxIdAndMapSize.

@Test
public void correctlyDeserializeTxIdAndMapSize() throws IOException {
    //GIVEN
    InMemoryCountsStore countStore = new InMemoryCountsStore();
    Map<CountsKey, long[]> updates = new HashMap<>();
    updates.put(CountsKeyFactory.nodeKey(1), new long[] { 1 });
    updates.put(CountsKeyFactory.nodeKey(2), new long[] { 1 });
    updates.put(CountsKeyFactory.nodeKey(3), new long[] { 1 });
    countStore.updateAll(1, updates);
    serializedBytes = ByteBuffer.allocate(1000);
    InMemoryClosableChannel logChannel = new InMemoryClosableChannel(serializedBytes.array(), false);
    serialize(logChannel, countStore.snapshot(1));
    //WHEN
    serializedBytes.position(8);
    //We serialized 3, but now the deserialization should only expect 2.
    serializedBytes.putInt(2);
    //THEN
    CountsSnapshot countsSnapshot = deserialize(logChannel);
    assertEquals(2, countsSnapshot.getMap().size());
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) CountsKey(org.neo4j.kernel.impl.store.counts.keys.CountsKey) 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