use of org.neo4j.kernel.impl.api.index.IndexProxy 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.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.
the class IndexTxStateUpdaterTestBase method setUp.
void setUp(List<IndexDescriptor> indexes) throws IndexNotFoundKernelException {
txState = mock(TransactionState.class);
when(txState.memoryTracker()).thenReturn(EmptyMemoryTracker.INSTANCE);
StorageReader storageReader = mock(StorageReader.class);
when(storageReader.valueIndexesGetRelated(any(), anyInt(), any())).thenAnswer(invocationOnMock -> {
long[] tokens = invocationOnMock.getArgument(0);
int propertyKeyId = invocationOnMock.getArgument(1);
Set<IndexDescriptor> descriptors = new HashSet<>();
for (IndexDescriptor index : indexes) {
SchemaDescriptor schema = index.schema();
if (schema.isAffected(tokens) && contains(schema.getPropertyIds(), propertyKeyId)) {
if (schema.propertySchemaType() == PropertySchemaType.COMPLETE_ALL_TOKENS) {
descriptors.add(index);
}
}
}
return descriptors;
});
when(storageReader.valueIndexesGetRelated(any(), any(int[].class), any())).thenAnswer(invocationOnMock -> {
long[] tokens = invocationOnMock.getArgument(0);
int[] propertyKeyIds = invocationOnMock.getArgument(1);
Set<IndexDescriptor> descriptors = new HashSet<>();
for (IndexDescriptor index : indexes) {
if (index.schema().isAffected(tokens)) {
boolean containsAll = true;
for (int propertyId : index.schema().getPropertyIds()) {
containsAll &= contains(propertyKeyIds, propertyId);
}
if (containsAll) {
descriptors.add(index);
}
}
}
return descriptors;
});
Read readOps = mock(Read.class);
when(readOps.txState()).thenReturn(txState);
IndexingService indexingService = mock(IndexingService.class);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexingService.getIndexProxy(any(IndexDescriptor.class))).thenReturn(indexProxy);
indexTxUpdater = new IndexTxStateUpdater(storageReader, readOps, indexingService);
}
use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.
the class LabelScanNodeViewTracingIT method tracePageCacheAccess.
@Test
void tracePageCacheAccess() throws Exception {
int nodeCount = 1000;
var label = Label.label("marker");
try (var tx = database.beginTx()) {
for (int i = 0; i < nodeCount; i++) {
var node = tx.createNode(label);
node.setProperty("a", randomAscii(10));
}
tx.commit();
}
var labelId = getLabelId(label);
var cacheTracer = new DefaultPageCacheTracer();
IndexProxy indexProxy = indexingService.getIndexProxy(findTokenIndex());
var scan = new LabelIndexedNodeStoreScan(Config.defaults(), storageEngine.newReader(), lockService, indexProxy.newTokenReader(), new TestTokenScanConsumer(), null, new int[] { labelId }, any -> false, false, jobScheduler, cacheTracer, INSTANCE);
scan.run(StoreScan.NO_EXTERNAL_UPDATES);
assertThat(cacheTracer.pins()).isEqualTo(3);
assertThat(cacheTracer.unpins()).isEqualTo(3);
assertThat(cacheTracer.hits()).isEqualTo(3);
}
use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method shouldIgnoreExistingOrphanedConstraintIndexWithDifferentName.
@Test
void shouldIgnoreExistingOrphanedConstraintIndexWithDifferentName() throws Exception {
// given
IndexingService indexingService = mock(IndexingService.class);
long orphanedConstraintIndexId = 111;
String orphanedName = "blabla";
IndexDescriptor orphanedIndex = IndexPrototype.uniqueForSchema(schema).withName(orphanedName).materialise(orphanedConstraintIndexId);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexingService.getIndexProxy(orphanedIndex)).thenReturn(indexProxy);
when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
when(schemaRead.index(schema)).thenReturn(Iterators.iterator(orphanedIndex));
when(schemaRead.indexGetForName(constraint.getName())).thenReturn(IndexDescriptor.NO_INDEX);
when(schemaRead.indexGetForName(orphanedName)).thenReturn(orphanedIndex);
when(schemaRead.indexGetOwningUniquenessConstraintId(orphanedIndex)).thenReturn(// which means it has no owner
null);
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
// when
KernelTransactionImplementation transaction = createTransaction();
creator.createUniquenessConstraintIndex(transaction, constraint, prototype);
// then
assertEquals(1, kernel.transactions.size());
verify(schemaRead).indexGetForName(constraint.getName());
verifyNoMoreInteractions(schemaRead);
}
use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method shouldCreateConstraintIndexForSpecifiedProvider.
@Test
void shouldCreateConstraintIndexForSpecifiedProvider() throws Exception {
// given
IndexingService indexingService = mock(IndexingService.class);
IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor("Groovy", "1.2");
IndexPrototype prototype = this.prototype.withIndexProvider(providerDescriptor);
IndexDescriptor index = prototype.materialise(this.index.getId());
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
when(schemaRead.indexGetForName(constraint.getName())).thenReturn(IndexDescriptor.NO_INDEX);
// when
KernelTransactionImplementation transaction = createTransaction();
creator.createUniquenessConstraintIndex(transaction, constraint, prototype);
// then
assertEquals(1, kernel.transactions.size());
KernelTransactionImplementation transactionInstance = kernel.transactions.get(0);
verify(transactionInstance).indexUniqueCreate(prototype);
verify(schemaRead).indexGetForName(constraint.getName());
verifyNoMoreInteractions(schemaRead);
}
Aggregations