use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.
the class ReadRecordsStep method nextBatchOrNull.
@SuppressWarnings("unchecked")
@Override
protected Object nextBatchOrNull(long ticket, int batchSize) {
PrimitiveLongIterator ids;
while ((ids = this.ids.nextBatch()) != null) {
RECORD[] batch = (RECORD[]) Array.newInstance(klass, batchSize);
int i = 0;
while (ids.hasNext()) {
if (cursor.next(ids.next()) && !IdValidator.isReservedId(record.getId())) {
batch[i++] = (RECORD) record.clone();
}
}
if (i > 0) {
count += i;
return i == batchSize ? batch : Arrays.copyOf(batch, i);
}
}
return null;
}
use of org.neo4j.collection.primitive.PrimitiveLongIterator 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.collection.primitive.PrimitiveLongIterator 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.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.
the class NodeLoadingIteratorTest method shouldHandleANonEmptyIteratorWithNotFoundEntities.
@Test
public void shouldHandleANonEmptyIteratorWithNotFoundEntities() throws Exception {
// given
Map<Long, Cursor<NodeItem>> map = new HashMap<>(3);
map.put(1L, mockCursor());
map.put(2L, null);
map.put(3L, mockCursor());
PrimitiveLongIterator inner = PrimitiveLongCollections.iterator(1, 2, 3);
NodeLoadingIterator iterator = new NodeLoadingIterator(inner, createMapping(map));
// when - then
for (long i = 1; i <= 2; i++) {
assertTrue(iterator.hasNext());
assertEquals(map.get(i + (i - 1)), iterator.next());
}
assertNoMoreElements(iterator);
}
use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.
the class NodeLoadingIteratorTest method shouldHandleANonEmptyIterator.
@Test
public void shouldHandleANonEmptyIterator() throws Exception {
// given
Map<Long, Cursor<NodeItem>> map = new HashMap<>(3);
map.put(1L, mockCursor());
map.put(2L, mockCursor());
map.put(3L, mockCursor());
PrimitiveLongIterator inner = PrimitiveLongCollections.iterator(1, 2, 3);
NodeLoadingIterator iterator = new NodeLoadingIterator(inner, createMapping(map));
// when - then
for (long i = 1; i <= 3; i++) {
assertTrue(iterator.hasNext());
assertEquals(map.get(i), iterator.next());
}
assertNoMoreElements(iterator);
}
Aggregations