Search in sources :

Example 86 with URL

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());
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) Field(java.lang.reflect.Field) Map(java.util.Map) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 87 with URL

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());
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invoker(com.alibaba.dubbo.rpc.Invoker) ArrayList(java.util.ArrayList) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 88 with URL

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();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpHandler(com.alibaba.dubbo.remoting.http.HttpHandler) HttpServer(com.alibaba.dubbo.remoting.http.HttpServer) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 89 with URL

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();
    }
}
Also used : DemoService(com.alibaba.dubbo.config.spring.api.DemoService) URL(com.alibaba.dubbo.common.URL) DemoServiceImpl(com.alibaba.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.Test)

Example 90 with URL

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();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RegistryService(com.alibaba.dubbo.registry.RegistryService) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Aggregations

URL (com.alibaba.dubbo.common.URL)297 Test (org.junit.Test)169 ArrayList (java.util.ArrayList)73 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)64 HashMap (java.util.HashMap)45 Result (com.alibaba.dubbo.rpc.Result)37 Invoker (com.alibaba.dubbo.rpc.Invoker)36 Map (java.util.Map)36 List (java.util.List)30 Invocation (com.alibaba.dubbo.rpc.Invocation)29 ConcurrentMap (java.util.concurrent.ConcurrentMap)29 RegistryDirectory (com.alibaba.dubbo.registry.integration.RegistryDirectory)28 RpcException (com.alibaba.dubbo.rpc.RpcException)22 NotifyListener (com.alibaba.dubbo.registry.NotifyListener)20 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)18 RpcResult (com.alibaba.dubbo.rpc.RpcResult)17 DemoService (com.alibaba.dubbo.rpc.support.DemoService)12 Set (java.util.Set)12 ConcurrentHashSet (com.alibaba.dubbo.common.utils.ConcurrentHashSet)11 Protocol (com.alibaba.dubbo.rpc.Protocol)11