Search in sources :

Example 6 with AsyncResponse

use of io.servicecomb.core.AsyncResponse in project java-chassis by ServiceComb.

the class TestVertxHttpMethod method testDoMethod.

@Test
public void testDoMethod(@Mocked HttpClient httpClient) 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 = Mockito.mock(Invocation.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
    RestOperationMeta swaggerRestOperation = Mockito.mock(RestOperationMeta.class);
    Endpoint endpoint = Mockito.mock(Endpoint.class);
    Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
    URLPathBuilder urlPathBuilder = Mockito.mock(URLPathBuilder.class);
    Mockito.when(swaggerRestOperation.getPathBuilder()).thenReturn(urlPathBuilder);
    operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
    Mockito.when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerRestOperation);
    Mockito.when(invocation.getEndpoint()).thenReturn(endpoint);
    Mockito.when(request.exceptionHandler(Mockito.any())).then(answer -> null);
    this.doMethod(httpClientWithContext, invocation, asyncResp);
    Assert.assertTrue(true);
}
Also used : HttpClientWithContext(io.servicecomb.foundation.vertx.client.http.HttpClientWithContext) Context(io.vertx.core.Context) Invocation(io.servicecomb.core.Invocation) Endpoint(io.servicecomb.core.Endpoint) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) HttpClientWithContext(io.servicecomb.foundation.vertx.client.http.HttpClientWithContext) URLPathBuilder(io.servicecomb.common.rest.definition.path.URLPathBuilder) OperationMeta(io.servicecomb.core.definition.OperationMeta) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) AsyncResponse(io.servicecomb.core.AsyncResponse) Mock(mockit.Mock) Test(org.junit.Test)

Example 7 with AsyncResponse

use of io.servicecomb.core.AsyncResponse in project java-chassis by ServiceComb.

the class TestVertxPutMethod method testVertxPutMethod.

@Test
public void testVertxPutMethod() {
    HttpClient client = Mockito.mock(HttpClient.class);
    Invocation invocation = Mockito.mock(Invocation.class);
    IpPort ipPort = Mockito.mock(IpPort.class);
    RestOperationMeta operation = Mockito.mock(RestOperationMeta.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    Mockito.when(ipPort.getHostOrIp()).thenReturn("test");
    assertNotNull("test", ipPort.getHostOrIp());
    Mockito.when(ipPort.getPort()).thenReturn(13);
    assertEquals(13, ipPort.getPort());
    HttpClientRequest obj = VertxPutMethod.INSTANCE.createRequest(client, invocation, ipPort, "testCall", operation, asyncResp);
    Assert.assertNull(obj);
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) Invocation(io.servicecomb.core.Invocation) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) HttpClient(io.vertx.core.http.HttpClient) IpPort(io.servicecomb.foundation.common.net.IpPort) AsyncResponse(io.servicecomb.core.AsyncResponse) Test(org.junit.Test)

Example 8 with AsyncResponse

use of io.servicecomb.core.AsyncResponse 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);
}
Also used : Invocation(io.servicecomb.core.Invocation) Endpoint(io.servicecomb.core.Endpoint) OperationProtobuf(io.servicecomb.codec.protobuf.definition.OperationProtobuf) HttpClientWithContext(io.servicecomb.foundation.vertx.client.http.HttpClientWithContext) IpPort(io.servicecomb.foundation.common.net.IpPort) MockUp(mockit.MockUp) OperationMeta(io.servicecomb.core.definition.OperationMeta) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) AsyncResponse(io.servicecomb.core.AsyncResponse) Test(org.junit.Test)

Example 9 with AsyncResponse

use of io.servicecomb.core.AsyncResponse in project java-chassis by ServiceComb.

the class TestVertxDeleteMethod method testCreateRequest.

@Test
public void testCreateRequest() {
    HttpClient client = Mockito.mock(HttpClient.class);
    IpPort ipPort = Mockito.mock(IpPort.class);
    Mockito.when(ipPort.getPort()).thenReturn(23);
    Mockito.when(ipPort.getHostOrIp()).thenReturn("test");
    Invocation invocation = Mockito.mock(Invocation.class);
    RestOperationMeta operation = Mockito.mock(RestOperationMeta.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    HttpClientRequest obj = (HttpClientRequest) VertxDeleteMethod.INSTANCE.createRequest(client, invocation, ipPort, "testCall", operation, asyncResp);
    Assert.assertNull(obj);
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) Invocation(io.servicecomb.core.Invocation) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) HttpClient(io.vertx.core.http.HttpClient) IpPort(io.servicecomb.foundation.common.net.IpPort) AsyncResponse(io.servicecomb.core.AsyncResponse) Test(org.junit.Test)

Example 10 with AsyncResponse

use of io.servicecomb.core.AsyncResponse in project java-chassis by ServiceComb.

the class ProducerOperation method invoke.

public void invoke(Invocation invocation, AsyncResponse asyncResp) {
    InvocationContext context = new InvocationContext(invocation.getContext());
    ContextUtils.setInvocationContext(context);
    Response response = null;
    try {
        Object[] args = argsMapper.toProducerArgs(invocation);
        Object result = method.invoke(instance, args);
        response = responseMapper.mapResponse(context.getStatus(), result);
    } catch (Throwable e) {
        response = processException(e);
    }
    ContextUtils.removeInvocationContext();
    asyncResp.handle(response);
}
Also used : Response(io.servicecomb.core.Response) AsyncResponse(io.servicecomb.core.AsyncResponse) InvocationContext(io.servicecomb.core.context.InvocationContext)

Aggregations

AsyncResponse (io.servicecomb.core.AsyncResponse)22 Invocation (io.servicecomb.core.Invocation)18 Test (org.junit.Test)16 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)6 Response (io.servicecomb.core.Response)6 IpPort (io.servicecomb.foundation.common.net.IpPort)6 Endpoint (io.servicecomb.core.Endpoint)5 OperationMeta (io.servicecomb.core.definition.OperationMeta)5 HttpClientRequest (io.vertx.core.http.HttpClientRequest)5 MockUp (mockit.MockUp)5 HttpClient (io.vertx.core.http.HttpClient)4 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)3 HttpClientWithContext (io.servicecomb.foundation.vertx.client.http.HttpClientWithContext)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ExecutionListener (com.netflix.loadbalancer.reactive.ExecutionListener)2 ProduceProcessor (io.servicecomb.common.rest.codec.produce.ProduceProcessor)2 URLPathBuilder (io.servicecomb.common.rest.definition.path.URLPathBuilder)2 InvocationException (io.servicecomb.core.exception.InvocationException)2 SyncResponseExecutor (io.servicecomb.core.provider.consumer.SyncResponseExecutor)2 URIEndpointObject (io.servicecomb.foundation.common.net.URIEndpointObject)2