Search in sources :

Example 16 with Command

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

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

the class TransactionApplierFacadeTest method testVisit.

@Test
public void testVisit() throws Exception {
    Command cmd = mock(Command.class);
    // WHEN
    boolean result = facade.visit(cmd);
    // THEN
    InOrder inOrder = inOrder(cmd);
    inOrder.verify(cmd).handle(txApplier1);
    inOrder.verify(cmd).handle(txApplier2);
    inOrder.verify(cmd).handle(txApplier3);
    inOrder.verifyNoMoreInteractions();
    assertFalse(result);
}
Also used : InOrder(org.mockito.InOrder) Command(org.neo4j.kernel.impl.transaction.command.Command) IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) IndexCommand(org.neo4j.kernel.impl.index.IndexCommand) Test(org.junit.Test)

Example 18 with Command

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

the class LegacyIndexTransactionStateImplTest method nodeIndexDeletionRemovesCommands.

@Test
public void nodeIndexDeletionRemovesCommands() {
    LegacyIndexTransactionStateImpl state = newLegacyIndexTxState();
    state.addNode("index", 1, "key", "value1");
    state.addNode("index", 2, "key", "value2");
    state.removeNode("index", 3, "key", "value3");
    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));
    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 19 with Command

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

the class LegacyIndexTransactionStateImplTest method tracksNodeCommands.

@Test
public void tracksNodeCommands() {
    LegacyIndexTransactionStateImpl state = newLegacyIndexTxState();
    state.addNode("index1", 1, "key1", "value1");
    state.removeNode("index1", 1, "key2", "value2");
    state.addNode("index1", 2, "key1", "value3");
    state.addNode("index1", 3, "key2", "value4");
    state.removeNode("index2", 4, "key1", "value5");
    IndexDefineCommand indexDefinedCommand = new IndexDefineCommand();
    indexDefinedCommand.getOrAssignIndexNameId("index1");
    indexDefinedCommand.getOrAssignIndexNameId("index2");
    indexDefinedCommand.getOrAssignKeyId("key1");
    indexDefinedCommand.getOrAssignKeyId("key2");
    Set<Command> expectedCommands = new HashSet<>(Arrays.asList(indexDefinedCommand, addNode(1, 1, 1, "value1"), removeNode(1, 1, 2, "value2"), addNode(1, 2, 1, "value3"), addNode(1, 3, 2, "value4"), removeNode(2, 4, 1, "value5")));
    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 20 with Command

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

the class LegacyIndexTransactionStateImplTest method relationshipIndexDeletionRemovesCommands.

@Test
public void relationshipIndexDeletionRemovesCommands() {
    LegacyIndexTransactionStateImpl state = newLegacyIndexTxState();
    state.removeRelationship("index", 1, "key", "value1");
    state.addRelationship("index", 2, "key", "value2", 11, 11);
    state.addRelationship("index", 3, "key", "value3", 22, 22);
    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));
    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)

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