Search in sources :

Example 11 with JedisDataException

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"));
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisDataException(redis.clients.jedis.exceptions.JedisDataException)

Example 12 with JedisDataException

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");
}
Also used : JedisDataException(redis.clients.jedis.exceptions.JedisDataException) JedisDataException(redis.clients.jedis.exceptions.JedisDataException) IOException(java.io.IOException) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 13 with JedisDataException

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);
}
Also used : GeodeRedisServer(org.apache.geode.redis.GeodeRedisServer) CacheFactory(org.apache.geode.cache.CacheFactory) JedisDataException(redis.clients.jedis.exceptions.JedisDataException) JedisDataException(redis.clients.jedis.exceptions.JedisDataException) IOException(java.io.IOException) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 14 with JedisDataException

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();
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisDataException(redis.clients.jedis.exceptions.JedisDataException) JedisDataException(redis.clients.jedis.exceptions.JedisDataException) IOException(java.io.IOException) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 15 with JedisDataException

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();
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisDataException(redis.clients.jedis.exceptions.JedisDataException) Test(org.junit.Test)

Aggregations

JedisDataException (redis.clients.jedis.exceptions.JedisDataException)46 Jedis (redis.clients.jedis.Jedis)27 Test (org.junit.Test)20 Pipeline (redis.clients.jedis.Pipeline)6 Transaction (redis.clients.jedis.Transaction)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)4 List (java.util.List)3 Set (java.util.Set)3 Logger (org.apache.log4j.Logger)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Response (redis.clients.jedis.Response)2 QueryRedisClusterDetailResponse (beans.response.QueryRedisClusterDetailResponse)1 ObjectInput (com.alibaba.dubbo.common.serialize.ObjectInput)1 ObjectOutput (com.alibaba.dubbo.common.serialize.ObjectOutput)1 Invocation (com.alibaba.dubbo.rpc.Invocation)1 RpcException (com.alibaba.dubbo.rpc.RpcException)1