Search in sources :

Example 41 with ObjectName

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();
}
Also used : NotificationFilter(javax.management.NotificationFilter) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName)

Example 42 with ObjectName

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());
}
Also used : ManagedAggregateProcessorMBean(org.apache.camel.api.management.mbean.ManagedAggregateProcessorMBean) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 43 with ObjectName

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());
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 44 with ObjectName

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>"));
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 45 with ObjectName

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);
}
Also used : Exchange(org.apache.camel.Exchange) 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