You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by er...@apache.org on 2013/07/07 04:51:18 UTC

svn commit: r1500359 - in /lucene/dev/branches/branch_4x: ./ dev-tools/ lucene/ lucene/analysis/ lucene/analysis/icu/src/java/org/apache/lucene/collation/ lucene/backwards/ lucene/benchmark/ lucene/classification/ lucene/classification/src/ lucene/code...

Author: erick
Date: Sun Jul  7 02:51:17 2013
New Revision: 1500359

URL: http://svn.apache.org/r1500359
Log:
SOLR-4982 4x checkin, including the test fix (trunk r 1500354)

Added:
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java
      - copied, changed from r1500284, lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java
Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/dev-tools/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/BUILD.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/JRE_VERSION_MIGRATION.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/LICENSE.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/MIGRATE.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/NOTICE.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/README.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/SYSTEM_REQUIREMENTS.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/analysis/   (props changed)
    lucene/dev/branches/branch_4x/lucene/analysis/icu/src/java/org/apache/lucene/collation/ICUCollationKeyFilterFactory.java   (props changed)
    lucene/dev/branches/branch_4x/lucene/backwards/   (props changed)
    lucene/dev/branches/branch_4x/lucene/benchmark/   (props changed)
    lucene/dev/branches/branch_4x/lucene/build.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/classification/   (props changed)
    lucene/dev/branches/branch_4x/lucene/classification/build.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/classification/ivy.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/classification/src/   (props changed)
    lucene/dev/branches/branch_4x/lucene/codecs/   (props changed)
    lucene/dev/branches/branch_4x/lucene/common-build.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/index.40.cfs.zip   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/index.40.nocfs.zip   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/index.40.optimized.cfs.zip   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/index.40.optimized.nocfs.zip   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestSort.java   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestSortDocValues.java   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestSortRandom.java   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestTopFieldCollector.java   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestTotalHitCountCollector.java   (props changed)
    lucene/dev/branches/branch_4x/lucene/demo/   (props changed)
    lucene/dev/branches/branch_4x/lucene/facet/   (props changed)
    lucene/dev/branches/branch_4x/lucene/grouping/   (props changed)
    lucene/dev/branches/branch_4x/lucene/highlighter/   (props changed)
    lucene/dev/branches/branch_4x/lucene/ivy-settings.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/join/   (props changed)
    lucene/dev/branches/branch_4x/lucene/licenses/   (props changed)
    lucene/dev/branches/branch_4x/lucene/memory/   (props changed)
    lucene/dev/branches/branch_4x/lucene/misc/   (props changed)
    lucene/dev/branches/branch_4x/lucene/module-build.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/queries/   (props changed)
    lucene/dev/branches/branch_4x/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionQuerySort.java   (props changed)
    lucene/dev/branches/branch_4x/lucene/queryparser/   (props changed)
    lucene/dev/branches/branch_4x/lucene/replicator/   (props changed)
    lucene/dev/branches/branch_4x/lucene/sandbox/   (props changed)
    lucene/dev/branches/branch_4x/lucene/site/   (props changed)
    lucene/dev/branches/branch_4x/lucene/spatial/   (props changed)
    lucene/dev/branches/branch_4x/lucene/suggest/   (props changed)
    lucene/dev/branches/branch_4x/lucene/test-framework/   (props changed)
    lucene/dev/branches/branch_4x/lucene/tools/   (props changed)
    lucene/dev/branches/branch_4x/solr/   (props changed)
    lucene/dev/branches/branch_4x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/solr/LICENSE.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/NOTICE.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/README.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/SYSTEM_REQUIREMENTS.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/build.xml   (props changed)
    lucene/dev/branches/branch_4x/solr/cloud-dev/   (props changed)
    lucene/dev/branches/branch_4x/solr/common-build.xml   (props changed)
    lucene/dev/branches/branch_4x/solr/contrib/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/SolrCore.java
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/core/TestConfig.java   (props changed)
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java
    lucene/dev/branches/branch_4x/solr/example/   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpclient-LICENSE-ASL.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpclient-NOTICE.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpcore-LICENSE-ASL.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpcore-NOTICE.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpmime-LICENSE-ASL.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpmime-NOTICE.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/scripts/   (props changed)
    lucene/dev/branches/branch_4x/solr/site/   (props changed)
    lucene/dev/branches/branch_4x/solr/solrj/   (props changed)
    lucene/dev/branches/branch_4x/solr/test-framework/   (props changed)
    lucene/dev/branches/branch_4x/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
    lucene/dev/branches/branch_4x/solr/webapp/   (props changed)

Modified: lucene/dev/branches/branch_4x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/CHANGES.txt?rev=1500359&r1=1500358&r2=1500359&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Sun Jul  7 02:51:17 2013
@@ -223,6 +223,12 @@ Bug Fixes
 
 * SOLR-5000: ManagedIndexSchema doesn't persist uniqueKey tag after calling addFields
   method. (Jun Ohtani, Steve Rowe)
