summaryrefslogtreecommitdiffstats
path: root/vespaclient-java/src/test/java/com/yahoo/vespafeeder/BenchmarkProgressPrinterTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'vespaclient-java/src/test/java/com/yahoo/vespafeeder/BenchmarkProgressPrinterTest.java')
-rw-r--r--vespaclient-java/src/test/java/com/yahoo/vespafeeder/BenchmarkProgressPrinterTest.java77
1 files changed, 77 insertions, 0 deletions
diff --git a/vespaclient-java/src/test/java/com/yahoo/vespafeeder/BenchmarkProgressPrinterTest.java b/vespaclient-java/src/test/java/com/yahoo/vespafeeder/BenchmarkProgressPrinterTest.java
new file mode 100644
index 00000000000..2b0b4cc9048
--- /dev/null
+++ b/vespaclient-java/src/test/java/com/yahoo/vespafeeder/BenchmarkProgressPrinterTest.java
@@ -0,0 +1,77 @@
+// Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespafeeder;
+
+import com.yahoo.clientmetrics.RouteMetricSet;
+import com.yahoo.concurrent.Timer;
+import com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage;
+import com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage;
+import com.yahoo.messagebus.EmptyReply;
+import junit.framework.TestCase;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+/**
+ */
+public class BenchmarkProgressPrinterTest extends TestCase {
+
+ class DummyTimer implements Timer {
+ long ms;
+
+ public long milliTime() { return ms; }
+ }
+
+ 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,\\s*3,\\s*2,\\s*\\d+,\\s*\\d+,\\s*\\d+$";
+ assertTrue("Value '" + val + "' does not match pattern '" + correctPattern + "'", val.matches(correctPattern));
+ }
+
+}