use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestMicroserviceInstanceCache method testGetOrCreateMicroservice.
@Test
public void testGetOrCreateMicroservice(@Mocked Microservice microservice) {
new MockUp<DiscoveryManager>() {
@Mock
public Microservice getMicroservice(String microserviceId) {
if ("forkedid".equals(microserviceId)) {
return microservice;
}
if ("forkedidNull".equals(microserviceId)) {
return null;
}
throw new IllegalArgumentException("unrecognized param");
}
};
Microservice cachedService = MicroserviceInstanceCache.getOrCreate("forkedid");
Assert.assertNotNull(cachedService);
cachedService = MicroserviceInstanceCache.getOrCreate("forkedid");
Assert.assertNotNull(cachedService);
cachedService = MicroserviceInstanceCache.getOrCreate("forkedidNull");
Assert.assertNull(cachedService);
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class LocalServiceRegistryClientImplTest method registerSchema_normal.
@Test
public void registerSchema_normal() {
Microservice v1 = mockRegisterMicroservice(appId, microserviceName, "1.0.0");
Assert.assertTrue(registryClient.registerSchema(v1.getServiceId(), "sid", "content"));
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class LocalServiceRegistryClientImplTest method testFindServiceInstance.
@Test
public void testFindServiceInstance() {
Microservice microservice = mockRegisterMicroservice(appId, microserviceName, "1.0.0");
MicroserviceInstance instance = new MicroserviceInstance();
instance.setServiceId(microservice.getServiceId());
String instanceId = registryClient.registerMicroserviceInstance(instance);
Assert.assertNotNull(registryClient.findServiceInstance(microservice.getServiceId(), instanceId));
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class LocalServiceRegistryClientImplTest method findServiceInstance_twoSelectOne.
@Test
public void findServiceInstance_twoSelectOne() {
Microservice v1 = mockRegisterMicroservice(appId, microserviceName, "1.0.0");
mockRegisterMicroservice(appId, microserviceName, "2.0.0");
MicroserviceInstance instance = new MicroserviceInstance();
instance.setInstanceId("testid");
instance.setServiceId(v1.getServiceId());
registryClient.registerMicroserviceInstance(instance);
List<MicroserviceInstance> result = registryClient.findServiceInstance("self", appId, microserviceName, "1.0.0");
Assert.assertThat(result, Matchers.contains(instance));
MicroserviceInstances microserviceInstances = registryClient.findServiceInstances("self", appId, microserviceName, "1.0.0", "0");
List<MicroserviceInstance> results = microserviceInstances.getInstancesResponse().getInstances();
Assert.assertThat(results, Matchers.contains(instance));
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class LocalServiceRegistryClientImplTest method mockRegisterMicroservice.
private Microservice mockRegisterMicroservice(String appId, String name, String version) {
Microservice microservice = new Microservice();
microservice.setAppId(appId);
microservice.setServiceName(name);
microservice.setVersion(version);
String serviceId = registryClient.registerMicroservice(microservice);
microservice.setServiceId(serviceId);
return microservice;
}
Aggregations