use of javax.management.ObjectName in project camel by apache.
the class JmxNotificationEventNotifierTest method testExchangeDone.
public void testExchangeDone() throws Exception {
// START SNIPPET: e2
// register the NotificationListener
ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=eventnotifiers,name=JmxEventNotifier");
MyNotificationListener listener = new MyNotificationListener();
context.getManagementStrategy().getManagementAgent().getMBeanServer().addNotificationListener(on, listener, new NotificationFilter() {
private static final long serialVersionUID = 1L;
public boolean isNotificationEnabled(Notification notification) {
return notification.getSource().equals("MyCamel");
}
}, null);
// END SNIPPET: e2
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
assertEquals("Get a wrong number of events", 8, listener.getEventCounter());
context.stop();
}
use of javax.management.ObjectName in project camel by apache.
the class ManagedAggregateControllerTest method testForceCompletionOfGroup.
@Test
public void testForceCompletionOfGroup() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MBeanServer mbeanServer = getMBeanServer();
ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"myAggregator\"");
assertTrue(mbeanServer.isRegistered(on));
getMockEndpoint("mock:aggregated").expectedMessageCount(0);
template.sendBodyAndHeader("direct:start", "test1", "id", "1");
template.sendBodyAndHeader("direct:start", "test2", "id", "2");
template.sendBodyAndHeader("direct:start", "test3", "id", "1");
template.sendBodyAndHeader("direct:start", "test4", "id", "2");
assertMockEndpointsSatisfied();
getMockEndpoint("mock:aggregated").expectedMessageCount(1);
getMockEndpoint("mock:aggregated").expectedBodiesReceivedInAnyOrder("test1test3");
getMockEndpoint("mock:aggregated").expectedPropertyReceived(Exchange.AGGREGATED_COMPLETED_BY, "force");
Integer pending = (Integer) mbeanServer.invoke(on, "aggregationRepositoryGroups", null, null);
assertEquals(2, pending.intValue());
Integer groups = (Integer) mbeanServer.invoke(on, "forceCompletionOfGroup", new Object[] { "1" }, new String[] { "java.lang.String" });
assertEquals(1, groups.intValue());
assertMockEndpointsSatisfied();
Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(4, completed.longValue());
completed = (Long) mbeanServer.getAttribute(on, "TotalCompleted");
assertEquals(1, completed.longValue());
Long in = (Long) mbeanServer.getAttribute(on, "TotalIn");
assertEquals(4, in.longValue());
Long byForced = (Long) mbeanServer.getAttribute(on, "CompletedByForce");
assertEquals(1, byForced.longValue());
Long bySize = (Long) mbeanServer.getAttribute(on, "CompletedBySize");
assertEquals(0, bySize.longValue());
Integer size = (Integer) mbeanServer.getAttribute(on, "CompletionSize");
assertEquals(10, size.longValue());
String lan = (String) mbeanServer.getAttribute(on, "CorrelationExpressionLanguage");
assertEquals("header", lan);
String cor = (String) mbeanServer.getAttribute(on, "CorrelationExpression");
assertEquals("id", cor);
Integer inflight = (Integer) mbeanServer.getAttribute(on, "InProgressCompleteExchanges");
assertEquals(0, inflight.intValue());
pending = (Integer) mbeanServer.invoke(on, "aggregationRepositoryGroups", null, null);
assertEquals(1, pending.intValue());
// we can also use the client mbean
ManagedAggregateProcessorMBean client = context.getManagedProcessor("myAggregator", ManagedAggregateProcessorMBean.class);
assertNotNull(client);
assertEquals(1, client.getCompletedByForce());
assertEquals(4, client.getTotalIn());
}
use of javax.management.ObjectName in project camel by apache.
the class ManagedAggregateControllerTest method testForceCompletionOfAll.
@Test
public void testForceCompletionOfAll() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MBeanServer mbeanServer = getMBeanServer();
ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"myAggregator\"");
assertTrue(mbeanServer.isRegistered(on));
getMockEndpoint("mock:aggregated").expectedMessageCount(0);
template.sendBodyAndHeader("direct:start", "test1", "id", "1");
template.sendBodyAndHeader("direct:start", "test2", "id", "2");
template.sendBodyAndHeader("direct:start", "test3", "id", "1");
template.sendBodyAndHeader("direct:start", "test4", "id", "2");
getMockEndpoint("mock:aggregated").expectedMessageCount(2);
getMockEndpoint("mock:aggregated").expectedBodiesReceivedInAnyOrder("test1test3", "test2test4");
getMockEndpoint("mock:aggregated").expectedPropertyReceived(Exchange.AGGREGATED_COMPLETED_BY, "force");
Integer pending = (Integer) mbeanServer.invoke(on, "aggregationRepositoryGroups", null, null);
assertEquals(2, pending.intValue());
Integer groups = (Integer) mbeanServer.invoke(on, "forceCompletionOfAllGroups", null, null);
assertEquals(2, groups.intValue());
assertMockEndpointsSatisfied();
Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(4, completed.longValue());
completed = (Long) mbeanServer.getAttribute(on, "TotalCompleted");
assertEquals(2, completed.longValue());
Long in = (Long) mbeanServer.getAttribute(on, "TotalIn");
assertEquals(4, in.longValue());
Long byForced = (Long) mbeanServer.getAttribute(on, "CompletedByForce");
assertEquals(2, byForced.longValue());
Long bySize = (Long) mbeanServer.getAttribute(on, "CompletedBySize");
assertEquals(0, bySize.longValue());
Integer size = (Integer) mbeanServer.getAttribute(on, "CompletionSize");
assertEquals(10, size.longValue());
String lan = (String) mbeanServer.getAttribute(on, "CorrelationExpressionLanguage");
assertEquals("header", lan);
String cor = (String) mbeanServer.getAttribute(on, "CorrelationExpression");
assertEquals("id", cor);
Integer inflight = (Integer) mbeanServer.getAttribute(on, "InProgressCompleteExchanges");
assertEquals(0, inflight.intValue());
pending = (Integer) mbeanServer.invoke(on, "aggregationRepositoryGroups", null, null);
assertEquals(0, pending.intValue());
}
use of javax.management.ObjectName in project camel by apache.
the class ManagedBrowsableEndpointAsXmlFileTest method testBrowseableEndpointAsXmlAllIncludeBody.
public void testBrowseableEndpointAsXmlAllIncludeBody() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
template.sendBodyAndHeader("direct:start", "Hello World", Exchange.FILE_NAME, "hello.txt");
MBeanServer mbeanServer = getMBeanServer();
ObjectName name = ObjectName.getInstance("org.apache.camel:context=camel-1,type=endpoints,name=\"file://target/files\"");
String out = (String) mbeanServer.invoke(name, "browseAllMessagesAsXml", new Object[] { true }, new String[] { "java.lang.Boolean" });
assertNotNull(out);
log.info(out);
assertTrue("Should contain the body", out.contains("Hello World</body>"));
}
use of javax.management.ObjectName in project camel by apache.
the class ManagedBrowsableEndpointAsXmlTest method testBrowseableEndpointAsXmlAll.
public void testBrowseableEndpointAsXmlAll() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
getMockEndpoint("mock:result").expectedMessageCount(2);
template.sendBodyAndHeader("direct:start", "Hello World", "foo", 123);
template.sendBodyAndHeader("direct:start", "Bye World", "foo", 456);
assertMockEndpointsSatisfied();
MBeanServer mbeanServer = getMBeanServer();
List<Exchange> exchanges = getMockEndpoint("mock:result").getReceivedExchanges();
ObjectName name = ObjectName.getInstance("org.apache.camel:context=camel-1,type=endpoints,name=\"mock://result\"");
String out = (String) mbeanServer.invoke(name, "browseAllMessagesAsXml", new Object[] { false }, new String[] { "java.lang.Boolean" });
assertNotNull(out);
log.info(out);
assertEquals("<messages>\n<message exchangeId=\"" + exchanges.get(0).getExchangeId() + "\">\n <headers>\n" + " <header key=\"foo\" type=\"java.lang.Integer\">123</header>\n </headers>\n</message>\n" + "<message exchangeId=\"" + exchanges.get(1).getExchangeId() + "\">\n <headers>\n <header key=\"foo\" type=\"java.lang.Integer\">456</header>\n </headers>\n" + "</message>\n</messages>", out);
}
Aggregations