Search in sources :

Example 1 with DemoService

use of com.alibaba.dubbo.config.spring.api.DemoService in project dubbo by alibaba.

the class ConfigTest method refer.

private DemoService refer(String url) {
    ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
    reference.setApplication(new ApplicationConfig("consumer"));
    reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
    reference.setInterface(DemoService.class);
    reference.setUrl(url);
    return reference.get();
}
Also used : RegistryConfig(com.alibaba.dubbo.config.RegistryConfig) ApplicationConfig(com.alibaba.dubbo.config.ApplicationConfig) ReferenceConfig(com.alibaba.dubbo.config.ReferenceConfig) DemoService(com.alibaba.dubbo.config.spring.api.DemoService)

Example 2 with DemoService

use of com.alibaba.dubbo.config.spring.api.DemoService in project dubbo by alibaba.

the class ConfigTest method testSystemPropertyOverrideXmlDefault.

@SuppressWarnings("unchecked")
@Test
public void testSystemPropertyOverrideXmlDefault() throws Exception {
    System.setProperty("dubbo.application.name", "sysover");
    System.setProperty("dubbo.application.owner", "sysowner");
    System.setProperty("dubbo.registry.address", "N/A");
    System.setProperty("dubbo.protocol.name", "dubbo");
    System.setProperty("dubbo.protocol.port", "20819");
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/system-properties-override-default.xml");
    providerContext.start();
    try {
        ServiceConfig<DemoService> service = (ServiceConfig<DemoService>) providerContext.getBean("demoServiceConfig");
        assertEquals("sysover", service.getApplication().getName());
        assertEquals("sysowner", service.getApplication().getOwner());
        assertEquals("N/A", service.getRegistry().getAddress());
        assertEquals("dubbo", service.getProtocol().getName());
        assertEquals(20819, service.getProtocol().getPort().intValue());
    } finally {
        System.setProperty("dubbo.application.name", "");
        System.setProperty("dubbo.application.owner", "");
        System.setProperty("dubbo.registry.address", "");
        System.setProperty("dubbo.protocol.name", "");
        System.setProperty("dubbo.protocol.port", "");
        providerContext.stop();
        providerContext.close();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ServiceConfig(com.alibaba.dubbo.config.ServiceConfig) DemoService(com.alibaba.dubbo.config.spring.api.DemoService) Test(org.junit.Test)

Example 3 with DemoService

use of com.alibaba.dubbo.config.spring.api.DemoService in project dubbo by alibaba.

the class ConfigTest method testMultiProtocolDefault.

@Test
public void testMultiProtocolDefault() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol-default.xml");
    ctx.start();
    try {
        DemoService demoService = refer("rmi://127.0.0.1:10991");
        String hello = demoService.sayName("hello");
        assertEquals("say:hello", hello);
    } finally {
        ctx.stop();
        ctx.close();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DemoService(com.alibaba.dubbo.config.spring.api.DemoService) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) Test(org.junit.Test)

Example 4 with DemoService

use of com.alibaba.dubbo.config.spring.api.DemoService 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 : RegistryConfig(com.alibaba.dubbo.config.RegistryConfig) ApplicationConfig(com.alibaba.dubbo.config.ApplicationConfig) ServiceConfig(com.alibaba.dubbo.config.ServiceConfig) ReferenceConfig(com.alibaba.dubbo.config.ReferenceConfig) DemoService(com.alibaba.dubbo.config.spring.api.DemoService) ProtocolConfig(com.alibaba.dubbo.config.ProtocolConfig) URL(com.alibaba.dubbo.common.URL) DemoServiceImpl(com.alibaba.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.Test)

Example 5 with DemoService

use of com.alibaba.dubbo.config.spring.api.DemoService in project dubbo by alibaba.

the class ConfigTest method testSystemPropertyOverrideXml.

@SuppressWarnings("unchecked")
@Test
public void testSystemPropertyOverrideXml() throws Exception {
    System.setProperty("dubbo.application.name", "sysover");
    System.setProperty("dubbo.application.owner", "sysowner");
    System.setProperty("dubbo.registry.address", "N/A");
    System.setProperty("dubbo.protocol.name", "dubbo");
    System.setProperty("dubbo.protocol.port", "20819");
    System.setProperty("dubbo.service.register", "false");
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/system-properties-override.xml");
    providerContext.start();
    try {
        ServiceConfig<DemoService> service = (ServiceConfig<DemoService>) providerContext.getBean("demoServiceConfig");
        URL url = service.toUrls().get(0);
        assertEquals("sysover", url.getParameter("application"));
        assertEquals("sysowner", url.getParameter("owner"));
        assertEquals("dubbo", url.getProtocol());
        assertEquals(20819, url.getPort());
        String register = url.getParameter("register");
        assertTrue(register != null && !"".equals(register));
        assertEquals(false, Boolean.valueOf(register));
    } finally {
        System.setProperty("dubbo.application.name", "");
        System.setProperty("dubbo.application.owner", "");
        System.setProperty("dubbo.registry.address", "");
        System.setProperty("dubbo.protocol.name", "");
        System.setProperty("dubbo.protocol.port", "");
        System.setProperty("dubbo.service.register", "");
        providerContext.stop();
        providerContext.close();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ServiceConfig(com.alibaba.dubbo.config.ServiceConfig) DemoService(com.alibaba.dubbo.config.spring.api.DemoService) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Aggregations

DemoService (com.alibaba.dubbo.config.spring.api.DemoService)22 Test (org.junit.Test)21 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)11 RegistryConfig (com.alibaba.dubbo.config.RegistryConfig)10 ServiceConfig (com.alibaba.dubbo.config.ServiceConfig)10 ApplicationConfig (com.alibaba.dubbo.config.ApplicationConfig)9 DemoServiceImpl (com.alibaba.dubbo.config.spring.impl.DemoServiceImpl)8 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)8 ProtocolConfig (com.alibaba.dubbo.config.ProtocolConfig)7 URL (com.alibaba.dubbo.common.URL)6 ReferenceConfig (com.alibaba.dubbo.config.ReferenceConfig)6 RpcException (com.alibaba.dubbo.rpc.RpcException)4 ConsumerConfig (com.alibaba.dubbo.config.ConsumerConfig)1 ProviderConfig (com.alibaba.dubbo.config.ProviderConfig)1 HelloService (com.alibaba.dubbo.config.spring.api.HelloService)1 HelloServiceImpl (com.alibaba.dubbo.config.spring.impl.HelloServiceImpl)1 GenericException (com.alibaba.dubbo.rpc.service.GenericException)1 GenericService (com.alibaba.dubbo.rpc.service.GenericService)1 BeansException (org.springframework.beans.BeansException)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1