use of org.apache.dubbo.registry.Registry in project dubbo by alibaba.
the class AbstractRegistryFactoryTest method testRegistryFactoryCache.
@Test
public void testRegistryFactoryCache() throws Exception {
URL url = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostAddress() + ":2233");
Registry registry1 = registryFactory.getRegistry(url);
Registry registry2 = registryFactory.getRegistry(url);
Assertions.assertEquals(registry1, registry2);
}
use of org.apache.dubbo.registry.Registry in project dubbo by alibaba.
the class AbstractRegistryFactoryTest method testRegistryFactoryIpCache.
/**
* Registration center address `dubbo` does not resolve
*/
// @Test
public void testRegistryFactoryIpCache() throws Exception {
Registry registry1 = registryFactory.getRegistry(URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostName() + ":2233"));
Registry registry2 = registryFactory.getRegistry(URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostAddress() + ":2233"));
Assertions.assertEquals(registry1, registry2);
}
use of org.apache.dubbo.registry.Registry in project dubbo by alibaba.
the class ConfigTest method testGenericServiceConfig.
@Test
public void testGenericServiceConfig() throws Exception {
ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
service.setRegistry(new RegistryConfig("mock://localhost"));
service.setInterface(DemoService.class.getName());
service.setGeneric(GENERIC_SERIALIZATION_BEAN);
service.setRef((method, parameterTypes, args) -> null);
DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(new ApplicationConfig("test")).service(service).start();
try {
Collection<Registry> collection = MockRegistryFactory.getCachedRegistry();
MockRegistry registry = (MockRegistry) collection.iterator().next();
URL url = registry.getRegistered().get(0);
Assertions.assertEquals(GENERIC_SERIALIZATION_BEAN, url.getParameter(GENERIC_KEY));
} finally {
MockRegistryFactory.cleanCachedRegistry();
bootstrap.stop();
}
}
use of org.apache.dubbo.registry.Registry in project dubbo by alibaba.
the class ServiceCheckUtils method getConsumerAddressNum.
public static int getConsumerAddressNum(ConsumerModel consumerModel) {
// TODO, only check one registry by default.
int num = 0;
Collection<Registry> registries = AbstractRegistryFactory.getRegistries();
if (CollectionUtils.isNotEmpty(registries)) {
AbstractRegistry abstractRegistry = (AbstractRegistry) registries.iterator().next();
for (Map.Entry<URL, Map<String, List<URL>>> entry : abstractRegistry.getNotified().entrySet()) {
if (entry.getKey().getServiceKey().equals(consumerModel.getServiceKey())) {
if (CollectionUtils.isNotEmptyMap(entry.getValue())) {
num = entry.getValue().size();
}
}
}
}
return num;
}
use of org.apache.dubbo.registry.Registry in project dubbo by alibaba.
the class Online method online.
public static boolean online(String servicePattern) {
boolean hasService = false;
Collection<ProviderModel> providerModelList = serviceRepository.getExportedServices();
for (ProviderModel providerModel : providerModelList) {
if (providerModel.getServiceMetadata().getDisplayServiceKey().matches(servicePattern)) {
hasService = true;
List<ProviderModel.RegisterStatedURL> statedUrls = providerModel.getStatedUrl();
for (ProviderModel.RegisterStatedURL statedURL : statedUrls) {
if (!statedURL.isRegistered()) {
Registry registry = registryFactory.getRegistry(statedURL.getRegistryUrl());
registry.register(statedURL.getProviderUrl());
statedURL.setRegistered(true);
}
}
}
}
return hasService;
}
Aggregations