Search in sources :

Example 16 with RegistryConfig

use of com.alibaba.dubbo.config.RegistryConfig in project dubbo by alibaba.

the class ConfigTest method testReferGenericExport.

@Test
public void testReferGenericExport() throws Exception {
    ApplicationConfig ac = new ApplicationConfig("test-refer-generic-export");
    RegistryConfig rc = new RegistryConfig();
    rc.setAddress(RegistryConfig.NO_AVAILABLE);
    ServiceConfig<GenericService> sc = new ServiceConfig<GenericService>();
    sc.setApplication(ac);
    sc.setRegistry(rc);
    sc.setInterface(DemoService.class.getName());
    sc.setRef(new GenericService() {

        public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException {
            return null;
        }
    });
    ReferenceConfig<DemoService> ref = new ReferenceConfig<DemoService>();
    ref.setApplication(ac);
    ref.setRegistry(rc);
    ref.setInterface(DemoService.class.getName());
    try {
        sc.export();
        ref.get();
        Assert.fail();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        sc.unexport();
        ref.destroy();
    }
}
Also used : RegistryConfig(com.alibaba.dubbo.config.RegistryConfig) GenericService(com.alibaba.dubbo.rpc.service.GenericService) DemoService(com.alibaba.dubbo.config.spring.api.DemoService) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) GenericException(com.alibaba.dubbo.rpc.service.GenericException) BeanCreationException(org.springframework.beans.factory.BeanCreationException) GenericException(com.alibaba.dubbo.rpc.service.GenericException) BeansException(org.springframework.beans.BeansException) RpcException(com.alibaba.dubbo.rpc.RpcException) ApplicationConfig(com.alibaba.dubbo.config.ApplicationConfig) ServiceConfig(com.alibaba.dubbo.config.ServiceConfig) ReferenceConfig(com.alibaba.dubbo.config.ReferenceConfig) Test(org.junit.Test)

Example 17 with RegistryConfig

use of com.alibaba.dubbo.config.RegistryConfig in project dubbo by alibaba.

the class ConfigTest method testSystemPropertyOverrideProperties.

@Test
public void testSystemPropertyOverrideProperties() throws Exception {
    String portString = System.getProperty("dubbo.protocol.port");
    System.clearProperty("dubbo.protocol.port");
    try {
        int port = 1234;
        System.setProperty("dubbo.protocol.port", String.valueOf(port));
        ApplicationConfig application = new ApplicationConfig();
        application.setName("aaa");
        RegistryConfig registry = new RegistryConfig();
        registry.setAddress("N/A");
        ProtocolConfig protocol = new ProtocolConfig();
        protocol.setName("rmi");
        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);
            // from api
            assertEquals("aaa", url.getParameter("application"));
            // from dubbo.properties
            assertEquals("world", url.getParameter("owner"));
            // from system property
            assertEquals(1234, url.getPort());
        } finally {
            service.unexport();
        }
    } finally {
        if (portString != null) {
            System.setProperty("dubbo.protocol.port", portString);
        }
    }
}
Also used : RegistryConfig(com.alibaba.dubbo.config.RegistryConfig) ApplicationConfig(com.alibaba.dubbo.config.ApplicationConfig) ServiceConfig(com.alibaba.dubbo.config.ServiceConfig) DemoService(com.alibaba.dubbo.config.spring.api.DemoService) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) 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 18 with RegistryConfig

use of com.alibaba.dubbo.config.RegistryConfig in project dubbo by alibaba.

the class ConfigTest method testToString.

@Test
public void testToString() {
    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:20881");
    String str = reference.toString();
    assertTrue(str.startsWith("<dubbo:reference "));
    assertTrue(str.contains(" url=\"dubbo://127.0.0.1:20881\" "));
    assertTrue(str.contains(" interface=\"com.alibaba.dubbo.config.spring.api.DemoService\" "));
    assertTrue(str.endsWith(" />"));
}
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) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) Test(org.junit.Test)

Example 19 with RegistryConfig

use of com.alibaba.dubbo.config.RegistryConfig in project dubbo by alibaba.

the class ConfigTest method testXmlOverrideProperties.

@Test
public void testXmlOverrideProperties() throws Exception {
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/xml-override-properties.xml");
    providerContext.start();
    try {
        ApplicationConfig application = (ApplicationConfig) providerContext.getBean("application");
        assertEquals("demo-provider", application.getName());
        assertEquals("world", application.getOwner());
        RegistryConfig registry = (RegistryConfig) providerContext.getBean("registry");
        assertEquals("N/A", registry.getAddress());
        ProtocolConfig dubbo = (ProtocolConfig) providerContext.getBean("dubbo");
        assertEquals(20813, dubbo.getPort().intValue());
    } finally {
        providerContext.stop();
        providerContext.close();
    }
}
Also used : RegistryConfig(com.alibaba.dubbo.config.RegistryConfig) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationConfig(com.alibaba.dubbo.config.ApplicationConfig) ProtocolConfig(com.alibaba.dubbo.config.ProtocolConfig) Test(org.junit.Test)

Example 20 with RegistryConfig

use of com.alibaba.dubbo.config.RegistryConfig in project dubbo by alibaba.

the class ConfigTest method testSystemPropertyOverrideApi.

@Test
public void testSystemPropertyOverrideApi() 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", "20834");
    try {
        ApplicationConfig application = new ApplicationConfig();
        application.setName("aaa");
        RegistryConfig registry = new RegistryConfig();
        registry.setAddress("127.0.0.1");
        ProtocolConfig protocol = new ProtocolConfig();
        protocol.setName("rmi");
        protocol.setPort(1099);
        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("sysover", url.getParameter("application"));
            assertEquals("sysowner", url.getParameter("owner"));
            assertEquals("dubbo", url.getProtocol());
            assertEquals(20834, url.getPort());
        } finally {
            service.unexport();
        }
    } 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", "");
    }
}
Also used : RegistryConfig(com.alibaba.dubbo.config.RegistryConfig) ApplicationConfig(com.alibaba.dubbo.config.ApplicationConfig) ServiceConfig(com.alibaba.dubbo.config.ServiceConfig) 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)

Aggregations

RegistryConfig (com.alibaba.dubbo.config.RegistryConfig)20 ApplicationConfig (com.alibaba.dubbo.config.ApplicationConfig)17 ProtocolConfig (com.alibaba.dubbo.config.ProtocolConfig)15 Test (org.junit.Test)15 ServiceConfig (com.alibaba.dubbo.config.ServiceConfig)11 DemoService (com.alibaba.dubbo.config.spring.api.DemoService)11 ReferenceConfig (com.alibaba.dubbo.config.ReferenceConfig)10 DemoServiceImpl (com.alibaba.dubbo.config.spring.impl.DemoServiceImpl)7 URL (com.alibaba.dubbo.common.URL)5 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)5 RpcException (com.alibaba.dubbo.rpc.RpcException)4 ConsumerConfig (com.alibaba.dubbo.config.ConsumerConfig)3 GenericService (com.alibaba.dubbo.rpc.service.GenericService)3 Date (java.util.Date)3 MethodConfig (com.alibaba.dubbo.config.MethodConfig)2 ProviderConfig (com.alibaba.dubbo.config.ProviderConfig)2 DemoService (com.alibaba.dubbo.config.api.DemoService)2 GenericException (com.alibaba.dubbo.rpc.service.GenericException)2 BeansException (org.springframework.beans.BeansException)2 Service (com.alibaba.dubbo.config.annotation.Service)1