Search in sources :

Example 1 with OperationMeta

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

the class TestConsumerSchemaFactory method testGetOrCreateConsumer.

@Test
public void testGetOrCreateConsumer() {
    MicroserviceMeta microserviceMeta = consumerSchemaFactory.getOrCreateConsumer("ms", "latest");
    OperationMeta operationMeta = microserviceMeta.ensureFindOperation("schema.add");
    Assert.assertEquals("add", operationMeta.getOperationId());
}
Also used : MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta) ConsumerOperationMeta(io.servicecomb.core.provider.consumer.ConsumerOperationMeta) OperationMeta(io.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 2 with OperationMeta

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

the class TestConsumer method testInvokerUtils.

@Test
public void testInvokerUtils() {
    Invocation oInvocation = Mockito.mock(Invocation.class);
    OperationMeta oOperationMeta = Mockito.mock(OperationMeta.class);
    Mockito.when(oOperationMeta.isSync()).thenReturn(false);
    Mockito.when(oInvocation.getOperationMeta()).thenReturn(oOperationMeta);
    InvokerUtils.reactiveInvoke(oInvocation, Mockito.mock(AsyncResponse.class));
    boolean validReactiveInvoke = true;
    try {
        InvokerUtils.reactiveInvoke(null, null);
    } catch (Exception e) {
        Assert.assertEquals(java.lang.NullPointerException.class, e.getClass());
        validReactiveInvoke = false;
    }
    Assert.assertFalse(validReactiveInvoke);
    boolean validInvokeIsNull = true;
    try {
        InvokerUtils.invoke(null);
    } catch (Exception e) {
        Assert.assertEquals(java.lang.NullPointerException.class, e.getClass());
        validInvokeIsNull = false;
    }
    Assert.assertFalse(validInvokeIsNull);
    boolean validInvoke = true;
    try {
        InvokerUtils.invoke(oInvocation);
    } catch (Exception e) {
        Assert.assertEquals(java.lang.NullPointerException.class, e.getClass());
        validInvoke = false;
    }
    Assert.assertFalse(validInvoke);
}
Also used : OperationMeta(io.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 3 with OperationMeta

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

the class TestInvokerUtils method testInvoke.

@Test
public void testInvoke() {
    Object[] objectArray = new Object[2];
    Invocation invocation = Mockito.mock(Invocation.class);
    OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
    Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
    Mockito.when(operationMeta.isSync()).thenReturn(false);
    Mockito.when(invocation.getArgs()).thenReturn(objectArray);
    Object obj = InvokerUtils.invoke(invocation);
    Assert.assertNull(obj);
}
Also used : Invocation(io.servicecomb.core.Invocation) OperationMeta(io.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 4 with OperationMeta

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

the class TestInvokerUtils method testSyncInvokeInvocationWithException.

@Test
public void testSyncInvokeInvocationWithException() throws InterruptedException {
    Invocation invocation = Mockito.mock(Invocation.class);
    Response response = Mockito.mock(Response.class);
    new MockUp<SyncResponseExecutor>() {

        @Mock
        public Response waitResponse() throws InterruptedException {
            return Mockito.mock(Response.class);
        }
    };
    Mockito.when(response.isSuccessed()).thenReturn(true);
    OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
    Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
    Mockito.when(operationMeta.getMicroserviceQualifiedName()).thenReturn("test");
    try {
        InvokerUtils.syncInvoke(invocation);
    } catch (InvocationException e) {
        Assert.assertEquals(490, e.getStatusCode());
    }
}
Also used : Response(io.servicecomb.core.Response) AsyncResponse(io.servicecomb.core.AsyncResponse) Invocation(io.servicecomb.core.Invocation) InvocationException(io.servicecomb.core.exception.InvocationException) MockUp(mockit.MockUp) OperationMeta(io.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 5 with OperationMeta

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

the class ConsumerQpsFlowControlHandler method handle.

@Override
public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {
    if (!Config.INSTANCE.isConsumerEnabled()) {
        invocation.next(asyncResp);
        return;
    }
    OperationMeta operationMeta = invocation.getOperationMeta();
    QpsController qpsController = qpsControllerMgr.getOrCreate(operationMeta);
    if (qpsController.isLimitNewRequest()) {
        // 429
        CommonExceptionData errorData = new CommonExceptionData("rejected by qps flowcontrol");
        asyncResp.consumerFail(new InvocationException(QpsConst.TOO_MANY_REQUESTS_STATUS, errorData));
        return;
    }
    invocation.next(asyncResp);
}
Also used : InvocationException(io.servicecomb.core.exception.InvocationException) CommonExceptionData(io.servicecomb.core.exception.CommonExceptionData) OperationMeta(io.servicecomb.core.definition.OperationMeta)

Aggregations

OperationMeta (io.servicecomb.core.definition.OperationMeta)36 Test (org.junit.Test)18 Invocation (io.servicecomb.core.Invocation)15 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)12 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)8 SchemaMeta (io.servicecomb.core.definition.SchemaMeta)8 MockUp (mockit.MockUp)7 WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)6 AsyncResponse (io.servicecomb.core.AsyncResponse)6 Endpoint (io.servicecomb.core.Endpoint)6 Response (io.servicecomb.core.Response)5 InvocationException (io.servicecomb.core.exception.InvocationException)5 HttpClientResponse (io.vertx.core.http.HttpClientResponse)5 URLPathBuilder (io.servicecomb.common.rest.definition.path.URLPathBuilder)4 MicroserviceMeta (io.servicecomb.core.definition.MicroserviceMeta)4 HttpClientWithContext (io.servicecomb.foundation.vertx.client.http.HttpClientWithContext)4 Buffer (io.vertx.core.buffer.Buffer)4 ConsumerOperationMeta (io.servicecomb.core.provider.consumer.ConsumerOperationMeta)3 IpPort (io.servicecomb.foundation.common.net.IpPort)3 HttpClientRequest (io.vertx.core.http.HttpClientRequest)3