use of org.apache.dubbo.registry.NotifyListener in project dubbo by alibaba.
the class AbstractRegistryTest method testNotifyIfURLNull.
@Test
public void testNotifyIfURLNull() throws Exception {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false);
NotifyListener listener1 = urls -> notified.set(Boolean.TRUE);
URL url1 = new URL("dubbo", "192.168.0.1", 2200, parametersConsumer);
abstractRegistry.subscribe(url1, listener1);
NotifyListener listener2 = urls -> notified.set(Boolean.TRUE);
URL url2 = new URL("dubbo", "192.168.0.2", 2201, parametersConsumer);
abstractRegistry.subscribe(url2, listener2);
NotifyListener listener3 = urls -> notified.set(Boolean.TRUE);
URL url3 = new URL("dubbo", "192.168.0.3", 2202, parametersConsumer);
abstractRegistry.subscribe(url3, listener3);
List<URL> urls = new ArrayList<>();
urls.add(url1);
urls.add(url2);
urls.add(url3);
abstractRegistry.notify(null, listener1, urls);
Assertions.fail("notify url == null");
});
}
use of org.apache.dubbo.registry.NotifyListener in project dubbo by alibaba.
the class AbstractRegistryTest method testSubscribeIfUrlNull.
@Test
public void testSubscribeIfUrlNull() throws Exception {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false);
NotifyListener listener = urls -> notified.set(Boolean.TRUE);
URL url = new URL("dubbo", "192.168.0.1", 2200);
abstractRegistry.subscribe(null, listener);
Assertions.fail("subscribe url == null");
});
}
use of org.apache.dubbo.registry.NotifyListener in project dubbo by alibaba.
the class FailbackRegistry method recover.
@Override
protected void recover() throws Exception {
// register
Set<URL> recoverRegistered = new HashSet<URL>(getRegistered());
if (!recoverRegistered.isEmpty()) {
if (logger.isInfoEnabled()) {
logger.info("Recover register url " + recoverRegistered);
}
for (URL url : recoverRegistered) {
// remove fail registry or unRegistry task first.
removeFailedRegistered(url);
removeFailedUnregistered(url);
addFailedRegistered(url);
}
}
// subscribe
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()) {
// First remove other tasks to ensure that addFailedSubscribed can succeed.
removeFailedSubscribed(url, listener);
addFailedSubscribed(url, listener);
}
}
}
}
use of org.apache.dubbo.registry.NotifyListener in project dubbo by alibaba.
the class DubboRegistryTest method setUp.
@BeforeEach
public void setUp() {
registryURL = new URL(REGISTRY_PROTOCOL, NetUtils.getLocalHost(), NetUtils.getAvailablePort()).addParameter(Constants.CHECK_KEY, false).setServiceInterface(RegistryService.class.getName());
serviceURL = new URL(DubboProtocol.NAME, NetUtils.getLocalHost(), NetUtils.getAvailablePort()).addParameter(Constants.CHECK_KEY, false).setServiceInterface(RegistryService.class.getName());
registryService = new MockDubboRegistry(registryURL);
invoker = mock(Invoker.class);
given(invoker.getUrl()).willReturn(serviceURL);
given(invoker.getInterface()).willReturn(RegistryService.class);
given(invoker.invoke(new RpcInvocation())).willReturn(null);
dubboRegistry = new DubboRegistry(invoker, registryService);
notifyListener = mock(NotifyListener.class);
}
use of org.apache.dubbo.registry.NotifyListener in project dubbo by alibaba.
the class MulticastRegistryTest method testUnsubscribe.
/**
* Test method for {@link org.apache.dubbo.registry.multicast.MulticastRegistry#unsubscribe(URL, NotifyListener)}
*/
@Test
public void testUnsubscribe() {
// subscribe first
registry.subscribe(consumerUrl, new NotifyListener() {
@Override
public void notify(List<URL> urls) {
// do nothing
}
});
// then unsubscribe
registry.unsubscribe(consumerUrl, new NotifyListener() {
@Override
public void notify(List<URL> urls) {
Map<URL, Set<NotifyListener>> subscribed = registry.getSubscribed();
Set<NotifyListener> listeners = subscribed.get(consumerUrl);
assertTrue(listeners.isEmpty());
Map<URL, Set<URL>> received = registry.getReceived();
assertTrue(received.get(consumerUrl).isEmpty());
}
});
}
Aggregations