Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#540] Fix '$' in XREAD #299

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected Slice response() {
mapKeyToBeginEntryId.append(
key,
"$".equalsIgnoreCase(id.toString())
? new StreamId(0, 1) // lowest possible id
? new StreamId(0, 0) // lowest possible id
: new StreamId(id)
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.InstanceOfAssertFactories.LIST;

@ExtendWith(ComparisonBase.class)
public class EvalTest {
Expand Down Expand Up @@ -58,15 +59,15 @@ void evalTableOfStringsTest(Jedis jedis) {
void evalTableOfLongTest(Jedis jedis) {
Object eval_return = jedis.eval("return { 1, 2, 3 }", 0);
assertThat(eval_return).isInstanceOf(ArrayList.class)
.asList().containsExactly(1L, 2L, 3L);
.asInstanceOf(LIST).containsExactly(1L, 2L, 3L);
assertThat(((List<?>) eval_return).get(0)).isInstanceOf(Long.class);
}

@TestTemplate
void evalDeepListTest(Jedis jedis) {
Object eval_return = jedis.eval("return { 'test', 2, {'test', 2} }", 0);
assertThat(eval_return).isInstanceOf(ArrayList.class)
.asList().containsExactly("test", 2L, Arrays.asList("test", 2L));
.asInstanceOf(LIST).containsExactly("test", 2L, asList("test", 2L));
assertThat(((List<?>) eval_return).get(0)).isInstanceOf(String.class);
assertThat(((List<?>) eval_return).get(1)).isInstanceOf(Long.class);
assertThat(((List<?>) eval_return).get(2)).isInstanceOf(ArrayList.class);
Expand All @@ -76,7 +77,7 @@ void evalDeepListTest(Jedis jedis) {
void evalDictTest(Jedis jedis) {
Object eval_return = jedis.eval("return { a = 1, 2 }", 0);
assertThat(eval_return).isInstanceOf(ArrayList.class)
.asList().containsExactly(2L);
.asInstanceOf(LIST).containsExactly(2L);
assertThat(((List<?>) eval_return).get(0)).isInstanceOf(Long.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.InstanceOfAssertFactories.LIST;

@ExtendWith(ComparisonBase.class)
public class XReadTests {
Expand Down Expand Up @@ -68,7 +69,7 @@ void blockingXREADforStreamThatRanDry(Jedis jedis) throws ExecutionException, In
.hasSize(1)
.first()
.extracting(Map.Entry::getValue)
.asList()
.asInstanceOf(LIST)
.hasSize(1)
.first()
.usingRecursiveComparison()
Expand Down Expand Up @@ -98,7 +99,7 @@ void whenAddIsInvokedWithSingleStream_EnsureTemporaryBlockedXreadIsAwaken(Jedis
.hasSize(1)
.first()
.extracting(Map.Entry::getValue)
.asList()
.asInstanceOf(LIST)
.hasSize(1)
.first()
.usingRecursiveComparison()
Expand Down Expand Up @@ -146,7 +147,7 @@ void whenAddIsInvokedWithSeveralStreams_EnsureTemporaryBlockedXreadAwakenImmedia
.hasSize(1)
.first()
.extracting(Map.Entry::getValue)
.asList()
.asInstanceOf(LIST)
.hasSize(1)
.first()
.usingRecursiveComparison()
Expand Down Expand Up @@ -186,4 +187,50 @@ void whenAddIsInvokedWithSeveralStreams_EnsureTemporaryBlockedXreadAwakenImmedia

assertThat(blockingReadJob.isCancelled()).isFalse();
}

@TestTemplate
void whenLastEntryIsCalledOnEmptyStream_EnsureXaddAwakes(Jedis jedis)
throws ExecutionException, InterruptedException {
Future<?> blockingReadJob = scheduledThreadPool.submit(() -> {
List<Map.Entry<String, List<StreamEntry>>> answer = blockedClient.xread(
XReadParams.xReadParams().block(0).count(1),
Collections.singletonMap("test:jedis", StreamEntryID.LAST_ENTRY)
);

assertThat(answer)
.hasSize(1)
.first()
.extracting(Map.Entry::getValue)
.asInstanceOf(LIST)
.hasSize(1)
.first()
.usingRecursiveComparison()
.comparingOnlyFields("fields")
.isEqualTo(
new StreamEntry(
new StreamEntryID(0, 1),
Collections.singletonMap("a", "b")
)
);
});

ScheduledFuture<?> addJob = scheduledThreadPool.schedule(() -> {
jedis.xadd(
"test:jedis",
XAddParams.xAddParams(),
Collections.singletonMap("a", "b")
);
}, 2, TimeUnit.SECONDS);


ScheduledFuture<?> cancellationJob = scheduledThreadPool.schedule(() -> {
blockingReadJob.cancel(true);
}, 15, TimeUnit.SECONDS);

addJob.get();
cancellationJob.get();
blockingReadJob.get();

assertThat(blockingReadJob.isCancelled()).isFalse();
}
}
Loading