use of redis.clients.jedis.exceptions.JedisDataException in project ignite by apache.
the class RedisProtocolSelfTest 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 geode by apache.
the class AuthJUnitTest method testAuthRejectAccept.
@Test
public void testAuthRejectAccept() {
setupCacheWithPassword();
Exception ex = null;
try {
jedis.auth("wrongpwd");
} catch (JedisDataException e) {
ex = e;
}
assertNotNull(ex);
String res = jedis.auth(PASSWORD);
assertEquals(res, "OK");
}
use of redis.clients.jedis.exceptions.JedisDataException in project geode by apache.
the class AuthJUnitTest method testAuthNoPwd.
@Test
public void testAuthNoPwd() {
CacheFactory cf = new CacheFactory();
cf.set(LOG_LEVEL, "error");
cf.set(MCAST_PORT, "0");
cf.set(LOCATORS, "");
cache = cf.create();
server = new GeodeRedisServer("localhost", port);
server.start();
Exception ex = null;
try {
jedis.auth(PASSWORD);
} catch (JedisDataException e) {
ex = e;
}
assertNotNull(ex);
}
use of redis.clients.jedis.exceptions.JedisDataException in project geode by apache.
the class AuthJUnitTest method testSeparateClientRequests.
@Test
public void testSeparateClientRequests() {
setupCacheWithPassword();
Jedis authorizedJedis = null;
Jedis nonAuthorizedJedis = null;
try {
authorizedJedis = new Jedis("localhost", port, 100000);
nonAuthorizedJedis = new Jedis("localhost", port, 100000);
String res = authorizedJedis.auth(PASSWORD);
assertEquals(res, "OK");
// No exception for authorized client
authorizedJedis.set("foo", "bar");
authorizedJedis.auth(PASSWORD);
Exception ex = null;
try {
nonAuthorizedJedis.set("foo", "bar");
} catch (JedisDataException e) {
ex = e;
}
assertNotNull(ex);
} finally {
if (authorizedJedis != null)
authorizedJedis.close();
if (nonAuthorizedJedis != null)
nonAuthorizedJedis.close();
}
}
use of redis.clients.jedis.exceptions.JedisDataException in project cachecloud by sohutv.
the class JedisSentinelTest method sentinelMonitor.
@Test
public void sentinelMonitor() {
Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort());
try {
// monitor new master
String result = j.sentinelMonitor(MONITOR_MASTER_NAME, MASTER_IP, master.getPort(), 1);
assertEquals("OK", result);
// already monitored
try {
j.sentinelMonitor(MONITOR_MASTER_NAME, MASTER_IP, master.getPort(), 1);
fail();
} catch (JedisDataException e) {
// pass
}
} finally {
j.close();
}
}
Aggregations