Search in sources :

Example 36 with ConstraintDescriptor

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())));
}
Also used : ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) Test(org.junit.jupiter.api.Test)

Example 37 with ConstraintDescriptor

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"));
}
Also used : ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 38 with ConstraintDescriptor

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)));
}
Also used : ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) Test(org.junit.jupiter.api.Test)

Example 39 with ConstraintDescriptor

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());
}
Also used : IndexConfigCompleter(org.neo4j.internal.schema.IndexConfigCompleter) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) IndexCapability(org.neo4j.internal.schema.IndexCapability) MutableInt(org.apache.commons.lang3.mutable.MutableInt) SchemaRule(org.neo4j.internal.schema.SchemaRule) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) ConstraintDescriptorFactory.uniqueForLabel(org.neo4j.internal.schema.constraints.ConstraintDescriptorFactory.uniqueForLabel) ConstraintDescriptorFactory(org.neo4j.internal.schema.constraints.ConstraintDescriptorFactory) ArrayList(java.util.ArrayList) StandardConstraintRuleAccessor(org.neo4j.storageengine.api.StandardConstraintRuleAccessor) IndexConfigCompleter(org.neo4j.internal.schema.IndexConfigCompleter) Collections.singleton(java.util.Collections.singleton) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) SchemaDescriptor.forLabel(org.neo4j.internal.schema.SchemaDescriptor.forLabel) Iterables(org.neo4j.internal.helpers.collection.Iterables) Arrays.asList(java.util.Arrays.asList) SchemaDescriptor.forRelType(org.neo4j.internal.schema.SchemaDescriptor.forRelType) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SchemaDescriptor.fulltext(org.neo4j.internal.schema.SchemaDescriptor.fulltext) Iterator(java.util.Iterator) Iterators(org.neo4j.internal.helpers.collection.Iterators) ConstraintType(org.neo4j.internal.schema.ConstraintType) IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability) Set(java.util.Set) ValueCategory(org.neo4j.values.storable.ValueCategory) Iterators.single(org.neo4j.internal.helpers.collection.Iterators.single) RELATIONSHIP(org.neo4j.common.EntityType.RELATIONSHIP) Test(org.junit.jupiter.api.Test) IndexValueCapability(org.neo4j.internal.schema.IndexValueCapability) List(java.util.List) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) Iterators.asSet(org.neo4j.internal.helpers.collection.Iterators.asSet) FulltextSchemaDescriptor(org.neo4j.internal.schema.FulltextSchemaDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Collections(java.util.Collections) NODE(org.neo4j.common.EntityType.NODE) Race(org.neo4j.test.Race) ValueCategory(org.neo4j.values.storable.ValueCategory) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) IndexCapability(org.neo4j.internal.schema.IndexCapability) ArrayList(java.util.ArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 40 with ConstraintDescriptor

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);
}
Also used : ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)107 Test (org.junit.jupiter.api.Test)62 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)34 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)32 UniquenessConstraintDescriptor (org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor)26 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)21 NodeKeyConstraintDescriptor (org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor)20 IndexBackedConstraintDescriptor (org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor)19 SchemaReadCore (org.neo4j.internal.kernel.api.SchemaReadCore)16 TokenRead (org.neo4j.internal.kernel.api.TokenRead)9 ArrayList (java.util.ArrayList)8 RepeatedTest (org.junit.jupiter.api.RepeatedTest)6 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)6 SchemaStore (org.neo4j.kernel.impl.store.SchemaStore)6 InternalIndexState (org.neo4j.internal.kernel.api.InternalIndexState)5 SchemaWrite (org.neo4j.internal.kernel.api.SchemaWrite)5 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)5 SchemaRule (org.neo4j.internal.schema.SchemaRule)5 SchemaRecord (org.neo4j.kernel.impl.store.record.SchemaRecord)5 OptionalLong (java.util.OptionalLong)4