SOLR-1301: Fix a couple of bugs around setting up the embedded Solr instance.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1548600 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2013-12-06 17:04:47 +00:00
parent d516948bbd
commit 00b0209844
3 changed files with 19 additions and 19 deletions

View File

@ -42,6 +42,7 @@ import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.core.HdfsDirectoryFactory;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrResourceLoader;
import org.slf4j.Logger;
@ -138,20 +139,11 @@ class SolrRecordWriter<K, V> extends RecordWriter<K, V> {
}
LOG.info("Creating embedded Solr server with solrHomeDir: " + solrHomeDir + ", fs: " + fs + ", outputShardDir: " + outputShardDir);
Properties props = new Properties();
// FIXME note this is odd (no scheme) given Solr doesn't currently
// support uris (just abs/relative path)
Path solrDataDir = new Path(outputShardDir, "data");
if (!fs.exists(solrDataDir) && !fs.mkdirs(solrDataDir)) {
throw new IOException("Unable to create " + solrDataDir);
}
String dataDirStr = solrDataDir.toUri().toString();
props.setProperty("solr.data.dir", dataDirStr);
props.setProperty("solr.home", solrHomeDir.toString());
SolrResourceLoader loader = new SolrResourceLoader(solrHomeDir.toString(),
null, props);
SolrResourceLoader loader = new SolrResourceLoader(solrHomeDir.toString(), null, null);
LOG.info(String
.format(Locale.ENGLISH,
@ -159,18 +151,25 @@ class SolrRecordWriter<K, V> extends RecordWriter<K, V> {
solrHomeDir, solrHomeDir.toUri(), loader.getInstanceDir(),
loader.getConfigDir(), dataDirStr, outputShardDir));
CoreContainer container = new CoreContainer(loader);
container.load();
CoreDescriptor descr = new CoreDescriptor(container, "core1",
".", props);
SolrCore core = container.create(descr);
container.register(core, false);
// TODO: This is fragile and should be well documented
System.setProperty("solr.directoryFactory", HdfsDirectoryFactory.class.getName());
System.setProperty("solr.lock.type", "hdfs");
System.setProperty("solr.hdfs.nrtcachingdirectory", "false");
System.setProperty("solr.hdfs.blockcache.enabled", "false");
System.setProperty("solr.autoCommit.maxTime", "-1");
System.setProperty("solr.autoSoftCommit.maxTime", "-1");
CoreContainer container = new CoreContainer(loader);
container.load();
Properties props = new Properties();
props.setProperty(CoreDescriptor.CORE_DATADIR, dataDirStr);
CoreDescriptor descr = new CoreDescriptor(container, "core1", solrHomeDir.toString(), props);
SolrCore core = container.create(descr);
container.register(core, false);
EmbeddedSolrServer solr = new EmbeddedSolrServer(container, "core1");
return solr;
}

View File

@ -45,7 +45,6 @@ public abstract class MRUnitBase extends SolrTestCaseJ4 {
}
protected void setupHadoopConfig(Configuration config) throws IOException {
config.set(SolrOutputFormat.ZIP_NAME, solrHomeZip.getName());
String tempDir = TEMP_DIR + "/test-morphlines-" + System.currentTimeMillis();
new File(tempDir).mkdirs();

View File

@ -36,6 +36,7 @@ import org.apache.lucene.util.Constants;
import org.apache.solr.common.SolrInputDocument;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@ -95,6 +96,7 @@ public class MorphlineReducerTest extends MRUnitBase {
}
@Test
@Ignore("This test cannot currently work because it uses a local filesystem output path for the indexes and Solr requires hdfs output paths")
public void testReducer() throws Exception {
MySolrReducer myReducer = new MySolrReducer();
try {