use of redis.clients.jedis.exceptions.JedisDataException in project ignite by apache.
the class RedisProtocolSelfTest method testStrlen.
/**
* @throws Exception If failed.
*/
public void testStrlen() throws Exception {
try (Jedis jedis = pool.getResource()) {
Assert.assertEquals(0, (long) jedis.strlen("strlenKeyNonExisting"));
jcache().put("strlenKey", "abc");
Assert.assertEquals(3, (long) jedis.strlen("strlenKey"));
jcache().put("setDataTypeKey", new HashSet<String>(Arrays.asList("1", "2")));
try {
jedis.strlen("setDataTypeKey");
assert false : "Exception has to be thrown!";
} catch (JedisDataException e) {
assertTrue(e.getMessage().startsWith("WRONGTYPE"));
}
}
}
use of redis.clients.jedis.exceptions.JedisDataException in project ignite by apache.
the class RedisProtocolStringSelfTest method testIncrDecr.
/**
* @throws Exception If failed.
*/
public void testIncrDecr() throws Exception {
try (Jedis jedis = pool.getResource()) {
Assert.assertEquals(1, (long) jedis.incr("newKeyIncr"));
Assert.assertEquals(-1, (long) jedis.decr("newKeyDecr"));
Assert.assertEquals("1", jedis.get("newKeyIncr"));
Assert.assertEquals("-1", jedis.get("newKeyDecr"));
Assert.assertEquals(1, (long) jedis.incr("incrKey1"));
jedis.set("incrKey1", "10");
Assert.assertEquals(11L, (long) jedis.incr("incrKey1"));
jedis.set("decrKey1", "10");
Assert.assertEquals(9L, (long) jedis.decr("decrKey1"));
jedis.set("nonInt", "abc");
try {
jedis.incr("nonInt");
assert false : "Exception has to be thrown!";
} catch (JedisDataException e) {
assertTrue(e.getMessage().startsWith("ERR"));
}
try {
jedis.decr("nonInt");
assert false : "Exception has to be thrown!";
} catch (JedisDataException e) {
assertTrue(e.getMessage().startsWith("ERR"));
}
jedis.set("outOfRangeIncr1", "9223372036854775808");
try {
jedis.incr("outOfRangeIncr1");
assert false : "Exception has to be thrown!";
} catch (JedisDataException e) {
assertTrue(e.getMessage().startsWith("ERR"));
}
jedis.set("outOfRangeDecr1", "-9223372036854775809");
try {
jedis.decr("outOfRangeDecr1");
assert false : "Exception has to be thrown!";
} catch (JedisDataException e) {
assertTrue(e.getMessage().startsWith("ERR"));
}
jedis.set("outOfRangeInc2", String.valueOf(Long.MAX_VALUE));
try {
jedis.incr("outOfRangeInc2");
assert false : "Exception has to be thrown!";
} catch (JedisDataException e) {
assertTrue(e.getMessage().startsWith("ERR"));
}
jedis.set("outOfRangeDecr2", String.valueOf(Long.MIN_VALUE));
try {
jedis.decr("outOfRangeDecr2");
assert false : "Exception has to be thrown!";
} catch (JedisDataException e) {
assertTrue(e.getMessage().startsWith("ERR"));
}
}
}
use of redis.clients.jedis.exceptions.JedisDataException in project ignite by apache.
the class RedisProtocolStringSelfTest method testGet.
/**
* @throws Exception If failed.
*/
public void testGet() throws Exception {
try (Jedis jedis = pool.getResource()) {
jcache().put("getKey1", "getVal1");
Assert.assertEquals("getVal1", jedis.get("getKey1"));
Assert.assertNull(jedis.get("wrongKey"));
jcache().put("setDataTypeKey", new HashSet<String>(Arrays.asList("1", "2")));
try {
jedis.get("setDataTypeKey");
assert false : "Exception has to be thrown!";
} catch (JedisDataException e) {
assertTrue(e.getMessage().startsWith("WRONGTYPE"));
}
}
}
use of redis.clients.jedis.exceptions.JedisDataException in project ignite by apache.
the class RedisProtocolStringSelfTest method testIncrDecrBy.
/**
* @throws Exception If failed.
*/
public void testIncrDecrBy() throws Exception {
try (Jedis jedis = pool.getResource()) {
Assert.assertEquals(2, (long) jedis.incrBy("newKeyIncrBy", 2));
Assert.assertEquals(-2, (long) jedis.decrBy("newKeyDecrBy", 2));
jedis.set("incrDecrKeyBy", "1");
Assert.assertEquals(11L, (long) jedis.incrBy("incrDecrKeyBy", 10));
Assert.assertEquals(9L, (long) jedis.decrBy("incrDecrKeyBy", 2));
jedis.set("outOfRangeIncrBy", "1");
try {
jedis.incrBy("outOfRangeIncrBy", Long.MAX_VALUE);
assert false : "Exception has to be thrown!";
} catch (JedisDataException e) {
assertTrue(e.getMessage().startsWith("ERR"));
}
jedis.set("outOfRangeDecrBy", "-1");
try {
jedis.decrBy("outOfRangeDecrBy", Long.MIN_VALUE);
assert false : "Exception has to be thrown!";
} catch (JedisDataException e) {
assertTrue(e.getMessage().startsWith("ERR"));
}
jedis.set("outOfRangeIncBy2", String.valueOf(Long.MAX_VALUE));
try {
jedis.incrBy("outOfRangeIncBy2", Long.MAX_VALUE);
assert false : "Exception has to be thrown!";
} catch (JedisDataException e) {
assertTrue(e.getMessage().startsWith("ERR"));
}
jedis.set("outOfRangeDecrBy2", String.valueOf(Long.MIN_VALUE));
try {
jedis.decrBy("outOfRangeDecrBy2", Long.MIN_VALUE);
assert false : "Exception has to be thrown!";
} catch (JedisDataException e) {
assertTrue(e.getMessage().startsWith("ERR"));
}
}
}
use of redis.clients.jedis.exceptions.JedisDataException in project ignite by apache.
the class RedisProtocolStringSelfTest method testAppend.
/**
* @throws Exception If failed.
*/
public void testAppend() throws Exception {
try (Jedis jedis = pool.getResource()) {
Assert.assertEquals(5, (long) jedis.append("appendKey1", "Hello"));
Assert.assertEquals(12, (long) jedis.append("appendKey1", " World!"));
jcache().put("setDataTypeKey", new HashSet<String>(Arrays.asList("1", "2")));
try {
jedis.append("setDataTypeKey", "");
assert false : "Exception has to be thrown!";
} catch (JedisDataException e) {
assertTrue(e.getMessage().startsWith("WRONGTYPE"));
}
}
}
Aggregations