use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class LocalServiceRegistryClientImplTest method getMicroserviceId_latest.
@Test
public void getMicroserviceId_latest() {
Microservice v2 = mockRegisterMicroservice(appId, microserviceName, "2.0.0");
mockRegisterMicroservice(appId, microserviceName, "1.0.0");
String serviceId = registryClient.getMicroserviceId(appId, microserviceName, DefinitionConst.VERSION_RULE_LATEST, "");
Assert.assertEquals(v2.getServiceId(), serviceId);
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class Consumer method prepareEdge.
private URIEndpointObject prepareEdge(String prefix) {
Microservice microservice = RegistrationManager.INSTANCE.getMicroservice();
MicroserviceInstance microserviceInstance = (MicroserviceInstance) DiscoveryManager.INSTANCE.getAppManager().getOrCreateMicroserviceVersionRule(microservice.getAppId(), "edge", DefinitionConst.VERSION_RULE_ALL).getVersionedCache().mapData().values().stream().findFirst().get();
URIEndpointObject edgeAddress = new URIEndpointObject(microserviceInstance.getEndpoints().get(0));
edgePrefix = String.format("http://%s:%d/%s/business", edgeAddress.getHostOrIp(), edgeAddress.getPort(), prefix);
return edgeAddress;
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class MockMicroserviceVersions method findInstances.
public List<MicroserviceInstance> findInstances(String... strVersions) {
List<String> unifyVersions = Arrays.stream(strVersions).map(version -> new Version(version).getVersion()).collect(Collectors.toList());
List<MicroserviceInstance> instances = new ArrayList<>();
for (MicroserviceInstance instance : mockedInstances) {
Microservice microservice = mockedMicroservices.get(instance.getServiceId());
for (String version : unifyVersions) {
if (version.equals(microservice.getVersion())) {
instances.add(instance);
break;
}
}
}
return instances;
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class MockMicroserviceVersions method addMock.
public void addMock(String version, int instanceCount) {
version = new Version(version).getVersion();
Microservice microservice = new Microservice();
microservice.setAppId(getAppId());
microservice.setServiceName(getMicroserviceName());
microservice.setServiceId("sid-" + version);
microservice.setVersion(version);
mockedMicroservices.put(microservice.getServiceId(), microservice);
for (int idx = 0; idx < instanceCount; idx++) {
MicroserviceInstance instance = new MicroserviceInstance();
instance.setServiceId(microservice.getServiceId());
instance.setInstanceId(String.format("iid-%s-%d", version, idx));
mockedInstances.add(instance);
}
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestRegistry method testDelegate.
@SuppressWarnings("deprecation")
@Test
public void testDelegate() {
ServiceRegistry serviceRegistry = LocalServiceRegistryFactory.createLocal();
serviceRegistry.init();
RegistryUtils.init();
serviceRegistry.run();
RegistryUtils.setServiceRegistry(serviceRegistry);
Assert.assertEquals(serviceRegistry, RegistryUtils.getServiceRegistry());
Assert.assertEquals(serviceRegistry.getServiceRegistryClient(), RegistryUtils.getServiceRegistryClient());
Microservice microservice = RegistryUtils.getMicroservice();
Assert.assertEquals(serviceRegistry.getMicroservice(), microservice);
Assert.assertEquals(serviceRegistry.getMicroserviceInstance(), RegistryUtils.getMicroserviceInstance());
List<MicroserviceInstance> instanceList = RegistryUtils.findServiceInstance("default", "default", "0.0.1");
Assert.assertEquals(1, instanceList.size());
Assert.assertEquals(RegistryUtils.getMicroservice().getServiceId(), instanceList.get(0).getServiceId());
instanceList = RegistryUtils.findServiceInstance("default", "notExists", "0.0.1");
Assert.assertNull(instanceList);
MicroserviceInstances microserviceInstances = RegistryUtils.findServiceInstances("default", "default", "0.0.1");
List<MicroserviceInstance> instanceLists = microserviceInstances.getInstancesResponse().getInstances();
Assert.assertEquals(1, instanceLists.size());
Assert.assertEquals(RegistryUtils.getMicroservice().getServiceId(), instanceLists.get(0).getServiceId());
Map<String, String> properties = new HashMap<>();
properties.put("k", "v");
RegistryUtils.updateInstanceProperties(properties);
Assert.assertEquals(properties, RegistryUtils.getMicroserviceInstance().getProperties());
Assert.assertEquals(microservice, RegistryUtils.getMicroservice(microservice.getServiceId()));
RegistryUtils.updateMicroserviceProperties(properties);
Assert.assertEquals(properties, RegistryUtils.getMicroservice().getProperties());
Assert.assertEquals("default", RegistryUtils.getAppId());
}
Aggregations