Search in sources :

Example 1 with RedisException

use of io.lettuce.core.RedisException in project Sermant by huaweicloud.

the class RtcConsumer method logicProcess.

private void logicProcess(String topic, List<ConsumerRecord<String, String>> records, TopicPartition topicPartition) {
    InterfaceTopicHandleStrategy handler = topicHandleStrategyFactory.getTopicHandleStrategy(topic);
    try {
        handler.handleRecordByTopic(records);
        // 实时记录redis中各分区的消费偏移量offset
        String offset = String.valueOf(records.get(records.size() - 1).offset() + 1);
        redisUtil.set(topicPartition.topic() + ":" + topicPartition.partition(), offset);
        LOGGER.debug("real time partition:{}, offset:{}", topicPartition, offset);
    } catch (RedisException ex) {
        LOGGER.error("task process error", ex);
    }
}
Also used : InterfaceTopicHandleStrategy(com.huawei.flowrecordreplay.console.rtc.consumer.strategy.InterfaceTopicHandleStrategy) RedisException(io.lettuce.core.RedisException)

Example 2 with RedisException

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

the class TransactionalCommandUnitTests method shouldCompleteOnException.

@Test
void shouldCompleteOnException() {
    RedisCommand<String, String, String> inner = new Command<>(CommandType.SET, new StatusOutput<>(StringCodec.UTF8));
    TransactionalCommand<String, String, String> command = new TransactionalCommand<>(new AsyncCommand<>(inner));
    command.completeExceptionally(new RedisException("foo"));
    assertThat(command).isCompletedExceptionally();
}
Also used : RedisException(io.lettuce.core.RedisException) Test(org.junit.jupiter.api.Test)

Example 3 with RedisException

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

the class AtLeastOnceTest method commandCancelledOverSyncAPIAfterConnectionIsDisconnected.

@Test
void commandCancelledOverSyncAPIAfterConnectionIsDisconnected() {
    StatefulRedisConnection<String, String> connection = client.connect();
    RedisCommands<String, String> sync = connection.sync();
    RedisCommands<String, String> verificationConnection = client.connect().sync();
    sync.set(key, "1");
    ConnectionWatchdog connectionWatchdog = ConnectionTestUtil.getConnectionWatchdog(sync.getStatefulConnection());
    connectionWatchdog.setListenOnChannelInactive(false);
    sync.quit();
    Wait.untilTrue(() -> !sync.getStatefulConnection().isOpen()).waitOrTimeout();
    try {
        sync.incr(key);
    } catch (RedisException e) {
        assertThat(e).isExactlyInstanceOf(RedisCommandTimeoutException.class);
    }
    assertThat(verificationConnection.get("key")).isEqualTo("1");
    assertThat(ConnectionTestUtil.getDisconnectedBuffer(connection).size()).isGreaterThan(0);
    assertThat(ConnectionTestUtil.getCommandBuffer(connection)).isEmpty();
    connectionWatchdog.setListenOnChannelInactive(true);
    connectionWatchdog.scheduleReconnect();
    while (!ConnectionTestUtil.getCommandBuffer(connection).isEmpty() || !ConnectionTestUtil.getDisconnectedBuffer(connection).isEmpty()) {
        Delay.delay(Duration.ofMillis(10));
    }
    assertThat(sync.get(key)).isEqualTo("1");
    sync.getStatefulConnection().close();
    verificationConnection.getStatefulConnection().close();
}
Also used : ConnectionWatchdog(io.lettuce.core.protocol.ConnectionWatchdog) RedisException(io.lettuce.core.RedisException) RedisCommandTimeoutException(io.lettuce.core.RedisCommandTimeoutException) AbstractRedisClientTest(io.lettuce.core.AbstractRedisClientTest) Test(org.junit.jupiter.api.Test)

Example 4 with RedisException

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

the class ClusterTopologyRefreshUnitTests method shouldPropagateCommandFailures.

