mirror of https://github.com/apache/lucene.git
SOLR-2170: BasicZkTest instantiates extra CoreContainer
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1023893 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
de733c1671
commit
0a19c3781d
|
@ -25,7 +25,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.solr.common.SolrException;
|
||||
import org.apache.zookeeper.KeeperException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -140,5 +139,12 @@ public class CloudState {
|
|||
|
||||
return liveNodesSet;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("live nodes:" + liveNodes);
|
||||
sb.append(" collections:" + collectionStates);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ public class CoreContainer
|
|||
protected String solrHome;
|
||||
@Deprecated
|
||||
protected String solrConfigFilenameOverride;
|
||||
private String defaultCoreName = "";
|
||||
protected String defaultCoreName = "";
|
||||
private ZkController zkController;
|
||||
private SolrZkServer zkServer;
|
||||
|
||||
|
@ -121,7 +121,7 @@ public class CoreContainer
|
|||
this.solrHome = solrHome;
|
||||
}
|
||||
|
||||
private void initZooKeeper(String zkHost, int zkClientTimeout) {
|
||||
protected void initZooKeeper(String zkHost, int zkClientTimeout) {
|
||||
// if zkHost sys property is not set, we are not using ZooKeeper
|
||||
String zookeeperHost;
|
||||
if(zkHost == null) {
|
||||
|
|
|
@ -175,12 +175,21 @@ public class TestHarness {
|
|||
}
|
||||
@Override
|
||||
public CoreContainer initialize() {
|
||||
CoreContainer container = new CoreContainer(new SolrResourceLoader(SolrResourceLoader.locateSolrHome()));
|
||||
CoreContainer container = new CoreContainer(new SolrResourceLoader(SolrResourceLoader.locateSolrHome())) {
|
||||
{
|
||||
hostPort = System.getProperty("hostPort");
|
||||
hostContext = "solr";
|
||||
defaultCoreName = "collection1";
|
||||
initZooKeeper(System.getProperty("zkHost"), 10000);
|
||||
}
|
||||
};
|
||||
|
||||
CoreDescriptor dcore = new CoreDescriptor(container, coreName, solrConfig.getResourceLoader().getInstanceDir());
|
||||
dcore.setConfigName(solrConfig.getResourceName());
|
||||
dcore.setSchemaName(indexSchema.getResourceName());
|
||||
SolrCore core = new SolrCore( null, dataDirectory, solrConfig, indexSchema, dcore);
|
||||
SolrCore core = new SolrCore("collection1", dataDirectory, solrConfig, indexSchema, dcore);
|
||||
container.register(coreName, core, false);
|
||||
|
||||
return container;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -219,8 +219,9 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
|||
if (factoryProp == null) {
|
||||
System.setProperty("solr.directoryFactory","solr.RAMDirectoryFactory");
|
||||
}
|
||||
|
||||
createTempDir();
|
||||
if (dataDir == null) {
|
||||
createTempDir();
|
||||
}
|
||||
|
||||
// other methods like starting a jetty instance need these too
|
||||
System.setProperty("solr.test.sys.prop1", "propone");
|
||||
|
|
|
@ -18,14 +18,14 @@ package org.apache.solr.cloud;
|
|||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.common.cloud.SolrZkClient;
|
||||
import org.apache.solr.common.cloud.ZkNodeProps;
|
||||
import org.apache.solr.core.CoreContainer;
|
||||
import org.apache.solr.core.SolrConfig;
|
||||
import org.apache.solr.util.TestHarness;
|
||||
import org.apache.zookeeper.CreateMode;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -46,51 +46,22 @@ public abstract class AbstractZkTestCase extends SolrTestCaseJ4 {
|
|||
|
||||
protected static String zkDir;
|
||||
|
||||
public AbstractZkTestCase() {
|
||||
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void azt_beforeClass() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
if (h != null) {
|
||||
log.warn("HACK: closing previous test harness");
|
||||
h.close();
|
||||
h=null;
|
||||
}
|
||||
|
||||
createTempDir();
|
||||
zkDir = dataDir.getAbsolutePath() + File.separator
|
||||
+ "zookeeper/server1/data";
|
||||
zkServer = new ZkTestServer(zkDir);
|
||||
zkServer.run();
|
||||
|
||||
System.setProperty("zkHost", zkServer.getZkAddress());
|
||||
System.setProperty("hostPort", "0000");
|
||||
|
||||
buildZooKeeper(zkServer.getZkHost(), zkServer.getZkAddress(),
|
||||
getSolrConfigFile(), getSchemaFile());
|
||||
|
||||
log.info("####SETUP_START " + getName());
|
||||
|
||||
dataDir.mkdirs();
|
||||
|
||||
// set some system properties for use by tests
|
||||
System.setProperty("solr.test.sys.prop1", "propone");
|
||||
System.setProperty("solr.test.sys.prop2", "proptwo");
|
||||
|
||||
CoreContainer.Initializer init = new CoreContainer.Initializer() {
|
||||
{
|
||||
this.dataDir = AbstractZkTestCase.dataDir.getAbsolutePath();
|
||||
}
|
||||
};
|
||||
|
||||
h = new TestHarness("", init);
|
||||
lrf = h.getRequestFactory("standard", 0, 20, "version", "2.2");
|
||||
|
||||
log.info("####SETUP_END " + getName());
|
||||
"solrconfig.xml", "schema.xml");
|
||||
|
||||
initCore("solrconfig.xml", "schema.xml");
|
||||
}
|
||||
|
||||
// static to share with distrib test
|
||||
|
@ -131,15 +102,20 @@ public abstract class AbstractZkTestCase extends SolrTestCaseJ4 {
|
|||
if (DEBUG) {
|
||||
printLayout(zkServer.getZkHost());
|
||||
}
|
||||
|
||||
SolrConfig.severeErrors.clear();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void azt_afterClass() throws IOException {
|
||||
zkServer.shutdown();
|
||||
System.clearProperty("zkHost");
|
||||
System.clearProperty("solr.test.sys.prop1");
|
||||
System.clearProperty("solr.test.sys.prop2");
|
||||
SolrConfig.severeErrors.clear();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
private void printLayout(String zkHost) throws Exception {
|
||||
protected void printLayout(String zkHost) throws Exception {
|
||||
SolrZkClient zkClient = new SolrZkClient(zkHost, AbstractZkTestCase.TIMEOUT);
|
||||
zkClient.printLayoutToStdOut();
|
||||
zkClient.close();
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.apache.solr.client.solrj.impl.CloudSolrServer;
|
|||
import org.apache.solr.client.solrj.response.QueryResponse;
|
||||
import org.apache.solr.common.params.CommonParams;
|
||||
import org.apache.solr.common.params.ModifiableSolrParams;
|
||||
import org.apache.solr.core.SolrConfig;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
/**
|
||||
|
@ -279,5 +278,6 @@ public class BasicDistributedZkTest extends AbstractDistributedZkTestCase {
|
|||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
System.clearProperty("CLOUD_UPDATE_DELAY");
|
||||
System.clearProperty("zkHost");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,17 +21,18 @@ import org.apache.lucene.index.LogMergePolicy;
|
|||
import org.apache.solr.core.SolrCore;
|
||||
import org.apache.solr.update.SolrIndexWriter;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class BasicZkTest extends AbstractZkTestCase {
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
initCore("solrconfig.xml", "schema.xml");
|
||||
public static void beforeClass() {
|
||||
System.setProperty("CLOUD_UPDATE_DELAY", "1");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -99,13 +100,17 @@ public class BasicZkTest extends AbstractZkTestCase {
|
|||
Thread.sleep(300);
|
||||
|
||||
// try a reconnect from disconnect
|
||||
|
||||
zkServer = new ZkTestServer(zkDir);
|
||||
zkServer.run();
|
||||
|
||||
// ensure zk still thinks node is up
|
||||
assertTrue(zkController.getCloudState().liveNodesContain(zkController.getNodeName()));
|
||||
Thread.sleep(300);
|
||||
|
||||
// ensure zk still thinks node is up
|
||||
assertTrue(
|
||||
zkController.getCloudState().getLiveNodes().toString(),
|
||||
zkController.getCloudState().liveNodesContain(
|
||||
zkController.getNodeName()));
|
||||
|
||||
// test maxint
|
||||
assertQ(req("q", "id:[100 TO 110]", "rows", "2147483647"),
|
||||
"//*[@numFound='4']");
|
||||
|
@ -124,6 +129,10 @@ public class BasicZkTest extends AbstractZkTestCase {
|
|||
assertU(delQ("id:[100 TO 110]"));
|
||||
assertU(commit());
|
||||
assertQ(req("id:[100 TO 110]"), "//*[@numFound='0']");
|
||||
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
System.clearProperty("CLOUD_UPDATE_DELAY");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,18 +27,16 @@ import org.apache.solr.common.cloud.Slice;
|
|||
import org.apache.solr.common.cloud.SolrZkClient;
|
||||
import org.apache.solr.common.cloud.ZkNodeProps;
|
||||
import org.apache.solr.core.CoreContainer;
|
||||
import org.apache.solr.core.CoreContainer.Initializer;
|
||||
import org.apache.solr.core.CoreDescriptor;
|
||||
import org.apache.solr.core.SolrConfig;
|
||||
import org.apache.solr.core.SolrCore;
|
||||
import org.apache.solr.core.CoreContainer.Initializer;
|
||||
import org.apache.zookeeper.CreateMode;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* TODO: look at hostPort used below
|
||||
*/
|
||||
|
|
|
@ -21,9 +21,7 @@ import java.io.IOException;
|
|||
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.common.cloud.ZkNodeProps;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
public class ZkNodePropsTest extends SolrTestCaseJ4 {
|
||||
|
|
|
@ -95,7 +95,6 @@ public class TestJmxIntegration extends AbstractSolrTestCase {
|
|||
}
|
||||
if (bean==null) throw new RuntimeException("searcher was never registered");
|
||||
ObjectName searcher = getObjectName("searcher", bean);
|
||||
|
||||
MBeanServer mbeanServer = servers.get(0);
|
||||
log.info("Mbeans in server: " + mbeanServer.queryNames(null, null));
|
||||
|
||||
|
@ -114,7 +113,14 @@ public class TestJmxIntegration extends AbstractSolrTestCase {
|
|||
Hashtable<String, String> map = new Hashtable<String, String>();
|
||||
map.put("type", key);
|
||||
map.put("id", infoBean.getName());
|
||||
return ObjectName.getInstance("solr", map);
|
||||
String coreName = h.getCore().getName();
|
||||
if (coreName.equals("")) {
|
||||
String defaultCoreName = h.getCore().getCoreDescriptor().getCoreContainer().getDefaultCoreName();
|
||||
if (!defaultCoreName.equals("")) {
|
||||
coreName = defaultCoreName;
|
||||
}
|
||||
}
|
||||
return ObjectName.getInstance(("solr" + (null != coreName ? "/" + coreName : "")), map);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue