~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to solr/core/src/test/org/apache/solr/core/TestQuerySenderNoQuery.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.apache.solr.core;
2
 
 
3
 
/**
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
10
 
 *
11
 
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 
 *
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.
18
 
 */
19
 
 
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;
28
 
 
29
 
public class TestQuerySenderNoQuery extends SolrTestCaseJ4 {
30
 
 
31
 
  // number of instances configured in the solrconfig.xml
32
 
  private static final int EXPECTED_MOCK_LISTENER_INSTANCES = 4;
33
 
 
34
 
  private static int preInitMockListenerCount = 0;
35
 
 
36
 
  @BeforeClass
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
41
 
    // in the same VM
42
 
    preInitMockListenerCount = MockEventListener.getCreateCount();
43
 
 
44
 
    initCore("solrconfig-querysender-noquery.xml","schema.xml");
45
 
  }
46
 
 
47
 
  public void testListenerCreationCounts() {
48
 
    SolrCore core = h.getCore();
49
 
 
50
 
    assertEquals("Unexpected number of listeners created",
51
 
                 EXPECTED_MOCK_LISTENER_INSTANCES,
52
 
                 MockEventListener.getCreateCount() - preInitMockListenerCount);
53
 
  }
54
 
 
55
 
  @Test
56
 
  public void testRequestHandlerRegistry() {
57
 
    // property values defined in build.xml
58
 
    SolrCore core = h.getCore();
59
 
 
60
 
    assertEquals( 2, core.firstSearcherListeners.size() );
61
 
    assertEquals( 2, core.newSearcherListeners.size() );
62
 
  }
63
 
 
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
66
 
  @Test
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;
72
 
 
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);
80
 
 
81
 
    Directory dir = currentSearcher.getIndexReader().directory();
82
 
    SolrIndexSearcher newSearcher = new SolrIndexSearcher(core, core.getSchema(), "testQuerySenderNoQuery", dir, true, false);
83
 
 
84
 
    qsl.newSearcher(newSearcher, currentSearcher); // get newSearcher.
85
 
    assertNull("Req (newsearcher) is not null", mock.req);
86
 
    newSearcher.close();
87
 
    currentSearcherRef.decref();
88
 
  }
89
 
 
90
 
}