|
|
|
@ -1,29 +1,9 @@
|
|
|
|
|
package org.redisson;
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
|
import java.util.AbstractMap;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
import java.util.concurrent.ConcurrentMap;
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
|
|
|
|
|
|
|
|
import org.junit.Assert;
|
|
|
|
|
import org.assertj.core.api.Assertions;
|
|
|
|
|
import org.junit.Assume;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.redisson.api.RDestroyable;
|
|
|
|
|
import org.redisson.api.RLocalCachedMap;
|
|
|
|
|
import org.redisson.api.RMap;
|
|
|
|
|
import org.redisson.api.RMapCache;
|
|
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
|
|
import org.redisson.api.*;
|
|
|
|
|
import org.redisson.api.map.MapLoader;
|
|
|
|
|
import org.redisson.api.map.MapWriter;
|
|
|
|
|
import org.redisson.client.codec.Codec;
|
|
|
|
@ -34,6 +14,14 @@ import org.redisson.codec.CompositeCodec;
|
|
|
|
|
import org.redisson.codec.JsonJacksonCodec;
|
|
|
|
|
import org.redisson.config.Config;
|
|
|
|
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
|
|
|
|
|
public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
public static class SimpleKey implements Serializable {
|
|
|
|
@ -237,9 +225,7 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
rmap.put("A", "1");
|
|
|
|
|
rmap.put("B", "2");
|
|
|
|
|
|
|
|
|
|
Iterator<Map.Entry<String, String>> iterator = rmap.entrySet().iterator();
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
|
Map.Entry<String, String> next = iterator.next();
|
|
|
|
|
for (Entry<String, String> next : rmap.entrySet()) {
|
|
|
|
|
assertThat(next).isIn(new AbstractMap.SimpleEntry("A", "1"), new AbstractMap.SimpleEntry("B", "2"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -362,30 +348,30 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
map.put(new SimpleKey("1"), new SimpleValue("2"));
|
|
|
|
|
map.put(new SimpleKey("3"), new SimpleValue("4"));
|
|
|
|
|
map.put(new SimpleKey("5"), new SimpleValue("6"));
|
|
|
|
|
Assert.assertEquals(3, map.size());
|
|
|
|
|
assertThat(map.size()).isEqualTo(3);
|
|
|
|
|
|
|
|
|
|
map.put(new SimpleKey("1"), new SimpleValue("2"));
|
|
|
|
|
map.put(new SimpleKey("3"), new SimpleValue("4"));
|
|
|
|
|
Assert.assertEquals(3, map.size());
|
|
|
|
|
assertThat(map.size()).isEqualTo(3);
|
|
|
|
|
|
|
|
|
|
map.put(new SimpleKey("1"), new SimpleValue("21"));
|
|
|
|
|
map.put(new SimpleKey("3"), new SimpleValue("41"));
|
|
|
|
|
Assert.assertEquals(3, map.size());
|
|
|
|
|
assertThat(map.size()).isEqualTo(3);
|
|
|
|
|
|
|
|
|
|
map.put(new SimpleKey("51"), new SimpleValue("6"));
|
|
|
|
|
Assert.assertEquals(4, map.size());
|
|
|
|
|
assertThat(map.size()).isEqualTo(4);
|
|
|
|
|
|
|
|
|
|
map.remove(new SimpleKey("3"));
|
|
|
|
|
Assert.assertEquals(3, map.size());
|
|
|
|
|
assertThat(map.size()).isEqualTo(3);
|
|
|
|
|
destroy(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testEmptyRemove() {
|
|
|
|
|
RMap<Integer, Integer> map = getMap("simple");
|
|
|
|
|
Assert.assertFalse(map.remove(1, 3));
|
|
|
|
|
assertThat(map.remove(1, 3)).isFalse();
|
|
|
|
|
map.put(4, 5);
|
|
|
|
|
Assert.assertTrue(map.remove(4, 5));
|
|
|
|
|
assertThat(map.remove(4, 5)).isTrue();
|
|
|
|
|
destroy(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -484,10 +470,10 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
map.put(new SimpleKey("5"), new SimpleValue("6"));
|
|
|
|
|
|
|
|
|
|
SimpleValue val1 = map.get(new SimpleKey("33"));
|
|
|
|
|
Assert.assertEquals("44", val1.getValue());
|
|
|
|
|
assertThat(val1.getValue()).isEqualTo("44");
|
|
|
|
|
|
|
|
|
|
SimpleValue val2 = map.get(new SimpleKey("5"));
|
|
|
|
|
Assert.assertEquals("6", val2.getValue());
|
|
|
|
|
assertThat(val2.getValue()).isEqualTo("6");
|
|
|
|
|
destroy(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -497,13 +483,13 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
SimpleKey key = new SimpleKey("1");
|
|
|
|
|
SimpleValue value = new SimpleValue("2");
|
|
|
|
|
map.put(key, value);
|
|
|
|
|
Assert.assertEquals(value, map.putIfAbsent(key, new SimpleValue("3")));
|
|
|
|
|
Assert.assertEquals(value, map.get(key));
|
|
|
|
|
assertThat(map.putIfAbsent(key, new SimpleValue("3"))).isEqualTo(value);
|
|
|
|
|
assertThat(map.get(key)).isEqualTo(value);
|
|
|
|
|
|
|
|
|
|
SimpleKey key1 = new SimpleKey("2");
|
|
|
|
|
SimpleValue value1 = new SimpleValue("4");
|
|
|
|
|
Assert.assertNull(map.putIfAbsent(key1, value1));
|
|
|
|
|
Assert.assertEquals(value1, map.get(key1));
|
|
|
|
|
assertThat(map.putIfAbsent(key1, value1)).isNull();
|
|
|
|
|
assertThat(map.get(key1)).isEqualTo(value1);
|
|
|
|
|
destroy(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -513,12 +499,12 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
Assume.assumeTrue(!(map instanceof RLocalCachedMap));
|
|
|
|
|
SimpleObjectWithoutDefaultConstructor object = new SimpleObjectWithoutDefaultConstructor("test-val");
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals("test-val", object.getTestField());
|
|
|
|
|
assertThat(object.getTestField()).isEqualTo("test-val");
|
|
|
|
|
map.put("test-key", object);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
map.get("test-key");
|
|
|
|
|
Assert.fail("Expected exception from map.get() call");
|
|
|
|
|
Assertions.fail("Expected exception from map.get() call");
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
@ -548,10 +534,10 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
map.put(new SimpleKey("1"), new SimpleValue("2"));
|
|
|
|
|
|
|
|
|
|
boolean res = map.replace(new SimpleKey("1"), new SimpleValue("43"), new SimpleValue("31"));
|
|
|
|
|
Assert.assertFalse(res);
|
|
|
|
|
assertThat(res).isFalse();
|
|
|
|
|
|
|
|
|
|
SimpleValue val1 = map.get(new SimpleKey("1"));
|
|
|
|
|
Assert.assertEquals("2", val1.getValue());
|
|
|
|
|
assertThat(val1.getValue()).isEqualTo("2");
|
|
|
|
|
destroy(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -561,13 +547,13 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
map.put(new SimpleKey("1"), new SimpleValue("2"));
|
|
|
|
|
|
|
|
|
|
boolean res = map.replace(new SimpleKey("1"), new SimpleValue("2"), new SimpleValue("3"));
|
|
|
|
|
Assert.assertTrue(res);
|
|
|
|
|
assertThat(res).isTrue();
|
|
|
|
|
|
|
|
|
|
boolean res1 = map.replace(new SimpleKey("1"), new SimpleValue("2"), new SimpleValue("3"));
|
|
|
|
|
Assert.assertFalse(res1);
|
|
|
|
|
assertThat(res1).isFalse();
|
|
|
|
|
|
|
|
|
|
SimpleValue val1 = map.get(new SimpleKey("1"));
|
|
|
|
|
Assert.assertEquals("3", val1.getValue());
|
|
|
|
|
assertThat(val1.getValue()).isEqualTo("3");
|
|
|
|
|
destroy(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -577,10 +563,10 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
map.put(new SimpleKey("1"), new SimpleValue("2"));
|
|
|
|
|
|
|
|
|
|
SimpleValue res = map.replace(new SimpleKey("1"), new SimpleValue("3"));
|
|
|
|
|
Assert.assertEquals("2", res.getValue());
|
|
|
|
|
assertThat(res.getValue()).isEqualTo("2");
|
|
|
|
|
|
|
|
|
|
SimpleValue val1 = map.get(new SimpleKey("1"));
|
|
|
|
|
Assert.assertEquals("3", val1.getValue());
|
|
|
|
|
assertThat(val1.getValue()).isEqualTo("3");
|
|
|
|
|
destroy(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -593,11 +579,11 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
map.put(new SimpleKey("5"), new SimpleValue("6"));
|
|
|
|
|
|
|
|
|
|
SimpleValue val1 = map.get(new SimpleKey("33"));
|
|
|
|
|
Assert.assertEquals("44", val1.getValue());
|
|
|
|
|
assertThat(val1.getValue()).isEqualTo("44");
|
|
|
|
|
|
|
|
|
|
map.put(new SimpleKey("33"), new SimpleValue("abc"));
|
|
|
|
|
SimpleValue val2 = map.get(new SimpleKey("33"));
|
|
|
|
|
Assert.assertEquals("abc", val2.getValue());
|
|
|
|
|
assertThat(val2.getValue()).isEqualTo("abc");
|
|
|
|
|
destroy(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -608,9 +594,9 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
map.put(new SimpleKey("33"), new SimpleValue("44"));
|
|
|
|
|
map.put(new SimpleKey("5"), new SimpleValue("6"));
|
|
|
|
|
|
|
|
|
|
Assert.assertTrue(map.containsValue(new SimpleValue("2")));
|
|
|
|
|
Assert.assertFalse(map.containsValue(new SimpleValue("441")));
|
|
|
|
|
Assert.assertFalse(map.containsValue(new SimpleKey("5")));
|
|
|
|
|
assertThat(map.containsValue(new SimpleValue("2"))).isTrue();
|
|
|
|
|
assertThat(map.containsValue(new SimpleValue("441"))).isFalse();
|
|
|
|
|
assertThat(map.containsValue(new SimpleKey("5"))).isFalse();
|
|
|
|
|
destroy(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -621,8 +607,8 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
map.put(new SimpleKey("33"), new SimpleValue("44"));
|
|
|
|
|
map.put(new SimpleKey("5"), new SimpleValue("6"));
|
|
|
|
|
|
|
|
|
|
Assert.assertTrue(map.containsKey(new SimpleKey("33")));
|
|
|
|
|
Assert.assertFalse(map.containsKey(new SimpleKey("34")));
|
|
|
|
|
assertThat(map.containsKey(new SimpleKey("33"))).isTrue();
|
|
|
|
|
assertThat(map.containsKey(new SimpleKey("34"))).isFalse();
|
|
|
|
|
destroy(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -632,13 +618,13 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
map.put(new SimpleKey("1"), new SimpleValue("2"));
|
|
|
|
|
|
|
|
|
|
boolean res = map.remove(new SimpleKey("2"), new SimpleValue("1"));
|
|
|
|
|
Assert.assertFalse(res);
|
|
|
|
|
assertThat(res).isFalse();
|
|
|
|
|
|
|
|
|
|
boolean res1 = map.remove(new SimpleKey("1"), new SimpleValue("3"));
|
|
|
|
|
Assert.assertFalse(res1);
|
|
|
|
|
assertThat(res1).isFalse();
|
|
|
|
|
|
|
|
|
|
SimpleValue val1 = map.get(new SimpleKey("1"));
|
|
|
|
|
Assert.assertEquals("2", val1.getValue());
|
|
|
|
|
assertThat(val1.getValue()).isEqualTo("2");
|
|
|
|
|
destroy(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -648,12 +634,12 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
map.put(new SimpleKey("1"), new SimpleValue("2"));
|
|
|
|
|
|
|
|
|
|
boolean res = map.remove(new SimpleKey("1"), new SimpleValue("2"));
|
|
|
|
|
Assert.assertTrue(res);
|
|
|
|
|
assertThat(res).isTrue();
|
|
|
|
|
|
|
|
|
|
SimpleValue val1 = map.get(new SimpleKey("1"));
|
|
|
|
|
Assert.assertNull(val1);
|
|
|
|
|
assertThat(val1).isNull();
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(0, map.size());
|
|
|
|
|
assertThat(map.size()).isZero();
|
|
|
|
|
destroy(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -713,7 +699,7 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
for (Iterator<Integer> iterator = map.values().iterator(); iterator.hasNext();) {
|
|
|
|
|
Integer value = iterator.next();
|
|
|
|
|
if (!values.remove(value)) {
|
|
|
|
|
Assert.fail();
|
|
|
|
|
Assertions.fail("unable to remove value " + value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -724,11 +710,11 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void testFastPut() throws Exception {
|
|
|
|
|
RMap<Integer, Integer> map = getMap("simple");
|
|
|
|
|
Assert.assertTrue(map.fastPut(1, 2));
|
|
|
|
|
assertThat(map.fastPut(1, 2)).isTrue();
|
|
|
|
|
assertThat(map.get(1)).isEqualTo(2);
|
|
|
|
|
Assert.assertFalse(map.fastPut(1, 3));
|
|
|
|
|
assertThat(map.fastPut(1, 3)).isFalse();
|
|
|
|
|
assertThat(map.get(1)).isEqualTo(3);
|
|
|
|
|
Assert.assertEquals(1, map.size());
|
|
|
|
|
assertThat(map.size()).isEqualTo(1);
|
|
|
|
|
destroy(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -739,8 +725,8 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
assertThat(map.fastReplace(1, 3)).isTrue();
|
|
|
|
|
assertThat(map.fastReplace(2, 0)).isFalse();
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(1, map.size());
|
|
|
|
|
|
|
|
|
|
assertThat(map.size()).isEqualTo(1);
|
|
|
|
|
assertThat(map.get(1)).isEqualTo(3);
|
|
|
|
|
destroy(map);
|
|
|
|
|
}
|
|
|
|
@ -820,7 +806,7 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
assertThat(map.readAllKeySet().size()).isEqualTo(3);
|
|
|
|
|
Map<SimpleKey, SimpleValue> testMap = new HashMap<>(map);
|
|
|
|
|
assertThat(map.readAllKeySet()).containsOnlyElementsOf(testMap.keySet());
|
|
|
|
|
assertThat(map.readAllKeySet()).isSubsetOf(testMap.keySet());
|
|
|
|
|
destroy(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -838,9 +824,9 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
iterator.remove();
|
|
|
|
|
cnt++;
|
|
|
|
|
}
|
|
|
|
|
Assert.assertEquals(10000, cnt);
|
|
|
|
|
assertThat(cnt).isEqualTo(10000);
|
|
|
|
|
assertThat(map).isEmpty();
|
|
|
|
|
Assert.assertEquals(0, map.size());
|
|
|
|
|
assertThat(map.size()).isEqualTo(0);
|
|
|
|
|
destroy(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -862,7 +848,7 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
}
|
|
|
|
|
cnt++;
|
|
|
|
|
}
|
|
|
|
|
Assert.assertEquals(10000, cnt);
|
|
|
|
|
assertThat(cnt).isEqualTo(10000);
|
|
|
|
|
assertThat(map.size()).isEqualTo(cnt - removed);
|
|
|
|
|
destroy(map);
|
|
|
|
|
}
|
|
|
|
@ -881,9 +867,9 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
iterator.remove();
|
|
|
|
|
cnt++;
|
|
|
|
|
}
|
|
|
|
|
Assert.assertEquals(10000, cnt);
|
|
|
|
|
assertThat(cnt).isEqualTo(10000);
|
|
|
|
|
assertThat(map).isEmpty();
|
|
|
|
|
Assert.assertEquals(0, map.size());
|
|
|
|
|
assertThat(map.size()).isEqualTo(0);
|
|
|
|
|
destroy(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -896,7 +882,7 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
assertThat(map.readAllKeySet().size()).isEqualTo(1000);
|
|
|
|
|
Map<SimpleKey, SimpleValue> testMap = new HashMap<>(map);
|
|
|
|
|
assertThat(map.readAllKeySet()).containsOnlyElementsOf(testMap.keySet());
|
|
|
|
|
assertThat(map.readAllKeySet()).isSubsetOf(testMap.keySet());
|
|
|
|
|
destroy(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -909,7 +895,7 @@ public abstract class BaseMapTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
assertThat(map.readAllValues().size()).isEqualTo(3);
|
|
|
|
|
Map<SimpleKey, SimpleValue> testMap = new HashMap<>(map);
|
|
|
|
|
assertThat(map.readAllValues()).containsOnlyElementsOf(testMap.values());
|
|
|
|
|
assertThat(map.readAllValues()).isSubsetOf(testMap.values());
|
|
|
|
|
destroy(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|