Search in sources :

Example 21 with ServiceConfig

use of org.apache.dubbo.config.ServiceConfig 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);
        DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(application).registry(registry).protocol(protocol).service(service).start();
        try {
            URL url = service.getExportedUrls().get(0);
            assertEquals("sysover", url.getParameter("application"));
            assertEquals("sysowner", url.getParameter("owner"));
            assertEquals("dubbo", url.getProtocol());
            assertEquals(20834, url.getPort());
        } finally {
            bootstrap.stop();
        }
    } 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(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) URL(org.apache.dubbo.common.URL) DemoServiceImpl(org.apache.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 22 with ServiceConfig

use of org.apache.dubbo.config.ServiceConfig 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(org.apache.dubbo.config.ServiceConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) Test(org.junit.jupiter.api.Test)

Example 23 with ServiceConfig

use of org.apache.dubbo.config.ServiceConfig in project dubbo by alibaba.

the class ConfigTest method testSystemPropertyOverrideApiDefault.

@Test
public void testSystemPropertyOverrideApiDefault() 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 {
        ServiceConfig<DemoService> serviceConfig = new ServiceConfig<DemoService>();
        serviceConfig.setInterface(DemoService.class);
        serviceConfig.setRef(new DemoServiceImpl());
        DubboBootstrap bootstrap = DubboBootstrap.getInstance().service(serviceConfig).start();
        try {
            assertEquals("sysover", serviceConfig.getApplication().getName());
            assertEquals("sysowner", serviceConfig.getApplication().getOwner());
            assertEquals("N/A", serviceConfig.getRegistry().getAddress());
            assertEquals("dubbo", serviceConfig.getProtocol().getName());
            assertEquals(20834, serviceConfig.getProtocol().getPort().intValue());
        } finally {
            bootstrap.stop();
        }
    } 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 : ServiceConfig(org.apache.dubbo.config.ServiceConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) DemoServiceImpl(org.apache.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 24 with ServiceConfig

use of org.apache.dubbo.config.ServiceConfig in project dubbo by alibaba.

the class Application method startWithBootstrap.

private static void startWithBootstrap() {
    ServiceConfig<DemoServiceImpl> service = new ServiceConfig<>();
    service.setInterface(DemoService.class);
    service.setRef(new DemoServiceImpl());
    DubboBootstrap bootstrap = DubboBootstrap.getInstance();
    bootstrap.application(new ApplicationConfig("dubbo-demo-api-provider")).registry(new RegistryConfig("zookeeper://127.0.0.1:2181")).service(service).start().await();
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap)

Example 25 with ServiceConfig

use of org.apache.dubbo.config.ServiceConfig in project dubbo by alibaba.

the class GenericServiceTest method testGenericImplementationWithBeanSerialization.

@Test
public void testGenericImplementationWithBeanSerialization() throws Exception {
    final AtomicReference reference = new AtomicReference();
    ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
    service.setInterface(DemoService.class.getName());
    service.setRef(new GenericService() {

        public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException {
            if ("getUsers".equals(method)) {
                GenericParameter arg = new GenericParameter();
                arg.method = method;
                arg.parameterTypes = parameterTypes;
                arg.arguments = args;
                reference.set(arg);
                return args[0];
            }
            if ("sayName".equals(method)) {
                return null;
            }
            return args;
        }
    });
    ReferenceConfig<DemoService> ref = null;
    ref = new ReferenceConfig<DemoService>();
    ref.setInterface(DemoService.class);
    ref.setUrl("dubbo://127.0.0.1:29581?scope=remote&generic=bean&timeout=3000");
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(new ApplicationConfig("generic-test")).registry(new RegistryConfig("N/A")).protocol(new ProtocolConfig("dubbo", 29581)).service(service).reference(ref);
    bootstrap.start();
    try {
        DemoService demoService = bootstrap.getCache().get(ref);
        User user = new User();
        user.setName("zhangsan");
        List<User> users = new ArrayList<User>();
        users.add(user);
        List<User> result = demoService.getUsers(users);
        Assertions.assertEquals(users.size(), result.size());
        Assertions.assertEquals(user.getName(), result.get(0).getName());
        GenericParameter gp = (GenericParameter) reference.get();
        Assertions.assertEquals("getUsers", gp.method);
        Assertions.assertEquals(1, gp.parameterTypes.length);
        Assertions.assertEquals(ReflectUtils.getName(List.class), gp.parameterTypes[0]);
        Assertions.assertEquals(1, gp.arguments.length);
        Assertions.assertTrue(gp.arguments[0] instanceof JavaBeanDescriptor);
        JavaBeanDescriptor descriptor = (JavaBeanDescriptor) gp.arguments[0];
        Assertions.assertTrue(descriptor.isCollectionType());
        Assertions.assertEquals(ArrayList.class.getName(), descriptor.getClassName());
        Assertions.assertEquals(1, descriptor.propertySize());
        descriptor = (JavaBeanDescriptor) descriptor.getProperty(0);
        Assertions.assertTrue(descriptor.isBeanType());
        Assertions.assertEquals(User.class.getName(), descriptor.getClassName());
        Assertions.assertEquals(user.getName(), ((JavaBeanDescriptor) descriptor.getProperty("name")).getPrimitiveProperty());
        Assertions.assertNull(demoService.sayName("zhangsan"));
    } finally {
        bootstrap.stop();
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) GenericService(org.apache.dubbo.rpc.service.GenericService) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) GenericException(org.apache.dubbo.rpc.service.GenericException) JavaBeanDescriptor(org.apache.dubbo.common.beanutil.JavaBeanDescriptor) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) ArrayList(java.util.ArrayList) List(java.util.List) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceConfig (org.apache.dubbo.config.ServiceConfig)26 RegistryConfig (org.apache.dubbo.config.RegistryConfig)19 Test (org.junit.jupiter.api.Test)19 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)18 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)14 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)14 DemoService (org.apache.dubbo.config.spring.api.DemoService)11 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)9 URL (org.apache.dubbo.common.URL)7 GenericService (org.apache.dubbo.rpc.service.GenericService)7 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)6 ArrayList (java.util.ArrayList)5 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)4 List (java.util.List)3 JavaBeanDescriptor (org.apache.dubbo.common.beanutil.JavaBeanDescriptor)2 MethodConfig (org.apache.dubbo.config.MethodConfig)2 ProviderConfig (org.apache.dubbo.config.ProviderConfig)2 UserService (org.apache.dubbo.config.bootstrap.rest.UserService)2 UserServiceImpl (org.apache.dubbo.config.bootstrap.rest.UserServiceImpl)2 GenericException (org.apache.dubbo.rpc.service.GenericException)2