Fixed - RMap.getAll doesn't not preserve the order of elements #712

pull/694/merge
Nikita 8 years ago
parent adbca7bbf6
commit 88cb7c53f1

@ -17,7 +17,7 @@ package org.redisson.connection.decoder;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -57,7 +57,7 @@ public class MapGetAllDecoder implements MultiDecoder<Map<Object, Object>> {
if (parts.isEmpty()) {
return Collections.emptyMap();
}
Map<Object, Object> result = new HashMap<Object, Object>(parts.size());
Map<Object, Object> result = new LinkedHashMap<Object, Object>(parts.size());
for (int index = 0; index < args.size()-shiftIndex; index++) {
Object value = parts.get(index);
if (!allowNulls && value == null) {

@ -162,6 +162,31 @@ public class RedissonMapTest extends BaseTest {
assertThat(map.valueSize("4")).isZero();
assertThat(map.valueSize("1")).isEqualTo(6);
}
@Test
public void testGetAllOrder() {
RMap<Integer, Integer> map = redisson.getMap("getAll");
map.put(1, 100);
map.put(2, 200);
map.put(3, 300);
map.put(4, 400);
map.put(5, 500);
map.put(6, 600);
map.put(7, 700);
map.put(8, 800);
Map<Integer, Integer> filtered = map.getAll(new HashSet<Integer>(Arrays.asList(2, 3, 5, 1, 7, 8)));
Map<Integer, Integer> expectedMap = new LinkedHashMap<Integer, Integer>();
expectedMap.put(1, 100);
expectedMap.put(2, 200);
expectedMap.put(3, 300);
expectedMap.put(5, 500);
expectedMap.put(7, 700);
expectedMap.put(8, 800);
assertThat(filtered.entrySet()).containsExactlyElementsOf(expectedMap.entrySet());
}
@Test
public void testGetAll() {

Loading…
Cancel
Save