diff --git a/src/main/java/com/lambdaworks/redis/protocol/Command.java b/src/main/java/com/lambdaworks/redis/protocol/Command.java index 0762a189ef..0f1aa3269b 100644 --- a/src/main/java/com/lambdaworks/redis/protocol/Command.java +++ b/src/main/java/com/lambdaworks/redis/protocol/Command.java @@ -17,7 +17,6 @@ import com.lambdaworks.redis.internal.LettuceAssert; import com.lambdaworks.redis.output.CommandOutput; - import io.netty.buffer.ByteBuf; /** @@ -170,6 +169,6 @@ public boolean isCancelled() { @Override public boolean isDone() { - return status == ST_COMPLETED; + return status != ST_INITIAL; } } diff --git a/src/main/java/com/lambdaworks/redis/protocol/CommandHandler.java b/src/main/java/com/lambdaworks/redis/protocol/CommandHandler.java index 02045c8813..f0ba4cf54c 100644 --- a/src/main/java/com/lambdaworks/redis/protocol/CommandHandler.java +++ b/src/main/java/com/lambdaworks/redis/protocol/CommandHandler.java @@ -849,7 +849,7 @@ private void validateWrite(int commands) { } private static boolean isWriteable(RedisCommand command) { - return !command.isCancelled() && !command.isDone(); + return !command.isDone(); } @SuppressWarnings("unchecked") diff --git a/src/test/java/com/lambdaworks/redis/protocol/CommandInternalsTest.java b/src/test/java/com/lambdaworks/redis/protocol/CommandInternalsTest.java index 3c769d692f..7e90396ccc 100644 --- a/src/test/java/com/lambdaworks/redis/protocol/CommandInternalsTest.java +++ b/src/test/java/com/lambdaworks/redis/protocol/CommandInternalsTest.java @@ -32,57 +32,67 @@ * @author Mark Paluch */ public class CommandInternalsTest { + protected RedisCodec codec = new Utf8StringCodec(); protected Command sut; @Before - public final void createCommand() throws Exception { + public void createCommand() { + CommandOutput output = new StatusOutput<>(codec); sut = new Command<>(CommandType.INFO, output, null); } @Test - public void isCancelled() throws Exception { + public void isCancelled() { assertThat(sut.isCancelled()).isFalse(); + assertThat(sut.isDone()).isFalse(); + sut.cancel(); assertThat(sut.isCancelled()).isTrue(); + assertThat(sut.isDone()).isTrue(); + sut.cancel(); } @Test - public void isDone() throws Exception { + public void isDone() { + assertThat(sut.isCancelled()).isFalse(); assertThat(sut.isDone()).isFalse(); + sut.complete(); + + assertThat(sut.isCancelled()).isFalse(); assertThat(sut.isDone()).isTrue(); } @Test - public void get() throws Exception { + public void get() { assertThat(sut.get()).isNull(); sut.getOutput().set(buffer("one")); assertThat(sut.get()).isEqualTo("one"); } @Test - public void getError() throws Exception { + public void getError() { sut.getOutput().setError("error"); assertThat(sut.getError()).isEqualTo("error"); } @Test(expected = IllegalStateException.class) - public void setOutputAfterCompleted() throws Exception { + public void setOutputAfterCompleted() { sut.complete(); sut.setOutput(new StatusOutput<>(codec)); } @Test - public void testToString() throws Exception { + public void testToString() { assertThat(sut.toString()).contains("Command"); } @Test - public void customKeyword() throws Exception { + public void customKeyword() { sut = new Command<>(MyKeywords.DUMMY, null, null); sut.setOutput(new StatusOutput<>(codec)); @@ -91,14 +101,14 @@ public void customKeyword() throws Exception { } @Test - public void customKeywordWithArgs() throws Exception { + public void customKeywordWithArgs() { sut = new Command<>(MyKeywords.DUMMY, null, new CommandArgs<>(codec)); sut.getArgs().add(MyKeywords.DUMMY); assertThat(sut.getArgs().toString()).contains(MyKeywords.DUMMY.name()); } @Test - public void getWithTimeout() throws Exception { + public void getWithTimeout() { sut.getOutput().set(buffer("one")); sut.complete(); @@ -128,7 +138,7 @@ public String get() throws RedisException { } @Test - public void sillyTestsForEmmaCoverage() throws Exception { + public void sillyTestsForEmmaCoverage() { assertThat(CommandType.valueOf("APPEND")).isEqualTo(CommandType.APPEND); assertThat(CommandKeyword.valueOf("AFTER")).isEqualTo(CommandKeyword.AFTER); }