use of redis.clients.jedis.Transaction in project jedis by redis.
the class TransactionCommandsTest method testResetStateWithFullyExecutedTransaction.
@Test
public void testResetStateWithFullyExecutedTransaction() {
Jedis jedis2 = createJedis();
jedis2.auth("foobared");
Transaction t = jedis2.multi();
t.set("mykey", "foo");
t.get("mykey");
List<Object> resp = t.exec();
assertNotNull(resp);
assertEquals(2, resp.size());
jedis2.resetState();
jedis2.close();
}
use of redis.clients.jedis.Transaction in project jedis by redis.
the class TransactionCommandsTest method multi.
@Test
public void multi() {
Transaction trans = jedis.multi();
trans.sadd("foo", "a");
trans.sadd("foo", "b");
trans.scard("foo");
List<Object> response = trans.exec();
List<Object> expected = new ArrayList<Object>();
expected.add(1L);
expected.add(1L);
expected.add(2L);
assertEquals(expected, response);
// Binary
trans = jedis.multi();
trans.sadd(bfoo, ba);
trans.sadd(bfoo, bb);
trans.scard(bfoo);
response = trans.exec();
expected = new ArrayList<Object>();
expected.add(1L);
expected.add(1L);
expected.add(2L);
assertEquals(expected, response);
}
use of redis.clients.jedis.Transaction in project jedis by redis.
the class TransactionCommandsTest method execFail.
@Test
public void execFail() {
Transaction trans = jedis.multi();
trans.set("a", "a");
trans.set("b", "b");
try (MockedStatic<Protocol> protocol = Mockito.mockStatic(Protocol.class)) {
protocol.when(() -> Protocol.read(any())).thenThrow(JedisConnectionException.class);
trans.exec();
fail("Should get mocked JedisConnectionException.");
} catch (JedisConnectionException jce) {
// should be here
} finally {
// close() should pass
trans.close();
}
assertTrue(jedis.isBroken());
}
use of redis.clients.jedis.Transaction in project jedis by redis.
the class TransactionCommandsTest method testResetStateWhenInWatch.
//
// @Test
// public void testResetStateWhenInMultiWithinPipeline() {
// Pipeline p = jedis.pipelined();
// p.multi();
// p.set("foooo", "barrr");
//
// jedis.resetState();
// assertNull(jedis.get("foooo"));
// }
@Test
public void testResetStateWhenInWatch() {
jedis.watch("mykey", "somekey");
// state reset : unwatch
jedis.resetState();
Transaction t = jedis.multi();
nj.set("mykey", "bar");
t.set("mykey", "foo");
List<Object> resp = t.exec();
assertNotNull(resp);
assertEquals(1, resp.size());
assertEquals("foo", jedis.get("mykey"));
}
use of redis.clients.jedis.Transaction in project jedis by redis.
the class TransactionCommandsTest method transactionResponseWithinPipeline.
@Test(expected = IllegalStateException.class)
public void transactionResponseWithinPipeline() {
jedis.set("string", "foo");
Transaction t = jedis.multi();
Response<String> string = t.get("string");
string.get();
t.exec();
}
Aggregations