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());
}
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"));
}
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"));
}
Aggregations