Fixed - RLocalCachedMap.readAllValues() method uses key decoder instead of value. #3792

pull/3806/head
Nikita Koksharov 4 years ago
parent f642bb32f3
commit d8ea37bb90

@ -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<K, V> extends RedissonMap<K, V> implements R
public static final String DISABLED_KEYS_SUFFIX = "disabled-keys";
public static final String DISABLED_ACK_SUFFIX = ":topic";
private static final RedisCommand<Set<Object>> ALL_KEYS = new RedisCommand<Set<Object>>("EVAL", new MapKeyDecoder(new ObjectSetReplayDecoder<Object>()));
private static final RedisCommand<Set<Object>> ALL_VALUES = new RedisCommand<Set<Object>>("EVAL", new MapValueDecoder(new ObjectSetReplayDecoder<Object>()));
private static final RedisCommand<Set<Entry<Object, Object>>> ALL_ENTRIES = new RedisCommand<>("EVAL", new ObjectMapEntryReplayDecoder());
private static final RedisCommand<Map<Object, Object>> ALL_MAP = new RedisCommand<Map<Object, Object>>("EVAL", new ObjectMapReplayDecoder());
@ -866,7 +863,7 @@ public class RedissonLocalCachedMap<K, V> extends RedissonMap<K, V> implements R
}
RPromise<Collection<V>> promise = new RedissonPromise<Collection<V>>();
RFuture<Collection<V>> future = commandExecutor.evalReadAsync(getRawName(), codec, ALL_KEYS,
RFuture<Collection<V>> future = commandExecutor.evalReadAsync(getRawName(), codec, ALL_VALUES,
"local entries = redis.call('hgetall', KEYS[1]); "
+ "local result = {};"
+ "for j, v in ipairs(entries) do "

@ -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<String, SimpleValue> map1 = redisson.getLocalCachedMap("test", codec, LocalCachedMapOptions.defaults());
RLocalCachedMap<String, SimpleValue> map2 = redisson.getLocalCachedMap("test", codec, LocalCachedMapOptions.defaults());
map1.put("key", new SimpleValue("3"));
Collection<SimpleValue> s = map1.readAllValues();
assertThat(s).hasSize(1);
Collection<SimpleValue> s2 = map2.readAllValues();
assertThat(s2).hasSize(1);
}
@Test
public void testReadValuesAndEntries() {
RLocalCachedMap<Object, Object> m = redisson.getLocalCachedMap("testValuesWithNearCache2",
@ -885,13 +904,12 @@ public class RedissonLocalCachedMapTest extends BaseMapTest {
assertThat(map.readAllValues().size()).isEqualTo(3);
Map<SimpleKey, SimpleValue> testMap = new HashMap<>(map);
assertThat(map.readAllValues()).containsOnlyElementsOf(testMap.values());
assertThat(map.readAllValues()).containsAll(testMap.values());
RMap<SimpleKey, SimpleValue> 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)

Loading…
Cancel
Save