Search in sources :

Example 1 with RegistryService

use of com.alibaba.dubbo.registry.RegistryService in project dubbo by alibaba.

the class ConfigTest method testAnnotation.

@Test
public void testAnnotation() {
    SimpleRegistryService registryService = new SimpleRegistryService();
    Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4548, registryService);
    try {
        ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/annotation-provider.xml");
        providerContext.start();
        try {
            ClassPathXmlApplicationContext consumerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/annotation-consumer.xml");
            consumerContext.start();
            try {
                AnnotationAction annotationAction = (AnnotationAction) consumerContext.getBean("annotationAction");
                String hello = annotationAction.doSayName("hello");
                assertEquals("annotation:hello", hello);
            } finally {
                consumerContext.stop();
                consumerContext.close();
            }
        } finally {
            providerContext.stop();
            providerContext.close();
        }
    } finally {
        exporter.unexport();
    }
}
Also used : AnnotationAction(com.alibaba.dubbo.config.spring.annotation.consumer.AnnotationAction) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) RegistryService(com.alibaba.dubbo.registry.RegistryService) Test(org.junit.Test)

Example 2 with RegistryService

use of com.alibaba.dubbo.registry.RegistryService 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)

Example 3 with RegistryService

use of com.alibaba.dubbo.registry.RegistryService in project dubbo by alibaba.

the class ConfigTest method testDelayOnInitialized.

@Test
public void testDelayOnInitialized() throws Exception {
    SimpleRegistryService registryService = new SimpleRegistryService();
    Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4548, registryService);
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/delay-on-initialized.xml");
    //ctx.start();
    try {
        List<URL> urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
        assertNotNull(urls);
        assertEquals(1, urls.size());
        assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20883/com.alibaba.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString());
    } finally {
        ctx.stop();
        ctx.close();
        exporter.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)

Example 4 with RegistryService

use of com.alibaba.dubbo.registry.RegistryService in project dubbo by alibaba.

the class DubboRegistryFactory method createRegistry.

public Registry createRegistry(URL url) {
    url = getRegistryURL(url);
    List<URL> urls = new ArrayList<URL>();
    urls.add(url.removeParameter(Constants.BACKUP_KEY));
    String backup = url.getParameter(Constants.BACKUP_KEY);
    if (backup != null && backup.length() > 0) {
        String[] addresses = Constants.COMMA_SPLIT_PATTERN.split(backup);
        for (String address : addresses) {
            urls.add(url.setAddress(address));
        }
    }
    RegistryDirectory<RegistryService> directory = new RegistryDirectory<RegistryService>(RegistryService.class, url.addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName()).addParameterAndEncoded(Constants.REFER_KEY, url.toParameterString()));
    Invoker<RegistryService> registryInvoker = cluster.join(directory);
    RegistryService registryService = proxyFactory.getProxy(registryInvoker);
    DubboRegistry registry = new DubboRegistry(registryInvoker, registryService);
    directory.setRegistry(registry);
    directory.setProtocol(protocol);
    directory.notify(urls);
    directory.subscribe(new URL(Constants.CONSUMER_PROTOCOL, NetUtils.getLocalHost(), 0, RegistryService.class.getName(), url.getParameters()));
    return registry;
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) ArrayList(java.util.ArrayList) RegistryService(com.alibaba.dubbo.registry.RegistryService) URL(com.alibaba.dubbo.common.URL)

Example 5 with RegistryService

use of com.alibaba.dubbo.registry.RegistryService in project dubbo by alibaba.

the class ConfigTest method testMultiProtocolRegister.

@Test
public void testMultiProtocolRegister() {
    SimpleRegistryService registryService = new SimpleRegistryService();
    Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4547, registryService);
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol-register.xml");
    ctx.start();
    try {
        List<URL> urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
        assertNotNull(urls);
        assertEquals(1, urls.size());
        assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20824/com.alibaba.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString());
    } finally {
        ctx.stop();
        ctx.close();
        exporter.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

RegistryService (com.alibaba.dubbo.registry.RegistryService)6 URL (com.alibaba.dubbo.common.URL)5 Test (org.junit.Test)5 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)5 AnnotationAction (com.alibaba.dubbo.config.spring.annotation.consumer.AnnotationAction)1 RegistryDirectory (com.alibaba.dubbo.registry.integration.RegistryDirectory)1 ArrayList (java.util.ArrayList)1 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)1