use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
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());
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestMicroserviceRegisterTask method testReRegisteredSetForProd.
/**
* There is schema in service center which is different from local schema.
*/
@Test(expected = IllegalStateException.class)
public void testReRegisteredSetForProd(@Mocked ServiceRegistryClient srClient) {
Microservice otherMicroservice = new Microservice();
otherMicroservice.setAppId(microservice.getAppId());
otherMicroservice.setServiceName("ms1");
otherMicroservice.addSchema("s1", "");
List<GetSchemaResponse> list = new ArrayList<>();
GetSchemaResponse resp = new GetSchemaResponse();
resp.setSchemaId("s1");
resp.setSummary("c1188d709631a9038874f9efc6eb894f");
list.add(resp);
Holder<List<GetSchemaResponse>> onlineSchemasHolder = new Holder<>();
onlineSchemasHolder.setValue(list).setStatusCode(200);
new Expectations() {
{
srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
result = "serviceId";
srClient.getMicroservice(anyString);
result = otherMicroservice;
srClient.getSchemas(anyString);
result = onlineSchemasHolder;
}
};
microservice.addSchema("s1", "");
microservice.setEnvironment("prod");
MicroserviceRegisterTask registerTask = new MicroserviceRegisterTask(eventBus, srClient, microservice);
registerTask.run();
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestMicroserviceRegisterTask method testLocalSchemaAndServiceCenterSchemaDiff.
/**
* There is schema in service center which is different from local schema.
*/
@Test
public void testLocalSchemaAndServiceCenterSchemaDiff(@Mocked ServiceRegistryClient srClient) {
Microservice otherMicroservice = new Microservice();
otherMicroservice.setAppId(microservice.getAppId());
otherMicroservice.setServiceName("ms1");
otherMicroservice.addSchema("s1", "abcd");
List<GetSchemaResponse> list = new ArrayList<>();
GetSchemaResponse resp = new GetSchemaResponse();
resp.setSchemaId("s1");
resp.setSummary("c1188d709631a9038874f9efc6eb894f");
list.add(resp);
Holder<List<GetSchemaResponse>> onlineSchemasHolder = new Holder<>();
onlineSchemasHolder.setValue(list).setStatusCode(200);
new Expectations() {
{
srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
result = "serviceId";
srClient.getMicroservice(anyString);
result = otherMicroservice;
srClient.getSchemas(anyString);
result = onlineSchemasHolder;
srClient.getSchema(anyString, anyString);
result = "swagger: \"2.0\"\n" + "info:\n" + " version: \"1.0.0\"\n" + " title: \"swagger definition for org.apache.servicecomb.demo.jaxrs.server.RequestClientTimeOut\"\n" + " x-java-interface: \"cse.gen.jaxrstest.jaxrs.clientreqtimeout.RequestClientTimeOutIntf\"\n" + "basePath: \"/clientreqtimeout\"\n" + "consumes:\n" + "- \"application/json\"\n" + "produces:\n" + "- \"application/json\"\n" + "paths:\n" + " /sayhello:\n" + " post:\n" + " operationId: \"sayHello\"\n" + " parameters:\n" + " - in: \"body\"\n" + " name: \"student\"\n" + " required: false\n" + " schema:\n" + " $ref: \"#/definitions/Student\"\n" + " responses:\n" + " 200:\n" + " description: \"response of 200\"\n" + " schema:\n" + " $ref: \"#/definitions/Student\"\n" + "definitions:\n" + " Student:\n" + " type: \"object\"\n" + " required:\n" + " - \"name\"\n" + " properties:\n" + " name:\n" + " type: \"string\"\n" + " age:\n" + " type: \"integer\"\n" + " format: \"int32\"\n" + " maximum: 20\n" + " x-java-class: \"org.apache.servicecomb.demo.validator.Student\"";
}
};
microservice.addSchema("s1", "swagger: \"2.0\"\n" + "info:\n" + " version: \"1.0.0\"\n" + " title: \"swagger definition for org.apache.servicecomb.demo.jaxrs.server.RequestClientTimeOut\"\n" + " x-java-interface: \"cse.gen.jaxrstest.jaxrs.clientreqtimeout.RequestClientTimeOutIntf\"\n" + "basePath: \"/clientreqtimeout\"\n" + "consumes:\n" + "- \"application/json\"\n" + "produces:\n" + "- \"application/json\"\n" + "paths:\n" + " /sayhello:\n" + " post:\n" + " operationId: \"sayHello\"\n" + " parameters:\n" + " - in: \"body\"\n" + " name: \"student\"\n" + " required: false\n" + " schema:\n" + " $ref: \"#/definitions/Student\"\n" + " responses:\n" + " 200:\n" + " description: \"response of 200\"\n" + " schema:\n" + " type: \"string\"\n" + "definitions:\n" + " Student:\n" + " type: \"object\"\n" + " required:\n" + " - \"name\"\n" + " properties:\n" + " name:\n" + " type: \"string\"\n" + " age:\n" + " type: \"integer\"\n" + " format: \"int32\"\n" + " maximum: 20\n" + " x-java-class: \"org.apache.servicecomb.demo.validator.Student\"");
microservice.setEnvironment("prod");
MicroserviceRegisterTask registerTask = new MicroserviceRegisterTask(eventBus, srClient, microservice);
Boolean isIlleagalException = false;
try {
registerTask.run();
} catch (IllegalStateException exception) {
isIlleagalException = true;
List<LoggingEvent> events = collector.getEvents().stream().filter(e -> {
return MicroserviceRegisterTask.class.getName().equals(e.getLoggerName());
}).collect(Collectors.toList());
Assert.assertEquals("service center schema and local schema both are different:\n" + " service center schema:\n" + "[swagger: \"2.0\"\n" + "info:\n" + " version: \"1.0.0\"\n" + " title: \"swagger definition for org.apache.servicecomb.demo.jaxrs.server.RequestClientTimeOut\"\n" + " x-java-interface: \"cse.gen.jaxrstest.jaxrs.clientreqtimeout.RequestClientTimeOutIntf\"\n" + "basePath: \"/clientreqtimeout\"\n" + "consumes:\n" + "- \"application/json\"\n" + "produces:\n" + "- \"application/json\"\n" + "paths:\n" + " /sayhello:\n" + " post:\n" + " operationId: \"sayHello\"\n" + " parameters:\n" + " - in: \"body\"\n" + " name: \"student\"\n" + " required: false\n" + " schema:\n" + " $ref: \"#/definitions/Student\"\n" + " responses:\n" + " 200:\n" + " description: \"response of 200\"\n" + " schema:\n" + " $ref: \"#/definitions/Student\"\n" + "definitions:\n" + " Student:\n" + " type: \"object\"\n" + " required:\n" + " - \"name\"\n" + " properties:\n" + " name:\n" + " type: \"string\"\n" + " age:\n" + " type: \"integer\"\n" + " format: \"int32\"\n" + " maximum: 20\n" + " x-java-class: \"org.apache.servicecomb.demo.validator.Student\"\n" + " local schema:\n" + "[swagger: \"2.0\"\n" + "info:\n" + " version: \"1.0.0\"\n" + " title: \"swagger definition for org.apache.servicecomb.demo.jaxrs.server.RequestClientTimeOut\"\n" + " x-java-interface: \"cse.gen.jaxrstest.jaxrs.clientreqtimeout.RequestClientTimeOutIntf\"\n" + "basePath: \"/clientreqtimeout\"\n" + "consumes:\n" + "- \"application/json\"\n" + "produces:\n" + "- \"application/json\"\n" + "paths:\n" + " /sayhello:\n" + " post:\n" + " operationId: \"sayHello\"\n" + " parameters:\n" + " - in: \"body\"\n" + " name: \"student\"\n" + " required: false\n" + " schema:\n" + " $ref: \"#/definitions/Student\"\n" + " responses:\n" + " 200:\n" + " description: \"response of 200\"\n" + " schema:\n" + " type: \"string\"\n" + "definitions:\n" + " Student:\n" + " type: \"object\"\n" + " required:\n" + " - \"name\"\n" + " properties:\n" + " name:\n" + " type: \"string\"\n" + " age:\n" + " type: \"integer\"\n" + " format: \"int32\"\n" + " maximum: 20\n" + " x-java-class: \"org.apache.servicecomb.demo.validator.Student\"]", events.get(4).getMessage());
Assert.assertEquals("The difference in local schema:\n" + "[type: \"string\"\n" + "definitions:\n" + " Student:\n" + " type: \"object\"\n" + " required:\n" + " - \"name\"\n" + " properties:\n" + " name:\n" + " type: \"string\"\n" + " age:\n" + " type: \"integer\"\n" + " format: \"int32\"\n" + " maximum: 20\n" + " x-java-class: \"org.apache.servicecomb.demo.validator.Student\"]", events.get(5).getMessage());
}
Assert.assertEquals(true, isIlleagalException);
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestMicroserviceRegisterTask method testAlreadyRegisteredSchemaIdSetNotMatch.
@Test(expected = IllegalStateException.class)
public void testAlreadyRegisteredSchemaIdSetNotMatch(@Mocked ServiceRegistryClient srClient) {
Microservice otherMicroservice = new Microservice();
otherMicroservice.setAppId(microservice.getAppId());
otherMicroservice.setServiceName("ms1");
otherMicroservice.addSchema("s1", "");
Holder<List<GetSchemaResponse>> onlineSchemasHolder = new Holder<>();
onlineSchemasHolder.setStatusCode(200);
ArrayList<GetSchemaResponse> schemaResponseList = new ArrayList<>();
onlineSchemasHolder.setValue(schemaResponseList);
GetSchemaResponse schemaResponse = new GetSchemaResponse();
schemaResponseList.add(schemaResponse);
schemaResponse.setSchemaId("s1");
new Expectations() {
{
srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
result = "serviceId";
srClient.getMicroservice(anyString);
result = otherMicroservice;
srClient.getSchemas("serviceId");
result = onlineSchemasHolder;
}
};
MicroserviceRegisterTask registerTask = new MicroserviceRegisterTask(eventBus, srClient, microservice);
registerTask.run();
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestMicroserviceRegisterTask method testReRegisterForProductAndLocalSchemasAreLess.
/**
* env = production and there are schemas only existing in service center
*/
@Test(expected = IllegalStateException.class)
public void testReRegisterForProductAndLocalSchemasAreLess(@Mocked ServiceRegistryClient srClient) {
Microservice otherMicroservice = new Microservice();
otherMicroservice.setAppId(microservice.getAppId());
otherMicroservice.setServiceName("ms1");
otherMicroservice.addSchema("s1", null);
otherMicroservice.addSchema("s2", null);
List<GetSchemaResponse> list = new ArrayList<>();
GetSchemaResponse resp = new GetSchemaResponse();
resp.setSchemaId("s1");
list.add(resp);
resp = new GetSchemaResponse();
resp.setSchemaId("s2");
list.add(resp);
Holder<List<GetSchemaResponse>> onlineSchemasHolder = new Holder<>();
onlineSchemasHolder.setValue(list).setStatusCode(200);
new Expectations() {
{
srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
result = "serviceId";
srClient.getMicroservice(anyString);
result = otherMicroservice;
srClient.getSchemas(anyString);
result = onlineSchemasHolder;
srClient.getSchema("serviceId", "s1");
result = null;
srClient.registerSchema("serviceId", "s1", "s1Content");
result = true;
}
};
microservice.addSchema("s1", "s1Content");
microservice.setEnvironment("production");
MicroserviceRegisterTask registerTask = new MicroserviceRegisterTask(eventBus, srClient, microservice);
registerTask.run();
}
Aggregations