mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-04-29 22:27:33 +00:00
[Fix][Update] CacheStore-redis, Core 修复缓存组件的逻辑问题, 调整 Core 中对于 CacheStoreBuilder 的测试用例;
[Fix] CacheStoreBuilder 修复 Factory.canGetCacheStore 返回 false 被无视的问题; [Fix] RedisConnectionPool 修复因变量未及时更新导致的逻辑异常; [Update] CacheStoreBuilderTest 调整测试用例以更具体的检查获取的缓存实现类与预期是否相同;
This commit is contained in:
parent
b017599eae
commit
c27d072e68
@ -85,6 +85,7 @@ class RedisConnectionPool {
|
||||
JedisPool jedisPool = POOL.get();
|
||||
if (jedisPool == null || jedisPool.isClosed()) {
|
||||
reconnectRedis();
|
||||
jedisPool = POOL.get();
|
||||
if (jedisPool == null || jedisPool.isClosed()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -112,6 +112,8 @@ public class CacheStoreBuilder {
|
||||
try {
|
||||
if (factory.canGetCacheStore()) {
|
||||
log.debug("CacheStoreFactory {} 可用(优先级: {}).", info.getFactoryName(), info.getFactoryPriority());
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("CacheStoreFactory " + info.getFactoryName() +
|
||||
|
@ -19,6 +19,10 @@ package net.lamgc.cgj.bot.cache;
|
||||
|
||||
import net.lamgc.cgj.bot.cache.convert.StringConverter;
|
||||
import net.lamgc.cgj.bot.cache.convert.StringToStringConverter;
|
||||
import net.lamgc.cgj.bot.cache.local.CopyOnWriteArrayListCacheStore;
|
||||
import net.lamgc.cgj.bot.cache.local.HashSetCacheStore;
|
||||
import net.lamgc.cgj.bot.cache.redis.RedisMapCacheStore;
|
||||
import net.lamgc.cgj.bot.cache.redis.RedisSingleCacheStore;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -32,10 +36,21 @@ public class CacheStoreBuilderTest {
|
||||
final String identify = "test";
|
||||
final StringConverter<String> converter = new StringToStringConverter();
|
||||
|
||||
Assert.assertNotNull(CacheStoreBuilder.newSingleCacheStore(CacheStoreSource.REMOTE, identify, converter));
|
||||
Assert.assertNotNull(CacheStoreBuilder.newListCacheStore(CacheStoreSource.MEMORY, identify, converter));
|
||||
Assert.assertNotNull(CacheStoreBuilder.newMapCacheStore(CacheStoreSource.REMOTE, identify, converter));
|
||||
Assert.assertNotNull(CacheStoreBuilder.newSetCacheStore(identify, converter));
|
||||
SingleCacheStore<String> singleCacheStore = CacheStoreBuilder.newSingleCacheStore(CacheStoreSource.REMOTE, identify, converter);
|
||||
Assert.assertNotNull(singleCacheStore);
|
||||
Assert.assertEquals(RedisSingleCacheStore.class, singleCacheStore.getClass());
|
||||
|
||||
ListCacheStore<String> listCacheStore = CacheStoreBuilder.newListCacheStore(CacheStoreSource.MEMORY, identify, converter);
|
||||
Assert.assertNotNull(listCacheStore);
|
||||
Assert.assertEquals(CopyOnWriteArrayListCacheStore.class, listCacheStore.getClass());
|
||||
|
||||
MapCacheStore<String> mapCacheStore = CacheStoreBuilder.newMapCacheStore(CacheStoreSource.REMOTE, identify, converter);
|
||||
Assert.assertNotNull(mapCacheStore);
|
||||
Assert.assertEquals(RedisMapCacheStore.class, mapCacheStore.getClass());
|
||||
|
||||
SetCacheStore<String> setCacheStore = CacheStoreBuilder.newSetCacheStore(identify, converter);
|
||||
Assert.assertNotNull(setCacheStore);
|
||||
Assert.assertEquals(HashSetCacheStore.class, setCacheStore.getClass());
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user