Search in sources :

Example 6 with ObjectName

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

the class ManagedErrorHandlerOptionsTest method testManagedErrorHandlerOptions.

public void testManagedErrorHandlerOptions() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    counter = 0;
    MBeanServer mbeanServer = getMBeanServer();
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=errorhandlers,*"), null);
    assertEquals(1, set.size());
    ObjectName on = set.iterator().next();
    mbeanServer.setAttribute(on, new Attribute("MaximumRedeliveries", 3));
    Integer max = (Integer) mbeanServer.getAttribute(on, "MaximumRedeliveries");
    assertEquals(3, max.intValue());
    mbeanServer.setAttribute(on, new Attribute("MaximumRedeliveryDelay", Long.valueOf("20000")));
    Long delay = (Long) mbeanServer.getAttribute(on, "MaximumRedeliveryDelay");
    assertEquals(20000, delay.longValue());
    mbeanServer.setAttribute(on, new Attribute("RedeliveryDelay", Long.valueOf("250")));
    delay = (Long) mbeanServer.getAttribute(on, "RedeliveryDelay");
    assertEquals(250, delay.longValue());
    String camelId = (String) mbeanServer.getAttribute(on, "CamelId");
    assertEquals("camel-1", camelId);
    mbeanServer.setAttribute(on, new Attribute("BackOffMultiplier", Double.valueOf("3.5")));
    Double backoff = (Double) mbeanServer.getAttribute(on, "BackOffMultiplier");
    assertNotNull(backoff);
    mbeanServer.setAttribute(on, new Attribute("CollisionAvoidanceFactor", Double.valueOf("1.5")));
    Double cf = (Double) mbeanServer.getAttribute(on, "CollisionAvoidanceFactor");
    assertNotNull(cf);
    mbeanServer.setAttribute(on, new Attribute("CollisionAvoidancePercent", Double.valueOf("75")));
    Double cp = (Double) mbeanServer.getAttribute(on, "CollisionAvoidancePercent");
    assertNotNull(cp);
    mbeanServer.setAttribute(on, new Attribute("DelayPattern", "0:1000;5:5000"));
    String dp = (String) mbeanServer.getAttribute(on, "DelayPattern");
    assertNotNull(dp);
    mbeanServer.setAttribute(on, new Attribute("RetriesExhaustedLogLevel", "WARN"));
    String ell = (String) mbeanServer.getAttribute(on, "RetriesExhaustedLogLevel");
    assertEquals(LoggingLevel.WARN.name(), ell);
    mbeanServer.setAttribute(on, new Attribute("RetryAttemptedLogLevel", "WARN"));
    String rll = (String) mbeanServer.getAttribute(on, "RetryAttemptedLogLevel");
    assertEquals(LoggingLevel.WARN.name(), rll);
    mbeanServer.setAttribute(on, new Attribute("LogStackTrace", Boolean.TRUE));
    Boolean lst = (Boolean) mbeanServer.getAttribute(on, "LogStackTrace");
    assertEquals(true, lst.booleanValue());
    mbeanServer.setAttribute(on, new Attribute("UseCollisionAvoidance", Boolean.TRUE));
    Boolean uca = (Boolean) mbeanServer.getAttribute(on, "UseCollisionAvoidance");
    assertEquals(true, uca.booleanValue());
    mbeanServer.setAttribute(on, new Attribute("UseExponentialBackOff", Boolean.TRUE));
    Boolean uebf = (Boolean) mbeanServer.getAttribute(on, "UseExponentialBackOff");
    assertEquals(true, uebf.booleanValue());
    Boolean ne = (Boolean) mbeanServer.getAttribute(on, "DeadLetterHandleNewException");
    assertEquals(false, ne.booleanValue());
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertEquals(3, counter);
    assertMockEndpointsSatisfied();
    // now change to 0 attempts and try again
    counter = 0;
    mock.reset();
    mock.expectedMessageCount(0);
    mbeanServer.setAttribute(on, new Attribute("MaximumRedeliveries", 0));
    try {
        template.sendBody("direct:start", "Bye World");
        fail("Should have thrown exception");
    } catch (CamelExecutionException e) {
        IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
        assertEquals("Forced", cause.getMessage());
    }
    assertEquals(1, counter);
    // and should now be 0
    max = (Integer) mbeanServer.getAttribute(on, "MaximumRedeliveries");
    assertEquals(0, max.intValue());
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) Attribute(javax.management.Attribute) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 7 with ObjectName

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

