use of org.neo4j.kernel.impl.api.StateHandlingStatementOperations in project neo4j by neo4j.
the class StateHandlingStatementOperationsTest method indexQueryClosesIndexReader.
@Test
public void indexQueryClosesIndexReader() throws Exception {
KernelStatement kernelStatement = mock(KernelStatement.class);
StoreStatement storeStatement = mock(StoreStatement.class);
IndexReader indexReader = mock(IndexReader.class);
when(indexReader.query(any())).thenReturn(PrimitiveLongCollections.emptyIterator());
when(storeStatement.getFreshIndexReader(any())).thenReturn(indexReader);
when(kernelStatement.getStoreStatement()).thenReturn(storeStatement);
StateHandlingStatementOperations operations = newTxStateOps(mock(StoreReadLayer.class));
operations.nodeGetFromUniqueIndexSeek(kernelStatement, NewIndexDescriptorFactory.uniqueForLabel(1, 1), IndexQuery.exact(1, "foo"));
verify(indexReader).close();
}
use of org.neo4j.kernel.impl.api.StateHandlingStatementOperations in project neo4j by neo4j.
the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexRangeSeekByPrefixWithIndexQuery.
@Test
public void shouldConsiderTransactionStateDuringIndexRangeSeekByPrefixWithIndexQuery() 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 indexQuery = IndexQuery.stringPrefix(index.schema().getPropertyId(), "prefix");
when(indexReader.query(indexQuery)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
// When
PrimitiveLongIterator results = context.indexQuery(statement, index, indexQuery);
// Then
assertEquals(asSet(42L, 43L), PrimitiveLongCollections.toSet(results));
}
use of org.neo4j.kernel.impl.api.StateHandlingStatementOperations in project neo4j by neo4j.
the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexBetweenRangeSeekByNumberWithIndexQuery.
@SuppressWarnings("unchecked")
@Test
public void shouldConsiderTransactionStateDuringIndexBetweenRangeSeekByNumberWithIndexQuery() throws Exception {
// Given
final int propertyKey = 2;
final int inRange = 15;
int lower = 10;
int upper = 20;
TransactionState txState = mock(TransactionState.class);
KernelStatement statement = mock(KernelStatement.class);
when(statement.hasTxStateWithChanges()).thenReturn(true);
when(statement.txState()).thenReturn(txState);
StorageStatement storageStatement = mock(StorageStatement.class);
when(statement.getStoreStatement()).thenReturn(storageStatement);
when(txState.indexUpdatesForRangeSeekByNumber(index, lower, true, upper, false)).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);
when(txState.augmentSingleNodeCursor(any(Cursor.class), anyLong())).thenAnswer(invocationOnMock -> {
long nodeId = (long) invocationOnMock.getArguments()[1];
when(txState.augmentSinglePropertyCursor(any(Cursor.class), any(PropertyContainerState.class), eq(propertyKey))).thenReturn(asPropertyCursor(intProperty(propertyKey, inRange)));
return asNodeCursor(nodeId, nodeId + 20000);
});
IndexReader indexReader = addMockedIndexReader(storageStatement);
IndexQuery.NumberRangePredicate indexQuery = IndexQuery.range(index.schema().getPropertyId(), lower, true, upper, false);
when(indexReader.query(indexQuery)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
when(storageStatement.acquireSingleNodeCursor(anyLong())).thenAnswer(invocationOnMock -> {
long nodeId = (long) invocationOnMock.getArguments()[0];
when(storeReadLayer.nodeGetProperty(eq(storageStatement), any(NodeItem.class), eq(propertyKey))).thenReturn(asPropertyCursor(intProperty(propertyKey, inRange)));
return asNodeCursor(nodeId, nodeId + 20000);
});
StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
// When
PrimitiveLongIterator results = context.indexQuery(statement, index, indexQuery);
// Then
assertEquals(asSet(42L, 43L), PrimitiveLongCollections.toSet(results));
}
Aggregations