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:27:26 UTC

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

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

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


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

commit 1eef78d5f89eac07fca23df9a35cf016f420112d
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();