From 8f6343fb83aefd2b5d63bd975e2ba13ff7a273ed Mon Sep 17 00:00:00 2001 From: Mark Robert Miller Date: Thu, 12 Dec 2013 20:15:52 +0000 Subject: [PATCH] SOLR-5548: Give DistributedSearchTestCase / JettySolrRunner the ability to specify extra filters. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1550508 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 3 ++ .../solrj/embedded/JettySolrRunner.java | 36 ++++++++++++++++--- .../solr/BaseDistributedSearchTestCase.java | 10 ++++-- .../cloud/AbstractFullDistribZkTestBase.java | 4 +-- 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 3ae9bcb31e3..3ba5609c003 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -241,6 +241,9 @@ Other Changes * SOLR-5533: Improve out of the box support for running Solr on hdfs with SolrCloud. (Mark Miller) +* SOLR-5548: Give DistributedSearchTestCase / JettySolrRunner the ability to + specify extra filters. (Greg Chanan via Mark Miller) + ================== 4.6.0 ================== Versions of Major Components diff --git a/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java b/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java index b47fa3f314a..7dc0e0e4c88 100644 --- a/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java +++ b/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java @@ -93,6 +93,8 @@ public class JettySolrRunner { /** Maps servlet holders (i.e. factories: class + init params) to path specs */ private SortedMap extraServlets = new TreeMap(); + private SortedMap extraRequestFilters; + private LinkedList extraFilters; private SSLConfig sslConfig; @@ -167,16 +169,30 @@ public class JettySolrRunner { public JettySolrRunner(String solrHome, String context, int port, String solrConfigFilename, String schemaFileName, boolean stopAtShutdown, SortedMap extraServlets) { - if (null != extraServlets) { this.extraServlets.putAll(extraServlets); } - this.init(solrHome, context, port, stopAtShutdown); - this.solrConfigFilename = solrConfigFilename; - this.schemaFilename = schemaFileName; + this (solrHome, context, port, solrConfigFilename, schemaFileName, + stopAtShutdown, extraServlets, null, null); } public JettySolrRunner(String solrHome, String context, int port, String solrConfigFilename, String schemaFileName, boolean stopAtShutdown, SortedMap extraServlets, SSLConfig sslConfig) { + this (solrHome, context, port, solrConfigFilename, schemaFileName, + stopAtShutdown, extraServlets, sslConfig, null); + } + + /** + * Constructor taking an ordered list of additional (filter holder -> path spec) mappings. + * Filters are placed after the DebugFilter but before the SolrDispatchFilter. + */ + public JettySolrRunner(String solrHome, String context, int port, + String solrConfigFilename, String schemaFileName, boolean stopAtShutdown, + SortedMap extraServlets, SSLConfig sslConfig, + SortedMap extraRequestFilters) { if (null != extraServlets) { this.extraServlets.putAll(extraServlets); } + if (null != extraRequestFilters) { + this.extraRequestFilters = new TreeMap(extraRequestFilters.comparator()); + this.extraRequestFilters.putAll(extraRequestFilters); + } this.init(solrHome, context, port, stopAtShutdown); this.solrConfigFilename = solrConfigFilename; this.schemaFilename = schemaFileName; @@ -309,6 +325,13 @@ public class JettySolrRunner { // SolrDispatchFilter filter = new SolrDispatchFilter(); // FilterHolder fh = new FilterHolder(filter); debugFilter = root.addFilter(DebugFilter.class, "*", EnumSet.of(DispatcherType.REQUEST) ); + if (extraRequestFilters != null) { + extraFilters = new LinkedList(); + for (Class filterClass : extraRequestFilters.keySet()) { + extraFilters.add(root.addFilter(filterClass, extraRequestFilters.get(filterClass), + EnumSet.of(DispatcherType.REQUEST))); + } + } dispatchFilter = root.addFilter(SolrDispatchFilter.class, "*", EnumSet.of(DispatcherType.REQUEST) ); for (ServletHolder servletHolder : extraServlets.keySet()) { String pathSpec = extraServlets.get(servletHolder); @@ -445,6 +468,11 @@ public class JettySolrRunner { //server.destroy(); if (server.getState().equals(Server.FAILED)) { filter.destroy(); + if (extraFilters != null) { + for (FilterHolder f : extraFilters) { + f.getFilter().destroy(); + } + } } server.join(); diff --git a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java index 877bed1f4f2..195949bcfd7 100644 --- a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java +++ b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java @@ -368,7 +368,8 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 { boolean stopAtShutdown = true; JettySolrRunner jetty = new JettySolrRunner - (solrHome.getAbsolutePath(), context, 0, solrConfigOverride, schemaOverride, stopAtShutdown, getExtraServlets()); + (solrHome.getAbsolutePath(), context, 0, solrConfigOverride, schemaOverride, stopAtShutdown, + getExtraServlets(), null, getExtraRequestFilters()); jetty.setShards(shardList); jetty.setDataDir(dataDir); if (explicitCoreNodeName) { @@ -383,7 +384,12 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 { public SortedMap getExtraServlets() { return null; } - + + /** Override this method to insert extra filters into the JettySolrRunners that are created using createJetty() */ + public SortedMap getExtraRequestFilters() { + return null; + } + protected SolrServer createNewSolrServer(int port) { try { // setup the server... diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java index 9b118fbe9a9..11e790b3a55 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java @@ -453,7 +453,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes String solrConfigOverride) throws Exception { JettySolrRunner jetty = new JettySolrRunner(getSolrHome(), context, 0, - solrConfigOverride, null, false, getExtraServlets()); + solrConfigOverride, null, false, getExtraServlets(), null, getExtraRequestFilters()); jetty.setShards(shardList); jetty.setDataDir(getDataDir(dataDir)); jetty.start(); @@ -467,7 +467,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes solrHome = getRelativeSolrHomePath(solrHome); } - JettySolrRunner jetty = new JettySolrRunner(solrHome.getPath(), context, 0, solrConfigOverride, schemaOverride, false, getExtraServlets()); + JettySolrRunner jetty = new JettySolrRunner(solrHome.getPath(), context, 0, solrConfigOverride, schemaOverride, false, getExtraServlets(), null, getExtraRequestFilters()); jetty.setShards(shardList); jetty.setDataDir(getDataDir(dataDir)); jetty.start();