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
1 changed files with 15 additions and 11 deletions

View File

@ -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);
throw new UncheckedIOException(e);
}
})
.sum()
< 1024 * 1024 * maxSegmentSizeMb * 1.5);
.sum();
long limit = (long) (1024 * 1024 * maxSegmentSizeMb * 1.5);
assertTrue(
"size=" + size + ",limit=" + limit + ",maxSegmentSizeMb=" + maxSegmentSizeMb,
size < limit);
}
}