Search in sources :

Example 1 with Protocol

use of redis.clients.jedis.Protocol 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());
}
Also used : Transaction(redis.clients.jedis.Transaction) Protocol(redis.clients.jedis.Protocol) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException) Test(org.junit.Test)

Example 2 with Protocol

use of redis.clients.jedis.Protocol in project jedis by xetorthio.

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

Example 3 with Protocol

use of redis.clients.jedis.Protocol in project jedis by xetorthio.

the class TransactionCommandsTest method discardFail.

@Test
public void discardFail() {
    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.discard();
        fail("Should get mocked JedisConnectionException.");
    } catch (JedisConnectionException jce) {
    // should be here
    } finally {
        // close() should pass
        trans.close();
    }
    assertTrue(jedis.isBroken());
}
Also used : Transaction(redis.clients.jedis.Transaction) Protocol(redis.clients.jedis.Protocol) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException) Test(org.junit.Test)

Example 4 with Protocol

use of redis.clients.jedis.Protocol in project jedis by redis.

the class TransactionCommandsTest method discardFail.

@Test
public void discardFail() {
    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.discard();
        fail("Should get mocked JedisConnectionException.");
    } catch (JedisConnectionException jce) {
    // should be here
    } finally {
        // close() should pass
        trans.close();
    }
    assertTrue(jedis.isBroken());
}
Also used : Transaction(redis.clients.jedis.Transaction) Protocol(redis.clients.jedis.Protocol) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 Protocol (redis.clients.jedis.Protocol)4 Transaction (redis.clients.jedis.Transaction)4 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)4