From 2bdfbeb72d20ca9bd3f9f5275464397d6798db89 Mon Sep 17 00:00:00 2001 From: LamGC Date: Mon, 11 Jan 2021 16:38:59 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]=20CacheStore-Redis=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20'putAll'=20=E5=9B=A0=20Map=20=E4=B8=BA=E7=A9=BA=E4=B8=94?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E7=96=8F=E6=BC=8F=E5=AF=BC=E8=87=B4=E6=8A=9B?= =?UTF-8?q?=E5=87=BA=E5=BC=82=E5=B8=B8=E7=9A=84=E9=97=AE=E9=A2=98,=20?= =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B5=8B=E8=AF=95=E9=A1=B9;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Fix] RedisMapCacheStore 修复 'putAll' 因 Map 为空且检查疏漏导致抛出异常的问题; [Update] RedisMapCacheStoreTest 调整测试用前缀, 完善 'putAll' 对空 Map 参数在不同情况下的测试; --- .../net/lamgc/cgj/bot/cache/redis/RedisMapCacheStore.java | 2 +- .../lamgc/cgj/bot/cache/redis/RedisMapCacheStoreTest.java | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ContentGrabbingJi-CacheStore-redis/src/main/java/net/lamgc/cgj/bot/cache/redis/RedisMapCacheStore.java b/ContentGrabbingJi-CacheStore-redis/src/main/java/net/lamgc/cgj/bot/cache/redis/RedisMapCacheStore.java index 6de0d2b..c748f48 100644 --- a/ContentGrabbingJi-CacheStore-redis/src/main/java/net/lamgc/cgj/bot/cache/redis/RedisMapCacheStore.java +++ b/ContentGrabbingJi-CacheStore-redis/src/main/java/net/lamgc/cgj/bot/cache/redis/RedisMapCacheStore.java @@ -111,7 +111,7 @@ public class RedisMapCacheStore extends RedisCacheStore> imple Objects.requireNonNull(key); Objects.requireNonNull(map); if (map.size() == 0) { - return true; + return exists(key); } final Map targetMap = new HashMap<>(map.size()); diff --git a/ContentGrabbingJi-CacheStore-redis/src/test/java/net/lamgc/cgj/bot/cache/redis/RedisMapCacheStoreTest.java b/ContentGrabbingJi-CacheStore-redis/src/test/java/net/lamgc/cgj/bot/cache/redis/RedisMapCacheStoreTest.java index ef6c6f6..1fe4ad2 100644 --- a/ContentGrabbingJi-CacheStore-redis/src/test/java/net/lamgc/cgj/bot/cache/redis/RedisMapCacheStoreTest.java +++ b/ContentGrabbingJi-CacheStore-redis/src/test/java/net/lamgc/cgj/bot/cache/redis/RedisMapCacheStoreTest.java @@ -54,7 +54,7 @@ public class RedisMapCacheStoreTest { } } - private final static MapCacheStore cacheStore = factory.newMapCacheStore("test", new StringToStringConverter()); + private final static MapCacheStore cacheStore = factory.newMapCacheStore("test:map", new StringToStringConverter()); @Before public void before() { @@ -135,12 +135,14 @@ public class RedisMapCacheStoreTest { Assert.assertTrue("clearMap operation failed!", cacheStore.clearMap(key)); // putAll - // empty map - Assert.assertTrue(cacheStore.putAll(key, new HashMap<>())); + // empty map, key no exist + Assert.assertFalse(cacheStore.putAll(key, new HashMap<>())); // non-empty map Assert.assertTrue(cacheStore.putAll(key, expectedMap)); Assert.assertTrue(expectedMap.keySet().containsAll(cacheStore.mapFieldSet(key))); Assert.assertTrue(expectedMap.values().containsAll(cacheStore.mapValueSet(key))); + // empty map, key exist + Assert.assertTrue(cacheStore.putAll(key, new HashMap<>())); } @Test