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

« back to all changes in this revision

Viewing changes to solr/core/src/test/org/apache/solr/core/TestQuerySenderListener.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
 
/**
2
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 
 * contributor license agreements.  See the NOTICE file distributed with
4
 
 * this work for additional information regarding copyright ownership.
5
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 
 * (the "License"); you may not use this file except in compliance with
7
 
 * the License.  You may obtain a copy of the License at
8
 
 *
9
 
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 
 *
11
 
 * Unless required by applicable law or agreed to in writing, software
12
 
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 
 * See the License for the specific language governing permissions and
15
 
 * limitations under the License.
16
 
 */
17
 
 
18
 
package org.apache.solr.core;
19
 
 
20
 
import org.apache.solr.SolrTestCaseJ4;
21
 
import org.apache.solr.search.SolrIndexSearcher;
22
 
import org.apache.solr.util.RefCounted;
23
 
import org.apache.solr.common.params.EventParams;
24
 
import org.apache.lucene.store.Directory;
25
 
import org.junit.BeforeClass;
26
 
import org.junit.Test;
27
 
 
28
 
public class TestQuerySenderListener extends SolrTestCaseJ4 {
29
 
 
30
 
  // number of instances configured in the solrconfig.xml
31
 
  private static final int EXPECTED_MOCK_LISTENER_INSTANCES = 4;
32
 
 
33
 
  private static int preInitMockListenerCount = 0;
34
 
 
35
 
  @BeforeClass
36
 
  public static void beforeClass() throws Exception {
37
 
    // record current value prior to core initialization
38
 
    // so we can verify the correct number of instances later
39
 
    // NOTE: this won't work properly if concurrent tests run
40
 
    // in the same VM
41
 
    preInitMockListenerCount = MockEventListener.getCreateCount();
42
 
 
43
 
    initCore("solrconfig-querysender.xml","schema.xml");
44
 
  }
45
 
 
46
 
  public void testListenerCreationCounts() {
47
 
    SolrCore core = h.getCore();
48
 
 
49
 
    assertEquals("Unexpected number of listeners created",
50
 
                 EXPECTED_MOCK_LISTENER_INSTANCES, 
51
 
                 MockEventListener.getCreateCount() - preInitMockListenerCount);
52
 
  }
53
 
 
54
 
  @Test
55
 
  public void testRequestHandlerRegistry() {
56
 
    // property values defined in build.xml
57
 
    SolrCore core = h.getCore();
58
 
 
59
 
    assertEquals( 2, core.firstSearcherListeners.size() );
60
 
    assertEquals( 2, core.newSearcherListeners.size() );
61
 
  }
62
 
 
63
 
  @Test
64
 
  public void testSearcherEvents() throws Exception {
65
 
    SolrCore core = h.getCore();
66
 
    SolrEventListener newSearcherListener = core.newSearcherListeners.get(0);
67
 
    assertTrue("Not an instance of QuerySenderListener", newSearcherListener instanceof QuerySenderListener);
68
 
    QuerySenderListener qsl = (QuerySenderListener) newSearcherListener;
69
 
 
70
 
    RefCounted<SolrIndexSearcher> currentSearcherRef = core.getSearcher();
71
 
    SolrIndexSearcher currentSearcher = currentSearcherRef.get();
72
 
    qsl.newSearcher(currentSearcher, null);//test new Searcher
73
 
    MockQuerySenderListenerReqHandler mock = (MockQuerySenderListenerReqHandler) core.getRequestHandler("mock");
74
 
    assertNotNull("Mock is null", mock);
75
 
    String evt = mock.req.getParams().get(EventParams.EVENT);
76
 
    assertNotNull("Event is null", evt);
77
 
    assertTrue(evt + " is not equal to " + EventParams.FIRST_SEARCHER, evt.equals(EventParams.FIRST_SEARCHER) == true);
78
 
    Directory dir = currentSearcher.getReader().directory();
79
 
    SolrIndexSearcher newSearcher = new SolrIndexSearcher(core, core.getSchema(), "testQuerySenderListener", dir, true, false);
80
 
 
81
 
    qsl.newSearcher(newSearcher, currentSearcher);
82
 
    evt = mock.req.getParams().get(EventParams.EVENT);
83
 
    assertNotNull("Event is null", evt);
84
 
    assertTrue(evt + " is not equal to " + EventParams.NEW_SEARCHER, evt.equals(EventParams.NEW_SEARCHER) == true);
85
 
    newSearcher.close();
86
 
    currentSearcherRef.decref();
87
 
  }
88
 
 
89
 
}
90