use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class AnalysisRegistryTests method testCloseIndexAnalyzersMultipleTimes.
public void testCloseIndexAnalyzersMultipleTimes() throws IOException {
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", indexSettings);
IndexAnalyzers indexAnalyzers = new AnalysisRegistry(new Environment(settings), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()).build(idxSettings);
indexAnalyzers.close();
indexAnalyzers.close();
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class AnalysisTests method testParseNonExistingFile.
public void testParseNonExistingFile() {
Path tempDir = createTempDir();
Settings nodeSettings = Settings.builder().put("foo.bar_path", tempDir.resolve("foo.dict")).put(Environment.PATH_HOME_SETTING.getKey(), tempDir).build();
Environment env = new Environment(nodeSettings);
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> Analysis.getWordList(env, nodeSettings, "foo.bar"));
assertEquals("IOException while reading foo.bar_path: " + tempDir.resolve("foo.dict").toString(), ex.getMessage());
assertTrue(ex.getCause().toString(), ex.getCause() instanceof FileNotFoundException || ex.getCause() instanceof NoSuchFileException);
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class AnalysisTests method testParseWordList.
public void testParseWordList() throws IOException {
Path tempDir = createTempDir();
Path dict = tempDir.resolve("foo.dict");
Settings nodeSettings = Settings.builder().put("foo.bar_path", dict).put(Environment.PATH_HOME_SETTING.getKey(), tempDir).build();
try (BufferedWriter writer = Files.newBufferedWriter(dict, StandardCharsets.UTF_8)) {
writer.write("hello");
writer.write('\n');
writer.write("world");
writer.write('\n');
}
Environment env = new Environment(nodeSettings);
List<String> wordList = Analysis.getWordList(env, nodeSettings, "foo.bar");
assertEquals(Arrays.asList("hello", "world"), wordList);
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class AnalysisTestsHelper method createTestAnalysisFromSettings.
public static ESTestCase.TestAnalysis createTestAnalysisFromSettings(Settings settings) throws IOException {
if (settings.get(IndexMetaData.SETTING_VERSION_CREATED) == null) {
settings = Settings.builder().put(settings).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
}
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("test", settings);
AnalysisRegistry analysisRegistry = new AnalysisModule(new Environment(settings), emptyList()).getAnalysisRegistry();
return new ESTestCase.TestAnalysis(analysisRegistry.build(indexSettings), analysisRegistry.buildTokenFilterFactories(indexSettings), analysisRegistry.buildTokenizerFactories(indexSettings), analysisRegistry.buildCharFilterFactories(indexSettings));
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class NativeScriptTests method testNativeScript.
public void testNativeScript() throws InterruptedException {
Settings settings = Settings.builder().put("node.name", "testNativeScript").put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), false).build();
ScriptModule scriptModule = new ScriptModule(settings, new Environment(settings), null, singletonList(new NativeScriptEngineService(settings, singletonMap("my", new MyNativeScriptFactory()))), emptyList());
List<Setting<?>> scriptSettings = scriptModule.getSettings();
scriptSettings.add(InternalSettingsPlugin.VERSION_CREATED);
ExecutableScript executable = scriptModule.getScriptService().executable(new Script(ScriptType.INLINE, NativeScriptEngineService.NAME, "my", Collections.emptyMap()), ScriptContext.Standard.SEARCH);
assertThat(executable.run().toString(), equalTo("test"));
}
Aggregations