Search in sources :

Example 31 with Invocation

use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.

the class TestHighwayCodec method testDecodeRequest.

@Test
public void testDecodeRequest(@Mocked Endpoint endpoint) throws Exception {
    commonMock();
    Mockito.when(schemaMeta.getProviderHandlerChain()).thenReturn(Collections.emptyList());
    Object[] args = new Object[] {};
    Mockito.when(schema.readObject(bodyBuffer, null)).thenReturn(args);
    Invocation invocation = new Invocation(endpoint, operationMeta, null);
    HighwayCodec.decodeRequest(invocation, header, operationProtobuf, bodyBuffer, null);
    Assert.assertSame(args, invocation.getSwaggerArguments());
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) Test(org.junit.Test)

Example 32 with Invocation

use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.

the class TestHighwayTransport method testSendException.

@Test
public void testSendException() throws Exception {
    Invocation invocation = Mockito.mock(Invocation.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    commonHighwayMock(invocation);
    Holder<Boolean> sended = new Holder<>(false);
    new MockUp<HighwayClient>() {

        @Mock
        public void send(Invocation invocation, AsyncResponse asyncResp) throws Exception {
            sended.value = true;
        }
    };
    transport.send(invocation, asyncResp);
    Assert.assertTrue(sended.value);
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) Holder(javax.xml.ws.Holder) MockUp(mockit.MockUp) AsyncResponse(org.apache.servicecomb.swagger.invocation.AsyncResponse) Test(org.junit.Test)

Example 33 with Invocation

use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.

the class TestEdgeInvocation method createInvocation.

@Test
public void createInvocation(@Mocked MicroserviceVersionMeta microserviceVersionMeta, @Mocked MicroserviceVersionRule microserviceVersionRule, @Mocked RestOperationMeta restOperationMeta, @Mocked Microservice microservice) {
    edgeInvocation.latestMicroserviceVersionMeta = microserviceVersionMeta;
    edgeInvocation.microserviceVersionRule = microserviceVersionRule;
    Deencapsulation.setField(edgeInvocation, "restOperationMeta", restOperationMeta);
    new Expectations(RegistryUtils.class) {

        {
            RegistryUtils.getMicroservice();
            result = microservice;
        }
    };
    edgeInvocation.createInvocation();
    Invocation invocation = Deencapsulation.getField(edgeInvocation, "invocation");
    Assert.assertThat(invocation.getResponseExecutor(), Matchers.instanceOf(ReactiveResponseExecutor.class));
}
Also used : Expectations(mockit.Expectations) Invocation(org.apache.servicecomb.core.Invocation) ReactiveResponseExecutor(org.apache.servicecomb.core.provider.consumer.ReactiveResponseExecutor) HttpServerRequestWrapperForTest(io.vertx.ext.web.impl.HttpServerRequestWrapperForTest) Test(org.junit.Test)

Example 34 with Invocation

use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.

the class TestUrlWithServiceNameClientHttpRequestFactory method invoke_checkPath.

@Test
public void invoke_checkPath(@Mocked Invocation invocation, @Mocked RequestMeta requestMeta) {
    Map<String, String> handlerContext = new HashMap<>();
    UrlWithServiceNameClientHttpRequest request = new UrlWithServiceNameClientHttpRequest(uri, HttpMethod.GET) {

        @Override
        protected Response doInvoke(Invocation invocation) {
            return Response.ok(null);
        }
    };
    new Expectations(InvocationFactory.class) {

        {
            invocation.getHandlerContext();
            result = handlerContext;
            InvocationFactory.forConsumer((ReferenceConfig) any, (OperationMeta) any, (Object[]) any);
            result = invocation;
        }
    };
    Deencapsulation.setField(request, "requestMeta", requestMeta);
    Deencapsulation.setField(request, "path", request.findUriPath(uri));
    Deencapsulation.invoke(request, "invoke", new Object[] { new Object[] {} });
    Assert.assertEquals("/ms/v1/path?null", handlerContext.get(RestConst.REST_CLIENT_REQUEST_PATH));
}
Also used : Expectations(mockit.Expectations) Invocation(org.apache.servicecomb.core.Invocation) HashMap(java.util.HashMap) UrlWithServiceNameClientHttpRequest(org.apache.servicecomb.provider.springmvc.reference.UrlWithServiceNameClientHttpRequestFactory.UrlWithServiceNameClientHttpRequest) Test(org.junit.Test)

Example 35 with Invocation

use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.

the class CseClientHttpRequest method invoke.

private CseClientHttpResponse invoke(Object[] args) {
    Invocation invocation = InvocationFactory.forConsumer(requestMeta.getReferenceConfig(), requestMeta.getOperationMeta(), args);
    invocation.getHandlerContext().put(RestConst.REST_CLIENT_REQUEST_PATH, path + "?" + this.uri.getRawQuery());
    if (context != null) {
        invocation.addContext(context);
    }
    invocation.getHandlerContext().put(RestConst.CONSUMER_HEADER, httpHeaders);
    Response response = doInvoke(invocation);
    if (response.isSuccessed()) {
        return new CseClientHttpResponse(response);
    }
    throw ExceptionFactory.convertConsumerException((Throwable) response.getResult());
}
Also used : Response(org.apache.servicecomb.swagger.invocation.Response) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) Invocation(org.apache.servicecomb.core.Invocation)

Aggregations

Invocation (org.apache.servicecomb.core.Invocation)66 Test (org.junit.Test)50 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)23 Response (org.apache.servicecomb.swagger.invocation.Response)19 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)16 MockUp (mockit.MockUp)11 HystrixCommandProperties (com.netflix.hystrix.HystrixCommandProperties)9 ArrayList (java.util.ArrayList)9 Server (com.netflix.loadbalancer.Server)8 HashMap (java.util.HashMap)8 Holder (javax.xml.ws.Holder)8 Expectations (mockit.Expectations)7 Mock (mockit.Mock)7 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)5 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)5 Map (java.util.Map)4 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)4 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)4 Endpoint (org.apache.servicecomb.core.Endpoint)4 CseServer (org.apache.servicecomb.loadbalance.CseServer)4