Search in sources :

Example 96 with Invocation

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

the class TokenFilterTest method testInvokeWithToken.

@Test
public void testInvokeWithToken() throws Exception {
    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, token);
    Invocation invocation = Mockito.mock(Invocation.class);
    when(invocation.getObjectAttachments()).thenReturn(attachments);
    Result result = tokenFilter.invoke(invoker, invocation);
    Assertions.assertEquals("result", result.getValue());
}
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) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 97 with Invocation

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

the class ExpiringCacheFactoryTest method testExpiringCacheUnExpired.

@Test
public void testExpiringCacheUnExpired() throws Exception {
    URL url = URL.valueOf("test://test:12/test?cache=expiring&cache.seconds=0&cache.interval=1");
    AbstractCacheFactory cacheFactory = getCacheFactory();
    Invocation invocation = new RpcInvocation();
    Cache cache = cacheFactory.getCache(url, invocation);
    cache.put("testKey", "testValue");
    Thread.sleep(1100);
    assertNotNull(cache.get("testKey"));
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) AbstractCacheFactory(org.apache.dubbo.cache.support.AbstractCacheFactory) URL(org.apache.dubbo.common.URL) Cache(org.apache.dubbo.cache.Cache) Test(org.junit.jupiter.api.Test) AbstractCacheFactoryTest(org.apache.dubbo.cache.support.AbstractCacheFactoryTest)

Example 98 with Invocation

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

the class ExpiringCacheFactoryTest method testExpiringCacheGetExpired.

@Test
public void testExpiringCacheGetExpired() throws Exception {
    URL url = URL.valueOf("test://test:12/test?cache=expiring&cache.seconds=1&cache.interval=1");
    AbstractCacheFactory cacheFactory = getCacheFactory();
    Invocation invocation = new RpcInvocation();
    Cache cache = cacheFactory.getCache(url, invocation);
    cache.put("testKey", "testValue");
    Thread.sleep(2100);
    assertNull(cache.get("testKey"));
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) AbstractCacheFactory(org.apache.dubbo.cache.support.AbstractCacheFactory) URL(org.apache.dubbo.common.URL) Cache(org.apache.dubbo.cache.Cache) Test(org.junit.jupiter.api.Test) AbstractCacheFactoryTest(org.apache.dubbo.cache.support.AbstractCacheFactoryTest)

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