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);
}
}
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();
}
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();
}
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);
}
}
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);
}
Aggregations