ClusterDeleteEventFactory extends AbstractClusterEventFactory { @Override public ClusterEvent createClusterEvent(String clusterName, ClusterTbl clusterTbl) { ClusterDeleteEvent clusterDeleteEvent = new ClusterDeleteEvent(clusterName, executors); ClusterType clusterType = ClusterType.lookup(clusterTbl.getClusterType()); if (clusterType.supportMultiActiveDC()) return null; List<ShardTbl> shardTbls = shardService.findAllByClusterName(clusterName); long activeDcId = clusterService.find(clusterName).getActivedcId(); String activeDcName = dcService.getDcName(activeDcId); if(shardTbls != null) { for(ShardTbl shardTbl : shardTbls) { logger.info("[createClusterEvent] Create Shard Delete Event: {}", shardTbl); Map<Long, SetinelTbl> sentinelMap = sentinelService.findByShard(shardTbl.getId()); ShardDeleteEvent shardEvent = new ShardDeleteEvent(clusterName, shardTbl.getShardName(), executors); shardEvent.setClusterType(clusterType); try { shardEvent.setShardMonitorName(metaCache.getSentinelMonitorName(clusterName, shardTbl.getShardName())); } catch (Exception e) { logger.warn("[createClusterEvent]", e); shardEvent.setShardMonitorName(SentinelUtil.getSentinelMonitorName(clusterName, shardTbl.getSetinelMonitorName(), activeDcName)); } shardEvent.setShardSentinels(getShardSentinelAddress(sentinelMap)); shardDeleteEventListeners .forEach(shardDeleteEventListener -> shardEvent.addObserver(shardDeleteEventListener)); clusterDeleteEvent.addShardEvent(shardEvent); } } clusterEventListeners .forEach(clusterDeleteEventListener -> clusterDeleteEvent.addObserver(clusterDeleteEventListener)); return clusterDeleteEvent; }  @Override ClusterEvent createClusterEvent(String clusterName, ClusterTbl clusterTbl);  }
@Test public void createClusterEvent() throws Exception { List<ClusterTbl> clusters = clusterService.findAllClustersWithOrgInfo(); ClusterEvent clusterEvent = clusterDeleteEventFactory.createClusterEvent(clusters.get(0).getClusterName(), clusters.get(0)); Assert.assertTrue(clusterEvent instanceof ClusterDeleteEvent); for(ShardEvent shardEvent : clusterEvent.getShardEvents()) { Assert.assertTrue(shardEvent instanceof ShardDeleteEvent); Assert.assertEquals(clusterEvent.getClusterName(), shardEvent.getClusterName()); } }
@Test public void testCreateForCRDTCluster() { String clusterId = "test-cluster"; ClusterEvent clusterEvent = clusterDeleteEventFactory.createClusterEvent(clusterId, new ClusterTbl().setClusterName(clusterId).setClusterType(ClusterType.BI_DIRECTION.toString())); Assert.assertNull(clusterEvent); }