From 1f5d2b1ea15aae556398c44e652110a68ef4a06e Mon Sep 17 00:00:00 2001 From: John Blum Date: Tue, 19 Sep 2023 13:39:28 -0700 Subject: [PATCH] Fix bzPopMaxShouldWorkCorrectly() and bzPopMinShouldWorkCorrectly() tests 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 --- .../redis/connection/jedis/JedisClusterConnectionTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java index 78ffeb756e..13621d31fc 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java @@ -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); @@ -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);