Search in sources :

Example 41 with Invocation

use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.

the class TimeoutFilterTest method testInvokeWithoutTimeout.

@Test
public void testInvokeWithoutTimeout() throws Exception {
    int timeout = 3000;
    Invoker invoker = Mockito.mock(Invoker.class);
    when(invoker.invoke(any(Invocation.class))).thenReturn(new AppResponse("result"));
    when(invoker.getUrl()).thenReturn(URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&timeout=" + timeout));
    Invocation invocation = Mockito.mock(Invocation.class);
    when(invocation.getMethodName()).thenReturn("testInvokeWithoutTimeout");
    Result result = timeoutFilter.invoke(invoker, invocation);
    Assertions.assertEquals("result", result.getValue());
}
Also used : BlockMyInvoker(org.apache.dubbo.rpc.support.BlockMyInvoker) Invoker(org.apache.dubbo.rpc.Invoker) Invocation(org.apache.dubbo.rpc.Invocation) AppResponse(org.apache.dubbo.rpc.AppResponse) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 42 with Invocation

use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.

the class TpsLimitFilterTest method testFail.

@Test
public void testFail() throws Exception {
    Assertions.assertThrows(RpcException.class, () -> {
        URL url = URL.valueOf("test://test");
        url = url.addParameter(INTERFACE_KEY, "org.apache.dubbo.rpc.file.TpsService");
        url = url.addParameter(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 : Invocation(org.apache.dubbo.rpc.Invocation) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) MyInvoker(org.apache.dubbo.rpc.support.MyInvoker) URL(org.apache.dubbo.common.URL) RpcException(org.apache.dubbo.rpc.RpcException) Test(org.junit.jupiter.api.Test)

Example 43 with Invocation

use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.

the class TokenFilterTest method testInvokeWithoutToken.

@Test
public void testInvokeWithoutToken() throws Exception {
    Assertions.assertThrows(RpcException.class, () -> {
        String token = "token";
        Invoker invoker = Mockito.mock(Invoker.class);
        URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&token=" + token);
        when(invoker.getUrl()).thenReturn(url);
        when(invoker.invoke(any(Invocation.class))).thenReturn(new AppResponse("result"));
        Invocation invocation = Mockito.mock(Invocation.class);
        tokenFilter.invoke(invoker, invocation);
    });
}
Also used : Invoker(org.apache.dubbo.rpc.Invoker) Invocation(org.apache.dubbo.rpc.Invocation) AppResponse(org.apache.dubbo.rpc.AppResponse) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 44 with Invocation

use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.

the class TokenFilterTest method testInvokeWithWrongToken.

@Test
public void testInvokeWithWrongToken() throws Exception {
    Assertions.assertThrows(RpcException.class, () -> {
        String token = "token";
        Invoker invoker = Mockito.mock(Invoker.class);
        URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&token=" + token);
        when(invoker.getUrl()).thenReturn(url);
        when(invoker.invoke(any(Invocation.class))).thenReturn(new AppResponse("result"));
        Map<String, Object> attachments = new HashMap<>();
        attachments.put(TOKEN_KEY, "wrongToken");
        Invocation invocation = Mockito.mock(Invocation.class);
        when(invocation.getObjectAttachments()).thenReturn(attachments);
        tokenFilter.invoke(invoker, invocation);
    });
}
Also used : Invoker(org.apache.dubbo.rpc.Invoker) Invocation(org.apache.dubbo.rpc.Invocation) HashMap(java.util.HashMap) AppResponse(org.apache.dubbo.rpc.AppResponse) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 45 with Invocation

use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.

the class AddressRouterTest method testAddressRouteSelector.

@Test
public void testAddressRouteSelector() {
    Router router = new AddressRouterFactory().getRouter(URL.valueOf("url"));
    List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
    invokers.add(new MockInvoker<>(new URL("dubbo", "129.34.56.7", 8809), true));
    invokers.add(new MockInvoker<>(new URL("dubbo", "129.34.56.8", 8809), true));
    invokers.add(new MockInvoker<>(new URL("dubbo", "129.34.56.9", 8809), true));
    Invocation invocation = new RpcInvocation();
    Address address = new Address("129.34.56.9", 8809);
    invocation.setObjectAttachment("address", address);
    List<Invoker<String>> list = router.route(invokers, URL.valueOf("url"), invocation);
    Assertions.assertEquals(address.getIp(), list.get(0).getUrl().getHost());
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invoker(org.apache.dubbo.rpc.Invoker) MockInvoker(org.apache.dubbo.rpc.cluster.router.MockInvoker) Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) ArrayList(java.util.ArrayList) Router(org.apache.dubbo.rpc.cluster.Router) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Aggregations

Invocation (org.apache.dubbo.rpc.Invocation)98 Test (org.junit.jupiter.api.Test)78 URL (org.apache.dubbo.common.URL)77 Invoker (org.apache.dubbo.rpc.Invoker)44 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)44 Result (org.apache.dubbo.rpc.Result)33 AppResponse (org.apache.dubbo.rpc.AppResponse)29 RpcException (org.apache.dubbo.rpc.RpcException)18 MockInvocation (org.apache.dubbo.rpc.support.MockInvocation)17 HashMap (java.util.HashMap)16 AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)13 BlockMyInvoker (org.apache.dubbo.rpc.support.BlockMyInvoker)11 MyInvoker (org.apache.dubbo.rpc.support.MyInvoker)10 ArrayList (java.util.ArrayList)8 Person (org.apache.dubbo.rpc.support.Person)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 IMetricManager (com.alibaba.metrics.IMetricManager)5 Method (java.lang.reflect.Method)5 DemoService (org.apache.dubbo.monitor.dubbo.service.DemoService)5 FastCompass (com.alibaba.metrics.FastCompass)4