Search in sources :

Example 11 with BacklogTracerEventMessage

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

the class BacklogTracerTest method testBacklogTracerEventMessageDumpAll.

@SuppressWarnings("unchecked")
public void testBacklogTracerEventMessageDumpAll() 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 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<Exchange> fooExchanges = getMockEndpoint("mock:foo").getReceivedExchanges();
    List<Exchange> barExchanges = getMockEndpoint("mock:bar").getReceivedExchanges();
    List<BacklogTracerEventMessage> events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpAllTracedMessages", null, null);
    assertNotNull(events);
    assertEquals(6, events.size());
    BacklogTracerEventMessage event0 = events.get(0);
    assertEquals("route1", event0.getRouteId());
    assertEquals(null, event0.getToNode());
    assertEquals("    <message exchangeId=\"" + fooExchanges.get(0).getExchangeId() + "\">\n" + "      <body type=\"java.lang.String\">Hello World</body>\n" + "    </message>", event0.getMessageAsXml());
    BacklogTracerEventMessage event1 = events.get(1);
    assertEquals("route1", event1.getRouteId());
    assertEquals("foo", event1.getToNode());
    assertEquals("    <message exchangeId=\"" + fooExchanges.get(0).getExchangeId() + "\">\n" + "      <body type=\"java.lang.String\">Hello World</body>\n" + "    </message>", event1.getMessageAsXml());
    BacklogTracerEventMessage event2 = events.get(2);
    assertEquals("route1", event2.getRouteId());
    assertEquals("bar", event2.getToNode());
    assertEquals("    <message exchangeId=\"" + barExchanges.get(0).getExchangeId() + "\">\n" + "      <body type=\"java.lang.String\">Hello World</body>\n" + "    </message>", event2.getMessageAsXml());
    BacklogTracerEventMessage event3 = events.get(3);
    assertEquals("route1", event3.getRouteId());
    assertEquals(null, event3.getToNode());
    assertEquals("    <message exchangeId=\"" + fooExchanges.get(1).getExchangeId() + "\">\n" + "      <body type=\"java.lang.String\">Bye World</body>\n" + "    </message>", event3.getMessageAsXml());
    BacklogTracerEventMessage event4 = events.get(4);
    assertEquals("route1", event4.getRouteId());
    assertEquals("foo", event4.getToNode());
    assertEquals("    <message exchangeId=\"" + fooExchanges.get(1).getExchangeId() + "\">\n" + "      <body type=\"java.lang.String\">Bye World</body>\n" + "    </message>", event3.getMessageAsXml());
    BacklogTracerEventMessage event5 = events.get(5);
    assertEquals("route1", event5.getRouteId());
    assertEquals("bar", event5.getToNode());
    assertEquals("    <message exchangeId=\"" + barExchanges.get(1).getExchangeId() + "\">\n" + "      <body type=\"java.lang.String\">Bye World</body>\n" + "    </message>", event4.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 12 with BacklogTracerEventMessage

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

the class BacklogTracerTest method testBacklogTracerNotRemoveOnDumpPattern.

@SuppressWarnings("unchecked")
public void testBacklogTracerNotRemoveOnDumpPattern() 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, "dumpTracedMessages", new Object[] { "foo" }, new String[] { "java.lang.String" });
    assertNotNull(events);
    assertEquals(2, events.size());
    // and if we get again they are still there
    events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "foo" }, new String[] { "java.lang.String" });
    assertEquals(2, 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, "dumpTracedMessages", new Object[] { "foo" }, new String[] { "java.lang.String" });
    assertNotNull(events);
    assertEquals(3, events.size());
    // and bar should also have 3 traced messages
    events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "bar" }, new String[] { "java.lang.String" });
    assertNotNull(events);
    assertEquals(3, 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 13 with BacklogTracerEventMessage

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

the class BacklogTracerPatternRouteTest method testBacklogTracerPattern.

@SuppressWarnings("unchecked")
public void testBacklogTracerPattern() 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);
    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());
    // set the pattern to match only coolRoute
    mbeanServer.setAttribute(on, new Attribute("TracePattern", "coolRoute"));
    // 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, "dumpTracedMessages", new Object[] { "foo" }, new String[] { "java.lang.String" });
    assertNotNull(events);
    assertEquals(2, events.size());
    // there should also be messages on bar
    events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "bar" }, new String[] { "java.lang.String" });
    assertNotNull(events);
    assertEquals(2, events.size());
    // but not on beer
    events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "beer" }, new String[] { "java.lang.String" });
    assertNotNull(events);
    assertEquals(0, events.size());
}
Also used : 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 14 with BacklogTracerEventMessage

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

the class BacklogTracerPatternTest method testBacklogTracerPattern.

@SuppressWarnings("unchecked")
public void testBacklogTracerPattern() 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);
    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());
    // set the pattern to match only foo*
    mbeanServer.setAttribute(on, new Attribute("TracePattern", "foo*"));
    // 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());
    // there should be no messages on bar
    events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "bar" }, new String[] { "java.lang.String" });
    assertNotNull(events);
    assertEquals(0, events.size());
}
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)

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