use of io.servicecomb.serviceregistry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestSimpleLoadBalanceHandler method mock.
public void mock() {
Microservice microService = new Microservice();
microService.setAppId("100");
new MockUp<RegistryUtils>() {
@Mock
public Microservice getMicroservice() {
return microService;
}
};
}
use of io.servicecomb.serviceregistry.api.registry.Microservice in project java-chassis by ServiceComb.
the class RegistryUtils method createMicroserviceFromDefinition.
private static Microservice createMicroserviceFromDefinition() {
Microservice microservice = new Microservice();
String name = DynamicPropertyFactory.getInstance().getStringProperty("service_description.name", null).get();
if (name == null || name.isEmpty()) {
throw new IllegalArgumentException("You must configure service_description.name");
}
microservice.setServiceName(name);
microservice.setAppId(DynamicPropertyFactory.getInstance().getStringProperty("APPLICATION_ID", "default").get());
microservice.setVersion(DynamicPropertyFactory.getInstance().getStringProperty("service_description.version", "1.0.0").get());
microservice.setDescription(DynamicPropertyFactory.getInstance().getStringProperty("service_description.description", "").get());
microservice.setLevel(DynamicPropertyFactory.getInstance().getStringProperty("service_description.role", "FRONT").get());
Map<String, String> propertiesMap = MicroservicePropertiesLoader.INSTANCE.loadProperties();
if (!isEmpty(propertiesMap)) {
microservice.setProperties(propertiesMap);
// 当允许跨app调用时为服务设置一个别名
if (allowCrossApp(propertiesMap)) {
microservice.setAlias(Microservice.generateAbsoluteMicroserviceName(microservice.getAppId(), microservice.getServiceName()));
}
}
return microservice;
}
use of io.servicecomb.serviceregistry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestInstanceCacheManager method testInstanceUpdate.
@Test
public void testInstanceUpdate() {
Microservice oInstance = RegistryUtils.getMicroservice();
InstanceCacheManager oInstanceCacheManager = new InstanceCacheManager();
MicroserviceInstanceChangedEvent oChangedEnvent = new MicroserviceInstanceChangedEvent();
oChangedEnvent.setAction(WatchAction.UPDATE);
MicroserviceKey oKey = new MicroserviceKey();
oKey.setAppId(oInstance.getAppId());
oKey.setVersion(oInstance.getVersion());
oKey.setServiceName(oInstance.getServiceName());
oChangedEnvent.setKey(oKey);
oChangedEnvent.setInstance(RegistryUtils.getMicroserviceInstance());
oInstanceCacheManager.onInstanceUpdate(oChangedEnvent);
oChangedEnvent.setAction(WatchAction.DELETE);
oInstanceCacheManager.onInstanceUpdate(oChangedEnvent);
oChangedEnvent.setAction(WatchAction.CREATE);
oInstanceCacheManager.onInstanceUpdate(oChangedEnvent);
Assert.assertEquals("UP", RegistryUtils.getMicroserviceInstance().getStatus().toString());
}
use of io.servicecomb.serviceregistry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestClienthttp method testServiceRegistryClientImpl.
@SuppressWarnings("unchecked")
@Test
public void testServiceRegistryClientImpl(@Mocked IpPortManager manager) {
IpPort ipPort = new IpPort("127.0.0.1", 8853);
new Expectations() {
{
manager.get();
result = ipPort;
manager.next();
result = null;
}
};
Microservice oInstance = RegistryUtils.getMicroservice();
RegistryThread oThread = new RegistryThread();
oThread.start();
ServiceRegistryClientImpl oClient = (ServiceRegistryClientImpl) RegistryClientFactory.getRegistryClient();
oClient.registerMicroservice(oInstance);
oClient.registerMicroserviceInstance(RegistryUtils.getMicroserviceInstance());
try {
oClient.init();
} catch (Exception e) {
Assert.assertEquals(null, e.getMessage());
}
Assert.assertEquals(null, oClient.getMicroservice(RegistryUtils.getMicroservice().getServiceId()));
Assert.assertEquals(null, oClient.getMicroserviceInstance("testConsumerID", "testproviderID"));
Assert.assertEquals(null, oClient.findServiceInstance(RegistryUtils.getMicroservice().getServiceId(), RegistryUtils.getMicroservice().getAppId(), RegistryUtils.getMicroservice().getServiceName(), RegistryUtils.getMicroservice().getVersion()));
Assert.assertEquals(null, oClient.getMicroserviceId(RegistryUtils.getMicroservice().getAppId(), RegistryUtils.getMicroservice().getServiceName(), RegistryUtils.getMicroservice().getVersion()));
Assert.assertEquals(null, oClient.heartbeat(RegistryUtils.getMicroservice().getServiceId(), RegistryUtils.getMicroserviceInstance().getInstanceId()));
oClient.watch("", Mockito.mock(AsyncResultCallback.class));
Assert.assertEquals(false, oClient.unregisterMicroserviceInstance(RegistryUtils.getMicroservice().getServiceId(), RegistryUtils.getMicroserviceInstance().getInstanceId()));
}
use of io.servicecomb.serviceregistry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestServiceRegistryClientImpl method testException.
@Test
public void testException() {
Microservice oInstance = RegistryUtils.getMicroservice();
RegistryThread oThread = new RegistryThread();
oThread.start();
oClient.registerMicroservice(oInstance);
oClient.registerMicroserviceInstance(RegistryUtils.getMicroserviceInstance());
try {
oClient.init();
} catch (Exception e) {
Assert.assertEquals(null, e.getMessage());
}
new MockUp<CountDownLatch>() {
@Mock
public void await() throws InterruptedException {
throw new InterruptedException();
}
};
Assert.assertEquals(null, oClient.getMicroserviceId(RegistryUtils.getMicroservice().getAppId(), RegistryUtils.getMicroservice().getServiceName(), RegistryUtils.getMicroservice().getVersion()));
Assert.assertEquals(null, oClient.getAllMicroservices());
Assert.assertEquals(null, oClient.registerMicroservice(RegistryUtils.getMicroservice()));
Assert.assertEquals(null, oClient.getMicroservice("microserviceId"));
Assert.assertEquals(null, oClient.getMicroserviceInstance("consumerId", "providerId"));
Assert.assertEquals(false, oClient.unregisterMicroserviceInstance("microserviceId", "microserviceInstanceId"));
Assert.assertEquals(null, oClient.heartbeat("microserviceId", "microserviceInstanceId"));
Assert.assertEquals(null, oClient.findServiceInstance("selfMicroserviceId", "appId", "serviceName", "versionRule"));
MicroserviceInstance microInstance = Mockito.mock(MicroserviceInstance.class);
Assert.assertEquals(null, oClient.registerMicroserviceInstance(microInstance));
Assert.assertEquals("a", new ClientException("a").getMessage());
}
Aggregations