Search in sources :

Example 16 with MockTerminal

use of org.opensearch.cli.MockTerminal in project OpenSearch by opensearch-project.

the class RemoveCustomsCommandIT method testRemoveCustomsSuccessful.

public void testRemoveCustomsSuccessful() throws Exception {
    internalCluster().setBootstrapClusterManagerNodeIndex(0);
    String node = internalCluster().startNode();
    createIndex("test");
    client().admin().indices().prepareDelete("test").get();
    assertEquals(1, client().admin().cluster().prepareState().get().getState().metadata().indexGraveyard().getTombstones().size());
    Settings dataPathSettings = internalCluster().dataPathSettings(node);
    ensureStableCluster(1);
    internalCluster().stopRandomDataNode();
    Environment environment = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(dataPathSettings).build());
    MockTerminal terminal = removeCustoms(environment, false, randomBoolean() ? new String[] { "index-graveyard" } : new String[] { "index-*" });
    assertThat(terminal.getOutput(), containsString(RemoveCustomsCommand.CUSTOMS_REMOVED_MSG));
    assertThat(terminal.getOutput(), containsString("The following customs will be removed:"));
    assertThat(terminal.getOutput(), containsString("index-graveyard"));
    internalCluster().startNode(dataPathSettings);
    assertEquals(0, client().admin().cluster().prepareState().get().getState().metadata().indexGraveyard().getTombstones().size());
}
Also used : Environment(org.opensearch.env.Environment) TestEnvironment(org.opensearch.env.TestEnvironment) Matchers.containsString(org.hamcrest.Matchers.containsString) MockTerminal(org.opensearch.cli.MockTerminal) Settings(org.opensearch.common.settings.Settings)

Example 17 with MockTerminal

use of org.opensearch.cli.MockTerminal in project OpenSearch by opensearch-project.

the class RemoveCustomsCommandIT method executeCommand.

private MockTerminal executeCommand(OpenSearchNodeCommand command, Environment environment, boolean abort, String... args) throws Exception {
    final MockTerminal terminal = new MockTerminal();
    final OptionSet options = command.getParser().parse(args);
    final String input;
    if (abort) {
        input = randomValueOtherThanMany(c -> c.equalsIgnoreCase("y"), () -> randomAlphaOfLength(1));
    } else {
        input = randomBoolean() ? "y" : "Y";
    }
    terminal.addTextInput(input);
    try {
        command.execute(terminal, options, environment);
    } finally {
        assertThat(terminal.getOutput(), containsString(OpenSearchNodeCommand.STOP_WARNING_MSG));
    }
    return terminal;
}
Also used : Environment(org.opensearch.env.Environment) UserException(org.opensearch.cli.UserException) TestEnvironment(org.opensearch.env.TestEnvironment) MockTerminal(org.opensearch.cli.MockTerminal) Settings(org.opensearch.common.settings.Settings) OpenSearchException(org.opensearch.OpenSearchException) OpenSearchIntegTestCase(org.opensearch.test.OpenSearchIntegTestCase) Matchers.containsString(org.hamcrest.Matchers.containsString) OptionSet(joptsimple.OptionSet) Matchers.containsString(org.hamcrest.Matchers.containsString) OptionSet(joptsimple.OptionSet) MockTerminal(org.opensearch.cli.MockTerminal)

Example 18 with MockTerminal

use of org.opensearch.cli.MockTerminal in project OpenSearch by opensearch-project.

the class RemoveCustomsCommandIT method removeCustoms.

private MockTerminal removeCustoms(Environment environment, boolean abort, String... args) throws Exception {
    final MockTerminal terminal = executeCommand(new RemoveCustomsCommand(), environment, abort, args);
    assertThat(terminal.getOutput(), containsString(RemoveCustomsCommand.CONFIRMATION_MSG));
    assertThat(terminal.getOutput(), containsString(RemoveCustomsCommand.CUSTOMS_REMOVED_MSG));
    return terminal;
}
Also used : MockTerminal(org.opensearch.cli.MockTerminal)

Example 19 with MockTerminal

use of org.opensearch.cli.MockTerminal in project OpenSearch by opensearch-project.

the class RemoveSettingsCommandIT method executeCommand.

private MockTerminal executeCommand(OpenSearchNodeCommand command, Environment environment, boolean abort, String... args) throws Exception {
    final MockTerminal terminal = new MockTerminal();
    final OptionSet options = command.getParser().parse(args);
    final String input;
    if (abort) {
        input = randomValueOtherThanMany(c -> c.equalsIgnoreCase("y"), () -> randomAlphaOfLength(1));
    } else {
        input = randomBoolean() ? "y" : "Y";
    }
    terminal.addTextInput(input);
    try {
        command.execute(terminal, options, environment);
    } finally {
        assertThat(terminal.getOutput(), containsString(OpenSearchNodeCommand.STOP_WARNING_MSG));
    }
    return terminal;
}
Also used : Environment(org.opensearch.env.Environment) UserException(org.opensearch.cli.UserException) TestEnvironment(org.opensearch.env.TestEnvironment) MockTerminal(org.opensearch.cli.MockTerminal) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.not(org.hamcrest.Matchers.not) Settings(org.opensearch.common.settings.Settings) OpenSearchException(org.opensearch.OpenSearchException) DiskThresholdSettings(org.opensearch.cluster.routing.allocation.DiskThresholdSettings) OpenSearchIntegTestCase(org.opensearch.test.OpenSearchIntegTestCase) Matchers.containsString(org.hamcrest.Matchers.containsString) OptionSet(joptsimple.OptionSet) Matchers.containsString(org.hamcrest.Matchers.containsString) OptionSet(joptsimple.OptionSet) MockTerminal(org.opensearch.cli.MockTerminal)

Example 20 with MockTerminal

use of org.opensearch.cli.MockTerminal in project OpenSearch by opensearch-project.

the class RemoveSettingsCommandIT method removeSettings.

private MockTerminal removeSettings(Environment environment, boolean abort, String... args) throws Exception {
    final MockTerminal terminal = executeCommand(new RemoveSettingsCommand(), environment, abort, args);
    assertThat(terminal.getOutput(), containsString(RemoveSettingsCommand.CONFIRMATION_MSG));
    assertThat(terminal.getOutput(), containsString(RemoveSettingsCommand.SETTINGS_REMOVED_MSG));
    return terminal;
}
Also used : MockTerminal(org.opensearch.cli.MockTerminal)

Aggregations

MockTerminal (org.opensearch.cli.MockTerminal)51 Environment (org.opensearch.env.Environment)17 Matchers.containsString (org.hamcrest.Matchers.containsString)16 Settings (org.opensearch.common.settings.Settings)16 TestEnvironment (org.opensearch.env.TestEnvironment)16 Path (java.nio.file.Path)15 OptionSet (joptsimple.OptionSet)13 OpenSearchException (org.opensearch.OpenSearchException)12 IOException (java.io.IOException)10 OptionParser (joptsimple.OptionParser)10 Version (org.opensearch.Version)10 ClusterState (org.opensearch.cluster.ClusterState)10 NodeEnvironment (org.opensearch.env.NodeEnvironment)10 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)8 TranslogCorruptedException (org.opensearch.index.translog.TranslogCorruptedException)8 Metadata (org.opensearch.cluster.metadata.Metadata)7 IndexSettings (org.opensearch.index.IndexSettings)7 Files (java.nio.file.Files)6 Arrays (java.util.Arrays)6 Matcher (java.util.regex.Matcher)6