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
This commit is contained in:
Robert Muir 2021-10-09 12:33:29 -04:00
parent 6c6a3bd5bd
commit c1fe9efb4b
No known key found for this signature in database
GPG Key ID: 817AE1DD322D7ECA

View File

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