CheckCluster extends OuterClientService.AbstractInfo { @Override public boolean equals(Object obj) { if (!(obj instanceof CheckCluster)) { throw EqualsException.createClusterException(clusterName, "obj not cluster:" + obj); } CheckCluster other = (CheckCluster) obj; if (!(ObjectUtils.equals(clusterName, other.clusterName))) { throw EqualsException.createClusterException(clusterName, String.format("[clusterName Not Equal]%s, %s", clusterName, other.clusterName)); } try{ if(ObjectUtils.equals(shards, other.shards)){ return true; }else { throw EqualsException.createClusterException(clusterName, String.format("shard not equal:%s, %s", shards, other.getShards())); } }catch (EqualsException e){ e.setClusterName(clusterName); throw e; } } CheckCluster(String clusterName); void setClusterName(String clusterName); CheckShard getOrCreate(String shardName); String getClusterName(); Map<String, CheckShard> getShards(); @Override boolean equals(Object obj); void equalsException(Object obj); @Override int hashCode();  }
@Test public void testEquals() { CheckCluster cluster1 = new CheckCluster(clusterName); CheckCluster cluster2 = new CheckCluster(clusterName); cluster1.equals(cluster2); String[] shards = new String[]{"shard1", "shard2"}; CheckShard shard1 = cluster1.getOrCreate(shards[0]); shard1.addRedis(new CheckRedis("127.0.0.1", 6379, "jq")); try { cluster1.equals(cluster2); Assert.fail(); }catch (EqualsException e){ logger.info("{}", e.getMessage()); } CheckShard shard2 = cluster2.getOrCreate(shards[0]); try { cluster1.equals(cluster2); Assert.fail(); }catch (EqualsException e){ logger.info("{}", e.getMessage()); } shard2.addRedis(new CheckRedis("127.0.0.1", 6379, "jq")); cluster1.equals(cluster2); shard2.clearRedises(); shard2.addRedis(new CheckRedis("127.0.0.1", 6379, "oy")); try { cluster1.equals(cluster2); Assert.fail(); }catch (EqualsException e){ logger.info("{}", e.getMessage()); } }