@Test
void shouldPropagateCommandFailures() {
    List<RedisURI> seed = Arrays.asList(RedisURI.create("127.0.0.1", 7380), RedisURI.create("127.0.0.1", 7381));
    when(nodeConnectionFactory.connectToNodeAsync(any(RedisCodec.class), eq(InetSocketAddress.createUnresolved("127.0.0.1", 7380)))).thenReturn(completedFuture((StatefulRedisConnection) connection1));
    when(nodeConnectionFactory.connectToNodeAsync(any(RedisCodec.class), eq(InetSocketAddress.createUnresolved("127.0.0.1", 7381)))).thenReturn(completedFuture((StatefulRedisConnection) connection2));
    reset(connection1, connection2);
    when(connection1.async()).thenReturn(asyncCommands1);
    when(connection2.async()).thenReturn(asyncCommands2);
    when(connection1.closeAsync()).thenReturn(CompletableFuture.completedFuture(null));
    when(connection2.closeAsync()).thenReturn(CompletableFuture.completedFuture(null));
    when(connection1.dispatch(any(RedisCommand.class))).thenAnswer(invocation -> {
        TimedAsyncCommand command = invocation.getArgument(0);
        command.completeExceptionally(new RedisException("AUTH"));
        return command;
    });
    RedisException nestedException = new RedisException("NESTED");
    when(connection2.dispatch(any(RedisCommand.class))).thenAnswer(invocation -> {
        TimedAsyncCommand command = invocation.getArgument(0);
        command.completeExceptionally(nestedException);
        return command;
    });
    CompletionStage<Map<RedisURI, Partitions>> actual = sut.loadViews(seed, Duration.ofSeconds(1), true);
    assertThat(actual).isCompletedExceptionally();
    try {
        actual.toCompletableFuture().join();
        fail("Missing CompletionException");
    } catch (CompletionException e) {
        assertThat(e.getCause()).hasSuppressedException(nestedException);
    }
}
Also used : RedisCodec(io.lettuce.core.codec.RedisCodec) RedisURI(io.lettuce.core.RedisURI) CompletionException(java.util.concurrent.CompletionException) RedisCommand(io.lettuce.core.protocol.RedisCommand) RedisException(io.lettuce.core.RedisException) HashMap(java.util.HashMap) Map(java.util.Map) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection) Test(org.junit.jupiter.api.Test)

Example 5 with RedisException

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

the class StatefulRedisClusterConnectionImpl method getConnectionAsync.

@Override
public CompletableFuture<StatefulRedisConnection<K, V>> getConnectionAsync(String nodeId) {
    RedisURI redisURI = lookup(nodeId);
    if (redisURI == null) {
        throw new RedisException("NodeId " + nodeId + " does not belong to the cluster");
    }
    AsyncClusterConnectionProvider provider = (AsyncClusterConnectionProvider) getClusterDistributionChannelWriter().getClusterConnectionProvider();
    return provider.getConnectionAsync(ClusterConnectionProvider.Intent.WRITE, nodeId);
}
Also used : RedisURI(io.lettuce.core.RedisURI) RedisException(io.lettuce.core.RedisException)

Aggregations

RedisException (io.lettuce.core.RedisException)23 Test (org.junit.jupiter.api.Test)7 RedisURI (io.lettuce.core.RedisURI)5 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)4 Collection (java.util.Collection)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 RedisCommand (io.lettuce.core.protocol.RedisCommand)3 HashMap (java.util.HashMap)3 RedisChannelWriter (io.lettuce.core.RedisChannelWriter)2 RedisConnectionException (io.lettuce.core.RedisConnectionException)2 Intent (io.lettuce.core.masterreplica.MasterReplicaConnectionProvider.Intent)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 InterfaceTopicHandleStrategy (com.huawei.flowrecordreplay.console.rtc.consumer.strategy.InterfaceTopicHandleStrategy)1 AbstractRedisClientTest (io.lettuce.core.AbstractRedisClientTest)1 ClientOptions (io.lettuce.core.ClientOptions)1 ConnectionEvents (io.lettuce.core.ConnectionEvents)1 RedisChannelHandler (io.lettuce.core.RedisChannelHandler)1 RedisCommandTimeoutException (io.lettuce.core.RedisCommandTimeoutException)1