ConsulSyncToNacosServiceImpl implements SyncService { @Override public boolean sync(TaskDO taskDO) { try { ConsulClient consulClient = consulServerHolder.get(taskDO.getSourceClusterId(), null); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), null); Response<List<HealthService>> response = consulClient.getHealthServices(taskDO.getServiceName(), true, QueryParams.DEFAULT); List<HealthService> healthServiceList = response.getValue(); Set<String> instanceKeys = new HashSet<>(); overrideAllInstance(taskDO, destNamingService, healthServiceList, instanceKeys); cleanAllOldInstance(taskDO, destNamingService, instanceKeys); specialSyncEventBus.subscribe(taskDO, this::sync); } catch (Exception e) { log.error("Sync task from consul to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.SYNC_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);  }
@Test public void testConsulSyncToNacos() throws Exception { TaskDO taskDO = mock(TaskDO.class); mockSync(taskDO); Assert.assertTrue(consulSyncToNacosService.sync(taskDO)); }
@Test(expected = Exception.class) public void testConsulSyncToNacosWithException() throws Exception { Assert.assertFalse(consulSyncToNacosService.sync(null)); }