Search in sources :

Example 16 with UniquenessConstraintDescriptor

use of org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor in project neo4j by neo4j.

the class NodePropertyExistenceConstraintCreationIT method shouldNotDropPropertyExistenceConstraintThatDoesNotExistWhenThereIsAUniquePropertyConstraint.

@Test
public void shouldNotDropPropertyExistenceConstraintThatDoesNotExistWhenThereIsAUniquePropertyConstraint() throws Exception {
    // given
    UniquenessConstraintDescriptor constraint;
    {
        SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
        constraint = statement.uniquePropertyConstraintCreate(descriptor);
        commit();
    }
    // when
    try {
        SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
        statement.constraintDrop(ConstraintDescriptorFactory.existsForSchema(constraint.schema()));
        fail("expected exception");
    }// then
     catch (DropConstraintFailureException e) {
        assertThat(e.getCause(), instanceOf(NoSuchConstraintException.class));
    } finally {
        rollback();
    }
    // then
    {
        ReadOperations statement = readOperationsInNewTransaction();
        Iterator<ConstraintDescriptor> constraints = statement.constraintsGetForSchema(descriptor);
        assertEquals(constraint, single(constraints));
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) ResourceIterator(org.neo4j.graphdb.ResourceIterator) Iterator(java.util.Iterator) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) DropConstraintFailureException(org.neo4j.kernel.api.exceptions.schema.DropConstraintFailureException) Test(org.junit.Test)

Example 17 with UniquenessConstraintDescriptor

use of org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor in project neo4j by neo4j.

the class UniquenessConstraintCreationIT method shouldDropConstraintIndexWhenDroppingConstraint.

@Test
public void shouldDropConstraintIndexWhenDroppingConstraint() throws Exception {
    // given
    Statement statement = statementInNewTransaction(SecurityContext.AUTH_DISABLED);
    UniquenessConstraintDescriptor constraint = statement.schemaWriteOperations().uniquePropertyConstraintCreate(descriptor);
    assertEquals(asSet(uniqueIndex), asSet(statement.readOperations().uniqueIndexesGetAll()));
    commit();
    // when
    SchemaWriteOperations schemaWriteOperations = schemaWriteOperationsInNewTransaction();
    schemaWriteOperations.constraintDrop(constraint);
    commit();
    // then
    ReadOperations readOperations = readOperationsInNewTransaction();
    assertEquals(emptySetOf(NewIndexDescriptor.class), asSet(readOperations.uniqueIndexesGetAll()));
    commit();
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) Test(org.junit.Test)

Example 18 with UniquenessConstraintDescriptor

use of org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor in project neo4j by neo4j.

the class LockingStatementOperationsTest method shouldAcquireSchemaWriteLockBeforeDroppingConstraint.

@Test
public void shouldAcquireSchemaWriteLockBeforeDroppingConstraint() throws Exception {
    // given
    UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema(descriptor);
    // when
    lockingOps.constraintDrop(state, constraint);
    // then
    order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.SCHEMA, schemaResource());
    order.verify(schemaWriteOps).constraintDrop(state, constraint);
}
Also used : UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) Test(org.junit.Test)

Example 19 with UniquenessConstraintDescriptor

use of org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor in project neo4j by neo4j.

the class TxStateTest method shouldDifferentiateBetweenUniquenessConstraintsForDifferentLabels.

@Test
public void shouldDifferentiateBetweenUniquenessConstraintsForDifferentLabels() throws Exception {
    // when
    UniquenessConstraintDescriptor constraint1 = ConstraintDescriptorFactory.uniqueForLabel(1, 17);
    state.constraintDoAdd(constraint1, 7);
    UniquenessConstraintDescriptor constraint2 = ConstraintDescriptorFactory.uniqueForLabel(2, 17);
    state.constraintDoAdd(constraint2, 19);
    // then
    assertEquals(singleton(constraint1), state.constraintsChangesForLabel(1).getAdded());
    assertEquals(singleton(constraint2), state.constraintsChangesForLabel(2).getAdded());
}
Also used : UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) Test(org.junit.Test)

Example 20 with UniquenessConstraintDescriptor

use of org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor in project neo4j by neo4j.

the class StateHandlingStatementOperationsTest method shouldGetAllConstraints.

@Test
public void shouldGetAllConstraints() throws Exception {
    // given
    UniquenessConstraintDescriptor constraint1 = ConstraintDescriptorFactory.uniqueForLabel(2, 3);
    UniquenessConstraintDescriptor constraint2 = ConstraintDescriptorFactory.uniqueForLabel(4, 5);
    TransactionState txState = new TxState();
    KernelStatement state = mockedState(txState);
    when(inner.constraintsGetForSchema(constraint1.schema())).thenAnswer(invocation -> Iterators.emptyIterator());
    when(inner.constraintsGetForSchema(constraint2.schema())).thenAnswer(invocation -> Iterators.emptyIterator());
    when(inner.constraintsGetAll()).thenAnswer(invocation -> iterator(constraint2));
    StateHandlingStatementOperations context = newTxStateOps(inner);
    context.uniquePropertyConstraintCreate(state, constraint1.schema());
    context.uniquePropertyConstraintCreate(state, constraint2.schema());
    // when
    Set<ConstraintDescriptor> result = Iterables.asSet(asIterable(context.constraintsGetAll(state)));
    // then
    assertEquals(asSet(constraint1, constraint2), result);
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) Test(org.junit.Test)

Aggregations

UniquenessConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor)20 Test (org.junit.Test)12 ConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor)7 NodeExistenceConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.NodeExistenceConstraintDescriptor)4 RelExistenceConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.RelExistenceConstraintDescriptor)4 UniquePropertyValueValidationException (org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException)3 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)3 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)3 StateHandlingStatementOperations (org.neo4j.kernel.impl.api.StateHandlingStatementOperations)3 ReadOperations (org.neo4j.kernel.api.ReadOperations)2 SchemaWriteOperations (org.neo4j.kernel.api.SchemaWriteOperations)2 CreateConstraintFailureException (org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException)2 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)2 NodeItem (org.neo4j.storageengine.api.NodeItem)2 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 Matchers.anyLong (org.mockito.Matchers.anyLong)1 ResourceIterator (org.neo4j.graphdb.ResourceIterator)1 CastingIterator (org.neo4j.helpers.collection.CastingIterator)1 Statement (org.neo4j.kernel.api.Statement)1