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);
}
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());
}
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);
}
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);
}
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);
}
Aggregations