Search in sources :

Example 71 with Environment

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();
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) Environment(org.elasticsearch.env.Environment) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 72 with Environment

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);
}
Also used : Path(java.nio.file.Path) FileNotFoundException(java.io.FileNotFoundException) NoSuchFileException(java.nio.file.NoSuchFileException) Environment(org.elasticsearch.env.Environment) Settings(org.elasticsearch.common.settings.Settings)

Example 73 with Environment

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);
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) Settings(org.elasticsearch.common.settings.Settings) BufferedWriter(java.io.BufferedWriter)

Example 74 with Environment

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));
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) Environment(org.elasticsearch.env.Environment) AnalysisModule(org.elasticsearch.indices.analysis.AnalysisModule)

Example 75 with Environment

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"));
}
Also used : Setting(org.elasticsearch.common.settings.Setting) Environment(org.elasticsearch.env.Environment) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

Environment (org.elasticsearch.env.Environment)130 Settings (org.elasticsearch.common.settings.Settings)84 Path (java.nio.file.Path)66 Matchers.containsString (org.hamcrest.Matchers.containsString)42 NodeEnvironment (org.elasticsearch.env.NodeEnvironment)26 TestEnvironment (org.elasticsearch.env.TestEnvironment)22 IndexSettings (org.elasticsearch.index.IndexSettings)21 UserException (org.elasticsearch.cli.UserException)17 IOException (java.io.IOException)15 AnalysisModule (org.elasticsearch.indices.analysis.AnalysisModule)9 MockTerminal (org.elasticsearch.cli.MockTerminal)8 ClusterState (org.elasticsearch.cluster.ClusterState)8 ScriptService (org.elasticsearch.script.ScriptService)8 HashMap (java.util.HashMap)7 ScriptContextRegistry (org.elasticsearch.script.ScriptContextRegistry)7 ScriptEngineRegistry (org.elasticsearch.script.ScriptEngineRegistry)7 ScriptSettings (org.elasticsearch.script.ScriptSettings)7 ArrayList (java.util.ArrayList)6 ElasticsearchException (org.elasticsearch.ElasticsearchException)6 Before (org.junit.Before)6