Apache Lucene open-source search software
SOLR-4817 Solr should not fall back to the back compat built in solr.xml in SolrCloud mode.
Erick Erickson84063af19a36
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 239344dc1b2..590c8161e03 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -148,6 +148,9 @@ Bug Fixes* SOLR-5174: Admin UI - Query View doesn't highlight (json) Result if itcontains HTML Tags (steffkes)++* SOLR-4817 Solr should not fall back to the back compat built in solr.xml in SolrCloud+ mode (Erick Erickson)Optimizations----------------------diff --git a/solr/contrib/clustering/src/test-files/clustering/solr/solr.xml b/solr/contrib/clustering/src/test-files/clustering/solr/solr.xmlnew file mode 100644index 00000000000..6a6cdda13e6--- /dev/null+++ b/solr/contrib/clustering/src/test-files/clustering/solr/solr.xml@@ -0,0 +1,29 @@+<?xml version="1.0" encoding="UTF-8" ?>+<!--+ Licensed to the Apache Software Foundation (ASF) under one or more+ contributor license agreements. See the NOTICE file distributed with+ this work for additional information regarding copyright ownership.+ The ASF licenses this file to You under the Apache License, Version 2.0+ (the "License"); you may not use this file except in compliance with+ the License. You may obtain a copy of the License at++ http://www.apache.org/licenses/LICENSE-2.0++ Unless required by applicable law or agreed to in writing, software+ distributed under the License is distributed on an "AS IS" BASIS,+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ See the License for the specific language governing permissions and+ limitations under the License.+-->++<!--+ solr.xml mimicking the old default solr.xml+-->++<solr persistent="false">+ <cores adminPath="/admin/cores" defaultCoreName="collection1"+ host="${host:}" hostPort="${hostPort:}" hostContext="${hostContext:}"+ zkClientTimeout="${zkClientTimeout:15000}">+ <core name="collection1" shard="${shard:}" collection="${collection:collection1}" instanceDir="collection1"/>+ </cores>+</solr>diff --git a/solr/contrib/dataimporthandler/src/test-files/dih/solr/solr.xml b/solr/contrib/dataimporthandler/src/test-files/dih/solr/solr.xmlnew file mode 100644index 00000000000..ee072013336--- /dev/null+++ b/solr/contrib/dataimporthandler/src/test-files/dih/solr/solr.xml@@ -0,0 +1,29 @@+<?xml version="1.0" encoding="UTF-8" ?>+<!--+ Licensed to the Apache Software Foundation (ASF) under one or more+ contributor license agreements. See the NOTICE file distributed with+ this work for additional information regarding copyright ownership.+ The ASF licenses this file to You under the Apache License, Version 2.0+ (the "License"); you may not use this file except in compliance with+ the License. You may obtain a copy of the License at++ http://www.apache.org/licenses/LICENSE-2.0++ Unless required by applicable law or agreed to in writing, software+ distributed under the License is distributed on an "AS IS" BASIS,+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ See the License for the specific language governing permissions and+ limitations under the License.+-->++<!--+ solr.xml mimicking the old default solr.xml+-->++<solr persistent="false">+ <cores adminPath="/admin/cores" defaultCoreName="collection1"+ host="${host:}" hostPort="${hostPort:}" hostContext="${hostContext:}"+ zkClientTimeout="${zkClientTimeout:15000}">+ <core name="collection1" shard="${shard:}" collection="${collection:collection1}" instanceDir="collection1"/>+ </cores>+</solr>\ No newline at end of filediff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.javaindex 39b5a78bcb4..8092bde4516 100644--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java@@ -41,6 +41,7 @@ import java.util.List;*/public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCase {private static final String CONF_DIR = "dih/solr/collection1/conf/";+ private static final String ROOT_DIR = "dih/solr/";SolrInstance instance = null;JettySolrRunner jetty;@@ -144,6 +145,11 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCareturn CONF_DIR + "contentstream-solrconfig.xml";}+ public String getSolrXmlFile() {+ return ROOT_DIR + "solr.xml";+ }++public void setUp() throws Exception {File home = new File(TEMP_DIR,@@ -158,6 +164,7 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCadataDir.mkdirs();confDir.mkdirs();+ FileUtils.copyFile(getFile(getSolrXmlFile()), new File(homeDir, "solr.xml"));File f = new File(confDir, "solrconfig.xml");FileUtils.copyFile(getFile(getSolrConfigFile()), f);f = new File(confDir, "schema.xml");diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.javaindex 15a21c771ea..c13cca2e0a9 100644--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java@@ -49,7 +49,8 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTeprivate static final String SOLR_CONFIG = "dataimport-solrconfig.xml";private static final String SOLR_SCHEMA = "dataimport-schema.xml";private static final String SOURCE_CONF_DIR = "dih" + File.separator + "solr" + File.separator + "collection1" + File.separator + "conf" + File.separator;-+ private static final String ROOT_DIR = "dih" + File.separator + "solr" + File.separator;+private static final String DEAD_SOLR_SERVER = "http://[ff01::114]:33332/solr";private static final List<Map<String,Object>> DB_DOCS = new ArrayList<Map<String,Object>>();@@ -293,7 +294,11 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTepublic String getSolrConfigFile() {return SOURCE_CONF_DIR + "dataimport-solrconfig.xml";}-++ public String getSolrXmlFile() {+ return ROOT_DIR + "solr.xml";+ }+public void setUp() throws Exception {File home = new File(TEMP_DIR, getClass().getName() + "-"@@ -306,7 +311,8 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTehomeDir.mkdirs();dataDir.mkdirs();confDir.mkdirs();-++ FileUtils.copyFile(getFile(getSolrXmlFile()), new File(homeDir, "solr.xml"));File f = new File(confDir, "solrconfig.xml");FileUtils.copyFile(getFile(getSolrConfigFile()), f);f = new File(confDir, "schema.xml");diff --git a/solr/core/src/java/org/apache/solr/core/ConfigSolr.java b/solr/core/src/java/org/apache/solr/core/ConfigSolr.javaindex f61c1c1a685..56252a490d2 100644--- a/solr/core/src/java/org/apache/solr/core/ConfigSolr.java+++ b/solr/core/src/java/org/apache/solr/core/ConfigSolr.java@@ -55,8 +55,8 @@ public abstract class ConfigSolr {try {if (!configFile.exists()) {- log.info("{} does not exist, using default configuration", configFile.getAbsolutePath());- inputStream = new ByteArrayInputStream(ConfigSolrXmlOld.DEF_SOLR_XML.getBytes(Charsets.UTF_8));+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,+ "solr.xml does not exist in " + configFile.getAbsolutePath() + " cannot start Solr");}else {inputStream = new FileInputStream(configFile);diff --git a/solr/core/src/java/org/apache/solr/core/ConfigSolrXmlOld.java b/solr/core/src/java/org/apache/solr/core/ConfigSolrXmlOld.javaindex ddd6cea962d..1ee2ff385ef 100644--- a/solr/core/src/java/org/apache/solr/core/ConfigSolrXmlOld.java+++ b/solr/core/src/java/org/apache/solr/core/ConfigSolrXmlOld.java@@ -50,6 +50,8 @@ public class ConfigSolrXmlOld extends ConfigSolr {private final CoresLocator persistor;+ public static final String DEFAULT_DEFAULT_CORE_NAME = "collection1";+@Overrideprotected String getShardHandlerFactoryConfigPath() {return "solr/cores/shardHandlerFactory";@@ -273,19 +275,4 @@ public class ConfigSolrXmlOld extends ConfigSolr {}return new Properties();}-- public static final String DEFAULT_DEFAULT_CORE_NAME = "collection1";-- public static final String DEF_SOLR_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"- + "<solr persistent=\"false\">\n"- + " <cores adminPath=\"/admin/cores\" defaultCoreName=\""- + DEFAULT_DEFAULT_CORE_NAME- + "\""- + " host=\"${host:}\" hostPort=\"${hostPort:}\" hostContext=\"${hostContext:}\" zkClientTimeout=\"${zkClientTimeout:15000}\""- + ">\n"- + " <core name=\""- + DEFAULT_DEFAULT_CORE_NAME- + "\" shard=\"${shard:}\" collection=\"${collection:collection1}\" instanceDir=\"collection1\" />\n"- + " </cores>\n" + "</solr>";-}diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.javaindex d938b2678f5..f11cc6adab5 100644--- a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java+++ b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java@@ -202,7 +202,7 @@ public class SolrDispatchFilter implements Filter}if (this.cores == null) {- ((HttpServletResponse)response).sendError( 503, "Server is shutting down" );+ ((HttpServletResponse)response).sendError( 503, "Server is shutting down or failed to initialize" );return;}CoreContainer cores = this.cores;diff --git a/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java b/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.javaindex d04a9603e3d..181dae10b29 100644--- a/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java+++ b/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java@@ -56,6 +56,7 @@ public class TestSolrCoreProperties extends SolrJettyTestBase {dataDir.mkdirs();confDir.mkdirs();+ FileUtils.copyFile(new File(SolrTestCaseJ4.TEST_HOME(), "solr.xml"), new File(homeDir, "solr.xml"));String src_dir = TEST_HOME() + "/collection1/conf";FileUtils.copyFile(new File(src_dir, "schema-tiny.xml"),new File(confDir, "schema.xml"));diff --git a/solr/core/src/test/org/apache/solr/cloud/ClusterStateUpdateTest.java b/solr/core/src/test/org/apache/solr/cloud/ClusterStateUpdateTest.javaindex 892e0d8ebb7..670ed26733e 100644--- a/solr/core/src/test/org/apache/solr/cloud/ClusterStateUpdateTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/ClusterStateUpdateTest.java@@ -17,6 +17,7 @@ package org.apache.solr.cloud;* limitations under the License.*/+import org.apache.commons.io.FileUtils;import org.apache.lucene.util.LuceneTestCase.Slow;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.common.cloud.ClusterState;@@ -36,6 +37,7 @@ import org.slf4j.Logger;import org.slf4j.LoggerFactory;import java.io.File;+import java.io.IOException;import java.util.HashMap;import java.util.Map;import java.util.Set;@@ -64,19 +66,31 @@ public class ClusterStateUpdateTest extends SolrTestCaseJ4 {private File dataDir3;private File dataDir4;-+++ private static final File solrHomeDirectory = new File(TEMP_DIR, "ZkControllerTest");+@BeforeClass- public static void beforeClass() {+ public static void beforeClass() throws IOException {System.setProperty("solrcloud.skip.autorecovery", "true");System.setProperty("genericCoreNodeNames", "false");+ if (solrHomeDirectory.exists()) {+ FileUtils.deleteDirectory(solrHomeDirectory);+ }+ copyMinFullSetup(solrHomeDirectory);+}-+@AfterClass- public static void afterClass() throws InterruptedException {+ public static void afterClass() throws InterruptedException, IOException {System.clearProperty("solrcloud.skip.autorecovery");System.clearProperty("genericCoreNodeNames");+ if (solrHomeDirectory.exists()) {+ FileUtils.deleteDirectory(solrHomeDirectory);+ }}+@Overridepublic void setUp() throws Exception {super.setUp();@@ -111,19 +125,19 @@ public class ClusterStateUpdateTest extends SolrTestCaseJ4 {System.setProperty("solr.solr.home", TEST_HOME());System.setProperty("hostPort", "1661");System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir1.getAbsolutePath());- container1 = new CoreContainer();+ container1 = new CoreContainer(solrHomeDirectory.getAbsolutePath());container1.load();System.clearProperty("hostPort");System.setProperty("hostPort", "1662");System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir2.getAbsolutePath());- container2 = new CoreContainer();+ container2 = new CoreContainer(solrHomeDirectory.getAbsolutePath());container2.load();System.clearProperty("hostPort");System.setProperty("hostPort", "1663");System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir3.getAbsolutePath());- container3 = new CoreContainer();+ container3 = new CoreContainer(solrHomeDirectory.getAbsolutePath());container3.load();System.clearProperty("hostPort");System.clearProperty("solr.solr.home");@@ -222,7 +236,7 @@ public class ClusterStateUpdateTest extends SolrTestCaseJ4 {System.setProperty("hostPort", "1662");System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir2.getAbsolutePath());- container2 = new CoreContainer();+ container2 = new CoreContainer(solrHomeDirectory.getAbsolutePath());container2.load();System.clearProperty("hostPort");diff --git a/solr/core/src/test/org/apache/solr/cloud/SolrXmlInZkTest.java b/solr/core/src/test/org/apache/solr/cloud/SolrXmlInZkTest.javaindex 7a06c0ebc28..562f41ba3e2 100644--- a/solr/core/src/test/org/apache/solr/cloud/SolrXmlInZkTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/SolrXmlInZkTest.java@@ -33,6 +33,7 @@ import org.junit.rules.RuleChain;import org.junit.rules.TestRule;import java.io.File;+import java.io.IOException;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.nio.charset.Charset;@@ -145,23 +146,23 @@ public class SolrXmlInZkTest extends SolrTestCaseJ4 {setUpZkAndDiskXml(false, true);fail("Should have gotten an exception here!");} catch (InvocationTargetException ite) {- SolrException se = (SolrException) ite.getTargetException();assertEquals("Should have an exception here, file not in ZK.",- "Could not load solr.xml from zookeeper", se.getMessage());+ "Could not load solr.xml from zookeeper", ite.getTargetException().getMessage());} finally {closeZK();}}- // TODO: Solr 5.0. when we remove the default solr.xml from configSolrXmlOld this should start failing.@Testpublic void testNotInZkOrOnDisk() throws Exception {try {System.clearProperty("solr.solrxml.location");System.setProperty("hostPort", "8787");setUpZkAndDiskXml(false, false); // solr.xml not on disk either- assertEquals("Should have gotten the default port from the hard-coded default solr.xml file via sys prop.",- cfg.getZkHostPort(), "8787");+ fail("Should have thrown an exception here");+ } catch (InvocationTargetException ite) {+ assertTrue("Should be failing to create default solr.xml in code",+ ite.getTargetException().getCause().getMessage().indexOf("solr.xml does not exist") != -1);} finally {closeZK();}@@ -185,9 +186,8 @@ public class SolrXmlInZkTest extends SolrTestCaseJ4 {setUpZkAndDiskXml(false, true);fail("Should have thrown exception in SolrXmlInZkTest.testBadSysProp");} catch (InvocationTargetException ite) {- SolrException se = (SolrException) ite.getTargetException();assertEquals("Should have an exception in SolrXmlInZkTest.testBadSysProp, sysprop set to bogus value.",- se.getMessage(), "Bad solr.solrxml.location set: solrHomeDir - should be 'solrhome' or 'zookeeper'");+ ite.getTargetException().getMessage(), "Bad solr.solrxml.location set: solrHomeDir - should be 'solrhome' or 'zookeeper'");} finally {closeZK();}@@ -208,9 +208,7 @@ public class SolrXmlInZkTest extends SolrTestCaseJ4 {fail("Should have thrown an exception");} catch (InvocationTargetException ite) {assertTrue("Should be catching a SolrException", ite.getTargetException() instanceof SolrException);- String cause = ((SolrException) ite.getTargetException()).getMessage();-- assertEquals("Caught Solr exception", cause,+ assertEquals("Caught Solr exception", ite.getTargetException().getMessage(),"Could not load solr.xml from zookeeper: zkHost system property not set");}}diff --git a/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java b/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.javaindex f0bc70b193b..7343cc49363 100644--- a/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java@@ -17,6 +17,7 @@ package org.apache.solr.cloud;* the License.*/+import org.apache.commons.io.FileUtils;import org.apache.lucene.util.LuceneTestCase.Slow;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.common.cloud.SolrZkClient;@@ -26,6 +27,7 @@ import org.apache.solr.core.CoreContainer;import org.apache.solr.core.CoreDescriptor;import org.apache.solr.util.ExternalPaths;import org.apache.zookeeper.CreateMode;+import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Test;@@ -42,12 +44,26 @@ public class ZkControllerTest extends SolrTestCaseJ4 {static final int TIMEOUT = 10000;private static final boolean DEBUG = false;-+++ private static final File solrHomeDirectory = new File(TEMP_DIR, "ZkControllerTest");+@BeforeClasspublic static void beforeClass() throws Exception {+ if (solrHomeDirectory.exists()) {+ FileUtils.deleteDirectory(solrHomeDirectory);+ }+ copyMinFullSetup(solrHomeDirectory);initCore();}+ @AfterClass+ public static void afterClass() throws Exception {+ if (solrHomeDirectory.exists()) {+ FileUtils.deleteDirectory(solrHomeDirectory);+ }+ }+public void testNodeNameUrlConversion() throws Exception {// nodeName from parts@@ -240,7 +256,7 @@ public class ZkControllerTest extends SolrTestCaseJ4 {}private CoreContainer getCoreContainer() {- CoreContainer cc = new CoreContainer(TEMP_DIR.getAbsolutePath());+ CoreContainer cc = new CoreContainer(solrHomeDirectory.getAbsolutePath());cc.load();return cc;}diff --git a/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistence.java b/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistence.javaindex 37977c10256..603e85c0be2 100644--- a/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistence.java+++ b/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistence.java@@ -382,7 +382,10 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {@Testpublic void testPersist() throws Exception {- final CoreContainer cores = init(ConfigSolrXmlOld.DEF_SOLR_XML, "collection1");+ String defXml = FileUtils.readFileToString(+ new File(SolrTestCaseJ4.TEST_HOME(), "solr.xml"),+ Charsets.UTF_8.toString());+ final CoreContainer cores = init(defXml, "collection1");SolrXMLCoresLocator.NonPersistingLocator locator= (SolrXMLCoresLocator.NonPersistingLocator) cores.getCoresLocator();diff --git a/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistor.java b/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistor.javaindex fe466efb2b7..d1b7d3cf117 100644--- a/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistor.java+++ b/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistor.java@@ -18,15 +18,18 @@ package org.apache.solr.core;*/import com.google.common.collect.ImmutableList;+import org.apache.commons.io.FileUtils;+import org.apache.solr.SolrTestCaseJ4;import org.junit.Test;import java.io.File;+import java.io.IOException;import java.util.List;import static org.junit.Assert.assertEquals;import static org.junit.Assert.assertTrue;-public class TestSolrXmlPersistor {+public class TestSolrXmlPersistor extends SolrTestCaseJ4 {private static final List<CoreDescriptor> EMPTY_CD_LIST = ImmutableList.<CoreDescriptor>builder().build();@@ -58,21 +61,33 @@ public class TestSolrXmlPersistor {}@Test- public void simpleCoreDescriptorIsPersisted() {+ public void simpleCoreDescriptorIsPersisted() throws IOException {final String solrxml = "<solr><cores></cores></solr>";- SolrResourceLoader loader = new SolrResourceLoader("solr/example/solr");- CoreContainer cc = new CoreContainer(loader);+ final File solrHomeDirectory = new File(TEMP_DIR, "ZkControllerTest");+ try {+ if (solrHomeDirectory.exists()) {+ FileUtils.deleteDirectory(solrHomeDirectory);+ }+ copyMinFullSetup(solrHomeDirectory);- final CoreDescriptor cd = new CoreDescriptor(cc, "testcore", "instance/dir/");- List<CoreDescriptor> cds = ImmutableList.of(cd);+ CoreContainer cc = new CoreContainer(solrHomeDirectory.getAbsolutePath());- SolrXMLCoresLocator persistor = new SolrXMLCoresLocator(solrxml, null);- assertEquals(persistor.buildSolrXML(cds),+ final CoreDescriptor cd = new CoreDescriptor(cc, "testcore", "instance/dir/");+ List<CoreDescriptor> cds = ImmutableList.of(cd);++ SolrXMLCoresLocator persistor = new SolrXMLCoresLocator(solrxml, null);+ assertEquals(persistor.buildSolrXML(cds),"<solr><cores>" + SolrXMLCoresLocator.NEWLINE- + " <core name=\"testcore\" instanceDir=\"instance/dir/\"/>" + SolrXMLCoresLocator.NEWLINE- + "</cores></solr>");+ + " <core name=\"testcore\" instanceDir=\"instance/dir/\"/>" + SolrXMLCoresLocator.NEWLINE+ + "</cores></solr>");+ } finally {+ if (solrHomeDirectory.exists()) {+ FileUtils.deleteDirectory(solrHomeDirectory);+ }++ }}@Testdiff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.javaindex ff59990a8f9..a0a05a06067 100644--- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java+++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java@@ -69,6 +69,7 @@ import org.apache.solr.core.SolrCore;import org.apache.solr.core.StandardDirectoryFactory;import org.apache.solr.servlet.SolrDispatchFilter;import org.apache.solr.util.AbstractSolrTestCase;+import org.apache.solr.util.FileUtils;import org.junit.After;import org.junit.Before;import org.junit.Test;@@ -139,7 +140,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {private static JettySolrRunner createJetty(SolrInstance instance) throws Exception {System.setProperty("solr.data.dir", instance.getDataDir());-+ FileUtils.copyFile(new File(SolrTestCaseJ4.TEST_HOME(), "solr.xml"), new File(instance.getHomeDir(), "solr.xml"));JettySolrRunner jetty = new JettySolrRunner(instance.getHomeDir(), "/solr", 0);jetty.start();diff --git a/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java b/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.javaindex d6256e919ed..c1f74ac13c7 100644--- a/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java+++ b/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java@@ -27,10 +27,12 @@ import org.apache.solr.client.solrj.request.QueryRequest;import org.apache.solr.client.solrj.response.QueryResponse;import org.apache.solr.common.SolrException;import org.apache.solr.common.SolrInputDocument;+import org.junit.AfterClass;import org.junit.Before;import org.junit.BeforeClass;import org.junit.Test;+import java.io.File;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;@@ -44,10 +46,18 @@ import java.net.URLEncoder;*/public class TestRemoteStreaming extends SolrJettyTestBase {+ private static final File solrHomeDirectory = new File(TEMP_DIR, "TestRemoteStreaming");+@BeforeClasspublic static void beforeTest() throws Exception {//this one has handleSelect=true which a test here needs- createJetty("solr/", null, null);+ setupJettyTestHome(solrHomeDirectory, "collection1");+ createJetty(solrHomeDirectory.getAbsolutePath(), null, null);+ }++ @AfterClass+ public static void afterTest() throws Exception {+ cleanUpJettyHome(solrHomeDirectory);}@Beforediff --git a/solr/core/src/test/org/apache/solr/schema/TestBinaryField.java b/solr/core/src/test/org/apache/solr/schema/TestBinaryField.javaindex 98624601899..2c0a8203de5 100644--- a/solr/core/src/test/org/apache/solr/schema/TestBinaryField.java+++ b/solr/core/src/test/org/apache/solr/schema/TestBinaryField.java@@ -17,20 +17,17 @@package org.apache.solr.schema;import java.io.File;-import java.io.FileOutputStream;import java.nio.ByteBuffer;import java.util.List;-import org.apache.commons.io.IOUtils;import org.apache.commons.io.FileUtils;+import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.client.solrj.SolrServer;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.client.solrj.beans.Field;-import org.apache.solr.client.solrj.impl.HttpSolrServer;import org.apache.solr.client.solrj.response.QueryResponse;import org.apache.solr.common.*;-import org.apache.solr.core.SolrResourceLoader;import org.apache.solr.SolrJettyTestBase;import org.junit.BeforeClass;@@ -49,6 +46,8 @@ public class TestBinaryField extends SolrJettyTestBase {dataDir.mkdirs();confDir.mkdirs();+ FileUtils.copyFile(new File(SolrTestCaseJ4.TEST_HOME(), "solr.xml"), new File(homeDir, "solr.xml"));+String src_dir = TEST_HOME() + "/collection1/conf";FileUtils.copyFile(new File(src_dir, "schema-binaryfield.xml"),new File(confDir, "schema.xml"));diff --git a/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTest.java b/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTest.javaindex d3a651fc25d..3cec999981f 100644--- a/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTest.java+++ b/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTest.java@@ -23,11 +23,13 @@ import java.io.Writer;import java.util.Arrays;import java.util.Date;+import com.google.common.base.Charsets;import org.apache.http.Header;import org.apache.http.HttpResponse;import org.apache.http.client.methods.HttpRequestBase;import org.apache.http.impl.cookie.DateUtils;import org.apache.solr.common.params.CommonParams;+import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Test;@@ -37,13 +39,18 @@ import org.apache.lucene.util._TestUtil;* A test case for the several HTTP cache headers emitted by Solr*/public class CacheHeaderTest extends CacheHeaderTestBase {+ private static final File solrHomeDirectory = new File(TEMP_DIR, "CacheHeaderTest");@BeforeClasspublic static void beforeTest() throws Exception {- createJetty("solr/", null, null);+ setupJettyTestHome(solrHomeDirectory, "collection1");+ createJetty(solrHomeDirectory.getAbsolutePath(), null, null);}- protected static final String CHARSET = "UTF-8";+ @AfterClass+ public static void afterTest() throws Exception {+ cleanUpJettyHome(solrHomeDirectory);+ }protected static final String CONTENTS = "id\n100\n101\n102";@@ -241,7 +248,7 @@ public class CacheHeaderTest extends CacheHeaderTestBase {}protected File makeFile(String contents) {- return makeFile(contents, CHARSET);+ return makeFile(contents, Charsets.UTF_8.toString());}protected File makeFile(String contents, String charset) {diff --git a/solr/solrj/src/test-files/solrj/solr/solr.xml b/solr/solrj/src/test-files/solrj/solr/solr.xmlindex 73d11117219..be8a4d79702 100644--- a/solr/solrj/src/test-files/solrj/solr/solr.xml+++ b/solr/solrj/src/test-files/solrj/solr/solr.xml@@ -29,6 +29,7 @@If 'null' (or absent), cores will not be manageable via request handler--><cores adminPath="/admin/cores" defaultCoreName="collection1" host="127.0.0.1" hostPort="${hostPort:8983}" hostContext="${hostContext:solr}" zkClientTimeout="8000" genericCoreNodeNames="${genericCoreNodeNames:true}">- <core name="collection1" instanceDir="collection1" shard="${shard:}" collection="${collection:collection1}" config="${solrconfig:solrconfig.xml}" schema="${schema:schema.xml}"/>+ <core name="collection1" instanceDir="collection1" shard="${shard:}" collection="${collection:collection1}" />+ <!--config="${solrconfig:solrconfig.xml}" schema="${schema:schema.xml}"/--></cores></solr>diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.javaindex 54ebbf621e7..0f06d068552 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java@@ -273,6 +273,11 @@ public class TestLBHttpSolrServer extends LuceneTestCase {return "solrj/solr/collection1/conf/solrconfig-slave1.xml";}+ public String getSolrXmlFile() {+ return "solrj/solr/solr.xml";+ }++public void setUp() throws Exception {File home = new File(LuceneTestCase.TEMP_DIR,getClass().getName() + "-" + System.currentTimeMillis());@@ -286,6 +291,8 @@ public class TestLBHttpSolrServer extends LuceneTestCase {dataDir.mkdirs();confDir.mkdirs();+ FileUtils.copyFile(SolrTestCaseJ4.getFile(getSolrXmlFile()), new File(homeDir, "solr.xml"));+File f = new File(confDir, "solrconfig.xml");FileUtils.copyFile(SolrTestCaseJ4.getFile(getSolrConfigFile()), f);f = new File(confDir, "schema.xml");diff --git a/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java b/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.javaindex feae82a1d26..af6da5c1fba 100644--- a/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java+++ b/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java@@ -22,6 +22,7 @@ import java.util.HashMap;import java.util.Map;import java.util.SortedMap;+import org.apache.commons.io.FileUtils;import org.apache.solr.client.solrj.SolrServer;import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;import org.apache.solr.client.solrj.embedded.JettySolrRunner;@@ -188,4 +189,21 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4return new EmbeddedSolrServer( h.getCoreContainer(), "" );}}++ // Sets up the necessary config files for Jetty. At least some tests require that the solrconfig from the test+ // file directory are used, but some also require that the solr.xml file be explicitly there as of SOLR-4817+ public static void setupJettyTestHome(File solrHome, String collection) throws Exception {+ if (solrHome.exists()) {+ FileUtils.deleteDirectory(solrHome);+ }+ copySolrHomeToTemp(solrHome, collection);+ }++ public static void cleanUpJettyHome(File solrHome) throws Exception {+ if (solrHome.exists()) {+ FileUtils.deleteDirectory(solrHome);+ }+ }++}diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.javaindex 35f48d06619..365c241a121 100644--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java@@ -1599,16 +1599,53 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {}}// Creates a mininmal conf dir.- public void copyMinConf(File dstRoot) throws IOException {+ public static void copyMinConf(File dstRoot) throws IOException {File subHome = new File(dstRoot, "conf");- assertTrue("Failed to make subdirectory ", dstRoot.mkdirs());+ if (! dstRoot.exists()) {+ assertTrue("Failed to make subdirectory ", dstRoot.mkdirs());+ }+String top = SolrTestCaseJ4.TEST_HOME() + "/collection1/conf";FileUtils.copyFile(new File(top, "schema-tiny.xml"), new File(subHome, "schema.xml"));FileUtils.copyFile(new File(top, "solrconfig-minimal.xml"), new File(subHome, "solrconfig.xml"));FileUtils.copyFile(new File(top, "solrconfig.snippet.randomindexconfig.xml"), new File(subHome, "solrconfig.snippet.randomindexconfig.xml"));}+ // Creates minimal full setup, including the old solr.xml file that used to be hard coded in COnfigSolrXmlOld+ public static void copyMinFullSetup(File dstRoot) throws IOException {+ if (! dstRoot.exists()) {+ assertTrue("Failed to make subdirectory ", dstRoot.mkdirs());+ }+ File xmlF = new File(SolrTestCaseJ4.TEST_HOME(), "solr.xml");+ FileUtils.copyFile(xmlF, new File(dstRoot, "solr.xml"));+ copyMinConf(dstRoot);+ }++ // Creates a consistent configuration, _including_ solr.xml at dstRoot. Creates collection1/conf and copies+ // the stock files in there. Seems to be indicated for some tests when we remove the default, hard-coded+ // solr.xml from being automatically synthesized from SolrConfigXmlOld.DEFAULT_SOLR_XML.+ public static void copySolrHomeToTemp(File dstRoot, String collection) throws IOException {+ if (!dstRoot.exists()) {+ assertTrue("Failed to make subdirectory ", dstRoot.mkdirs());+ }++ FileUtils.copyFile(new File(SolrTestCaseJ4.TEST_HOME(), "solr.xml"), new File(dstRoot, "solr.xml"));++ File subHome = new File(dstRoot, collection + File.separator + "conf");+ String top = SolrTestCaseJ4.TEST_HOME() + "/collection1/conf";+ FileUtils.copyFile(new File(top, "currency.xml"), new File(subHome, "currency.xml"));+ FileUtils.copyFile(new File(top, "mapping-ISOLatin1Accent.txt"), new File(subHome, "mapping-ISOLatin1Accent.txt"));+ FileUtils.copyFile(new File(top, "old_synonyms.txt"), new File(subHome, "old_synonyms.txt"));+ FileUtils.copyFile(new File(top, "open-exchange-rates.json"), new File(subHome, "open-exchange-rates.json"));+ FileUtils.copyFile(new File(top, "protwords.txt"), new File(subHome, "protwords.txt"));+ FileUtils.copyFile(new File(top, "schema.xml"), new File(subHome, "schema.xml"));+ FileUtils.copyFile(new File(top, "solrconfig.snippet.randomindexconfig.xml"), new File(subHome, "solrconfig.snippet.randomindexconfig.xml"));+ FileUtils.copyFile(new File(top, "solrconfig.xml"), new File(subHome, "solrconfig.xml"));+ FileUtils.copyFile(new File(top, "stopwords.txt"), new File(subHome, "stopwords.txt"));+ FileUtils.copyFile(new File(top, "synonyms.txt"), new File(subHome, "synonyms.txt"));+ }+public static CoreDescriptorBuilder buildCoreDescriptor(CoreContainer container, String name, String instancedir) {return new CoreDescriptorBuilder(container, name, instancedir);}