Search in sources :

Example 46 with ProtocolConfig

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

the class RelaxedDubboConfigBinderTest method testBinder.

@Test
public void testBinder() {
    ApplicationConfig applicationConfig = new ApplicationConfig();
    Map<String, Object> properties = getSubProperties(environment.getPropertySources(), "dubbo.application");
    dubboConfigBinder.bind(properties, true, true, applicationConfig);
    Assert.assertEquals("hello", applicationConfig.getName());
    Assert.assertEquals("world", applicationConfig.getOwner());
    RegistryConfig registryConfig = new RegistryConfig();
    properties = getSubProperties(environment.getPropertySources(), "dubbo.registry");
    dubboConfigBinder.bind(properties, true, true, registryConfig);
    Assert.assertEquals("10.20.153.17", registryConfig.getAddress());
    ProtocolConfig protocolConfig = new ProtocolConfig();
    properties = getSubProperties(environment.getPropertySources(), "dubbo.protocol");
    dubboConfigBinder.bind(properties, true, true, protocolConfig);
    Assert.assertEquals(Integer.valueOf(20881), protocolConfig.getPort());
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) Test(org.junit.Test)

Example 47 with ProtocolConfig

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

the class DubboHealthIndicator method resolveStatusCheckerNamesMapFromProtocolConfigs.

private Map<String, String> resolveStatusCheckerNamesMapFromProtocolConfigs() {
    Map<String, String> statusCheckerNamesMap = new LinkedHashMap<>();
    for (Map.Entry<String, ProtocolConfig> entry : protocolConfigs.entrySet()) {
        String beanName = entry.getKey();
        ProtocolConfig protocolConfig = entry.getValue();
        Set<String> statusCheckerNames = getStatusCheckerNames(protocolConfig);
        for (String statusCheckerName : statusCheckerNames) {
            String source = buildSource(beanName, protocolConfig);
            statusCheckerNamesMap.put(statusCheckerName, source);
        }
    }
    return statusCheckerNamesMap;
}
Also used : ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 48 with ProtocolConfig

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

the class BinderDubboConfigBinderTest method testBinder.

@Test
public void testBinder() {
    ApplicationConfig applicationConfig = new ApplicationConfig();
    Map<String, Object> properties = getSubProperties(environment.getPropertySources(), "dubbo.application");
    dubboConfigBinder.bind(properties, true, true, applicationConfig);
    Assert.assertEquals("hello", applicationConfig.getName());
    Assert.assertEquals("world", applicationConfig.getOwner());
    RegistryConfig registryConfig = new RegistryConfig();
    properties = getSubProperties(environment.getPropertySources(), "dubbo.registry");
    dubboConfigBinder.bind(properties, true, true, registryConfig);
    Assert.assertEquals("10.20.153.17", registryConfig.getAddress());
    ProtocolConfig protocolConfig = new ProtocolConfig();
    properties = getSubProperties(environment.getPropertySources(), "dubbo.protocol");
    dubboConfigBinder.bind(properties, true, true, protocolConfig);
    Assert.assertEquals(Integer.valueOf(20881), protocolConfig.getPort());
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) Test(org.junit.Test)

Example 49 with ProtocolConfig

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

the class ConfigManagerTest method testAddConfig.

@Test
public void testAddConfig() {
    configManager.addConfig(new ApplicationConfig());
    configManager.addConfig(new ProviderConfig());
    configManager.addConfig(new ProtocolConfig());
    assertTrue(configManager.getApplication().isPresent());
    assertFalse(configManager.getProviders().isEmpty());
    assertFalse(configManager.getProtocols().isEmpty());
}
Also used : ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ProviderConfig(org.apache.dubbo.config.ProviderConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) Test(org.junit.jupiter.api.Test)

Example 50 with ProtocolConfig

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

ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)52 Test (org.junit.jupiter.api.Test)30 RegistryConfig (org.apache.dubbo.config.RegistryConfig)29 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)27 ServiceConfig (org.apache.dubbo.config.ServiceConfig)14 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)11 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)8 DemoService (org.apache.dubbo.config.spring.api.DemoService)8 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)7 ArrayList (java.util.ArrayList)6 ProviderConfig (org.apache.dubbo.config.ProviderConfig)6 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)6 GenericService (org.apache.dubbo.rpc.service.GenericService)5 Map (java.util.Map)4 URL (org.apache.dubbo.common.URL)4 Bean (org.springframework.context.annotation.Bean)4 List (java.util.List)3 ConsumerConfig (org.apache.dubbo.config.ConsumerConfig)3 ConfigTest (org.apache.dubbo.config.spring.ConfigTest)3 Test (org.junit.Test)3