use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.
the class IndexQueryTransactionStateTest method shouldIncludeCreatedNodesWithCorrectLabelAndProperty.
@Test
public void shouldIncludeCreatedNodesWithCorrectLabelAndProperty() throws Exception {
// Given
when(indexReader.query(withValue)).then(answerAsPrimitiveLongIteratorFrom(asList(2L, 3L)));
long nodeId = 1L;
state.txState().nodeDoAddProperty(nodeId, stringProperty(propertyKeyId, value));
when(statement.acquireSingleNodeCursor(nodeId)).thenReturn(asNodeCursor(nodeId, 40L));
mockStoreProperty();
when(store.indexesGetForLabel(labelId)).thenReturn(indexes.iterator());
txContext.nodeAddLabel(state, nodeId, labelId);
// When
PrimitiveLongIterator result = txContext.indexQuery(state, newIndexDescriptor, withValue);
// Then
assertThat(PrimitiveLongCollections.toSet(result), equalTo(asSet(nodeId, 2L, 3L)));
}
use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.
the class IndexingAcceptanceTest method shouldNotIncludeNodesDeletedInSameTxInIndexSeekByPrefix.
@Test
public void shouldNotIncludeNodesDeletedInSameTxInIndexSeekByPrefix() throws SchemaRuleNotFoundException, IndexNotFoundKernelException, IndexNotApplicableKernelException {
// GIVEN
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
IndexDefinition index = Neo4jMatchers.createIndex(db, LABEL1, "name");
createNodes(db, LABEL1, "name", "Mattias");
PrimitiveLongSet toDelete = createNodes(db, LABEL1, "name", "Karlsson", "Mats");
PrimitiveLongSet expected = createNodes(db, LABEL1, "name", "Karl");
// WHEN
PrimitiveLongSet found = Primitive.longSet();
try (Transaction tx = db.beginTx()) {
PrimitiveLongIterator deleting = toDelete.iterator();
while (deleting.hasNext()) {
long id = deleting.next();
db.getNodeById(id).delete();
expected.remove(id);
}
Statement statement = getStatement((GraphDatabaseAPI) db);
ReadOperations readOperations = statement.readOperations();
NewIndexDescriptor descriptor = indexDescriptor(readOperations, index);
int propertyKeyId = descriptor.schema().getPropertyId();
found.addAll(readOperations.indexQuery(descriptor, stringPrefix(propertyKeyId, "Karl")));
}
// THEN
assertThat(found, equalTo(expected));
}
use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.
the class CompositeIndexingIT method shouldSeeAllNodesAddedBeforeTransaction.
@Test
public void shouldSeeAllNodesAddedBeforeTransaction() throws Exception {
if (// this test does not make any sense for UNIQUE indexes
index.type() != UNIQUE) {
long nodeID1 = createNode();
long nodeID2 = createNode();
long nodeID3 = createNode();
try (Transaction ignore = graphDatabaseAPI.beginTx()) {
PrimitiveLongIterator resultIterator = seek();
Set<Long> result = PrimitiveLongCollections.toSet(resultIterator);
assertThat(result, contains(nodeID1, nodeID2, nodeID3));
}
}
}
use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.
the class CompositeIndexingIT method shouldSeeNodeAddedToByLabelIndexInTransaction.
@Test
public void shouldSeeNodeAddedToByLabelIndexInTransaction() throws Exception {
try (Transaction ignore = graphDatabaseAPI.beginTx()) {
DataWriteOperations writeOperations = statement().dataWriteOperations();
long nodeID = writeOperations.nodeCreate();
for (int propID : index.schema().getPropertyIds()) {
writeOperations.nodeSetProperty(nodeID, DefinedProperty.intProperty(propID, propID));
}
writeOperations.nodeAddLabel(nodeID, LABEL_ID);
PrimitiveLongIterator resultIterator = seek();
assertThat(resultIterator.next(), equalTo(nodeID));
assertFalse(resultIterator.hasNext());
}
}
use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.
the class HopScotchHashingAlgorithmTest method shouldSupportIteratingThroughResize.
@Test
public void shouldSupportIteratingThroughResize() throws Exception {
// GIVEN
int threshold = figureOutGrowthThreshold();
TableGrowthAwareMonitor monitor = new TableGrowthAwareMonitor();
PrimitiveLongSet set = new PrimitiveLongHashSet(new LongKeyTable<>(DEFAULT_H, VALUE_MARKER), VALUE_MARKER, monitor);
Set<Long> added = new HashSet<>();
for (int i = 0; i < threshold - 1; i++) {
long value = i * 3;
set.add(value);
added.add(value);
}
// WHEN
PrimitiveLongIterator iterator = set.iterator();
Set<Long> iterated = new HashSet<>();
for (int i = 0; i < threshold / 2; i++) {
iterated.add(iterator.next());
}
assertFalse(monitor.checkAndReset());
// will push it over the edge, to grow the table
set.add((threshold - 1) * 3);
assertTrue(monitor.checkAndReset());
while (iterator.hasNext()) {
iterated.add(iterator.next());
}
// THEN
assertEquals(added, iterated);
}
Aggregations