mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-26 14:54:56 +00:00
Convert relative paths to URI first in tests to prevent URL encoded paths
If a path to the test classes contains spaces Hunspell tests failed due to URL encoded paths. This happens on CI builds if you give the build a name containing a space. This is fixed by first converting to a URI and created a File object from the URI directly.
This commit is contained in:
parent
25c1b93d57
commit
8b617fb48f
@ -28,6 +28,8 @@ import org.apache.lucene.util.TimeUnits;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -68,5 +70,17 @@ public abstract class ElasticsearchTestCase extends AbstractRandomizedTest {
|
||||
public static String randomNumericType(Random random) {
|
||||
return numericTypes[random.nextInt(numericTypes.length)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link File} pointing to the class path relative resource given
|
||||
* as the first argument. In contrast to
|
||||
* <code>getClass().getResource(...).getFile()</code> this method will not
|
||||
* return URL encoded paths if the parent path contains spaces or other
|
||||
* non-standard characters.
|
||||
*/
|
||||
public File getResource(String relativePath) {
|
||||
URI uri = URI.create(getClass().getResource(relativePath).toString());
|
||||
return new File(uri);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ import org.elasticsearch.test.integration.AbstractNodesTests;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
@ -45,11 +44,11 @@ public class HunspellServiceTests extends AbstractNodesTests {
|
||||
public void closeNodes() {
|
||||
closeAllNodes();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLocaleDirectoryWithNodeLevelConfig() throws Exception {
|
||||
Settings settings = ImmutableSettings.settingsBuilder()
|
||||
.put("path.conf", getClass().getResource("/indices/analyze/conf_dir").getFile())
|
||||
.put("path.conf", getResource("/indices/analyze/conf_dir"))
|
||||
.put("indices.analysis.hunspell.dictionary.lazy", true)
|
||||
.put("indices.analysis.hunspell.dictionary.ignore_case", true)
|
||||
.build();
|
||||
@ -66,7 +65,7 @@ public class HunspellServiceTests extends AbstractNodesTests {
|
||||
@Test
|
||||
public void testLocaleDirectoryWithLocaleSpecificConfig() throws Exception {
|
||||
Settings settings = ImmutableSettings.settingsBuilder()
|
||||
.put("path.conf", getClass().getResource("/indices/analyze/conf_dir").getFile())
|
||||
.put("path.conf", getResource("/indices/analyze/conf_dir"))
|
||||
.put("indices.analysis.hunspell.dictionary.lazy", true)
|
||||
.put("indices.analysis.hunspell.dictionary.ignore_case", true)
|
||||
.put("indices.analysis.hunspell.dictionary.en_US.strict_affix_parsing", false)
|
||||
@ -92,7 +91,7 @@ public class HunspellServiceTests extends AbstractNodesTests {
|
||||
@Test
|
||||
public void testCustomizeLocaleDirectory() throws Exception {
|
||||
Settings settings = ImmutableSettings.settingsBuilder()
|
||||
.put("indices.analysis.hunspell.dictionary.location", getClass().getResource("/indices/analyze/conf_dir/hunspell").getFile())
|
||||
.put("indices.analysis.hunspell.dictionary.location", getResource("/indices/analyze/conf_dir/hunspell"))
|
||||
.build();
|
||||
|
||||
Node node = startNode("node1", settings);
|
||||
|
@ -24,22 +24,21 @@ import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.analysis.AnalysisService;
|
||||
import org.elasticsearch.index.analysis.HunspellTokenFilterFactory;
|
||||
import org.elasticsearch.index.analysis.TokenFilterFactory;
|
||||
import org.elasticsearch.test.integration.ElasticsearchTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class HunspellTokenFilterFactoryTests {
|
||||
|
||||
public class HunspellTokenFilterFactoryTests extends ElasticsearchTestCase {
|
||||
|
||||
@Test
|
||||
public void testDedup() throws IOException {
|
||||
Settings settings = settingsBuilder()
|
||||
.put("path.conf", getClass().getResource("/indices/analyze/conf_dir").getFile())
|
||||
.put("path.conf", getResource("/indices/analyze/conf_dir"))
|
||||
.put("index.analysis.filter.en_US.type", "hunspell")
|
||||
.put("index.analysis.filter.en_US.locale", "en_US")
|
||||
.build();
|
||||
@ -51,7 +50,7 @@ public class HunspellTokenFilterFactoryTests {
|
||||
assertThat(hunspellTokenFilter.dedup(), is(true));
|
||||
|
||||
settings = settingsBuilder()
|
||||
.put("path.conf", getClass().getResource("/indices/analyze/conf_dir").getFile())
|
||||
.put("path.conf", getResource("/indices/analyze/conf_dir"))
|
||||
.put("index.analysis.filter.en_US.type", "hunspell")
|
||||
.put("index.analysis.filter.en_US.dedup", false)
|
||||
.put("index.analysis.filter.en_US.locale", "en_US")
|
||||
@ -67,7 +66,7 @@ public class HunspellTokenFilterFactoryTests {
|
||||
@Test
|
||||
public void testDefaultRecursionLevel() throws IOException {
|
||||
Settings settings = settingsBuilder()
|
||||
.put("path.conf", getClass().getResource("/indices/analyze/conf_dir").getFile())
|
||||
.put("path.conf", getResource("/indices/analyze/conf_dir"))
|
||||
.put("index.analysis.filter.en_US.type", "hunspell")
|
||||
.put("index.analysis.filter.en_US.locale", "en_US")
|
||||
.build();
|
||||
@ -82,7 +81,7 @@ public class HunspellTokenFilterFactoryTests {
|
||||
@Test
|
||||
public void testCustomRecursionLevel() throws IOException {
|
||||
Settings settings = settingsBuilder()
|
||||
.put("path.conf", getClass().getResource("/indices/analyze/conf_dir").getFile())
|
||||
.put("path.conf", getResource("/indices/analyze/conf_dir"))
|
||||
.put("index.analysis.filter.en_US.type", "hunspell")
|
||||
.put("index.analysis.filter.en_US.recursion_level", 0)
|
||||
.put("index.analysis.filter.en_US.locale", "en_US")
|
||||
@ -98,7 +97,7 @@ public class HunspellTokenFilterFactoryTests {
|
||||
@Test(expected = ProvisionException.class)
|
||||
public void negativeRecursionLevelShouldFail() throws IOException {
|
||||
Settings settings = settingsBuilder()
|
||||
.put("path.conf", getClass().getResource("/indices/analyze/conf_dir").getFile())
|
||||
.put("path.conf", getResource("/indices/analyze/conf_dir"))
|
||||
.put("index.analysis.filter.en_US.type", "hunspell")
|
||||
.put("index.analysis.filter.en_US.recursion_level", -1)
|
||||
.put("index.analysis.filter.en_US.locale", "en_US")
|
||||
|
Loading…
x
Reference in New Issue
Block a user