use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.
the class TestGrpcCodec method testDecodeResponse.
@Test
public void testDecodeResponse() {
boolean status = false;
try {
RoutingContext routingContext = Mockito.mock(RoutingContext.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
WrapSchema schema = ProtobufSchemaUtils.getOrCreateSchema(int.class);
Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(schema);
Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
Buffer bodyBuffer = Mockito.mock(Buffer.class);
Mockito.when(routingContext.getBody()).thenReturn(bodyBuffer);
HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
Mockito.when(routingContext.request()).thenReturn(request);
Mockito.when(request.getHeader(Const.CSE_CONTEXT)).thenReturn("{\"name\":\"test\"}");
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(operationProtobuf.getResponseSchema()).thenReturn(Mockito.mock(WrapSchema.class));
HttpClientResponse httpResponse = Mockito.mock(HttpClientResponse.class);
Buffer buffer = Mockito.mock(Buffer.class);
GrpcCodec.decodeResponse(invocation, operationProtobuf, httpResponse, buffer);
} catch (Exception e) {
status = true;
}
Assert.assertFalse(status);
}
use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.
the class TestGrpcCodec method testDecodeRequest.
@Test
public void testDecodeRequest() {
boolean status = false;
try {
RoutingContext routingContext = Mockito.mock(RoutingContext.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
WrapSchema schema = ProtobufSchemaUtils.getOrCreateSchema(int.class);
Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(schema);
Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
Buffer bodyBuffer = Mockito.mock(Buffer.class);
Mockito.when(routingContext.getBody()).thenReturn(bodyBuffer);
HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
Mockito.when(routingContext.request()).thenReturn(request);
SchemaMeta schemaMeta = Mockito.mock(SchemaMeta.class);
Mockito.when(operationMeta.getSchemaMeta()).thenReturn(schemaMeta);
Mockito.when(request.getHeader(Const.CSE_CONTEXT)).thenReturn("{\"name\":\"test\"}");
GrpcCodec.setGrpcTransport(new GrpcTransport());
GrpcCodec.decodeRequest(routingContext, operationMeta);
} catch (Exception e) {
status = true;
}
Assert.assertFalse(status);
}
use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.
the class TestGrpcTransport method testSend.
@Test
public void testSend() {
boolean status = false;
Invocation invocation = Mockito.mock(Invocation.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
Endpoint lEndpoint = Mockito.mock(Endpoint.class);
Mockito.when(invocation.getEndpoint()).thenReturn(lEndpoint);
WrapSchema lWrapSchema = Mockito.mock(WrapSchema.class);
Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(lWrapSchema);
IpPort ipPort = Mockito.mock(IpPort.class);
Mockito.when(lEndpoint.getAddress()).thenReturn(ipPort);
Mockito.when(ipPort.getHostOrIp()).thenReturn("127.0.0.1");
Mockito.when(ipPort.getPort()).thenReturn(80);
new MockUp<ClientPoolManager<HttpClientWithContext>>() {
@Mock
public HttpClientWithContext findThreadBindClientPool() {
return Mockito.mock(HttpClientWithContext.class);
}
};
try {
transport.send(invocation, asyncResp);
} catch (Exception e) {
status = true;
}
Assert.assertFalse(status);
}
use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.
the class VertxHttpMethod method doMethod.
public void doMethod(HttpClientWithContext httpClientWithContext, Invocation invocation, AsyncResponse asyncResp) throws Exception {
OperationMeta operationMeta = invocation.getOperationMeta();
RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
String path = this.createRequestPath(invocation, swaggerRestOperation);
IpPort ipPort = (IpPort) invocation.getEndpoint().getAddress();
HttpClientRequest clientRequest = this.createRequest(httpClientWithContext.getHttpClient(), invocation, ipPort, path, swaggerRestOperation, asyncResp);
RestClientRequestImpl restClientRequest = new RestClientRequestImpl(clientRequest);
RestCodec.argsToRest(invocation.getArgs(), swaggerRestOperation, restClientRequest);
clientRequest.exceptionHandler(e -> {
LOGGER.error(e.toString());
asyncResp.fail(invocation.getInvocationType(), e);
});
// 从业务线程转移到网络线程中去发送
httpClientWithContext.runOnContext(httpClient -> {
this.setCseContext(invocation, clientRequest);
clientRequest.setTimeout(AbstractTransport.getRequestTimeout());
try {
restClientRequest.end();
} catch (Exception e) {
LOGGER.error("send http reqeust failed,", e);
asyncResp.fail(invocation.getInvocationType(), e);
}
});
}
use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.
the class TestHighwayTransport method commonHighwayMock.
private void commonHighwayMock(Invocation invocation) {
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
Endpoint lEndpoint = Mockito.mock(Endpoint.class);
Mockito.when(invocation.getEndpoint()).thenReturn(lEndpoint);
WrapSchema lWrapSchema = Mockito.mock(WrapSchema.class);
Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(lWrapSchema);
URIEndpointObject ep = Mockito.mock(URIEndpointObject.class);
Mockito.when(lEndpoint.getAddress()).thenReturn(ep);
Mockito.when(ep.getHostOrIp()).thenReturn("127.0.0.1");
Mockito.when(ep.getPort()).thenReturn(80);
}
Aggregations