Search in sources :

Example 1 with AbstractCacheFactory

use of org.apache.dubbo.cache.support.AbstractCacheFactory in project dubbo by alibaba.

the class JCacheFactoryTest method testJCacheGetExpired.

@Test
public void testJCacheGetExpired() throws Exception {
    URL url = URL.valueOf("test://test:12/test?cache=jacache&cache.write.expire=1");
    AbstractCacheFactory cacheFactory = getCacheFactory();
    Invocation invocation = new RpcInvocation();
    Cache cache = cacheFactory.getCache(url, invocation);
    cache.put("testKey", "testValue");
    Thread.sleep(10);
    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)

Example 2 with AbstractCacheFactory

use of org.apache.dubbo.cache.support.AbstractCacheFactory 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 3 with AbstractCacheFactory

use of org.apache.dubbo.cache.support.AbstractCacheFactory 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

Cache (org.apache.dubbo.cache.Cache)3 AbstractCacheFactory (org.apache.dubbo.cache.support.AbstractCacheFactory)3 AbstractCacheFactoryTest (org.apache.dubbo.cache.support.AbstractCacheFactoryTest)3 URL (org.apache.dubbo.common.URL)3 Invocation (org.apache.dubbo.rpc.Invocation)3 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)3 Test (org.junit.jupiter.api.Test)3