use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.
the class PlainOperationsTest method indexedBackedConstraintCreateMustThrowOnAnyTokenSchemas.
@Test
void indexedBackedConstraintCreateMustThrowOnAnyTokenSchemas() throws Exception {
// given
SchemaDescriptor schema = SchemaDescriptor.forAnyEntityTokens(NODE);
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("any token schema");
}
use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.
the class LookupAccessorsFromRunningDb method apply.
@Override
public IndexAccessor apply(IndexDescriptor indexDescriptor) {
try {
IndexProxy proxy = indexingService.getIndexProxy(indexDescriptor);
while (proxy instanceof AbstractDelegatingIndexProxy) {
proxy = ((AbstractDelegatingIndexProxy) proxy).getDelegate();
}
assertEquals(InternalIndexState.ONLINE, proxy.getState());
return ((OnlineIndexProxy) proxy).accessor();
} catch (IndexNotFoundKernelException e) {
throw new RuntimeException(e);
}
}
use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.
the class DynamicIndexStoreViewTest method shouldVisitNodesUsingTokenIndex.
@Test
void shouldVisitNodesUsingTokenIndex() throws Exception {
long[] nodeIds = { 1, 2, 3, 4, 5, 6, 7, 8 };
int[] indexedLabels = { 2, 6 };
StubStorageCursors cursors = new StubStorageCursors().withTokenIndexes();
IndexProxy indexProxy = mock(IndexProxy.class);
IndexProxyProvider indexProxies = mock(IndexProxyProvider.class);
StubTokenIndexReader tokenReader = new StubTokenIndexReader();
IndexDescriptor descriptor = forSchema(forAnyEntityTokens(NODE), DESCRIPTOR).withName("index").materialise(0);
when(indexProxy.getState()).thenReturn(InternalIndexState.ONLINE);
when(indexProxy.newTokenReader()).thenReturn(tokenReader);
when(indexProxy.getDescriptor()).thenReturn(descriptor);
when(indexProxies.getIndexProxy(any())).thenReturn(indexProxy);
// Nodes indexed by label
for (long nodeId : nodeIds) {
cursors.withNode(nodeId).propertyId(1).relationship(1).labels(2, 6);
tokenReader.index(indexedLabels, nodeId);
}
// Nodes not indexed
cursors.withNode(9).labels(5);
cursors.withNode(10).labels(6);
DynamicIndexStoreView storeView = dynamicIndexStoreView(cursors, indexProxies);
TestTokenScanConsumer consumer = new TestTokenScanConsumer();
StoreScan storeScan = storeView.visitNodes(indexedLabels, Predicates.ALWAYS_TRUE_INT, new TestPropertyScanConsumer(), consumer, false, true, NULL, INSTANCE);
storeScan.run(StoreScan.NO_EXTERNAL_UPDATES);
assertThat(consumer.batches.size()).isEqualTo(1);
assertThat(consumer.batches.get(0).size()).isEqualTo(nodeIds.length);
}
use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.
the class CheckerTestBase method labelIndexWriter.
IndexUpdater labelIndexWriter() {
IndexingService indexingService = db.getDependencyResolver().resolveDependency(IndexingService.class);
final IndexDescriptor[] indexDescriptors = schemaStorage.indexGetForSchema(SchemaDescriptor.forAnyEntityTokens(EntityType.NODE), CursorContext.NULL);
// The Node Label Index should exist and be unique.
assertThat(indexDescriptors.length).isEqualTo(1);
IndexDescriptor nli = indexDescriptors[0];
IndexProxy indexProxy;
try {
indexProxy = indexingService.getIndexProxy(nli);
} catch (IndexNotFoundKernelException e) {
throw new RuntimeException(e);
}
return indexProxy.newUpdater(IndexUpdateMode.ONLINE, CursorContext.NULL);
}
use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method shouldCreateIndexInAnotherTransaction.
@Test
void shouldCreateIndexInAnotherTransaction() throws Exception {
// given
IndexProxy indexProxy = mock(IndexProxy.class);
IndexingService indexingService = mock(IndexingService.class);
when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
when(indexProxy.getDescriptor()).thenReturn(index);
when(schemaRead.indexGetForName(constraint.getName())).thenReturn(IndexDescriptor.NO_INDEX);
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
// when
IndexDescriptor constraintIndex = creator.createUniquenessConstraintIndex(createTransaction(), constraint, prototype);
// then
assertEquals(INDEX_ID, constraintIndex.getId());
verify(schemaRead).indexGetForName(constraint.getName());
verifyNoMoreInteractions(schemaRead);
verify(indexProxy).awaitStoreScanCompleted(anyLong(), any());
}
Aggregations