use of com.alicp.jetcache.testsupport.CountClass in project jetcache by alibaba.
the class CacheHandlerTest method testStaticInvokeUnlessAndNull.
@Test
public void testStaticInvokeUnlessAndNull() throws Throwable {
Method method = CountClass.class.getMethod("countNull");
cacheAnnoConfig.setCacheNullValue(false);
cacheAnnoConfig.setUnless("mvel{result==0}");
cacheInvokeConfig.init();
//null, not cached
Assert.assertNull(invoke(method, null));
//0, not cached
Assert.assertEquals(0, invoke(method, null).longValue());
//1, cache
Assert.assertEquals(1, invoke(method, null).longValue());
//cache hit
Assert.assertEquals(1, invoke(method, null).longValue());
cacheAnnoConfig.setUnless("mvel{result==1}");
cacheInvokeConfig.init();
Assert.assertEquals(2, invoke(method, null).longValue());
Assert.assertEquals(2, invoke(method, null).longValue());
count = new CountClass();
cacheAnnoConfig.setUnless("mvel{result==2}");
cacheInvokeConfig.init();
Assert.assertNull(invoke(method, null));
//0, cached
Assert.assertEquals(0, invoke(method, null).longValue());
//cache hit
Assert.assertEquals(0, invoke(method, null).longValue());
cacheAnnoConfig.setCacheNullValue(true);
count = new CountClass();
cacheAnnoConfig.setUnless("mvel{result==0}");
cacheInvokeConfig.init();
Assert.assertNull(invoke(method, null));
Assert.assertNull(invoke(method, null));
}
use of com.alicp.jetcache.testsupport.CountClass in project jetcache by alibaba.
the class ProxyUtilTest method testGetProxy.
@Test
public void testGetProxy() {
CacheAnnoConfig cac = new CacheAnnoConfig();
cac.setArea(CacheConsts.DEFAULT_AREA);
cac.setCacheType(CacheType.REMOTE);
cac.setCondition(CacheConsts.UNDEFINED_STRING);
cac.setUnless(CacheConsts.UNDEFINED_STRING);
cac.setEnabled(true);
cac.setTimeUnit(TimeUnit.SECONDS);
cac.setExpire(100);
cac.setName(CacheConsts.UNDEFINED_STRING);
cac.setSerialPolicy(CacheConsts.DEFAULT_SERIAL_POLICY);
cac.setKeyConvertor(KeyConvertor.FASTJSON);
Count c1 = new CountClass();
Count c2 = ProxyUtil.getProxy(c1, cac, globalCacheConfig);
Assert.assertNotEquals(c1.count(), c1.count());
Assert.assertEquals(c2.count(), c2.count());
Assert.assertEquals(c2.count(100), c2.count(100));
Assert.assertEquals(c2.count("S", 100), c2.count("S", 100));
Assert.assertEquals(c2.count(new DynamicQuery(), 100), c2.count(new DynamicQuery(), 100));
Assert.assertNotEquals(c2.count(200), c2.count(100));
}
use of com.alicp.jetcache.testsupport.CountClass in project jetcache by alibaba.
the class CacheHandlerTest method setup.
@BeforeEach
public void setup() {
GlobalCacheConfig globalCacheConfig = new GlobalCacheConfig();
configProvider = new ConfigProvider();
configProvider.setGlobalCacheConfig(globalCacheConfig);
configProvider.init();
cache = LinkedHashMapCacheBuilder.createLinkedHashMapCacheBuilder().keyConvertor(FastjsonKeyConvertor.INSTANCE).buildCache();
cachedAnnoConfig = new CachedAnnoConfig();
cachedAnnoConfig.setArea(CacheConsts.DEFAULT_AREA);
cachedAnnoConfig.setName("myCacheName");
cachedAnnoConfig.setEnabled(CacheConsts.DEFAULT_ENABLED);
cachedAnnoConfig.setTimeUnit(TimeUnit.SECONDS);
cachedAnnoConfig.setExpire(100);
cachedAnnoConfig.setCacheType(CacheType.REMOTE);
cachedAnnoConfig.setLocalLimit(CacheConsts.DEFAULT_LOCAL_LIMIT);
cachedAnnoConfig.setCacheNullValue(CacheConsts.DEFAULT_CACHE_NULL_VALUE);
cachedAnnoConfig.setCondition(CacheConsts.UNDEFINED_STRING);
cachedAnnoConfig.setPostCondition(CacheConsts.UNDEFINED_STRING);
cachedAnnoConfig.setSerialPolicy(CacheConsts.DEFAULT_SERIAL_POLICY);
cachedAnnoConfig.setKeyConvertor(KeyConvertor.FASTJSON);
cachedAnnoConfig.setKey(CacheConsts.UNDEFINED_STRING);
cacheInvokeConfig = new CacheInvokeConfig();
cacheInvokeConfig.setCachedAnnoConfig(cachedAnnoConfig);
configMap = new ConfigMap();
count = new CountClass();
}
use of com.alicp.jetcache.testsupport.CountClass in project jetcache by alibaba.
the class CacheHandlerInvalidateTest method setup.
@BeforeEach
public void setup() throws Exception {
GlobalCacheConfig globalCacheConfig = new GlobalCacheConfig();
configProvider = new ConfigProvider();
configProvider.setGlobalCacheConfig(globalCacheConfig);
configProvider.init();
cache = LinkedHashMapCacheBuilder.createLinkedHashMapCacheBuilder().keyConvertor(FastjsonKeyConvertor.INSTANCE).buildCache();
cacheInvokeConfig = new CacheInvokeConfig();
configMap = new ConfigMap();
count = new CountClass();
method = CountClass.class.getMethod("update", String.class, int.class);
cacheInvokeContext = configProvider.getCacheContext().createCacheInvokeContext(configMap);
cacheInvokeContext.setCacheInvokeConfig(cacheInvokeConfig);
invalidateAnnoConfig = new CacheInvalidateAnnoConfig();
invalidateAnnoConfig.setDefineMethod(method);
invalidateAnnoConfig.setCondition(CacheConsts.UNDEFINED_STRING);
cacheInvokeConfig.setInvalidateAnnoConfigs(Collections.singletonList(invalidateAnnoConfig));
invalidateAnnoConfig.setKey("args[0]");
cacheInvokeConfig.setCachedAnnoConfig(null);
cacheInvokeContext.setMethod(method);
cacheInvokeContext.setArgs(new Object[] { "KEY", 1000 });
cacheInvokeContext.setInvoker(() -> method.invoke(count, cacheInvokeContext.getArgs()));
cacheInvokeContext.setCacheFunction((a, b) -> cache);
}
use of com.alicp.jetcache.testsupport.CountClass in project jetcache by alibaba.
the class CacheHandlerUpdateTest method setup.
@BeforeEach
public void setup() throws Exception {
GlobalCacheConfig globalCacheConfig = new GlobalCacheConfig();
configProvider = new ConfigProvider();
configProvider.setGlobalCacheConfig(globalCacheConfig);
configProvider.init();
cache = LinkedHashMapCacheBuilder.createLinkedHashMapCacheBuilder().keyConvertor(FastjsonKeyConvertor.INSTANCE).buildCache();
cacheInvokeConfig = new CacheInvokeConfig();
configMap = new ConfigMap();
count = new CountClass();
Method method = CountClass.class.getMethod("update", String.class, int.class);
cacheInvokeContext = configProvider.getCacheContext().createCacheInvokeContext(configMap);
cacheInvokeContext.setCacheInvokeConfig(cacheInvokeConfig);
updateAnnoConfig = new CacheUpdateAnnoConfig();
updateAnnoConfig.setCondition(CacheConsts.UNDEFINED_STRING);
updateAnnoConfig.setDefineMethod(method);
cacheInvokeConfig.setUpdateAnnoConfig(updateAnnoConfig);
updateAnnoConfig.setKey("args[0]");
updateAnnoConfig.setValue("args[1]");
cacheInvokeContext.setMethod(method);
cacheInvokeContext.setArgs(new Object[] { "K1", 1000 });
cacheInvokeContext.setInvoker(() -> cacheInvokeContext.getMethod().invoke(count, cacheInvokeContext.getArgs()));
cacheInvokeContext.setCacheFunction((a, b) -> cache);
}
Aggregations