LUCENE-9991: Address bug in TestStringValueFacetCounts (#168)

This commit is contained in:
Greg Miller 2021-06-04 14:40:07 -07:00 committed by GitHub
parent d47b75395c
commit 4404b19142
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 11 deletions

View File

@ -436,6 +436,8 @@ Bug Fixes
* LUCEDNE-9967: Do not throw NullPointerException while trying to handle another exception in * LUCEDNE-9967: Do not throw NullPointerException while trying to handle another exception in
ReplicaNode.start (Steven Schlansker) ReplicaNode.start (Steven Schlansker)
* LUCENE-9991: Fix edge case failure in TestStringValueFacetCounts (Greg Miller)
Other Other
--------------------- ---------------------

View File

@ -297,6 +297,22 @@ public class TestStringValueFacetCounts extends FacetTestCase {
FacetResult facetResult = facets.getTopChildren(topN, "field"); FacetResult facetResult = facets.getTopChildren(topN, "field");
assertEquals("field", facetResult.dim);
assertEquals(0, facetResult.path.length);
assertEquals(expectedTotalDocsWithValue, facetResult.value);
assertEquals(expectedLabelCount, facetResult.childCount);
// getAllDims should return a singleton list with the same results as getTopChildren
List<FacetResult> allDims = facets.getAllDims(topN);
assertEquals(1, allDims.size());
assertEquals(facetResult, allDims.get(0));
// This is a little strange, but we request all labels at this point so that when we
// secondarily sort by label value in order to compare to the expected results, we have
// all the values. See LUCENE-9991:
int maxTopN = expectedCountsSorted.size();
facetResult = facets.getTopChildren(maxTopN, "field");
// also sort expected labels by count, value (these will be sorted by count, ord -- but since // also sort expected labels by count, value (these will be sorted by count, ord -- but since
// we have no insight into the ordinals assigned to the values, we resort) // we have no insight into the ordinals assigned to the values, we resort)
Arrays.sort( Arrays.sort(
@ -309,12 +325,7 @@ public class TestStringValueFacetCounts extends FacetTestCase {
return cmp; return cmp;
}); });
assertEquals("field", facetResult.dim); for (int i = 0; i < Math.min(topN, maxTopN); i++) {
assertEquals(0, facetResult.path.length);
assertEquals(expectedTotalDocsWithValue, facetResult.value);
assertEquals(expectedLabelCount, facetResult.childCount);
for (int i = 0; i < Math.min(topN, expectedCountsSorted.size()); i++) {
String expectedKey = expectedCountsSorted.get(i).getKey(); String expectedKey = expectedCountsSorted.get(i).getKey();
int expectedValue = expectedCountsSorted.get(i).getValue(); int expectedValue = expectedCountsSorted.get(i).getValue();
assertEquals(expectedKey, facetResult.labelValues[i].label); assertEquals(expectedKey, facetResult.labelValues[i].label);
@ -323,11 +334,6 @@ public class TestStringValueFacetCounts extends FacetTestCase {
assertEquals(expectedValue, facets.getSpecificValue("field", expectedKey)); assertEquals(expectedValue, facets.getSpecificValue("field", expectedKey));
} }
// getAllDims should return a singleton list with the same results as getTopChildren
List<FacetResult> allDims = facets.getAllDims(topN);
assertEquals(1, allDims.size());
assertEquals(facetResult, allDims.get(0));
// execute a "drill down" query on one of the values at random and make sure the total hits // execute a "drill down" query on one of the values at random and make sure the total hits
// match the expected count provided by faceting // match the expected count provided by faceting
if (expectedCountsSorted.isEmpty() == false) { if (expectedCountsSorted.isEmpty() == false) {