Search in sources :

Example 36 with SofaResponse

use of com.alipay.sofa.rpc.core.response.SofaResponse in project sofa-rpc by sofastack.

the class TestChainFilter7 method invoke.

@Override
public SofaResponse invoke(FilterInvoker invoker, SofaRequest request) throws SofaRpcException {
    request.getMethodArgs()[0] = request.getMethodArgs()[0] + "_q7";
    SofaResponse response = invoker.invoke(request);
    if (!request.isAsync()) {
        response.setAppResponse(response.getAppResponse() + "_s7");
    }
    return response;
}
Also used : SofaResponse(com.alipay.sofa.rpc.core.response.SofaResponse)

Example 37 with SofaResponse

use of com.alipay.sofa.rpc.core.response.SofaResponse in project sofa-rpc by sofastack.

the class TestChainFilter8 method invoke.

@Override
public SofaResponse invoke(FilterInvoker invoker, SofaRequest request) throws SofaRpcException {
    request.getMethodArgs()[0] = request.getMethodArgs()[0] + "_q8";
    SofaResponse response = invoker.invoke(request);
    if (!request.isAsync()) {
        response.setAppResponse(response.getAppResponse() + "_s8");
    }
    return response;
}
Also used : SofaResponse(com.alipay.sofa.rpc.core.response.SofaResponse)

Example 38 with SofaResponse

use of com.alipay.sofa.rpc.core.response.SofaResponse in project sofa-rpc by sofastack.

the class RpcClientStatTest method testClientStat.

