Apache Lucene open-source search software
SOLR-215 -- fixing SolrEventListener initalization and adding test that instantiates an SolrEventListener on startup.
Ryan McKinley4674b5f4469e
diff --git a/src/java/org/apache/solr/core/SolrCore.java b/src/java/org/apache/solr/core/SolrCore.javaindex 6d35cf3987b..a2f69c0329c 100644--- a/src/java/org/apache/solr/core/SolrCore.java+++ b/src/java/org/apache/solr/core/SolrCore.java@@ -130,11 +130,11 @@ public final class SolrCore {if (nodes!=null) {for (int i=0; i<nodes.getLength(); i++) {Node node = nodes.item(i);- String className = DOMUtil.getAttr(node,"class");- SolrEventListener listener = (SolrEventListener)solrConfig.newInstance(className);- listener.init(DOMUtil.childNodesToNamedList(node));- lst.add(listener);- log.info("added SolrEventListener: " + listener);+ String className = DOMUtil.getAttr(node,"class");+ SolrEventListener listener = createEventListener(className);+ listener.init(DOMUtil.childNodesToNamedList(node));+ lst.add(listener);+ log.info("added SolrEventListener: " + listener);}}return lst;diff --git a/src/test/org/apache/solr/core/TestQuerySenderListener.java b/src/test/org/apache/solr/core/TestQuerySenderListener.javanew file mode 100644index 00000000000..e57d0b3be7d--- /dev/null+++ b/src/test/org/apache/solr/core/TestQuerySenderListener.java@@ -0,0 +1,39 @@+/**+ * 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.core;++import org.apache.solr.handler.RequestHandlerBase;+import org.apache.solr.request.SolrQueryRequest;+import org.apache.solr.request.SolrQueryResponse;+import org.apache.solr.request.SolrRequestHandler;+import org.apache.solr.util.AbstractSolrTestCase;++public class TestQuerySenderListener extends AbstractSolrTestCase {++ @Override public String getSchemaFile() { return "schema.xml"; }+ @Override public String getSolrConfigFile() { return "solrconfig-querysender.xml"; }++ public void testRequestHandlerRegistry() {+ // property values defined in build.xml+ SolrCore core = h.getCore();++ assertEquals( 1, core.firstSearcherListeners.size() );+ assertEquals( 1, core.newSearcherListeners.size() );+ }+}+diff --git a/src/test/test-files/solr/conf/solrconfig-querysender.xml b/src/test/test-files/solr/conf/solrconfig-querysender.xmlnew file mode 100644index 00000000000..7de8035624c--- /dev/null+++ b/src/test/test-files/solr/conf/solrconfig-querysender.xml@@ -0,0 +1,53 @@+<?xml version="1.0" ?>++<!--+ 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.+-->++<!-- $Id$+ $Source$+ $Name$+ -->++<config>+++ <query>+++ <!-- a newSearcher event is fired whenever a new searcher is being prepared+ and there is a current searcher handling requests (aka registered). -->+ <!-- QuerySenderListener takes an array of NamedList and executes a+ local query request for each NamedList in sequence. -->+ <listener event="newSearcher" class="solr.QuerySenderListener">+ <arr name="queries">+ <lst> <str name="q">solr</str> <str name="start">0</str> <str name="rows">10</str> </lst>+ <lst> <str name="q">rocks</str> <str name="start">0</str> <str name="rows">10</str> </lst>+ </arr>+ </listener>++ <!-- a firstSearcher event is fired whenever a new searcher is being+ prepared but there is no current registered searcher to handle+ requests or to gain prewarming data from. -->+ <listener event="firstSearcher" class="solr.QuerySenderListener">+ <arr name="queries">+ <lst> <str name="q">fast_warm</str> <str name="start">0</str> <str name="rows">10</str> </lst>+ </arr>+ </listener>++ </query>++</config>