Search in sources :

Example 11 with DefaultServiceInstance

use of org.apache.dubbo.registry.client.DefaultServiceInstance in project dubbo by alibaba.

the class SpringCloudMetadataServiceURLBuilderTest method testBuild.

@Test
public void testBuild() {
    List<URL> urls = builder.build(new DefaultServiceInstance("127.0.0.1", "test", 8080));
    assertEquals(0, urls.size());
    urls = builder.build(serviceInstance);
    assertEquals(1, urls.size());
    URL url = urls.get(0);
    assertEquals("192.168.0.102", url.getHost());
    assertEquals(20881, url.getPort());
    assertEquals("com.alibaba.cloud.dubbo.service.DubboMetadataService", url.getServiceInterface());
}
Also used : DefaultServiceInstance(org.apache.dubbo.registry.client.DefaultServiceInstance) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 12 with DefaultServiceInstance

use of org.apache.dubbo.registry.client.DefaultServiceInstance in project dubbo by alibaba.

the class ConsulServiceDiscoveryTest method testGetInstances.

@Test
public void testGetInstances() throws Exception {
    String serviceName = "ConsulTest77Service";
    assertTrue(consulServiceDiscovery.getInstances(serviceName).isEmpty());
    int portA = NetUtils.getAvailablePort();
    int portB = NetUtils.getAvailablePort();
    consulServiceDiscovery.register(new DefaultServiceInstance(valueOf(System.nanoTime()), serviceName, "127.0.0.1", portA));
    consulServiceDiscovery.register(new DefaultServiceInstance(valueOf(System.nanoTime()), serviceName, "127.0.0.1", portB));
    Thread.sleep(5000);
    Assertions.assertFalse(consulServiceDiscovery.getInstances(serviceName).isEmpty());
    List<String> r = convertToIpPort(consulServiceDiscovery.getInstances(serviceName));
    assertTrue(r.contains("127.0.0.1:" + portA));
    assertTrue(r.contains("127.0.0.1:" + portB));
}
Also used : DefaultServiceInstance(org.apache.dubbo.registry.client.DefaultServiceInstance) Test(org.junit.jupiter.api.Test)

Example 13 with DefaultServiceInstance

use of org.apache.dubbo.registry.client.DefaultServiceInstance in project dubbo by alibaba.

the class SofaRegistryServiceDiscovery method handleRegistryData.

private List<ServiceInstance> handleRegistryData(String dataId, UserData userData, ServiceInstancesChangedListener listener, CountDownLatch latch) {
    try {
        List<String> datas = getUserData(dataId, userData);
        List<ServiceInstance> serviceInstances = new ArrayList<>(datas.size());
        for (String serviceData : datas) {
            SofaRegistryInstance sri = gson.fromJson(serviceData, SofaRegistryInstance.class);
            DefaultServiceInstance serviceInstance = new DefaultServiceInstance(sri.getId(), dataId, sri.getHost(), sri.getPort());
            serviceInstance.setMetadata(sri.getMetadata());
            serviceInstances.add(serviceInstance);
        }
        if (null != listener) {
            listener.onEvent(new ServiceInstancesChangedEvent(dataId, serviceInstances));
        }
        return serviceInstances;
    } finally {
        if (null != latch) {
            latch.countDown();
        }
    }
}
Also used : DefaultServiceInstance(org.apache.dubbo.registry.client.DefaultServiceInstance) ArrayList(java.util.ArrayList) ServiceInstance(org.apache.dubbo.registry.client.ServiceInstance) DefaultServiceInstance(org.apache.dubbo.registry.client.DefaultServiceInstance) ServiceInstancesChangedEvent(org.apache.dubbo.registry.client.event.ServiceInstancesChangedEvent)

Example 14 with DefaultServiceInstance

use of org.apache.dubbo.registry.client.DefaultServiceInstance in project dubbo by alibaba.

the class EtcdServiceDiscoveryTest method testUnRegistry.

@Test
public void testUnRegistry() throws Exception {
    ServiceInstance serviceInstance = new DefaultServiceInstance(valueOf(System.nanoTime()), "EtcdTest2Service", "127.0.0.1", 8080);
    Assertions.assertNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance)));
    etcdServiceDiscovery.register(serviceInstance);
    Assertions.assertNotNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance)));
    etcdServiceDiscovery.unregister(serviceInstance);
    Assertions.assertNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance)));
}
Also used : DefaultServiceInstance(org.apache.dubbo.registry.client.DefaultServiceInstance) ServiceInstance(org.apache.dubbo.registry.client.ServiceInstance) DefaultServiceInstance(org.apache.dubbo.registry.client.DefaultServiceInstance) Test(org.junit.jupiter.api.Test)

Example 15 with DefaultServiceInstance

use of org.apache.dubbo.registry.client.DefaultServiceInstance in project dubbo by alibaba.

the class EurekaServiceDiscovery method buildServiceInstance.

private ServiceInstance buildServiceInstance(InstanceInfo instance) {
    DefaultServiceInstance serviceInstance = new DefaultServiceInstance(instance.getId(), instance.getAppName(), instance.getHostName(), instance.isPortEnabled(InstanceInfo.PortType.SECURE) ? instance.getSecurePort() : instance.getPort());
    serviceInstance.setMetadata(instance.getMetadata());
    return serviceInstance;
}
Also used : DefaultServiceInstance(org.apache.dubbo.registry.client.DefaultServiceInstance)

Aggregations

DefaultServiceInstance (org.apache.dubbo.registry.client.DefaultServiceInstance)16 Test (org.junit.jupiter.api.Test)8 ServiceInstance (org.apache.dubbo.registry.client.ServiceInstance)6 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 URL (org.apache.dubbo.common.URL)2 ServiceInstancesChangedEvent (org.apache.dubbo.registry.client.event.ServiceInstancesChangedEvent)2 Gson (com.google.gson.Gson)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)1 MetadataInfo (org.apache.dubbo.metadata.MetadataInfo)1 ServiceInstanceCustomizer (org.apache.dubbo.registry.client.ServiceInstanceCustomizer)1 ServiceInstancesChangedListener (org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener)1 ZookeeperInstance (org.apache.dubbo.registry.zookeeper.ZookeeperInstance)1