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

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1026868 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2010-10-24 19:10:10 +00:00
parent af9e49cf88
commit 9c7336c45c
1 changed files with 40 additions and 1 deletions

View File

@ -19,6 +19,7 @@ package org.apache.solr.client.solrj;
import junit.framework.Assert; import junit.framework.Assert;
import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
@ -49,7 +50,8 @@ public class TestLBHttpSolrServer extends LuceneTestCase {
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
httpClient = new HttpClient(); httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
httpClient.getParams().setParameter("http.connection.timeout", new Integer(1000)); httpClient.getParams().setParameter("http.connection.timeout", new Integer(1000));
for (int i = 0; i < solr.length; i++) { for (int i = 0; i < solr.length; i++) {
solr[i] = new SolrInstance("solr" + i, 0); solr[i] = new SolrInstance("solr" + i, 0);
@ -153,6 +155,43 @@ public class TestLBHttpSolrServer extends LuceneTestCase {
Assert.assertEquals("solr0", name); 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 { private class SolrInstance {
String name; String name;
File homeDir; File homeDir;