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 3979a93 commit bc79069
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/main/java/io/lettuce/core/output/StreamReadOutput.java
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
*/
package io.lettuce.core.commands;

import static io.lettuce.core.protocol.CommandType.XINFO;
import static org.assertj.core.api.Assertions.assertThat;
import static io.lettuce.core.protocol.CommandType.*;
import static org.assertj.core.api.Assertions.*;

import java.time.Instant;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

Expand All @@ -28,7 +33,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 @@ -336,6 +350,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 bc79069

Please sign in to comment.