tests fixes

pull/243/head
Nikita 10 years ago
parent 2464df938d
commit 2219b692bc

@ -134,10 +134,10 @@ public class RedissonCountDownLatchTest extends BaseTest {
Assert.assertTrue(latch.delete());
}
@Test(expected = IllegalStateException.class)
@Test
public void testDeleteFailed() throws Exception {
RCountDownLatch latch = redisson.getCountDownLatch("latch");
Assert.assertTrue(latch.delete());
Assert.assertFalse(latch.delete());
}
@Test

@ -1,32 +1,40 @@
package org.redisson;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import org.redisson.core.RList;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
public class RedissonListTest extends BaseTest {
@Test
public void testAddAllAsync() {
public void testAddAllAsync() throws InterruptedException {
final RList<Long> list = redisson.getList("list");
list.addAllAsync(Arrays.asList(1L, 2L, 3L)).addListener(new FutureListener<Boolean>() {
@Override
public void operationComplete(Future<Boolean> future) throws Exception {
list.addAllAsync(Arrays.asList(1L, 24L, 3L));
}
});
}).awaitUninterruptibly();
Thread.sleep(1000);
Assert.assertThat(list, Matchers.contains(1L, 2L, 3L, 1L, 24L, 3L));
}
@Test
public void testAddAsync() {
public void testAddAsync() throws InterruptedException {
final RList<Long> list = redisson.getList("list");
list.addAsync(1L).addListener(new FutureListener<Boolean>() {
@Override
@ -35,9 +43,11 @@ public class RedissonListTest extends BaseTest {
}
}).awaitUninterruptibly();
Thread.sleep(1000);
Assert.assertThat(list, Matchers.contains(1L, 2L));
}
@Test
public void testLong() {
List<Long> list = redisson.getList("list");

@ -5,30 +5,12 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.redisson.core.RLock;
public class RedissonLockTest extends BaseConcurrentTest {
Redisson redisson;
@Before
public void before() {
redisson = BaseTest.createInstance();
}
@After
public void after() {
try {
redisson.flushdb();
} finally {
redisson.shutdown();
}
}
@Test
public void testForceUnlock() {
RLock lock = redisson.getLock("lock");
@ -62,6 +44,7 @@ public class RedissonLockTest extends BaseConcurrentTest {
lock.unlock();
}
@Test
public void testAutoExpire() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);

@ -9,23 +9,22 @@ import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import org.redisson.client.RedisException;
import org.redisson.core.RScript;
import com.lambdaworks.redis.RedisException;
public class RedissonScriptTest extends BaseTest {
@Test
public void testEval() {
RScript script = redisson.getScript();
List<Object> res = script.eval("return {1,2,3.3333,'foo',nil,'bar'}", RScript.ReturnType.MULTI, Collections.emptyList());
List<Object> res = script.eval("return {1,2,3.3333,'\"foo\"',nil,'bar'}", RScript.ReturnType.MULTI, Collections.emptyList());
MatcherAssert.assertThat(res, Matchers.<Object>contains(1L, 2L, 3L, "foo"));
}
@Test
public void testEvalAsync() {
RScript script = redisson.getScript();
Future<List<Object>> res = script.evalAsync("return {1,2,3.3333,'foo',nil,'bar'}", RScript.ReturnType.MULTI, Collections.emptyList());
Future<List<Object>> res = script.evalAsync("return {1,2,3.3333,'\"foo\"',nil,'bar'}", RScript.ReturnType.MULTI, Collections.emptyList());
MatcherAssert.assertThat(res.awaitUninterruptibly().getNow(), Matchers.<Object>contains(1L, 2L, 3L, "foo"));
}
@ -34,18 +33,18 @@ public class RedissonScriptTest extends BaseTest {
RScript s = redisson.getScript();
String r = s.scriptLoad("return redis.call('get', 'foo')");
Assert.assertEquals("282297a0228f48cd3fc6a55de6316f31422f5d17", r);
List<Boolean> r1 = s.scriptExists(r);
Assert.assertEquals(1, r1.size());
Assert.assertTrue(r1.get(0));
s.scriptFlush();
List<Boolean> r2 = s.scriptExists(r);
Assert.assertEquals(1, r2.size());
Assert.assertFalse(r2.get(0));
}
@Test
public void testScriptFlush() {
redisson.getBucket("foo").set("bar");
@ -53,15 +52,15 @@ public class RedissonScriptTest extends BaseTest {
Assert.assertEquals("282297a0228f48cd3fc6a55de6316f31422f5d17", r);
String r1 = redisson.getScript().evalSha("282297a0228f48cd3fc6a55de6316f31422f5d17", RScript.ReturnType.VALUE, Collections.emptyList());
Assert.assertEquals("bar", r1);
String r2 = redisson.getScript().scriptFlush();
Assert.assertEquals("OK", r2);
Boolean r2 = redisson.getScript().scriptFlush();
Assert.assertTrue(r2);
try {
redisson.getScript().evalSha("282297a0228f48cd3fc6a55de6316f31422f5d17", RScript.ReturnType.VALUE, Collections.emptyList());
} catch (Exception e) {
Assert.assertEquals(RedisException.class, e.getClass());
}
}
@Test
public void testScriptLoad() {
redisson.getBucket("foo").set("bar");
@ -70,7 +69,7 @@ public class RedissonScriptTest extends BaseTest {
String r1 = redisson.getScript().evalSha("282297a0228f48cd3fc6a55de6316f31422f5d17", RScript.ReturnType.VALUE, Collections.emptyList());
Assert.assertEquals("bar", r1);
}
@Test
public void testScriptLoadAsync() {
redisson.getBucket("foo").set("bar");
@ -79,7 +78,7 @@ public class RedissonScriptTest extends BaseTest {
String r1 = redisson.getScript().evalSha("282297a0228f48cd3fc6a55de6316f31422f5d17", RScript.ReturnType.VALUE, Collections.emptyList());
Assert.assertEquals("bar", r1);
}
@Test
public void testEvalSha() {
redisson.getBucket("foo").set("bar");
@ -88,7 +87,7 @@ public class RedissonScriptTest extends BaseTest {
String r1 = redisson.getScript().evalSha("282297a0228f48cd3fc6a55de6316f31422f5d17", RScript.ReturnType.VALUE, Collections.emptyList());
Assert.assertEquals("bar", r1);
}
@Test
public void testEvalshaAsync() {
redisson.getBucket("foo").set("bar");
@ -98,5 +97,5 @@ public class RedissonScriptTest extends BaseTest {
Assert.assertEquals("bar", r1.awaitUninterruptibly().getNow());
}
}

Loading…
Cancel
Save