Search in sources :

Example 11 with XMLWriter

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());
}
Also used : StringWriter(java.io.StringWriter) IOException(java.io.IOException) XMLWriter(com.yahoo.text.XMLWriter)

Example 12 with XMLWriter

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\">&lt;&gt;\"&amp;</error>\n", writer.toString());
}
Also used : StringWriter(java.io.StringWriter) DefaultErrorHit(com.yahoo.search.result.DefaultErrorHit) ErrorHit(com.yahoo.search.result.ErrorHit) DefaultErrorHit(com.yahoo.search.result.DefaultErrorHit) XMLWriter(com.yahoo.text.XMLWriter) Test(org.junit.Test)

Example 13 with XMLWriter

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());
}
Also used : LoadBalancer(com.yahoo.documentapi.messagebus.protocol.LoadBalancer) XMLWriter(com.yahoo.text.XMLWriter) AtomicLong(java.util.concurrent.atomic.AtomicLong) Mirror(com.yahoo.jrt.slobrok.api.Mirror) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 14 with XMLWriter

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();
}
Also used : StringWriter(java.io.StringWriter) XMLWriter(com.yahoo.text.XMLWriter)

Aggregations

XMLWriter (com.yahoo.text.XMLWriter)14 IOException (java.io.IOException)4 StringWriter (java.io.StringWriter)4 TraceNode (com.yahoo.yolean.trace.TraceNode)3 OutputStreamWriter (java.io.OutputStreamWriter)3 ErrorMessage (com.yahoo.processing.request.ErrorMessage)2 Utf8String (com.yahoo.text.Utf8String)2 Iterator (java.util.Iterator)2 Test (org.junit.Test)2 LoadBalancer (com.yahoo.documentapi.messagebus.protocol.LoadBalancer)1 Mirror (com.yahoo.jrt.slobrok.api.Mirror)1 MetricSnapshot (com.yahoo.metrics.MetricSnapshot)1 DefaultRenderer (com.yahoo.search.rendering.DefaultRenderer)1 DefaultErrorHit (com.yahoo.search.result.DefaultErrorHit)1 ErrorHit (com.yahoo.search.result.ErrorHit)1 PrintWriter (java.io.PrintWriter)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1