You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by iv...@apache.org on 2026/05/22 13:43:47 UTC

(lucene) branch main updated: Make TestSimilarity#testTermDocSimilarity thread safe (#16108)

This is an automated email from the ASF dual-hosted git repository.

iverase pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/main by this push:
     new 9c957f8a2c6 Make TestSimilarity#testTermDocSimilarity thread safe (#16108)
9c957f8a2c6 is described below

commit 9c957f8a2c6dea79e834b308ec2288d999f5acbd
Author: Ignacio Vera <iv...@apache.org>
AuthorDate: Fri May 22 14:43:41 2026 +0100

    Make TestSimilarity#testTermDocSimilarity thread safe (#16108)
---
 lucene/core/src/test/org/apache/lucene/search/TestSimilarity.java | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSimilarity.java b/lucene/core/src/test/org/apache/lucene/search/TestSimilarity.java
index 6ec72a4a5fa..de2b5078e8b 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestSimilarity.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestSimilarity.java
@@ -18,6 +18,7 @@ package org.apache.lucene.search;
 
 import java.io.IOException;
 import java.util.Collection;
+import java.util.concurrent.atomic.LongAdder;
 import java.util.function.Function;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
@@ -268,7 +269,7 @@ public class TestSimilarity extends LuceneTestCase {
       throws IOException {
     CollectorManager<SimpleCollector, Integer> collector =
         new CollectorManager<>() {
-          int count = 0;
+          final LongAdder count = new LongAdder();
 
           @Override
           public SimpleCollector newCollector() {
@@ -279,8 +280,7 @@ public class TestSimilarity extends LuceneTestCase {
               public void collect(int doc) throws IOException {
                 // System.out.println("Doc=" + doc + " score=" + scorer.score());
                 assertEquals(scores[doc + base], scorer.score(), 0);
-                // not thread-safe, but I think it's OK?
-                ++count;
+                count.increment();
               }
 
               @Override
@@ -292,7 +292,7 @@ public class TestSimilarity extends LuceneTestCase {
 
           @Override
           public Integer reduce(Collection<SimpleCollector> collectors) {
-            return count;
+            return count.intValue();
           }
         };