Search in sources :

Example 16 with Registry

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);
}
Also used : Registry(org.apache.dubbo.registry.Registry) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 17 with Registry

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);
}
Also used : Registry(org.apache.dubbo.registry.Registry)

Example 18 with Registry

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();
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) GenericService(org.apache.dubbo.rpc.service.GenericService) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) MockRegistry(org.apache.dubbo.config.spring.registry.MockRegistry) DemoService(org.apache.dubbo.config.spring.api.DemoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) MockRegistry(org.apache.dubbo.config.spring.registry.MockRegistry) Registry(org.apache.dubbo.registry.Registry) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 19 with Registry

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;
}
Also used : AbstractRegistry(org.apache.dubbo.registry.support.AbstractRegistry) AbstractRegistry(org.apache.dubbo.registry.support.AbstractRegistry) Registry(org.apache.dubbo.registry.Registry) Map(java.util.Map) URL(org.apache.dubbo.common.URL)

Example 20 with Registry

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;
}
Also used : Registry(org.apache.dubbo.registry.Registry) ProviderModel(org.apache.dubbo.rpc.model.ProviderModel)

Aggregations

Registry (org.apache.dubbo.registry.Registry)26 Test (org.junit.jupiter.api.Test)9 AbstractRegistry (org.apache.dubbo.registry.support.AbstractRegistry)8 URL (org.apache.dubbo.common.URL)7 ArrayList (java.util.ArrayList)3 Status (org.apache.dubbo.common.status.Status)3 ProviderModel (org.apache.dubbo.rpc.model.ProviderModel)3 RegistryStatusChecker (org.apache.dubbo.registry.status.RegistryStatusChecker)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ConfigurationException (org.apache.dubbo.admin.common.exception.ConfigurationException)1 QOS_HOST (org.apache.dubbo.common.constants.QosConstants.QOS_HOST)1 QOS_PORT (org.apache.dubbo.common.constants.QosConstants.QOS_PORT)1 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)1 RegistryConfig (org.apache.dubbo.config.RegistryConfig)1 ServiceConfig (org.apache.dubbo.config.ServiceConfig)1 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)1 DemoService (org.apache.dubbo.config.spring.api.DemoService)1 MockRegistry (org.apache.dubbo.config.spring.registry.MockRegistry)1 NotifyListener (org.apache.dubbo.registry.NotifyListener)1