Search in sources :

Example 1 with RegistryService

use of org.apache.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(org.apache.dubbo.config.spring.annotation.consumer.AnnotationAction) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Matchers.containsString(org.hamcrest.Matchers.containsString) RegistryService(org.apache.dubbo.registry.RegistryService) Test(org.junit.jupiter.api.Test)

Example 2 with RegistryService

use of org.apache.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("org.apache.dubbo.config.spring.api.DemoService");
        assertNotNull(urls);
        assertEquals(1, urls.size());
        assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20888/org.apache.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(org.apache.dubbo.registry.RegistryService) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 3 with RegistryService

use of org.apache.dubbo.registry.RegistryService in project dubbo by alibaba.

the class DubboRegistryFactory method createRegistry.

@Override
public Registry createRegistry(URL url) {
    url = getRegistryURL(url);
    List<URL> urls = new ArrayList<>();
    urls.add(url.removeParameter(BACKUP_KEY));
    String backup = url.getParameter(BACKUP_KEY);
    if (backup != null && backup.length() > 0) {
        String[] addresses = COMMA_SPLIT_PATTERN.split(backup);
        for (String address : addresses) {
            urls.add(url.setAddress(address));
        }
    }
    RegistryDirectory<RegistryService> directory = new RegistryDirectory<>(RegistryService.class, url.addParameter(INTERFACE_KEY, RegistryService.class.getName()).addParameterAndEncoded(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.setRouterChain(RouterChain.buildChain(url));
    directory.notify(urls);
    directory.subscribe(new URL(CONSUMER_PROTOCOL, NetUtils.getLocalHost(), 0, RegistryService.class.getName(), url.getParameters()));
    return registry;
}
Also used : RegistryDirectory(org.apache.dubbo.registry.integration.RegistryDirectory) ArrayList(java.util.ArrayList) RegistryService(org.apache.dubbo.registry.RegistryService) URL(org.apache.dubbo.common.URL)

Example 4 with RegistryService

use of org.apache.dubbo.registry.RegistryService in project dubbo by alibaba.

the class ConfigTest method testDelayFixedTime.

@Test
public void testDelayFixedTime() throws Exception {
    SimpleRegistryService registryService = new SimpleRegistryService();
    Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4548, registryService);
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/delay-fixed-time.xml");
    ctx.start();
    try {
        List<URL> urls = registryService.getRegistered().get("org.apache.dubbo.config.spring.api.DemoService");
        assertNull(urls);
        int i = 0;
        while ((i++) < 60 && urls == null) {
            urls = registryService.getRegistered().get("org.apache.dubbo.config.spring.api.DemoService");
            Thread.sleep(10);
        }
        assertNotNull(urls);
        assertEquals(1, urls.size());
        assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20888/org.apache.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(org.apache.dubbo.registry.RegistryService) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 5 with RegistryService

use of org.apache.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("org.apache.dubbo.config.spring.api.DemoService");
        assertNotNull(urls);
        assertEquals(1, urls.size());
        assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20824/org.apache.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(org.apache.dubbo.registry.RegistryService) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Aggregations

RegistryService (org.apache.dubbo.registry.RegistryService)6 URL (org.apache.dubbo.common.URL)5 Test (org.junit.jupiter.api.Test)5 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)5 ArrayList (java.util.ArrayList)1 AnnotationAction (org.apache.dubbo.config.spring.annotation.consumer.AnnotationAction)1 RegistryDirectory (org.apache.dubbo.registry.integration.RegistryDirectory)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1