SOLR-5494: CoreContainer#remove throws NPE rather than returning null when a SolrCore does not exist in core discovery mode.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1544844 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2013-11-23 17:47:56 +00:00
parent b892c597f7
commit aa253e949f
3 changed files with 23 additions and 4 deletions

View File

@ -103,6 +103,9 @@ New Features
This is intended to eventually replace the Suggester support through the
SpellCheckComponent. (Areek Zillur, Varun Thacker via shalin)
* SOLR-5494: CoreContainer#remove throws NPE rather than returning null when
a SolrCore does not exist in core discovery mode. (Mark Miller)
Bug Fixes
----------------------

View File

@ -91,7 +91,11 @@ public class CorePropertiesLocator implements CoresLocator {
@Override
public void delete(CoreContainer cc, CoreDescriptor... coreDescriptors) {
if (coreDescriptors == null) {
return;
}
for (CoreDescriptor cd : coreDescriptors) {
if (cd == null) continue;
File instanceDir = new File(cd.getInstanceDir());
File propertiesFile = new File(instanceDir, PROPERTIES_FILENAME);
propertiesFile.renameTo(new File(instanceDir, PROPERTIES_FILENAME + ".unloaded"));

View File

@ -149,7 +149,10 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
//create solrHome
File solrHomeDirectory = new File(TEMP_DIR, this.getClass().getName()
+ "_noCores");
SetUpHome(solrHomeDirectory, EMPTY_SOLR_XML);
boolean oldSolrXml = random().nextBoolean();
SetUpHome(solrHomeDirectory, oldSolrXml ? EMPTY_SOLR_XML : EMPTY_SOLR_XML2);
CoreContainer cores = new CoreContainer(solrHomeDirectory.getAbsolutePath());
cores.load();
try {
@ -166,14 +169,19 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
assertEquals("There core registered", 1, cores.getCores().size());
if (oldSolrXml) {
assertXmlFile(new File(solrHomeDirectory, "solr.xml"),
"/solr/cores[@transientCacheSize='32']");
}
newCore.close();
cores.remove("core1");
//assert cero cores
assertEquals("There should not be cores", 0, cores.getCores().size());
// try and remove a core that does not exist
SolrCore ret = cores.remove("non_existent_core");
assertNull(ret);
} finally {
cores.shutdown();
FileUtils.deleteDirectory(solrHomeDirectory);
@ -275,4 +283,8 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
" <cores adminPath=\"/admin/cores\" transientCacheSize=\"32\" >\n" +
" </cores>\n" +
"</solr>";
private static final String EMPTY_SOLR_XML2 ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
"<solr>\n" +
"</solr>";
}