memChannel.stop();
pmemChannel.stop();
}
private void testWithPort(int port) throws Exception {
MonitorService srv = new HTTPMetricsServer();
Context context = new Context();
if(port > 1024){
context.put(HTTPMetricsServer.CONFIG_PORT, String.valueOf(port));
} else {
port = HTTPMetricsServer.DEFAULT_PORT;
}
srv.configure(context);
srv.start();
Thread.sleep(1000);
URL url = new URL("http://0.0.0.0:" + String.valueOf(port) + "/metrics");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
BufferedReader reader = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;
String result = "";
while ((line = reader.readLine()) != null) {
result += line;
}
reader.close();
Map<String, Map<String, String>> mbeans = gson.fromJson(result, mapType);
Assert.assertNotNull(mbeans);
Map<String, String> memBean = mbeans.get("CHANNEL.memChannel");
Assert.assertNotNull(memBean);
JMXTestUtils.checkChannelCounterParams(memBean);
Map<String, String> pmemBean = mbeans.get("CHANNEL.pmemChannel");
Assert.assertNotNull(pmemBean);
JMXTestUtils.checkChannelCounterParams(pmemBean);
srv.stop();
System.out.println(String.valueOf(port) + "test success!");
}