ClusterMetaComparator extends AbstractMetaComparator<ShardMeta, ClusterChange> { @Override public void compare() { Triple<Set<String>, Set<String>, Set<String>> result = getDiff(current.getShards().keySet(), future.getShards().keySet()); for(String shardId : result.getFirst()){ added.add(future.findShard(shardId)); } for(String shardId : result.getLast()){ removed.add(current.findShard(shardId)); } for(String shardId : result.getMiddle()){ ShardMeta currentMeta = current.findShard(shardId); ShardMeta futureMeta = future.findShard(shardId); if(!reflectionEquals(currentMeta, futureMeta)){ ShardMetaComparator comparator = new ShardMetaComparator(currentMeta, futureMeta); comparator.compare(); modified.add(comparator); } } } ClusterMetaComparator(ClusterMeta current, ClusterMeta future); @Override void compare(); ClusterMeta getCurrent(); ClusterMeta getFuture(); @Override String idDesc();  }
@Test public void testAdded(){ ShardMeta shard = differentShard(current); future.addShard(shard); ClusterMetaComparator clusterMetaComparator = new ClusterMetaComparator(current, future); clusterMetaComparator.compare(); Assert.assertEquals(1, clusterMetaComparator.getAdded().size()); Assert.assertEquals(shard, clusterMetaComparator.getAdded().toArray()[0]); Assert.assertEquals(0, clusterMetaComparator.getRemoved().size()); Assert.assertEquals(0, clusterMetaComparator.getMofified().size()); }
@Test public void testEqual(){ ClusterMetaComparator clusterMetaComparator = new ClusterMetaComparator(current, future); clusterMetaComparator.compare(); Assert.assertEquals(0, clusterMetaComparator.getAdded().size()); Assert.assertEquals(0, clusterMetaComparator.getRemoved().size()); Assert.assertEquals(0, clusterMetaComparator.getMofified().size()); }
@Test public void testRemoved(){ ShardMeta shard = differentShard(current); current.addShard(shard); ClusterMetaComparator clusterMetaComparator = new ClusterMetaComparator(current, future); clusterMetaComparator.compare(); Assert.assertEquals(0, clusterMetaComparator.getAdded().size()); Assert.assertEquals(1, clusterMetaComparator.getRemoved().size()); Assert.assertEquals(shard, clusterMetaComparator.getRemoved().toArray()[0]); Assert.assertEquals(0, clusterMetaComparator.getMofified().size()); }