Merge branch 'master' into 3.0.0
# Conflicts: # redisson/src/main/java/org/redisson/reactive/RedissonBatchReactive.javapull/1303/head
commit
a66cf86fc1
@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2016 Nikita Koksharov
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.redisson.client.protocol.convertor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Nikita Koksharov
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class DoubleNullSafeReplayConvertor extends DoubleReplayConvertor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Double convert(Object obj) {
|
||||||
|
Double r = super.convert(obj);
|
||||||
|
if (r == null) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,177 +0,0 @@
|
|||||||
package org.redisson;
|
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentMap;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class RedissonConcurrentMapTest extends BaseConcurrentTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSingleReplaceOldValue_SingleInstance() throws InterruptedException {
|
|
||||||
final String name = "testSingleReplaceOldValue_SingleInstance";
|
|
||||||
|
|
||||||
ConcurrentMap<String, String> map = BaseTest.createInstance().getMap(name);
|
|
||||||
map.put("1", "122");
|
|
||||||
|
|
||||||
testSingleInstanceConcurrency(100, r -> {
|
|
||||||
ConcurrentMap<String, String> map1 = r.getMap(name);
|
|
||||||
map1.replace("1", "122", "32");
|
|
||||||
map1.replace("1", "0", "31");
|
|
||||||
});
|
|
||||||
|
|
||||||
ConcurrentMap<String, String> testMap = BaseTest.createInstance().getMap(name);
|
|
||||||
Assert.assertEquals("32", testMap.get("1"));
|
|
||||||
|
|
||||||
assertMapSize(1, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSingleRemoveValue_SingleInstance() throws InterruptedException {
|
|
||||||
final String name = "testSingleRemoveValue_SingleInstance";
|
|
||||||
|
|
||||||
ConcurrentMap<String, String> map = BaseTest.createInstance().getMap(name);
|
|
||||||
map.putIfAbsent("1", "0");
|
|
||||||
testSingleInstanceConcurrency(100, r -> {
|
|
||||||
ConcurrentMap<String, String> map1 = r.getMap(name);
|
|
||||||
map1.remove("1", "0");
|
|
||||||
});
|
|
||||||
|
|
||||||
assertMapSize(0, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSingleReplace_SingleInstance() throws InterruptedException {
|
|
||||||
final String name = "testSingleReplace_SingleInstance";
|
|
||||||
|
|
||||||
ConcurrentMap<String, String> map = BaseTest.createInstance().getMap(name);
|
|
||||||
map.put("1", "0");
|
|
||||||
|
|
||||||
testSingleInstanceConcurrency(100, r -> {
|
|
||||||
ConcurrentMap<String, String> map1 = r.getMap(name);
|
|
||||||
map1.replace("1", "3");
|
|
||||||
});
|
|
||||||
|
|
||||||
ConcurrentMap<String, String> testMap = BaseTest.createInstance().getMap(name);
|
|
||||||
Assert.assertEquals("3", testMap.get("1"));
|
|
||||||
|
|
||||||
assertMapSize(1, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test_Multi_Replace_MultiInstance() throws InterruptedException {
|
|
||||||
final String name = "test_Multi_Replace_MultiInstance";
|
|
||||||
|
|
||||||
ConcurrentMap<Integer, Integer> map = BaseTest.createInstance().getMap(name);
|
|
||||||
for (int i = 0; i < 5; i++) {
|
|
||||||
map.put(i, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
final SecureRandom secureRandom = new SecureRandom();
|
|
||||||
testSingleInstanceConcurrency(100, r -> {
|
|
||||||
ConcurrentMap<Integer, Integer> map1 = r.getMap(name);
|
|
||||||
Assert.assertNotNull(map1.replace(secureRandom.nextInt(5), 2));
|
|
||||||
});
|
|
||||||
|
|
||||||
ConcurrentMap<Integer, Integer> testMap = BaseTest.createInstance().getMap(name);
|
|
||||||
for (Integer value : testMap.values()) {
|
|
||||||
Assert.assertEquals(2, (int)value);
|
|
||||||
}
|
|
||||||
assertMapSize(5, name);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test_Multi_RemoveValue_MultiInstance() throws InterruptedException {
|
|
||||||
final String name = "test_Multi_RemoveValue_MultiInstance";
|
|
||||||
|
|
||||||
ConcurrentMap<Integer, Integer> map = BaseTest.createInstance().getMap(name);
|
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
map.put(i, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
final SecureRandom secureRandom = new SecureRandom();
|
|
||||||
testMultiInstanceConcurrency(100, r -> {
|
|
||||||
ConcurrentMap<String, String> map1 = r.getMap(name);
|
|
||||||
map1.remove(secureRandom.nextInt(10), 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
assertMapSize(0, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSinglePutIfAbsent_SingleInstance() throws InterruptedException {
|
|
||||||
final String name = "testSinglePutIfAbsent_SingleInstance";
|
|
||||||
|
|
||||||
ConcurrentMap<String, String> map = BaseTest.createInstance().getMap(name);
|
|
||||||
map.putIfAbsent("1", "0");
|
|
||||||
testSingleInstanceConcurrency(100, r -> {
|
|
||||||
ConcurrentMap<String, String> map1 = r.getMap(name);
|
|
||||||
map1.putIfAbsent("1", "1");
|
|
||||||
});
|
|
||||||
|
|
||||||
ConcurrentMap<String, String> testMap = BaseTest.createInstance().getMap(name);
|
|
||||||
Assert.assertEquals("0", testMap.get("1"));
|
|
||||||
|
|
||||||
assertMapSize(1, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMultiPutIfAbsent_SingleInstance() throws InterruptedException {
|
|
||||||
final String name = "testMultiPutIfAbsent_SingleInstance";
|
|
||||||
testSingleInstanceConcurrency(100, r -> {
|
|
||||||
ConcurrentMap<String, String> map = r.getMap(name);
|
|
||||||
map.putIfAbsent("" + Math.random(), "1");
|
|
||||||
});
|
|
||||||
|
|
||||||
assertMapSize(100, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMultiPutIfAbsent_MultiInstance() throws InterruptedException {
|
|
||||||
final String name = "testMultiPutIfAbsent_MultiInstance";
|
|
||||||
testMultiInstanceConcurrency(100, r -> {
|
|
||||||
ConcurrentMap<String, String> map = r.getMap(name);
|
|
||||||
map.putIfAbsent("" + Math.random(), "1");
|
|
||||||
});
|
|
||||||
|
|
||||||
assertMapSize(100, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertMapSize(int size, String name) {
|
|
||||||
Map<String, String> map = BaseTest.createInstance().getMap(name);
|
|
||||||
Assert.assertEquals(size, map.size());
|
|
||||||
clear(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMultiPut_SingleInstance() throws InterruptedException {
|
|
||||||
final String name = "testMultiPut_SingleInstance";
|
|
||||||
testSingleInstanceConcurrency(100, r -> {
|
|
||||||
Map<String, String> map = r.getMap(name);
|
|
||||||
map.put("" + Math.random(), "1");
|
|
||||||
});
|
|
||||||
|
|
||||||
assertMapSize(100, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMultiPut_MultiInstance() throws InterruptedException {
|
|
||||||
final String name = "testMultiPut_MultiInstance";
|
|
||||||
testMultiInstanceConcurrency(100, r -> {
|
|
||||||
ConcurrentMap<String, String> map = r.getMap(name);
|
|
||||||
map.putIfAbsent("" + Math.random(), "1");
|
|
||||||
});
|
|
||||||
|
|
||||||
assertMapSize(100, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void clear(Map<?, ?> map) {
|
|
||||||
map.clear();
|
|
||||||
Assert.assertEquals(0, map.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue