DefaultClusterHealthMonitor implements ClusterHealthMonitor { @Override public void removeListener(Listener listener) { listeners.remove(listener); } DefaultClusterHealthMonitor(String clusterId, ShardService shardService); @Override String getClusterId(); @Override void healthCheckMasterDown(String shardId); @Override void healthCheckMasterUp(String shardId); @Override void outerClientMasterDown(String shardId); @Override void outerClientMasterUp(String shardId); @Override void addListener(Listener listener); @Override void removeListener(Listener listener); @Override ClusterHealthState getState();  }
@Test public void testRemoveListener() { final int[] count = {0}; ClusterHealthMonitor.Listener listener = new ClusterHealthMonitor.Listener() { @Override public void stateChange(String clusterId, ClusterHealthState pre, ClusterHealthState current) { logger.info("[stateChange][{}]{} -> {}", clusterId, pre, current); count[0]++; } }; monitor.addListener(listener); fakeShardService("shard1", "shard2", "shard3", "shard4"); monitor.healthCheckMasterDown("shard1"); monitor.healthCheckMasterDown("shard1"); monitor.healthCheckMasterDown("shard1"); monitor.healthCheckMasterDown("shard2"); monitor.healthCheckMasterDown("shard4"); monitor.removeListener(listener); monitor.healthCheckMasterDown("shard3"); Assert.assertEquals(3, count[0]); }