Search in sources :

Example 96 with ConstraintDescriptor

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

the class SchemaStatementProcedureTest method schemaStatementsShouldHandleConstraintWithBackticks.

@Test
void schemaStatementsShouldHandleConstraintWithBackticks() throws IndexNotFoundKernelException, ProcedureException, LabelNotFoundKernelException, PropertyKeyIdNotFoundKernelException {
    ConstraintDescriptor constraint = ConstraintDescriptorFactory.existsForSchema(forLabel(1, 1)).withName(NAME_WITH_BACKTICKS);
    SchemaReadCore schemaReadCore = getSchemaReadCore(constraint);
    TokenRead tokenRead = mock(TokenRead.class);
    when(tokenRead.nodeLabelName(1)).thenReturn(LABEL_WITH_BACKTICKS);
    when(tokenRead.propertyKeyName(1)).thenReturn(PROPERTY_KEY_WITH_BACKTICKS);
    Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
    Iterator<BuiltInProcedures.SchemaStatementResult> iter = result.iterator();
    assertTrue(iter.hasNext());
    BuiltInProcedures.SchemaStatementResult next = iter.next();
    assertEquals(NAME_WITH_BACKTICKS, next.name);
    assertEquals(format("CREATE CONSTRAINT %s ON (a:%s) ASSERT (a.%s) IS NOT NULL", ESCAPED_NAME_WITH_BACKTICKS, ESCAPED_LABEL_WITH_BACKTICKS, ESCAPED_PROPERTY_KEY_WITH_BACKTICKS), next.createStatement);
    assertEquals(format("DROP CONSTRAINT %s", ESCAPED_NAME_WITH_BACKTICKS), next.dropStatement);
    assertEquals(NAME_WITH_BACKTICKS, next.name);
    assertFalse(iter.hasNext());
}
Also used : ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) TokenRead(org.neo4j.internal.kernel.api.TokenRead) Test(org.junit.jupiter.api.Test)

Example 97 with ConstraintDescriptor

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

the class SchemaStatementProcedureTest method schemaStatementsMustOnlyIncludeIndexBackedConstraintNotActualIndex.

@Test
void schemaStatementsMustOnlyIncludeIndexBackedConstraintNotActualIndex() throws IndexNotFoundKernelException, ProcedureException {
    IndexDescriptor index = someOrphanedIndex();
    ConstraintDescriptor constraint = indexBackedConstraint(index);
    index = indexBoundToConstraint(index, constraint);
    InternalIndexState internalIndexState = InternalIndexState.ONLINE;
    SchemaReadCore schemaReadCore = getSchemaReadCore(constraint, index, internalIndexState);
    TokenRead tokenRead = mock(TokenRead.class);
    Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
    Iterator<BuiltInProcedures.SchemaStatementResult> iter = result.iterator();
    assertTrue(iter.hasNext());
    BuiltInProcedures.SchemaStatementResult next = iter.next();
    assertEquals(SchemaStatementProcedure.SchemaRuleType.CONSTRAINT.name(), next.type);
    assertEquals(CONSTRAINT_NAME, next.name);
    assertFalse(iter.hasNext());
}
Also used : InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) TokenRead(org.neo4j.internal.kernel.api.TokenRead) Test(org.junit.jupiter.api.Test)

Example 98 with ConstraintDescriptor

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

the class TxStateTest method shouldDropRelationshipPropertyExistenceConstraint.

@Test
void shouldDropRelationshipPropertyExistenceConstraint() {
    // Given
    ConstraintDescriptor constraint = ConstraintDescriptorFactory.existsForRelType(1, 42);
    state.constraintDoAdd(constraint);
    // When
    state.constraintDoDrop(constraint);
    // Then
    assertTrue(state.constraintsChangesForRelationshipType(1).isEmpty());
}
Also used : ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) IndexBackedConstraintDescriptor(org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 99 with ConstraintDescriptor

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

the class TxStateTest method addingRelationshipPropertyExistenceConstraintConstraintShouldBeIdempotent.

@Test
void addingRelationshipPropertyExistenceConstraintConstraintShouldBeIdempotent() {
    // Given
    ConstraintDescriptor constraint1 = ConstraintDescriptorFactory.existsForRelType(1, 42);
    ConstraintDescriptor constraint2 = ConstraintDescriptorFactory.existsForRelType(1, 42);
    // When
    state.constraintDoAdd(constraint1);
    state.constraintDoAdd(constraint2);
    // Then
    assertEquals(constraint1, constraint2);
    assertEquals(singleton(constraint1), state.constraintsChangesForRelationshipType(1).getAdded());
}
Also used : ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) IndexBackedConstraintDescriptor(org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 100 with ConstraintDescriptor

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

the class TxStateTest method shouldDifferentiateRelationshipPropertyExistenceConstraints.

@Test
void shouldDifferentiateRelationshipPropertyExistenceConstraints() {
    // Given
    ConstraintDescriptor constraint1 = ConstraintDescriptorFactory.existsForRelType(1, 11);
    ConstraintDescriptor constraint2 = ConstraintDescriptorFactory.existsForRelType(1, 22);
    ConstraintDescriptor constraint3 = ConstraintDescriptorFactory.existsForRelType(3, 33);
    // When
    state.constraintDoAdd(constraint1);
    state.constraintDoAdd(constraint2);
    state.constraintDoAdd(constraint3);
    // Then
    assertEquals(asSet(constraint1, constraint2), state.constraintsChangesForRelationshipType(1).getAdded());
    assertEquals(singleton(constraint1), state.constraintsChangesForSchema(constraint1.schema()).getAdded());
    assertEquals(singleton(constraint2), state.constraintsChangesForSchema(constraint2.schema()).getAdded());
    assertEquals(singleton(constraint3), state.constraintsChangesForRelationshipType(3).getAdded());
    assertEquals(singleton(constraint3), state.constraintsChangesForSchema(constraint3.schema()).getAdded());
}
Also used : ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) IndexBackedConstraintDescriptor(org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor) RepeatedTest(org.junit.jupiter.api.RepeatedTest) 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