the class ManagedErrorHandlerTest method testManagedErrorHandler.

public void testManagedErrorHandler() 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=errorhandlers,*"), null);
    // there should only be 2 error handler types as route 1 and route 3 uses the same default error handler
    assertEquals(2, set.size());
    Iterator<ObjectName> it = set.iterator();
    ObjectName on1 = it.next();
    ObjectName on2 = it.next();
    String name1 = on1.getCanonicalName();
    String name2 = on2.getCanonicalName();
    assertTrue("Should be a default error handler", name1.contains("CamelDefaultErrorHandlerBuilder") || name2.contains("CamelDefaultErrorHandlerBuilder"));
    assertTrue("Should be a dead letter error handler", name1.contains("DeadLetterChannelBuilder") || name2.contains("DeadLetterChannelBuilder"));
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 8 with ObjectName

use of javax.management.ObjectName 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 9 with ObjectName

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

the class ManagedFromRestGetEmbeddedRouteTest method testFromRestModel.

public void testFromRestModel() 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=context,name=\"camel-1\"");
    String xml = (String) mbeanServer.invoke(on, "dumpRestsAsXml", null, null);
    assertNotNull(xml);
    log.info(xml);
    assertTrue(xml.contains("<rests"));
    assertTrue(xml.contains("<rest path=\"/say/hello\">"));
    assertTrue(xml.contains("<rest path=\"/say/bye\">"));
    assertTrue(xml.contains("</rest>"));
    assertTrue(xml.contains("<get"));
    assertTrue(xml.contains("<route"));
    assertTrue(xml.contains("<transform"));
    assertTrue(xml.contains("<post"));
    assertTrue(xml.contains("application/json"));
    assertTrue(xml.contains("</rests>"));
    String xml2 = (String) mbeanServer.invoke(on, "dumpRoutesAsXml", null, null);
    log.info(xml2);
    // and we should have rest in the routes that indicate its from a rest dsl
    assertTrue(xml2.contains("rest=\"true\""));
    // there should be 2 + 1 routes
    assertEquals(2 + 1, context.getRouteDefinitions().size());
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 10 with ObjectName

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

the class ManagedFromRestPlaceholderTest method testFromRestModelPlaceholder.

public void testFromRestModelPlaceholder() 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=context,name=\"camel-1\"");
    String xml = (String) mbeanServer.invoke(on, "dumpRestsAsXml", new Object[] { true }, new String[] { "boolean" });
    assertNotNull(xml);
    log.info(xml);
    assertTrue(xml.contains("<rests"));
    assertTrue(xml.contains("<rest path=\"/say/hello\">"));
    assertTrue(xml.contains("<rest path=\"/say/bye\">"));
    assertTrue(xml.contains("</rest>"));
    assertTrue(xml.contains("<get"));
    assertTrue(xml.contains("application/json"));
    assertTrue(xml.contains("<post"));
    assertTrue(xml.contains("application/json"));
    assertTrue(xml.contains("</rests>"));
    assertTrue(xml.contains("<param collectionFormat=\"multi\" dataType=\"string\" defaultValue=\"b\" description=\"header param description2\" " + "name=\"header_letter\" required=\"false\" type=\"query\">"));
    assertTrue(xml.contains("<param dataType=\"integer\" defaultValue=\"1\" description=\"header param description1\" " + "name=\"header_count\" required=\"true\" type=\"header\">"));
    assertTrue(xml.contains("<value>1</value>"));
    assertTrue(xml.contains("<value>a</value>"));
    assertTrue(xml.contains("<responseMessage code=\"300\" message=\"test msg\" responseModel=\"java.lang.Integer\"/>"));
    String xml2 = (String) mbeanServer.invoke(on, "dumpRoutesAsXml", null, null);
    log.info(xml2);
    // and we should have rest in the routes that indicate its from a rest dsl
    assertTrue(xml2.contains("rest=\"true\""));
    // there should be 3 + 2 routes
    assertEquals(3 + 2, context.getRouteDefinitions().size());
}
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