提交 79a7ead8 编写于 作者: N Nikita Koksharov

refactoring

上级 6025bab1
......@@ -8,6 +8,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;
import org.redisson.RedisRunner.FailedToStartRedisException;
import org.redisson.RedisRunner.RedisProcess;
......@@ -19,6 +20,7 @@ public class RedissonBucketTest extends BaseTest {
@Test
public void testSizeInMemory() {
Assume.assumeTrue(RedisRunner.getDefaultRedisServerInstance().getRedisVersion().compareTo("4.0.0") > 0);
RBucket<Integer> al = redisson.getBucket("test");
al.set(1234);
assertThat(al.sizeInMemory()).isEqualTo(55);
......
......@@ -15,6 +15,9 @@ import java.util.concurrent.ExecutionException;
import org.junit.Assert;
import org.junit.Test;
import org.redisson.api.RMapReactive;
import org.redisson.client.codec.DoubleCodec;
import org.redisson.client.codec.IntegerCodec;
import org.redisson.codec.CompositeCodec;
public class RedissonMapReactiveTest extends BaseReactiveTest {
......@@ -122,7 +125,7 @@ public class RedissonMapReactiveTest extends BaseReactiveTest {
@Test
public void testAddAndGet() throws InterruptedException {
RMapReactive<Integer, Integer> map = redisson.getMap("getAll");
RMapReactive<Integer, Integer> map = redisson.getMap("getAll", new CompositeCodec(redisson.getConfig().getCodec(), IntegerCodec.INSTANCE));
sync(map.put(1, 100));
Integer res = sync(map.addAndGet(1, 12));
......@@ -130,7 +133,7 @@ public class RedissonMapReactiveTest extends BaseReactiveTest {
res = sync(map.get(1));
Assert.assertEquals(112, (int)res);
RMapReactive<Integer, Double> map2 = redisson.getMap("getAll2");
RMapReactive<Integer, Double> map2 = redisson.getMap("getAll2", new CompositeCodec(redisson.getConfig().getCodec(), DoubleCodec.INSTANCE));
sync(map2.put(1, new Double(100.2)));
Double res2 = sync(map2.addAndGet(1, new Double(12.1)));
......@@ -138,7 +141,7 @@ public class RedissonMapReactiveTest extends BaseReactiveTest {
res2 = sync(map2.get(1));
Assert.assertTrue(new Double(112.3).compareTo(res2) == 0);
RMapReactive<String, Integer> mapStr = redisson.getMap("mapStr");
RMapReactive<String, Integer> mapStr = redisson.getMap("mapStr", new CompositeCodec(redisson.getConfig().getCodec(), IntegerCodec.INSTANCE));
assertThat(sync(mapStr.put("1", 100))).isNull();
assertThat(sync(mapStr.addAndGet("1", 12))).isEqualTo(112);
......
......@@ -102,7 +102,7 @@ public class RedissonPriorityBlockingDequeTest extends BaseTest {
long s = System.currentTimeMillis();
assertThat(queue1.pollFirst(5, TimeUnit.SECONDS)).isNull();
assertThat(System.currentTimeMillis() - s).isGreaterThan(5000);
assertThat(System.currentTimeMillis() - s).isGreaterThan(4900);
}
@Test
......
......@@ -9,7 +9,7 @@ import java.util.Locale;
public class RedissonRuntimeEnvironment {
public static final boolean isTravis = "true".equalsIgnoreCase(System.getProperty("travisEnv"));
public static final String redisBinaryPath = System.getProperty("redisBinary", "C:\\Devel\\projects\\redis\\redis-x64-4.0.2.2\\redis-server.exe");
public static final String redisBinaryPath = System.getProperty("redisBinary", "C:\\Devel\\projects\\redis\\Redis-x64-3.2.100\\redis-server.exe");
public static final String tempDir = System.getProperty("java.io.tmpdir");
public static final String OS;
public static final boolean isWindows;
......
......@@ -9,15 +9,17 @@ import org.junit.Assert;
import org.junit.Test;
import org.redisson.api.RScript;
import org.redisson.api.RScriptReactive;
import org.redisson.api.RScriptRx;
import org.redisson.client.RedisException;
import org.redisson.client.codec.StringCodec;
public class RedissonScriptReactiveTest extends BaseReactiveTest {
@Test
public void testEval() {
RScriptReactive script = redisson.getScript();
List<Object> res = sync(script.<List<Object>>eval(RScript.Mode.READ_ONLY, "return {1,2,3.3333,'\"foo\"',nil,'bar'}", RScript.ReturnType.MULTI, Collections.emptyList()));
assertThat(res).containsExactly(1L, 2L, 3L, "foo");
RScriptReactive script = redisson.getScript(StringCodec.INSTANCE);
List<Object> res = sync(script.eval(RScript.Mode.READ_ONLY, "return {'1','2','3.3333','foo',nil,'bar'}", RScript.ReturnType.MULTI, Collections.emptyList()));
assertThat(res).containsExactly("1", "2", "3.3333", "foo");
}
@Test
......
......@@ -31,7 +31,6 @@ public class RedissonScriptTest extends BaseTest {
l = l + 1;
}
StringCodec codec = new StringCodec();
String max = "'[DENY" + "\t" + "TESTREDISSON" + "\t" + "1506524856099'";
String min = "'[DENY" + "\t" + "TESTREDISSON" + "\t" + "1506524856000'";
String luaScript1= "local d = {}; d[1] = redis.call('zrevrangebylex','ABCD17436'," +max+","+min+",'LIMIT',0,5); ";
......@@ -39,15 +38,14 @@ public class RedissonScriptTest extends BaseTest {
luaScript1= luaScript1 + " d[3] = redis.call('zrevrangebylex','ABCD17436'," +max+","+min+",'LIMIT',0,25); ";
luaScript1 = luaScript1 + " return d;";
Future<Object> r1 = redisson.getScript().evalAsync(RScript.Mode.READ_ONLY, codec,
List<List<Object>> objs = redisson.getScript(StringCodec.INSTANCE).eval(RScript.Mode.READ_ONLY,
luaScript1,
RScript.ReturnType.MULTI, Collections.emptyList());
List<List<Object>> obj1 = (List<List<Object>>) r1.get();
assertThat(obj1).hasSize(3);
assertThat(obj1.get(0)).hasSize(5);
assertThat(obj1.get(1)).hasSize(15);
assertThat(obj1.get(2)).hasSize(25);
assertThat(objs).hasSize(3);
assertThat(objs.get(0)).hasSize(5);
assertThat(objs.get(1)).hasSize(15);
assertThat(objs.get(2)).hasSize(25);
}
@Test
......
......@@ -433,7 +433,7 @@ public class RedissonTest {
System.out.println("master " + master.getRedisServerAddressAndPort() + " has been stopped!");
Thread.sleep(TimeUnit.SECONDS.toMillis(20));
Thread.sleep(TimeUnit.SECONDS.toMillis(30));
RedisProcess newMaster = null;
Collection<ClusterNode> newMasterNodes = redisson.getClusterNodesGroup().getNodes(NodeType.MASTER);
......
......@@ -3,6 +3,7 @@ package org.redisson;
import static org.awaitility.Awaitility.await;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
......@@ -28,7 +29,7 @@ import org.redisson.config.Config;
public class RedissonTopicPatternTest extends BaseTest {
public static class Message {
public static class Message implements Serializable {
private String name;
......
......@@ -18,6 +18,7 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.awaitility.Duration;
import org.junit.After;
......@@ -151,7 +152,9 @@ public class RedissonTopicTest {
CountDownLatch latch = new CountDownLatch(count);
RTopic eventsTopic = redisson.getTopic("eventsTopic");
AtomicInteger co = new AtomicInteger();
eventsTopic.addListener(String.class, (channel, msg) -> {
co.incrementAndGet();
latch.countDown();
});
......@@ -161,7 +164,7 @@ public class RedissonTopicTest {
Thread.sleep(10);
}
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(latch.await(40, TimeUnit.SECONDS)).isTrue();
redisson.shutdown();
}
......@@ -201,7 +204,7 @@ public class RedissonTopicTest {
futures.add(s);
}
executor.shutdown();
Assert.assertTrue(executor.awaitTermination(threads * loops * 1000, TimeUnit.SECONDS));
Assert.assertTrue(executor.awaitTermination(100, TimeUnit.SECONDS));
for (Future<?> future : futures) {
future.get();
......@@ -561,18 +564,17 @@ public class RedissonTopicTest {
redisson2.shutdown();
}
volatile long counter;
@Test
public void testHeavyLoad() throws InterruptedException {
final CountDownLatch messageRecieved = new CountDownLatch(1000);
AtomicLong counter = new AtomicLong();
RedissonClient redisson1 = BaseTest.createInstance();
RTopic topic1 = redisson1.getTopic("topic");
topic1.addListener(Message.class, (channel, msg) -> {
Assert.assertEquals(new Message("123"), msg);
messageRecieved.countDown();
counter++;
counter.incrementAndGet();
});
RedissonClient redisson2 = BaseTest.createInstance();
......@@ -582,7 +584,8 @@ public class RedissonTopicTest {
messageRecieved.countDown();
});
for (int i = 0; i < 5000; i++) {
int count = 10000;
for (int i = 0; i < count; i++) {
topic2.publish(new Message("123"));
}
......@@ -590,7 +593,7 @@ public class RedissonTopicTest {
Thread.sleep(1000);
Assert.assertEquals(5000, counter);
Assert.assertEquals(count, counter.get());
redisson1.shutdown();
redisson2.shutdown();
......
......@@ -15,6 +15,9 @@ import java.util.concurrent.ExecutionException;
import org.junit.Assert;
import org.junit.Test;
import org.redisson.api.RMapRx;
import org.redisson.client.codec.DoubleCodec;
import org.redisson.client.codec.IntegerCodec;
import org.redisson.codec.CompositeCodec;
public class RedissonMapRxTest extends BaseRxTest {
......@@ -122,7 +125,7 @@ public class RedissonMapRxTest extends BaseRxTest {
@Test
public void testAddAndGet() throws InterruptedException {
RMapRx<Integer, Integer> map = redisson.getMap("getAll");
RMapRx<Integer, Integer> map = redisson.getMap("getAll", new CompositeCodec(redisson.getConfig().getCodec(), IntegerCodec.INSTANCE));
sync(map.put(1, 100));
Integer res = sync(map.addAndGet(1, 12));
......@@ -130,7 +133,7 @@ public class RedissonMapRxTest extends BaseRxTest {
res = sync(map.get(1));
Assert.assertEquals(112, (int)res);
RMapRx<Integer, Double> map2 = redisson.getMap("getAll2");
RMapRx<Integer, Double> map2 = redisson.getMap("getAll2", new CompositeCodec(redisson.getConfig().getCodec(), DoubleCodec.INSTANCE));
sync(map2.put(1, new Double(100.2)));
Double res2 = sync(map2.addAndGet(1, new Double(12.1)));
......@@ -138,7 +141,7 @@ public class RedissonMapRxTest extends BaseRxTest {
res2 = sync(map2.get(1));
Assert.assertTrue(new Double(112.3).compareTo(res2) == 0);
RMapRx<String, Integer> mapStr = redisson.getMap("mapStr");
RMapRx<String, Integer> mapStr = redisson.getMap("mapStr", new CompositeCodec(redisson.getConfig().getCodec(), IntegerCodec.INSTANCE));
assertThat(sync(mapStr.put("1", 100))).isNull();
assertThat(sync(mapStr.addAndGet("1", 12))).isEqualTo(112);
......
......@@ -10,14 +10,15 @@ import org.junit.Test;
import org.redisson.api.RScript;
import org.redisson.api.RScriptRx;
import org.redisson.client.RedisException;
import org.redisson.client.codec.StringCodec;
public class RedissonScriptRxTest extends BaseRxTest {
@Test
public void testEval() {
RScriptRx script = redisson.getScript();
List<Object> res = sync(script.<List<Object>>eval(RScript.Mode.READ_ONLY, "return {1,2,3.3333,'\"foo\"',nil,'bar'}", RScript.ReturnType.MULTI, Collections.emptyList()));
assertThat(res).containsExactly(1L, 2L, 3L, "foo");
RScriptRx script = redisson.getScript(StringCodec.INSTANCE);
List<Object> res = sync(script.eval(RScript.Mode.READ_ONLY, "return {'1','2','3.3333','foo',nil,'bar'}", RScript.ReturnType.MULTI, Collections.emptyList()));
assertThat(res).containsExactly("1", "2", "3.3333", "foo");
}
@Test
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册