Search in sources :

Example 46 with MBeanServer

use of javax.management.MBeanServer in project camel by apache.

the class BacklogDebuggerTest method testBacklogDebuggerUpdateBodyAndHeader.

@SuppressWarnings("unchecked")
public void testBacklogDebuggerUpdateBodyAndHeader() 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=BacklogDebugger");
    assertNotNull(on);
    mbeanServer.isRegistered(on);
    Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
    assertEquals("Should not be enabled", Boolean.FALSE, enabled);
    // enable debugger
    mbeanServer.invoke(on, "enableDebugger", null, null);
    enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
    assertEquals("Should be enabled", Boolean.TRUE, enabled);
    // add breakpoint at bar
    mbeanServer.invoke(on, "addBreakpoint", new Object[] { "foo" }, new String[] { "java.lang.String" });
    mbeanServer.invoke(on, "addBreakpoint", new Object[] { "bar" }, new String[] { "java.lang.String" });
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(0);
    mock.setSleepForEmptyTest(1000);
    template.sendBody("seda:start", "Hello World");
    assertMockEndpointsSatisfied();
    // add breakpoint at bar
    Set<String> nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
    assertNotNull(nodes);
    assertEquals(1, nodes.size());
    assertEquals("foo", nodes.iterator().next());
    // update body and header
    mbeanServer.invoke(on, "setMessageBodyOnBreakpoint", new Object[] { "foo", "Changed body" }, new String[] { "java.lang.String", "java.lang.Object" });
    mbeanServer.invoke(on, "setMessageHeaderOnBreakpoint", new Object[] { "foo", "beer", "Carlsberg" }, new String[] { "java.lang.String", "java.lang.String", "java.lang.Object" });
    // resume breakpoint
    mbeanServer.invoke(on, "resumeBreakpoint", new Object[] { "foo" }, new String[] { "java.lang.String" });
    Thread.sleep(1000);
    // add breakpoint at bar
    nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
    assertNotNull(nodes);
    assertEquals(1, nodes.size());
    assertEquals("bar", nodes.iterator().next());
    // the message should be ours
    String xml = (String) mbeanServer.invoke(on, "dumpTracedMessagesAsXml", new Object[] { "bar" }, new String[] { "java.lang.String" });
    assertNotNull(xml);
    log.info(xml);
    assertTrue("Should contain our body", xml.contains("Changed body"));
    assertTrue("Should contain bar node", xml.contains("<toNode>bar</toNode>"));
    assertTrue("Should contain our added header", xml.contains("<header key=\"beer\" type=\"java.lang.String\">Carlsberg</header>"));
    resetMocks();
    mock.expectedMessageCount(1);
    // resume breakpoint
    mbeanServer.invoke(on, "resumeBreakpoint", new Object[] { "bar" }, new String[] { "java.lang.String" });
    assertMockEndpointsSatisfied();
    // and no suspended anymore
    nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
    assertNotNull(nodes);
    assertEquals(0, nodes.size());
}
Also used : Set(java.util.Set) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 47 with MBeanServer

use of javax.management.MBeanServer in project camel by apache.

the class BacklogDebuggerTest method testBacklogDebuggerSuspendOnlyOneAtBreakpoint.

@SuppressWarnings("unchecked")
public void testBacklogDebuggerSuspendOnlyOneAtBreakpoint() 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=BacklogDebugger");
    assertNotNull(on);
    mbeanServer.isRegistered(on);
    Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
    assertEquals("Should not be enabled", Boolean.FALSE, enabled);
    // enable debugger
    mbeanServer.invoke(on, "enableDebugger", null, null);
    enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
    assertEquals("Should be enabled", Boolean.TRUE, enabled);
    // add breakpoint at bar
    mbeanServer.invoke(on, "addBreakpoint", new Object[] { "bar" }, new String[] { "java.lang.String" });
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(2);
    // only one of them is suspended
    template.sendBody("seda:start", "Hello World");
    template.sendBody("seda:start", "Hello Camel");
    template.sendBody("seda:start", "Hello Earth");
    assertMockEndpointsSatisfied();
    // add breakpoint at bar
    Set<String> nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
    assertNotNull(nodes);
    assertEquals(1, nodes.size());
    assertEquals("bar", nodes.iterator().next());
    // the message should be ours
    String xml = (String) mbeanServer.invoke(on, "dumpTracedMessagesAsXml", new Object[] { "bar" }, new String[] { "java.lang.String" });
    assertNotNull(xml);
    log.info(xml);
    assertTrue("Should contain bar node", xml.contains("<toNode>bar</toNode>"));
    resetMocks();
    mock.expectedMessageCount(1);
    // resume breakpoint
    mbeanServer.invoke(on, "resumeBreakpoint", new Object[] { "bar" }, new String[] { "java.lang.String" });
    assertMockEndpointsSatisfied();
    // and no suspended anymore
    nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
    assertNotNull(nodes);
    assertEquals(0, nodes.size());
}
Also used : Set(java.util.Set) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 48 with MBeanServer

