ZookeeperSyncToNacosServiceImpl implements SyncService { @Override public boolean delete(TaskDO taskDO) { if (taskDO.getServiceName() == null) { return true; } try { CloseableUtils.closeQuietly(treeCacheMap.get(taskDO.getTaskId())); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), null); if(!ALL_SERVICE_NAME_PATTERN.equals(taskDO.getServiceName())) { if (nacosServiceNameMap.containsKey(taskDO.getServiceName())) { List<Instance> allInstances = destNamingService.getAllInstances(nacosServiceNameMap.get(taskDO.getServiceName())); for (Instance instance : allInstances) { if (needDelete(instance.getMetadata(), taskDO)) { destNamingService.deregisterInstance(instance.getServiceName(), instance.getIp(), instance.getPort()); } nacosServiceNameMap.remove(taskDO.getServiceName()); } } } else { Set<String> serviceNames = nacosServiceNameMap.keySet(); for(String serviceName : serviceNames) { if (nacosServiceNameMap.containsKey(serviceName)) { List<Instance> allInstances = destNamingService.getAllInstances(serviceName); for (Instance instance : allInstances) { if (needDelete(instance.getMetadata(), taskDO)) { destNamingService.deregisterInstance(instance.getServiceName(), instance.getIp(), instance.getPort()); } nacosServiceNameMap.remove(serviceName); } } } } } catch (Exception e) { log.error("delete task from zookeeper to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.DELETE_ERROR); return false; } return true; } @Autowired  ZookeeperSyncToNacosServiceImpl(ZookeeperServerHolder zookeeperServerHolder,
                                           NacosServerHolder nacosServerHolder, SkyWalkerCacheServices skyWalkerCacheServices); @Override boolean sync(TaskDO taskDO); @Override boolean delete(TaskDO taskDO);  }
@Test(expected = Exception.class) public void testZookeeperDeleteToNacosWithException() throws Exception { Assert.assertFalse(zookeeperSyncToNacosService.delete(null)); }