Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-5682: Make the admin InfoHandler more pluggable / derivable.

Mark Robert Miller801c267066dd
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 243714fb090..74b6b9795f8 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -173,6 +173,9 @@ New Features
response into an entry in the NamedList.
(Upayavira, Vitaliy Zhovtyuk via shalin)
+* SOLR-5682: Make the admin InfoHandler more pluggable / derivable.
+ (Greg Chanan via Mark Miller)
+
Bug Fixes
----------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/InfoHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/InfoHandler.java
index 6ce5a5f6c1e..6c23ff26f32 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/InfoHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/InfoHandler.java
@@ -109,4 +109,36 @@ public class InfoHandler extends RequestHandlerBase {
public String getSource() {
return "$URL: https://svn.apache.org/repos/asf/lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/InfoHandler.java $";
}
+
+ protected PropertiesRequestHandler getPropertiesHandler() {
+ return propertiesHandler;
+ }
+
+ protected ThreadDumpHandler getThreadDumpHandler() {
+ return threadDumpHandler;
+ }
+
+ protected LoggingHandler getLoggingHandler() {
+ return loggingHandler;
+ }
+
+ protected SystemInfoHandler getSystemInfoHandler() {
+ return systemInfoHandler;
+ }
+
+ protected void setPropertiesHandler(PropertiesRequestHandler propertiesHandler) {
+ this.propertiesHandler = propertiesHandler;
+ }
+
+ protected void setThreadDumpHandler(ThreadDumpHandler threadDumpHandler) {
+ this.threadDumpHandler = threadDumpHandler;
+ }
+
+ protected void setLoggingHandler(LoggingHandler loggingHandler) {
+ this.loggingHandler = loggingHandler;
+ }
+
+ protected void setSystemInfoHandler(SystemInfoHandler systemInfoHandler) {
+ this.systemInfoHandler = systemInfoHandler;
+ }
}
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/InfoHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/InfoHandlerTest.java
index 306a99d1d85..6ac9d8637c4 100644
--- a/solr/core/src/test/org/apache/solr/handler/admin/InfoHandlerTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/InfoHandlerTest.java
@@ -17,9 +17,9 @@
package org.apache.solr.handler.admin;
+import java.io.IOException;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
-import org.apache.solr.common.params.CommonParams;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
@@ -68,6 +68,98 @@ public class InfoHandlerTest extends SolrTestCaseJ4 {
}
+ @Test
+ public void testOverriddenHandlers() throws Exception {
+ final CoreContainer cores = h.getCoreContainer();
+ final InfoHandler infoHandler = new InfoHandler(cores);
+ infoHandler.init(null);
+
+ CountPropertiesRequestHandler propHandler = new CountPropertiesRequestHandler();
+ CountThreadDumpHandler threadHandler = new CountThreadDumpHandler();
+ CountLoggingHandler loggingHandler = new CountLoggingHandler(cores);
+ CountSystemInfoHandler systemInfoHandler = new CountSystemInfoHandler(cores);
+
+ // set the request handlers
+ infoHandler.setPropertiesHandler(propHandler);
+ infoHandler.setThreadDumpHandler(threadHandler);
+ infoHandler.setLoggingHandler(loggingHandler);
+ infoHandler.setSystemInfoHandler(systemInfoHandler);
+
+ // verify that the sets are reflected in the gets
+ assertEquals(propHandler, infoHandler.getPropertiesHandler());
+ assertEquals(threadHandler, infoHandler.getThreadDumpHandler());
+ assertEquals(loggingHandler, infoHandler.getLoggingHandler());
+ assertEquals(systemInfoHandler, infoHandler.getSystemInfoHandler());
+
+ // call each handler and verify it was actually called
+ handleRequest(infoHandler, "properties");
+ handleRequest(infoHandler, "threads");
+ handleRequest(infoHandler, "logging");
+ handleRequest(infoHandler, "system");
+
+ assertEquals(1, propHandler.getRequestCount());
+ assertEquals(1, threadHandler.getRequestCount());
+ assertEquals(1, loggingHandler.getRequestCount());
+ assertEquals(1, systemInfoHandler.getRequestCount());
+ }
+
+ // derived request handlers that count the number of request body counts made
+ public static class CountPropertiesRequestHandler extends PropertiesRequestHandler {
+ private int requestCount = 0;
+
+ @Override
+ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp)
+ throws IOException {
+ ++requestCount;
+ super.handleRequestBody(req, rsp);
+ }
+
+ public int getRequestCount() { return requestCount; }
+ }
+
+ public static class CountThreadDumpHandler extends ThreadDumpHandler {
+ private int requestCount = 0;
+
+ @Override
+ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp)
+ throws IOException {
+ ++requestCount;
+ super.handleRequestBody(req, rsp);
+ }
+
+ public int getRequestCount() { return requestCount; }
+ }
+
+ public static class CountLoggingHandler extends LoggingHandler {
+ private int requestCount = 0;
+
+ CountLoggingHandler(CoreContainer cores) { super(cores); }
+
+ @Override
+ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp)
+ throws Exception {
+ ++requestCount;
+ super.handleRequestBody(req, rsp);
+ }
+
+ public int getRequestCount() { return requestCount; }
+ }
+
+ public static class CountSystemInfoHandler extends SystemInfoHandler {
+ private int requestCount = 0;
+
+ CountSystemInfoHandler(CoreContainer cores) { super(cores); }
+
+ @Override
+ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp)
+ throws Exception {
+ ++requestCount;
+ super.handleRequestBody(req, rsp);
+ }
+
+ public int getRequestCount() { return requestCount; }
+ }
+
private SolrQueryResponse handleRequest(InfoHandler infoHandler, String path)
throws Exception {
SolrQueryResponse rsp = new SolrQueryResponse();