Skip to content

Commit

Permalink
Fix StreamReadOutput to consider messages without body #1622
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Mar 4, 2021
1 parent 83801f6 commit aef96d1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/java/io/lettuce/core/output/StreamReadOutput.java
Expand Up @@ -73,6 +73,7 @@ public void set(ByteBuffer bytes) {

if (key == null) {
bodyReceived = true;

if (bytes == null) {
return;
}
Expand All @@ -92,6 +93,10 @@ public void set(ByteBuffer bytes) {
@Override
public void multi(int count) {

if (id != null && key == null && count == -1) {
bodyReceived = true;
}

if (!initialized) {
output = OutputFactory.newList(count);
initialized = true;
Expand Down
Expand Up @@ -34,7 +34,16 @@
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;

import io.lettuce.core.*;
import io.lettuce.core.Consumer;
import io.lettuce.core.Limit;
import io.lettuce.core.Range;
import io.lettuce.core.StreamMessage;
import io.lettuce.core.TestSupport;
import io.lettuce.core.TransactionResult;
import io.lettuce.core.XAddArgs;
import io.lettuce.core.XClaimArgs;
import io.lettuce.core.XGroupCreateArgs;
import io.lettuce.core.XReadArgs;
import io.lettuce.core.XReadArgs.StreamOffset;
import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.core.codec.StringCodec;
Expand Down Expand Up @@ -377,6 +386,24 @@ void xgroupreadDeletedMessage() {
assertThat(messages.get(0).getBody()).isEmpty();
}

@Test
void xgroupreadTrimmedMessage() {

for (int i = 0; i < 10; i++) {
redis.xadd(key, Collections.singletonMap("key", "value1"));
}

redis.xgroupCreate(StreamOffset.from(key, "0-0"), "del-group", XGroupCreateArgs.Builder.mkstream());

redis.xreadgroup(Consumer.from("del-group", "consumer1"), XReadArgs.Builder.count(10), StreamOffset.lastConsumed(key));
redis.xtrim(key, 1);

List<StreamMessage<String, String>> messages = redis.xreadgroup(Consumer.from("del-group", "consumer1"),
XReadArgs.Builder.count(10), StreamOffset.from(key, "0-0"));

assertThat(messages).hasSize(10);
}

@Test
void xpendingWithoutRead() {

Expand Down

0 comments on commit aef96d1

Please sign in to comment.