From d8ea37bb90811638a71572fc9892fb26388db72f Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Tue, 24 Aug 2021 09:00:11 +0300 Subject: [PATCH] Fixed - RLocalCachedMap.readAllValues() method uses key decoder instead of value. #3792 --- .../org/redisson/RedissonLocalCachedMap.java | 9 ++---- .../redisson/RedissonLocalCachedMapTest.java | 30 +++++++++++++++---- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java b/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java index 003ed5c36..a4a1a4158 100644 --- a/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java +++ b/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java @@ -29,10 +29,7 @@ import org.redisson.client.codec.StringCodec; import org.redisson.client.protocol.RedisCommand; import org.redisson.client.protocol.RedisCommands; import org.redisson.client.protocol.convertor.NumberConvertor; -import org.redisson.client.protocol.decoder.MapKeyDecoder; -import org.redisson.client.protocol.decoder.ObjectMapEntryReplayDecoder; -import org.redisson.client.protocol.decoder.ObjectMapReplayDecoder; -import org.redisson.client.protocol.decoder.ObjectSetReplayDecoder; +import org.redisson.client.protocol.decoder.*; import org.redisson.command.CommandAsyncExecutor; import org.redisson.eviction.EvictionScheduler; import org.redisson.misc.RPromise; @@ -51,7 +48,7 @@ public class RedissonLocalCachedMap extends RedissonMap implements R public static final String DISABLED_KEYS_SUFFIX = "disabled-keys"; public static final String DISABLED_ACK_SUFFIX = ":topic"; - private static final RedisCommand> ALL_KEYS = new RedisCommand>("EVAL", new MapKeyDecoder(new ObjectSetReplayDecoder())); + private static final RedisCommand> ALL_VALUES = new RedisCommand>("EVAL", new MapValueDecoder(new ObjectSetReplayDecoder())); private static final RedisCommand>> ALL_ENTRIES = new RedisCommand<>("EVAL", new ObjectMapEntryReplayDecoder()); private static final RedisCommand> ALL_MAP = new RedisCommand>("EVAL", new ObjectMapReplayDecoder()); @@ -866,7 +863,7 @@ public class RedissonLocalCachedMap extends RedissonMap implements R } RPromise> promise = new RedissonPromise>(); - RFuture> future = commandExecutor.evalReadAsync(getRawName(), codec, ALL_KEYS, + RFuture> future = commandExecutor.evalReadAsync(getRawName(), codec, ALL_VALUES, "local entries = redis.call('hgetall', KEYS[1]); " + "local result = {};" + "for j, v in ipairs(entries) do " diff --git a/redisson/src/test/java/org/redisson/RedissonLocalCachedMapTest.java b/redisson/src/test/java/org/redisson/RedissonLocalCachedMapTest.java index ab5a15e2e..4632a94c7 100644 --- a/redisson/src/test/java/org/redisson/RedissonLocalCachedMapTest.java +++ b/redisson/src/test/java/org/redisson/RedissonLocalCachedMapTest.java @@ -1,5 +1,7 @@ package org.redisson; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import org.awaitility.Awaitility; import org.awaitility.Durations; import org.junit.jupiter.api.Assertions; @@ -18,6 +20,8 @@ import org.redisson.client.codec.IntegerCodec; import org.redisson.client.codec.StringCodec; import org.redisson.client.protocol.RedisCommands; import org.redisson.codec.CompositeCodec; +import org.redisson.codec.JsonJacksonCodec; +import org.redisson.codec.TypedJsonJacksonCodec; import org.redisson.config.Config; import java.util.*; @@ -166,8 +170,23 @@ public class RedissonLocalCachedMapTest extends BaseMapTest { assertThat(m.size()).isEqualTo(10000); } - - + + @Test + public void testReadAllValues2() { + ObjectMapper objectMapper = new JsonJacksonCodec().getObjectMapper() + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + Codec codec = new TypedJsonJacksonCodec(String.class, SimpleValue.class, objectMapper); + + RLocalCachedMap map1 = redisson.getLocalCachedMap("test", codec, LocalCachedMapOptions.defaults()); + RLocalCachedMap map2 = redisson.getLocalCachedMap("test", codec, LocalCachedMapOptions.defaults()); + map1.put("key", new SimpleValue("3")); + Collection s = map1.readAllValues(); + assertThat(s).hasSize(1); + Collection s2 = map2.readAllValues(); + assertThat(s2).hasSize(1); + } + + @Test public void testReadValuesAndEntries() { RLocalCachedMap m = redisson.getLocalCachedMap("testValuesWithNearCache2", @@ -885,13 +904,12 @@ public class RedissonLocalCachedMapTest extends BaseMapTest { assertThat(map.readAllValues().size()).isEqualTo(3); Map testMap = new HashMap<>(map); - assertThat(map.readAllValues()).containsOnlyElementsOf(testMap.values()); + assertThat(map.readAllValues()).containsAll(testMap.values()); RMap map2 = redisson.getLocalCachedMap("simple", LocalCachedMapOptions.defaults()); - assertThat(map2.readAllValues()).containsOnlyElementsOf(testMap.values()); + assertThat(map2.readAllValues()).containsAll(testMap.values()); } - @Test public void testInvalidationOnFastRemove() throws InterruptedException { new InvalidationTest() { @@ -935,7 +953,7 @@ public class RedissonLocalCachedMapTest extends BaseMapTest { } @Test - public void testFastRemoveEmpty() throws InterruptedException, ExecutionException { + public void testFastRemoveEmpty() { LocalCachedMapOptions options = LocalCachedMapOptions.defaults() .evictionPolicy(EvictionPolicy.NONE) .cacheSize(3)