Search in sources :

Example 1 with ObjectName

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

the class ManagedCircuitBreakerLoadBalancerTest method testManageCircuitBreakerLoadBalancer.

public void testManageCircuitBreakerLoadBalancer() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    getMockEndpoint("mock:foo").whenExchangeReceived(1, new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            throw new SQLException("Forced");
        }
    });
    MockEndpoint foo = getMockEndpoint("mock:foo");
    foo.expectedBodiesReceived("Hello World", "Bye World");
    try {
        template.sendBodyAndHeader("direct:start", "Hello World", "foo", "123");
        fail("Should fail");
    } catch (Exception e) {
        assertIsInstanceOf(SQLException.class, e.getCause());
        assertEquals("Forced", e.getCause().getMessage());
    }
    template.sendBodyAndHeader("direct:start", "Bye World", "foo", "123");
    assertMockEndpointsSatisfied();
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    // get the object name for the delayer
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mysend\"");
    // should be on route1
    String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
    assertEquals("route1", routeId);
    String camelId = (String) mbeanServer.getAttribute(on, "CamelId");
    assertEquals("camel-1", camelId);
    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals(ServiceStatus.Started.name(), state);
    Integer size = (Integer) mbeanServer.getAttribute(on, "Size");
    assertEquals(1, size.intValue());
    Long half = (Long) mbeanServer.getAttribute(on, "HalfOpenAfter");
    assertEquals(5000, half.longValue());
    Integer attempts = (Integer) mbeanServer.getAttribute(on, "Threshold");
    assertEquals(2, attempts.intValue());
    String exceptions = (String) mbeanServer.getAttribute(on, "Exceptions");
    assertEquals("java.io.IOException,java.sql.SQLException", exceptions);
    String cbState = (String) mbeanServer.getAttribute(on, "CircuitBreakerState");
    assertEquals("closed", cbState);
    String dump = (String) mbeanServer.invoke(on, "dumpState", null, null);
    assertTrue(dump.startsWith("State closed, failures 0, closed since"));
    TabularData data = (TabularData) mbeanServer.invoke(on, "exceptionStatistics", null, null);
    assertNotNull(data);
    assertEquals(2, data.size());
    data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { false }, new String[] { "boolean" });
    assertNotNull(data);
    assertEquals(2, data.size());
    data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { true }, new String[] { "boolean" });
    assertNotNull(data);
    assertEquals(5, data.size());
    String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
    assertNotNull(json);
    assertTrue(json.contains("\"description\": \"Balances message processing among a number of nodes"));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) SQLException(java.sql.SQLException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) SQLException(java.sql.SQLException) IOException(java.io.IOException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Example 2 with ObjectName

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

the class ManagedConvertBodyTest method testManageConvertBody.

public void testManageConvertBody() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MockEndpoint foo = getMockEndpoint("mock:foo");
    foo.expectedMessageCount(1);
    template.sendBodyAndHeader("direct:start", "Hello World", "foo", "123");
    assertMockEndpointsSatisfied();
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    // get the object name for the delayer
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mysend\"");
    // should be on route1
    String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
    assertEquals("route1", routeId);
    String camelId = (String) mbeanServer.getAttribute(on, "CamelId");
    assertEquals("camel-1", camelId);
    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals(ServiceStatus.Started.name(), state);
    String uri = (String) mbeanServer.getAttribute(on, "Type");
    assertEquals("byte[]", uri);
    TabularData data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { false }, new String[] { "boolean" });
    assertNotNull(data);
    assertEquals(2, data.size());
    data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { true }, new String[] { "boolean" });
    assertNotNull(data);
    assertEquals(4, data.size());
    String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
    assertNotNull(json);
    assertTrue(json.contains("\"description\": \"Converts the message body to another type"));
    assertTrue(json.contains("byte[]"));
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Example 3 with ObjectName

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

the class ManagedCustomBeanTest method testManageCustomBean.

public void testManageCustomBean() 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=\"custom\"");
    getMockEndpoint("mock:result").expectedMessageCount(1);
    getMockEndpoint("mock:result").expectedHeaderReceived("foo", "hey");
    template.sendBody("direct:start", "World");
    assertMockEndpointsSatisfied();
    String foo = (String) mbeanServer.getAttribute(on, "Foo");
    assertEquals("hey", foo);
    // change foo
    mbeanServer.setAttribute(on, new Attribute("Foo", "changed"));
    resetMocks();
    getMockEndpoint("mock:result").expectedMessageCount(1);
    getMockEndpoint("mock:result").expectedHeaderReceived("foo", "changed");
    template.sendBody("direct:start", "Camel");
    assertMockEndpointsSatisfied();
}
Also used : Attribute(javax.management.Attribute) ManagedAttribute(org.apache.camel.api.management.ManagedAttribute) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 4 with ObjectName

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

the class ManagedCustomComponentNameTest method testCustomName.

public void testCustomName() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MBeanServer mbeanServer = getMBeanServer();
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=components,*"), null);
    assertEquals(3, set.size());
    ObjectName on = set.iterator().next();
    assertTrue("Should be registered", mbeanServer.isRegistered(on));
    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals(ServiceStatus.Started.name(), state);
    String id = (String) mbeanServer.getAttribute(on, "CamelId");
    assertEquals("camel-1", id);
    context.stop();
    assertFalse("Should no longer be registered", mbeanServer.isRegistered(on));
    set = mbeanServer.queryNames(new ObjectName("*:type=components,*"), null);
    assertEquals("Should no longer be registered", 0, set.size());
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 5 with ObjectName

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

the class ManagedCustomPolicyTest method testPolicy.

public void testPolicy() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    assertEquals(1, counter.get());
    MBeanServer mbeanServer = getMBeanServer();
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), null);
    assertEquals(3, set.size());
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"foo\"");
    assertTrue("Should be registered: foo", mbeanServer.isRegistered(on));
    on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"result\"");
    assertTrue("Should be registered: result", mbeanServer.isRegistered(on));
    on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"bar\"");
    assertTrue("Should be registered: bar", mbeanServer.isRegistered(on));
}
Also used : 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