use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class PlainOperationsTest method uniqueIndexesMustBeNamedAfterTheirConstraints.
@Test
void uniqueIndexesMustBeNamedAfterTheirConstraints() throws KernelException {
when(creationContext.reserveSchema()).thenReturn(1L, 2L, 3L);
when(storageReader.constraintsGetForSchema(any())).thenReturn(Iterators.emptyResourceIterator());
when(storageReader.indexGetForSchema(any())).thenReturn(Iterators.emptyResourceIterator());
String constraintName = "my_constraint";
when(constraintIndexCreator.createUniquenessConstraintIndex(any(), any(), any())).thenAnswer(i -> {
IndexPrototype prototype = i.getArgument(2);
Optional<String> name = prototype.getName();
assertTrue(name.isPresent());
assertThat(name.get()).isEqualTo(constraintName);
return prototype.materialise(2);
});
IndexPrototype prototype = IndexPrototype.uniqueForSchema(schema).withName(constraintName);
IndexBackedConstraintDescriptor constraint = operations.uniquePropertyConstraintCreate(prototype).asIndexBackedConstraint();
assertThat(constraint.ownedIndexId()).isEqualTo(2L);
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class PlainOperationsTest method indexedBackedConstraintCreateMustThrowOnNonUniqueIndexPrototypes.
@Test
void indexedBackedConstraintCreateMustThrowOnNonUniqueIndexPrototypes() throws Exception {
// given
when(tokenHolders.labelTokens().getTokenById(anyInt())).thenReturn(new NamedToken("Label", 123));
when(tokenHolders.propertyKeyTokens().getTokenById(anyInt())).thenReturn(new NamedToken("prop", 456));
IndexPrototype prototype = IndexPrototype.forSchema(schema).withName("constraint name").withIndexProvider(GenericNativeIndexProvider.DESCRIPTOR);
IndexDescriptor constraintIndex = prototype.materialise(42);
when(constraintIndexCreator.createUniquenessConstraintIndex(any(), any(), eq(prototype))).thenReturn(constraintIndex);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexProxy.getDescriptor()).thenReturn(constraintIndex);
when(indexingService.getIndexProxy(constraintIndex)).thenReturn(indexProxy);
when(storageReader.constraintsGetForSchema(schema)).thenReturn(Collections.emptyIterator());
when(storageReader.indexGetForSchema(schema)).thenReturn(Collections.emptyIterator());
// when
var e = assertThrows(KernelException.class, () -> operations.uniquePropertyConstraintCreate(prototype));
assertThat(e.getUserMessage(tokenHolders)).containsIgnoringCase("index prototype").containsIgnoringCase("not unique");
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class PlainOperationsTest method shouldAcquireSchemaWriteLockBeforeCreatingUniquenessConstraint.
@Test
void shouldAcquireSchemaWriteLockBeforeCreatingUniquenessConstraint() throws Exception {
// given
IndexPrototype prototype = IndexPrototype.uniqueForSchema(schema).withName("constraint name").withIndexProvider(GenericNativeIndexProvider.DESCRIPTOR);
IndexDescriptor constraintIndex = prototype.materialise(42);
when(constraintIndexCreator.createUniquenessConstraintIndex(any(), any(), eq(prototype))).thenReturn(constraintIndex);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexProxy.getDescriptor()).thenReturn(constraintIndex);
when(indexingService.getIndexProxy(constraintIndex)).thenReturn(indexProxy);
when(storageReader.constraintsGetForSchema(schema.schema())).thenReturn(Collections.emptyIterator());
when(storageReader.indexGetForSchema(schema.schema())).thenReturn(Collections.emptyIterator());
// when
operations.uniquePropertyConstraintCreate(prototype);
// then
order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.LABEL, schema.getLabelId());
order.verify(txState).constraintDoAdd(ConstraintDescriptorFactory.uniqueForSchema(schema), constraintIndex);
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class SchemaStorageIT method makeIndexRuleForConstraint.
private IndexDescriptor makeIndexRuleForConstraint(long ruleId, String label, String propertyKey, long constraintId) {
LabelSchemaDescriptor schema = forLabel(labelId(label), propId(propertyKey));
IndexPrototype prototype = uniqueForSchema(schema, GenericNativeIndexProvider.DESCRIPTOR);
UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema(schema);
prototype = prototype.withName(SchemaRule.generateName(constraint, new String[] { label }, new String[] { propertyKey }));
return prototype.materialise(ruleId).withOwningConstraintId(constraintId);
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class SchemaStorageIT method makeIndexRule.
private IndexDescriptor makeIndexRule(long ruleId, String label, String propertyKey) {
LabelSchemaDescriptor schema = forLabel(labelId(label), propId(propertyKey));
IndexPrototype prototype = forSchema(schema, GenericNativeIndexProvider.DESCRIPTOR);
prototype = prototype.withName(SchemaRule.generateName(prototype, new String[] { label }, new String[] { propertyKey }));
return prototype.materialise(ruleId);
}
Aggregations