Search in sources :

Example 1 with Invocation

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

the class TestVertxRestTransport method testSendException.

@Test
public void testSendException() {
    boolean validAssert;
    Invocation invocation = Mockito.mock(Invocation.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    URIEndpointObject endpoint = Mockito.mock(URIEndpointObject.class);
    Endpoint end = Mockito.mock(Endpoint.class);
    Mockito.when(invocation.getEndpoint()).thenReturn(end);
    Mockito.when(invocation.getEndpoint().getAddress()).thenReturn(endpoint);
    try {
        validAssert = true;
        instance.send(invocation, asyncResp);
    } catch (Exception e) {
        validAssert = false;
    }
    Assert.assertFalse(validAssert);
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) Endpoint(org.apache.servicecomb.core.Endpoint) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) AsyncResponse(org.apache.servicecomb.swagger.invocation.AsyncResponse) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with Invocation

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

the class TraceIdItemTest method testGetFormattedElement.

@Test
public void testGetFormattedElement() {
    AccessLogParam<RoutingContext> param = new AccessLogParam<>();
    RoutingContext routingContext = Mockito.mock(RoutingContext.class);
    Map<String, Object> data = new HashMap<>();
    RestProducerInvocation restProducerInvocation = new RestProducerInvocation();
    Invocation invocation = Mockito.mock(Invocation.class);
    String traceIdTest = "traceIdTest";
    Mockito.when(invocation.getContext(Const.TRACE_ID_NAME)).thenReturn(traceIdTest);
    Deencapsulation.setField(restProducerInvocation, "invocation", invocation);
    Mockito.when(routingContext.data()).thenReturn(data);
    data.put("servicecomb-rest-producer-invocation", restProducerInvocation);
    param.setContextData(routingContext);
    String result = ELEMENT.getFormattedItem(param);
    Assert.assertThat(result, is(traceIdTest));
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) RestProducerInvocation(org.apache.servicecomb.common.rest.RestProducerInvocation) Invocation(org.apache.servicecomb.core.Invocation) HashMap(java.util.HashMap) AccessLogParam(org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam) RestProducerInvocation(org.apache.servicecomb.common.rest.RestProducerInvocation) Test(org.junit.Test)

Example 3 with Invocation

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

the class TraceIdItemTest method testGetFormattedElementOnTraceIdNotFound.

@Test
public void testGetFormattedElementOnTraceIdNotFound() {
    AccessLogParam<RoutingContext> param = new AccessLogParam<>();
    RoutingContext routingContext = Mockito.mock(RoutingContext.class);
    Map<String, Object> data = new HashMap<>();
    RestProducerInvocation restProducerInvocation = new RestProducerInvocation();
    Invocation invocation = Mockito.mock(Invocation.class);
    Mockito.when(invocation.getContext(Const.TRACE_ID_NAME)).thenReturn("");
    Deencapsulation.setField(restProducerInvocation, "invocation", invocation);
    Mockito.when(routingContext.data()).thenReturn(data);
    data.put("servicecomb-rest-producer-invocation", restProducerInvocation);
    param.setContextData(routingContext);
    String result = ELEMENT.getFormattedItem(param);
    Assert.assertThat(result, is("-"));
    Mockito.when(invocation.getContext(Const.TRACE_ID_NAME)).thenReturn(null);
    result = ELEMENT.getFormattedItem(param);
    Assert.assertThat(result, is("-"));
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) RestProducerInvocation(org.apache.servicecomb.common.rest.RestProducerInvocation) Invocation(org.apache.servicecomb.core.Invocation) HashMap(java.util.HashMap) AccessLogParam(org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam) RestProducerInvocation(org.apache.servicecomb.common.rest.RestProducerInvocation) Test(org.junit.Test)

Example 4 with Invocation

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

the class TestProducerSchemaFactory method testGetOrCreateProducer.

