Search in sources :

Example 1 with TabularData

use of javax.management.openmbean.TabularData 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 TabularData

use of javax.management.openmbean.TabularData 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 TabularData

use of javax.management.openmbean.TabularData in project camel by apache.

the class ManagedFailoverLoadBalancerTest method testManageFailoverLoadBalancer.

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

        @Override
        public void process(Exchange exchange) throws Exception {
            throw new IOException("Forced");
        }
    });
    MockEndpoint bar = getMockEndpoint("mock:bar");
    bar.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);
    Integer size = (Integer) mbeanServer.getAttribute(on, "Size");
    assertEquals(2, size.intValue());
    Boolean roundRobin = (Boolean) mbeanServer.getAttribute(on, "RoundRobin");
    assertEquals(true, roundRobin.booleanValue());
    Boolean sticky = (Boolean) mbeanServer.getAttribute(on, "Sticky");
    assertEquals(true, sticky.booleanValue());
    Integer attempts = (Integer) mbeanServer.getAttribute(on, "MaximumFailoverAttempts");
    assertEquals(3, attempts.intValue());
    String exceptions = (String) mbeanServer.getAttribute(on, "Exceptions");
    assertEquals("java.io.IOException,java.sql.SQLException", exceptions);
    String id = (String) mbeanServer.getAttribute(on, "LastGoodProcessorId");
    assertEquals("bar", id);
    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(3, 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) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) IOException(java.io.IOException) SQLException(java.sql.SQLException) IOException(java.io.IOException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Example 4 with TabularData

use of javax.management.openmbean.TabularData in project camel by apache.

the class ManagedListComponentsTest method testListComponents.

public void testListComponents() 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=20-camel-1,type=context,name=\"camel-1\"");
    // list all components found in classpath
    TabularData data = (TabularData) mbeanServer.invoke(on, "listComponents", null, null);
    assertTrue("There should be more than 20 components", data.size() > 20);
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Example 5 with TabularData

use of javax.management.openmbean.TabularData in project camel by apache.

the class ManagedRecipientListTest method testManageRecipientList.

public void testManageRecipientList() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MockEndpoint foo = getMockEndpoint("mock:foo");
    foo.expectedMessageCount(2);
    MockEndpoint bar = getMockEndpoint("mock:bar");
    bar.expectedMessageCount(1);
    template.sendBodyAndHeader("direct:start", "Hello World", "whereto", "mock:foo");
    template.sendBodyAndHeader("direct:start", "Bye World", "whereto", "mock:foo");
    template.sendBodyAndHeader("direct:start", "Hi World", "whereto", "mock:bar");
    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);
    Boolean parallel = (Boolean) mbeanServer.getAttribute(on, "ParallelProcessing");
    assertEquals(false, parallel.booleanValue());
    String lan = (String) mbeanServer.getAttribute(on, "ExpressionLanguage");
    assertEquals("header", lan);
    String uri = (String) mbeanServer.getAttribute(on, "Expression");
    assertEquals("whereto", uri);
    TabularData data = (TabularData) mbeanServer.invoke(on, "extendedInformation", 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(18, data.size());
    String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
    assertNotNull(json);
    assertTrue(json.contains("\"description\": \"Routes messages to a number of dynamically specified recipients (dynamic to)"));
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Aggregations

TabularData (javax.management.openmbean.TabularData)183 CompositeData (javax.management.openmbean.CompositeData)91 TabularDataSupport (javax.management.openmbean.TabularDataSupport)67 ObjectName (javax.management.ObjectName)54 MBeanServer (javax.management.MBeanServer)50 CompositeType (javax.management.openmbean.CompositeType)47 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)43 Test (org.junit.Test)38 Map (java.util.Map)28 ArrayList (java.util.ArrayList)23 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)21 HashMap (java.util.HashMap)20 TabularType (javax.management.openmbean.TabularType)17 Bundle (org.osgi.framework.Bundle)17 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)15 Collection (java.util.Collection)13 IOException (java.io.IOException)11 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)9 List (java.util.List)8 ServiceReference (org.osgi.framework.ServiceReference)8