use of com.yahoo.text.XMLWriter in project vespa by vespa-engine.
the class HitRendererTestCase method assertRender.
@SuppressWarnings("deprecation")
private static void assertRender(HitGroup hit, String expectedXml) {
StringWriter str = new StringWriter();
XMLWriter out = new XMLWriter(str, 0, -1);
try {
HitRenderer.renderHeader(hit, out);
while (out.openTags().size() > 0) {
out.closeTag();
}
} catch (IOException e) {
fail();
}
assertEquals(expectedXml, str.toString());
}
use of com.yahoo.text.XMLWriter in project vespa by vespa-engine.
the class ErrorHitRenderTestCase method testXMLEscaping.
@Test
public void testXMLEscaping() throws java.io.IOException {
ErrorHit h = new DefaultErrorHit("testcase", ErrorMessage.createUnspecifiedError("<>\"&"));
StringWriter writer = new StringWriter();
SearchRendererAdaptor.renderMessageDefaultErrorHit(new XMLWriter(writer), h.errors().iterator().next());
assertEquals("<error source=\"testcase\" error=\"Unspecified error\" code=\"5\"><>\"&</error>\n", writer.toString());
}
use of com.yahoo.text.XMLWriter in project vespa by vespa-engine.
the class LoadBalancerTestCase method testLoadBalancer.
@Test
public void testLoadBalancer() {
LoadBalancer.Metrics m = new LoadBalancer.Metrics("");
LoadBalancer lb = new LoadBalancer("foo", "", m);
Mirror.Entry[] entries = new Mirror.Entry[] { new Mirror.Entry("foo/0/default", "tcp/bar:1"), new Mirror.Entry("foo/1/default", "tcp/bar:2"), new Mirror.Entry("foo/2/default", "tcp/bar:3") };
List<LoadBalancer.NodeMetrics> weights = lb.getNodeWeights();
{
for (int i = 0; i < 99; i++) {
LoadBalancer.Node node = lb.getRecipient(entries);
assertEquals("foo/" + (i % 3) + "/default", node.entry.getName());
}
assertEquals(33, weights.get(0).sent.get().intValue());
assertEquals(33, weights.get(1).sent.get().intValue());
assertEquals(33, weights.get(2).sent.get().intValue());
weights.get(0).sent.set(new AtomicLong(0));
weights.get(1).sent.set(new AtomicLong(0));
weights.get(2).sent.set(new AtomicLong(0));
}
{
// Simulate that one node is overloaded. It returns busy twice as often as the others.
for (int i = 0; i < 100; i++) {
lb.received(new LoadBalancer.Node(new Mirror.Entry("foo/0/default", "tcp/bar:1"), weights.get(0)), true);
lb.received(new LoadBalancer.Node(new Mirror.Entry("foo/0/default", "tcp/bar:1"), weights.get(0)), false);
lb.received(new LoadBalancer.Node(new Mirror.Entry("foo/0/default", "tcp/bar:1"), weights.get(0)), false);
lb.received(new LoadBalancer.Node(new Mirror.Entry("foo/2/default", "tcp/bar:3"), weights.get(2)), true);
lb.received(new LoadBalancer.Node(new Mirror.Entry("foo/2/default", "tcp/bar:3"), weights.get(2)), false);
lb.received(new LoadBalancer.Node(new Mirror.Entry("foo/2/default", "tcp/bar:3"), weights.get(2)), false);
lb.received(new LoadBalancer.Node(new Mirror.Entry("foo/1/default", "tcp/bar:2"), weights.get(1)), true);
lb.received(new LoadBalancer.Node(new Mirror.Entry("foo/1/default", "tcp/bar:2"), weights.get(1)), true);
lb.received(new LoadBalancer.Node(new Mirror.Entry("foo/1/default", "tcp/bar:2"), weights.get(1)), false);
}
PrintWriter writer = new PrintWriter(System.out);
m.toXML(new XMLWriter(writer));
writer.flush();
assertEquals(421, (int) (100 * weights.get(0).weight.get() / weights.get(1).weight.get()));
assertEquals(100, (int) (100 * weights.get(1).weight.get()));
assertEquals(421, (int) (100 * weights.get(2).weight.get() / weights.get(1).weight.get()));
}
assertEquals("foo/0/default", lb.getRecipient(entries).entry.getName());
assertEquals("foo/0/default", lb.getRecipient(entries).entry.getName());
assertEquals("foo/1/default", lb.getRecipient(entries).entry.getName());
assertEquals("foo/2/default", lb.getRecipient(entries).entry.getName());
assertEquals("foo/2/default", lb.getRecipient(entries).entry.getName());
assertEquals("foo/2/default", lb.getRecipient(entries).entry.getName());
assertEquals("foo/2/default", lb.getRecipient(entries).entry.getName());
assertEquals("foo/0/default", lb.getRecipient(entries).entry.getName());
assertEquals("foo/0/default", lb.getRecipient(entries).entry.getName());
assertEquals("foo/0/default", lb.getRecipient(entries).entry.getName());
}
use of com.yahoo.text.XMLWriter in project vespa by vespa-engine.
the class MetricSnapshot method toXml.
public String toXml(MetricManager man, String consumer, int verbosity) {
StringWriter str = new StringWriter();
XMLWriter writer = new XMLWriter(str);
printXml(man, consumer, verbosity, writer);
return str.toString();
}
Aggregations