blob: 2b0b4cc90484168ae38a74c6dacf68a9b4872d8e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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));
}
}
|