Skip to content

Commit

Permalink
Fix bzPopMaxShouldWorkCorrectly() and bzPopMinShouldWorkCorrectly() t…
Browse files Browse the repository at this point in the history
…ests in JedisClusterConnectionTests.

Jedis 5.0 changed the bzpopmax and bzpopmin Redis commands to no longer return an empty (Array)List internally when evaluating and popping from an empty sorted set. A NullPointerException will be thrown if either bzpopmax or bzpopmin commands are executd on an empty Redis sorted set in Jedis 5.0 (vs. Jedis 4.x):

Caused by: java.lang.NullPointerException: Cannot invoke 'java.util.List.isEmpty()' because l is null:
  at redis.clients.jedis.BuilderFactory7.build(BuilderFactory.java:616)

This seems like a bug in Jedis. It is safe to execute zcard(key) to return the cardinality of (number of elements in) the sorted set before the test executes, ensuring a clean, reliable run.

Closes #2612
  • Loading branch information
jxblum committed Sep 25, 2023
1 parent f50119f commit 7d9d250
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ public void zPopMinShouldWorkCorrectly() {
@EnabledOnCommand("BZPOPMIN")
public void bzPopMinShouldWorkCorrectly() {

assertThat(clusterConnection.bZPopMin(KEY_1_BYTES, 10, TimeUnit.MILLISECONDS)).isNull();
assertThat(clusterConnection.zSetCommands().zCard(KEY_1_BYTES)).isZero();

nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES);
nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES);
Expand All @@ -2306,7 +2306,7 @@ public void zPopMaxShouldWorkCorrectly() {
@EnabledOnCommand("BZPOPMAX")
public void bzPopMaxShouldWorkCorrectly() {

assertThat(clusterConnection.bZPopMax(KEY_1_BYTES, 10, TimeUnit.MILLISECONDS)).isNull();
assertThat(clusterConnection.zSetCommands().zCard(KEY_1_BYTES)).isZero();

nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES);
nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES);
Expand Down

0 comments on commit 7d9d250

Please sign in to comment.