Search in sources :

Example 11 with Command

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

the class TxPullResponseEncodeDecodeTest method newCommittedTransactionRepresentation.

private CommittedTransactionRepresentation newCommittedTransactionRepresentation() {
    final long arbitraryRecordId = 27L;
    Command.NodeCommand command = new Command.NodeCommand(new NodeRecord(arbitraryRecordId), new NodeRecord(arbitraryRecordId));
    PhysicalTransactionRepresentation physicalTransactionRepresentation = new PhysicalTransactionRepresentation(asList(new LogEntryCommand(command).getXaCommand()));
    physicalTransactionRepresentation.setHeader(new byte[] {}, 0, 0, 0, 0, 0, 0);
    LogEntryStart startEntry = new LogEntryStart(0, 0, 0L, 0L, new byte[] {}, LogPosition.UNSPECIFIED);
    OnePhaseCommit commitEntry = new OnePhaseCommit(42, 0);
    return new CommittedTransactionRepresentation(startEntry, physicalTransactionRepresentation, commitEntry);
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) 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) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 12 with Command

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

the class LogEntryParserV2_1Test method shouldParseCommandsUsingAGivenFactory.

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

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

the class VersionAwareLogEntryReaderTest method shouldReadACommandLogEntry.

@Test
public void shouldReadACommandLogEntry() throws IOException {
    // given
    LogEntryVersion version = LogEntryVersion.CURRENT;
    Command.NodeCommand nodeCommand = new Command.NodeCommand(new NodeRecord(11), new NodeRecord(11));
    final LogEntryCommand command = new LogEntryCommand(version, nodeCommand);
    final InMemoryClosableChannel channel = new InMemoryClosableChannel();
    channel.put(version.byteCode());
    channel.put(LogEntryByteCodes.COMMAND);
    nodeCommand.serialize(channel);
    // when
    final LogEntry logEntry = logEntryReader.readLogEntry(channel);
    // then
    assertEquals(command, logEntry);
}
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 14 with Command

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

the class NodeCommandTest method shouldSerializeSecondaryUnitUsage.

@Test
public void shouldSerializeSecondaryUnitUsage() throws Exception {
    // Given
    // a record that is changed to include a secondary unit
    NodeRecord before = new NodeRecord(13, false, 1, 2);
    before.setInUse(true);
    before.setRequiresSecondaryUnit(false);
    // this and the previous line set the defaults, they are here for clarity
    before.setSecondaryUnitId(NO_ID);
    NodeRecord after = new NodeRecord(13, false, 1, 2);
    after.setInUse(true);
    after.setRequiresSecondaryUnit(true);
    after.setSecondaryUnitId(14L);
    Command.NodeCommand command = new Command.NodeCommand(before, after);
    // Then
    assertSerializationWorksFor(command);
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) Command(org.neo4j.kernel.impl.transaction.command.Command) Test(org.junit.Test)

Example 15 with Command

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

the class SchemaRuleCommandTest method shouldWriteSchemaRuleToLog.

@Test
public void shouldWriteSchemaRuleToLog() throws Exception {
    // GIVEN
    SchemaRecord beforeRecords = serialize(rule, id, false, false);
    SchemaRecord afterRecords = serialize(rule, id, true, true);
    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)

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