Search in sources :

Example 6 with BacklogTracerEventMessage

use of org.apache.camel.api.management.mbean.BacklogTracerEventMessage in project camel by apache.

the class BacklogTracerTest method testBacklogTracerNotRemoveOnDump.

@SuppressWarnings("unchecked")
public void testBacklogTracerNotRemoveOnDump() throws Exception {
    MBeanServer mbeanServer = getMBeanServer();
    ObjectName on = new ObjectName("org.apache.camel:context=camel-1,type=tracer,name=BacklogTracer");
    assertNotNull(on);
    mbeanServer.isRegistered(on);
    Boolean removeOnDump = (Boolean) mbeanServer.getAttribute(on, "RemoveOnDump");
    assertEquals(Boolean.TRUE, removeOnDump);
    // disable it
    mbeanServer.setAttribute(on, new Attribute("RemoveOnDump", Boolean.FALSE));
    Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
    assertEquals("Should not be enabled", Boolean.FALSE, enabled);
    // enable it
    mbeanServer.setAttribute(on, new Attribute("Enabled", Boolean.TRUE));
    getMockEndpoint("mock:foo").expectedMessageCount(2);
    getMockEndpoint("mock:bar").expectedMessageCount(2);
    template.sendBody("direct:start", "Hello World");
    template.sendBody("direct:start", "Bye World");
    assertMockEndpointsSatisfied();
    List<BacklogTracerEventMessage> events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpAllTracedMessages", null, null);
    assertNotNull(events);
    assertEquals(6, events.size());
    // and if we get again they are still there
    events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpAllTracedMessages", null, null);
    assertNotNull(events);
    assertEquals(6, events.size());
    // send in another message
    resetMocks();
    getMockEndpoint("mock:foo").expectedMessageCount(1);
    getMockEndpoint("mock:bar").expectedMessageCount(1);
    template.sendBody("direct:start", "Hi World");
    assertMockEndpointsSatisfied();
    // and now we should have 3 more messages
    events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpAllTracedMessages", null, null);
    assertNotNull(events);
    assertEquals(9, events.size());
}
Also used : BacklogTracerEventMessage(org.apache.camel.api.management.mbean.BacklogTracerEventMessage) Attribute(javax.management.Attribute) List(java.util.List) NodeList(org.w3c.dom.NodeList) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 7 with BacklogTracerEventMessage

use of org.apache.camel.api.management.mbean.BacklogTracerEventMessage in project camel by apache.

the class BacklogTracerTest method testBacklogTracerEventMessage.

@SuppressWarnings("unchecked")
public void testBacklogTracerEventMessage() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MBeanServer mbeanServer = getMBeanServer();
    ObjectName on = new ObjectName("org.apache.camel:context=camel-1,type=tracer,name=BacklogTracer");
    assertNotNull(on);
    assertTrue(mbeanServer.isRegistered(on));
    Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
    assertEquals("Should not be enabled", Boolean.FALSE, enabled);
    Integer size = (Integer) mbeanServer.getAttribute(on, "BacklogSize");
    assertEquals("Should be 1000", 1000, size.intValue());
    Boolean removeOnDump = (Boolean) mbeanServer.getAttribute(on, "RemoveOnDump");
    assertEquals(Boolean.TRUE, removeOnDump);
    // enable it
    mbeanServer.setAttribute(on, new Attribute("Enabled", Boolean.TRUE));
    getMockEndpoint("mock:foo").expectedMessageCount(2);
    getMockEndpoint("mock:bar").expectedMessageCount(2);
    template.sendBody("direct:start", "Hello World");
    template.sendBody("direct:start", "Bye World");
    assertMockEndpointsSatisfied();
    List<Exchange> exchanges = getMockEndpoint("mock:foo").getReceivedExchanges();
    List<BacklogTracerEventMessage> events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "foo" }, new String[] { "java.lang.String" });
    assertNotNull(events);
    assertEquals(2, events.size());
    BacklogTracerEventMessage event1 = events.get(0);
    assertEquals("foo", event1.getToNode());
    assertEquals("    <message exchangeId=\"" + exchanges.get(0).getExchangeId() + "\">\n" + "      <body type=\"java.lang.String\">Hello World</body>\n" + "    </message>", event1.getMessageAsXml());
    BacklogTracerEventMessage event2 = events.get(1);
    assertEquals("foo", event2.getToNode());
    assertEquals("    <message exchangeId=\"" + exchanges.get(1).getExchangeId() + "\">\n" + "      <body type=\"java.lang.String\">Bye World</body>\n" + "    </message>", event2.getMessageAsXml());
}
Also used : Exchange(org.apache.camel.Exchange) BacklogTracerEventMessage(org.apache.camel.api.management.mbean.BacklogTracerEventMessage) Attribute(javax.management.Attribute) List(java.util.List) NodeList(org.w3c.dom.NodeList) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 8 with BacklogTracerEventMessage

