use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class PlainOperationsTest method indexedBackedConstraintCreateMustThrowOnFulltextSchemas.
@Test
void indexedBackedConstraintCreateMustThrowOnFulltextSchemas() throws Exception {
// given
when(tokenHolders.labelTokens().getTokenById(anyInt())).thenReturn(new NamedToken("Label", 123));
when(tokenHolders.propertyKeyTokens().getTokenById(anyInt())).thenReturn(new NamedToken("prop", 456));
SchemaDescriptor schema = SchemaDescriptor.fulltext(NODE, this.schema.getEntityTokenIds(), this.schema.getPropertyIds());
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)).thenReturn(Collections.emptyIterator());
when(storageReader.indexGetForSchema(schema)).thenReturn(Collections.emptyIterator());
// when
var e = assertThrows(KernelException.class, () -> operations.uniquePropertyConstraintCreate(prototype));
assertThat(e.getUserMessage(tokenHolders)).contains("full-text schema");
}
use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class PlainOperationsTest method shouldReleaseAcquiredSchemaWriteLockIfConstraintCreationFails.
@Test
void shouldReleaseAcquiredSchemaWriteLockIfConstraintCreationFails() throws Exception {
// given
UniquenessConstraintDescriptor constraint = uniqueForSchema(schema);
storageReaderWithConstraints(constraint);
int labelId = schema.getLabelId();
int propertyId = schema.getPropertyId();
when(tokenHolders.labelTokens().getTokenById(labelId)).thenReturn(new NamedToken("Label", labelId));
when(tokenHolders.propertyKeyTokens().getTokenById(propertyId)).thenReturn(new NamedToken("prop", labelId));
// when
try {
operations.uniquePropertyConstraintCreate(IndexPrototype.uniqueForSchema(schema).withName("constraint name"));
fail("Expected an exception because this schema should already be constrained.");
} catch (AlreadyConstrainedException ignore) {
// Good.
}
// then
order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.LABEL, labelId);
order.verify(storageReader).constraintsGetForSchema(schema);
order.verify(locks).releaseExclusive(ResourceTypes.LABEL, labelId);
}
use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class PlainOperationsTest method shouldReleaseAcquiredSchemaWriteLockIfRelationshipPropertyExistenceConstraintCreationFails.
@Test
void shouldReleaseAcquiredSchemaWriteLockIfRelationshipPropertyExistenceConstraintCreationFails() throws Exception {
// given
RelationTypeSchemaDescriptor descriptor = SchemaDescriptor.forRelType(11, 13);
RelExistenceConstraintDescriptor constraint = existsForSchema(descriptor);
storageReaderWithConstraints(constraint);
int relTypeId = descriptor.getRelTypeId();
int propertyId = descriptor.getPropertyId();
when(tokenHolders.relationshipTypeTokens().getTokenById(relTypeId)).thenReturn(new NamedToken("Label", relTypeId));
when(tokenHolders.propertyKeyTokens().getTokenById(propertyId)).thenReturn(new NamedToken("prop", relTypeId));
// when
try {
operations.relationshipPropertyExistenceConstraintCreate(descriptor, "constraint name");
fail("Expected an exception because this schema should already be constrained.");
} catch (AlreadyConstrainedException ignore) {
// Good.
}
// then
order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.RELATIONSHIP_TYPE, relTypeId);
order.verify(storageReader).constraintsGetForSchema(descriptor);
order.verify(locks).releaseExclusive(ResourceTypes.RELATIONSHIP_TYPE, relTypeId);
}
use of org.neo4j.token.api.NamedToken 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.token.api.NamedToken in project neo4j by neo4j.
the class PlainOperationsTest method shouldReleaseAcquiredSchemaWriteLockIfNodeKeyConstraintCreationFails.
@Test
void shouldReleaseAcquiredSchemaWriteLockIfNodeKeyConstraintCreationFails() throws Exception {
// given
NodeKeyConstraintDescriptor constraint = nodeKeyForSchema(schema);
storageReaderWithConstraints(constraint);
int labelId = schema.getLabelId();
int propertyId = schema.getPropertyId();
when(tokenHolders.labelTokens().getTokenById(labelId)).thenReturn(new NamedToken("Label", labelId));
when(tokenHolders.propertyKeyTokens().getTokenById(propertyId)).thenReturn(new NamedToken("prop", labelId));
// when
try {
operations.nodeKeyConstraintCreate(IndexPrototype.uniqueForSchema(schema).withName("constraint name"));
fail("Expected an exception because this schema should already be constrained.");
} catch (AlreadyConstrainedException ignore) {
// Good.
}
// then
order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.LABEL, labelId);
order.verify(storageReader).constraintsGetForSchema(schema);
order.verify(locks).releaseExclusive(ResourceTypes.LABEL, labelId);
}
Aggregations