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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations