From 7f1204e09ec749ca29c3f430a40096cbd7eb11db Mon Sep 17 00:00:00 2001 From: Ivan Vilata-i-Balaguer Date: Thu, 12 May 2016 10:04:22 +0200 Subject: [PATCH] Simplify test progress reporting, force printing on last entry --- .../p2p/network/NetworkStressTest.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/network/src/test/java/io/bitsquare/p2p/network/NetworkStressTest.java b/network/src/test/java/io/bitsquare/p2p/network/NetworkStressTest.java index 49e90678fe..650dbcbcae 100644 --- a/network/src/test/java/io/bitsquare/p2p/network/NetworkStressTest.java +++ b/network/src/test/java/io/bitsquare/p2p/network/NetworkStressTest.java @@ -114,17 +114,19 @@ public class NetworkStressTest { /** Print a progress bar based on the given character. */ private void printProgress(char c, int n) { + if (n < 1) + return; // nothing to represent + long now = System.currentTimeMillis(); - if (now - lastProgressUpdateMillis < 500) - return; // throttle message printing below half a second + if ((n != 1) && ((now - lastProgressUpdateMillis) < 500)) + return; // throttle message printing below half a second (but last one is always printed) lastProgressUpdateMillis = now; - if (n > 0) { - String hdr = String.format("\r%s> ", this.getClass().getSimpleName()); - String msg = (hdr.length() - 1/*carriage return*/ + n + 1/*final space*/ > terminalColumns) - ? String.format("%c*%d", c, n) - : nChars(c, n); - System.out.print(hdr + msg + ' '); - } + + String hdr = String.format("\r%s> ", this.getClass().getSimpleName()); + String msg = (hdr.length() - 1/*carriage return*/ + n + 1/*final space*/ > terminalColumns) + ? String.format("%c*%d", c, n) + : nChars(c, n); + System.out.print(hdr + msg + ' '); if (n == 1) System.out.print('\n'); System.out.flush();