Search in sources :

Example 6 with Command

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

the class LegacyIndexTransactionStateImplTest method removalOfRelationshipIndexDoesNotClearNodeCommandsForNodeIndexWithSameName.

@Test
public void removalOfRelationshipIndexDoesNotClearNodeCommandsForNodeIndexWithSameName() {
    LegacyIndexTransactionStateImpl state = newLegacyIndexTxState();
    state.addNode("index", 1, "key", "value");
    state.addRelationship("index", 1, "key", "value", 11, 11);
    state.deleteIndex(IndexEntityType.Relationship, "index");
    IndexDefineCommand indexDefinedCommand = new IndexDefineCommand();
    indexDefinedCommand.getOrAssignIndexNameId("index");
    indexDefinedCommand.getOrAssignKeyId("key");
    IndexCommand.DeleteCommand delete = new IndexCommand.DeleteCommand();
    delete.init(1, IndexEntityType.Relationship.id());
    Set<Command> expectedCommands = new HashSet<>(Arrays.asList(indexDefinedCommand, delete, addNode(1, 1, 1, "value")));
    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 7 with Command

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

the class BatchingTransactionAppenderConcurrencyTest method tx.

protected TransactionToApply tx() {
    NodeRecord before = new NodeRecord(0);
    NodeRecord after = new NodeRecord(0);
    after.setInUse(true);
    Command.NodeCommand nodeCommand = new Command.NodeCommand(before, after);
    PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(asList((Command) nodeCommand));
    tx.setHeader(new byte[0], 0, 0, 0, 0, 0, 0);
    return new TransactionToApply(tx);
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) Command(org.neo4j.kernel.impl.transaction.command.Command)

Example 8 with Command

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

the class LogEntryParserDispatcherV6Test method shouldParserCommandsUsingAGivenFactory.

@Test
public void shouldParserCommandsUsingAGivenFactory() throws IOException {
    // given
    // The record, it will be used as before and after
    NodeRecord theRecord = new NodeRecord(1);
    Command.NodeCommand nodeCommand = new Command.NodeCommand(theRecord, theRecord);
    final LogEntryCommand command = new LogEntryCommand(version, nodeCommand);
    final InMemoryClosableChannel channel = new InMemoryClosableChannel();
    channel.put(NeoCommandType.NODE_COMMAND);
    channel.putLong(theRecord.getId());
    // record image before
    // not in use
    channel.put((byte) 0);
    // number of dynamic records in use
    channel.putInt(0);
    // record image after
    // not in use
    channel.put((byte) 0);
    // number of dynamic records in use
    channel.putInt(0);
    channel.getCurrentPosition(marker);
    // when
    final LogEntryParser parser = version.entryParser(LogEntryByteCodes.COMMAND);
    final LogEntry logEntry = parser.parse(version, channel, marker, commandReader);
    // then
    assertEquals(command, logEntry);
    assertFalse(parser.skip());
}
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 9 with Command

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

the class LogEntryParserV2_2Test method shouldParseCommandsUsingAGivenFactory.

@Test
public void shouldParseCommandsUsingAGivenFactory() throws IOException {
    // given
    Command.NodeCommand nodeCommand = new Command.NodeCommand(new NodeRecord(0), new NodeRecord(0));
    final LogEntryCommand command = new LogEntryCommand(version, nodeCommand);
    final InMemoryClosableChannel channel = new InMemoryClosableChannel();
    nodeCommand.serialize(channel);
    channel.getCurrentPosition(marker);
    // when
    final LogEntryParser parser = version.entryParser(LogEntryByteCodes.COMMAND);
    final LogEntry logEntry = parser.parse(version, channel, marker, commandReader);
    // then
    assertEquals(command, logEntry);
    assertFalse(parser.skip());
}
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 10 with Command

use of org.neo4j.kernel.impl.transaction.command.Command 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)

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