UnhealthyInfoModel { public UnhealthyInfoModel merge(UnhealthyInfoModel other) { if (null == other) return this; other.unhealthyInstance.forEach((cluster, shards) -> { shards.forEach((dcShardName, instances) -> { instances.forEach(redis -> { this.addUnhealthyInstance(cluster, dcShardName, redis); }); }); }); return this; } UnhealthyInfoModel(); UnhealthyInfoModel merge(UnhealthyInfoModel other); void addUnhealthyInstance(String cluster, String dc, String shard, HostPort redis); @JsonIgnore Set<String> getUnhealthyClusterNames(); List<Pair<String, String> > getUnhealthyDcShardByCluster(String clusterName); List<String> getUnhealthyClusterDesc(String clusterName); int countUnhealthyShardByCluster(String clusterName); int countUnhealthyRedisByCluster(String clusterName); int getUnhealthyCluster(); int getUnhealthyShard(); int getUnhealthyRedis(); List<String> getAttachFailDc(); void setAttachFailDc(List<String> attachFailDc); Map<String, Map<String, Set<HostPort>>> getUnhealthyInstance(); void setUnhealthyInstance(Map<String, Map<String, Set<HostPort>>> unhealthyInstance);  }
@Test public void testMerge() { UnhealthyInfoModel origin = new UnhealthyInfoModel(); UnhealthyInfoModel target = new UnhealthyInfoModel(); origin.addUnhealthyInstance("cluster1", "jq", "shard1", new HostPort("127.0.0.1", 6379)); target.addUnhealthyInstance("cluster2", "oy", "shard1", new HostPort("127.0.0.2", 6479)); origin.merge(target); Assert.assertEquals(2, origin.getUnhealthyCluster()); Assert.assertEquals(2, origin.getUnhealthyShard()); Assert.assertEquals(2, origin.getUnhealthyRedis()); target.addUnhealthyInstance("cluster1", "jq", "shard1", new HostPort("127.0.0.2", 6379)); origin.merge(target); Assert.assertEquals(2, origin.getUnhealthyCluster()); Assert.assertEquals(2, origin.getUnhealthyShard()); Assert.assertEquals(3, origin.getUnhealthyRedis()); }