Merge pull request #537 from HeartSaVioR/deprecated_transactionblock_and_pipelineblock
Mark @Duplicated to TransactionBlock and PipelineBlock related classes / methods
This commit is contained in:
@@ -15,7 +15,6 @@ import org.junit.Test;
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
import redis.clients.jedis.PipelineBlock;
|
||||
import redis.clients.jedis.Response;
|
||||
import redis.clients.jedis.Tuple;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
@@ -35,21 +34,10 @@ public class PipeliningTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void pipeline() throws UnsupportedEncodingException {
|
||||
List<Object> results = jedis.pipelined(new PipelineBlock() {
|
||||
public void execute() {
|
||||
set("foo", "bar");
|
||||
get("foo");
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(2, results.size());
|
||||
assertEquals("OK", results.get(0));
|
||||
assertEquals("bar", results.get(1));
|
||||
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.set("foo", "bar");
|
||||
p.get("foo");
|
||||
results = p.syncAndReturnAll();
|
||||
List<Object> results = p.syncAndReturnAll();
|
||||
|
||||
assertEquals(2, results.size());
|
||||
assertEquals("OK", results.get(0));
|
||||
|
||||
@@ -16,9 +16,7 @@ import redis.clients.jedis.Pipeline;
|
||||
import redis.clients.jedis.Protocol.Keyword;
|
||||
import redis.clients.jedis.Response;
|
||||
import redis.clients.jedis.Transaction;
|
||||
import redis.clients.jedis.TransactionBlock;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
|
||||
public class TransactionCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
@@ -73,87 +71,6 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiBlock() {
|
||||
List<Object> response = jedis.multi(new TransactionBlock() {
|
||||
@Override
|
||||
public void execute() {
|
||||
sadd("foo", "a");
|
||||
sadd("foo", "b");
|
||||
scard("foo");
|
||||
}
|
||||
});
|
||||
|
||||
List<Object> expected = new ArrayList<Object>();
|
||||
expected.add(1L);
|
||||
expected.add(1L);
|
||||
expected.add(2L);
|
||||
assertEquals(expected, response);
|
||||
|
||||
// Binary
|
||||
response = jedis.multi(new TransactionBlock() {
|
||||
@Override
|
||||
public void execute() {
|
||||
sadd(bfoo, ba);
|
||||
sadd(bfoo, bb);
|
||||
scard(bfoo);
|
||||
}
|
||||
});
|
||||
|
||||
expected = new ArrayList<Object>();
|
||||
expected.add(1L);
|
||||
expected.add(1L);
|
||||
expected.add(2L);
|
||||
assertEquals(expected, response);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiBlockWithErrorRedisDiscardsTransaction() throws Exception {
|
||||
// Transaction with error - Redis discards transaction automatically
|
||||
// (Syntax Error, etc.)
|
||||
TransactionBlock tb = new TransactionBlock() {
|
||||
|
||||
@Override
|
||||
public void execute() throws JedisException {
|
||||
del("hello");
|
||||
hmset("hello", new HashMap<String, String>());
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
jedis.multi(tb);
|
||||
} catch (JedisDataException e) {
|
||||
assertTrue(e.getMessage().contains("EXECABORT"));
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiBlockWithErrorRedisForceToExecuteAllCommands()
|
||||
throws Exception {
|
||||
// Transaction with error - Redis doesn't roll back (Type Error,
|
||||
// Deletion of non-exist key, etc.)
|
||||
jedis.del("hello2");
|
||||
TransactionBlock tb2 = new TransactionBlock() {
|
||||
|
||||
@Override
|
||||
public void execute() throws JedisException {
|
||||
del("hello2");
|
||||
set("hello2", "hello");
|
||||
sadd("hello2", "hello2");
|
||||
}
|
||||
};
|
||||
|
||||
List<Object> responses = jedis.multi(tb2);
|
||||
assertEquals("OK", responses.get(1));
|
||||
assertEquals(JedisDataException.class, responses.get(2).getClass());
|
||||
|
||||
Exception exc = (JedisDataException) responses.get(2);
|
||||
assertTrue(exc.getMessage().contains("WRONGTYPE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void watch() throws UnknownHostException, IOException {
|
||||
jedis.watch("mykey", "somekey");
|
||||
|
||||
Reference in New Issue
Block a user