BenchmarkProgressPrinter implements RouteMetricSet.ProgressCallback { @Override public void done(RouteMetricSet metrics) { try { output.println("# Time used, num ok, num error, min latency, max latency, average latency"); printMetrics(output, metrics); } catch (Exception e) { e.printStackTrace(); } } BenchmarkProgressPrinter(Timer timer, PrintStream output); @Override void onProgress(RouteMetricSet metrics); @Override void done(RouteMetricSet metrics);  }
@Test public void testSimple() { ByteArrayOutputStream output = new ByteArrayOutputStream(); DummyTimer timer = new DummyTimer(); timer.ms = 0; BenchmarkProgressPrinter printer = new BenchmarkProgressPrinter(timer, new PrintStream(output)); RouteMetricSet metrics = new RouteMetricSet("foobar", printer); { EmptyReply reply = new EmptyReply(); reply.setMessage(PutDocumentMessage.createEmpty().setTimeReceived(1)); metrics.addReply(reply); } timer.ms = 1200; { EmptyReply reply = new EmptyReply(); reply.setMessage(PutDocumentMessage.createEmpty().setTimeReceived(2)); metrics.addReply(reply); } { EmptyReply reply = new EmptyReply(); reply.setMessage(UpdateDocumentMessage.createEmpty().setTimeReceived(3)); metrics.addReply(reply); } timer.ms = 2400; { EmptyReply reply = new EmptyReply(); reply.setMessage(UpdateDocumentMessage.createEmpty().setTimeReceived(4)); reply.addError(new com.yahoo.messagebus.Error(32, "foo")); metrics.addReply(reply); } timer.ms = 62000; { EmptyReply reply = new EmptyReply(); reply.setMessage(UpdateDocumentMessage.createEmpty().setTimeReceived(5)); reply.addError(new com.yahoo.messagebus.Error(64, "bar")); metrics.addReply(reply); } metrics.done(); String val = output.toString().split("\n")[1]; String correctPattern = "62000, \\d+, \\d+, \\d+, \\d+, \\d+$"; assertTrue("Value '" + val + "' does not match pattern '" + correctPattern + "'", val.matches(correctPattern)); }