You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2010/10/14 23:58:29 UTC

svn commit: r1022735 - /lucene/dev/trunk/solr/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java

Author: yonik
Date: Thu Oct 14 21:58:29 2010
New Revision: 1022735

URL: http://svn.apache.org/viewvc?rev=1022735&view=rev
Log:
tests: fix resource leaks + simplify

Modified:
    lucene/dev/trunk/solr/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java?rev=1022735&r1=1022734&r2=1022735&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java Thu Oct 14 21:58:29 2010
@@ -101,29 +101,15 @@ public class QueryElevationComponentTest
     
     assertEquals( "xxxx", comp.getAnalyzedQuery( "XXXX" ) );
     assertEquals( "xxxxyyyy", comp.getAnalyzedQuery( "XXXX YYYY" ) );
-  }
-
-  @Test
-  public void testEmptyQuery() throws Exception {
-    SolrCore core = h.getCore();
 
-    //String query = "title:ipod";
-
-    Map<String,String> args = new HashMap<String, String>();
-    args.put( "q.alt", "*:*" );
-    args.put( "defType", "dismax");
-    args.put( CommonParams.QT, "/elevate" );
-    //args.put( CommonParams.FL, "id,title,score" );
-    SolrQueryRequest req = new LocalSolrQueryRequest( core, new MapSolrParams( args) );
-    assertQ("Make sure QEC handles null queries", req, "//*[@numFound='0']");
+    assertQ("Make sure QEC handles null queries", req("qt","/elevate", "q.alt","*:*", "defType","dismax"),
+        "//*[@numFound='0']");
 
   }
 
   @Test
   public void testSorting() throws IOException
   {
-    SolrCore core = h.getCore();
-    
     assertU(adoc("id", "a", "title", "ipod",           "str_s", "a" ));
     assertU(adoc("id", "b", "title", "ipod ipod",      "str_s", "b" ));
     assertU(adoc("id", "c", "title", "ipod ipod ipod", "str_s", "c" ));
@@ -141,8 +127,10 @@ public class QueryElevationComponentTest
     args.put( CommonParams.FL, "id,score" );
     args.put( "indent", "true" );
     //args.put( CommonParams.FL, "id,title,score" );
-    SolrQueryRequest req = new LocalSolrQueryRequest( core, new MapSolrParams( args) );
-    
+    SolrQueryRequest req = new LocalSolrQueryRequest( h.getCore(), new MapSolrParams( args) );
+    IndexReader reader = req.getSearcher().getReader();
+    QueryElevationComponent booster = (QueryElevationComponent)req.getCore().getSearchComponent( "elevate" );
+
     assertQ("Make sure standard sort works as expected", req
             ,"//*[@numFound='3']"
             ,"//result/doc[1]/str[@name='id'][.='a']"
@@ -151,11 +139,10 @@ public class QueryElevationComponentTest
             );
     
     // Explicitly set what gets boosted
-    IndexReader reader = core.getSearcher().get().getReader();
-    QueryElevationComponent booster = (QueryElevationComponent)core.getSearchComponent( "elevate" );
     booster.elevationCache.clear();
     booster.setTopQueryResults( reader, query, new String[] { "x", "y", "z" }, null );
 
+
     assertQ("All six should make it", req
             ,"//*[@numFound='6']"
             ,"//result/doc[1]/str[@name='id'][.='x']"
@@ -230,6 +217,8 @@ public class QueryElevationComponentTest
         ,"//result/doc[3]/str[@name='id'][.='c']"
         );
 
+
+    req.close();
   }
   
   // write a test file to boost some docs
@@ -253,31 +242,33 @@ public class QueryElevationComponentTest
   @Test
   public void testElevationReloading() throws Exception
   {
-    SolrCore core = h.getCore();
-
     String testfile = "data-elevation.xml";
-    File f = new File( core.getDataDir(), testfile );
+    File f = new File( h.getCore().getDataDir(), testfile );
     writeFile( f, "aaa", "A" );
     
-    QueryElevationComponent comp = (QueryElevationComponent)core.getSearchComponent("elevate");
+    QueryElevationComponent comp = (QueryElevationComponent)h.getCore().getSearchComponent("elevate");
     NamedList<String> args = new NamedList<String>();
     args.add( QueryElevationComponent.CONFIG_FILE, testfile );
     comp.init( args );
-    comp.inform( core );
-    
-    IndexReader reader = core.getSearcher().get().getReader();
-    Map<String, ElevationObj> map = comp.getElevationMap(reader, core);
+    comp.inform( h.getCore() );
+
+    SolrQueryRequest req = req();
+    IndexReader reader = req.getSearcher().getReader();
+    Map<String, ElevationObj> map = comp.getElevationMap(reader, h.getCore());
     assertTrue( map.get( "aaa" ).priority.containsKey( new BytesRef("A") ) );
     assertNull( map.get( "bbb" ) );
+    req.close();
     
     // now change the file
     writeFile( f, "bbb", "B" );
     assertU(adoc("id", "10000")); // will get same reader if no index change
     assertU(commit());
-    
-    reader = core.getSearcher().get().getReader();
-    map = comp.getElevationMap(reader, core);
+
+    req = req();
+    reader = req.getSearcher().getReader();
+    map = comp.getElevationMap(reader, h.getCore());
     assertNull( map.get( "aaa" ) );
     assertTrue( map.get( "bbb" ).priority.containsKey( new BytesRef("B") ) );
+    req.close();
   }
 }