Search in sources :

Example 16 with PropertyCommand

use of org.neo4j.internal.recordstorage.Command.PropertyCommand in project neo4j by neo4j.

the class TransactionRecordStateTest method settingSchemaRulePropertyMustUpdateSchemaRecordIfChainHeadChanges.

@Test
void settingSchemaRulePropertyMustUpdateSchemaRecordIfChainHeadChanges() throws Exception {
    neoStores = createStores();
    TransactionRecordState state = newTransactionRecordState();
    long ruleId = neoStores.getSchemaStore().nextId(NULL);
    IndexDescriptor rule = IndexPrototype.forSchema(forLabel(0, 1)).withName("index_" + ruleId).materialise(ruleId);
    state.schemaRuleCreate(ruleId, false, rule);
    apply(state);
    state = newTransactionRecordState();
    state.schemaRuleSetProperty(ruleId, 42, Values.booleanValue(true), rule);
    List<StorageCommand> commands = new ArrayList<>();
    state.extractCommands(commands, INSTANCE);
    assertThat(commands.size()).isEqualTo(2);
    // Order matters. Props added before schema.
    PropertyCommand propCmd = (PropertyCommand) commands.get(0);
    assertThat(propCmd.getSchemaRuleId()).isEqualTo(ruleId);
    assertThat(propCmd.getBefore().inUse()).isEqualTo(false);
    assertThat(propCmd.getAfter().inUse()).isEqualTo(true);
    assertThat(propCmd.getAfter().isCreated()).isEqualTo(true);
    assertThat(propCmd.getAfter().getSchemaRuleId()).isEqualTo(ruleId);
    SchemaRuleCommand schemaCmd = (SchemaRuleCommand) commands.get(1);
    assertThat(schemaCmd.getSchemaRule()).isEqualTo(rule);
    assertThat(schemaCmd.getBefore().inUse()).isEqualTo(true);
    assertThat(schemaCmd.getBefore().getNextProp()).isEqualTo(Record.NO_NEXT_PROPERTY.longValue());
    assertThat(schemaCmd.getAfter().inUse()).isEqualTo(true);
    assertThat(schemaCmd.getAfter().isCreated()).isEqualTo(false);
    assertThat(schemaCmd.getAfter().getNextProp()).isEqualTo(propCmd.getKey());
    apply(transaction(commands));
    state = newTransactionRecordState();
    state.schemaRuleSetProperty(ruleId, 42, Values.booleanValue(false), rule);
    commands.clear();
    state.extractCommands(commands, INSTANCE);
    assertThat(commands.size()).isEqualTo(1);
    propCmd = (PropertyCommand) commands.get(0);
    assertThat(propCmd.getSchemaRuleId()).isEqualTo(ruleId);
    assertThat(propCmd.getBefore().inUse()).isEqualTo(true);
    assertThat(propCmd.getAfter().inUse()).isEqualTo(true);
    assertThat(propCmd.getAfter().isCreated()).isEqualTo(false);
}
Also used : SchemaRuleCommand(org.neo4j.internal.recordstorage.Command.SchemaRuleCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) Test(org.junit.jupiter.api.Test)

Aggregations

PropertyCommand (org.neo4j.internal.recordstorage.Command.PropertyCommand)16 Test (org.junit.jupiter.api.Test)10 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)8 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)7 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)6 ArrayList (java.util.ArrayList)5 StorageCommand (org.neo4j.storageengine.api.StorageCommand)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 NodeCommand (org.neo4j.internal.recordstorage.Command.NodeCommand)4 SchemaRuleCommand (org.neo4j.internal.recordstorage.Command.SchemaRuleCommand)4 Value (org.neo4j.values.storable.Value)4 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)3 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)2 PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)2 IndexEntryUpdate (org.neo4j.storageengine.api.IndexEntryUpdate)2 BaseCommand (org.neo4j.internal.recordstorage.Command.BaseCommand)1 FulltextSchemaDescriptor (org.neo4j.internal.schema.FulltextSchemaDescriptor)1 CommandsToApply (org.neo4j.storageengine.api.CommandsToApply)1