Search in sources :

Example 6 with RegistryService

use of org.apache.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("org.apache.dubbo.config.spring.api.DemoService");
        assertNull(urls1);
        List<URL> urls2 = registryService2.getRegistered().get("org.apache.dubbo.config.spring.api.DemoService");
        assertNotNull(urls2);
        assertEquals(1, urls2.size());
        assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20880/org.apache.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(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