Search in sources :

Example 6 with MyInvoker

use of com.alibaba.dubbo.rpc.support.MyInvoker in project dubbo by alibaba.

the class ConsumerContextFilterTest method testSetContext.

@Test
public void testSetContext() {
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
    Invoker<DemoService> invoker = new MyInvoker<DemoService>(url);
    Invocation invocation = new MockInvocation();
    consumerContextFilter.invoke(invoker, invocation);
    assertEquals(invoker, RpcContext.getContext().getInvoker());
    assertEquals(invocation, RpcContext.getContext().getInvocation());
    assertEquals(NetUtils.getLocalHost() + ":0", RpcContext.getContext().getLocalAddressString());
    assertEquals("test:11", RpcContext.getContext().getRemoteAddressString());
}
Also used : MockInvocation(com.alibaba.dubbo.rpc.support.MockInvocation) Invocation(com.alibaba.dubbo.rpc.Invocation) DemoService(com.alibaba.dubbo.rpc.support.DemoService) MockInvocation(com.alibaba.dubbo.rpc.support.MockInvocation) MyInvoker(com.alibaba.dubbo.rpc.support.MyInvoker) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 7 with MyInvoker

use of com.alibaba.dubbo.rpc.support.MyInvoker in project dubbo by alibaba.

the class ContextFilterTest method testWithAttachments.

@Test
public void testWithAttachments() {
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
    Invoker<DemoService> invoker = new MyInvoker<DemoService>(url);
    Invocation invocation = new MockInvocation();
    Result result = contextFilter.invoke(invoker, invocation);
    assertNull(RpcContext.getContext().getInvoker());
}
Also used : MockInvocation(com.alibaba.dubbo.rpc.support.MockInvocation) Invocation(com.alibaba.dubbo.rpc.Invocation) DemoService(com.alibaba.dubbo.rpc.support.DemoService) MockInvocation(com.alibaba.dubbo.rpc.support.MockInvocation) MyInvoker(com.alibaba.dubbo.rpc.support.MyInvoker) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) RpcResult(com.alibaba.dubbo.rpc.RpcResult) Test(org.junit.Test)

Example 8 with MyInvoker

use of com.alibaba.dubbo.rpc.support.MyInvoker in project dubbo by alibaba.

the class TpsLimitFilterTest method testFail.

@Test(expected = RpcException.class)
public void testFail() throws Exception {
    URL url = URL.valueOf("test://test");
    url = url.addParameter(Constants.INTERFACE_KEY, "com.alibaba.dubbo.rpc.file.TpsService");
    url = url.addParameter(Constants.TPS_LIMIT_RATE_KEY, 5);
    Invoker<TpsLimitFilterTest> invoker = new MyInvoker<TpsLimitFilterTest>(url);
    Invocation invocation = new MockInvocation();
    for (int i = 0; i < 10; i++) {
        try {
            filter.invoke(invoker, invocation);
        } catch (Exception e) {
            assertTrue(i >= 5);
            throw e;
        }
    }
}
Also used : MockInvocation(com.alibaba.dubbo.rpc.support.MockInvocation) Invocation(com.alibaba.dubbo.rpc.Invocation) MockInvocation(com.alibaba.dubbo.rpc.support.MockInvocation) MyInvoker(com.alibaba.dubbo.rpc.support.MyInvoker) URL(com.alibaba.dubbo.common.URL) RpcException(com.alibaba.dubbo.rpc.RpcException) Test(org.junit.Test)

Example 9 with MyInvoker

use of com.alibaba.dubbo.rpc.support.MyInvoker in project dubbo by alibaba.

the class TpsLimitFilterTest method testWithoutCount.

@Test
public void testWithoutCount() throws Exception {
    URL url = URL.valueOf("test://test");
    url = url.addParameter(Constants.INTERFACE_KEY, "com.alibaba.dubbo.rpc.file.TpsService");
    url = url.addParameter(Constants.TPS_LIMIT_RATE_KEY, 5);
    Invoker<TpsLimitFilterTest> invoker = new MyInvoker<TpsLimitFilterTest>(url);
    Invocation invocation = new MockInvocation();
    filter.invoke(invoker, invocation);
}
Also used : MockInvocation(com.alibaba.dubbo.rpc.support.MockInvocation) Invocation(com.alibaba.dubbo.rpc.Invocation) MockInvocation(com.alibaba.dubbo.rpc.support.MockInvocation) MyInvoker(com.alibaba.dubbo.rpc.support.MyInvoker) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Aggregations

Invocation (com.alibaba.dubbo.rpc.Invocation)9 MockInvocation (com.alibaba.dubbo.rpc.support.MockInvocation)9 MyInvoker (com.alibaba.dubbo.rpc.support.MyInvoker)9 Test (org.junit.Test)9 URL (com.alibaba.dubbo.common.URL)8 BlockMyInvoker (com.alibaba.dubbo.rpc.support.BlockMyInvoker)2 DemoService (com.alibaba.dubbo.rpc.support.DemoService)2 Result (com.alibaba.dubbo.rpc.Result)1 RpcException (com.alibaba.dubbo.rpc.RpcException)1 RpcResult (com.alibaba.dubbo.rpc.RpcResult)1