Search in sources :

Example 46 with MockTerminal

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

the class OverrideNodeVersionCommandTests method testOverwritesIfTooOld.

public void testOverwritesIfTooOld() throws Exception {
    final Version nodeVersion = NodeMetadataTests.tooOldVersion();
    PersistedClusterStateService.overrideVersion(nodeVersion, nodePaths);
    final MockTerminal mockTerminal = new MockTerminal();
    mockTerminal.addTextInput(randomFrom("y", "Y"));
    new OverrideNodeVersionCommand().processNodePaths(mockTerminal, nodePaths, 0, noOptions, environment);
    assertThat(mockTerminal.getOutput(), allOf(containsString("too old"), containsString("data loss"), containsString("You should not use this tool"), containsString(Version.CURRENT.toString()), containsString(nodeVersion.toString()), containsString(OverrideNodeVersionCommand.SUCCESS_MESSAGE)));
    expectThrows(IllegalStateException.class, () -> mockTerminal.readText(""));
    final NodeMetadata nodeMetadata = PersistedClusterStateService.nodeMetadata(nodePaths);
    assertThat(nodeMetadata.nodeVersion(), equalTo(Version.CURRENT));
}
Also used : Version(org.opensearch.Version) MockTerminal(org.opensearch.cli.MockTerminal)

Example 47 with MockTerminal

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

the class OverrideNodeVersionCommandTests method testFailsOnEmptyPath.

public void testFailsOnEmptyPath() {
    final Path emptyPath = createTempDir();
    final MockTerminal mockTerminal = new MockTerminal();
    final OpenSearchException openSearchException = expectThrows(OpenSearchException.class, () -> new OverrideNodeVersionCommand().processNodePaths(mockTerminal, new Path[] { emptyPath }, 0, noOptions, environment));
    assertThat(openSearchException.getMessage(), equalTo(OverrideNodeVersionCommand.NO_METADATA_MESSAGE));
    expectThrows(IllegalStateException.class, () -> mockTerminal.readText(""));
}
Also used : Path(java.nio.file.Path) OpenSearchException(org.opensearch.OpenSearchException) MockTerminal(org.opensearch.cli.MockTerminal)

Example 48 with MockTerminal

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

the class OverrideNodeVersionCommandTests method testWarnsIfTooNew.

public void testWarnsIfTooNew() throws Exception {
    final Version nodeVersion = NodeMetadataTests.tooNewVersion();
    PersistedClusterStateService.overrideVersion(nodeVersion, nodePaths);
    final MockTerminal mockTerminal = new MockTerminal();
    mockTerminal.addTextInput(randomFrom("yy", "Yy", "n", "yes", "true", "N", "no"));
    final OpenSearchException openSearchException = expectThrows(OpenSearchException.class, () -> new OverrideNodeVersionCommand().processNodePaths(mockTerminal, nodePaths, 0, noOptions, environment));
    assertThat(openSearchException.getMessage(), equalTo("aborted by user"));
    assertThat(mockTerminal.getOutput(), allOf(containsString("data loss"), containsString("You should not use this tool"), containsString(Version.CURRENT.toString()), containsString(nodeVersion.toString())));
    expectThrows(IllegalStateException.class, () -> mockTerminal.readText(""));
    final NodeMetadata nodeMetadata = PersistedClusterStateService.nodeMetadata(nodePaths);
    assertThat(nodeMetadata.nodeVersion(), equalTo(nodeVersion));
}
Also used : Version(org.opensearch.Version) OpenSearchException(org.opensearch.OpenSearchException) MockTerminal(org.opensearch.cli.MockTerminal)

Example 49 with MockTerminal

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

the class OverrideNodeVersionCommandTests method testWarnsIfTooOld.

public void testWarnsIfTooOld() throws Exception {
    final Version nodeVersion = NodeMetadataTests.tooOldVersion();
    PersistedClusterStateService.overrideVersion(nodeVersion, nodePaths);
    final MockTerminal mockTerminal = new MockTerminal();
    mockTerminal.addTextInput("n\n");
    final OpenSearchException openSearchException = expectThrows(OpenSearchException.class, () -> new OverrideNodeVersionCommand().processNodePaths(mockTerminal, nodePaths, 0, noOptions, environment));
    assertThat(openSearchException.getMessage(), equalTo("aborted by user"));
    assertThat(mockTerminal.getOutput(), allOf(containsString("too old"), containsString("data loss"), containsString("You should not use this tool"), containsString(Version.CURRENT.toString()), containsString(nodeVersion.toString())));
    expectThrows(IllegalStateException.class, () -> mockTerminal.readText(""));
    final NodeMetadata nodeMetadata = PersistedClusterStateService.nodeMetadata(nodePaths);
    assertThat(nodeMetadata.nodeVersion(), equalTo(nodeVersion));
}
Also used : Version(org.opensearch.Version) OpenSearchException(org.opensearch.OpenSearchException) MockTerminal(org.opensearch.cli.MockTerminal)

Example 50 with MockTerminal

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

the class OverrideNodeVersionCommandTests method testFailsIfUnnecessary.

public void testFailsIfUnnecessary() throws IOException {
    final Version nodeVersion = Version.fromId(between(Version.CURRENT.minimumIndexCompatibilityVersion().id, Version.CURRENT.id));
    PersistedClusterStateService.overrideVersion(nodeVersion, nodePaths);
    final MockTerminal mockTerminal = new MockTerminal();
    final OpenSearchException openSearchException = expectThrows(OpenSearchException.class, () -> new OverrideNodeVersionCommand().processNodePaths(mockTerminal, nodePaths, 0, noOptions, environment));
    assertThat(openSearchException.getMessage(), allOf(containsString("compatible with current version"), containsString(Version.CURRENT.toString()), containsString(nodeVersion.toString())));
    expectThrows(IllegalStateException.class, () -> mockTerminal.readText(""));
}
Also used : Version(org.opensearch.Version) OpenSearchException(org.opensearch.OpenSearchException) MockTerminal(org.opensearch.cli.MockTerminal)

Aggregations

MockTerminal (org.opensearch.cli.MockTerminal)50 Environment (org.opensearch.env.Environment)16 Path (java.nio.file.Path)15 Matchers.containsString (org.hamcrest.Matchers.containsString)15 Settings (org.opensearch.common.settings.Settings)15 TestEnvironment (org.opensearch.env.TestEnvironment)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)9 NodeEnvironment (org.opensearch.env.NodeEnvironment)9 TranslogCorruptedException (org.opensearch.index.translog.TranslogCorruptedException)8 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)7 IndexSettings (org.opensearch.index.IndexSettings)7 Files (java.nio.file.Files)6 Arrays (java.util.Arrays)6 Matcher (java.util.regex.Matcher)6 Pattern (java.util.regex.Pattern)6