You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dn...@apache.org on 2020/04/10 19:28:19 UTC

[lucene-solr] branch master updated: LUCENE-9298: Fix TestBufferedUpdates

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

dnhatn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new 527e651  LUCENE-9298: Fix TestBufferedUpdates
527e651 is described below

commit 527e6516604e0f7ded72d8ac6f7b6b79884b62c5
Author: Nhat Nguyen <nh...@elastic.co>
AuthorDate: Fri Apr 10 15:27:09 2020 -0400

    LUCENE-9298: Fix TestBufferedUpdates
    
    This test failed on Elastic CI because we did not add any term in the
    loop. This commit ensures that we always add at least one docId, term
    and query in the test.
---
 .../apache/lucene/index/TestBufferedUpdates.java   | 40 ++++++++++------------
 1 file changed, 18 insertions(+), 22 deletions(-)

diff --git a/lucene/core/src/test/org/apache/lucene/index/TestBufferedUpdates.java b/lucene/core/src/test/org/apache/lucene/index/TestBufferedUpdates.java
index b240af6..51a5117 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestBufferedUpdates.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestBufferedUpdates.java
@@ -19,37 +19,33 @@ package org.apache.lucene.index;
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.util.LuceneTestCase;
 
-import java.util.stream.IntStream;
-
 /**
  * Unit test for {@link BufferedUpdates}
  */
 public class TestBufferedUpdates extends LuceneTestCase {
-  /**
-   * return a term that maybe duplicated with pre
-   */
-  private static Term mayDuplicate(int bound) {
-    boolean shouldDuplicated = bound > 3 && random().nextBoolean();
-    if (shouldDuplicated) {
-      return new Term("myField", String.valueOf(random().nextInt(bound)));
-    }
-    return new Term("myField", String.valueOf(bound));
-  }
 
   public void testRamBytesUsed() {
     BufferedUpdates bu = new BufferedUpdates("seg1");
     assertEquals(bu.ramBytesUsed(), 0L);
     assertFalse(bu.any());
-    IntStream.range(0, random().nextInt(atLeast(200))).forEach(id -> {
-      int reminder = random().nextInt(3);
-      if (reminder == 0) {
-        bu.addDocID(id);
-      } else if (reminder == 1) {
-        bu.addQuery(new TermQuery(mayDuplicate(id)), id);
-      } else if (reminder == 2) {
-        bu.addTerm((mayDuplicate(id)), id);
-      }
-    });
+    int docIds = atLeast(1);
+    for (int i = 0; i < docIds; i++) {
+      bu.addDocID(random().nextInt(100));
+    }
+
+    int queries = atLeast(1);
+    for (int i = 0; i < queries; i++) {
+      final int docIDUpto = random().nextBoolean() ? Integer.MAX_VALUE : random().nextInt();
+      final Term term = new Term("id", Integer.toString(random().nextInt(100)));
+      bu.addQuery(new TermQuery(term), docIDUpto);
+    }
+
+    int terms = atLeast(1);
+    for (int i = 0; i < terms; i++) {
+      final int docIDUpto = random().nextBoolean() ? Integer.MAX_VALUE : random().nextInt();
+      final Term term = new Term("id", Integer.toString(random().nextInt(100)));
+      bu.addTerm(term, docIDUpto);
+    }
     assertTrue("we have added tons of docIds, terms and queries", bu.any());
 
     long totalUsed = bu.ramBytesUsed();