Search in sources :

Example 1 with RedisCommandExecutionException

use of io.lettuce.core.RedisCommandExecutionException in project api-layer by zowe.

the class RedisOperatorTest method givenRedisExecutionExceptionNotOutOfMemory_thenThrowRetryableRedisException.

@Test
void givenRedisExecutionExceptionNotOutOfMemory_thenThrowRetryableRedisException() throws ExecutionException, InterruptedException {
    RedisFuture<Boolean> future = (RedisFuture<Boolean>) mock(RedisFuture.class);
    when(redisCommands.hsetnx(any(), any(), any())).thenReturn(future);
    when(future.get()).thenThrow(new ExecutionException(new RedisCommandExecutionException("error")));
    assertThrows(RetryableRedisException.class, () -> underTest.create(REDIS_ENTRY));
}
Also used : RedisCommandExecutionException(io.lettuce.core.RedisCommandExecutionException) RedisFuture(io.lettuce.core.RedisFuture) RedisCommandExecutionException(io.lettuce.core.RedisCommandExecutionException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test)

Example 2 with RedisCommandExecutionException

use of io.lettuce.core.RedisCommandExecutionException in project lettuce-core by lettuce-io.

the class AsyncCommandUnitTests method awaitAllWithExecutionException.

@Test
void awaitAllWithExecutionException() {
    sut.completeExceptionally(new RedisCommandExecutionException("error"));
    assertThatThrownBy(() -> Futures.await(0, TimeUnit.SECONDS, sut)).isInstanceOf(RedisException.class);
}
Also used : RedisCommandExecutionException(io.lettuce.core.RedisCommandExecutionException) Test(org.junit.jupiter.api.Test)

Example 3 with RedisCommandExecutionException

use of io.lettuce.core.RedisCommandExecutionException in project lettuce-core by lettuce-io.

the class RedisCommandsIntegrationTests method doesNotFailIfCommandRetrievalFails.

@Test
void doesNotFailIfCommandRetrievalFails() {
    StatefulRedisConnection connectionMock = Mockito.mock(StatefulRedisConnection.class);
    RedisCommands commandsMock = Mockito.mock(RedisCommands.class);
    when(connectionMock.sync()).thenReturn(commandsMock);
    doThrow(new RedisCommandExecutionException("ERR unknown command 'COMMAND'")).when(commandsMock).command();
    RedisCommandFactory factory = new RedisCommandFactory(connectionMock);
    assertThat(factory).hasFieldOrPropertyWithValue("verifyCommandMethods", false);
}
Also used : RedisCommands(io.lettuce.core.api.sync.RedisCommands) RedisCommandExecutionException(io.lettuce.core.RedisCommandExecutionException) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection) Test(org.junit.jupiter.api.Test)

Example 4 with RedisCommandExecutionException

use of io.lettuce.core.RedisCommandExecutionException in project lettuce-core by lettuce-io.

the class NodeSelectionInvocationHandler method createExecutionException.

private RedisCommandExecutionException createExecutionException(Map<RedisClusterNode, CompletionStage<?>> executions) {
    List<RedisClusterNode> failed = new ArrayList<>();
    executions.forEach((redisClusterNode, completionStage) -> {
        if (!completionStage.toCompletableFuture().isCompletedExceptionally()) {
            failed.add(redisClusterNode);
        }
    });
    RedisCommandExecutionException e = ExceptionFactory.createExecutionException("Multi-node command execution failed on node(s): " + getNodeDescription(failed));
    executions.forEach((redisClusterNode, completionStage) -> {
        CompletableFuture<?> completableFuture = completionStage.toCompletableFuture();
        if (completableFuture.isCompletedExceptionally()) {
            try {
                completableFuture.get();
            } catch (Exception innerException) {
                if (innerException instanceof ExecutionException) {
                    e.addSuppressed(innerException.getCause());
                } else {
                    e.addSuppressed(innerException);
                }
            }
        }
    });
    return e;
}
Also used : RedisCommandExecutionException(io.lettuce.core.RedisCommandExecutionException) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) ArrayList(java.util.ArrayList) RedisCommandExecutionException(io.lettuce.core.RedisCommandExecutionException) ExecutionException(java.util.concurrent.ExecutionException) RedisCommandExecutionException(io.lettuce.core.RedisCommandExecutionException) RedisCommandTimeoutException(io.lettuce.core.RedisCommandTimeoutException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with RedisCommandExecutionException

use of io.lettuce.core.RedisCommandExecutionException in project lettuce-core by lettuce-io.

the class RedisCommandsBatchingIntegrationTests method shouldHandleAsynchronousBatchErrors.

@Test
void shouldHandleAsynchronousBatchErrors() throws Exception {
    RedisCommandFactory factory = new RedisCommandFactory(redis.getStatefulConnection());
    Batching api = factory.getCommands(Batching.class);
    api.setAsync("k1", value);
    api.setAsync("k2", value);
    api.llen("k2");
    api.setAsync("k4", value);
    assertThat(redis.get("k1")).isNull();
    RedisFuture<Long> llen = api.llenAsync("k4");
    llen.await(1, TimeUnit.SECONDS);
    assertThat(redis.get("k1")).isEqualTo(value);
    assertThat(redis.get("k4")).isEqualTo(value);
    try {
        Futures.await(1, TimeUnit.SECONDS, llen);
        fail("Missing RedisCommandExecutionException");
    } catch (Exception e) {
        assertThat(e).isInstanceOf(RedisCommandExecutionException.class);
    }
}
Also used : RedisCommandExecutionException(io.lettuce.core.RedisCommandExecutionException) CommandBatching(io.lettuce.core.dynamic.batch.CommandBatching) RedisCommandExecutionException(io.lettuce.core.RedisCommandExecutionException) BatchException(io.lettuce.core.dynamic.batch.BatchException) Test(org.junit.jupiter.api.Test)

Aggregations

RedisCommandExecutionException (io.lettuce.core.RedisCommandExecutionException)6 Test (org.junit.jupiter.api.Test)5 ExecutionException (java.util.concurrent.ExecutionException)2 RedisCommandTimeoutException (io.lettuce.core.RedisCommandTimeoutException)1 RedisFuture (io.lettuce.core.RedisFuture)1 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)1 RedisCommands (io.lettuce.core.api.sync.RedisCommands)1 RedisClusterNode (io.lettuce.core.cluster.models.partitions.RedisClusterNode)1 BatchException (io.lettuce.core.dynamic.batch.BatchException)1 CommandBatching (io.lettuce.core.dynamic.batch.CommandBatching)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1