use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.
the class TestServiceRegistryClientImpl method testPrivateMethodCreateHttpClientOptions.
@Test
public void testPrivateMethodCreateHttpClientOptions() {
MicroserviceFactory microserviceFactory = new MicroserviceFactory();
Microservice microservice = microserviceFactory.create("app", "ms");
oClient.registerMicroservice(microservice);
oClient.registerMicroserviceInstance(microservice.getInstance());
new MockUp<ServiceRegistryConfig>() {
@Mock
public HttpVersion getHttpVersion() {
return HttpVersion.HTTP_2;
}
@Mock
public boolean isSsl() {
return true;
}
};
try {
oClient.init();
HttpClientOptions httpClientOptions = Deencapsulation.invoke(oClient, "createHttpClientOptions");
Assert.assertNotNull(httpClientOptions);
Assert.assertEquals(80, httpClientOptions.getDefaultPort());
} catch (Exception e) {
Assert.assertNotNull(e);
}
}
use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.
the class TestPropertiesLoader method testMicroservicePropertiesLoader.
@Test
public void testMicroservicePropertiesLoader() throws Exception {
Microservice microservice = ServiceRegistryFactory.createLocal().getMicroservice();
Map<String, String> expectedMap = new HashMap<>();
expectedMap.put("key1", "value1");
expectedMap.put("key2", "value2");
expectedMap.put("ek0", "ev0");
Assert.assertEquals(expectedMap, microservice.getProperties());
}
use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.
the class TestPropertiesLoader method testEmptyExtendedClass.
@Test
public void testEmptyExtendedClass() {
Microservice microservice = microserviceFactory.create("default", "emptyExtendedClass");
Assert.assertEquals(0, microservice.getProperties().size());
}
use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.
the class TestLocalServiceRegistry method testUpdateProperties.
@Test
public void testUpdateProperties() {
ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
serviceRegistry.init();
serviceRegistry.run();
Microservice microservice = serviceRegistry.getMicroservice();
Map<String, String> properties = new HashMap<>();
properties.put("k", "v");
try {
serviceRegistry.getServiceRegistryClient().updateInstanceProperties(microservice.getServiceId(), "notExist", properties);
Assert.fail("must throw exception");
} catch (IllegalArgumentException e) {
Assert.assertEquals("Invalid argument. microserviceId=" + microservice.getServiceId() + ", microserviceInstanceId=notExist.", e.getMessage());
}
serviceRegistry.updateMicroserviceProperties(properties);
Assert.assertEquals(properties, microservice.getProperties());
serviceRegistry.updateInstanceProperties(properties);
Assert.assertEquals(properties, microservice.getInstance().getProperties());
properties.put("k1", "v1");
serviceRegistry.updateMicroserviceProperties(properties);
Assert.assertEquals(properties, microservice.getProperties());
serviceRegistry.updateInstanceProperties(properties);
Assert.assertEquals(properties, microservice.getInstance().getProperties());
}
use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.
the class TestAbstractRegisterTask method testHeartbeatOtherFailed.
@Test
public void testHeartbeatOtherFailed(@Mocked ServiceRegistryClient srClient) {
MicroserviceRegisterTask registerTask = new MicroserviceRegisterTask(eventBus, srClient, microservice);
ReflectUtils.setField(registerTask, "registered", true);
Microservice otherMicroservice = new Microservice();
otherMicroservice.setAppId(microservice.getAppId());
otherMicroservice.setServiceName("ms1");
MicroserviceInstanceHeartbeatTask heartbeatTask = new MicroserviceInstanceHeartbeatTask(eventBus, srClient, otherMicroservice);
ReflectUtils.setField(heartbeatTask, "heartbeatResult", HeartbeatResult.INSTANCE_NOT_REGISTERED);
Assert.assertEquals(true, registerTask.isRegistered());
eventBus.post(heartbeatTask);
Assert.assertEquals(true, registerTask.isRegistered());
}
Aggregations