Search in sources :

Example 46 with ApplicationConfig

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

Example 47 with ApplicationConfig

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

the class AnnotatedInterfaceConfigBeanBuilder method configureApplicationConfig.

private void configureApplicationConfig(C configBean) {
    String applicationConfigBeanName = resolveApplicationConfigBeanName(attributes);
    ApplicationConfig applicationConfig = getOptionalBean(applicationContext, applicationConfigBeanName, ApplicationConfig.class);
    configBean.setApplication(applicationConfig);
}
Also used : ApplicationConfig(org.apache.dubbo.config.ApplicationConfig)

Example 48 with ApplicationConfig

use of org.apache.dubbo.config.ApplicationConfig 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 49 with ApplicationConfig

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

the class ConfigTest method testXmlOverrideProperties.

@Test
public void testXmlOverrideProperties() throws Exception {
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/xml-override-properties.xml");
    providerContext.start();
    try {
        ApplicationConfig application = (ApplicationConfig) providerContext.getBean("application");
        assertEquals("demo-provider", application.getName());
        assertEquals("world", application.getOwner());
        RegistryConfig registry = (RegistryConfig) providerContext.getBean("registry");
        assertEquals("N/A", registry.getAddress());
        ProtocolConfig dubbo = (ProtocolConfig) providerContext.getBean("dubbo");
        assertEquals(20813, dubbo.getPort().intValue());
    } finally {
        providerContext.stop();
        providerContext.close();
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) Test(org.junit.jupiter.api.Test)

Example 50 with ApplicationConfig

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

Aggregations

ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)75 RegistryConfig (org.apache.dubbo.config.RegistryConfig)42 Test (org.junit.jupiter.api.Test)32 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)27 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)19 ServiceConfig (org.apache.dubbo.config.ServiceConfig)18 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)16 DemoService (org.apache.dubbo.config.spring.api.DemoService)13 URL (org.apache.dubbo.common.URL)9 GenericService (org.apache.dubbo.rpc.service.GenericService)8 Test (org.junit.Test)8 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)7 ArrayList (java.util.ArrayList)6 MonitorConfig (org.apache.dubbo.config.MonitorConfig)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 AbstractInterfaceConfigTest (org.apache.dubbo.config.AbstractInterfaceConfigTest)4 UserService (org.apache.dubbo.config.bootstrap.rest.UserService)4 MetadataReportConfig (org.apache.dubbo.config.MetadataReportConfig)3 ModuleConfig (org.apache.dubbo.config.ModuleConfig)3 UserServiceImpl (org.apache.dubbo.config.bootstrap.rest.UserServiceImpl)3