@Override
    public SofaResponse invoke(FilterInvoker invoker, SofaRequest request) throws SofaRpcException {
        // Now only support sync invoke.
        if (request.getInvokeType() != null && !RpcConstants.INVOKER_TYPE_SYNC.equals(request.getInvokeType())) {
            return invoker.invoke(request);
        }

        String interfaceResourceName = getInterfaceResourceName(request);
        String methodResourceName = getMethodResourceName(request);

        Entry interfaceEntry = null;
        Entry methodEntry = null;
        try {
            interfaceEntry = SphU.entry(interfaceResourceName, ResourceTypeConstants.COMMON_RPC, EntryType.OUT);
            methodEntry = SphU.entry(methodResourceName, ResourceTypeConstants.COMMON_RPC,
                EntryType.OUT, getMethodArguments(request));

            SofaResponse response = invoker.invoke(request);

            traceResponseException(response, interfaceEntry, methodEntry);
            return response;
        } catch (BlockException e) {
            return SofaRpcFallbackRegistry.getConsumerFallback().handle(invoker, request, e);
        } catch (Throwable t) {
            throw traceOtherException(t, interfaceEntry, methodEntry);
        } finally {
            if (methodEntry != null) {
                methodEntry.exit(1, getMethodArguments(request));
            }

            if (interfaceEntry != null) {
                interfaceEntry.exit();
            }
        }
    }
@Test
    public void testInvokeSentinelWorks() {
        SentinelSofaRpcConsumerFilter filter = new SentinelSofaRpcConsumerFilter();

        final String interfaceResourceName = "com.alibaba.csp.sentinel.adapter.sofa.rpc.service.DemoService";
        final String methodResourceName = "com.alibaba.csp.sentinel.adapter.sofa.rpc.service.DemoService#sayHello(java.lang.String,int)";

        SofaRequest request = mock(SofaRequest.class);
        when(request.getInvokeType()).thenReturn(RpcConstants.INVOKER_TYPE_SYNC);
        when(request.getInterfaceName()).thenReturn(interfaceResourceName);
        when(request.getMethodName()).thenReturn("sayHello");
        when(request.getMethodArgSigs()).thenReturn(new String[]{"java.lang.String", "int"});
        when(request.getMethodArgs()).thenReturn(new Object[]{"Sentinel", 2020});

        FilterInvoker filterInvoker = mock(FilterInvoker.class);
        when(filterInvoker.invoke(request)).thenAnswer(new Answer<SofaResponse>() {
            @Override
            public SofaResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
                verifyInvocationStructure(interfaceResourceName, methodResourceName);
                SofaResponse response = new SofaResponse();
                response.setAppResponse("Hello Sentinel 2020");
                return response;
            }
        });

        // Before invoke
        assertNull(ContextUtil.getContext());

        // Do invoke
        SofaResponse response = filter.invoke(filterInvoker, request);
        assertEquals("Hello Sentinel 2020", response.getAppResponse());
        verify(filterInvoker).invoke(request);

        // After invoke, make sure exit context
        assertNull(ContextUtil.getContext());
    }