Search in sources :

Example 46 with ObjectName

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

the class BacklogDebuggerTest method testBacklogDebuggerRemoveBodyAndHeader.

@SuppressWarnings("unchecked")
public void testBacklogDebuggerRemoveBodyAndHeader() 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, "removeMessageBodyOnBreakpoint", new Object[] { "foo" }, new String[] { "java.lang.String" });
    mbeanServer.invoke(on, "removeMessageHeaderOnBreakpoint", new Object[] { "foo", "beer" }, new String[] { "java.lang.String", "java.lang.String" });
    // 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 not contain our body", xml.contains("<body>[Body is null]</body>"));
    assertTrue("Should contain bar node", xml.contains("<toNode>bar</toNode>"));
    assertFalse("Should not contain any headers", xml.contains("<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 ObjectName

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

the class BacklogDebuggerTest method testBacklogDebuggerConditional.

@SuppressWarnings("unchecked")
public void testBacklogDebuggerConditional() 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);
    // validate conditional breakpoint (mistake on purpose)
    Object out = mbeanServer.invoke(on, "validateConditionalBreakpoint", new Object[] { "unknown", "${body contains 'Camel'" }, new String[] { "java.lang.String", "java.lang.String" });
    assertEquals("No language could be found for: unknown", out);
    // validate conditional breakpoint (mistake on purpose)
    out = mbeanServer.invoke(on, "validateConditionalBreakpoint", new Object[] { "simple", "${body contains 'Camel'" }, new String[] { "java.lang.String", "java.lang.String" });
    assertNotNull(out);
    assertTrue(out.toString().startsWith("Invalid syntax ${body contains 'Camel'"));
    // validate conditional breakpoint (is correct)
    out = mbeanServer.invoke(on, "validateConditionalBreakpoint", new Object[] { "simple", "${body} contains 'Camel'" }, new String[] { "java.lang.String", "java.lang.String" });
    assertNull(out);
    // add breakpoint at bar
    mbeanServer.invoke(on, "addConditionalBreakpoint", new Object[] { "bar", "simple", "${body} contains 'Camel'" }, new String[] { "java.lang.String", "java.lang.String", "java.lang.String" });
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    template.sendBody("seda:start", "Hello World");
    assertMockEndpointsSatisfied();
    // add not breakpoint at bar as condition did not match
    Set<String> nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
    assertNotNull(nodes);
    assertEquals(0, nodes.size());
    resetMocks();
    mock.expectedMessageCount(0);
    mock.setSleepForEmptyTest(1000);
    template.sendBody("seda:start", "Hello Camel");
    assertMockEndpointsSatisfied();
    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 Camel"));
    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 ObjectName

use of javax.management.ObjectName 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 49 with ObjectName

use of javax.management.ObjectName 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 50 with ObjectName

use of javax.management.ObjectName 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)

Aggregations

ObjectName (javax.management.ObjectName)1515 MBeanServer (javax.management.MBeanServer)691 Test (org.junit.Test)258 MalformedObjectNameException (javax.management.MalformedObjectNameException)168 IOException (java.io.IOException)101 HashMap (java.util.HashMap)99 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)97 Attribute (javax.management.Attribute)94 InstanceNotFoundException (javax.management.InstanceNotFoundException)94 ArrayList (java.util.ArrayList)91 MBeanServerConnection (javax.management.MBeanServerConnection)72 Map (java.util.Map)66 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)66 MBeanInfo (javax.management.MBeanInfo)64 TabularData (javax.management.openmbean.TabularData)55 JMXServiceURL (javax.management.remote.JMXServiceURL)55 MBeanRegistrationException (javax.management.MBeanRegistrationException)53 JMXConnector (javax.management.remote.JMXConnector)53 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)48 Notification (javax.management.Notification)47