use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method shouldReleaseSchemaLockWhileAwaitingIndexPopulation.
@Test
public void shouldReleaseSchemaLockWhileAwaitingIndexPopulation() throws Exception {
// given
StubKernel kernel = new StubKernel();
IndexingService indexingService = mock(IndexingService.class);
StatementOperationParts constraintCreationContext = mockedParts();
PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
KernelStatement state = mockedState();
when(constraintCreationContext.schemaReadOperations().indexGetCommittedId(state, index)).thenReturn(2468L);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexingService.getIndexProxy(anyLong())).thenReturn(indexProxy);
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, propertyAccessor, true);
// when
creator.createUniquenessConstraintIndex(state, constraintCreationContext.schemaReadOperations(), index.schema());
// then
verify(state.locks().pessimistic()).releaseExclusive(ResourceTypes.SCHEMA, ResourceTypes.schemaResource());
verify(state.locks().pessimistic()).acquireExclusive(state.lockTracer(), ResourceTypes.SCHEMA, ResourceTypes.schemaResource());
}
use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.
the class PlainOperationsTest method shouldAcquireSchemaWriteLockBeforeRemovingIndexRule.
@Test
void shouldAcquireSchemaWriteLockBeforeRemovingIndexRule() throws Exception {
// given
IndexDescriptor index = IndexPrototype.forSchema(SchemaDescriptor.forLabel(0, 0)).withName("index").materialise(0);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexProxy.getDescriptor()).thenReturn(index);
when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
when(storageReader.indexExists(index)).thenReturn(true);
// when
operations.indexDrop(index);
// then
order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.LABEL, 0);
order.verify(txState).indexDoDrop(index);
}
use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.
the class PlainOperationsTest method shouldAcquireSchemaNameWriteLockBeforeRemovingIndexByName.
@Test
void shouldAcquireSchemaNameWriteLockBeforeRemovingIndexByName() throws Exception {
// given
String indexName = "My fancy index";
IndexDescriptor index = IndexPrototype.forSchema(SchemaDescriptor.forLabel(0, 0)).withName(indexName).materialise(0);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexProxy.getDescriptor()).thenReturn(index);
when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
when(storageReader.indexGetForName(indexName)).thenReturn(index);
when(storageReader.indexExists(index)).thenReturn(true);
// when
operations.indexDrop(indexName);
// then
long indexNameLock = ResourceIds.schemaNameResourceId(indexName);
order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.SCHEMA_NAME, indexNameLock);
order.verify(txState).indexDoDrop(index);
}
use of org.neo4j.kernel.impl.api.index.IndexProxy 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.kernel.impl.api.index.IndexProxy 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");
}
Aggregations