ShardMetaComparator extends AbstractMetaComparator<Redis, ShardChange> { @Override public void compare() { List<Redis> currentAll = getAll(current); List<Redis> futureAll = getAll(future); Pair<List<Redis>, List<Pair<Redis, Redis>>> subResult = sub(futureAll, currentAll); List<Redis> tAdded = subResult.getKey(); added.addAll(tAdded); List<Pair<Redis, Redis>> modified = subResult.getValue(); compareConfigConfig(modified); List<Redis> tRemoved = sub(currentAll, futureAll).getKey(); removed.addAll(tRemoved); } ShardMetaComparator(ShardMeta current, ShardMeta future); @Override void compare(); ShardMeta getCurrent(); ShardMeta getFuture(); @Override String idDesc();  }
@Test public void testRemove(){ KeeperMeta removed = differentKeeper(current); current.addKeeper(removed); ShardMetaComparator comparator = new ShardMetaComparator(current, future); comparator.compare(); Assert.assertEquals(0, comparator.getAdded().size()); Assert.assertEquals(1, comparator.getRemoved().size()); Assert.assertEquals(removed, comparator.getRemoved().toArray()[0]); Assert.assertEquals(0, comparator.getMofified().size()); }
@Test public void testAdd(){ KeeperMeta added = differentKeeper(current); future.addKeeper(added); ShardMetaComparator comparator = new ShardMetaComparator(current, future); comparator.compare(); Assert.assertEquals(1, comparator.getAdded().size()); Assert.assertEquals(added, comparator.getAdded().toArray()[0]); Assert.assertEquals(0, comparator.getRemoved().size()); Assert.assertEquals(0, comparator.getMofified().size()); }
@Test public void testEquals(){ ShardMetaComparator comparator = new ShardMetaComparator(current, future); comparator.compare(); Assert.assertEquals(0, comparator.getAdded().size()); Assert.assertEquals(0, comparator.getRemoved().size()); Assert.assertEquals(0, comparator.getMofified().size()); }
@Test public void testEqualsWithSentinelIdChanged(){ long currentSentinelId = future.getSentinelId() == null ? 0 : future.getSentinelId(); future.setSentinelId( currentSentinelId + 100 ); ShardMetaComparator comparator = new ShardMetaComparator(current, future); comparator.compare(); Assert.assertEquals(0, comparator.getAdded().size()); Assert.assertEquals(0, comparator.getRemoved().size()); Assert.assertEquals(0, comparator.getMofified().size()); }