Skip to content

Commit

Permalink
SOLR-17479: Deprecate the single letter options (#2748)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Christos Malliaridis <[email protected]>
  • Loading branch information
epugh and malliaridis authored Oct 9, 2024
1 parent f5b0129 commit af54816
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 59 deletions.
159 changes: 145 additions & 14 deletions solr/core/src/java/org/apache/solr/cli/AssertTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,24 @@ public List<Option> getOptions() {
return List.of(
Option.builder("R")
.desc("Asserts that we are NOT the root user.")
.longOpt("not-root")
.deprecated(
DeprecatedAttributes.builder()
.setForRemoval(true)
.setSince("9.8")
.setDescription("Use --not-root instead")
.get())
.build(),
Option.builder("r").desc("Asserts that we are the root user.").longOpt("root").build(),
Option.builder()
.desc("Asserts that Solr is NOT running on a certain URL. Default timeout is 1000ms.")
.longOpt("not-started")
.hasArg(true)
.argName("url")
Option.builder().desc("Asserts that we are NOT the root user.").longOpt("not-root").build(),
Option.builder("r")
.desc("Asserts that we are the root user.")
.deprecated(
DeprecatedAttributes.builder()
.setForRemoval(true)
.setSince("9.8")
.setDescription("Use --root instead")
.get())
.build(),
Option.builder().desc("Asserts that we are the root user.").longOpt("root").build(),
Option.builder("S")
.desc("Asserts that Solr is NOT running on a certain URL. Default timeout is 1000ms.")
.deprecated(
Expand All @@ -84,8 +93,8 @@ public List<Option> getOptions() {
.argName("url")
.build(),
Option.builder()
.desc("Asserts that Solr is running on a certain URL. Default timeout is 1000ms.")
.longOpt("started")
.desc("Asserts that Solr is NOT running on a certain URL. Default timeout is 1000ms.")
.longOpt("not-started")
.hasArg(true)
.argName("url")
.build(),
Expand All @@ -100,52 +109,136 @@ public List<Option> getOptions() {
.hasArg(true)
.argName("url")
.build(),
Option.builder()
.desc("Asserts that Solr is running on a certain URL. Default timeout is 1000ms.")
.longOpt("started")
.hasArg(true)
.argName("url")
.build(),
Option.builder()
.desc("Asserts that we run as same user that owns <directory>.")
.longOpt("same-user")
.hasArg(true)
.argName("directory")
.build(),
Option.builder("x")
.desc("Asserts that directory <directory> exists.")
.deprecated(
DeprecatedAttributes.builder()
.setForRemoval(true)
.setSince("9.8")
.setDescription("Use --exists instead")
.get())
.hasArg(true)
.argName("directory")
.build(),
Option.builder()
.desc("Asserts that directory <directory> exists.")
.longOpt("exists")
.hasArg(true)
.argName("directory")
.build(),
Option.builder("X")
.desc("Asserts that directory <directory> does NOT exist.")
.deprecated(
DeprecatedAttributes.builder()
.setForRemoval(true)
.setSince("9.8")
.setDescription("Use --not-exists instead")
.get())
.hasArg(true)
.argName("directory")
.build(),
Option.builder()
.desc("Asserts that directory <directory> does NOT exist.")
.longOpt("not-exists")
.hasArg(true)
.argName("directory")
.build(),
Option.builder("c")
.desc(
"Asserts that Solr is running in cloud mode. Also fails if Solr not running. URL should be for root Solr path.")
.deprecated(
DeprecatedAttributes.builder()
.setForRemoval(true)
.setSince("9.8")
.setDescription("Use --cloud instead")
.get())
.hasArg(true)
.argName("url")
.build(),
Option.builder()
.desc(
"Asserts that Solr is running in cloud mode. Also fails if Solr not running. URL should be for root Solr path.")
.longOpt("cloud")
.hasArg(true)
.argName("url")
.build(),
Option.builder("C")
.desc(
"Asserts that Solr is not running in cloud mode. Also fails if Solr not running. URL should be for root Solr path.")
.deprecated(
DeprecatedAttributes.builder()
.setForRemoval(true)
.setSince("9.8")
.setDescription("Use --not-cloud instead")
.get())
.hasArg(true)
.argName("url")
.build(),
Option.builder()
.desc(
"Asserts that Solr is not running in cloud mode. Also fails if Solr not running. URL should be for root Solr path.")
.longOpt("not-cloud")
.hasArg(true)
.argName("url")
.build(),
Option.builder("m")
.desc("Exception message to be used in place of the default error message.")
.deprecated(
DeprecatedAttributes.builder()
.setForRemoval(true)
.setSince("9.8")
.setDescription("Use --message instead")
.get())
.hasArg(true)
.argName("message")
.build(),
Option.builder()
.desc("Exception message to be used in place of the default error message.")
.longOpt("message")
.hasArg(true)
.argName("message")
.build(),
Option.builder("t")
.desc("Timeout in ms for commands supporting a timeout.")
.deprecated(
DeprecatedAttributes.builder()
.setForRemoval(true)
.setSince("9.8")
.setDescription("Use --timeout instead")
.get())
.hasArg(true)
.type(Long.class)
.argName("ms")
.build(),
Option.builder()
.desc("Timeout in ms for commands supporting a timeout.")
.longOpt("timeout")
.hasArg(true)
.type(Long.class)
.argName("ms")
.build(),
Option.builder("e")
.desc("Return an exit code instead of printing error message on assert fail.")
.deprecated(
DeprecatedAttributes.builder()
.setForRemoval(true)
.setSince("9.8")
.setDescription("Use --exitcode instead")
.get())
.build(),
Option.builder()
.desc("Return an exit code instead of printing error message on assert fail.")
.longOpt("exitcode")
.build(),
Expand Down Expand Up @@ -201,53 +294,91 @@ protected int runAssert(CommandLine cli) throws Exception {
if (cli.hasOption("m")) {
message = cli.getOptionValue("m");
}
if (cli.hasOption("message")) {
message = cli.getOptionValue("message");
}
if (cli.hasOption("t")) {
timeoutMs = Long.parseLong(cli.getOptionValue("t"));
}
if (cli.hasOption("timeout")) {
timeoutMs = Long.parseLong(cli.getOptionValue("timeout"));
}
if (cli.hasOption("e")) {
useExitCode = true;
}
if (cli.hasOption("exitcode")) {
useExitCode = true;
}

int ret = 0;
if (cli.hasOption("r")) {
if (cli.hasOption("root") || cli.hasOption("r")) {
ret += assertRootUser();
}
if (cli.hasOption("R")) {
if (cli.hasOption("not-root") || cli.hasOption("R")) {
ret += assertNotRootUser();
}
if (cli.hasOption("x")) {
ret += assertFileExists(cli.getOptionValue("x"));
}
if (cli.hasOption("exists")) {
ret += assertFileExists(cli.getOptionValue("exists"));
}
if (cli.hasOption("X")) {
ret += assertFileNotExists(cli.getOptionValue("X"));
}
if (cli.hasOption("not-exists")) {
ret += assertFileNotExists(cli.getOptionValue("not-exists"));
}
if (cli.hasOption("same-user")) {
ret += sameUser(cli.getOptionValue("same-user"));
}
if (cli.hasOption("s") || cli.hasOption("started")) {
if (cli.hasOption("s")) {
ret +=
assertSolrRunning(
SolrCLI.getOptionWithDeprecatedAndDefault(cli, "started", "s", null),
cli.getOptionValue("s"), cli.getOptionValue(SolrCLI.OPTION_CREDENTIALS.getLongOpt()));
}
if (cli.hasOption("started")) {
ret +=
assertSolrRunning(
cli.getOptionValue("started"),
cli.getOptionValue(SolrCLI.OPTION_CREDENTIALS.getLongOpt()));
}
if (cli.hasOption("S") || cli.hasOption("not-started")) {
if (cli.hasOption("S")) {
ret +=
assertSolrNotRunning(
SolrCLI.getOptionWithDeprecatedAndDefault(cli, "not-started", "S", null),
cli.getOptionValue(SolrCLI.OPTION_CREDENTIALS.getLongOpt()));
}
if (cli.hasOption("not-started")) {
ret +=
assertSolrNotRunning(
cli.getOptionValue("not-started"),
cli.getOptionValue(SolrCLI.OPTION_CREDENTIALS.getLongOpt()));
}
if (cli.hasOption("c")) {
ret +=
assertSolrRunningInCloudMode(
SolrCLI.normalizeSolrUrl(cli.getOptionValue("c")),
cli.getOptionValue(SolrCLI.OPTION_CREDENTIALS.getLongOpt()));
}
if (cli.hasOption("cloud")) {
ret +=
assertSolrRunningInCloudMode(
SolrCLI.normalizeSolrUrl(cli.getOptionValue("cloud")),
cli.getOptionValue(SolrCLI.OPTION_CREDENTIALS.getLongOpt()));
}
if (cli.hasOption("C")) {
ret +=
assertSolrNotRunningInCloudMode(
SolrCLI.normalizeSolrUrl(cli.getOptionValue("C")),
cli.getOptionValue(SolrCLI.OPTION_CREDENTIALS.getLongOpt()));
}
if (cli.hasOption("not-cloud")) {
ret +=
assertSolrNotRunningInCloudMode(
SolrCLI.normalizeSolrUrl(cli.getOptionValue("not-cloud")),
cli.getOptionValue(SolrCLI.OPTION_CREDENTIALS.getLongOpt()));
}
return ret;
}

Expand Down
30 changes: 15 additions & 15 deletions solr/core/src/test/org/apache/solr/cli/AssertToolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void raisesExitCode100OnError() throws Exception {

final int numAssertionsFailed = runAssertToolWithArgs(args);

assertEquals("Expected AssertTool to raise an error", numAssertionsFailed, 100);
assertEquals("Expected AssertTool to raise an error", 100, numAssertionsFailed);
}

@Test
Expand All @@ -56,7 +56,7 @@ public void checksForTheExistenceOfDirectoryThatExists() throws Exception {
final int numAssertionsFailed = runAssertToolWithArgs(args);

assertEquals(
"Expected AssertTool to pass assertion that directory exists", numAssertionsFailed, 0);
"Expected AssertTool to pass assertion that directory exists", 0, numAssertionsFailed);
}

@Test
Expand All @@ -70,7 +70,7 @@ public void checksForTheExistenceOfDirectoryThatDoesntExist() throws Exception {
final int numAssertionsFailed = runAssertToolWithArgs(args);

assertEquals(
"Expected AssertTool to fail assertion that directory exists", numAssertionsFailed, 1);
"Expected AssertTool to fail assertion that directory exists", 1, numAssertionsFailed);
}

@Test
Expand All @@ -82,8 +82,8 @@ public void checksForTheNonExistenceOfDirectoryThatExists() throws Exception {

assertEquals(
"Expected AssertTool to fail assertion that directory doesnt exist",
numAssertionsFailed,
1);
1,
numAssertionsFailed);
}

@Test
Expand All @@ -96,8 +96,8 @@ public void checksForTheNonExistenceDirectoryThatDoesntExist() throws Exception

assertEquals(
"Expected AssertTool to fail assertion that directory doesnt exist",
numAssertionsFailed,
0);
0,
numAssertionsFailed);
}

@Test
Expand All @@ -109,8 +109,8 @@ public void checksForThePresenceOfSolrOnCorrectUrl() throws Exception {

assertEquals(
"Expected AssertTool to pass assertion when Solr is running on provided URL",
numAssertionsFailed,
0);
0,
numAssertionsFailed);
}

@Test
Expand All @@ -122,8 +122,8 @@ public void checksForThePresenceOfSolrOnIncorrectUrl() throws Exception {

assertEquals(
"Expected AssertTool to fail assertion when Solr isn't running on provided URL",
numAssertionsFailed,
1);
1,
numAssertionsFailed);
}

@Test
Expand All @@ -135,8 +135,8 @@ public void checksForTheAbsenceOfSolrOnCorrectUrl() throws Exception {

assertEquals(
"Expected AssertTool to fail assertion when Solr is running on provided URL",
numAssertionsFailed,
1);
1,
numAssertionsFailed);
}

@Test
Expand All @@ -148,8 +148,8 @@ public void checksForTheAbsenceOfSolrOnIncorrectUrl() throws Exception {

assertEquals(
"Expected AssertTool to pass assertion when Solr isn't running on provided URL",
numAssertionsFailed,
0);
0,
numAssertionsFailed);
}

private int runAssertToolWithArgs(String[] args) throws Exception {
Expand Down
4 changes: 2 additions & 2 deletions solr/packaging/test/test_assert.bats
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ teardown() {
run solr assert --cloud http://localhost:${SOLR_PORT}
assert_output --partial "ERROR: Solr is not running in cloud mode"

run ! solr assert --cloud http://localhost:${SOLR_PORT} -e
run ! solr assert --cloud http://localhost:${SOLR_PORT} --exitcode
}

@test "assert for cloud mode" {
Expand All @@ -54,5 +54,5 @@ teardown() {
assert_output --partial "needn't include Solr's context-root"
assert_output --partial "ERROR: Solr is not running in standalone mode"

run ! solr assert --not-cloud http://localhost:${SOLR_PORT} -e
run ! solr assert --not-cloud http://localhost:${SOLR_PORT} --exitcode
}
Loading

0 comments on commit af54816

Please sign in to comment.