MetricLogger implements IZkDataListener, ConnectedComponent { protected void logMetric(MetricsRecord metrics) { switch (_outputType) { case Log4J: LOG.info(metrics); break; case SysOut: System.out.println(metrics.toString()); break; default: throw new IllegalStateException("output type " + _outputType + " not supported"); } _loggedRecords++; } MetricLogger(OutputType outputType, InteractionProtocol protocol); @Override void handleDataChange(String dataPath, Object data); @Override void handleDataDeleted(String dataPath); void join(); long getLoggedRecords(); @Override void disconnect(); @Override void reconnect();  }
@Test public void testLogMetric() throws Exception { InteractionProtocol protocol = _zk.createInteractionProtocol(); MetricLogger metricLogger = new MetricLogger(OutputType.Log4J, protocol); protocol.setMetric("node1", new MetricsRecord("node1")); Thread.sleep(500); protocol.setMetric("node1", new MetricsRecord("node1")); Thread.sleep(500); assertEquals(2, metricLogger.getLoggedRecords()); protocol.unregisterComponent(metricLogger); protocol.disconnect(); }