use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class FulltextProceduresTestSupport method assertQueryFindsIds.
static void assertQueryFindsIds(GraphDatabaseService db, boolean queryNodes, String index, String query, LongHashSet ids) {
// Create a defensive copy, because we're going to modify this instance.
ids = new LongHashSet(ids);
String queryCall = queryNodes ? QUERY_NODES : QUERY_RELS;
long[] expectedIds = ids.toArray();
MutableLongSet actualIds = new LongHashSet();
try (Transaction tx = db.beginTx()) {
LongFunction<Entity> getEntity = queryNodes ? tx::getNodeById : tx::getRelationshipById;
Result result = tx.execute(format(queryCall, index, query));
Double score = Double.MAX_VALUE;
while (result.hasNext()) {
Map<String, Object> entry = result.next();
long nextId = ((Entity) entry.get(queryNodes ? NODE : RELATIONSHIP)).getId();
Double nextScore = (Double) entry.get(SCORE);
assertThat(nextScore).isLessThanOrEqualTo(score);
score = nextScore;
actualIds.add(nextId);
if (!ids.remove(nextId)) {
String msg = "This id was not expected: " + nextId;
failQuery(getEntity, index, query, ids, expectedIds, actualIds, msg);
}
}
if (!ids.isEmpty()) {
String msg = "Not all expected ids were found: " + ids;
failQuery(getEntity, index, query, ids, expectedIds, actualIds, msg);
}
tx.commit();
}
}
use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class LuceneFulltextTestSupport method assertQueryFindsIds.
void assertQueryFindsIds(KernelTransaction ktx, boolean nodes, String indexName, String query, long... ids) throws Exception {
IndexDescriptor index = ktx.schemaRead().indexGetForName(indexName);
IndexReadSession indexSession = ktx.dataRead().indexReadSession(index);
MutableLongSet set = LongSets.mutable.of(ids);
if (nodes) {
try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
ktx.dataRead().nodeIndexSeek(indexSession, cursor, unconstrained(), PropertyIndexQuery.fulltextSearch(query));
while (cursor.next()) {
long nodeId = cursor.nodeReference();
assertTrue(set.remove(nodeId), format("Result returned node id %d, expected one of %s", nodeId, Arrays.toString(ids)));
}
}
} else {
try (RelationshipValueIndexCursor cursor = ktx.cursors().allocateRelationshipValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
ktx.dataRead().relationshipIndexSeek(indexSession, cursor, unconstrained(), PropertyIndexQuery.fulltextSearch(query));
while (cursor.next()) {
long relationshipId = cursor.relationshipReference();
assertTrue(set.remove(relationshipId), format("Result returned relationship id %d, expected one of %s", relationshipId, Arrays.toString(ids)));
}
}
}
if (!set.isEmpty()) {
fail("Number of results differ from expected. " + set.size() + " IDs were not found in the result: " + set);
}
}
use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class ReuseStorageSpaceIT method shouldPrioritizeFreelistWhenConcurrentlyAllocating.
@Test
void shouldPrioritizeFreelistWhenConcurrentlyAllocating() throws Exception {
DatabaseManagementService dbms = new TestDatabaseManagementServiceBuilder(directory.homePath()).setConfig(GraphDatabaseInternalSettings.force_small_id_cache, true).build();
try {
// given
GraphDatabaseAPI db = (GraphDatabaseAPI) dbms.database(DEFAULT_DATABASE_NAME);
int numNodes = 40_000;
MutableLongSet nodeIds = createNodes(db, numNodes);
try (Transaction tx = db.beginTx()) {
nodeIds.forEach(nodeId -> tx.getNodeById(nodeId).delete());
tx.commit();
}
db.getDependencyResolver().resolveDependency(IdController.class).maintenance();
// First create 40,000 nodes, then delete them, ensure ID maintenance has run and allocate concurrently
int numThreads = 4;
Collection<Callable<MutableLongSet>> allocators = new ArrayList<>();
for (int i = 0; i < numThreads; i++) {
allocators.add(() -> createNodes(db, numNodes / numThreads));
}
ExecutorService executor = Executors.newFixedThreadPool(numThreads);
List<Future<MutableLongSet>> results = executor.invokeAll(allocators);
MutableLongSet reallocatedNodeIds = LongSets.mutable.withInitialCapacity(numNodes);
for (Future<MutableLongSet> result : results) {
reallocatedNodeIds.addAll(result.get());
}
assertThat(reallocatedNodeIds).as(diff(nodeIds, reallocatedNodeIds)).isEqualTo(nodeIds);
} finally {
dbms.shutdown();
}
}
use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class EntityValueIndexCursorTestBase method shouldPerformExactLookup.
@Test
void shouldPerformExactLookup() throws Exception {
// given
int prop = token.propertyKey(PROP_NAME);
IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(PROP_INDEX_NAME));
try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
MutableLongSet uniqueIds = new LongHashSet();
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, "zero"));
// then
assertFoundEntitiesAndNoValue(cursor, uniqueIds);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, "one"));
// then
assertFoundEntitiesAndNoValue(cursor, uniqueIds, strOne);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, "two"));
// then
assertFoundEntitiesAndNoValue(cursor, uniqueIds, strTwo1, strTwo2);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, "three"));
// then
assertFoundEntitiesAndNoValue(cursor, uniqueIds, strThree1, strThree2, strThree3);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, 1));
// then
assertFoundEntitiesAndNoValue(cursor, 1, uniqueIds);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, 2));
// then
assertFoundEntitiesAndNoValue(cursor, 2, uniqueIds);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, 3));
// then
assertFoundEntitiesAndNoValue(cursor, 3, uniqueIds);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, 6));
// then
assertFoundEntitiesAndNoValue(cursor, uniqueIds, num6);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, 12.0));
// then
assertFoundEntitiesAndNoValue(cursor, uniqueIds, num12a, num12b);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, true));
// then
assertFoundEntitiesAndNoValue(cursor, uniqueIds, boolTrue);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, Values.pointValue(Cartesian, 0, 0)));
// then
assertFoundEntitiesAndNoValue(cursor, 3, uniqueIds);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, Values.pointValue(Cartesian_3D, 0, 0, 0)));
// then
assertFoundEntitiesAndNoValue(cursor, 1, uniqueIds);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, Values.pointValue(WGS84, 0, 0)));
// then
assertFoundEntitiesAndNoValue(cursor, 1, uniqueIds);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, Values.pointValue(WGS84_3D, 0, 0, 0)));
// then
assertFoundEntitiesAndNoValue(cursor, 1, uniqueIds);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, DateValue.date(1989, 3, 24)));
// then
assertFoundEntitiesAndNoValue(cursor, 2, uniqueIds);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, DateValue.date(1986, 11, 18)));
// then
assertFoundEntitiesAndNoValue(cursor, 1, uniqueIds);
}
}
use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class EntityValueIndexCursorTestBase method shouldProvideValuesForPoints.
@Test
void shouldProvideValuesForPoints() throws Exception {
// given
assumeTrue(indexParams.indexProvidesSpatialValues());
int prop = token.propertyKey(EVER_PROP_NAME);
IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(WHAT_EVER_INDEX_NAME));
assertEquals(IndexValueCapability.YES, index.reference().getCapability().valueCapability(ValueCategory.GEOMETRY));
try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
MutableLongSet uniqueIds = new LongHashSet();
// when
entityParams.entityIndexSeek(tx, index, cursor, unorderedValues(), PropertyIndexQuery.range(prop, Cartesian));
// then
assertFoundEntitiesAndValue(cursor, uniqueIds, index.reference().getCapability().valueCapability(ValueCategory.GEOMETRY), true, whateverPoint);
}
}
Aggregations