@Test
@Ignore
public void testClientStat() {
    try {
        Tracer rpcSofaTracer = Tracers.getTracer();
        Field tracerField = null;
        try {
            tracerField = RpcSofaTracer.class.getDeclaredField("sofaTracer");
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
        tracerField.setAccessible(true);
        SofaTracer tracer = null;
        // OpenTracing tracer 标准实现
        try {
            tracer = (SofaTracer) tracerField.get(rpcSofaTracer);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        Reporter clientReporter = tracer.getClientReporter();
        assertNotNull(clientReporter);
        assertTrue(clientReporter instanceof MemoryReporterImpl);
        memoryReporter = (MemoryReporterImpl) clientReporter;
        final SofaRequest request = new SofaRequest();
        request.setInterfaceName("a");
        request.setTargetServiceUniqueName("app.service:1.0");
        request.setMethodName("method");
        RpcInternalContext context = RpcInternalContext.getContext();
        context.setAttachment(RpcConstants.INTERNAL_KEY_APP_NAME, "client");
        // this will not be used, only in real invoke
        final ProviderInfo providerInfo = new ProviderInfo();
        providerInfo.setStaticAttr(ProviderInfoAttrs.ATTR_APP_NAME, "server");
        context.setProviderInfo(providerInfo);
        for (int i = 0; i < 10; i++) {
            rpcSofaTracer.startRpc(request);
            rpcSofaTracer.clientBeforeSend(request);
            final SofaResponse response = new SofaResponse();
            response.setAppResponse("b");
            rpcSofaTracer.clientReceived(request, response, null);
        }
        Map<StatKey, StatValues> datas = memoryReporter.getStoreDatas();
        LOGGER.info("1" + datas);
        Assert.assertEquals(1, datas.size());
        for (Map.Entry entry : datas.entrySet()) {
            final StatMapKey key = (StatMapKey) entry.getKey();
            final StatValues value = (StatValues) entry.getValue();
            Assert.assertEquals("client,,app.service:1.0,method", key.getKey());
            Assert.assertEquals(10, value.getCurrentValue()[0]);
        }
        request.setTargetServiceUniqueName("app.service:2.0");
        for (int i = 0; i < 20; i++) {
            rpcSofaTracer.startRpc(request);
            rpcSofaTracer.clientBeforeSend(request);
            final SofaResponse response = new SofaResponse();
            response.setAppResponse("b");
            rpcSofaTracer.clientReceived(request, response, null);
        }
        LOGGER.info("2" + datas);
        int i = 0;
        for (Map.Entry entry : datas.entrySet()) {
            if (i == 0) {
                continue;
            }
            final StatMapKey key = (StatMapKey) entry.getKey();
            final StatValues value = (StatValues) entry.getValue();
            Assert.assertEquals("client,,app.service:2.0,method", key.getKey());
            Assert.assertEquals(20, value.getCurrentValue()[0]);
        }
        Assert.assertEquals(2, datas.size());
    } catch (Throwable e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
Also used : MemoryReporterImpl(com.alipay.sofa.rpc.tracer.sofatracer.factory.MemoryReporterImpl) SofaRequest(com.alipay.sofa.rpc.core.request.SofaRequest) Tracer(com.alipay.sofa.rpc.tracer.Tracer) SofaTracer(com.alipay.common.tracer.core.SofaTracer) RpcSofaTracer(com.alipay.sofa.rpc.tracer.sofatracer.RpcSofaTracer) Reporter(com.alipay.common.tracer.core.reporter.facade.Reporter) RpcInternalContext(com.alipay.sofa.rpc.context.RpcInternalContext) StatKey(com.alipay.common.tracer.core.reporter.stat.model.StatKey) Field(java.lang.reflect.Field) StatMapKey(com.alipay.common.tracer.core.reporter.stat.model.StatMapKey) ProviderInfo(com.alipay.sofa.rpc.client.ProviderInfo) RpcSofaTracer(com.alipay.sofa.rpc.tracer.sofatracer.RpcSofaTracer) StatValues(com.alipay.common.tracer.core.reporter.stat.model.StatValues) SofaResponse(com.alipay.sofa.rpc.core.response.SofaResponse) Map(java.util.Map) SofaTracer(com.alipay.common.tracer.core.SofaTracer) RpcSofaTracer(com.alipay.sofa.rpc.tracer.sofatracer.RpcSofaTracer) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 39 with SofaResponse

use of com.alipay.sofa.rpc.core.response.SofaResponse in project skywalking-java by apache.

the class SofaRpcProviderInterceptor method afterMethod.

@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
    SofaResponse result = (SofaResponse) ret;
    if (result != null && result.isError()) {
        dealException((Throwable) result.getAppResponse());
    }
    ContextManager.stopSpan();
    return ret;
}
Also used : SofaResponse(com.alipay.sofa.rpc.core.response.SofaResponse)

Example 40 with SofaResponse

use of com.alipay.sofa.rpc.core.response.SofaResponse in project skywalking-java by apache.

the class SofaRpcConsumerInterceptor method afterMethod.

@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
    SofaResponse result = (SofaResponse) ret;
    if (result != null && result.isError()) {
        dealException((Throwable) result.getAppResponse());
    }
    ContextManager.stopSpan();
    return ret;
}
Also used : SofaResponse(com.alipay.sofa.rpc.core.response.SofaResponse)

Aggregations

SofaResponse (com.alipay.sofa.rpc.core.response.SofaResponse)85 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)25 Test (org.junit.Test)21 SofaRequest (com.alipay.sofa.rpc.core.request.SofaRequest)19 RpcInternalContext (com.alipay.sofa.rpc.context.RpcInternalContext)12 Method (java.lang.reflect.Method)10 AbstractByteBuf (com.alipay.sofa.rpc.transport.AbstractByteBuf)9 HashMap (java.util.HashMap)9 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)6 ClientEndInvokeEvent (com.alipay.sofa.rpc.event.ClientEndInvokeEvent)6 ByteArrayWrapperByteBuf (com.alipay.sofa.rpc.transport.ByteArrayWrapperByteBuf)6 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)5 ClientAsyncReceiveEvent (com.alipay.sofa.rpc.event.ClientAsyncReceiveEvent)5 ClientSyncReceiveEvent (com.alipay.sofa.rpc.event.ClientSyncReceiveEvent)5 Serializer (com.alipay.sofa.rpc.codec.Serializer)4 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)4 FilterChain (com.alipay.sofa.rpc.filter.FilterChain)4 Hessian2Input (com.caucho.hessian.io.Hessian2Input)4 BlockException (com.alibaba.csp.sentinel.slots.block.BlockException)3 DeserializationException (com.alipay.remoting.exception.DeserializationException)3