use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaCacheTest method shouldRemoveConstraints.
@Test
void shouldRemoveConstraints() {
// GIVEN
SchemaCache cache = newSchemaCache();
cache.addSchemaRule(uniquenessConstraint(0L, 1, 2, 133L));
cache.addSchemaRule(uniquenessConstraint(1L, 3, 4, 133L));
// WHEN
cache.removeSchemaRule(0L);
// THEN
ConstraintDescriptor dropped = uniqueForLabel(1, 1);
ConstraintDescriptor unique = uniqueForLabel(3, 4);
assertEquals(asSet(unique), Iterables.asSet(cache.constraints()));
assertEquals(asSet(), asSet(cache.constraintsForLabel(1)));
assertEquals(asSet(), asSet(cache.constraintsForSchema(dropped.schema())));
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaCacheTest method shouldFindConstraintAndIndexByName.
@Test
void shouldFindConstraintAndIndexByName() {
IndexDescriptor index = IndexPrototype.uniqueForSchema(forLabel(2, 3)).withName("schema name").materialise(1);
ConstraintDescriptor constraint = uniquenessConstraint(4, 2, 3, 1).withName("schema name");
SchemaCache cache = newSchemaCache(index, constraint);
assertEquals(index, cache.indexForName("schema name"));
assertEquals(constraint, cache.constraintForName("schema name"));
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaCacheTest method shouldListConstraints.
@Test
void shouldListConstraints() {
// GIVEN
SchemaCache cache = newSchemaCache();
// WHEN
cache.addSchemaRule(uniquenessConstraint(0L, 1, 2, 133L));
cache.addSchemaRule(uniquenessConstraint(1L, 3, 4, 133L));
cache.addSchemaRule(relPropertyExistenceConstraint(2L, 5, 6));
cache.addSchemaRule(nodePropertyExistenceConstraint(3L, 7, 8));
// THEN
ConstraintDescriptor unique1 = uniqueForLabel(1, 2);
ConstraintDescriptor unique2 = uniqueForLabel(3, 4);
ConstraintDescriptor existsRel = ConstraintDescriptorFactory.existsForRelType(5, 6);
ConstraintDescriptor existsNode = ConstraintDescriptorFactory.existsForLabel(7, 8);
assertEquals(asSet(unique1, unique2, existsRel, existsNode), Iterables.asSet(cache.constraints()));
assertEquals(asSet(unique1), asSet(cache.constraintsForLabel(1)));
assertEquals(asSet(unique1), asSet(cache.constraintsForSchema(unique1.schema())));
assertEquals(asSet(), asSet(cache.constraintsForSchema(forLabel(1, 3))));
assertEquals(asSet(existsRel), asSet(cache.constraintsForRelationshipType(5)));
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaCacheTest method shouldCompleteConfigurationOfIndexesAddedToCache.
@Test
void shouldCompleteConfigurationOfIndexesAddedToCache() {
IndexCapability capability = new IndexCapability() {
@Override
public IndexOrderCapability orderCapability(ValueCategory... valueCategories) {
return IndexOrderCapability.NONE;
}
@Override
public IndexValueCapability valueCapability(ValueCategory... valueCategories) {
return IndexValueCapability.NO;
}
};
List<IndexDescriptor> completed = new ArrayList<>();
IndexConfigCompleter completer = index -> {
completed.add(index);
return index.withIndexCapability(capability);
};
SchemaCache cache = new SchemaCache(new ConstraintSemantics(), completer);
IndexDescriptor index1 = newIndexRule(1, 2, 3);
ConstraintDescriptor constraint1 = uniquenessConstraint(2, 2, 3, 1);
IndexDescriptor index2 = newIndexRule(3, 4, 5);
ConstraintDescriptor constraint2 = uniquenessConstraint(4, 4, 5, 3);
IndexDescriptor index3 = newIndexRule(5, 5, 5);
cache.load(asList(index1, constraint1));
cache.addSchemaRule(index2);
cache.addSchemaRule(constraint2);
cache.addSchemaRule(index3);
assertEquals(List.of(index1, index2, index3), completed);
assertEquals(capability, cache.getIndex(index1.getId()).getCapability());
assertEquals(capability, cache.getIndex(index2.getId()).getCapability());
assertEquals(capability, cache.getIndex(index3.getId()).getCapability());
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaCacheTest method shouldListConstraintsForLabel.
@Test
void shouldListConstraintsForLabel() {
// Given
ConstraintDescriptor rule1 = uniquenessConstraint(0, 1, 1, 0);
ConstraintDescriptor rule2 = uniquenessConstraint(1, 2, 1, 0);
ConstraintDescriptor rule3 = nodePropertyExistenceConstraint(2, 1, 2);
SchemaCache cache = newSchemaCache();
cache.addSchemaRule(rule1);
cache.addSchemaRule(rule2);
cache.addSchemaRule(rule3);
// When
Set<ConstraintDescriptor> listed = asSet(cache.constraintsForLabel(1));
// Then
Set<ConstraintDescriptor> expected = asSet(rule1, rule3);
assertEquals(expected, listed);
}
Aggregations