@Test public void testConsulDeleteSyncToNacos() throws Exception { TaskDO taskDO = mock(TaskDO.class); mockDelete(taskDO); Assert.assertTrue(consulSyncToNacosService.delete(taskDO)); }
@Override public boolean delete(TaskDO taskDO) { try { specialSyncEventBus.unsubscribe(taskDO); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), null); List<Instance> allInstances = destNamingService.getAllInstances(taskDO.getServiceName()); for (Instance instance : allInstances) { if (needDelete(instance.getMetadata(), taskDO)) { destNamingService.deregisterInstance(taskDO.getServiceName(), instance.getIp(), instance.getPort()); } } } catch (Exception e) { log.error("delete task from consul to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.DELETE_ERROR); return false; } return true; }
ConsulSyncToNacosServiceImpl implements SyncService { @Override public boolean delete(TaskDO taskDO) { try { specialSyncEventBus.unsubscribe(taskDO); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), null); List<Instance> allInstances = destNamingService.getAllInstances(taskDO.getServiceName()); for (Instance instance : allInstances) { if (needDelete(instance.getMetadata(), taskDO)) { destNamingService.deregisterInstance(taskDO.getServiceName(), instance.getIp(), instance.getPort()); } } } catch (Exception e) { log.error("delete task from consul to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.DELETE_ERROR); return false; } return true; } }
ConsulSyncToNacosServiceImpl implements SyncService { @Override public boolean delete(TaskDO taskDO) { try { specialSyncEventBus.unsubscribe(taskDO); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), null); List<Instance> allInstances = destNamingService.getAllInstances(taskDO.getServiceName()); for (Instance instance : allInstances) { if (needDelete(instance.getMetadata(), taskDO)) { destNamingService.deregisterInstance(taskDO.getServiceName(), instance.getIp(), instance.getPort()); } } } catch (Exception e) { log.error("delete task from consul to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.DELETE_ERROR); return false; } return true; } @Autowired  ConsulSyncToNacosServiceImpl(ConsulServerHolder consulServerHolder,
        SkyWalkerCacheServices skyWalkerCacheServices, NacosServerHolder nacosServerHolder,
        SpecialSyncEventBus specialSyncEventBus); }
ConsulSyncToNacosServiceImpl implements SyncService { @Override public boolean delete(TaskDO taskDO) { try { specialSyncEventBus.unsubscribe(taskDO); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), null); List<Instance> allInstances = destNamingService.getAllInstances(taskDO.getServiceName()); for (Instance instance : allInstances) { if (needDelete(instance.getMetadata(), taskDO)) { destNamingService.deregisterInstance(taskDO.getServiceName(), instance.getIp(), instance.getPort()); } } } catch (Exception e) { log.error("delete task from consul to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.DELETE_ERROR); return false; } return true; } @Autowired  ConsulSyncToNacosServiceImpl(ConsulServerHolder consulServerHolder,
        SkyWalkerCacheServices skyWalkerCacheServices, NacosServerHolder nacosServerHolder,
        SpecialSyncEventBus specialSyncEventBus); @Override boolean delete(TaskDO taskDO); @Override boolean sync(TaskDO taskDO); }
ConsulSyncToNacosServiceImpl implements SyncService { @Override public boolean delete(TaskDO taskDO) { try { specialSyncEventBus.unsubscribe(taskDO); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), null); List<Instance> allInstances = destNamingService.getAllInstances(taskDO.getServiceName()); for (Instance instance : allInstances) { if (needDelete(instance.getMetadata(), taskDO)) { destNamingService.deregisterInstance(taskDO.getServiceName(), instance.getIp(), instance.getPort()); } } } catch (Exception e) { log.error("delete task from consul to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.DELETE_ERROR); return false; } return true; } @Autowired  ConsulSyncToNacosServiceImpl(ConsulServerHolder consulServerHolder,
        SkyWalkerCacheServices skyWalkerCacheServices, NacosServerHolder nacosServerHolder,
        SpecialSyncEventBus specialSyncEventBus); @Override boolean delete(TaskDO taskDO); @Override boolean sync(TaskDO taskDO);  }