SOLR-6158: Fix configSetBaseDir path resolution

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1601758 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Alan Woodward 2014-06-10 19:48:11 +00:00
parent d3919d3b0a
commit 0b621ca842
3 changed files with 35 additions and 11 deletions

View File

@ -163,6 +163,9 @@ Bug Fixes
* SOLR-6146: Incorrect configuration such as wrong chroot in zk server address can
cause CloudSolrServer to leak resources. (Jessica Cheng, Varun Thacker, shalin)
* SOLR-6158: Relative configSetBase directories were resolved relative to the
container CWD, rather than solr.home. (Simon Endele, Alan Woodward)
Other Changes
---------------------

View File

@ -113,7 +113,7 @@ public abstract class ConfigSetService {
*/
public static class Default extends ConfigSetService {
private final String configSetBase;
private final File configSetBase;
/**
* Create a new ConfigSetService.Default
@ -122,7 +122,19 @@ public abstract class ConfigSetService {
*/
public Default(SolrResourceLoader loader, String configSetBase) {
super(loader);
this.configSetBase = configSetBase;
this.configSetBase = resolveBaseDirectory(loader, configSetBase);
}
private File resolveBaseDirectory(SolrResourceLoader loader, String configSetBase) {
File csBase = new File(configSetBase);
if (!csBase.isAbsolute())
csBase = new File(loader.getInstanceDir(), configSetBase);
return csBase;
}
// for testing
File getConfigSetBase() {
return this.configSetBase;
}
@Override

View File

@ -17,14 +17,7 @@ package org.apache.solr.core;
* limitations under the License.
*/
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.core.Is.is;
import static org.junit.internal.matchers.StringContains.containsString;
import java.io.File;
import java.io.IOException;
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
import org.apache.commons.io.FileUtils;
import org.apache.solr.SolrTestCaseJ4;
import org.junit.Rule;
@ -32,7 +25,13 @@ import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
import java.io.File;
import java.io.IOException;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.core.Is.is;
import static org.junit.internal.matchers.StringContains.containsString;
public class TestConfigSets extends SolrTestCaseJ4 {
@ -53,6 +52,16 @@ public class TestConfigSets extends SolrTestCaseJ4 {
return container;
}
@Test
public void testDefaultConfigSetBasePathResolution() throws IOException {
try (SolrResourceLoader loader = new SolrResourceLoader("/path/to/solr/home")) {
ConfigSetService.Default relativeCSS = new ConfigSetService.Default(loader, "configsets");
assertThat(relativeCSS.getConfigSetBase().getAbsolutePath(), is("/path/to/solr/home/configsets"));
ConfigSetService.Default absoluteCSS = new ConfigSetService.Default(loader, "/path/to/configsets");
assertThat(absoluteCSS.getConfigSetBase().getAbsolutePath(), is("/path/to/configsets"));
}
}
@Test
public void testConfigSetServiceFindsConfigSets() {
CoreContainer container = null;