public void testManagedCamelContextClient() throws Exception { // JMX tests dont work well on AIX CI servers (hangs them) if (isPlatform("aix")) { return; } ManagedCamelContextMBean client = context.getManagedCamelContext(); assertNotNull(client); assertEquals("camel-1", client.getCamelId()); assertEquals("Started", client.getState()); List<String> names = client.findComponentNames(); assertNotNull(names); assertTrue(names.contains("mock")); }
public ManagedCamelContextMBean getManagedCamelContext() { // jmx must be enabled if (getManagementStrategy().getManagementAgent() == null) { return null; } try { ObjectName on = getManagementStrategy().getManagementNamingStrategy().getObjectNameForCamelContext(this); return getManagementStrategy().getManagementAgent().newProxyClient(on, ManagedCamelContextMBean.class); } catch (MalformedObjectNameException e) { throw ObjectHelper.wrapRuntimeCamelException(e); } }
public void testNewProxy() 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\""); ManagedCamelContextMBean proxy = JMX.newMBeanProxy(mbeanServer, on, ManagedCamelContextMBean.class); assertNotNull(proxy); }
public void connect(String serviceUrl) throws Exception { JMXServiceURL url = new JMXServiceURL(serviceUrl); connector = JMXConnectorFactory.connect(url, null); connection = connector.getMBeanServerConnection(); // create a mbean proxy so we can use the type safe api ObjectName on = new ObjectName("org.apache.camel:context=camel-1,type=context,name=\"camel-1\""); proxy = JMX.newMBeanProxy(connection, on, ManagedCamelContextMBean.class); }
@After public void tearDown() throws Exception { long time = watch.stop(); log.info("********************************************************************************"); log.info("Testing done: " + getTestMethodName() + "(" + getClass().getName() + ")"); log.info("Took: " + TimeUtils.printDuration(time) + " (" + time + " millis)"); // if we should dump route stats, then write that to a file if (isDumpRouteCoverage()) { String className = this.getClass().getSimpleName(); String dir = "target/camel-route-coverage"; String name = className + "-" + getTestMethodName() + ".xml"; ManagedCamelContextMBean managedCamelContext = context.getManagedCamelContext(); if (managedCamelContext == null) { log.warn("Cannot dump route coverage to file as JMX is not enabled. Override useJmx() method to enable JMX in the unit test classes."); } else { String xml = managedCamelContext.dumpRoutesCoverageAsXml(); String combined = "<camelRouteCoverage>\n" + gatherTestDetailsAsXml() + xml + "\n</camelRouteCoverage>"; File file = new File(dir); // ensure dir exists file.mkdirs(); file = new File(dir, name); log.info("Dumping route coverage to file: " + file); InputStream is = new ByteArrayInputStream(combined.getBytes()); OutputStream os = new FileOutputStream(file, false); IOHelper.copyAndCloseInput(is, os); IOHelper.close(os); } } log.info("********************************************************************************"); if (isCreateCamelContextPerClass()) { // we tear down in after class return; } LOG.debug("tearDown test"); doStopTemplates(consumer, template); doStopCamelContext(context, camelContextService); }
@Override public ManagedCamelContextMBean getManagedCamelContext() { return context.getManagedCamelContext(); }
/** * Gets the managed Camel context client api */ ManagedCamelContextMBean getManagedCamelContext();