mirror of https://github.com/apache/lucene.git
SOLR-4948: Tidy up CoreContainer construction logic
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1496505 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b6601c3247
commit
f47bb580ee
|
@ -46,6 +46,8 @@ Other Changes
|
|||
|
||||
* SOLR-4792: Stop shipping a .war. (Robert Muir)
|
||||
|
||||
* SOLR-4948: Tidied up CoreContainer construction logic. (Alan Woodward)
|
||||
|
||||
================== 4.4.0 ==================
|
||||
|
||||
Versions of Major Components
|
||||
|
|
|
@ -1,14 +1,5 @@
|
|||
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.CommandLineParser;
|
||||
import org.apache.commons.cli.HelpFormatter;
|
||||
|
@ -17,18 +8,19 @@ import org.apache.commons.cli.OptionBuilder;
|
|||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
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.SolrZkClient;
|
||||
import org.apache.solr.core.Config;
|
||||
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.zookeeper.KeeperException;
|
||||
import org.xml.sax.InputSource;
|
||||
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
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
@ -178,25 +170,7 @@ public class ZkCLI {
|
|||
SolrResourceLoader loader = new SolrResourceLoader(solrHome);
|
||||
solrHome = loader.getInstanceDir();
|
||||
|
||||
File configFile = new File(solrHome, SOLR_XML);
|
||||
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);
|
||||
}
|
||||
|
||||
ConfigSolr cfg = ConfigSolr.fromSolrHome(solrHome);
|
||||
|
||||
if(!ZkController.checkChrootPath(zkServerAddress, true)) {
|
||||
System.out.println("A chroot was specified in zkHost but the znode doesn't exist. ");
|
||||
|
|
|
@ -17,28 +17,6 @@ package org.apache.solr.cloud;
|
|||
* 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.solr.client.solrj.impl.HttpSolrServer;
|
||||
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.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.
|
||||
*
|
||||
|
|
|
@ -68,6 +68,7 @@ public class Config {
|
|||
static final XPathFactory xpathFactory = XPathFactory.newInstance();
|
||||
|
||||
private final Document doc;
|
||||
private final Document origDoc; // with unsubstituted properties
|
||||
private final String prefix;
|
||||
private final String name;
|
||||
private final SolrResourceLoader loader;
|
||||
|
@ -131,6 +132,7 @@ public class Config {
|
|||
db.setErrorHandler(xmllog);
|
||||
try {
|
||||
doc = db.parse(is);
|
||||
origDoc = copyDoc(doc);
|
||||
} finally {
|
||||
// some XML parsers are broken and don't close the byte stream (but they should according to spec)
|
||||
IOUtils.closeQuietly(is.getByteStream());
|
||||
|
@ -140,19 +142,24 @@ public class Config {
|
|||
}
|
||||
} catch (ParserConfigurationException e) {
|
||||
SolrException.log(log, "Exception during parsing file: " + name, e);
|
||||
throw e;
|
||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
|
||||
} catch (SAXException e) {
|
||||
SolrException.log(log, "Exception during parsing file: " + name, e);
|
||||
throw e;
|
||||
} catch( SolrException e ){
|
||||
SolrException.log(log,"Error in "+name,e);
|
||||
throw e;
|
||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
|
||||
} catch (TransformerException e) {
|
||||
SolrException.log(log, "Exception during parsing file: " + name, e);
|
||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
|
||||
}
|
||||
}
|
||||
|
||||
public Config(SolrResourceLoader loader, String name, Document doc) {
|
||||
this.prefix = null;
|
||||
this.doc = doc;
|
||||
try {
|
||||
this.origDoc = copyDoc(doc);
|
||||
} catch (TransformerException e) {
|
||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
|
||||
}
|
||||
this.name = name;
|
||||
this.loader = loader;
|
||||
}
|
||||
|
@ -441,4 +448,9 @@ public class Config {
|
|||
|
||||
return version;
|
||||
}
|
||||
|
||||
public Config getOriginalConfig() {
|
||||
return new Config(loader, null, origDoc);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,15 +17,8 @@ package org.apache.solr.core;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathConstants;
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.solr.common.SolrException;
|
||||
import org.apache.solr.util.DOMUtil;
|
||||
import org.apache.solr.util.PropertiesUtil;
|
||||
|
@ -33,13 +26,77 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathConstants;
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
|
||||
public abstract class ConfigSolr {
|
||||
protected static Logger log = LoggerFactory.getLogger(ConfigSolr.class);
|
||||
|
||||
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.
|
||||
public static enum CfgProp {
|
||||
SOLR_ADMINHANDLER,
|
||||
|
@ -78,6 +135,11 @@ public abstract class ConfigSolr {
|
|||
public ConfigSolr(Config config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
// for extension & testing.
|
||||
protected ConfigSolr() {
|
||||
|
||||
}
|
||||
|
||||
public Config getConfig() {
|
||||
return config;
|
||||
|
@ -124,7 +186,8 @@ public abstract class ConfigSolr {
|
|||
Properties properties = new Properties();
|
||||
for (int i = 0; i < props.getLength(); 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;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,12 @@ package org.apache.solr.core;
|
|||
* 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.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -27,15 +33,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
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 final Map<String, CoreDescriptor> coreDescriptorMap;
|
||||
|
||||
public ConfigSolrXml(Config config, CoreContainer container)
|
||||
throws ParserConfigurationException, IOException, SAXException {
|
||||
public ConfigSolrXml(Config config, CoreContainer container) {
|
||||
super(config);
|
||||
checkForIllegalConfig();
|
||||
|
||||
fillPropMap();
|
||||
|
||||
String coreRoot = get(CfgProp.SOLR_COREROOTDIRECTORY, (container == null ? config.getResourceLoader().getInstanceDir() : container.getSolrHome()));
|
||||
coreDescriptorMap = solrCoreDiscoverer.discover(container, new File(coreRoot));
|
||||
try {
|
||||
checkForIllegalConfig();
|
||||
fillPropMap();
|
||||
config.substituteProperties();
|
||||
String coreRoot = get(CfgProp.SOLR_COREROOTDIRECTORY, (container == null ? config.getResourceLoader().getInstanceDir() : container.getSolrHome()));
|
||||
coreDescriptorMap = solrCoreDiscoverer.discover(container, new File(coreRoot));
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkForIllegalConfig() throws IOException {
|
||||
|
|
|
@ -17,6 +17,17 @@ package org.apache.solr.core;
|
|||
* 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.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -28,20 +39,6 @@ import java.util.Map;
|
|||
import java.util.Properties;
|
||||
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;
|
||||
|
||||
public ConfigSolrXmlOld(Config config, CoreContainer container)
|
||||
throws ParserConfigurationException, IOException, SAXException {
|
||||
|
||||
public ConfigSolrXmlOld(Config config) {
|
||||
super(config);
|
||||
checkForIllegalConfig(container);
|
||||
|
||||
fillPropMap();
|
||||
initCoreList(container);
|
||||
try {
|
||||
checkForIllegalConfig();
|
||||
fillPropMap();
|
||||
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
|
||||
// config
|
||||
failIfFound("solr/str[@name='adminHandler']");
|
||||
|
@ -154,7 +154,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",
|
||||
XPathConstants.NODESET);
|
||||
|
@ -219,7 +219,7 @@ public class ConfigSolrXmlOld extends ConfigSolr {
|
|||
NamedNodeMap attributes = node.getAttributes();
|
||||
for (int i = 0; i < attributes.getLength(); i++) {
|
||||
Node attribute = attributes.item(i);
|
||||
String val = attribute.getNodeValue();
|
||||
String val = PropertiesUtil.substituteProperty(attribute.getNodeValue(), null);
|
||||
if (CoreDescriptor.CORE_DATADIR.equals(attribute.getNodeName()) ||
|
||||
CoreDescriptor.CORE_INSTDIR.equals(attribute.getNodeName())) {
|
||||
if (val.indexOf('$') == -1) {
|
||||
|
@ -257,7 +257,8 @@ public class ConfigSolrXmlOld extends ConfigSolr {
|
|||
Node node = coreNodes.item(idx);
|
||||
if (coreName.equals(DOMUtil.getAttr(node, CoreDescriptor.CORE_NAME,
|
||||
null))) {
|
||||
return DOMUtil.getAttr(node, property, defaultVal);
|
||||
String propVal = DOMUtil.getAttr(node, property, defaultVal);
|
||||
return PropertiesUtil.substituteProperty(propVal, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -286,16 +287,16 @@ public class ConfigSolrXmlOld extends ConfigSolr {
|
|||
}
|
||||
|
||||
public static final String DEF_SOLR_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
|
||||
+ "<solr persistent=\"false\">\n"
|
||||
+ " <cores adminPath=\"/admin/cores\" defaultCoreName=\""
|
||||
+ CoreContainer.DEFAULT_DEFAULT_CORE_NAME
|
||||
+ "\""
|
||||
+ " host=\"${host:}\" hostPort=\"${hostPort:}\" hostContext=\"${hostContext:}\" zkClientTimeout=\"${zkClientTimeout:15000}\""
|
||||
+ ">\n"
|
||||
+ " <core name=\""
|
||||
+ CoreContainer.DEFAULT_DEFAULT_CORE_NAME
|
||||
+ "\" shard=\"${shard:}\" collection=\"${collection:}\" instanceDir=\"collection1\" />\n"
|
||||
+ " </cores>\n" + "</solr>";
|
||||
+ "<solr persistent=\"false\">\n"
|
||||
+ " <cores adminPath=\"/admin/cores\" defaultCoreName=\""
|
||||
+ CoreContainer.DEFAULT_DEFAULT_CORE_NAME
|
||||
+ "\""
|
||||
+ " host=\"${host:}\" hostPort=\"${hostPort:}\" hostContext=\"${hostContext:}\" zkClientTimeout=\"${zkClientTimeout:15000}\""
|
||||
+ ">\n"
|
||||
+ " <core name=\""
|
||||
+ CoreContainer.DEFAULT_DEFAULT_CORE_NAME
|
||||
+ "\" shard=\"${shard:}\" collection=\"${collection:}\" instanceDir=\"collection1\" />\n"
|
||||
+ " </cores>\n" + "</solr>";
|
||||
|
||||
@Override
|
||||
public void substituteProperties() {
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
package org.apache.solr.core;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.solr.cloud.ZkController;
|
||||
import org.apache.solr.cloud.ZkSolrResourceLoader;
|
||||
import org.apache.solr.common.SolrException;
|
||||
|
@ -39,21 +38,10 @@ import org.apache.solr.util.plugin.PluginInfoInitialized;
|
|||
import org.apache.zookeeper.KeeperException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Document;
|
||||
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 java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
@ -76,6 +64,8 @@ import java.util.concurrent.LinkedBlockingQueue;
|
|||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
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 CollectionsHandler collectionsHandler = null;
|
||||
protected File configFile = null;
|
||||
protected String libDir = null;
|
||||
protected SolrResourceLoader loader = null;
|
||||
|
||||
protected Properties containerProperties;
|
||||
protected Map<String ,IndexSchema> indexSchemaCache;
|
||||
protected String adminHandler;
|
||||
protected boolean shareSchema;
|
||||
protected Integer zkClientTimeout;
|
||||
protected String solrHome;
|
||||
protected String defaultCoreName = null;
|
||||
protected int distribUpdateConnTimeout = 0;
|
||||
protected int distribUpdateSoTimeout = 0;
|
||||
|
@ -126,151 +114,90 @@ public class CoreContainer
|
|||
|
||||
private int coreLoadThreads;
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated
|
||||
* @deprecated use the single arg constructor with locateSolrHome()
|
||||
* @see SolrResourceLoader#locateSolrHome
|
||||
* Create a new CoreContainer using system properties to detect the solr home
|
||||
* directory. The container's cores are not loaded.
|
||||
* @see #load()
|
||||
*/
|
||||
@Deprecated
|
||||
public CoreContainer() {
|
||||
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 {
|
||||
this(dir);
|
||||
this.load(dir, configFile);
|
||||
public CoreContainer(SolrResourceLoader loader) {
|
||||
this(loader, ConfigSolr.fromSolrHome(loader.getInstanceDir()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Minimal CoreContainer constructor.
|
||||
* @param loader the CoreContainer resource loader
|
||||
* Create a new CoreContainer using the given solr home directory. The container's
|
||||
* cores are not loaded.
|
||||
* @param solrHome a String containing the path to the solr home directory
|
||||
* @see #load()
|
||||
*/
|
||||
public CoreContainer(SolrResourceLoader loader) {
|
||||
this(loader.getInstanceDir());
|
||||
this.loader = loader;
|
||||
public CoreContainer(String solrHome) {
|
||||
this(new SolrResourceLoader(solrHome), ConfigSolr.fromSolrHome(solrHome));
|
||||
}
|
||||
|
||||
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() {
|
||||
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. 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
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param dir the home directory of all resources.
|
||||
* @param is the configuration file InputStream. May be a properties file or an xml file
|
||||
* Load the cores defined for this CoreContainer
|
||||
*/
|
||||
public void load() {
|
||||
|
||||
log.info("Loading cores into CoreContainer {}", System.identityHashCode(this));
|
||||
|
||||
// Let's keep this ugly boolean out of public circulation.
|
||||
protected void load(String dir, InputStream is, String fileName) {
|
||||
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
|
||||
libDir = cfg.get(ConfigSolr.CfgProp.SOLR_SHAREDLIB , 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());
|
||||
loader.addToClassLoader(libDir, null, false);
|
||||
loader.reloadLuceneSPI();
|
||||
|
@ -1076,7 +1003,7 @@ public class CoreContainer
|
|||
}
|
||||
|
||||
public File getConfigFile() {
|
||||
return configFile;
|
||||
return new File(solrHome, ConfigSolr.SOLR_XML_FILE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1090,7 +1017,7 @@ public class CoreContainer
|
|||
/** Persists the cores config file in cores.xml. */
|
||||
@Deprecated
|
||||
public void persist() {
|
||||
persistFile(configFile);
|
||||
persistFile(getConfigFile());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1111,7 +1038,7 @@ public class CoreContainer
|
|||
// only the old solrxml persists
|
||||
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">
|
||||
Map<String,String> rootSolrAttribs = new HashMap<String,String>();
|
||||
|
@ -1183,7 +1110,7 @@ public class CoreContainer
|
|||
cfg.get(ConfigSolr.CfgProp.SOLR_SHARDHANDLERFACTORY_SOCKETTIMEOUT, null));
|
||||
|
||||
try {
|
||||
solrCores.persistCores(origCfg, containerProperties, rootSolrAttribs,coresAttribs,
|
||||
solrCores.persistCores(cfg.config.getOriginalConfig(), containerProperties, rootSolrAttribs,coresAttribs,
|
||||
loggingAttribs, watcherAttribs, shardHandlerAttrib, shardHandlerProps, file, loader);
|
||||
} catch (XPathExpressionException e) {
|
||||
throw new SolrException(ErrorCode.SERVER_ERROR, null, e);
|
||||
|
@ -1270,14 +1197,7 @@ public class CoreContainer
|
|||
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 {
|
||||
|
|
|
@ -17,6 +17,15 @@ package org.apache.solr.core;
|
|||
* 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.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -31,16 +40,6 @@ import java.util.Set;
|
|||
import java.util.TreeSet;
|
||||
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 {
|
||||
private static SolrXMLSerializer SOLR_XML_SERIALIZER = new SolrXMLSerializer();
|
||||
|
@ -534,7 +533,7 @@ class SolrCores {
|
|||
// Insure instdir is persisted if it's the default since it's checked at startup even if not specified on the
|
||||
// create command.
|
||||
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 {
|
||||
|
||||
|
@ -555,8 +554,8 @@ class SolrCores {
|
|||
}
|
||||
|
||||
coreAttribs.put(CoreDescriptor.CORE_NAME, coreName);
|
||||
|
||||
addCoreProperty(coreAttribs, loader, node, CoreDescriptor.CORE_INSTDIR, dcore.getRawInstanceDir(), null);
|
||||
coreAttribs.put(CoreDescriptor.CORE_INSTDIR, dcore.getRawInstanceDir());
|
||||
//addCoreProperty(coreAttribs, loader, node, CoreDescriptor.CORE_INSTDIR, dcore.getRawInstanceDir(), null);
|
||||
|
||||
addCoreProperty(coreAttribs, loader, node, CoreDescriptor.CORE_COLLECTION,
|
||||
StringUtils.isNotBlank(collection) ? collection : dcore.getName());
|
||||
|
|
|
@ -17,56 +17,58 @@
|
|||
|
||||
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.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
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.regex.Matcher;
|
||||
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
|
||||
*/
|
||||
|
|
|
@ -137,7 +137,7 @@ public abstract class LogWatcher<E> {
|
|||
v.size = config.getInt(ConfigSolr.CfgProp.SOLR_LOGGING_WATCHER_SIZE, 50);
|
||||
v.threshold = config.get(ConfigSolr.CfgProp.SOLR_LOGGING_WATCHER_THRESHOLD, null);
|
||||
if (v.size > 0) {
|
||||
log.info("Registering Log Listener");
|
||||
log.info("Registering Log Listener [{}]", logWatcher.getName());
|
||||
logWatcher.registerListener(v);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,18 +17,6 @@
|
|||
|
||||
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.Tokenizer;
|
||||
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
|
||||
|
@ -67,6 +55,18 @@ import org.apache.solr.search.Sorting;
|
|||
import org.slf4j.Logger;
|
||||
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.
|
||||
*
|
||||
|
@ -799,6 +799,15 @@ public abstract class FieldType extends FieldProperties {
|
|||
namedPropertyValues.add(getPropertyName(TOKENIZED), isTokenized());
|
||||
// The BINARY property is always false
|
||||
// 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
|
||||
Set<String> fieldProperties = new HashSet<String>();
|
||||
for (String propertyName : FieldProperties.propertyNames) {
|
||||
|
@ -826,15 +835,7 @@ public abstract class FieldType extends FieldProperties {
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,35 +17,6 @@
|
|||
|
||||
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.solr.common.SolrException;
|
||||
import org.apache.solr.common.SolrException.ErrorCode;
|
||||
|
@ -81,6 +52,34 @@ import org.apache.solr.util.FastWriter;
|
|||
import org.slf4j.Logger;
|
||||
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
|
||||
*
|
||||
|
@ -116,12 +115,11 @@ public class SolrDispatchFilter implements Filter
|
|||
{
|
||||
log.info("SolrDispatchFilter.init()");
|
||||
|
||||
CoreContainer.Initializer init = createInitializer();
|
||||
try {
|
||||
// web.xml configuration
|
||||
this.pathPrefix = config.getInitParameter( "path-prefix" );
|
||||
|
||||
this.cores = init.initialize();
|
||||
this.cores = createCoreContainer();
|
||||
log.info("user.dir=" + System.getProperty("user.dir"));
|
||||
}
|
||||
catch( Throwable t ) {
|
||||
|
@ -132,15 +130,20 @@ public class SolrDispatchFilter implements Filter
|
|||
|
||||
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() {
|
||||
return cores;
|
||||
}
|
||||
|
||||
/** Method to override to change how CoreContainer initialization is performed. */
|
||||
protected CoreContainer.Initializer createInitializer() {
|
||||
return new CoreContainer.Initializer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
|
|
|
@ -17,11 +17,6 @@ package org.apache.solr.cloud;
|
|||
* 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.solr.SolrTestCaseJ4;
|
||||
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.ZkStateReader;
|
||||
import org.apache.solr.core.CoreContainer;
|
||||
import org.apache.solr.core.CoreContainer.Initializer;
|
||||
import org.apache.solr.core.CoreDescriptor;
|
||||
import org.apache.solr.core.SolrCore;
|
||||
import org.apache.zookeeper.CreateMode;
|
||||
|
@ -41,6 +35,11 @@ import org.junit.Test;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Slow
|
||||
public class ClusterStateUpdateTest extends SolrTestCaseJ4 {
|
||||
protected static Logger log = LoggerFactory
|
||||
|
@ -65,8 +64,6 @@ public class ClusterStateUpdateTest extends SolrTestCaseJ4 {
|
|||
private File dataDir3;
|
||||
|
||||
private File dataDir4;
|
||||
|
||||
private Initializer init2;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
|
@ -111,22 +108,21 @@ public class ClusterStateUpdateTest extends SolrTestCaseJ4 {
|
|||
|
||||
System.setProperty("solr.solr.home", TEST_HOME());
|
||||
System.setProperty("hostPort", "1661");
|
||||
CoreContainer.Initializer init1 = new CoreContainer.Initializer();
|
||||
System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir1.getAbsolutePath());
|
||||
container1 = init1.initialize();
|
||||
container1 = new CoreContainer();
|
||||
container1.load();
|
||||
System.clearProperty("hostPort");
|
||||
|
||||
System.setProperty("hostPort", "1662");
|
||||
init2 = new CoreContainer.Initializer();
|
||||
System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir2.getAbsolutePath());
|
||||
container2 = init2.initialize();
|
||||
container2 = new CoreContainer();
|
||||
container2.load();
|
||||
System.clearProperty("hostPort");
|
||||
|
||||
System.setProperty("hostPort", "1663");
|
||||
CoreContainer.Initializer init3 = new CoreContainer.Initializer();
|
||||
|
||||
System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir3.getAbsolutePath());
|
||||
container3 = init3.initialize();
|
||||
container3 = new CoreContainer();
|
||||
container3.load();
|
||||
System.clearProperty("hostPort");
|
||||
System.clearProperty("solr.solr.home");
|
||||
|
||||
|
@ -224,7 +220,11 @@ public class ClusterStateUpdateTest extends SolrTestCaseJ4 {
|
|||
.disconnect();
|
||||
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
|
||||
for(int i = 0; i < 200; i++) {
|
||||
|
|
|
@ -17,6 +17,20 @@ package org.apache.solr.cloud;
|
|||
* 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.IOException;
|
||||
import java.util.HashMap;
|
||||
|
@ -27,22 +41,6 @@ import java.util.Set;
|
|||
import java.util.regex.Matcher;
|
||||
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
|
||||
public class LeaderElectionIntegrationTest extends SolrTestCaseJ4 {
|
||||
protected static Logger log = LoggerFactory
|
||||
|
@ -140,7 +138,6 @@ public class LeaderElectionIntegrationTest extends SolrTestCaseJ4 {
|
|||
|
||||
System.setProperty("hostPort", Integer.toString(port));
|
||||
System.setProperty("shard", shard);
|
||||
Initializer init = new CoreContainer.Initializer();
|
||||
System.setProperty("solr.data.dir", data.getAbsolutePath());
|
||||
System.setProperty("solr.solr.home", TEST_HOME());
|
||||
Set<Integer> ports = shardPorts.get(shard);
|
||||
|
@ -149,7 +146,8 @@ public class LeaderElectionIntegrationTest extends SolrTestCaseJ4 {
|
|||
shardPorts.put(shard, ports);
|
||||
}
|
||||
ports.add(port);
|
||||
CoreContainer container = init.initialize();
|
||||
CoreContainer container = new CoreContainer();
|
||||
container.load();
|
||||
assertTrue("Container " + port + " has no cores!", container.getCores()
|
||||
.size() > 0);
|
||||
containerMap.put(port, container);
|
||||
|
|
|
@ -28,7 +28,6 @@ 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.apache.zookeeper.CreateMode;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
@ -62,8 +61,6 @@ public class SliceStateUpdateTest extends SolrTestCaseJ4 {
|
|||
|
||||
private File dataDir3;
|
||||
|
||||
private Initializer init2;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
System.setProperty("solrcloud.skip.autorecovery", "true");
|
||||
|
@ -117,20 +114,21 @@ public class SliceStateUpdateTest extends SolrTestCaseJ4 {
|
|||
|
||||
System.setProperty("solr.solr.home", TEST_HOME());
|
||||
System.setProperty("hostPort", "1661");
|
||||
CoreContainer.Initializer init1 = new CoreContainer.Initializer();
|
||||
System.setProperty("solr.data.dir", SliceStateUpdateTest.this.dataDir1.getAbsolutePath());
|
||||
container1 = init1.initialize();
|
||||
container1 = new CoreContainer();
|
||||
|
||||
System.clearProperty("hostPort");
|
||||
|
||||
System.setProperty("hostPort", "1662");
|
||||
init2 = new CoreContainer.Initializer();
|
||||
System.setProperty("solr.data.dir", SliceStateUpdateTest.this.dataDir2.getAbsolutePath());
|
||||
container2 = init2.initialize();
|
||||
container2 = new CoreContainer();
|
||||
System.clearProperty("hostPort");
|
||||
|
||||
System.clearProperty("solr.solr.home");
|
||||
|
||||
container1.load();
|
||||
container2.load();
|
||||
|
||||
log.info("####SETUP_END " + getTestName());
|
||||
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
package org.apache.solr.cloud;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.common.cloud.SolrZkClient;
|
||||
import org.apache.solr.core.CoreContainer;
|
||||
|
@ -30,6 +28,8 @@ import org.junit.Test;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class TestMultiCoreConfBootstrap extends SolrTestCaseJ4 {
|
||||
protected static Logger log = LoggerFactory.getLogger(TestMultiCoreConfBootstrap.class);
|
||||
protected CoreContainer cores = null;
|
||||
|
@ -99,7 +99,7 @@ public class TestMultiCoreConfBootstrap extends SolrTestCaseJ4 {
|
|||
@Test
|
||||
public void testMultiCoreConfBootstrap() throws Exception {
|
||||
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();
|
||||
// zkclient.printLayoutToStdOut();
|
||||
|
||||
|
|
|
@ -17,8 +17,6 @@ package org.apache.solr.cloud;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.common.cloud.SolrZkClient;
|
||||
import org.apache.solr.common.cloud.ZooKeeperException;
|
||||
|
@ -31,6 +29,8 @@ import org.junit.Test;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class TestZkChroot extends SolrTestCaseJ4 {
|
||||
protected static Logger log = LoggerFactory.getLogger(TestZkChroot.class);
|
||||
protected CoreContainer cores = null;
|
||||
|
@ -91,7 +91,7 @@ public class TestZkChroot extends SolrTestCaseJ4 {
|
|||
SolrZkClient zkClient2 = null;
|
||||
|
||||
try {
|
||||
cores = new CoreContainer(home, new File(home, "solr.xml"));
|
||||
cores = CoreContainer.createAndLoad(home, new File(home, "solr.xml"));
|
||||
zkClient = cores.getZkController().getZkClient();
|
||||
|
||||
assertTrue(zkClient.exists("/clusterstate.json", true));
|
||||
|
@ -122,7 +122,7 @@ public class TestZkChroot extends SolrTestCaseJ4 {
|
|||
AbstractZkTestCase.TIMEOUT);
|
||||
assertFalse("Path '" + chroot + "' should not exist before the test",
|
||||
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");
|
||||
} catch (ZooKeeperException e) {
|
||||
// expected
|
||||
|
@ -150,7 +150,7 @@ public class TestZkChroot extends SolrTestCaseJ4 {
|
|||
AbstractZkTestCase.TIMEOUT);
|
||||
assertFalse("Path '" + chroot + "' should not exist before the test",
|
||||
zkClient.exists(chroot, true));
|
||||
cores = new CoreContainer(home, new File(home, "solr.xml"));
|
||||
cores = CoreContainer.createAndLoad(home, new File(home, "solr.xml"));
|
||||
assertTrue(
|
||||
"solrconfig.xml should have been uploaded to zk to the correct config directory",
|
||||
zkClient.exists(chroot + ZkController.CONFIGS_ZKNODE + "/"
|
||||
|
@ -176,7 +176,7 @@ public class TestZkChroot extends SolrTestCaseJ4 {
|
|||
assertTrue(zkClient.exists(chroot, 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));
|
||||
} finally {
|
||||
if (cores != null) cores.shutdown();
|
||||
|
|
|
@ -17,11 +17,6 @@ package org.apache.solr.cloud;
|
|||
* 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.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.common.cloud.SolrZkClient;
|
||||
|
@ -34,6 +29,11 @@ import org.apache.zookeeper.CreateMode;
|
|||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slow
|
||||
public class ZkControllerTest extends SolrTestCaseJ4 {
|
||||
|
||||
|
@ -240,12 +240,8 @@ public class ZkControllerTest extends SolrTestCaseJ4 {
|
|||
}
|
||||
|
||||
private CoreContainer getCoreContainer() {
|
||||
CoreContainer cc = new CoreContainer(TEMP_DIR.getAbsolutePath()) {
|
||||
{
|
||||
initShardHandler();
|
||||
}
|
||||
};
|
||||
|
||||
CoreContainer cc = new CoreContainer(TEMP_DIR.getAbsolutePath());
|
||||
cc.load();
|
||||
return cc;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,8 @@
|
|||
package org.apache.solr.core;
|
||||
|
||||
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;
|
||||
|
||||
public abstract class AbstractBadConfigTestBase extends SolrTestCaseJ4 {
|
||||
|
@ -50,26 +49,37 @@ public abstract class AbstractBadConfigTestBase extends SolrTestCaseJ4 {
|
|||
|
||||
ignoreException(Pattern.quote(errString));
|
||||
try {
|
||||
|
||||
if (null == solrHome) {
|
||||
initCore( solrconfigFile, schemaFile );
|
||||
} else {
|
||||
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
|
||||
throw new SolrException
|
||||
(ErrorCode.SERVER_ERROR,
|
||||
"Unexpected error, expected error matching: " + errString, e);
|
||||
} finally {
|
||||
CoreContainer cc = h.getCoreContainer();
|
||||
for (Map.Entry<String, Exception> entry : cc.getCoreInitFailures().entrySet()) {
|
||||
if (matches(entry.getValue(), errString))
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (matches(e, errString))
|
||||
return;
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
deleteCore();
|
||||
resetExceptionIgnores();
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,23 +17,17 @@
|
|||
|
||||
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.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.junit.Before;
|
||||
import org.junit.After;
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
||||
|
||||
|
@ -44,8 +38,7 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
|||
// would be nice to do this in an @Before method,
|
||||
// but junit doesn't let @Before methods have test names
|
||||
solrHome = new File(TEMP_DIR, this.getClass().getName() + "_" + dirSuffix);
|
||||
assertTrue("Failed to mkdirs solrhome", solrHome.mkdirs());
|
||||
cc = new CoreContainer(solrHome.getAbsolutePath());
|
||||
assertTrue("Failed to mkdirs solrhome [" + solrHome + "]", solrHome.mkdirs());
|
||||
}
|
||||
|
||||
@After
|
||||
|
@ -68,7 +61,7 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
|||
Map<String,Exception> failures = null;
|
||||
Collection<String> cores = null;
|
||||
Exception fail = null;
|
||||
|
||||
|
||||
init("empty_flow");
|
||||
|
||||
// solr.xml
|
||||
|
@ -77,7 +70,8 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
|||
|
||||
// ----
|
||||
// init the CoreContainer
|
||||
cc.load(solrHome.getAbsolutePath(), solrXml);
|
||||
cc = new CoreContainer(solrHome.getAbsolutePath());
|
||||
cc.load();
|
||||
|
||||
// check that we have the cores we expect
|
||||
cores = cc.getCoreNames();
|
||||
|
@ -154,18 +148,19 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
|||
FileUtils.getFile(solrHome, "col_ok", "conf", "solrconfig.xml"));
|
||||
FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),
|
||||
FileUtils.getFile(solrHome, "col_ok", "conf", "schema.xml"));
|
||||
|
||||
|
||||
// our "bad" collection
|
||||
ignoreException(Pattern.quote("DummyMergePolicy"));
|
||||
FileUtils.copyFile(getFile("solr/collection1/conf/bad-mp-solrconfig.xml"),
|
||||
FileUtils.getFile(solrHome, "col_bad", "conf", "solrconfig.xml"));
|
||||
FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),
|
||||
FileUtils.getFile(solrHome, "col_bad", "conf", "schema.xml"));
|
||||
|
||||
|
||||
|
||||
|
||||
// -----
|
||||
// init the CoreContainer with the mix of ok/bad cores
|
||||
cc.load(solrHome.getAbsolutePath(), solrXml);
|
||||
cc = new CoreContainer(solrHome.getAbsolutePath());
|
||||
cc.load();
|
||||
|
||||
// check that we have the cores we expect
|
||||
cores = cc.getCoreNames();
|
||||
|
@ -293,8 +288,8 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
|||
fail("corrupt solrconfig.xml failed to trigger exception from reload");
|
||||
} catch (SolrException e) {
|
||||
assertTrue("We're supposed to have a wrapped SAXParserException here, but we don't",
|
||||
e.getCause() instanceof SAXParseException);
|
||||
SAXParseException se = (SAXParseException)e.getCause();
|
||||
e.getCause().getCause() instanceof SAXParseException);
|
||||
SAXParseException se = (SAXParseException)e.getCause().getCause();
|
||||
assertTrue("reload exception doesn't refer to slrconfig.xml " + se.getSystemId(),
|
||||
0 < se.getSystemId().indexOf("solrconfig.xml"));
|
||||
|
||||
|
@ -318,9 +313,9 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
|||
fail = failures.get("col_bad");
|
||||
assertNotNull("null failure for test core", fail);
|
||||
assertTrue("init failure isn't SAXParseException",
|
||||
fail instanceof SAXParseException);
|
||||
fail.getCause() instanceof SAXParseException);
|
||||
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
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
public class SolrCoreCheckLockOnStartupTest extends SolrTestCaseJ4 {
|
||||
|
||||
|
@ -62,13 +63,9 @@ public class SolrCoreCheckLockOnStartupTest extends SolrTestCaseJ4 {
|
|||
try {
|
||||
//opening a new core on the same index
|
||||
initCore("solrconfig-simplelock.xml", "schema.xml");
|
||||
if (checkForCoreInitException(LockObtainFailedException.class))
|
||||
return;
|
||||
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 {
|
||||
indexWriter.close();
|
||||
directory.close();
|
||||
|
@ -79,24 +76,33 @@ public class SolrCoreCheckLockOnStartupTest extends SolrTestCaseJ4 {
|
|||
@Test
|
||||
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
|
||||
IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(Version.LUCENE_40, null));
|
||||
|
||||
try {
|
||||
//opening a new core on the same index
|
||||
initCore("solrconfig-nativelock.xml", "schema.xml");
|
||||
CoreContainer cc = h.getCoreContainer();
|
||||
if (checkForCoreInitException(LockObtainFailedException.class))
|
||||
return;
|
||||
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 {
|
||||
indexWriter.close();
|
||||
directory.close();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,16 @@
|
|||
|
||||
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.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -27,17 +37,6 @@ import java.util.List;
|
|||
import java.util.jar.JarEntry;
|
||||
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 {
|
||||
|
||||
private static String oldSolrHome;
|
||||
|
@ -72,7 +71,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
|||
FileUtils.copyDirectory(new File(SolrTestCaseJ4.TEST_HOME()), solrHomeDirectory);
|
||||
|
||||
CoreContainer ret = new CoreContainer(solrHomeDirectory.getAbsolutePath());
|
||||
ret.load(solrHomeDirectory.getAbsolutePath(), new File(solrHomeDirectory, "solr.xml"));
|
||||
ret.load();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -161,13 +160,13 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
|||
SolrCore template = null;
|
||||
try {
|
||||
template = cores.getCore("collection1");
|
||||
instDir = template.getCoreDescriptor().getInstanceDir();
|
||||
instDir = template.getCoreDescriptor().getRawInstanceDir();
|
||||
} finally {
|
||||
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());
|
||||
|
||||
// sanity check the basic persistence of the default init
|
||||
|
@ -262,14 +261,8 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
|||
File solrHomeDirectory = new File(TEMP_DIR, this.getClass().getName()
|
||||
+ "_noCores");
|
||||
SetUpHome(solrHomeDirectory, EMPTY_SOLR_XML);
|
||||
CoreContainer.Initializer init = new CoreContainer.Initializer();
|
||||
CoreContainer cores = null;
|
||||
try {
|
||||
cores = init.initialize();
|
||||
}
|
||||
catch(Exception e) {
|
||||
fail("CoreContainer not created" + e.getMessage());
|
||||
}
|
||||
CoreContainer cores = new CoreContainer(solrHomeDirectory.getAbsolutePath());
|
||||
cores.load();
|
||||
try {
|
||||
//assert zero cores
|
||||
assertEquals("There should not be cores", 0, cores.getCores().size());
|
||||
|
@ -362,24 +355,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, "custom-lib-solr.xml"), "<solr sharedLib=\"customLib\"><cores/></solr>", "UTF-8");
|
||||
|
||||
final CoreContainer cc1 = new CoreContainer(tmpRoot.getAbsolutePath());
|
||||
cc1.load(tmpRoot.getAbsolutePath(), new File(tmpRoot, "default-lib-solr.xml"));
|
||||
final CoreContainer cc1 = CoreContainer.createAndLoad(tmpRoot.getAbsolutePath(), new File(tmpRoot, "default-lib-solr.xml"));
|
||||
try {
|
||||
cc1.loader.openResource("defaultSharedLibFile").close();
|
||||
} finally {
|
||||
cc1.shutdown();
|
||||
}
|
||||
|
||||
final CoreContainer cc2 = new CoreContainer(tmpRoot.getAbsolutePath());
|
||||
cc2.load(tmpRoot.getAbsolutePath(), new File(tmpRoot, "explicit-lib-solr.xml"));
|
||||
final CoreContainer cc2 = CoreContainer.createAndLoad(tmpRoot.getAbsolutePath(), new File(tmpRoot, "explicit-lib-solr.xml"));
|
||||
try {
|
||||
cc2.loader.openResource("defaultSharedLibFile").close();
|
||||
} finally {
|
||||
cc2.shutdown();
|
||||
}
|
||||
|
||||
final CoreContainer cc3 = new CoreContainer(tmpRoot.getAbsolutePath());
|
||||
cc3.load(tmpRoot.getAbsolutePath(), new File(tmpRoot, "custom-lib-solr.xml"));
|
||||
final CoreContainer cc3 = CoreContainer.createAndLoad(tmpRoot.getAbsolutePath(), new File(tmpRoot, "custom-lib-solr.xml"));
|
||||
try {
|
||||
cc3.loader.openResource("customSharedLibFile").close();
|
||||
} finally {
|
||||
|
|
|
@ -17,10 +17,6 @@ package org.apache.solr.core;
|
|||
* 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.lucene.util.IOUtils;
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
|
@ -29,6 +25,10 @@ import org.junit.After;
|
|||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
public class TestCoreDiscovery extends SolrTestCaseJ4 {
|
||||
|
||||
@BeforeClass
|
||||
|
@ -106,11 +106,8 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
|
|||
}
|
||||
|
||||
private CoreContainer init() throws Exception {
|
||||
|
||||
CoreContainer.Initializer init = new CoreContainer.Initializer();
|
||||
|
||||
final CoreContainer cores = init.initialize();
|
||||
cores.setPersistent(false);
|
||||
final CoreContainer cores = new CoreContainer();
|
||||
cores.load();
|
||||
return cores;
|
||||
}
|
||||
|
||||
|
@ -183,10 +180,12 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
|
|||
cc = init();
|
||||
fail("Should have thrown exception in testDuplicateNames");
|
||||
} catch (SolrException se) {
|
||||
Throwable cause = se.getCause();
|
||||
String message = cause.getMessage();
|
||||
assertTrue("Should have seen an exception because two cores had the same name",
|
||||
"Core + desc.getName() + \" defined twice".indexOf(se.getMessage()) != -1);
|
||||
assertTrue("/core1 should have been mentioned in the message", "/core1".indexOf(se.getMessage()) != -1);
|
||||
assertTrue("/core2 should have been mentioned in the message", "/core2".indexOf(se.getMessage()) != -1);
|
||||
message.indexOf("Core core1 defined more than once") != -1);
|
||||
assertTrue("/core1 should have been mentioned in the message", message.indexOf("/core1") != -1);
|
||||
assertTrue("/core2 should have been mentioned in the message", message.indexOf("/core2") != -1);
|
||||
} finally {
|
||||
if (cc != null) {
|
||||
cc.shutdown();
|
||||
|
|
|
@ -66,7 +66,7 @@ public class TestLazyCores extends SolrTestCaseJ4 {
|
|||
File solrXml = new File(solrHomeDirectory, "solr.xml");
|
||||
FileUtils.write(solrXml, LOTS_SOLR_XML, IOUtils.CHARSET_UTF_8.toString());
|
||||
final CoreContainer cores = new CoreContainer(solrHomeDirectory.getAbsolutePath());
|
||||
cores.load(solrHomeDirectory.getAbsolutePath(), solrXml);
|
||||
cores.load();
|
||||
// h.getCoreContainer().load(solrHomeDirectory.getAbsolutePath(), new File(solrHomeDirectory, "solr.xml"));
|
||||
|
||||
cores.setPersistent(false);
|
||||
|
|
|
@ -29,8 +29,7 @@ import java.io.File;
|
|||
public class TestShardHandlerFactory extends SolrTestCaseJ4 {
|
||||
|
||||
public void testXML() throws Exception {
|
||||
CoreContainer cc = new CoreContainer(TEST_HOME());
|
||||
cc.load(TEST_HOME(), new File(TEST_HOME(), "solr-shardhandler.xml"));
|
||||
CoreContainer cc = CoreContainer.createAndLoad(TEST_HOME(), new File(TEST_HOME(), "solr-shardhandler.xml"));
|
||||
ShardHandlerFactory factory = cc.getShardHandlerFactory();
|
||||
assertTrue(factory instanceof MockShardHandlerFactory);
|
||||
NamedList args = ((MockShardHandlerFactory)factory).args;
|
||||
|
|
|
@ -44,7 +44,7 @@ public class TestSolrXml extends SolrTestCaseJ4 {
|
|||
boolean oldStyle = (config.getNode("solr/cores", false) != null);
|
||||
ConfigSolr cfg;
|
||||
if (oldStyle) {
|
||||
cfg = new ConfigSolrXmlOld(config, cc);
|
||||
cfg = new ConfigSolrXmlOld(config);
|
||||
} else {
|
||||
cfg = new ConfigSolrXml(config, cc);
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ public class TestSolrXml extends SolrTestCaseJ4 {
|
|||
boolean oldStyle = (config.getNode("solr/cores", false) != null);
|
||||
ConfigSolr cfg;
|
||||
if (oldStyle) {
|
||||
cfg = new ConfigSolrXmlOld(config, cc);
|
||||
cfg = new ConfigSolrXmlOld(config);
|
||||
} else {
|
||||
cfg = new ConfigSolrXml(config, cc);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.apache.solr.SolrTestCaseJ4;
|
|||
import org.apache.solr.common.params.CoreAdminParams;
|
||||
import org.apache.solr.handler.admin.CoreAdminHandler;
|
||||
import org.apache.solr.response.SolrQueryResponse;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.RuleChain;
|
||||
|
@ -46,12 +45,14 @@ import java.util.List;
|
|||
|
||||
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
|
||||
public static void beforeClass() throws Exception {
|
||||
initCore("solrconfig-minimal.xml", "schema-tiny.xml");
|
||||
}
|
||||
*/
|
||||
|
||||
@Rule
|
||||
public TestRule solrTestRules =
|
||||
|
@ -59,9 +60,9 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
|
|||
|
||||
|
||||
private CoreContainer init(String solrXmlString, String... subDirs) throws Exception {
|
||||
if (solrHomeDirectory.exists()) {
|
||||
FileUtils.deleteDirectory(solrHomeDirectory);
|
||||
}
|
||||
|
||||
createTempDir();
|
||||
solrHomeDirectory = dataDir;
|
||||
|
||||
for (String s : subDirs) {
|
||||
copyMinConf(new File(solrHomeDirectory, s));
|
||||
|
@ -69,10 +70,8 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
|
|||
|
||||
File solrXml = new File(solrHomeDirectory, "solr.xml");
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -304,7 +303,7 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
|
|||
} else if (persistList[idx].contains("@config='solrconfig.xml'")) {
|
||||
expressions[idx] = persistList[idx].replace("solrconfig.xml", "${solrconfig:solrconfig.xml}");
|
||||
} else if (persistList[idx].contains("@instanceDir=")) {
|
||||
expressions[idx] = persistList[idx].replaceFirst("instanceDir\\='.*?'", "instanceDir='" + which + "'");
|
||||
expressions[idx] = persistList[idx].replaceFirst("instanceDir\\='.*?'", "instanceDir='" + which + "/'");
|
||||
} else {
|
||||
expressions[idx] = persistList[idx];
|
||||
}
|
||||
|
@ -611,14 +610,14 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
|
|||
" shareSchema=\"${shareSchema:false}\" distribUpdateConnTimeout=\"${distribUpdateConnTimeout:15000}\" \n" +
|
||||
" distribUpdateSoTimeout=\"${distribUpdateSoTimeout:120000}\" \n" +
|
||||
" leaderVoteWait=\"${leadVoteWait:32}\" managementPath=\"${manpath:/var/lib/path}\" transientCacheSize=\"${tranSize:128}\"> \n" +
|
||||
" <core name=\"SystemVars1\" instanceDir=\"SystemVars1\" shard=\"${shard:32}\" \n" +
|
||||
" <core name=\"SystemVars1\" instanceDir=\"SystemVars1/\" shard=\"${shard:32}\" \n" +
|
||||
" collection=\"${collection:collection1}\" config=\"${solrconfig:solrconfig.xml}\" \n" +
|
||||
" schema=\"${schema:schema.xml}\" ulogDir=\"${ulog:./}\" roles=\"${myrole:boss}\" \n" +
|
||||
" dataDir=\"${data:./}\" loadOnStartup=\"${onStart:true}\" transient=\"${tran:true}\" \n" +
|
||||
" coreNodeName=\"${coreNode:utterlyridiculous}\" \n" +
|
||||
" >\n" +
|
||||
" </core>\n" +
|
||||
" <core name=\"SystemVars2\" instanceDir=\"SystemVars2\" shard=\"${shard:32}\" \n" +
|
||||
" <core name=\"SystemVars2\" instanceDir=\"SystemVars2/\" shard=\"${shard:32}\" \n" +
|
||||
" collection=\"${collection:collection2}\" config=\"${solrconfig:solrconfig.xml}\" \n" +
|
||||
" coreNodeName=\"${coreNodeName:}\" schema=\"${schema:schema.xml}\">\n" +
|
||||
" <property name=\"collection\" value=\"{collection:collection2}\"/>\n" +
|
||||
|
@ -632,7 +631,7 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
|
|||
private static String SOLR_XML_MINIMAL =
|
||||
"<solr >\n" +
|
||||
" <cores> \n" +
|
||||
" <core name=\"SystemVars1\" instanceDir=\"SystemVars1\" />\n" +
|
||||
" <core name=\"SystemVars1\" instanceDir=\"SystemVars1/\" />\n" +
|
||||
" </cores>\n" +
|
||||
"</solr>";
|
||||
|
||||
|
|
|
@ -17,15 +17,22 @@
|
|||
|
||||
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.common.params.CommonParams;
|
||||
import org.apache.solr.logging.jul.JulInfo;
|
||||
import org.apache.solr.logging.log4j.Log4jInfo;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
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
|
||||
public static void beforeClass() throws Exception {
|
||||
|
@ -35,7 +42,8 @@ public class LoggingHandlerTest extends SolrTestCaseJ4 {
|
|||
@Test
|
||||
public void testLogLevelHandlerOutput() throws Exception {
|
||||
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",
|
||||
req(CommonParams.QT,"/admin/logging")
|
||||
|
@ -46,8 +54,8 @@ public class LoggingHandlerTest extends SolrTestCaseJ4 {
|
|||
assertQ("Set and remove a level",
|
||||
req(CommonParams.QT,"/admin/logging",
|
||||
"set", "org.xxx.yyy.abc:null",
|
||||
"set", "org.xxx.yyy.zzz:FINEST")
|
||||
,"//arr[@name='loggers']/lst/str[.='org.xxx.yyy.zzz']/../str[@name='level'][.='FINEST']"
|
||||
"set", "org.xxx.yyy.zzz:TRACE")
|
||||
,"//arr[@name='loggers']/lst/str[.='org.xxx.yyy.zzz']/../str[@name='level'][.='TRACE']"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,17 +17,18 @@
|
|||
|
||||
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.request.SolrQueryRequest;
|
||||
import org.apache.solr.schema.IndexSchema;
|
||||
import org.apache.solr.util.AbstractSolrTestCase;
|
||||
import org.apache.solr.util.TestHarness;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
|
||||
/**
|
||||
* :TODO: currently only tests some of the utilities in the LukeRequestHandler
|
||||
*/
|
||||
|
@ -156,7 +157,7 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase {
|
|||
try {
|
||||
// First, determine that the two fields ARE there
|
||||
String response = h.query(req);
|
||||
assertNull(h.validateXPath(response,
|
||||
assertNull(TestHarness.validateXPath(response,
|
||||
getFieldXPathPrefix("solr_t") + "[@name='index']",
|
||||
getFieldXPathPrefix("solr_s") + "[@name='index']"
|
||||
));
|
||||
|
@ -165,7 +166,7 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase {
|
|||
for (String f : Arrays.asList("solr_ti",
|
||||
"solr_td", "solr_pl", "solr_dt", "solr_b")) {
|
||||
|
||||
assertNotNull(h.validateXPath(response,
|
||||
assertNotNull(TestHarness.validateXPath(response,
|
||||
getFieldXPathPrefix(f) + "[@name='index']"));
|
||||
|
||||
}
|
||||
|
@ -175,7 +176,7 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase {
|
|||
for (String f : Arrays.asList("solr_t", "solr_s", "solr_ti",
|
||||
"solr_td", "solr_pl", "solr_dt", "solr_b")) {
|
||||
|
||||
assertNull(h.validateXPath(response,
|
||||
assertNull(TestHarness.validateXPath(response,
|
||||
getFieldXPathPrefix(f) + "[@name='index']"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -187,7 +188,7 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase {
|
|||
SolrQueryRequest req = req("qt", "/admin/luke", "show", "schema");
|
||||
|
||||
String xml = h.query(req);
|
||||
String r = h.validateXPath
|
||||
String r = TestHarness.validateXPath
|
||||
(xml,
|
||||
field("text") + "/arr[@name='copySources']/str[.='title']",
|
||||
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");
|
||||
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);
|
||||
|
||||
// Put back the configuration expected by the rest of the tests in this suite
|
||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.solr.handler.component;
|
|||
*/
|
||||
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.common.SolrException;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -34,14 +33,7 @@ public class BadComponentTest extends SolrTestCaseJ4{
|
|||
ignoreException(".*QueryElevationComponent.*");
|
||||
System.setProperty("elevate.file", "foo.xml");
|
||||
initCore("solrconfig-elevate.xml", "schema12.xml");
|
||||
assertTrue(false);
|
||||
} catch (RuntimeException e) {
|
||||
//TODO: better way of checking this?
|
||||
if (e.getCause() instanceof SolrException){
|
||||
assertTrue(true);
|
||||
} else {
|
||||
assertTrue(false);
|
||||
}
|
||||
assertTrue(hasInitException("QueryElevationComponent"));
|
||||
} finally {
|
||||
System.clearProperty("elevate.file");
|
||||
resetExceptionIgnores();
|
||||
|
|
|
@ -17,10 +17,6 @@
|
|||
|
||||
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.client.solrj.request.AbstractUpdateRequest;
|
||||
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.SolrCore;
|
||||
import org.apache.solr.util.ExternalPaths;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Abstract base class for testing merge indexes command
|
||||
*
|
||||
|
@ -42,7 +41,8 @@ import org.junit.BeforeClass;
|
|||
*
|
||||
*/
|
||||
public abstract class MergeIndexesExampleTestBase extends SolrExampleTestBase {
|
||||
protected static CoreContainer cores;
|
||||
|
||||
protected CoreContainer cores;
|
||||
private String saveProp;
|
||||
private File dataDir2;
|
||||
|
||||
|
@ -56,13 +56,11 @@ public abstract class MergeIndexesExampleTestBase extends SolrExampleTestBase {
|
|||
if (dataDir == null) {
|
||||
createTempDir();
|
||||
}
|
||||
cores = new CoreContainer();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
cores.shutdown();
|
||||
cores = null;
|
||||
|
||||
protected void setupCoreContainer() {
|
||||
cores = new CoreContainer();
|
||||
cores.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -71,6 +69,8 @@ public abstract class MergeIndexesExampleTestBase extends SolrExampleTestBase {
|
|||
System.setProperty("solr.directoryFactory", "solr.StandardDirectoryFactory");
|
||||
super.setUp();
|
||||
|
||||
setupCoreContainer();
|
||||
|
||||
SolrCore.log.info("CORES=" + cores + " : " + cores.getCoreNames());
|
||||
cores.setPersistent(false);
|
||||
|
||||
|
@ -96,6 +96,8 @@ public abstract class MergeIndexesExampleTestBase extends SolrExampleTestBase {
|
|||
System.err.println("!!!! WARNING: best effort to remove " + dataDir2.getAbsolutePath() + " FAILED !!!!!");
|
||||
}
|
||||
}
|
||||
|
||||
cores.shutdown();
|
||||
|
||||
if (saveProp == null) System.clearProperty("solr.directoryFactory");
|
||||
else System.setProperty("solr.directoryFactory", saveProp);
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
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.CoreAdminRequest;
|
||||
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.SolrCore;
|
||||
import org.apache.solr.util.ExternalPaths;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -41,27 +39,23 @@ import org.junit.Test;
|
|||
*/
|
||||
public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
|
||||
{
|
||||
protected static CoreContainer cores;
|
||||
protected CoreContainer cores;
|
||||
|
||||
private File dataDir2;
|
||||
private File dataDir1;
|
||||
|
||||
@Override public String getSolrHome() { return ExternalPaths.EXAMPLE_MULTICORE_HOME; }
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeThisClass2() throws Exception {
|
||||
protected void setupCoreContainer() {
|
||||
cores = new CoreContainer();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
cores.shutdown();
|
||||
cores.load();
|
||||
}
|
||||
|
||||
@Override public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
setupCoreContainer();
|
||||
|
||||
SolrCore.log.info("CORES=" + cores + " : " + cores.getCoreNames());
|
||||
cores.setPersistent(false);
|
||||
|
||||
|
@ -89,6 +83,8 @@ public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
|
|||
System.err.println("!!!! WARNING: best effort to remove " + dataDir2.getAbsolutePath() + " FAILED !!!!!");
|
||||
}
|
||||
}
|
||||
|
||||
cores.shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -61,7 +61,7 @@ public abstract class AbstractEmbeddedSolrServerTestCase extends LuceneTestCase
|
|||
System.setProperty("dataDir2", dataDir2.getAbsolutePath());
|
||||
System.setProperty("tempDir", tempDir.getAbsolutePath());
|
||||
System.setProperty("tests.shardhandler.randomSeed", Long.toString(random().nextLong()));
|
||||
cores = new CoreContainer(SOLR_HOME.getAbsolutePath(), getSolrXml());
|
||||
cores = CoreContainer.createAndLoad(SOLR_HOME.getAbsolutePath(), getSolrXml());
|
||||
}
|
||||
|
||||
protected abstract File getSolrXml() throws Exception;
|
||||
|
|
|
@ -17,10 +17,9 @@
|
|||
|
||||
package org.apache.solr.client.solrj.embedded;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.solr.client.solrj.MergeIndexesExampleTestBase;
|
||||
import org.apache.solr.client.solrj.SolrServer;
|
||||
import org.apache.solr.core.CoreContainer;
|
||||
import org.apache.solr.core.SolrCore;
|
||||
|
||||
/**
|
||||
|
@ -36,10 +35,12 @@ public class MergeIndexesEmbeddedTest extends MergeIndexesExampleTestBase {
|
|||
// TODO: fix this test to use MockDirectoryFactory
|
||||
System.clearProperty("solr.directoryFactory");
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
File home = new File(getSolrHome());
|
||||
File f = new File(home, "solr.xml");
|
||||
cores.load(getSolrHome(), f);
|
||||
@Override
|
||||
protected void setupCoreContainer() {
|
||||
cores = new CoreContainer(getSolrHome());
|
||||
cores.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,10 +17,9 @@
|
|||
|
||||
package org.apache.solr.client.solrj.embedded;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.solr.client.solrj.MultiCoreExampleTestBase;
|
||||
import org.apache.solr.client.solrj.SolrServer;
|
||||
import org.apache.solr.core.CoreContainer;
|
||||
|
||||
/**
|
||||
* This runs SolrServer test using
|
||||
|
@ -35,10 +34,11 @@ public class MultiCoreEmbeddedTest extends MultiCoreExampleTestBase {
|
|||
// TODO: fix this test to use MockDirectoryFactory
|
||||
System.clearProperty("solr.directoryFactory");
|
||||
super.setUp();
|
||||
|
||||
File home = new File( getSolrHome() );
|
||||
File f = new File( home, "solr.xml" );
|
||||
cores.load( getSolrHome(), f );
|
||||
}
|
||||
|
||||
protected void setupCoreContainer() {
|
||||
cores = new CoreContainer(getSolrHome());
|
||||
cores.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,20 +17,15 @@
|
|||
|
||||
package org.apache.solr.client.solrj.embedded;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.xpath.*;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.client.solrj.SolrQuery;
|
||||
import org.apache.solr.client.solrj.SolrServer;
|
||||
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.common.SolrInputDocument;
|
||||
import org.apache.solr.core.CoreContainer;
|
||||
|
@ -46,7 +41,15 @@ import org.slf4j.LoggerFactory;
|
|||
import org.w3c.dom.Document;
|
||||
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.InputStreamReader;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -258,7 +261,7 @@ public class TestSolrProperties extends AbstractEmbeddedSolrServerTestCase {
|
|||
// System.out.println("xml:" + solrPersistXml);
|
||||
// fis.close();
|
||||
|
||||
cores = new CoreContainer(SOLR_HOME.getAbsolutePath(), new File(tempDir, SOLR_PERSIST_XML));
|
||||
cores = CoreContainer.createAndLoad(SOLR_HOME.getAbsolutePath(), new File(tempDir, SOLR_PERSIST_XML));
|
||||
|
||||
mcr = CoreAdminRequest.persist(SOLR_PERSIST_XML, getRenamedSolrAdmin());
|
||||
|
||||
|
|
|
@ -17,26 +17,28 @@
|
|||
|
||||
package org.apache.solr;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.RandomizedContext;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
|
||||
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.lucene.util.Constants;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.lucene.util.QuickPatchThreadsFilter;
|
||||
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.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.core.CoreContainer;
|
||||
import org.apache.solr.core.SolrConfig;
|
||||
import org.apache.solr.core.SolrCore;
|
||||
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.SchemaField;
|
||||
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.RevertDefaultThreadHandlerRule;
|
||||
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.TestRule;
|
||||
import org.noggit.CharArr;
|
||||
|
@ -54,9 +59,22 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.RandomizedContext;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
|
||||
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.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
|
||||
|
@ -403,6 +421,29 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
|||
("standard",0,20,CommonParams.VERSION,"2.2");
|
||||
}
|
||||
|
||||
public static CoreContainer createCoreContainer(String solrHome, String solrXML) {
|
||||
testSolrHome = checkNotNull(solrHome);
|
||||
h = new TestHarness(solrHome, solrXML);
|
||||
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
|
||||
* to log the fact that their setUp process has ended.
|
||||
*/
|
||||
|
@ -1449,12 +1490,12 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
|||
return result;
|
||||
}
|
||||
|
||||
public void assertXmlFile(final File file, String... xpath)
|
||||
public static void assertXmlFile(final File file, String... xpath)
|
||||
throws IOException, SAXException {
|
||||
|
||||
try {
|
||||
String xml = FileUtils.readFileToString(file, "UTF-8");
|
||||
String results = h.validateXPath(xml, xpath);
|
||||
String results = TestHarness.validateXPath(xml, xpath);
|
||||
if (null != results) {
|
||||
String msg = "File XPath failure: file=" + file.getPath() + " xpath="
|
||||
+ results + "\n\nxml was: " + xml;
|
||||
|
|
|
@ -33,10 +33,10 @@ import java.io.StringWriter;
|
|||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
abstract public class BaseTestHarness {
|
||||
private final ThreadLocal<DocumentBuilder> builderTL = new ThreadLocal<DocumentBuilder>();
|
||||
private final ThreadLocal<XPath> xpathTL = new ThreadLocal<XPath>();
|
||||
private static final ThreadLocal<DocumentBuilder> builderTL = new ThreadLocal<DocumentBuilder>();
|
||||
private static final ThreadLocal<XPath> xpathTL = new ThreadLocal<XPath>();
|
||||
|
||||
public DocumentBuilder getXmlDocumentBuilder() {
|
||||
public static DocumentBuilder getXmlDocumentBuilder() {
|
||||
try {
|
||||
DocumentBuilder builder = builderTL.get();
|
||||
if (builder == null) {
|
||||
|
@ -49,7 +49,7 @@ abstract public class BaseTestHarness {
|
|||
}
|
||||
}
|
||||
|
||||
public XPath getXpath() {
|
||||
public static XPath getXpath() {
|
||||
try {
|
||||
XPath xpath = xpathTL.get();
|
||||
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
|
||||
* @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 {
|
||||
|
||||
if (tests==null || tests.length == 0) return null;
|
||||
|
|
|
@ -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) {
|
||||
String msg = "REQUEST FAILED: xpath=" + results
|
||||
|
|
|
@ -17,20 +17,17 @@
|
|||
|
||||
package org.apache.solr.util;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import org.apache.solr.common.SolrException;
|
||||
import org.apache.solr.common.params.CommonParams;
|
||||
import org.apache.solr.common.util.NamedList;
|
||||
import org.apache.solr.core.Config;
|
||||
import org.apache.solr.core.ConfigSolrXmlOld;
|
||||
import org.apache.solr.common.util.NamedList.NamedListEntry;
|
||||
import org.apache.solr.core.ConfigSolr;
|
||||
import org.apache.solr.core.CoreContainer;
|
||||
import org.apache.solr.core.SolrConfig;
|
||||
import org.apache.solr.core.SolrCore;
|
||||
import org.apache.solr.core.CoreContainer;
|
||||
import org.apache.solr.core.CoreDescriptor;
|
||||
import org.apache.solr.core.SolrResourceLoader;
|
||||
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.SolrQueryRequest;
|
||||
import org.apache.solr.request.SolrRequestHandler;
|
||||
|
@ -40,9 +37,6 @@ import org.apache.solr.response.SolrQueryResponse;
|
|||
import org.apache.solr.schema.IndexSchema;
|
||||
import org.apache.solr.schema.IndexSchemaFactory;
|
||||
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.File;
|
||||
|
@ -51,8 +45,6 @@ import java.io.StringWriter;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
|
||||
/**
|
||||
* This class provides a simple harness that may be useful when
|
||||
|
@ -106,19 +98,8 @@ public class TestHarness extends BaseTestHarness {
|
|||
SolrConfig solrConfig,
|
||||
String schemaFile) {
|
||||
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 solrConfig solronfig instance
|
||||
|
@ -137,18 +118,26 @@ public class TestHarness extends BaseTestHarness {
|
|||
public TestHarness( String dataDirectory,
|
||||
SolrConfig solrConfig,
|
||||
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 instance
|
||||
* @param indexSchema schema instance
|
||||
*/
|
||||
public TestHarness(String coreName, String dataDir, SolrConfig solrConfig, IndexSchema indexSchema) {
|
||||
try {
|
||||
if (coreName == null)
|
||||
coreName = CoreContainer.DEFAULT_DEFAULT_CORE_NAME;
|
||||
|
||||
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.init( null );
|
||||
} catch (Exception e) {
|
||||
|
@ -156,72 +145,46 @@ public class TestHarness extends BaseTestHarness {
|
|||
}
|
||||
}
|
||||
|
||||
// Creates a container based on infos needed to create one core
|
||||
static class Initializer extends CoreContainer.Initializer {
|
||||
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", 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());
|
||||
dcore.setConfigName(solrConfig.getResourceName());
|
||||
dcore.setSchemaName(indexSchema.getResourceName());
|
||||
|
||||
if (container.getZkController() != null) {
|
||||
container.preRegisterInZk(dcore);
|
||||
}
|
||||
|
||||
SolrCore core = new SolrCore(coreName, dataDirectory, solrConfig, indexSchema, dcore);
|
||||
container.register(coreName, core, false);
|
||||
/**
|
||||
* Create a TestHarness using a specific solr home directory and solr xml
|
||||
* @param solrHome the solr home directory
|
||||
* @param solrXml a File pointing to a solr.xml configuration
|
||||
*/
|
||||
public TestHarness(String solrHome, String solrXml) {
|
||||
this(new SolrResourceLoader(solrHome),
|
||||
ConfigSolr.fromInputStream(null, new ByteArrayInputStream(solrXml.getBytes(Charsets.UTF_8))));
|
||||
}
|
||||
|
||||
// TODO: we should be exercising the *same* core container initialization code, not equivalent code!
|
||||
if (container.getZkController() == null && core.getUpdateHandler().getUpdateLog() != null) {
|
||||
// always kick off recovery if we are in standalone mode.
|
||||
core.getUpdateHandler().getUpdateLog().recoverFromLog();
|
||||
}
|
||||
return container;
|
||||
}
|
||||
/**
|
||||
* 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,
|
||||
SolrConfig solrConfig, IndexSchema 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.getResourceName()
|
||||
+ "\" schema=\"" + schema.getResourceName() + "\" 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() {
|
||||
|
|
Loading…
Reference in New Issue