use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.
the class RegistryDirectoryTest method test_Constructor_CheckStatus.
@Test
public void test_Constructor_CheckStatus() throws Exception {
URL url = URL.valueOf("notsupported://10.20.30.40/" + service + "?a=b").addParameterAndEncoded(Constants.REFER_KEY, "foo=bar");
RegistryDirectory reg = getRegistryDirectory(url);
Field field = reg.getClass().getDeclaredField("queryMap");
field.setAccessible(true);
Map<String, String> queryMap = (Map<String, String>) field.get(reg);
Assert.assertEquals("bar", queryMap.get("foo"));
Assert.assertEquals(url.clearParameters().addParameter("foo", "bar"), reg.getUrl());
}
use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.
the class RegistryDirectoryTest method test_NotifiedDubbo1.
// The test call is independent of the path of the registry url
@Test
public void test_NotifiedDubbo1() {
URL errorPathUrl = URL.valueOf("notsupport:/" + "xxx" + "?refer=" + URL.encode("interface=" + service));
RegistryDirectory registryDirectory = getRegistryDirectory(errorPathUrl);
List<URL> serviceUrls = new ArrayList<URL>();
URL Dubbo1URL = URL.valueOf("dubbo://127.0.0.1:9098?lazy=true");
serviceUrls.add(Dubbo1URL.addParameter("methods", "getXXX"));
registryDirectory.notify(serviceUrls);
Assert.assertEquals(true, registryDirectory.isAvailable());
invocation = new RpcInvocation();
List<Invoker<DemoService>> invokers = registryDirectory.list(invocation);
Assert.assertEquals(1, invokers.size());
invocation.setMethodName("getXXX");
invokers = registryDirectory.list(invocation);
Assert.assertEquals(1, invokers.size());
Assert.assertEquals(DemoService.class.getName(), invokers.get(0).getUrl().getPath());
}
use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.
the class JettyHttpBinderTest method shouldAbleHandleRequestForJettyBinder.
@Test
public void shouldAbleHandleRequestForJettyBinder() throws Exception {
int port = TestUtil.getFreePort();
URL url = new URL("http", "localhost", port, new String[] { Constants.BIND_PORT_KEY, String.valueOf(port) });
HttpServer httpServer = new JettyHttpServer(url, new HttpHandler() {
@Override
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.getWriter().write("Jetty");
}
});
String response = Request.Get(url.toJavaURL().toURI()).execute().returnContent().asString();
assertThat(response, is("Jetty"));
httpServer.close();
}
use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.
the class ConfigTest method testApiOverrideProperties.
@Test
public void testApiOverrideProperties() throws Exception {
ApplicationConfig application = new ApplicationConfig();
application.setName("api-override-properties");
RegistryConfig registry = new RegistryConfig();
registry.setAddress("N/A");
ProtocolConfig protocol = new ProtocolConfig();
protocol.setName("dubbo");
protocol.setPort(13123);
ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
service.setApplication(application);
service.setRegistry(registry);
service.setProtocol(protocol);
service.export();
try {
URL url = service.toUrls().get(0);
assertEquals("api-override-properties", url.getParameter("application"));
assertEquals("world", url.getParameter("owner"));
assertEquals(13123, url.getPort());
ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
reference.setApplication(new ApplicationConfig("consumer"));
reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
reference.setInterface(DemoService.class);
reference.setUrl("dubbo://127.0.0.1:13123");
reference.get();
try {
url = reference.toUrls().get(0);
assertEquals("2000", url.getParameter("timeout"));
} finally {
reference.destroy();
}
} finally {
service.unexport();
}
}
use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.
the class ConfigTest method testMultiRegistry.
@Test
public void testMultiRegistry() {
SimpleRegistryService registryService1 = new SimpleRegistryService();
Exporter<RegistryService> exporter1 = SimpleRegistryExporter.export(4545, registryService1);
SimpleRegistryService registryService2 = new SimpleRegistryService();
Exporter<RegistryService> exporter2 = SimpleRegistryExporter.export(4546, registryService2);
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-registry.xml");
ctx.start();
try {
List<URL> urls1 = registryService1.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
assertNull(urls1);
List<URL> urls2 = registryService2.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
assertNotNull(urls2);
assertEquals(1, urls2.size());
assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20880/com.alibaba.dubbo.config.spring.api.DemoService", urls2.get(0).toIdentityString());
} finally {
ctx.stop();
ctx.close();
exporter1.unexport();
exporter2.unexport();
}
}
Aggregations