Apache Lucene open-source search software
SOLR-6840: Remove support for old-style solr.xml
Alan Woodwarde61cd9654b06
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 5f01d790cd8..2a71d09bbb5 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -183,6 +183,10 @@ Upgrading from Solr 4.x* Due to changes in the underlying commons-codec package, users of the BeiderMorseFilterFactorywill need to rebuild their indexes after upgrading. See LUCENE-6058 for more details.+* The 'old-style' solr.xml format is no longer supported, and cores must be+ defined using core.properties files. See+ https://cwiki.apache.org/confluence/display/solr/Format+of+solr.xml+Detailed Change List----------------------@@ -738,6 +742,8 @@ Other Changes* SOLR-6981: Add a delete action to the bin/solr script to allow deleting of cores /collections (with delete collection config directory from ZK) (Timothy Potter)+* SOLR-6840: Remove support for old-style solr.xml (Erick Erickson, Alan Woodward)+================== 4.10.3 ==================Bug Fixesdiff --git a/solr/contrib/clustering/src/test-files/clustering/solr/solr.xml b/solr/contrib/clustering/src/test-files/clustering/solr/solr.xmlindex 98a31e6d668..f39bd6464a3 100644--- a/solr/contrib/clustering/src/test-files/clustering/solr/solr.xml+++ b/solr/contrib/clustering/src/test-files/clustering/solr/solr.xml@@ -20,14 +20,10 @@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"/>-+<solr>+<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory"><str name="urlScheme">${urlScheme:}</str></shardHandlerFactory>- </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.xmlindex 4088f521d08..330eef10509 100644--- a/solr/contrib/dataimporthandler/src/test-files/dih/solr/solr.xml+++ b/solr/contrib/dataimporthandler/src/test-files/dih/solr/solr.xml@@ -20,13 +20,8 @@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"/>+<solr><shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory"><str name="urlScheme">${urlScheme:}</str></shardHandlerFactory>- </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 88f96ef4a95..d26b284ea83 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@@ -16,9 +16,6 @@*/package org.apache.solr.handler.dataimport;-import java.io.File;-import java.util.List;-import org.apache.commons.io.FileUtils;import org.apache.solr.client.solrj.embedded.JettySolrRunner;import org.apache.solr.client.solrj.impl.HttpSolrClient;@@ -32,6 +29,10 @@ import org.junit.After;import org.junit.Before;import org.junit.Test;+import java.io.File;+import java.nio.file.Files;+import java.util.List;+/*** Test for ContentStreamDataSource*@@ -67,7 +68,7 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCaparams.set("command", "full-import");params.set("clean", "false");req.setParams(params);- HttpSolrClient solrClient = new HttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr"));+ HttpSolrClient solrClient = new HttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr/collection1"));try {solrClient.request(req);ModifiableSolrParams qparams = new ModifiableSolrParams();@@ -90,7 +91,7 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCa"clean", "false", UpdateParams.COMMIT, "false",UpdateParams.COMMIT_WITHIN, "1000");req.setParams(params);- HttpSolrClient solrServer = new HttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr"));+ HttpSolrClient solrServer = new HttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr/collection1"));solrServer.request(req);Thread.sleep(100);ModifiableSolrParams queryAll = params("q", "*");@@ -168,6 +169,8 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCaFileUtils.copyFile(getFile(getSchemaFile()), f);f = new File(confDir, "data-config.xml");FileUtils.copyFile(getFile(CONF_DIR + "dataconfig-contentstream.xml"), f);++ Files.createFile(homeDir.toPath().resolve("collection1/core.properties"));}}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 82ceaabfd7d..dd193c1cc89 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@@ -17,14 +17,6 @@ package org.apache.solr.handler.dataimport;* limitations under the License.*/-import java.io.File;-import java.io.IOException;-import java.util.ArrayList;-import java.util.HashMap;-import java.util.List;-import java.util.Map;-import java.util.Map.Entry;-import org.apache.commons.io.FileUtils;import org.apache.lucene.util.IOUtils;import org.apache.solr.client.solrj.SolrServerException;@@ -38,6 +30,15 @@ import org.junit.BeforeClass;import org.slf4j.Logger;import org.slf4j.LoggerFactory;+import java.io.File;+import java.io.IOException;+import java.nio.file.Files;+import java.util.ArrayList;+import java.util.HashMap;+import java.util.List;+import java.util.Map;+import java.util.Map.Entry;+/*** End-to-end test of SolrEntityProcessor. "Real" test using embedded Solr*/@@ -94,7 +95,7 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe}private String getSourceUrl() {- return buildUrl(jetty.getLocalPort(), "/solr");+ return buildUrl(jetty.getLocalPort(), "/solr/collection1");}//TODO: fix this test to close its directories@@ -332,6 +333,8 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTeFileUtils.copyFile(getFile(getSchemaFile()), f);f = new File(confDir, "data-config.xml");FileUtils.copyFile(getFile(SOURCE_CONF_DIR + "dataconfig-contentstream.xml"), f);++ Files.createFile(confDir.toPath().resolve("../core.properties"));}public void tearDown() throws Exception {diff --git a/solr/contrib/morphlines-core/src/test-files/solr/solr.xml b/solr/contrib/morphlines-core/src/test-files/solr/solr.xmlindex 3c6317e2caf..5c8756ec476 100644--- a/solr/contrib/morphlines-core/src/test-files/solr/solr.xml+++ b/solr/contrib/morphlines-core/src/test-files/solr/solr.xml@@ -16,18 +16,25 @@limitations under the License.-->-<!--- All (relative) paths are relative to the installation path-- persistent: Save changes made via the API to this file- sharedLib: path to a lib directory that will be shared across all cores--->-<solr persistent="${solr.xml.persist:false}">+<solr>++ <solrcloud>+ <int name="hostPort">${hostPort:8983}</int>+ <str name="hostContext">${hostContext:solr}</str>+ <int name="zkClientTimeout">${solr.zkclienttimeout:30000}</int>+ <str name="host">127.0.0.1</str>+ </solrcloud>++ <shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">+ <str name="urlScheme">${urlScheme:}</str>+ <int name="socketTimeout">${socketTimeout:120000}</int>+ <int name="connTimeout">${connTimeout:15000}</int>+ </shardHandlerFactory><!--adminPath: RequestHandler path to manage cores.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="${solr.zkclienttimeout:30000}" numShards="${numShards:3}" shareSchema="${shareSchema:false}"genericCoreNodeNames="${genericCoreNodeNames:true}" leaderVoteWait="0"@@ -40,5 +47,6 @@<int name="connTimeout">${connTimeout:15000}</int></shardHandlerFactory></cores>+ --></solr>diff --git a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineTestBase.java b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineTestBase.javaindex 336f5deca99..8a64a428cb7 100644--- a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineTestBase.java+++ b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineTestBase.java@@ -16,25 +16,14 @@*/package org.apache.solr.morphlines.solr;-import java.io.ByteArrayInputStream;-import java.io.File;-import java.io.IOException;-import java.util.Arrays;-import java.util.Calendar;-import java.util.Collection;-import java.util.HashMap;-import java.util.HashSet;-import java.util.Iterator;-import java.util.Locale;-import java.util.Map;-import java.util.Map.Entry;-import java.util.TimeZone;-import java.util.concurrent.atomic.AtomicInteger;-+import com.codahale.metrics.MetricRegistry;+import com.google.common.base.Joiner;+import com.google.common.io.Files;+import com.typesafe.config.Config;import org.apache.commons.io.FileUtils;import org.apache.solr.SolrTestCaseJ4;-import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.client.solrj.SolrClient;+import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.client.solrj.SolrServerException;import org.apache.solr.client.solrj.impl.HttpSolrClient;import org.apache.solr.client.solrj.impl.XMLResponseParser;@@ -56,10 +45,20 @@ import org.kitesdk.morphline.stdlib.PipeBuilder;import org.slf4j.Logger;import org.slf4j.LoggerFactory;-import com.codahale.metrics.MetricRegistry;-import com.google.common.base.Joiner;-import com.google.common.io.Files;-import com.typesafe.config.Config;+import java.io.ByteArrayInputStream;+import java.io.File;+import java.io.IOException;+import java.util.Arrays;+import java.util.Calendar;+import java.util.Collection;+import java.util.HashMap;+import java.util.HashSet;+import java.util.Iterator;+import java.util.Locale;+import java.util.Map;+import java.util.Map.Entry;+import java.util.TimeZone;+import java.util.concurrent.atomic.AtomicInteger;public class AbstractSolrMorphlineTestBase extends SolrTestCaseJ4 {private static Locale savedLocale;@@ -123,7 +122,7 @@ public class AbstractSolrMorphlineTestBase extends SolrTestCaseJ4 {((HttpSolrClient) solrClient).setParser(new XMLResponseParser());} else {if (TEST_WITH_EMBEDDED_SOLR_SERVER) {- solrClient = new EmbeddedTestSolrServer(h.getCoreContainer(), "");+ solrClient = new EmbeddedTestSolrServer(h.getCoreContainer(), DEFAULT_TEST_CORENAME);} else {throw new RuntimeException("Not yet implemented");//solrServer = new TestSolrServer(getSolrClient());diff --git a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineZkTestBase.java b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineZkTestBase.javaindex 13e47960744..fc403351cc2 100644--- a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineZkTestBase.java+++ b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineZkTestBase.java@@ -17,11 +17,9 @@package org.apache.solr.morphlines.solr;-import java.io.File;-import java.io.IOException;-import java.util.Iterator;-import java.util.Locale;-+import com.codahale.metrics.MetricRegistry;+import com.google.common.collect.ListMultimap;+import com.typesafe.config.Config;import org.apache.commons.io.FileUtils;import org.apache.solr.client.solrj.SolrServerException;import org.apache.solr.client.solrj.embedded.JettySolrRunner;@@ -42,9 +40,10 @@ import org.kitesdk.morphline.base.FaultTolerance;import org.kitesdk.morphline.base.Notifications;import org.kitesdk.morphline.stdlib.PipeBuilder;-import com.codahale.metrics.MetricRegistry;-import com.google.common.collect.ListMultimap;-import com.typesafe.config.Config;+import java.io.File;+import java.io.IOException;+import java.util.Iterator;+import java.util.Locale;public abstract class AbstractSolrMorphlineZkTestBase extends AbstractFullDistribZkTestBase {private static File solrHomeDirectory;@@ -155,7 +154,8 @@ public abstract class AbstractSolrMorphlineZkTestBase extends AbstractFullDistripublic JettySolrRunner createJetty(File solrHome, String dataDir,String shardList, String solrConfigOverride, String schemaOverride)throws Exception {-++ writeCoreProperties(solrHome.toPath(), DEFAULT_TEST_CORENAME);JettySolrRunner jetty = new JettySolrRunner(solrHome.getAbsolutePath(),context, 0, solrConfigOverride, schemaOverride, true, null, sslConfig);diff --git a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/SolrMorphlineTest.java b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/SolrMorphlineTest.javaindex 1731b4dc62c..1fceed95128 100644--- a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/SolrMorphlineTest.java+++ b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/SolrMorphlineTest.java@@ -16,17 +16,15 @@*/package org.apache.solr.morphlines.solr;-import java.io.File;-import java.util.Arrays;--import org.apache.lucene.util.Constants;import org.junit.BeforeClass;import org.junit.Test;-import org.kitesdk.morphline.api.Record;import org.kitesdk.morphline.base.Fields;import org.kitesdk.morphline.base.Notifications;+import java.io.File;+import java.util.Arrays;+public class SolrMorphlineTest extends AbstractSolrMorphlineTestBase {@Testdiff --git a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/SolrMorphlineZkAliasTest.java b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/SolrMorphlineZkAliasTest.javaindex 43a813af914..1de9a6d506e 100644--- a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/SolrMorphlineZkAliasTest.java+++ b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/SolrMorphlineZkAliasTest.java@@ -16,11 +16,13 @@*/package org.apache.solr.morphlines.solr;-import java.io.File;-import java.io.IOException;-import java.util.Iterator;--import org.apache.lucene.util.Constants;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction.Action;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies.Consequence;import org.apache.lucene.util.LuceneTestCase.Slow;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.client.solrj.SolrServerException;@@ -35,13 +37,9 @@ import org.kitesdk.morphline.api.Record;import org.kitesdk.morphline.base.Fields;import org.kitesdk.morphline.base.Notifications;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction.Action;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies.Consequence;+import java.io.File;+import java.io.IOException;+import java.util.Iterator;@ThreadLeakAction({Action.WARN})@ThreadLeakLingering(linger = 0)diff --git a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/SolrMorphlineZkAvroTest.java b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/SolrMorphlineZkAvroTest.javaindex e9b9d105cf8..db1c96b22dc 100644--- a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/SolrMorphlineZkAvroTest.java+++ b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/SolrMorphlineZkAvroTest.java@@ -16,19 +16,21 @@*/package org.apache.solr.morphlines.solr;-import java.io.File;-import java.util.ArrayList;-import java.util.Collections;-import java.util.Comparator;-import java.util.Iterator;-import java.util.List;-+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction.Action;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies.Consequence;+import com.google.common.base.Joiner;+import com.google.common.base.Preconditions;+import com.google.common.io.Files;import org.apache.avro.Schema.Field;import org.apache.avro.file.DataFileReader;import org.apache.avro.file.FileReader;import org.apache.avro.generic.GenericData;import org.apache.avro.generic.GenericDatumReader;-import org.apache.lucene.util.Constants;import org.apache.lucene.util.LuceneTestCase.Slow;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.client.solrj.response.QueryResponse;@@ -38,16 +40,12 @@ import org.kitesdk.morphline.api.Record;import org.kitesdk.morphline.base.Fields;import org.kitesdk.morphline.base.Notifications;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction.Action;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies.Consequence;-import com.google.common.base.Joiner;-import com.google.common.base.Preconditions;-import com.google.common.io.Files;+import java.io.File;+import java.util.ArrayList;+import java.util.Collections;+import java.util.Comparator;+import java.util.Iterator;+import java.util.List;@ThreadLeakAction({Action.WARN})@ThreadLeakLingering(linger = 0)diff --git a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/SolrMorphlineZkTest.java b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/SolrMorphlineZkTest.javaindex b75314c4465..753126a2fa8 100644--- a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/SolrMorphlineZkTest.java+++ b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/SolrMorphlineZkTest.java@@ -16,10 +16,13 @@*/package org.apache.solr.morphlines.solr;-import java.io.File;-import java.util.Iterator;--import org.apache.lucene.util.Constants;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction.Action;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies.Consequence;import org.apache.lucene.util.LuceneTestCase.Slow;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.client.solrj.response.QueryResponse;@@ -29,13 +32,8 @@ import org.kitesdk.morphline.api.Record;import org.kitesdk.morphline.base.Fields;import org.kitesdk.morphline.base.Notifications;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction.Action;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies.Consequence;+import java.io.File;+import java.util.Iterator;@ThreadLeakAction({Action.WARN})@ThreadLeakLingering(linger = 0)diff --git a/solr/core/src/java/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java b/solr/core/src/java/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.javaindex 376f08de754..50df70b767f 100644--- a/solr/core/src/java/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java+++ b/solr/core/src/java/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java@@ -129,10 +129,8 @@ public class EmbeddedSolrServer extends SolrClient}}// Perhaps the path is to manage the cores- if( handler == null &&- coreContainer != null &&- path.equals( coreContainer.getAdminPath() ) ) {- handler = coreContainer.getMultiCoreHandler();+ if (handler == null) {+ handler = coreContainer.getRequestHandler(path);}}if( handler == null ) {diff --git a/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java b/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.javaindex a34691a2c60..33b40988c03 100644--- a/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java+++ b/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java@@ -31,7 +31,6 @@ import org.eclipse.jetty.servlet.FilterHolder;import org.eclipse.jetty.servlet.ServletContextHandler;import org.eclipse.jetty.servlet.ServletHolder;import org.eclipse.jetty.servlets.GzipFilter;-import org.eclipse.jetty.servlets.gzip.GzipHandler;import org.eclipse.jetty.util.component.LifeCycle;import org.eclipse.jetty.util.log.Logger;import org.eclipse.jetty.util.ssl.SslContextFactory;@@ -64,6 +63,9 @@ import java.util.concurrent.atomic.AtomicLong;* @since solr 1.3*/public class JettySolrRunner {++ private static final AtomicLong JETTY_ID_COUNTER = new AtomicLong();+Server server;FilterHolder dispatchFilter;@@ -73,6 +75,7 @@ public class JettySolrRunner {private String solrConfigFilename;private String schemaFilename;+ private final String coreRootDirectory;private boolean waitOnSolr = false;@@ -91,6 +94,8 @@ public class JettySolrRunner {private String coreNodeName;+ private final String name;+/** Maps servlet holders (i.e. factories: class + init params) to path specs */private SortedMap<ServletHolder,String> extraServlets = new TreeMap<>();private SortedMap<Class,String> extraRequestFilters;@@ -149,12 +154,16 @@ public class JettySolrRunner {public JettySolrRunner(String solrHome, String context, int port) {this.init(solrHome, context, port, true);+ this.name = "jetty-" + JETTY_ID_COUNTER.incrementAndGet();+ this.coreRootDirectory = System.getProperty("coreRootDirectory", null);}public JettySolrRunner(String solrHome, String context, int port, String solrConfigFilename, String schemaFileName) {this.init(solrHome, context, port, true);this.solrConfigFilename = solrConfigFilename;this.schemaFilename = schemaFileName;+ this.name = "jetty-" + JETTY_ID_COUNTER.incrementAndGet();+ this.coreRootDirectory = System.getProperty("coreRootDirectory", null);}public JettySolrRunner(String solrHome, String context, int port,@@ -162,6 +171,8 @@ public class JettySolrRunner {this.init(solrHome, context, port, stopAtShutdown);this.solrConfigFilename = solrConfigFilename;this.schemaFilename = schemaFileName;+ this.name = "jetty-" + JETTY_ID_COUNTER.incrementAndGet();+ this.coreRootDirectory = System.getProperty("coreRootDirectory", null);}/**@@ -199,6 +210,9 @@ public class JettySolrRunner {this.schemaFilename = schemaFileName;this.sslConfig = sslConfig;+ this.name = "jetty-" + JETTY_ID_COUNTER.incrementAndGet();+ this.coreRootDirectory = System.getProperty("coreRootDirectory", null);+this.init(solrHome, context, port, stopAtShutdown);}@@ -207,6 +221,7 @@ public class JettySolrRunner {this.solrHome = solrHome;this.stopAtShutdown = stopAtShutdown;+System.setProperty("solr.solr.home", solrHome);if (System.getProperty("jetty.testMode") != null) {// if this property is true, then jetty will be configured to use SSL@@ -298,6 +313,8 @@ public class JettySolrRunner {solrConfigFilename);if (schemaFilename != null) System.setProperty("schema",schemaFilename);+ if (coreRootDirectory != null)+ System.setProperty("coreRootDirectory", coreRootDirectory);// SolrDispatchFilter filter = new SolrDispatchFilter();// FilterHolder fh = new FilterHolder(filter);debugFilter = root.addFilter(DebugFilter.class, "*", EnumSet.of(DispatcherType.REQUEST) );diff --git a/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.java b/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.javaindex 02f358af87f..4f4efcc0b76 100644--- a/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.java+++ b/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.java@@ -17,6 +17,7 @@ package org.apache.solr.cloud;* limitations under the License.*/+import com.google.common.base.Strings;import org.apache.solr.common.cloud.Slice;import org.apache.solr.common.cloud.ZkStateReader;import org.apache.solr.common.params.SolrParams;@@ -49,10 +50,14 @@ public class CloudDescriptor {public CloudDescriptor(String coreName, Properties props, CoreDescriptor cd) {this.cd = cd;this.shardId = props.getProperty(CoreDescriptor.CORE_SHARD, null);+ if (Strings.isNullOrEmpty(shardId))+ this.shardId = null;// If no collection name is specified, we default to the core namethis.collectionName = props.getProperty(CoreDescriptor.CORE_COLLECTION, coreName);this.roles = props.getProperty(CoreDescriptor.CORE_ROLES, null);this.nodeName = props.getProperty(CoreDescriptor.CORE_NODE_NAME);+ if (Strings.isNullOrEmpty(nodeName))+ this.nodeName = null;this.numShards = PropertiesUtil.toInteger(props.getProperty(CloudDescriptor.NUM_SHARDS), null);}diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkController.java b/solr/core/src/java/org/apache/solr/cloud/ZkController.javaindex 5656ce8735c..f7068f75202 100644--- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java+++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java@@ -614,15 +614,13 @@ public final class ZkController {ShardHandler shardHandler;UpdateShardHandler updateShardHandler;- String adminPath;shardHandler = cc.getShardHandlerFactory().getShardHandler();updateShardHandler = cc.getUpdateShardHandler();- adminPath = cc.getAdminPath();if (!zkRunOnly) {overseerElector = new LeaderElector(zkClient);this.overseer = new Overseer(shardHandler, updateShardHandler,- adminPath, zkStateReader, this, cc.getConfig());+ CoreContainer.CORES_HANDLER_PATH, zkStateReader, this, cc.getConfig());ElectionContext context = new OverseerElectionContext(zkClient,overseer, getNodeName());overseerElector.setup(context);diff --git a/solr/core/src/java/org/apache/solr/core/ConfigSolr.java b/solr/core/src/java/org/apache/solr/core/ConfigSolr.javaindex 412b4506336..f4e501c685c 100644--- a/solr/core/src/java/org/apache/solr/core/ConfigSolr.java+++ b/solr/core/src/java/org/apache/solr/core/ConfigSolr.java@@ -22,25 +22,15 @@ import org.apache.solr.cloud.CloudConfigSetService;import org.apache.solr.cloud.ZkController;import org.apache.solr.common.SolrException;import org.apache.solr.logging.LogWatcherConfig;-import org.apache.solr.util.DOMUtil;-import org.apache.solr.util.PropertiesUtil;import org.slf4j.Logger;import org.slf4j.LoggerFactory;-import org.w3c.dom.Node;-import org.w3c.dom.NodeList;import org.xml.sax.InputSource;-import javax.xml.xpath.XPath;-import javax.xml.xpath.XPathConstants;-import javax.xml.xpath.XPathExpressionException;-import java.io.ByteArrayInputStream;import java.io.File;import java.io.FileInputStream;import java.io.InputStream;import java.nio.charset.StandardCharsets;-import java.util.HashMap;-import java.util.Map;import java.util.Properties;@@ -74,10 +64,9 @@ public abstract class ConfigSolr {public static ConfigSolr fromInputStream(SolrResourceLoader loader, InputStream is) {try {byte[] buf = IOUtils.toByteArray(is);- String originalXml = new String(buf, StandardCharsets.UTF_8);try (ByteArrayInputStream dup = new ByteArrayInputStream(buf)) {Config config = new Config(loader, null, new InputSource(dup), null, false);- return fromConfig(config, originalXml);+ return new ConfigSolrXml(config);}} catch (SolrException exc) {throw exc;@@ -89,12 +78,6 @@ public abstract class ConfigSolr {public static ConfigSolr fromSolrHome(SolrResourceLoader loader, String solrHome) {return fromFile(loader, new File(solrHome, SOLR_XML_FILE));}-- public static ConfigSolr fromConfig(Config config, String originalXml) {- boolean oldStyle = (config.getNode("solr/cores", false) != null);- return oldStyle ? new ConfigSolrXmlOld(config, originalXml)- : new ConfigSolrXml(config);- }public abstract CoresLocator getCoresLocator();@@ -106,32 +89,26 @@ public abstract class ConfigSolr {* @return core root directory*/public String getCoreRootDirectory() {- SolrResourceLoader loader = config.getResourceLoader();- String relativeDir = get(CfgProp.SOLR_COREROOTDIRECTORY, null);+ String relativeDir = getString(CfgProp.SOLR_COREROOTDIRECTORY, null);if (relativeDir != null)return loader.resolve(relativeDir);return loader.getInstanceDir();}- public PluginInfo getShardHandlerFactoryPluginInfo() {- Node node = config.getNode(getShardHandlerFactoryConfigPath(), false);- return (node == null) ? null : new PluginInfo(node, "shardHandlerFactory", false, true);- }-- protected abstract String getShardHandlerFactoryConfigPath();+ public abstract PluginInfo getShardHandlerFactoryPluginInfo();public String getZkHost() {String sysZkHost = System.getProperty("zkHost");if (sysZkHost != null)return sysZkHost;- return get(CfgProp.SOLR_ZKHOST, null);+ return getString(CfgProp.SOLR_ZKHOST, null);}public int getZkClientTimeout() {String sysProp = System.getProperty("zkClientTimeout");if (sysProp != null)return Integer.parseInt(sysProp);- return get(CfgProp.SOLR_ZKCLIENTTIMEOUT, DEFAULT_ZK_CLIENT_TIMEOUT);+ return getInt(CfgProp.SOLR_ZKCLIENTTIMEOUT, DEFAULT_ZK_CLIENT_TIMEOUT);}private static final int DEFAULT_ZK_CLIENT_TIMEOUT = 15000;@@ -150,120 +127,110 @@ public abstract class ConfigSolr {protected static final String DEFAULT_CORE_ADMIN_PATH = "/admin/cores";public String getSolrHostPort() {- return get(CfgProp.SOLR_HOSTPORT, null);+ return getString(CfgProp.SOLR_HOSTPORT, null);}public String getZkHostContext() {- return get(CfgProp.SOLR_HOSTCONTEXT, null);+ return getString(CfgProp.SOLR_HOSTCONTEXT, null);}public String getHost() {- return get(CfgProp.SOLR_HOST, null);+ return getString(CfgProp.SOLR_HOST, null);}public int getLeaderVoteWait() {- return get(CfgProp.SOLR_LEADERVOTEWAIT, DEFAULT_LEADER_VOTE_WAIT);+ return getInt(CfgProp.SOLR_LEADERVOTEWAIT, DEFAULT_LEADER_VOTE_WAIT);}public int getLeaderConflictResolveWait() {- return get(CfgProp.SOLR_LEADERCONFLICTRESOLVEWAIT, DEFAULT_LEADER_CONFLICT_RESOLVE_WAIT);+ return getInt(CfgProp.SOLR_LEADERCONFLICTRESOLVEWAIT, DEFAULT_LEADER_CONFLICT_RESOLVE_WAIT);}public int getAutoReplicaFailoverWaitAfterExpiration() {- return get(CfgProp.SOLR_AUTOREPLICAFAILOVERWAITAFTEREXPIRATION, DEFAULT_AUTO_REPLICA_FAILOVER_WAIT_AFTER_EXPIRATION);+ return getInt(CfgProp.SOLR_AUTOREPLICAFAILOVERWAITAFTEREXPIRATION, DEFAULT_AUTO_REPLICA_FAILOVER_WAIT_AFTER_EXPIRATION);}public int getAutoReplicaFailoverWorkLoopDelay() {- return get(CfgProp.SOLR_AUTOREPLICAFAILOVERWORKLOOPDELAY, DEFAULT_AUTO_REPLICA_FAILOVER_WORKLOOP_DELAY);+ return getInt(CfgProp.SOLR_AUTOREPLICAFAILOVERWORKLOOPDELAY, DEFAULT_AUTO_REPLICA_FAILOVER_WORKLOOP_DELAY);}public int getAutoReplicaFailoverBadNodeExpiration() {- return get(CfgProp.SOLR_AUTOREPLICAFAILOVERBADNODEEXPIRATION, DEFAULT_AUTO_REPLICA_FAILOVER_BAD_NODE_EXPIRATION);+ return getInt(CfgProp.SOLR_AUTOREPLICAFAILOVERBADNODEEXPIRATION, DEFAULT_AUTO_REPLICA_FAILOVER_BAD_NODE_EXPIRATION);}public boolean getGenericCoreNodeNames() {- return get(CfgProp.SOLR_GENERICCORENODENAMES, false);+ return getBoolean(CfgProp.SOLR_GENERICCORENODENAMES, false);}public int getDistributedConnectionTimeout() {- return get(CfgProp.SOLR_DISTRIBUPDATECONNTIMEOUT, DEFAULT_DISTRIBUPDATECONNTIMEOUT);+ return getInt(CfgProp.SOLR_DISTRIBUPDATECONNTIMEOUT, DEFAULT_DISTRIBUPDATECONNTIMEOUT);}public int getDistributedSocketTimeout() {- return get(CfgProp.SOLR_DISTRIBUPDATESOTIMEOUT, DEFAULT_DISTRIBUPDATESOTIMEOUT);+ return getInt(CfgProp.SOLR_DISTRIBUPDATESOTIMEOUT, DEFAULT_DISTRIBUPDATESOTIMEOUT);}public int getMaxUpdateConnections() {- return get(CfgProp.SOLR_MAXUPDATECONNECTIONS, 10000);+ return getInt(CfgProp.SOLR_MAXUPDATECONNECTIONS, 10000);}public int getMaxUpdateConnectionsPerHost() {- return get(CfgProp.SOLR_MAXUPDATECONNECTIONSPERHOST, 100);+ return getInt(CfgProp.SOLR_MAXUPDATECONNECTIONSPERHOST, 100);}public int getCoreLoadThreadCount() {- return get(ConfigSolr.CfgProp.SOLR_CORELOADTHREADS, DEFAULT_CORE_LOAD_THREADS);+ return getInt(ConfigSolr.CfgProp.SOLR_CORELOADTHREADS, DEFAULT_CORE_LOAD_THREADS);}public String getSharedLibDirectory() {- return get(ConfigSolr.CfgProp.SOLR_SHAREDLIB , null);- }-- public String getDefaultCoreName() {- return get(CfgProp.SOLR_CORES_DEFAULT_CORE_NAME, null);- }-- public abstract boolean isPersistent();-- public String getAdminPath() {- return get(CfgProp.SOLR_ADMINPATH, DEFAULT_CORE_ADMIN_PATH);+ return getString(ConfigSolr.CfgProp.SOLR_SHAREDLIB, null);}public String getCoreAdminHandlerClass() {- return get(CfgProp.SOLR_ADMINHANDLER, "org.apache.solr.handler.admin.CoreAdminHandler");+ return getString(CfgProp.SOLR_ADMINHANDLER, "org.apache.solr.handler.admin.CoreAdminHandler");}public String getZkCredentialsProviderClass() {- return get(CfgProp.SOLR_ZKCREDENTIALSPROVIDER, null);+ return getString(CfgProp.SOLR_ZKCREDENTIALSPROVIDER, null);}public String getZkACLProviderClass() {- return get(CfgProp.SOLR_ZKACLPROVIDER, null);+ return getString(CfgProp.SOLR_ZKACLPROVIDER, null);}public String getCollectionsHandlerClass() {- return get(CfgProp.SOLR_COLLECTIONSHANDLER, "org.apache.solr.handler.admin.CollectionsHandler");+ return getString(CfgProp.SOLR_COLLECTIONSHANDLER, "org.apache.solr.handler.admin.CollectionsHandler");}public String getInfoHandlerClass() {- return get(CfgProp.SOLR_INFOHANDLER, "org.apache.solr.handler.admin.InfoHandler");+ return getString(CfgProp.SOLR_INFOHANDLER, "org.apache.solr.handler.admin.InfoHandler");}public boolean hasSchemaCache() {- return get(ConfigSolr.CfgProp.SOLR_SHARESCHEMA, false);+ return getBoolean(ConfigSolr.CfgProp.SOLR_SHARESCHEMA, false);}public String getManagementPath() {- return get(CfgProp.SOLR_MANAGEMENTPATH, null);+ return getString(CfgProp.SOLR_MANAGEMENTPATH, null);}public String getConfigSetBaseDirectory() {- return get(CfgProp.SOLR_CONFIGSETBASEDIR, "configsets");+ return getString(CfgProp.SOLR_CONFIGSETBASEDIR, "configsets");}public LogWatcherConfig getLogWatcherConfig() {- String loggingClass = get(CfgProp.SOLR_LOGGING_CLASS, null);- String loggingWatcherThreshold = get(CfgProp.SOLR_LOGGING_WATCHER_THRESHOLD, null);+ String loggingClass = getString(CfgProp.SOLR_LOGGING_CLASS, null);+ String loggingWatcherThreshold = getString(CfgProp.SOLR_LOGGING_WATCHER_THRESHOLD, null);return new LogWatcherConfig(- get(CfgProp.SOLR_LOGGING_ENABLED, true),+ getBoolean(CfgProp.SOLR_LOGGING_ENABLED, true),loggingClass,loggingWatcherThreshold,- get(CfgProp.SOLR_LOGGING_WATCHER_SIZE, 50)+ getInt(CfgProp.SOLR_LOGGING_WATCHER_SIZE, 50));}public int getTransientCacheSize() {- return get(CfgProp.SOLR_TRANSIENTCACHESIZE, Integer.MAX_VALUE);+ return getInt(CfgProp.SOLR_TRANSIENTCACHESIZE, Integer.MAX_VALUE);}public ConfigSetService createCoreConfigService(SolrResourceLoader loader, ZkController zkController) {@@ -275,7 +242,7 @@ public abstract class ConfigSolr {}// Ugly for now, but we'll at least be able to centralize all of the differences between 4x and 5x.- protected static enum CfgProp {+ public static enum CfgProp {SOLR_ADMINHANDLER,SOLR_COLLECTIONSHANDLER,SOLR_CORELOADTHREADS,@@ -309,59 +276,44 @@ public abstract class ConfigSolr {SOLR_ZKCREDENTIALSPROVIDER,SOLR_ZKACLPROVIDER,-- //TODO: Remove all of these elements for 5.0- SOLR_PERSISTENT,- SOLR_CORES_DEFAULT_CORE_NAME,- SOLR_ADMINPATH+}- protected Config config;- protected Map<CfgProp, Object> propMap = new HashMap<>();+ protected final SolrResourceLoader loader;+ protected final Properties solrProperties;- public ConfigSolr(Config config) {- this.config = config;- config.substituteProperties();+ public ConfigSolr(SolrResourceLoader loader, Properties solrProperties) {+ this.loader = loader;+ this.solrProperties = solrProperties;}- // for extension & testing.- protected ConfigSolr() {-+ public ConfigSolr(SolrResourceLoader loader) {+ this(loader, new Properties());}-- public Config getConfig() {- return config;++ protected abstract String getProperty(CfgProp key);++ private String getString(CfgProp key, String defaultValue) {+ String v = getProperty(key);+ return v == null ? defaultValue : v;}- @SuppressWarnings("unchecked")- public <T> T get(CfgProp key, T defaultValue) {- if (propMap.containsKey(key) && propMap.get(key) != null) {- return (T) propMap.get(key);- }- return defaultValue;+ private int getInt(CfgProp key, int defaultValue) {+ String v = getProperty(key);+ return v == null ? defaultValue : Integer.parseInt(v);}- public Properties getSolrProperties(String path) {- try {- return readProperties(((NodeList) config.evaluate(- path, XPathConstants.NODESET)).item(0));- } catch (Exception e) {- SolrException.log(log, null, e);- }- return null;+ private boolean getBoolean(CfgProp key, boolean defaultValue) {+ String v = getProperty(key);+ return v == null ? defaultValue : Boolean.parseBoolean(v);+ }+ public Properties getSolrProperties() {+ return solrProperties;}-- protected Properties readProperties(Node node) throws XPathExpressionException {- XPath xpath = config.getXPath();- NodeList props = (NodeList) xpath.evaluate("property", node, XPathConstants.NODESET);- Properties properties = new Properties();- for (int i = 0; i < props.getLength(); i++) {- Node prop = props.item(i);- properties.setProperty(DOMUtil.getAttr(prop, "name"),- PropertiesUtil.substituteProperty(DOMUtil.getAttr(prop, "value"), null));- }- return properties;++ public SolrResourceLoader getSolrResourceLoader() {+ return loader;}}diff --git a/solr/core/src/java/org/apache/solr/core/ConfigSolrXml.java b/solr/core/src/java/org/apache/solr/core/ConfigSolrXml.javaindex f3ea1f25043..0ed08558626 100644--- a/solr/core/src/java/org/apache/solr/core/ConfigSolrXml.java+++ b/solr/core/src/java/org/apache/solr/core/ConfigSolrXml.java@@ -17,24 +17,26 @@ package org.apache.solr.core;* limitations under the License.*/+import com.google.common.base.Function;+import com.google.common.base.Functions;import org.apache.solr.common.SolrException;import org.apache.solr.common.util.NamedList;import org.apache.solr.util.DOMUtil;--import com.google.common.base.Function;-import com.google.common.base.Functions;--import org.w3c.dom.Node;-import org.w3c.dom.NodeList;-+import org.apache.solr.util.PropertiesUtil;import org.slf4j.Logger;import org.slf4j.LoggerFactory;+import org.w3c.dom.Node;+import org.w3c.dom.NodeList;-import java.io.IOException;-import java.util.List;+import javax.xml.xpath.XPath;+import javax.xml.xpath.XPathConstants;+import javax.xml.xpath.XPathExpressionException;import java.util.ArrayList;-import java.util.Map;+import java.util.HashMap;+import java.util.List;import java.util.Locale;+import java.util.Map;+import java.util.Properties;/**@@ -45,51 +47,28 @@ public class ConfigSolrXml extends ConfigSolr {protected static Logger log = LoggerFactory.getLogger(ConfigSolrXml.class);private final CoresLocator coresLocator;+ private final Config config;+ private final Map<CfgProp, Object> propMap = new HashMap<>();public ConfigSolrXml(Config config) {- super(config);- try {- checkForIllegalConfig();- fillPropMap();- coresLocator = new CorePropertiesLocator(getCoreRootDirectory());- } catch (IOException e) {- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);- }+ super(config.getResourceLoader(), loadProperties(config));+ this.config = config;+ this.config.substituteProperties();+ checkForIllegalConfig();+ fillPropMap();+ coresLocator = new CorePropertiesLocator(getCoreRootDirectory());}- private void checkForIllegalConfig() throws IOException {+ private void checkForIllegalConfig() {- // Do sanity checks - we don't want to find old style configfailIfFound("solr/@coreLoadThreads");failIfFound("solr/@persistent");failIfFound("solr/@sharedLib");failIfFound("solr/@zkHost");- failIfFound("solr/logging/@class");- failIfFound("solr/logging/@enabled");- failIfFound("solr/logging/watcher/@size");- failIfFound("solr/logging/watcher/@threshold");-- failIfFound("solr/cores/@adminHandler");- failIfFound("solr/cores/@distribUpdateConnTimeout");- failIfFound("solr/cores/@distribUpdateSoTimeout");- failIfFound("solr/cores/@host");- failIfFound("solr/cores/@hostContext");- failIfFound("solr/cores/@hostPort");- failIfFound("solr/cores/@leaderVoteWait");- failIfFound("solr/cores/@leaderConflictResolveWait");- failIfFound("solr/cores/@genericCoreNodeNames");- failIfFound("solr/cores/@managementPath");- failIfFound("solr/cores/@shareSchema");- failIfFound("solr/cores/@transientCacheSize");- failIfFound("solr/cores/@zkClientTimeout");-- // These have no counterpart in 5.0, asking for any of these in Solr 5.0- // will result in an error being- // thrown.- failIfFound("solr/cores/@defaultCoreName");+ failIfFound("solr/cores");+failIfFound("solr/@persistent");- failIfFound("solr/cores/@adminPath");}@@ -97,7 +76,32 @@ public class ConfigSolrXml extends ConfigSolr {if (config.getVal(xPath, false) != null) {throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Should not have found " + xPath +- " solr.xml may be a mix of old and new style formats.");+ "\n. Please upgrade your solr.xml: https://cwiki.apache.org/confluence/display/solr/Format+of+solr.xml");+ }+ }++ protected String getProperty(CfgProp key) {+ if (!propMap.containsKey(key) || propMap.get(key) == null)+ return null;+ return propMap.get(key).toString();+ }++ private static Properties loadProperties(Config config) {+ try {+ Node node = ((NodeList) config.evaluate("solr", XPathConstants.NODESET)).item(0);+ XPath xpath = config.getXPath();+ NodeList props = (NodeList) xpath.evaluate("property", node, XPathConstants.NODESET);+ Properties properties = new Properties();+ for (int i = 0; i < props.getLength(); i++) {+ Node prop = props.item(i);+ properties.setProperty(DOMUtil.getAttr(prop, "name"),+ PropertiesUtil.substituteProperty(DOMUtil.getAttr(prop, "value"), null));+ }+ return properties;+ }+ catch (XPathExpressionException e) {+ log.warn("Error parsing solr.xml: " + e.getMessage());+ return null;}}@@ -247,24 +251,9 @@ public class ConfigSolrXml extends ConfigSolr {}}- @Override- public String getDefaultCoreName() {- return "collection1";- }-- @Override- public boolean isPersistent() {- return true;- }-- @Override- protected String getShardHandlerFactoryConfigPath() {- return "solr/shardHandlerFactory";- }-- @Override- public String getAdminPath() {- return DEFAULT_CORE_ADMIN_PATH;+ public PluginInfo getShardHandlerFactoryPluginInfo() {+ Node node = config.getNode("solr/shardHandlerFactory", false);+ return (node == null) ? null : new PluginInfo(node, "shardHandlerFactory", false, true);}@Overridediff --git a/solr/core/src/java/org/apache/solr/core/ConfigSolrXmlOld.java b/solr/core/src/java/org/apache/solr/core/ConfigSolrXmlOld.javadeleted file mode 100644index 6d57f31ff74..00000000000--- a/solr/core/src/java/org/apache/solr/core/ConfigSolrXmlOld.java+++ /dev/null@@ -1,284 +0,0 @@-package org.apache.solr.core;--/*- * 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.- */--import javax.xml.xpath.XPathConstants;-import javax.xml.xpath.XPathExpressionException;-import java.io.File;-import java.io.IOException;-import java.util.ArrayList;-import java.util.HashMap;-import java.util.HashSet;-import java.util.List;-import java.util.Locale;-import java.util.Map;-import java.util.Properties;-import java.util.Set;--import org.apache.commons.lang.StringUtils;-import org.apache.solr.common.SolrException;-import org.apache.solr.util.DOMUtil;-import org.apache.solr.util.PropertiesUtil;-import org.slf4j.Logger;-import org.slf4j.LoggerFactory;-import org.w3c.dom.Node;-import org.w3c.dom.NodeList;---/**- *- */-public class ConfigSolrXmlOld extends ConfigSolr {-- protected static Logger log = LoggerFactory.getLogger(ConfigSolrXmlOld.class);-- private NodeList coreNodes = null;-- private final CoresLocator persistor;-- public static final String DEFAULT_DEFAULT_CORE_NAME = "collection1";-- @Override- protected String getShardHandlerFactoryConfigPath() {- return "solr/cores/shardHandlerFactory";- }-- public ConfigSolrXmlOld(Config config, String originalXML) {- super(config);- try {- checkForIllegalConfig();- fillPropMap();- initCoreList();- this.persistor = isPersistent() ? new SolrXMLCoresLocator(originalXML, this)- : new SolrXMLCoresLocator.NonPersistingLocator(originalXML, this);- }- catch (IOException e) {- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);- }- }-- @Override- public CoresLocator getCoresLocator() {- return this.persistor;- }-- private void checkForIllegalConfig() throws IOException {- // Do sanity checks - we don't want to find new style- // config- failIfFound("solr/str[@name='adminHandler']");- failIfFound("solr/int[@name='coreLoadThreads']");- failIfFound("solr/str[@name='coreRootDirectory']");- failIfFound("solr/solrcloud/int[@name='distribUpdateConnTimeout']");- failIfFound("solr/solrcloud/int[@name='distribUpdateSoTimeout']");- failIfFound("solr/solrcloud/str[@name='host']");- failIfFound("solr/solrcloud/str[@name='hostContext']");- failIfFound("solr/solrcloud/int[@name='hostPort']");- failIfFound("solr/solrcloud/int[@name='leaderVoteWait']");- failIfFound("solr/solrcloud/int[@name='genericCoreNodeNames']");- failIfFound("solr/str[@name='managementPath']");- failIfFound("solr/str[@name='sharedLib']");- failIfFound("solr/str[@name='shareSchema']");- failIfFound("solr/int[@name='transientCacheSize']");- failIfFound("solr/solrcloud/int[@name='zkClientTimeout']");- failIfFound("solr/solrcloud/int[@name='zkHost']");-- failIfFound("solr/logging/str[@name='class']");- failIfFound("solr/logging/str[@name='enabled']");-- failIfFound("solr/logging/watcher/int[@name='size']");- failIfFound("solr/logging/watcher/int[@name='threshold']");- }-- private void failIfFound(String xPath) {-- if (config.getVal(xPath, false) != null) {- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Should not have found " + xPath +- " solr.xml may be a mix of old and new style formats.");- }- }-- @Override- public boolean isPersistent() {- return config.getBool("solr/@persistent", false);- }-- @Override- public String getDefaultCoreName() {- return get(CfgProp.SOLR_CORES_DEFAULT_CORE_NAME, DEFAULT_DEFAULT_CORE_NAME);- }-- private void fillPropMap() {- storeConfigPropertyAsInt(CfgProp.SOLR_CORELOADTHREADS, "solr/@coreLoadThreads");- storeConfigPropertyAsString(CfgProp.SOLR_SHAREDLIB, "solr/@sharedLib");- storeConfigPropertyAsString(CfgProp.SOLR_ZKHOST, "solr/@zkHost");- storeConfigPropertyAsString(CfgProp.SOLR_LOGGING_CLASS, "solr/logging/@class");- storeConfigPropertyAsBoolean(CfgProp.SOLR_LOGGING_ENABLED, "solr/logging/@enabled");- storeConfigPropertyAsInt(CfgProp.SOLR_LOGGING_WATCHER_SIZE, "solr/logging/watcher/@size");- storeConfigPropertyAsString(CfgProp.SOLR_LOGGING_WATCHER_THRESHOLD, "solr/logging/watcher/@threshold");- storeConfigPropertyAsString(CfgProp.SOLR_ADMINHANDLER, "solr/cores/@adminHandler");- storeConfigPropertyAsString(CfgProp.SOLR_COLLECTIONSHANDLER, "solr/cores/@collectionsHandler");- storeConfigPropertyAsString(CfgProp.SOLR_INFOHANDLER, "solr/cores/@infoHandler");- storeConfigPropertyAsInt(CfgProp.SOLR_DISTRIBUPDATECONNTIMEOUT, "solr/cores/@distribUpdateConnTimeout");- storeConfigPropertyAsInt(CfgProp.SOLR_DISTRIBUPDATESOTIMEOUT, "solr/cores/@distribUpdateSoTimeout");- storeConfigPropertyAsInt(CfgProp.SOLR_MAXUPDATECONNECTIONS, "solr/cores/@maxUpdateConnections");- storeConfigPropertyAsInt(CfgProp.SOLR_MAXUPDATECONNECTIONSPERHOST, "solr/cores/@maxUpdateConnectionsPerHost");- storeConfigPropertyAsString(CfgProp.SOLR_HOST, "solr/cores/@host");- storeConfigPropertyAsString(CfgProp.SOLR_HOSTCONTEXT, "solr/cores/@hostContext");- storeConfigPropertyAsString(CfgProp.SOLR_HOSTPORT, "solr/cores/@hostPort");- storeConfigPropertyAsInt(CfgProp.SOLR_LEADERVOTEWAIT, "solr/cores/@leaderVoteWait");- storeConfigPropertyAsBoolean(CfgProp.SOLR_GENERICCORENODENAMES, "solr/cores/@genericCoreNodeNames");- storeConfigPropertyAsBoolean(CfgProp.SOLR_AUTOREPLICAFAILOVERBADNODEEXPIRATION, "solr/cores/@autoReplicaFailoverBadNodeExpiration");- storeConfigPropertyAsBoolean(CfgProp.SOLR_AUTOREPLICAFAILOVERWAITAFTEREXPIRATION, "solr/cores/@autoReplicaFailoverWaitAfterExpiration");- storeConfigPropertyAsBoolean(CfgProp.SOLR_AUTOREPLICAFAILOVERWORKLOOPDELAY, "solr/cores/@autoReplicaFailoverWorkLoopDelay");- storeConfigPropertyAsString(CfgProp.SOLR_ZKACLPROVIDER, "solr/cores/@zkACLProvider");- storeConfigPropertyAsString(CfgProp.SOLR_ZKCREDENTIALSPROVIDER, "solr/cores/@zkCredentialsProvider");- storeConfigPropertyAsString(CfgProp.SOLR_MANAGEMENTPATH, "solr/cores/@managementPath");- storeConfigPropertyAsBoolean(CfgProp.SOLR_SHARESCHEMA, "solr/cores/@shareSchema");- storeConfigPropertyAsInt(CfgProp.SOLR_TRANSIENTCACHESIZE, "solr/cores/@transientCacheSize");- storeConfigPropertyAsInt(CfgProp.SOLR_ZKCLIENTTIMEOUT, "solr/cores/@zkClientTimeout");- storeConfigPropertyAsString(CfgProp.SOLR_CONFIGSETBASEDIR, "solr/cores/@configSetBaseDir");-- // These have no counterpart in 5.0, asking, for any of these in Solr 5.0- // will result in an error being- // thrown.- storeConfigPropertyAsString(CfgProp.SOLR_CORES_DEFAULT_CORE_NAME, "solr/cores/@defaultCoreName");- storeConfigPropertyAsString(CfgProp.SOLR_PERSISTENT, "solr/@persistent");- storeConfigPropertyAsString(CfgProp.SOLR_ADMINPATH, "solr/cores/@adminPath");- }-- private void storeConfigPropertyAsInt(CfgProp key, String xmlPath) {- String valueAsString = config.getVal(xmlPath, false);- if (StringUtils.isNotBlank(valueAsString)) {- propMap.put(key, Integer.parseInt(valueAsString));- } else {- propMap.put(key, null);- }- }-- private void storeConfigPropertyAsBoolean(CfgProp key, String xmlPath) {- String valueAsString = config.getVal(xmlPath, false);- if (StringUtils.isNotBlank(valueAsString)) {- propMap.put(key, Boolean.parseBoolean(valueAsString));- } else {- propMap.put(key, null);- }- }-- private void storeConfigPropertyAsString(CfgProp key, String xmlPath) {- propMap.put(key, config.getVal(xmlPath, false));- }-- private void initCoreList() throws IOException {-- coreNodes = (NodeList) config.evaluate("solr/cores/core",- XPathConstants.NODESET);- // Check a couple of error conditions- Set<String> names = new HashSet<>(); // for duplicate names- Map<String,String> dirs = new HashMap<>(); // for duplicate- // data dirs.-- for (int idx = 0; idx < coreNodes.getLength(); ++idx) {- Node node = coreNodes.item(idx);- String name = DOMUtil.getAttr(node, CoreDescriptor.CORE_NAME, null);-- String dataDir = DOMUtil.getAttr(node, CoreDescriptor.CORE_DATADIR, null);- if (name != null) {- if (!names.contains(name)) {- names.add(name);- } else {- String msg = String.format(Locale.ROOT,- "More than one core defined for core named %s", name);- log.error(msg);- }- }-- String instDir = DOMUtil.getAttr(node, CoreDescriptor.CORE_INSTDIR, null);-- if (dataDir != null) {- String absData = null;- File dataFile = new File(dataDir);- if (dataFile.isAbsolute()) {- absData = dataFile.getCanonicalPath();- } else if (instDir != null) {- File instFile = new File(instDir);- absData = new File(instFile, dataDir).getCanonicalPath();- }- if (absData != null) {- if (!dirs.containsKey(absData)) {- dirs.put(absData, name);- } else {- String msg = String- .format(- Locale.ROOT,- "More than one core points to data dir %s. They are in %s and %s",- absData, dirs.get(absData), name);- log.warn(msg);- }- }- }- }-- }-- public List<String> getAllCoreNames() {- List<String> ret = new ArrayList<>();-- synchronized (coreNodes) {- for (int idx = 0; idx < coreNodes.getLength(); ++idx) {- Node node = coreNodes.item(idx);- ret.add(DOMUtil.getAttr(node, CoreDescriptor.CORE_NAME, null));- }- }-- return ret;- }-- public String getProperty(String coreName, String property, String defaultVal) {-- synchronized (coreNodes) {- for (int idx = 0; idx < coreNodes.getLength(); ++idx) {- Node node = coreNodes.item(idx);- if (coreName.equals(DOMUtil.getAttr(node, CoreDescriptor.CORE_NAME,- null))) {- String propVal = DOMUtil.getAttr(node, property);- if (propVal == null)- propVal = defaultVal;- return propVal;- }- }- }- return defaultVal;-- }-- public Properties getCoreProperties(String coreName) {- synchronized (coreNodes) {- for (int idx = 0; idx < coreNodes.getLength(); idx++) {- Node node = coreNodes.item(idx);- if (coreName.equals(DOMUtil.getAttr(node, CoreDescriptor.CORE_NAME, null))) {- try {- return readProperties(node);- } catch (XPathExpressionException e) {- SolrException.log(log, e);- }- }- }- }- return new Properties();- }-}diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.javaindex 5b9003e6590..949f9a7c1bd 100644--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java@@ -17,21 +17,8 @@package org.apache.solr.core;-import static com.google.common.base.Preconditions.checkNotNull;--import java.io.File;-import java.util.ArrayList;-import java.util.Collection;-import java.util.HashMap;-import java.util.List;-import java.util.Locale;-import java.util.Map;-import java.util.Properties;-import java.util.concurrent.Callable;-import java.util.concurrent.ConcurrentHashMap;-import java.util.concurrent.ExecutorService;-import java.util.concurrent.Executors;-+import com.google.common.collect.ImmutableMap;+import com.google.common.collect.Maps;import org.apache.solr.cloud.ZkController;import org.apache.solr.cloud.ZkSolrResourceLoader;import org.apache.solr.common.SolrException;@@ -51,8 +38,20 @@ import org.apache.zookeeper.KeeperException;import org.slf4j.Logger;import org.slf4j.LoggerFactory;-import com.google.common.collect.ImmutableMap;-import com.google.common.collect.Maps;+import java.io.File;+import java.util.ArrayList;+import java.util.Collection;+import java.util.HashMap;+import java.util.List;+import java.util.Locale;+import java.util.Map;+import java.util.Properties;+import java.util.concurrent.Callable;+import java.util.concurrent.ConcurrentHashMap;+import java.util.concurrent.ExecutorService;+import java.util.concurrent.Executors;++import static com.google.common.base.Preconditions.checkNotNull;/**@@ -102,9 +101,14 @@ public class CoreContainer {protected final CoresLocator coresLocator;private String hostName;+private final JarRepository jarRepository = new JarRepository(this);-- private Map<String ,SolrRequestHandler> containerHandlers = new HashMap<>();++ public static final String CORES_HANDLER_PATH = "/admin/cores";+ public static final String COLLECTIONS_HANDLER_PATH = "/admin/collections";+ public static final String INFO_HANDLER_PATH = "/admin/info";++ private Map<String, SolrRequestHandler> containerHandlers = new HashMap<>();public SolrRequestHandler getRequestHandler(String path) {return RequestHandlerBase.getRequestHandler(path, containerHandlers);@@ -112,7 +116,6 @@ public class CoreContainer {public Map<String, SolrRequestHandler> getRequestHandlers(){return this.containerHandlers;-}// private ClientConnectionManager clientConnectionManager = new PoolingClientConnectionManager();@@ -137,7 +140,7 @@ public class CoreContainer {* @see #load()*/public CoreContainer(SolrResourceLoader loader) {- this(loader, ConfigSolr.fromSolrHome(loader, loader.getInstanceDir()));+ this(ConfigSolr.fromSolrHome(loader, loader.getInstanceDir()));}/**@@ -154,19 +157,15 @@ public class CoreContainer {* Create a new CoreContainer using the given SolrResourceLoader,* configuration and CoresLocator. The container's cores are* not loaded.- * @param loader the SolrResourceLoader* @param config a ConfigSolr representation of this container's configuration* @see #load()*/- public CoreContainer(SolrResourceLoader loader, ConfigSolr config) {- this.loader = checkNotNull(loader);- this.solrHome = loader.getInstanceDir();- this.cfg = checkNotNull(config);- this.coresLocator = config.getCoresLocator();+ public CoreContainer(ConfigSolr config) {+ this(config, config.getCoresLocator());}- public CoreContainer(SolrResourceLoader loader, ConfigSolr config, CoresLocator locator) {- this.loader = checkNotNull(loader);+ public CoreContainer(ConfigSolr config, CoresLocator locator) {+ this.loader = config.getSolrResourceLoader();this.solrHome = loader.getInstanceDir();this.cfg = checkNotNull(config);this.coresLocator = locator;@@ -194,7 +193,7 @@ public class CoreContainer {*/public static CoreContainer createAndLoad(String solrHome, File configFile) {SolrResourceLoader loader = new SolrResourceLoader(solrHome);- CoreContainer cc = new CoreContainer(loader, ConfigSolr.fromFile(loader, configFile));+ CoreContainer cc = new CoreContainer(ConfigSolr.fromFile(loader, configFile));try {cc.load();} catch (Exception e) {@@ -243,15 +242,15 @@ public class CoreContainer {zkSys.initZooKeeper(this, solrHome, cfg);collectionsHandler = createHandler(cfg.getCollectionsHandlerClass(), CollectionsHandler.class);- containerHandlers.put("/admin/collections" , collectionsHandler);+ containerHandlers.put(COLLECTIONS_HANDLER_PATH, collectionsHandler);infoHandler = createHandler(cfg.getInfoHandlerClass(), InfoHandler.class);- containerHandlers.put("/admin/info" , infoHandler);+ containerHandlers.put(INFO_HANDLER_PATH, infoHandler);coreAdminHandler = createHandler(cfg.getCoreAdminHandlerClass(), CoreAdminHandler.class);- containerHandlers.put(cfg.getAdminPath() , coreAdminHandler);+ containerHandlers.put(CORES_HANDLER_PATH, coreAdminHandler);coreConfigService = cfg.createCoreConfigService(loader, zkSys.getZkController());- containerProperties = cfg.getSolrProperties("solr");+ containerProperties = cfg.getSolrProperties();// setup executor to load cores in parallel// do not limit the size of the executor in zk mode since cores may try and wait for each other.@@ -599,8 +598,6 @@ public class CoreContainer {*/public void reload(String name) {- name = checkDefault(name);-SolrCore core = solrCores.getCoreFromAnyList(name, false);if (core == null)throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "No such core: " + name );@@ -623,11 +620,6 @@ public class CoreContainer {}- //5.0 remove all checkDefaults?- private String checkDefault(String name) {- return (null == name || name.isEmpty()) ? getDefaultCoreName() : name;- }-/*** Swaps two SolrCore descriptors.*/@@ -635,8 +627,6 @@ public class CoreContainer {if( n0 == null || n1 == null ) {throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Can not swap unnamed cores." );}- n0 = checkDefault(n0);- n1 = checkDefault(n1);solrCores.swap(n0, n1);coresLocator.swap(this, solrCores.getCoreDescriptor(n0), solrCores.getCoreDescriptor(n1));@@ -662,8 +652,6 @@ public class CoreContainer {*/public void unload(String name, boolean deleteIndexDir, boolean deleteDataDir, boolean deleteInstanceDir) {- name = checkDefault(name);-// check for core-init errors firstCoreLoadFailure loadFailure = coreInitFailures.remove(name);if (loadFailure != null) {@@ -715,7 +703,6 @@ public class CoreContainer {try (SolrCore core = getCore(name)) {if (core != null) {registerCore(toName, core, true);- name = checkDefault(name);SolrCore old = solrCores.remove(name);coresLocator.rename(this, old.getCoreDescriptor(), core.getCoreDescriptor());}@@ -753,8 +740,6 @@ public class CoreContainer {*/public SolrCore getCore(String name) {- name = checkDefault(name);-// Do this in two phases since we don't want to lock access to the cores over a load.SolrCore core = solrCores.getCoreFromAnyList(name, true);@@ -821,26 +806,6 @@ public class CoreContainer {return infoHandler;}- // ---------------- Multicore self related methods ----------------- /**- * the default core name, or null if there is no default core name- */- public String getDefaultCoreName() {- return cfg.getDefaultCoreName();- }-- // all of the following properties aren't synchronized- // but this should be OK since they normally won't be changed rapidly- @Deprecated- public boolean isPersistent() {- return cfg.isPersistent();- }-- public String getAdminPath() {- return cfg.getAdminPath();- }-public String getHostName() {return this.hostName;}diff --git a/solr/core/src/java/org/apache/solr/core/SolrXMLCoresLocator.java b/solr/core/src/java/org/apache/solr/core/SolrXMLCoresLocator.javadeleted file mode 100644index bd7052341f4..00000000000--- a/solr/core/src/java/org/apache/solr/core/SolrXMLCoresLocator.java+++ /dev/null@@ -1,240 +0,0 @@-package org.apache.solr.core;--/*- * 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.- */--import com.google.common.collect.ImmutableList;-import org.apache.commons.io.IOUtils;-import org.apache.commons.lang.StringUtils;-import org.slf4j.Logger;-import org.slf4j.LoggerFactory;--import java.io.File;-import java.io.FileOutputStream;-import java.io.IOException;-import java.io.OutputStreamWriter;-import java.io.Writer;-import java.nio.charset.StandardCharsets;-import java.util.ArrayList;-import java.util.Arrays;-import java.util.List;-import java.util.Map;-import java.util.Properties;-import java.util.regex.Matcher;-import java.util.regex.Pattern;--/**- * Writes any changes in core definitions to this instance's solr.xml- */-public class SolrXMLCoresLocator implements CoresLocator {-- private static final Logger logger = LoggerFactory.getLogger(SolrXMLCoresLocator.class);-- private final String solrXmlTemplate;- private final ConfigSolrXmlOld cfg;-- /** Core name to use if a core definition has no name */- public static final String DEFAULT_CORE_NAME = "collection1";-- /**- * Create a new SolrXMLCoresLocator- * @param originalXML the original content of the solr.xml file- * @param cfg the CoreContainer's config object- */- public SolrXMLCoresLocator(String originalXML, ConfigSolrXmlOld cfg) {- this.solrXmlTemplate = buildTemplate(originalXML);- this.cfg = cfg;- }-- private static Pattern POPULATED_CORES_TAG- = Pattern.compile("^(.*<cores[^>]*>)(.*)(</cores>.*)$", Pattern.DOTALL);- private static Pattern EMPTY_CORES_TAG- = Pattern.compile("^(.*<cores[^>]*)/>(.*)$", Pattern.DOTALL);-- private static Pattern SHARD_HANDLER_TAG- = Pattern.compile("(<shardHandlerFactory[^>]*>.*</shardHandlerFactory>)|(<shardHandlerFactory[^>]*/>)",- Pattern.DOTALL);-- private static String CORES_PLACEHOLDER = "{{CORES_PLACEHOLDER}}";-- // Package-private for testing- // We replace the existing <cores></cores> contents with a template pattern- // that we can later replace with the up-to-date core definitions. We also- // need to extract the <shardHandlerFactory> section, as, annoyingly, it's- // kept inside <cores/>.- static String buildTemplate(String originalXML) {-- String shardHandlerConfig = "";- Matcher shfMatcher = SHARD_HANDLER_TAG.matcher(originalXML);- if (shfMatcher.find()) {- shardHandlerConfig = shfMatcher.group(0);- }-- Matcher popMatcher = POPULATED_CORES_TAG.matcher(originalXML);- if (popMatcher.matches()) {- return new StringBuilder(popMatcher.group(1))- .append(CORES_PLACEHOLDER).append(shardHandlerConfig).append(popMatcher.group(3)).toString();- }-- // Self-closing <cores/> tag gets expanded to <cores></cores>- Matcher emptyMatcher = EMPTY_CORES_TAG.matcher(originalXML);- if (emptyMatcher.matches())- return new StringBuilder(emptyMatcher.group(1))- .append(">").append(CORES_PLACEHOLDER).append("</cores>")- .append(emptyMatcher.group(2)).toString();-- // If there's no <cores> tag at all, add one at the end of the file- return originalXML.replace("</solr>", "<cores>" + CORES_PLACEHOLDER + "</cores></solr>");- }-- // protected access for testing- protected String buildSolrXML(List<CoreDescriptor> cds) {- StringBuilder builder = new StringBuilder();- for (CoreDescriptor cd : cds) {- builder.append(buildCoreTag(cd));- }- return solrXmlTemplate.replace(CORES_PLACEHOLDER, builder.toString());- }-- public static final String NEWLINE = System.getProperty("line.separator");- public static final String INDENT = " ";-- /**- * Serialize a coredescriptor as a String containing an XML <core> tag.- * @param cd the CoreDescriptor- * @return an XML representation of the CoreDescriptor- */- protected static String buildCoreTag(CoreDescriptor cd) {-- StringBuilder builder = new StringBuilder(NEWLINE).append(INDENT).append("<core");- for (Map.Entry<Object, Object> entry : cd.getPersistableStandardProperties().entrySet()) {- builder.append(" ").append(entry.getKey()).append("=\"").append(entry.getValue()).append("\"");- }-- Properties userProperties = cd.getPersistableUserProperties();- if (userProperties.isEmpty()) {- return builder.append("/>").append(NEWLINE).toString();- }-- builder.append(">").append(NEWLINE);- for (Map.Entry<Object, Object> entry : userProperties.entrySet()) {- builder.append(INDENT).append(INDENT)- .append("<property name=\"").append(entry.getKey()).append("\" value=\"")- .append(entry.getValue()).append("\"/>").append(NEWLINE);- }-- return builder.append("</core>").append(NEWLINE).toString();-- }-- @Override- public synchronized final void persist(CoreContainer cc, CoreDescriptor... coreDescriptors) {- List<CoreDescriptor> cds = new ArrayList<>(cc.getCoreDescriptors().size() + coreDescriptors.length);-- cds.addAll(cc.getCoreDescriptors());- cds.addAll(Arrays.asList(coreDescriptors));-- doPersist(buildSolrXML(cds));- }-- protected void doPersist(String xml) {- File file = new File(cfg.config.getResourceLoader().getInstanceDir(), ConfigSolr.SOLR_XML_FILE);- Writer writer = null;- FileOutputStream fos = null;- try {- fos = new FileOutputStream(file);- writer = new OutputStreamWriter(fos, StandardCharsets.UTF_8);- writer.write(xml);- writer.close();- logger.info("Persisted core descriptions to {}", file.getAbsolutePath());- } catch (IOException e) {- logger.error("Couldn't persist core descriptions to {} : {}",- file.getAbsolutePath(), e);- } finally {- IOUtils.closeQuietly(writer);- IOUtils.closeQuietly(fos);- }- }-- @Override- public void create(CoreContainer cc, CoreDescriptor... coreDescriptors) {- this.persist(cc, coreDescriptors);- }-- @Override- public void delete(CoreContainer cc, CoreDescriptor... coreDescriptors) {- // coreDescriptors is kind of a useless param - we persist the current state off cc- this.persist(cc);- }-- @Override- public void rename(CoreContainer cc, CoreDescriptor oldCD, CoreDescriptor newCD) {- // we don't need those params, we just write out the current cc state- this.persist(cc);- }-- @Override- public void swap(CoreContainer cc, CoreDescriptor cd1, CoreDescriptor cd2) {- this.persist(cc);- }-- @Override- public List<CoreDescriptor> discover(CoreContainer cc) {-- ImmutableList.Builder<CoreDescriptor> listBuilder = ImmutableList.builder();-- for (String coreName : cfg.getAllCoreNames()) {-- String name = cfg.getProperty(coreName, CoreDescriptor.CORE_NAME, DEFAULT_CORE_NAME);- String instanceDir = cfg.getProperty(coreName, CoreDescriptor.CORE_INSTDIR, "");-- Properties coreProperties = new Properties();- for (String propName : CoreDescriptor.standardPropNames) {- String propValue = cfg.getProperty(coreName, propName, "");- if (StringUtils.isNotEmpty(propValue))- coreProperties.setProperty(propName, propValue);- }- coreProperties.putAll(cfg.getCoreProperties(coreName));-- listBuilder.add(new CoreDescriptor(cc, name, instanceDir, coreProperties));- }-- return listBuilder.build();- }-- // for testing- String getTemplate() {- return solrXmlTemplate;- }-- public static class NonPersistingLocator extends SolrXMLCoresLocator {-- public NonPersistingLocator(String originalXML, ConfigSolrXmlOld cfg) {- super(originalXML, cfg);- this.xml = originalXML;- }-- @Override- public void doPersist(String xml) {- this.xml = xml;- }-- public String xml;-- }--}diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.javaindex 3687828ce8b..85e8be8662a 100644--- a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java@@ -17,25 +17,8 @@package org.apache.solr.handler.admin;-import static org.apache.solr.common.cloud.DocCollection.DOC_ROUTER;--import java.io.File;-import java.io.IOException;-import java.util.ArrayList;-import java.util.Arrays;-import java.util.Collection;-import java.util.Collections;-import java.util.Date;-import java.util.HashMap;-import java.util.Iterator;-import java.util.LinkedHashMap;-import java.util.List;-import java.util.Map;-import java.util.Properties;-import java.util.concurrent.ExecutorService;-import java.util.concurrent.Executors;-import java.util.concurrent.Future;-+import com.google.common.collect.ImmutableMap;+import com.google.common.collect.Lists;import org.apache.commons.lang.StringUtils;import org.apache.lucene.index.DirectoryReader;import org.apache.lucene.search.MatchAllDocsQuery;@@ -67,7 +50,6 @@ import org.apache.solr.core.CoreDescriptor;import org.apache.solr.core.DirectoryFactory;import org.apache.solr.core.DirectoryFactory.DirContext;import org.apache.solr.core.SolrCore;-import org.apache.solr.core.SolrXMLCoresLocator;import org.apache.solr.handler.RequestHandlerBase;import org.apache.solr.request.LocalSolrQueryRequest;import org.apache.solr.request.SolrQueryRequest;@@ -86,8 +68,24 @@ import org.apache.zookeeper.KeeperException;import org.slf4j.Logger;import org.slf4j.LoggerFactory;-import com.google.common.collect.ImmutableMap;-import com.google.common.collect.Lists;+import java.io.File;+import java.io.IOException;+import java.util.ArrayList;+import java.util.Arrays;+import java.util.Collection;+import java.util.Collections;+import java.util.Date;+import java.util.HashMap;+import java.util.Iterator;+import java.util.LinkedHashMap;+import java.util.List;+import java.util.Map;+import java.util.Properties;+import java.util.concurrent.ExecutorService;+import java.util.concurrent.Executors;+import java.util.concurrent.Future;++import static org.apache.solr.common.cloud.DocCollection.DOC_ROUTER;/***@@ -586,12 +584,7 @@ public class CoreAdminHandler extends RequestHandlerBase {// only write out the descriptor if the core is successfully createdcoreContainer.getCoresLocator().create(coreContainer, dcore);-- if (coreContainer.getCoresLocator() instanceof SolrXMLCoresLocator) {- // hack - in this case we persist once more because a core create race might- // have dropped entries.- coreContainer.getCoresLocator().create(coreContainer);- }+rsp.add("core", core.getName());}catch (Exception ex) {@@ -694,7 +687,6 @@ public class CoreAdminHandler extends RequestHandlerBase {}try {if (cname == null) {- rsp.add("defaultCoreName", coreContainer.getDefaultCoreName());for (String name : coreContainer.getAllCoreNames()) {status.add(name, getCoreStatus(coreContainer, name, isIndexInfoNeeded));}@@ -1111,7 +1103,6 @@ public class CoreAdminHandler extends RequestHandlerBase {CoreDescriptor desc = cores.getUnloadedCoreDescriptor(cname);if (desc != null) {info.add("name", desc.getName());- info.add("isDefaultCore", desc.getName().equals(cores.getDefaultCoreName()));info.add("instanceDir", desc.getInstanceDir());// None of the following are guaranteed to be present in a not-yet-loaded core.String tmp = desc.getDataDir();@@ -1126,7 +1117,6 @@ public class CoreAdminHandler extends RequestHandlerBase {try (SolrCore core = cores.getCore(cname)) {if (core != null) {info.add("name", core.getName());- info.add("isDefaultCore", core.getName().equals(cores.getDefaultCoreName()));info.add("instanceDir", normalizePath(core.getResourceLoader().getInstanceDir()));info.add("dataDir", normalizePath(core.getDataDir()));info.add("config", core.getConfigResource());diff --git a/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java b/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.javaindex 157209737dc..37cb2a0c6ee 100644--- a/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java+++ b/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java@@ -17,21 +17,20 @@package org.apache.solr.servlet;-import java.io.InputStream;-import java.io.IOException;-import java.io.OutputStreamWriter;-import java.io.Writer;-import java.nio.charset.StandardCharsets;--import javax.servlet.http.HttpServletRequest;-import javax.servlet.http.HttpServletResponse;-import org.apache.commons.io.IOUtils;-import org.apache.commons.lang.StringUtils;import org.apache.commons.lang.StringEscapeUtils;+import org.apache.commons.lang.StringUtils;import org.apache.solr.core.CoreContainer;import org.apache.solr.core.SolrCore;+import javax.servlet.http.HttpServletRequest;+import javax.servlet.http.HttpServletResponse;+import java.io.IOException;+import java.io.InputStream;+import java.io.OutputStreamWriter;+import java.io.Writer;+import java.nio.charset.StandardCharsets;+/*** A simple servlet to load the Solr Admin UI*@@ -63,7 +62,7 @@ public final class LoadAdminUiServlet extends BaseSolrServlet {};String[] replace = new String[] {StringEscapeUtils.escapeJavaScript(request.getContextPath()),- StringEscapeUtils.escapeJavaScript(cores.getAdminPath()),+ StringEscapeUtils.escapeJavaScript(CoreContainer.CORES_HANDLER_PATH),StringEscapeUtils.escapeJavaScript(pack.getSpecificationVersion())};diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.javaindex 53e49227edc..42e62056c77 100644--- a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java+++ b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java@@ -178,7 +178,7 @@ public class SolrDispatchFilter extends BaseSolrFilter {protected CoreContainer createCoreContainer() {SolrResourceLoader loader = new SolrResourceLoader(SolrResourceLoader.locateSolrHome());ConfigSolr config = loadConfigSolr(loader);- CoreContainer cores = new CoreContainer(loader, config);+ CoreContainer cores = new CoreContainer(config);cores.load();return cores;}@@ -250,22 +250,18 @@ public class SolrDispatchFilter extends BaseSolrFilter {path = path.substring( 0, idx );}- // Check for the core admin page- if( path.equals( cores.getAdminPath() ) ) {- handler = cores.getMultiCoreHandler();- solrReq = SolrRequestParsers.DEFAULT.parse(null,path, req);- handleAdminRequest(req, response, handler, solrReq);- return;- }+boolean usingAliases = false;List<String> collectionsList = null;- // Check for the core admin collections url++ // Check for container handlershandler = cores.getRequestHandler(path);- if( handler!= null ) {- solrReq = SolrRequestParsers.DEFAULT.parse(null,path, req);+ if (handler != null) {+ solrReq = SolrRequestParsers.DEFAULT.parse(null, path, req);handleAdminRequest(req, response, handler, solrReq);return;- } else {+ }+ else {//otherwise, we should find a core from the pathidx = path.indexOf( "/", 1 );if( idx > 1 ) {diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig-slave.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig-slave.xmlindex edf195c7adc..1782c5496ec 100644--- a/solr/core/src/test-files/solr/collection1/conf/solrconfig-slave.xml+++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig-slave.xml@@ -42,7 +42,7 @@<requestHandler name="/replication" class="solr.ReplicationHandler"><lst name="slave">- <str name="masterUrl">http://127.0.0.1:TEST_PORT/solr</str>+ <str name="masterUrl">http://127.0.0.1:TEST_PORT/solr/collection1</str><str name="pollInterval">00:00:01</str><str name="compression">COMPRESSION</str></lst>diff --git a/solr/core/src/test-files/solr/solr-shardhandler-old.xml b/solr/core/src/test-files/solr/configsets/bad-mergepolicy/conf/schema.xmlsimilarity index 70%rename from solr/core/src/test-files/solr/solr-shardhandler-old.xmlrename to solr/core/src/test-files/solr/configsets/bad-mergepolicy/conf/schema.xmlindex 70aaa56faa0..9e2f9471026 100644--- a/solr/core/src/test-files/solr/solr-shardhandler-old.xml+++ b/solr/core/src/test-files/solr/configsets/bad-mergepolicy/conf/schema.xml@@ -15,15 +15,11 @@See the License for the specific language governing permissions andlimitations under the License.-->--<!--- old-style solr.xml specifying a custom shardHandlerFactory--->-<solr>- <cores>- <shardHandlerFactory name="shardHandlerFactory"- class="org.apache.solr.core.MockShardHandlerFactory">- <str name="myMagicRequiredParameter">myMagicRequiredValue</str>- </shardHandlerFactory>- </cores>-</solr>+<schema name="minimal" version="1.1">+ <types>+ <fieldType name="string" class="solr.StrField"/>+ </types>+ <fields>+ <dynamicField name="*" type="string" indexed="true" stored="true" />+ </fields>+</schema>diff --git a/solr/core/src/test-files/solr/configsets/bad-mergepolicy/conf/solrconfig.xml b/solr/core/src/test-files/solr/configsets/bad-mergepolicy/conf/solrconfig.xmlnew file mode 100644index 00000000000..0cc5faa08f4--- /dev/null+++ b/solr/core/src/test-files/solr/configsets/bad-mergepolicy/conf/solrconfig.xml@@ -0,0 +1,34 @@+<?xml version="1.0" ?>++<!--+ 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.+-->++<config>++ <directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.RAMDirectoryFactory}"/>++ <luceneMatchVersion>${tests.luceneMatchVersion:LATEST}</luceneMatchVersion>++ <indexConfig>+ <mergePolicy class="org.apache.solr.update.DummyMergePolicy"/>+ <mergeFactor>8</mergeFactor>+ </indexConfig>++ <updateHandler class="solr.DirectUpdateHandler2"/>+ <requestHandler name="standard" class="solr.StandardRequestHandler"></requestHandler>++</config>diff --git a/solr/core/src/test-files/solr/solr-no-core-old-style.xml b/solr/core/src/test-files/solr/solr-no-core-old-style.xmldeleted file mode 100644index c7e26965055..00000000000--- a/solr/core/src/test-files/solr/solr-no-core-old-style.xml+++ /dev/null@@ -1,41 +0,0 @@-<?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.--->--<!--- All (relative) paths are relative to the installation path-- persistent: Save changes made via the API to this file- sharedLib: path to a lib directory that will be shared across all cores--->-<solr persistent="${solr.xml.persist:true}">-- <!--- adminPath: RequestHandler path to manage cores.- 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="${solr.zkclienttimeout:30000}" numShards="${numShards:3}" shareSchema="${shareSchema:false}"- genericCoreNodeNames="${genericCoreNodeNames:true}" leaderVoteWait="0"- distribUpdateConnTimeout="${distribUpdateConnTimeout:45000}" distribUpdateSoTimeout="${distribUpdateSoTimeout:3400000}">- <shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">- <int name="socketTimeout">${socketTimeout:120000}</int>- <int name="connTimeout">${connTimeout:15000}</int>- </shardHandlerFactory>- </cores>--</solr>diff --git a/solr/core/src/test-files/solr/solr-no-core.xml b/solr/core/src/test-files/solr/solr-no-core.xmlindex 60d2ff1b9c1..52d3e7618dd 100644--- a/solr/core/src/test-files/solr/solr-no-core.xml+++ b/solr/core/src/test-files/solr/solr-no-core.xml@@ -19,6 +19,8 @@<solr><str name="shareSchema">${shareSchema:false}</str>+ <str name="configSetBaseDir">${configSetBaseDir:configsets}</str>+ <str name="coreRootDirectory">${coreRootDirectory:.}</str><solrcloud><str name="host">127.0.0.1</str>diff --git a/solr/core/src/test-files/solr/solr-stress-old.xml b/solr/core/src/test-files/solr/solr-stress-old.xmldeleted file mode 100644index 9a83cf2fe00..00000000000--- a/solr/core/src/test-files/solr/solr-stress-old.xml+++ /dev/null@@ -1,59 +0,0 @@-<?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.--->--<!--- All (relative) paths are relative to the installation path-- persistent: Save changes made via the API to this file- sharedLib: path to a lib directory that will be shared across all cores--->-<solr persistent="${solr.xml.persist:true}">-- <!--- adminPath: RequestHandler path to manage cores.- 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}">- <core name="00000_core" instanceDir="00000_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="false" loadOnStartup="true" />- <core name="00001_core" instanceDir="00001_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />- <core name="00002_core" instanceDir="00002_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />- <core name="00003_core" instanceDir="00003_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />- <core name="00004_core" instanceDir="00004_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />- <core name="00005_core" instanceDir="00005_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />- <core name="00006_core" instanceDir="00006_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />- <core name="00007_core" instanceDir="00007_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />- <core name="00008_core" instanceDir="00008_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />- <core name="00009_core" instanceDir="00009_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />- <core name="00010_core" instanceDir="00010_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />- <core name="00011_core" instanceDir="00011_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />- <core name="00012_core" instanceDir="00012_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />- <core name="00013_core" instanceDir="00013_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />- <core name="00014_core" instanceDir="00014_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />- <core name="00015_core" instanceDir="00015_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />- <core name="00016_core" instanceDir="00016_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />- <core name="00017_core" instanceDir="00017_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />- <core name="00018_core" instanceDir="00018_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />- <core name="00019_core" instanceDir="00019_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />- <shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">- <int name="socketTimeout">${socketTimeout:90000}</int>- <int name="connTimeout">${connTimeout:15000}</int>- </shardHandlerFactory>- </cores>--</solr>diff --git a/solr/core/src/test-files/solr/solr.xml b/solr/core/src/test-files/solr/solr.xmlindex 4fa106c838b..09f0121878e 100644--- a/solr/core/src/test-files/solr/solr.xml+++ b/solr/core/src/test-files/solr/solr.xml@@ -18,27 +18,28 @@<!--All (relative) paths are relative to the installation path-- persistent: Save changes made via the API to this file- sharedLib: path to a lib directory that will be shared across all cores-->-<solr persistent="${solr.xml.persist:false}">+<solr>++ <str name="shareSchema">${shareSchema:false}</str>+ <str name="configSetBaseDir">${configSetBaseDir:configsets}</str>+ <str name="coreRootDirectory">${coreRootDirectory:.}</str>++ <shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">+ <str name="urlScheme">${urlScheme:}</str>+ <int name="socketTimeout">${socketTimeout:90000}</int>+ <int name="connTimeout">${connTimeout:15000}</int>+ </shardHandlerFactory>- <!--- adminPath: RequestHandler path to manage cores.- 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="${solr.zkclienttimeout:30000}" shareSchema="${shareSchema:false}"- genericCoreNodeNames="${genericCoreNodeNames:true}" leaderVoteWait="0"- distribUpdateConnTimeout="${distribUpdateConnTimeout:45000}" distribUpdateSoTimeout="${distribUpdateSoTimeout:340000}">- <core name="collection1" instanceDir="collection1" shard="${shard:}" collection="${collection:collection1}" config="${solrconfig:solrconfig.xml}" schema="${schema:schema.xml}"- coreNodeName="${coreNodeName:}"/>- <shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">- <str name="urlScheme">${urlScheme:}</str>- <int name="socketTimeout">${socketTimeout:90000}</int>- <int name="connTimeout">${connTimeout:15000}</int>- </shardHandlerFactory>- </cores>+ <solrcloud>+ <str name="host">127.0.0.1</str>+ <int name="hostPort">${hostPort:8983}</int>+ <str name="hostContext">${hostContext:solr}</str>+ <int name="zkClientTimeout">${solr.zkclienttimeout:30000}</int>+ <bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>+ <int name="leaderVoteWait">0</int>+ <int name="distribUpdateConnTimeout">${distribUpdateConnTimeout:45000}</int>+ <int name="distribUpdateSoTimeout">${distribUpdateSoTimeout:340000}</int>+ </solrcloud></solr>diff --git a/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java b/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.javaindex 283dddc0894..42fea2ff59b 100644--- a/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java+++ b/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java@@ -16,20 +16,21 @@*/package org.apache.solr;-import java.io.File;-import java.io.FileOutputStream;-import java.io.OutputStreamWriter;-import java.io.Writer;-import java.util.Properties;-import org.apache.commons.io.FileUtils;import org.apache.lucene.util.IOUtils;+import org.apache.solr.client.solrj.embedded.JettySolrRunner;import org.apache.solr.client.solrj.response.QueryResponse;import org.apache.solr.common.params.SolrParams;import org.apache.solr.common.util.NamedList;import org.junit.BeforeClass;+import java.io.File;+import java.io.FileOutputStream;+import java.io.OutputStreamWriter;+import java.io.Writer;import java.nio.charset.StandardCharsets;+import java.nio.file.Files;+import java.util.Properties;/*** <p> Test for Loading core properties from a properties file </p>@@ -39,6 +40,8 @@ import java.nio.charset.StandardCharsets;*/public class TestSolrCoreProperties extends SolrJettyTestBase {+ // TODO these properties files don't work with configsets+@BeforeClasspublic static void beforeTest() throws Exception {File homeDir = createTempDir().toFile();@@ -68,7 +71,19 @@ public class TestSolrCoreProperties extends SolrJettyTestBase {p.store(fos, null);IOUtils.close(fos);- createJetty(homeDir.getAbsolutePath(), null, null);+ Files.createFile(collDir.toPath().resolve("core.properties"));++ jetty = new JettySolrRunner(homeDir.getAbsolutePath(), "/solr", 0, null, null, true, null, sslConfig);++ // this sets the property for jetty starting SolrDispatchFilter+ if (System.getProperty("solr.data.dir") == null && System.getProperty("solr.hdfs.home") == null) {+ jetty.setDataDir(createTempDir().toFile().getCanonicalPath());+ }++ jetty.start();+ port = jetty.getLocalPort();++ //createJetty(homeDir.getAbsolutePath(), null, null);}public void testSimple() throws Exception {diff --git a/solr/core/src/test/org/apache/solr/TestTolerantSearch.java b/solr/core/src/test/org/apache/solr/TestTolerantSearch.javaindex d6f781666fe..354df28c85b 100644--- a/solr/core/src/test/org/apache/solr/TestTolerantSearch.java+++ b/solr/core/src/test/org/apache/solr/TestTolerantSearch.java@@ -1,12 +1,8 @@package org.apache.solr;-import java.io.File;-import java.io.IOException;-import java.io.OutputStream;-import org.apache.commons.io.FileUtils;-import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.client.solrj.SolrClient;+import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.client.solrj.SolrServerException;import org.apache.solr.client.solrj.impl.HttpSolrClient;import org.apache.solr.client.solrj.request.CoreAdminRequest;@@ -21,6 +17,10 @@ import org.apache.solr.response.SolrQueryResponse;import org.junit.AfterClass;import org.junit.BeforeClass;+import java.io.File;+import java.io.IOException;+import java.io.OutputStream;+/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with@@ -60,7 +60,7 @@ public class TestTolerantSearch extends SolrJettyTestBase {solrHome = createSolrHome();createJetty(solrHome.getAbsolutePath(), null, null);String url = jetty.getBaseUrl().toString();- collection1 = new HttpSolrClient(url);+ collection1 = new HttpSolrClient(url + "/collection1");collection2 = new HttpSolrClient(url + "/collection2");String urlCollection1 = jetty.getBaseUrl().toString() + "/" + "collection1";@@ -69,9 +69,16 @@ public class TestTolerantSearch extends SolrJettyTestBase {shard2 = urlCollection2.replaceAll("https?://", "");//create second core- CoreAdminRequest.Create req = new CoreAdminRequest.Create();- req.setCoreName("collection2");- collection1.request(req);+ HttpSolrClient nodeClient = new HttpSolrClient(url);+ try {+ CoreAdminRequest.Create req = new CoreAdminRequest.Create();+ req.setCoreName("collection2");+ req.setConfigSet("collection1");+ nodeClient.request(req);+ }+ finally {+ nodeClient.shutdown();+ }SolrInputDocument doc = new SolrInputDocument();doc.setField("id", "1");diff --git a/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java b/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.javaindex da26ae12db3..414e77f4bf6 100644--- a/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java@@ -41,6 +41,8 @@ import org.junit.After;import org.junit.AfterClass;import org.junit.Before;import org.junit.BeforeClass;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;/*** Test sync phase that occurs when Leader goes down and a new Leader is@@ -48,6 +50,8 @@ import org.junit.BeforeClass;*/@Slowpublic class AliasIntegrationTest extends AbstractFullDistribZkTestBase {++ private static final Logger logger = LoggerFactory.getLogger(AliasIntegrationTest.class);@BeforeClasspublic static void beforeSuperClass() throws Exception {@@ -80,12 +84,14 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {@Overridepublic void doTest() throws Exception {-+handle.clear();handle.put("timestamp", SKIPVAL);-+waitForThingsToLevelOut(30);+ logger.info("### STARTING ACTUAL TEST");+del("*:*");createCollection("collection2", 2, 1, 10);@@ -258,6 +264,8 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {sawException = true;}assertTrue(sawException);++ logger.info("### FINISHED ACTUAL TEST");}private void createAlias(String alias, String collections)diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.javaindex a2e7c3e060c..5fa42b7a701 100644--- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java@@ -54,7 +54,6 @@ import org.apache.solr.common.util.StrUtils;import org.apache.solr.core.CoreContainer;import org.apache.solr.core.SolrCore;import org.apache.solr.core.SolrInfoMBean.Category;-import org.apache.solr.core.SolrResourceLoader;import org.apache.solr.servlet.SolrDispatchFilter;import org.apache.solr.update.DirectUpdateHandler2;import org.apache.solr.util.DefaultSolrThreadFactory;@@ -64,10 +63,12 @@ import org.junit.BeforeClass;import javax.management.MBeanServer;import javax.management.MBeanServerFactory;import javax.management.ObjectName;-import java.io.File;import java.io.IOException;import java.lang.management.ManagementFactory;+import java.nio.file.Files;+import java.nio.file.Path;+import java.nio.file.Paths;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;@@ -110,7 +111,6 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa// we randomly use a second config set rather than just oneprivate boolean secondConfigSet = random().nextBoolean();- private boolean oldStyleSolrXml = false;@BeforeClasspublic static void beforeThisClass2() throws Exception {@@ -123,13 +123,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBasuper.setUp();useJettyDataDir = false;-- oldStyleSolrXml = random().nextBoolean();- if (oldStyleSolrXml) {- System.err.println("Using old style solr.xml");- } else {- System.err.println("Using new style solr.xml");- }+if (secondConfigSet ) {String zkHost = zkServer.getZkHost();String zkAddress = zkServer.getZkAddress();@@ -158,12 +152,11 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa}System.setProperty("numShards", Integer.toString(sliceCount));- System.setProperty("solr.xml.persist", "true");+}protected String getSolrXml() {- // test old style and new style solr.xml- return oldStyleSolrXml ? "solr-no-core-old-style.xml" : "solr-no-core.xml";+ return "solr-no-core.xml";}@@ -953,28 +946,22 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa}}- private void checkInstanceDirs(JettySolrRunner jetty) {+ private void checkInstanceDirs(JettySolrRunner jetty) throws IOException {CoreContainer cores = ((SolrDispatchFilter) jetty.getDispatchFilter().getFilter()).getCores();Collection<SolrCore> theCores = cores.getCores();for (SolrCore core : theCores) {- if (!oldStyleSolrXml) {- // look for core props file- assertTrue("Could not find expected core.properties file",- new File((String) core.getStatistics().get("instanceDir"),- "core.properties").exists());- }- try {- assertEquals(- new File(SolrResourceLoader.normalizeDir(jetty.getSolrHome() + File.separator- + core.getName())).getCanonicalPath(),- new File(SolrResourceLoader.normalizeDir((String) core.getStatistics().get(- "instanceDir"))).getCanonicalPath());- } catch (IOException e) {- log.error("Failed to get canonical path", e);- fail("Failed to get canonical path");- }+ // look for core props file+ assertTrue("Could not find expected core.properties file",+ new File((String) core.getStatistics().get("instanceDir"),+ "core.properties").exists());++ Path expected = Paths.get(jetty.getSolrHome()).toAbsolutePath().resolve("cores").resolve(core.getName());+ Path reported = Paths.get((String) core.getStatistics().get("instanceDir"));++ assertTrue("Expected: " + expected + "\nFrom core stats: " + reported, Files.isSameFile(expected, reported));+}}diff --git a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.java b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.javaindex 55a02a5b2e0..bed3d7280fc 100644--- a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.java@@ -23,6 +23,7 @@ import org.apache.solr.common.cloud.SolrZkClient;import org.apache.solr.common.cloud.ZkNodeProps;import org.apache.solr.common.cloud.ZkStateReader;import org.apache.solr.core.CoreContainer;+import org.apache.solr.core.CoreDescriptor;import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Test;@@ -146,8 +147,7 @@ public class LeaderElectionIntegrationTest extends SolrTestCaseJ4 {ports.add(port);CoreContainer container = new CoreContainer();container.load();- assertTrue("Container " + port + " has no cores!", container.getCores()- .size() > 0);+ container.create(new CoreDescriptor(container, "collection1", "collection1", "collection", "collection1"));containerMap.put(port, container);System.clearProperty("solr.solr.home");System.clearProperty("hostPort");diff --git a/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java b/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.javaindex c873287ddbf..2c95ce964d6 100644--- a/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java+++ b/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java@@ -17,14 +17,6 @@ package org.apache.solr.cloud;* limitations under the License.*/-import java.io.File;-import java.io.FileInputStream;-import java.io.FileNotFoundException;-import java.io.InputStream;-import java.nio.charset.StandardCharsets;-import java.util.Collection;-import java.util.List;-import org.apache.commons.io.FileUtils;import org.apache.commons.io.IOUtils;import org.apache.commons.io.filefilter.RegexFileFilter;@@ -44,6 +36,14 @@ import org.junit.Test;import org.slf4j.Logger;import org.slf4j.LoggerFactory;+import java.io.File;+import java.io.FileInputStream;+import java.io.FileNotFoundException;+import java.io.InputStream;+import java.nio.charset.StandardCharsets;+import java.util.Collection;+import java.util.List;+// TODO: This test would be a lot faster if it used a solrhome with fewer config// files - there are a lot of them to uploadpublic class ZkCLITest extends SolrTestCaseJ4 {@@ -78,19 +78,10 @@ public class ZkCLITest extends SolrTestCaseJ4 {log.info("####SETUP_START " + getTestName());String exampleHome = SolrJettyTestBase.legacyExampleCollection1SolrHome();-- boolean useNewSolrXml = random().nextBoolean();+File tmpDir = createTempDir().toFile();- if (useNewSolrXml) {- solrHome = exampleHome;- } else {- File tmpSolrHome = new File(tmpDir, "tmp-solr-home");- FileUtils.copyDirectory(new File(exampleHome), tmpSolrHome);- FileUtils.copyFile(getFile("old-solr-example/solr.xml"), new File(tmpSolrHome, "solr.xml"));- solrHome = tmpSolrHome.getAbsolutePath();- }--+ solrHome = exampleHome;+zkDir = tmpDir.getAbsolutePath() + File.separator+ "zookeeper/server1/data";log.info("ZooKeeper dataDir:" + zkDir);diff --git a/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java b/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.javaindex 6a93a1f6d4f..a9f1bcedf5c 100644--- a/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java@@ -17,12 +17,6 @@ package org.apache.solr.cloud;* the License.*/-import java.io.File;-import java.util.Collections;-import java.util.HashMap;-import java.util.List;-import java.util.Map;-import org.apache.lucene.util.LuceneTestCase.Slow;import org.apache.solr.SolrJettyTestBase;import org.apache.solr.SolrTestCaseJ4;@@ -33,6 +27,7 @@ import org.apache.solr.core.ConfigSolr;import org.apache.solr.core.CoreContainer;import org.apache.solr.core.CoreDescriptor;import org.apache.solr.core.CoresLocator;+import org.apache.solr.core.PluginInfo;import org.apache.solr.handler.admin.CoreAdminHandler;import org.apache.solr.handler.component.HttpShardHandlerFactory;import org.apache.solr.update.UpdateShardHandler;@@ -41,6 +36,12 @@ import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Test;+import java.io.File;+import java.util.Collections;+import java.util.HashMap;+import java.util.List;+import java.util.Map;+@Slowpublic class ZkControllerTest extends SolrTestCaseJ4 {@@ -321,7 +322,7 @@ public class ZkControllerTest extends SolrTestCaseJ4 {@Overridepublic ConfigSolr getConfig() {- return new ConfigSolr() {+ return new ConfigSolr(null, null) {@Overridepublic CoresLocator getCoresLocator() {@@ -329,25 +330,22 @@ public class ZkControllerTest extends SolrTestCaseJ4 {}@Override- protected String getShardHandlerFactoryConfigPath() {- throw new UnsupportedOperationException();+ public PluginInfo getShardHandlerFactoryPluginInfo() {+ return null;}@Override- public boolean isPersistent() {- throw new UnsupportedOperationException();- }};+ protected String getProperty(CfgProp key) {+ return null;+ }++ };}@Overridepublic UpdateShardHandler getUpdateShardHandler() {return new UpdateShardHandler(null);}-- @Override- public String getAdminPath() {- return "/admin/cores";- }}}diff --git a/solr/core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.java b/solr/core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.javadeleted file mode 100644index 3862f1b319e..00000000000--- a/solr/core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.java+++ /dev/null@@ -1,436 +0,0 @@-/*- * 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.- */--package org.apache.solr.core;--import org.apache.commons.io.FileUtils;-import org.apache.lucene.util.IOUtils;-import org.apache.solr.SolrTestCaseJ4;-import org.apache.solr.common.SolrException;-import org.junit.After;-import org.xml.sax.SAXParseException;--import java.io.File;-import java.util.Collection;-import java.util.Map;-import java.util.regex.Pattern;--public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {-- File solrHome = null;- CoreContainer cc = null;-- private void init(final String dirSuffix) {- solrHome = createTempDir(dirSuffix).toFile();- }-- @After- public void cleanUp() throws Exception {- if (cc != null) {- cc.shutdown();- cc = null;- }-- solrHome = null;- }-- public void testFlowWithEmpty() throws Exception {- // reused state- Map<String,CoreContainer.CoreLoadFailure> failures = null;- Collection<String> cores = null;- Exception fail = null;-- init("empty_flow");-- // solr.xml- File solrXml = new File(solrHome, "solr.xml");- FileUtils.write(solrXml, EMPTY_SOLR_XML, IOUtils.UTF_8);-- // ----- // init the CoreContainer- cc = new CoreContainer(solrHome.getAbsolutePath());- cc.load();-- // check that we have the cores we expect- cores = cc.getCoreNames();- assertNotNull("core names is null", cores);- assertEquals("wrong number of cores", 0, cores.size());-- // check that we have the failures we expect- failures = cc.getCoreInitFailures();- assertNotNull("core failures is a null map", failures);- assertEquals("wrong number of core failures", 0, failures.size());-- // ------ // try to add a collection with a path that doesn't exist- final CoreDescriptor bogus = new CoreDescriptor(cc, "bogus", "bogus_path");- try {- ignoreException(Pattern.quote("bogus_path"));- cc.create(bogus);- fail("bogus inst dir failed to trigger exception from create");- } catch (SolrException e) {- assertTrue("init exception doesn't mention bogus dir: " + e.getCause().getCause().getMessage(),- 0 < e.getCause().getCause().getMessage().indexOf("bogus_path"));-- }-- // check that we have the cores we expect- cores = cc.getCoreNames();- assertNotNull("core names is null", cores);- assertEquals("wrong number of cores", 0, cores.size());-- // check that we have the failures we expect- failures = cc.getCoreInitFailures();- assertNotNull("core failures is a null map", failures);- assertEquals("wrong number of core failures", 1, failures.size());- fail = failures.get("bogus").exception;- assertNotNull("null failure for test core", fail);- assertTrue("init failure doesn't mention problem: " + fail.getCause().getMessage(),- 0 < fail.getCause().getMessage().indexOf("bogus_path"));-- // check that we get null accessing a non-existent core- assertNull(cc.getCore("does_not_exist"));- // check that we get a 500 accessing the core with an init failure- try {- SolrCore c = cc.getCore("bogus");- fail("Failed to get Exception on accessing core with init failure");- } catch (SolrException ex) {- assertEquals(500, ex.code());- // double wrapped- String cause = ex.getCause().getCause().getMessage();- assertTrue("getCore() ex cause doesn't mention init fail: " + cause,- 0 < cause.indexOf("bogus_path"));-- }-- // let the test end here, with some recorded failures, and let cleanUp()- // verify that there is no problem shuting down CoreContainer with known- // SolrCore failures- }-- public void testFlowBadFromStart() throws Exception {-- // reused state- Map<String,CoreContainer.CoreLoadFailure> failures = null;- Collection<String> cores = null;- Exception fail = null;-- init("bad_flow");-- // start with two collections: one valid, and one broken- File solrXml = new File(solrHome, "solr.xml");- FileUtils.write(solrXml, BAD_SOLR_XML, IOUtils.UTF_8);-- // our "ok" collection- FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-defaults.xml"),- FileUtils.getFile(solrHome, "col_ok", "conf", "solrconfig.xml"));- FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),- FileUtils.getFile(solrHome, "col_ok", "conf", "schema.xml"));-- // our "bad" collection- ignoreException(Pattern.quote("DummyMergePolicy"));- FileUtils.copyFile(getFile("solr/collection1/conf/bad-mp-solrconfig.xml"),- FileUtils.getFile(solrHome, "col_bad", "conf", "solrconfig.xml"));- FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),- FileUtils.getFile(solrHome, "col_bad", "conf", "schema.xml"));--- // ------ // init the CoreContainer with the mix of ok/bad cores- cc = new CoreContainer(solrHome.getAbsolutePath());- cc.load();-- // check that we have the cores we expect- cores = cc.getCoreNames();- assertNotNull("core names is null", cores);- assertEquals("wrong number of cores", 1, cores.size());- assertTrue("col_ok not found", cores.contains("col_ok"));-- // check that we have the failures we expect- failures = cc.getCoreInitFailures();- assertNotNull("core failures is a null map", failures);- assertEquals("wrong number of core failures", 1, failures.size());- fail = failures.get("col_bad").exception;- assertNotNull("null failure for test core", fail);- assertTrue("init failure doesn't mention problem: " + fail.getMessage(),- 0 < fail.getMessage().indexOf("DummyMergePolicy"));-- // check that we get null accessing a non-existent core- assertNull(cc.getCore("does_not_exist"));- // check that we get a 500 accessing the core with an init failure- try {- SolrCore c = cc.getCore("col_bad");- fail("Failed to get Exception on accessing core with init failure");- } catch (SolrException ex) {- assertEquals(500, ex.code());- // double wrapped- String cause = ex.getCause().getCause().getMessage();- assertTrue("getCore() ex cause doesn't mention init fail: " + cause,- 0 < cause.indexOf("DummyMergePolicy"));- }-- // ------ // "fix" the bad collection- FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-defaults.xml"),- FileUtils.getFile(solrHome, "col_bad", "conf", "solrconfig.xml"));- final CoreDescriptor fixed = new CoreDescriptor(cc, "col_bad", "col_bad");- cc.create(fixed);-- // check that we have the cores we expect- cores = cc.getCoreNames();- assertNotNull("core names is null", cores);- assertEquals("wrong number of cores", 2, cores.size());- assertTrue("col_ok not found", cores.contains("col_ok"));- assertTrue("col_bad not found", cores.contains("col_bad"));-- // check that we have the failures we expect- failures = cc.getCoreInitFailures();- assertNotNull("core failures is a null map", failures);- assertEquals("wrong number of core failures", 0, failures.size());--- // ------ // try to add a collection with a path that doesn't exist- final CoreDescriptor bogus = new CoreDescriptor(cc, "bogus", "bogus_path");- try {- ignoreException(Pattern.quote("bogus_path"));- cc.create(bogus);- fail("bogus inst dir failed to trigger exception from create");- } catch (SolrException e) {- assertTrue("init exception doesn't mention bogus dir: " + e.getCause().getCause().getMessage(),- 0 < e.getCause().getCause().getMessage().indexOf("bogus_path"));-- }-- // check that we have the cores we expect- cores = cc.getCoreNames();- assertNotNull("core names is null", cores);- assertEquals("wrong number of cores", 2, cores.size());- assertTrue("col_ok not found", cores.contains("col_ok"));- assertTrue("col_bad not found", cores.contains("col_bad"));-- // check that we have the failures we expect- failures = cc.getCoreInitFailures();- assertNotNull("core failures is a null map", failures);- assertEquals("wrong number of core failures", 1, failures.size());- fail = failures.get("bogus").exception;- assertNotNull("null failure for test core", fail);- assertTrue("init failure doesn't mention problem: " + fail.getCause().getMessage(),- 0 < fail.getCause().getMessage().indexOf("bogus_path"));-- // check that we get null accessing a non-existent core- assertNull(cc.getCore("does_not_exist"));- // check that we get a 500 accessing the core with an init failure- try {- SolrCore c = cc.getCore("bogus");- fail("Failed to get Exception on accessing core with init failure");- } catch (SolrException ex) {- assertEquals(500, ex.code());- // double wrapped- String cause = ex.getCause().getCause().getMessage();- assertTrue("getCore() ex cause doesn't mention init fail: " + cause,- 0 < cause.indexOf("bogus_path"));- }-- // ------ // break col_bad's config and try to RELOAD to add failure-- final long col_bad_old_start = getCoreStartTime(cc, "col_bad");-- FileUtils.write- (FileUtils.getFile(solrHome, "col_bad", "conf", "solrconfig.xml"),- "This is giberish, not valid XML <",- IOUtils.UTF_8);-- try {- ignoreException(Pattern.quote("SAX"));- cc.reload("col_bad");- fail("corrupt solrconfig.xml failed to trigger exception from reload");- } catch (SolrException e) {- Throwable rootException = getWrappedException(e);- assertTrue("We're supposed to have a wrapped SAXParserException here, but we don't",- rootException instanceof SAXParseException);- SAXParseException se = (SAXParseException) rootException;- assertTrue("reload exception doesn't refer to slrconfig.xml " + se.getSystemId(),- 0 < se.getSystemId().indexOf("solrconfig.xml"));-- }-- assertEquals("Failed core reload should not have changed start time",- col_bad_old_start, getCoreStartTime(cc, "col_bad"));-- // check that we have the cores we expect- cores = cc.getCoreNames();- assertNotNull("core names is null", cores);- assertEquals("wrong number of cores", 2, cores.size());- assertTrue("col_ok not found", cores.contains("col_ok"));- assertTrue("col_bad not found", cores.contains("col_bad"));-- // check that we have the failures we expect- failures = cc.getCoreInitFailures();- assertNotNull("core failures is a null map", failures);- assertEquals("wrong number of core failures", 2, failures.size());- Throwable ex = getWrappedException(failures.get("col_bad").exception);- assertNotNull("null failure for test core", ex);- assertTrue("init failure isn't SAXParseException",- ex instanceof SAXParseException);- SAXParseException saxEx = (SAXParseException) ex;- assertTrue("init failure doesn't mention problem: " + saxEx.toString(), saxEx.getSystemId().contains("solrconfig.xml"));-- // ----- // fix col_bad's config (again) and RELOAD to fix failure- FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-defaults.xml"),- FileUtils.getFile(solrHome, "col_bad", "conf", "solrconfig.xml"));- cc.reload("col_bad");-- assertTrue("Core reload should have changed start time",- col_bad_old_start < getCoreStartTime(cc, "col_bad"));--- // check that we have the cores we expect- cores = cc.getCoreNames();- assertNotNull("core names is null", cores);- assertEquals("wrong number of cores", 2, cores.size());- assertTrue("col_ok not found", cores.contains("col_ok"));- assertTrue("col_bad not found", cores.contains("col_bad"));-- // check that we have the failures we expect- failures = cc.getCoreInitFailures();- assertNotNull("core failures is a null map", failures);- assertEquals("wrong number of core failures", 1, failures.size());-- }-- public void testJavaLangErrorFromHandlerOnStartup() throws Exception {-- // reused state- Map<String,CoreContainer.CoreLoadFailure> failures = null;- Collection<String> cores = null;- Exception fail = null;-- init("java_lang_error_handler");-- // start with two collections: 1 ok, and 1 that throws java.lang.Error on startup- File solrXml = new File(solrHome, "solr.xml");- FileUtils.write(solrXml, BAD_SOLR_XML, IOUtils.UTF_8);-- // our "ok" collection- FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-defaults.xml"),- FileUtils.getFile(solrHome, "col_ok", "conf", "solrconfig.xml"));- FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),- FileUtils.getFile(solrHome, "col_ok", "conf", "schema.xml"));-- // our "bad" collection- ignoreException(Pattern.quote("my_error_handler"));- FileUtils.copyFile(getFile("solr/collection1/conf/bad-error-solrconfig.xml"),- FileUtils.getFile(solrHome, "col_bad", "conf", "solrconfig.xml"));- FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),- FileUtils.getFile(solrHome, "col_bad", "conf", "schema.xml"));--- // ------ // init the CoreContainer with the mix of ok/bad cores- cc = new CoreContainer(solrHome.getAbsolutePath());- cc.load();-- // check that we have the cores we expect- cores = cc.getCoreNames();- assertNotNull("core names is null", cores);- assertEquals("wrong number of cores", 1, cores.size());- assertTrue("col_ok not found", cores.contains("col_ok"));-- // check that we have the failures we expect- failures = cc.getCoreInitFailures();- assertNotNull("core failures is a null map", failures);- assertEquals("wrong number of core failures", 1, failures.size());- fail = failures.get("col_bad").exception;- assertNotNull("null failure for test core", fail);- assertTrue("init failure doesn't mention root problem: " + fail.getMessage(),- 0 < fail.getMessage().indexOf("throwing a java.lang.Error"));- }-- public void testJavaLangErrorFromSchemaOnStartup() throws Exception {-- // reused state- Map<String,CoreContainer.CoreLoadFailure> failures = null;- Collection<String> cores = null;- Exception fail = null;-- init("java_lang_error_schema");-- // start with two collections: 1 ok, and 1 that throws java.lang.Error on startup- File solrXml = new File(solrHome, "solr.xml");- FileUtils.write(solrXml, BAD_SOLR_XML, IOUtils.UTF_8);-- // our "ok" collection- FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-defaults.xml"),- FileUtils.getFile(solrHome, "col_ok", "conf", "solrconfig.xml"));- FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),- FileUtils.getFile(solrHome, "col_ok", "conf", "schema.xml"));-- // our "bad" collection- ignoreException(Pattern.quote("error_ft"));- FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-defaults.xml"),- FileUtils.getFile(solrHome, "col_bad", "conf", "solrconfig.xml"));- FileUtils.copyFile(getFile("solr/collection1/conf/bad-schema-init-error.xml"),- FileUtils.getFile(solrHome, "col_bad", "conf", "schema.xml"));--- // ------ // init the CoreContainer with the mix of ok/bad cores- cc = new CoreContainer(solrHome.getAbsolutePath());- cc.load();-- // check that we have the cores we expect- cores = cc.getCoreNames();- assertNotNull("core names is null", cores);- assertEquals("wrong number of cores", 1, cores.size());- assertTrue("col_ok not found", cores.contains("col_ok"));-- // check that we have the failures we expect- failures = cc.getCoreInitFailures();- assertNotNull("core failures is a null map", failures);- assertEquals("wrong number of core failures", 1, failures.size());- fail = failures.get("col_bad").exception;- assertNotNull("null failure for test core", fail);- assertTrue("init failure doesn't mention root problem: " + fail.getMessage(),- 0 < fail.getMessage().indexOf("throwing java.lang.Error"));-- }-- private long getCoreStartTime(final CoreContainer cc, final String name) {- try (SolrCore tmp = cc.getCore(name)) {- return tmp.getStartTime();- }- }-- private static final String EMPTY_SOLR_XML ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +- "<solr persistent=\"false\">\n" +- " <cores adminPath=\"/admin/cores\">\n" +- " </cores>\n" +- "</solr>";-- private static final String BAD_SOLR_XML =- "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +- "<solr persistent=\"false\">\n" +- " <cores adminPath=\"/admin/cores\">\n" +- " <core name=\"col_ok\" instanceDir=\"col_ok\" />\n" +- " <core name=\"col_bad\" instanceDir=\"col_bad\" />\n" +- " </cores>\n" +- "</solr>";--}diff --git a/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java b/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.javaindex 5dc1687675b..d787390bc93 100644--- a/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java+++ b/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java@@ -105,47 +105,41 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {@Testpublic void test5Seconds() throws Exception {- doStress(5, random().nextBoolean());+ doStress(5);}@Test@Nightlypublic void test15SecondsOld() throws Exception {- doStress(15, true);+ doStress(15);}@Test@Nightlypublic void test15SecondsNew() throws Exception {- doStress(15, false);+ doStress(15);}@Test@Nightlypublic void test10MinutesOld() throws Exception {- doStress(300, true);+ doStress(300);}@Test@Nightlypublic void test10MinutesNew() throws Exception {- doStress(300, false);+ doStress(300);}@Test@Weekly- public void test1HourOld() throws Exception {- doStress(1800, true);+ public void test1Hour() throws Exception {+ doStress(1800);}-- @Test- @Weekly- public void test1HourNew() throws Exception {- doStress(1800, false);- }--+private void buildClients() throws Exception {+jetty.start();url = buildUrl(jetty.getLocalPort(), "/solr/");@@ -169,8 +163,8 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {}// Unless things go _really_ well, stop after you have the directories set up.- private void doStress(int secondsToRun, boolean oldStyle) throws Exception {- makeCores(solrHomeDirectory, oldStyle);+ private void doStress(int secondsToRun) throws Exception {+ makeCores(solrHomeDirectory);//MUST start the server after the cores are made.buildClients();@@ -213,25 +207,22 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {}}- private void makeCores(File home, boolean oldStyle) throws Exception {+ private void makeCores(File home) throws Exception {File testSrcRoot = new File(SolrTestCaseJ4.TEST_HOME());String srcSolrXml = "solr-stress-new.xml";- if (oldStyle) {- srcSolrXml = "solr-stress-old.xml";- }FileUtils.copyFile(new File(testSrcRoot, srcSolrXml), new File(home, "solr.xml"));// create directories in groups of 100 until you have enough.for (int idx = 0; idx < numCores; ++idx) {String coreName = String.format(Locale.ROOT, "%05d_core", idx);- makeCore(new File(home, coreName), testSrcRoot, oldStyle);+ makeCore(new File(home, coreName), testSrcRoot);coreCounts.put(coreName, 0L);coreNames.add(coreName);}}- private void makeCore(File coreDir, File testSrcRoot, boolean oldStyle) throws IOException {+ private void makeCore(File coreDir, File testSrcRoot) throws IOException {File conf = new File(coreDir, "conf");if (!conf.mkdirs()) log.warn("mkdirs returned false in makeCore... ignoring");@@ -244,9 +235,7 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {FileUtils.copyFile(new File(testConf, "solrconfig.snippet.randomindexconfig.xml"),new File(conf, "solrconfig.snippet.randomindexconfig.xml"));- if (!oldStyle) {- FileUtils.copyFile(new File(testSrcRoot, "conf/core.properties"), new File(coreDir, "core.properties"));- }+ FileUtils.copyFile(new File(testSrcRoot, "conf/core.properties"), new File(coreDir, "core.properties"));}diff --git a/solr/core/src/test/org/apache/solr/core/SolrCoreTest.java b/solr/core/src/test/org/apache/solr/core/SolrCoreTest.javaindex 42b4fef2538..b78b8d71ffd 100644--- a/solr/core/src/test/org/apache/solr/core/SolrCoreTest.java+++ b/solr/core/src/test/org/apache/solr/core/SolrCoreTest.java@@ -51,35 +51,6 @@ public class SolrCoreTest extends SolrTestCaseJ4 {deleteCore();super.tearDown();}-- @Test- public void testRemoveThenAddDefaultCore() throws Exception {- final CoreContainer cores = h.getCoreContainer();- SolrCore core = cores.getCore("");-- assertEquals(COLLECTION1, cores.getDefaultCoreName());-- cores.unload("");- core.close();-- CoreDescriptor cd = new CoreDescriptor(cores, COLLECTION1, "collection1",- CoreDescriptor.CORE_DATADIR, createTempDir("dataDir2").toFile().getAbsolutePath());-- cores.create(cd);-- assertEquals(COLLECTION1, cores.getDefaultCoreName());-- // so we should be able to get a core with collection1- core = cores.getCore(COLLECTION1);- assertNotNull(core);- core.close();-- // and with ""- core = cores.getCore("");- assertNotNull(core);-- core.close();- }@Testpublic void testRequestHandlerRegistry() {@@ -100,7 +71,7 @@ public class SolrCoreTest extends SolrTestCaseJ4 {@Testpublic void testClose() throws Exception {final CoreContainer cores = h.getCoreContainer();- SolrCore core = cores.getCore("");+ SolrCore core = cores.getCore(SolrTestCaseJ4.DEFAULT_TEST_CORENAME);ClosingRequestHandler handler1 = new ClosingRequestHandler();handler1.inform( core );@@ -120,7 +91,7 @@ public class SolrCoreTest extends SolrTestCaseJ4 {assertTrue("Refcount != 1", core.getOpenCount() == 1);final CoreContainer cores = h.getCoreContainer();- SolrCore c1 = cores.getCore("");+ SolrCore c1 = cores.getCore(SolrTestCaseJ4.DEFAULT_TEST_CORENAME);assertTrue("Refcount != 2", core.getOpenCount() == 2);ClosingRequestHandler handler1 = new ClosingRequestHandler();@@ -131,12 +102,12 @@ public class SolrCoreTest extends SolrTestCaseJ4 {assertNull( old ); // should not be anything...assertEquals( core.getRequestHandlers().get( path ), handler1 );- SolrCore c2 = cores.getCore("");+ SolrCore c2 = cores.getCore(SolrTestCaseJ4.DEFAULT_TEST_CORENAME);c1.close();assertTrue("Refcount < 1", core.getOpenCount() >= 1);assertTrue("Handler is closed", handler1.closed == false);- c1 = cores.getCore("");+ c1 = cores.getCore(SolrTestCaseJ4.DEFAULT_TEST_CORENAME);assertTrue("Refcount < 2", core.getOpenCount() >= 2);assertTrue("Handler is closed", handler1.closed == false);@@ -184,7 +155,7 @@ public class SolrCoreTest extends SolrTestCaseJ4 {try {for (int l = 0; l < LOOP; ++l) {r += 1;- core = cores.getCore("");+ core = cores.getCore(SolrTestCaseJ4.DEFAULT_TEST_CORENAME);// sprinkle concurrency hinting...yield(l);assertTrue("Refcount < 1", core.getOpenCount() >= 1);diff --git a/solr/core/src/test/org/apache/solr/core/TestConfigSets.java b/solr/core/src/test/org/apache/solr/core/TestConfigSets.javaindex 2e238675edd..7193b25105d 100644--- a/solr/core/src/test/org/apache/solr/core/TestConfigSets.java+++ b/solr/core/src/test/org/apache/solr/core/TestConfigSets.java@@ -46,7 +46,7 @@ public class TestConfigSets extends SolrTestCaseJ4 {System.setProperty("configsets", configSetsBaseDir);SolrResourceLoader loader = new SolrResourceLoader(testDirectory.getAbsolutePath());- CoreContainer container = new CoreContainer(loader, ConfigSolr.fromString(loader, solrxml));+ CoreContainer container = new CoreContainer(ConfigSolr.fromString(loader, solrxml));container.load();return container;@@ -115,12 +115,12 @@ public class TestConfigSets extends SolrTestCaseJ4 {System.setProperty("configsets", csd);SolrResourceLoader loader = new SolrResourceLoader(testDirectory.getAbsolutePath());- CoreContainer container = new CoreContainer(loader, ConfigSolr.fromString(loader, solrxml));+ CoreContainer container = new CoreContainer(ConfigSolr.fromString(loader, solrxml));container.load();// We initially don't have a /get handler definedSolrCore core = container.create(new CoreDescriptor(container, "core1", testDirectory + "/core", "configSet", "configset-2"));- assertThat("No /get handler should be defined in the initial configuration",+ assertThat("No /dump handler should be defined in the initial configuration",core.getRequestHandler("/dump"), is(nullValue()));// Now copy in a config with a /get handler and reload@@ -129,7 +129,7 @@ public class TestConfigSets extends SolrTestCaseJ4 {container.reload("core1");core = container.getCore("core1");- assertThat("A /get handler should be defined in the reloaded configuration",+ assertThat("A /dump handler should be defined in the reloaded configuration",core.getRequestHandler("/dump"), is(notNullValue()));core.close();diff --git a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.javaindex 2b97664650b..a577ff8f1fd 100644--- a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java+++ b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java@@ -18,6 +18,7 @@package org.apache.solr.core;import org.apache.commons.io.FileUtils;+import org.apache.lucene.util.IOUtils;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.common.SolrException;import org.apache.solr.handler.admin.CollectionsHandler;@@ -26,19 +27,18 @@ import org.apache.solr.handler.admin.InfoHandler;import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Test;-import org.xml.sax.SAXException;+import org.xml.sax.SAXParseException;-import javax.xml.parsers.ParserConfigurationException;-import java.io.BufferedWriter;import java.io.File;import java.io.FileOutputStream;-import java.io.IOException;-import java.io.OutputStreamWriter;-import java.nio.charset.StandardCharsets;+import java.nio.file.Path;import java.util.ArrayList;+import java.util.Collection;import java.util.List;+import java.util.Map;import java.util.jar.JarEntry;import java.util.jar.JarOutputStream;+import java.util.regex.Pattern;import static org.hamcrest.CoreMatchers.not;import static org.hamcrest.CoreMatchers.nullValue;@@ -55,7 +55,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {@BeforeClasspublic static void beforeClass() throws Exception {oldSolrHome = System.getProperty(SOLR_HOME_PROP);- initCore("solrconfig.xml", "schema.xml");+ System.setProperty("configsets", getFile("solr/configsets").getAbsolutePath());}@AfterClass@@ -67,16 +67,14 @@ public class TestCoreContainer extends SolrTestCaseJ4 {}}- private File solrHomeDirectory;-- private CoreContainer init(String dirName) throws Exception {-- solrHomeDirectory = createTempDir(dirName).toFile();-- FileUtils.copyDirectory(new File(SolrTestCaseJ4.TEST_HOME()), solrHomeDirectory);- System.out.println("Using solrconfig from " + new File(SolrTestCaseJ4.TEST_HOME()).getAbsolutePath());+ private CoreContainer init(String xml) throws Exception {+ Path solrHomeDirectory = createTempDir();+ return init(solrHomeDirectory, xml);+ }- CoreContainer ret = new CoreContainer(solrHomeDirectory.getAbsolutePath());+ private CoreContainer init(Path homeDirectory, String xml) throws Exception {+ SolrResourceLoader loader = new SolrResourceLoader(homeDirectory.toString());+ CoreContainer ret = new CoreContainer(ConfigSolr.fromString(loader, xml));ret.load();return ret;}@@ -84,12 +82,14 @@ public class TestCoreContainer extends SolrTestCaseJ4 {@Testpublic void testShareSchema() throws Exception {System.setProperty("shareSchema", "true");- final CoreContainer cores = init("_shareSchema");++ CoreContainer cores = init(CONFIGSETS_SOLR_XML);+try {- CoreDescriptor descriptor1 = new CoreDescriptor(cores, "core1", "./collection1");+ CoreDescriptor descriptor1 = new CoreDescriptor(cores, "core1", "./collection1", "configSet", "minimal");SolrCore core1 = cores.create(descriptor1);- CoreDescriptor descriptor2 = new CoreDescriptor(cores, "core2", "./collection1");+ CoreDescriptor descriptor2 = new CoreDescriptor(cores, "core2", "./collection1", "configSet", "minimal");SolrCore core2 = cores.create(descriptor2);assertSame(core1.getLatestSchema(), core2.getLatestSchema());@@ -102,12 +102,14 @@ public class TestCoreContainer extends SolrTestCaseJ4 {@Testpublic void testReloadSequential() throws Exception {- final CoreContainer cc = init("_reloadSequential");+ final CoreContainer cc = init(CONFIGSETS_SOLR_XML);+ CoreDescriptor descriptor1 = new CoreDescriptor(cc, "core1", "./collection1", "configSet", "minimal");+ cc.create(descriptor1);try {- cc.reload("collection1");- cc.reload("collection1");- cc.reload("collection1");- cc.reload("collection1");+ cc.reload("core1");+ cc.reload("core1");+ cc.reload("core1");+ cc.reload("core1");} finally {cc.shutdown();@@ -116,63 +118,52 @@ public class TestCoreContainer extends SolrTestCaseJ4 {@Testpublic void testReloadThreaded() throws Exception {- final CoreContainer cc = init("_reloadThreaded");-- class TestThread extends Thread {- @Override- public void run() {- cc.reload("collection1");- }+ final CoreContainer cc = init(CONFIGSETS_SOLR_XML);+ CoreDescriptor descriptor1 = new CoreDescriptor(cc, "core1", "./collection1", "configSet", "minimal");+ cc.create(descriptor1);++ class TestThread extends Thread {+ @Override+ public void run() {+ cc.reload("core1");}+ }- List<Thread> threads = new ArrayList<>();- int numThreads = 4;- for (int i = 0; i < numThreads; i++) {- threads.add(new TestThread());- }+ List<Thread> threads = new ArrayList<>();+ int numThreads = 4;+ for (int i = 0; i < numThreads; i++) {+ threads.add(new TestThread());+ }- for (Thread thread : threads) {- thread.start();- }+ for (Thread thread : threads) {+ thread.start();+ }- for (Thread thread : threads) {- thread.join();+ for (Thread thread : threads) {+ thread.join();}cc.shutdown();}+ @Test+ public void testNoCores() throws Exception {+ CoreContainer cores = init(CONFIGSETS_SOLR_XML);- @Test- public void testNoCores() throws IOException, ParserConfigurationException, SAXException {- //create solrHome- File solrHomeDirectory = createTempDir().toFile();-- boolean oldSolrXml = random().nextBoolean();-- SetUpHome(solrHomeDirectory, oldSolrXml ? EMPTY_SOLR_XML : EMPTY_SOLR_XML2);- CoreContainer cores = new CoreContainer(solrHomeDirectory.getAbsolutePath());- cores.load();try {//assert zero coresassertEquals("There should not be cores", 0, cores.getCores().size());- FileUtils.copyDirectory(new File(SolrTestCaseJ4.TEST_HOME(), "collection1"), solrHomeDirectory);//add a new core- CoreDescriptor coreDescriptor = new CoreDescriptor(cores, "core1", solrHomeDirectory.getAbsolutePath());+ CoreDescriptor coreDescriptor = new CoreDescriptor(cores, "core1", "collection1", CoreDescriptor.CORE_CONFIGSET, "minimal");SolrCore newCore = cores.create(coreDescriptor);//assert one registered coreassertEquals("There core registered", 1, cores.getCores().size());- if (oldSolrXml) {- assertXmlFile(new File(solrHomeDirectory, "solr.xml"),- "/solr/cores[@transientCacheSize='32']");- }-cores.unload("core1");//assert cero coresassertEquals("There should not be cores", 0, cores.getCores().size());@@ -193,27 +184,14 @@ public class TestCoreContainer extends SolrTestCaseJ4 {}@Test- public void testLogWatcherEnabledByDefault() {- assertNotNull(h.getCoreContainer().getLogging());- }-- private void SetUpHome(File solrHomeDirectory, String xmlFile) throws IOException {- if (solrHomeDirectory.exists()) {- FileUtils.deleteDirectory(solrHomeDirectory);- }- assertTrue("Failed to mkdirs workDir", solrHomeDirectory.mkdirs());+ public void testLogWatcherEnabledByDefault() throws Exception {+ CoreContainer cc = init("<solr></solr>");try {- File solrXmlFile = new File(solrHomeDirectory, "solr.xml");- BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(solrXmlFile), StandardCharsets.UTF_8));- out.write(xmlFile);- out.close();- } catch (IOException e) {- FileUtils.deleteDirectory(solrHomeDirectory);- throw e;+ assertNotNull(cc.getLogging());+ }+ finally {+ cc.shutdown();}-- //init- System.setProperty(SOLR_HOME_PROP, solrHomeDirectory.getAbsolutePath());}@Test@@ -221,13 +199,12 @@ public class TestCoreContainer extends SolrTestCaseJ4 {MockCoresLocator cl = new MockCoresLocator();- solrHomeDirectory = createTempDir("_deleteBadCores").toFile();- SolrResourceLoader resourceLoader = new SolrResourceLoader(solrHomeDirectory.getAbsolutePath());- File instanceDir = new File(solrHomeDirectory, "_deleteBadCores");+ SolrResourceLoader resourceLoader = new SolrResourceLoader(createTempDir().toString());+System.setProperty("configsets", getFile("solr/configsets").getAbsolutePath());- final CoreContainer cc = new CoreContainer(resourceLoader, ConfigSolr.fromString(resourceLoader, EMPTY_SOLR_XML2), cl);- CoreDescriptor badcore = new CoreDescriptor(cc, "badcore", instanceDir.getAbsolutePath(), "configSet", "nosuchconfigset");+ final CoreContainer cc = new CoreContainer(ConfigSolr.fromString(resourceLoader, CONFIGSETS_SOLR_XML), cl);+ CoreDescriptor badcore = new CoreDescriptor(cc, "badcore", "badcore", "configSet", "nosuchconfigset");cl.add(badcore);try {@@ -238,7 +215,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {assertThat(cc.getCoreInitFailures().size(), is(0));// can we create the core now with a good config?- SolrCore core = cc.create(new CoreDescriptor(cc, "badcore", instanceDir.getAbsolutePath(), "configSet", "minimal"));+ SolrCore core = cc.create(new CoreDescriptor(cc, "badcore", "badcore", "configSet", "minimal"));assertThat(core, not(nullValue()));}@@ -249,13 +226,13 @@ public class TestCoreContainer extends SolrTestCaseJ4 {@Testpublic void testClassLoaderHierarchy() throws Exception {- final CoreContainer cc = init("_classLoaderHierarchy");+ final CoreContainer cc = init(CONFIGSETS_SOLR_XML);try {ClassLoader sharedLoader = cc.loader.getClassLoader();ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();assertSame(contextLoader, sharedLoader.getParent());- CoreDescriptor descriptor1 = new CoreDescriptor(cc, "core1", "./collection1");+ CoreDescriptor descriptor1 = new CoreDescriptor(cc, "core1", "./collection1", "configSet", "minimal");SolrCore core1 = cc.create(descriptor1);ClassLoader coreLoader = core1.getResourceLoader().getClassLoader();assertSame(sharedLoader, coreLoader.getParent());@@ -267,9 +244,9 @@ public class TestCoreContainer extends SolrTestCaseJ4 {@Testpublic void testSharedLib() throws Exception {- File tmpRoot = createTempDir("testSharedLib").toFile();+ Path tmpRoot = createTempDir("testSharedLib");- File lib = new File(tmpRoot, "lib");+ File lib = new File(tmpRoot.toFile(), "lib");lib.mkdirs();JarOutputStream jar1 = new JarOutputStream(new FileOutputStream(new File(lib, "jar1.jar")));@@ -277,7 +254,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {jar1.closeEntry();jar1.close();- File customLib = new File(tmpRoot, "customLib");+ File customLib = new File(tmpRoot.toFile(), "customLib");customLib.mkdirs();JarOutputStream jar2 = new JarOutputStream(new FileOutputStream(new File(customLib, "jar2.jar")));@@ -285,41 +262,32 @@ public class TestCoreContainer extends SolrTestCaseJ4 {jar2.closeEntry();jar2.close();- FileUtils.writeStringToFile(new File(tmpRoot, "default-lib-solr.xml"), "<solr><cores/></solr>", "UTF-8");- FileUtils.writeStringToFile(new File(tmpRoot, "explicit-lib-solr.xml"), "<solr sharedLib=\"lib\"><cores/></solr>", "UTF-8");- FileUtils.writeStringToFile(new File(tmpRoot, "custom-lib-solr.xml"), "<solr sharedLib=\"customLib\"><cores/></solr>", "UTF-8");-- final CoreContainer cc1 = CoreContainer.createAndLoad(tmpRoot.getAbsolutePath(), new File(tmpRoot, "default-lib-solr.xml"));+ final CoreContainer cc1 = init(tmpRoot, "<solr></solr>");try {cc1.loader.openResource("defaultSharedLibFile").close();} finally {cc1.shutdown();}- final CoreContainer cc2 = CoreContainer.createAndLoad(tmpRoot.getAbsolutePath(), new File(tmpRoot, "explicit-lib-solr.xml"));+ final CoreContainer cc2 = init(tmpRoot, "<solr><str name=\"sharedLib\">lib</str></solr>");try {cc2.loader.openResource("defaultSharedLibFile").close();} finally {cc2.shutdown();}- final CoreContainer cc3 = CoreContainer.createAndLoad(tmpRoot.getAbsolutePath(), new File(tmpRoot, "custom-lib-solr.xml"));+ final CoreContainer cc3 = init(tmpRoot, "<solr><str name=\"sharedLib\">customLib</str></solr>");try {cc3.loader.openResource("customSharedLibFile").close();} finally {cc3.shutdown();}}-- private static final String EMPTY_SOLR_XML ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +- "<solr persistent=\"false\">\n" +- " <cores adminPath=\"/admin/cores\" transientCacheSize=\"32\" >\n" +- " </cores>\n" +- "</solr>";-- private static final String EMPTY_SOLR_XML2 ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +++ private static final String CONFIGSETS_SOLR_XML ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +"<solr>\n" +- "<str name=\"configSetBaseDir\">${configsets:configsets}</str>" ++ "<str name=\"configSetBaseDir\">${configsets:configsets}</str>\n" ++ "<str name=\"shareSchema\">${shareSchema:false}</str>\n" +"</solr>";private static final String CUSTOM_HANDLERS_SOLR_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +@@ -350,12 +318,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {@Testpublic void testCustomHandlers() throws Exception {- solrHomeDirectory = createTempDir("_customHandlers").toFile();- SolrResourceLoader loader = new SolrResourceLoader(solrHomeDirectory.getAbsolutePath());-- ConfigSolr config = ConfigSolr.fromString(loader, CUSTOM_HANDLERS_SOLR_XML);-- CoreContainer cc = new CoreContainer(loader, config);+ CoreContainer cc = init(CUSTOM_HANDLERS_SOLR_XML);try {cc.load();assertThat(cc.getCollectionsHandler(), is(instanceOf(CustomCollectionsHandler.class)));@@ -406,4 +369,262 @@ public class TestCoreContainer extends SolrTestCaseJ4 {return cores;}}++ @Test+ public void testCoreInitFailuresFromEmptyContainer() throws Exception {+ // reused state+ Map<String,CoreContainer.CoreLoadFailure> failures = null;+ Collection<String> cores = null;+ Exception fail = null;++ // ----+ // init the CoreContainer+ CoreContainer cc = init(CONFIGSETS_SOLR_XML);++ // check that we have the cores we expect+ cores = cc.getCoreNames();+ assertNotNull("core names is null", cores);+ assertEquals("wrong number of cores", 0, cores.size());++ // check that we have the failures we expect+ failures = cc.getCoreInitFailures();+ assertNotNull("core failures is a null map", failures);+ assertEquals("wrong number of core failures", 0, failures.size());++ // -----+ // try to add a collection with a path that doesn't exist+ final CoreDescriptor bogus = new CoreDescriptor(cc, "bogus", "bogus_path");+ try {+ ignoreException(Pattern.quote("bogus_path"));+ cc.create(bogus);+ fail("bogus inst dir failed to trigger exception from create");+ } catch (SolrException e) {+ assertTrue("init exception doesn't mention bogus dir: " + e.getCause().getCause().getMessage(),+ 0 < e.getCause().getCause().getMessage().indexOf("bogus_path"));++ }++ // check that we have the cores we expect+ cores = cc.getCoreNames();+ assertNotNull("core names is null", cores);+ assertEquals("wrong number of cores", 0, cores.size());++ // check that we have the failures we expect+ failures = cc.getCoreInitFailures();+ assertNotNull("core failures is a null map", failures);+ assertEquals("wrong number of core failures", 1, failures.size());+ fail = failures.get("bogus").exception;+ assertNotNull("null failure for test core", fail);+ assertTrue("init failure doesn't mention problem: " + fail.getCause().getMessage(),+ 0 < fail.getCause().getMessage().indexOf("bogus_path"));++ // check that we get null accessing a non-existent core+ assertNull(cc.getCore("does_not_exist"));+ // check that we get a 500 accessing the core with an init failure+ try {+ SolrCore c = cc.getCore("bogus");+ fail("Failed to get Exception on accessing core with init failure");+ } catch (SolrException ex) {+ assertEquals(500, ex.code());+ // double wrapped+ String cause = ex.getCause().getCause().getMessage();+ assertTrue("getCore() ex cause doesn't mention init fail: " + cause,+ 0 < cause.indexOf("bogus_path"));++ }++ cc.shutdown();+ }++ @Test+ public void testCoreInitFailuresOnReload() throws Exception {++ // reused state+ Map<String,CoreContainer.CoreLoadFailure> failures = null;+ Collection<String> cores = null;+ Exception fail = null;++ // -----+ // init the CoreContainer with the mix of ok/bad cores+ MockCoresLocator cl = new MockCoresLocator();++ SolrResourceLoader resourceLoader = new SolrResourceLoader(createTempDir().toString());++ System.setProperty("configsets", getFile("solr/configsets").getAbsolutePath());++ final CoreContainer cc = new CoreContainer(ConfigSolr.fromString(resourceLoader, CONFIGSETS_SOLR_XML), cl);+ cl.add(new CoreDescriptor(cc, "col_ok", "col_ok", "configSet", "minimal"));+ cl.add(new CoreDescriptor(cc, "col_bad", "col_bad", "configSet", "bad-mergepolicy"));+ cc.load();++ // check that we have the cores we expect+ cores = cc.getCoreNames();+ assertNotNull("core names is null", cores);+ assertEquals("wrong number of cores", 1, cores.size());+ assertTrue("col_ok not found", cores.contains("col_ok"));++ // check that we have the failures we expect+ failures = cc.getCoreInitFailures();+ assertNotNull("core failures is a null map", failures);+ assertEquals("wrong number of core failures", 1, failures.size());+ fail = failures.get("col_bad").exception;+ assertNotNull("null failure for test core", fail);+ assertTrue("init failure doesn't mention problem: " + fail.getMessage(),+ 0 < fail.getMessage().indexOf("DummyMergePolicy"));++ // check that we get null accessing a non-existent core+ assertNull(cc.getCore("does_not_exist"));+ // check that we get a 500 accessing the core with an init failure+ try {+ SolrCore c = cc.getCore("col_bad");+ fail("Failed to get Exception on accessing core with init failure");+ } catch (SolrException ex) {+ assertEquals(500, ex.code());+ // double wrapped+ String cause = ex.getCause().getCause().getMessage();+ assertTrue("getCore() ex cause doesn't mention init fail: " + cause,+ 0 < cause.indexOf("DummyMergePolicy"));+ }++ // -----+ // "fix" the bad collection+ FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-defaults.xml"),+ FileUtils.getFile(cc.getSolrHome(), "col_bad", "conf", "solrconfig.xml"));+ FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),+ FileUtils.getFile(cc.getSolrHome(), "col_bad", "conf", "schema.xml"));+ final CoreDescriptor fixed = new CoreDescriptor(cc, "col_bad", "col_bad");+ cc.create(fixed);++ // check that we have the cores we expect+ cores = cc.getCoreNames();+ assertNotNull("core names is null", cores);+ assertEquals("wrong number of cores", 2, cores.size());+ assertTrue("col_ok not found", cores.contains("col_ok"));+ assertTrue("col_bad not found", cores.contains("col_bad"));++ // check that we have the failures we expect+ failures = cc.getCoreInitFailures();+ assertNotNull("core failures is a null map", failures);+ assertEquals("wrong number of core failures", 0, failures.size());+++ // -----+ // try to add a collection with a path that doesn't exist+ final CoreDescriptor bogus = new CoreDescriptor(cc, "bogus", "bogus_path");+ try {+ ignoreException(Pattern.quote("bogus_path"));+ cc.create(bogus);+ fail("bogus inst dir failed to trigger exception from create");+ } catch (SolrException e) {+ assertTrue("init exception doesn't mention bogus dir: " + e.getCause().getCause().getMessage(),+ 0 < e.getCause().getCause().getMessage().indexOf("bogus_path"));++ }++ // check that we have the cores we expect+ cores = cc.getCoreNames();+ assertNotNull("core names is null", cores);+ assertEquals("wrong number of cores", 2, cores.size());+ assertTrue("col_ok not found", cores.contains("col_ok"));+ assertTrue("col_bad not found", cores.contains("col_bad"));++ // check that we have the failures we expect+ failures = cc.getCoreInitFailures();+ assertNotNull("core failures is a null map", failures);+ assertEquals("wrong number of core failures", 1, failures.size());+ fail = failures.get("bogus").exception;+ assertNotNull("null failure for test core", fail);+ assertTrue("init failure doesn't mention problem: " + fail.getCause().getMessage(),+ 0 < fail.getCause().getMessage().indexOf("bogus_path"));++ // check that we get null accessing a non-existent core+ assertNull(cc.getCore("does_not_exist"));+ // check that we get a 500 accessing the core with an init failure+ try {+ SolrCore c = cc.getCore("bogus");+ fail("Failed to get Exception on accessing core with init failure");+ } catch (SolrException ex) {+ assertEquals(500, ex.code());+ // double wrapped+ String cause = ex.getCause().getCause().getMessage();+ assertTrue("getCore() ex cause doesn't mention init fail: " + cause,+ 0 < cause.indexOf("bogus_path"));+ }++ // -----+ // break col_bad's config and try to RELOAD to add failure++ final long col_bad_old_start = getCoreStartTime(cc, "col_bad");++ FileUtils.write+ (FileUtils.getFile(cc.getSolrHome(), "col_bad", "conf", "solrconfig.xml"),+ "This is giberish, not valid XML <",+ IOUtils.UTF_8);++ try {+ ignoreException(Pattern.quote("SAX"));+ cc.reload("col_bad");+ fail("corrupt solrconfig.xml failed to trigger exception from reload");+ } catch (SolrException e) {+ Throwable rootException = getWrappedException(e);+ assertTrue("We're supposed to have a wrapped SAXParserException here, but we don't",+ rootException instanceof SAXParseException);+ SAXParseException se = (SAXParseException) rootException;+ assertTrue("reload exception doesn't refer to slrconfig.xml " + se.getSystemId(),+ 0 < se.getSystemId().indexOf("solrconfig.xml"));++ }++ assertEquals("Failed core reload should not have changed start time",+ col_bad_old_start, getCoreStartTime(cc, "col_bad"));++ // check that we have the cores we expect+ cores = cc.getCoreNames();+ assertNotNull("core names is null", cores);+ assertEquals("wrong number of cores", 2, cores.size());+ assertTrue("col_ok not found", cores.contains("col_ok"));+ assertTrue("col_bad not found", cores.contains("col_bad"));++ // check that we have the failures we expect+ failures = cc.getCoreInitFailures();+ assertNotNull("core failures is a null map", failures);+ assertEquals("wrong number of core failures", 2, failures.size());+ Throwable ex = getWrappedException(failures.get("col_bad").exception);+ assertNotNull("null failure for test core", ex);+ assertTrue("init failure isn't SAXParseException",+ ex instanceof SAXParseException);+ SAXParseException saxEx = (SAXParseException) ex;+ assertTrue("init failure doesn't mention problem: " + saxEx.toString(), saxEx.getSystemId().contains("solrconfig.xml"));++ // ----+ // fix col_bad's config (again) and RELOAD to fix failure+ FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-defaults.xml"),+ FileUtils.getFile(cc.getSolrHome(), "col_bad", "conf", "solrconfig.xml"));+ cc.reload("col_bad");++ assertTrue("Core reload should have changed start time",+ col_bad_old_start < getCoreStartTime(cc, "col_bad"));+++ // check that we have the cores we expect+ cores = cc.getCoreNames();+ assertNotNull("core names is null", cores);+ assertEquals("wrong number of cores", 2, cores.size());+ assertTrue("col_ok not found", cores.contains("col_ok"));+ assertTrue("col_bad not found", cores.contains("col_bad"));++ // check that we have the failures we expect+ failures = cc.getCoreInitFailures();+ assertNotNull("core failures is a null map", failures);+ assertEquals("wrong number of core failures", 1, failures.size());++ cc.shutdown();++ }++ private long getCoreStartTime(final CoreContainer cc, final String name) {+ try (SolrCore tmp = cc.getCore(name)) {+ return tmp.getStartTime();+ }+ }}diff --git a/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java b/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.javaindex 95caf0edb27..96c7f5288cc 100644--- a/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java+++ b/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java@@ -140,8 +140,6 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {CoreContainer cc = init();try {- assertEquals(ConfigSolrXmlOld.DEFAULT_DEFAULT_CORE_NAME,- cc.getDefaultCoreName());TestLazyCores.checkInCores(cc, "core1");TestLazyCores.checkNotInCores(cc, "lazy1", "core2", "collection1");diff --git a/solr/core/src/test/org/apache/solr/core/TestImplicitCoreProperties.java b/solr/core/src/test/org/apache/solr/core/TestImplicitCoreProperties.javaindex 9768221785e..b38ec0681b9 100644--- a/solr/core/src/test/org/apache/solr/core/TestImplicitCoreProperties.java+++ b/solr/core/src/test/org/apache/solr/core/TestImplicitCoreProperties.java@@ -1,7 +1,6 @@package org.apache.solr.core;import org.apache.solr.SolrTestCaseJ4;-import java.io.File;import org.junit.Test;/*@@ -22,17 +21,16 @@ import org.junit.Test;*/public class TestImplicitCoreProperties extends SolrTestCaseJ4 {- public static final String SOLRXML =- "<solr><cores><core name=\"collection1\" instanceDir=\"collection1\" config=\"solrconfig-implicitproperties.xml\"/></cores></solr>";-@Testpublic void testImplicitPropertiesAreSubstitutedInSolrConfig() {- CoreContainer cc = createCoreContainer(TEST_HOME(), SOLRXML);+ CoreContainer cc+ = createCoreContainer("collection1", "data", "solrconfig-implicitproperties.xml", "schema.xml");+try {assertQ(req("q", "*:*"), "//str[@name='dummy1'][.='collection1']"- , "//str[@name='dummy2'][.='data"+File.separator+"']"+ , "//str[@name='dummy2'][.='data']", "//str[@name='dummy3'][.='solrconfig-implicitproperties.xml']", "//str[@name='dummy4'][.='schema.xml']", "//str[@name='dummy5'][.='false']"diff --git a/solr/core/src/test/org/apache/solr/core/TestLazyCores.java b/solr/core/src/test/org/apache/solr/core/TestLazyCores.javaindex befd579993b..e15dcb63212 100644--- a/solr/core/src/test/org/apache/solr/core/TestLazyCores.java+++ b/solr/core/src/test/org/apache/solr/core/TestLazyCores.java@@ -17,9 +17,10 @@ package org.apache.solr.core;* limitations under the License.*/-import org.apache.commons.lang.StringUtils;+import com.google.common.collect.ImmutableList;import org.apache.commons.codec.Charsets;import org.apache.commons.io.FileUtils;+import org.apache.commons.lang.StringUtils;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.common.SolrException;import org.apache.solr.common.params.CoreAdminParams;@@ -31,9 +32,7 @@ import org.apache.solr.response.SolrQueryResponse;import org.apache.solr.update.AddUpdateCommand;import org.apache.solr.update.CommitUpdateCommand;import org.apache.solr.update.UpdateHandler;-import org.apache.solr.util.TestHarness;-import org.junit.Before;-import org.junit.BeforeClass;+import org.apache.solr.util.ReadOnlyCoresLocator;import org.junit.Test;import java.io.File;@@ -48,18 +47,7 @@ import java.util.regex.Pattern;public class TestLazyCores extends SolrTestCaseJ4 {- @BeforeClass- public static void beforeClass() throws Exception {- initCore("solrconfig-minimal.xml", "schema-tiny.xml");- }-private File solrHomeDirectory;-- @Before- @Override- public void setUp() throws Exception {- super.setUp();- }private CoreContainer init() throws Exception {solrHomeDirectory = createTempDir().toFile();@@ -69,17 +57,7 @@ public class TestLazyCores extends SolrTestCaseJ4 {}SolrResourceLoader loader = new SolrResourceLoader(solrHomeDirectory.getAbsolutePath());-- File solrXml = new File(solrHomeDirectory, "solr.xml");- FileUtils.write(solrXml, LOTS_SOLR_XML, Charsets.UTF_8.toString());- ConfigSolrXmlOld config = (ConfigSolrXmlOld) ConfigSolr.fromFile(loader, solrXml);-- CoresLocator locator = new SolrXMLCoresLocator.NonPersistingLocator(LOTS_SOLR_XML, config);--- final CoreContainer cores = new CoreContainer(loader, config, locator);- cores.load();- return cores;+ return createCoreContainer(new LazyCoreTestConfig(loader));}@Test@@ -172,14 +150,16 @@ public class TestLazyCores extends SolrTestCaseJ4 {// Now just insure that the normal searching on "collection1" finds _0_ on the same query that found _2_ above.// Use of makeReq above and req below is tricky, very tricky.+ SolrCore collection1 = cc.getCore("collection1");assertQ("test raw query",- req("q", "{!raw f=v_t}hello", "wt", "xml")+ makeReq(collection1, "q", "{!raw f=v_t}hello", "wt", "xml"), "//result[@numFound='0']");checkInCores(cc, "collectionLazy4");core4.close();+ collection1.close();} finally {cc.shutdown();}@@ -411,72 +391,6 @@ public class TestLazyCores extends SolrTestCaseJ4 {}}-- //Make sure persisting not-loaded lazy cores is done. See SOLR-4347-- @Test- public void testPersistence() throws Exception {- final CoreContainer cc = init();- try {- copyMinConf(new File(solrHomeDirectory, "core1"));- copyMinConf(new File(solrHomeDirectory, "core2"));- copyMinConf(new File(solrHomeDirectory, "core3"));- copyMinConf(new File(solrHomeDirectory, "core4"));-- final CoreDescriptor cd1 = buildCoreDescriptor(cc, "core1", "./core1")- .isTransient(true).loadOnStartup(true).build();- final CoreDescriptor cd2 = buildCoreDescriptor(cc, "core2", "./core2")- .isTransient(true).loadOnStartup(false).build();- final CoreDescriptor cd3 = buildCoreDescriptor(cc, "core3", "./core3")- .isTransient(false).loadOnStartup(true).build();- final CoreDescriptor cd4 = buildCoreDescriptor(cc, "core4", "./core4")- .isTransient(false).loadOnStartup(false).build();--- SolrCore core1 = cc.create(cd1);- SolrCore core2 = cc.create(cd2);- SolrCore core3 = cc.create(cd3);- SolrCore core4 = cc.create(cd4);-- SolrXMLCoresLocator.NonPersistingLocator locator =- (SolrXMLCoresLocator.NonPersistingLocator) cc.getCoresLocator();-- TestHarness.validateXPath(locator.xml,- "/solr/cores/core[@name='collection1']",- "/solr/cores/core[@name='collectionLazy2']",- "/solr/cores/core[@name='collectionLazy3']",- "/solr/cores/core[@name='collectionLazy4']",- "/solr/cores/core[@name='collectionLazy5']",- "/solr/cores/core[@name='collectionLazy6']",- "/solr/cores/core[@name='collectionLazy7']",- "/solr/cores/core[@name='collectionLazy8']",- "/solr/cores/core[@name='collectionLazy9']",- "/solr/cores/core[@name='core1']",- "/solr/cores/core[@name='core2']",- "/solr/cores/core[@name='core3']",- "/solr/cores/core[@name='core4']",- "13=count(/solr/cores/core)");-- removeOne(cc, "collectionLazy2");- removeOne(cc, "collectionLazy3");- removeOne(cc, "collectionLazy4");- removeOne(cc, "collectionLazy5");- removeOne(cc, "collectionLazy6");- removeOne(cc, "collectionLazy7");- removeOne(cc, "core1");- removeOne(cc, "core2");- removeOne(cc, "core3");- removeOne(cc, "core4");-- // now test that unloading a core means the core is not persisted- TestHarness.validateXPath(locator.xml, "3=count(/solr/cores/core)");-- } finally {- cc.shutdown();- }- }--// Test that transient cores// 1> produce errors as appropriate when the config or schema files are foo'd// 2> "self heal". That is, if the problem is corrected can the core be reloaded and used?@@ -627,12 +541,8 @@ public class TestLazyCores extends SolrTestCaseJ4 {SolrResourceLoader loader = new SolrResourceLoader(solrHomeDirectory.getAbsolutePath());ConfigSolrXml config = (ConfigSolrXml) ConfigSolr.fromFile(loader, solrXml);- CoresLocator locator = new CorePropertiesLocator(solrHomeDirectory.getAbsolutePath());-// OK this should succeed, but at the end we should have recorded a series of errors.- final CoreContainer cores = new CoreContainer(loader, config, locator);- cores.load();- return cores;+ return createCoreContainer(config);}// We want to see that the core "heals itself" if an un-corrupted file is written to the directory.@@ -669,9 +579,6 @@ public class TestLazyCores extends SolrTestCaseJ4 {}}- private void removeOne(CoreContainer cc, String coreName) {- cc.unload(coreName);- }public static void checkNotInCores(CoreContainer cc, String... nameCheck) {Collection<String> names = cc.getCoreNames();for (String name : nameCheck) {@@ -712,26 +619,51 @@ public class TestLazyCores extends SolrTestCaseJ4 {return StringUtils.join(args, File.separator);}- private final static String LOTS_SOLR_XML = " <solr persistent=\"false\"> " +- "<cores adminPath=\"/admin/cores\" defaultCoreName=\"collectionLazy2\" transientCacheSize=\"4\"> " +- "<core name=\"collection1\" instanceDir=\"collection1\" /> " ++ public static class LazyCoreTestConfig extends ConfigSolr {- "<core name=\"collectionLazy2\" instanceDir=\"collection2\" transient=\"true\" loadOnStartup=\"true\" /> " +-- "<core name=\"collectionLazy3\" instanceDir=\"collection3\" transient=\"on\" loadOnStartup=\"false\" /> " +-- "<core name=\"collectionLazy4\" instanceDir=\"collection4\" transient=\"false\" loadOnStartup=\"false\" /> " +-- "<core name=\"collectionLazy5\" instanceDir=\"collection5\" transient=\"false\" loadOnStartup=\"true\" /> " ++ public LazyCoreTestConfig(SolrResourceLoader loader) {+ super(loader, null);+ }- "<core name=\"collectionLazy6\" instanceDir=\"collection6\" transient=\"true\" loadOnStartup=\"false\" /> " ++ static CoreDescriptor makeCoreDescriptor(CoreContainer cc, String coreName, String instanceDir, String isTransient, String loadOnStartup) {+ return new CoreDescriptor(cc, coreName, instanceDir,+ CoreDescriptor.CORE_TRANSIENT, isTransient,+ CoreDescriptor.CORE_LOADONSTARTUP, loadOnStartup);+ }- "<core name=\"collectionLazy7\" instanceDir=\"collection7\" transient=\"true\" loadOnStartup=\"false\" /> " ++ @Override+ public CoresLocator getCoresLocator() {+ return new ReadOnlyCoresLocator() {+ @Override+ public List<CoreDescriptor> discover(CoreContainer cc) {+ return ImmutableList.of(+ new CoreDescriptor(cc, "collection1", "collection1"),+ makeCoreDescriptor(cc, "collectionLazy2", "collection2", "true", "true"),+ makeCoreDescriptor(cc, "collectionLazy3", "collection3", "on", "false"),+ makeCoreDescriptor(cc, "collectionLazy4", "collection4", "false", "false"),+ makeCoreDescriptor(cc, "collectionLazy5", "collection5", "false", "true"),+ makeCoreDescriptor(cc, "collectionLazy6", "collection6", "true", "false"),+ makeCoreDescriptor(cc, "collectionLazy7", "collection7", "true", "false"),+ makeCoreDescriptor(cc, "collectionLazy8", "collection8", "true", "false"),+ makeCoreDescriptor(cc, "collectionLazy9", "collection9", "true", "false")+ );+ }+ };+ }- "<core name=\"collectionLazy8\" instanceDir=\"collection8\" transient=\"true\" loadOnStartup=\"false\" /> " ++ @Override+ public PluginInfo getShardHandlerFactoryPluginInfo() {+ return null;+ }- "<core name=\"collectionLazy9\" instanceDir=\"collection9\" transient=\"true\" loadOnStartup=\"false\" /> " ++ @Override+ protected String getProperty(CfgProp key) {+ switch (key) {+ case SOLR_TRANSIENTCACHESIZE:+ return "4";+ }+ return null;+ }+ }- "</cores> " +- "</solr>";}diff --git a/solr/core/src/test/org/apache/solr/core/TestShardHandlerFactory.java b/solr/core/src/test/org/apache/solr/core/TestShardHandlerFactory.javaindex 778b23b14ef..849146800c7 100644--- a/solr/core/src/test/org/apache/solr/core/TestShardHandlerFactory.java+++ b/solr/core/src/test/org/apache/solr/core/TestShardHandlerFactory.java@@ -38,13 +38,4 @@ public class TestShardHandlerFactory extends SolrTestCaseJ4 {cc.shutdown();}- public void testOldXML() throws Exception {- CoreContainer cc = CoreContainer.createAndLoad(TEST_HOME(), new File(TEST_HOME(), "solr-shardhandler-old.xml"));- ShardHandlerFactory factory = cc.getShardHandlerFactory();- assertTrue(factory instanceof MockShardHandlerFactory);- NamedList args = ((MockShardHandlerFactory)factory).args;- assertEquals("myMagicRequiredValue", args.get("myMagicRequiredParameter"));- factory.close();- cc.shutdown();- }}diff --git a/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java b/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.javaindex 443f71cbab6..49500093228 100644--- a/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java+++ b/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java@@ -18,30 +18,10 @@ package org.apache.solr.core;*/-import java.io.File;-import java.io.IOException;-import java.io.StringReader;-import java.nio.charset.StandardCharsets;-import java.text.MessageFormat;-import java.util.ArrayList;-import java.util.Arrays;-import java.util.Collections;-import java.util.List;-import java.util.Map;-import java.util.Objects;-import java.util.SortedMap;-import java.util.TreeMap;-import java.util.concurrent.TimeUnit;-import com.google.common.collect.ImmutableList;import org.apache.commons.io.FileUtils;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.client.solrj.impl.CloudSolrClient;-import org.apache.solr.common.cloud.DocCollection;-import org.apache.solr.common.cloud.Replica;-import org.apache.solr.common.cloud.Slice;-import org.apache.solr.common.cloud.ZkStateReader;-import org.apache.solr.handler.TestBlobHandler;import org.apache.solr.handler.TestSolrConfigHandlerConcurrent;import org.apache.solr.util.RestTestBase;import org.apache.solr.util.RestTestHarness;@@ -54,6 +34,19 @@ import org.restlet.ext.servlet.ServerServlet;import org.slf4j.Logger;import org.slf4j.LoggerFactory;+import java.io.File;+import java.io.IOException;+import java.io.StringReader;+import java.text.MessageFormat;+import java.util.Arrays;+import java.util.Collections;+import java.util.List;+import java.util.Map;+import java.util.Objects;+import java.util.SortedMap;+import java.util.TreeMap;+import java.util.concurrent.TimeUnit;+import static org.apache.solr.core.ConfigOverlay.getObjectByPath;import static org.apache.solr.handler.TestBlobHandler.getAsString;diff --git a/solr/core/src/test/org/apache/solr/core/TestSolrXml.java b/solr/core/src/test/org/apache/solr/core/TestSolrXml.javaindex 4327ec0a4ac..9855bcd10fd 100644--- a/solr/core/src/test/org/apache/solr/core/TestSolrXml.java+++ b/solr/core/src/test/org/apache/solr/core/TestSolrXml.java@@ -88,8 +88,6 @@ public class TestSolrXml extends SolrTestCaseJ4 {assertEquals("trans cache size", 66, cfg.getTransientCacheSize());assertEquals("zk client timeout", 77, cfg.getZkClientTimeout());assertEquals("zk host", "testZkHost", cfg.getZkHost());- assertEquals("persistent", true, cfg.isPersistent());- assertEquals("core admin path", ConfigSolr.DEFAULT_CORE_ADMIN_PATH, cfg.getAdminPath());}// Test a few property substitutions that happen to be in solr-50-all.xml.diff --git a/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistence.java b/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistence.javadeleted file mode 100644index 2e43e61f3ca..00000000000--- a/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistence.java+++ /dev/null@@ -1,613 +0,0 @@-/*- * 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.- */--package org.apache.solr.core;--import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;-import org.apache.commons.io.FileUtils;-import org.apache.commons.lang.StringUtils;-import org.apache.lucene.util.IOUtils;-import org.apache.lucene.util.LuceneTestCase;-import org.apache.solr.SolrTestCaseJ4;-import org.apache.solr.common.params.CoreAdminParams;-import org.apache.solr.handler.admin.CoreAdminHandler;-import org.apache.solr.response.SolrQueryResponse;-import org.apache.solr.util.TestHarness;-import org.junit.Before;-import org.junit.Rule;-import org.junit.Test;-import org.junit.rules.RuleChain;-import org.junit.rules.TestRule;-import org.w3c.dom.Document;-import org.w3c.dom.NamedNodeMap;-import org.w3c.dom.Node;-import org.w3c.dom.NodeList;-import org.xml.sax.SAXException;--import javax.xml.parsers.DocumentBuilder;-import javax.xml.parsers.DocumentBuilderFactory;-import javax.xml.parsers.ParserConfigurationException;-import java.io.ByteArrayInputStream;-import java.io.File;-import java.io.FileInputStream;-import java.io.IOException;-import java.io.InputStream;-import java.nio.charset.StandardCharsets;-import java.util.ArrayList;-import java.util.List;--import static org.hamcrest.core.Is.is;--public class TestSolrXmlPersistence extends SolrTestCaseJ4 {-- private File solrHomeDirectory = createTempDir().toFile();-- @Rule- public TestRule solrTestRules =- RuleChain.outerRule(new SystemPropertiesRestoreRule());-- @Before- public void setupTest() {- solrHomeDirectory = createTempDir(LuceneTestCase.getTestClass().getSimpleName()).toFile();- }-- private CoreContainer init(String solrXmlString, String... subDirs) throws Exception {-- for (String s : subDirs) {- copyMinConf(new File(solrHomeDirectory, s));- }-- File solrXml = new File(solrHomeDirectory, "solr.xml");- FileUtils.write(solrXml, solrXmlString, IOUtils.UTF_8);-- final CoreContainer cores = createCoreContainer(solrHomeDirectory.getAbsolutePath(), solrXmlString);- return cores;- }--- // take a solr.xml with system vars in <solr>, <cores> and <core> and <core/properties> tags that have system- // variables defined. Insure that after persisting solr.xml, they're all still there as ${} syntax.- // Also insure that nothing extra crept in.- @Test- public void testSystemVars() throws Exception {- //Set these system props in order to insure that we don't write out the values rather than the ${} syntax.- System.setProperty("solr.zkclienttimeout", "93");- System.setProperty("solrconfig", "solrconfig.xml");- System.setProperty("schema", "schema.xml");- System.setProperty("zkHostSet", "localhost:9983");-- CoreContainer cc = init(SOLR_XML_LOTS_SYSVARS, "SystemVars1", "SystemVars2");- try {- origMatchesPersist(cc, SOLR_XML_LOTS_SYSVARS);- } finally {- cc.shutdown();- }- }-- @Test- public void testReload() throws Exception {- // Whether the core is transient or not can make a difference.- doReloadTest("SystemVars2");- doReloadTest("SystemVars1");-- }-- private void doReloadTest(String which) throws Exception {-- CoreContainer cc = init(SOLR_XML_LOTS_SYSVARS, "SystemVars1", "SystemVars2");- try {- final CoreAdminHandler admin = new CoreAdminHandler(cc);- SolrQueryResponse resp = new SolrQueryResponse();- admin.handleRequestBody- (req(CoreAdminParams.ACTION,- CoreAdminParams.CoreAdminAction.RELOAD.toString(),- CoreAdminParams.CORE, which),- resp);- assertNull("Exception on reload", resp.getException());-- origMatchesPersist(cc, SOLR_XML_LOTS_SYSVARS);- } finally {- cc.shutdown();- if (solrHomeDirectory.exists()) {- FileUtils.deleteDirectory(solrHomeDirectory);- }- }-- }-- @Test- public void testRename() throws Exception {- doTestRename("SystemVars1");- doTestRename("SystemVars2");- }-- private void doTestRename(String which) throws Exception {- CoreContainer cc = init(SOLR_XML_LOTS_SYSVARS, "SystemVars1", "SystemVars2");- SolrXMLCoresLocator.NonPersistingLocator locator- = (SolrXMLCoresLocator.NonPersistingLocator) cc.getCoresLocator();-- try {- final CoreAdminHandler admin = new CoreAdminHandler(cc);- SolrQueryResponse resp = new SolrQueryResponse();- admin.handleRequestBody- (req(CoreAdminParams.ACTION,- CoreAdminParams.CoreAdminAction.RENAME.toString(),- CoreAdminParams.CORE, which,- CoreAdminParams.OTHER, "RenamedCore"),- resp);- assertNull("Exception on rename", resp.getException());-- // OK, Assure that if I change everything that has been renamed with the original value for the core, it matches- // the old list- String[] persistList = getAllNodes();- String[] expressions = new String[persistList.length];-- for (int idx = 0; idx < persistList.length; ++idx) {- expressions[idx] = persistList[idx].replaceAll("RenamedCore", which);- }-- //assertXmlFile(origXml, expressions);- TestHarness.validateXPath(SOLR_XML_LOTS_SYSVARS, expressions);-- // Now the other way, If I replace the original name in the original XML file with "RenamedCore", does it match- // what was persisted?- persistList = getAllNodes(SOLR_XML_LOTS_SYSVARS);- expressions = new String[persistList.length];- for (int idx = 0; idx < persistList.length; ++idx) {- // /solr/cores/core[@name='SystemVars1' and @collection='${collection:collection1}']- expressions[idx] = persistList[idx].replace("@name='" + which + "'", "@name='RenamedCore'");- }-- TestHarness.validateXPath(locator.xml, expressions);-- } finally {- cc.shutdown();- if (solrHomeDirectory.exists()) {- FileUtils.deleteDirectory(solrHomeDirectory);- }- }- }-- @Test- public void testSwap() throws Exception {- doTestSwap("SystemVars1", "SystemVars2");- doTestSwap("SystemVars2", "SystemVars1");- }-- /*- Count the number of times substring appears in target- */- private int countOccurrences(String target, String substring) {- int pos = -1, count = 0;- while ((pos = target.indexOf(substring, pos + 1)) != -1) {- count++;- }- return count;- }-- private void doTestSwap(String from, String to) throws Exception {- CoreContainer cc = init(SOLR_XML_LOTS_SYSVARS, "SystemVars1", "SystemVars2");- SolrXMLCoresLocator.NonPersistingLocator locator- = (SolrXMLCoresLocator.NonPersistingLocator) cc.getCoresLocator();-- int coreCount = countOccurrences(locator.xml, "<core ");-- try {- final CoreAdminHandler admin = new CoreAdminHandler(cc);- SolrQueryResponse resp = new SolrQueryResponse();- admin.handleRequestBody- (req(CoreAdminParams.ACTION,- CoreAdminParams.CoreAdminAction.SWAP.toString(),- CoreAdminParams.CORE, from,- CoreAdminParams.OTHER, to),- resp);- assertNull("Exception on swap", resp.getException());-- assertThat("Swapping cores should leave the same number of cores as before",- countOccurrences(locator.xml, "<core "), is(coreCount));-- String[] persistList = getAllNodes();- String[] expressions = new String[persistList.length];-- // Now manually change the names back and it should match exactly to the original XML.- for (int idx = 0; idx < persistList.length; ++idx) {- String fromName = "@name='" + from + "'";- String toName = "@name='" + to + "'";- if (persistList[idx].contains(fromName)) {- expressions[idx] = persistList[idx].replace(fromName, toName);- } else {- expressions[idx] = persistList[idx].replace(toName, fromName);- }- }-- //assertXmlFile(origXml, expressions);- TestHarness.validateXPath(SOLR_XML_LOTS_SYSVARS, expressions);-- } finally {- cc.shutdown();- if (solrHomeDirectory.exists()) {- FileUtils.deleteDirectory(solrHomeDirectory);- }- }- }-- @Test- public void testMinimalXml() throws Exception {- CoreContainer cc = init(SOLR_XML_MINIMAL, "SystemVars1");- try {- cc.shutdown();- origMatchesPersist(cc, SOLR_XML_MINIMAL);- } finally {- cc.shutdown();- }- }-- private void origMatchesPersist(CoreContainer cc, String originalSolrXML) throws Exception {- String[] expressions = getAllNodes(originalSolrXML);- SolrXMLCoresLocator.NonPersistingLocator locator- = (SolrXMLCoresLocator.NonPersistingLocator) cc.getCoresLocator();-- TestHarness.validateXPath(locator.xml, expressions);- }-- @Test- public void testUnloadCreate() throws Exception {- doTestUnloadCreate("SystemVars1");- doTestUnloadCreate("SystemVars2");- }-- private void doTestUnloadCreate(String which) throws Exception {- CoreContainer cc = init(SOLR_XML_LOTS_SYSVARS, "SystemVars1", "SystemVars2");- try {- final CoreAdminHandler admin = new CoreAdminHandler(cc);-- SolrQueryResponse resp = new SolrQueryResponse();- admin.handleRequestBody- (req(CoreAdminParams.ACTION,- CoreAdminParams.CoreAdminAction.UNLOAD.toString(),- CoreAdminParams.CORE, which),- resp);- assertNull("Exception on unload", resp.getException());-- //origMatchesPersist(cc, new File(solrHomeDirectory, "unloadcreate1.solr.xml"));-- String instPath = new File(solrHomeDirectory, which).getAbsolutePath();- admin.handleRequestBody- (req(CoreAdminParams.ACTION,- CoreAdminParams.CoreAdminAction.CREATE.toString(),- CoreAdminParams.INSTANCE_DIR, instPath,- CoreAdminParams.NAME, which),- resp);- assertNull("Exception on create", resp.getException());-- String[] persistList = getAllNodes();- String[] expressions = new String[persistList.length];-- // Now manually change the names back and it should match exactly to the original XML.- for (int idx = 0; idx < persistList.length; ++idx) {- String name = "@name='" + which + "'";-- if (persistList[idx].contains(name)) {- if (persistList[idx].contains("@schema='schema.xml'")) {- expressions[idx] = persistList[idx].replace("schema.xml", "${schema:schema.xml}");- } else if (persistList[idx].contains("@config='solrconfig.xml'")) {- expressions[idx] = persistList[idx].replace("solrconfig.xml", "${solrconfig:solrconfig.xml}");- } else if (persistList[idx].contains("@instanceDir=")) {- expressions[idx] = persistList[idx].replaceFirst("instanceDir\\='.*?'", "instanceDir='" + which + "/'");- } else {- expressions[idx] = persistList[idx];- }- } else {- expressions[idx] = persistList[idx];- }- }-- //assertXmlFile(origXml, expressions);- TestHarness.validateXPath(SOLR_XML_LOTS_SYSVARS, expressions);-- } finally {- cc.shutdown();- if (solrHomeDirectory.exists()) {- FileUtils.deleteDirectory(solrHomeDirectory);- }- }- }-- @Test- public void testCreatePersistCore() throws Exception {- // Template for creating a core.- CoreContainer cc = init(SOLR_XML_LOTS_SYSVARS, "SystemVars1", "SystemVars2", "props1", "props2");- SolrXMLCoresLocator.NonPersistingLocator locator- = (SolrXMLCoresLocator.NonPersistingLocator) cc.getCoresLocator();-- try {- final CoreAdminHandler admin = new CoreAdminHandler(cc);- // create a new core (using CoreAdminHandler) w/ properties-- SolrQueryResponse resp = new SolrQueryResponse();- admin.handleRequestBody- (req(CoreAdminParams.ACTION,- CoreAdminParams.CoreAdminAction.CREATE.toString(),- CoreAdminParams.NAME, "props1",- CoreAdminParams.TRANSIENT, "true",- CoreAdminParams.LOAD_ON_STARTUP, "true",- CoreAdminParams.PROPERTY_PREFIX + "prefix1", "valuep1",- CoreAdminParams.PROPERTY_PREFIX + "prefix2", "valueP2",- "wt", "json", // need to insure that extra parameters are _not_ preserved (actually happened).- "qt", "admin/cores"),- resp);- assertNull("Exception on create", resp.getException());-- String instPath2 = new File(solrHomeDirectory, "props2").getAbsolutePath();- admin.handleRequestBody- (req(CoreAdminParams.ACTION,- CoreAdminParams.CoreAdminAction.CREATE.toString(),- CoreAdminParams.INSTANCE_DIR, instPath2,- CoreAdminParams.NAME, "props2",- CoreAdminParams.PROPERTY_PREFIX + "prefix2_1", "valuep2_1",- CoreAdminParams.PROPERTY_PREFIX + "prefix2_2", "valueP2_2",- CoreAdminParams.CONFIG, "solrconfig.xml",- CoreAdminParams.DATA_DIR, "./dataDirTest",- CoreAdminParams.SCHEMA, "schema.xml"),- resp);- assertNull("Exception on create", resp.getException());-- // Everything that was in the original XML file should be in the persisted one.- TestHarness.validateXPath(locator.xml, getAllNodes(SOLR_XML_LOTS_SYSVARS));-- // And the params for the new core should be in the persisted file.- TestHarness.validateXPath- (- locator.xml,- "/solr/cores/core[@name='props1']/property[@name='prefix1' and @value='valuep1']"- , "/solr/cores/core[@name='props1']/property[@name='prefix2' and @value='valueP2']"- , "/solr/cores/core[@name='props1' and @transient='true']"- , "/solr/cores/core[@name='props1' and @loadOnStartup='true']"- , "/solr/cores/core[@name='props1' and @instanceDir='props1" + File.separator + "']"- , "/solr/cores/core[@name='props2']/property[@name='prefix2_1' and @value='valuep2_1']"- , "/solr/cores/core[@name='props2']/property[@name='prefix2_2' and @value='valueP2_2']"- , "/solr/cores/core[@name='props2' and @config='solrconfig.xml']"- , "/solr/cores/core[@name='props2' and @schema='schema.xml']"- , "/solr/cores/core[@name='props2' and not(@loadOnStartup)]"- , "/solr/cores/core[@name='props2' and not(@transient)]"- , "/solr/cores/core[@name='props2' and @instanceDir='" + instPath2 + "']"- , "/solr/cores/core[@name='props2' and @dataDir='./dataDirTest']"- );-- } finally {- cc.shutdown();- }- }-- @Test- public void testPersist() throws Exception {-- String defXml = FileUtils.readFileToString(- new File(SolrTestCaseJ4.TEST_HOME(), "solr.xml"),- StandardCharsets.UTF_8.name());- final CoreContainer cores = init(defXml, "collection1");- SolrXMLCoresLocator.NonPersistingLocator locator- = (SolrXMLCoresLocator.NonPersistingLocator) cores.getCoresLocator();-- String instDir;- try (SolrCore template = cores.getCore("collection1")) {- assertNotNull(template);- instDir = template.getCoreDescriptor().getRawInstanceDir();- }-- final File instDirFile = new File(cores.getSolrHome(), instDir);- assertTrue("instDir doesn't exist: " + instDir, instDirFile.exists());-- // sanity check the basic persistence of the default init- TestHarness.validateXPath(locator.xml,- "/solr[@persistent='true']",- "/solr/cores[@defaultCoreName='collection1' and not(@transientCacheSize)]",- "/solr/cores/core[@name='collection1' and @instanceDir='" + instDir +- "' and @transient='false' and @loadOnStartup='true' ]",- "1=count(/solr/cores/core)");-- // create some new cores and sanity check the persistence-- final File dataXfile = new File(solrHomeDirectory, "dataX");- final String dataX = dataXfile.getAbsolutePath();- assertTrue("dataXfile mkdirs failed: " + dataX, dataXfile.mkdirs());-- final File instYfile = new File(solrHomeDirectory, "instY");- FileUtils.copyDirectory(instDirFile, instYfile);-- // :HACK: dataDir leaves off trailing "/", but instanceDir uses it- final String instY = instYfile.getAbsolutePath() + "/";-- final CoreDescriptor xd = buildCoreDescriptor(cores, "X", instDir)- .withDataDir(dataX).build();-- final CoreDescriptor yd = new CoreDescriptor(cores, "Y", instY);-- SolrCore x = null;- SolrCore y = null;- try {- x = cores.create(xd);- y = cores.create(yd);-- assertEquals("cores not added?", 3, cores.getCoreNames().size());-- TestHarness.validateXPath(locator.xml,- "/solr[@persistent='true']",- "/solr/cores[@defaultCoreName='collection1']",- "/solr/cores/core[@name='collection1' and @instanceDir='" + instDir- + "']", "/solr/cores/core[@name='X' and @instanceDir='" + instDir- + "' and @dataDir='" + dataX + "']",- "/solr/cores/core[@name='Y' and @instanceDir='" + instY + "']",- "3=count(/solr/cores/core)");-- // Test for saving implicit properties, we should not do this.- TestHarness.validateXPath(locator.xml,- "/solr/cores/core[@name='X' and not(@solr.core.instanceDir) and not (@solr.core.configName)]");-- cores.unload("X");-- TestHarness.validateXPath(locator.xml, "/solr[@persistent='true']",- "/solr/cores[@defaultCoreName='collection1']",- "/solr/cores/core[@name='collection1' and @instanceDir='" + instDir + "']",- "/solr/cores/core[@name='Y' and @instanceDir='" + instY + "']",- "2=count(/solr/cores/core)");-- } finally {- cores.shutdown();- }- }--- private String[] getAllNodes(InputStream is) throws ParserConfigurationException, IOException, SAXException {- List<String> expressions = new ArrayList<>(); // XPATH and value for all elements in the indicated XML- DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory- .newInstance();- DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();- Document document = docBuilder.parse(is);-- Node root = document.getDocumentElement();- gatherNodes(root, expressions, "");- return expressions.toArray(new String[expressions.size()]);- }-- private String[] getAllNodes() throws ParserConfigurationException, IOException, SAXException {- return getAllNodes(new FileInputStream(new File(solrHomeDirectory, "solr.xml")));- }-- private String[] getAllNodes(String xmlString) throws ParserConfigurationException, IOException, SAXException {- return getAllNodes(new ByteArrayInputStream(xmlString.getBytes(StandardCharsets.UTF_8)));- }-- /*- private void assertSolrXmlFile(String... xpathExpressions) throws IOException, SAXException {- assertXmlFile(new File(solrHomeDirectory, "solr.xml"), xpathExpressions);- }- */-- // Note this is pretty specialized for a solr.xml file because working with the DOM is such a pain.-- private static List<String> qualified = new ArrayList<String>() {{- add("core");- add("property");- add("int");- add("str");- add("long");- add("property");- }};-- private static List<String> addText = new ArrayList<String>() {{- add("int");- add("str");- add("long");- }};-- // path is the path to parent node-- private void gatherNodes(Node node, List<String> expressions, String path) {-- String nodeName = node.getNodeName();- String thisPath = path + "/" + nodeName;- //Parent[@id='1']/Children/child[@name]- // Add in the xpaths for verification of any attributes.- NamedNodeMap attrs = node.getAttributes();- String qualifier = "";- if (attrs.getLength() > 0) {- // Assemble the prefix for qualifying all of the attributes with the same name- if (qualified.contains(nodeName)) {- qualifier = "@name='" + node.getAttributes().getNamedItem("name").getTextContent() + "'";- }-- for (int idx = 0; idx < attrs.getLength(); ++idx) {-- Node attr = attrs.item(idx);- if (StringUtils.isNotBlank(qualifier) && "name".equals(attr.getNodeName())) {- continue; // Already added "name" attribute in qualifier string.- }- if (StringUtils.isNotBlank(qualifier)) {- // Create [@name="stuff" and @attrib="value"] fragment- expressions.add(thisPath +- "[" + qualifier + " and @" + attr.getNodeName() + "='" + attr.getTextContent() + "']");-- } else {- // Create [@attrib="value"] fragment- expressions.add(thisPath +- "[" + qualifier + " @" + attr.getNodeName() + "='" + attr.getTextContent() + "']");- }- }- }- // Now add the text for special nodes- // a[normalize-space(text())='somesite']- if (addText.contains(nodeName)) {- expressions.add(thisPath + "[" + qualifier + " and text()='" + node.getTextContent() + "']");- }- // Now collect all the child element nodes.- NodeList nodeList = node.getChildNodes();- for (int i = 0; i < nodeList.getLength(); i++) {-- Node currentNode = nodeList.item(i);- if (currentNode.getNodeType() == Node.ELEMENT_NODE) {- if (StringUtils.isNotBlank(qualifier)) {- gatherNodes(currentNode, expressions, thisPath + "[" + qualifier + "]");- } else {- gatherNodes(currentNode, expressions, thisPath);- }- }- }- }-- public static String SOLR_XML_LOTS_SYSVARS =- "<solr persistent=\"${solr.xml.persist:false}\" coreLoadThreads=\"12\" sharedLib=\"${something:.}\" >\n" +- " <logging class=\"${logclass:log4j.class}\" enabled=\"{logenable:true}\">\n" +- " <watcher size=\"${watchSize:13}\" threshold=\"${logThresh:54}\" />\n" +- " </logging>\n" +- " <cores adminPath=\"/admin/cores\" defaultCoreName=\"SystemVars1\" host=\"127.0.0.1\" \n" +- " hostPort=\"${hostPort:8983}\" hostContext=\"${hostContext:solr}\" \n" +- " zkClientTimeout=\"${solr.zkclienttimeout:30000}\" \n" +- " shareSchema=\"${shareSchema:false}\" distribUpdateConnTimeout=\"${distribUpdateConnTimeout:15000}\" \n" +- " distribUpdateSoTimeout=\"${distribUpdateSoTimeout:120000}\" \n" +- " leaderVoteWait=\"${leadVoteWait:32}\" managementPath=\"${manpath:/var/lib/path}\" transientCacheSize=\"${tranSize:128}\"> \n" +- " <core name=\"SystemVars1\" instanceDir=\"SystemVars1/\" shard=\"${shard:32}\" \n" +- " collection=\"${collection:collection1}\" config=\"${solrconfig:solrconfig.xml}\" \n" +- " schema=\"${schema:schema.xml}\" ulogDir=\"${ulog:./}\" roles=\"${myrole:boss}\" \n" +- " dataDir=\"${data:./}\" loadOnStartup=\"${onStart:true}\" transient=\"${tran:true}\" \n" +- " coreNodeName=\"${coreNode:utterlyridiculous}\" \n" +- " >\n" +- " </core>\n" +- " <core name=\"SystemVars2\" instanceDir=\"SystemVars2/\" shard=\"${shard:32}\" \n" +- " collection=\"${collection:collection2}\" config=\"${solrconfig:solrconfig.xml}\" \n" +- " coreNodeName=\"${coreNodeName:}\" schema=\"${schema:schema.xml}\">\n" +- " <property name=\"collection\" value=\"{collection:collection2}\"/>\n" +- " <property name=\"schema\" value=\"${schema:schema.xml}\"/>\n" +- " <property name=\"coreNodeName\" value=\"EricksCore\"/>\n" +- " </core>\n" +- " <shardHandlerFactory name=\"${shhandler:shardHandlerFactory}\" class=\"${handlefac:HttpShardHandlerFactory}\">\n" +- " <int name=\"socketTimeout\">${socketTimeout:120000}</int> \n" +- " <int name=\"connTimeout\">${connTimeout:15000}</int> \n" +- " <str name=\"arbitraryName\">${arbitrarySysValue:foobar}</str>\n" +- " </shardHandlerFactory> \n" +- " </cores>\n" +- "</solr>";--- private static String SOLR_XML_MINIMAL =- "<solr >\n" +- " <cores> \n" +- " <core name=\"SystemVars1\" instanceDir=\"SystemVars1/\" />\n" +- " </cores>\n" +- "</solr>";--}diff --git a/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistor.java b/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistor.javadeleted file mode 100644index f93117f54fb..00000000000--- a/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistor.java+++ /dev/null@@ -1,127 +0,0 @@-package org.apache.solr.core;--/*- * 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.- */--import java.io.File;-import java.io.IOException;-import java.util.List;--import org.apache.commons.io.FileUtils;-import org.apache.solr.SolrTestCaseJ4;-import org.junit.Test;--import com.google.common.collect.ImmutableList;--public class TestSolrXmlPersistor extends SolrTestCaseJ4 {-- private static final List<CoreDescriptor> EMPTY_CD_LIST = ImmutableList.<CoreDescriptor>builder().build();-- @Test- public void selfClosingCoresTagIsPersisted() {-- final String solrxml = "<solr><cores adminHandler=\"/admin\"/></solr>";-- SolrXMLCoresLocator persistor = new SolrXMLCoresLocator(solrxml, null);- assertEquals("<solr><cores adminHandler=\"/admin\"></cores></solr>", persistor.buildSolrXML(EMPTY_CD_LIST));-- }-- @Test- public void emptyCoresTagIsPersisted() {- final String solrxml = "<solr><cores adminHandler=\"/admin\"></cores></solr>";-- SolrXMLCoresLocator persistor = new SolrXMLCoresLocator(solrxml, null);- assertEquals("<solr><cores adminHandler=\"/admin\"></cores></solr>", persistor.buildSolrXML(EMPTY_CD_LIST));- }-- @Test- public void emptySolrXmlIsPersisted() {- final String solrxml = "<solr></solr>";-- SolrXMLCoresLocator persistor = new SolrXMLCoresLocator(solrxml, null);- assertEquals("<solr><cores></cores></solr>", persistor.buildSolrXML(EMPTY_CD_LIST));- }-- @Test- public void simpleCoreDescriptorIsPersisted() throws IOException {-- final String solrxml = "<solr><cores></cores></solr>";-- final File solrHomeDirectory = createTempDir().toFile();-- copyMinFullSetup(solrHomeDirectory);-- CoreContainer cc = new CoreContainer(solrHomeDirectory.getAbsolutePath());-- final CoreDescriptor cd = new CoreDescriptor(cc, "testcore",- "instance/dir/");- List<CoreDescriptor> cds = ImmutableList.of(cd);-- SolrXMLCoresLocator persistor = new SolrXMLCoresLocator(solrxml, null);- String xml = persistor.buildSolrXML(cds);-- assertTrue(xml.contains("<solr><cores>"));- assertTrue(xml.contains("name=\"testcore\""));- assertTrue(xml.contains("instanceDir=\"instance/dir/\""));- assertTrue(xml.contains("</cores></solr>"));- }-- @Test- public void shardHandlerInfoIsPersisted() {-- final String solrxml =- "<solr>" +- "<cores adminHandler=\"whatever\">" +- "<core name=\"testcore\" instanceDir=\"instance/dir/\"/>" +- "<shardHandlerFactory name=\"shardHandlerFactory\" class=\"HttpShardHandlerFactory\">" +- "<int name=\"socketTimeout\">${socketTimeout:500}</int>" +- "<str name=\"arbitrary\">arbitraryValue</str>" +- "</shardHandlerFactory>" +- "</cores>" +- "</solr>";-- SolrXMLCoresLocator locator = new SolrXMLCoresLocator(solrxml, null);- assertTrue(locator.getTemplate().contains("{{CORES_PLACEHOLDER}}"));- assertTrue(locator.getTemplate().contains("<shardHandlerFactory "));- assertTrue(locator.getTemplate().contains("${socketTimeout:500}"));-- }-- @Test- public void simpleShardHandlerInfoIsPersisted() {-- final String solrxml =- "<solr>" +- "<cores adminHandler=\"whatever\">" +- "<core name=\"testcore\" instanceDir=\"instance/dir/\"/>" +- "<shardHandlerFactory name=\"shardHandlerFactory\" class=\"HttpShardHandlerFactory\"/>" +- "</cores>" +- "</solr>";-- SolrXMLCoresLocator locator = new SolrXMLCoresLocator(solrxml, null);- assertTrue(locator.getTemplate().contains("{{CORES_PLACEHOLDER}}"));- assertTrue(locator.getTemplate().contains("<shardHandlerFactory "));- }-- @Test- public void complexXmlIsParsed() {- SolrXMLCoresLocator locator = new SolrXMLCoresLocator(TestSolrXmlPersistence.SOLR_XML_LOTS_SYSVARS, null);- assertTrue(locator.getTemplate().contains("{{CORES_PLACEHOLDER}}"));- }--}diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.javaindex 6b24bdd59c2..d1c2405e96a 100644--- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java+++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java@@ -68,6 +68,7 @@ import java.util.ArrayList;import java.util.Arrays;import java.util.Collection;import java.util.Date;+import java.util.Properties;import java.util.Set;import java.util.concurrent.TimeUnit;@@ -153,7 +154,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {private static SolrClient createNewSolrClient(int port) {try {// setup the client...- HttpSolrClient client = new HttpSolrClient(buildUrl(port));+ HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/" + DEFAULT_TEST_CORENAME);client.setConnectionTimeout(15000);client.setSoTimeout(60000);client.setDefaultMaxConnectionsPerHost(100);@@ -261,18 +262,27 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {}private NamedList<Object> reloadCore(SolrClient s, String core) throws Exception {-+ModifiableSolrParams params = new ModifiableSolrParams();params.set("action","reload");params.set("core", core);params.set("qt","/admin/cores");QueryRequest req = new QueryRequest(params);- NamedList<Object> res = s.request(req);-- assertNotNull("null response from server", res);+ HttpSolrClient adminClient = adminClient(s);+ try {+ NamedList<Object> res = adminClient.request(req);+ assertNotNull("null response from server", res);+ return res;+ }+ finally {+ adminClient.shutdown();+ }+ }- return res;+ private HttpSolrClient adminClient(SolrClient client) {+ String adminUrl = ((HttpSolrClient)client).getBaseURL().replace("/collection1", "");+ return new HttpSolrClient(adminUrl);}@Test@@ -449,7 +459,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {//jetty servers.private void invokeReplicationCommand(int pJettyPort, String pCommand) throws IOException{- String masterUrl = buildUrl(pJettyPort) + "/replication?command=" + pCommand;+ String masterUrl = buildUrl(pJettyPort) + "/" + DEFAULT_TEST_CORENAME + "/replication?command=" + pCommand;URL u = new URL(masterUrl);InputStream stream = u.openStream();stream.close();@@ -608,8 +618,8 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {assertEquals(nDocs, masterQueryResult.getNumFound());// snappull- String masterUrl = buildUrl(slaveJetty.getLocalPort()) + "/replication?command=fetchindex&masterUrl=";- masterUrl += buildUrl(masterJetty.getLocalPort()) + "/replication";+ String masterUrl = buildUrl(slaveJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME + "/replication?command=fetchindex&masterUrl=";+ masterUrl += buildUrl(masterJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME + "/replication";URL url = new URL(masterUrl);InputStream stream = url.openStream();stream.close();@@ -962,8 +972,10 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {URL url;InputStream stream;masterUrl = buildUrl(to.getLocalPort())+ + "/" + DEFAULT_TEST_CORENAME+ "/replication?wait=true&command=fetchindex&masterUrl="- + buildUrl(from.getLocalPort()) + "/replication";+ + buildUrl(from.getLocalPort())+ + "/" + DEFAULT_TEST_CORENAME + "/replication";url = new URL(masterUrl);stream = url.openStream();stream.close();@@ -1391,34 +1403,40 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {final long sleepInterval = 200;long timeSlept = 0;- SolrParams p = params("action","status", "core", "collection1");- while (timeSlept < timeout) {- QueryRequest req = new QueryRequest(p);- req.setPath("/admin/cores");- try {- NamedList data = client.request(req);- for (String k : new String[] {"status","collection1"}) {- Object o = data.get(k);- assertNotNull("core status rsp missing key: " + k, o);- data = (NamedList) o;- }- Date startTime = (Date) data.get("startTime");- assertNotNull("core has null startTime", startTime);- if (null == min || startTime.after(min)) {- return startTime;+ HttpSolrClient adminClient = adminClient(client);+ try {+ SolrParams p = params("action", "status", "core", "collection1");+ while (timeSlept < timeout) {+ QueryRequest req = new QueryRequest(p);+ req.setPath("/admin/cores");+ try {+ NamedList data = adminClient.request(req);+ for (String k : new String[]{"status", "collection1"}) {+ Object o = data.get(k);+ assertNotNull("core status rsp missing key: " + k, o);+ data = (NamedList) o;+ }+ Date startTime = (Date) data.get("startTime");+ assertNotNull("core has null startTime", startTime);+ if (null == min || startTime.after(min)) {+ return startTime;+ }+ } catch (SolrException e) {+ // workarround for SOLR-4668+ if (500 != e.code()) {+ throw e;+ } // else server possibly from the core reload in progress...}- } catch (SolrException e) {- // workarround for SOLR-4668- if (500 != e.code()) {- throw e;- } // else server possibly from the core reload in progress...- }- timeSlept += sleepInterval;- Thread.sleep(sleepInterval);+ timeSlept += sleepInterval;+ Thread.sleep(sleepInterval);+ }+ fail("timed out waiting for collection1 startAt time to exceed: " + min);+ return min; // compilation neccessity+ }+ finally {+ adminClient.shutdown();}- fail("timed out waiting for collection1 startAt time to exceed: " + min);- return min; // compilation neccessity}private static String buildUrl(int port) {@@ -1476,6 +1494,11 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {System.setProperty("solr.test.sys.prop1", "propone");System.setProperty("solr.test.sys.prop2", "proptwo");+ Properties props = new Properties();+ props.setProperty("name", "collection1");++ writeCoreProperties(homeDir.toPath().resolve("collection1"), props, "TestReplicationHandler");+dataDir = new File(homeDir + "/collection1", "data");confDir = new File(homeDir + "/collection1", "conf");diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.javaindex 963197ddec4..ff236525748 100644--- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java+++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java@@ -73,7 +73,7 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase {private static SolrClient createNewSolrClient(int port) {try {// setup the client...- HttpSolrClient client = new HttpSolrClient(buildUrl(port, context));+ HttpSolrClient client = new HttpSolrClient(buildUrl(port, context) + "/" + DEFAULT_TEST_CORENAME);client.setConnectionTimeout(15000);client.setSoTimeout(60000);client.setDefaultMaxConnectionsPerHost(100);@@ -260,7 +260,7 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase {}public void fetchStatus() throws IOException {- String masterUrl = buildUrl(masterJetty.getLocalPort(), "/solr") + "/replication?command=" + ReplicationHandler.CMD_DETAILS;+ String masterUrl = buildUrl(masterJetty.getLocalPort(), "/solr") + "/" + DEFAULT_TEST_CORENAME + "/replication?command=" + ReplicationHandler.CMD_DETAILS;URL url;InputStream stream = null;try {@@ -309,10 +309,10 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase {public void runCommand() {String masterUrl = null;if(backupName != null) {- masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/replication?command=" + cmd ++ masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME + "/replication?command=" + cmd +"&name=" + backupName;} else {- masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/replication?command=" + cmd ++ masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME + "/replication?command=" + cmd +(addNumberToKeepInRequest ? "&" + backupKeepParamName + "=1" : "");}@@ -343,7 +343,7 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase {}public boolean fetchStatus() throws IOException {- String masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/replication?command=" + ReplicationHandler.CMD_DETAILS;+ String masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME + "/replication?command=" + ReplicationHandler.CMD_DETAILS;URL url;InputStream stream = null;try {diff --git a/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.javaindex cbc93d69e0b..af97a844644 100644--- a/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java+++ b/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java@@ -31,7 +31,6 @@ import org.apache.solr.common.util.NamedList;import org.apache.solr.core.CoreContainer;import org.apache.solr.core.CoreDescriptor;import org.apache.solr.core.SolrCore;-import org.apache.solr.core.SolrXMLCoresLocator;import org.apache.solr.response.SolrQueryResponse;import org.junit.BeforeClass;import org.junit.Rule;@@ -73,8 +72,6 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {new File(subHome, "solrconfig.snippet.randomindexconfig.xml"));final CoreContainer cores = h.getCoreContainer();- SolrXMLCoresLocator.NonPersistingLocator locator- = (SolrXMLCoresLocator.NonPersistingLocator) cores.getCoresLocator();final CoreAdminHandler admin = new CoreAdminHandler(cores);@@ -98,15 +95,6 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {resp);assertNull("Exception on create", resp.getException());- // First assert that these values are persisted.- h.validateXPath- (locator.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.diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.javaindex de75b5a3fe7..9efacc20798 100644--- a/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java+++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java@@ -65,7 +65,8 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase {solrHome = createSolrHome();createJetty(solrHome.getAbsolutePath(), null, null);String url = jetty.getBaseUrl().toString();- collection1 = new HttpSolrClient(url);++ collection1 = new HttpSolrClient(url + "/collection1");collection2 = new HttpSolrClient(url + "/collection2");String urlCollection1 = jetty.getBaseUrl().toString() + "/" + "collection1";@@ -74,9 +75,16 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase {shard2 = urlCollection2.replaceAll("https?://", "");//create second core- CoreAdminRequest.Create req = new CoreAdminRequest.Create();- req.setCoreName("collection2");- collection1.request(req);+ HttpSolrClient nodeClient = new HttpSolrClient(url);+ try {+ CoreAdminRequest.Create req = new CoreAdminRequest.Create();+ req.setCoreName("collection2");+ req.setConfigSet("collection1");+ nodeClient.request(req);+ }+ finally {+ nodeClient.shutdown();+ }SolrInputDocument doc = new SolrInputDocument();doc.setField("id", "1");diff --git a/solr/core/src/test/org/apache/solr/rest/SolrRestletTestBase.java b/solr/core/src/test/org/apache/solr/rest/SolrRestletTestBase.javaindex e5fc0173daf..ea8a40c1b09 100644--- a/solr/core/src/test/org/apache/solr/rest/SolrRestletTestBase.java+++ b/solr/core/src/test/org/apache/solr/rest/SolrRestletTestBase.java@@ -21,6 +21,8 @@ import org.eclipse.jetty.servlet.ServletHolder;import org.junit.BeforeClass;import org.restlet.ext.servlet.ServerServlet;+import java.nio.file.Path;+import java.util.Properties;import java.util.SortedMap;import java.util.TreeMap;@@ -42,11 +44,25 @@ abstract public class SolrRestletTestBase extends RestTestBase {*/@BeforeClasspublic static void init() throws Exception {++ Path tempDir = createTempDir();+ Path coresDir = tempDir.resolve("cores");++ System.setProperty("coreRootDirectory", coresDir.toString());+ System.setProperty("configSetBaseDir", TEST_HOME());+final SortedMap<ServletHolder,String> extraServlets = new TreeMap<>();final ServletHolder solrSchemaRestApi = new ServletHolder("SolrSchemaRestApi", ServerServlet.class);solrSchemaRestApi.setInitParameter("org.restlet.application", "org.apache.solr.rest.SolrSchemaRestApi");extraServlets.put(solrSchemaRestApi, "/schema/*"); // '/schema/*' matches '/schema', '/schema/', and '/schema/whatever...'+ Properties props = new Properties();+ props.setProperty("name", DEFAULT_TEST_CORENAME);+ props.setProperty("config", "solrconfig.xml");+ props.setProperty("schema", "schema-rest.xml");+ props.setProperty("configSet", "collection1");++ writeCoreProperties(coresDir.resolve("core"), props, "SolrRestletTestBase");createJettyAndHarness(TEST_HOME(), "solrconfig.xml", "schema-rest.xml", "/solr", true, extraServlets);}}diff --git a/solr/core/src/test/org/apache/solr/rest/schema/TestManagedSchemaDynamicFieldResource.java b/solr/core/src/test/org/apache/solr/rest/schema/TestManagedSchemaDynamicFieldResource.javaindex 56c85c3f0a9..792d1634395 100644--- a/solr/core/src/test/org/apache/solr/rest/schema/TestManagedSchemaDynamicFieldResource.java+++ b/solr/core/src/test/org/apache/solr/rest/schema/TestManagedSchemaDynamicFieldResource.java@@ -16,11 +16,6 @@ package org.apache.solr.rest.schema;* limitations under the License.*/-import java.io.File;-import java.util.SortedMap;-import java.util.TreeMap;-import java.util.regex.Pattern;-import org.apache.commons.io.FileUtils;import org.apache.solr.util.RestTestBase;import org.eclipse.jetty.servlet.ServletHolder;@@ -29,6 +24,11 @@ import org.junit.Before;import org.junit.Test;import org.restlet.ext.servlet.ServerServlet;+import java.io.File;+import java.util.SortedMap;+import java.util.TreeMap;+import java.util.regex.Pattern;+public class TestManagedSchemaDynamicFieldResource extends RestTestBase {private static File tmpSolrHome;diff --git a/solr/core/src/test/org/apache/solr/rest/schema/TestManagedSchemaFieldResource.java b/solr/core/src/test/org/apache/solr/rest/schema/TestManagedSchemaFieldResource.javaindex 50bc71198fa..83eb1a8b120 100644--- a/solr/core/src/test/org/apache/solr/rest/schema/TestManagedSchemaFieldResource.java+++ b/solr/core/src/test/org/apache/solr/rest/schema/TestManagedSchemaFieldResource.java@@ -16,11 +16,6 @@ package org.apache.solr.rest.schema;* limitations under the License.*/-import java.io.File;-import java.util.SortedMap;-import java.util.TreeMap;-import java.util.regex.Pattern;-import org.apache.commons.io.FileUtils;import org.apache.solr.util.RestTestBase;import org.eclipse.jetty.servlet.ServletHolder;@@ -29,6 +24,11 @@ import org.junit.Before;import org.junit.Test;import org.restlet.ext.servlet.ServerServlet;+import java.io.File;+import java.util.SortedMap;+import java.util.TreeMap;+import java.util.regex.Pattern;+public class TestManagedSchemaFieldResource extends RestTestBase {private static File tmpSolrHome;diff --git a/solr/core/src/test/org/apache/solr/schema/TestBinaryField.java b/solr/core/src/test/org/apache/solr/schema/TestBinaryField.javaindex 4ca91b8f861..d43163dc3ee 100644--- a/solr/core/src/test/org/apache/solr/schema/TestBinaryField.java+++ b/solr/core/src/test/org/apache/solr/schema/TestBinaryField.java@@ -17,10 +17,7 @@package org.apache.solr.schema;-import java.io.File;-import java.nio.ByteBuffer;-import java.util.List;-+import com.google.common.base.Charsets;import org.apache.commons.io.FileUtils;import org.apache.solr.SolrJettyTestBase;import org.apache.solr.SolrTestCaseJ4;@@ -34,6 +31,14 @@ import org.apache.solr.common.SolrDocumentList;import org.apache.solr.common.SolrInputDocument;import org.junit.BeforeClass;+import java.io.File;+import java.io.OutputStreamWriter;+import java.io.Writer;+import java.nio.ByteBuffer;+import java.nio.file.Files;+import java.util.List;+import java.util.Properties;+@SuppressSSL(bugUrl = "https://issues.apache.org/jira/browse/SOLR-5776")public class TestBinaryField extends SolrJettyTestBase {@@ -60,6 +65,12 @@ public class TestBinaryField extends SolrJettyTestBase {FileUtils.copyFile(new File(src_dir, "solrconfig.snippet.randomindexconfig.xml"),new File(confDir, "solrconfig.snippet.randomindexconfig.xml"));+ try (Writer w = new OutputStreamWriter(Files.newOutputStream(collDir.toPath().resolve("core.properties")), Charsets.UTF_8)) {+ Properties coreProps = new Properties();+ coreProps.put("name", "collection1");+ coreProps.store(w, "");+ }+createJetty(homeDir.getAbsolutePath(), null, null);}diff --git a/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java b/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.javaindex 6b1863211e8..a1c561e53b3 100644--- a/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java+++ b/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java@@ -19,8 +19,8 @@ package org.apache.solr.update;import org.apache.lucene.index.LogDocMergePolicy;import org.apache.solr.BaseDistributedSearchTestCase;-import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.client.solrj.SolrClient;+import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.client.solrj.SolrServerException;import org.apache.solr.client.solrj.embedded.JettySolrRunner;import org.apache.solr.client.solrj.impl.HttpSolrClient;@@ -36,6 +36,7 @@ import org.apache.solr.common.util.NamedList;import org.apache.solr.core.ConfigSolr;import org.apache.solr.core.CoreContainer;import org.apache.solr.core.CoresLocator;+import org.apache.solr.core.PluginInfo;import org.apache.solr.core.SolrCore;import org.apache.solr.core.SolrEventListener;import org.apache.solr.search.SolrIndexSearcher;@@ -52,6 +53,7 @@ import org.xml.sax.SAXException;import javax.xml.parsers.ParserConfigurationException;import java.io.File;import java.io.IOException;+import java.nio.file.Path;import java.util.ArrayList;import java.util.Collections;import java.util.List;@@ -70,7 +72,7 @@ public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {private UpdateShardHandler updateShardHandler;public SolrCmdDistributorTest() throws ParserConfigurationException, IOException, SAXException {- updateShardHandler = new UpdateShardHandler(new ConfigSolr() {+ updateShardHandler = new UpdateShardHandler(new ConfigSolr(null, null) {@Overridepublic CoresLocator getCoresLocator() {@@ -78,14 +80,15 @@ public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {}@Override- protected String getShardHandlerFactoryConfigPath() {+ public PluginInfo getShardHandlerFactoryPluginInfo() {return null;}@Override- public boolean isPersistent() {- return false;- }});+ protected String getProperty(CfgProp key) {+ return null;+ }+ });fixShardCount = true;shardCount = 4;@@ -105,6 +108,10 @@ public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {// we don't get helpful override behavior due to the method being static@Overrideprotected void createServers(int numShards) throws Exception {++ System.setProperty("configSetBaseDir", TEST_HOME());+ System.setProperty("coreRootDirectory", testDir.toPath().resolve("control").toString());+ writeCoreProperties(testDir.toPath().resolve("control/cores"), DEFAULT_TEST_CORENAME);controlJetty = createJetty(new File(getSolrHome()), testDir + "/control/data", null, getSolrConfigFile(), getSchemaFile());controlClient = createNewSolrClient(controlJetty.getLocalPort());@@ -113,6 +120,10 @@ public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {StringBuilder sb = new StringBuilder();for (int i = 0; i < numShards; i++) {if (sb.length() > 0) sb.append(',');+ String shardname = "shard" + i;+ Path coresPath = testDir.toPath().resolve(shardname).resolve("cores");+ writeCoreProperties(coresPath, DEFAULT_TEST_CORENAME);+ System.setProperty("coreRootDirectory", testDir.toPath().resolve(shardname).toString());JettySolrRunner j = createJetty(new File(getSolrHome()),testDir + "/shard" + i + "/data", null, getSolrConfigFile(),getSchemaFile());diff --git a/solr/core/src/test/org/apache/solr/util/MockConfigSolr.java b/solr/core/src/test/org/apache/solr/util/MockConfigSolr.javaindex 6b67940bb05..506c22c867c 100644--- a/solr/core/src/test/org/apache/solr/util/MockConfigSolr.java+++ b/solr/core/src/test/org/apache/solr/util/MockConfigSolr.java@@ -19,25 +19,30 @@ package org.apache.solr.util;import org.apache.solr.core.ConfigSolr;import org.apache.solr.core.CoresLocator;+import org.apache.solr.core.PluginInfo;/****/public class MockConfigSolr extends ConfigSolr {+ public MockConfigSolr() {+ super(null, null);+ }+@Overridepublic CoresLocator getCoresLocator() {return null;}@Override- protected String getShardHandlerFactoryConfigPath() {+ public PluginInfo getShardHandlerFactoryPluginInfo() {return null;}@Override- public boolean isPersistent() {- return false;+ protected String getProperty(CfgProp key) {+ return null;}}diff --git a/solr/example/example-DIH/solr/db/core.properties b/solr/example/example-DIH/solr/db/core.propertiesnew file mode 100644index 00000000000..e69de29bb2ddiff --git a/solr/example/example-DIH/solr/mail/core.properties b/solr/example/example-DIH/solr/mail/core.propertiesnew file mode 100644index 00000000000..e69de29bb2ddiff --git a/solr/example/example-DIH/solr/rss/core.properties b/solr/example/example-DIH/solr/rss/core.propertiesnew file mode 100644index 00000000000..e69de29bb2ddiff --git a/solr/example/example-DIH/solr/solr.xml b/solr/example/example-DIH/solr/solr.xmlindex a9d924ba992..191e51f5962 100644--- a/solr/example/example-DIH/solr/solr.xml+++ b/solr/example/example-DIH/solr/solr.xml@@ -1,10 +1,2 @@<?xml version="1.0" encoding="UTF-8" standalone="yes"?>-<solr sharedLib="lib" persistent="true">- <cores adminPath="/admin/cores" hostPort="${jetty.port:8983}" hostContext="${hostContext:solr}">- <core default="true" instanceDir="db" name="db"/>- <core default="false" instanceDir="rss" name="rss"/>- <core default="false" instanceDir="mail" name="mail"/>- <core default="false" instanceDir="tika" name="tika"/>- <core default="false" instanceDir="solr" name="solr"/>- </cores>-</solr>+<solr></solr>diff --git a/solr/example/example-DIH/solr/solr/core.properties b/solr/example/example-DIH/solr/solr/core.propertiesnew file mode 100644index 00000000000..e69de29bb2ddiff --git a/solr/example/example-DIH/solr/tika/core.properties b/solr/example/example-DIH/solr/tika/core.propertiesnew file mode 100644index 00000000000..e69de29bb2ddiff --git a/solr/solrj/src/test-files/solrj/solr/shared/conf/schema.xml b/solr/solrj/src/test-files/solrj/solr/configsets/shared/conf/schema.xmlsimilarity index 100%rename from solr/solrj/src/test-files/solrj/solr/shared/conf/schema.xmlrename to solr/solrj/src/test-files/solrj/solr/configsets/shared/conf/schema.xmldiff --git a/solr/solrj/src/test-files/solrj/solr/shared/conf/solrconfig.xml b/solr/solrj/src/test-files/solrj/solr/configsets/shared/conf/solrconfig.xmlsimilarity index 100%rename from solr/solrj/src/test-files/solrj/solr/shared/conf/solrconfig.xmlrename to solr/solrj/src/test-files/solrj/solr/configsets/shared/conf/solrconfig.xmldiff --git a/solr/solrj/src/test-files/solrj/solr/shared/conf/stopwords-en.txt b/solr/solrj/src/test-files/solrj/solr/configsets/shared/conf/stopwords-en.txtsimilarity index 100%rename from solr/solrj/src/test-files/solrj/solr/shared/conf/stopwords-en.txtrename to solr/solrj/src/test-files/solrj/solr/configsets/shared/conf/stopwords-en.txtdiff --git a/solr/solrj/src/test-files/solrj/solr/shared/conf/stopwords-fr.txt b/solr/solrj/src/test-files/solrj/solr/configsets/shared/conf/stopwords-fr.txtsimilarity index 100%rename from solr/solrj/src/test-files/solrj/solr/shared/conf/stopwords-fr.txtrename to solr/solrj/src/test-files/solrj/solr/configsets/shared/conf/stopwords-fr.txtdiff --git a/solr/solrj/src/test-files/solrj/solr/multicore/solr.xml b/solr/solrj/src/test-files/solrj/solr/multicore/solr.xmlindex 4e27135ee73..bffa48ef884 100644--- a/solr/solrj/src/test-files/solrj/solr/multicore/solr.xml+++ b/solr/solrj/src/test-files/solrj/solr/multicore/solr.xml@@ -16,25 +16,7 @@limitations under the License.-->-<!--- All (relative) paths are relative to the installation path-- persistent: Save changes made via the API to this file- sharedLib: path to a lib directory that will be shared across all cores--->-<solr persistent="false">+<solr>+- <!--- adminPath: RequestHandler path to manage cores.- If 'null' (or absent), cores will not be manageable via request handler- -->- <cores adminPath="/admin/cores" host="${host:}" hostPort="${jetty.port:8983}" hostContext="${hostContext:solr}">- <core name="core0" instanceDir="core0" />- <core name="core1" instanceDir="core1" />-- <shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">- <str name="urlScheme">${urlScheme:}</str>- </shardHandlerFactory>- </cores>-</solr>diff --git a/solr/solrj/src/test-files/solrj/solr/shared/collection1/core.properties b/solr/solrj/src/test-files/solrj/solr/shared/collection1/core.propertiesnew file mode 100644index 00000000000..09545567ed0--- /dev/null+++ b/solr/solrj/src/test-files/solrj/solr/shared/collection1/core.properties@@ -0,0 +1 @@+configSet=shared\ No newline at end of filediff --git a/solr/solrj/src/test-files/solrj/solr/shared/core0/core.properties b/solr/solrj/src/test-files/solrj/solr/shared/core0/core.propertiesnew file mode 100644index 00000000000..afb87fe2c7b--- /dev/null+++ b/solr/solrj/src/test-files/solrj/solr/shared/core0/core.properties@@ -0,0 +1,8 @@+name=core0+dataDir=${dataDir1}+collection=${collection:acollection}+version=3.5+l10n=EN+ctlField=core0+comment=This is a sample with a sys prop ${sysprop:default}+configSet=shared\ No newline at end of filediff --git a/solr/solrj/src/test-files/solrj/solr/shared/core1/core.properties b/solr/solrj/src/test-files/solrj/solr/shared/core1/core.propertiesnew file mode 100644index 00000000000..341afa57c02--- /dev/null+++ b/solr/solrj/src/test-files/solrj/solr/shared/core1/core.properties@@ -0,0 +1,6 @@+dataDir=${dataDir2}+version=2.4+l10n=FR+ctlField=core1+comment=Ceci est un exemple+configSet=shared\ No newline at end of filediff --git a/solr/solrj/src/test-files/solrj/solr/shared/solr.xml b/solr/solrj/src/test-files/solrj/solr/shared/solr.xmlindex a954a3a8d00..7abf439359f 100644--- a/solr/solrj/src/test-files/solrj/solr/shared/solr.xml+++ b/solr/solrj/src/test-files/solrj/solr/shared/solr.xml@@ -16,20 +16,45 @@limitations under the License.-->+<solr>++ <str name="shareSchema">${shareSchema:false}</str>+ <str name="configSetBaseDir">${configSetBaseDir:../configsets}</str>+ <str name="coreRootDirectory">${coreRootDirectory:.}</str>++ <shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">+ <str name="urlScheme">${urlScheme:}</str>+ <int name="socketTimeout">${socketTimeout:90000}</int>+ <int name="connTimeout">${connTimeout:15000}</int>+ </shardHandlerFactory>++ <solrcloud>+ <str name="host">127.0.0.1</str>+ <int name="hostPort">${hostPort:8983}</int>+ <str name="hostContext">${hostContext:solr}</str>+ <int name="zkClientTimeout">${solr.zkclienttimeout:30000}</int>+ <bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>+ <int name="leaderVoteWait">0</int>+ <int name="distribUpdateConnTimeout">${distribUpdateConnTimeout:45000}</int>+ <int name="distribUpdateSoTimeout">${distribUpdateSoTimeout:340000}</int>+ </solrcloud>++</solr>+<!--All (relative) paths are relative to the installation pathpersistent: Save changes made via the API to this filesharedLib: path to a lib directory that will be shared across all cores--->+<solr persistent="false"><property name="version" value="1.3"/><property name="lang" value="english, french"/>- <!--+adminPath: RequestHandler path to manage cores.If 'null' (or absent), cores will not be manageable via REST- -->+<cores adminPath="/admin/cores" defaultCoreName="core0" host="127.0.0.1" hostPort="${hostPort:8983}" hostContext="${hostContext:solr}" zkClientTimeout="8000" genericCoreNodeNames="${genericCoreNodeNames:true}" configSetBaseDir="${configSetBase:configsets}"><core name="collection1" instanceDir="." /><core name="core0" instanceDir="${theInstanceDir:./}" dataDir="${dataDir1}" collection="${collection:acollection}">@@ -46,3 +71,4 @@</core></cores></solr>+-->diff --git a/solr/solrj/src/test-files/solrj/solr/solr.xml b/solr/solrj/src/test-files/solrj/solr/solr.xmlindex c5d6baceb36..8f799668f5d 100644--- a/solr/solrj/src/test-files/solrj/solr/solr.xml+++ b/solr/solrj/src/test-files/solrj/solr/solr.xml@@ -16,24 +16,52 @@limitations under the License.-->+<!--All (relative) paths are relative to the installation path-- persistent: Save changes made via the API to this file- sharedLib: path to a lib directory that will be shared across all cores-->+<solr>++ <str name="shareSchema">${shareSchema:false}</str>+ <str name="configSetBaseDir">${configSetBaseDir:configsets}</str>+ <str name="coreRootDirectory">${coreRootDirectory:.}</str>++ <shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">+ <str name="urlScheme">${urlScheme:}</str>+ <int name="socketTimeout">${socketTimeout:90000}</int>+ <int name="connTimeout">${connTimeout:15000}</int>+ </shardHandlerFactory>++ <solrcloud>+ <str name="host">127.0.0.1</str>+ <int name="hostPort">${hostPort:8983}</int>+ <str name="hostContext">${hostContext:solr}</str>+ <int name="zkClientTimeout">${solr.zkclienttimeout:30000}</int>+ <bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>+ <int name="leaderVoteWait">0</int>+ <int name="distribUpdateConnTimeout">${distribUpdateConnTimeout:45000}</int>+ <int name="distribUpdateSoTimeout">${distribUpdateSoTimeout:340000}</int>+ </solrcloud>++</solr>+++ <!--+ All (relative) paths are relative to the installation path++ persistent: Save changes made via the API to this file+ sharedLib: path to a lib directory that will be shared across all cores+<solr persistent="false">- <!--- adminPath: RequestHandler path to manage cores.- 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="${solr.zkclienttimeout:30000}" shareSchema="${shareSchema:false}"genericCoreNodeNames="${genericCoreNodeNames:true}" leaderVoteWait="0"distribUpdateConnTimeout="${distribUpdateConnTimeout:45000}" distribUpdateSoTimeout="${distribUpdateSoTimeout:340000}"><core name="collection1" instanceDir="collection1" shard="${shard:}" collection="${collection:collection1}" />- <!--config="${solrconfig:solrconfig.xml}" schema="${schema:schema.xml}"/-->+<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory"><str name="urlScheme">${urlScheme:}</str><int name="socketTimeout">${socketTimeout:90000}</int>@@ -41,3 +69,4 @@</shardHandlerFactory></cores></solr>+-->\ No newline at end of filediff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrClient.java b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrClient.javaindex f37a35ec1e7..b3e671b6829 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrClient.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrClient.java@@ -17,15 +17,8 @@package org.apache.solr.client.solrj;-import java.io.File;-import java.io.IOException;-import java.util.ArrayList;-import java.util.HashSet;-import java.util.List;-import java.util.Set;-+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;import junit.framework.Assert;-import org.apache.commons.io.FileUtils;import org.apache.http.impl.client.CloseableHttpClient;import org.apache.lucene.util.IOUtils;@@ -46,7 +39,13 @@ import org.junit.BeforeClass;import org.slf4j.Logger;import org.slf4j.LoggerFactory;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;+import java.io.File;+import java.io.IOException;+import java.nio.file.Files;+import java.util.ArrayList;+import java.util.HashSet;+import java.util.List;+import java.util.Set;/*** Test for LBHttpSolrClient@@ -268,7 +267,7 @@ public class TestLBHttpSolrClient extends SolrTestCaseJ4 {}public String getUrl() {- return buildUrl(port, "/solr");+ return buildUrl(port, "/solr/collection1");}public String getSchemaFile() {@@ -303,6 +302,7 @@ public class TestLBHttpSolrClient extends SolrTestCaseJ4 {FileUtils.copyFile(SolrTestCaseJ4.getFile(getSolrConfigFile()), f);f = new File(confDir, "schema.xml");FileUtils.copyFile(SolrTestCaseJ4.getFile(getSchemaFile()), f);+ Files.createFile(homeDir.toPath().resolve("collection1/core.properties"));}public void tearDown() throws Exception {diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/TestSolrProperties.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/TestSolrProperties.javaindex 684dec87b1d..3b94377b9e1 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/TestSolrProperties.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/TestSolrProperties.java@@ -19,16 +19,14 @@ package org.apache.solr.client.solrj.embedded;import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;import org.apache.solr.SolrTestCaseJ4;-import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.client.solrj.SolrClient;+import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;import org.apache.solr.client.solrj.request.CoreAdminRequest;import org.apache.solr.client.solrj.request.QueryRequest;import org.apache.solr.client.solrj.request.UpdateRequest;import org.apache.solr.client.solrj.response.CoreAdminResponse;import org.apache.solr.common.SolrInputDocument;-import org.apache.solr.core.SolrXMLCoresLocator;-import org.apache.solr.util.TestHarness;import org.junit.Rule;import org.junit.Test;import org.junit.rules.RuleChain;@@ -67,9 +65,6 @@ public class TestSolrProperties extends AbstractEmbeddedSolrServerTestCase {@Testpublic void testProperties() throws Exception {- SolrXMLCoresLocator.NonPersistingLocator locator- = (SolrXMLCoresLocator.NonPersistingLocator) cores.getCoresLocator();-UpdateRequest up = new UpdateRequest();up.setAction(ACTION.COMMIT, true, true);up.deleteByQuery("*:*");@@ -139,33 +134,6 @@ public class TestSolrProperties extends AbstractEmbeddedSolrServerTestCase {long after = mcr.getStartTime(name).getTime();assertTrue("should have more recent time: " + after + "," + before, after > before);- TestHarness.validateXPath(locator.xml,- "/solr/cores[@defaultCoreName='core0']",- "/solr/cores[@host='127.0.0.1']",- "/solr/cores[@hostPort='${hostPort:8983}']",- "/solr/cores[@zkClientTimeout='8000']",- "/solr/cores[@hostContext='${hostContext:solr}']",- "/solr/cores[@genericCoreNodeNames='${genericCoreNodeNames:true}']"- );-- CoreAdminRequest.renameCore(name, "renamed_core", coreadmin);-- TestHarness.validateXPath(locator.xml,- "/solr/cores/core[@name='renamed_core']",- "/solr/cores/core[@instanceDir='${theInstanceDir:./}']",- "/solr/cores/core[@collection='${collection:acollection}']"- );-- coreadmin = getRenamedSolrAdmin();- File dataDir = new File(tempDir,"data3");- File tlogDir = new File(tempDir,"tlog3");-- CoreAdminRequest.createCore("newCore", SOLR_HOME.getAbsolutePath(),- coreadmin, null, null, dataDir.getAbsolutePath(),- tlogDir.getAbsolutePath());-- TestHarness.validateXPath(locator.xml, "/solr/cores/core[@name='collection1' and @instanceDir='.']");-}}diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.javaindex e187e632583..c381483a89a 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java@@ -110,6 +110,7 @@ public class TestCoreAdmin extends AbstractEmbeddedSolrServerTestCase {req.setInstanceDir(newCoreInstanceDir.getAbsolutePath() + File.separator + "newcore");req.setDataDir(dataDir.getAbsolutePath());req.setUlogDir(new File(dataDir, "ulog").getAbsolutePath());+ req.setConfigSet("shared");// These should be the inverse of defaults.req.setIsLoadOnStartup(false);diff --git a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.javaindex 61851b8c8fa..e573d2cba3b 100644--- a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java+++ b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java@@ -45,6 +45,7 @@ import org.slf4j.LoggerFactory;import java.io.File;import java.io.IOException;+import java.nio.file.Path;import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;@@ -53,6 +54,7 @@ import java.util.HashMap;import java.util.HashSet;import java.util.List;import java.util.Map;+import java.util.Properties;import java.util.Random;import java.util.Set;import java.util.SortedMap;@@ -285,25 +287,33 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {}protected JettySolrRunner createControlJetty() throws Exception {+ writeCoreProperties(testDir.toPath().resolve("control/cores"), DEFAULT_TEST_CORENAME);+ System.setProperty("coreRootDirectory", testDir.toPath().resolve("control").toString());JettySolrRunner jetty = createJetty(new File(getSolrHome()), testDir + "/control/data", null, getSolrConfigFile(), getSchemaFile());return jetty;}-+protected void createServers(int numShards) throws Exception {- controlJetty = createControlJetty();+ System.setProperty("configSetBaseDir", getSolrHome());++ controlJetty = createControlJetty();controlClient = createNewSolrClient(controlJetty.getLocalPort());shardsArr = new String[numShards];StringBuilder sb = new StringBuilder();for (int i = 0; i < numShards; i++) {if (sb.length() > 0) sb.append(',');+ String shardname = "shard" + i;+ Path coresPath = testDir.toPath().resolve(shardname).resolve("cores");+ writeCoreProperties(coresPath, DEFAULT_TEST_CORENAME);+ System.setProperty("coreRootDirectory", testDir.toPath().resolve(shardname).toString());JettySolrRunner j = createJetty(new File(getSolrHome()),testDir + "/shard" + i + "/data", null, getSolrConfigFile(),getSchemaFile());jettys.add(j);clients.add(createNewSolrClient(j.getLocalPort()));- String shardStr = buildUrl(j.getLocalPort());+ String shardStr = buildUrl(j.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME;shardsArr[i] = shardStr;sb.append(shardStr);}@@ -389,7 +399,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {protected SolrClient createNewSolrClient(int port) {try {// setup the client...- HttpSolrClient client = new HttpSolrClient(buildUrl(port));+ HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/" + DEFAULT_TEST_CORENAME);client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);client.setSoTimeout(90000);client.setDefaultMaxConnectionsPerHost(100);@@ -931,6 +941,20 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {if (solrxml != null) {FileUtils.copyFile(new File(getSolrHome(), solrxml), new File(jettyHome, "solr.xml"));}++ Properties coreProperties = new Properties();+ coreProperties.setProperty("name", "collection1");+ coreProperties.setProperty("shard", "${shard:}");+ coreProperties.setProperty("collection", "${collection:collection1}");+ coreProperties.setProperty("config", "${solrconfig:solrconfig.xml}");+ coreProperties.setProperty("schema", "${schema:schema.xml}");+ coreProperties.setProperty("coreNodeName", "${coreNodeName:}");++ writeCoreProperties(jettyHome.toPath().resolve("cores/collection1"), coreProperties, "collection1");++ // <core name="collection1" instanceDir="collection1" shard="${shard:}"+ // collection="${collection:collection1}" config="${solrconfig:solrconfig.xml}" schema="${schema:schema.xml}"+ //coreNodeName="${coreNodeName:}"/>}}diff --git a/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java b/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.javaindex e23ad317b5a..b7bcd2cdfb7 100644--- a/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java+++ b/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java@@ -17,11 +17,6 @@ package org.apache.solr;* limitations under the License.*/-import java.io.File;-import java.io.OutputStreamWriter;-import java.util.Properties;-import java.util.SortedMap;-import org.apache.commons.io.FileUtils;import org.apache.lucene.util.LuceneTestCase;import org.apache.solr.client.solrj.SolrClient;@@ -35,6 +30,12 @@ import org.junit.BeforeClass;import org.slf4j.Logger;import org.slf4j.LoggerFactory;+import java.io.File;+import java.io.OutputStreamWriter;+import java.nio.file.Path;+import java.util.Properties;+import java.util.SortedMap;+abstract public class SolrJettyTestBase extends SolrTestCaseJ4{@@ -57,6 +58,19 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4// creates the data dirinitCore(null, null, solrHome);+ Path coresDir = createTempDir().resolve("cores");++ System.setProperty("coreRootDirectory", coresDir.toString());+ System.setProperty("configSetBaseDir", solrHome);++ Properties props = new Properties();+ props.setProperty("name", DEFAULT_TEST_CORENAME);+ props.setProperty("configSet", "collection1");+ props.setProperty("config", "${solrconfig:solrconfig.xml}");+ props.setProperty("schema", "${schema:schema.xml}");++ writeCoreProperties(coresDir.resolve("core"), props, "RestTestBase");+ignoreException("maxWarmingSearchers");context = context==null ? "/solr" : context;@@ -120,7 +134,7 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4throw new RuntimeException( ex );}} else {- return new EmbeddedSolrServer( h.getCoreContainer(), "" );+ return new EmbeddedSolrServer( h.getCoreContainer(), "collection1" );}}diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.javaindex 4d865056fe8..b7f484197d6 100644--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java@@ -17,40 +17,9 @@package org.apache.solr;-import static com.google.common.base.Preconditions.checkNotNull;--import java.io.File;-import java.io.IOException;-import java.io.Reader;-import java.io.StringReader;-import java.io.StringWriter;-import java.lang.annotation.Documented;-import java.lang.annotation.ElementType;-import java.lang.annotation.Inherited;-import java.lang.annotation.Retention;-import java.lang.annotation.RetentionPolicy;-import java.lang.annotation.Target;-import java.net.URL;-import java.nio.file.Path;-import java.util.ArrayList;-import java.util.Arrays;-import java.util.Comparator;-import java.util.Date;-import java.util.HashMap;-import java.util.HashSet;-import java.util.Iterator;-import java.util.LinkedHashMap;-import java.util.List;-import java.util.Locale;-import java.util.Map;-import java.util.Properties;-import java.util.logging.ConsoleHandler;-import java.util.logging.Handler;-import java.util.logging.Level;-import java.util.regex.Pattern;--import javax.xml.xpath.XPathExpressionException;-+import com.carrotsearch.randomizedtesting.RandomizedContext;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;+import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;import org.apache.commons.codec.Charsets;import org.apache.commons.io.FileUtils;import org.apache.lucene.analysis.MockAnalyzer;@@ -77,7 +46,6 @@ import org.apache.solr.common.params.SolrParams;import org.apache.solr.common.util.ObjectReleaseTracker;import org.apache.solr.common.util.XML;import org.apache.solr.core.ConfigSolr;-import org.apache.solr.core.ConfigSolrXmlOld;import org.apache.solr.core.CoreContainer;import org.apache.solr.core.CoreDescriptor;import org.apache.solr.core.SolrConfig;@@ -109,9 +77,42 @@ import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.xml.sax.SAXException;-import com.carrotsearch.randomizedtesting.RandomizedContext;-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;-import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;+import javax.xml.xpath.XPathExpressionException;+import java.io.File;+import java.io.IOException;+import java.io.OutputStreamWriter;+import java.io.Reader;+import java.io.StringReader;+import java.io.StringWriter;+import java.io.Writer;+import java.lang.annotation.Documented;+import java.lang.annotation.ElementType;+import java.lang.annotation.Inherited;+import java.lang.annotation.Retention;+import java.lang.annotation.RetentionPolicy;+import java.lang.annotation.Target;+import java.net.URL;+import java.nio.charset.Charset;+import java.nio.file.Files;+import java.nio.file.Path;+import java.util.ArrayList;+import java.util.Arrays;+import java.util.Comparator;+import java.util.Date;+import java.util.HashMap;+import java.util.HashSet;+import java.util.Iterator;+import java.util.LinkedHashMap;+import java.util.List;+import java.util.Locale;+import java.util.Map;+import java.util.Properties;+import java.util.logging.ConsoleHandler;+import java.util.logging.Handler;+import java.util.logging.Level;+import java.util.regex.Pattern;++import static com.google.common.base.Preconditions.checkNotNull;/*** A junit4 Solr test harness that extends LuceneTestCaseJ4. To change which core is used when loading the schema and solrconfig.xml, simply@@ -125,9 +126,32 @@ import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;})@SuppressSysoutChecks(bugUrl = "Solr dumps tons of logs to console.")public abstract class SolrTestCaseJ4 extends LuceneTestCase {- private static String coreName = ConfigSolrXmlOld.DEFAULT_DEFAULT_CORE_NAME;++ public static final String DEFAULT_TEST_CORENAME = "collection1";++ private static String coreName = DEFAULT_TEST_CORENAME;+public static int DEFAULT_CONNECTION_TIMEOUT = 60000; // default socket connection timeout in ms+ protected void writeCoreProperties(Path coreDirectory, String corename) throws IOException {+ Properties props = new Properties();+ props.setProperty("name", corename);+ props.setProperty("configSet", "collection1");+ props.setProperty("config", "${solrconfig:solrconfig.xml}");+ props.setProperty("schema", "${schema:schema.xml}");++ writeCoreProperties(coreDirectory, props, this.getTestName());+ }++ public static void writeCoreProperties(Path coreDirectory, Properties properties, String testname) throws IOException {+ log.info("Writing core.properties file to {}", coreDirectory);+ Files.createDirectories(coreDirectory);+ try (Writer writer =+ new OutputStreamWriter(Files.newOutputStream(coreDirectory.resolve("core.properties")), Charset.forName("UTF-8"))) {+ properties.store(writer, testname);+ }+ }+/*** Annotation for test classes that want to disable SSL*/@@ -188,7 +212,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {endTrackingSearchers();assertTrue("Some resources were not closed, shutdown, or released.", ObjectReleaseTracker.clearObjectTrackerAndCheckEmpty());resetFactory();- coreName = ConfigSolrXmlOld.DEFAULT_DEFAULT_CORE_NAME;+ coreName = DEFAULT_TEST_CORENAME;} finally {initCoreDataDir = null;System.clearProperty("zookeeper.forceSync");@@ -290,7 +314,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {FileUtils.write(tmpFile, xmlStr, IOUtils.UTF_8);SolrResourceLoader loader = new SolrResourceLoader(solrHome.getAbsolutePath());- h = new TestHarness(loader, ConfigSolr.fromFile(loader, new File(solrHome, "solr.xml")));+ h = new TestHarness(ConfigSolr.fromFile(loader, new File(solrHome, "solr.xml")));lrf = h.getRequestFactory("standard", 0, 20, CommonParams.VERSION, "2.2");}@@ -572,6 +596,19 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {return h.getCoreContainer();}+ public static CoreContainer createCoreContainer(ConfigSolr config) {+ testSolrHome = config.getSolrResourceLoader().getInstanceDir();+ h = new TestHarness(config);+ lrf = h.getRequestFactory("standard", 0, 20, CommonParams.VERSION, "2.2");+ return h.getCoreContainer();+ }++ public static CoreContainer createCoreContainer(String coreName, String dataDir, String solrConfig, String schema) {+ CoreContainer cc = createCoreContainer(new TestHarness.TestConfigSolr(coreName, dataDir, solrConfig, schema));+ h.coreName = coreName;+ return cc;+ }+public static CoreContainer createDefaultCoreContainer(String solrHome) {testSolrHome = checkNotNull(solrHome);h = new TestHarness("collection1", initCoreDataDir.getAbsolutePath(), "solrconfig.xml", "schema.xml");@@ -1780,7 +1817,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {copyMinConf(dstRoot, null);}- // Creates a minimal conf dir. Optionally adding in a core.properties file from the string passed in+ // Creates a minimal conf dir, adding in a core.properties file from the string passed in// the string to write to the core.properties file may be null in which case nothing is done with it.// propertiesContent may be an empty string, which will actually work.public static void copyMinConf(File dstRoot, String propertiesContent) throws IOException {@@ -1789,6 +1826,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {if (! dstRoot.exists()) {assertTrue("Failed to make subdirectory ", dstRoot.mkdirs());}+ Files.createFile(dstRoot.toPath().resolve("core.properties"));if (propertiesContent != null) {FileUtils.writeStringToFile(new File(dstRoot, "core.properties"), propertiesContent, Charsets.UTF_8.toString());}diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.javaindex 41722309b55..9d459ad67d5 100644--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java@@ -281,9 +281,10 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTestry {- File controlJettyDir = createTempDir().toFile();+ File controlJettyDir = createTempDir("control").toFile();setupJettySolrHome(controlJettyDir);-++ System.setProperty("coreRootDirectory", controlJettyDir.toPath().resolve("cores").toString());controlJetty = createJetty(controlJettyDir, useJettyDataDir ? getDataDir(testDir+ "/control/data") : null); // don't pass shard name... let it default to// "shard1"@@ -393,11 +394,12 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTesif (sb.length() > 0) sb.append(',');int cnt = this.jettyIntCntr.incrementAndGet();- File jettyDir = createTempDir().toFile();+ File jettyDir = createTempDir("shard-" + i).toFile();jettyDir.mkdirs();setupJettySolrHome(jettyDir);log.info("create jetty " + i);+ System.setProperty("coreRootDirectory", jettyDir.toPath().resolve("cores").toString());JettySolrRunner j = createJetty(jettyDir, useJettyDataDir ? getDataDir(testDir + "/jetty"+ cnt) : null, null, "solrconfig.xml", null);jettys.add(j);diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.javaindex 2535e70ff1d..382d3d497d1 100644--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.java+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.java@@ -17,10 +17,6 @@ package org.apache.solr.cloud;* limitations under the License.*/-import java.io.File;-import java.util.HashMap;-import java.util.Map;-import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.common.cloud.SolrZkClient;import org.apache.solr.common.cloud.ZkNodeProps;@@ -31,6 +27,10 @@ import org.junit.BeforeClass;import org.slf4j.Logger;import org.slf4j.LoggerFactory;+import java.io.File;+import java.util.HashMap;+import java.util.Map;+/*** Base test class for ZooKeeper tests.*/@@ -74,7 +74,7 @@ public abstract class AbstractZkTestCase extends SolrTestCaseJ4 {buildZooKeeper(zkServer.getZkHost(), zkServer.getZkAddress(), SOLRHOME,"solrconfig.xml", "schema.xml");-+initCore("solrconfig.xml", "schema.xml");}diff --git a/solr/test-framework/src/java/org/apache/solr/util/ReadOnlyCoresLocator.java b/solr/test-framework/src/java/org/apache/solr/util/ReadOnlyCoresLocator.javanew file mode 100644index 00000000000..af370a95784--- /dev/null+++ b/solr/test-framework/src/java/org/apache/solr/util/ReadOnlyCoresLocator.java@@ -0,0 +1,51 @@+package org.apache.solr.util;++/*+ * 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.+ */++import org.apache.solr.core.CoreContainer;+import org.apache.solr.core.CoreDescriptor;+import org.apache.solr.core.CoresLocator;++public abstract class ReadOnlyCoresLocator implements CoresLocator {++ @Override+ public void create(CoreContainer cc, CoreDescriptor... coreDescriptors) {+ // no-op+ }++ @Override+ public void persist(CoreContainer cc, CoreDescriptor... coreDescriptors) {+ // no-op+ }++ @Override+ public void delete(CoreContainer cc, CoreDescriptor... coreDescriptors) {+ // no-op+ }++ @Override+ public void rename(CoreContainer cc, CoreDescriptor oldCD, CoreDescriptor newCD) {+ // no-op+ }++ @Override+ public void swap(CoreContainer cc, CoreDescriptor cd1, CoreDescriptor cd2) {+ // no-op+ }++}diff --git a/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java b/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.javaindex 5ab8d22a907..09227b9e189 100644--- a/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java+++ b/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java@@ -16,12 +16,6 @@ package org.apache.solr.util;* limitations under the License.*/-import java.io.IOException;-import java.util.Map;-import java.util.SortedMap;--import javax.xml.xpath.XPathExpressionException;-import org.apache.solr.JSONTestUtil;import org.apache.solr.SolrJettyTestBase;import org.apache.solr.common.SolrException;@@ -29,11 +23,15 @@ import org.apache.solr.common.params.MultiMapSolrParams;import org.apache.solr.common.util.StrUtils;import org.apache.solr.servlet.SolrRequestParsers;import org.eclipse.jetty.servlet.ServletHolder;+import org.junit.AfterClass;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.xml.sax.SAXException;-import org.junit.AfterClass;+import javax.xml.xpath.XPathExpressionException;+import java.io.IOException;+import java.util.Map;+import java.util.SortedMap;abstract public class RestTestBase extends SolrJettyTestBase {private static final Logger log = LoggerFactory.getLogger(RestTestBase.class);@@ -56,7 +54,7 @@ abstract public class RestTestBase extends SolrJettyTestBase {restTestHarness = new RestTestHarness(new RESTfulServerProvider() {@Overridepublic String getBaseURL() {- return jetty.getBaseUrl().toString();+ return jetty.getBaseUrl().toString() + "/" + DEFAULT_TEST_CORENAME;}});}diff --git a/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java b/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.javaindex 0a856118c15..1fa50148435 100644--- a/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java+++ b/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java@@ -16,14 +16,6 @@ package org.apache.solr.util;* limitations under the License.*/-import java.io.Closeable;-import java.io.IOException;-import java.net.URLEncoder;-import java.nio.charset.StandardCharsets;--import javax.xml.xpath.XPathConstants;-import javax.xml.xpath.XPathExpressionException;-import org.apache.http.HttpEntity;import org.apache.http.client.methods.HttpDelete;import org.apache.http.client.methods.HttpGet;@@ -37,6 +29,13 @@ import org.apache.http.util.EntityUtils;import org.apache.solr.client.solrj.impl.HttpClientUtil;import org.apache.solr.common.params.ModifiableSolrParams;+import javax.xml.xpath.XPathConstants;+import javax.xml.xpath.XPathExpressionException;+import java.io.Closeable;+import java.io.IOException;+import java.net.URLEncoder;+import java.nio.charset.StandardCharsets;+/*** Facilitates testing Solr's REST API via a provided embedded Jetty*/@@ -52,6 +51,10 @@ public class RestTestHarness extends BaseTestHarness implements Closeable {public String getBaseURL() {return serverProvider.getBaseURL();}++ public String getAdminURL() {+ return getBaseURL().replace("/collection1", "");+ }/*** Validates an XML "query" response against an array of XPath test strings@@ -97,6 +100,10 @@ public class RestTestHarness extends BaseTestHarness implements Closeable {return getResponse(new HttpGet(getBaseURL() + request));}+ public String adminQuery(String request) throws Exception {+ return getResponse(new HttpGet(getAdminURL() + request));+ }+/*** Processes a PUT request using a URL path (with no context path) + optional query params,* e.g. "/schema/fields/newfield", PUTs the given content, and returns the response content.@@ -152,17 +159,25 @@ public class RestTestHarness extends BaseTestHarness implements Closeable {}}-+ public String checkAdminResponseStatus(String xml, String code) throws Exception {+ try {+ String response = adminQuery(xml);+ String valid = validateXPath(response, "//int[@name='status']="+code );+ return (null == valid) ? null : response;+ } catch (XPathExpressionException e) {+ throw new RuntimeException("?!? static xpath has bug?", e);+ }+ }/*** Reloads the first core listed in the response to the core admin handler STATUS command*/@Overridepublic void reload() throws Exception {String coreName = (String)evaluateXPath- (query("/admin/cores?action=STATUS"),+ (adminQuery("/admin/cores?action=STATUS"),"//lst[@name='status']/lst[1]/str[@name='name']",XPathConstants.STRING);- String xml = checkResponseStatus("/admin/cores?action=RELOAD&core=" + coreName, "0");+ String xml = checkAdminResponseStatus("/admin/cores?action=RELOAD&core=" + coreName, "0");if (null != xml) {throw new RuntimeException("RELOAD failed:\n" + xml);}diff --git a/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java b/solr/test-framework/src/java/org/apache/solr/util/TestHarness.javaindex 0a09d2962b6..cf0836dc98d 100644--- a/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java+++ b/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java@@ -17,13 +17,17 @@package org.apache.solr.util;+import com.google.common.collect.ImmutableList;+import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.common.SolrException;import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.util.NamedList;import org.apache.solr.common.util.NamedList.NamedListEntry;import org.apache.solr.core.ConfigSolr;-import org.apache.solr.core.ConfigSolrXmlOld;import org.apache.solr.core.CoreContainer;+import org.apache.solr.core.CoreDescriptor;+import org.apache.solr.core.CoresLocator;+import org.apache.solr.core.PluginInfo;import org.apache.solr.core.SolrConfig;import org.apache.solr.core.SolrCore;import org.apache.solr.core.SolrResourceLoader;@@ -42,6 +46,7 @@ import java.io.File;import java.io.IOException;import java.io.StringWriter;import java.util.HashMap;+import java.util.List;import java.util.Map;/**@@ -57,7 +62,7 @@ import java.util.Map;**/public class TestHarness extends BaseTestHarness {- String coreName;+ public String coreName;protected volatile CoreContainer container;public UpdateRequestHandler updater;@@ -78,11 +83,10 @@ public class TestHarness extends BaseTestHarness {}/**- * Creates a SolrConfig object for the- * {@link ConfigSolrXmlOld#DEFAULT_DEFAULT_CORE_NAME} core using {@link #createConfig(String,String,String)}+ * Creates a SolrConfig object for the default test core using {@link #createConfig(String,String,String)}*/public static SolrConfig createConfig(String solrHome, String confFile) {- return createConfig(solrHome, ConfigSolrXmlOld.DEFAULT_DEFAULT_CORE_NAME, confFile);+ return createConfig(solrHome, SolrTestCaseJ4.DEFAULT_TEST_CORENAME, confFile);}/**@@ -116,7 +120,7 @@ public class TestHarness extends BaseTestHarness {public TestHarness( String dataDirectory,SolrConfig solrConfig,IndexSchema indexSchema) {- this(ConfigSolrXmlOld.DEFAULT_DEFAULT_CORE_NAME, dataDirectory, solrConfig, indexSchema);+ this(SolrTestCaseJ4.DEFAULT_TEST_CORENAME, dataDirectory, solrConfig, indexSchema);}/**@@ -126,21 +130,9 @@ public class TestHarness extends BaseTestHarness {* @param indexSchema schema resource name*/public TestHarness(String coreName, String dataDir, String solrConfig, String indexSchema) {- try {- if (coreName == null)- coreName = ConfigSolrXmlOld.DEFAULT_DEFAULT_CORE_NAME;- this.coreName = coreName;-- SolrResourceLoader loader = new SolrResourceLoader(SolrResourceLoader.locateSolrHome());- ConfigSolr config = getTestHarnessConfig(loader, coreName, dataDir, solrConfig, indexSchema);- container = new CoreContainer(loader, config);- container.load();-- updater = new UpdateRequestHandler();- updater.init( null );- } catch (Exception e) {- throw new RuntimeException(e);- }+ this(new TestConfigSolr(new SolrResourceLoader(SolrResourceLoader.locateSolrHome()),+ coreName, dataDir, solrConfig, indexSchema));+ this.coreName = (coreName == null) ? SolrTestCaseJ4.DEFAULT_TEST_CORENAME : coreName;}public TestHarness(String coreName, String dataDir, SolrConfig solrConfig, IndexSchema indexSchema) {@@ -162,38 +154,81 @@ public class TestHarness extends BaseTestHarness {* @param solrXml the text of a solrxml*/public TestHarness(SolrResourceLoader loader, String solrXml) {- this(loader, ConfigSolr.fromString(loader, solrXml));+ this(ConfigSolr.fromString(loader, solrXml));}/**- * Create a TestHarness using a specific resource loader and config- * @param loader the SolrResourceLoader to use+ * Create a TestHarness using a specific config* @param config the ConfigSolr to use*/- public TestHarness(SolrResourceLoader loader, ConfigSolr config) {- container = new CoreContainer(loader, config);+ public TestHarness(ConfigSolr config) {+ container = new CoreContainer(config);container.load();updater = new UpdateRequestHandler();updater.init(null);}- private static ConfigSolr getTestHarnessConfig(SolrResourceLoader loader, String coreName, String dataDir,- String solrConfig, String schema) {- String solrxml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"- + "<solr persistent=\"false\">\n"- + " <cores adminPath=\"/admin/cores\" defaultCoreName=\""- + ConfigSolrXmlOld.DEFAULT_DEFAULT_CORE_NAME- + "\""- + " host=\"${host:}\" hostPort=\"${hostPort:}\" hostContext=\"${hostContext:}\""- + " distribUpdateSoTimeout=\"30000\""- + " zkClientTimeout=\"${zkClientTimeout:30000}\" distribUpdateConnTimeout=\"30000\""- + ">\n"- + " <core name=\"" + coreName + "\" config=\"" + solrConfig- + "\" schema=\"" + schema + "\" dataDir=\"" + dataDir- + "\" transient=\"false\" loadOnStartup=\"true\""- + " shard=\"${shard:shard1}\" collection=\"${collection:collection1}\" instanceDir=\"" + coreName + "/\" />\n"- + " </cores>\n" + "</solr>";- return ConfigSolr.fromString(loader, solrxml);+ public static class TestConfigSolr extends ConfigSolr {++ final CoresLocator locator;++ public TestConfigSolr(String coreName, String dataDir, String solrConfig, String schema) {+ this(new SolrResourceLoader(SolrResourceLoader.locateSolrHome()), coreName, dataDir, solrConfig, schema);+ }++ public TestConfigSolr(SolrResourceLoader loader, String coreName, String dataDir, String solrConfig, String schema) {+ super(loader);+ locator = new TestCoresLocator(coreName, dataDir, solrConfig, schema);+ }++ @Override+ public CoresLocator getCoresLocator() {+ return locator;+ }++ @Override+ public PluginInfo getShardHandlerFactoryPluginInfo() {+ return null;+ }++ @Override+ protected String getProperty(CfgProp key) {+ switch (key) {+ case SOLR_HOST: return System.getProperty("host");+ case SOLR_HOSTPORT: return System.getProperty("hostPort", "");+ case SOLR_HOSTCONTEXT: return System.getProperty("hostContext", "");+ case SOLR_DISTRIBUPDATESOTIMEOUT: return "30000";+ case SOLR_ZKCLIENTTIMEOUT: return System.getProperty("zkClientTimeout", "30000");+ case SOLR_DISTRIBUPDATECONNTIMEOUT: return "30000";+ case SOLR_SHARESCHEMA: return System.getProperty("shareSchema", "false");+ }+ return null;+ }+ }++ public static class TestCoresLocator extends ReadOnlyCoresLocator {++ final String coreName;+ final String dataDir;+ final String solrConfig;+ final String schema;++ public TestCoresLocator(String coreName, String dataDir, String solrConfig, String schema) {+ this.coreName = coreName == null ? SolrTestCaseJ4.DEFAULT_TEST_CORENAME : coreName;+ this.dataDir = dataDir;+ this.schema = schema;+ this.solrConfig = solrConfig;+ }++ @Override+ public List<CoreDescriptor> discover(CoreContainer cc) {+ return ImmutableList.of(new CoreDescriptor(cc, coreName, coreName,+ CoreDescriptor.CORE_DATADIR, dataDir,+ CoreDescriptor.CORE_CONFIG, solrConfig,+ CoreDescriptor.CORE_SCHEMA, schema,+ CoreDescriptor.CORE_COLLECTION, System.getProperty("collection", "collection1"),+ CoreDescriptor.CORE_SHARD, System.getProperty("shard", "shard1")));+ }}public CoreContainer getCoreContainer() {@@ -289,7 +324,8 @@ public class TestHarness extends BaseTestHarness {* @see LocalSolrQueryRequest*/public String query(String handler, SolrQueryRequest req) throws Exception {- try (SolrCore core = getCoreInc()) {+ try {+ SolrCore core = req.getCore();SolrQueryResponse rsp = new SolrQueryResponse();SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));core.execute(core.getRequestHandler(handler),req,rsp);