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