LUCENE-10529: Fix TestTaxonomyFacetAssociations NPE when randomly indexing no documents for dim

This commit is contained in:
Greg Miller 2022-04-26 20:05:39 -07:00
parent 2a618586de
commit f11468186a
2 changed files with 23 additions and 6 deletions

View File

@ -149,6 +149,9 @@ Bug Fixes
* LUCENE-10533: SpellChecker.formGrams is missing bounds check (Kevin Risden)
* LUCENE-10529: Properly handle when TestTaxonomyFacetAssociations test case randomly indexes
no documents instead of throwing an NPE. (Greg Miller)
Build
---------------------

View File

@ -427,9 +427,16 @@ public class TestTaxonomyFacetAssociations extends FacetTestCase {
}
FacetResult facetResult = facets.getTopChildren(10, dim);
assertEquals(dim, facetResult.dim);
assertEquals(aggregatedValue, facetResult.value.intValue());
assertEquals(expected.size(), facetResult.childCount);
if (expected.isEmpty()) {
// If we hit the rare random case where nothing is indexed for the dim, we expect a null
// facetResult (see: LUCENE-10529)
assertNull(facetResult);
} else {
assertEquals(dim, facetResult.dim);
assertEquals(aggregatedValue, facetResult.value.intValue());
assertEquals(expected.size(), facetResult.childCount);
}
}
private void validateFloats(
@ -451,8 +458,15 @@ public class TestTaxonomyFacetAssociations extends FacetTestCase {
}
FacetResult facetResult = facets.getTopChildren(10, dim);
assertEquals(dim, facetResult.dim);
assertEquals(aggregatedValue, facetResult.value.floatValue(), 1);
assertEquals(expected.size(), facetResult.childCount);
if (expected.isEmpty()) {
// If we hit the rare random case where nothing is indexed for the dim, we expect a null
// facetResult (see: LUCENE-10529)
assertNull(facetResult);
} else {
assertEquals(dim, facetResult.dim);
assertEquals(aggregatedValue, facetResult.value.floatValue(), 1);
assertEquals(expected.size(), facetResult.childCount);
}
}
}