File tree 3 files changed +46
-1
lines changed
main/java/com/rabbitmq/stream/perf
test/java/com/rabbitmq/stream/perf
3 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -394,6 +394,13 @@ public void setMaxSegmentSize(ByteCapacity in) {
394
394
description = "AMQP URI to use to create super stream topology" )
395
395
private String amqpUri ;
396
396
397
+ @ CommandLine .Option (
398
+ names = {"--time" , "-z" },
399
+ description = "run duration in seconds, unlimited by default" ,
400
+ defaultValue = "0" ,
401
+ converter = Utils .GreaterThanOrEqualToZeroIntegerTypeConverter .class )
402
+ private int time ;
403
+
397
404
private MetricsCollector metricsCollector ;
398
405
private PerformanceMetrics performanceMetrics ;
399
406
private List <Monitoring > monitorings ;
@@ -940,7 +947,11 @@ public Integer call() throws Exception {
940
947
Thread shutdownHook = new Thread (() -> latch .countDown ());
941
948
Runtime .getRuntime ().addShutdownHook (shutdownHook );
942
949
try {
943
- latch .await ();
950
+ if (this .time > 0 ) {
951
+ latch .await (this .time , TimeUnit .SECONDS );
952
+ } else {
953
+ latch .await ();
954
+ }
944
955
Runtime .getRuntime ().removeShutdownHook (shutdownHook );
945
956
} catch (InterruptedException e ) {
946
957
// moving on to the closing sequence
Original file line number Diff line number Diff line change @@ -487,6 +487,23 @@ public Integer convert(String input) {
487
487
}
488
488
}
489
489
490
+ static class GreaterThanOrEqualToZeroIntegerTypeConverter
491
+ implements CommandLine .ITypeConverter <Integer > {
492
+
493
+ @ Override
494
+ public Integer convert (String input ) {
495
+ try {
496
+ Integer value = Integer .valueOf (input );
497
+ if (value < 0 ) {
498
+ throw new IllegalArgumentException ();
499
+ }
500
+ return value ;
501
+ } catch (Exception e ) {
502
+ throw new CommandLine .TypeConversionException (input + " is not greater than or equal to 0" );
503
+ }
504
+ }
505
+ }
506
+
490
507
static class CompressionTypeConverter implements CommandLine .ITypeConverter <Compression > {
491
508
492
509
@ Override
Original file line number Diff line number Diff line change 37
37
import java .net .HttpURLConnection ;
38
38
import java .net .ServerSocket ;
39
39
import java .net .URL ;
40
+ import java .time .Duration ;
40
41
import java .util .HashMap ;
41
42
import java .util .List ;
42
43
import java .util .Locale ;
@@ -409,6 +410,17 @@ void confirmLatencyShouldBeIncluded() throws Exception {
409
410
.doesNotContain ("confirm latency" );
410
411
}
411
412
413
+ @ Test
414
+ void shouldStopWhenTimeIsSet () throws Exception {
415
+ int time = 3 ;
416
+ long start = System .nanoTime ();
417
+ run (builder ().time (time ));
418
+ waitUntilStreamExists (s );
419
+ waitRunEnds ();
420
+ assertThat (Duration .ofNanos (System .nanoTime () - start ))
421
+ .isGreaterThanOrEqualTo (Duration .ofSeconds (3 ));
422
+ }
423
+
412
424
void singleActiveConsumersOnSuperStream () throws Exception {
413
425
String consumerName = "app-1" ;
414
426
Future <?> run =
@@ -639,6 +651,11 @@ ArgumentsBuilder singleActiveConsumer() {
639
651
return this ;
640
652
}
641
653
654
+ ArgumentsBuilder time (int time ) {
655
+ arguments .put ("time" , String .valueOf (time ));
656
+ return this ;
657
+ }
658
+
642
659
String build () {
643
660
return this .arguments .entrySet ().stream ()
644
661
.map (e -> "--" + e .getKey () + (e .getValue ().isEmpty () ? "" : (" " + e .getValue ())))
You can’t perform that action at this time.
0 commit comments