From 201c6447eaa95f87f2c5c0250951a68fa40a2258 Mon Sep 17 00:00:00 2001 From: Mark Robert Miller Date: Wed, 20 Oct 2010 13:24:00 +0000 Subject: [PATCH] SOLR-2127: When using the defaultCoreName attribute, after performing a swap, solr.xml no longer contains the defaultCoreName attribute, and the core which was dafult is now renamed to "" git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1025547 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/solr/core/CoreContainer.java | 1 + .../solrj/embedded/TestSolrProperties.java | 40 +++++++++++++++---- solr/src/test/test-files/solr/shared/solr.xml | 2 +- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/solr/src/java/org/apache/solr/core/CoreContainer.java b/solr/src/java/org/apache/solr/core/CoreContainer.java index 4fa3c5b4526..7cd71659bd1 100644 --- a/solr/src/java/org/apache/solr/core/CoreContainer.java +++ b/solr/src/java/org/apache/solr/core/CoreContainer.java @@ -907,6 +907,7 @@ public class CoreContainer writeAttribute(w, "adminPath",adminPath); if(adminHandler != null) writeAttribute(w, "adminHandler",adminHandler); if(shareSchema) writeAttribute(w, "shareSchema","true"); + if(!defaultCoreName.equals("")) writeAttribute(w, "defaultCoreName",defaultCoreName); w.write(">\n"); synchronized(cores) { diff --git a/solr/src/test/org/apache/solr/client/solrj/embedded/TestSolrProperties.java b/solr/src/test/org/apache/solr/client/solrj/embedded/TestSolrProperties.java index 9db8f5b0701..bed4641b9f8 100644 --- a/solr/src/test/org/apache/solr/client/solrj/embedded/TestSolrProperties.java +++ b/solr/src/test/org/apache/solr/client/solrj/embedded/TestSolrProperties.java @@ -17,7 +17,15 @@ package org.apache.solr.client.solrj.embedded; -import static junit.framework.Assert.assertEquals; +import java.io.File; +import java.io.FileInputStream; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; import org.apache.lucene.util.LuceneTestCase; import org.apache.solr.SolrTestCaseJ4; @@ -32,14 +40,12 @@ import org.apache.solr.common.SolrInputDocument; import org.apache.solr.core.CoreContainer; import org.apache.solr.util.AbstractSolrTestCase; import org.junit.After; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import org.junit.Before; import org.junit.Test; - -import java.io.File; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Node; /** * @version $Id$ @@ -48,6 +54,9 @@ import org.slf4j.LoggerFactory; public class TestSolrProperties extends LuceneTestCase { protected static Logger log = LoggerFactory.getLogger(TestSolrProperties.class); protected CoreContainer cores = null; + private File solrXml; + + private static final XPathFactory xpathFactory = XPathFactory.newInstance(); public String getSolrHome() { return "solr/shared"; @@ -64,8 +73,8 @@ public class TestSolrProperties extends LuceneTestCase { log.info("pwd: " + (new File(".")).getAbsolutePath()); File home = new File(getSolrHome()); - File f = new File(home, "solr.xml"); - cores = new CoreContainer(getSolrHome(), f); + solrXml = new File(home, "solr.xml"); + cores = new CoreContainer(getSolrHome(), solrXml); } @After @@ -175,5 +184,22 @@ public class TestSolrProperties extends LuceneTestCase { assertTrue("should have more recent time: " + after + "," + before, after > before); mcr = CoreAdminRequest.persist("solr-persist.xml", coreadmin); + + // System.out.println(IOUtils.toString(new FileInputStream(new File(solrXml.getParent(), "solr-persist.xml")))); + DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + FileInputStream fis = new FileInputStream(new File(solrXml.getParent(), "solr-persist.xml")); + try { + Document document = builder.parse(fis); + assertTrue(exists("/solr/cores[@defaultCoreName='core0']", document)); + } finally { + fis.close(); + } + + } + + public static boolean exists(String xpathStr, Node node) + throws XPathExpressionException { + XPath xpath = xpathFactory.newXPath(); + return (Boolean) xpath.evaluate(xpathStr, node, XPathConstants.BOOLEAN); } } diff --git a/solr/src/test/test-files/solr/shared/solr.xml b/solr/src/test/test-files/solr/shared/solr.xml index 2bd54c74d77..970ec198b35 100644 --- a/solr/src/test/test-files/solr/shared/solr.xml +++ b/solr/src/test/test-files/solr/shared/solr.xml @@ -30,7 +30,7 @@ adminPath: RequestHandler path to manage cores. If 'null' (or absent), cores will not be manageable via REST --> - +