use of javax.management.MBeanServer in project camel by apache.

the class BacklogDebuggerTest method testBacklogDebugger.

@SuppressWarnings("unchecked")
public void testBacklogDebugger() 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=BacklogDebugger");
    assertNotNull(on);
    mbeanServer.isRegistered(on);
    Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
    assertEquals("Should not be enabled", Boolean.FALSE, enabled);
    // enable debugger
    mbeanServer.invoke(on, "enableDebugger", null, null);
    enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
    assertEquals("Should be enabled", Boolean.TRUE, enabled);
    // add breakpoint at bar
    mbeanServer.invoke(on, "addBreakpoint", new Object[] { "bar" }, new String[] { "java.lang.String" });
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(0);
    mock.setSleepForEmptyTest(1000);
    template.sendBody("seda:start", "Hello World");
    assertMockEndpointsSatisfied();
    // add breakpoint at bar
    Set<String> nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
    assertNotNull(nodes);
    assertEquals(1, nodes.size());
    assertEquals("bar", nodes.iterator().next());
    // the message should be ours
    String xml = (String) mbeanServer.invoke(on, "dumpTracedMessagesAsXml", new Object[] { "bar" }, new String[] { "java.lang.String" });
    assertNotNull(xml);
    log.info(xml);
    assertTrue("Should contain our body", xml.contains("Hello World"));
    assertTrue("Should contain bar node", xml.contains("<toNode>bar</toNode>"));
    resetMocks();
    mock.expectedMessageCount(1);
    // resume breakpoint
    mbeanServer.invoke(on, "resumeBreakpoint", new Object[] { "bar" }, new String[] { "java.lang.String" });
    assertMockEndpointsSatisfied();
    // and no suspended anymore
    nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
    assertNotNull(nodes);
    assertEquals(0, nodes.size());
}
Also used : Set(java.util.Set) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 49 with MBeanServer

use of javax.management.MBeanServer in project camel by apache.

the class BacklogTracerFilterTest method testBacklogTracerFilter.