+  
+* SOLR-4982: Creating a core while referencing system properties looks like it loses files
+  Actually, instanceDir, config, dataDir and schema are not dereferenced properly
+  when creating cores that reference sys vars (e.g. &dataDir=${dir}). In the dataDir
+  case in particular this leads to the index being put in a directory literally named
+  ${dir} but on restart the sysvar will be properly dereferenced.
 
 * SOLR-5002: Don't create multiple SolrResourceLoaders for same Solr home, wasting 
   resources and slowing down startup. This fixes the problem where the loader was

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java?rev=1500359&r1=1500358&r2=1500359&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java Sun Jul  7 02:51:17 2013
@@ -46,7 +46,7 @@ public class CoreDescriptor {
   public static final String CORE_TRANSIENT = "transient";
   public static final String CORE_NODE_NAME = "coreNodeName";
 
-  static final String[] standardPropNames = {
+  public static final String[] standardPropNames = {
       CORE_NAME,
       CORE_CONFIG,
       CORE_INSTDIR,
@@ -65,7 +65,7 @@ public class CoreDescriptor {
   // them individually.
   private Properties coreProperties = new Properties();
 
-  //TODO: 5.0 remove this, this is solely a hack for persistence.
+  //TODO: 5.0 remove this, this is solely a hack for persistence. And perhaps creating cores in discovery mode?
   private Properties createdProperties = new Properties();
 
   private boolean loadedImplicit = false;

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/SolrCore.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/SolrCore.java?rev=1500359&r1=1500358&r2=1500359&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/SolrCore.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/SolrCore.java Sun Jul  7 02:51:17 2013
@@ -26,6 +26,7 @@ import java.io.Writer;
 import java.lang.reflect.Constructor;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
@@ -873,6 +874,18 @@ public final class SolrCore implements S
       propFile.getParentFile().mkdirs();
       Properties props = new Properties();
       props.put("name", cd.getName());
+
+      // This must be being created since there's no file here already. So write out all of the params we were
+      // created with. This _may_ overwrite the name above, but that's OK.
+      Collection<String> stds = new HashSet(Arrays.asList(CoreDescriptor.standardPropNames));
+      for (String prop : cd.getCreatedProperties().stringPropertyNames()) {
+        // Only preserve things that are legal, and let's just keep instDir right out of the persisted file even
+        // though it's part of the create properties on the URL.
+        if (! CoreDescriptor.CORE_INSTDIR.equals(prop) && stds.contains(prop)) {
+          props.put(prop, cd.getCreatedProperties().getProperty(prop));
+        }
+      }
+
       if (cc.isZooKeeperAware()) {
         String collection = cd.getCloudDescriptor().getCollectionName();
         if (collection != null) {

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java?rev=1500359&r1=1500358&r2=1500359&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java Sun Jul  7 02:51:17 2013
@@ -57,6 +57,7 @@ import org.apache.solr.update.UpdateLog;
 import org.apache.solr.update.processor.UpdateRequestProcessor;
 import org.apache.solr.update.processor.UpdateRequestProcessorChain;
 import org.apache.solr.util.NumberUtils;
+import org.apache.solr.util.PropertiesUtil;
 import org.apache.solr.util.RefCounted;
 import org.apache.zookeeper.KeeperException;
 import org.slf4j.Logger;
@@ -414,6 +415,7 @@ public class CoreAdminHandler extends Re
       throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                               "Core name is mandatory to CREATE a SolrCore");
     }
+
     CoreDescriptor dcore = null;
     try {
       
@@ -427,22 +429,30 @@ public class CoreAdminHandler extends Re
       if (instanceDir == null) {
         // instanceDir = coreContainer.getSolrHome() + "/" + name;
         instanceDir = name; // bare name is already relative to solr home
+      } else {
+        instanceDir = PropertiesUtil.substituteProperty(instanceDir, null);
       }
 
       dcore = new CoreDescriptor(coreContainer, name, instanceDir);
 
       //  fillup optional parameters
       String opts = params.get(CoreAdminParams.CONFIG);
-      if (opts != null)
+      if (opts != null) {
+        opts = PropertiesUtil.substituteProperty(opts, null);
         dcore.setConfigName(opts);
+      }
 
       opts = params.get(CoreAdminParams.SCHEMA);
-      if (opts != null)
+      if (opts != null) {
+        opts = PropertiesUtil.substituteProperty(opts, null);
         dcore.setSchemaName(opts);
+      }
 
       opts = params.get(CoreAdminParams.DATA_DIR);
-      if (opts != null)
+      if (opts != null) {
+        opts = PropertiesUtil.substituteProperty(opts, null);
         dcore.setDataDir(opts);
+      }
 
       opts = params.get(CoreAdminParams.ULOG_DIR);
       if (opts != null)

Copied: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java (from r1500284, lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java?p2=lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java&p1=lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java&r1=1500284&r2=1500359&rev=1500359&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java Sun Jul  7 02:51:17 2013
@@ -40,13 +40,12 @@ public class CoreAdminCreateDiscoverTest
   private static File solrHomeDirectory = null;
 
   private static CoreAdminHandler admin = null;
-//  private static CoreContainer cc = null;
 
   private static String coreNormal = "normal";
   private static String coreSysProps = "sys_props";
 
   @BeforeClass
-  public static void before() throws Exception {
+  public static void beforeClass() throws Exception {
     useFactory(null); // I require FS-based indexes for this test.
 
     solrHomeDirectory = new File(TEMP_DIR, "solrHome/" + CoreAdminCreateDiscoverTest.getClassName());
@@ -61,8 +60,8 @@ public class CoreAdminCreateDiscoverTest
   }
 
   @AfterClass
-  public static void after() throws Exception {
-    h.close();
+  public static void afterClass() throws Exception {
+    admin = null; // Release it or the test harness complains.
     if (solrHomeDirectory.exists()) {
       FileUtils.deleteDirectory(solrHomeDirectory);
     }

Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java?rev=1500359&r1=1500358&r2=1500359&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java Sun Jul  7 02:51:17 2013
@@ -17,9 +17,9 @@
 
 package org.apache.solr.handler.admin;
 
+import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
 import org.apache.solr.core.CoreContainer;
 import org.apache.solr.core.SolrCore;
-import org.apache.solr.handler.admin.CoreAdminHandler;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.params.CoreAdminParams;
 import org.apache.solr.common.util.NamedList;
@@ -28,15 +28,14 @@ import org.apache.solr.SolrTestCaseJ4;
 
 import java.util.Map;
 import java.io.File;
-import java.io.IOException;
-
-import javax.xml.xpath.XPathExpressionException;
 
 import org.apache.commons.io.FileUtils;
 
 import org.junit.BeforeClass;
+import org.junit.Rule;
 import org.junit.Test;
-import org.xml.sax.SAXException;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TestRule;
 
 public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
   
@@ -44,7 +43,93 @@ public class CoreAdminHandlerTest extend
   public static void beforeClass() throws Exception {
     initCore("solrconfig.xml", "schema.xml");
   }
-  
+
+  @Rule
+  public TestRule solrTestRules = RuleChain.outerRule(new SystemPropertiesRestoreRule());
+
+  public String getCoreName() { return this.getClass().getName() + "_sys_vars"; }
+
+  @Test
+  public void testCreateWithSysVars() throws Exception {
+    useFactory(null); // I require FS-based indexes for this test.
+
+    final File workDir = new File(TEMP_DIR, getCoreName());
+
+    if (workDir.exists()) {
+      FileUtils.deleteDirectory(workDir);
+    }
+    assertTrue("Failed to mkdirs workDir", workDir.mkdirs());
+    String coreName = "with_sys_vars";
+    File instDir = new File(workDir, coreName);
+    File subHome = new File(instDir, "conf");
+    assertTrue("Failed to make subdirectory ", subHome.mkdirs());
+
+    // Be sure we pick up sysvars when we create this
+    String srcDir = SolrTestCaseJ4.TEST_HOME() + "/collection1/conf";
+    FileUtils.copyFile(new File(srcDir, "schema-tiny.xml"), new File(subHome, "schema_ren.xml"));
+    FileUtils.copyFile(new File(srcDir, "solrconfig-minimal.xml"), new File(subHome, "solrconfig_ren.xml"));
+    FileUtils.copyFile(new File(srcDir, "solrconfig.snippet.randomindexconfig.xml"),
+        new File(subHome, "solrconfig.snippet.randomindexconfig.xml"));
+
+    final CoreContainer cores = h.getCoreContainer();
+    cores.setPersistent(false); // we'll do this explicitly as needed
+
+    final CoreAdminHandler admin = new CoreAdminHandler(cores);
+
+    // create a new core (using CoreAdminHandler) w/ properties
+    System.setProperty("INSTDIR_TEST", instDir.getAbsolutePath());
+    System.setProperty("CONFIG_TEST", "solrconfig_ren.xml");
+    System.setProperty("SCHEMA_TEST", "schema_ren.xml");
+
+    File dataDir = new File(workDir.getAbsolutePath(), "data_diff");
+    System.setProperty("DATA_TEST", dataDir.getAbsolutePath());
+
+    SolrQueryResponse resp = new SolrQueryResponse();
+    admin.handleRequestBody
+        (req(CoreAdminParams.ACTION,
+            CoreAdminParams.CoreAdminAction.CREATE.toString(),
+            CoreAdminParams.NAME, getCoreName(),
+            CoreAdminParams.INSTANCE_DIR, "${INSTDIR_TEST}",
+            CoreAdminParams.CONFIG, "${CONFIG_TEST}",
+            CoreAdminParams.SCHEMA, "${SCHEMA_TEST}",
+            CoreAdminParams.DATA_DIR, "${DATA_TEST}"),
+            resp);
+    assertNull("Exception on create", resp.getException());
+
+    // verify props are in persisted file
+
+    final File xml = new File(workDir, "persist-solr.xml");
+    cores.persistFile(xml);
+
+    // First assert that these values are persisted.
+    assertXmlFile
+        (xml
+            ,"/solr/cores/core[@name='" + getCoreName() + "' and @instanceDir='${INSTDIR_TEST}']"
+            ,"/solr/cores/core[@name='" + getCoreName() + "' and @dataDir='${DATA_TEST}']"
+            ,"/solr/cores/core[@name='" + getCoreName() + "' and @schema='${SCHEMA_TEST}']"
+            ,"/solr/cores/core[@name='" + getCoreName() + "' and @config='${CONFIG_TEST}']"
+        );
+
+    // Now assert that certain values are properly dereferenced in the process of creating the core, see
+    // SOLR-4982.
+
+    // Should NOT be a datadir named ${DATA_TEST} (literal). This is the bug after all
+    File badDir = new File(instDir, "${DATA_TEST}");
+    assertFalse("Should have substituted the sys var, found file " + badDir.getAbsolutePath(), badDir.exists());
+
+    // For the other 3 vars, we couldn't get past creating the core fi dereferencing didn't work correctly.
+
+    // Should have segments in the directory pointed to by the ${DATA_TEST}.
+    File test = new File(dataDir, "index");
+    assertTrue("Should have found index dir at " + test.getAbsolutePath(), test.exists());
+    test = new File(test,"segments.gen");
+    assertTrue("Should have found segments.gen at " + test.getAbsolutePath(), test.exists());
+
+    // Cleanup
+    FileUtils.deleteDirectory(workDir);
+
+  }
+
   @Test
   public void testCoreAdminHandler() throws Exception {
     final File workDir = new File(TEMP_DIR, this.getClass().getName());
@@ -141,6 +226,8 @@ public class CoreAdminHandlerTest extend
                
     // :TODO: because of SOLR-3665 we can't ask for status from all cores
 
-  }
+    // cleanup
+    FileUtils.deleteDirectory(workDir);
 
+  }
 }

Modified: lucene/dev/branches/branch_4x/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java?rev=1500359&r1=1500358&r2=1500359&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java (original)
+++ lucene/dev/branches/branch_4x/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java Sun Jul  7 02:51:17 2013
@@ -21,6 +21,7 @@ import com.carrotsearch.randomizedtestin
 import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
 import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
 import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.QuickPatchThreadsFilter;
 import org.apache.solr.client.solrj.util.ClientUtils;
@@ -32,9 +33,11 @@ import org.apache.solr.common.params.Com
 import org.apache.solr.common.params.ModifiableSolrParams;
 import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.util.XML;
+import org.apache.solr.core.ConfigSolr;
 import org.apache.solr.core.CoreContainer;
 import org.apache.solr.core.SolrConfig;
 import org.apache.solr.core.SolrCore;
+import org.apache.solr.core.SolrResourceLoader;
 import org.apache.solr.handler.JsonUpdateRequestHandler;
 import org.apache.solr.request.LocalSolrQueryRequest;
 import org.apache.solr.request.SolrQueryRequest;
@@ -155,6 +158,25 @@ public abstract class SolrTestCaseJ4 ext
     }
   }
 
+  /**
+   * Call this from @BeforeClass to set up the test harness and update handler with no cores.
+   *
+   * @param solrHome The solr home directory.
+   * @param xmlStr - the text of an XML file to use. If null, use the what's the absolute minimal file.
+   * @throws Exception Lost of file-type things can go wrong.
+   */
+  public static void setupNoCoreTest(File solrHome, String xmlStr) throws Exception {
+
+    File tmpFile = new File(solrHome, ConfigSolr.SOLR_XML_FILE);
+    if (xmlStr == null) {
+      xmlStr = "<solr></solr>";
+    }
+    FileUtils.write(tmpFile, xmlStr, IOUtils.CHARSET_UTF_8.toString());
+
+    SolrResourceLoader loader = new SolrResourceLoader(solrHome.getAbsolutePath());
+    h = new TestHarness(loader, ConfigSolr.fromFile(loader, new File(solrHome, "solr.xml")));
+    lrf = h.getRequestFactory("standard", 0, 20, CommonParams.VERSION, "2.2");
+  }
 
   @Override
   public void setUp() throws Exception {