Apache Lucene open-source search software
SOLR-7594: Fix test bug on RptWithGeometryField's cache state The bug was that I can't compare the segment count; I should compare cache keys
David Wayne Smileyb70192e95ca8
diff --git a/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java b/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.javaindex c00bb6e2d30..c1903102c6c 100644--- a/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java+++ b/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java@@ -126,18 +126,23 @@ public class TestSolr4Spatial2 extends SolrTestCaseJ4 {assertEquals("1", cache.getStatistics().get("cumulative_hits").toString());assertEquals("1 segment",- 1, ((SolrIndexSearcher) h.getCore().getInfoRegistry().get("searcher")).getRawReader().leaves().size());+ 1, getSearcher().getRawReader().leaves().size());+ // Get key of first leaf reader -- this one contains the match for sure.+ Object leafKey1 = getFirstLeafReaderKey();+// add new segmentassertU(adoc("id", "3"));+assertU(commit()); // sometimes merges (to one seg), sometimes won't- boolean newSeg =- (((SolrIndexSearcher)h.getCore().getInfoRegistry().get("searcher")).getRawReader().leaves().size() > 1);// can still find the same documentassertJQ(sameReq, "/response/numFound==1", "/response/docs/[0]/id=='1'");- // when there are new segments, we accumulate another hit. This tests the cache was not blown away on commit.- assertEquals(newSeg ? "2" : "1", cache.getStatistics().get("cumulative_hits").toString());+ // When there are new segments, we accumulate another hit. This tests the cache was not blown away on commit.+ // Checking equality for the first reader's cache key indicates wether the cache should still be valid.+ Object leafKey2 = getFirstLeafReaderKey();+ assertEquals(leafKey1.equals(leafKey2) ? "2" : "1", cache.getStatistics().get("cumulative_hits").toString());+// Now try to see if heatmaps work:assertJQ(req("q", "*:*", "facet", "true", FacetParams.FACET_HEATMAP, fieldName, "json.nl", "map"),@@ -145,4 +150,14 @@ public class TestSolr4Spatial2 extends SolrTestCaseJ4 {}+ protected SolrIndexSearcher getSearcher() {+ // neat trick; needn't deal with the hassle RefCounted+ return (SolrIndexSearcher) h.getCore().getInfoRegistry().get("searcher");+ }+++ protected Object getFirstLeafReaderKey() {+ return getSearcher().getRawReader().leaves().get(0).reader().getCoreCacheKey();+ }+}