SOLR-4948: Tidy up CoreContainer construction logic

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1498990 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Alan Woodward 2013-07-02 15:50:49 +00:00
parent 42b3251408
commit f38c5163cc
45 changed files with 773 additions and 778 deletions

View File

@ -47,6 +47,8 @@ Other Changes
* SOLR-4792: Stop shipping a .war. (Robert Muir) * SOLR-4792: Stop shipping a .war. (Robert Muir)
* SOLR-4948: Tidied up CoreContainer construction logic. (Alan Woodward)
================== 4.4.0 ================== ================== 4.4.0 ==================
Versions of Major Components Versions of Major Components

View File

@ -60,7 +60,8 @@ public class TestZKPropertiesWriter extends AbstractDataImportHandlerTestCase {
AbstractZkTestCase.buildZooKeeper(zkServer.getZkHost(), zkServer.getZkAddress(), getFile("dih/solr"), AbstractZkTestCase.buildZooKeeper(zkServer.getZkHost(), zkServer.getZkAddress(), getFile("dih/solr"),
"dataimport-solrconfig.xml", "dataimport-schema.xml"); "dataimport-solrconfig.xml", "dataimport-schema.xml");
initCore("dataimport-solrconfig.xml", "dataimport-schema.xml", getFile("dih/solr").getAbsolutePath()); //initCore("solrconfig.xml", "schema.xml", getFile("dih/solr").getAbsolutePath());
createDefaultCoreContainer(getFile("dih/solr").getAbsolutePath());
} }
@Before @Before

View File

