Simplify test progress reporting, force printing on last entry

This commit is contained in:
Ivan Vilata-i-Balaguer 2016-05-12 10:04:22 +02:00
parent 53019a88f2
commit 7f1204e09e

View File

@ -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();