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