You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by no...@apache.org on 2022/01/24 06:18:29 UTC

[solr] branch jira/SOLR15715 updated: added test

This is an automated email from the ASF dual-hosted git repository.

noble pushed a commit to branch jira/SOLR15715
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/jira/SOLR15715 by this push:
     new f92b912  added test
f92b912 is described below

commit f92b9126001f88d8149eaab1c9e30cc9033c7217
Author: Noble Paul <no...@gmail.com>
AuthorDate: Mon Jan 24 17:17:51 2022 +1100

    added test
---
 .../apache/solr/api/CoordinatorV2HttpSolrCall.java | 29 +++++++-
 .../solr/servlet/CoordinatorHttpSolrCall.java      | 40 +++++++++--
 .../apache/solr/search/TestCoordinatorRole.java    | 84 ++++++++++++++++++++++
 3 files changed, 148 insertions(+), 5 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/api/CoordinatorV2HttpSolrCall.java b/solr/core/src/java/org/apache/solr/api/CoordinatorV2HttpSolrCall.java
index 5d713db..035fb80 100644
--- a/solr/core/src/java/org/apache/solr/api/CoordinatorV2HttpSolrCall.java
+++ b/solr/core/src/java/org/apache/solr/api/CoordinatorV2HttpSolrCall.java
@@ -1,3 +1,20 @@
+/*
+ * 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.api;
 
 import javax.servlet.http.HttpServletRequest;
@@ -8,15 +25,25 @@ import org.apache.solr.core.SolrCore;
 import org.apache.solr.servlet.CoordinatorHttpSolrCall;
 import org.apache.solr.servlet.SolrDispatchFilter;
 
-public class CoordinatorV2HttpSolrCall extends V2HttpCall{
+public class CoordinatorV2HttpSolrCall extends V2HttpCall {
+  private String collectionName;
   public CoordinatorV2HttpSolrCall(SolrDispatchFilter solrDispatchFilter, CoreContainer cc, HttpServletRequest request,
                                    HttpServletResponse response, boolean retry) {
     super(solrDispatchFilter, cc, request, response, retry);
   }
   @Override
   protected SolrCore getCoreByCollection(String collectionName, boolean isPreferLeader) {
+    this.collectionName = collectionName;
     SolrCore core = super.getCoreByCollection(collectionName, isPreferLeader);
     if (core != null) return core;
     return CoordinatorHttpSolrCall.getCore(this, collectionName, isPreferLeader);
   }
+
+  @Override
+  protected void init() throws Exception {
+    super.init();
+    if(action == SolrDispatchFilter.Action.PROCESS && core != null) {
+      solrReq = CoordinatorHttpSolrCall.wrappedReq(solrReq, collectionName, this);
+    }
+  }
 }
diff --git a/solr/core/src/java/org/apache/solr/servlet/CoordinatorHttpSolrCall.java b/solr/core/src/java/org/apache/solr/servlet/CoordinatorHttpSolrCall.java
index 584da26..82bd3c1 100644
--- a/solr/core/src/java/org/apache/solr/servlet/CoordinatorHttpSolrCall.java
+++ b/solr/core/src/java/org/apache/solr/servlet/CoordinatorHttpSolrCall.java
@@ -1,3 +1,20 @@
+/*
+ * 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.servlet;
 
 import javax.servlet.http.HttpServletRequest;
@@ -6,16 +23,20 @@ import javax.servlet.http.HttpServletResponse;
 import java.lang.invoke.MethodHandles;
 import java.security.Principal;
 import java.util.Map;
+import java.util.Properties;
 import java.util.concurrent.ConcurrentHashMap;
 import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.cloud.CloudDescriptor;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.cloud.ClusterState;
 import org.apache.solr.common.cloud.DocCollection;
+import org.apache.solr.common.cloud.Replica;
 import org.apache.solr.common.cloud.ZkStateReader;
 import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.util.ContentStream;
 import org.apache.solr.common.util.Utils;
 import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.CoreDescriptor;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.request.LocalSolrQueryRequest;
 import org.apache.solr.request.SolrQueryRequest;
@@ -29,6 +50,7 @@ import org.slf4j.LoggerFactory;
 public class CoordinatorHttpSolrCall extends HttpSolrCall {
   public static final String SYNTHETIC_COLL_PREFIX = "SYNTHETIC-CONF-COLL_";
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+  private String collectionName;
 
   public CoordinatorHttpSolrCall(SolrDispatchFilter solrDispatchFilter, CoreContainer cores, HttpServletRequest request,
                                  HttpServletResponse response, boolean retry) {
@@ -37,6 +59,7 @@ public class CoordinatorHttpSolrCall extends HttpSolrCall {
 
   @Override
   protected SolrCore getCoreByCollection(String collectionName, boolean isPreferLeader) {
+    this.collectionName = collectionName;
     SolrCore core = super.getCoreByCollection(collectionName, isPreferLeader);
     if (core != null) return core;
     return getCore(this, collectionName, isPreferLeader);
@@ -124,11 +147,17 @@ public class CoordinatorHttpSolrCall extends HttpSolrCall {
   protected void init() throws Exception {
     super.init();
     if(action == SolrDispatchFilter.Action.PROCESS && core != null) {
-      solrReq = wrappedReq(solrReq);
+      solrReq = wrappedReq(solrReq, collectionName, this);
     }
   }
 
-  private SolrQueryRequest wrappedReq(SolrQueryRequest delegate) {
+  public static SolrQueryRequest wrappedReq(SolrQueryRequest delegate, String collectionName, HttpSolrCall httpSolrCall) {
+    Properties p = new Properties();
+    p.put(CoreDescriptor.CORE_COLLECTION, collectionName);
+    p.put(CloudDescriptor.REPLICA_TYPE, Replica.Type.PULL.toString());
+
+    CloudDescriptor cloudDescriptor =  new CloudDescriptor(delegate.getCore().getCoreDescriptor(),
+            delegate.getCore().getName(), p);
      return new SolrQueryRequest() {
       @Override
       public SolrParams getParams() {
@@ -159,7 +188,6 @@ public class CoordinatorHttpSolrCall extends HttpSolrCall {
       @Override
       public void close() {
         delegate.close();
-
       }
 
       @Override
@@ -215,7 +243,11 @@ public class CoordinatorHttpSolrCall extends HttpSolrCall {
 
        @Override
        public HttpSolrCall getHttpSolrCall() {
-         return CoordinatorHttpSolrCall.this;
+         return httpSolrCall;
+       }
+       @Override
+       public CloudDescriptor getCloudDescriptor() {
+         return cloudDescriptor;
        }
      };
   }
diff --git a/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java b/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java
new file mode 100644
index 0000000..4442814
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java
@@ -0,0 +1,84 @@
+/*
+ * 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.search;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.embedded.JettySolrRunner;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.NavigableObject;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.util.Utils;
+import org.apache.solr.core.NodeRoles;
+import org.apache.solr.servlet.CoordinatorHttpSolrCall;
+import org.junit.BeforeClass;
+
+public class TestCoordinatorRole extends SolrCloudTestCase {
+
+  @BeforeClass
+  public static void setupCluster() throws Exception {
+    configureCluster(4)
+            .addConfig("conf", configset("cloud-minimal"))
+            .configure();
+  }
+
+  public void testSimple() throws Exception {
+    CloudSolrClient client = cluster.getSolrClient();
+    String COLLECTION_NAME = "test_coll";
+    String COLLECTION_NAME_2 = CoordinatorHttpSolrCall.SYNTHETIC_COLL_PREFIX +"conf";
+    CollectionAdminRequest
+            .createCollection(COLLECTION_NAME, "conf", 2, 2)
+            .process(cluster.getSolrClient());
+    cluster.waitForActiveCollection(COLLECTION_NAME, 2, 4);
+    UpdateRequest ur = new UpdateRequest();
+    for (int i = 0; i < 10; i++) {
+      SolrInputDocument doc2 = new SolrInputDocument();
+      doc2.addField("id", "" + i);
+      doc2.addField("fld1_s", "1 value 1 value 1 value 1 value 1 value 1 value 1 value ");
+      doc2.addField("fld2_s", "2 value 2 value 2 value 2 value 2 value 2 value 2 value 2 value 2 value 2 value ");
+      doc2.addField("fld3_s", "3 value 3 value 3 value 3 value 3 value 3 value 3 value 3 value 3 value 3 value 3 value 3 value 3 value 3 value ");
+      doc2.addField("fld4_s", "4 value 4 value 4 value 4 value 4 value 4 value 4 value 4 value 4 value ");
+      doc2.addField("fld5_s", "5 value 5 value 5 value 5 value 5 value 5 value 5 value 5 value 5 value 5 value 5 value 5 value ");
+      ur.add(doc2);
+    }
+
+    ur.commit(client, COLLECTION_NAME);
+    QueryResponse rsp = client.query(COLLECTION_NAME, new SolrQuery("*:*"));
+    assertEquals(10, rsp.getResults().getNumFound());
+
+    System.setProperty(NodeRoles.NODE_ROLES_PROP, "coordinator:on");
+    JettySolrRunner jetty = null;
+    try {
+      jetty = cluster.startJettySolrRunner();
+    } finally {
+      System.clearProperty(NodeRoles.NODE_ROLES_PROP);
+    }
+    NavigableObject result = (NavigableObject) Utils.executeGET(cluster.getSolrClient().getHttpClient(),
+            jetty.getBaseUrl().toString()+"/"+COLLECTION_NAME +"/select?q=*:*&wt=javabin", Utils.JAVABINCONSUMER);
+
+    assertEquals(10, ((Collection)result._get("response", Collections.emptyList())).size());
+
+  }
+
+}
\ No newline at end of file