use of org.apache.dubbo.registry.client.DefaultServiceInstance in project dubbo by alibaba.
the class EtcdServiceDiscoveryTest method testGetInstances.
@Test
public void testGetInstances() throws Exception {
String serviceName = "EtcdTest77Service";
Assertions.assertTrue(etcdServiceDiscovery.getInstances(serviceName).isEmpty());
etcdServiceDiscovery.register(new DefaultServiceInstance(valueOf(System.nanoTime()), serviceName, "127.0.0.1", 8080));
etcdServiceDiscovery.register(new DefaultServiceInstance(valueOf(System.nanoTime()), serviceName, "127.0.0.1", 9809));
Assertions.assertFalse(etcdServiceDiscovery.getInstances(serviceName).isEmpty());
List<String> r = convertToIpPort(etcdServiceDiscovery.getInstances(serviceName));
Assertions.assertTrue(r.contains("127.0.0.1:8080"));
Assertions.assertTrue(r.contains("127.0.0.1:9809"));
}
use of org.apache.dubbo.registry.client.DefaultServiceInstance in project dubbo by alibaba.
the class EtcdServiceDiscoveryTest method testRegistry.
@Test
public void testRegistry() throws Exception {
ServiceInstance serviceInstance = new DefaultServiceInstance(valueOf(System.nanoTime()), "EtcdTestService", "127.0.0.1", 8080);
Assertions.assertNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance)));
etcdServiceDiscovery.register(serviceInstance);
Assertions.assertNotNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance)));
}
use of org.apache.dubbo.registry.client.DefaultServiceInstance in project dubbo by alibaba.
the class EtcdServiceDiscoveryTest method testUpdate.
@Test
public void testUpdate() throws Exception {
DefaultServiceInstance serviceInstance = new DefaultServiceInstance(valueOf(System.nanoTime()), "EtcdTest34Service", "127.0.0.1", 8080);
Assertions.assertNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance)));
etcdServiceDiscovery.register(serviceInstance);
Assertions.assertNotNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance)));
Assertions.assertEquals(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance)), new Gson().toJson(serviceInstance));
serviceInstance.setPort(9999);
etcdServiceDiscovery.update(serviceInstance);
Assertions.assertNotNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance)));
Assertions.assertEquals(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance)), new Gson().toJson(serviceInstance));
}
use of org.apache.dubbo.registry.client.DefaultServiceInstance in project dubbo by alibaba.
the class ConsulServiceDiscoveryTest method testRegistration.
@Test
public void testRegistration() throws InterruptedException {
DefaultServiceInstance serviceInstance = createServiceInstance(SERVICE_NAME, LOCALHOST, NetUtils.getAvailablePort());
consulServiceDiscovery.register(serviceInstance);
Thread.sleep(5000);
List<ServiceInstance> serviceInstances = consulServiceDiscovery.getInstances(SERVICE_NAME);
assertEquals(serviceInstances.size(), 1);
assertEquals(serviceInstances.get(0).getId(), Integer.toHexString(serviceInstance.hashCode()));
assertEquals(serviceInstances.get(0).getHost(), serviceInstance.getHost());
assertEquals(serviceInstances.get(0).getServiceName(), serviceInstance.getServiceName());
assertEquals(serviceInstances.get(0).getPort(), serviceInstance.getPort());
consulServiceDiscovery.unregister(serviceInstance);
Thread.sleep(5000);
serviceInstances = consulServiceDiscovery.getInstances(SERVICE_NAME);
System.out.println(serviceInstances.size());
assertTrue(serviceInstances.isEmpty());
}
use of org.apache.dubbo.registry.client.DefaultServiceInstance in project dubbo by alibaba.
the class NacosNamingServiceUtils method toServiceInstance.
/**
* Convert the {@link Instance} to {@link ServiceInstance}
*
* @param instance {@link Instance}
* @return non-null
* @since 2.7.5
*/
public static ServiceInstance toServiceInstance(Instance instance) {
DefaultServiceInstance serviceInstance = new DefaultServiceInstance(instance.getInstanceId(), NamingUtils.getServiceName(instance.getServiceName()), instance.getIp(), instance.getPort());
serviceInstance.setMetadata(instance.getMetadata());
serviceInstance.setEnabled(instance.isEnabled());
serviceInstance.setHealthy(instance.isHealthy());
return serviceInstance;
}
Aggregations