Search in sources :

Example 26 with ServiceConfig

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

the class GenericServiceTest method testGenericReferenceException.

@SuppressWarnings("unchecked")
@Test
public void testGenericReferenceException() {
    ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
    service.setInterface(DemoService.class.getName());
    service.setRef(new DemoServiceImpl());
    ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>();
    reference.setInterface(DemoService.class);
    reference.setUrl("dubbo://127.0.0.1:29581?scope=remote&timeout=3000");
    reference.setGeneric(true);
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(new ApplicationConfig("generic-test")).registry(new RegistryConfig("N/A")).protocol(new ProtocolConfig("dubbo", 29581)).service(service).reference(reference);
    bootstrap.start();
    try {
        GenericService genericService = ReferenceConfigCache.getCache().get(reference);
        List<Map<String, Object>> users = new ArrayList<Map<String, Object>>();
        Map<String, Object> user = new HashMap<String, Object>();
        user.put("class", "org.apache.dubbo.config.api.User");
        user.put("name", "actual.provider");
        users.add(user);
        users = (List<Map<String, Object>>) genericService.$invoke("getUsers", new String[] { List.class.getName() }, new Object[] { users });
        Assertions.assertEquals(1, users.size());
        Assertions.assertEquals("actual.provider", users.get(0).get("name"));
    } finally {
        bootstrap.stop();
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) GenericService(org.apache.dubbo.rpc.service.GenericService) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) ArrayList(java.util.ArrayList) List(java.util.List) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) HashMap(java.util.HashMap) Map(java.util.Map) 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