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 spring-projects#2612
  • Loading branch information
jxblum committed Sep 21, 2023
1 parent b7a64b0 commit b61f45c
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 b61f45c

Please sign in to comment.