use of org.apache.servicecomb.core.Invocation in project incubator-skywalking by apache.
the class TransportClientHandlerInterceptor method beforeMethod.
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
Invocation invocation = (Invocation) allArguments[0];
if (!checkRegisterStatus(invocation)) {
return;
}
URI uri = new URI(invocation.getEndpoint().toString());
String peer = uri.getHost() + ":" + uri.getPort();
String operationName = invocation.getMicroserviceQualifiedName();
final ContextCarrier contextCarrier = new ContextCarrier();
AbstractSpan span = ContextManager.createExitSpan(operationName, contextCarrier, peer);
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
invocation.getContext().put(next.getHeadKey(), next.getHeadValue());
}
String url = invocation.getOperationMeta().getOperationPath();
Tags.URL.set(span, url);
span.setComponent(ComponentsDefine.SERVICECOMB);
SpanLayer.asRPCFramework(span);
}
use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestVertxHttpMethod method testHandleResponse.
@Test
public void testHandleResponse() {
boolean status = false;
try {
Invocation invocation = mock(Invocation.class);
AsyncResponse asyncResp = mock(AsyncResponse.class);
HttpClientResponse httpResponse = mock(HttpClientResponse.class);
OperationMeta operationMeta = mock(OperationMeta.class);
RestOperationMeta swaggerRestOperation = mock(RestOperationMeta.class);
Endpoint endpoint = mock(Endpoint.class);
when(invocation.getOperationMeta()).thenReturn(operationMeta);
URLPathBuilder urlPathBuilder = mock(URLPathBuilder.class);
when(swaggerRestOperation.getPathBuilder()).thenReturn(urlPathBuilder);
operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerRestOperation);
when(invocation.getEndpoint()).thenReturn(endpoint);
String contentType = httpResponse.getHeader("Content-Type");
ProduceProcessor produceProcessor = mock(ProduceProcessor.class);
when(swaggerRestOperation.findProduceProcessor(contentType)).thenReturn(produceProcessor);
this.handleResponse(invocation, httpResponse, asyncResp);
} catch (Exception ex) {
status = true;
}
Assert.assertFalse(status);
}
use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestVertxHttpMethod method testCreateRequest.
@Test
public void testCreateRequest() {
HttpClient client = mock(HttpClient.class);
Invocation invocation = mock(Invocation.class);
OperationMeta operationMeta = mock(OperationMeta.class);
Endpoint endpoint = mock(Endpoint.class);
URIEndpointObject address = mock(URIEndpointObject.class);
when(invocation.getEndpoint()).thenReturn(endpoint);
when(endpoint.getAddress()).thenReturn(address);
when(address.isSslEnabled()).thenReturn(false);
when(invocation.getOperationMeta()).thenReturn(operationMeta);
RestOperationMeta swaggerRestOperation = mock(RestOperationMeta.class);
when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerRestOperation);
IpPort ipPort = mock(IpPort.class);
when(ipPort.getPort()).thenReturn(10);
when(ipPort.getHostOrIp()).thenReturn("ever");
AsyncResponse asyncResp = mock(AsyncResponse.class);
List<HttpMethod> methods = new ArrayList<>(Arrays.asList(HttpMethod.GET, HttpMethod.PUT, HttpMethod.POST, HttpMethod.DELETE, HttpMethod.PATCH));
for (HttpMethod method : methods) {
when(swaggerRestOperation.getHttpMethod()).thenReturn(method.toString());
HttpClientRequest obj = VertxHttpMethod.INSTANCE.createRequest(client, invocation, ipPort, "good", asyncResp);
Assert.assertNull(obj);
}
}
use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestVertxHttpMethod method testSetCseContext.
@Test
public void testSetCseContext() {
boolean status = false;
try {
Invocation invocation = mock(Invocation.class);
HttpClientResponse httpResponse = mock(HttpClientResponse.class);
OperationMeta operationMeta = mock(OperationMeta.class);
RestOperationMeta swaggerRestOperation = mock(RestOperationMeta.class);
HttpClientRequest request = mock(HttpClientRequest.class);
Endpoint endpoint = mock(Endpoint.class);
when(invocation.getOperationMeta()).thenReturn(operationMeta);
URLPathBuilder urlPathBuilder = mock(URLPathBuilder.class);
when(swaggerRestOperation.getPathBuilder()).thenReturn(urlPathBuilder);
operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerRestOperation);
when(invocation.getEndpoint()).thenReturn(endpoint);
String contentType = httpResponse.getHeader("Content-Type");
ProduceProcessor produceProcessor = mock(ProduceProcessor.class);
when(swaggerRestOperation.findProduceProcessor(contentType)).thenReturn(produceProcessor);
this.setCseContext(invocation, request);
} catch (Exception ex) {
status = true;
}
Assert.assertFalse(status);
}
use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestVertxHttpMethod method testDoMethod.
@Test
public void testDoMethod(@Mocked HttpClient httpClient, @Injectable URIEndpointObject address) throws Exception {
Context context = new MockUp<Context>() {
@Mock
public void runOnContext(Handler<Void> action) {
action.handle(null);
}
}.getMockInstance();
HttpClientWithContext httpClientWithContext = new HttpClientWithContext(httpClient, context);
Invocation invocation = mock(Invocation.class);
AsyncResponse asyncResp = mock(AsyncResponse.class);
OperationMeta operationMeta = mock(OperationMeta.class);
RestOperationMeta swaggerRestOperation = mock(RestOperationMeta.class);
Endpoint endpoint = mock(Endpoint.class);
when(invocation.getOperationMeta()).thenReturn(operationMeta);
URLPathBuilder urlPathBuilder = mock(URLPathBuilder.class);
when(swaggerRestOperation.getPathBuilder()).thenReturn(urlPathBuilder);
operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerRestOperation);
when(invocation.getEndpoint()).thenReturn(endpoint);
when(endpoint.getAddress()).thenReturn(address);
when(request.exceptionHandler(Mockito.any())).then(answer -> null);
Map<String, Object> map = new HashMap<>();
when(invocation.getHandlerContext()).then(answer -> map);
;
this.doMethod(httpClientWithContext, invocation, asyncResp);
Assert.assertTrue(true);
}
Aggregations