mirror of https://github.com/apache/lucene.git
SOLR-5504: Windows can throw a ConnectException when Linux throws a SocketException - also add a bit more testing.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1546224 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e54b08e2ab
commit
e5fbf6dce2
|
@ -19,6 +19,7 @@ package org.apache.solr.update;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.SocketException;
|
||||
|
||||
import org.apache.solr.client.solrj.SolrRequest;
|
||||
import org.apache.solr.client.solrj.SolrServer;
|
||||
|
@ -31,7 +32,7 @@ public class MockStreamingSolrServers extends StreamingSolrServers {
|
|||
public static Logger log = LoggerFactory
|
||||
.getLogger(MockStreamingSolrServers.class);
|
||||
|
||||
public enum Exp {CONNECT_EXCEPTION};
|
||||
public enum Exp {CONNECT_EXCEPTION, SOCKET_EXCEPTION};
|
||||
|
||||
private volatile Exp exp = null;
|
||||
|
||||
|
@ -53,7 +54,8 @@ public class MockStreamingSolrServers extends StreamingSolrServers {
|
|||
switch (exp) {
|
||||
case CONNECT_EXCEPTION:
|
||||
return new ConnectException();
|
||||
|
||||
case SOCKET_EXCEPTION:
|
||||
return new SocketException();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -318,7 +318,8 @@ public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {
|
|||
|
||||
testMaxRetries();
|
||||
testOneRetry();
|
||||
testRetryNode();
|
||||
testRetryNodeAgainstBadAddress();
|
||||
testRetryNodeWontRetrySocketError();
|
||||
}
|
||||
|
||||
private void testMaxRetries() throws IOException {
|
||||
|
@ -393,13 +394,60 @@ public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {
|
|||
long numFoundAfter = solrclient.query(new SolrQuery("*:*")).getResults()
|
||||
.getNumFound();
|
||||
|
||||
// we will get java.net.SocketException: Network is unreachable, which we don't retry on
|
||||
// we will get java.net.ConnectException which we retry on
|
||||
assertEquals(numFoundBefore + 1, numFoundAfter);
|
||||
assertEquals(0, cmdDistrib.getErrors().size());
|
||||
}
|
||||
|
||||
private void testRetryNodeWontRetrySocketError() throws Exception {
|
||||
final HttpSolrServer solrclient = (HttpSolrServer) clients.get(0);
|
||||
long numFoundBefore = solrclient.query(new SolrQuery("*:*")).getResults()
|
||||
.getNumFound();
|
||||
final MockStreamingSolrServers ss = new MockStreamingSolrServers(updateShardHandler);
|
||||
SolrCmdDistributor cmdDistrib = new SolrCmdDistributor(ss, 5, 0);
|
||||
ss.setExp(Exp.SOCKET_EXCEPTION);
|
||||
ArrayList<Node> nodes = new ArrayList<Node>();
|
||||
|
||||
private void testRetryNode() throws SolrServerException, IOException {
|
||||
ZkNodeProps nodeProps = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, solrclient.getBaseURL(),
|
||||
ZkStateReader.CORE_NAME_PROP, "");
|
||||
|
||||
final AtomicInteger retries = new AtomicInteger();
|
||||
nodeProps = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, solrclient.getBaseURL(), ZkStateReader.CORE_NAME_PROP, "");
|
||||
RetryNode retryNode = new RetryNode(new ZkCoreNodeProps(nodeProps), null, "collection1", "shard1") {
|
||||
@Override
|
||||
public boolean checkRetry() {
|
||||
retries.incrementAndGet();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
nodes.add(retryNode);
|
||||
|
||||
AddUpdateCommand cmd = new AddUpdateCommand(null);
|
||||
cmd.solrDoc = sdoc("id", id.incrementAndGet());
|
||||
ModifiableSolrParams params = new ModifiableSolrParams();
|
||||
|
||||
CommitUpdateCommand ccmd = new CommitUpdateCommand(null, false);
|
||||
cmdDistrib.distribAdd(cmd, nodes, params);
|
||||
|
||||
ss.setExp(null);
|
||||
cmdDistrib.distribCommit(ccmd, nodes, params);
|
||||
cmdDistrib.finish();
|
||||
|
||||
// it will checkRetry, but not actually do it...
|
||||
assertEquals(1, retries.get());
|
||||
|
||||
|
||||
long numFoundAfter = solrclient.query(new SolrQuery("*:*")).getResults()
|
||||
.getNumFound();
|
||||
|
||||
// we will get java.net.SocketException: Network is unreachable, which we don't retry on
|
||||
assertEquals(numFoundBefore, numFoundAfter);
|
||||
assertEquals(1, cmdDistrib.getErrors().size());
|
||||
}
|
||||
|
||||
private void testRetryNodeAgainstBadAddress() throws SolrServerException, IOException {
|
||||
// Test RetryNode
|
||||
SolrCmdDistributor cmdDistrib = new SolrCmdDistributor(updateShardHandler);
|
||||
final HttpSolrServer solrclient = (HttpSolrServer) clients.get(0);
|
||||
|
@ -439,10 +487,17 @@ public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {
|
|||
long numFoundAfter = solrclient.query(new SolrQuery("*:*")).getResults()
|
||||
.getNumFound();
|
||||
|
||||
// we will get java.net.SocketException: Network is unreachable and not retry
|
||||
assertEquals(numFoundBefore, numFoundAfter);
|
||||
// different OS's will throw different exceptions for the bad address above
|
||||
if (numFoundBefore != numFoundAfter) {
|
||||
assertEquals(0, cmdDistrib.getErrors().size());
|
||||
assertEquals(numFoundBefore + 1, numFoundAfter);
|
||||
} else {
|
||||
// we will get java.net.SocketException: Network is unreachable and not retry
|
||||
assertEquals(numFoundBefore, numFoundAfter);
|
||||
|
||||
assertEquals(1, cmdDistrib.getErrors().size());
|
||||
}
|
||||
|
||||
assertEquals(1, cmdDistrib.getErrors().size());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue