Skip to content

Commit cbadc56

Browse files
committed
Make sure wrong value for boolean option returns error
1 parent deb24b9 commit cbadc56

File tree

3 files changed

+362
-18
lines changed

3 files changed

+362
-18
lines changed

src/main/java/com/rabbitmq/stream/perf/Converters.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ final class Converters {
4343
private static final CommandLine.ITypeConverter<Duration> DURATION_TYPE_CONVERTER =
4444
new DurationTypeConverter();
4545

46+
static final CommandLine.ITypeConverter<Boolean> BOOLEAN_TYPE_CONVERTER = new BooleanConverter();
47+
4648
private Converters() {}
4749

4850
static void typeConversionException(String message) {
@@ -434,6 +436,18 @@ public Integer convert(String input) {
434436
}
435437
}
436438

439+
static class BooleanConverter implements CommandLine.ITypeConverter<Boolean> {
440+
441+
@Override
442+
public Boolean convert(String value) {
443+
if ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)) {
444+
return Boolean.parseBoolean(value);
445+
} else {
446+
throw new CommandLine.TypeConversionException("'" + value + "' is not a boolean");
447+
}
448+
}
449+
}
450+
437451
private static void throwConversionException(String format, String... arguments) {
438452
throw new CommandLine.TypeConversionException(String.format(format, (Object[]) arguments));
439453
}

src/main/java/com/rabbitmq/stream/perf/StreamPerfTest.java

