Search in sources :

Example 6 with MethodConfig

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

the class UrlTestBase method initServConf.

@SuppressWarnings("deprecation")
protected void initServConf() {
    regConfForProvider = new RegistryConfig();
    regConfForService = new RegistryConfig();
    provConf = new ProviderConfig();
    protoConfForProvider = new ProtocolConfig("mockprotocol");
    protoConfForService = new ProtocolConfig("mockprotocol");
    methodConfForService = new MethodConfig();
    servConf = new ServiceConfig<DemoService>();
    // provConf.setApplication(appConfForProvider);
    servConf.setApplication(application);
    provConf.setRegistry(regConfForProvider);
    servConf.setRegistry(regConfForService);
    provConf.setProtocols(new ArrayList<>(Arrays.asList(protoConfForProvider)));
    servConf.setProtocols(new ArrayList<>(Arrays.asList(protoConfForService)));
    servConf.setMethods(Arrays.asList(new MethodConfig[] { methodConfForService }));
    servConf.setProvider(provConf);
    servConf.setRef(demoService);
    servConf.setInterfaceClass(DemoService.class);
    methodConfForService.setName("sayName");
    regConfForService.setAddress("127.0.0.1:9090");
    regConfForService.setProtocol("mockregistry");
    application.setName("ConfigTests");
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) MethodConfig(org.apache.dubbo.config.MethodConfig) ProviderConfig(org.apache.dubbo.config.ProviderConfig) DemoService(org.apache.dubbo.config.api.DemoService) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig)

Example 7 with MethodConfig

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

the class ReferenceBuilderTest method addMethods.

@Test
void addMethods() {
    MethodConfig method = new MethodConfig();
    ReferenceBuilder builder = new ReferenceBuilder();
    builder.addMethods(Collections.singletonList(method));
    Assertions.assertTrue(builder.build().getMethods().contains(method));
    Assertions.assertEquals(1, builder.build().getMethods().size());
}
Also used : MethodConfig(org.apache.dubbo.config.MethodConfig) Test(org.junit.jupiter.api.Test)

Example 8 with MethodConfig

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

the class ServiceBuilderTest method addMethods.

@Test
void addMethods() {
    MethodConfig method = new MethodConfig();
    ServiceBuilder builder = new ServiceBuilder();
    builder.addMethods(Collections.singletonList(method));
    Assertions.assertTrue(builder.build().getMethods().contains(method));
    Assertions.assertEquals(1, builder.build().getMethods().size());
}
Also used : MethodConfig(org.apache.dubbo.config.MethodConfig) Test(org.junit.jupiter.api.Test)

Example 9 with MethodConfig

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

the class MethodBuilderTest method build.

@Test
void build() {
    ArgumentConfig argument = new ArgumentConfig();
    MethodBuilder builder = new MethodBuilder();
    builder.name("name").stat(1).retry(true).reliable(false).executes(2).deprecated(true).sticky(false).isReturn(true).oninvoke("on-invoke-object").oninvokeMethod("on-invoke-method").service("service").onreturn("on-return-object").onreturnMethod("on-return-method").serviceId("serviceId").onthrow("on-throw-object").onthrowMethod("on-throw-method").addArgument(argument);
    MethodConfig config = builder.build();
    MethodConfig config2 = builder.build();
    Assertions.assertTrue(config.isRetry());
    Assertions.assertFalse(config.isReliable());
    Assertions.assertTrue(config.getDeprecated());
    Assertions.assertFalse(config.getSticky());
    Assertions.assertTrue(config.isReturn());
    Assertions.assertEquals(1, config.getStat());
    Assertions.assertEquals(2, config.getExecutes());
    Assertions.assertEquals("on-invoke-object", config.getOninvoke());
    Assertions.assertEquals("on-invoke-method", config.getOninvokeMethod());
    Assertions.assertEquals("on-return-object", config.getOnreturn());
    Assertions.assertEquals("on-return-method", config.getOnreturnMethod());
    Assertions.assertEquals("on-throw-object", config.getOnthrow());
    Assertions.assertEquals("on-throw-method", config.getOnthrowMethod());
    Assertions.assertEquals("name", config.getName());
    Assertions.assertEquals("service", config.getService());
    Assertions.assertEquals("serviceId", config.getServiceId());
    Assertions.assertNotSame(config, config2);
}
Also used : MethodConfig(org.apache.dubbo.config.MethodConfig) ArgumentConfig(org.apache.dubbo.config.ArgumentConfig) Test(org.junit.jupiter.api.Test)

Example 10 with MethodConfig

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

the class CacheTest method testCache.

private void testCache(String type) throws Exception {
    ApplicationConfig applicationConfig = new ApplicationConfig("cache-test");
    RegistryConfig registryConfig = new RegistryConfig("N/A");
    ProtocolConfig protocolConfig = new ProtocolConfig("injvm");
    ServiceConfig<CacheService> service = new ServiceConfig<CacheService>();
    service.setApplication(applicationConfig);
    service.setRegistry(registryConfig);
    service.setProtocol(protocolConfig);
    service.setInterface(CacheService.class.getName());
    service.setRef(new CacheServiceImpl());
    service.export();
    try {
        ReferenceConfig<CacheService> reference = new ReferenceConfig<CacheService>();
        reference.setApplication(applicationConfig);
        reference.setInterface(CacheService.class);
        reference.setUrl("injvm://127.0.0.1?scope=remote&cache=true");
        MethodConfig method = new MethodConfig();
        method.setName("findCache");
        method.setCache(type);
        reference.setMethods(Arrays.asList(method));
        CacheService cacheService = reference.get();
        try {
            // verify cache, same result is returned for multiple invocations (in fact, the return value increases
            // on every invocation on the server side)
            String fix = null;
            cacheService.findCache("0");
            for (int i = 0; i < 3; i++) {
                String result = cacheService.findCache("0");
                assertTrue(fix == null || fix.equals(result));
                fix = result;
                Thread.sleep(100);
            }
            if ("lru".equals(type)) {
                // default cache.size is 1000 for LRU, should have cache expired if invoke more than 1001 times
                for (int n = 0; n < 1001; n++) {
                    String pre = null;
                    cacheService.findCache(String.valueOf(n));
                    for (int i = 0; i < 10; i++) {
                        String result = cacheService.findCache(String.valueOf(n));
                        assertTrue(pre == null || pre.equals(result));
                        pre = result;
                    }
                }
                // verify if the first cache item is expired in LRU cache
                String result = cacheService.findCache("0");
                assertFalse(fix == null || fix.equals(result));
            }
        } finally {
            reference.destroy();
        }
    } finally {
        service.unexport();
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) MethodConfig(org.apache.dubbo.config.MethodConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig)

Aggregations

MethodConfig (org.apache.dubbo.config.MethodConfig)13 Test (org.junit.jupiter.api.Test)7 RegistryConfig (org.apache.dubbo.config.RegistryConfig)3 DemoService (org.apache.dubbo.config.api.DemoService)3 ConsumerConfig (org.apache.dubbo.config.ConsumerConfig)2 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)2 ProviderConfig (org.apache.dubbo.config.ProviderConfig)2 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)2 ServiceConfig (org.apache.dubbo.config.ServiceConfig)2 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)1 ArgumentConfig (org.apache.dubbo.config.ArgumentConfig)1 Method (org.apache.dubbo.config.annotation.Method)1 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)1 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)1 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)1 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)1