You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by is...@apache.org on 2021/04/05 21:23:36 UTC
[lucene-solr] branch branch_8x updated: SOLR-15288: Fix test
resource leak issue
This is an automated email from the ASF dual-hosted git repository.
ishan pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/branch_8x by this push:
new 745d2db SOLR-15288: Fix test resource leak issue
745d2db is described below
commit 745d2dbc393ffe60968791e8e6a47b33a8b79bac
Author: Ishan Chattopadhyaya <is...@apache.org>
AuthorDate: Tue Apr 6 02:50:24 2021 +0530
SOLR-15288: Fix test resource leak issue
---
.../client/solrj/impl/CloudSolrClientTest.java | 60 ---------------
.../common/cloud/PerReplicaStatesRestartTest.java | 90 ++++++++++++++++++++++
2 files changed, 90 insertions(+), 60 deletions(-)
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
index 2a5fcad..d726d24 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
@@ -53,7 +53,6 @@ import org.apache.solr.client.solrj.response.RequestStatusState;
import org.apache.solr.client.solrj.response.SolrPingResponse;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.cloud.AbstractDistribZkTestBase;
-import org.apache.solr.cloud.MiniSolrCloudCluster;
import org.apache.solr.cloud.SolrCloudTestCase;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
@@ -1121,63 +1120,4 @@ public class CloudSolrClientTest extends SolrCloudTestCase {
assertEquals(4, prs.states.size());
}
- public void testPRSRestart() throws Exception {
- String testCollection = "prs_restart_test";
- MiniSolrCloudCluster cluster1 =
- configureCluster(1)
- .addConfig("conf1", getFile("solrj").toPath().resolve("solr").resolve("configsets").resolve("streaming").resolve("conf"))
- .withJettyConfig(jetty -> jetty.enableV2(true))
- .configure();
- try {
- CollectionAdminRequest.createCollection(testCollection, "conf1", 1, 1)
- .setPerReplicaState(Boolean.TRUE)
- .process(cluster1.getSolrClient());
- cluster1.waitForActiveCollection(testCollection, 1, 1);
-
- DocCollection c = cluster1.getSolrClient().getZkStateReader().getCollection(testCollection);
- c.forEachReplica((s, replica) -> assertNotNull(replica.getReplicaState()));
- String collectionPath = ZkStateReader.getCollectionPath(testCollection);
- PerReplicaStates prs = PerReplicaStates.fetch(collectionPath, cluster.getZkClient(), null);
- assertEquals(1, prs.states.size());
-
- JettySolrRunner jsr = cluster1.startJettySolrRunner();
- assertEquals(2,cluster1.getJettySolrRunners().size());
-
- // Now let's do an add replica
- CollectionAdminRequest
- .addReplicaToShard(testCollection, "shard1")
- .process(cluster1.getSolrClient());
- cluster1.waitForActiveCollection(testCollection, 1, 2);
- prs = PerReplicaStates.fetch(collectionPath, cluster.getZkClient(), null);
- assertEquals(2, prs.states.size());
- c = cluster1.getSolrClient().getZkStateReader().getCollection(testCollection);
- prs.states.forEachEntry((s, state) -> assertEquals(Replica.State.ACTIVE, state.state));
-
- String replicaName = null;
- for (Replica r : c.getSlice("shard1").getReplicas()) {
- if(r.getNodeName() .equals(jsr.getNodeName())) {
- replicaName = r.getName();
- }
- }
-
- if(replicaName != null) {
- log.info("restarting the node : {}, state.json v: {} downreplica :{}", jsr.getNodeName(), c.getZNodeVersion(), replicaName);
- jsr.stop();
- c = cluster1.getSolrClient().getZkStateReader().getCollection(testCollection);
- log.info("after down node, state.json v: {}", c.getZNodeVersion());
- prs = PerReplicaStates.fetch(collectionPath, cluster.getZkClient(), null);
- PerReplicaStates.State st = prs.get(replicaName);
- assertNotEquals(Replica.State.ACTIVE, st.state);
- jsr.start();
- cluster1.waitForActiveCollection(testCollection, 1, 2);
- prs = PerReplicaStates.fetch(collectionPath, cluster.getZkClient(), null);
- prs.states.forEachEntry((s, state) -> assertEquals(Replica.State.ACTIVE, state.state));
- }
-
- } finally {
- cluster1.shutdown();
- log.info("SHUTDOWN CLUSTER");
- }
-
- }
}
diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesRestartTest.java b/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesRestartTest.java
new file mode 100644
index 0000000..3246adb
--- /dev/null
+++ b/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesRestartTest.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.common.cloud;
+
+import java.lang.invoke.MethodHandles;
+
+import org.apache.solr.client.solrj.embedded.JettySolrRunner;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.cloud.MiniSolrCloudCluster;
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PerReplicaStatesRestartTest extends SolrCloudTestCase {
+
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ public void testPRSRestart() throws Exception {
+ String testCollection = "prs_restart_test";
+ MiniSolrCloudCluster cluster1 =
+ configureCluster(1)
+ .addConfig("conf1", getFile("solrj").toPath().resolve("solr").resolve("configsets").resolve("streaming").resolve("conf"))
+ .withJettyConfig(jetty -> jetty.enableV2(true))
+ .configure();
+ try {
+ CollectionAdminRequest.createCollection(testCollection, "conf1", 1, 1)
+ .setPerReplicaState(Boolean.TRUE)
+ .process(cluster1.getSolrClient());
+ cluster1.waitForActiveCollection(testCollection, 1, 1);
+
+ DocCollection c = cluster1.getSolrClient().getZkStateReader().getCollection(testCollection);
+ c.forEachReplica((s, replica) -> assertNotNull(replica.getReplicaState()));
+ String collectionPath = ZkStateReader.getCollectionPath(testCollection);
+ PerReplicaStates prs = PerReplicaStates.fetch(collectionPath, cluster.getZkClient(), null);
+ assertEquals(1, prs.states.size());
+
+ JettySolrRunner jsr = cluster1.startJettySolrRunner();
+ assertEquals(2,cluster1.getJettySolrRunners().size());
+
+ // Now let's do an add replica
+ CollectionAdminRequest
+ .addReplicaToShard(testCollection, "shard1")
+ .process(cluster1.getSolrClient());
+ cluster1.waitForActiveCollection(testCollection, 1, 2);
+ prs = PerReplicaStates.fetch(collectionPath, cluster.getZkClient(), null);
+ assertEquals(2, prs.states.size());
+ c = cluster1.getSolrClient().getZkStateReader().getCollection(testCollection);
+ prs.states.forEachEntry((s, state) -> assertEquals(Replica.State.ACTIVE, state.state));
+
+ String replicaName = null;
+ for (Replica r : c.getSlice("shard1").getReplicas()) {
+ if(r.getNodeName() .equals(jsr.getNodeName())) {
+ replicaName = r.getName();
+ }
+ }
+
+ if(replicaName != null) {
+ log.info("restarting the node : {}, state.json v: {} downreplica :{}", jsr.getNodeName(), c.getZNodeVersion(), replicaName);
+ jsr.stop();
+ c = cluster1.getSolrClient().getZkStateReader().getCollection(testCollection);
+ log.info("after down node, state.json v: {}", c.getZNodeVersion());
+ prs = PerReplicaStates.fetch(collectionPath, cluster.getZkClient(), null);
+ PerReplicaStates.State st = prs.get(replicaName);
+ assertNotEquals(Replica.State.ACTIVE, st.state);
+ jsr.start();
+ cluster1.waitForActiveCollection(testCollection, 1, 2);
+ prs = PerReplicaStates.fetch(collectionPath, cluster.getZkClient(), null);
+ prs.states.forEachEntry((s, state) -> assertEquals(Replica.State.ACTIVE, state.state));
+ }
+
+ } finally {
+ cluster1.shutdown();
+ }
+
+ }
+}