lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hoss...@apache.org
Subject svn commit: r1384872 - in /lucene/dev/trunk/solr: CHANGES.txt test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java test-framework/src/java/org/apache/solr/util/TestHarness.java
Date Fri, 14 Sep 2012 18:07:24 GMT
Author: hossman
Date: Fri Sep 14 18:07:23 2012
New Revision: 1384872

URL: http://svn.apache.org/viewvc?rev=1384872&view=rev
Log:
SOLR-3826: Test framework improvements for specifying coreName on initCore

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
    lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1384872&r1=1384871&r2=1384872&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Fri Sep 14 18:07:23 2012
@@ -214,6 +214,10 @@ Other Changes
 
 * SOLR-3824: Velocity: Error messages from search not displayed (janhoy)
 
+* SOLR-3826: Test framework improvements for specifying coreName on initCore
+  (Amit Nithian, hossman)
+
+
 ==================  4.0.0-BETA ===================
 
 

Modified: lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java?rev=1384872&r1=1384871&r2=1384872&view=diff
==============================================================================
--- lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java (original)
+++ lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java Fri
Sep 14 18:07:23 2012
@@ -30,6 +30,7 @@ import org.apache.solr.common.*;
 import org.apache.solr.common.cloud.SolrZkClient;
 import org.apache.solr.common.params.*;
 import org.apache.solr.common.util.XML;
+import org.apache.solr.core.CoreContainer;
 import org.apache.solr.core.SolrConfig;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.handler.JsonUpdateRequestHandler;
@@ -52,7 +53,9 @@ import com.carrotsearch.randomizedtestin
 import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
 
 /**
- * A junit4 Solr test harness that extends LuceneTestCaseJ4.
+ * A junit4 Solr test harness that extends LuceneTestCaseJ4. To change which core is used
when loading the schema and solrconfig.xml, simply
+ * invoke the {@link #initCore(String, String, String, String)} method.
+ * 
  * Unlike {@link AbstractSolrTestCase}, a new core is not created for each test method.
  */
 @ThreadLeakFilters(defaultFilters = true, filters = {
@@ -60,6 +63,7 @@ import com.carrotsearch.randomizedtestin
     QuickPatchThreadsFilter.class
 })
 public abstract class SolrTestCaseJ4 extends LuceneTestCase {
+  private static String coreName = CoreContainer.DEFAULT_DEFAULT_CORE_NAME;
   public static int DEFAULT_CONNECTION_TIMEOUT = 1000;  // default socket connection timeout
in ms
 
 
@@ -178,7 +182,13 @@ public abstract class SolrTestCaseJ4 ext
     initCore();
   }
 
-
+  /** Call initCore in @BeforeClass to instantiate a solr core in your test class.
+   * deleteCore will be called for you via SolrTestCaseJ4 @AfterClass */
+  public static void initCore(String config, String schema, String solrHome, String pCoreName)
throws Exception {
+    coreName=pCoreName;
+    initCore(config,schema,solrHome);
+  }
+  
   static long numOpens;
   static long numCloses;
   public static void startTrackingSearchers() {
@@ -358,7 +368,7 @@ public abstract class SolrTestCaseJ4 ext
   }
 
   public static void createCore() {
-    solrConfig = TestHarness.createConfig(testSolrHome, getSolrConfigFile());
+    solrConfig = TestHarness.createConfig(testSolrHome, coreName, getSolrConfigFile());
     h = new TestHarness( dataDir.getAbsolutePath(),
             solrConfig,
             getSchemaFile());

Modified: lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java?rev=1384872&r1=1384871&r2=1384872&view=diff
==============================================================================
--- lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java (original)
+++ lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java Fri
Sep 14 18:07:23 2012
@@ -76,17 +76,30 @@ public class TestHarness {
   private final ThreadLocal<DocumentBuilder> builderTL = new ThreadLocal<DocumentBuilder>();
   private final ThreadLocal<XPath> xpathTL = new ThreadLocal<XPath>();
   public UpdateRequestHandler updater;
-        
-  public static SolrConfig createConfig(String solrHome, String confFile) {
+ 
+  /**
+   * Creates a SolrConfig object for the specified coreName assuming it 
+   * follows the basic conventions of being a relative path in the solrHome 
+   * dir. (ie: <code>${solrHome}/${coreName}/conf/${confFile}</code>
+   */
+  public static SolrConfig createConfig(String solrHome, String coreName, String confFile)
{
     // set some system properties for use by tests
     System.setProperty("solr.test.sys.prop1", "propone");
     System.setProperty("solr.test.sys.prop2", "proptwo");
     try {
-      return new SolrConfig(solrHome + File.separator + "collection1", confFile, null);
+      return new SolrConfig(solrHome + File.separator + coreName, confFile, null);
     } catch (Exception xany) {
       throw new RuntimeException(xany);
     }
   }
+  
+  /**
+   * Creates a SolrConfig object for the 
+   * {@link CoreContainer#DEFAULT_DEFAULT_CORE_NAME} core using {@link #createConfig(String,String,String)}
+   */
+  public static SolrConfig createConfig(String solrHome, String confFile) {
+    return createConfig(solrHome, CoreContainer.DEFAULT_DEFAULT_CORE_NAME, confFile);
+  }
 
    /**
     * @param dataDirectory path for index data, will not be cleaned up
@@ -176,7 +189,7 @@ public class TestHarness {
         {
           hostPort = System.getProperty("hostPort");
           hostContext = "solr";
-          defaultCoreName = "collection1";
+          defaultCoreName = CoreContainer.DEFAULT_DEFAULT_CORE_NAME;
           initZooKeeper(System.getProperty("zkHost"), 10000);
         }
       };



Mime
View raw message