Search in sources :

Example 21 with Command

use of org.neo4j.kernel.impl.transaction.command.Command in project neo4j by neo4j.

the class LegacyIndexTransactionStateImplTest method tracksRelationshipCommands.

@Test
public void tracksRelationshipCommands() {
    LegacyIndexTransactionStateImpl state = newLegacyIndexTxState();
    state.removeRelationship("index1", 1, "key1", "value1");
    state.addRelationship("index1", 1, "key2", "value2", 11, 11);
    state.removeRelationship("index1", 2, "key1", "value3");
    state.addRelationship("index1", 3, "key2", "value4", 22, 22);
    state.addRelationship("index2", 4, "key1", "value5", 33, 33);
    IndexDefineCommand indexDefinedCommand = new IndexDefineCommand();
    indexDefinedCommand.getOrAssignIndexNameId("index1");
    indexDefinedCommand.getOrAssignIndexNameId("index2");
    indexDefinedCommand.getOrAssignKeyId("key1");
    indexDefinedCommand.getOrAssignKeyId("key2");
    Set<Command> expectedCommands = new HashSet<>(Arrays.asList(indexDefinedCommand, removeRelationship(1, 1, 1, "value1"), addRelationship(1, 1, 2, "value2", 11, 11), removeRelationship(1, 2, 1, "value3"), addRelationship(1, 3, 2, "value4", 22, 22), addRelationship(2, 4, 1, "value5", 33, 33)));
    assertEquals(expectedCommands, extractCommands(state));
}
Also used : IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) Command(org.neo4j.kernel.impl.transaction.command.Command) IndexCommand(org.neo4j.kernel.impl.index.IndexCommand) IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with Command

use of org.neo4j.kernel.impl.transaction.command.Command in project neo4j by neo4j.

the class LegacyIndexTransactionStateImplTest method removalOfNodeIndexDoesNotClearRelationshipCommandsForRelationshipIndexWithSameName.

@Test
public void removalOfNodeIndexDoesNotClearRelationshipCommandsForRelationshipIndexWithSameName() {
    LegacyIndexTransactionStateImpl state = newLegacyIndexTxState();
    state.addNode("index", 1, "key", "value");
    state.addRelationship("index", 1, "key", "value", 11, 11);
    state.deleteIndex(IndexEntityType.Node, "index");
    IndexDefineCommand indexDefinedCommand = new IndexDefineCommand();
    indexDefinedCommand.getOrAssignIndexNameId("index");
    indexDefinedCommand.getOrAssignKeyId("key");
    IndexCommand.DeleteCommand delete = new IndexCommand.DeleteCommand();
    delete.init(1, IndexEntityType.Node.id());
    Set<Command> expectedCommands = new HashSet<>(Arrays.asList(indexDefinedCommand, delete, addRelationship(1, 1, 1, "value", 11, 11)));
    assertEquals(expectedCommands, extractCommands(state));
}
Also used : IndexCommand(org.neo4j.kernel.impl.index.IndexCommand) IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) Command(org.neo4j.kernel.impl.transaction.command.Command) IndexCommand(org.neo4j.kernel.impl.index.IndexCommand) IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 23 with Command

use of org.neo4j.kernel.impl.transaction.command.Command in project neo4j by neo4j.

the class LegacyLogEntryReaderTest method shouldReadTheEntries.

@Test
public void shouldReadTheEntries() throws IOException {
    // given
    final LogEntry start = new LogEntryStart(0, 1, 2, 3, EMPTY_ADDITIONAL_ARRAY, UNSPECIFIED);
    NodeRecord record = new NodeRecord(42);
    final LogEntry command = new LogEntryCommand(new Command.NodeCommand(record, record));
    final LogEntry commit = new OnePhaseCommit(42, 43);
    final LogEntryReader<ReadableLogChannel> logEntryReader = mock(LogEntryReader.class);
    when(logEntryReader.readLogEntry(any(ReadableLogChannel.class))).thenReturn(new IdentifiableLogEntry(start, 1), new IdentifiableLogEntry(command, 1), new IdentifiableLogEntry(commit, 1), null);
    final LegacyLogEntryReader reader = new LegacyLogEntryReader(fs, from -> logEntryReader);
    // when
    final IOCursor<LogEntry> cursor = reader.openReadableChannel(input).other();
    // then
    assertTrue(cursor.next());
    assertEquals(start, cursor.get());
    assertTrue(cursor.next());
    assertEquals(command, cursor.get());
    assertTrue(cursor.next());
    assertEquals(commit, cursor.get());
    assertFalse(cursor.next());
    cursor.close();
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) Command(org.neo4j.kernel.impl.transaction.command.Command) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) OnePhaseCommit(org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit) IdentifiableLogEntry(org.neo4j.kernel.impl.transaction.log.entry.IdentifiableLogEntry) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) IdentifiableLogEntry(org.neo4j.kernel.impl.transaction.log.entry.IdentifiableLogEntry) Test(org.junit.Test)

Aggregations

Command (org.neo4j.kernel.impl.transaction.command.Command)23 Test (org.junit.Test)18 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)12 IndexCommand (org.neo4j.kernel.impl.index.IndexCommand)7 IndexDefineCommand (org.neo4j.kernel.impl.index.IndexDefineCommand)7 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)7 StorageCommand (org.neo4j.storageengine.api.StorageCommand)7 HashSet (java.util.HashSet)6 LogEntryCommand (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand)5 SchemaRecord (org.neo4j.kernel.impl.store.record.SchemaRecord)3 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)3 OnePhaseCommit (org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit)3 SchemaRuleCommand (org.neo4j.kernel.impl.transaction.command.Command.SchemaRuleCommand)2 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)2 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)2 File (java.io.File)1 InOrder (org.mockito.InOrder)1 ClassGuardedAdversary (org.neo4j.adversaries.ClassGuardedAdversary)1 CountingAdversary (org.neo4j.adversaries.CountingAdversary)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1