File tree Expand file tree Collapse file tree 3 files changed +46
-1
lines changed
main/java/com/rabbitmq/stream/perf
test/java/com/rabbitmq/stream/perf Expand file tree Collapse file tree 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) {
394394 description = "AMQP URI to use to create super stream topology" )
395395 private String amqpUri ;
396396
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+
397404 private MetricsCollector metricsCollector ;
398405 private PerformanceMetrics performanceMetrics ;
399406 private List <Monitoring > monitorings ;
@@ -940,7 +947,11 @@ public Integer call() throws Exception {
940947 Thread shutdownHook = new Thread (() -> latch .countDown ());
941948 Runtime .getRuntime ().addShutdownHook (shutdownHook );
942949 try {
943- latch .await ();
950+ if (this .time > 0 ) {
951+ latch .await (this .time , TimeUnit .SECONDS );
952+ } else {
953+ latch .await ();
954+ }
944955 Runtime .getRuntime ().removeShutdownHook (shutdownHook );
945956 } catch (InterruptedException e ) {
946957 // 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) {
487487 }
488488 }
489489
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+
490507 static class CompressionTypeConverter implements CommandLine .ITypeConverter <Compression > {
491508
492509 @ Override
Original file line number Diff line number Diff line change 3737import java .net .HttpURLConnection ;
3838import java .net .ServerSocket ;
3939import java .net .URL ;
40+ import java .time .Duration ;
4041import java .util .HashMap ;
4142import java .util .List ;
4243import java .util .Locale ;
@@ -409,6 +410,17 @@ void confirmLatencyShouldBeIncluded() throws Exception {
409410 .doesNotContain ("confirm latency" );
410411 }
411412
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+
412424 void singleActiveConsumersOnSuperStream () throws Exception {
413425 String consumerName = "app-1" ;
414426 Future <?> run =
@@ -639,6 +651,11 @@ ArgumentsBuilder singleActiveConsumer() {
639651 return this ;
640652 }
641653
654+ ArgumentsBuilder time (int time ) {
655+ arguments .put ("time" , String .valueOf (time ));
656+ return this ;
657+ }
658+
642659 String build () {
643660 return this .arguments .entrySet ().stream ()
644661 .map (e -> "--" + e .getKey () + (e .getValue ().isEmpty () ? "" : (" " + e .getValue ())))
You can’t perform that action at this time.
0 commit comments