DefaultDcMetaChangeManager extends AbstractStartStoppable implements DcMetaChangeManager, MetaComparatorVisitor<ClusterMeta> { @Override public void visitModified(MetaComparator comparator) { ClusterMetaComparator clusterMetaComparator = (ClusterMetaComparator) comparator; updateDcInterested(clusterMetaComparator); clusterMetaComparator.accept(new ClusterMetaComparatorVisitor(addConsumer, removeConsumer, redisChanged)); } DefaultDcMetaChangeManager(HealthCheckInstanceManager instanceManager); @Override void compare(DcMeta future); @Override void visitAdded(ClusterMeta added); @Override void visitModified(MetaComparator comparator); @Override void visitRemoved(ClusterMeta removed);  }
@Test public void visitModified() { ClusterMeta clusterMeta = getDcMeta("oy").findCluster("cluster2"); ClusterMeta clone = MetaClone.clone(clusterMeta); clone.getShards().get("shard2").addRedis(new RedisMeta()); manager.visitModified(new ClusterMetaComparator(clusterMeta, clone)); verify(instanceManager, never()).getOrCreate(any()); }
@Test public void testActiveDcInterestedNotChange() { ClusterMeta cluster = getDcMeta("oy").findCluster("cluster2"); ClusterMeta newCluster = MetaClone.clone(cluster); newCluster.setActiveDc("rb"); manager.visitModified(new ClusterMetaComparator(cluster, newCluster)); Mockito.verify(instanceManager, never()).getOrCreate(any()); Mockito.verify(instanceManager, never()).remove(any()); cluster = getDcMeta("oy").findCluster("cluster1"); newCluster = MetaClone.clone(cluster); manager.visitModified(new ClusterMetaComparator(cluster, newCluster)); Mockito.verify(instanceManager, never()).getOrCreate(any()); Mockito.verify(instanceManager, never()).remove(any()); }
@Test public void testActiveDcOY2JQ() { ClusterMeta cluster = getDcMeta("oy").findCluster("cluster2"); ClusterMeta newCluster = MetaClone.clone(cluster); newCluster.setActiveDc("jq"); manager.visitModified(new ClusterMetaComparator(cluster, newCluster)); Mockito.verify(instanceManager, times(2)).getOrCreate(any()); Mockito.verify(instanceManager, never()).remove(any()); Assert.assertEquals(Sets.newHashSet(new HostPort("127.0.0.2", 8100), new HostPort("127.0.0.2", 8101)), addedRedises); }
@Test public void testActiveDcJQ2OY() { ClusterMeta cluster = getDcMeta("oy").findCluster("cluster1"); ClusterMeta newCluster = MetaClone.clone(cluster); newCluster.setActiveDc("oy"); manager.visitModified(new ClusterMetaComparator(cluster, newCluster)); Mockito.verify(instanceManager, never()).getOrCreate(any()); Mockito.verify(instanceManager, times(2)).remove(any()); Assert.assertEquals(Sets.newHashSet(new HostPort("127.0.0.1", 8100), new HostPort("127.0.0.1", 8101)), deletedRedised); }
@Test public void testDcsInterestedNotChange() { ClusterMeta cluster = getDcMeta("oy").findCluster("cluster4"); ClusterMeta newCluster = MetaClone.clone(cluster); newCluster.setDcs("rb"); manager.visitModified(new ClusterMetaComparator(cluster, newCluster)); Mockito.verify(instanceManager, never()).getOrCreate(any()); Mockito.verify(instanceManager, never()).remove(any()); cluster = getDcMeta("oy").findCluster("cluster3"); newCluster = MetaClone.clone(cluster); newCluster.setDcs("jq,oy,rb"); manager.visitModified(new ClusterMetaComparator(cluster, newCluster)); Mockito.verify(instanceManager, never()).getOrCreate(any()); Mockito.verify(instanceManager, never()).remove(any()); }
@Test public void testDcsAddCurrentDc() { ClusterMeta cluster = getDcMeta("oy").findCluster("cluster4"); ClusterMeta newCluster = MetaClone.clone(cluster); newCluster.setDcs("jq,oy"); manager.visitModified(new ClusterMetaComparator(cluster, newCluster)); Mockito.verify(instanceManager, times(1)).getOrCreate(any()); Mockito.verify(instanceManager, never()).remove(any()); Assert.assertEquals(Sets.newHashSet(new HostPort("10.0.0.2", 6479)), addedRedises); }
@Test public void testDcsDeleteCurrentDc() { ClusterMeta cluster = getDcMeta("oy").findCluster("cluster3"); ClusterMeta newCluster = MetaClone.clone(cluster); newCluster.setDcs("oy"); manager.visitModified(new ClusterMetaComparator(cluster, newCluster)); Mockito.verify(instanceManager, never()).getOrCreate(any()); Mockito.verify(instanceManager, times(1)).remove(any()); Assert.assertEquals(Sets.newHashSet(new HostPort("10.0.0.2", 6379)), deletedRedised); }