use of org.apache.dubbo.registry.NotifyListener in project dubbo by alibaba.
the class AbstractRegistryService method doNotify.
private void doNotify(String service, List<URL> urls) {
notified.put(service, urls);
List<NotifyListener> listeners = notifyListeners.get(service);
if (listeners != null) {
for (NotifyListener listener : listeners) {
try {
notify(service, urls, listener);
} catch (Throwable t) {
logger.error("Failed to notify registry event, service: " + service + ", urls: " + urls + ", cause: " + t.getMessage(), t);
}
}
}
}
use of org.apache.dubbo.registry.NotifyListener in project dubbo by alibaba.
the class RegistryProtocolTest method testNotifyOverride_notmatch.
// @Test
// public void testNotifyOverride() throws Exception {
// URL newRegistryUrl = registryUrl.addParameter(EXPORT_KEY, serviceUrl);
// Invoker<RegistryProtocolTest> invoker = new MockInvoker<RegistryProtocolTest>(RegistryProtocolTest.class, newRegistryUrl);
//
// ServiceDescriptor descriptor = ApplicationModel.getServiceRepository().registerService(DemoService.class);
// ApplicationModel.getServiceRepository().registerProvider(service, new DemoServiceImpl(), descriptor, null, null);
//
// Exporter<?> exporter = protocol.export(invoker);
// RegistryProtocol rprotocol = getRegistryProtocol();
// NotifyListener listener = getListener(rprotocol);
// List<URL> urls = new ArrayList<URL>();
// urls.add(URL.valueOf("override://0.0.0.0/?timeout=1000"));
// urls.add(URL.valueOf("override://0.0.0.0/" + service + "?timeout=100"));
// urls.add(URL.valueOf("override://0.0.0.0/" + service + "?x=y"));
// listener.notify(urls);
//
// assertTrue(exporter.getInvoker().isAvailable());
// assertEquals("100", exporter.getInvoker().getUrl().getParameter("timeout"));
// assertEquals("y", exporter.getInvoker().getUrl().getParameter("x"));
//
// exporter.unexport();
// // int timeout = ConfigUtils.getServerShutdownTimeout();
// // Thread.sleep(timeout + 1000);
// // assertEquals(false, exporter.getInvoker().isAvailable());
// destroyRegistryProtocol();
//
// }
/**
* The name of the service does not match and can't override invoker
* Service name matching, service version number mismatch
*/
@Test
public void testNotifyOverride_notmatch() throws Exception {
URL newRegistryUrl = registryUrl.addParameter(EXPORT_KEY, serviceUrl);
Invoker<RegistryProtocolTest> invoker = new MockInvoker<RegistryProtocolTest>(RegistryProtocolTest.class, newRegistryUrl);
ServiceDescriptor descriptor = ApplicationModel.getServiceRepository().registerService(DemoService.class);
ApplicationModel.getServiceRepository().registerProvider(service, new DemoServiceImpl(), descriptor, null, null);
Exporter<?> exporter = protocol.export(invoker);
RegistryProtocol rprotocol = getRegistryProtocol();
NotifyListener listener = getListener(rprotocol);
List<URL> urls = new ArrayList<URL>();
urls.add(URL.valueOf("override://0.0.0.0/org.apache.dubbo.registry.protocol.HackService?timeout=100"));
listener.notify(urls);
assertTrue(exporter.getInvoker().isAvailable());
assertNull(exporter.getInvoker().getUrl().getParameter("timeout"));
exporter.unexport();
destroyRegistryProtocol();
}
use of org.apache.dubbo.registry.NotifyListener in project dubbo by alibaba.
the class EtcdRegistryTest method test_subscribe_when_register0.
@Test
public void test_subscribe_when_register0() throws InterruptedException {
Assertions.assertEquals(0, registry.getRegistered().size());
Assertions.assertEquals(0, registry.getSubscribed().size());
CountDownLatch notNotified = new CountDownLatch(3);
ConcurrentHashMap<URL, Boolean> notifiedUrls = new ConcurrentHashMap<>();
registry.subscribe(consumerUrl, new NotifyListener() {
public void notify(List<URL> urls) {
if (urls != null && urls.size() > 0) {
if (!urls.get(0).getProtocol().equals("empty")) {
for (Iterator<URL> iterator = urls.iterator(); iterator.hasNext(); ) {
notifiedUrls.put(iterator.next(), true);
}
}
}
notNotified.countDown();
}
});
registry.register(serviceUrl);
registry.register(serviceUrl2);
Assertions.assertTrue(notNotified.await(15, TimeUnit.SECONDS));
Assertions.assertTrue(notifiedUrls.containsKey(serviceUrl));
Assertions.assertTrue(notifiedUrls.containsKey(serviceUrl2));
Map<URL, Set<NotifyListener>> subscribed = registry.getSubscribed();
Assertions.assertEquals(consumerUrl, subscribed.keySet().iterator().next());
}
use of org.apache.dubbo.registry.NotifyListener in project dubbo by alibaba.
the class EtcdRegistryTest method test_subscribe_when_register1.
@Test
public void test_subscribe_when_register1() throws InterruptedException {
Assertions.assertEquals(0, registry.getRegistered().size());
Assertions.assertEquals(0, registry.getSubscribed().size());
CountDownLatch notNotified = new CountDownLatch(2);
final AtomicReference<URL> notifiedUrls = new AtomicReference<URL>();
registry.subscribe(consumerUrl, new NotifyListener() {
public void notify(List<URL> urls) {
notifiedUrls.set(urls.get(0));
notNotified.countDown();
}
});
registry.register(serviceUrl);
// register service3 should not trigger notify
registry.register(serviceUrl3);
Assertions.assertTrue(notNotified.await(15, TimeUnit.SECONDS));
Assertions.assertEquals(serviceUrl, notifiedUrls.get());
Map<URL, Set<NotifyListener>> subscribed = registry.getSubscribed();
Assertions.assertEquals(consumerUrl, subscribed.keySet().iterator().next());
}
use of org.apache.dubbo.registry.NotifyListener in project dubbo by alibaba.
the class EtcdRegistryTest method test_subscribe_when_register2.
@Test
public void test_subscribe_when_register2() throws InterruptedException {
Assertions.assertEquals(0, registry.getRegistered().size());
Assertions.assertEquals(0, registry.getSubscribed().size());
CountDownLatch notNotified = new CountDownLatch(3);
ConcurrentHashMap<URL, Boolean> notifiedUrls = new ConcurrentHashMap<>();
registry.subscribe(subscribe, new NotifyListener() {
public void notify(List<URL> urls) {
if (urls != null && urls.size() > 0) {
if (!urls.get(0).getProtocol().equals("empty")) {
for (Iterator<URL> iterator = urls.iterator(); iterator.hasNext(); ) {
notifiedUrls.put(iterator.next(), true);
}
notNotified.countDown();
}
}
}
});
registry.register(serviceUrl);
registry.register(serviceUrl2);
// service3 interface is not equals server2
registry.register(serviceUrl3);
Assertions.assertTrue(notNotified.await(15, TimeUnit.SECONDS));
Assertions.assertEquals(3, notifiedUrls.size());
Assertions.assertTrue(notifiedUrls.containsKey(serviceUrl));
Assertions.assertTrue(notifiedUrls.containsKey(serviceUrl2));
Assertions.assertTrue(notifiedUrls.containsKey(serviceUrl3));
}
Aggregations