Search in sources :

Example 11 with MockTerminal

use of org.elasticsearch.cli.MockTerminal 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;
    }
}
Also used : Path(java.nio.file.Path) MockTerminal(org.elasticsearch.cli.MockTerminal) MockTerminal(org.elasticsearch.cli.MockTerminal) Terminal(org.elasticsearch.cli.Terminal) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Environment(org.elasticsearch.env.Environment) Settings(org.elasticsearch.common.settings.Settings)

Example 12 with MockTerminal

use of org.elasticsearch.cli.MockTerminal in project elasticsearch by elastic.

the class InstallPluginCommandTests method testOfficialPluginsIncludesXpack.

public void testOfficialPluginsIncludesXpack() throws Exception {
    MockTerminal terminal = new MockTerminal();
    new InstallPluginCommand() {

        @Override
        protected boolean addShutdownHook() {
            return false;
        }
    }.main(new String[] { "--help" }, terminal);
    assertTrue(terminal.getOutput(), terminal.getOutput().contains("x-pack"));
}
Also used : MockTerminal(org.elasticsearch.cli.MockTerminal)

Example 13 with MockTerminal

use of org.elasticsearch.cli.MockTerminal in project elasticsearch by elastic.

the class ListPluginsCommandTests method testPluginWithoutVerboseMultiplePlugins.

public void testPluginWithoutVerboseMultiplePlugins() throws Exception {
    buildFakePlugin(env, "fake desc 1", "fake_plugin1", "org.fake");
    buildFakePlugin(env, "fake desc 2", "fake_plugin2", "org.fake2");
    MockTerminal terminal = listPlugins(home, new String[0]);
    String output = terminal.getOutput();
    assertEquals(output, buildMultiline("fake_plugin1", "fake_plugin2"));
}
Also used : MockTerminal(org.elasticsearch.cli.MockTerminal)

Example 14 with MockTerminal

use of org.elasticsearch.cli.MockTerminal in project elasticsearch by elastic.

the class ListPluginsCommandTests method testNoPlugins.

public void testNoPlugins() throws Exception {
    MockTerminal terminal = listPlugins(home);
    assertTrue(terminal.getOutput(), terminal.getOutput().isEmpty());
}
Also used : MockTerminal(org.elasticsearch.cli.MockTerminal)

Example 15 with MockTerminal

use of org.elasticsearch.cli.MockTerminal in project elasticsearch by elastic.

the class ListPluginsCommandTests method testPluginWithVerbose.

public void testPluginWithVerbose() throws Exception {
    buildFakePlugin(env, "fake desc", "fake_plugin", "org.fake");
    String[] params = { "-v" };
    MockTerminal terminal = listPlugins(home, params);
    assertEquals(terminal.getOutput(), buildMultiline("Plugins directory: " + env.pluginsFile(), "fake_plugin", "- Plugin information:", "Name: fake_plugin", "Description: fake desc", "Version: 1.0", " * Classname: org.fake"));
}
Also used : MockTerminal(org.elasticsearch.cli.MockTerminal)

Aggregations

MockTerminal (org.elasticsearch.cli.MockTerminal)20 Path (java.nio.file.Path)5 Environment (org.elasticsearch.env.Environment)3 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 UserException (org.elasticsearch.cli.UserException)2 Settings (org.elasticsearch.common.settings.Settings)2 MalformedURLException (java.net.MalformedURLException)1 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 OptionParser (joptsimple.OptionParser)1 OptionSet (joptsimple.OptionSet)1 Directory (org.apache.lucene.store.Directory)1 FSDirectory (org.apache.lucene.store.FSDirectory)1 Lock (org.apache.lucene.store.Lock)1 LockObtainFailedException (org.apache.lucene.store.LockObtainFailedException)1 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)1 SearchPhaseExecutionException (org.elasticsearch.action.search.SearchPhaseExecutionException)1