Skip to content

Apache Lucene open-source search software

SOLR-3354: the corecontainer sometimes fail to start (#cores==0), check that everything is correctly set up before going to actual tests or fail fast

Sami Siren6f43ebfd9097
diff --git a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.java b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.java
index 8c88580c24c..f98a89f28fd 100644
--- a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.java
@@ -21,6 +21,7 @@ import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
@@ -94,20 +95,43 @@ public class LeaderElectionIntegrationTest extends SolrTestCaseJ4 {
System.setProperty("solr.test.sys.prop2", "proptwo");
for (int i = 7000; i < 7000 + NUM_SHARD_REPLICAS; i++) {
- setupContainer(i, "shard1");
+ try {
+ setupContainer(i, "shard1");
+ } catch (Throwable t) {
+ log.error("!!!Could not start container:" + i + " The exception thrown was: " + t.getClass() + " " + t.getMessage());
+ fail("Could not start container:" + i + ". Reason:" + t.getClass() + " " + t.getMessage());
+ }
+ }
+ try {
+ setupContainer(3333, "shard2");
+ } catch (Throwable t) {
+ log.error("!!!Could not start container 3333. The exception thrown was: " + t.getClass() + " " + t.getMessage());
+ fail("Could not start container: 3333");
}
-
- setupContainer(3333, "shard2");
zkClient = new SolrZkClient(zkServer.getZkAddress(),
AbstractZkTestCase.TIMEOUT);
-
+
reader = new ZkStateReader(zkClient);
reader.createClusterStateWatchersAndUpdate();
+ boolean initSuccessful = false;
+ for (int i = 0; i < 30; i++) {
+ List<String> liveNodes = zkClient.getChildren("/live_nodes", null, true);
+ if (liveNodes.size() == NUM_SHARD_REPLICAS + 1) {
+ // all nodes up
+ initSuccessful = true;
+ break;
+ }
+ Thread.sleep(1000);
+ log.info("Waiting for more nodes to come up, now: " + liveNodes.size()
+ + "/" + (NUM_SHARD_REPLICAS + 1));
+ }
+ if (!initSuccessful) {
+ fail("Init was not successful!");
+ }
log.info("####SETUP_END " + getName());
-
}
-
+
private void setupContainer(int port, String shard) throws IOException,
ParserConfigurationException, SAXException {
File data = new File(dataDir + File.separator + "data_" + port);
@@ -125,6 +149,8 @@ public class LeaderElectionIntegrationTest extends SolrTestCaseJ4 {
}
ports.add(port);
CoreContainer container = init.initialize();
+ assertTrue("Container " + port + " has no cores!", container.getCores()
+ .size() > 0);
containerMap.put(port, container);
System.clearProperty("solr.solr.home");
System.clearProperty("hostPort");
@@ -171,6 +197,7 @@ public class LeaderElectionIntegrationTest extends SolrTestCaseJ4 {
}
if (leaderPort == newLeaderPort) {
+ zkClient.printLayoutToStdOut();
fail("We didn't find a new leader! " + leaderPort + " was shutdown, but it's still showing as the leader");
}