diff --git a/src/main/java/com/lambdaworks/redis/protocol/CommandHandler.java b/src/main/java/com/lambdaworks/redis/protocol/CommandHandler.java index 401531b5f0..207a6f66f3 100644 --- a/src/main/java/com/lambdaworks/redis/protocol/CommandHandler.java +++ b/src/main/java/com/lambdaworks/redis/protocol/CommandHandler.java @@ -799,10 +799,10 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) } } - private void writeSingleCommand(ChannelHandlerContext ctx, RedisCommand command, ChannelPromise promise) - throws Exception { + private void writeSingleCommand(ChannelHandlerContext ctx, RedisCommand command, ChannelPromise promise) { if (!isWriteable(command)) { + promise.trySuccess(); return; } @@ -810,8 +810,7 @@ private void writeSingleCommand(ChannelHandlerContext ctx, RedisCommand ctx.write(command, promise); } - private void writeBatch(ChannelHandlerContext ctx, Collection> batch, ChannelPromise promise) - throws Exception { + private void writeBatch(ChannelHandlerContext ctx, Collection> batch, ChannelPromise promise) { Collection> deduplicated = new LinkedHashSet<>(batch.size(), 1); @@ -842,6 +841,8 @@ private void writeBatch(ChannelHandlerContext ctx, Collection connection = client.connect().sync(); assertThat(connection.auth(passwd)).isEqualTo("OK"); assertThat(connection.set(key, value)).isEqualTo("OK"); connection.quit(); + + Thread.sleep(100); assertThat(connection.get(key)).isEqualTo(value); } }; diff --git a/src/test/java/com/lambdaworks/redis/protocol/CommandHandlerTest.java b/src/test/java/com/lambdaworks/redis/protocol/CommandHandlerTest.java index 3c720868c2..496e85bf88 100644 --- a/src/test/java/com/lambdaworks/redis/protocol/CommandHandlerTest.java +++ b/src/test/java/com/lambdaworks/redis/protocol/CommandHandlerTest.java @@ -456,14 +456,27 @@ public void shouldCancelCommandsOnEncoderException() throws Exception { assertThat(command.exception).isInstanceOf(EncoderException.class); } + @Test + public void shouldNotWriteCancelledCommand() throws Exception { + + command.cancel(); + sut.write(context, command, promise); + + verifyZeroInteractions(context); + assertThat(disconnectedBuffer).isEmpty(); + verify(promise).trySuccess(); + + } + @Test public void shouldNotWriteCancelledCommands() throws Exception { command.cancel(); - sut.write(context, command, null); + sut.write(context, Collections.singleton(command), promise); verifyZeroInteractions(context); assertThat(disconnectedBuffer).isEmpty(); + verify(promise).trySuccess(); } @Test