FailbackRegistry extends AbstractRegistry { @Override protected void recover() throws Exception { Set<URL> recoverRegistered = new HashSet<URL>(getRegistered()); if (!recoverRegistered.isEmpty()) { if (logger.isInfoEnabled()) { logger.info("Recover register url " + recoverRegistered); } for (URL url : recoverRegistered) { addFailedRegistered(url); } } Map<URL, Set<NotifyListener>> recoverSubscribed = new HashMap<URL, Set<NotifyListener>>(getSubscribed()); if (!recoverSubscribed.isEmpty()) { if (logger.isInfoEnabled()) { logger.info("Recover subscribe url " + recoverSubscribed.keySet()); } for (Map.Entry<URL, Set<NotifyListener>> entry : recoverSubscribed.entrySet()) { URL url = entry.getKey(); for (NotifyListener listener : entry.getValue()) { addFailedSubscribed(url, listener); } } } } FailbackRegistry(URL url); void removeFailedRegisteredTask(URL url); void removeFailedUnregisteredTask(URL url); void removeFailedSubscribedTask(URL url, NotifyListener listener); void removeFailedUnsubscribedTask(URL url, NotifyListener listener); @Override void register(URL url); @Override void reExportRegister(URL url); @Override void unregister(URL url); @Override void reExportUnregister(URL url); @Override void subscribe(URL url, NotifyListener listener); @Override void unsubscribe(URL url, NotifyListener listener); @Override void destroy(); abstract void doRegister(URL url); abstract void doUnregister(URL url); abstract void doSubscribe(URL url, NotifyListener listener); abstract void doUnsubscribe(URL url, NotifyListener listener);  }
@Test public void testRecover() throws Exception { CountDownLatch countDownLatch = new CountDownLatch(4); final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false); NotifyListener listener = new NotifyListener() { @Override public void notify(List<URL> urls) { notified.set(Boolean.TRUE); } }; MockRegistry mockRegistry = new MockRegistry(registryUrl, countDownLatch); mockRegistry.register(serviceUrl); mockRegistry.subscribe(serviceUrl, listener); Assertions.assertEquals(1, mockRegistry.getRegistered().size()); Assertions.assertEquals(1, mockRegistry.getSubscribed().size()); mockRegistry.recover(); countDownLatch.await(); Assertions.assertEquals(0, mockRegistry.getFailedRegistered().size()); FailbackRegistry.Holder h = new FailbackRegistry.Holder(registryUrl, listener); Assertions.assertNull(mockRegistry.getFailedSubscribed().get(h)); Assertions.assertEquals(countDownLatch.getCount(), 0); }