use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class InternalScriptedMetricTests method mockScriptService.
/**
* Mock of the script service. The script that is run looks at the
* "_aggs" parameter visible when executing the script and simply returns the count.
* This should be equal to the number of input InternalScriptedMetrics that are reduced
* in total.
*/
@Override
protected ScriptService mockScriptService() {
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), "false").build();
// mock script always retuns the size of the input aggs list as result
@SuppressWarnings("unchecked") MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME, Collections.singletonMap(REDUCE_SCRIPT_NAME, script -> {
return ((List<Object>) script.get("_aggs")).size();
}));
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(scriptEngine));
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
try {
return new ScriptService(settings, new Environment(settings), null, scriptEngineRegistry, scriptContextRegistry, scriptSettings);
} catch (IOException e) {
throw new ElasticsearchException(e);
}
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class IcuTokenizerFactory method parseRules.
//parse a single RBBi rule file
private BreakIterator parseRules(String filename, Environment env) throws IOException {
final Path path = env.configFile().resolve(filename);
String rules = Files.readAllLines(path).stream().filter((v) -> v.startsWith("#") == false).collect(Collectors.joining("\n"));
return new RuleBasedBreakIterator(rules.toString());
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class IndexModuleTests method testForceCustomQueryCache.
public void testForceCustomQueryCache() throws IOException {
Settings indexSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
IndexModule module = new IndexModule(IndexSettingsModule.newIndexSettings("foo", indexSettings), new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
module.forceQueryCacheProvider((a, b) -> new CustomQueryCache());
expectThrows(AlreadySetException.class, () -> module.forceQueryCacheProvider((a, b) -> new CustomQueryCache()));
IndexService indexService = newIndexService(module);
assertTrue(indexService.cache().query() instanceof CustomQueryCache);
indexService.close("simon says", false);
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class InternalSettingsPreparerTests method testDefaultPropertiesOverride.
public void testDefaultPropertiesOverride() throws Exception {
Path configDir = homeDir.resolve("config");
Files.createDirectories(configDir);
Files.write(configDir.resolve("elasticsearch.yml"), Collections.singletonList("setting: bar"), StandardCharsets.UTF_8);
Map<String, String> props = Collections.singletonMap("default.setting", "foo");
Environment env = InternalSettingsPreparer.prepareEnvironment(baseEnvSettings, null, props);
assertEquals("bar", env.settings().get("setting"));
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class InternalSettingsPreparerTests method testDefaultProperties.
public void testDefaultProperties() throws Exception {
Map<String, String> props = Collections.singletonMap("default.setting", "foo");
Environment env = InternalSettingsPreparer.prepareEnvironment(baseEnvSettings, null, props);
assertEquals("foo", env.settings().get("setting"));
}
Aggregations