GetMonitorData implements Activity { public void doUpdate(List<String> lines) { Map<String, Integer> values = Maps.newHashMap(); for ( String line : lines ) { String[] parts = line.split("\\s"); if ( parts.length == 2 ) { try { String name = parts[0]; int value = Integer.parseInt(parts[1]); values.put(name, value); } catch ( NumberFormatException ignore ) { } } } monitor.updateValues(values); } GetMonitorData(Exhibitor exhibitor, ZookeeperMonitoredData monitor); @Override void completed(boolean wasSuccessful); @Override Boolean call(); void doUpdate(List<String> lines);  }
@Test public void testSimple() { final String[] lines = { "zk_version 3.4.4-1386507, built on 09/17/2012 08:33 GMT", "zk_avg_latency 0", "zk_max_latency 0", "zk_min_latency 0", "zk_packets_received 1", "zk_num_alive_connections 1", "zk_outstanding_requests 0", "zk_server_state standalone", "zk_znode_count 5", "zk_watch_count 0", "zk_ephemerals_count 0", "zk_approximate_data_size 34", "zk_open_file_descriptor_count 46", "zk_max_file_descriptor_count 10240" }; ZookeeperMonitoredData zookeeperMonitoredData = new ZookeeperMonitoredData(); Assert.assertEquals(zookeeperMonitoredData.zk_ephemerals_count.get(), 0); Assert.assertEquals(zookeeperMonitoredData.zk_approximate_data_size.get(), 0); zookeeperMonitoredData.zk_packets_sent.set(10101); List<String> linesList = Arrays.asList(lines); GetMonitorData getMonitorData = new GetMonitorData(Mockito.mock(Exhibitor.class), zookeeperMonitoredData); getMonitorData.doUpdate(linesList); Assert.assertEquals(zookeeperMonitoredData.zk_ephemerals_count.get(), 0); Assert.assertEquals(zookeeperMonitoredData.zk_packets_received.get(), 1); Assert.assertEquals(zookeeperMonitoredData.zk_approximate_data_size.get(), 34); Assert.assertEquals(zookeeperMonitoredData.zk_max_file_descriptor_count.get(), 10240); Assert.assertEquals(zookeeperMonitoredData.zk_packets_sent.get(), 0); }