SOLR-4817 Solr should not fall back to the back compat built in solr.xml in SolrCloud mode.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1517398 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erick Erickson 2013-08-26 00:06:04 +00:00
parent 278d690bad
commit 84063af19a
22 changed files with 252 additions and 64 deletions

View File

@ -149,6 +149,9 @@ Bug Fixes
* SOLR-5174: Admin UI - Query View doesn't highlight (json) Result if it
contains HTML Tags (steffkes)
* SOLR-4817 Solr should not fall back to the back compat built in solr.xml in SolrCloud
mode (Erick Erickson)
Optimizations
----------------------

View File

@ -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>

View File

@ -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>

View File

@ -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 AbstractDataImportHandlerTestCa
return 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 AbstractDataImportHandlerTestCa
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");

View File

@ -49,6 +49,7 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe
private 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";
@ -294,6 +295,10 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe
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() + "-"
@ -307,6 +312,7 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe
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");

View File

@ -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);

View File

@ -50,6 +50,8 @@ public class ConfigSolrXmlOld extends ConfigSolr {
private final CoresLocator persistor;
public static final String DEFAULT_DEFAULT_CORE_NAME = "collection1";
@Override
protected 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>";
}

View File

@ -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;

View File

@ -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"));

View File

@ -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;
@ -65,17 +67,29 @@ public class ClusterStateUpdateTest extends SolrTestCaseJ4 {
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);
}
}
@Override
public void setUp() throws Exception {
@ -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");

View File

@ -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.
@Test
public 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");
}
}

View File

@ -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;
@ -43,11 +45,25 @@ public class ZkControllerTest extends SolrTestCaseJ4 {
private static final boolean DEBUG = false;
private static final File solrHomeDirectory = new File(TEMP_DIR, "ZkControllerTest");
@BeforeClass
public 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;
}

View File

@ -382,7 +382,10 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
@Test
public 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();

View File

@ -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,12 +61,18 @@ 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);
CoreContainer cc = new CoreContainer(solrHomeDirectory.getAbsolutePath());
final CoreDescriptor cd = new CoreDescriptor(cc, "testcore", "instance/dir/");
List<CoreDescriptor> cds = ImmutableList.of(cd);
@ -73,6 +82,12 @@ public class TestSolrXmlPersistor {
"<solr><cores>" + SolrXMLCoresLocator.NEWLINE
+ " <core name=\"testcore\" instanceDir=\"instance/dir/\"/>" + SolrXMLCoresLocator.NEWLINE
+ "</cores></solr>");
} finally {
if (solrHomeDirectory.exists()) {
FileUtils.deleteDirectory(solrHomeDirectory);
}
}
}
@Test

View File

@ -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();

View File

@ -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");
@BeforeClass
public 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);
}
@Before

View File

@ -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"));

View File

@ -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");
@BeforeClass
public 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) {

View File

@ -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>

View File

@ -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");

View File

@ -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 SolrTestCaseJ4
return 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);
}
}
}

View File

@ -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");
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);
}