SOLR-5164: add relative solr.home testing to some tests, explicitly check for expected instanceDir handling with relative solr.home

SOLR-5099: explicity check for proper solrcore.properties creation
Speed up some tests by setting leaderVoteWait to 0

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1514857 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2013-08-16 19:12:29 +00:00
parent d9ad5bfb76
commit d0bb1cc471
6 changed files with 93 additions and 31 deletions

View File

@ -26,7 +26,6 @@ import java.util.Random;
import java.util.SortedMap; import java.util.SortedMap;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.net.URL; import java.net.URL;
import java.net.MalformedURLException; import java.net.MalformedURLException;
@ -499,6 +498,10 @@ public class JettySolrRunner {
public void setCoreNodeName(String coreNodeName) { public void setCoreNodeName(String coreNodeName) {
this.coreNodeName = coreNodeName; this.coreNodeName = coreNodeName;
} }
public String getSolrHome() {
return solrHome;
}
} }
class NoLog implements Logger { class NoLog implements Logger {

View File

@ -2241,6 +2241,7 @@ public final class SolrCore implements SolrInfoMBean {
lst.add("coreName", name==null ? "(null)" : name); lst.add("coreName", name==null ? "(null)" : name);
lst.add("startTime", new Date(startTime)); lst.add("startTime", new Date(startTime));
lst.add("refCount", getOpenCount()); lst.add("refCount", getOpenCount());
lst.add("instanceDir", resourceLoader.getInstanceDir());
lst.add("indexDir", getIndexDir()); lst.add("indexDir", getIndexDir());
CoreDescriptor cd = getCoreDescriptor(); CoreDescriptor cd = getCoreDescriptor();

View File

@ -410,7 +410,8 @@ public class CoreAdminHandler extends RequestHandlerBase {
"Missing parameter [" + CoreAdminParams.NAME + "]"); "Missing parameter [" + CoreAdminParams.NAME + "]");
String instancedir = params.get(CoreAdminParams.INSTANCE_DIR); String instancedir = params.get(CoreAdminParams.INSTANCE_DIR);
if (StringUtils.isEmpty(instancedir)) { if (StringUtils.isEmpty(instancedir)) {
instancedir = name; // Already relative to solrHome, we haven't been given an absolute path. instancedir = name; // will be resolved later against solr.home
//instancedir = container.getSolrHome() + "/" + name;
} }
Properties coreProps = new Properties(); Properties coreProps = new Properties();

View File

@ -30,7 +30,7 @@
--> -->
<cores adminPath="/admin/cores" defaultCoreName="collection1" host="127.0.0.1" hostPort="${hostPort:8983}" <cores adminPath="/admin/cores" defaultCoreName="collection1" host="127.0.0.1" hostPort="${hostPort:8983}"
hostContext="${hostContext:solr}" zkClientTimeout="${solr.zkclienttimeout:30000}" numShards="${numShards:3}" shareSchema="${shareSchema:false}" hostContext="${hostContext:solr}" zkClientTimeout="${solr.zkclienttimeout:30000}" numShards="${numShards:3}" shareSchema="${shareSchema:false}"
genericCoreNodeNames="${genericCoreNodeNames:true}" genericCoreNodeNames="${genericCoreNodeNames:true}" leaderVoteWait="0"
distribUpdateConnTimeout="${distribUpdateConnTimeout:15000}" distribUpdateSoTimeout="${distribUpdateSoTimeout:120000}"> distribUpdateConnTimeout="${distribUpdateConnTimeout:15000}" distribUpdateSoTimeout="${distribUpdateSoTimeout:120000}">
<core name="collection1" instanceDir="collection1" shard="${shard:}" collection="${collection:collection1}" config="${solrconfig:solrconfig.xml}" schema="${schema:schema.xml}" <core name="collection1" instanceDir="collection1" shard="${shard:}" collection="${collection:collection1}" config="${solrconfig:solrconfig.xml}" schema="${schema:schema.xml}"
coreNodeName="${coreNodeName:}"/> coreNodeName="${coreNodeName:}"/>

View File

@ -17,12 +17,39 @@ package org.apache.solr.cloud;
* limitations under the License. * limitations under the License.
*/ */
import static org.apache.solr.cloud.OverseerCollectionProcessor.REPLICATION_FACTOR;
import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.Future;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import org.apache.lucene.util.Constants; import org.apache.lucene.util.Constants;
import org.apache.lucene.util.LuceneTestCase.Slow; import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.lucene.util._TestUtil; import org.apache.lucene.util._TestUtil;
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.SolrServerException; import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.CloudSolrServer; import org.apache.solr.client.solrj.impl.CloudSolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer; import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer.RemoteSolrException; import org.apache.solr.client.solrj.impl.HttpSolrServer.RemoteSolrException;
@ -46,8 +73,10 @@ import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap; import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.common.util.StrUtils; import org.apache.solr.common.util.StrUtils;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrInfoMBean.Category; import org.apache.solr.core.SolrInfoMBean.Category;
import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.servlet.SolrDispatchFilter; import org.apache.solr.servlet.SolrDispatchFilter;
import org.apache.solr.update.DirectUpdateHandler2; import org.apache.solr.update.DirectUpdateHandler2;
import org.apache.solr.update.SolrCmdDistributor.Request; import org.apache.solr.update.SolrCmdDistributor.Request;
@ -55,32 +84,6 @@ import org.apache.solr.util.DefaultSolrThreadFactory;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.Future;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import static org.apache.solr.cloud.OverseerCollectionProcessor.REPLICATION_FACTOR;
/** /**
* Tests the Cloud Collections API. * Tests the Cloud Collections API.
*/ */
@ -500,6 +503,8 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
waitForRecoveriesToFinish("awholynewcollection_" + j, zkStateReader, false); waitForRecoveriesToFinish("awholynewcollection_" + j, zkStateReader, false);
} }
checkInstanceDirs(jettys.get(0));
List<String> collectionNameList = new ArrayList<String>(); List<String> collectionNameList = new ArrayList<String>();
collectionNameList.addAll(collectionInfos.keySet()); collectionNameList.addAll(collectionInfos.keySet());
String collectionName = collectionNameList.get(random().nextInt(collectionNameList.size())); String collectionName = collectionNameList.get(random().nextInt(collectionNameList.size()));
@ -658,6 +663,24 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
checkNoTwoShardsUseTheSameIndexDir(); checkNoTwoShardsUseTheSameIndexDir();
} }
private void checkInstanceDirs(JettySolrRunner jetty) {
CoreContainer cores = ((SolrDispatchFilter) jetty.getDispatchFilter()
.getFilter()).getCores();
Collection<SolrCore> theCores = cores.getCores();
for (SolrCore core : theCores) {
// look for core props file
assertTrue("Could not find expected core.properties file",
new File((String) core.getStatistics().get("instanceDir"),
"core.properties").exists());
assertEquals(
SolrResourceLoader.normalizeDir(jetty.getSolrHome() + File.separator
+ core.getName()),
SolrResourceLoader.normalizeDir((String) core.getStatistics().get(
"instanceDir")));
}
}
private boolean waitForReloads(String collectionName, Map<String,Long> urlToTimeBefore) throws SolrServerException, IOException { private boolean waitForReloads(String collectionName, Map<String,Long> urlToTimeBefore) throws SolrServerException, IOException {

View File

@ -17,8 +17,10 @@ package org.apache.solr.cloud;
* limitations under the License. * limitations under the License.
*/ */
import org.apache.commons.io.FilenameUtils;
import org.apache.http.params.CoreConnectionPNames; import org.apache.http.params.CoreConnectionPNames;
import org.apache.lucene.util.LuceneTestCase.Slow; import org.apache.lucene.util.LuceneTestCase.Slow;
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.SolrRequest; import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.SolrServer;
@ -44,6 +46,7 @@ import org.apache.solr.common.params.CollectionParams.CollectionAction;
import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.StrUtils; import org.apache.solr.common.util.StrUtils;
import org.apache.solr.core.SolrResourceLoader;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
@ -455,14 +458,45 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
} }
public JettySolrRunner createJetty(File solrHome, String dataDir, String shardList, String solrConfigOverride, String schemaOverride) throws Exception { public JettySolrRunner createJetty(File solrHome, String dataDir, String shardList, String solrConfigOverride, String schemaOverride) throws Exception {
// randomly test a relative solr.home path
JettySolrRunner jetty = new JettySolrRunner(solrHome.getAbsolutePath(), context, 0, solrConfigOverride, schemaOverride, false, getExtraServlets()); if (random().nextBoolean()) {
solrHome = getRelativeSolrHomePath(solrHome);
}
JettySolrRunner jetty = new JettySolrRunner(solrHome.getPath(), context, 0, solrConfigOverride, schemaOverride, false, getExtraServlets());
jetty.setShards(shardList); jetty.setShards(shardList);
jetty.setDataDir(getDataDir(dataDir)); jetty.setDataDir(getDataDir(dataDir));
jetty.start(); jetty.start();
return jetty; return jetty;
} }
private File getRelativeSolrHomePath(File solrHome) {
String path = SolrResourceLoader.normalizeDir(new File(".").getAbsolutePath());
String base = new File(solrHome.getPath()).getAbsolutePath();
if (base.startsWith("."));
base.replaceFirst("\\.", new File(".").getName());
if (path.endsWith(File.separator + ".")) {
path = path.substring(0, path.length() - 2);
}
int splits = path.split(File.separator).length;
StringBuilder p = new StringBuilder();
for (int i = 0; i < splits - 2; i++) {
p.append(".." + File.separator);
}
String prefix = FilenameUtils.getPrefix(path);
if (base.startsWith(prefix)) {
base = base.substring(prefix.length());
}
solrHome = new File(p.toString() + base);
return solrHome;
}
protected void updateMappingsFromZk(List<JettySolrRunner> jettys, protected void updateMappingsFromZk(List<JettySolrRunner> jettys,
List<SolrServer> clients) throws Exception { List<SolrServer> clients) throws Exception {