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));
}
}
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();
}
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);
}
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());
}
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);
}
Aggregations