use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.
the class TestOperationProtobuf method testOperationProtobuf.
@Test
public void testOperationProtobuf() throws Exception {
UnitTestMeta meta = new UnitTestMeta();
SchemaMeta schemaMeta = meta.getOrCreateSchemaMeta(Impl.class);
OperationMeta operationMeta = schemaMeta.findOperation("test");
OperationProtobuf operationProtobuf = ProtobufManager.getOrCreateOperation(operationMeta);
Assert.assertEquals(operationMeta, operationProtobuf.getOperationMeta());
Assert.assertEquals(ArgsNotWrapSchema.class, operationProtobuf.getRequestSchema().getClass());
Assert.assertEquals(NormalWrapSchema.class, operationProtobuf.getResponseSchema().getClass());
WrapSchema responseSchema = operationProtobuf.findResponseSchema(200);
Assert.assertEquals(operationProtobuf.getResponseSchema(), responseSchema);
responseSchema = operationProtobuf.findResponseSchema(300);
Assert.assertNotNull(responseSchema);
Assert.assertNotEquals(operationProtobuf.getResponseSchema(), responseSchema);
}
use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.
the class AbstractRestServer method handleRequest.
protected void handleRequest(RestServerRequestInternal restRequest, HTTP_RESPONSE httpResponse) {
try {
RestOperationMeta restOperation = findRestOperation(restRequest);
OperationMeta operationMeta = restOperation.getOperationMeta();
operationMeta.getExecutor().execute(() -> {
try {
runOnExecutor(restRequest, restOperation, httpResponse);
} catch (Exception e) {
LOGGER.error("rest server onRequest error", e);
sendFailResponse(restRequest, httpResponse, e);
}
});
} catch (Exception e) {
LOGGER.error("rest server onRequest error", e);
sendFailResponse(restRequest, httpResponse, e);
}
}
use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.
the class MockUtil method mockRequestMeta.
public void mockRequestMeta() {
new MockUp<RequestMeta>() {
@Mock
public OperationMeta getOperationMeta() throws Exception {
OperationMeta om = new OperationMeta();
om.init(new SchemaMeta(null, new MicroserviceMeta("test"), null), this.getClass().getMethods()[0], "path", "get", null);
return om;
}
};
}
use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.
the class TestHttpRequestParamCreator method testCreateMockParam.
@Test
public void testCreateMockParam() throws Exception {
ProducerHttpRequestArgMapper lHttpRequestParamCreator = new ProducerHttpRequestArgMapper(0);
Invocation invocation = Mockito.mock(Invocation.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
RestOperationMeta swaggerOperation = Mockito.mock(RestOperationMeta.class);
Mockito.when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerOperation);
HttpServletRequest lHttpServletRequest = (HttpServletRequest) lHttpRequestParamCreator.createContextArg(invocation);
Assert.assertNull(lHttpServletRequest.getMethod());
}
use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.
the class RestEngineSchemaListener method onSchemaLoaded.
@Override
public void onSchemaLoaded(SchemaMeta... schemaMetas) {
// 此时相应的ServicePathManager可能正在被使用,为避免太高的复杂度,使用copy on write逻辑
Map<String, ServicePathManager> mgrMap = new HashMap<>();
for (SchemaMeta schemaMeta : schemaMetas) {
MicroserviceMeta microserviceMeta = schemaMeta.getMicroserviceMeta();
ServicePathManager mgr = findPathManager(mgrMap, microserviceMeta);
if (mgr.isSchemaExists(schemaMeta.getSchemaId())) {
LOGGER.info("on schema loaded, exists schema. {}:{}", schemaMeta.getMicroserviceName(), schemaMeta.getSchemaId());
continue;
}
LOGGER.info("on schema loaded, new schema. {}:{}", schemaMeta.getMicroserviceName(), schemaMeta.getSchemaId());
mgr.addSchema(schemaMeta.getSchemaId());
for (OperationMeta operationMeta : schemaMeta.getOperations()) {
RestOperationMeta restOperationMeta = new RestOperationMeta();
restOperationMeta.init(operationMeta);
operationMeta.putExtData(RestConst.SWAGGER_REST_OPERATION, restOperationMeta);
mgr.addResource(restOperationMeta);
}
}
for (ServicePathManager mgr : mgrMap.values()) {
// 对具有动态path operation进行排序
mgr.sortPath();
mgr.printService();
mgr.saveToMicroserviceMeta();
}
}
Aggregations