public DevelopmentProvider() throws Exception { MetricsSetup.withRegistry(getServices(), new MetricRegistry()). startJMXReporter(JMX_DOMAIN); getServices().addService(ControlService.class, new JMXControlService(JMX_DOMAIN, new Hashtable<>())); StreamScopeSetup.register(getServices()); HttpServer server = HttpServer.getInstance(); getServices().addService(HttpServer.class, server); server.startServer(); }
static void startProvider(DirectProvider provider) throws InterruptedException, ExecutionException { provider.getServices().addService(ControlService.class, new JMXControlService("org.apache.edgent.test.apps.runtime", new Hashtable<>())); AppService.createAndRegister(provider, provider); JobRegistry.createAndRegister(provider.getServices()); }
@Test(expected=RuntimeException.class) public void testDoubleunregister() throws Exception { ControlService cs = new JMXControlService(DOMAIN, new Hashtable<>()); String type = "timer"; String id = "a"; String alias = "ControlA"; String controlId = cs.registerControl(type, id, alias, TimerMBean.class, new Timer()); cs.unregister(controlId); cs.unregister(controlId); } }
@Test(expected=RuntimeException.class) public void testDoubleRegister() throws Exception { ControlService cs = new JMXControlService(DOMAIN, new Hashtable<>()); String type = "timer"; String id = "a"; String alias = "ControlA"; String controlId = cs.registerControl(type, id, alias, TimerMBean.class, new Timer()); try { cs.registerControl(type, id, alias, TimerMBean.class, new Timer()); } finally { cs.unregister(controlId); } } @Test(expected=RuntimeException.class)
@Test public void testControlObject() throws Exception { ControlService cs = new JMXControlService(DOMAIN, new Hashtable<>()); String type = "timer"; String id = "a"; String alias = "ControlA"; String controlId = cs.registerControl(type, id, alias, TimerMBean.class, new Timer()); assertNotNull(controlId); ObjectName on = ObjectName.getInstance(controlId); assertEquals(DOMAIN, on.getDomain()); assertEquals(type, ObjectName.unquote(on.getKeyProperty("type"))); assertEquals(id, ObjectName.unquote(on.getKeyProperty("id"))); assertEquals(alias, ObjectName.unquote(on.getKeyProperty("alias"))); assertEquals(TimerMBean.class.getName(), ObjectName.unquote(on.getKeyProperty("interface"))); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); assertTrue(mbs.isRegistered(on)); cs.unregister(controlId); assertFalse(mbs.isRegistered(on)); }
addKeys.put("device", ObjectName.quote("pi")); ControlService cs = new JMXControlService(DOMAIN, addKeys);