public void testSimple() throws Exception {
String[] s = new String[solr.length];
for (int i = 0; i < solr.length; i++) {
s[i] = solr[i].getUrl();
}
LBHttpSolrServer lbHttpSolrServer = new LBHttpSolrServer(httpClient, s);
lbHttpSolrServer.setAliveCheckInterval(500);
SolrQuery solrQuery = new SolrQuery("*:*");
Set<String> names = new HashSet<String>();
QueryResponse resp = null;
for (String value : s) {
resp = lbHttpSolrServer.query(solrQuery);
assertEquals(10, resp.getResults().getNumFound());
names.add(resp.getResults().get(0).getFieldValue("name").toString());
}
assertEquals(3, names.size());
// Kill a server and test again
solr[1].jetty.stop();
solr[1].jetty = null;
names.clear();
for (String value : s) {
resp = lbHttpSolrServer.query(solrQuery);
assertEquals(10, resp.getResults().getNumFound());
names.add(resp.getResults().get(0).getFieldValue("name").toString());
}
assertEquals(2, names.size());
assertFalse(names.contains("solr1"));
// Start the killed server once again
solr[1].startJetty();
// Wait for the alive check to complete
Thread.sleep(1200);
names.clear();
for (String value : s) {
resp = lbHttpSolrServer.query(solrQuery);
assertEquals(10, resp.getResults().getNumFound());
names.add(resp.getResults().get(0).getFieldValue("name").toString());
}
assertEquals(3, names.size());
}