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();
}
}
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);
}
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(" />"));
}
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();
}
}
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();
}
}
Aggregations