Search in sources :

Example 16 with ReferenceConfig

use of org.apache.dubbo.config.ReferenceConfig 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=\"org.apache.dubbo.config.spring.api.DemoService\" "));
    assertTrue(str.endsWith(" />"));
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 17 with ReferenceConfig

use of org.apache.dubbo.config.ReferenceConfig 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.setRegistry(registry);
    service.setProtocol(protocol);
    ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
    reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
    reference.setInterface(DemoService.class);
    reference.setUrl("dubbo://127.0.0.1:13123");
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(application).registry(registry).protocol(protocol).service(service).reference(reference).start();
    try {
        URL url = service.getExportedUrls().get(0);
        assertEquals("api-override-properties", url.getParameter("application"));
        assertEquals("world", url.getParameter("owner"));
        assertEquals(13123, url.getPort());
        url = reference.getExportedUrls().get(0);
        assertEquals("2000", url.getParameter("timeout"));
    } finally {
        bootstrap.stop();
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) 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 18 with ReferenceConfig

use of org.apache.dubbo.config.ReferenceConfig 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)

Example 19 with ReferenceConfig

use of org.apache.dubbo.config.ReferenceConfig in project incubator-dubbo-ops by apache.

the class GenericServiceImpl method invoke.

public Object invoke(String service, String method, String[] parameterTypes, Object[] params) {
    ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
    String group = Tool.getGroup(service);
    String version = Tool.getVersion(service);
    String intf = Tool.getInterface(service);
    reference.setGeneric(true);
    reference.setApplication(applicationConfig);
    reference.setInterface(intf);
    reference.setVersion(version);
    reference.setGroup(group);
    // Keep it consistent with the ConfigManager cache
    reference.setSticky(false);
    try {
        removeGenericSymbol(parameterTypes);
        GenericService genericService = reference.get();
        return genericService.$invoke(method, parameterTypes, params);
    } finally {
        reference.destroy();
    }
}
Also used : GenericService(org.apache.dubbo.rpc.service.GenericService) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig)

Aggregations

ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)19 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)16 RegistryConfig (org.apache.dubbo.config.RegistryConfig)16 Test (org.junit.jupiter.api.Test)12 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)11 ServiceConfig (org.apache.dubbo.config.ServiceConfig)9 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)8 DemoService (org.apache.dubbo.config.spring.api.DemoService)7 GenericService (org.apache.dubbo.rpc.service.GenericService)7 ArrayList (java.util.ArrayList)4 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 List (java.util.List)2 URL (org.apache.dubbo.common.URL)2 ConsumerConfig (org.apache.dubbo.config.ConsumerConfig)2 MethodConfig (org.apache.dubbo.config.MethodConfig)2 DemoService (org.apache.dubbo.demo.DemoService)2 GreetingsService (com.pinpoint.test.plugin.api.GreetingsService)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1