mirror of https://github.com/apache/lucene.git
SOLR-844 followup -- Fix bug with incorrect alive count which makes LBHttpSolrServer assume that all servers are down even when one is running
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@765912 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
05116b7cc0
commit
3f7f21c995
|
@ -190,6 +190,7 @@ public class LBHttpSolrServer extends SolrServer {
|
|||
int count = counter.incrementAndGet();
|
||||
int attempts = 0;
|
||||
Exception ex;
|
||||
int startSize = aliveServers.size();
|
||||
while (true) {
|
||||
int size = aliveServers.size();
|
||||
if (size < 1) throw new SolrServerException("No live SolrServers available to handle this request");
|
||||
|
@ -216,7 +217,7 @@ public class LBHttpSolrServer extends SolrServer {
|
|||
throw new SolrServerException(e);
|
||||
}
|
||||
attempts++;
|
||||
if (attempts >= aliveServers.size())
|
||||
if (attempts >= startSize)
|
||||
throw new SolrServerException("No live SolrServers available to handle this request", ex);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package org.apache.solr.client.solrj;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.Assert;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
|
||||
|
@ -118,6 +119,28 @@ public class TestLBHttpSolrServer extends TestCase {
|
|||
assertEquals(3, names.size());
|
||||
}
|
||||
|
||||
public void testTwoServers() throws Exception {
|
||||
LBHttpSolrServer lbHttpSolrServer = new LBHttpSolrServer(httpClient, solr[0].getUrl(), solr[1].getUrl());
|
||||
lbHttpSolrServer.setAliveCheckInterval(1);
|
||||
SolrQuery solrQuery = new SolrQuery("*:*");
|
||||
Set<String> names = new HashSet<String>();
|
||||
QueryResponse resp = null;
|
||||
solr[0].jetty.stop();
|
||||
solr[0].jetty = null;
|
||||
resp = lbHttpSolrServer.query(solrQuery);
|
||||
String name = resp.getResults().get(0).getFieldValue("name").toString();
|
||||
Assert.assertEquals("solr1", name);
|
||||
resp = lbHttpSolrServer.query(solrQuery);
|
||||
name = resp.getResults().get(0).getFieldValue("name").toString();
|
||||
Assert.assertEquals("solr1", name);
|
||||
solr[1].jetty.stop();
|
||||
solr[1].jetty = null;
|
||||
solr[0].startJetty();
|
||||
Thread.sleep(1200);
|
||||
resp = lbHttpSolrServer.query(solrQuery);
|
||||
name = resp.getResults().get(0).getFieldValue("name").toString();
|
||||
Assert.assertEquals("solr0", name);
|
||||
}
|
||||
|
||||
private class SolrInstance extends AbstractSolrTestCase {
|
||||
|
||||
|
|
Loading…
Reference in New Issue