Search in sources :

Example 1 with StoreScan

use of org.neo4j.kernel.impl.api.index.StoreScan in project neo4j by neo4j.

the class FullScanStoreViewTest method shouldScanExistingRelationshipsForARelationshipType.

@Test
void shouldScanExistingRelationshipsForARelationshipType() {
    // given
    TestPropertyScanConsumer propertyScanConsumer = new TestPropertyScanConsumer();
    StoreScan storeScan = storeView.visitRelationships(new int[] { relTypeId }, id -> id == relPropertyKeyId, propertyScanConsumer, null, true, true, NULL, INSTANCE);
    // when
    storeScan.run(NO_EXTERNAL_UPDATES);
    // then
    assertThat(propertyScanConsumer.batches.get(0)).containsExactlyInAnyOrder(record(aKnowsS.getId(), relPropertyKeyId, "long", new long[] { relTypeId }), record(sKnowsA.getId(), relPropertyKeyId, "lengthy", new long[] { relTypeId }));
}
Also used : StoreScan(org.neo4j.kernel.impl.api.index.StoreScan) Test(org.junit.jupiter.api.Test)

Example 2 with StoreScan

use of org.neo4j.kernel.impl.api.index.StoreScan in project neo4j by neo4j.

the class FullScanStoreViewTest method shouldLockNodesWhileReadingThem.

@Test
void shouldLockNodesWhileReadingThem() {
    // given
    StoreScan storeScan = storeView.visitNodes(new int[] { labelId }, id -> id == propertyKeyId, new TestPropertyScanConsumer(), null, false, true, NULL, INSTANCE);
    // when
    storeScan.run(NO_EXTERNAL_UPDATES);
    // then
    assertThat(lockMocks.size()).as("allocated locks: " + lockMocks.keySet()).isGreaterThanOrEqualTo(2);
    Lock lock0 = lockMocks.get(0L);
    Lock lock1 = lockMocks.get(1L);
    assertNotNull(lock0, "Lock[node=0] never acquired");
    assertNotNull(lock1, "Lock[node=1] never acquired");
    InOrder order = inOrder(locks, lock0, lock1);
    order.verify(locks).acquireNodeLock(0, SHARED);
    order.verify(lock0).release();
    order.verify(locks).acquireNodeLock(1, SHARED);
    order.verify(lock1).release();
}
Also used : InOrder(org.mockito.InOrder) StoreScan(org.neo4j.kernel.impl.api.index.StoreScan) Lock(org.neo4j.lock.Lock) Test(org.junit.jupiter.api.Test)

Example 3 with StoreScan

use of org.neo4j.kernel.impl.api.index.StoreScan in project neo4j by neo4j.

the class FullScanStoreViewTest method shouldScanExistingNodesForALabel.

@Test
void shouldScanExistingNodesForALabel() {
    // given
    TestPropertyScanConsumer propertyScanConsumer = new TestPropertyScanConsumer();
    StoreScan storeScan = storeView.visitNodes(new int[] { labelId }, id -> id == propertyKeyId, propertyScanConsumer, new TestTokenScanConsumer(), false, true, NULL, INSTANCE);
    // when
    storeScan.run(NO_EXTERNAL_UPDATES);
    // then
    assertThat(propertyScanConsumer.batches.get(0)).containsExactlyInAnyOrder(record(alistair.getId(), propertyKeyId, "Alistair", new long[] { labelId }), record(stefan.getId(), propertyKeyId, "Stefan", new long[] { labelId }));
}
Also used : StoreScan(org.neo4j.kernel.impl.api.index.StoreScan) Test(org.junit.jupiter.api.Test)

Example 4 with StoreScan

use of org.neo4j.kernel.impl.api.index.StoreScan 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);
}
Also used : StoreScan(org.neo4j.kernel.impl.api.index.StoreScan) IndexProxyProvider(org.neo4j.kernel.impl.api.index.IndexingService.IndexProxyProvider) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 5 with StoreScan

use of org.neo4j.kernel.impl.api.index.StoreScan 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);
}
Also used : StoreScan(org.neo4j.kernel.impl.api.index.StoreScan) IndexProxyProvider(org.neo4j.kernel.impl.api.index.IndexingService.IndexProxyProvider) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) Test(org.junit.jupiter.api.Test)

Aggregations

StoreScan (org.neo4j.kernel.impl.api.index.StoreScan)12 Test (org.junit.jupiter.api.Test)11 IndexProxyProvider (org.neo4j.kernel.impl.api.index.IndexingService.IndexProxyProvider)4 StubStorageCursors (org.neo4j.storageengine.api.StubStorageCursors)4 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)3 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)3 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)2 InOrder (org.mockito.InOrder)2 Value (org.neo4j.values.storable.Value)2 File (java.io.File)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 Boolean.parseBoolean (java.lang.Boolean.parseBoolean)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1