EurekaSyncToNacosServiceImpl implements SyncService { @Override public boolean sync(TaskDO taskDO) { try { EurekaNamingService eurekaNamingService = eurekaServerHolder.get(taskDO.getSourceClusterId(), null); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), null); List<InstanceInfo> eurekaInstances = eurekaNamingService.getApplications(taskDO.getServiceName()); List<Instance> nacosInstances = destNamingService.getAllInstances(taskDO.getServiceName()); if (CollectionUtils.isEmpty(eurekaInstances)) { deleteAllInstance(taskDO, destNamingService, nacosInstances); } else { if (!CollectionUtils.isEmpty(nacosInstances)) { removeInvalidInstance(taskDO, destNamingService, eurekaInstances, nacosInstances); } addValidInstance(taskDO, destNamingService, eurekaInstances); } specialSyncEventBus.subscribe(taskDO, this::sync); } catch (Exception e) { log.error("sync task from eureka to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.SYNC_ERROR); return false; } return true; } @Autowired  EurekaSyncToNacosServiceImpl(EurekaServerHolder eurekaServerHolder,
        SkyWalkerCacheServices skyWalkerCacheServices, NacosServerHolder nacosServerHolder,
        SpecialSyncEventBus specialSyncEventBus, MetricsManager metricsManager); @Override boolean delete(TaskDO taskDO); @Override boolean sync(TaskDO taskDO);  }
@Test(expected = Exception.class) public void testEurekaSyncToNacosWithException() throws Exception { Assert.assertFalse(eurekaSyncToNacosService.sync(null)); }
@Test public void testEurekaSyncToNacos() throws Exception { TaskDO taskDO = mock(TaskDO.class); mockSync(taskDO); Assert.assertTrue(eurekaSyncToNacosService.sync(taskDO)); }