Search in sources :

Example 31 with JedisDataException

use of redis.clients.jedis.exceptions.JedisDataException in project jedis by xetorthio.

the class TransactionCommandsTest method execGetResponse.

@Test
public void execGetResponse() {
    Transaction t = jedis.multi();
    t.set("foo", "bar");
    t.smembers("foo");
    t.get("foo");
    List<Response<?>> lr = t.execGetResponse();
    try {
        lr.get(1).get();
        fail("We expect exception here!");
    } catch (JedisDataException e) {
    // that is fine we should be here
    }
    assertEquals("bar", lr.get(2).get());
}
Also used : Response(redis.clients.jedis.Response) Transaction(redis.clients.jedis.Transaction) JedisDataException(redis.clients.jedis.exceptions.JedisDataException) Test(org.junit.Test)

Example 32 with JedisDataException

use of redis.clients.jedis.exceptions.JedisDataException in project jedis by xetorthio.

the class TransactionCommandsTest method transactionResponseWithError.

@Test
public void transactionResponseWithError() {
    Transaction t = jedis.multi();
    t.set("foo", "bar");
    Response<Set<String>> error = t.smembers("foo");
    Response<String> r = t.get("foo");
    List<Object> l = t.exec();
    assertEquals(JedisDataException.class, l.get(1).getClass());
    try {
        error.get();
        fail("We expect exception here!");
    } catch (JedisDataException e) {
    // that is fine we should be here
    }
    assertEquals(r.get(), "bar");
}
Also used : Set(java.util.Set) Transaction(redis.clients.jedis.Transaction) JedisDataException(redis.clients.jedis.exceptions.JedisDataException) Test(org.junit.Test)

Example 33 with JedisDataException

use of redis.clients.jedis.exceptions.JedisDataException in project jedis by xetorthio.

the class PipeliningTest method testCloseableWithMulti.

@Test
public void testCloseableWithMulti() throws IOException {
    // we need to test with fresh instance of Jedis
    Jedis jedis2 = new Jedis(hnp.getHost(), hnp.getPort(), 500);
    jedis2.auth("foobared");
    Pipeline pipeline = jedis2.pipelined();
    Response<String> retFuture1 = pipeline.set("a", "1");
    Response<String> retFuture2 = pipeline.set("b", "2");
    pipeline.multi();
    pipeline.set("a", "a");
    pipeline.set("b", "b");
    pipeline.close();
    try {
        pipeline.exec();
        fail("close should discard transaction");
    } catch (JedisDataException e) {
        assertTrue(e.getMessage().contains("EXEC without MULTI"));
    // pass
    }
    // it shouldn't meet any exception
    retFuture1.get();
    retFuture2.get();
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisDataException(redis.clients.jedis.exceptions.JedisDataException) Pipeline(redis.clients.jedis.Pipeline) Test(org.junit.Test)

Example 34 with JedisDataException

use of redis.clients.jedis.exceptions.JedisDataException in project jedis by xetorthio.

the class PipeliningTest method piplineWithError.

@Test
public void piplineWithError() {
    Pipeline p = jedis.pipelined();
    p.set("foo", "bar");
    Response<Set<String>> error = p.smembers("foo");
    Response<String> r = p.get("foo");
    p.sync();
    try {
        error.get();
        fail();
    } catch (JedisDataException e) {
    // that is fine we should be here
    }
    assertEquals(r.get(), "bar");
}
Also used : Set(java.util.Set) JedisDataException(redis.clients.jedis.exceptions.JedisDataException) Pipeline(redis.clients.jedis.Pipeline) Test(org.junit.Test)

Example 35 with JedisDataException

use of redis.clients.jedis.exceptions.JedisDataException in project jedis by xetorthio.

the class JedisSentinelTest method sentinelRemove.

@Test
public void sentinelRemove() {
    Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort());
    try {
        ensureMonitored(sentinel, REMOVE_MASTER_NAME, MASTER_IP, master.getPort(), 1);
        String result = j.sentinelRemove(REMOVE_MASTER_NAME);
        assertEquals("OK", result);
        // not exist
        try {
            result = j.sentinelRemove(REMOVE_MASTER_NAME);
            assertNotEquals("OK", result);
            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