@Test
public void testGetOrCreateProducer() throws Exception {
    OperationMeta operationMeta = schemaMeta.ensureFindOperation("add");
    Assert.assertEquals("add", operationMeta.getOperationId());
    SwaggerProducerOperation producerOperation = operationMeta.getExtData(Const.PRODUCER_OPERATION);
    Object addBody = Class.forName("cse.gen.app.ms.schema.addBody").newInstance();
    ReflectUtils.setField(addBody, "x", 1);
    ReflectUtils.setField(addBody, "y", 2);
    Invocation invocation = new Invocation((Endpoint) null, operationMeta, new Object[] { addBody }) {

        @Override
        public String getInvocationQualifiedName() {
            return "";
        }
    };
    Holder<Response> holder = new Holder<>();
    producerOperation.invoke(invocation, resp -> {
        holder.value = resp;
    });
    Assert.assertEquals(3, (int) holder.value.getResult());
    invocation.setSwaggerArguments(new Object[] { 1, 2 });
    producerOperation.invoke(invocation, resp -> {
        holder.value = resp;
    });
    Assert.assertEquals(true, holder.value.isFailed());
    InvocationException exception = (InvocationException) holder.value.getResult();
    CommonExceptionData data = (CommonExceptionData) exception.getErrorData();
    Assert.assertEquals("Cse Internal Server Error", data.getMessage());
}
Also used : Response(org.apache.servicecomb.swagger.invocation.Response) Invocation(org.apache.servicecomb.core.Invocation) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) Holder(javax.xml.ws.Holder) SwaggerProducerOperation(org.apache.servicecomb.swagger.engine.SwaggerProducerOperation) CommonExceptionData(org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 5 with Invocation

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

the class TestShutdownHookHandler method testShutdownHookHandlerReject.

@Test
public void testShutdownHookHandlerReject() throws Exception {
    Deencapsulation.setField(ShutdownHookHandler.INSTANCE, "shuttingDown", true);
    Holder<InvocationType> typeHolder = new Holder<>(InvocationType.PRODUCER);
    Invocation invocation = new MockUp<Invocation>() {

        @Mock
        public InvocationType getInvocationType() {
            return typeHolder.value;
        }
    }.getMockInstance();
    ShutdownHookHandler handler = ShutdownHookHandler.INSTANCE;
    handler.handle(invocation, asyncResp -> {
        InvocationException e = asyncResp.getResult();
        Assert.assertEquals(((CommonExceptionData) e.getErrorData()).getMessage(), "shutting down in progress");
        Assert.assertEquals(e.getStatusCode(), 590);
    });
    typeHolder.value = InvocationType.CONSUMER;
    handler.handle(invocation, asyncResp -> {
        InvocationException e = asyncResp.getResult();
        Assert.assertEquals(((CommonExceptionData) e.getErrorData()).getMessage(), "shutting down in progress");
        Assert.assertEquals(e.getStatusCode(), 490);
    });
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) Holder(javax.xml.ws.Holder) InvocationType(org.apache.servicecomb.swagger.invocation.InvocationType) Mock(mockit.Mock) Test(org.junit.Test)

Aggregations

Invocation (org.apache.servicecomb.core.Invocation)204 Test (org.junit.Test)125 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)52 ArrayList (java.util.ArrayList)39 HashMap (java.util.HashMap)37 Response (org.apache.servicecomb.swagger.invocation.Response)37 Before (org.junit.Before)29 MockUp (mockit.MockUp)26 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)23 Expectations (mockit.Expectations)20 InvocationFinishEvent (org.apache.servicecomb.core.event.InvocationFinishEvent)20 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)19 HystrixCommandProperties (com.netflix.hystrix.HystrixCommandProperties)18 Transport (org.apache.servicecomb.core.Transport)18 RoutingContext (io.vertx.ext.web.RoutingContext)17 Map (java.util.Map)17 ServerAccessLogEvent (org.apache.servicecomb.core.event.ServerAccessLogEvent)17 List (java.util.List)16 Endpoint (org.apache.servicecomb.core.Endpoint)16 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)15