Search in sources :

Example 11 with SchemaRuleCommand

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

the class SchemaRuleCommandTest method writeAndReadOfArbitrarySchemaRules.

@SuppressWarnings("OptionalGetWithoutIsPresent")
@RepeatedTest(1000)
void writeAndReadOfArbitrarySchemaRules() throws Exception {
    RandomSchema randomSchema = new RandomSchema();
    SchemaRule rule = randomSchema.schemaRules().filter(indexBackedConstraintsWithoutIndexes()).findFirst().get();
    long ruleId = rule.getId();
    SchemaRecord before = new SchemaRecord(ruleId).initialize(false, NO_NEXT_PROPERTY.longValue());
    SchemaRecord after = new SchemaRecord(ruleId).initialize(true, 42);
    after.setCreated();
    SchemaRuleCommand command = new SchemaRuleCommand(serialization, before, after, rule);
    InMemoryClosableChannel buffer = new InMemoryClosableChannel((int) ByteUnit.kibiBytes(5));
    when(neoStores.getSchemaStore()).thenReturn(schemaStore);
    // WHEN
    command.serialize(buffer);
    SchemaRuleCommand readCommand = (SchemaRuleCommand) serialization.read(buffer);
    // THEN
    assertEquals(ruleId, readCommand.getKey());
    assertThat(readCommand.getSchemaRule()).isEqualTo(rule);
}
Also used : SchemaRuleCommand(org.neo4j.internal.recordstorage.Command.SchemaRuleCommand) SchemaRecord(org.neo4j.kernel.impl.store.record.SchemaRecord) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) SchemaRule(org.neo4j.internal.schema.SchemaRule) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 12 with SchemaRuleCommand

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

the class SchemaRuleCommandTest method shouldWriteCreatedSchemaRuleToStore.

@Test
void shouldWriteCreatedSchemaRuleToStore() throws Exception {
    // GIVEN
    SchemaRecord before = new SchemaRecord(id).initialize(false, NO_NEXT_PROPERTY.longValue());
    SchemaRecord after = new SchemaRecord(id).initialize(true, 42);
    when(neoStores.getSchemaStore()).thenReturn(schemaStore);
    // WHEN
    visitSchemaRuleCommand(storeApplier, new SchemaRuleCommand(serialization, before, after, rule));
    // THEN
    verify(schemaStore).updateRecord(eq(after), any(), any());
}
Also used : SchemaRuleCommand(org.neo4j.internal.recordstorage.Command.SchemaRuleCommand) SchemaRecord(org.neo4j.kernel.impl.store.record.SchemaRecord) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 13 with SchemaRuleCommand

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

the class SchemaRuleCommandTest method shouldWriteSchemaRuleToLog.

@Test
void shouldWriteSchemaRuleToLog() throws Exception {
    // GIVEN
    SchemaRecord before = new SchemaRecord(id).initialize(false, NO_NEXT_PROPERTY.longValue());
    SchemaRecord after = new SchemaRecord(id).initialize(true, 42);
    after.setCreated();
    SchemaRuleCommand command = new SchemaRuleCommand(serialization, before, after, rule);
    InMemoryClosableChannel buffer = new InMemoryClosableChannel();
    when(neoStores.getSchemaStore()).thenReturn(schemaStore);
    // WHEN
    command.serialize(buffer);
    Command readCommand = serialization.read(buffer);
    // THEN
    assertThat(readCommand).isInstanceOf(SchemaRuleCommand.class);
    assertSchemaRule((SchemaRuleCommand) readCommand);
}
Also used : SchemaRuleCommand(org.neo4j.internal.recordstorage.Command.SchemaRuleCommand) SchemaRecord(org.neo4j.kernel.impl.store.record.SchemaRecord) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) SchemaRuleCommand(org.neo4j.internal.recordstorage.Command.SchemaRuleCommand) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 14 with SchemaRuleCommand

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

the class TransactionRecordStateTest method deletingSchemaRuleMustAlsoDeletePropertyChain.

@Test
void deletingSchemaRuleMustAlsoDeletePropertyChain() 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);
    state.schemaRuleSetProperty(ruleId, 42, Values.booleanValue(true), rule);
    apply(state);
    state = newTransactionRecordState();
    state.schemaRuleDelete(ruleId, rule);
    List<StorageCommand> commands = new ArrayList<>();
    state.extractCommands(commands, INSTANCE);
    assertThat(commands.size()).isEqualTo(2);
    // Order matters. Rule deletes before property deletes.
    SchemaRuleCommand schemaCmd = (SchemaRuleCommand) commands.get(0);
    assertThat(schemaCmd.getKey()).isEqualTo(ruleId);
    assertThat(schemaCmd.getBefore().inUse()).isEqualTo(true);
    assertThat(schemaCmd.getAfter().inUse()).isEqualTo(false);
    PropertyCommand propCmd = (PropertyCommand) commands.get(1);
    assertThat(propCmd.getKey()).isEqualTo(schemaCmd.getBefore().getNextProp());
    assertThat(propCmd.getBefore().inUse()).isEqualTo(true);
    assertThat(propCmd.getAfter().inUse()).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)

Example 15 with SchemaRuleCommand

use of org.neo4j.internal.recordstorage.Command.SchemaRuleCommand 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

SchemaRuleCommand (org.neo4j.internal.recordstorage.Command.SchemaRuleCommand)15 Test (org.junit.jupiter.api.Test)13 SchemaRecord (org.neo4j.kernel.impl.store.record.SchemaRecord)9 RepeatedTest (org.junit.jupiter.api.RepeatedTest)8 ArrayList (java.util.ArrayList)6 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)6 StorageCommand (org.neo4j.storageengine.api.StorageCommand)6 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)5 PropertyCommand (org.neo4j.internal.recordstorage.Command.PropertyCommand)4 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)3 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)2 SchemaRule (org.neo4j.internal.schema.SchemaRule)2