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
This commit is contained in:
Mark Robert Miller 2013-12-12 20:15:52 +00:00
parent 7e070c34a4
commit 8f6343fb83
4 changed files with 45 additions and 8 deletions

View File

@ -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

View File

@ -93,6 +93,8 @@ public class JettySolrRunner {
/** Maps servlet holders (i.e. factories: class + init params) to path specs */
private SortedMap<ServletHolder,String> extraServlets = new TreeMap<ServletHolder,String>();
private SortedMap<Class,String> extraRequestFilters;
private LinkedList<FilterHolder> 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<ServletHolder,String> 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<ServletHolder,String> 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<ServletHolder,String> extraServlets, SSLConfig sslConfig,
SortedMap<Class,String> extraRequestFilters) {
if (null != extraServlets) { this.extraServlets.putAll(extraServlets); }
if (null != extraRequestFilters) {
this.extraRequestFilters = new TreeMap<Class,String>(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<FilterHolder>();
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();

View File

@ -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<ServletHolder,String> getExtraServlets() {
return null;
}
/** Override this method to insert extra filters into the JettySolrRunners that are created using createJetty() */
public SortedMap<Class,String> getExtraRequestFilters() {
return null;
}
protected SolrServer createNewSolrServer(int port) {
try {
// setup the server...

View File

@ -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();