use of org.elasticsearch.cli.Terminal in project elasticsearch by elastic.
the class Bootstrap method createEnvironment.
private static Environment createEnvironment(boolean foreground, Path pidFile, SecureSettings secureSettings, Settings initialSettings) {
Terminal terminal = foreground ? Terminal.DEFAULT : null;
Settings.Builder builder = Settings.builder();
if (pidFile != null) {
builder.put(Environment.PIDFILE_SETTING.getKey(), pidFile);
}
builder.put(initialSettings);
if (secureSettings != null) {
builder.setSecureSettings(secureSettings);
}
return InternalSettingsPreparer.prepareEnvironment(builder.build(), terminal, Collections.emptyMap());
}
use of org.elasticsearch.cli.Terminal in project elasticsearch by elastic.
the class ESElasticsearchCliTestCase method runTest.
void runTest(final int expectedStatus, final boolean expectedInit, final Consumer<String> outputConsumer, final InitConsumer initConsumer, String... args) throws Exception {
final MockTerminal terminal = new MockTerminal();
Path home = createTempDir();
try {
final AtomicBoolean init = new AtomicBoolean();
final int status = Elasticsearch.main(args, new Elasticsearch() {
@Override
protected Environment createEnv(Terminal terminal, Map<String, String> settings) {
Settings realSettings = Settings.builder().put("path.home", home).put(settings).build();
return new Environment(realSettings);
}
@Override
void init(final boolean daemonize, final Path pidFile, final boolean quiet, Environment initialEnv) {
init.set(true);
initConsumer.accept(!daemonize, pidFile, quiet, initialEnv);
}
@Override
protected boolean addShutdownHook() {
return false;
}
}, terminal);
assertThat(status, equalTo(expectedStatus));
assertThat(init.get(), equalTo(expectedInit));
outputConsumer.accept(terminal.getOutput());
} catch (Exception e) {
// if an unexpected exception is thrown, we log
// terminal output to aid debugging
logger.info(terminal.getOutput());
// rethrow so the test fails
throw e;
}
}
Aggregations