SOLR-6374: Improved TestIntervalFaceting: Avoid asserting on number of segments as that depends on the seed. Skip tests when multiple segments can't be generated easily

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1617858 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tomas Eduardo Fernandez Lobbe 2014-08-14 00:21:29 +00:00
parent b7ad072dda
commit e0c00539b5
1 changed files with 27 additions and 6 deletions

View File

@ -68,7 +68,6 @@ public class TestIntervalFaceting extends SolrTestCaseJ4 {
assertU(adoc("id", "9", "test_ss_dv", "cat"));
assertU(adoc("id", "10"));
assertU(commit());
assertMultipleReaders();
assertIntervalQueriesString("test_ss_dv");
assertU(delQ("*:*"));
@ -100,7 +99,18 @@ public class TestIntervalFaceting extends SolrTestCaseJ4 {
assertU(adoc("id", "9", "test_s_dv", "cat"));
assertU(adoc("id", "10"));
assertU(commit());
assertMultipleReaders();
int i = 11;
while (getNumberOfReaders() < 2 && i < 10) {
//try to get more than one segment
assertU(adoc("id", String.valueOf(i), "test_i_dv", String.valueOf(i)));
assertU(commit());
}
if (getNumberOfReaders() < 2) {
// It is OK if for some seeds we fall into this case (for example, TieredMergePolicy with
// segmentsPerTier=2). Most of the case we shouldn't and the test should proceed.
log.warn("Could not generate more than 1 segment for this seed. Will skip the test");
return;
}
assertIntervalQueriesString("test_s_dv");
@ -126,12 +136,11 @@ public class TestIntervalFaceting extends SolrTestCaseJ4 {
assertIntervalQuery("test_s_dv", "[Las\\,,Los Angeles]", "1");
}
private void assertMultipleReaders() {
private int getNumberOfReaders() {
RefCounted<SolrIndexSearcher> searcherRef = h.getCore().getSearcher();
try {
SolrIndexSearcher searcher = searcherRef.get();
int numReaders = searcher.getTopReaderContext().leaves().size();
assertTrue("Expected multiple reader leaves. Found " + numReaders, numReaders >= 2);
return searcher.getTopReaderContext().leaves().size();
} finally {
searcherRef.decref();
}
@ -708,7 +717,19 @@ public class TestIntervalFaceting extends SolrTestCaseJ4 {
assertU(adoc("id", "10"));
assertU(adoc("id", "11", "test_i_dv", "10"));
assertU(commit());
assertMultipleReaders();
int i = 12;
while (getNumberOfReaders() < 2 && i < 10) {
//try to get more than one segment
assertU(adoc("id", String.valueOf(i), "test_s_dv", String.valueOf(i)));
assertU(commit());
}
if (getNumberOfReaders() < 2) {
// It is OK if for some seeds we fall into this case (for example, TieredMergePolicy with
// segmentsPerTier=2). Most of the case we shouldn't and the test should proceed.
log.warn("Could not generate more than 1 segment for this seed. Will skip the test");
return;
}
assertIntervalQueriesNumeric("test_i_dv");
}