From be6faf61a0d1ab00f9b459be5d5717e65adaf8c4 Mon Sep 17 00:00:00 2001 From: Greg Miller Date: Fri, 4 Jun 2021 14:40:07 -0700 Subject: [PATCH] LUCENE-9991: Address bug in TestStringValueFacetCounts (#168) --- lucene/CHANGES.txt | 2 ++ .../facet/TestStringValueFacetCounts.java | 28 +++++++++++-------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 59de22459ee0..c4c353de22d9 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -89,6 +89,8 @@ Bug Fixes * LUCEDNE-9967: Do not throw NullPointerException while trying to handle another exception in ReplicaNode.start (Steven Schlansker) +* LUCENE-9991: Fix edge case failure in TestStringValueFacetCounts (Greg Miller) + Other --------------------- diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestStringValueFacetCounts.java b/lucene/facet/src/test/org/apache/lucene/facet/TestStringValueFacetCounts.java index 2c14830eb05d..895bd7a43273 100644 --- a/lucene/facet/src/test/org/apache/lucene/facet/TestStringValueFacetCounts.java +++ b/lucene/facet/src/test/org/apache/lucene/facet/TestStringValueFacetCounts.java @@ -309,6 +309,22 @@ private void checkFacetResult( 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 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 // we have no insight into the ordinals assigned to the values, we resort) Arrays.sort( @@ -321,12 +337,7 @@ private void checkFacetResult( return cmp; }); - assertEquals("field", facetResult.dim); - assertEquals(0, facetResult.path.length); - assertEquals(expectedTotalDocsWithValue, facetResult.value); - assertEquals(expectedLabelCount, facetResult.childCount); - - for (int i = 0; i < Math.min(topN, expectedCountsSorted.size()); i++) { + for (int i = 0; i < Math.min(topN, maxTopN); i++) { String expectedKey = expectedCountsSorted.get(i).getKey(); int expectedValue = expectedCountsSorted.get(i).getValue(); assertEquals(expectedKey, facetResult.labelValues[i].label); @@ -335,11 +346,6 @@ private void checkFacetResult( assertEquals(expectedValue, facets.getSpecificValue("field", expectedKey)); } - // getAllDims should return a singleton list with the same results as getTopChildren - List 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 // match the expected count provided by faceting if (expectedCountsSorted.isEmpty() == false) {