[Fix] CacheStore-Redis 修复 'putAll' 因 Map 为空且检查疏漏导致抛出异常的问题, 完善测试项;

[Fix] RedisMapCacheStore 修复 'putAll' 因 Map 为空且检查疏漏导致抛出异常的问题;
[Update] RedisMapCacheStoreTest 调整测试用前缀, 完善 'putAll' 对空 Map 参数在不同情况下的测试;
This commit is contained in:
LamGC 2021-01-11 16:38:59 +08:00
parent 8d9debeb1b
commit 2bdfbeb72d
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D
2 changed files with 6 additions and 4 deletions

View File

@ -111,7 +111,7 @@ public class RedisMapCacheStore<V> extends RedisCacheStore<Map<String, V>> imple
Objects.requireNonNull(key);
Objects.requireNonNull(map);
if (map.size() == 0) {
return true;
return exists(key);
}
final Map<String, String> targetMap = new HashMap<>(map.size());

View File

@ -54,7 +54,7 @@ public class RedisMapCacheStoreTest {
}
}
private final static MapCacheStore<String> cacheStore = factory.newMapCacheStore("test", new StringToStringConverter());
private final static MapCacheStore<String> 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