Apache Lucene open-source search software
SOLR-5652: Make test more deterministicly random, and increase logging to try and track down strange test failure
Chris M. Hostetter6851eab30caa
diff --git a/solr/core/src/test/org/apache/solr/CursorPagingTest.java b/solr/core/src/test/org/apache/solr/CursorPagingTest.javaindex 09c49ce0ec6..5f728bbc6bc 100644--- a/solr/core/src/test/org/apache/solr/CursorPagingTest.java+++ b/solr/core/src/test/org/apache/solr/CursorPagingTest.java@@ -555,16 +555,19 @@ public class CursorPagingTest extends SolrTestCaseJ4 {}/**- * a list of the fields in the schema - excluding _version_+ * An immutable list of the fields in the schema (excluding _version_) in a+ * deterministically random order.*/- private Collection<String> getAllFieldNames() {+ private List<String> getAllFieldNames() {ArrayList<String> names = new ArrayList<String>(37);for (String f : h.getCore().getLatestSchema().getFields().keySet()) {if (! f.equals("_version_")) {names.add(f);}}- return Collections.<String>unmodifiableCollection(names);+ Collections.sort(names);+ Collections.shuffle(names,random());+ return Collections.<String>unmodifiableList(names);}/**diff --git a/solr/core/src/test/org/apache/solr/cloud/DistribCursorPagingTest.java b/solr/core/src/test/org/apache/solr/cloud/DistribCursorPagingTest.javaindex 90ce821c14c..23bade3e8f0 100644--- a/solr/core/src/test/org/apache/solr/cloud/DistribCursorPagingTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/DistribCursorPagingTest.java@@ -38,7 +38,11 @@ import static org.apache.solr.common.params.CursorMarkParams.CURSOR_MARK_NEXT;import static org.apache.solr.common.params.CursorMarkParams.CURSOR_MARK_START;import org.apache.solr.search.CursorMark; //jdoc+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;+import java.io.IOException;+import java.util.List;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;@@ -54,6 +58,8 @@ import java.util.Map;@Slowpublic class DistribCursorPagingTest extends AbstractFullDistribZkTestBase {+ public static Logger log = LoggerFactory.getLogger(DistribCursorPagingTest.class);+public DistribCursorPagingTest() {System.setProperty("solr.test.useFilterForSortedQuery", Boolean.toString(random().nextBoolean()));configString = CursorPagingTest.TEST_SOLRCONFIG_NAME;@@ -456,19 +462,25 @@ public class DistribCursorPagingTest extends AbstractFullDistribZkTestBase {}commit();+ log.info("SOLR-5652: Begining Loop over smallish num of docs");+ final boolean SOLR_5652 = true;+for (String f : allFieldNames) {for (String order : new String[] {" asc", " desc"}) {String sort = f + order + ("id".equals(f) ? "" : ", id" + order);String rows = "" + _TestUtil.nextInt(random(),13,50);- SentinelIntSet ids = assertFullWalkNoDups(initialDocs,+ SentinelIntSet ids = assertFullWalkNoDups(SOLR_5652,+ initialDocs,params("q", "*:*",- "fl","id",+ "fl","id,"+f,"rows",rows,"sort",sort));assertEquals(initialDocs, ids.size());}}+ log.info("SOLR-5652: Ending Loop over smallish num of docs");+// now add a lot more docs, and test a handful of randomized multi-level sortsfor (int i = initialDocs+1; i <= totalDocs; i++) {SolrInputDocument doc = CursorPagingTest.buildRandomDocument(i);@@ -498,9 +510,11 @@ public class DistribCursorPagingTest extends AbstractFullDistribZkTestBase {}/**- * Asks the LukeRequestHandler on the control client for a list of the fields in the schema - excluding _version_+ * Asks the LukeRequestHandler on the control client for a list of the fields in the+ * schema (excluding _version_) and then returns the field names in a deterministically+ * random order.*/- private Collection<String> getAllFieldNames() throws SolrServerException, IOException {+ private List<String> getAllFieldNames() throws SolrServerException, IOException {LukeRequest req = new LukeRequest("/admin/luke");req.setShowSchema(true);NamedList<Object> rsp = controlClient.request(req);@@ -512,7 +526,9 @@ public class DistribCursorPagingTest extends AbstractFullDistribZkTestBase {names.add(item.getKey());}}- return Collections.<String>unmodifiableCollection(names);+ Collections.sort(names);+ Collections.shuffle(names,random());+ return Collections.<String>unmodifiableList(names);}/**@@ -604,11 +620,19 @@ public class DistribCursorPagingTest extends AbstractFullDistribZkTestBase {* </p>*/public SentinelIntSet assertFullWalkNoDups(int maxSize, SolrParams params) throws Exception {+ return assertFullWalkNoDups(false, maxSize, params);+ }++ /** :TODO: refactor method into two arg version once SOLR-5652 is resolved */+ private SentinelIntSet assertFullWalkNoDups(final boolean verbose,+ final int maxSize,+ final SolrParams params) throws Exception {SentinelIntSet ids = new SentinelIntSet(maxSize, -1);String cursorMark = CURSOR_MARK_START;int docsOnThisPage = Integer.MAX_VALUE;while (0 < docsOnThisPage) {- QueryResponse rsp = cloudClient.query(p(params, CURSOR_MARK_PARAM, cursorMark));+ final SolrParams p = p(params, CURSOR_MARK_PARAM, cursorMark);+ QueryResponse rsp = cloudClient.query(p);String nextCursorMark = assertHashNextCursorMark(rsp);SolrDocumentList docs = extractDocList(rsp);docsOnThisPage = docs.size();@@ -621,12 +645,24 @@ public class DistribCursorPagingTest extends AbstractFullDistribZkTestBase {assertEquals("no more docs, but "+CURSOR_MARK_NEXT+" isn't same",cursorMark, nextCursorMark);}++ if (verbose) { // SOLR-5652+ // SolrDocument is a bit more verbose then we need+ StringBuilder s = new StringBuilder();+ for (SolrDocument doc : docs) {+ s.append(doc.getFieldValuesMap().toString());+ s.append("; ");+ }+ log.info("SOLR-5652: ({}) gave us these docs: {}", p, s);+ }+for (SolrDocument doc : docs) {int id = ((Integer)doc.get("id")).intValue();if (ids.exists(id)) {- String msg = "walk already seen: " + id;+ String msg = "(" + p + ") walk already seen: " + id;try {- queryAndCompareShards(params("q","id:"+id));+ queryAndCompareShards(params("distrib","false",+ "q","id:"+id));} catch (AssertionError ae) {throw new AssertionError(msg + ", found shard inconsistency that would explain it...", ae);}