You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2010/10/24 21:10:11 UTC

svn commit: r1026868 - /lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java

Author: yonik
Date: Sun Oct 24 19:10:10 2010
New Revision: 1026868

URL: http://svn.apache.org/viewvc?rev=1026868&view=rev
Log:
SOLR-2162: tests should use multi-threaded connection manager

Modified:
    lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java?rev=1026868&r1=1026867&r2=1026868&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java Sun Oct 24 19:10:10 2010
@@ -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 extend
 
   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 extend
     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;