use of org.apache.camel.api.management.mbean.BacklogTracerEventMessage in project camel by apache.

the class BacklogTracer method dumpAllTracedMessagesAsXml.

public String dumpAllTracedMessagesAsXml() {
    List<BacklogTracerEventMessage> events = dumpAllTracedMessages();
    StringBuilder sb = new StringBuilder();
    sb.append("<").append(BacklogTracerEventMessage.ROOT_TAG).append("s>");
    for (BacklogTracerEventMessage event : events) {
        sb.append("\n").append(event.toXml(2));
    }
    sb.append("\n</").append(BacklogTracerEventMessage.ROOT_TAG).append("s>");
    return sb.toString();
}
Also used : BacklogTracerEventMessage(org.apache.camel.api.management.mbean.BacklogTracerEventMessage)

Example 9 with BacklogTracerEventMessage

use of org.apache.camel.api.management.mbean.BacklogTracerEventMessage in project camel by apache.

the class BacklogTracerStreamCachingTest method testBacklogTracerEventMessageStreamCaching.

@SuppressWarnings("unchecked")
public void testBacklogTracerEventMessageStreamCaching() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MBeanServer mbeanServer = getMBeanServer();
    ObjectName on = new ObjectName("org.apache.camel:context=camel-1,type=tracer,name=BacklogTracer");
    assertNotNull(on);
    assertTrue(mbeanServer.isRegistered(on));
    Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
    assertEquals("Should not be enabled", Boolean.FALSE, enabled);
    Integer size = (Integer) mbeanServer.getAttribute(on, "BacklogSize");
    assertEquals("Should be 1000", 1000, size.intValue());
    Boolean removeOnDump = (Boolean) mbeanServer.getAttribute(on, "RemoveOnDump");
    assertEquals(Boolean.TRUE, removeOnDump);
    // enable streams
    mbeanServer.setAttribute(on, new Attribute("BodyIncludeStreams", Boolean.TRUE));
    // enable it
    mbeanServer.setAttribute(on, new Attribute("Enabled", Boolean.TRUE));
    getMockEndpoint("mock:bar").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    List<Exchange> exchanges = getMockEndpoint("mock:bar").getReceivedExchanges();
    List<BacklogTracerEventMessage> events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "bar" }, new String[] { "java.lang.String" });
    assertNotNull(events);
    assertEquals(1, events.size());
    BacklogTracerEventMessage event1 = events.get(0);
    assertEquals("bar", event1.getToNode());
    assertEquals("    <message exchangeId=\"" + exchanges.get(0).getExchangeId() + "\">\n" + "      <body type=\"org.apache.camel.converter.stream.ByteArrayInputStreamCache\">Bye World</body>\n" + "    </message>", event1.getMessageAsXml());
}
Also used : Exchange(org.apache.camel.Exchange) BacklogTracerEventMessage(org.apache.camel.api.management.mbean.BacklogTracerEventMessage) Attribute(javax.management.Attribute) List(java.util.List) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 10 with BacklogTracerEventMessage

use of org.apache.camel.api.management.mbean.BacklogTracerEventMessage in project camel by apache.

