use of org.apache.dubbo.config.RegistryConfig in project dubbo by alibaba.
the class ModuleBuilderTest method addRegistries.
@Test
void addRegistries() {
RegistryConfig registry = new RegistryConfig();
ModuleBuilder builder = new ModuleBuilder();
builder.addRegistries(Collections.singletonList(registry));
Assertions.assertTrue(builder.build().getRegistries().contains(registry));
Assertions.assertEquals(1, builder.build().getRegistries().size());
}
use of org.apache.dubbo.config.RegistryConfig in project dubbo by alibaba.
the class ApplicationBuilderTest method addRegistries.
@Test
void addRegistries() {
RegistryConfig registry = new RegistryConfig();
ApplicationBuilder builder = new ApplicationBuilder();
builder.addRegistries(Collections.singletonList(registry));
Assertions.assertNotNull(builder.build().getRegistry());
Assertions.assertEquals(1, builder.build().getRegistries().size());
Assertions.assertSame(registry, builder.build().getRegistry());
}
use of org.apache.dubbo.config.RegistryConfig 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.RegistryConfig in project dubbo by alibaba.
the class RegistryBuilderTest method build.
@Test
void build() {
RegistryBuilder builder = new RegistryBuilder();
builder.address("address").username("username").password("password").port(8080).protocol("protocol").transporter("transporter").server("server").client("client").cluster("cluster").group("group").version("version").timeout(1000).session(2000).file("file").wait(Integer.valueOf(10)).isCheck(true).isDynamic(false).register(true).subscribe(false).isDefault(true).simplified(false).extraKeys("A").parameter("default.num", "one").id("id").prefix("prefix");
RegistryConfig config = builder.build();
RegistryConfig config2 = builder.build();
Assertions.assertEquals(8080, config.getPort());
Assertions.assertEquals(1000, config.getTimeout());
Assertions.assertEquals(2000, config.getSession());
Assertions.assertEquals(10, config.getWait());
Assertions.assertTrue(config.isCheck());
Assertions.assertFalse(config.isDynamic());
Assertions.assertTrue(config.isRegister());
Assertions.assertFalse(config.isSubscribe());
Assertions.assertTrue(config.isDefault());
Assertions.assertFalse(config.getSimplified());
Assertions.assertEquals("address", config.getAddress());
Assertions.assertEquals("username", config.getUsername());
Assertions.assertEquals("password", config.getPassword());
Assertions.assertEquals("protocol", config.getProtocol());
Assertions.assertEquals("transporter", config.getTransporter());
Assertions.assertEquals("server", config.getServer());
Assertions.assertEquals("client", config.getClient());
Assertions.assertEquals("cluster", config.getCluster());
Assertions.assertEquals("group", config.getGroup());
Assertions.assertEquals("version", config.getVersion());
Assertions.assertEquals("file", config.getFile());
Assertions.assertEquals("A", config.getExtraKeys());
Assertions.assertTrue(config.getParameters().containsKey("default.num"));
Assertions.assertEquals("one", config.getParameters().get("default.num"));
Assertions.assertEquals("id", config.getId());
Assertions.assertEquals("prefix", config.getPrefix());
Assertions.assertNotSame(config, config2);
}
use of org.apache.dubbo.config.RegistryConfig in project dubbo by alibaba.
the class PublishingServiceDefinitionListenerTest method testOnServiceConfigExportedEvent.
/**
* Test {@link ServiceConfigExportedEvent} arising
*/
@Test
public void testOnServiceConfigExportedEvent() {
ServiceConfig<EchoService> serviceConfig = new ServiceConfig<>();
serviceConfig.setInterface(EchoService.class);
serviceConfig.setRef(new EchoServiceImpl());
serviceConfig.setRegistry(new RegistryConfig("N/A"));
serviceConfig.setProtocol(new ProtocolConfig("dubbo", NetUtils.getAvailablePort(20880 + new Random().nextInt(10000))));
serviceConfig.export();
String serviceDefinition = writableMetadataService.getServiceDefinition(EchoService.class.getName());
ServiceDefinition serviceDefinitionBuild = ServiceDefinitionBuilder.build(serviceConfig.getInterfaceClass());
assertEquals(serviceDefinition, JSON.toJSONString(serviceDefinitionBuild));
serviceConfig.unexport();
}
Aggregations