Search in sources :

Example 1 with LabelSchemaDescriptor

use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.

the class TxStateTest method shouldAddUniquenessConstraint.

@Test
void shouldAddUniquenessConstraint() {
    // when
    LabelSchemaDescriptor schema = forLabel(1, 17);
    UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema(schema);
    state.constraintDoAdd(constraint, IndexPrototype.uniqueForSchema(schema).withName("constraint_7").materialise(7));
    // then
    DiffSets<ConstraintDescriptor> diff = state.constraintsChangesForLabel(1);
    assertEquals(singleton(constraint), diff.getAdded());
    assertTrue(diff.getRemoved().isEmpty());
}
Also used : ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) IndexBackedConstraintDescriptor(org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 2 with LabelSchemaDescriptor

use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.

the class TxStateTest method addingUniquenessConstraintShouldBeIdempotent.

@Test
void addingUniquenessConstraintShouldBeIdempotent() {
    // given
    LabelSchemaDescriptor schema = forLabel(1, 17);
    UniquenessConstraintDescriptor constraint1 = ConstraintDescriptorFactory.uniqueForSchema(schema);
    state.constraintDoAdd(constraint1, IndexPrototype.uniqueForSchema(schema).withName("constraint_7").materialise(7));
    // when
    UniquenessConstraintDescriptor constraint2 = ConstraintDescriptorFactory.uniqueForSchema(schema);
    state.constraintDoAdd(constraint2, IndexPrototype.uniqueForSchema(schema).withName("constraint_19").materialise(19));
    // then
    assertEquals(constraint1, constraint2);
    assertEquals(singleton(constraint1), state.constraintsChangesForLabel(1).getAdded());
}
Also used : LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 3 with LabelSchemaDescriptor

use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.

the class BuiltInProceduresTest method givenIndex.

private void givenIndex(String label, String propKey) {
    int labelId = token(label, labels);
    int propId = token(propKey, propKeys);
    int id = indexes.size() + 1000;
    Map<String, Value> configMap = new HashMap<>();
    configMap.put("config1", Values.stringValue("value1"));
    configMap.put("config2", Values.intValue(2));
    configMap.put("config3", Values.booleanValue(true));
    LabelSchemaDescriptor schema = forLabel(labelId, propId);
    IndexDescriptor index = IndexPrototype.forSchema(schema, EMPTY.getProviderDescriptor()).withName("index_" + id).materialise(id).withIndexConfig(IndexConfig.with(configMap));
    indexes.add(index);
}
Also used : HashMap(java.util.HashMap) Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue) AnyValue(org.neo4j.values.AnyValue) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 4 with LabelSchemaDescriptor

use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.

the class BuiltInProceduresTest method givenUniqueConstraint.

private void givenUniqueConstraint(String label, String propKey) {
    int labelId = token(label, labels);
    int propId = token(propKey, propKeys);
    LabelSchemaDescriptor schema = forLabel(labelId, propId);
    int id = uniqueIndexes.size() + 1000;
    final String name = "constraint_" + id;
    IndexDescriptor index = IndexPrototype.uniqueForSchema(schema, EMPTY.getProviderDescriptor()).withName(name).materialise(id);
    uniqueIndexes.add(index);
    final UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForLabel(labelId, propId).withName(name);
    constraints.add(constraint);
}
Also used : LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 5 with LabelSchemaDescriptor

use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.

the class FusionIndexPopulatorTest method verifySampleToCorrectPopulator.

private void verifySampleToCorrectPopulator(Value[] values, IndexPopulator populator) {
    for (Value value : values) {
        // when
        IndexEntryUpdate<LabelSchemaDescriptor> update = add(value);
        fusionIndexPopulator.includeSample(update);
        // then
        verify(populator).includeSample(update);
        reset(populator);
    }
}
Also used : Value(org.neo4j.values.storable.Value) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor)

Aggregations

LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)63 Test (org.junit.jupiter.api.Test)41 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)24 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)16 SchemaWrite (org.neo4j.internal.kernel.api.SchemaWrite)5 UniquenessConstraintDescriptor (org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor)5 Value (org.neo4j.values.storable.Value)5 Transaction (org.neo4j.graphdb.Transaction)4 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)4 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)4 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)4 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 RepeatedTest (org.junit.jupiter.api.RepeatedTest)3 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)3 Node (org.neo4j.graphdb.Node)3 TokenRead (org.neo4j.internal.kernel.api.TokenRead)3 TokenWrite (org.neo4j.internal.kernel.api.TokenWrite)3 IndexConfig (org.neo4j.internal.schema.IndexConfig)3