Skip to content

Commit

Permalink
Report done status for Command.isDone() if command was canceled #629
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Oct 17, 2017
1 parent d103253 commit 12a0d6f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
3 changes: 1 addition & 2 deletions src/main/java/com/lambdaworks/redis/protocol/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import com.lambdaworks.redis.internal.LettuceAssert;
import com.lambdaworks.redis.output.CommandOutput;

import io.netty.buffer.ByteBuf;

/**
Expand Down Expand Up @@ -170,6 +169,6 @@ public boolean isCancelled() {

@Override
public boolean isDone() {
return status == ST_COMPLETED;
return status != ST_INITIAL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,57 +32,67 @@
* @author Mark Paluch
*/
public class CommandInternalsTest {

protected RedisCodec<String, String> codec = new Utf8StringCodec();
protected Command<String, String, String> sut;

@Before
public final void createCommand() throws Exception {
public void createCommand() {

CommandOutput<String, String, String> 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));
Expand All @@ -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();

Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 12a0d6f

Please sign in to comment.