You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2023/10/13 16:08:41 UTC

[lucene] branch branch_9x updated: Fix TestSizeBoundedForceMerge. (#12673)

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

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


The following commit(s) were added to refs/heads/branch_9x by this push:
     new dfab805fb22 Fix TestSizeBoundedForceMerge. (#12673)
dfab805fb22 is described below

commit dfab805fb22824bc88eb154dad5c3ef705ccf4f2
Author: Adrien Grand <jp...@gmail.com>
AuthorDate: Fri Oct 13 18:05:27 2023 +0200

    Fix TestSizeBoundedForceMerge. (#12673)
    
    This test sometimes fails because `SimpleText` has a non-deterministic size for
    its segment info file, due to escape characters. The test now enforces the
    default codec, and checks that segments have the expected size before moving
    forward with forcemerge().
    
    Closes #12648
---
 .../org/apache/lucene/index/TestSizeBoundedForceMerge.java   | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/lucene/core/src/test/org/apache/lucene/index/TestSizeBoundedForceMerge.java b/lucene/core/src/test/org/apache/lucene/index/TestSizeBoundedForceMerge.java
index fbf1f8533f9..e0fe0616787 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestSizeBoundedForceMerge.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestSizeBoundedForceMerge.java
@@ -23,6 +23,7 @@ import org.apache.lucene.document.StringField;
 import org.apache.lucene.store.ByteBuffersDirectory;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.tests.util.LuceneTestCase;
+import org.apache.lucene.tests.util.TestUtil;
 
 public class TestSizeBoundedForceMerge extends LuceneTestCase {
 
@@ -43,6 +44,9 @@ public class TestSizeBoundedForceMerge extends LuceneTestCase {
 
   private static IndexWriterConfig newWriterConfig() {
     IndexWriterConfig conf = newIndexWriterConfig(null);
+    // Force using the default codec and not e.g. SimpleText which has a non-deterministic byte size
+    // of its segment info due to escape characters.
+    conf.setCodec(TestUtil.getDefaultCodec());
     conf.setMaxBufferedDocs(IndexWriterConfig.DISABLE_AUTO_FLUSH);
     conf.setRAMBufferSizeMB(IndexWriterConfig.DEFAULT_RAM_BUFFER_SIZE_MB);
     // don't use compound files, because the overhead make size checks unreliable.
@@ -67,6 +71,14 @@ public class TestSizeBoundedForceMerge extends LuceneTestCase {
     writer.close();
 
     SegmentInfos sis = SegmentInfos.readLatestCommit(dir);
+    int numberOfSegmentsOfMinimumSize = 1;
+    for (int i = 1; i < sis.size(); ++i) {
+      if (sis.info(i).sizeInBytes() == sis.info(0).sizeInBytes()) {
+        numberOfSegmentsOfMinimumSize++;
+      }
+    }
+    assertEquals(numSegments - 1, numberOfSegmentsOfMinimumSize);
+
     double min = sis.info(0).sizeInBytes();
 
     conf = newWriterConfig();