From c27d072e6862bef004e929e3b47b09419e2359fe Mon Sep 17 00:00:00 2001 From: LamGC Date: Tue, 6 Oct 2020 10:28:45 +0800 Subject: [PATCH] =?UTF-8?q?[Fix][Update]=20CacheStore-redis,=20Core=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=93=E5=AD=98=E7=BB=84=E4=BB=B6=E7=9A=84?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=97=AE=E9=A2=98,=20=E8=B0=83=E6=95=B4=20Co?= =?UTF-8?q?re=20=E4=B8=AD=E5=AF=B9=E4=BA=8E=20CacheStoreBuilder=20?= =?UTF-8?q?=E7=9A=84=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Fix] CacheStoreBuilder 修复 Factory.canGetCacheStore 返回 false 被无视的问题; [Fix] RedisConnectionPool 修复因变量未及时更新导致的逻辑异常; [Update] CacheStoreBuilderTest 调整测试用例以更具体的检查获取的缓存实现类与预期是否相同; --- .../bot/cache/redis/RedisConnectionPool.java | 1 + .../cgj/bot/cache/CacheStoreBuilder.java | 2 ++ .../cgj/bot/cache/CacheStoreBuilderTest.java | 23 +++++++++++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ContentGrabbingJi-CacheStore-redis/src/main/java/net/lamgc/cgj/bot/cache/redis/RedisConnectionPool.java b/ContentGrabbingJi-CacheStore-redis/src/main/java/net/lamgc/cgj/bot/cache/redis/RedisConnectionPool.java index 1ad0abb..1ac0a64 100644 --- a/ContentGrabbingJi-CacheStore-redis/src/main/java/net/lamgc/cgj/bot/cache/redis/RedisConnectionPool.java +++ b/ContentGrabbingJi-CacheStore-redis/src/main/java/net/lamgc/cgj/bot/cache/redis/RedisConnectionPool.java @@ -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; } diff --git a/ContentGrabbingJi-core/src/main/java/net/lamgc/cgj/bot/cache/CacheStoreBuilder.java b/ContentGrabbingJi-core/src/main/java/net/lamgc/cgj/bot/cache/CacheStoreBuilder.java index 5d431f1..a19aa9f 100644 --- a/ContentGrabbingJi-core/src/main/java/net/lamgc/cgj/bot/cache/CacheStoreBuilder.java +++ b/ContentGrabbingJi-core/src/main/java/net/lamgc/cgj/bot/cache/CacheStoreBuilder.java @@ -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() + diff --git a/ContentGrabbingJi-core/src/test/java/net/lamgc/cgj/bot/cache/CacheStoreBuilderTest.java b/ContentGrabbingJi-core/src/test/java/net/lamgc/cgj/bot/cache/CacheStoreBuilderTest.java index 4106cdd..509efe9 100644 --- a/ContentGrabbingJi-core/src/test/java/net/lamgc/cgj/bot/cache/CacheStoreBuilderTest.java +++ b/ContentGrabbingJi-core/src/test/java/net/lamgc/cgj/bot/cache/CacheStoreBuilderTest.java @@ -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 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 singleCacheStore = CacheStoreBuilder.newSingleCacheStore(CacheStoreSource.REMOTE, identify, converter); + Assert.assertNotNull(singleCacheStore); + Assert.assertEquals(RedisSingleCacheStore.class, singleCacheStore.getClass()); + + ListCacheStore listCacheStore = CacheStoreBuilder.newListCacheStore(CacheStoreSource.MEMORY, identify, converter); + Assert.assertNotNull(listCacheStore); + Assert.assertEquals(CopyOnWriteArrayListCacheStore.class, listCacheStore.getClass()); + + MapCacheStore mapCacheStore = CacheStoreBuilder.newMapCacheStore(CacheStoreSource.REMOTE, identify, converter); + Assert.assertNotNull(mapCacheStore); + Assert.assertEquals(RedisMapCacheStore.class, mapCacheStore.getClass()); + + SetCacheStore setCacheStore = CacheStoreBuilder.newSetCacheStore(identify, converter); + Assert.assertNotNull(setCacheStore); + Assert.assertEquals(HashSetCacheStore.class, setCacheStore.getClass()); }