use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.
the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexScanWithIndexQuery.
@Test
public void shouldConsiderTransactionStateDuringIndexScanWithIndexQuery() throws Exception {
// Given
TransactionState txState = mock(TransactionState.class);
KernelStatement statement = mock(KernelStatement.class);
when(statement.hasTxStateWithChanges()).thenReturn(true);
when(statement.txState()).thenReturn(txState);
when(txState.indexUpdatesForScan(index)).thenReturn(new DiffSets<>(Collections.singleton(42L), Collections.singleton(44L)));
when(txState.addedAndRemovedNodes()).thenReturn(new DiffSets<>(Collections.singleton(45L), Collections.singleton(46L)));
StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
IndexReader indexReader = addMockedIndexReader(statement);
IndexQuery query = IndexQuery.exists(index.schema().getPropertyId());
when(indexReader.query(query)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
// When
PrimitiveLongIterator results = context.indexQuery(statement, index, query);
// Then
assertEquals(asSet(42L, 43L), PrimitiveLongCollections.toSet(results));
}
use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.
the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexRangeSeekByPrefix.
@Test
public void shouldConsiderTransactionStateDuringIndexRangeSeekByPrefix() throws Exception {
// Given
TransactionState txState = mock(TransactionState.class);
KernelStatement statement = mock(KernelStatement.class);
when(statement.hasTxStateWithChanges()).thenReturn(true);
when(statement.txState()).thenReturn(txState);
when(txState.indexUpdatesForRangeSeekByPrefix(index, "prefix")).thenReturn(new DiffSets<>(Collections.singleton(42L), Collections.singleton(44L)));
when(txState.addedAndRemovedNodes()).thenReturn(new DiffSets<>(Collections.singleton(45L), Collections.singleton(46L)));
StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
IndexReader indexReader = addMockedIndexReader(statement);
IndexQuery.StringPrefixPredicate query = IndexQuery.stringPrefix(index.schema().getPropertyId(), "prefix");
when(indexReader.query(query)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
// When
PrimitiveLongIterator results = context.indexQuery(statement, index, query);
// Then
assertEquals(asSet(42L, 43L), PrimitiveLongCollections.toSet(results));
}
use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.
the class IndexLookup method getAnyIndexOrNull.
public Index getAnyIndexOrNull(final long[] labelIds, final int propertyKeyId) throws IOException {
List<IndexRule> indexRules = indexRuleIndex.get(propertyKeyId);
if (indexRules == null) {
return null;
}
IndexRule rule = findIndexRuleWithOneOfLabels(indexRules, labelIds);
if (rule == null) {
return null;
}
final IndexReader reader = getIndexReader(rule);
return (nodeId, propertyValue) -> reader.countIndexedNodes(nodeId, propertyValue) > 0;
}
use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.
the class IndexLookup method getIndexReader.
private IndexReader getIndexReader(IndexRule rule) throws IOException {
IndexReader reader = readerCache.get(rule);
if (reader == null) {
IndexAccessor accessor = schemaIndexProvider.getOnlineAccessor(rule.getId(), rule.getIndexDescriptor(), samplingConfig);
indexAccessors.add(accessor);
reader = accessor.newReader();
readerCache.put(rule, reader);
}
return reader;
}
use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.
the class StateHandlingStatementOperationsTest method addMockedIndexReader.
private IndexReader addMockedIndexReader(StorageStatement storeStatement) throws IndexNotFoundKernelException {
IndexReader indexReader = mock(IndexReader.class);
when(storeStatement.getIndexReader(any(NewIndexDescriptor.class))).thenReturn(indexReader);
return indexReader;
}
Aggregations