Skip to content

Apache Lucene open-source search software

SOLR-2162: tests should use multi-threaded connection manager

Yonik Seeley9c7336c45c91
diff --git a/solr/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java b/solr/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java
index 40ea6413c27..01072dba840 100644
--- a/solr/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java
+++ b/solr/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java
@@ -19,6 +19,7 @@ package org.apache.solr.client.solrj;
import junit.framework.Assert;
import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.SolrTestCaseJ4;
@@ -49,7 +50,8 @@ public class TestLBHttpSolrServer extends LuceneTestCase {
public void setUp() throws Exception {
super.setUp();
- httpClient = new HttpClient();
+ httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
+
httpClient.getParams().setParameter("http.connection.timeout", new Integer(1000));
for (int i = 0; i < solr.length; i++) {
solr[i] = new SolrInstance("solr" + i, 0);
@@ -153,6 +155,43 @@ public class TestLBHttpSolrServer extends LuceneTestCase {
Assert.assertEquals("solr0", name);
}
+ public void testReliability() throws Exception {
+ String[] s = new String[solr.length];
+ for (int i = 0; i < solr.length; i++) {
+ s[i] = solr[i].getUrl();
+ }
+ HttpClient myHttpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
+
+ myHttpClient.getParams().setParameter("http.connection.timeout", new Integer(100));
+ myHttpClient.getParams().setParameter("http.socket.timeout", new Integer(100));
+ LBHttpSolrServer lbHttpSolrServer = new LBHttpSolrServer(myHttpClient, s);
+ lbHttpSolrServer.setAliveCheckInterval(500);
+
+ // Kill a server and test again
+ solr[1].jetty.stop();
+ solr[1].jetty = null;
+
+ // query the servers
+ for (String value : s)
+ lbHttpSolrServer.query(new SolrQuery("*:*"));
+
+ // Start the killed server once again
+ solr[1].startJetty();
+ // Wait for the alive check to complete
+ waitForServer(30000, lbHttpSolrServer, 3, "solr1");
+ }
+
+ // wait maximum ms for serverName to come back up
+ private void waitForServer(int maximum, LBHttpSolrServer server, int nServers, String serverName) throws Exception {
+ long endTime = System.currentTimeMillis() + maximum;
+ while (System.currentTimeMillis() < endTime) {
+ QueryResponse resp = server.query(new SolrQuery("*:*"));
+ String name = resp.getResults().get(0).getFieldValue("name").toString();
+ if (name.equals(serverName))
+ return;
+ }
+ }
+
private class SolrInstance {
String name;
File homeDir;