You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2021/10/09 16:34:51 UTC

[lucene] branch main updated: LUCENE-10160: improve assert to be easier to debug

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

rmuir 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 c1fe9ef  LUCENE-10160: improve assert to be easier to debug
c1fe9ef is described below

commit c1fe9efb4beb319f3022908b1c755475af222a37
Author: Robert Muir <rm...@apache.org>
AuthorDate: Sat Oct 9 12:33:29 2021 -0400

    LUCENE-10160: improve assert to be easier to debug
    
    Instead of a vague: java.lang.AssertionError at..., include some basic
    information:
    
    java.lang.AssertionError: size=16252835,limit=15728640,maxSegmentSizeMb=10.0
---
 .../apache/lucene/index/TestTieredMergePolicy.java | 26 +++++++++++++---------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/lucene/core/src/test/org/apache/lucene/index/TestTieredMergePolicy.java b/lucene/core/src/test/org/apache/lucene/index/TestTieredMergePolicy.java
index 64f51e8..863da7f 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestTieredMergePolicy.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestTieredMergePolicy.java
@@ -17,6 +17,7 @@
 package org.apache.lucene.index;
 
 import java.io.IOException;
+import java.io.UncheckedIOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -494,18 +495,21 @@ public class TestTieredMergePolicy extends BaseMergePolicyTestCase {
 
   private static void assertMaxSize(MergeSpecification specification, double maxSegmentSizeMb) {
     for (OneMerge merge : specification.merges) {
-      assertTrue(
+      long size =
           merge.segments.stream()
-                  .mapToLong(
-                      s -> {
-                        try {
-                          return s.sizeInBytes();
-                        } catch (IOException e) {
-                          throw new AssertionError(e);
-                        }
-                      })
-                  .sum()
-              < 1024 * 1024 * maxSegmentSizeMb * 1.5);
+              .mapToLong(
+                  s -> {
+                    try {
+                      return s.sizeInBytes();
+                    } catch (IOException e) {
+                      throw new UncheckedIOException(e);
+                    }
+                  })
+              .sum();
+      long limit = (long) (1024 * 1024 * maxSegmentSizeMb * 1.5);
+      assertTrue(
+          "size=" + size + ",limit=" + limit + ",maxSegmentSizeMb=" + maxSegmentSizeMb,
+          size < limit);
     }
   }