Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

Improve BadClusterTest and some ZK/Curator error handling

Houston Putman42629b5a687c
diff --git a/solr/core/src/java/org/apache/solr/cloud/Overseer.java b/solr/core/src/java/org/apache/solr/cloud/Overseer.java
index a32a5d1cdfc..12b2cfa7206 100644
--- a/solr/core/src/java/org/apache/solr/cloud/Overseer.java
+++ b/solr/core/src/java/org/apache/solr/cloud/Overseer.java
@@ -481,7 +481,7 @@ public class Overseer implements SolrCloseable {
byte[] data;
try {
data = zkClient.getData(path, null, stat, true);
- } catch (IllegalStateException e) {
+ } catch (IllegalStateException | KeeperException.NoNodeException e) {
return;
} catch (Exception e) {
log.warn("Error communicating with ZooKeeper", e);
diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkController.java b/solr/core/src/java/org/apache/solr/cloud/ZkController.java
index ff6540d0153..1a14c2006a5 100644
--- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java
+++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java
@@ -529,7 +529,9 @@ public class ZkController implements Closeable {
} catch (InterruptedException e) {
// Restore the interrupted status
Thread.currentThread().interrupt();
- throw new ZooKeeperException(ErrorCode.SERVER_ERROR, "", e);
+ // This means that we are closing down and the executor is shut down.
+ // There is no need to throw an additional error here, as the executor will
+ // not accept further listener commands.
} catch (Exception e) {
log.error("Exception during reconnect", e);
throw new ZooKeeperException(ErrorCode.SERVER_ERROR, "", e);
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/BadClusterTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/BadClusterTest.java
index b401d073af3..089f85e1bc5 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/BadClusterTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/BadClusterTest.java
@@ -32,6 +32,7 @@ import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.MultiMapSolrParams;
+import org.hamcrest.Matchers;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -86,7 +87,9 @@ public class BadClusterTest extends SolrCloudTestCase {
private void testAllNodesDown() throws Exception {
try (CloudSolrStream stream = new CloudSolrStream(buildSearchExpression(), streamFactory)) {
- cluster.expireZkSession(cluster.getReplicaJetty(getReplicas().get(0)));
+ // Pre-warm the streaming clients, so that the following getTuples can fail quickly
+ assertEquals(0, getTuples(stream).size());
+ cluster.expireZkSession(cluster.getReplicaJetty(getReplicas().getFirst()));
expectThrows(IOException.class, () -> getTuples(stream));
}
}
@@ -94,12 +97,18 @@ public class BadClusterTest extends SolrCloudTestCase {
private void testClusterShutdown() throws Exception {
try (CloudSolrStream stream = new CloudSolrStream(buildSearchExpression(), streamFactory)) {
cluster.shutdown();
- getTuples(stream);
- fail("Expected IOException: SolrException: TimeoutException");
- } catch (IOException ioe) {
+ IOException ioe = expectThrows(IOException.class, () -> getTuples(stream));
+ assertNotNull("IOException must have a SolrException cause", ioe.getCause());
+ assertThat(
+ "Cause of IOException is incorrect",
+ ioe.getCause(),
+ Matchers.instanceOf(SolrException.class));
SolrException se = (SolrException) ioe.getCause();
- TimeoutException te = (TimeoutException) se.getCause();
- assertNotNull(te);
+ assertNotNull("SolrException must have a TimeoutException cause", se.getCause());
+ assertThat(
+ "Cause of SolrException is incorrect",
+ se.getCause(),
+ Matchers.instanceOf(TimeoutException.class));
}
}