Search in sources :

Example 61 with InMemoryClosableChannel

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

the class SchemaRuleCommandTest method shouldRecreateSchemaRuleWhenDeleteCommandReadFromDisk.

@Test
public void shouldRecreateSchemaRuleWhenDeleteCommandReadFromDisk() throws Exception {
    // GIVEN
    SchemaRecord beforeRecords = serialize(rule, id, true, true);
    SchemaRecord afterRecords = serialize(rule, id, false, false);
    SchemaRuleCommand command = new SchemaRuleCommand(beforeRecords, afterRecords, rule);
    InMemoryClosableChannel buffer = new InMemoryClosableChannel();
    when(neoStores.getSchemaStore()).thenReturn(schemaStore);
    // WHEN
    command.serialize(buffer);
    Command readCommand = reader.read(buffer);
    // THEN
    assertThat(readCommand, instanceOf(SchemaRuleCommand.class));
    assertSchemaRule((SchemaRuleCommand) readCommand);
}
Also used : SchemaRuleCommand(org.neo4j.kernel.impl.transaction.command.Command.SchemaRuleCommand) SchemaRecord(org.neo4j.kernel.impl.store.record.SchemaRecord) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) Command(org.neo4j.kernel.impl.transaction.command.Command) SchemaRuleCommand(org.neo4j.kernel.impl.transaction.command.Command.SchemaRuleCommand) Test(org.junit.Test)

Example 62 with InMemoryClosableChannel

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

the class IndexDefineCommandTest method shouldFailToWriteIndexDefineCommandIfMapIsLargerThanShort.

@Test
public void shouldFailToWriteIndexDefineCommandIfMapIsLargerThanShort() throws IOException {
    // GIVEN
    InMemoryClosableChannel channel = new InMemoryClosableChannel(1000);
    IndexDefineCommand command = mock(IndexDefineCommand.class);
    Map<String, Integer> largeMap = initMap(0xFFFF + 1);
    when(command.getIndexNameIdRange()).thenReturn(largeMap);
    when(command.getKeyIdRange()).thenReturn(largeMap);
    // WHEN
    try {
        command.serialize(channel);
        fail("Expected an AssertionError");
    } catch (AssertionError e) {
    // THEN Fine
    }
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) Test(org.junit.Test)

Example 63 with InMemoryClosableChannel

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

the class InMemoryCountsStoreSnapshotDeserializerTest method correctlyDeserializeIndexSample.

@Test
public void correctlyDeserializeIndexSample() throws IOException {
    //GIVEN
    long indexId = 1;
    serializedBytes = ByteBuffer.allocate(1000);
    InMemoryClosableChannel logChannel = new InMemoryClosableChannel(serializedBytes.array(), false);
    writeSimpleHeader(logChannel);
    logChannel.put(INDEX_SAMPLE.code);
    logChannel.putLong(indexId);
    logChannel.putLong(1);
    logChannel.putLong(1);
    //WHEN
    IndexSampleKey expectedNode = CountsKeyFactory.indexSampleKey(indexId);
    CountsSnapshot countsSnapshot = deserialize(logChannel);
    //THEN
    assertNotNull(countsSnapshot.getMap().get(expectedNode));
    assertArrayEquals(new long[] { 1, 1 }, countsSnapshot.getMap().get(expectedNode));
}
Also used : IndexSampleKey(org.neo4j.kernel.impl.store.counts.keys.IndexSampleKey) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) Test(org.junit.Test)

Example 64 with InMemoryClosableChannel

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

the class InMemoryCountsStoreSnapshotDeserializerTest method correctlyDeserializeEntityRelationship.

@Test
public void correctlyDeserializeEntityRelationship() throws IOException {
    //GIVEN
    serializedBytes = ByteBuffer.allocate(1000);
    InMemoryClosableChannel logChannel = new InMemoryClosableChannel(serializedBytes.array(), false);
    writeSimpleHeader(logChannel);
    logChannel.put(ENTITY_RELATIONSHIP.code);
    logChannel.putInt(1);
    logChannel.putInt(1);
    logChannel.putInt(1);
    logChannel.putLong(1);
    //WHEN
    RelationshipKey expectedNode = CountsKeyFactory.relationshipKey(1, 1, 1);
    CountsSnapshot countsSnapshot = deserialize(logChannel);
    //THEN
    assertNotNull(countsSnapshot.getMap().get(expectedNode));
    assertArrayEquals(new long[] { 1 }, countsSnapshot.getMap().get(expectedNode));
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) RelationshipKey(org.neo4j.kernel.impl.store.counts.keys.RelationshipKey) Test(org.junit.Test)

Example 65 with InMemoryClosableChannel

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

the class InMemoryCountsStoreSnapshotDeserializerTest method correctlyDeserializeTxId.

@Test
public void correctlyDeserializeTxId() throws IOException {
    //GIVEN
    serializedBytes = ByteBuffer.allocate(1000);
    InMemoryClosableChannel logChannel = new InMemoryClosableChannel(serializedBytes.array(), false);
    logChannel.putLong(72);
    logChannel.putInt(0);
    //WHEN
    CountsSnapshot countsSnapshot = deserialize(logChannel);
    //THEN
    assertEquals(72, countsSnapshot.getTxId());
}
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