use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.
the class TestMicroserviceVersionMetaFactory method create.
@Test
public void create(@Mocked ConsumerSchemaFactory consumerSchemaFactory, @Mocked SchemaListenerManager schemaListenerManager) {
String microserviceName = "app:ms";
String microserviceId = "id";
Microservice microservice = new Microservice();
microservice.setVersion("1.0.0");
new Expectations(RegistryUtils.class) {
{
RegistryUtils.getMicroservice(microserviceId);
result = microservice;
}
};
CseContext.getInstance().setConsumerSchemaFactory(consumerSchemaFactory);
CseContext.getInstance().setSchemaListenerManager(schemaListenerManager);
MicroserviceVersionMetaFactory factory = new MicroserviceVersionMetaFactory();
MicroserviceVersion microserviceVersion = factory.create(microserviceName, microserviceId);
Assert.assertThat(microserviceVersion, Matchers.instanceOf(MicroserviceVersionMeta.class));
}
use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.
the class TestPropertiesLoader method testInstancePropertiesLoader.
@Test
public void testInstancePropertiesLoader() {
Microservice microservice = ServiceRegistryFactory.createLocal().getMicroservice();
MicroserviceInstance instance = microservice.getInstance();
Map<String, String> expectedMap = new HashMap<>();
expectedMap.put("key0", "value0");
expectedMap.put("ek0", "ev0");
Assert.assertEquals(expectedMap, instance.getProperties());
}
use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.
the class MicroserviceVersionTestUtils method createMicroserviceVersion.
public static MicroserviceVersion createMicroserviceVersion(String microserviceId, String version) {
Microservice microservice = new Microservice();
microservice.setServiceId(microserviceId);
microservice.setVersion(version);
new Expectations(RegistryUtils.class) {
{
RegistryUtils.getMicroservice(microserviceId);
result = microservice;
}
};
return new MicroserviceVersion(microserviceId);
}
use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.
the class TestLocalServiceRegistry method testSchema.
@Test
public void testSchema() {
ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
Microservice microservice = serviceRegistry.getMicroservice();
microservice.addSchema("s1", "s1-content");
serviceRegistry.init();
serviceRegistry.run();
try {
serviceRegistry.getServiceRegistryClient().isSchemaExist("notExist", "s1");
Assert.fail("must throw exception");
} catch (IllegalArgumentException e) {
Assert.assertEquals("Invalid serviceId, serviceId=notExist", e.getMessage());
}
try {
serviceRegistry.getServiceRegistryClient().getSchema("notExist", "s1");
Assert.fail("must throw exception");
} catch (IllegalArgumentException e) {
Assert.assertEquals("Invalid serviceId, serviceId=notExist", e.getMessage());
}
Assert.assertEquals(true, serviceRegistry.getServiceRegistryClient().isSchemaExist(microservice.getServiceId(), "s1"));
String content = serviceRegistry.getServiceRegistryClient().getSchema(microservice.getServiceId(), "s1");
Assert.assertEquals("s1-content", content);
}
use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.
the class TestMicroserviceInstanceHeartbeatTask method testOtherMicroservice.
@Test
public void testOtherMicroservice(@Mocked ServiceRegistryClient srClient, @Mocked ServiceRegistryConfig serviceRegistryConfig, @Mocked MicroserviceWatchTask watchTask) {
Microservice otherMicroservice = new Microservice();
otherMicroservice.setServiceName("ms1");
new Expectations() {
{
watchTask.getMicroservice();
result = otherMicroservice;
}
};
MicroserviceInstanceHeartbeatTask heartbeatTask = new MicroserviceInstanceHeartbeatTask(eventBus, srClient, microservice);
watchTask.taskStatus = TaskStatus.READY;
eventBus.post(watchTask);
heartbeatTask.run();
Assert.assertNull(heartbeatTask.getHeartbeatResult());
Assert.assertEquals(false, heartbeatTask.isNeedRegisterInstance());
Assert.assertEquals(0, heartbeatTaskList.size());
}
Aggregations