use of org.apache.dubbo.registry.integration.RegistryProtocol in project dubbo by alibaba.
the class RegistryProtocolTest method testGetParamsToRegistry.
@Test
public void testGetParamsToRegistry() {
RegistryProtocol registryProtocol = getRegistryProtocol();
String[] additionalParams = new String[] { "key1", "key2" };
String[] registryParams = registryProtocol.getParamsToRegistry(DEFAULT_REGISTER_PROVIDER_KEYS, additionalParams);
String[] expectParams = ArrayUtils.addAll(DEFAULT_REGISTER_PROVIDER_KEYS, additionalParams);
Assertions.assertArrayEquals(expectParams, registryParams);
}
use of org.apache.dubbo.registry.integration.RegistryProtocol in project dubbo by alibaba.
the class RegistryProtocolTest method testExportUrlNull.
@Test
public void testExportUrlNull() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
RegistryProtocol registryProtocol = getRegistryProtocol();
// registryProtocol.setCluster(new FailfastCluster());
Protocol dubboProtocol = DubboProtocol.getDubboProtocol();
registryProtocol.setProtocol(dubboProtocol);
Invoker<DemoService> invoker = new DubboInvoker<DemoService>(DemoService.class, registryUrl, new ExchangeClient[] { new MockedClient("10.20.20.20", 2222, true) });
registryProtocol.export(invoker);
});
}
use of org.apache.dubbo.registry.integration.RegistryProtocol in project dubbo by alibaba.
the class RegistryProtocolTest method testDefaultPort.
@Test
public void testDefaultPort() {
RegistryProtocol registryProtocol = getRegistryProtocol();
assertEquals(9090, registryProtocol.getDefaultPort());
}
use of org.apache.dubbo.registry.integration.RegistryProtocol in project dubbo by alibaba.
the class RegistryProtocolTest method testExport.
@Test
public void testExport() {
RegistryProtocol registryProtocol = getRegistryProtocol();
// registryProtocol.setCluster(new FailfastCluster());
registryProtocol.setRegistryFactory(ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension());
ServiceDescriptor descriptor = ApplicationModel.getServiceRepository().registerService(DemoService.class);
ApplicationModel.getServiceRepository().registerProvider(service, new DemoServiceImpl(), descriptor, null, null);
Protocol dubboProtocol = DubboProtocol.getDubboProtocol();
registryProtocol.setProtocol(dubboProtocol);
URL newRegistryUrl = registryUrl.addParameter(EXPORT_KEY, serviceUrl);
DubboInvoker<DemoService> invoker = new DubboInvoker<DemoService>(DemoService.class, newRegistryUrl, new ExchangeClient[] { new MockedClient("10.20.20.20", 2222, true) });
Exporter<DemoService> exporter = registryProtocol.export(invoker);
Exporter<DemoService> exporter2 = registryProtocol.export(invoker);
// The same invoker, exporter that multiple exported are different
Assertions.assertNotSame(exporter, exporter2);
exporter.unexport();
exporter2.unexport();
}
use of org.apache.dubbo.registry.integration.RegistryProtocol 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();
}
Aggregations