Lines changed: 120 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
name = "stream-perf-test",
9595
mixinStandardHelpOptions = false,
9696
showDefaultValues = true,
97+
separator = " ",
9798
description = "Tests the performance of stream queues in RabbitMQ.")
9899
public class StreamPerfTest implements Callable<Integer> {
99100

@@ -169,8 +170,14 @@ public class StreamPerfTest implements Callable<Integer> {
169170
@CommandLine.Option(
170171
names = {"--delete-streams", "-ds"},
171172
description = "whether to delete stream(s) after the run or not",
173+
arity = "0..1",
174+
fallbackValue = "true",
172175
defaultValue = "false")
173-
private boolean deleteStreams;
176+
void setDeleteStreams(String input) throws Exception {
177+
this.deleteStreams = Converters.BOOLEAN_TYPE_CONVERTER.convert(input);
178+
}
179+
180+
boolean deleteStreams;
174181

175182
@CommandLine.Option(
176183
names = {"--offset", "-o"},
@@ -265,14 +272,26 @@ public class StreamPerfTest implements Callable<Integer> {
265272
@CommandLine.Option(
266273
names = {"--version", "-v"},
267274
description = "show version information",
275+
arity = "0..1",
276+
fallbackValue = "true",
268277
defaultValue = "false")
269-
private boolean version;
278+
void setVersion(String input) throws Exception {
279+
this.version = Converters.BOOLEAN_TYPE_CONVERTER.convert(input);
280+
}
281+
282+
boolean version;
270283

271284
@CommandLine.Option(
272285
names = {"--summary-file", "-sf"},
273286
description = "generate a summary file with metrics",
287+
arity = "0..1",
288+
fallbackValue = "true",
274289
defaultValue = "false")
275-
private boolean summaryFile;
290+
void setSummaryFile(String input) throws Exception {
291+
this.summaryFile = Converters.BOOLEAN_TYPE_CONVERTER.convert(input);
292+
}
293+
294+
boolean summaryFile;
276295

277296
@CommandLine.Option(
278297
names = {"--producers-by-connection", "-pbc"},
@@ -309,8 +328,14 @@ public class StreamPerfTest implements Callable<Integer> {
309328
@CommandLine.Option(
310329
names = {"--load-balancer", "-lb"},
311330
description = "assume URIs point to a load balancer",
331+
arity = "0..1",
332+
fallbackValue = "true",
312333
defaultValue = "false")
313-
private boolean loadBalancer;
334+
void setLoadBalancer(String input) throws Exception {
335+
this.loadBalancer = Converters.BOOLEAN_TYPE_CONVERTER.convert(input);
336+
}
337+
338+
boolean loadBalancer;
314339

315340
@CommandLine.Option(
316341
names = {"--consumer-names", "-cn"},
@@ -324,14 +349,26 @@ public class StreamPerfTest implements Callable<Integer> {
324349
@CommandLine.Option(
325350
names = {"--metrics-byte-rates", "-mbr"},
326351
description = "include written and read byte rates in metrics",
352+
arity = "0..1",
353+
fallbackValue = "true",
327354
defaultValue = "false")
328-
private boolean includeByteRates;
355+
void setIncludeByteRates(String input) throws Exception {
356+
this.includeByteRates = Converters.BOOLEAN_TYPE_CONVERTER.convert(input);
357+
}
358+
359+
boolean includeByteRates;
329360

330361
@CommandLine.Option(
331362
names = {"--memory-report", "-mr"},
332363
description = "report information on memory settings and usage",
364+
arity = "0..1",
365+
fallbackValue = "true",
333366
defaultValue = "false")
334-
private boolean memoryReport;
367+
void setMemoryReport(String input) throws Exception {
368+
this.memoryReport = Converters.BOOLEAN_TYPE_CONVERTER.convert(input);
369+
}
370+
371+
boolean memoryReport;
335372

336373
@CommandLine.Option(
337374
names = {"--server-name-indication", "-sni"},
@@ -349,8 +386,14 @@ public class StreamPerfTest implements Callable<Integer> {
349386
@CommandLine.Option(
350387
names = {"--environment-variables", "-env"},
351388
description = "show usage with environment variables",
389+
arity = "0..1",
390+
fallbackValue = "true",
352391
defaultValue = "false")
353-
private boolean environmentVariables;
392+
void setEnvironmentVariables(String input) throws Exception {
393+
this.environmentVariables = Converters.BOOLEAN_TYPE_CONVERTER.convert(input);
394+
}
395+
396+
boolean environmentVariables;
354397

355398
@CommandLine.Option(
356399
names = {"--rpc-timeout", "-rt"},
@@ -362,14 +405,26 @@ public class StreamPerfTest implements Callable<Integer> {
362405
@CommandLine.Option(
363406
names = {"--confirm-latency", "-cl"},
364407
description = "evaluate confirm latency",
408+
arity = "0..1",
409+
fallbackValue = "true",
365410
defaultValue = "false")
366-
private boolean confirmLatency;
411+
void setConfirmLatency(String input) throws Exception {
412+
this.confirmLatency = Converters.BOOLEAN_TYPE_CONVERTER.convert(input);
413+
}
414+
415+
boolean confirmLatency;
367416

368417
@CommandLine.Option(
369418
names = {"--super-streams", "-sst"},
370419
description = "use super streams (RabbitMQ 3.13+)",
420+
arity = "0..1",
421+
fallbackValue = "true",
371422
defaultValue = "false")
372-
private boolean superStreams;
423+
void setSuperStreams(String input) throws Exception {
424+
this.superStreams = Converters.BOOLEAN_TYPE_CONVERTER.convert(input);
425+
}
426+
427+
boolean superStreams;
373428

374429
@CommandLine.Option(
375430
names = {"--super-stream-partitions", "-ssp"},
@@ -381,8 +436,14 @@ public class StreamPerfTest implements Callable<Integer> {
381436
@CommandLine.Option(
382437
names = {"--single-active-consumer", "-sac"},
383438
description = "use single active consumer",
439+
arity = "0..1",
440+
fallbackValue = "true",
384441
defaultValue = "false")
385-
private boolean singleActiveConsumer;
442+
void setSingleActiveConsumer(String input) throws Exception {
443+
this.singleActiveConsumer = Converters.BOOLEAN_TYPE_CONVERTER.convert(input);
444+
}
445+
446+
boolean singleActiveConsumer;
386447

387448
@CommandLine.Option(
388449
names = {"--amqp-uri", "-au"},
@@ -406,8 +467,14 @@ public class StreamPerfTest implements Callable<Integer> {
406467
@CommandLine.Option(
407468
names = {"--metrics-command-line-arguments", "-mcla"},
408469
description = "add fixed metrics with command line arguments label",
470+
arity = "0..1",
471+
fallbackValue = "true",
409472
defaultValue = "false")
410-
private boolean metricsCommandLineArguments;
473+
void setMetricsCommandLineArguments(String input) throws Exception {
474+
this.metricsCommandLineArguments = Converters.BOOLEAN_TYPE_CONVERTER.convert(input);
475+
}
476+
477+
boolean metricsCommandLineArguments;
411478

412479
@CommandLine.Option(
413480
names = {"--requested-max-frame-size", "-rmfs"},
@@ -419,8 +486,14 @@ public class StreamPerfTest implements Callable<Integer> {
419486
@CommandLine.Option(
420487
names = {"--native-epoll", "-ne"},
421488
description = "use Netty's native epoll transport (Linux x86-64 only)",
489+
arity = "0..1",
490+
fallbackValue = "true",
422491
defaultValue = "false")
423-
private boolean nativeEpoll;
492+
void setNativeEpoll(String input) throws Exception {
493+
this.nativeEpoll = Converters.BOOLEAN_TYPE_CONVERTER.convert(input);
494+
}
495+
496+
boolean nativeEpoll;
424497

425498
@ArgGroup(exclusive = false, multiplicity = "0..1")
426499
InstanceSyncOptions instanceSyncOptions;
@@ -447,26 +520,50 @@ public class StreamPerfTest implements Callable<Integer> {
447520
@CommandLine.Option(
448521
names = {"--force-replica-for-consumers", "-frfc"},
449522
description = "force the connection to a replica for consumers",
523+
arity = "0..1",
524+
fallbackValue = "true",
450525
defaultValue = "false")
451-
private boolean forceReplicaForConsumers;
526+
void setForceReplicaForConsumers(String input) throws Exception {
527+
this.forceReplicaForConsumers = Converters.BOOLEAN_TYPE_CONVERTER.convert(input);
528+
}
529+
530+
boolean forceReplicaForConsumers;
452531

453532
@CommandLine.Option(
454533
names = {"--no-dev-mode", "-ndm"},
455534
description = "do not use development mode (useful for local cluster)",
535+
arity = "0..1",
536+
fallbackValue = "true",
456537
defaultValue = "false")
457-
private boolean noDevMode;
538+
void setNoDevMode(String input) throws Exception {
539+
this.noDevMode = Converters.BOOLEAN_TYPE_CONVERTER.convert(input);
540+
}
541+
542+
boolean noDevMode;
458543

459544
@CommandLine.Option(
460545
names = {"--dynamic-batch-size", "-dbs"},
461546
description = "use dynamic batch size for publishing",
547+
arity = "0..1",
548+
fallbackValue = "true",
462549
defaultValue = "true")
463-
private boolean dynamicBatch;
550+
void setDynamicBatch(String input) throws Exception {
551+
this.dynamicBatch = Converters.BOOLEAN_TYPE_CONVERTER.convert(input);
552+
}
553+
554+
boolean dynamicBatch;
464555

465556
@CommandLine.Option(
466557
names = {"--batch-size-metric", "-bsm"},
467558
description = "display batch size",
559+
arity = "0..1",
560+
fallbackValue = "true",
468561
defaultValue = "false")
469-
private boolean includeBatchSizeMetric;
562+
void setIncludeByteSizeMetric(String input) throws Exception {
563+
this.includeBatchSizeMetric = Converters.BOOLEAN_TYPE_CONVERTER.convert(input);
564+
}
565+
566+
boolean includeBatchSizeMetric;
470567

471568
static class InstanceSyncOptions {
472569

@@ -553,9 +650,14 @@ static class InstanceSyncOptions {
553650
@CommandLine.Option(
554651
names = {"--tcp-no-delay", "-tnd"},
555652
description = "TCP NODELAY",
556-
arity = "1",
653+
arity = "0..1",
654+
fallbackValue = "true",
557655
defaultValue = "true")
558-
private boolean tcpNoDelay;
656+
void setTcpNoDelay(String input) throws Exception {
657+
this.tcpNoDelay = Converters.BOOLEAN_TYPE_CONVERTER.convert(input);
658+
}
659+
660+
boolean tcpNoDelay;
559661

560662
@CommandLine.Option(
561663
names = {"--consumer-latency", "-L"},

0 commit comments

Comments
 (0)