use of org.neo4j.kernel.impl.api.index.IndexingService.IndexProxyProvider 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.IndexingService.IndexProxyProvider in project neo4j by neo4j.
the class DynamicIndexStoreViewTest method shouldVisitAllNodesWithoutTokenIndexes.
@Test
void shouldVisitAllNodesWithoutTokenIndexes() {
long[] nodeIds = { 1, 2, 3, 4, 5, 6, 7, 8 };
int[] indexedLabels = { 2, 6 };
StubStorageCursors cursors = new StubStorageCursors().withoutTokenIndexes();
IndexProxyProvider indexProxies = mock(IndexProxyProvider.class);
// Nodes indexed by label
for (long nodeId : nodeIds) {
cursors.withNode(nodeId).propertyId(1).relationship(1).labels(2, 6);
}
// Nodes not in index
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 + 2);
}
use of org.neo4j.kernel.impl.api.index.IndexingService.IndexProxyProvider in project neo4j by neo4j.
the class DynamicIndexStoreViewTest method shouldVisitRelationshipsUsingTokenIndex.
@Test
void shouldVisitRelationshipsUsingTokenIndex() throws Throwable {
// Given
StubTokenIndexReader tokenReader = new StubTokenIndexReader();
StubStorageCursors cursors = new StubStorageCursors().withTokenIndexes();
IndexProxy indexProxy = mock(IndexProxy.class);
IndexProxyProvider indexProxies = mock(IndexProxyProvider.class);
IndexDescriptor descriptor = forSchema(forAnyEntityTokens(RELATIONSHIP), DESCRIPTOR).withName("index").materialise(0);
when(indexProxy.getState()).thenReturn(InternalIndexState.ONLINE);
when(indexProxy.getDescriptor()).thenReturn(descriptor);
when(indexProxy.newTokenReader()).thenReturn(tokenReader);
when(indexProxies.getIndexProxy(any())).thenReturn(indexProxy);
int targetType = 1;
int notTargetType = 2;
int[] indexedTypes = { targetType };
String targetPropertyKey = "key";
String notTargetPropertyKey = "not-key";
Value propertyValue = Values.stringValue("value");
MutableLongList relationshipsWithTargetType = LongLists.mutable.empty();
long id = 0;
int wantedPropertyUpdates = 5;
for (int i = 0; i < wantedPropertyUpdates; i++) {
// Relationships that are indexed
cursors.withRelationship(id, 1, targetType, 3).properties(targetPropertyKey, propertyValue);
tokenReader.index(indexedTypes, id);
relationshipsWithTargetType.add(id++);
// Relationship with wrong property
cursors.withRelationship(id++, 1, targetType, 3).properties(notTargetPropertyKey, propertyValue);
// Relationship with wrong type
cursors.withRelationship(id++, 1, notTargetType, 3).properties(targetPropertyKey, propertyValue);
}
// When
DynamicIndexStoreView storeView = dynamicIndexStoreView(cursors, indexProxies);
TestTokenScanConsumer tokenConsumer = new TestTokenScanConsumer();
TestPropertyScanConsumer propertyScanConsumer = new TestPropertyScanConsumer();
StoreScan storeScan = storeView.visitRelationships(indexedTypes, relationType -> true, propertyScanConsumer, tokenConsumer, false, true, NULL, INSTANCE);
storeScan.run(StoreScan.NO_EXTERNAL_UPDATES);
// Then make sure all the fitting relationships where included
assertThat(propertyScanConsumer.batches.size()).isEqualTo(1);
assertThat(propertyScanConsumer.batches.get(0).size()).isEqualTo(wantedPropertyUpdates);
// and that we didn't visit any more relationships than what we would get from scan store
assertThat(tokenConsumer.batches.size()).isEqualTo(1);
assertThat(tokenConsumer.batches.get(0).size()).isEqualTo(relationshipsWithTargetType.size());
}
use of org.neo4j.kernel.impl.api.index.IndexingService.IndexProxyProvider in project neo4j by neo4j.
the class DynamicIndexStoreViewTest method shouldVisitAllRelationshipsWithoutTokenIndexes.
@Test
void shouldVisitAllRelationshipsWithoutTokenIndexes() {
StubStorageCursors cursors = new StubStorageCursors().withoutTokenIndexes();
IndexProxyProvider indexProxies = mock(IndexProxyProvider.class);
int targetType = 1;
int notTargetType = 2;
int[] targetTypeArray = { targetType };
String targetPropertyKey = "key";
Value propertyValue = Values.stringValue("value");
MutableLongList relationshipsWithTargetType = LongLists.mutable.empty();
long id = 0;
int wantedPropertyUpdates = 5;
for (int i = 0; i < wantedPropertyUpdates; i++) {
// Relationship fitting our target
cursors.withRelationship(id, 1, targetType, 3).properties(targetPropertyKey, propertyValue);
relationshipsWithTargetType.add(id++);
// Relationship with different type
cursors.withRelationship(id, 1, notTargetType, 3).properties(targetPropertyKey, propertyValue);
relationshipsWithTargetType.add(id++);
}
int targetPropertyKeyId = cursors.propertyKeyTokenHolder().getIdByName(targetPropertyKey);
IntPredicate propertyKeyIdFilter = value -> value == targetPropertyKeyId;
DynamicIndexStoreView storeView = dynamicIndexStoreView(cursors, indexProxies);
TestTokenScanConsumer tokenConsumer = new TestTokenScanConsumer();
TestPropertyScanConsumer propertyScanConsumer = new TestPropertyScanConsumer();
StoreScan storeScan = storeView.visitRelationships(targetTypeArray, propertyKeyIdFilter, propertyScanConsumer, tokenConsumer, false, true, NULL, INSTANCE);
storeScan.run(StoreScan.NO_EXTERNAL_UPDATES);
assertThat(tokenConsumer.batches.size()).isEqualTo(1);
assertThat(tokenConsumer.batches.get(0).size()).isEqualTo(relationshipsWithTargetType.size());
}
Aggregations