epugh commented on code in PR #5238:
URL: https://github.com/apache/solr/pull/5238#discussion_r4414212059


##########
solr/core/src/test/org/apache/solr/handler/component/SearchRequestListenerTest.java:
##########
@@ -0,0 +1,402 @@
+/*
+ * 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.handler.component;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Queue;
+import java.util.Set;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.request.QueryRequest;
+import org.apache.solr.client.solrj.request.SolrPing;
+import org.apache.solr.client.solrj.request.SolrQuery;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.client.solrj.request.V2Request;
+import org.apache.solr.client.solrj.response.InputStreamResponseParser;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.cloud.Replica;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.common.util.SimpleOrderedMap;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.embedded.JettySolrRunner;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.request.SolrQueryRequestBase;
+import org.apache.solr.request.SolrRequestInfo;
+import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.search.CallerSpecificQueryLimit;
+import org.apache.solr.util.TestInjection;
+import org.apache.solr.util.ThreadCpuTimer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class SearchRequestListenerTest extends SolrCloudTestCase {
+  private static final String COLLECTION = "listener";
+  private static final String DISPATCH_COLLECTION = "listener_dispatch";
+  private static final int NUM_SHARDS = 2;
+  private static final Queue<Event> events = new ConcurrentLinkedQueue<>();
+
+  private static final List<SearchRequestListener> listeners = new 
ArrayList<>();
+
+  private record Event(String node, SearchRequestInfo info) {}
+
+  @BeforeClass
+  public static void setupCluster() throws Exception {
+    configureCluster(2)
+        .addConfig("conf", configset("cloud-minimal"))
+        .addConfig("dispatch", configset("search-request-listener"))
+        .configure();
+    createCollection(COLLECTION);
+    createCollection(DISPATCH_COLLECTION, "dispatch");
+  }
+
+  @Before
+  public void registerListeners() {
+    events.clear();
+    addListeners(false);
+  }
+
+  @After
+  public void removeListeners() {
+    for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
+      listeners.forEach(jetty.getCoreContainer()::removeSearchRequestListener);
+    }
+    listeners.clear();
+  }
+
+  private static void createCollection(String name) throws Exception {
+    createCollection(name, "conf");
+  }
+
+  private static void createCollection(String name, String config) throws 
Exception {
+    CollectionAdminRequest.createCollection(name, config, NUM_SHARDS, 1)
+        .processAndWait(cluster.getSolrClient(), DEFAULT_TIMEOUT);
+    cluster.waitForActiveCollection(name, NUM_SHARDS, NUM_SHARDS);
+    new UpdateRequest()
+        .add("id", "1")
+        .add("id", "2")
+        .add("id", "3")
+        .commit(cluster.getSolrClient(), name);
+  }
+
+  private static void addListeners(boolean withThrowingListener) {
+    for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
+      String node = jetty.getNodeName();
+      if (withThrowingListener) {
+        addListener(
+            jetty,
+            info -> {
+              throw new RuntimeException("listener failure");
+            });
+      }
+      addListener(jetty, info -> events.add(new Event(node, info)));
+    }
+  }
+
+  private static void addListener(JettySolrRunner jetty, SearchRequestListener 
listener) {
+    listeners.add(listener);
+    jetty.getCoreContainer().addSearchRequestListener(listener);
+  }
+
+  private static SolrClient nodeClient() {

Review Comment:
   cool



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to