@SuppressWarnings("unchecked")
public void testBacklogTracerFilter() 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 filter to match only if header foo exists
    mbeanServer.setAttribute(on, new Attribute("TraceFilter", "${header.foo} != null"));
    // 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.sendBodyAndHeader("direct:start", "Bye World", "foo", 123);
    assertMockEndpointsSatisfied();
    List<Exchange> exchanges = getMockEndpoint("mock:foo").getReceivedExchanges();
    List<BacklogTracerEventMessage> events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpAllTracedMessages", null, null);
    assertNotNull(events);
    assertEquals(3, events.size());
    BacklogTracerEventMessage event = events.get(0);
    assertEquals(null, event.getToNode());
    assertEquals("    <message exchangeId=\"" + exchanges.get(1).getExchangeId() + "\">\n" + "      <headers>\n" + "        <header key=\"foo\" type=\"java.lang.Integer\">123</header>\n" + "      </headers>\n" + "      <body type=\"java.lang.String\">Bye World</body>\n" + "    </message>", event.getMessageAsXml());
    BacklogTracerEventMessage event1 = events.get(1);
    assertEquals("foo", event1.getToNode());
    assertEquals("    <message exchangeId=\"" + exchanges.get(1).getExchangeId() + "\">\n" + "      <headers>\n" + "        <header key=\"foo\" type=\"java.lang.Integer\">123</header>\n" + "      </headers>\n" + "      <body type=\"java.lang.String\">Bye World</body>\n" + "    </message>", event1.getMessageAsXml());
    BacklogTracerEventMessage event2 = events.get(2);
    assertEquals("bar", event2.getToNode());
    assertEquals("    <message exchangeId=\"" + exchanges.get(1).getExchangeId() + "\">\n" + "      <headers>\n" + "        <header key=\"foo\" type=\"java.lang.Integer\">123</header>\n" + "      </headers>\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) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 50 with MBeanServer

use of javax.management.MBeanServer in project camel by apache.

the class BacklogTracerIdOnAllNodesTest 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);
    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());
    // enable it
    mbeanServer.setAttribute(on, new Attribute("Enabled", Boolean.TRUE));
    getMockEndpoint("mock:camel").expectedBodiesReceived("Hello Camel");
    getMockEndpoint("mock:other").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:end").expectedMessageCount(2);
    template.sendBody("direct:start", "Hello Camel");
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    List<Exchange> fooExchanges = getMockEndpoint("mock:foo").getReceivedExchanges();
    List<Exchange> camelExchanges = getMockEndpoint("mock:camel").getReceivedExchanges();
    RouteDefinition route = context.getRouteDefinitions().get(0);
    assertNotNull(route);
    ChoiceDefinition choice = (ChoiceDefinition) route.getOutputs().get(0);
    assertEquals("choice1", choice.getId());
    WhenDefinition when = (WhenDefinition) choice.getOutputs().get(0);
    assertEquals("when1", when.getId());
    LogDefinition log1 = (LogDefinition) when.getOutputs().get(0);
    assertEquals("log1", log1.getId());
    ToDefinition to1 = (ToDefinition) when.getOutputs().get(1);
    assertEquals("camel", to1.getId());
    OtherwiseDefinition other = (OtherwiseDefinition) choice.getOutputs().get(1);
    assertEquals("otherwise1", other.getId());
    LogDefinition log2 = (LogDefinition) other.getOutputs().get(0);
    assertEquals("log2", log2.getId());
    ToDefinition to2 = (ToDefinition) other.getOutputs().get(1);
    assertEquals("to1", to2.getId());
    ToDefinition to3 = (ToDefinition) other.getOutputs().get(2);
    assertEquals("foo", to3.getId());
    ToDefinition to4 = (ToDefinition) route.getOutputs().get(1);
    assertEquals("end", to4.getId());
    List<BacklogTracerEventMessage> events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "to1" }, new String[] { "java.lang.String" });
    assertNotNull(events);
    assertEquals(1, events.size());
    BacklogTracerEventMessage event1 = events.get(0);
    assertEquals("to1", event1.getToNode());
    assertEquals("    <message exchangeId=\"" + fooExchanges.get(0).getExchangeId() + "\">\n" + "      <body type=\"java.lang.String\">Hello World</body>\n" + "    </message>", event1.getMessageAsXml());
    events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "camel" }, new String[] { "java.lang.String" });
    assertNotNull(events);
    assertEquals(1, events.size());
    event1 = events.get(0);
    assertEquals("camel", event1.getToNode());
    assertEquals("    <message exchangeId=\"" + camelExchanges.get(0).getExchangeId() + "\">\n" + "      <body type=\"java.lang.String\">Hello Camel</body>\n" + "    </message>", event1.getMessageAsXml());
}
Also used : ToDefinition(org.apache.camel.model.ToDefinition) BacklogTracerEventMessage(org.apache.camel.api.management.mbean.BacklogTracerEventMessage) Attribute(javax.management.Attribute) OtherwiseDefinition(org.apache.camel.model.OtherwiseDefinition) ObjectName(javax.management.ObjectName) Exchange(org.apache.camel.Exchange) RouteDefinition(org.apache.camel.model.RouteDefinition) ChoiceDefinition(org.apache.camel.model.ChoiceDefinition) List(java.util.List) LogDefinition(org.apache.camel.model.LogDefinition) WhenDefinition(org.apache.camel.model.WhenDefinition) MBeanServer(javax.management.MBeanServer)

Aggregations

MBeanServer (javax.management.MBeanServer)830 ObjectName (javax.management.ObjectName)690 Test (org.junit.Test)143 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)93 MalformedObjectNameException (javax.management.MalformedObjectNameException)62 JMXServiceURL (javax.management.remote.JMXServiceURL)60 Attribute (javax.management.Attribute)56 IOException (java.io.IOException)54 HashMap (java.util.HashMap)51 TabularData (javax.management.openmbean.TabularData)51 JMXConnectorServer (javax.management.remote.JMXConnectorServer)44 JMXConnector (javax.management.remote.JMXConnector)37 ArrayList (java.util.ArrayList)35 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)34 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)34 InstanceNotFoundException (javax.management.InstanceNotFoundException)32 MBeanRegistrationException (javax.management.MBeanRegistrationException)29 Map (java.util.Map)28 MBeanServerConnection (javax.management.MBeanServerConnection)28 LocalMBeanServer (org.apache.openejb.monitoring.LocalMBeanServer)28