3232import java .security .NoSuchAlgorithmException ;
3333import java .text .SimpleDateFormat ;
3434import java .util .*;
35- import java .util .concurrent .ExecutorService ;
36- import java .util .concurrent .SynchronousQueue ;
37- import java .util .concurrent .ThreadPoolExecutor ;
38- import java .util .concurrent .TimeUnit ;
35+ import java .util .concurrent .*;
3936import java .util .function .Function ;
4037
4138import static com .rabbitmq .perf .OptionsUtils .forEach ;
@@ -318,13 +315,16 @@ public static void main(String [] args, PerfTestOptions perfTestOptions) {
318315 p .setBodyFieldCount (bodyFieldCount );
319316 p .setBodyCount (bodyCount );
320317
321- MulticastSet .CompletionHandler completionHandler = getCompletionHandler (p );
318+ ConcurrentMap <String , Integer > completionReasons = new ConcurrentHashMap <>();
319+
320+ MulticastSet .CompletionHandler completionHandler = getCompletionHandler (p , completionReasons );
322321
323322 factory .setExceptionHandler (perfTestOptions .exceptionHandler );
324323
325324 MulticastSet set = new MulticastSet (stats , factory , p , testID , uris , completionHandler , shutdownService );
326325 set .run (true );
327326
327+ System .out .println (stopLine (completionReasons ));
328328 stats .printFinal ();
329329 } catch (ParseException exp ) {
330330 System .err .println ("Parsing failed. Reason: " + exp .getMessage ());
@@ -340,6 +340,26 @@ public static void main(String [] args, PerfTestOptions perfTestOptions) {
340340 systemExiter .exit (exitStatus );
341341 }
342342
343+ static String stopLine (Map <String , Integer > reasons ) {
344+ StringBuilder stoppedLine = new StringBuilder ("test stopped" );
345+ if (reasons .size () > 0 ) {
346+ stoppedLine .append (" (" );
347+ int count = 1 ;
348+ for (Map .Entry <String , Integer > reasonToCount : reasons .entrySet ()) {
349+ stoppedLine .append (reasonToCount .getKey ());
350+ if (reasonToCount .getValue () > 1 ) {
351+ stoppedLine .append (" [" ).append (reasonToCount .getValue ()).append ("]" );
352+ }
353+ if (count < reasons .size ()) {
354+ stoppedLine .append (", " );
355+ }
356+ count ++;
357+ }
358+ stoppedLine .append (")" );
359+ }
360+ return stoppedLine .toString ();
361+ }
362+
343363 private static PrintWriter openCsvFileForWriting (String outputFile , ShutdownService shutdownService ) throws IOException {
344364 PrintWriter output ;
345365 File file = new File (outputFile );
@@ -396,7 +416,7 @@ private static ConnectionFactory configureNioIfRequested(CommandLineProxy cmd, C
396416 };
397417 }
398418
399- static MulticastSet .CompletionHandler getCompletionHandler (MulticastParams p ) {
419+ static MulticastSet .CompletionHandler getCompletionHandler (MulticastParams p , ConcurrentMap < String , Integer > reasons ) {
400420 MulticastSet .CompletionHandler completionHandler ;
401421 if (p .hasLimit ()) {
402422 int countLimit = 0 ;
@@ -406,14 +426,14 @@ static MulticastSet.CompletionHandler getCompletionHandler(MulticastParams p) {
406426 countLimit += p .getProducerThreadCount ();
407427 }
408428 if (p .getConsumerMsgCount () > 0 ) {
409- countLimit += p .getProducerThreadCount ();
429+ countLimit += p .getConsumerThreadCount ();
410430 }
411431 completionHandler = new MulticastSet .DefaultCompletionHandler (
412432 p .getTimeLimit (),
413- countLimit
414- );
433+ countLimit ,
434+ reasons );
415435 } else {
416- completionHandler = new MulticastSet .NoLimitCompletionHandler ();
436+ completionHandler = new MulticastSet .NoLimitCompletionHandler (reasons );
417437 }
418438 return completionHandler ;
419439 }
0 commit comments