dweiss commented on code in PR #15306:
URL: https://github.com/apache/lucene/pull/15306#discussion_r2414648648
##########
lucene/core/src/test/org/apache/lucene/util/TestPriorityQueue.java:
##########
@@ -208,57 +209,48 @@ public void testAddAllDoesNotFitIntoQueue() {
() -> pq.addAll(list));
}
+ /** Randomly add and remove elements, comparing against the reference
java.util.PriorityQueue. */
public void testRemovalsAndInsertions() {
- Random random = random();
- int numDocsInPQ = TestUtil.nextInt(random, 1, 100);
- IntegerQueue pq = new IntegerQueue(numDocsInPQ);
- Integer lastLeast = null;
-
- // Basic insertion of new content
- ArrayList<Integer> sds = new ArrayList<>(numDocsInPQ);
- for (int i = 0; i < numDocsInPQ * 10; i++) {
- Integer newEntry = Math.abs(random.nextInt());
- sds.add(newEntry);
- Integer evicted = pq.insertWithOverflow(newEntry);
- pq.checkValidity();
- if (evicted != null) {
- assertTrue(sds.remove(evicted));
- if (evicted != newEntry) {
- assertSame(evicted, lastLeast);
+ int maxElement = RandomNumbers.randomIntBetween(random(), 1, 10_000);
+ int size = maxElement / 2 + 1;
+
+ var reference = new java.util.PriorityQueue<Integer>();
+ var pq = new IntegerQueue(size);
+
+ Random localRandom = new Xoroshiro128PlusRandom(random().nextLong());
+
+ // Lucene's PriorityQueue.remove uses reference equality, not .equals to
determine which
+ // elements
+ // to remove (!).
+ HashMap<Integer, Integer> ints = new HashMap<>();
Review Comment:
This test had a huge iteration count, was checking tons of stuff
unnecessarily... I rewrote it to just compare against Java's PriorityQueue...
but it turned out that lucene's PriorityQueue.remove(T) is implemented as a
linear scan through all elements, with reference equality (which is surprising
to say the least...). That's why this "cache" of ints needs to be here.
PQ.remove is only used from one place within Lucene... maybe we should drop
this method entirely (or at least change == to .equals to be less surprising?).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]