Skip to content

Commit af54816

Browse files
epughmalliaridis
andauthored
SOLR-17479: Deprecate the single letter options (#2748)
--------- Co-authored-by: Christos Malliaridis <[email protected]>
1 parent f5b0129 commit af54816

File tree

5 files changed

+186
-59
lines changed

5 files changed

+186
-59
lines changed

solr/core/src/java/org/apache/solr/cli/AssertTool.java

Lines changed: 145 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,24 @@ public List<Option> getOptions() {
6363
return List.of(
6464
Option.builder("R")
6565
.desc("Asserts that we are NOT the root user.")
66-
.longOpt("not-root")
66+
.deprecated(
67+
DeprecatedAttributes.builder()
68+
.setForRemoval(true)
69+
.setSince("9.8")
70+
.setDescription("Use --not-root instead")
71+
.get())
6772
.build(),
68-
Option.builder("r").desc("Asserts that we are the root user.").longOpt("root").build(),
69-
Option.builder()
70-
.desc("Asserts that Solr is NOT running on a certain URL. Default timeout is 1000ms.")
71-
.longOpt("not-started")
72-
.hasArg(true)
73-
.argName("url")
73+
Option.builder().desc("Asserts that we are NOT the root user.").longOpt("not-root").build(),
74+
Option.builder("r")
75+
.desc("Asserts that we are the root user.")
76+
.deprecated(
77+
DeprecatedAttributes.builder()
78+
.setForRemoval(true)
79+
.setSince("9.8")
80+
.setDescription("Use --root instead")
81+
.get())
7482
.build(),
83+
Option.builder().desc("Asserts that we are the root user.").longOpt("root").build(),
7584
Option.builder("S")
7685
.desc("Asserts that Solr is NOT running on a certain URL. Default timeout is 1000ms.")
7786
.deprecated(
@@ -84,8 +93,8 @@ public List<Option> getOptions() {
8493
.argName("url")
8594
.build(),
8695
Option.builder()
87-
.desc("Asserts that Solr is running on a certain URL. Default timeout is 1000ms.")
88-
.longOpt("started")
96+
.desc("Asserts that Solr is NOT running on a certain URL. Default timeout is 1000ms.")
97+
.longOpt("not-started")
8998
.hasArg(true)
9099
.argName("url")
91100
.build(),
@@ -100,52 +109,136 @@ public List<Option> getOptions() {
100109
.hasArg(true)
101110
.argName("url")
102111
.build(),
112+
Option.builder()
113+
.desc("Asserts that Solr is running on a certain URL. Default timeout is 1000ms.")
114+
.longOpt("started")
115+
.hasArg(true)
116+
.argName("url")
117+
.build(),
103118
Option.builder()
104119
.desc("Asserts that we run as same user that owns <directory>.")
105120
.longOpt("same-user")
106121
.hasArg(true)
107122
.argName("directory")
108123
.build(),
109124
Option.builder("x")
125+
.desc("Asserts that directory <directory> exists.")
126+
.deprecated(
127+
DeprecatedAttributes.builder()
128+
.setForRemoval(true)
129+
.setSince("9.8")
130+
.setDescription("Use --exists instead")
131+
.get())
132+
.hasArg(true)
133+
.argName("directory")
134+
.build(),
135+
Option.builder()
110136
.desc("Asserts that directory <directory> exists.")
111137
.longOpt("exists")
112138
.hasArg(true)
113139
.argName("directory")
114140
.build(),
115141
Option.builder("X")
142+
.desc("Asserts that directory <directory> does NOT exist.")
143+
.deprecated(
144+
DeprecatedAttributes.builder()
145+
.setForRemoval(true)
146+
.setSince("9.8")
147+
.setDescription("Use --not-exists instead")
148+
.get())
149+
.hasArg(true)
150+
.argName("directory")
151+
.build(),
152+
Option.builder()
116153
.desc("Asserts that directory <directory> does NOT exist.")
117154
.longOpt("not-exists")
118155
.hasArg(true)
119156
.argName("directory")
120157
.build(),
121158
Option.builder("c")
159+
.desc(
160+
"Asserts that Solr is running in cloud mode. Also fails if Solr not running. URL should be for root Solr path.")
161+
.deprecated(
162+
DeprecatedAttributes.builder()
163+
.setForRemoval(true)
164+
.setSince("9.8")
165+
.setDescription("Use --cloud instead")
166+
.get())
167+
.hasArg(true)
168+
.argName("url")
169+
.build(),
170+
Option.builder()
122171
.desc(
123172
"Asserts that Solr is running in cloud mode. Also fails if Solr not running. URL should be for root Solr path.")
124173
.longOpt("cloud")
125174
.hasArg(true)
126175
.argName("url")
127176
.build(),
128177
Option.builder("C")
178+
.desc(
179+
"Asserts that Solr is not running in cloud mode. Also fails if Solr not running. URL should be for root Solr path.")
180+
.deprecated(
181+
DeprecatedAttributes.builder()
182+
.setForRemoval(true)
183+
.setSince("9.8")
184+
.setDescription("Use --not-cloud instead")
185+
.get())
186+
.hasArg(true)
187+
.argName("url")
188+
.build(),
189+
Option.builder()
129190
.desc(
130191
"Asserts that Solr is not running in cloud mode. Also fails if Solr not running. URL should be for root Solr path.")
131192
.longOpt("not-cloud")
132193
.hasArg(true)
133194
.argName("url")
134195
.build(),
135196
Option.builder("m")
197+
.desc("Exception message to be used in place of the default error message.")
198+
.deprecated(
199+
DeprecatedAttributes.builder()
200+
.setForRemoval(true)
201+
.setSince("9.8")
202+
.setDescription("Use --message instead")
203+
.get())
204+
.hasArg(true)
205+
.argName("message")
206+
.build(),
207+
Option.builder()
136208
.desc("Exception message to be used in place of the default error message.")
137209
.longOpt("message")
138210
.hasArg(true)
139211
.argName("message")
140212
.build(),
141213
Option.builder("t")
214+
.desc("Timeout in ms for commands supporting a timeout.")
215+
.deprecated(
216+
DeprecatedAttributes.builder()
217+
.setForRemoval(true)
218+
.setSince("9.8")
219+
.setDescription("Use --timeout instead")
220+
.get())
221+
.hasArg(true)
222+
.type(Long.class)
223+
.argName("ms")
224+
.build(),
225+
Option.builder()
142226
.desc("Timeout in ms for commands supporting a timeout.")
143227
.longOpt("timeout")
144228
.hasArg(true)
145229
.type(Long.class)
146230
.argName("ms")
147231
.build(),
148232
Option.builder("e")
233+
.desc("Return an exit code instead of printing error message on assert fail.")
234+
.deprecated(
235+
DeprecatedAttributes.builder()
236+
.setForRemoval(true)
237+
.setSince("9.8")
238+
.setDescription("Use --exitcode instead")
239+
.get())
240+
.build(),
241+
Option.builder()
149242
.desc("Return an exit code instead of printing error message on assert fail.")
150243
.longOpt("exitcode")
151244
.build(),
@@ -201,53 +294,91 @@ protected int runAssert(CommandLine cli) throws Exception {
201294
if (cli.hasOption("m")) {
202295
message = cli.getOptionValue("m");
203296
}
297+
if (cli.hasOption("message")) {
298+
message = cli.getOptionValue("message");
299+
}
204300
if (cli.hasOption("t")) {
205301
timeoutMs = Long.parseLong(cli.getOptionValue("t"));
206302
}
303+
if (cli.hasOption("timeout")) {
304+
timeoutMs = Long.parseLong(cli.getOptionValue("timeout"));
305+
}
207306
if (cli.hasOption("e")) {
208307
useExitCode = true;
209308
}
309+
if (cli.hasOption("exitcode")) {
310+
useExitCode = true;
311+
}
210312

211313
int ret = 0;
212-
if (cli.hasOption("r")) {
314+
if (cli.hasOption("root") || cli.hasOption("r")) {
213315
ret += assertRootUser();
214316
}
215-
if (cli.hasOption("R")) {
317+
if (cli.hasOption("not-root") || cli.hasOption("R")) {
216318
ret += assertNotRootUser();
217319
}
218320
if (cli.hasOption("x")) {
219321
ret += assertFileExists(cli.getOptionValue("x"));
220322
}
323+
if (cli.hasOption("exists")) {
324+
ret += assertFileExists(cli.getOptionValue("exists"));
325+
}
221326
if (cli.hasOption("X")) {
222327
ret += assertFileNotExists(cli.getOptionValue("X"));
223328
}
329+
if (cli.hasOption("not-exists")) {
330+
ret += assertFileNotExists(cli.getOptionValue("not-exists"));
331+
}
224332
if (cli.hasOption("same-user")) {
225333
ret += sameUser(cli.getOptionValue("same-user"));
226334
}
227-
if (cli.hasOption("s") || cli.hasOption("started")) {
335+
if (cli.hasOption("s")) {
228336
ret +=
229337
assertSolrRunning(
230-
SolrCLI.getOptionWithDeprecatedAndDefault(cli, "started", "s", null),
338+
cli.getOptionValue("s"), cli.getOptionValue(SolrCLI.OPTION_CREDENTIALS.getLongOpt()));
339+
}
340+
if (cli.hasOption("started")) {
341+
ret +=
342+
assertSolrRunning(
343+
cli.getOptionValue("started"),
231344
cli.getOptionValue(SolrCLI.OPTION_CREDENTIALS.getLongOpt()));
232345
}
233-
if (cli.hasOption("S") || cli.hasOption("not-started")) {
346+
if (cli.hasOption("S")) {
234347
ret +=
235348
assertSolrNotRunning(
236349
SolrCLI.getOptionWithDeprecatedAndDefault(cli, "not-started", "S", null),
237350
cli.getOptionValue(SolrCLI.OPTION_CREDENTIALS.getLongOpt()));
238351
}
352+
if (cli.hasOption("not-started")) {
353+
ret +=
354+
assertSolrNotRunning(
355+
cli.getOptionValue("not-started"),
356+
cli.getOptionValue(SolrCLI.OPTION_CREDENTIALS.getLongOpt()));
357+
}
239358
if (cli.hasOption("c")) {
240359
ret +=
241360
assertSolrRunningInCloudMode(
242361
SolrCLI.normalizeSolrUrl(cli.getOptionValue("c")),
243362
cli.getOptionValue(SolrCLI.OPTION_CREDENTIALS.getLongOpt()));
244363
}
364+
if (cli.hasOption("cloud")) {
365+
ret +=
366+
assertSolrRunningInCloudMode(
367+
SolrCLI.normalizeSolrUrl(cli.getOptionValue("cloud")),
368+
cli.getOptionValue(SolrCLI.OPTION_CREDENTIALS.getLongOpt()));
369+
}
245370
if (cli.hasOption("C")) {
246371
ret +=
247372
assertSolrNotRunningInCloudMode(
248373
SolrCLI.normalizeSolrUrl(cli.getOptionValue("C")),
249374
cli.getOptionValue(SolrCLI.OPTION_CREDENTIALS.getLongOpt()));
250375
}
376+
if (cli.hasOption("not-cloud")) {
377+
ret +=
378+
assertSolrNotRunningInCloudMode(
379+
SolrCLI.normalizeSolrUrl(cli.getOptionValue("not-cloud")),
380+
cli.getOptionValue(SolrCLI.OPTION_CREDENTIALS.getLongOpt()));
381+
}
251382
return ret;
252383
}
253384

solr/core/src/test/org/apache/solr/cli/AssertToolTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void raisesExitCode100OnError() throws Exception {
4545

4646
final int numAssertionsFailed = runAssertToolWithArgs(args);
4747

48-
assertEquals("Expected AssertTool to raise an error", numAssertionsFailed, 100);
48+
assertEquals("Expected AssertTool to raise an error", 100, numAssertionsFailed);
4949
}
5050

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

5858
assertEquals(
59-
"Expected AssertTool to pass assertion that directory exists", numAssertionsFailed, 0);
59+
"Expected AssertTool to pass assertion that directory exists", 0, numAssertionsFailed);
6060
}
6161

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

7272
assertEquals(
73-
"Expected AssertTool to fail assertion that directory exists", numAssertionsFailed, 1);
73+
"Expected AssertTool to fail assertion that directory exists", 1, numAssertionsFailed);
7474
}
7575

7676
@Test
@@ -82,8 +82,8 @@ public void checksForTheNonExistenceOfDirectoryThatExists() throws Exception {
8282

8383
assertEquals(
8484
"Expected AssertTool to fail assertion that directory doesnt exist",
85-
numAssertionsFailed,
86-
1);
85+
1,
86+
numAssertionsFailed);
8787
}
8888

8989
@Test
@@ -96,8 +96,8 @@ public void checksForTheNonExistenceDirectoryThatDoesntExist() throws Exception
9696

9797
assertEquals(
9898
"Expected AssertTool to fail assertion that directory doesnt exist",
99-
numAssertionsFailed,
100-
0);
99+
0,
100+
numAssertionsFailed);
101101
}
102102

103103
@Test
@@ -109,8 +109,8 @@ public void checksForThePresenceOfSolrOnCorrectUrl() throws Exception {
109109

110110
assertEquals(
111111
"Expected AssertTool to pass assertion when Solr is running on provided URL",
112-
numAssertionsFailed,
113-
0);
112+
0,
113+
numAssertionsFailed);
114114
}
115115

116116
@Test
@@ -122,8 +122,8 @@ public void checksForThePresenceOfSolrOnIncorrectUrl() throws Exception {
122122

123123
assertEquals(
124124
"Expected AssertTool to fail assertion when Solr isn't running on provided URL",
125-
numAssertionsFailed,
126-
1);
125+
1,
126+
numAssertionsFailed);
127127
}
128128

129129
@Test
@@ -135,8 +135,8 @@ public void checksForTheAbsenceOfSolrOnCorrectUrl() throws Exception {
135135

136136
assertEquals(
137137
"Expected AssertTool to fail assertion when Solr is running on provided URL",
138-
numAssertionsFailed,
139-
1);
138+
1,
139+
numAssertionsFailed);
140140
}
141141

142142
@Test
@@ -148,8 +148,8 @@ public void checksForTheAbsenceOfSolrOnIncorrectUrl() throws Exception {
148148

149149
assertEquals(
150150
"Expected AssertTool to pass assertion when Solr isn't running on provided URL",
151-
numAssertionsFailed,
152-
0);
151+
0,
152+
numAssertionsFailed);
153153
}
154154

155155
private int runAssertToolWithArgs(String[] args) throws Exception {

solr/packaging/test/test_assert.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ teardown() {
4040
run solr assert --cloud http://localhost:${SOLR_PORT}
4141
assert_output --partial "ERROR: Solr is not running in cloud mode"
4242

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

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

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

0 commit comments

Comments
 (0)