AgentServlet extends HttpServlet { @Override public void destroy() { backendManager.destroy(); if (discoveryMulticastResponder != null) { discoveryMulticastResponder.stop(); discoveryMulticastResponder = null; } super.destroy(); } AgentServlet();  AgentServlet(Restrictor pRestrictor); @Override void init(ServletConfig pServletConfig); @Override void destroy();  }
@Test public void initWithCustomAccessRestrictor() throws ServletException { prepareStandardInitialisation(); servlet.destroy(); }
@Test public void initWithAgentDiscoveryAndGivenUrl() throws ServletException, IOException, InterruptedException { checkMulticastAvailable(); String url = "http: prepareStandardInitialisation(ConfigKey.DISCOVERY_AGENT_URL.getKeyValue(), url); String multicastGroup = ConfigKey.MULTICAST_GROUP.getDefaultValue(); int multicastPort = Integer.valueOf(ConfigKey.MULTICAST_PORT.getDefaultValue()); Thread.sleep(1000); try { JolokiaDiscovery discovery = new JolokiaDiscovery("test", new QuietLogHandler()); List<JSONObject> in = discovery.lookupAgentsWithTimeoutAndMulticastAddress(500, multicastGroup, multicastPort); for (JSONObject json : in) { if (json.get("url") != null && json.get("url").equals(url)) { return; } } fail("No agent found"); } finally { servlet.destroy(); } }
@Test public void initWithAgentDiscoveryAndUrlLookup() throws ServletException, IOException { checkMulticastAvailable(); prepareStandardInitialisation(ConfigKey.DISCOVERY_ENABLED.getKeyValue(), "true"); try { JolokiaDiscovery discovery = new JolokiaDiscovery("test", new QuietLogHandler()); List<JSONObject> in = discovery.lookupAgents(); assertTrue(in.size() > 0); for (JSONObject json : in) { if (json.get("url") == null) { return; } } fail("Every message has an URL"); } finally { servlet.destroy(); } }