Skip to content

Commit

Permalink
Align exceptions when invoking commands #119
Browse files Browse the repository at this point in the history
Throw RedisException instead of future-transport on disconnected state when reconnect is disabled.
  • Loading branch information
mp911de committed Aug 19, 2015
1 parent adc7b21 commit 46bd6b2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public ClusterDistributionChannelWriter(RedisChannelWriter<K, V> defaultWriter)
@Override
public <T> RedisCommand<K, V, T> write(RedisCommand<K, V, T> command) {

checkArgument(command != null, "command must not be null");

RedisCommand<K, V, T> commandToSend = command;
CommandArgs<K, V> args = command.getArgs();
RedisChannelWriter<K, V> channelWriter = null;
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/lambdaworks/redis/protocol/CommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

package com.lambdaworks.redis.protocol;

import static com.google.common.base.Preconditions.checkArgument;

import java.nio.channels.ClosedChannelException;
import java.nio.charset.Charset;
import java.util.ArrayDeque;
Expand Down Expand Up @@ -164,6 +166,8 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Interrup
@Override
public <T> RedisCommand<K, V, T> write(RedisCommand<K, V, T> command) {

checkArgument(command != null, "command must not be null");

if (lifecycleState == LifecycleState.CLOSED) {
throw new RedisException("Connection is closed");
}
Expand All @@ -174,10 +178,8 @@ public <T> RedisCommand<K, V, T> write(RedisCommand<K, V, T> command) {
}

if ((channel == null || !isConnected()) && !clientOptions.isAutoReconnect()) {
command.setException(new RedisException(
"Connection is in a disconnected state and reconnect is disabled. Commands are not accepted."));
command.complete();
return command;
throw new RedisException(
"Connection is in a disconnected state and reconnect is disabled. Commands are not accepted.");
}

try {
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/lambdaworks/redis/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ public void disconnectedConnectionWithoutReconnect() throws Exception {
connection.quit();
waitUntilDisconnected(connection);
try {
connection.get(key).get();
} catch (Exception e) {
assertThat(e).hasRootCauseInstanceOf(RedisException.class).hasMessageContaining(
connection.get(key);
} catch (RedisException e) {
assertThat(e).hasMessageContaining(
"Connection is in a disconnected state and reconnect is disabled");
} finally {
connection.close();
Expand Down

0 comments on commit 46bd6b2

Please sign in to comment.