mirror of https://github.com/apache/lucene.git
Revert 1496505
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1496564 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d6b40cc39a
commit
450534ff3a
|
@ -46,8 +46,6 @@ Other Changes
|
||||||
|
|
||||||
* SOLR-4792: Stop shipping a .war. (Robert Muir)
|
* SOLR-4792: Stop shipping a .war. (Robert Muir)
|
||||||
|
|
||||||
* SOLR-4948: Tidied up CoreContainer construction logic. (Alan Woodward)
|
|
||||||
|
|
||||||
================== 4.4.0 ==================
|
================== 4.4.0 ==================
|
||||||
|
|
||||||
Versions of Major Components
|
Versions of Major Components
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
package org.apache.solr.cloud;
|
package org.apache.solr.cloud;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
import org.apache.commons.cli.CommandLine;
|
import org.apache.commons.cli.CommandLine;
|
||||||
import org.apache.commons.cli.CommandLineParser;
|
import org.apache.commons.cli.CommandLineParser;
|
||||||
import org.apache.commons.cli.HelpFormatter;
|
import org.apache.commons.cli.HelpFormatter;
|
||||||
|
@ -8,19 +17,18 @@ import org.apache.commons.cli.OptionBuilder;
|
||||||
import org.apache.commons.cli.Options;
|
import org.apache.commons.cli.Options;
|
||||||
import org.apache.commons.cli.ParseException;
|
import org.apache.commons.cli.ParseException;
|
||||||
import org.apache.commons.cli.PosixParser;
|
import org.apache.commons.cli.PosixParser;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.solr.common.cloud.OnReconnect;
|
import org.apache.solr.common.cloud.OnReconnect;
|
||||||
import org.apache.solr.common.cloud.SolrZkClient;
|
import org.apache.solr.common.cloud.SolrZkClient;
|
||||||
|
import org.apache.solr.core.Config;
|
||||||
import org.apache.solr.core.ConfigSolr;
|
import org.apache.solr.core.ConfigSolr;
|
||||||
|
import org.apache.solr.core.ConfigSolrXml;
|
||||||
|
import org.apache.solr.core.ConfigSolrXmlOld;
|
||||||
import org.apache.solr.core.SolrResourceLoader;
|
import org.apache.solr.core.SolrResourceLoader;
|
||||||
import org.apache.zookeeper.KeeperException;
|
import org.apache.zookeeper.KeeperException;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.TimeoutException;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
@ -170,7 +178,25 @@ public class ZkCLI {
|
||||||
SolrResourceLoader loader = new SolrResourceLoader(solrHome);
|
SolrResourceLoader loader = new SolrResourceLoader(solrHome);
|
||||||
solrHome = loader.getInstanceDir();
|
solrHome = loader.getInstanceDir();
|
||||||
|
|
||||||
ConfigSolr cfg = ConfigSolr.fromSolrHome(solrHome);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if(!ZkController.checkChrootPath(zkServerAddress, true)) {
|
if(!ZkController.checkChrootPath(zkServerAddress, true)) {
|
||||||
System.out.println("A chroot was specified in zkHost but the znode doesn't exist. ");
|
System.out.println("A chroot was specified in zkHost but the znode doesn't exist. ");
|
||||||
|
|
|
@ -17,6 +17,28 @@ package org.apache.solr.cloud;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.solr.client.solrj.impl.HttpSolrServer;
|
import org.apache.solr.client.solrj.impl.HttpSolrServer;
|
||||||
import org.apache.solr.client.solrj.request.CoreAdminRequest.WaitForState;
|
import org.apache.solr.client.solrj.request.CoreAdminRequest.WaitForState;
|
||||||
|
@ -52,28 +74,6 @@ import org.apache.zookeeper.data.Stat;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.NetworkInterface;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.Future;
|
|
||||||
import java.util.concurrent.TimeoutException;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle ZooKeeper interactions.
|
* Handle ZooKeeper interactions.
|
||||||
*
|
*
|
||||||
|
|
|
@ -68,7 +68,6 @@ public class Config {
|
||||||
static final XPathFactory xpathFactory = XPathFactory.newInstance();
|
static final XPathFactory xpathFactory = XPathFactory.newInstance();
|
||||||
|
|
||||||
private final Document doc;
|
private final Document doc;
|
||||||
private final Document origDoc; // with unsubstituted properties
|
|
||||||
private final String prefix;
|
private final String prefix;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final SolrResourceLoader loader;
|
private final SolrResourceLoader loader;
|
||||||
|
@ -132,7 +131,6 @@ public class Config {
|
||||||
db.setErrorHandler(xmllog);
|
db.setErrorHandler(xmllog);
|
||||||
try {
|
try {
|
||||||
doc = db.parse(is);
|
doc = db.parse(is);
|
||||||
origDoc = copyDoc(doc);
|
|
||||||
} finally {
|
} finally {
|
||||||
// some XML parsers are broken and don't close the byte stream (but they should according to spec)
|
// some XML parsers are broken and don't close the byte stream (but they should according to spec)
|
||||||
IOUtils.closeQuietly(is.getByteStream());
|
IOUtils.closeQuietly(is.getByteStream());
|
||||||
|
@ -142,24 +140,19 @@ public class Config {
|
||||||
}
|
}
|
||||||
} catch (ParserConfigurationException e) {
|
} catch (ParserConfigurationException e) {
|
||||||
SolrException.log(log, "Exception during parsing file: " + name, e);
|
SolrException.log(log, "Exception during parsing file: " + name, e);
|
||||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
|
throw e;
|
||||||
} catch (SAXException e) {
|
} catch (SAXException e) {
|
||||||
SolrException.log(log, "Exception during parsing file: " + name, e);
|
SolrException.log(log, "Exception during parsing file: " + name, e);
|
||||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
|
throw e;
|
||||||
} catch (TransformerException e) {
|
} catch( SolrException e ){
|
||||||
SolrException.log(log, "Exception during parsing file: " + name, e);
|
SolrException.log(log,"Error in "+name,e);
|
||||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Config(SolrResourceLoader loader, String name, Document doc) {
|
public Config(SolrResourceLoader loader, String name, Document doc) {
|
||||||
this.prefix = null;
|
this.prefix = null;
|
||||||
this.doc = doc;
|
this.doc = doc;
|
||||||
try {
|
|
||||||
this.origDoc = copyDoc(doc);
|
|
||||||
} catch (TransformerException e) {
|
|
||||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
|
|
||||||
}
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.loader = loader;
|
this.loader = loader;
|
||||||
}
|
}
|
||||||
|
@ -448,9 +441,4 @@ public class Config {
|
||||||
|
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Config getOriginalConfig() {
|
|
||||||
return new Config(loader, null, origDoc);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,15 @@ package org.apache.solr.core;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import java.util.HashMap;
|
||||||
import org.apache.commons.io.IOUtils;
|
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 org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.util.DOMUtil;
|
import org.apache.solr.util.DOMUtil;
|
||||||
import org.apache.solr.util.PropertiesUtil;
|
import org.apache.solr.util.PropertiesUtil;
|
||||||
|
@ -26,77 +33,13 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
import org.xml.sax.InputSource;
|
|
||||||
|
|
||||||
import javax.xml.xpath.XPath;
|
|
||||||
import javax.xml.xpath.XPathConstants;
|
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
|
|
||||||
public abstract class ConfigSolr {
|
public abstract class ConfigSolr {
|
||||||
protected static Logger log = LoggerFactory.getLogger(ConfigSolr.class);
|
protected static Logger log = LoggerFactory.getLogger(ConfigSolr.class);
|
||||||
|
|
||||||
public final static String SOLR_XML_FILE = "solr.xml";
|
public final static String SOLR_XML_FILE = "solr.xml";
|
||||||
|
|
||||||
public static ConfigSolr fromFile(File configFile) {
|
|
||||||
log.info("Loading container configuration from {}", configFile.getAbsolutePath());
|
|
||||||
|
|
||||||
String solrHome = configFile.getParent();
|
|
||||||
SolrResourceLoader loader = new SolrResourceLoader(solrHome);
|
|
||||||
InputStream inputStream = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!configFile.exists()) {
|
|
||||||
log.info("{} does not exist, using default configuration", configFile.getAbsolutePath());
|
|
||||||
inputStream = new ByteArrayInputStream(ConfigSolrXmlOld.DEF_SOLR_XML.getBytes(Charsets.UTF_8));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
inputStream = new FileInputStream(configFile);
|
|
||||||
}
|
|
||||||
return fromInputStream(loader, inputStream);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
|
|
||||||
"Could not load SOLR configuration", e);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
IOUtils.closeQuietly(inputStream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConfigSolr fromString(SolrResourceLoader loader, String xml) {
|
|
||||||
return fromInputStream(loader, new ByteArrayInputStream(xml.getBytes(Charsets.UTF_8)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConfigSolr fromInputStream(SolrResourceLoader loader, InputStream is) {
|
|
||||||
try {
|
|
||||||
Config config = new Config(loader, null, new InputSource(is), null, false);
|
|
||||||
//config.substituteProperties();
|
|
||||||
return fromConfig(config);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConfigSolr fromSolrHome(String solrHome) {
|
|
||||||
return fromFile(new File(solrHome, SOLR_XML_FILE));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConfigSolr fromConfig(Config config) {
|
|
||||||
boolean oldStyle = (config.getNode("solr/cores", false) != null);
|
|
||||||
return oldStyle ? new ConfigSolrXmlOld(config)
|
|
||||||
: new ConfigSolrXml(config, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ugly for now, but we'll at least be able to centralize all of the differences between 4x and 5x.
|
// Ugly for now, but we'll at least be able to centralize all of the differences between 4x and 5x.
|
||||||
public static enum CfgProp {
|
public static enum CfgProp {
|
||||||
SOLR_ADMINHANDLER,
|
SOLR_ADMINHANDLER,
|
||||||
|
@ -135,11 +78,6 @@ public abstract class ConfigSolr {
|
||||||
public ConfigSolr(Config config) {
|
public ConfigSolr(Config config) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
// for extension & testing.
|
|
||||||
protected ConfigSolr() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Config getConfig() {
|
public Config getConfig() {
|
||||||
return config;
|
return config;
|
||||||
|
@ -186,8 +124,7 @@ public abstract class ConfigSolr {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
for (int i = 0; i < props.getLength(); i++) {
|
for (int i = 0; i < props.getLength(); i++) {
|
||||||
Node prop = props.item(i);
|
Node prop = props.item(i);
|
||||||
properties.setProperty(DOMUtil.getAttr(prop, "name"),
|
properties.setProperty(DOMUtil.getAttr(prop, "name"), DOMUtil.getAttr(prop, "value"));
|
||||||
PropertiesUtil.substituteProperty(DOMUtil.getAttr(prop, "value"), null));
|
|
||||||
}
|
}
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,12 +17,6 @@ package org.apache.solr.core;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.solr.common.SolrException;
|
|
||||||
import org.apache.solr.util.PropertiesUtil;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -33,6 +27,15 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.solr.common.SolrException;
|
||||||
|
import org.apache.solr.util.PropertiesUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -43,18 +46,15 @@ public class ConfigSolrXml extends ConfigSolr {
|
||||||
private SolrCoreDiscoverer solrCoreDiscoverer = new SolrCoreDiscoverer();
|
private SolrCoreDiscoverer solrCoreDiscoverer = new SolrCoreDiscoverer();
|
||||||
private final Map<String, CoreDescriptor> coreDescriptorMap;
|
private final Map<String, CoreDescriptor> coreDescriptorMap;
|
||||||
|
|
||||||
public ConfigSolrXml(Config config, CoreContainer container) {
|
public ConfigSolrXml(Config config, CoreContainer container)
|
||||||
|
throws ParserConfigurationException, IOException, SAXException {
|
||||||
super(config);
|
super(config);
|
||||||
try {
|
checkForIllegalConfig();
|
||||||
checkForIllegalConfig();
|
|
||||||
fillPropMap();
|
fillPropMap();
|
||||||
config.substituteProperties();
|
|
||||||
String coreRoot = get(CfgProp.SOLR_COREROOTDIRECTORY, (container == null ? config.getResourceLoader().getInstanceDir() : container.getSolrHome()));
|
String coreRoot = get(CfgProp.SOLR_COREROOTDIRECTORY, (container == null ? config.getResourceLoader().getInstanceDir() : container.getSolrHome()));
|
||||||
coreDescriptorMap = solrCoreDiscoverer.discover(container, new File(coreRoot));
|
coreDescriptorMap = solrCoreDiscoverer.discover(container, new File(coreRoot));
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkForIllegalConfig() throws IOException {
|
private void checkForIllegalConfig() throws IOException {
|
||||||
|
|
|
@ -17,17 +17,6 @@ package org.apache.solr.core;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.solr.common.SolrException;
|
|
||||||
import org.apache.solr.util.DOMUtil;
|
|
||||||
import org.apache.solr.util.PropertiesUtil;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.w3c.dom.NamedNodeMap;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
import javax.xml.xpath.XPathConstants;
|
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -39,6 +28,20 @@ import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.xpath.XPathConstants;
|
||||||
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
|
|
||||||
|
import org.apache.solr.common.SolrException;
|
||||||
|
import org.apache.solr.util.DOMUtil;
|
||||||
|
import org.apache.solr.util.PropertiesUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.w3c.dom.NamedNodeMap;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -48,20 +51,17 @@ public class ConfigSolrXmlOld extends ConfigSolr {
|
||||||
|
|
||||||
private NodeList coreNodes = null;
|
private NodeList coreNodes = null;
|
||||||
|
|
||||||
public ConfigSolrXmlOld(Config config) {
|
public ConfigSolrXmlOld(Config config, CoreContainer container)
|
||||||
|
throws ParserConfigurationException, IOException, SAXException {
|
||||||
|
|
||||||
super(config);
|
super(config);
|
||||||
try {
|
checkForIllegalConfig(container);
|
||||||
checkForIllegalConfig();
|
|
||||||
fillPropMap();
|
fillPropMap();
|
||||||
config.substituteProperties();
|
initCoreList(container);
|
||||||
initCoreList();
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkForIllegalConfig() throws IOException {
|
private void checkForIllegalConfig(CoreContainer container) throws IOException {
|
||||||
// Do sanity checks - we don't want to find new style
|
// Do sanity checks - we don't want to find new style
|
||||||
// config
|
// config
|
||||||
failIfFound("solr/str[@name='adminHandler']");
|
failIfFound("solr/str[@name='adminHandler']");
|
||||||
|
@ -154,7 +154,7 @@ public class ConfigSolrXmlOld extends ConfigSolr {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initCoreList() throws IOException {
|
private void initCoreList(CoreContainer container) throws IOException {
|
||||||
|
|
||||||
coreNodes = (NodeList) config.evaluate("solr/cores/core",
|
coreNodes = (NodeList) config.evaluate("solr/cores/core",
|
||||||
XPathConstants.NODESET);
|
XPathConstants.NODESET);
|
||||||
|
@ -219,7 +219,7 @@ public class ConfigSolrXmlOld extends ConfigSolr {
|
||||||
NamedNodeMap attributes = node.getAttributes();
|
NamedNodeMap attributes = node.getAttributes();
|
||||||
for (int i = 0; i < attributes.getLength(); i++) {
|
for (int i = 0; i < attributes.getLength(); i++) {
|
||||||
Node attribute = attributes.item(i);
|
Node attribute = attributes.item(i);
|
||||||
String val = PropertiesUtil.substituteProperty(attribute.getNodeValue(), null);
|
String val = attribute.getNodeValue();
|
||||||
if (CoreDescriptor.CORE_DATADIR.equals(attribute.getNodeName()) ||
|
if (CoreDescriptor.CORE_DATADIR.equals(attribute.getNodeName()) ||
|
||||||
CoreDescriptor.CORE_INSTDIR.equals(attribute.getNodeName())) {
|
CoreDescriptor.CORE_INSTDIR.equals(attribute.getNodeName())) {
|
||||||
if (val.indexOf('$') == -1) {
|
if (val.indexOf('$') == -1) {
|
||||||
|
@ -257,8 +257,7 @@ public class ConfigSolrXmlOld extends ConfigSolr {
|
||||||
Node node = coreNodes.item(idx);
|
Node node = coreNodes.item(idx);
|
||||||
if (coreName.equals(DOMUtil.getAttr(node, CoreDescriptor.CORE_NAME,
|
if (coreName.equals(DOMUtil.getAttr(node, CoreDescriptor.CORE_NAME,
|
||||||
null))) {
|
null))) {
|
||||||
String propVal = DOMUtil.getAttr(node, property, defaultVal);
|
return DOMUtil.getAttr(node, property, defaultVal);
|
||||||
return PropertiesUtil.substituteProperty(propVal, null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -287,16 +286,16 @@ public class ConfigSolrXmlOld extends ConfigSolr {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String DEF_SOLR_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
|
public static final String DEF_SOLR_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
|
||||||
+ "<solr persistent=\"false\">\n"
|
+ "<solr persistent=\"false\">\n"
|
||||||
+ " <cores adminPath=\"/admin/cores\" defaultCoreName=\""
|
+ " <cores adminPath=\"/admin/cores\" defaultCoreName=\""
|
||||||
+ CoreContainer.DEFAULT_DEFAULT_CORE_NAME
|
+ CoreContainer.DEFAULT_DEFAULT_CORE_NAME
|
||||||
+ "\""
|
+ "\""
|
||||||
+ " host=\"${host:}\" hostPort=\"${hostPort:}\" hostContext=\"${hostContext:}\" zkClientTimeout=\"${zkClientTimeout:15000}\""
|
+ " host=\"${host:}\" hostPort=\"${hostPort:}\" hostContext=\"${hostContext:}\" zkClientTimeout=\"${zkClientTimeout:15000}\""
|
||||||
+ ">\n"
|
+ ">\n"
|
||||||
+ " <core name=\""
|
+ " <core name=\""
|
||||||
+ CoreContainer.DEFAULT_DEFAULT_CORE_NAME
|
+ CoreContainer.DEFAULT_DEFAULT_CORE_NAME
|
||||||
+ "\" shard=\"${shard:}\" collection=\"${collection:}\" instanceDir=\"collection1\" />\n"
|
+ "\" shard=\"${shard:}\" collection=\"${collection:}\" instanceDir=\"collection1\" />\n"
|
||||||
+ " </cores>\n" + "</solr>";
|
+ " </cores>\n" + "</solr>";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void substituteProperties() {
|
public void substituteProperties() {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
package org.apache.solr.core;
|
package org.apache.solr.core;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.solr.cloud.ZkController;
|
import org.apache.solr.cloud.ZkController;
|
||||||
import org.apache.solr.cloud.ZkSolrResourceLoader;
|
import org.apache.solr.cloud.ZkSolrResourceLoader;
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
|
@ -38,10 +39,21 @@ import org.apache.solr.util.plugin.PluginInfoInitialized;
|
||||||
import org.apache.zookeeper.KeeperException;
|
import org.apache.zookeeper.KeeperException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
|
import javax.xml.transform.Transformer;
|
||||||
|
import javax.xml.transform.TransformerException;
|
||||||
|
import javax.xml.transform.TransformerFactory;
|
||||||
|
import javax.xml.transform.dom.DOMResult;
|
||||||
|
import javax.xml.transform.dom.DOMSource;
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -64,8 +76,6 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -94,13 +104,15 @@ public class CoreContainer
|
||||||
|
|
||||||
protected CoreAdminHandler coreAdminHandler = null;
|
protected CoreAdminHandler coreAdminHandler = null;
|
||||||
protected CollectionsHandler collectionsHandler = null;
|
protected CollectionsHandler collectionsHandler = null;
|
||||||
|
protected File configFile = null;
|
||||||
protected String libDir = null;
|
protected String libDir = null;
|
||||||
|
protected SolrResourceLoader loader = null;
|
||||||
protected Properties containerProperties;
|
protected Properties containerProperties;
|
||||||
protected Map<String ,IndexSchema> indexSchemaCache;
|
protected Map<String ,IndexSchema> indexSchemaCache;
|
||||||
protected String adminHandler;
|
protected String adminHandler;
|
||||||
protected boolean shareSchema;
|
protected boolean shareSchema;
|
||||||
protected Integer zkClientTimeout;
|
protected Integer zkClientTimeout;
|
||||||
|
protected String solrHome;
|
||||||
protected String defaultCoreName = null;
|
protected String defaultCoreName = null;
|
||||||
protected int distribUpdateConnTimeout = 0;
|
protected int distribUpdateConnTimeout = 0;
|
||||||
protected int distribUpdateSoTimeout = 0;
|
protected int distribUpdateSoTimeout = 0;
|
||||||
|
@ -114,90 +126,151 @@ public class CoreContainer
|
||||||
|
|
||||||
private int coreLoadThreads;
|
private int coreLoadThreads;
|
||||||
private CloserThread backgroundCloser = null;
|
private CloserThread backgroundCloser = null;
|
||||||
|
protected volatile ConfigSolr cfg;
|
||||||
protected final ConfigSolr cfg;
|
private Config origCfg;
|
||||||
protected final SolrResourceLoader loader;
|
|
||||||
protected final String solrHome;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
log.info("New CoreContainer " + System.identityHashCode(this));
|
log.info("New CoreContainer " + System.identityHashCode(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new CoreContainer using system properties to detect the solr home
|
* Deprecated
|
||||||
* directory. The container's cores are not loaded.
|
* @deprecated use the single arg constructor with locateSolrHome()
|
||||||
* @see #load()
|
* @see SolrResourceLoader#locateSolrHome
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public CoreContainer() {
|
public CoreContainer() {
|
||||||
this(SolrResourceLoader.locateSolrHome());
|
this(SolrResourceLoader.locateSolrHome());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new CoreContainer using the given SolrResourceLoader. The container's
|
* Initalize CoreContainer directly from the constructor
|
||||||
* cores are not loaded.
|
*/
|
||||||
* @param loader the SolrResourceLoader
|
public CoreContainer(String dir, File configFile) throws FileNotFoundException {
|
||||||
* @see #load()
|
this(dir);
|
||||||
|
this.load(dir, configFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minimal CoreContainer constructor.
|
||||||
|
* @param loader the CoreContainer resource loader
|
||||||
*/
|
*/
|
||||||
public CoreContainer(SolrResourceLoader loader) {
|
public CoreContainer(SolrResourceLoader loader) {
|
||||||
this(loader, ConfigSolr.fromSolrHome(loader.getInstanceDir()));
|
this(loader.getInstanceDir());
|
||||||
|
this.loader = 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(String solrHome) {
|
public CoreContainer(String solrHome) {
|
||||||
this(new SolrResourceLoader(solrHome), ConfigSolr.fromSolrHome(solrHome));
|
this.solrHome = solrHome;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new CoreContainer using the given SolrResourceLoader and
|
|
||||||
* configuration. The container's cores are not loaded.
|
|
||||||
* @param loader the SolrResourceLoader
|
|
||||||
* @param config a ConfigSolr representation of this container's configuration
|
|
||||||
* @see #load()
|
|
||||||
*/
|
|
||||||
public CoreContainer(SolrResourceLoader loader, ConfigSolr config) {
|
|
||||||
this.loader = checkNotNull(loader);
|
|
||||||
this.solrHome = loader.getInstanceDir();
|
|
||||||
this.cfg = checkNotNull(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new CoreContainer and load its cores
|
|
||||||
* @param solrHome the solr home directory
|
|
||||||
* @param configFile the file containing this container's configuration
|
|
||||||
* @return a loaded CoreContainer
|
|
||||||
*/
|
|
||||||
public static CoreContainer createAndLoad(String solrHome, File configFile) {
|
|
||||||
CoreContainer cc = new CoreContainer(new SolrResourceLoader(solrHome), ConfigSolr.fromFile(configFile));
|
|
||||||
cc.load();
|
|
||||||
return cc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Properties getContainerProperties() {
|
public Properties getContainerProperties() {
|
||||||
return containerProperties;
|
return containerProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper class to initialize the CoreContainer
|
||||||
|
public static class Initializer {
|
||||||
|
|
||||||
|
// core container instantiation
|
||||||
|
public CoreContainer initialize() throws FileNotFoundException {
|
||||||
|
CoreContainer cores = null;
|
||||||
|
String solrHome = SolrResourceLoader.locateSolrHome();
|
||||||
|
// ContainerConfigFilename could could be a properties file
|
||||||
|
File fconf = new File(solrHome, "solr.xml");
|
||||||
|
|
||||||
|
log.info("looking for solr config file: " + fconf.getAbsolutePath());
|
||||||
|
cores = new CoreContainer(solrHome);
|
||||||
|
|
||||||
|
// first we find zkhost, then we check for solr.xml in zk
|
||||||
|
// 1. look for zkhost from sys prop 2. look for zkhost in {solr.home}/solr.properties
|
||||||
|
|
||||||
|
// Either we have a config file or not.
|
||||||
|
|
||||||
|
if (fconf.exists()) {
|
||||||
|
cores.load(solrHome, fconf);
|
||||||
|
} else {
|
||||||
|
// Back compart support
|
||||||
|
log.info("no solr.xml found. using default old-style solr.xml");
|
||||||
|
try {
|
||||||
|
cores.load(solrHome, new ByteArrayInputStream(ConfigSolrXmlOld.DEF_SOLR_XML.getBytes("UTF-8")), null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new SolrException(ErrorCode.SERVER_ERROR,
|
||||||
|
"CoreContainer.Initialize failed when trying to load default solr.xml file", e);
|
||||||
|
}
|
||||||
|
cores.configFile = fconf;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cores;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Initialization / Cleanup
|
// Initialization / Cleanup
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a config file listing the available solr cores.
|
||||||
|
* @param dir the home directory of all resources.
|
||||||
|
* @param configFile the configuration file
|
||||||
|
*/
|
||||||
|
public void load(String dir, File configFile) throws FileNotFoundException {
|
||||||
|
this.configFile = configFile;
|
||||||
|
InputStream in = new FileInputStream(configFile);
|
||||||
|
try {
|
||||||
|
this.load(dir, in, configFile.getName());
|
||||||
|
} finally {
|
||||||
|
IOUtils.closeQuietly(in);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the cores defined for this CoreContainer
|
* 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
|
||||||
*/
|
*/
|
||||||
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;
|
ThreadPoolExecutor coreLoadExecutor = null;
|
||||||
|
if (null == dir) {
|
||||||
|
// don't rely on SolrResourceLoader(), determine explicitly first
|
||||||
|
dir = SolrResourceLoader.locateSolrHome();
|
||||||
|
}
|
||||||
|
log.info("Loading CoreContainer using Solr Home: '{}'", dir);
|
||||||
|
|
||||||
|
this.loader = new SolrResourceLoader(dir);
|
||||||
|
solrHome = loader.getInstanceDir();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Config config = new Config(loader, null, new InputSource(is), null, false);
|
||||||
|
|
||||||
|
// old style defines cores in solr.xml, new style disovers them by
|
||||||
|
// directory structure
|
||||||
|
boolean oldStyle = (config.getNode("solr/cores", false) != null);
|
||||||
|
|
||||||
|
if (oldStyle) {
|
||||||
|
// ConfigSolr handles keep orig values around for non solrcore level items,
|
||||||
|
// but this is still how original core lvl attributes are kept around
|
||||||
|
this.origCfg = new Config(loader, null, copyDoc(config.getDocument()));
|
||||||
|
|
||||||
|
this.cfg = new ConfigSolrXmlOld(config, this);
|
||||||
|
} else {
|
||||||
|
this.cfg = new ConfigSolrXml(config, this);
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new SolrException(ErrorCode.SERVER_ERROR, "", e);
|
||||||
|
}
|
||||||
|
// Since the cores var is now initialized to null, let's set it up right
|
||||||
|
// now.
|
||||||
|
cfg.substituteProperties();
|
||||||
|
|
||||||
// add the sharedLib to the shared resource loader before initializing cfg based plugins
|
// add the sharedLib to the shared resource loader before initializing cfg based plugins
|
||||||
libDir = cfg.get(ConfigSolr.CfgProp.SOLR_SHAREDLIB , null);
|
libDir = cfg.get(ConfigSolr.CfgProp.SOLR_SHAREDLIB , null);
|
||||||
if (libDir != null) {
|
if (libDir != null) {
|
||||||
File f = FileUtils.resolvePath(new File(solrHome), libDir);
|
File f = FileUtils.resolvePath(new File(dir), libDir);
|
||||||
log.info("loading shared library: " + f.getAbsolutePath());
|
log.info("loading shared library: " + f.getAbsolutePath());
|
||||||
loader.addToClassLoader(libDir, null, false);
|
loader.addToClassLoader(libDir, null, false);
|
||||||
loader.reloadLuceneSPI();
|
loader.reloadLuceneSPI();
|
||||||
|
@ -1003,7 +1076,7 @@ public class CoreContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getConfigFile() {
|
public File getConfigFile() {
|
||||||
return new File(solrHome, ConfigSolr.SOLR_XML_FILE);
|
return configFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1017,7 +1090,7 @@ public class CoreContainer
|
||||||
/** Persists the cores config file in cores.xml. */
|
/** Persists the cores config file in cores.xml. */
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void persist() {
|
public void persist() {
|
||||||
persistFile(getConfigFile());
|
persistFile(configFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1038,7 +1111,7 @@ public class CoreContainer
|
||||||
// only the old solrxml persists
|
// only the old solrxml persists
|
||||||
if (cfg != null && !(cfg instanceof ConfigSolrXmlOld)) return;
|
if (cfg != null && !(cfg instanceof ConfigSolrXmlOld)) return;
|
||||||
|
|
||||||
log.info("Persisting cores config to " + (file == null ? getConfigFile() : file));
|
log.info("Persisting cores config to " + (file == null ? configFile : file));
|
||||||
|
|
||||||
// <solr attrib="value">
|
// <solr attrib="value">
|
||||||
Map<String,String> rootSolrAttribs = new HashMap<String,String>();
|
Map<String,String> rootSolrAttribs = new HashMap<String,String>();
|
||||||
|
@ -1110,7 +1183,7 @@ public class CoreContainer
|
||||||
cfg.get(ConfigSolr.CfgProp.SOLR_SHARDHANDLERFACTORY_SOCKETTIMEOUT, null));
|
cfg.get(ConfigSolr.CfgProp.SOLR_SHARDHANDLERFACTORY_SOCKETTIMEOUT, null));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
solrCores.persistCores(cfg.config.getOriginalConfig(), containerProperties, rootSolrAttribs,coresAttribs,
|
solrCores.persistCores(origCfg, containerProperties, rootSolrAttribs,coresAttribs,
|
||||||
loggingAttribs, watcherAttribs, shardHandlerAttrib, shardHandlerProps, file, loader);
|
loggingAttribs, watcherAttribs, shardHandlerAttrib, shardHandlerProps, file, loader);
|
||||||
} catch (XPathExpressionException e) {
|
} catch (XPathExpressionException e) {
|
||||||
throw new SolrException(ErrorCode.SERVER_ERROR, null, e);
|
throw new SolrException(ErrorCode.SERVER_ERROR, null, e);
|
||||||
|
@ -1197,7 +1270,14 @@ public class CoreContainer
|
||||||
return solrCores.getCoreToOrigName(core);
|
return solrCores.getCoreToOrigName(core);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Document copyDoc(Document document) throws TransformerException {
|
||||||
|
TransformerFactory tfactory = TransformerFactory.newInstance();
|
||||||
|
Transformer tx = tfactory.newTransformer();
|
||||||
|
DOMSource source = new DOMSource(document);
|
||||||
|
DOMResult result = new DOMResult();
|
||||||
|
tx.transform(source,result);
|
||||||
|
return (Document)result.getNode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CloserThread extends Thread {
|
class CloserThread extends Thread {
|
||||||
|
|
|
@ -17,15 +17,6 @@ package org.apache.solr.core;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.apache.solr.cloud.CloudDescriptor;
|
|
||||||
import org.apache.solr.common.SolrException;
|
|
||||||
import org.apache.solr.common.params.CoreAdminParams;
|
|
||||||
import org.apache.solr.core.SolrXMLSerializer.SolrCoreXMLDef;
|
|
||||||
import org.apache.solr.util.DOMUtil;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
|
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -40,6 +31,16 @@ import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.solr.cloud.CloudDescriptor;
|
||||||
|
import org.apache.solr.common.SolrException;
|
||||||
|
import org.apache.solr.common.params.CoreAdminParams;
|
||||||
|
import org.apache.solr.core.SolrXMLSerializer.SolrCoreXMLDef;
|
||||||
|
import org.apache.solr.util.DOMUtil;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
|
||||||
|
|
||||||
class SolrCores {
|
class SolrCores {
|
||||||
private static SolrXMLSerializer SOLR_XML_SERIALIZER = new SolrXMLSerializer();
|
private static SolrXMLSerializer SOLR_XML_SERIALIZER = new SolrXMLSerializer();
|
||||||
|
@ -527,7 +528,7 @@ class SolrCores {
|
||||||
// Insure instdir is persisted if it's the default since it's checked at startup even if not specified on the
|
// Insure instdir is persisted if it's the default since it's checked at startup even if not specified on the
|
||||||
// create command.
|
// create command.
|
||||||
if (! dcore.getCreatedProperties().containsKey(CoreDescriptor.CORE_INSTDIR)) {
|
if (! dcore.getCreatedProperties().containsKey(CoreDescriptor.CORE_INSTDIR)) {
|
||||||
coreAttribs.put(CoreDescriptor.CORE_INSTDIR, dcore.getRawInstanceDir());
|
coreAttribs.put(CoreDescriptor.CORE_INSTDIR, dcore.getProperty(CoreDescriptor.CORE_INSTDIR));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -548,8 +549,8 @@ class SolrCores {
|
||||||
}
|
}
|
||||||
|
|
||||||
coreAttribs.put(CoreDescriptor.CORE_NAME, coreName);
|
coreAttribs.put(CoreDescriptor.CORE_NAME, coreName);
|
||||||
coreAttribs.put(CoreDescriptor.CORE_INSTDIR, dcore.getRawInstanceDir());
|
|
||||||
//addCoreProperty(coreAttribs, loader, node, CoreDescriptor.CORE_INSTDIR, dcore.getRawInstanceDir(), null);
|
addCoreProperty(coreAttribs, loader, node, CoreDescriptor.CORE_INSTDIR, dcore.getRawInstanceDir(), null);
|
||||||
|
|
||||||
addCoreProperty(coreAttribs, loader, node, CoreDescriptor.CORE_COLLECTION,
|
addCoreProperty(coreAttribs, loader, node, CoreDescriptor.CORE_COLLECTION,
|
||||||
StringUtils.isNotBlank(collection) ? collection : dcore.getName());
|
StringUtils.isNotBlank(collection) ? collection : dcore.getName());
|
||||||
|
|
|
@ -17,58 +17,56 @@
|
||||||
|
|
||||||
package org.apache.solr.core;
|
package org.apache.solr.core;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.util.CharFilterFactory;
|
|
||||||
import org.apache.lucene.analysis.util.ResourceLoaderAware;
|
|
||||||
import org.apache.lucene.analysis.util.TokenFilterFactory;
|
|
||||||
import org.apache.lucene.analysis.util.TokenizerFactory;
|
|
||||||
import org.apache.lucene.analysis.util.WordlistLoader;
|
|
||||||
import org.apache.lucene.codecs.Codec;
|
|
||||||
import org.apache.lucene.codecs.DocValuesFormat;
|
|
||||||
import org.apache.lucene.codecs.PostingsFormat;
|
|
||||||
import org.apache.lucene.util.IOUtils;
|
|
||||||
import org.apache.solr.common.ResourceLoader;
|
|
||||||
import org.apache.solr.common.SolrException;
|
|
||||||
import org.apache.solr.handler.admin.CoreAdminHandler;
|
|
||||||
import org.apache.solr.handler.component.SearchComponent;
|
|
||||||
import org.apache.solr.handler.component.ShardHandlerFactory;
|
|
||||||
import org.apache.solr.request.SolrRequestHandler;
|
|
||||||
import org.apache.solr.response.QueryResponseWriter;
|
|
||||||
import org.apache.solr.schema.FieldType;
|
|
||||||
import org.apache.solr.schema.ManagedIndexSchemaFactory;
|
|
||||||
import org.apache.solr.schema.SimilarityFactory;
|
|
||||||
import org.apache.solr.search.QParserPlugin;
|
|
||||||
import org.apache.solr.update.processor.UpdateRequestProcessorFactory;
|
|
||||||
import org.apache.solr.util.FileUtils;
|
|
||||||
import org.apache.solr.util.plugin.SolrCoreAware;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import javax.naming.Context;
|
|
||||||
import javax.naming.InitialContext;
|
|
||||||
import javax.naming.NamingException;
|
|
||||||
import javax.naming.NoInitialContextException;
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.nio.charset.CharacterCodingException;
|
import java.util.*;
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.apache.lucene.analysis.util.CharFilterFactory;
|
||||||
|
import org.apache.lucene.analysis.util.ResourceLoaderAware;
|
||||||
|
import org.apache.lucene.analysis.util.TokenFilterFactory;
|
||||||
|
import org.apache.lucene.analysis.util.TokenizerFactory;
|
||||||
|
import org.apache.lucene.codecs.Codec;
|
||||||
|
import org.apache.lucene.codecs.PostingsFormat;
|
||||||
|
import org.apache.lucene.codecs.DocValuesFormat;
|
||||||
|
import org.apache.lucene.util.IOUtils;
|
||||||
|
import org.apache.lucene.analysis.util.WordlistLoader;
|
||||||
|
import org.apache.solr.common.ResourceLoader;
|
||||||
|
import org.apache.solr.handler.admin.CoreAdminHandler;
|
||||||
|
import org.apache.solr.handler.component.ShardHandlerFactory;
|
||||||
|
import org.apache.solr.schema.ManagedIndexSchemaFactory;
|
||||||
|
import org.apache.solr.schema.SimilarityFactory;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.nio.charset.CharacterCodingException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
|
||||||
|
import javax.naming.Context;
|
||||||
|
import javax.naming.InitialContext;
|
||||||
|
import javax.naming.NamingException;
|
||||||
|
import javax.naming.NoInitialContextException;
|
||||||
|
|
||||||
|
import org.apache.solr.util.FileUtils;
|
||||||
|
import org.apache.solr.common.SolrException;
|
||||||
|
import org.apache.solr.handler.component.SearchComponent;
|
||||||
|
import org.apache.solr.request.SolrRequestHandler;
|
||||||
|
import org.apache.solr.response.QueryResponseWriter;
|
||||||
|
import org.apache.solr.schema.FieldType;
|
||||||
|
import org.apache.solr.update.processor.UpdateRequestProcessorFactory;
|
||||||
|
import org.apache.solr.util.plugin.SolrCoreAware;
|
||||||
|
import org.apache.solr.search.QParserPlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since solr 1.3
|
* @since solr 1.3
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -137,7 +137,7 @@ public abstract class LogWatcher<E> {
|
||||||
v.size = config.getInt(ConfigSolr.CfgProp.SOLR_LOGGING_WATCHER_SIZE, 50);
|
v.size = config.getInt(ConfigSolr.CfgProp.SOLR_LOGGING_WATCHER_SIZE, 50);
|
||||||
v.threshold = config.get(ConfigSolr.CfgProp.SOLR_LOGGING_WATCHER_THRESHOLD, null);
|
v.threshold = config.get(ConfigSolr.CfgProp.SOLR_LOGGING_WATCHER_THRESHOLD, null);
|
||||||
if (v.size > 0) {
|
if (v.size > 0) {
|
||||||
log.info("Registering Log Listener [{}]", logWatcher.getName());
|
log.info("Registering Log Listener");
|
||||||
logWatcher.registerListener(v);
|
logWatcher.registerListener(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,18 @@
|
||||||
|
|
||||||
package org.apache.solr.schema;
|
package org.apache.solr.schema;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.apache.lucene.analysis.util.AbstractAnalysisFactory.LUCENE_MATCH_VERSION_PARAM;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
import org.apache.lucene.analysis.Tokenizer;
|
import org.apache.lucene.analysis.Tokenizer;
|
||||||
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
|
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
|
||||||
|
@ -55,18 +67,6 @@ import org.apache.solr.search.Sorting;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static org.apache.lucene.analysis.util.AbstractAnalysisFactory.LUCENE_MATCH_VERSION_PARAM;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for all field types used by an index schema.
|
* Base class for all field types used by an index schema.
|
||||||
*
|
*
|
||||||
|
@ -799,15 +799,6 @@ public abstract class FieldType extends FieldProperties {
|
||||||
namedPropertyValues.add(getPropertyName(TOKENIZED), isTokenized());
|
namedPropertyValues.add(getPropertyName(TOKENIZED), isTokenized());
|
||||||
// The BINARY property is always false
|
// The BINARY property is always false
|
||||||
// namedPropertyValues.add(getPropertyName(BINARY), hasProperty(BINARY));
|
// namedPropertyValues.add(getPropertyName(BINARY), hasProperty(BINARY));
|
||||||
if (null != getSimilarityFactory()) {
|
|
||||||
namedPropertyValues.add(SIMILARITY, getSimilarityFactory().getNamedPropertyValues());
|
|
||||||
}
|
|
||||||
if (null != getPostingsFormat()) {
|
|
||||||
namedPropertyValues.add(POSTINGS_FORMAT, getPostingsFormat());
|
|
||||||
}
|
|
||||||
if (null != getDocValuesFormat()) {
|
|
||||||
namedPropertyValues.add(DOC_VALUES_FORMAT, getDocValuesFormat());
|
|
||||||
}
|
|
||||||
} else { // Don't show defaults
|
} else { // Don't show defaults
|
||||||
Set<String> fieldProperties = new HashSet<String>();
|
Set<String> fieldProperties = new HashSet<String>();
|
||||||
for (String propertyName : FieldProperties.propertyNames) {
|
for (String propertyName : FieldProperties.propertyNames) {
|
||||||
|
@ -835,7 +826,15 @@ public abstract class FieldType extends FieldProperties {
|
||||||
namedPropertyValues.add(MULTI_TERM_ANALYZER, getAnalyzerProperties(((TextField) this).getMultiTermAnalyzer()));
|
namedPropertyValues.add(MULTI_TERM_ANALYZER, getAnalyzerProperties(((TextField) this).getMultiTermAnalyzer()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (null != getSimilarityFactory()) {
|
||||||
|
namedPropertyValues.add(SIMILARITY, getSimilarityFactory().getNamedPropertyValues());
|
||||||
|
}
|
||||||
|
if (null != getPostingsFormat()) {
|
||||||
|
namedPropertyValues.add(POSTINGS_FORMAT, getPostingsFormat());
|
||||||
|
}
|
||||||
|
if (null != getDocValuesFormat()) {
|
||||||
|
namedPropertyValues.add(DOC_VALUES_FORMAT, getDocValuesFormat());
|
||||||
|
}
|
||||||
return namedPropertyValues;
|
return namedPropertyValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,35 @@
|
||||||
|
|
||||||
package org.apache.solr.servlet;
|
package org.apache.solr.servlet;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
|
import javax.servlet.Filter;
|
||||||
|
import javax.servlet.FilterChain;
|
||||||
|
import javax.servlet.FilterConfig;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
import javax.servlet.ServletResponse;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.common.SolrException.ErrorCode;
|
import org.apache.solr.common.SolrException.ErrorCode;
|
||||||
|
@ -52,34 +81,6 @@ import org.apache.solr.util.FastWriter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.servlet.Filter;
|
|
||||||
import javax.servlet.FilterChain;
|
|
||||||
import javax.servlet.FilterConfig;
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.ServletRequest;
|
|
||||||
import javax.servlet.ServletResponse;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.WeakHashMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This filter looks at the incoming URL maps them to handlers defined in solrconfig.xml
|
* This filter looks at the incoming URL maps them to handlers defined in solrconfig.xml
|
||||||
*
|
*
|
||||||
|
@ -115,11 +116,12 @@ public class SolrDispatchFilter implements Filter
|
||||||
{
|
{
|
||||||
log.info("SolrDispatchFilter.init()");
|
log.info("SolrDispatchFilter.init()");
|
||||||
|
|
||||||
|
CoreContainer.Initializer init = createInitializer();
|
||||||
try {
|
try {
|
||||||
// web.xml configuration
|
// web.xml configuration
|
||||||
this.pathPrefix = config.getInitParameter( "path-prefix" );
|
this.pathPrefix = config.getInitParameter( "path-prefix" );
|
||||||
|
|
||||||
this.cores = createCoreContainer();
|
this.cores = init.initialize();
|
||||||
log.info("user.dir=" + System.getProperty("user.dir"));
|
log.info("user.dir=" + System.getProperty("user.dir"));
|
||||||
}
|
}
|
||||||
catch( Throwable t ) {
|
catch( Throwable t ) {
|
||||||
|
@ -130,20 +132,15 @@ public class SolrDispatchFilter implements Filter
|
||||||
|
|
||||||
log.info("SolrDispatchFilter.init() done");
|
log.info("SolrDispatchFilter.init() done");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Override this to change CoreContainer initialization
|
|
||||||
* @return a CoreContainer to hold this server's cores
|
|
||||||
*/
|
|
||||||
protected CoreContainer createCoreContainer() {
|
|
||||||
CoreContainer cores = new CoreContainer();
|
|
||||||
cores.load();
|
|
||||||
return cores;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CoreContainer getCores() {
|
public CoreContainer getCores() {
|
||||||
return cores;
|
return cores;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Method to override to change how CoreContainer initialization is performed. */
|
||||||
|
protected CoreContainer.Initializer createInitializer() {
|
||||||
|
return new CoreContainer.Initializer();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
|
|
|
@ -17,6 +17,11 @@ package org.apache.solr.cloud;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.lucene.util.LuceneTestCase.Slow;
|
import org.apache.lucene.util.LuceneTestCase.Slow;
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.common.cloud.ClusterState;
|
import org.apache.solr.common.cloud.ClusterState;
|
||||||
|
@ -26,6 +31,7 @@ import org.apache.solr.common.cloud.SolrZkClient;
|
||||||
import org.apache.solr.common.cloud.ZkNodeProps;
|
import org.apache.solr.common.cloud.ZkNodeProps;
|
||||||
import org.apache.solr.common.cloud.ZkStateReader;
|
import org.apache.solr.common.cloud.ZkStateReader;
|
||||||
import org.apache.solr.core.CoreContainer;
|
import org.apache.solr.core.CoreContainer;
|
||||||
|
import org.apache.solr.core.CoreContainer.Initializer;
|
||||||
import org.apache.solr.core.CoreDescriptor;
|
import org.apache.solr.core.CoreDescriptor;
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.zookeeper.CreateMode;
|
import org.apache.zookeeper.CreateMode;
|
||||||
|
@ -35,11 +41,6 @@ import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Slow
|
@Slow
|
||||||
public class ClusterStateUpdateTest extends SolrTestCaseJ4 {
|
public class ClusterStateUpdateTest extends SolrTestCaseJ4 {
|
||||||
protected static Logger log = LoggerFactory
|
protected static Logger log = LoggerFactory
|
||||||
|
@ -64,6 +65,8 @@ public class ClusterStateUpdateTest extends SolrTestCaseJ4 {
|
||||||
private File dataDir3;
|
private File dataDir3;
|
||||||
|
|
||||||
private File dataDir4;
|
private File dataDir4;
|
||||||
|
|
||||||
|
private Initializer init2;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
|
@ -108,21 +111,22 @@ public class ClusterStateUpdateTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
System.setProperty("solr.solr.home", TEST_HOME());
|
System.setProperty("solr.solr.home", TEST_HOME());
|
||||||
System.setProperty("hostPort", "1661");
|
System.setProperty("hostPort", "1661");
|
||||||
|
CoreContainer.Initializer init1 = new CoreContainer.Initializer();
|
||||||
System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir1.getAbsolutePath());
|
System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir1.getAbsolutePath());
|
||||||
container1 = new CoreContainer();
|
container1 = init1.initialize();
|
||||||
container1.load();
|
|
||||||
System.clearProperty("hostPort");
|
System.clearProperty("hostPort");
|
||||||
|
|
||||||
System.setProperty("hostPort", "1662");
|
System.setProperty("hostPort", "1662");
|
||||||
|
init2 = new CoreContainer.Initializer();
|
||||||
System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir2.getAbsolutePath());
|
System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir2.getAbsolutePath());
|
||||||
container2 = new CoreContainer();
|
container2 = init2.initialize();
|
||||||
container2.load();
|
|
||||||
System.clearProperty("hostPort");
|
System.clearProperty("hostPort");
|
||||||
|
|
||||||
System.setProperty("hostPort", "1663");
|
System.setProperty("hostPort", "1663");
|
||||||
|
CoreContainer.Initializer init3 = new CoreContainer.Initializer();
|
||||||
|
|
||||||
System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir3.getAbsolutePath());
|
System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir3.getAbsolutePath());
|
||||||
container3 = new CoreContainer();
|
container3 = init3.initialize();
|
||||||
container3.load();
|
|
||||||
System.clearProperty("hostPort");
|
System.clearProperty("hostPort");
|
||||||
System.clearProperty("solr.solr.home");
|
System.clearProperty("solr.solr.home");
|
||||||
|
|
||||||
|
@ -220,11 +224,7 @@ public class ClusterStateUpdateTest extends SolrTestCaseJ4 {
|
||||||
.disconnect();
|
.disconnect();
|
||||||
container2.shutdown();
|
container2.shutdown();
|
||||||
|
|
||||||
System.setProperty("hostPort", "1662");
|
container2 = init2.initialize();
|
||||||
System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir2.getAbsolutePath());
|
|
||||||
container2 = new CoreContainer();
|
|
||||||
container2.load();
|
|
||||||
System.clearProperty("hostPort");
|
|
||||||
|
|
||||||
// pause for watch to trigger
|
// pause for watch to trigger
|
||||||
for(int i = 0; i < 200; i++) {
|
for(int i = 0; i < 200; i++) {
|
||||||
|
|
|
@ -17,20 +17,6 @@ package org.apache.solr.cloud;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.lucene.util.LuceneTestCase.Slow;
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
|
||||||
import org.apache.solr.common.cloud.SolrZkClient;
|
|
||||||
import org.apache.solr.common.cloud.ZkNodeProps;
|
|
||||||
import org.apache.solr.common.cloud.ZkStateReader;
|
|
||||||
import org.apache.solr.core.CoreContainer;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -41,6 +27,22 @@ import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
|
import org.apache.lucene.util.LuceneTestCase.Slow;
|
||||||
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
|
import org.apache.solr.common.cloud.SolrZkClient;
|
||||||
|
import org.apache.solr.common.cloud.ZkNodeProps;
|
||||||
|
import org.apache.solr.common.cloud.ZkStateReader;
|
||||||
|
import org.apache.solr.core.CoreContainer;
|
||||||
|
import org.apache.solr.core.CoreContainer.Initializer;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
@Slow
|
@Slow
|
||||||
public class LeaderElectionIntegrationTest extends SolrTestCaseJ4 {
|
public class LeaderElectionIntegrationTest extends SolrTestCaseJ4 {
|
||||||
protected static Logger log = LoggerFactory
|
protected static Logger log = LoggerFactory
|
||||||
|
@ -138,6 +140,7 @@ public class LeaderElectionIntegrationTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
System.setProperty("hostPort", Integer.toString(port));
|
System.setProperty("hostPort", Integer.toString(port));
|
||||||
System.setProperty("shard", shard);
|
System.setProperty("shard", shard);
|
||||||
|
Initializer init = new CoreContainer.Initializer();
|
||||||
System.setProperty("solr.data.dir", data.getAbsolutePath());
|
System.setProperty("solr.data.dir", data.getAbsolutePath());
|
||||||
System.setProperty("solr.solr.home", TEST_HOME());
|
System.setProperty("solr.solr.home", TEST_HOME());
|
||||||
Set<Integer> ports = shardPorts.get(shard);
|
Set<Integer> ports = shardPorts.get(shard);
|
||||||
|
@ -146,8 +149,7 @@ public class LeaderElectionIntegrationTest extends SolrTestCaseJ4 {
|
||||||
shardPorts.put(shard, ports);
|
shardPorts.put(shard, ports);
|
||||||
}
|
}
|
||||||
ports.add(port);
|
ports.add(port);
|
||||||
CoreContainer container = new CoreContainer();
|
CoreContainer container = init.initialize();
|
||||||
container.load();
|
|
||||||
assertTrue("Container " + port + " has no cores!", container.getCores()
|
assertTrue("Container " + port + " has no cores!", container.getCores()
|
||||||
.size() > 0);
|
.size() > 0);
|
||||||
containerMap.put(port, container);
|
containerMap.put(port, container);
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.apache.solr.common.cloud.SolrZkClient;
|
||||||
import org.apache.solr.common.cloud.ZkNodeProps;
|
import org.apache.solr.common.cloud.ZkNodeProps;
|
||||||
import org.apache.solr.common.cloud.ZkStateReader;
|
import org.apache.solr.common.cloud.ZkStateReader;
|
||||||
import org.apache.solr.core.CoreContainer;
|
import org.apache.solr.core.CoreContainer;
|
||||||
|
import org.apache.solr.core.CoreContainer.Initializer;
|
||||||
import org.apache.zookeeper.CreateMode;
|
import org.apache.zookeeper.CreateMode;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
@ -61,6 +62,8 @@ public class SliceStateUpdateTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
private File dataDir3;
|
private File dataDir3;
|
||||||
|
|
||||||
|
private Initializer init2;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
System.setProperty("solrcloud.skip.autorecovery", "true");
|
System.setProperty("solrcloud.skip.autorecovery", "true");
|
||||||
|
@ -114,21 +117,20 @@ public class SliceStateUpdateTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
System.setProperty("solr.solr.home", TEST_HOME());
|
System.setProperty("solr.solr.home", TEST_HOME());
|
||||||
System.setProperty("hostPort", "1661");
|
System.setProperty("hostPort", "1661");
|
||||||
|
CoreContainer.Initializer init1 = new CoreContainer.Initializer();
|
||||||
System.setProperty("solr.data.dir", SliceStateUpdateTest.this.dataDir1.getAbsolutePath());
|
System.setProperty("solr.data.dir", SliceStateUpdateTest.this.dataDir1.getAbsolutePath());
|
||||||
container1 = new CoreContainer();
|
container1 = init1.initialize();
|
||||||
|
|
||||||
System.clearProperty("hostPort");
|
System.clearProperty("hostPort");
|
||||||
|
|
||||||
System.setProperty("hostPort", "1662");
|
System.setProperty("hostPort", "1662");
|
||||||
|
init2 = new CoreContainer.Initializer();
|
||||||
System.setProperty("solr.data.dir", SliceStateUpdateTest.this.dataDir2.getAbsolutePath());
|
System.setProperty("solr.data.dir", SliceStateUpdateTest.this.dataDir2.getAbsolutePath());
|
||||||
container2 = new CoreContainer();
|
container2 = init2.initialize();
|
||||||
System.clearProperty("hostPort");
|
System.clearProperty("hostPort");
|
||||||
|
|
||||||
System.clearProperty("solr.solr.home");
|
System.clearProperty("solr.solr.home");
|
||||||
|
|
||||||
container1.load();
|
|
||||||
container2.load();
|
|
||||||
|
|
||||||
log.info("####SETUP_END " + getTestName());
|
log.info("####SETUP_END " + getTestName());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
package org.apache.solr.cloud;
|
package org.apache.solr.cloud;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.common.cloud.SolrZkClient;
|
import org.apache.solr.common.cloud.SolrZkClient;
|
||||||
import org.apache.solr.core.CoreContainer;
|
import org.apache.solr.core.CoreContainer;
|
||||||
|
@ -28,8 +30,6 @@ import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class TestMultiCoreConfBootstrap extends SolrTestCaseJ4 {
|
public class TestMultiCoreConfBootstrap extends SolrTestCaseJ4 {
|
||||||
protected static Logger log = LoggerFactory.getLogger(TestMultiCoreConfBootstrap.class);
|
protected static Logger log = LoggerFactory.getLogger(TestMultiCoreConfBootstrap.class);
|
||||||
protected CoreContainer cores = null;
|
protected CoreContainer cores = null;
|
||||||
|
@ -99,7 +99,7 @@ public class TestMultiCoreConfBootstrap extends SolrTestCaseJ4 {
|
||||||
@Test
|
@Test
|
||||||
public void testMultiCoreConfBootstrap() throws Exception {
|
public void testMultiCoreConfBootstrap() throws Exception {
|
||||||
System.setProperty("bootstrap_conf", "true");
|
System.setProperty("bootstrap_conf", "true");
|
||||||
cores = CoreContainer.createAndLoad(home, new File(home, "solr.xml"));
|
cores = new CoreContainer(home, new File(home, "solr.xml"));
|
||||||
SolrZkClient zkclient = cores.getZkController().getZkClient();
|
SolrZkClient zkclient = cores.getZkController().getZkClient();
|
||||||
// zkclient.printLayoutToStdOut();
|
// zkclient.printLayoutToStdOut();
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ package org.apache.solr.cloud;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.common.cloud.SolrZkClient;
|
import org.apache.solr.common.cloud.SolrZkClient;
|
||||||
import org.apache.solr.common.cloud.ZooKeeperException;
|
import org.apache.solr.common.cloud.ZooKeeperException;
|
||||||
|
@ -29,8 +31,6 @@ import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class TestZkChroot extends SolrTestCaseJ4 {
|
public class TestZkChroot extends SolrTestCaseJ4 {
|
||||||
protected static Logger log = LoggerFactory.getLogger(TestZkChroot.class);
|
protected static Logger log = LoggerFactory.getLogger(TestZkChroot.class);
|
||||||
protected CoreContainer cores = null;
|
protected CoreContainer cores = null;
|
||||||
|
@ -91,7 +91,7 @@ public class TestZkChroot extends SolrTestCaseJ4 {
|
||||||
SolrZkClient zkClient2 = null;
|
SolrZkClient zkClient2 = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cores = CoreContainer.createAndLoad(home, new File(home, "solr.xml"));
|
cores = new CoreContainer(home, new File(home, "solr.xml"));
|
||||||
zkClient = cores.getZkController().getZkClient();
|
zkClient = cores.getZkController().getZkClient();
|
||||||
|
|
||||||
assertTrue(zkClient.exists("/clusterstate.json", true));
|
assertTrue(zkClient.exists("/clusterstate.json", true));
|
||||||
|
@ -122,7 +122,7 @@ public class TestZkChroot extends SolrTestCaseJ4 {
|
||||||
AbstractZkTestCase.TIMEOUT);
|
AbstractZkTestCase.TIMEOUT);
|
||||||
assertFalse("Path '" + chroot + "' should not exist before the test",
|
assertFalse("Path '" + chroot + "' should not exist before the test",
|
||||||
zkClient.exists(chroot, true));
|
zkClient.exists(chroot, true));
|
||||||
cores = CoreContainer.createAndLoad(home, new File(home, "solr.xml"));
|
cores = new CoreContainer(home, new File(home, "solr.xml"));
|
||||||
fail("There should be a zk exception, as the initial path doesn't exist");
|
fail("There should be a zk exception, as the initial path doesn't exist");
|
||||||
} catch (ZooKeeperException e) {
|
} catch (ZooKeeperException e) {
|
||||||
// expected
|
// expected
|
||||||
|
@ -150,7 +150,7 @@ public class TestZkChroot extends SolrTestCaseJ4 {
|
||||||
AbstractZkTestCase.TIMEOUT);
|
AbstractZkTestCase.TIMEOUT);
|
||||||
assertFalse("Path '" + chroot + "' should not exist before the test",
|
assertFalse("Path '" + chroot + "' should not exist before the test",
|
||||||
zkClient.exists(chroot, true));
|
zkClient.exists(chroot, true));
|
||||||
cores = CoreContainer.createAndLoad(home, new File(home, "solr.xml"));
|
cores = new CoreContainer(home, new File(home, "solr.xml"));
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"solrconfig.xml should have been uploaded to zk to the correct config directory",
|
"solrconfig.xml should have been uploaded to zk to the correct config directory",
|
||||||
zkClient.exists(chroot + ZkController.CONFIGS_ZKNODE + "/"
|
zkClient.exists(chroot + ZkController.CONFIGS_ZKNODE + "/"
|
||||||
|
@ -176,7 +176,7 @@ public class TestZkChroot extends SolrTestCaseJ4 {
|
||||||
assertTrue(zkClient.exists(chroot, true));
|
assertTrue(zkClient.exists(chroot, true));
|
||||||
assertFalse(zkClient.exists(chroot + "/clusterstate.json", true));
|
assertFalse(zkClient.exists(chroot + "/clusterstate.json", true));
|
||||||
|
|
||||||
cores = CoreContainer.createAndLoad(home, new File(home, "solr.xml"));
|
cores = new CoreContainer(home, new File(home, "solr.xml"));
|
||||||
assertTrue(zkClient.exists(chroot + "/clusterstate.json", true));
|
assertTrue(zkClient.exists(chroot + "/clusterstate.json", true));
|
||||||
} finally {
|
} finally {
|
||||||
if (cores != null) cores.shutdown();
|
if (cores != null) cores.shutdown();
|
||||||
|
|
|
@ -17,6 +17,11 @@ package org.apache.solr.cloud;
|
||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.lucene.util.LuceneTestCase.Slow;
|
import org.apache.lucene.util.LuceneTestCase.Slow;
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.common.cloud.SolrZkClient;
|
import org.apache.solr.common.cloud.SolrZkClient;
|
||||||
|
@ -29,11 +34,6 @@ import org.apache.zookeeper.CreateMode;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Slow
|
@Slow
|
||||||
public class ZkControllerTest extends SolrTestCaseJ4 {
|
public class ZkControllerTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
|
@ -240,8 +240,12 @@ public class ZkControllerTest extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
|
|
||||||
private CoreContainer getCoreContainer() {
|
private CoreContainer getCoreContainer() {
|
||||||
CoreContainer cc = new CoreContainer(TEMP_DIR.getAbsolutePath());
|
CoreContainer cc = new CoreContainer(TEMP_DIR.getAbsolutePath()) {
|
||||||
cc.load();
|
{
|
||||||
|
initShardHandler();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return cc;
|
return cc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,9 @@
|
||||||
package org.apache.solr.core;
|
package org.apache.solr.core;
|
||||||
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
|
import org.apache.solr.common.SolrException;
|
||||||
|
import org.apache.solr.common.SolrException.ErrorCode;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public abstract class AbstractBadConfigTestBase extends SolrTestCaseJ4 {
|
public abstract class AbstractBadConfigTestBase extends SolrTestCaseJ4 {
|
||||||
|
@ -49,37 +50,26 @@ public abstract class AbstractBadConfigTestBase extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
ignoreException(Pattern.quote(errString));
|
ignoreException(Pattern.quote(errString));
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (null == solrHome) {
|
if (null == solrHome) {
|
||||||
initCore( solrconfigFile, schemaFile );
|
initCore( solrconfigFile, schemaFile );
|
||||||
} else {
|
} else {
|
||||||
initCore( solrconfigFile, schemaFile, solrHome );
|
initCore( solrconfigFile, schemaFile, solrHome );
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
CoreContainer cc = h.getCoreContainer();
|
for (Throwable t = e; t != null; t = t.getCause()) {
|
||||||
for (Map.Entry<String, Exception> entry : cc.getCoreInitFailures().entrySet()) {
|
// short circuit out if we found what we expected
|
||||||
if (matches(entry.getValue(), errString))
|
if (t.getMessage() != null && -1 != t.getMessage().indexOf(errString)) return;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e) {
|
// otherwise, rethrow it, possibly completley unrelated
|
||||||
if (matches(e, errString))
|
throw new SolrException
|
||||||
return;
|
(ErrorCode.SERVER_ERROR,
|
||||||
throw e;
|
"Unexpected error, expected error matching: " + errString, e);
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
deleteCore();
|
deleteCore();
|
||||||
resetExceptionIgnores();
|
resetExceptionIgnores();
|
||||||
}
|
}
|
||||||
fail("Did not encounter any exception from: " + solrconfigFile + " using " + schemaFile);
|
fail("Did not encounter any exception from: " + solrconfigFile + " using " + schemaFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean matches(Exception e, String errString) {
|
|
||||||
for (Throwable t = e; t != null; t = t.getCause()) {
|
|
||||||
if (t.getMessage() != null && -1 != t.getMessage().indexOf(errString))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,17 +17,23 @@
|
||||||
|
|
||||||
package org.apache.solr.core;
|
package org.apache.solr.core;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import java.util.Map;
|
||||||
import org.apache.lucene.util.IOUtils;
|
import java.util.Collection;
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import java.util.regex.Pattern;
|
||||||
import org.apache.solr.common.SolrException;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.xml.sax.SAXParseException;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Map;
|
import org.apache.solr.common.SolrException;
|
||||||
import java.util.regex.Pattern;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
|
|
||||||
|
import org.apache.lucene.util.IOUtils;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
|
||||||
|
import org.xml.sax.SAXParseException;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.After;
|
||||||
|
|
||||||
public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
|
@ -38,7 +44,8 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
||||||
// would be nice to do this in an @Before method,
|
// would be nice to do this in an @Before method,
|
||||||
// but junit doesn't let @Before methods have test names
|
// but junit doesn't let @Before methods have test names
|
||||||
solrHome = new File(TEMP_DIR, this.getClass().getName() + "_" + dirSuffix);
|
solrHome = new File(TEMP_DIR, this.getClass().getName() + "_" + dirSuffix);
|
||||||
assertTrue("Failed to mkdirs solrhome [" + solrHome + "]", solrHome.mkdirs());
|
assertTrue("Failed to mkdirs solrhome", solrHome.mkdirs());
|
||||||
|
cc = new CoreContainer(solrHome.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
@ -61,7 +68,7 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
||||||
Map<String,Exception> failures = null;
|
Map<String,Exception> failures = null;
|
||||||
Collection<String> cores = null;
|
Collection<String> cores = null;
|
||||||
Exception fail = null;
|
Exception fail = null;
|
||||||
|
|
||||||
init("empty_flow");
|
init("empty_flow");
|
||||||
|
|
||||||
// solr.xml
|
// solr.xml
|
||||||
|
@ -70,8 +77,7 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
// ----
|
// ----
|
||||||
// init the CoreContainer
|
// init the CoreContainer
|
||||||
cc = new CoreContainer(solrHome.getAbsolutePath());
|
cc.load(solrHome.getAbsolutePath(), solrXml);
|
||||||
cc.load();
|
|
||||||
|
|
||||||
// check that we have the cores we expect
|
// check that we have the cores we expect
|
||||||
cores = cc.getCoreNames();
|
cores = cc.getCoreNames();
|
||||||
|
@ -148,19 +154,18 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
||||||
FileUtils.getFile(solrHome, "col_ok", "conf", "solrconfig.xml"));
|
FileUtils.getFile(solrHome, "col_ok", "conf", "solrconfig.xml"));
|
||||||
FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),
|
FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),
|
||||||
FileUtils.getFile(solrHome, "col_ok", "conf", "schema.xml"));
|
FileUtils.getFile(solrHome, "col_ok", "conf", "schema.xml"));
|
||||||
|
|
||||||
// our "bad" collection
|
// our "bad" collection
|
||||||
ignoreException(Pattern.quote("DummyMergePolicy"));
|
ignoreException(Pattern.quote("DummyMergePolicy"));
|
||||||
FileUtils.copyFile(getFile("solr/collection1/conf/bad-mp-solrconfig.xml"),
|
FileUtils.copyFile(getFile("solr/collection1/conf/bad-mp-solrconfig.xml"),
|
||||||
FileUtils.getFile(solrHome, "col_bad", "conf", "solrconfig.xml"));
|
FileUtils.getFile(solrHome, "col_bad", "conf", "solrconfig.xml"));
|
||||||
FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),
|
FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),
|
||||||
FileUtils.getFile(solrHome, "col_bad", "conf", "schema.xml"));
|
FileUtils.getFile(solrHome, "col_bad", "conf", "schema.xml"));
|
||||||
|
|
||||||
|
|
||||||
// -----
|
// -----
|
||||||
// init the CoreContainer with the mix of ok/bad cores
|
// init the CoreContainer with the mix of ok/bad cores
|
||||||
cc = new CoreContainer(solrHome.getAbsolutePath());
|
cc.load(solrHome.getAbsolutePath(), solrXml);
|
||||||
cc.load();
|
|
||||||
|
|
||||||
// check that we have the cores we expect
|
// check that we have the cores we expect
|
||||||
cores = cc.getCoreNames();
|
cores = cc.getCoreNames();
|
||||||
|
@ -288,8 +293,8 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
||||||
fail("corrupt solrconfig.xml failed to trigger exception from reload");
|
fail("corrupt solrconfig.xml failed to trigger exception from reload");
|
||||||
} catch (SolrException e) {
|
} catch (SolrException e) {
|
||||||
assertTrue("We're supposed to have a wrapped SAXParserException here, but we don't",
|
assertTrue("We're supposed to have a wrapped SAXParserException here, but we don't",
|
||||||
e.getCause().getCause() instanceof SAXParseException);
|
e.getCause() instanceof SAXParseException);
|
||||||
SAXParseException se = (SAXParseException)e.getCause().getCause();
|
SAXParseException se = (SAXParseException)e.getCause();
|
||||||
assertTrue("reload exception doesn't refer to slrconfig.xml " + se.getSystemId(),
|
assertTrue("reload exception doesn't refer to slrconfig.xml " + se.getSystemId(),
|
||||||
0 < se.getSystemId().indexOf("solrconfig.xml"));
|
0 < se.getSystemId().indexOf("solrconfig.xml"));
|
||||||
|
|
||||||
|
@ -313,9 +318,9 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
||||||
fail = failures.get("col_bad");
|
fail = failures.get("col_bad");
|
||||||
assertNotNull("null failure for test core", fail);
|
assertNotNull("null failure for test core", fail);
|
||||||
assertTrue("init failure isn't SAXParseException",
|
assertTrue("init failure isn't SAXParseException",
|
||||||
fail.getCause() instanceof SAXParseException);
|
fail instanceof SAXParseException);
|
||||||
assertTrue("init failure doesn't mention problem: " + fail.toString(),
|
assertTrue("init failure doesn't mention problem: " + fail.toString(),
|
||||||
0 < ((SAXParseException)fail.getCause()).getSystemId().indexOf("solrconfig.xml"));
|
0 < ((SAXParseException)fail).getSystemId().indexOf("solrconfig.xml"));
|
||||||
|
|
||||||
// ----
|
// ----
|
||||||
// fix col_bad's config (again) and RELOAD to fix failure
|
// fix col_bad's config (again) and RELOAD to fix failure
|
||||||
|
|
|
@ -29,7 +29,6 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class SolrCoreCheckLockOnStartupTest extends SolrTestCaseJ4 {
|
public class SolrCoreCheckLockOnStartupTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
|
@ -63,9 +62,13 @@ public class SolrCoreCheckLockOnStartupTest extends SolrTestCaseJ4 {
|
||||||
try {
|
try {
|
||||||
//opening a new core on the same index
|
//opening a new core on the same index
|
||||||
initCore("solrconfig-simplelock.xml", "schema.xml");
|
initCore("solrconfig-simplelock.xml", "schema.xml");
|
||||||
if (checkForCoreInitException(LockObtainFailedException.class))
|
|
||||||
return;
|
|
||||||
fail("Expected " + LockObtainFailedException.class.getSimpleName());
|
fail("Expected " + LockObtainFailedException.class.getSimpleName());
|
||||||
|
} catch (Throwable t) {
|
||||||
|
assertTrue(t instanceof RuntimeException);
|
||||||
|
assertNotNull(t.getCause());
|
||||||
|
assertTrue(t.getCause() instanceof RuntimeException);
|
||||||
|
assertNotNull(t.getCause().getCause());
|
||||||
|
assertTrue(t.getCause().getCause().toString(), t.getCause().getCause() instanceof LockObtainFailedException);
|
||||||
} finally {
|
} finally {
|
||||||
indexWriter.close();
|
indexWriter.close();
|
||||||
directory.close();
|
directory.close();
|
||||||
|
@ -76,33 +79,24 @@ public class SolrCoreCheckLockOnStartupTest extends SolrTestCaseJ4 {
|
||||||
@Test
|
@Test
|
||||||
public void testNativeLockErrorOnStartup() throws Exception {
|
public void testNativeLockErrorOnStartup() throws Exception {
|
||||||
|
|
||||||
File indexDir = new File(dataDir, "index");
|
Directory directory = newFSDirectory(new File(dataDir, "index"), new NativeFSLockFactory());
|
||||||
log.info("Acquiring lock on {}", indexDir.getAbsolutePath());
|
|
||||||
Directory directory = newFSDirectory(indexDir, new NativeFSLockFactory());
|
|
||||||
//creates a new IndexWriter without releasing the lock yet
|
//creates a new IndexWriter without releasing the lock yet
|
||||||
IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(Version.LUCENE_40, null));
|
IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(Version.LUCENE_40, null));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//opening a new core on the same index
|
//opening a new core on the same index
|
||||||
initCore("solrconfig-nativelock.xml", "schema.xml");
|
initCore("solrconfig-nativelock.xml", "schema.xml");
|
||||||
CoreContainer cc = h.getCoreContainer();
|
|
||||||
if (checkForCoreInitException(LockObtainFailedException.class))
|
|
||||||
return;
|
|
||||||
fail("Expected " + LockObtainFailedException.class.getSimpleName());
|
fail("Expected " + LockObtainFailedException.class.getSimpleName());
|
||||||
|
} catch(Throwable t) {
|
||||||
|
assertTrue(t instanceof RuntimeException);
|
||||||
|
assertNotNull(t.getCause());
|
||||||
|
assertTrue(t.getCause() instanceof RuntimeException);
|
||||||
|
assertNotNull(t.getCause().getCause());
|
||||||
|
assertTrue(t.getCause().getCause() instanceof LockObtainFailedException);
|
||||||
} finally {
|
} finally {
|
||||||
indexWriter.close();
|
indexWriter.close();
|
||||||
directory.close();
|
directory.close();
|
||||||
deleteCore();
|
deleteCore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkForCoreInitException(Class<? extends Exception> clazz) {
|
|
||||||
for (Map.Entry<String, Exception> entry : h.getCoreContainer().getCoreInitFailures().entrySet()) {
|
|
||||||
for (Throwable t = entry.getValue(); t != null; t = t.getCause()) {
|
|
||||||
if (clazz.isInstance(t))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,16 +17,6 @@
|
||||||
|
|
||||||
package org.apache.solr.core;
|
package org.apache.solr.core;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.apache.lucene.util.IOUtils;
|
|
||||||
import org.apache.lucene.util._TestUtil;
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
@ -37,6 +27,17 @@ import java.util.List;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarOutputStream;
|
import java.util.jar.JarOutputStream;
|
||||||
|
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.lucene.util.IOUtils;
|
||||||
|
import org.apache.lucene.util._TestUtil;
|
||||||
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
public class TestCoreContainer extends SolrTestCaseJ4 {
|
public class TestCoreContainer extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
private static String oldSolrHome;
|
private static String oldSolrHome;
|
||||||
|
@ -71,7 +72,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
||||||
FileUtils.copyDirectory(new File(SolrTestCaseJ4.TEST_HOME()), solrHomeDirectory);
|
FileUtils.copyDirectory(new File(SolrTestCaseJ4.TEST_HOME()), solrHomeDirectory);
|
||||||
|
|
||||||
CoreContainer ret = new CoreContainer(solrHomeDirectory.getAbsolutePath());
|
CoreContainer ret = new CoreContainer(solrHomeDirectory.getAbsolutePath());
|
||||||
ret.load();
|
ret.load(solrHomeDirectory.getAbsolutePath(), new File(solrHomeDirectory, "solr.xml"));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,13 +161,13 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
||||||
SolrCore template = null;
|
SolrCore template = null;
|
||||||
try {
|
try {
|
||||||
template = cores.getCore("collection1");
|
template = cores.getCore("collection1");
|
||||||
instDir = template.getCoreDescriptor().getRawInstanceDir();
|
instDir = template.getCoreDescriptor().getInstanceDir();
|
||||||
} finally {
|
} finally {
|
||||||
if (null != template) template.close();
|
if (null != template) template.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final File instDirFile = new File(cores.getSolrHome(), instDir);
|
final File instDirFile = new File(instDir);
|
||||||
assertTrue("instDir doesn't exist: " + instDir, instDirFile.exists());
|
assertTrue("instDir doesn't exist: " + instDir, instDirFile.exists());
|
||||||
|
|
||||||
// sanity check the basic persistence of the default init
|
// sanity check the basic persistence of the default init
|
||||||
|
@ -261,8 +262,14 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
||||||
File solrHomeDirectory = new File(TEMP_DIR, this.getClass().getName()
|
File solrHomeDirectory = new File(TEMP_DIR, this.getClass().getName()
|
||||||
+ "_noCores");
|
+ "_noCores");
|
||||||
SetUpHome(solrHomeDirectory, EMPTY_SOLR_XML);
|
SetUpHome(solrHomeDirectory, EMPTY_SOLR_XML);
|
||||||
CoreContainer cores = new CoreContainer(solrHomeDirectory.getAbsolutePath());
|
CoreContainer.Initializer init = new CoreContainer.Initializer();
|
||||||
cores.load();
|
CoreContainer cores = null;
|
||||||
|
try {
|
||||||
|
cores = init.initialize();
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
fail("CoreContainer not created" + e.getMessage());
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
//assert zero cores
|
//assert zero cores
|
||||||
assertEquals("There should not be cores", 0, cores.getCores().size());
|
assertEquals("There should not be cores", 0, cores.getCores().size());
|
||||||
|
@ -355,21 +362,24 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
||||||
FileUtils.writeStringToFile(new File(tmpRoot, "explicit-lib-solr.xml"), "<solr sharedLib=\"lib\"><cores/></solr>", "UTF-8");
|
FileUtils.writeStringToFile(new File(tmpRoot, "explicit-lib-solr.xml"), "<solr sharedLib=\"lib\"><cores/></solr>", "UTF-8");
|
||||||
FileUtils.writeStringToFile(new File(tmpRoot, "custom-lib-solr.xml"), "<solr sharedLib=\"customLib\"><cores/></solr>", "UTF-8");
|
FileUtils.writeStringToFile(new File(tmpRoot, "custom-lib-solr.xml"), "<solr sharedLib=\"customLib\"><cores/></solr>", "UTF-8");
|
||||||
|
|
||||||
final CoreContainer cc1 = CoreContainer.createAndLoad(tmpRoot.getAbsolutePath(), new File(tmpRoot, "default-lib-solr.xml"));
|
final CoreContainer cc1 = new CoreContainer(tmpRoot.getAbsolutePath());
|
||||||
|
cc1.load(tmpRoot.getAbsolutePath(), new File(tmpRoot, "default-lib-solr.xml"));
|
||||||
try {
|
try {
|
||||||
cc1.loader.openResource("defaultSharedLibFile").close();
|
cc1.loader.openResource("defaultSharedLibFile").close();
|
||||||
} finally {
|
} finally {
|
||||||
cc1.shutdown();
|
cc1.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
final CoreContainer cc2 = CoreContainer.createAndLoad(tmpRoot.getAbsolutePath(), new File(tmpRoot, "explicit-lib-solr.xml"));
|
final CoreContainer cc2 = new CoreContainer(tmpRoot.getAbsolutePath());
|
||||||
|
cc2.load(tmpRoot.getAbsolutePath(), new File(tmpRoot, "explicit-lib-solr.xml"));
|
||||||
try {
|
try {
|
||||||
cc2.loader.openResource("defaultSharedLibFile").close();
|
cc2.loader.openResource("defaultSharedLibFile").close();
|
||||||
} finally {
|
} finally {
|
||||||
cc2.shutdown();
|
cc2.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
final CoreContainer cc3 = CoreContainer.createAndLoad(tmpRoot.getAbsolutePath(), new File(tmpRoot, "custom-lib-solr.xml"));
|
final CoreContainer cc3 = new CoreContainer(tmpRoot.getAbsolutePath());
|
||||||
|
cc3.load(tmpRoot.getAbsolutePath(), new File(tmpRoot, "custom-lib-solr.xml"));
|
||||||
try {
|
try {
|
||||||
cc3.loader.openResource("customSharedLibFile").close();
|
cc3.loader.openResource("customSharedLibFile").close();
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -17,6 +17,10 @@ package org.apache.solr.core;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.lucene.util.IOUtils;
|
import org.apache.lucene.util.IOUtils;
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
|
@ -25,10 +29,6 @@ import org.junit.After;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
public class TestCoreDiscovery extends SolrTestCaseJ4 {
|
public class TestCoreDiscovery extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
|
@ -106,8 +106,11 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
|
|
||||||
private CoreContainer init() throws Exception {
|
private CoreContainer init() throws Exception {
|
||||||
final CoreContainer cores = new CoreContainer();
|
|
||||||
cores.load();
|
CoreContainer.Initializer init = new CoreContainer.Initializer();
|
||||||
|
|
||||||
|
final CoreContainer cores = init.initialize();
|
||||||
|
cores.setPersistent(false);
|
||||||
return cores;
|
return cores;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,12 +183,10 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
|
||||||
cc = init();
|
cc = init();
|
||||||
fail("Should have thrown exception in testDuplicateNames");
|
fail("Should have thrown exception in testDuplicateNames");
|
||||||
} catch (SolrException se) {
|
} catch (SolrException se) {
|
||||||
Throwable cause = se.getCause();
|
|
||||||
String message = cause.getMessage();
|
|
||||||
assertTrue("Should have seen an exception because two cores had the same name",
|
assertTrue("Should have seen an exception because two cores had the same name",
|
||||||
message.indexOf("Core core1 defined more than once") != -1);
|
"Core + desc.getName() + \" defined twice".indexOf(se.getMessage()) != -1);
|
||||||
assertTrue("/core1 should have been mentioned in the message", message.indexOf("/core1") != -1);
|
assertTrue("/core1 should have been mentioned in the message", "/core1".indexOf(se.getMessage()) != -1);
|
||||||
assertTrue("/core2 should have been mentioned in the message", message.indexOf("/core2") != -1);
|
assertTrue("/core2 should have been mentioned in the message", "/core2".indexOf(se.getMessage()) != -1);
|
||||||
} finally {
|
} finally {
|
||||||
if (cc != null) {
|
if (cc != null) {
|
||||||
cc.shutdown();
|
cc.shutdown();
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class TestLazyCores extends SolrTestCaseJ4 {
|
||||||
File solrXml = new File(solrHomeDirectory, "solr.xml");
|
File solrXml = new File(solrHomeDirectory, "solr.xml");
|
||||||
FileUtils.write(solrXml, LOTS_SOLR_XML, IOUtils.CHARSET_UTF_8.toString());
|
FileUtils.write(solrXml, LOTS_SOLR_XML, IOUtils.CHARSET_UTF_8.toString());
|
||||||
final CoreContainer cores = new CoreContainer(solrHomeDirectory.getAbsolutePath());
|
final CoreContainer cores = new CoreContainer(solrHomeDirectory.getAbsolutePath());
|
||||||
cores.load();
|
cores.load(solrHomeDirectory.getAbsolutePath(), solrXml);
|
||||||
// h.getCoreContainer().load(solrHomeDirectory.getAbsolutePath(), new File(solrHomeDirectory, "solr.xml"));
|
// h.getCoreContainer().load(solrHomeDirectory.getAbsolutePath(), new File(solrHomeDirectory, "solr.xml"));
|
||||||
|
|
||||||
cores.setPersistent(false);
|
cores.setPersistent(false);
|
||||||
|
|
|
@ -29,7 +29,8 @@ import java.io.File;
|
||||||
public class TestShardHandlerFactory extends SolrTestCaseJ4 {
|
public class TestShardHandlerFactory extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
public void testXML() throws Exception {
|
public void testXML() throws Exception {
|
||||||
CoreContainer cc = CoreContainer.createAndLoad(TEST_HOME(), new File(TEST_HOME(), "solr-shardhandler.xml"));
|
CoreContainer cc = new CoreContainer(TEST_HOME());
|
||||||
|
cc.load(TEST_HOME(), new File(TEST_HOME(), "solr-shardhandler.xml"));
|
||||||
ShardHandlerFactory factory = cc.getShardHandlerFactory();
|
ShardHandlerFactory factory = cc.getShardHandlerFactory();
|
||||||
assertTrue(factory instanceof MockShardHandlerFactory);
|
assertTrue(factory instanceof MockShardHandlerFactory);
|
||||||
NamedList args = ((MockShardHandlerFactory)factory).args;
|
NamedList args = ((MockShardHandlerFactory)factory).args;
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class TestSolrXml extends SolrTestCaseJ4 {
|
||||||
boolean oldStyle = (config.getNode("solr/cores", false) != null);
|
boolean oldStyle = (config.getNode("solr/cores", false) != null);
|
||||||
ConfigSolr cfg;
|
ConfigSolr cfg;
|
||||||
if (oldStyle) {
|
if (oldStyle) {
|
||||||
cfg = new ConfigSolrXmlOld(config);
|
cfg = new ConfigSolrXmlOld(config, cc);
|
||||||
} else {
|
} else {
|
||||||
cfg = new ConfigSolrXml(config, cc);
|
cfg = new ConfigSolrXml(config, cc);
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ public class TestSolrXml extends SolrTestCaseJ4 {
|
||||||
boolean oldStyle = (config.getNode("solr/cores", false) != null);
|
boolean oldStyle = (config.getNode("solr/cores", false) != null);
|
||||||
ConfigSolr cfg;
|
ConfigSolr cfg;
|
||||||
if (oldStyle) {
|
if (oldStyle) {
|
||||||
cfg = new ConfigSolrXmlOld(config);
|
cfg = new ConfigSolrXmlOld(config, cc);
|
||||||
} else {
|
} else {
|
||||||
cfg = new ConfigSolrXml(config, cc);
|
cfg = new ConfigSolrXml(config, cc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.common.params.CoreAdminParams;
|
import org.apache.solr.common.params.CoreAdminParams;
|
||||||
import org.apache.solr.handler.admin.CoreAdminHandler;
|
import org.apache.solr.handler.admin.CoreAdminHandler;
|
||||||
import org.apache.solr.response.SolrQueryResponse;
|
import org.apache.solr.response.SolrQueryResponse;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.RuleChain;
|
import org.junit.rules.RuleChain;
|
||||||
|
@ -45,14 +46,12 @@ import java.util.List;
|
||||||
|
|
||||||
public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
|
public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
private File solrHomeDirectory = new File(TEMP_DIR, this.getClass().getName());
|
private final File solrHomeDirectory = new File(TEMP_DIR, this.getClass().getName());
|
||||||
|
|
||||||
/*
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() throws Exception {
|
public static void beforeClass() throws Exception {
|
||||||
initCore("solrconfig-minimal.xml", "schema-tiny.xml");
|
initCore("solrconfig-minimal.xml", "schema-tiny.xml");
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public TestRule solrTestRules =
|
public TestRule solrTestRules =
|
||||||
|
@ -60,9 +59,9 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
|
|
||||||
private CoreContainer init(String solrXmlString, String... subDirs) throws Exception {
|
private CoreContainer init(String solrXmlString, String... subDirs) throws Exception {
|
||||||
|
if (solrHomeDirectory.exists()) {
|
||||||
createTempDir();
|
FileUtils.deleteDirectory(solrHomeDirectory);
|
||||||
solrHomeDirectory = dataDir;
|
}
|
||||||
|
|
||||||
for (String s : subDirs) {
|
for (String s : subDirs) {
|
||||||
copyMinConf(new File(solrHomeDirectory, s));
|
copyMinConf(new File(solrHomeDirectory, s));
|
||||||
|
@ -70,8 +69,10 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
File solrXml = new File(solrHomeDirectory, "solr.xml");
|
File solrXml = new File(solrHomeDirectory, "solr.xml");
|
||||||
FileUtils.write(solrXml, solrXmlString, IOUtils.CHARSET_UTF_8.toString());
|
FileUtils.write(solrXml, solrXmlString, IOUtils.CHARSET_UTF_8.toString());
|
||||||
|
final CoreContainer cores = new CoreContainer(solrHomeDirectory.getAbsolutePath());
|
||||||
|
cores.load(solrHomeDirectory.getAbsolutePath(), solrXml);
|
||||||
|
|
||||||
final CoreContainer cores = createCoreContainer(solrHomeDirectory.getAbsolutePath(), solrXmlString);
|
cores.setPersistent(false);
|
||||||
return cores;
|
return cores;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,7 +304,7 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
|
||||||
} else if (persistList[idx].contains("@config='solrconfig.xml'")) {
|
} else if (persistList[idx].contains("@config='solrconfig.xml'")) {
|
||||||
expressions[idx] = persistList[idx].replace("solrconfig.xml", "${solrconfig:solrconfig.xml}");
|
expressions[idx] = persistList[idx].replace("solrconfig.xml", "${solrconfig:solrconfig.xml}");
|
||||||
} else if (persistList[idx].contains("@instanceDir=")) {
|
} else if (persistList[idx].contains("@instanceDir=")) {
|
||||||
expressions[idx] = persistList[idx].replaceFirst("instanceDir\\='.*?'", "instanceDir='" + which + "/'");
|
expressions[idx] = persistList[idx].replaceFirst("instanceDir\\='.*?'", "instanceDir='" + which + "'");
|
||||||
} else {
|
} else {
|
||||||
expressions[idx] = persistList[idx];
|
expressions[idx] = persistList[idx];
|
||||||
}
|
}
|
||||||
|
@ -610,14 +611,14 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
|
||||||
" shareSchema=\"${shareSchema:false}\" distribUpdateConnTimeout=\"${distribUpdateConnTimeout:15000}\" \n" +
|
" shareSchema=\"${shareSchema:false}\" distribUpdateConnTimeout=\"${distribUpdateConnTimeout:15000}\" \n" +
|
||||||
" distribUpdateSoTimeout=\"${distribUpdateSoTimeout:120000}\" \n" +
|
" distribUpdateSoTimeout=\"${distribUpdateSoTimeout:120000}\" \n" +
|
||||||
" leaderVoteWait=\"${leadVoteWait:32}\" managementPath=\"${manpath:/var/lib/path}\" transientCacheSize=\"${tranSize:128}\"> \n" +
|
" leaderVoteWait=\"${leadVoteWait:32}\" managementPath=\"${manpath:/var/lib/path}\" transientCacheSize=\"${tranSize:128}\"> \n" +
|
||||||
" <core name=\"SystemVars1\" instanceDir=\"SystemVars1/\" shard=\"${shard:32}\" \n" +
|
" <core name=\"SystemVars1\" instanceDir=\"SystemVars1\" shard=\"${shard:32}\" \n" +
|
||||||
" collection=\"${collection:collection1}\" config=\"${solrconfig:solrconfig.xml}\" \n" +
|
" collection=\"${collection:collection1}\" config=\"${solrconfig:solrconfig.xml}\" \n" +
|
||||||
" schema=\"${schema:schema.xml}\" ulogDir=\"${ulog:./}\" roles=\"${myrole:boss}\" \n" +
|
" schema=\"${schema:schema.xml}\" ulogDir=\"${ulog:./}\" roles=\"${myrole:boss}\" \n" +
|
||||||
" dataDir=\"${data:./}\" loadOnStartup=\"${onStart:true}\" transient=\"${tran:true}\" \n" +
|
" dataDir=\"${data:./}\" loadOnStartup=\"${onStart:true}\" transient=\"${tran:true}\" \n" +
|
||||||
" coreNodeName=\"${coreNode:utterlyridiculous}\" \n" +
|
" coreNodeName=\"${coreNode:utterlyridiculous}\" \n" +
|
||||||
" >\n" +
|
" >\n" +
|
||||||
" </core>\n" +
|
" </core>\n" +
|
||||||
" <core name=\"SystemVars2\" instanceDir=\"SystemVars2/\" shard=\"${shard:32}\" \n" +
|
" <core name=\"SystemVars2\" instanceDir=\"SystemVars2\" shard=\"${shard:32}\" \n" +
|
||||||
" collection=\"${collection:collection2}\" config=\"${solrconfig:solrconfig.xml}\" \n" +
|
" collection=\"${collection:collection2}\" config=\"${solrconfig:solrconfig.xml}\" \n" +
|
||||||
" coreNodeName=\"${coreNodeName:}\" schema=\"${schema:schema.xml}\">\n" +
|
" coreNodeName=\"${coreNodeName:}\" schema=\"${schema:schema.xml}\">\n" +
|
||||||
" <property name=\"collection\" value=\"{collection:collection2}\"/>\n" +
|
" <property name=\"collection\" value=\"{collection:collection2}\"/>\n" +
|
||||||
|
@ -631,7 +632,7 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
|
||||||
private static String SOLR_XML_MINIMAL =
|
private static String SOLR_XML_MINIMAL =
|
||||||
"<solr >\n" +
|
"<solr >\n" +
|
||||||
" <cores> \n" +
|
" <cores> \n" +
|
||||||
" <core name=\"SystemVars1\" instanceDir=\"SystemVars1/\" />\n" +
|
" <core name=\"SystemVars1\" instanceDir=\"SystemVars1\" />\n" +
|
||||||
" </cores>\n" +
|
" </cores>\n" +
|
||||||
"</solr>";
|
"</solr>";
|
||||||
|
|
||||||
|
|
|
@ -17,22 +17,15 @@
|
||||||
|
|
||||||
package org.apache.solr.handler.admin;
|
package org.apache.solr.handler.admin;
|
||||||
|
|
||||||
import org.apache.log4j.Level;
|
import java.util.logging.Logger;
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.common.params.CommonParams;
|
import org.apache.solr.common.params.CommonParams;
|
||||||
import org.apache.solr.logging.log4j.Log4jInfo;
|
import org.apache.solr.logging.jul.JulInfo;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
public class LoggingHandlerTest extends SolrTestCaseJ4 {
|
public class LoggingHandlerTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
// TODO: This only tests Log4j at the moment, as that's what's defined
|
|
||||||
// through the CoreContainer.
|
|
||||||
|
|
||||||
// TODO: Would be nice to throw an exception on trying to set a
|
|
||||||
// log level that doesn't exist
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() throws Exception {
|
public static void beforeClass() throws Exception {
|
||||||
|
@ -42,8 +35,7 @@ public class LoggingHandlerTest extends SolrTestCaseJ4 {
|
||||||
@Test
|
@Test
|
||||||
public void testLogLevelHandlerOutput() throws Exception {
|
public void testLogLevelHandlerOutput() throws Exception {
|
||||||
Logger tst = Logger.getLogger("org.apache.solr.SolrTestCaseJ4");
|
Logger tst = Logger.getLogger("org.apache.solr.SolrTestCaseJ4");
|
||||||
tst.setLevel(Level.INFO);
|
JulInfo wrap = new JulInfo(tst.getName(), tst);
|
||||||
Log4jInfo wrap = new Log4jInfo(tst.getName(), tst);
|
|
||||||
|
|
||||||
assertQ("Show Log Levels OK",
|
assertQ("Show Log Levels OK",
|
||||||
req(CommonParams.QT,"/admin/logging")
|
req(CommonParams.QT,"/admin/logging")
|
||||||
|
@ -54,8 +46,8 @@ public class LoggingHandlerTest extends SolrTestCaseJ4 {
|
||||||
assertQ("Set and remove a level",
|
assertQ("Set and remove a level",
|
||||||
req(CommonParams.QT,"/admin/logging",
|
req(CommonParams.QT,"/admin/logging",
|
||||||
"set", "org.xxx.yyy.abc:null",
|
"set", "org.xxx.yyy.abc:null",
|
||||||
"set", "org.xxx.yyy.zzz:TRACE")
|
"set", "org.xxx.yyy.zzz:FINEST")
|
||||||
,"//arr[@name='loggers']/lst/str[.='org.xxx.yyy.zzz']/../str[@name='level'][.='TRACE']"
|
,"//arr[@name='loggers']/lst/str[.='org.xxx.yyy.zzz']/../str[@name='level'][.='FINEST']"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,18 +17,17 @@
|
||||||
|
|
||||||
package org.apache.solr.handler.admin;
|
package org.apache.solr.handler.admin;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
import org.apache.solr.common.luke.FieldFlag;
|
import org.apache.solr.common.luke.FieldFlag;
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
import org.apache.solr.schema.IndexSchema;
|
import org.apache.solr.schema.IndexSchema;
|
||||||
import org.apache.solr.util.AbstractSolrTestCase;
|
import org.apache.solr.util.AbstractSolrTestCase;
|
||||||
import org.apache.solr.util.TestHarness;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.EnumSet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* :TODO: currently only tests some of the utilities in the LukeRequestHandler
|
* :TODO: currently only tests some of the utilities in the LukeRequestHandler
|
||||||
*/
|
*/
|
||||||
|
@ -157,7 +156,7 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase {
|
||||||
try {
|
try {
|
||||||
// First, determine that the two fields ARE there
|
// First, determine that the two fields ARE there
|
||||||
String response = h.query(req);
|
String response = h.query(req);
|
||||||
assertNull(TestHarness.validateXPath(response,
|
assertNull(h.validateXPath(response,
|
||||||
getFieldXPathPrefix("solr_t") + "[@name='index']",
|
getFieldXPathPrefix("solr_t") + "[@name='index']",
|
||||||
getFieldXPathPrefix("solr_s") + "[@name='index']"
|
getFieldXPathPrefix("solr_s") + "[@name='index']"
|
||||||
));
|
));
|
||||||
|
@ -166,7 +165,7 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase {
|
||||||
for (String f : Arrays.asList("solr_ti",
|
for (String f : Arrays.asList("solr_ti",
|
||||||
"solr_td", "solr_pl", "solr_dt", "solr_b")) {
|
"solr_td", "solr_pl", "solr_dt", "solr_b")) {
|
||||||
|
|
||||||
assertNotNull(TestHarness.validateXPath(response,
|
assertNotNull(h.validateXPath(response,
|
||||||
getFieldXPathPrefix(f) + "[@name='index']"));
|
getFieldXPathPrefix(f) + "[@name='index']"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -176,7 +175,7 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase {
|
||||||
for (String f : Arrays.asList("solr_t", "solr_s", "solr_ti",
|
for (String f : Arrays.asList("solr_t", "solr_s", "solr_ti",
|
||||||
"solr_td", "solr_pl", "solr_dt", "solr_b")) {
|
"solr_td", "solr_pl", "solr_dt", "solr_b")) {
|
||||||
|
|
||||||
assertNull(TestHarness.validateXPath(response,
|
assertNull(h.validateXPath(response,
|
||||||
getFieldXPathPrefix(f) + "[@name='index']"));
|
getFieldXPathPrefix(f) + "[@name='index']"));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -188,7 +187,7 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase {
|
||||||
SolrQueryRequest req = req("qt", "/admin/luke", "show", "schema");
|
SolrQueryRequest req = req("qt", "/admin/luke", "show", "schema");
|
||||||
|
|
||||||
String xml = h.query(req);
|
String xml = h.query(req);
|
||||||
String r = TestHarness.validateXPath
|
String r = h.validateXPath
|
||||||
(xml,
|
(xml,
|
||||||
field("text") + "/arr[@name='copySources']/str[.='title']",
|
field("text") + "/arr[@name='copySources']/str[.='title']",
|
||||||
field("text") + "/arr[@name='copySources']/str[.='subject']",
|
field("text") + "/arr[@name='copySources']/str[.='subject']",
|
||||||
|
@ -218,7 +217,7 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase {
|
||||||
|
|
||||||
SolrQueryRequest req = req("qt", "/admin/luke", "show", "schema", "indent", "on");
|
SolrQueryRequest req = req("qt", "/admin/luke", "show", "schema", "indent", "on");
|
||||||
String xml = h.query(req);
|
String xml = h.query(req);
|
||||||
String result = TestHarness.validateXPath(xml, field("bday") + "/arr[@name='copyDests']/str[.='catchall_t']");
|
String result = h.validateXPath(xml, field("bday") + "/arr[@name='copyDests']/str[.='catchall_t']");
|
||||||
assertNull(xml, result);
|
assertNull(xml, result);
|
||||||
|
|
||||||
// Put back the configuration expected by the rest of the tests in this suite
|
// Put back the configuration expected by the rest of the tests in this suite
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.solr.handler.component;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
|
import org.apache.solr.common.SolrException;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,7 +34,14 @@ public class BadComponentTest extends SolrTestCaseJ4{
|
||||||
ignoreException(".*QueryElevationComponent.*");
|
ignoreException(".*QueryElevationComponent.*");
|
||||||
System.setProperty("elevate.file", "foo.xml");
|
System.setProperty("elevate.file", "foo.xml");
|
||||||
initCore("solrconfig-elevate.xml", "schema12.xml");
|
initCore("solrconfig-elevate.xml", "schema12.xml");
|
||||||
assertTrue(hasInitException("QueryElevationComponent"));
|
assertTrue(false);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
//TODO: better way of checking this?
|
||||||
|
if (e.getCause() instanceof SolrException){
|
||||||
|
assertTrue(true);
|
||||||
|
} else {
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
System.clearProperty("elevate.file");
|
System.clearProperty("elevate.file");
|
||||||
resetExceptionIgnores();
|
resetExceptionIgnores();
|
||||||
|
|
|
@ -17,6 +17,10 @@
|
||||||
|
|
||||||
package org.apache.solr.client.solrj;
|
package org.apache.solr.client.solrj;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.client.solrj.request.AbstractUpdateRequest;
|
import org.apache.solr.client.solrj.request.AbstractUpdateRequest;
|
||||||
import org.apache.solr.client.solrj.request.CoreAdminRequest;
|
import org.apache.solr.client.solrj.request.CoreAdminRequest;
|
||||||
|
@ -28,12 +32,9 @@ import org.apache.solr.common.params.SolrParams;
|
||||||
import org.apache.solr.core.CoreContainer;
|
import org.apache.solr.core.CoreContainer;
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.util.ExternalPaths;
|
import org.apache.solr.util.ExternalPaths;
|
||||||
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract base class for testing merge indexes command
|
* Abstract base class for testing merge indexes command
|
||||||
*
|
*
|
||||||
|
@ -41,8 +42,7 @@ import java.util.Arrays;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class MergeIndexesExampleTestBase extends SolrExampleTestBase {
|
public abstract class MergeIndexesExampleTestBase extends SolrExampleTestBase {
|
||||||
|
protected static CoreContainer cores;
|
||||||
protected CoreContainer cores;
|
|
||||||
private String saveProp;
|
private String saveProp;
|
||||||
private File dataDir2;
|
private File dataDir2;
|
||||||
|
|
||||||
|
@ -56,11 +56,13 @@ public abstract class MergeIndexesExampleTestBase extends SolrExampleTestBase {
|
||||||
if (dataDir == null) {
|
if (dataDir == null) {
|
||||||
createTempDir();
|
createTempDir();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected void setupCoreContainer() {
|
|
||||||
cores = new CoreContainer();
|
cores = new CoreContainer();
|
||||||
cores.load();
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void afterClass() {
|
||||||
|
cores.shutdown();
|
||||||
|
cores = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,8 +71,6 @@ public abstract class MergeIndexesExampleTestBase extends SolrExampleTestBase {
|
||||||
System.setProperty("solr.directoryFactory", "solr.StandardDirectoryFactory");
|
System.setProperty("solr.directoryFactory", "solr.StandardDirectoryFactory");
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
setupCoreContainer();
|
|
||||||
|
|
||||||
SolrCore.log.info("CORES=" + cores + " : " + cores.getCoreNames());
|
SolrCore.log.info("CORES=" + cores + " : " + cores.getCoreNames());
|
||||||
cores.setPersistent(false);
|
cores.setPersistent(false);
|
||||||
|
|
||||||
|
@ -96,8 +96,6 @@ public abstract class MergeIndexesExampleTestBase extends SolrExampleTestBase {
|
||||||
System.err.println("!!!! WARNING: best effort to remove " + dataDir2.getAbsolutePath() + " FAILED !!!!!");
|
System.err.println("!!!! WARNING: best effort to remove " + dataDir2.getAbsolutePath() + " FAILED !!!!!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cores.shutdown();
|
|
||||||
|
|
||||||
if (saveProp == null) System.clearProperty("solr.directoryFactory");
|
if (saveProp == null) System.clearProperty("solr.directoryFactory");
|
||||||
else System.setProperty("solr.directoryFactory", saveProp);
|
else System.setProperty("solr.directoryFactory", saveProp);
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
package org.apache.solr.client.solrj;
|
package org.apache.solr.client.solrj;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;
|
import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;
|
||||||
import org.apache.solr.client.solrj.request.CoreAdminRequest;
|
import org.apache.solr.client.solrj.request.CoreAdminRequest;
|
||||||
import org.apache.solr.client.solrj.request.CoreAdminRequest.Unload;
|
import org.apache.solr.client.solrj.request.CoreAdminRequest.Unload;
|
||||||
|
@ -28,10 +30,10 @@ import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.core.CoreContainer;
|
import org.apache.solr.core.CoreContainer;
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.util.ExternalPaths;
|
import org.apache.solr.util.ExternalPaths;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -39,23 +41,27 @@ import java.io.File;
|
||||||
*/
|
*/
|
||||||
public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
|
public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
|
||||||
{
|
{
|
||||||
protected CoreContainer cores;
|
protected static CoreContainer cores;
|
||||||
|
|
||||||
private File dataDir2;
|
private File dataDir2;
|
||||||
private File dataDir1;
|
private File dataDir1;
|
||||||
|
|
||||||
@Override public String getSolrHome() { return ExternalPaths.EXAMPLE_MULTICORE_HOME; }
|
@Override public String getSolrHome() { return ExternalPaths.EXAMPLE_MULTICORE_HOME; }
|
||||||
|
|
||||||
protected void setupCoreContainer() {
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void beforeThisClass2() throws Exception {
|
||||||
cores = new CoreContainer();
|
cores = new CoreContainer();
|
||||||
cores.load();
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void afterClass() {
|
||||||
|
cores.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void setUp() throws Exception {
|
@Override public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
setupCoreContainer();
|
|
||||||
|
|
||||||
SolrCore.log.info("CORES=" + cores + " : " + cores.getCoreNames());
|
SolrCore.log.info("CORES=" + cores + " : " + cores.getCoreNames());
|
||||||
cores.setPersistent(false);
|
cores.setPersistent(false);
|
||||||
|
|
||||||
|
@ -83,8 +89,6 @@ public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
|
||||||
System.err.println("!!!! WARNING: best effort to remove " + dataDir2.getAbsolutePath() + " FAILED !!!!!");
|
System.err.println("!!!! WARNING: best effort to remove " + dataDir2.getAbsolutePath() + " FAILED !!!!!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cores.shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -61,7 +61,7 @@ public abstract class AbstractEmbeddedSolrServerTestCase extends LuceneTestCase
|
||||||
System.setProperty("dataDir2", dataDir2.getAbsolutePath());
|
System.setProperty("dataDir2", dataDir2.getAbsolutePath());
|
||||||
System.setProperty("tempDir", tempDir.getAbsolutePath());
|
System.setProperty("tempDir", tempDir.getAbsolutePath());
|
||||||
System.setProperty("tests.shardhandler.randomSeed", Long.toString(random().nextLong()));
|
System.setProperty("tests.shardhandler.randomSeed", Long.toString(random().nextLong()));
|
||||||
cores = CoreContainer.createAndLoad(SOLR_HOME.getAbsolutePath(), getSolrXml());
|
cores = new CoreContainer(SOLR_HOME.getAbsolutePath(), getSolrXml());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract File getSolrXml() throws Exception;
|
protected abstract File getSolrXml() throws Exception;
|
||||||
|
|
|
@ -17,9 +17,10 @@
|
||||||
|
|
||||||
package org.apache.solr.client.solrj.embedded;
|
package org.apache.solr.client.solrj.embedded;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import org.apache.solr.client.solrj.MergeIndexesExampleTestBase;
|
import org.apache.solr.client.solrj.MergeIndexesExampleTestBase;
|
||||||
import org.apache.solr.client.solrj.SolrServer;
|
import org.apache.solr.client.solrj.SolrServer;
|
||||||
import org.apache.solr.core.CoreContainer;
|
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,12 +36,10 @@ public class MergeIndexesEmbeddedTest extends MergeIndexesExampleTestBase {
|
||||||
// TODO: fix this test to use MockDirectoryFactory
|
// TODO: fix this test to use MockDirectoryFactory
|
||||||
System.clearProperty("solr.directoryFactory");
|
System.clearProperty("solr.directoryFactory");
|
||||||
super.setUp();
|
super.setUp();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
File home = new File(getSolrHome());
|
||||||
protected void setupCoreContainer() {
|
File f = new File(home, "solr.xml");
|
||||||
cores = new CoreContainer(getSolrHome());
|
cores.load(getSolrHome(), f);
|
||||||
cores.load();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,9 +17,10 @@
|
||||||
|
|
||||||
package org.apache.solr.client.solrj.embedded;
|
package org.apache.solr.client.solrj.embedded;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import org.apache.solr.client.solrj.MultiCoreExampleTestBase;
|
import org.apache.solr.client.solrj.MultiCoreExampleTestBase;
|
||||||
import org.apache.solr.client.solrj.SolrServer;
|
import org.apache.solr.client.solrj.SolrServer;
|
||||||
import org.apache.solr.core.CoreContainer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This runs SolrServer test using
|
* This runs SolrServer test using
|
||||||
|
@ -34,11 +35,10 @@ public class MultiCoreEmbeddedTest extends MultiCoreExampleTestBase {
|
||||||
// TODO: fix this test to use MockDirectoryFactory
|
// TODO: fix this test to use MockDirectoryFactory
|
||||||
System.clearProperty("solr.directoryFactory");
|
System.clearProperty("solr.directoryFactory");
|
||||||
super.setUp();
|
super.setUp();
|
||||||
}
|
|
||||||
|
File home = new File( getSolrHome() );
|
||||||
protected void setupCoreContainer() {
|
File f = new File( home, "solr.xml" );
|
||||||
cores = new CoreContainer(getSolrHome());
|
cores.load( getSolrHome(), f );
|
||||||
cores.load();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,15 +17,20 @@
|
||||||
|
|
||||||
package org.apache.solr.client.solrj.embedded;
|
package org.apache.solr.client.solrj.embedded;
|
||||||
|
|
||||||
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
|
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 org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.client.solrj.SolrQuery;
|
import org.apache.solr.client.solrj.SolrQuery;
|
||||||
import org.apache.solr.client.solrj.SolrServer;
|
import org.apache.solr.client.solrj.SolrServer;
|
||||||
import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;
|
import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;
|
||||||
import org.apache.solr.client.solrj.request.CoreAdminRequest;
|
import org.apache.solr.client.solrj.request.*;
|
||||||
import org.apache.solr.client.solrj.request.QueryRequest;
|
|
||||||
import org.apache.solr.client.solrj.request.UpdateRequest;
|
|
||||||
import org.apache.solr.client.solrj.response.CoreAdminResponse;
|
import org.apache.solr.client.solrj.response.CoreAdminResponse;
|
||||||
import org.apache.solr.common.SolrInputDocument;
|
import org.apache.solr.common.SolrInputDocument;
|
||||||
import org.apache.solr.core.CoreContainer;
|
import org.apache.solr.core.CoreContainer;
|
||||||
|
@ -41,15 +46,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -261,7 +258,7 @@ public class TestSolrProperties extends AbstractEmbeddedSolrServerTestCase {
|
||||||
// System.out.println("xml:" + solrPersistXml);
|
// System.out.println("xml:" + solrPersistXml);
|
||||||
// fis.close();
|
// fis.close();
|
||||||
|
|
||||||
cores = CoreContainer.createAndLoad(SOLR_HOME.getAbsolutePath(), new File(tempDir, SOLR_PERSIST_XML));
|
cores = new CoreContainer(SOLR_HOME.getAbsolutePath(), new File(tempDir, SOLR_PERSIST_XML));
|
||||||
|
|
||||||
mcr = CoreAdminRequest.persist(SOLR_PERSIST_XML, getRenamedSolrAdmin());
|
mcr = CoreAdminRequest.persist(SOLR_PERSIST_XML, getRenamedSolrAdmin());
|
||||||
|
|
||||||
|
|
|
@ -17,28 +17,26 @@
|
||||||
|
|
||||||
package org.apache.solr;
|
package org.apache.solr;
|
||||||
|
|
||||||
import com.carrotsearch.randomizedtesting.RandomizedContext;
|
import java.io.*;
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
|
import java.util.*;
|
||||||
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
|
import java.util.logging.*;
|
||||||
|
|
||||||
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.lucene.util.Constants;
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LuceneTestCase;
|
||||||
import org.apache.lucene.util.QuickPatchThreadsFilter;
|
import org.apache.lucene.util.QuickPatchThreadsFilter;
|
||||||
import org.apache.solr.client.solrj.util.ClientUtils;
|
import org.apache.solr.client.solrj.util.ClientUtils;
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.*;
|
||||||
import org.apache.solr.common.SolrInputDocument;
|
|
||||||
import org.apache.solr.common.SolrInputField;
|
|
||||||
import org.apache.solr.common.cloud.SolrZkClient;
|
import org.apache.solr.common.cloud.SolrZkClient;
|
||||||
import org.apache.solr.common.params.CommonParams;
|
import org.apache.solr.common.params.*;
|
||||||
import org.apache.solr.common.params.ModifiableSolrParams;
|
|
||||||
import org.apache.solr.common.params.SolrParams;
|
|
||||||
import org.apache.solr.common.util.XML;
|
import org.apache.solr.common.util.XML;
|
||||||
import org.apache.solr.core.CoreContainer;
|
import org.apache.solr.core.CoreContainer;
|
||||||
import org.apache.solr.core.SolrConfig;
|
import org.apache.solr.core.SolrConfig;
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.handler.JsonUpdateRequestHandler;
|
import org.apache.solr.handler.JsonUpdateRequestHandler;
|
||||||
import org.apache.solr.request.LocalSolrQueryRequest;
|
import org.apache.solr.request.*;
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
|
||||||
import org.apache.solr.request.SolrRequestHandler;
|
|
||||||
import org.apache.solr.schema.IndexSchema;
|
import org.apache.solr.schema.IndexSchema;
|
||||||
import org.apache.solr.schema.SchemaField;
|
import org.apache.solr.schema.SchemaField;
|
||||||
import org.apache.solr.search.SolrIndexSearcher;
|
import org.apache.solr.search.SolrIndexSearcher;
|
||||||
|
@ -46,10 +44,7 @@ import org.apache.solr.servlet.DirectSolrConnection;
|
||||||
import org.apache.solr.util.AbstractSolrTestCase;
|
import org.apache.solr.util.AbstractSolrTestCase;
|
||||||
import org.apache.solr.util.RevertDefaultThreadHandlerRule;
|
import org.apache.solr.util.RevertDefaultThreadHandlerRule;
|
||||||
import org.apache.solr.util.TestHarness;
|
import org.apache.solr.util.TestHarness;
|
||||||
import org.junit.AfterClass;
|
import org.junit.*;
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.ClassRule;
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.rules.RuleChain;
|
import org.junit.rules.RuleChain;
|
||||||
import org.junit.rules.TestRule;
|
import org.junit.rules.TestRule;
|
||||||
import org.noggit.CharArr;
|
import org.noggit.CharArr;
|
||||||
|
@ -59,22 +54,9 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
import com.carrotsearch.randomizedtesting.RandomizedContext;
|
||||||
import java.io.File;
|
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
|
||||||
import java.io.IOException;
|
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.logging.ConsoleHandler;
|
|
||||||
import java.util.logging.Handler;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A junit4 Solr test harness that extends LuceneTestCaseJ4. To change which core is used when loading the schema and solrconfig.xml, simply
|
* A junit4 Solr test harness that extends LuceneTestCaseJ4. To change which core is used when loading the schema and solrconfig.xml, simply
|
||||||
|
@ -421,29 +403,6 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
||||||
("standard",0,20,CommonParams.VERSION,"2.2");
|
("standard",0,20,CommonParams.VERSION,"2.2");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CoreContainer createCoreContainer(String solrHome, String solrXML) {
|
|
||||||
testSolrHome = checkNotNull(solrHome);
|
|
||||||
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
|
/** Subclasses that override setUp can optionally call this method
|
||||||
* to log the fact that their setUp process has ended.
|
* to log the fact that their setUp process has ended.
|
||||||
*/
|
*/
|
||||||
|
@ -1490,12 +1449,12 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertXmlFile(final File file, String... xpath)
|
public void assertXmlFile(final File file, String... xpath)
|
||||||
throws IOException, SAXException {
|
throws IOException, SAXException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String xml = FileUtils.readFileToString(file, "UTF-8");
|
String xml = FileUtils.readFileToString(file, "UTF-8");
|
||||||
String results = TestHarness.validateXPath(xml, xpath);
|
String results = h.validateXPath(xml, xpath);
|
||||||
if (null != results) {
|
if (null != results) {
|
||||||
String msg = "File XPath failure: file=" + file.getPath() + " xpath="
|
String msg = "File XPath failure: file=" + file.getPath() + " xpath="
|
||||||
+ results + "\n\nxml was: " + xml;
|
+ results + "\n\nxml was: " + xml;
|
||||||
|
|
|
@ -33,10 +33,10 @@ import java.io.StringWriter;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
abstract public class BaseTestHarness {
|
abstract public class BaseTestHarness {
|
||||||
private static final ThreadLocal<DocumentBuilder> builderTL = new ThreadLocal<DocumentBuilder>();
|
private final ThreadLocal<DocumentBuilder> builderTL = new ThreadLocal<DocumentBuilder>();
|
||||||
private static final ThreadLocal<XPath> xpathTL = new ThreadLocal<XPath>();
|
private final ThreadLocal<XPath> xpathTL = new ThreadLocal<XPath>();
|
||||||
|
|
||||||
public static DocumentBuilder getXmlDocumentBuilder() {
|
public DocumentBuilder getXmlDocumentBuilder() {
|
||||||
try {
|
try {
|
||||||
DocumentBuilder builder = builderTL.get();
|
DocumentBuilder builder = builderTL.get();
|
||||||
if (builder == null) {
|
if (builder == null) {
|
||||||
|
@ -49,7 +49,7 @@ abstract public class BaseTestHarness {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static XPath getXpath() {
|
public XPath getXpath() {
|
||||||
try {
|
try {
|
||||||
XPath xpath = xpathTL.get();
|
XPath xpath = xpathTL.get();
|
||||||
if (xpath == null) {
|
if (xpath == null) {
|
||||||
|
@ -71,7 +71,7 @@ abstract public class BaseTestHarness {
|
||||||
* @param tests Array of XPath strings to test (in boolean mode) on the xml
|
* @param tests Array of XPath strings to test (in boolean mode) on the xml
|
||||||
* @return null if all good, otherwise the first test that fails.
|
* @return null if all good, otherwise the first test that fails.
|
||||||
*/
|
*/
|
||||||
public static String validateXPath(String xml, String... tests)
|
public String validateXPath(String xml, String... tests)
|
||||||
throws XPathExpressionException, SAXException {
|
throws XPathExpressionException, SAXException {
|
||||||
|
|
||||||
if (tests==null || tests.length == 0) return null;
|
if (tests==null || tests.length == 0) return null;
|
||||||
|
|
|
@ -127,7 +127,7 @@ abstract public class RestTestBase extends SolrJettyTestBase {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
String results = TestHarness.validateXPath(response, tests);
|
String results = restTestHarness.validateXPath(response, tests);
|
||||||
|
|
||||||
if (null != results) {
|
if (null != results) {
|
||||||
String msg = "REQUEST FAILED: xpath=" + results
|
String msg = "REQUEST FAILED: xpath=" + results
|
||||||
|
|
|
@ -17,17 +17,20 @@
|
||||||
|
|
||||||
package org.apache.solr.util;
|
package org.apache.solr.util;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.common.params.CommonParams;
|
import org.apache.solr.common.params.CommonParams;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.common.util.NamedList.NamedListEntry;
|
import org.apache.solr.core.Config;
|
||||||
import org.apache.solr.core.ConfigSolr;
|
import org.apache.solr.core.ConfigSolrXmlOld;
|
||||||
import org.apache.solr.core.CoreContainer;
|
|
||||||
import org.apache.solr.core.SolrConfig;
|
import org.apache.solr.core.SolrConfig;
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
|
import org.apache.solr.core.CoreContainer;
|
||||||
|
import org.apache.solr.core.CoreDescriptor;
|
||||||
import org.apache.solr.core.SolrResourceLoader;
|
import org.apache.solr.core.SolrResourceLoader;
|
||||||
import org.apache.solr.handler.UpdateRequestHandler;
|
import org.apache.solr.handler.UpdateRequestHandler;
|
||||||
|
import org.apache.solr.logging.ListenerConfig;
|
||||||
|
import org.apache.solr.logging.LogWatcher;
|
||||||
|
import org.apache.solr.logging.jul.JulWatcher;
|
||||||
import org.apache.solr.request.LocalSolrQueryRequest;
|
import org.apache.solr.request.LocalSolrQueryRequest;
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
import org.apache.solr.request.SolrRequestHandler;
|
import org.apache.solr.request.SolrRequestHandler;
|
||||||
|
@ -37,6 +40,9 @@ import org.apache.solr.response.SolrQueryResponse;
|
||||||
import org.apache.solr.schema.IndexSchema;
|
import org.apache.solr.schema.IndexSchema;
|
||||||
import org.apache.solr.schema.IndexSchemaFactory;
|
import org.apache.solr.schema.IndexSchemaFactory;
|
||||||
import org.apache.solr.servlet.DirectSolrConnection;
|
import org.apache.solr.servlet.DirectSolrConnection;
|
||||||
|
import org.apache.solr.common.util.NamedList.NamedListEntry;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -45,6 +51,8 @@ import java.io.StringWriter;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides a simple harness that may be useful when
|
* This class provides a simple harness that may be useful when
|
||||||
|
@ -98,8 +106,19 @@ public class TestHarness extends BaseTestHarness {
|
||||||
SolrConfig solrConfig,
|
SolrConfig solrConfig,
|
||||||
String schemaFile) {
|
String schemaFile) {
|
||||||
this( coreName, dataDirectory, solrConfig, IndexSchemaFactory.buildIndexSchema(schemaFile, solrConfig));
|
this( coreName, dataDirectory, solrConfig, IndexSchemaFactory.buildIndexSchema(schemaFile, solrConfig));
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @param coreName to initialize
|
||||||
|
* @param dataDirectory path for index data, will not be cleaned up
|
||||||
|
* @param solrConfig solrconfig instance
|
||||||
|
* @param indexSchema schema instance
|
||||||
|
*/
|
||||||
|
public TestHarness( String coreName,
|
||||||
|
String dataDirectory,
|
||||||
|
SolrConfig solrConfig,
|
||||||
|
IndexSchema indexSchema) {
|
||||||
|
this(coreName, new Initializer(coreName, dataDirectory, solrConfig, indexSchema));
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @param dataDirectory path for index data, will not be cleaned up
|
* @param dataDirectory path for index data, will not be cleaned up
|
||||||
* @param solrConfig solronfig instance
|
* @param solrConfig solronfig instance
|
||||||
|
@ -118,25 +137,17 @@ public class TestHarness extends BaseTestHarness {
|
||||||
public TestHarness( String dataDirectory,
|
public TestHarness( String dataDirectory,
|
||||||
SolrConfig solrConfig,
|
SolrConfig solrConfig,
|
||||||
IndexSchema indexSchema) {
|
IndexSchema indexSchema) {
|
||||||
this(CoreContainer.DEFAULT_DEFAULT_CORE_NAME, dataDirectory, solrConfig, indexSchema);
|
this(null, new Initializer(null, dataDirectory, solrConfig, indexSchema));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public TestHarness(String coreName, CoreContainer.Initializer init) {
|
||||||
* @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 {
|
try {
|
||||||
|
|
||||||
|
container = init.initialize();
|
||||||
if (coreName == null)
|
if (coreName == null)
|
||||||
coreName = CoreContainer.DEFAULT_DEFAULT_CORE_NAME;
|
coreName = CoreContainer.DEFAULT_DEFAULT_CORE_NAME;
|
||||||
this.coreName = coreName;
|
|
||||||
|
|
||||||
SolrResourceLoader loader = new SolrResourceLoader(SolrResourceLoader.locateSolrHome());
|
this.coreName = coreName;
|
||||||
ConfigSolr config = getTestHarnessConfig(coreName, dataDir, solrConfig, indexSchema);
|
|
||||||
container = new CoreContainer(loader, config);
|
|
||||||
container.load();
|
|
||||||
|
|
||||||
updater = new UpdateRequestHandler();
|
updater = new UpdateRequestHandler();
|
||||||
updater.init( null );
|
updater.init( null );
|
||||||
|
@ -145,46 +156,72 @@ public class TestHarness extends BaseTestHarness {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Creates a container based on infos needed to create one core
|
||||||
* Create a TestHarness using a specific solr home directory and solr xml
|
static class Initializer extends CoreContainer.Initializer {
|
||||||
* @param solrHome the solr home directory
|
String coreName;
|
||||||
* @param solrXml a File pointing to a solr.xml configuration
|
String dataDirectory;
|
||||||
*/
|
SolrConfig solrConfig;
|
||||||
public TestHarness(String solrHome, String solrXml) {
|
IndexSchema indexSchema;
|
||||||
this(new SolrResourceLoader(solrHome),
|
public Initializer(String coreName,
|
||||||
ConfigSolr.fromInputStream(null, new ByteArrayInputStream(solrXml.getBytes(Charsets.UTF_8))));
|
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);
|
||||||
|
|
||||||
/**
|
// TODO: we should be exercising the *same* core container initialization code, not equivalent code!
|
||||||
* Create a TestHarness using a specific resource loader and config
|
if (container.getZkController() == null && core.getUpdateHandler().getUpdateLog() != null) {
|
||||||
* @param loader the SolrResourceLoader to use
|
// always kick off recovery if we are in standalone mode.
|
||||||
* @param config the ConfigSolr to use
|
core.getUpdateHandler().getUpdateLog().recoverFromLog();
|
||||||
*/
|
}
|
||||||
public TestHarness(SolrResourceLoader loader, ConfigSolr config) {
|
return container;
|
||||||
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() {
|
public CoreContainer getCoreContainer() {
|
||||||
|
|
Loading…
Reference in New Issue