use of org.neo4j.internal.schema.SchemaRule in project neo4j by neo4j.
the class SchemaChecker method buildObligationsMap.
private void buildObligationsMap(long highId, RecordReader<SchemaRecord> reader, SchemaStorage schemaStorage, Map<Long, SchemaRecord> indexObligations, Map<Long, SchemaRecord> constraintObligations, Map<SchemaRuleKey, SchemaRecord> verifiedRulesWithRecords, CursorContext cursorContext) {
for (long id = schemaStore.getNumberOfReservedLowIds(); id < highId && !context.isCancelled(); id++) {
try {
SchemaRecord record = reader.read(id);
if (!record.inUse()) {
continue;
}
SchemaRule schemaRule = schemaStorage.loadSingleSchemaRule(id, cursorContext);
SchemaRecord previousContentRecord = verifiedRulesWithRecords.put(new SchemaRuleKey(schemaRule), record.copy());
if (previousContentRecord != null) {
reporter.forSchema(record).duplicateRuleContent(previousContentRecord);
}
if (schemaRule instanceof IndexDescriptor) {
IndexDescriptor rule = (IndexDescriptor) schemaRule;
if (rule.isUnique() && rule.getOwningConstraintId().isPresent()) {
SchemaRecord previousObligation = constraintObligations.put(rule.getOwningConstraintId().getAsLong(), record.copy());
if (previousObligation != null) {
reporter.forSchema(record).duplicateObligation(previousObligation);
}
}
} else if (schemaRule instanceof ConstraintDescriptor) {
ConstraintDescriptor rule = (ConstraintDescriptor) schemaRule;
if (rule.enforcesUniqueness()) {
SchemaRecord previousObligation = indexObligations.put(rule.asIndexBackedConstraint().ownedIndexId(), record.copy());
if (previousObligation != null) {
reporter.forSchema(record).duplicateObligation(previousObligation);
}
}
}
} catch (MalformedSchemaRuleException e) {
// This is OK, we'll report it below
}
}
}
use of org.neo4j.internal.schema.SchemaRule in project neo4j by neo4j.
the class WriteTransactionCommandOrderingTest method injectAllPossibleCommands.
private static TransactionRecordState injectAllPossibleCommands() {
RecordChangeSet recordChangeSet = mock(RecordChangeSet.class);
RecordChanges<LabelTokenRecord, Void> labelTokenChanges = mock(RecordChanges.class);
RecordChanges<RelationshipTypeTokenRecord, Void> relationshipTypeTokenChanges = mock(RecordChanges.class);
RecordChanges<PropertyKeyTokenRecord, Void> propertyKeyTokenChanges = mock(RecordChanges.class);
RecordChanges<NodeRecord, Void> nodeRecordChanges = mock(RecordChanges.class);
RecordChanges<RelationshipRecord, Void> relationshipRecordChanges = mock(RecordChanges.class);
RecordChanges<PropertyRecord, PrimitiveRecord> propertyRecordChanges = mock(RecordChanges.class);
RecordChanges<RelationshipGroupRecord, Integer> relationshipGroupChanges = mock(RecordChanges.class);
RecordChanges<SchemaRecord, SchemaRule> schemaRuleChanges = mock(RecordChanges.class);
when(recordChangeSet.getLabelTokenChanges()).thenReturn(labelTokenChanges);
when(recordChangeSet.getRelationshipTypeTokenChanges()).thenReturn(relationshipTypeTokenChanges);
when(recordChangeSet.getPropertyKeyTokenChanges()).thenReturn(propertyKeyTokenChanges);
when(recordChangeSet.getNodeRecords()).thenReturn(nodeRecordChanges);
when(recordChangeSet.getRelRecords()).thenReturn(relationshipRecordChanges);
when(recordChangeSet.getPropertyRecords()).thenReturn(propertyRecordChanges);
when(recordChangeSet.getRelGroupRecords()).thenReturn(relationshipGroupChanges);
when(recordChangeSet.getSchemaRuleChanges()).thenReturn(schemaRuleChanges);
List<RecordProxy<NodeRecord, Void>> nodeChanges = new LinkedList<>();
RecordChange<NodeRecord, Void> deletedNode = mock(RecordChange.class);
when(deletedNode.getBefore()).thenReturn(inUseNode());
when(deletedNode.forReadingLinkage()).thenReturn(missingNode());
nodeChanges.add(deletedNode);
RecordChange<NodeRecord, Void> createdNode = mock(RecordChange.class);
when(createdNode.getBefore()).thenReturn(missingNode());
when(createdNode.forReadingLinkage()).thenReturn(createdNode());
nodeChanges.add(createdNode);
RecordChange<NodeRecord, Void> updatedNode = mock(RecordChange.class);
when(updatedNode.getBefore()).thenReturn(inUseNode());
when(updatedNode.forReadingLinkage()).thenReturn(inUseNode());
nodeChanges.add(updatedNode);
when(nodeRecordChanges.changes()).thenReturn(nodeChanges);
when(nodeRecordChanges.changeSize()).thenReturn(3);
when(recordChangeSet.changeSize()).thenReturn(3);
when(labelTokenChanges.changes()).thenReturn(Collections.emptyList());
when(relationshipTypeTokenChanges.changes()).thenReturn(Collections.emptyList());
when(propertyKeyTokenChanges.changes()).thenReturn(Collections.emptyList());
when(relationshipRecordChanges.changes()).thenReturn(Collections.emptyList());
when(propertyRecordChanges.changes()).thenReturn(Collections.emptyList());
when(relationshipGroupChanges.changes()).thenReturn(Collections.emptyList());
when(schemaRuleChanges.changes()).thenReturn(Collections.emptyList());
NeoStores neoStores = mock(NeoStores.class);
NodeStore store = mock(NodeStore.class);
when(neoStores.getNodeStore()).thenReturn(store);
RelationshipGroupStore relationshipGroupStore = mock(RelationshipGroupStore.class);
when(neoStores.getRelationshipGroupStore()).thenReturn(relationshipGroupStore);
RelationshipStore relationshipStore = mock(RelationshipStore.class);
when(neoStores.getRelationshipStore()).thenReturn(relationshipStore);
return new TransactionRecordState(neoStores, mock(IntegrityValidator.class), recordChangeSet, 0, null, LockTracer.NONE, null, null, null, NULL, INSTANCE, LATEST_LOG_SERIALIZATION);
}
use of org.neo4j.internal.schema.SchemaRule in project neo4j by neo4j.
the class SchemaStoreMapificationTest method mapificationMustPreserveSchemaRulesAccurately.
@RepeatedTest(500)
void mapificationMustPreserveSchemaRulesAccurately() throws MalformedSchemaRuleException {
SchemaRule rule = RANDOM_SCHEMA.get();
Map<String, Value> mapified = SchemaStore.mapifySchemaRule(rule);
SchemaRule unmapified = SchemaStore.unmapifySchemaRule(rule.getId(), mapified);
if (!rule.equals(unmapified) || !unmapified.equals(rule)) {
fail("Mapification of schema rule was not fully reversible.\n" + "Expected: " + rule + "\n" + "But got: " + unmapified + "\n" + "Mapified rule: " + mapified);
}
}
use of org.neo4j.internal.schema.SchemaRule 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);
}
Aggregations