use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestMicroserviceRegisterTask method testLocalSchemaAndServiceCenterSchemaNoDiff.
@Test
public void testLocalSchemaAndServiceCenterSchemaNoDiff(@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" + " 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.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" + " properties:\n" + " name:\n" + " type: \"string\"\n" + " age:\n" + " type: \"integer\"\n" + " format: \"int32\"\n" + " maximum: 20\n" + " type: \"object\"\n" + " required:\n" + " - \"name\"\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;
}
Assert.assertEquals(false, isIlleagalException);
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestMicroserviceRegisterTask method testFirstRegisterForProd.
/**
* There is microservice information but no schema in service center.
*/
@Test
public void testFirstRegisterForProd(@Mocked ServiceRegistryClient srClient) {
Microservice otherMicroservice = new Microservice();
otherMicroservice.setAppId(microservice.getAppId());
otherMicroservice.setServiceName("ms1");
otherMicroservice.addSchema("s1", null);
List<GetSchemaResponse> list = new ArrayList<>();
GetSchemaResponse resp = new GetSchemaResponse();
resp.setSchemaId("s1");
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();
Assert.assertEquals(true, registerTask.isRegistered());
Assert.assertEquals(true, registerTask.isSchemaIdSetMatch());
Assert.assertEquals("serviceId", microservice.getServiceId());
Assert.assertEquals(1, taskList.size());
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestMicroserviceRegisterTask method testAlreadyRegisteredGetSchemaIdSetFailed.
@Test
public void testAlreadyRegisteredGetSchemaIdSetFailed(@Mocked ServiceRegistryClient srClient) {
Microservice otherMicroservice = new Microservice();
otherMicroservice.setAppId(microservice.getAppId());
otherMicroservice.setServiceName("ms1");
otherMicroservice.addSchema("s1", "");
new Expectations() {
{
srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
result = "serviceId";
srClient.getMicroservice(anyString);
result = null;
}
};
MicroserviceRegisterTask registerTask = new MicroserviceRegisterTask(eventBus, srClient, microservice);
registerTask.run();
Assert.assertEquals(false, registerTask.isRegistered());
Assert.assertEquals(false, registerTask.isSchemaIdSetMatch());
Assert.assertEquals("serviceId", microservice.getServiceId());
Assert.assertEquals(1, taskList.size());
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestMicroserviceRegisterTask method testLocalSchemaAndServiceCenterSchemaIgnoreDiff.
@Test
public void testLocalSchemaAndServiceCenterSchemaIgnoreDiff(@Mocked ServiceRegistryClient srClient, @Mocked ServiceRegistryConfig serviceRegistryConfig) {
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() {
{
serviceRegistryConfig.isIgnoreSwaggerDifference();
result = true;
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;
}
Assert.assertEquals(false, isIlleagalException);
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class RefreshableMicroserviceCacheTest method setUp.
@Before
public void setUp() throws Exception {
srClient = new MockUp<ServiceRegistryClient>() {
@Mock
MicroserviceInstances findServiceInstances(String consumerId, String appId, String serviceName, String versionRule, String revision) {
return findServiceInstancesOprHolder.value.apply(new Object[] { consumerId, appId, serviceName, versionRule, revision });
}
}.getMockInstance();
consumerService = new Microservice();
consumerService.setServiceId("consumerId");
microserviceCache = new RefreshableMicroserviceCache(consumerService, MicroserviceCacheKey.builder().env("env").appId("app").serviceName("svc").build(), srClient, false);
findServiceInstancesOprHolder.value = params -> {
MicroserviceInstances microserviceInstances = new MicroserviceInstances();
microserviceInstances.setNeedRefresh(true);
microserviceInstances.setRevision("rev0");
microserviceInstances.setMicroserviceNotExist(false);
FindInstancesResponse instancesResponse = new FindInstancesResponse();
instancesResponse.setInstances(pulledInstances);
microserviceInstances.setInstancesResponse(instancesResponse);
return microserviceInstances;
};
}
Aggregations