1
package org.apache.solr.core;
4
* Licensed to the Apache Software Foundation (ASF) under one or more
5
* contributor license agreements. See the NOTICE file distributed with
6
* this work for additional information regarding copyright ownership.
7
* The ASF licenses this file to You under the Apache License, Version 2.0
8
* (the "License"); you may not use this file except in compliance with
9
* the License. You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing, software
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
* See the License for the specific language governing permissions and
17
* limitations under the License.
20
import org.apache.lucene.store.Directory;
21
import org.apache.solr.SolrTestCaseJ4;
22
import org.apache.solr.common.params.EventParams;
23
import org.apache.solr.search.SolrIndexSearcher;
24
import org.apache.solr.search.TestExtendedDismaxParser;
25
import org.apache.solr.util.RefCounted;
26
import org.junit.BeforeClass;
27
import org.junit.Test;
29
public class TestQuerySenderNoQuery extends SolrTestCaseJ4 {
31
// number of instances configured in the solrconfig.xml
32
private static final int EXPECTED_MOCK_LISTENER_INSTANCES = 4;
34
private static int preInitMockListenerCount = 0;
37
public static void beforeClass() throws Exception {
38
// record current value prior to core initialization
39
// so we can verify the correct number of instances later
40
// NOTE: this won't work properly if concurrent tests run
42
preInitMockListenerCount = MockEventListener.getCreateCount();
44
initCore("solrconfig-querysender-noquery.xml","schema.xml");
47
public void testListenerCreationCounts() {
48
SolrCore core = h.getCore();
50
assertEquals("Unexpected number of listeners created",
51
EXPECTED_MOCK_LISTENER_INSTANCES,
52
MockEventListener.getCreateCount() - preInitMockListenerCount);
56
public void testRequestHandlerRegistry() {
57
// property values defined in build.xml
58
SolrCore core = h.getCore();
60
assertEquals( 2, core.firstSearcherListeners.size() );
61
assertEquals( 2, core.newSearcherListeners.size() );
64
// Determine that when the query lists are commented out of both new and
65
// first searchers in the config, we don't throw an NPE
67
public void testSearcherEvents() throws Exception {
68
SolrCore core = h.getCore();
69
SolrEventListener newSearcherListener = core.newSearcherListeners.get(0);
70
assertTrue("Not an instance of QuerySenderListener", newSearcherListener instanceof QuerySenderListener);
71
QuerySenderListener qsl = (QuerySenderListener) newSearcherListener;
73
RefCounted<SolrIndexSearcher> currentSearcherRef = core.getSearcher();
74
SolrIndexSearcher currentSearcher = currentSearcherRef.get();
75
SolrIndexSearcher dummy = null;
76
qsl.newSearcher(currentSearcher, dummy);//test first Searcher (since param is null)
77
MockQuerySenderListenerReqHandler mock = (MockQuerySenderListenerReqHandler) core.getRequestHandler("mock");
78
assertNotNull("Mock is null", mock);
79
assertNull("Req (firstsearcher) is not null", mock.req);
81
Directory dir = currentSearcher.getIndexReader().directory();
82
SolrIndexSearcher newSearcher = new SolrIndexSearcher(core, core.getSchema(), "testQuerySenderNoQuery", dir, true, false);
84
qsl.newSearcher(newSearcher, currentSearcher); // get newSearcher.
85
assertNull("Req (newsearcher) is not null", mock.req);
87
currentSearcherRef.decref();