MulticastSocketListenerThread extends Thread { public synchronized void shutdown() { setRunning(false); interrupt(); socket.close(); } MulticastSocketListenerThread(String name, InetAddress pHostAddress, AgentDetailsHolder pAgentDetailsHolder, Restrictor pRestrictor, String pMulticastGroup, int pMulticastPort, LogHandler pLogHandler); void run(); synchronized boolean isRunning(); synchronized void shutdown();  }
@Test public void simple() throws IOException, InterruptedException { checkForMulticastSupport(); MulticastSocketListenerThread listenerThread = startSocketListener(); try { DiscoveryOutgoingMessage out = new DiscoveryOutgoingMessage.Builder(QUERY) .agentId(UUID.randomUUID().toString()) .build(); List<DiscoveryIncomingMessage> discovered = sendQueryAndCollectAnswers(out, 500, MULTICAST_GROUP, MULTICAST_PORT, new LogHandler.StdoutLogHandler(true)); int idCount = 0; int urlCount = 0; for (DiscoveryIncomingMessage in : discovered) { AgentDetails agentDetails = in.getAgentDetails(); if (agentDetails.getAgentId().equals(id)) { idCount++; } if (JOLOKIA_URL.equals(in.getAgentDetails().toJSONObject().get("url"))) { urlCount++; } assertFalse(in.isQuery()); JSONObject details = agentDetails.toJSONObject(); if (details.get("server_vendor") != null && details.get("server_vendor").equals("jolokia")) { assertEquals(details.get("url"), JOLOKIA_URL); assertEquals(details.get("agent_version"), Version.getAgentVersion()); return; } } assertEquals(idCount,1,"Exactly one in message with the send id should have been received"); assertEquals(urlCount,1,"Only one message with the url should be included"); fail("No message found"); } finally { listenerThread.shutdown(); } }