the class BacklogTracerTest method testBacklogTracerNotRemoveOverflow.

@SuppressWarnings("unchecked")
public void testBacklogTracerNotRemoveOverflow() throws Exception {
    MBeanServer mbeanServer = getMBeanServer();
    ObjectName on = new ObjectName("org.apache.camel:context=camel-1,type=tracer,name=BacklogTracer");
    assertNotNull(on);
    mbeanServer.isRegistered(on);
    Boolean removeOnDump = (Boolean) mbeanServer.getAttribute(on, "RemoveOnDump");
    assertEquals(Boolean.TRUE, removeOnDump);
    // disable it
    mbeanServer.setAttribute(on, new Attribute("RemoveOnDump", Boolean.FALSE));
    Integer size = (Integer) mbeanServer.getAttribute(on, "BacklogSize");
    assertEquals("Should be 1000", 1000, size.intValue());
    // change size to 2 x 10 (as we need for first as well)
    mbeanServer.setAttribute(on, new Attribute("BacklogSize", 20));
    // set the pattern to match only foo
    mbeanServer.setAttribute(on, new Attribute("TracePattern", "foo"));
    Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
    assertEquals("Should not be enabled", Boolean.FALSE, enabled);
    // enable it
    mbeanServer.setAttribute(on, new Attribute("Enabled", Boolean.TRUE));
    getMockEndpoint("mock:foo").expectedMessageCount(10);
    getMockEndpoint("mock:bar").expectedMessageCount(10);
    for (int i = 0; i < 10; i++) {
        template.sendBody("direct:start", "###" + i + "###");
    }
    assertMockEndpointsSatisfied();
    List<BacklogTracerEventMessage> events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "foo" }, new String[] { "java.lang.String" });
    assertEquals(10, events.size());
    // the first should be 0 and the last 9
    String xml = events.get(0).getMessageAsXml();
    assertTrue(xml.contains("###0###"));
    xml = events.get(9).getMessageAsXml();
    assertTrue(xml.contains("###9###"));
    // send in another message
    template.sendBody("direct:start", "###" + 10 + "###");
    events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "foo" }, new String[] { "java.lang.String" });
    assertEquals(10, events.size());
    // and we are shifted one now
    xml = events.get(0).getMessageAsXml();
    assertTrue(xml.contains("###1###"));
    xml = events.get(9).getMessageAsXml();
    assertTrue(xml.contains("###10###"));
    // send in 4 messages
    template.sendBody("direct:start", "###" + 11 + "###");
    template.sendBody("direct:start", "###" + 12 + "###");
    template.sendBody("direct:start", "###" + 13 + "###");
    template.sendBody("direct:start", "###" + 14 + "###");
    events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "foo" }, new String[] { "java.lang.String" });
    assertEquals(10, events.size());
    // and we are shifted +4 now
    xml = events.get(0).getMessageAsXml();
    assertTrue(xml.contains("###5###"));
    xml = events.get(9).getMessageAsXml();
    assertTrue(xml.contains("###14###"));
}
Also used : BacklogTracerEventMessage(org.apache.camel.api.management.mbean.BacklogTracerEventMessage) Attribute(javax.management.Attribute) List(java.util.List) NodeList(org.w3c.dom.NodeList) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Aggregations

BacklogTracerEventMessage (org.apache.camel.api.management.mbean.BacklogTracerEventMessage)14 List (java.util.List)10 Attribute (javax.management.Attribute)10 MBeanServer (javax.management.MBeanServer)10 ObjectName (javax.management.ObjectName)10 Exchange (org.apache.camel.Exchange)6 NodeList (org.w3c.dom.NodeList)5 ChoiceDefinition (org.apache.camel.model.ChoiceDefinition)1 LogDefinition (org.apache.camel.model.LogDefinition)1 OtherwiseDefinition (org.apache.camel.model.OtherwiseDefinition)1 RouteDefinition (org.apache.camel.model.RouteDefinition)1 ToDefinition (org.apache.camel.model.ToDefinition)1 WhenDefinition (org.apache.camel.model.WhenDefinition)1