@ -1,14 +1,5 @@
package org.apache.solr.cloud; package org.apache.solr.cloud;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.concurrent.TimeoutException;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.HelpFormatter;
@ -17,13 +8,9 @@ import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options; import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException; import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser; import org.apache.commons.cli.PosixParser;
import org.apache.commons.io.IOUtils;
import org.apache.solr.common.cloud.OnReconnect; import org.apache.solr.common.cloud.OnReconnect;
import org.apache.solr.common.cloud.SolrZkClient; import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.core.Config;
import org.apache.solr.core.ConfigSolr; import org.apache.solr.core.ConfigSolr;
import org.apache.solr.core.ConfigSolrXml;
import org.apache.solr.core.ConfigSolrXmlOld;
import org.apache.solr.core.SolrResourceLoader; import org.apache.solr.core.SolrResourceLoader;
import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.KeeperException;
@ -32,6 +19,12 @@ import org.apache.zookeeper.data.ACL;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeoutException;
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
@ -183,25 +176,7 @@ public class ZkCLI {
SolrResourceLoader loader = new SolrResourceLoader(solrHome); SolrResourceLoader loader = new SolrResourceLoader(solrHome);
solrHome = loader.getInstanceDir(); solrHome = loader.getInstanceDir();
File configFile = new File(solrHome, SOLR_XML); ConfigSolr cfg = ConfigSolr.fromSolrHome(solrHome);
InputStream is = new FileInputStream(configFile);
ConfigSolr cfg;
try {
Config config = new Config(loader, null, new InputSource(is), null, false);
boolean oldStyle = (config.getNode("solr/cores", false) != null);
if (oldStyle) {
cfg = new ConfigSolrXmlOld(config, null);
} else {
cfg = new ConfigSolrXml(config, null);
}
} finally {
IOUtils.closeQuietly(is);
}
if(!ZkController.checkChrootPath(zkServerAddress, true)) { if(!ZkController.checkChrootPath(zkServerAddress, true)) {
System.out.println("A chroot was specified in zkHost but the znode doesn't exist. "); System.out.println("A chroot was specified in zkHost but the znode doesn't exist. ");

View File

@ -17,28 +17,6 @@ package org.apache.solr.cloud;
* limitations under the License. * limitations under the License.
*/ */
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.URLEncoder;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.solr.client.solrj.impl.HttpSolrServer; import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.request.CoreAdminRequest.WaitForState; import org.apache.solr.client.solrj.request.CoreAdminRequest.WaitForState;
@ -74,6 +52,28 @@ import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.URLEncoder;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** /**
* Handle ZooKeeper interactions. * Handle ZooKeeper interactions.
* *

View File

@ -68,6 +68,7 @@ public class Config {
static final XPathFactory xpathFactory = XPathFactory.newInstance(); static final XPathFactory xpathFactory = XPathFactory.newInstance();
private final Document doc; private final Document doc;
private final Document origDoc; // with unsubstituted properties
private final String prefix; private final String prefix;
private final String name; private final String name;
private final SolrResourceLoader loader; private final SolrResourceLoader loader;
@ -131,6 +132,7 @@ public class Config {
db.setErrorHandler(xmllog); db.setErrorHandler(xmllog);
try { try {
doc = db.parse(is); doc = db.parse(is);
origDoc = copyDoc(doc);
} finally { } finally {
// some XML parsers are broken and don't close the byte stream (but they should according to spec) // some XML parsers are broken and don't close the byte stream (but they should according to spec)
IOUtils.closeQuietly(is.getByteStream()); IOUtils.closeQuietly(is.getByteStream());
@ -140,19 +142,24 @@ public class Config {
} }
} catch (ParserConfigurationException e) { } catch (ParserConfigurationException e) {
SolrException.log(log, "Exception during parsing file: " + name, e); SolrException.log(log, "Exception during parsing file: " + name, e);
throw e; throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
} catch (SAXException e) { } catch (SAXException e) {
SolrException.log(log, "Exception during parsing file: " + name, e); SolrException.log(log, "Exception during parsing file: " + name, e);
throw e; throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
} catch( SolrException e ){ } catch (TransformerException e) {
SolrException.log(log,"Error in "+name,e); SolrException.log(log, "Exception during parsing file: " + name, e);
throw e; throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
} }
} }
public Config(SolrResourceLoader loader, String name, Document doc) { public Config(SolrResourceLoader loader, String name, Document doc) {
this.prefix = null; this.prefix = null;
this.doc = doc; this.doc = doc;
try {
this.origDoc = copyDoc(doc);
} catch (TransformerException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
}
this.name = name; this.name = name;
this.loader = loader; this.loader = loader;
} }
@ -441,4 +448,9 @@ public class Config {
return version; return version;
} }
public Config getOriginalConfig() {
return new Config(loader, null, origDoc);
}
} }

View File

@ -17,15 +17,8 @@ package org.apache.solr.core;
* limitations under the License. * limitations under the License.
*/ */
import java.util.HashMap; import com.google.common.base.Charsets;
import java.util.List; import org.apache.commons.io.IOUtils;
import java.util.Map;
import java.util.Properties;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException;
import org.apache.solr.util.DOMUtil; import org.apache.solr.util.DOMUtil;
import org.apache.solr.util.PropertiesUtil; import org.apache.solr.util.PropertiesUtil;
@ -33,13 +26,77 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; 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.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
public abstract class ConfigSolr { public abstract class ConfigSolr {
protected static Logger log = LoggerFactory.getLogger(ConfigSolr.class); protected static Logger log = LoggerFactory.getLogger(ConfigSolr.class);
public final static String SOLR_XML_FILE = "solr.xml"; public final static String SOLR_XML_FILE = "solr.xml";
public static ConfigSolr fromFile(File configFile) {
log.info("Loading container configuration from {}", configFile.getAbsolutePath());
String solrHome = configFile.getParent();
SolrResourceLoader loader = new SolrResourceLoader(solrHome);
InputStream inputStream = null;
try {
if (!configFile.exists()) {
log.info("{} does not exist, using default configuration", configFile.getAbsolutePath());
inputStream = new ByteArrayInputStream(ConfigSolrXmlOld.DEF_SOLR_XML.getBytes(Charsets.UTF_8));
}
else {
inputStream = new FileInputStream(configFile);
}
return fromInputStream(loader, inputStream);
}
catch (Exception e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
"Could not load SOLR configuration", e);
}
finally {
IOUtils.closeQuietly(inputStream);
}
}
public static ConfigSolr fromString(SolrResourceLoader loader, String xml) {
return fromInputStream(loader, new ByteArrayInputStream(xml.getBytes(Charsets.UTF_8)));
}
public static ConfigSolr fromInputStream(SolrResourceLoader loader, InputStream is) {
try {
Config config = new Config(loader, null, new InputSource(is), null, false);
//config.substituteProperties();
return fromConfig(config);
}
catch (Exception e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
}
}
public static ConfigSolr fromSolrHome(String solrHome) {
return fromFile(new File(solrHome, SOLR_XML_FILE));
}
public static ConfigSolr fromConfig(Config config) {
boolean oldStyle = (config.getNode("solr/cores", false) != null);
return oldStyle ? new ConfigSolrXmlOld(config)
: new ConfigSolrXml(config, null);
}
// Ugly for now, but we'll at least be able to centralize all of the differences between 4x and 5x. // Ugly for now, but we'll at least be able to centralize all of the differences between 4x and 5x.
public static enum CfgProp { public static enum CfgProp {
SOLR_ADMINHANDLER, SOLR_ADMINHANDLER,
@ -79,6 +136,11 @@ public abstract class ConfigSolr {
public ConfigSolr(Config config) { public ConfigSolr(Config config) {
this.config = config; this.config = config;
} }
// for extension & testing.
protected ConfigSolr() {
}
public Config getConfig() { public Config getConfig() {
return config; return config;
@ -125,7 +187,8 @@ public abstract class ConfigSolr {
Properties properties = new Properties(); Properties properties = new Properties();
for (int i = 0; i < props.getLength(); i++) { for (int i = 0; i < props.getLength(); i++) {
Node prop = props.item(i); Node prop = props.item(i);
properties.setProperty(DOMUtil.getAttr(prop, "name"), DOMUtil.getAttr(prop, "value")); properties.setProperty(DOMUtil.getAttr(prop, "name"),
PropertiesUtil.substituteProperty(DOMUtil.getAttr(prop, "value"), null));
} }
return properties; return properties;
} }

View File

@ -17,6 +17,12 @@ package org.apache.solr.core;
* limitations under the License. * limitations under the License.
*/ */
import org.apache.commons.io.IOUtils;
import org.apache.solr.common.SolrException;
import org.apache.solr.util.PropertiesUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
@ -27,15 +33,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.io.IOUtils;
import org.apache.solr.common.SolrException;
import org.apache.solr.util.PropertiesUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
/** /**
* *
@ -46,15 +43,18 @@ public class ConfigSolrXml extends ConfigSolr {
private SolrCoreDiscoverer solrCoreDiscoverer = new SolrCoreDiscoverer(); private SolrCoreDiscoverer solrCoreDiscoverer = new SolrCoreDiscoverer();
private final Map<String, CoreDescriptor> coreDescriptorMap; private final Map<String, CoreDescriptor> coreDescriptorMap;
public ConfigSolrXml(Config config, CoreContainer container) public ConfigSolrXml(Config config, CoreContainer container) {
throws ParserConfigurationException, IOException, SAXException {
super(config); super(config);
checkForIllegalConfig(); try {
checkForIllegalConfig();
fillPropMap(); fillPropMap();
config.substituteProperties();
String coreRoot = get(CfgProp.SOLR_COREROOTDIRECTORY, (container == null ? config.getResourceLoader().getInstanceDir() : container.getSolrHome())); String coreRoot = get(CfgProp.SOLR_COREROOTDIRECTORY, (container == null ? config.getResourceLoader().getInstanceDir() : container.getSolrHome()));
coreDescriptorMap = solrCoreDiscoverer.discover(container, new File(coreRoot)); coreDescriptorMap = solrCoreDiscoverer.discover(container, new File(coreRoot));
}
catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
}
} }
private void checkForIllegalConfig() throws IOException { private void checkForIllegalConfig() throws IOException {

View File

@ -17,6 +17,17 @@ package org.apache.solr.core;
* limitations under the License. * limitations under the License.
*/ */
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.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -28,20 +39,6 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
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.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
/** /**
* *
@ -51,17 +48,20 @@ public class ConfigSolrXmlOld extends ConfigSolr {
private NodeList coreNodes = null; private NodeList coreNodes = null;
public ConfigSolrXmlOld(Config config, CoreContainer container) public ConfigSolrXmlOld(Config config) {
throws ParserConfigurationException, IOException, SAXException {
super(config); super(config);
checkForIllegalConfig(container); try {
checkForIllegalConfig();
fillPropMap(); fillPropMap();
initCoreList(container); config.substituteProperties();
initCoreList();
}
catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
}
} }
private void checkForIllegalConfig(CoreContainer container) throws IOException { private void checkForIllegalConfig() throws IOException {
// Do sanity checks - we don't want to find new style // Do sanity checks - we don't want to find new style
// config // config
failIfFound("solr/str[@name='adminHandler']"); failIfFound("solr/str[@name='adminHandler']");
@ -157,7 +157,7 @@ public class ConfigSolrXmlOld extends ConfigSolr {
} }
private void initCoreList(CoreContainer container) throws IOException { private void initCoreList() throws IOException {
coreNodes = (NodeList) config.evaluate("solr/cores/core", coreNodes = (NodeList) config.evaluate("solr/cores/core",
XPathConstants.NODESET); XPathConstants.NODESET);
@ -222,7 +222,7 @@ public class ConfigSolrXmlOld extends ConfigSolr {
NamedNodeMap attributes = node.getAttributes(); NamedNodeMap attributes = node.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) { for (int i = 0; i < attributes.getLength(); i++) {
Node attribute = attributes.item(i); Node attribute = attributes.item(i);
String val = attribute.getNodeValue(); String val = PropertiesUtil.substituteProperty(attribute.getNodeValue(), null);
if (CoreDescriptor.CORE_DATADIR.equals(attribute.getNodeName()) || if (CoreDescriptor.CORE_DATADIR.equals(attribute.getNodeName()) ||
CoreDescriptor.CORE_INSTDIR.equals(attribute.getNodeName())) { CoreDescriptor.CORE_INSTDIR.equals(attribute.getNodeName())) {
if (val.indexOf('$') == -1) { if (val.indexOf('$') == -1) {
@ -260,7 +260,8 @@ public class ConfigSolrXmlOld extends ConfigSolr {
Node node = coreNodes.item(idx); Node node = coreNodes.item(idx);
if (coreName.equals(DOMUtil.getAttr(node, CoreDescriptor.CORE_NAME, if (coreName.equals(DOMUtil.getAttr(node, CoreDescriptor.CORE_NAME,
null))) { null))) {
return DOMUtil.getAttr(node, property, defaultVal); String propVal = DOMUtil.getAttr(node, property, defaultVal);
return PropertiesUtil.substituteProperty(propVal, null);
} }
} }
} }
@ -289,16 +290,16 @@ public class ConfigSolrXmlOld extends ConfigSolr {
} }
public static final String DEF_SOLR_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" public static final String DEF_SOLR_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
+ "<solr persistent=\"false\">\n" + "<solr persistent=\"false\">\n"
+ " <cores adminPath=\"/admin/cores\" defaultCoreName=\"" + " <cores adminPath=\"/admin/cores\" defaultCoreName=\""
+ CoreContainer.DEFAULT_DEFAULT_CORE_NAME + CoreContainer.DEFAULT_DEFAULT_CORE_NAME
+ "\"" + "\""
+ " host=\"${host:}\" hostPort=\"${hostPort:}\" hostContext=\"${hostContext:}\" zkClientTimeout=\"${zkClientTimeout:15000}\"" + " host=\"${host:}\" hostPort=\"${hostPort:}\" hostContext=\"${hostContext:}\" zkClientTimeout=\"${zkClientTimeout:15000}\""
+ ">\n" + ">\n"
+ " <core name=\"" + " <core name=\""
+ CoreContainer.DEFAULT_DEFAULT_CORE_NAME + CoreContainer.DEFAULT_DEFAULT_CORE_NAME
+ "\" shard=\"${shard:}\" collection=\"${collection:}\" instanceDir=\"collection1\" />\n" + "\" shard=\"${shard:}\" collection=\"${collection:}\" instanceDir=\"collection1\" />\n"
+ " </cores>\n" + "</solr>"; + " </cores>\n" + "</solr>";
@Override @Override
public void substituteProperties() { public void substituteProperties() {

View File

@ -17,7 +17,6 @@
package org.apache.solr.core; package org.apache.solr.core;
import org.apache.commons.io.IOUtils;
import org.apache.solr.cloud.ZkController; import org.apache.solr.cloud.ZkController;
import org.apache.solr.cloud.ZkSolrResourceLoader; import org.apache.solr.cloud.ZkSolrResourceLoader;
import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException;
@ -39,21 +38,10 @@ import org.apache.solr.util.plugin.PluginInfoInitialized;
import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathExpressionException;
import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -76,6 +64,8 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* *
@ -104,15 +94,13 @@ public class CoreContainer
protected CoreAdminHandler coreAdminHandler = null; protected CoreAdminHandler coreAdminHandler = null;
protected CollectionsHandler collectionsHandler = null; protected CollectionsHandler collectionsHandler = null;
protected File configFile = null;
protected String libDir = null; protected String libDir = null;
protected SolrResourceLoader loader = null;
protected Properties containerProperties; protected Properties containerProperties;
protected Map<String ,IndexSchema> indexSchemaCache; protected Map<String ,IndexSchema> indexSchemaCache;
protected String adminHandler; protected String adminHandler;
protected boolean shareSchema; protected boolean shareSchema;
protected Integer zkClientTimeout; protected Integer zkClientTimeout;
protected String solrHome;
protected String defaultCoreName = null; protected String defaultCoreName = null;
protected int distribUpdateConnTimeout = 0; protected int distribUpdateConnTimeout = 0;
protected int distribUpdateSoTimeout = 0; protected int distribUpdateSoTimeout = 0;
@ -126,151 +114,90 @@ public class CoreContainer
private int coreLoadThreads; private int coreLoadThreads;
private CloserThread backgroundCloser = null; private CloserThread backgroundCloser = null;
protected volatile ConfigSolr cfg;
private Config origCfg; protected final ConfigSolr cfg;
protected final SolrResourceLoader loader;
protected final String solrHome;
{ {
log.info("New CoreContainer " + System.identityHashCode(this)); log.info("New CoreContainer " + System.identityHashCode(this));
} }
/** /**
* Deprecated * Create a new CoreContainer using system properties to detect the solr home
* @deprecated use the single arg constructor with locateSolrHome() * directory. The container's cores are not loaded.
* @see SolrResourceLoader#locateSolrHome * @see #load()
*/ */
@Deprecated
public CoreContainer() { public CoreContainer() {
this(SolrResourceLoader.locateSolrHome()); this(SolrResourceLoader.locateSolrHome());
} }
/** /**
* Initalize CoreContainer directly from the constructor * Create a new CoreContainer using the given SolrResourceLoader. The container's
* cores are not loaded.
* @param loader the SolrResourceLoader
* @see #load()
*/ */
public CoreContainer(String dir, File configFile) throws FileNotFoundException { public CoreContainer(SolrResourceLoader loader) {
this(dir); this(loader, ConfigSolr.fromSolrHome(loader.getInstanceDir()));
this.load(dir, configFile);
} }
/** /**
* Minimal CoreContainer constructor. * Create a new CoreContainer using the given solr home directory. The container's
* @param loader the CoreContainer resource loader * cores are not loaded.
* @param solrHome a String containing the path to the solr home directory
* @see #load()
*/ */
public CoreContainer(SolrResourceLoader loader) { public CoreContainer(String solrHome) {
this(loader.getInstanceDir()); this(new SolrResourceLoader(solrHome), ConfigSolr.fromSolrHome(solrHome));
this.loader = loader;
} }
public CoreContainer(String solrHome) { /**
this.solrHome = solrHome; * Create a new CoreContainer using the given SolrResourceLoader and
* configuration. 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);
}
/**
* Create a new CoreContainer and load its cores
* @param solrHome the solr home directory
* @param configFile the file containing this container's configuration
* @return a loaded CoreContainer
*/
public static CoreContainer createAndLoad(String solrHome, File configFile) {
CoreContainer cc = new CoreContainer(new SolrResourceLoader(solrHome), ConfigSolr.fromFile(configFile));
cc.load();
return cc;
} }
public Properties getContainerProperties() { public Properties getContainerProperties() {
return containerProperties; return containerProperties;
} }
// Helper class to initialize the CoreContainer
public static class Initializer {
// core container instantiation
public CoreContainer initialize() throws FileNotFoundException {
CoreContainer cores = null;
String solrHome = SolrResourceLoader.locateSolrHome();
// ContainerConfigFilename could could be a properties file
File fconf = new File(solrHome, "solr.xml");
log.info("looking for solr config file: " + fconf.getAbsolutePath());
cores = new CoreContainer(solrHome);
// first we find zkhost, then we check for solr.xml in zk
// 1. look for zkhost from sys prop 2. TODO: look for zkhost in {solr.home}/solr.properties
// Either we have a config file or not.
if (fconf.exists()) {
cores.load(solrHome, fconf);
} else {
// Back compart support
log.info("no solr.xml found. using default old-style solr.xml");
try {
cores.load(solrHome, new ByteArrayInputStream(ConfigSolrXmlOld.DEF_SOLR_XML.getBytes("UTF-8")), null);
} catch (Exception e) {
throw new SolrException(ErrorCode.SERVER_ERROR,
"CoreContainer.Initialize failed when trying to load default solr.xml file", e);
}
cores.configFile = fconf;
}
return cores;
}
}
//------------------------------------------------------------------- //-------------------------------------------------------------------
// Initialization / Cleanup // Initialization / Cleanup
//------------------------------------------------------------------- //-------------------------------------------------------------------
/**
* Load a config file listing the available solr cores.
* @param dir the home directory of all resources.
* @param configFile the configuration file
*/
public void load(String dir, File configFile) throws FileNotFoundException {
this.configFile = configFile;
InputStream in = new FileInputStream(configFile);
try {
this.load(dir, in, configFile.getName());
} finally {
IOUtils.closeQuietly(in);
}
}
/** /**
* Load a config file listing the available solr cores. * Load the cores defined for this CoreContainer
*
* @param dir the home directory of all resources.
* @param is the configuration file InputStream. May be a properties file or an xml file
*/ */
public void load() {
log.info("Loading cores into CoreContainer [instanceDir={}]", loader.getInstanceDir());
// Let's keep this ugly boolean out of public circulation.
protected void load(String dir, InputStream is, String fileName) {
ThreadPoolExecutor coreLoadExecutor = null; ThreadPoolExecutor coreLoadExecutor = null;
if (null == dir) {
// don't rely on SolrResourceLoader(), determine explicitly first
dir = SolrResourceLoader.locateSolrHome();
}
log.info("Loading CoreContainer using Solr Home: '{}'", dir);
this.loader = new SolrResourceLoader(dir);
solrHome = loader.getInstanceDir();
try {
Config config = new Config(loader, null, new InputSource(is), null, false);
// old style defines cores in solr.xml, new style disovers them by
// directory structure
boolean oldStyle = (config.getNode("solr/cores", false) != null);
if (oldStyle) {
// ConfigSolr handles keep orig values around for non solrcore level items,
// but this is still how original core lvl attributes are kept around
this.origCfg = new Config(loader, null, copyDoc(config.getDocument()));
this.cfg = new ConfigSolrXmlOld(config, this);
} else {
this.cfg = new ConfigSolrXml(config, this);
}
} catch (Exception e) {
throw new SolrException(ErrorCode.SERVER_ERROR, "", e);
}
// Since the cores var is now initialized to null, let's set it up right
// now.
cfg.substituteProperties();
// add the sharedLib to the shared resource loader before initializing cfg based plugins // add the sharedLib to the shared resource loader before initializing cfg based plugins
libDir = cfg.get(ConfigSolr.CfgProp.SOLR_SHAREDLIB , null); libDir = cfg.get(ConfigSolr.CfgProp.SOLR_SHAREDLIB , null);
if (libDir != null) { if (libDir != null) {
File f = FileUtils.resolvePath(new File(dir), libDir); File f = FileUtils.resolvePath(new File(solrHome), libDir);
log.info("loading shared library: " + f.getAbsolutePath()); log.info("loading shared library: " + f.getAbsolutePath());
loader.addToClassLoader(libDir, null, false); loader.addToClassLoader(libDir, null, false);
loader.reloadLuceneSPI(); loader.reloadLuceneSPI();
@ -1077,7 +1004,7 @@ public class CoreContainer
} }
public File getConfigFile() { public File getConfigFile() {
return configFile; return new File(solrHome, ConfigSolr.SOLR_XML_FILE);
} }
/** /**
@ -1091,7 +1018,7 @@ public class CoreContainer
/** Persists the cores config file in cores.xml. */ /** Persists the cores config file in cores.xml. */
@Deprecated @Deprecated
public void persist() { public void persist() {
persistFile(configFile); persistFile(getConfigFile());
} }
/** /**
@ -1112,7 +1039,7 @@ public class CoreContainer
// only the old solrxml persists // only the old solrxml persists
if (cfg != null && !(cfg instanceof ConfigSolrXmlOld)) return; if (cfg != null && !(cfg instanceof ConfigSolrXmlOld)) return;
log.info("Persisting cores config to " + (file == null ? configFile : file)); log.info("Persisting cores config to " + (file == null ? getConfigFile() : file));
// <solr attrib="value"> // <solr attrib="value">
Map<String,String> rootSolrAttribs = new HashMap<String,String>(); Map<String,String> rootSolrAttribs = new HashMap<String,String>();
@ -1186,7 +1113,7 @@ public class CoreContainer
cfg.get(ConfigSolr.CfgProp.SOLR_SHARDHANDLERFACTORY_SOCKETTIMEOUT, null)); cfg.get(ConfigSolr.CfgProp.SOLR_SHARDHANDLERFACTORY_SOCKETTIMEOUT, null));
try { try {
solrCores.persistCores(origCfg, containerProperties, rootSolrAttribs,coresAttribs, solrCores.persistCores(cfg.config.getOriginalConfig(), containerProperties, rootSolrAttribs,coresAttribs,
loggingAttribs, watcherAttribs, shardHandlerAttrib, shardHandlerProps, file, loader); loggingAttribs, watcherAttribs, shardHandlerAttrib, shardHandlerProps, file, loader);
} catch (XPathExpressionException e) { } catch (XPathExpressionException e) {
throw new SolrException(ErrorCode.SERVER_ERROR, null, e); throw new SolrException(ErrorCode.SERVER_ERROR, null, e);
@ -1262,14 +1189,7 @@ public class CoreContainer
return solrCores.getCoreToOrigName(core); return solrCores.getCoreToOrigName(core);
} }
private Document copyDoc(Document document) throws TransformerException {
TransformerFactory tfactory = TransformerFactory.newInstance();
Transformer tx = tfactory.newTransformer();
DOMSource source = new DOMSource(document);
DOMResult result = new DOMResult();
tx.transform(source,result);
return (Document)result.getNode();
}
} }
class CloserThread extends Thread { class CloserThread extends Thread {

View File

@ -17,6 +17,15 @@ package org.apache.solr.core;
* limitations under the License. * limitations under the License.
*/ */
import org.apache.commons.lang.StringUtils;
import org.apache.solr.cloud.CloudDescriptor;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.core.SolrXMLSerializer.SolrCoreXMLDef;
import org.apache.solr.util.DOMUtil;
import org.w3c.dom.Node;
import javax.xml.xpath.XPathExpressionException;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -31,16 +40,6 @@ import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import javax.xml.xpath.XPathExpressionException;
import org.apache.commons.lang.StringUtils;
import org.apache.solr.cloud.CloudDescriptor;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.core.SolrXMLSerializer.SolrCoreXMLDef;
import org.apache.solr.util.DOMUtil;
import org.w3c.dom.Node;
class SolrCores { class SolrCores {
private static SolrXMLSerializer SOLR_XML_SERIALIZER = new SolrXMLSerializer(); private static SolrXMLSerializer SOLR_XML_SERIALIZER = new SolrXMLSerializer();
@ -498,7 +497,7 @@ class SolrCores {
// Insure instdir is persisted if it's the default since it's checked at startup even if not specified on the // Insure instdir is persisted if it's the default since it's checked at startup even if not specified on the
// create command. // create command.
if (! dcore.getCreatedProperties().containsKey(CoreDescriptor.CORE_INSTDIR)) { if (! dcore.getCreatedProperties().containsKey(CoreDescriptor.CORE_INSTDIR)) {
coreAttribs.put(CoreDescriptor.CORE_INSTDIR, dcore.getProperty(CoreDescriptor.CORE_INSTDIR)); coreAttribs.put(CoreDescriptor.CORE_INSTDIR, dcore.getRawInstanceDir());
} }
} else { } else {
@ -519,7 +518,7 @@ class SolrCores {
} }
coreAttribs.put(CoreDescriptor.CORE_NAME, coreName); coreAttribs.put(CoreDescriptor.CORE_NAME, coreName);
//coreAttribs.put(CoreDescriptor.CORE_INSTDIR, dcore.getRawInstanceDir());
addCoreProperty(coreAttribs, loader, node, CoreDescriptor.CORE_INSTDIR, dcore.getRawInstanceDir(), null); addCoreProperty(coreAttribs, loader, node, CoreDescriptor.CORE_INSTDIR, dcore.getRawInstanceDir(), null);
addCoreProperty(coreAttribs, loader, node, CoreDescriptor.CORE_COLLECTION, addCoreProperty(coreAttribs, loader, node, CoreDescriptor.CORE_COLLECTION,

View File

@ -17,56 +17,58 @@
package org.apache.solr.core; package org.apache.solr.core;
import org.apache.lucene.analysis.util.CharFilterFactory;
import org.apache.lucene.analysis.util.ResourceLoaderAware;
import org.apache.lucene.analysis.util.TokenFilterFactory;
import org.apache.lucene.analysis.util.TokenizerFactory;
import org.apache.lucene.analysis.util.WordlistLoader;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.DocValuesFormat;
import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.util.IOUtils;
import org.apache.solr.common.ResourceLoader;
import org.apache.solr.common.SolrException;
import org.apache.solr.handler.admin.CoreAdminHandler;
import org.apache.solr.handler.component.SearchComponent;
import org.apache.solr.handler.component.ShardHandlerFactory;
import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.response.QueryResponseWriter;
import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.ManagedIndexSchemaFactory;
import org.apache.solr.schema.SimilarityFactory;
import org.apache.solr.search.QParserPlugin;
import org.apache.solr.update.processor.UpdateRequestProcessorFactory;
import org.apache.solr.util.FileUtils;
import org.apache.solr.util.plugin.SolrCoreAware;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.NoInitialContextException;
import java.io.Closeable; import java.io.Closeable;
import java.io.File; import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.util.*; import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.lucene.analysis.util.CharFilterFactory;
import org.apache.lucene.analysis.util.ResourceLoaderAware;
import org.apache.lucene.analysis.util.TokenFilterFactory;
import org.apache.lucene.analysis.util.TokenizerFactory;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.codecs.DocValuesFormat;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.analysis.util.WordlistLoader;
import org.apache.solr.common.ResourceLoader;
import org.apache.solr.handler.admin.CoreAdminHandler;
import org.apache.solr.handler.component.ShardHandlerFactory;
import org.apache.solr.schema.ManagedIndexSchemaFactory;
import org.apache.solr.schema.SimilarityFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.lang.reflect.Constructor;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.NoInitialContextException;
import org.apache.solr.util.FileUtils;
import org.apache.solr.common.SolrException;
import org.apache.solr.handler.component.SearchComponent;
import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.response.QueryResponseWriter;
import org.apache.solr.schema.FieldType;
import org.apache.solr.update.processor.UpdateRequestProcessorFactory;
import org.apache.solr.util.plugin.SolrCoreAware;
import org.apache.solr.search.QParserPlugin;
/** /**
* @since solr 1.3 * @since solr 1.3
*/ */

View File

@ -17,6 +17,11 @@ package org.apache.solr.core;
* limitations under the License. * limitations under the License.
*/ */
import org.apache.solr.common.SolrException;
import org.apache.solr.common.util.XML;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -30,11 +35,6 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.util.XML;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SolrXMLSerializer { public class SolrXMLSerializer {
protected static Logger log = LoggerFactory protected static Logger log = LoggerFactory
.getLogger(SolrXMLSerializer.class); .getLogger(SolrXMLSerializer.class);
@ -151,7 +151,7 @@ public class SolrXMLSerializer {
} }
void persistFile(File file, SolrXMLDef solrXMLDef) { void persistFile(File file, SolrXMLDef solrXMLDef) {
log.info("Persisting cores config to " + file); log.info("Persisting cores config to " + file.getAbsolutePath());
File tmpFile = null; File tmpFile = null;
try { try {

View File

@ -17,19 +17,6 @@
package org.apache.solr.handler.admin; package org.apache.solr.handler.admin;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Future;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.DirectoryReader;
@ -57,8 +44,8 @@ import org.apache.solr.core.CloseHook;
import org.apache.solr.core.CoreContainer; import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.CoreDescriptor; import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.core.DirectoryFactory; import org.apache.solr.core.DirectoryFactory;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.DirectoryFactory.DirContext; import org.apache.solr.core.DirectoryFactory.DirContext;
import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.RequestHandlerBase; import org.apache.solr.handler.RequestHandlerBase;
import org.apache.solr.request.LocalSolrQueryRequest; import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.request.SolrQueryRequest;
@ -75,6 +62,19 @@ import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Future;
/** /**
* *
* @since solr 1.3 * @since solr 1.3
@ -732,7 +732,9 @@ public class CoreAdminHandler extends RequestHandlerBase {
boolean doPersist = false; boolean doPersist = false;
String fileName = params.get(CoreAdminParams.FILE); String fileName = params.get(CoreAdminParams.FILE);
if (fileName != null) { if (fileName != null) {
File file = new File(coreContainer.getConfigFile().getParentFile(), fileName); File file = new File(fileName);
if (!file.isAbsolute())
file = new File(coreContainer.getConfigFile().getParentFile(), fileName);
coreContainer.persistFile(file); coreContainer.persistFile(file);
rsp.add("saved", file.getAbsolutePath()); rsp.add("saved", file.getAbsolutePath());
doPersist = false; doPersist = false;

View File

@ -137,7 +137,7 @@ public abstract class LogWatcher<E> {
v.size = config.getInt(ConfigSolr.CfgProp.SOLR_LOGGING_WATCHER_SIZE, 50); v.size = config.getInt(ConfigSolr.CfgProp.SOLR_LOGGING_WATCHER_SIZE, 50);
v.threshold = config.get(ConfigSolr.CfgProp.SOLR_LOGGING_WATCHER_THRESHOLD, null); v.threshold = config.get(ConfigSolr.CfgProp.SOLR_LOGGING_WATCHER_THRESHOLD, null);
if (v.size > 0) { if (v.size > 0) {
log.info("Registering Log Listener"); log.info("Registering Log Listener [{}]", logWatcher.getName());
logWatcher.registerListener(v); logWatcher.registerListener(v);
} }
} }

View File

@ -17,18 +17,6 @@
package org.apache.solr.schema; package org.apache.solr.schema;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.apache.lucene.analysis.util.AbstractAnalysisFactory.LUCENE_MATCH_VERSION_PARAM;
import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.Tokenizer; import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
@ -67,6 +55,18 @@ import org.apache.solr.search.Sorting;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.apache.lucene.analysis.util.AbstractAnalysisFactory.LUCENE_MATCH_VERSION_PARAM;
/** /**
* Base class for all field types used by an index schema. * Base class for all field types used by an index schema.
* *
@ -799,6 +799,15 @@ public abstract class FieldType extends FieldProperties {
namedPropertyValues.add(getPropertyName(TOKENIZED), isTokenized()); namedPropertyValues.add(getPropertyName(TOKENIZED), isTokenized());
// The BINARY property is always false // The BINARY property is always false
// namedPropertyValues.add(getPropertyName(BINARY), hasProperty(BINARY)); // namedPropertyValues.add(getPropertyName(BINARY), hasProperty(BINARY));
if (null != getSimilarityFactory()) {
namedPropertyValues.add(SIMILARITY, getSimilarityFactory().getNamedPropertyValues());
}
if (null != getPostingsFormat()) {
namedPropertyValues.add(POSTINGS_FORMAT, getPostingsFormat());
}
if (null != getDocValuesFormat()) {
namedPropertyValues.add(DOC_VALUES_FORMAT, getDocValuesFormat());
}
} else { // Don't show defaults } else { // Don't show defaults
Set<String> fieldProperties = new HashSet<String>(); Set<String> fieldProperties = new HashSet<String>();
for (String propertyName : FieldProperties.propertyNames) { for (String propertyName : FieldProperties.propertyNames) {
@ -826,15 +835,7 @@ public abstract class FieldType extends FieldProperties {
namedPropertyValues.add(MULTI_TERM_ANALYZER, getAnalyzerProperties(((TextField) this).getMultiTermAnalyzer())); namedPropertyValues.add(MULTI_TERM_ANALYZER, getAnalyzerProperties(((TextField) this).getMultiTermAnalyzer()));
} }
} }
if (null != getSimilarityFactory()) {
namedPropertyValues.add(SIMILARITY, getSimilarityFactory().getNamedPropertyValues());
}
if (null != getPostingsFormat()) {
namedPropertyValues.add(POSTINGS_FORMAT, getPostingsFormat());
}
if (null != getDocValuesFormat()) {
namedPropertyValues.add(DOC_VALUES_FORMAT, getDocValuesFormat());
}
return namedPropertyValues; return namedPropertyValues;
} }

View File

@ -17,35 +17,6 @@
package org.apache.solr.servlet; package org.apache.solr.servlet;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.WeakHashMap;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode; import org.apache.solr.common.SolrException.ErrorCode;
@ -81,6 +52,34 @@ import org.apache.solr.util.FastWriter;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.WeakHashMap;
/** /**
* This filter looks at the incoming URL maps them to handlers defined in solrconfig.xml * This filter looks at the incoming URL maps them to handlers defined in solrconfig.xml
* *
@ -116,12 +115,11 @@ public class SolrDispatchFilter implements Filter
{ {
log.info("SolrDispatchFilter.init()"); log.info("SolrDispatchFilter.init()");
CoreContainer.Initializer init = createInitializer();
try { try {
// web.xml configuration // web.xml configuration
this.pathPrefix = config.getInitParameter( "path-prefix" ); this.pathPrefix = config.getInitParameter( "path-prefix" );
this.cores = init.initialize(); this.cores = createCoreContainer();
log.info("user.dir=" + System.getProperty("user.dir")); log.info("user.dir=" + System.getProperty("user.dir"));
} }
catch( Throwable t ) { catch( Throwable t ) {
@ -132,15 +130,20 @@ public class SolrDispatchFilter implements Filter
log.info("SolrDispatchFilter.init() done"); log.info("SolrDispatchFilter.init() done");
} }
/**
* Override this to change CoreContainer initialization
* @return a CoreContainer to hold this server's cores
*/
protected CoreContainer createCoreContainer() {
CoreContainer cores = new CoreContainer();
cores.load();
return cores;
}
public CoreContainer getCores() { public CoreContainer getCores() {
return cores; return cores;
} }
/** Method to override to change how CoreContainer initialization is performed. */
protected CoreContainer.Initializer createInitializer() {
return new CoreContainer.Initializer();
}
@Override @Override
public void destroy() { public void destroy() {

View File

@ -17,11 +17,6 @@ package org.apache.solr.cloud;
* limitations under the License. * limitations under the License.
*/ */
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.apache.lucene.util.LuceneTestCase.Slow; import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.cloud.ClusterState; import org.apache.solr.common.cloud.ClusterState;
@ -31,7 +26,6 @@ import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.cloud.ZkNodeProps; import org.apache.solr.common.cloud.ZkNodeProps;
import org.apache.solr.common.cloud.ZkStateReader; import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.core.CoreContainer; import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.CoreContainer.Initializer;
import org.apache.solr.core.CoreDescriptor; import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrCore;
import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.CreateMode;
@ -41,6 +35,11 @@ import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@Slow @Slow
public class ClusterStateUpdateTest extends SolrTestCaseJ4 { public class ClusterStateUpdateTest extends SolrTestCaseJ4 {
protected static Logger log = LoggerFactory protected static Logger log = LoggerFactory
@ -65,8 +64,6 @@ public class ClusterStateUpdateTest extends SolrTestCaseJ4 {
private File dataDir3; private File dataDir3;
private File dataDir4; private File dataDir4;
private Initializer init2;
@BeforeClass @BeforeClass
public static void beforeClass() { public static void beforeClass() {
@ -113,22 +110,21 @@ public class ClusterStateUpdateTest extends SolrTestCaseJ4 {
System.setProperty("solr.solr.home", TEST_HOME()); System.setProperty("solr.solr.home", TEST_HOME());
System.setProperty("hostPort", "1661"); System.setProperty("hostPort", "1661");
CoreContainer.Initializer init1 = new CoreContainer.Initializer();
System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir1.getAbsolutePath()); System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir1.getAbsolutePath());
container1 = init1.initialize(); container1 = new CoreContainer();
container1.load();
System.clearProperty("hostPort"); System.clearProperty("hostPort");
System.setProperty("hostPort", "1662"); System.setProperty("hostPort", "1662");
init2 = new CoreContainer.Initializer();
System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir2.getAbsolutePath()); System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir2.getAbsolutePath());
container2 = init2.initialize(); container2 = new CoreContainer();
container2.load();
System.clearProperty("hostPort"); System.clearProperty("hostPort");
System.setProperty("hostPort", "1663"); System.setProperty("hostPort", "1663");
CoreContainer.Initializer init3 = new CoreContainer.Initializer();
System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir3.getAbsolutePath()); System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir3.getAbsolutePath());
container3 = init3.initialize(); container3 = new CoreContainer();
container3.load();
System.clearProperty("hostPort"); System.clearProperty("hostPort");
System.clearProperty("solr.solr.home"); System.clearProperty("solr.solr.home");
@ -226,7 +222,11 @@ public class ClusterStateUpdateTest extends SolrTestCaseJ4 {
.disconnect(); .disconnect();
container2.shutdown(); container2.shutdown();
container2 = init2.initialize(); System.setProperty("hostPort", "1662");
System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir2.getAbsolutePath());
container2 = new CoreContainer();
container2.load();
System.clearProperty("hostPort");
// pause for watch to trigger // pause for watch to trigger
for(int i = 0; i < 200; i++) { for(int i = 0; i < 200; i++) {

View File

@ -17,6 +17,20 @@ package org.apache.solr.cloud;
* limitations under the License. * limitations under the License.
*/ */
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.SolrTestCaseJ4;
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.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
@ -27,22 +41,6 @@ import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.SolrTestCaseJ4;
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.CoreContainer.Initializer;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
@Slow @Slow
public class LeaderElectionIntegrationTest extends SolrTestCaseJ4 { public class LeaderElectionIntegrationTest extends SolrTestCaseJ4 {
protected static Logger log = LoggerFactory protected static Logger log = LoggerFactory
@ -140,7 +138,6 @@ public class LeaderElectionIntegrationTest extends SolrTestCaseJ4 {
System.setProperty("hostPort", Integer.toString(port)); System.setProperty("hostPort", Integer.toString(port));
System.setProperty("shard", shard); System.setProperty("shard", shard);
Initializer init = new CoreContainer.Initializer();
System.setProperty("solr.data.dir", data.getAbsolutePath()); System.setProperty("solr.data.dir", data.getAbsolutePath());
System.setProperty("solr.solr.home", TEST_HOME()); System.setProperty("solr.solr.home", TEST_HOME());
Set<Integer> ports = shardPorts.get(shard); Set<Integer> ports = shardPorts.get(shard);
@ -149,7 +146,8 @@ public class LeaderElectionIntegrationTest extends SolrTestCaseJ4 {
shardPorts.put(shard, ports); shardPorts.put(shard, ports);
} }
ports.add(port); ports.add(port);
CoreContainer container = init.initialize(); CoreContainer container = new CoreContainer();
container.load();
assertTrue("Container " + port + " has no cores!", container.getCores() assertTrue("Container " + port + " has no cores!", container.getCores()
.size() > 0); .size() > 0);
containerMap.put(port, container); containerMap.put(port, container);

View File

@ -28,7 +28,6 @@ import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.cloud.ZkNodeProps; import org.apache.solr.common.cloud.ZkNodeProps;
import org.apache.solr.common.cloud.ZkStateReader; import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.core.CoreContainer; import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.CoreContainer.Initializer;
import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.CreateMode;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
@ -62,8 +61,6 @@ public class SliceStateUpdateTest extends SolrTestCaseJ4 {
private File dataDir3; private File dataDir3;
private Initializer init2;
@BeforeClass @BeforeClass
public static void beforeClass() { public static void beforeClass() {
System.setProperty("solrcloud.skip.autorecovery", "true"); System.setProperty("solrcloud.skip.autorecovery", "true");
@ -117,20 +114,21 @@ public class SliceStateUpdateTest extends SolrTestCaseJ4 {
System.setProperty("solr.solr.home", TEST_HOME()); System.setProperty("solr.solr.home", TEST_HOME());
System.setProperty("hostPort", "1661"); System.setProperty("hostPort", "1661");
CoreContainer.Initializer init1 = new CoreContainer.Initializer();
System.setProperty("solr.data.dir", SliceStateUpdateTest.this.dataDir1.getAbsolutePath()); System.setProperty("solr.data.dir", SliceStateUpdateTest.this.dataDir1.getAbsolutePath());
container1 = init1.initialize(); container1 = new CoreContainer();
System.clearProperty("hostPort"); System.clearProperty("hostPort");
System.setProperty("hostPort", "1662"); System.setProperty("hostPort", "1662");
init2 = new CoreContainer.Initializer();
System.setProperty("solr.data.dir", SliceStateUpdateTest.this.dataDir2.getAbsolutePath()); System.setProperty("solr.data.dir", SliceStateUpdateTest.this.dataDir2.getAbsolutePath());
container2 = init2.initialize(); container2 = new CoreContainer();
System.clearProperty("hostPort"); System.clearProperty("hostPort");
System.clearProperty("solr.solr.home"); System.clearProperty("solr.solr.home");
container1.load();
container2.load();
log.info("####SETUP_END " + getTestName()); log.info("####SETUP_END " + getTestName());
} }

View File

@ -17,8 +17,6 @@
package org.apache.solr.cloud; package org.apache.solr.cloud;
import java.io.File;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.cloud.SolrZkClient; import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.core.CoreContainer; import org.apache.solr.core.CoreContainer;
@ -30,6 +28,8 @@ import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File;
public class TestMultiCoreConfBootstrap extends SolrTestCaseJ4 { public class TestMultiCoreConfBootstrap extends SolrTestCaseJ4 {
protected static Logger log = LoggerFactory.getLogger(TestMultiCoreConfBootstrap.class); protected static Logger log = LoggerFactory.getLogger(TestMultiCoreConfBootstrap.class);
protected CoreContainer cores = null; protected CoreContainer cores = null;
@ -99,7 +99,7 @@ public class TestMultiCoreConfBootstrap extends SolrTestCaseJ4 {
@Test @Test
public void testMultiCoreConfBootstrap() throws Exception { public void testMultiCoreConfBootstrap() throws Exception {
System.setProperty("bootstrap_conf", "true"); System.setProperty("bootstrap_conf", "true");
cores = new CoreContainer(home, new File(home, "solr.xml")); cores = CoreContainer.createAndLoad(home, new File(home, "solr.xml"));
SolrZkClient zkclient = cores.getZkController().getZkClient(); SolrZkClient zkclient = cores.getZkController().getZkClient();
// zkclient.printLayoutToStdOut(); // zkclient.printLayoutToStdOut();

View File

@ -17,8 +17,6 @@ package org.apache.solr.cloud;
* limitations under the License. * limitations under the License.
*/ */
import java.io.File;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.cloud.SolrZkClient; import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.cloud.ZooKeeperException; import org.apache.solr.common.cloud.ZooKeeperException;
@ -31,6 +29,8 @@ import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File;
public class TestZkChroot extends SolrTestCaseJ4 { public class TestZkChroot extends SolrTestCaseJ4 {
protected static Logger log = LoggerFactory.getLogger(TestZkChroot.class); protected static Logger log = LoggerFactory.getLogger(TestZkChroot.class);
protected CoreContainer cores = null; protected CoreContainer cores = null;
@ -91,7 +91,7 @@ public class TestZkChroot extends SolrTestCaseJ4 {
SolrZkClient zkClient2 = null; SolrZkClient zkClient2 = null;
try { try {
cores = new CoreContainer(home, new File(home, "solr.xml")); cores = CoreContainer.createAndLoad(home, new File(home, "solr.xml"));
zkClient = cores.getZkController().getZkClient(); zkClient = cores.getZkController().getZkClient();
assertTrue(zkClient.exists("/clusterstate.json", true)); assertTrue(zkClient.exists("/clusterstate.json", true));
@ -122,7 +122,7 @@ public class TestZkChroot extends SolrTestCaseJ4 {
AbstractZkTestCase.TIMEOUT); AbstractZkTestCase.TIMEOUT);
assertFalse("Path '" + chroot + "' should not exist before the test", assertFalse("Path '" + chroot + "' should not exist before the test",
zkClient.exists(chroot, true)); zkClient.exists(chroot, true));
cores = new CoreContainer(home, new File(home, "solr.xml")); cores = CoreContainer.createAndLoad(home, new File(home, "solr.xml"));
fail("There should be a zk exception, as the initial path doesn't exist"); fail("There should be a zk exception, as the initial path doesn't exist");
} catch (ZooKeeperException e) { } catch (ZooKeeperException e) {
// expected // expected
@ -150,7 +150,7 @@ public class TestZkChroot extends SolrTestCaseJ4 {
AbstractZkTestCase.TIMEOUT); AbstractZkTestCase.TIMEOUT);
assertFalse("Path '" + chroot + "' should not exist before the test", assertFalse("Path '" + chroot + "' should not exist before the test",
zkClient.exists(chroot, true)); zkClient.exists(chroot, true));
cores = new CoreContainer(home, new File(home, "solr.xml")); cores = CoreContainer.createAndLoad(home, new File(home, "solr.xml"));
assertTrue( assertTrue(
"solrconfig.xml should have been uploaded to zk to the correct config directory", "solrconfig.xml should have been uploaded to zk to the correct config directory",
zkClient.exists(chroot + ZkController.CONFIGS_ZKNODE + "/" zkClient.exists(chroot + ZkController.CONFIGS_ZKNODE + "/"
@ -176,7 +176,7 @@ public class TestZkChroot extends SolrTestCaseJ4 {
assertTrue(zkClient.exists(chroot, true)); assertTrue(zkClient.exists(chroot, true));
assertFalse(zkClient.exists(chroot + "/clusterstate.json", true)); assertFalse(zkClient.exists(chroot + "/clusterstate.json", true));
cores = new CoreContainer(home, new File(home, "solr.xml")); cores = CoreContainer.createAndLoad(home, new File(home, "solr.xml"));
assertTrue(zkClient.exists(chroot + "/clusterstate.json", true)); assertTrue(zkClient.exists(chroot + "/clusterstate.json", true));
} finally { } finally {
if (cores != null) cores.shutdown(); if (cores != null) cores.shutdown();

View File

@ -17,11 +17,6 @@ package org.apache.solr.cloud;
* the License. * the License.
*/ */
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.lucene.util.LuceneTestCase.Slow; import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.cloud.SolrZkClient; import org.apache.solr.common.cloud.SolrZkClient;
@ -34,6 +29,11 @@ import org.apache.zookeeper.CreateMode;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slow @Slow
public class ZkControllerTest extends SolrTestCaseJ4 { public class ZkControllerTest extends SolrTestCaseJ4 {
@ -240,12 +240,8 @@ public class ZkControllerTest extends SolrTestCaseJ4 {
} }
private CoreContainer getCoreContainer() { private CoreContainer getCoreContainer() {
CoreContainer cc = new CoreContainer(TEMP_DIR.getAbsolutePath()) { CoreContainer cc = new CoreContainer(TEMP_DIR.getAbsolutePath());
{ cc.load();
initShardHandler();
}
};
return cc; return cc;
} }

View File

@ -18,9 +18,8 @@
package org.apache.solr.core; package org.apache.solr.core;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import java.util.Map;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public abstract class AbstractBadConfigTestBase extends SolrTestCaseJ4 { public abstract class AbstractBadConfigTestBase extends SolrTestCaseJ4 {
@ -50,26 +49,37 @@ public abstract class AbstractBadConfigTestBase extends SolrTestCaseJ4 {
ignoreException(Pattern.quote(errString)); ignoreException(Pattern.quote(errString));
try { try {
if (null == solrHome) { if (null == solrHome) {
initCore( solrconfigFile, schemaFile ); initCore( solrconfigFile, schemaFile );
} else { } else {
initCore( solrconfigFile, schemaFile, solrHome ); initCore( solrconfigFile, schemaFile, solrHome );
} }
} catch (Exception e) {
for (Throwable t = e; t != null; t = t.getCause()) {
// short circuit out if we found what we expected
if (t.getMessage() != null && -1 != t.getMessage().indexOf(errString)) return;
}
// otherwise, rethrow it, possibly completley unrelated CoreContainer cc = h.getCoreContainer();
throw new SolrException for (Map.Entry<String, Exception> entry : cc.getCoreInitFailures().entrySet()) {
(ErrorCode.SERVER_ERROR, if (matches(entry.getValue(), errString))
"Unexpected error, expected error matching: " + errString, e); return;
} finally { }
}
catch (Exception e) {
if (matches(e, errString))
return;
throw e;
}
finally {
deleteCore(); deleteCore();
resetExceptionIgnores(); resetExceptionIgnores();
} }
fail("Did not encounter any exception from: " + solrconfigFile + " using " + schemaFile); fail("Did not encounter any exception from: " + solrconfigFile + " using " + schemaFile);
} }
private static boolean matches(Exception e, String errString) {
for (Throwable t = e; t != null; t = t.getCause()) {
if (t.getMessage() != null && -1 != t.getMessage().indexOf(errString))
return true;
}
return false;
}
} }

View File

@ -17,23 +17,17 @@
package org.apache.solr.core; package org.apache.solr.core;
import java.util.Map;
import java.util.Collection;
import java.util.regex.Pattern;
import java.io.File;
import org.apache.solr.common.SolrException;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.lucene.util.IOUtils;
import org.apache.commons.io.FileUtils; 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 org.xml.sax.SAXParseException;
import org.junit.Before; import java.io.File;
import org.junit.After; import java.util.Collection;
import java.util.Map;
import java.util.regex.Pattern;
public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 { public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
@ -44,8 +38,7 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
// would be nice to do this in an @Before method, // would be nice to do this in an @Before method,
// but junit doesn't let @Before methods have test names // but junit doesn't let @Before methods have test names
solrHome = new File(TEMP_DIR, this.getClass().getName() + "_" + dirSuffix); solrHome = new File(TEMP_DIR, this.getClass().getName() + "_" + dirSuffix);
assertTrue("Failed to mkdirs solrhome", solrHome.mkdirs()); assertTrue("Failed to mkdirs solrhome [" + solrHome + "]", solrHome.mkdirs());
cc = new CoreContainer(solrHome.getAbsolutePath());
} }
@After @After
@ -68,7 +61,7 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
Map<String,Exception> failures = null; Map<String,Exception> failures = null;
Collection<String> cores = null; Collection<String> cores = null;
Exception fail = null; Exception fail = null;
init("empty_flow"); init("empty_flow");
// solr.xml // solr.xml
@ -77,7 +70,8 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
// ---- // ----
// init the CoreContainer // init the CoreContainer
cc.load(solrHome.getAbsolutePath(), solrXml); cc = new CoreContainer(solrHome.getAbsolutePath());
cc.load();
// check that we have the cores we expect // check that we have the cores we expect
cores = cc.getCoreNames(); cores = cc.getCoreNames();
@ -154,18 +148,19 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
FileUtils.getFile(solrHome, "col_ok", "conf", "solrconfig.xml")); FileUtils.getFile(solrHome, "col_ok", "conf", "solrconfig.xml"));
FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"), FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),
FileUtils.getFile(solrHome, "col_ok", "conf", "schema.xml")); FileUtils.getFile(solrHome, "col_ok", "conf", "schema.xml"));
// our "bad" collection // our "bad" collection
ignoreException(Pattern.quote("DummyMergePolicy")); ignoreException(Pattern.quote("DummyMergePolicy"));
FileUtils.copyFile(getFile("solr/collection1/conf/bad-mp-solrconfig.xml"), FileUtils.copyFile(getFile("solr/collection1/conf/bad-mp-solrconfig.xml"),
FileUtils.getFile(solrHome, "col_bad", "conf", "solrconfig.xml")); FileUtils.getFile(solrHome, "col_bad", "conf", "solrconfig.xml"));
FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"), FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),
FileUtils.getFile(solrHome, "col_bad", "conf", "schema.xml")); FileUtils.getFile(solrHome, "col_bad", "conf", "schema.xml"));
// ----- // -----
// init the CoreContainer with the mix of ok/bad cores // init the CoreContainer with the mix of ok/bad cores
cc.load(solrHome.getAbsolutePath(), solrXml); cc = new CoreContainer(solrHome.getAbsolutePath());
cc.load();
// check that we have the cores we expect // check that we have the cores we expect
cores = cc.getCoreNames(); cores = cc.getCoreNames();
@ -293,8 +288,8 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
fail("corrupt solrconfig.xml failed to trigger exception from reload"); fail("corrupt solrconfig.xml failed to trigger exception from reload");
} catch (SolrException e) { } catch (SolrException e) {
assertTrue("We're supposed to have a wrapped SAXParserException here, but we don't", assertTrue("We're supposed to have a wrapped SAXParserException here, but we don't",
e.getCause() instanceof SAXParseException); e.getCause().getCause() instanceof SAXParseException);
SAXParseException se = (SAXParseException)e.getCause(); SAXParseException se = (SAXParseException)e.getCause().getCause();
assertTrue("reload exception doesn't refer to slrconfig.xml " + se.getSystemId(), assertTrue("reload exception doesn't refer to slrconfig.xml " + se.getSystemId(),
0 < se.getSystemId().indexOf("solrconfig.xml")); 0 < se.getSystemId().indexOf("solrconfig.xml"));
@ -318,9 +313,9 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
fail = failures.get("col_bad"); fail = failures.get("col_bad");
assertNotNull("null failure for test core", fail); assertNotNull("null failure for test core", fail);
assertTrue("init failure isn't SAXParseException", assertTrue("init failure isn't SAXParseException",
fail instanceof SAXParseException); fail.getCause() instanceof SAXParseException);
assertTrue("init failure doesn't mention problem: " + fail.toString(), assertTrue("init failure doesn't mention problem: " + fail.toString(),
0 < ((SAXParseException)fail).getSystemId().indexOf("solrconfig.xml")); 0 < ((SAXParseException)fail.getCause()).getSystemId().indexOf("solrconfig.xml"));
// ---- // ----
// fix col_bad's config (again) and RELOAD to fix failure // fix col_bad's config (again) and RELOAD to fix failure

View File

@ -29,6 +29,7 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.io.File; import java.io.File;
import java.util.Map;
public class SolrCoreCheckLockOnStartupTest extends SolrTestCaseJ4 { public class SolrCoreCheckLockOnStartupTest extends SolrTestCaseJ4 {
@ -62,13 +63,9 @@ public class SolrCoreCheckLockOnStartupTest extends SolrTestCaseJ4 {
try { try {
//opening a new core on the same index //opening a new core on the same index
initCore("solrconfig-simplelock.xml", "schema.xml"); initCore("solrconfig-simplelock.xml", "schema.xml");
if (checkForCoreInitException(LockObtainFailedException.class))
return;
fail("Expected " + LockObtainFailedException.class.getSimpleName()); fail("Expected " + LockObtainFailedException.class.getSimpleName());
} catch (Throwable t) {
assertTrue(t instanceof RuntimeException);
assertNotNull(t.getCause());
assertTrue(t.getCause() instanceof RuntimeException);
assertNotNull(t.getCause().getCause());
assertTrue(t.getCause().getCause().toString(), t.getCause().getCause() instanceof LockObtainFailedException);
} finally { } finally {
indexWriter.close(); indexWriter.close();
directory.close(); directory.close();
@ -79,24 +76,33 @@ public class SolrCoreCheckLockOnStartupTest extends SolrTestCaseJ4 {
@Test @Test
public void testNativeLockErrorOnStartup() throws Exception { public void testNativeLockErrorOnStartup() throws Exception {
Directory directory = newFSDirectory(new File(dataDir, "index"), new NativeFSLockFactory()); File indexDir = new File(dataDir, "index");
log.info("Acquiring lock on {}", indexDir.getAbsolutePath());
Directory directory = newFSDirectory(indexDir, new NativeFSLockFactory());
//creates a new IndexWriter without releasing the lock yet //creates a new IndexWriter without releasing the lock yet
IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(Version.LUCENE_40, null)); IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(Version.LUCENE_40, null));
try { try {
//opening a new core on the same index //opening a new core on the same index
initCore("solrconfig-nativelock.xml", "schema.xml"); initCore("solrconfig-nativelock.xml", "schema.xml");
CoreContainer cc = h.getCoreContainer();
if (checkForCoreInitException(LockObtainFailedException.class))
return;
fail("Expected " + LockObtainFailedException.class.getSimpleName()); fail("Expected " + LockObtainFailedException.class.getSimpleName());
} catch(Throwable t) {
assertTrue(t instanceof RuntimeException);
assertNotNull(t.getCause());
assertTrue(t.getCause() instanceof RuntimeException);
assertNotNull(t.getCause().getCause());
assertTrue(t.getCause().getCause() instanceof LockObtainFailedException);
} finally { } finally {
indexWriter.close(); indexWriter.close();
directory.close(); directory.close();
deleteCore(); deleteCore();
} }
} }
private boolean checkForCoreInitException(Class<? extends Exception> clazz) {
for (Map.Entry<String, Exception> entry : h.getCoreContainer().getCoreInitFailures().entrySet()) {
for (Throwable t = entry.getValue(); t != null; t = t.getCause()) {
if (clazz.isInstance(t))
return true;
}
}
return false;
}
} }

View File

@ -17,6 +17,16 @@
package org.apache.solr.core; package org.apache.solr.core;
import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util._TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -27,17 +37,6 @@ import java.util.List;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream; import java.util.jar.JarOutputStream;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util._TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.xml.sax.SAXException;
public class TestCoreContainer extends SolrTestCaseJ4 { public class TestCoreContainer extends SolrTestCaseJ4 {
private static String oldSolrHome; private static String oldSolrHome;
@ -70,9 +69,10 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
assertTrue("Failed to mkdirs workDir", solrHomeDirectory.mkdirs()); assertTrue("Failed to mkdirs workDir", solrHomeDirectory.mkdirs());
FileUtils.copyDirectory(new File(SolrTestCaseJ4.TEST_HOME()), solrHomeDirectory); FileUtils.copyDirectory(new File(SolrTestCaseJ4.TEST_HOME()), solrHomeDirectory);
System.out.println("Using solrconfig from " + new File(SolrTestCaseJ4.TEST_HOME()).getAbsolutePath());
CoreContainer ret = new CoreContainer(solrHomeDirectory.getAbsolutePath()); CoreContainer ret = new CoreContainer(solrHomeDirectory.getAbsolutePath());
ret.load(solrHomeDirectory.getAbsolutePath(), new File(solrHomeDirectory, "solr.xml")); ret.load();
return ret; return ret;
} }
@ -161,13 +161,13 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
SolrCore template = null; SolrCore template = null;
try { try {
template = cores.getCore("collection1"); template = cores.getCore("collection1");
instDir = template.getCoreDescriptor().getInstanceDir(); instDir = template.getCoreDescriptor().getRawInstanceDir();
} finally { } finally {
if (null != template) template.close(); if (null != template) template.close();
} }
} }
final File instDirFile = new File(instDir); final File instDirFile = new File(cores.getSolrHome(), instDir);
assertTrue("instDir doesn't exist: " + instDir, instDirFile.exists()); assertTrue("instDir doesn't exist: " + instDir, instDirFile.exists());
// sanity check the basic persistence of the default init // sanity check the basic persistence of the default init
@ -262,14 +262,8 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
File solrHomeDirectory = new File(TEMP_DIR, this.getClass().getName() File solrHomeDirectory = new File(TEMP_DIR, this.getClass().getName()
+ "_noCores"); + "_noCores");
SetUpHome(solrHomeDirectory, EMPTY_SOLR_XML); SetUpHome(solrHomeDirectory, EMPTY_SOLR_XML);
CoreContainer.Initializer init = new CoreContainer.Initializer(); CoreContainer cores = new CoreContainer(solrHomeDirectory.getAbsolutePath());
CoreContainer cores = null; cores.load();
try {
cores = init.initialize();
}
catch(Exception e) {
fail("CoreContainer not created" + e.getMessage());
}
try { try {
//assert zero cores //assert zero cores
assertEquals("There should not be cores", 0, cores.getCores().size()); assertEquals("There should not be cores", 0, cores.getCores().size());
@ -362,24 +356,21 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
FileUtils.writeStringToFile(new File(tmpRoot, "explicit-lib-solr.xml"), "<solr sharedLib=\"lib\"><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"); FileUtils.writeStringToFile(new File(tmpRoot, "custom-lib-solr.xml"), "<solr sharedLib=\"customLib\"><cores/></solr>", "UTF-8");
final CoreContainer cc1 = new CoreContainer(tmpRoot.getAbsolutePath()); final CoreContainer cc1 = CoreContainer.createAndLoad(tmpRoot.getAbsolutePath(), new File(tmpRoot, "default-lib-solr.xml"));
cc1.load(tmpRoot.getAbsolutePath(), new File(tmpRoot, "default-lib-solr.xml"));
try { try {
cc1.loader.openResource("defaultSharedLibFile").close(); cc1.loader.openResource("defaultSharedLibFile").close();
} finally { } finally {
cc1.shutdown(); cc1.shutdown();
} }
final CoreContainer cc2 = new CoreContainer(tmpRoot.getAbsolutePath()); final CoreContainer cc2 = CoreContainer.createAndLoad(tmpRoot.getAbsolutePath(), new File(tmpRoot, "explicit-lib-solr.xml"));
cc2.load(tmpRoot.getAbsolutePath(), new File(tmpRoot, "explicit-lib-solr.xml"));
try { try {
cc2.loader.openResource("defaultSharedLibFile").close(); cc2.loader.openResource("defaultSharedLibFile").close();
} finally { } finally {
cc2.shutdown(); cc2.shutdown();
} }
final CoreContainer cc3 = new CoreContainer(tmpRoot.getAbsolutePath()); final CoreContainer cc3 = CoreContainer.createAndLoad(tmpRoot.getAbsolutePath(), new File(tmpRoot, "custom-lib-solr.xml"));
cc3.load(tmpRoot.getAbsolutePath(), new File(tmpRoot, "custom-lib-solr.xml"));
try { try {
cc3.loader.openResource("customSharedLibFile").close(); cc3.loader.openResource("customSharedLibFile").close();
} finally { } finally {

View File

@ -17,10 +17,6 @@ package org.apache.solr.core;
* limitations under the License. * limitations under the License.
*/ */
import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
@ -29,6 +25,10 @@ import org.junit.After;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;
public class TestCoreDiscovery extends SolrTestCaseJ4 { public class TestCoreDiscovery extends SolrTestCaseJ4 {
@BeforeClass @BeforeClass
@ -106,11 +106,8 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
} }
private CoreContainer init() throws Exception { private CoreContainer init() throws Exception {
final CoreContainer cores = new CoreContainer();
CoreContainer.Initializer init = new CoreContainer.Initializer(); cores.load();
final CoreContainer cores = init.initialize();
cores.setPersistent(false);
return cores; return cores;
} }
@ -183,10 +180,12 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
cc = init(); cc = init();
fail("Should have thrown exception in testDuplicateNames"); fail("Should have thrown exception in testDuplicateNames");
} catch (SolrException se) { } catch (SolrException se) {
Throwable cause = se.getCause();
String message = cause.getMessage();
assertTrue("Should have seen an exception because two cores had the same name", assertTrue("Should have seen an exception because two cores had the same name",
"Core + desc.getName() + \" defined twice".indexOf(se.getMessage()) != -1); message.indexOf("Core core1 defined more than once") != -1);
assertTrue("/core1 should have been mentioned in the message", "/core1".indexOf(se.getMessage()) != -1); assertTrue("/core1 should have been mentioned in the message", message.indexOf("/core1") != -1);
assertTrue("/core2 should have been mentioned in the message", "/core2".indexOf(se.getMessage()) != -1); assertTrue("/core2 should have been mentioned in the message", message.indexOf("/core2") != -1);
} finally { } finally {
if (cc != null) { if (cc != null) {
cc.shutdown(); cc.shutdown();

View File

@ -66,7 +66,7 @@ public class TestLazyCores extends SolrTestCaseJ4 {
File solrXml = new File(solrHomeDirectory, "solr.xml"); File solrXml = new File(solrHomeDirectory, "solr.xml");
FileUtils.write(solrXml, LOTS_SOLR_XML, IOUtils.CHARSET_UTF_8.toString()); FileUtils.write(solrXml, LOTS_SOLR_XML, IOUtils.CHARSET_UTF_8.toString());
final CoreContainer cores = new CoreContainer(solrHomeDirectory.getAbsolutePath()); final CoreContainer cores = new CoreContainer(solrHomeDirectory.getAbsolutePath());
cores.load(solrHomeDirectory.getAbsolutePath(), solrXml); cores.load();
// h.getCoreContainer().load(solrHomeDirectory.getAbsolutePath(), new File(solrHomeDirectory, "solr.xml")); // h.getCoreContainer().load(solrHomeDirectory.getAbsolutePath(), new File(solrHomeDirectory, "solr.xml"));
cores.setPersistent(false); cores.setPersistent(false);

View File

@ -29,8 +29,7 @@ import java.io.File;
public class TestShardHandlerFactory extends SolrTestCaseJ4 { public class TestShardHandlerFactory extends SolrTestCaseJ4 {
public void testXML() throws Exception { public void testXML() throws Exception {
CoreContainer cc = new CoreContainer(TEST_HOME()); CoreContainer cc = CoreContainer.createAndLoad(TEST_HOME(), new File(TEST_HOME(), "solr-shardhandler.xml"));
cc.load(TEST_HOME(), new File(TEST_HOME(), "solr-shardhandler.xml"));
ShardHandlerFactory factory = cc.getShardHandlerFactory(); ShardHandlerFactory factory = cc.getShardHandlerFactory();
assertTrue(factory instanceof MockShardHandlerFactory); assertTrue(factory instanceof MockShardHandlerFactory);
NamedList args = ((MockShardHandlerFactory)factory).args; NamedList args = ((MockShardHandlerFactory)factory).args;

View File

@ -44,7 +44,7 @@ public class TestSolrXml extends SolrTestCaseJ4 {
boolean oldStyle = (config.getNode("solr/cores", false) != null); boolean oldStyle = (config.getNode("solr/cores", false) != null);
ConfigSolr cfg; ConfigSolr cfg;
if (oldStyle) { if (oldStyle) {
cfg = new ConfigSolrXmlOld(config, cc); cfg = new ConfigSolrXmlOld(config);
} else { } else {
cfg = new ConfigSolrXml(config, cc); cfg = new ConfigSolrXml(config, cc);
} }
@ -103,7 +103,7 @@ public class TestSolrXml extends SolrTestCaseJ4 {
boolean oldStyle = (config.getNode("solr/cores", false) != null); boolean oldStyle = (config.getNode("solr/cores", false) != null);
ConfigSolr cfg; ConfigSolr cfg;
if (oldStyle) { if (oldStyle) {
cfg = new ConfigSolrXmlOld(config, cc); cfg = new ConfigSolrXmlOld(config);
} else { } else {
cfg = new ConfigSolrXml(config, cc); cfg = new ConfigSolrXml(config, cc);
} }

View File

@ -25,7 +25,6 @@ import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.params.CoreAdminParams; import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.handler.admin.CoreAdminHandler; import org.apache.solr.handler.admin.CoreAdminHandler;
import org.apache.solr.response.SolrQueryResponse; import org.apache.solr.response.SolrQueryResponse;
import org.junit.BeforeClass;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.RuleChain; import org.junit.rules.RuleChain;
@ -46,12 +45,14 @@ import java.util.List;
public class TestSolrXmlPersistence extends SolrTestCaseJ4 { public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
private final File solrHomeDirectory = new File(TEMP_DIR, this.getClass().getName()); private File solrHomeDirectory = new File(TEMP_DIR, this.getClass().getName());
/*
@BeforeClass @BeforeClass
public static void beforeClass() throws Exception { public static void beforeClass() throws Exception {
initCore("solrconfig-minimal.xml", "schema-tiny.xml"); initCore("solrconfig-minimal.xml", "schema-tiny.xml");
} }
*/
@Rule @Rule
public TestRule solrTestRules = public TestRule solrTestRules =
@ -59,9 +60,9 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
private CoreContainer init(String solrXmlString, String... subDirs) throws Exception { private CoreContainer init(String solrXmlString, String... subDirs) throws Exception {
if (solrHomeDirectory.exists()) {
FileUtils.deleteDirectory(solrHomeDirectory); createTempDir();
} solrHomeDirectory = dataDir;
for (String s : subDirs) { for (String s : subDirs) {
copyMinConf(new File(solrHomeDirectory, s)); copyMinConf(new File(solrHomeDirectory, s));
@ -69,10 +70,8 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
File solrXml = new File(solrHomeDirectory, "solr.xml"); File solrXml = new File(solrHomeDirectory, "solr.xml");
FileUtils.write(solrXml, solrXmlString, IOUtils.CHARSET_UTF_8.toString()); FileUtils.write(solrXml, solrXmlString, IOUtils.CHARSET_UTF_8.toString());
final CoreContainer cores = new CoreContainer(solrHomeDirectory.getAbsolutePath());
cores.load(solrHomeDirectory.getAbsolutePath(), solrXml);
cores.setPersistent(false); final CoreContainer cores = createCoreContainer(solrHomeDirectory.getAbsolutePath(), solrXmlString);
return cores; return cores;
} }
@ -304,7 +303,7 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
} else if (persistList[idx].contains("@config='solrconfig.xml'")) { } else if (persistList[idx].contains("@config='solrconfig.xml'")) {
expressions[idx] = persistList[idx].replace("solrconfig.xml", "${solrconfig:solrconfig.xml}"); expressions[idx] = persistList[idx].replace("solrconfig.xml", "${solrconfig:solrconfig.xml}");
} else if (persistList[idx].contains("@instanceDir=")) { } else if (persistList[idx].contains("@instanceDir=")) {
expressions[idx] = persistList[idx].replaceFirst("instanceDir\\='.*?'", "instanceDir='" + which + "'"); expressions[idx] = persistList[idx].replaceFirst("instanceDir\\='.*?'", "instanceDir='" + which + "/'");
} else { } else {
expressions[idx] = persistList[idx]; expressions[idx] = persistList[idx];
} }
@ -611,14 +610,14 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
" shareSchema=\"${shareSchema:false}\" distribUpdateConnTimeout=\"${distribUpdateConnTimeout:15000}\" \n" + " shareSchema=\"${shareSchema:false}\" distribUpdateConnTimeout=\"${distribUpdateConnTimeout:15000}\" \n" +
" distribUpdateSoTimeout=\"${distribUpdateSoTimeout:120000}\" \n" + " distribUpdateSoTimeout=\"${distribUpdateSoTimeout:120000}\" \n" +
" leaderVoteWait=\"${leadVoteWait:32}\" managementPath=\"${manpath:/var/lib/path}\" transientCacheSize=\"${tranSize:128}\"> \n" + " leaderVoteWait=\"${leadVoteWait:32}\" managementPath=\"${manpath:/var/lib/path}\" transientCacheSize=\"${tranSize:128}\"> \n" +
" <core name=\"SystemVars1\" instanceDir=\"SystemVars1\" shard=\"${shard:32}\" \n" + " <core name=\"SystemVars1\" instanceDir=\"SystemVars1/\" shard=\"${shard:32}\" \n" +
" collection=\"${collection:collection1}\" config=\"${solrconfig:solrconfig.xml}\" \n" + " collection=\"${collection:collection1}\" config=\"${solrconfig:solrconfig.xml}\" \n" +
" schema=\"${schema:schema.xml}\" ulogDir=\"${ulog:./}\" roles=\"${myrole:boss}\" \n" + " schema=\"${schema:schema.xml}\" ulogDir=\"${ulog:./}\" roles=\"${myrole:boss}\" \n" +
" dataDir=\"${data:./}\" loadOnStartup=\"${onStart:true}\" transient=\"${tran:true}\" \n" + " dataDir=\"${data:./}\" loadOnStartup=\"${onStart:true}\" transient=\"${tran:true}\" \n" +
" coreNodeName=\"${coreNode:utterlyridiculous}\" \n" + " coreNodeName=\"${coreNode:utterlyridiculous}\" \n" +
" >\n" + " >\n" +
" </core>\n" + " </core>\n" +
" <core name=\"SystemVars2\" instanceDir=\"SystemVars2\" shard=\"${shard:32}\" \n" + " <core name=\"SystemVars2\" instanceDir=\"SystemVars2/\" shard=\"${shard:32}\" \n" +
" collection=\"${collection:collection2}\" config=\"${solrconfig:solrconfig.xml}\" \n" + " collection=\"${collection:collection2}\" config=\"${solrconfig:solrconfig.xml}\" \n" +
" coreNodeName=\"${coreNodeName:}\" schema=\"${schema:schema.xml}\">\n" + " coreNodeName=\"${coreNodeName:}\" schema=\"${schema:schema.xml}\">\n" +
" <property name=\"collection\" value=\"{collection:collection2}\"/>\n" + " <property name=\"collection\" value=\"{collection:collection2}\"/>\n" +
@ -632,7 +631,7 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
private static String SOLR_XML_MINIMAL = private static String SOLR_XML_MINIMAL =
"<solr >\n" + "<solr >\n" +
" <cores> \n" + " <cores> \n" +
" <core name=\"SystemVars1\" instanceDir=\"SystemVars1\" />\n" + " <core name=\"SystemVars1\" instanceDir=\"SystemVars1/\" />\n" +
" </cores>\n" + " </cores>\n" +
"</solr>"; "</solr>";

View File

@ -17,15 +17,22 @@
package org.apache.solr.handler.admin; package org.apache.solr.handler.admin;
import java.util.logging.Logger; import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.CommonParams;
import org.apache.solr.logging.jul.JulInfo; import org.apache.solr.logging.log4j.Log4jInfo;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
public class LoggingHandlerTest extends SolrTestCaseJ4 { public class LoggingHandlerTest extends SolrTestCaseJ4 {
// TODO: This only tests Log4j at the moment, as that's what's defined
// through the CoreContainer.
// TODO: Would be nice to throw an exception on trying to set a
// log level that doesn't exist
@BeforeClass @BeforeClass
public static void beforeClass() throws Exception { public static void beforeClass() throws Exception {
@ -35,7 +42,8 @@ public class LoggingHandlerTest extends SolrTestCaseJ4 {
@Test @Test
public void testLogLevelHandlerOutput() throws Exception { public void testLogLevelHandlerOutput() throws Exception {
Logger tst = Logger.getLogger("org.apache.solr.SolrTestCaseJ4"); Logger tst = Logger.getLogger("org.apache.solr.SolrTestCaseJ4");
JulInfo wrap = new JulInfo(tst.getName(), tst); tst.setLevel(Level.INFO);
Log4jInfo wrap = new Log4jInfo(tst.getName(), tst);
assertQ("Show Log Levels OK", assertQ("Show Log Levels OK",
req(CommonParams.QT,"/admin/logging") req(CommonParams.QT,"/admin/logging")
@ -46,8 +54,8 @@ public class LoggingHandlerTest extends SolrTestCaseJ4 {
assertQ("Set and remove a level", assertQ("Set and remove a level",
req(CommonParams.QT,"/admin/logging", req(CommonParams.QT,"/admin/logging",
"set", "org.xxx.yyy.abc:null", "set", "org.xxx.yyy.abc:null",
"set", "org.xxx.yyy.zzz:FINEST") "set", "org.xxx.yyy.zzz:TRACE")
,"//arr[@name='loggers']/lst/str[.='org.xxx.yyy.zzz']/../str[@name='level'][.='FINEST']" ,"//arr[@name='loggers']/lst/str[.='org.xxx.yyy.zzz']/../str[@name='level'][.='TRACE']"
); );
} }
} }

View File

@ -17,17 +17,18 @@
package org.apache.solr.handler.admin; package org.apache.solr.handler.admin;
import java.util.Arrays;
import java.util.EnumSet;
import org.apache.solr.common.luke.FieldFlag; import org.apache.solr.common.luke.FieldFlag;
import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.schema.IndexSchema; import org.apache.solr.schema.IndexSchema;
import org.apache.solr.util.AbstractSolrTestCase; import org.apache.solr.util.AbstractSolrTestCase;
import org.apache.solr.util.TestHarness;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import java.util.Arrays;
import java.util.EnumSet;
/** /**
* :TODO: currently only tests some of the utilities in the LukeRequestHandler * :TODO: currently only tests some of the utilities in the LukeRequestHandler
*/ */
@ -156,7 +157,7 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase {
try { try {
// First, determine that the two fields ARE there // First, determine that the two fields ARE there
String response = h.query(req); String response = h.query(req);
assertNull(h.validateXPath(response, assertNull(TestHarness.validateXPath(response,
getFieldXPathPrefix("solr_t") + "[@name='index']", getFieldXPathPrefix("solr_t") + "[@name='index']",
getFieldXPathPrefix("solr_s") + "[@name='index']" getFieldXPathPrefix("solr_s") + "[@name='index']"
)); ));
@ -165,7 +166,7 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase {
for (String f : Arrays.asList("solr_ti", for (String f : Arrays.asList("solr_ti",
"solr_td", "solr_pl", "solr_dt", "solr_b")) { "solr_td", "solr_pl", "solr_dt", "solr_b")) {
assertNotNull(h.validateXPath(response, assertNotNull(TestHarness.validateXPath(response,
getFieldXPathPrefix(f) + "[@name='index']")); getFieldXPathPrefix(f) + "[@name='index']"));
} }
@ -175,7 +176,7 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase {
for (String f : Arrays.asList("solr_t", "solr_s", "solr_ti", for (String f : Arrays.asList("solr_t", "solr_s", "solr_ti",
"solr_td", "solr_pl", "solr_dt", "solr_b")) { "solr_td", "solr_pl", "solr_dt", "solr_b")) {
assertNull(h.validateXPath(response, assertNull(TestHarness.validateXPath(response,
getFieldXPathPrefix(f) + "[@name='index']")); getFieldXPathPrefix(f) + "[@name='index']"));
} }
} catch (Exception e) { } catch (Exception e) {
@ -187,7 +188,7 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase {
SolrQueryRequest req = req("qt", "/admin/luke", "show", "schema"); SolrQueryRequest req = req("qt", "/admin/luke", "show", "schema");
String xml = h.query(req); String xml = h.query(req);
String r = h.validateXPath String r = TestHarness.validateXPath
(xml, (xml,
field("text") + "/arr[@name='copySources']/str[.='title']", field("text") + "/arr[@name='copySources']/str[.='title']",
field("text") + "/arr[@name='copySources']/str[.='subject']", field("text") + "/arr[@name='copySources']/str[.='subject']",
@ -217,7 +218,7 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase {
SolrQueryRequest req = req("qt", "/admin/luke", "show", "schema", "indent", "on"); SolrQueryRequest req = req("qt", "/admin/luke", "show", "schema", "indent", "on");
String xml = h.query(req); String xml = h.query(req);
String result = h.validateXPath(xml, field("bday") + "/arr[@name='copyDests']/str[.='catchall_t']"); String result = TestHarness.validateXPath(xml, field("bday") + "/arr[@name='copyDests']/str[.='catchall_t']");
assertNull(xml, result); assertNull(xml, result);
// Put back the configuration expected by the rest of the tests in this suite // Put back the configuration expected by the rest of the tests in this suite

View File

@ -19,7 +19,6 @@ package org.apache.solr.handler.component;
*/ */
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
import org.junit.Test; import org.junit.Test;
/** /**
@ -34,14 +33,7 @@ public class BadComponentTest extends SolrTestCaseJ4{
ignoreException(".*QueryElevationComponent.*"); ignoreException(".*QueryElevationComponent.*");
System.setProperty("elevate.file", "foo.xml"); System.setProperty("elevate.file", "foo.xml");
initCore("solrconfig-elevate.xml", "schema12.xml"); initCore("solrconfig-elevate.xml", "schema12.xml");
assertTrue(false); assertTrue(hasInitException("QueryElevationComponent"));
} catch (RuntimeException e) {
//TODO: better way of checking this?
if (e.getCause() instanceof SolrException){
assertTrue(true);
} else {
assertTrue(false);
}
} finally { } finally {
System.clearProperty("elevate.file"); System.clearProperty("elevate.file");
resetExceptionIgnores(); resetExceptionIgnores();

View File

@ -17,10 +17,6 @@
package org.apache.solr.client.solrj; package org.apache.solr.client.solrj;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest; import org.apache.solr.client.solrj.request.AbstractUpdateRequest;
import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest;
@ -32,9 +28,12 @@ import org.apache.solr.common.params.SolrParams;
import org.apache.solr.core.CoreContainer; import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrCore;
import org.apache.solr.util.ExternalPaths; import org.apache.solr.util.ExternalPaths;
import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
/** /**
* Abstract base class for testing merge indexes command * Abstract base class for testing merge indexes command
* *
@ -42,7 +41,8 @@ import org.junit.BeforeClass;
* *
*/ */
public abstract class MergeIndexesExampleTestBase extends SolrExampleTestBase { public abstract class MergeIndexesExampleTestBase extends SolrExampleTestBase {
protected static CoreContainer cores;
protected CoreContainer cores;
private String saveProp; private String saveProp;
private File dataDir2; private File dataDir2;
@ -56,13 +56,12 @@ public abstract class MergeIndexesExampleTestBase extends SolrExampleTestBase {
if (dataDir == null) { if (dataDir == null) {
createTempDir(); createTempDir();
} }
cores = new CoreContainer();
} }
@AfterClass protected void setupCoreContainer() {
public static void afterClass() { cores = new CoreContainer(getSolrHome());
cores.shutdown(); cores.load();
cores = null; //cores = CoreContainer.createAndLoad(getSolrHome(), new File(TEMP_DIR, "solr.xml"));
} }
@Override @Override
@ -71,17 +70,19 @@ public abstract class MergeIndexesExampleTestBase extends SolrExampleTestBase {
System.setProperty("solr.directoryFactory", "solr.StandardDirectoryFactory"); System.setProperty("solr.directoryFactory", "solr.StandardDirectoryFactory");
super.setUp(); super.setUp();
SolrCore.log.info("CORES=" + cores + " : " + cores.getCoreNames());
cores.setPersistent(false);
// setup datadirs // setup datadirs
System.setProperty( "solr.core0.data.dir", SolrTestCaseJ4.dataDir.getCanonicalPath() ); System.setProperty( "solr.core0.data.dir", SolrTestCaseJ4.dataDir.getCanonicalPath() );
dataDir2 = new File(TEMP_DIR, getClass().getName() + "-" dataDir2 = new File(TEMP_DIR, getClass().getName() + "-"
+ System.currentTimeMillis()); + System.currentTimeMillis());
dataDir2.mkdirs(); dataDir2.mkdirs();
System.setProperty( "solr.core1.data.dir", this.dataDir2.getCanonicalPath() ); System.setProperty( "solr.core1.data.dir", this.dataDir2.getCanonicalPath() );
setupCoreContainer();
SolrCore.log.info("CORES=" + cores + " : " + cores.getCoreNames());
cores.setPersistent(false);
} }
@Override @Override
@ -96,6 +97,8 @@ public abstract class MergeIndexesExampleTestBase extends SolrExampleTestBase {
System.err.println("!!!! WARNING: best effort to remove " + dataDir2.getAbsolutePath() + " FAILED !!!!!"); System.err.println("!!!! WARNING: best effort to remove " + dataDir2.getAbsolutePath() + " FAILED !!!!!");
} }
} }
cores.shutdown();
if (saveProp == null) System.clearProperty("solr.directoryFactory"); if (saveProp == null) System.clearProperty("solr.directoryFactory");
else System.setProperty("solr.directoryFactory", saveProp); else System.setProperty("solr.directoryFactory", saveProp);

View File

@ -17,8 +17,6 @@
package org.apache.solr.client.solrj; package org.apache.solr.client.solrj;
import java.io.File;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION; import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;
import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.client.solrj.request.CoreAdminRequest.Unload; import org.apache.solr.client.solrj.request.CoreAdminRequest.Unload;
@ -30,10 +28,10 @@ import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.CoreContainer; import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrCore;
import org.apache.solr.util.ExternalPaths; import org.apache.solr.util.ExternalPaths;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import java.io.File;
/** /**
* *
@ -41,30 +39,21 @@ import org.junit.Test;
*/ */
public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
{ {
protected static CoreContainer cores; protected CoreContainer cores;
private File dataDir2; private File dataDir2;
private File dataDir1; private File dataDir1;
@Override public String getSolrHome() { return ExternalPaths.EXAMPLE_MULTICORE_HOME; } @Override public String getSolrHome() { return ExternalPaths.EXAMPLE_MULTICORE_HOME; }
protected void setupCoreContainer() {
@BeforeClass
public static void beforeThisClass2() throws Exception {
cores = new CoreContainer(); cores = new CoreContainer();
} cores.load();
@AfterClass
public static void afterClass() {
cores.shutdown();
} }
@Override public void setUp() throws Exception { @Override public void setUp() throws Exception {
super.setUp(); super.setUp();
SolrCore.log.info("CORES=" + cores + " : " + cores.getCoreNames());
cores.setPersistent(false);
dataDir1 = new File(TEMP_DIR, getClass().getName() + "-core0-" dataDir1 = new File(TEMP_DIR, getClass().getName() + "-core0-"
+ System.currentTimeMillis()); + System.currentTimeMillis());
dataDir1.mkdirs(); dataDir1.mkdirs();
@ -74,7 +63,14 @@ public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
dataDir2.mkdirs(); dataDir2.mkdirs();
System.setProperty( "solr.core0.data.dir", this.dataDir1.getCanonicalPath() ); System.setProperty( "solr.core0.data.dir", this.dataDir1.getCanonicalPath() );
System.setProperty( "solr.core1.data.dir", this.dataDir2.getCanonicalPath() ); System.setProperty( "solr.core1.data.dir", this.dataDir2.getCanonicalPath() );
setupCoreContainer();
SolrCore.log.info("CORES=" + cores + " : " + cores.getCoreNames());
cores.setPersistent(false);
} }
@Override @Override
@ -89,6 +85,8 @@ public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
System.err.println("!!!! WARNING: best effort to remove " + dataDir2.getAbsolutePath() + " FAILED !!!!!"); System.err.println("!!!! WARNING: best effort to remove " + dataDir2.getAbsolutePath() + " FAILED !!!!!");
} }
} }
cores.shutdown();
} }
@Override @Override

View File

@ -51,6 +51,7 @@ public abstract class AbstractEmbeddedSolrServerTestCase extends LuceneTestCase
super.setUp(); super.setUp();
System.setProperty("solr.solr.home", SOLR_HOME.getAbsolutePath()); System.setProperty("solr.solr.home", SOLR_HOME.getAbsolutePath());
System.out.println("Solr home: " + SOLR_HOME.getAbsolutePath());
//The index is always stored within a temporary directory //The index is always stored within a temporary directory
createTempDir(); createTempDir();
@ -61,7 +62,8 @@ public abstract class AbstractEmbeddedSolrServerTestCase extends LuceneTestCase
System.setProperty("dataDir2", dataDir2.getAbsolutePath()); System.setProperty("dataDir2", dataDir2.getAbsolutePath());
System.setProperty("tempDir", tempDir.getAbsolutePath()); System.setProperty("tempDir", tempDir.getAbsolutePath());
System.setProperty("tests.shardhandler.randomSeed", Long.toString(random().nextLong())); System.setProperty("tests.shardhandler.randomSeed", Long.toString(random().nextLong()));
cores = new CoreContainer(SOLR_HOME.getAbsolutePath(), getSolrXml()); cores = CoreContainer.createAndLoad(SOLR_HOME.getAbsolutePath(), getSolrXml());
cores.setPersistent(false);
} }
protected abstract File getSolrXml() throws Exception; protected abstract File getSolrXml() throws Exception;

View File

@ -17,8 +17,6 @@
package org.apache.solr.client.solrj.embedded; package org.apache.solr.client.solrj.embedded;
import java.io.File;
import org.apache.solr.client.solrj.MergeIndexesExampleTestBase; import org.apache.solr.client.solrj.MergeIndexesExampleTestBase;
import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrCore;
@ -36,10 +34,6 @@ public class MergeIndexesEmbeddedTest extends MergeIndexesExampleTestBase {
// TODO: fix this test to use MockDirectoryFactory // TODO: fix this test to use MockDirectoryFactory
System.clearProperty("solr.directoryFactory"); System.clearProperty("solr.directoryFactory");
super.setUp(); super.setUp();
File home = new File(getSolrHome());
File f = new File(home, "solr.xml");
cores.load(getSolrHome(), f);
} }
@Override @Override

View File

@ -17,8 +17,6 @@
package org.apache.solr.client.solrj.embedded; package org.apache.solr.client.solrj.embedded;
import java.io.File;
import org.apache.solr.client.solrj.MultiCoreExampleTestBase; import org.apache.solr.client.solrj.MultiCoreExampleTestBase;
import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.SolrServer;
@ -35,10 +33,6 @@ public class MultiCoreEmbeddedTest extends MultiCoreExampleTestBase {
// TODO: fix this test to use MockDirectoryFactory // TODO: fix this test to use MockDirectoryFactory
System.clearProperty("solr.directoryFactory"); System.clearProperty("solr.directoryFactory");
super.setUp(); super.setUp();
File home = new File( getSolrHome() );
File f = new File( home, "solr.xml" );
cores.load( getSolrHome(), f );
} }
@Override @Override

View File

@ -17,20 +17,16 @@
package org.apache.solr.client.solrj.embedded; package org.apache.solr.client.solrj.embedded;
import java.io.File; import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
import java.io.FileInputStream; import com.google.common.io.ByteStreams;
import java.io.InputStreamReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.*;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION; import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;
import org.apache.solr.client.solrj.request.*; 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.client.solrj.response.CoreAdminResponse;
import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.core.CoreContainer; import org.apache.solr.core.CoreContainer;
@ -46,7 +42,17 @@ import org.slf4j.LoggerFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
/** /**
* *
@ -75,6 +81,17 @@ public class TestSolrProperties extends AbstractEmbeddedSolrServerTestCase {
public void tearDown() throws Exception { public void tearDown() throws Exception {
super.tearDown(); super.tearDown();
} }
private static void dumpFile(File fileToDump) throws IOException {
System.out.println("Dumping " + fileToDump.getAbsolutePath());
InputStream is = new FileInputStream(fileToDump);
try {
ByteStreams.copy(is, System.out);
}
finally {
IOUtils.closeQuietly(is);
}
}
@Override @Override
protected File getSolrXml() throws Exception { protected File getSolrXml() throws Exception {
@ -107,6 +124,10 @@ public class TestSolrProperties extends AbstractEmbeddedSolrServerTestCase {
@Test @Test
public void testProperties() throws Exception { public void testProperties() throws Exception {
String persistedSolrXml = new File(tempDir, SOLR_PERSIST_XML).getAbsolutePath();
log.info("persistedSolrXml: {}", persistedSolrXml);
UpdateRequest up = new UpdateRequest(); UpdateRequest up = new UpdateRequest();
up.setAction(ACTION.COMMIT, true, true); up.setAction(ACTION.COMMIT, true, true);
up.deleteByQuery("*:*"); up.deleteByQuery("*:*");
@ -176,14 +197,14 @@ public class TestSolrProperties extends AbstractEmbeddedSolrServerTestCase {
long after = mcr.getStartTime(name).getTime(); long after = mcr.getStartTime(name).getTime();
assertTrue("should have more recent time: " + after + "," + before, after > before); assertTrue("should have more recent time: " + after + "," + before, after > before);
mcr = CoreAdminRequest.persist(SOLR_PERSIST_XML, coreadmin); mcr = CoreAdminRequest.persist(persistedSolrXml, coreadmin);
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
FileInputStream fis = new FileInputStream(new File(tempDir, SOLR_PERSIST_XML)); FileInputStream fis = new FileInputStream(new File(persistedSolrXml));
try { try {
Document document = builder.parse(fis); Document document = builder.parse(fis);
fis.close(); fis.close();
fis = new FileInputStream(new File(tempDir, SOLR_PERSIST_XML)); fis = new FileInputStream(new File(persistedSolrXml));
String solrPersistXml = IOUtils.toString(new InputStreamReader(fis, "UTF-8")); String solrPersistXml = IOUtils.toString(new InputStreamReader(fis, "UTF-8"));
//System.out.println("xml:" + solrPersistXml); //System.out.println("xml:" + solrPersistXml);
assertTrue("\"/solr/cores[@defaultCoreName='core0']\" doesn't match in:\n" + solrPersistXml, assertTrue("\"/solr/cores[@defaultCoreName='core0']\" doesn't match in:\n" + solrPersistXml,
@ -204,14 +225,14 @@ public class TestSolrProperties extends AbstractEmbeddedSolrServerTestCase {
CoreAdminRequest.renameCore(name, "renamed_core", coreadmin); CoreAdminRequest.renameCore(name, "renamed_core", coreadmin);
mcr = CoreAdminRequest.persist(SOLR_PERSIST_XML, getRenamedSolrAdmin()); mcr = CoreAdminRequest.persist(persistedSolrXml, getRenamedSolrAdmin());
// fis = new FileInputStream(new File(tempDir, SOLR_PERSIST_XML)); // fis = new FileInputStream(new File(tempDir, SOLR_PERSIST_XML));
// String solrPersistXml = IOUtils.toString(fis); // String solrPersistXml = IOUtils.toString(fis);
// System.out.println("xml:" + solrPersistXml); // System.out.println("xml:" + solrPersistXml);
// fis.close(); // fis.close();
fis = new FileInputStream(new File(tempDir, SOLR_PERSIST_XML)); fis = new FileInputStream(new File(persistedSolrXml));
try { try {
Document document = builder.parse(fis); Document document = builder.parse(fis);
assertTrue(exists("/solr/cores/core[@name='renamed_core']", document)); assertTrue(exists("/solr/cores/core[@name='renamed_core']", document));
@ -235,14 +256,14 @@ public class TestSolrProperties extends AbstractEmbeddedSolrServerTestCase {
// System.out.println("xml:" + solrPersistXml); // System.out.println("xml:" + solrPersistXml);
// fis.close(); // fis.close();
mcr = CoreAdminRequest.persist(SOLR_PERSIST_XML, getRenamedSolrAdmin()); mcr = CoreAdminRequest.persist(persistedSolrXml, getRenamedSolrAdmin());
// fis = new FileInputStream(new File(solrXml.getParent(), SOLR_PERSIST_XML)); // fis = new FileInputStream(new File(solrXml.getParent(), SOLR_PERSIST_XML));
// solrPersistXml = IOUtils.toString(fis); // solrPersistXml = IOUtils.toString(fis);
// System.out.println("xml:" + solrPersistXml); // System.out.println("xml:" + solrPersistXml);
// fis.close(); // fis.close();
fis = new FileInputStream(new File(tempDir, SOLR_PERSIST_XML)); fis = new FileInputStream(new File(persistedSolrXml));
try { try {
Document document = builder.parse(fis); Document document = builder.parse(fis);
assertTrue(exists("/solr/cores/core[@name='collection1' and @instanceDir='.']", document)); assertTrue(exists("/solr/cores/core[@name='collection1' and @instanceDir='.']", document));
@ -259,9 +280,9 @@ public class TestSolrProperties extends AbstractEmbeddedSolrServerTestCase {
// System.out.println("xml:" + solrPersistXml); // System.out.println("xml:" + solrPersistXml);
// fis.close(); // fis.close();
cores = new CoreContainer(SOLR_HOME.getAbsolutePath(), new File(tempDir, SOLR_PERSIST_XML)); cores = CoreContainer.createAndLoad(SOLR_HOME.getAbsolutePath(), new File(persistedSolrXml));
mcr = CoreAdminRequest.persist(SOLR_PERSIST_XML, getRenamedSolrAdmin()); //mcr = CoreAdminRequest.persist(SOLR_PERSIST_XML, getRenamedSolrAdmin());
// fis = new FileInputStream(new File(solrXml.getParent(), // fis = new FileInputStream(new File(solrXml.getParent(),
// SOLR_PERSIST_XML)); // SOLR_PERSIST_XML));

View File

@ -17,8 +17,8 @@
package org.apache.solr.client.solrj.request; package org.apache.solr.client.solrj.request;
import java.io.File; import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
import org.apache.commons.io.FileUtils;
import org.apache.solr.SolrIgnoredThreadsFilter; import org.apache.solr.SolrIgnoredThreadsFilter;
import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.embedded.AbstractEmbeddedSolrServerTestCase; import org.apache.solr.client.solrj.embedded.AbstractEmbeddedSolrServerTestCase;
@ -27,14 +27,13 @@ import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrCore;
import org.apache.commons.io.FileUtils;
import org.junit.After; import org.junit.After;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters; import java.io.File;
@ThreadLeakFilters(defaultFilters = true, filters = {SolrIgnoredThreadsFilter.class}) @ThreadLeakFilters(defaultFilters = true, filters = {SolrIgnoredThreadsFilter.class})
public class TestCoreAdmin extends AbstractEmbeddedSolrServerTestCase { public class TestCoreAdmin extends AbstractEmbeddedSolrServerTestCase {
@ -67,6 +66,8 @@ public class TestCoreAdmin extends AbstractEmbeddedSolrServerTestCase {
File tmp = new File(TEMP_DIR, "solrtest-" + getTestClass().getSimpleName() + "-" + System.currentTimeMillis()); File tmp = new File(TEMP_DIR, "solrtest-" + getTestClass().getSimpleName() + "-" + System.currentTimeMillis());
tmp.mkdirs(); tmp.mkdirs();
log.info("Creating cores underneath {}", tmp);
File dataDir = new File(tmp, this.getTestName() File dataDir = new File(tmp, this.getTestName()
+ System.currentTimeMillis() + "-" + "data"); + System.currentTimeMillis() + "-" + "data");

View File

@ -17,26 +17,28 @@
package org.apache.solr; package org.apache.solr;
import java.io.*; import com.carrotsearch.randomizedtesting.RandomizedContext;
import java.util.*; import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
import java.util.logging.*; import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
import javax.xml.xpath.XPathExpressionException;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.Constants;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.QuickPatchThreadsFilter; import org.apache.lucene.util.QuickPatchThreadsFilter;
import org.apache.solr.client.solrj.util.ClientUtils; import org.apache.solr.client.solrj.util.ClientUtils;
import org.apache.solr.common.*; import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.SolrInputField;
import org.apache.solr.common.cloud.SolrZkClient; import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.params.*; import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.XML; import org.apache.solr.common.util.XML;
import org.apache.solr.core.CoreContainer; import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrConfig; import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.JsonUpdateRequestHandler; import org.apache.solr.handler.JsonUpdateRequestHandler;
import org.apache.solr.request.*; import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.schema.IndexSchema; import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.SchemaField; import org.apache.solr.schema.SchemaField;
import org.apache.solr.search.SolrIndexSearcher; import org.apache.solr.search.SolrIndexSearcher;
@ -44,7 +46,10 @@ import org.apache.solr.servlet.DirectSolrConnection;
import org.apache.solr.util.AbstractSolrTestCase; import org.apache.solr.util.AbstractSolrTestCase;
import org.apache.solr.util.RevertDefaultThreadHandlerRule; import org.apache.solr.util.RevertDefaultThreadHandlerRule;
import org.apache.solr.util.TestHarness; import org.apache.solr.util.TestHarness;
import org.junit.*; import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.rules.RuleChain; import org.junit.rules.RuleChain;
import org.junit.rules.TestRule; import org.junit.rules.TestRule;
import org.noggit.CharArr; import org.noggit.CharArr;
@ -54,9 +59,22 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import com.carrotsearch.randomizedtesting.RandomizedContext; import javax.xml.xpath.XPathExpressionException;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters; import java.io.File;
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule; import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
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 * A junit4 Solr test harness that extends LuceneTestCaseJ4. To change which core is used when loading the schema and solrconfig.xml, simply
@ -405,6 +423,40 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
("standard",0,20,CommonParams.VERSION,"2.2"); ("standard",0,20,CommonParams.VERSION,"2.2");
} }
public static CoreContainer createCoreContainer(String solrHome, String solrXML) {
testSolrHome = checkNotNull(solrHome);
if (dataDir == null)
createTempDir();
h = new TestHarness(solrHome, solrXML);
lrf = h.getRequestFactory("standard", 0, 20, CommonParams.VERSION, "2.2");
return h.getCoreContainer();
}
public static CoreContainer createDefaultCoreContainer(String solrHome) {
testSolrHome = checkNotNull(solrHome);
if (dataDir == null)
createTempDir();
h = new TestHarness("collection1", dataDir.getAbsolutePath(), "solrconfig.xml", "schema.xml");
lrf = h.getRequestFactory("standard", 0, 20, CommonParams.VERSION, "2.2");
return h.getCoreContainer();
}
public static boolean hasInitException(String message) {
for (Map.Entry<String, Exception> entry : h.getCoreContainer().getCoreInitFailures().entrySet()) {
if (entry.getValue().getMessage().indexOf(message) != -1)
return true;
}
return false;
}
public static boolean hasInitException(Class<? extends Exception> exceptionType) {
for (Map.Entry<String, Exception> entry : h.getCoreContainer().getCoreInitFailures().entrySet()) {
if (exceptionType.isAssignableFrom(entry.getValue().getClass()))
return true;
}
return false;
}
/** Subclasses that override setUp can optionally call this method /** Subclasses that override setUp can optionally call this method
* to log the fact that their setUp process has ended. * to log the fact that their setUp process has ended.
*/ */
@ -1451,12 +1503,12 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
return result; return result;
} }
public void assertXmlFile(final File file, String... xpath) public static void assertXmlFile(final File file, String... xpath)
throws IOException, SAXException { throws IOException, SAXException {
try { try {
String xml = FileUtils.readFileToString(file, "UTF-8"); String xml = FileUtils.readFileToString(file, "UTF-8");
String results = h.validateXPath(xml, xpath); String results = TestHarness.validateXPath(xml, xpath);
if (null != results) { if (null != results) {
String msg = "File XPath failure: file=" + file.getPath() + " xpath=" String msg = "File XPath failure: file=" + file.getPath() + " xpath="
+ results + "\n\nxml was: " + xml; + results + "\n\nxml was: " + xml;

View File

@ -33,10 +33,10 @@ import java.io.StringWriter;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
abstract public class BaseTestHarness { abstract public class BaseTestHarness {
private final ThreadLocal<DocumentBuilder> builderTL = new ThreadLocal<DocumentBuilder>(); private static final ThreadLocal<DocumentBuilder> builderTL = new ThreadLocal<DocumentBuilder>();
private final ThreadLocal<XPath> xpathTL = new ThreadLocal<XPath>(); private static final ThreadLocal<XPath> xpathTL = new ThreadLocal<XPath>();
public DocumentBuilder getXmlDocumentBuilder() { public static DocumentBuilder getXmlDocumentBuilder() {
try { try {
DocumentBuilder builder = builderTL.get(); DocumentBuilder builder = builderTL.get();
if (builder == null) { if (builder == null) {
@ -49,7 +49,7 @@ abstract public class BaseTestHarness {
} }
} }
public XPath getXpath() { public static XPath getXpath() {
try { try {
XPath xpath = xpathTL.get(); XPath xpath = xpathTL.get();
if (xpath == null) { if (xpath == null) {
@ -71,7 +71,7 @@ abstract public class BaseTestHarness {
* @param tests Array of XPath strings to test (in boolean mode) on the xml * @param tests Array of XPath strings to test (in boolean mode) on the xml
* @return null if all good, otherwise the first test that fails. * @return null if all good, otherwise the first test that fails.
*/ */
public String validateXPath(String xml, String... tests) public static String validateXPath(String xml, String... tests)
throws XPathExpressionException, SAXException { throws XPathExpressionException, SAXException {
if (tests==null || tests.length == 0) return null; if (tests==null || tests.length == 0) return null;

View File

@ -127,7 +127,7 @@ abstract public class RestTestBase extends SolrJettyTestBase {
} }
*/ */
String results = restTestHarness.validateXPath(response, tests); String results = TestHarness.validateXPath(response, tests);
if (null != results) { if (null != results) {
String msg = "REQUEST FAILED: xpath=" + results String msg = "REQUEST FAILED: xpath=" + results

View File

@ -17,21 +17,17 @@
package org.apache.solr.util; package org.apache.solr.util;
import com.google.common.base.Charsets;
import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.Config; import org.apache.solr.common.util.NamedList.NamedListEntry;
import org.apache.solr.core.ConfigSolrXmlOld; import org.apache.solr.core.ConfigSolr;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrConfig; import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrCore;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.core.SolrResourceLoader; import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.handler.UpdateRequestHandler; import org.apache.solr.handler.UpdateRequestHandler;
import org.apache.solr.logging.ListenerConfig;
import org.apache.solr.logging.LogWatcher;
import org.apache.solr.logging.jul.JulWatcher;
import org.apache.solr.request.LocalSolrQueryRequest; import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrRequestHandler; import org.apache.solr.request.SolrRequestHandler;
@ -41,9 +37,6 @@ import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.schema.IndexSchema; import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.IndexSchemaFactory; import org.apache.solr.schema.IndexSchemaFactory;
import org.apache.solr.servlet.DirectSolrConnection; import org.apache.solr.servlet.DirectSolrConnection;
import org.apache.solr.common.util.NamedList.NamedListEntry;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
@ -52,8 +45,6 @@ import java.io.StringWriter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
/** /**
* This class provides a simple harness that may be useful when * This class provides a simple harness that may be useful when
@ -107,19 +98,8 @@ public class TestHarness extends BaseTestHarness {
SolrConfig solrConfig, SolrConfig solrConfig,
String schemaFile) { String schemaFile) {
this( coreName, dataDirectory, solrConfig, IndexSchemaFactory.buildIndexSchema(schemaFile, solrConfig)); this( coreName, dataDirectory, solrConfig, IndexSchemaFactory.buildIndexSchema(schemaFile, solrConfig));
} }
/**
* @param coreName to initialize
* @param dataDirectory path for index data, will not be cleaned up
* @param solrConfig solrconfig instance
* @param indexSchema schema instance
*/
public TestHarness( String coreName,
String dataDirectory,
SolrConfig solrConfig,
IndexSchema indexSchema) {
this(coreName, new Initializer(coreName, dataDirectory, solrConfig, indexSchema));
}
/** /**
* @param dataDirectory path for index data, will not be cleaned up * @param dataDirectory path for index data, will not be cleaned up
* @param solrConfig solronfig instance * @param solrConfig solronfig instance
@ -138,18 +118,26 @@ public class TestHarness extends BaseTestHarness {
public TestHarness( String dataDirectory, public TestHarness( String dataDirectory,
SolrConfig solrConfig, SolrConfig solrConfig,
IndexSchema indexSchema) { IndexSchema indexSchema) {
this(null, new Initializer(null, dataDirectory, solrConfig, indexSchema)); this(CoreContainer.DEFAULT_DEFAULT_CORE_NAME, dataDirectory, solrConfig, indexSchema);
} }
public TestHarness(String coreName, CoreContainer.Initializer init) {
try {
container = init.initialize(); /**
* @param coreName to initialize
* @param dataDir path for index data, will not be cleaned up
* @param solrConfig solrconfig resource name
* @param indexSchema schema resource name
*/
public TestHarness(String coreName, String dataDir, String solrConfig, String indexSchema) {
try {
if (coreName == null) if (coreName == null)
coreName = CoreContainer.DEFAULT_DEFAULT_CORE_NAME; coreName = CoreContainer.DEFAULT_DEFAULT_CORE_NAME;
this.coreName = coreName; this.coreName = coreName;
SolrResourceLoader loader = new SolrResourceLoader(SolrResourceLoader.locateSolrHome());
ConfigSolr config = getTestHarnessConfig(coreName, dataDir, solrConfig, indexSchema);
container = new CoreContainer(loader, config);
container.load();
updater = new UpdateRequestHandler(); updater = new UpdateRequestHandler();
updater.init( null ); updater.init( null );
} catch (Exception e) { } catch (Exception e) {
@ -157,81 +145,50 @@ public class TestHarness extends BaseTestHarness {
} }
} }
// Creates a container based on infos needed to create one core public TestHarness(String coreName, String dataDir, SolrConfig solrConfig, IndexSchema indexSchema) {
static class Initializer extends CoreContainer.Initializer { this(coreName, dataDir, solrConfig.getResourceName(), indexSchema.getResourceName());
String coreName; }
String dataDirectory;
SolrConfig solrConfig;
IndexSchema indexSchema;
public Initializer(String coreName,
String dataDirectory,
SolrConfig solrConfig,
IndexSchema indexSchema) {
if (coreName == null)
coreName = CoreContainer.DEFAULT_DEFAULT_CORE_NAME;
this.coreName = coreName;
this.dataDirectory = dataDirectory;
this.solrConfig = solrConfig;
this.indexSchema = indexSchema;
}
public String getCoreName() {
return coreName;
}
@Override
public CoreContainer initialize() {
CoreContainer container;
try {
String solrHome = SolrResourceLoader.locateSolrHome();
container = new CoreContainer(new SolrResourceLoader(solrHome)) {
{
String hostPort = System.getProperty("hostPort", "8983");
String hostContext = System.getProperty("hostContext", "solr");
defaultCoreName = CoreContainer.DEFAULT_DEFAULT_CORE_NAME;
initShardHandler();
zkSys.initZooKeeper(this, solrHome, System.getProperty("zkHost"), 30000, hostPort, hostContext, null, "30000", true, 30000, 30000);
ByteArrayInputStream is = new ByteArrayInputStream(ConfigSolrXmlOld.DEF_SOLR_XML.getBytes("UTF-8"));
Config config = new Config(loader, null, new InputSource(is), null, false);
cfg = new ConfigSolrXmlOld(config, this);
}
};
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (SAXException e) {
throw new RuntimeException(e);
}
LogWatcher<?> logging = new JulWatcher("test");
logging.registerListener(new ListenerConfig());
container.setLogging(logging);
CoreDescriptor dcore = new CoreDescriptor(container, coreName, solrConfig.getResourceLoader().getInstanceDir());
if (container.isZooKeeperAware()) {
container.getZkController().preRegister(dcore);
}
dcore.setConfigName(solrConfig.getResourceName());
dcore.setSchemaName(indexSchema.getResourceName());
if (container.getZkController() != null) {
container.preRegisterInZk(dcore);
}
SolrCore core = new SolrCore(coreName, dataDirectory, solrConfig, indexSchema, dcore);
if (container.isZooKeeperAware() && Slice.CONSTRUCTION.equals(dcore.getCloudDescriptor().getShardState())) {
// set update log to buffer before publishing the core
core.getUpdateHandler().getUpdateLog().bufferUpdates();
}
container.register(coreName, core, false);
// TODO: we should be exercising the *same* core container initialization code, not equivalent code! /**
if (container.getZkController() == null && core.getUpdateHandler().getUpdateLog() != null) { * Create a TestHarness using a specific solr home directory and solr xml
// always kick off recovery if we are in standalone mode. * @param solrHome the solr home directory
core.getUpdateHandler().getUpdateLog().recoverFromLog(); * @param solrXml a File pointing to a solr.xml configuration
} */
return container; public TestHarness(String solrHome, String solrXml) {
} this(new SolrResourceLoader(solrHome),
ConfigSolr.fromInputStream(null, new ByteArrayInputStream(solrXml.getBytes(Charsets.UTF_8))));
}
/**
* Create a TestHarness using a specific resource loader and config
* @param loader the SolrResourceLoader to use
* @param config the ConfigSolr to use
*/
public TestHarness(SolrResourceLoader loader, ConfigSolr config) {
container = new CoreContainer(loader, config);
container.load();
updater = new UpdateRequestHandler();
updater.init(null);
}
private static ConfigSolr getTestHarnessConfig(String coreName, String dataDir,
String solrConfig, String schema) {
String solrxml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
+ "<solr persistent=\"false\">\n"
+ " <logging enabled=\"true\"/>\n"
+ " <cores adminPath=\"/admin/cores\" defaultCoreName=\""
+ CoreContainer.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(new SolrResourceLoader(dataDir), solrxml);
} }
public CoreContainer getCoreContainer() { public CoreContainer getCoreContainer() {