Apache Lucene open-source search software
:SOLR-13454: Investigate ReindexCollectionTest failures, added more safeguards in bandaid code
Erick Erickson4f8998714174
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.javaindex 21a91ee5441..90203664fc1 100644--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java@@ -121,6 +121,7 @@ import org.apache.solr.common.util.ExecutorUtil;import org.apache.solr.common.util.ObjectReleaseTracker;import org.apache.solr.common.util.SolrjNamedThreadFactory;import org.apache.solr.common.util.SuppressForbidden;+import org.apache.solr.common.util.TimeSource;import org.apache.solr.common.util.Utils;import org.apache.solr.common.util.XML;import org.apache.solr.core.CoreContainer;@@ -152,6 +153,7 @@ import org.apache.solr.util.SSLTestConfig;import org.apache.solr.util.StartupLoggingUtils;import org.apache.solr.util.TestHarness;import org.apache.solr.util.TestInjection;+import org.apache.solr.util.TimeOut;import org.apache.zookeeper.KeeperException;import org.junit.After;import org.junit.AfterClass;@@ -3116,7 +3118,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {QueryResponse rsp = client.query(collection, solrQuery);long found = rsp.getResults().getNumFound();- if (rsp.getResults().getNumFound() == expectedDocCount) {+ if (found == expectedDocCount) {return;}@@ -3131,9 +3133,17 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {// Add the bogus docnew UpdateRequest().add(bogus).commit(client, collection);+ // Let's spin until we find the doc.+ checkUniqueDoc(client, collection, idField, bogusID, true);+// Then remove it, we should be OK now since new searchers have been opened.new UpdateRequest().deleteById(bogusID).commit(client, collection);- // Let's check again to see if we succeeded++ // Now spin until the doc is gone.+ checkUniqueDoc(client, collection, idField, bogusID, false);++ // At this point we're absolutely, totally, positive that a new searcher has been opened, so go ahead and check+ // the actual condition.rsp = client.query(collection, solrQuery);found = rsp.getResults().getNumFound();@@ -3145,6 +3155,31 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {} else if (failAnyway) {fail("Solr11035BandAid failAnyway == true, would have successfully repaired the collection: '" + collection+ "' extra info: '" + tag + "'");+ } else {+ log.warn("Solr11035BandAid, repair successful");+ }+ }+ // Helper for bandaid+ private static void checkUniqueDoc(SolrClient client, String collection, String idField, String id, boolean shouldBeThere) throws IOException, SolrServerException {+ TimeOut timeOut = new TimeOut(100, TimeUnit.SECONDS, TimeSource.NANO_TIME);+ final SolrQuery solrQuery = new SolrQuery(idField + ":" + id);++ while (!timeOut.hasTimedOut()) {+ QueryResponse rsp = client.query(collection, solrQuery);+ long found = rsp.getResults().getNumFound();+ if (shouldBeThere && found == 1) {+ return;+ }+ if (shouldBeThere == false && found == 0) {+ return;+ }+ log.warn("Solr11035BandAid should have succeeded in checkUniqueDoc, shouldBeThere == {}, numFound = {}. Will try again after 250 ms sleep", shouldBeThere, found);+ try {+ Thread.sleep(250);+ } catch (InterruptedException e) {+ return; // just bail+ }}+}}