From c1fe9efb4beb319f3022908b1c755475af222a37 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 9 Oct 2021 12:33:29 -0400 Subject: [PATCH] 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 --- .../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 64f51e886c6..863da7f1792 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); } }