From 564d3df5d7e868e199a5e8a8cd04cd95f9280e62 Mon Sep 17 00:00:00 2001 From: NeatGuyCoding <15627489+NeatGuyCoding@users.noreply.github.com> Date: Sun, 5 Oct 2025 16:59:44 +0800 Subject: [PATCH] add more test assertions for ttl Signed-off-by: NeatGuyCoding <15627489+NeatGuyCoding@users.noreply.github.com> --- .../connection/jedis/JedisClusterConnectionTests.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 7c40d0a630..a4d21d175e 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 @@ -1336,6 +1336,7 @@ public void hGetExReturnsValueAndSetsExpiration() { assertThat(result.get(0)).isEqualTo(VALUE_1_BYTES); assertThat(clusterConnection.hashCommands().hExists(KEY_1_BYTES, KEY_2_BYTES)).isTrue(); assertThat(clusterConnection.hashCommands().hExists(KEY_1_BYTES, KEY_3_BYTES)).isTrue(); + assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isPositive(); } @Test // GH-3211 @@ -1348,6 +1349,7 @@ public void hGetExReturnsNullWhenFieldDoesNotExist() { assertThat(result).hasSize(1); assertThat(result.get(0)).isNull(); assertThat(clusterConnection.hashCommands().hExists(KEY_1_BYTES, KEY_2_BYTES)).isTrue(); + assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isEqualTo(-1L); } @Test // GH-3211 @@ -1357,6 +1359,7 @@ public void hGetExReturnsNullWhenKeyDoesNotExist() { List result = clusterConnection.hashCommands().hGetEx(KEY_1_BYTES, Expiration.seconds(60), KEY_2_BYTES); assertThat(result).hasSize(1); assertThat(result.get(0)).isNull(); + assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isEqualTo(-2L); } @Test // GH-3211 @@ -1375,6 +1378,7 @@ public void hGetExMultipleFieldsReturnsValuesAndSetsExpiration() { assertThat(clusterConnection.hashCommands().hExists(KEY_1_BYTES, KEY_2_BYTES)).isTrue(); assertThat(clusterConnection.hashCommands().hExists(KEY_1_BYTES, KEY_3_BYTES)).isTrue(); assertThat(clusterConnection.hashCommands().hExists(KEY_1_BYTES, "field3".getBytes())).isTrue(); + assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isPositive(); } @Test // GH-3211 @@ -1389,6 +1393,7 @@ public void hGetExMultipleFieldsWithNonExistentFields() { assertThat(result.get(0)).isEqualTo(VALUE_1_BYTES); assertThat(result.get(1)).isNull(); assertThat(clusterConnection.hashCommands().hExists(KEY_1_BYTES, KEY_2_BYTES)).isTrue(); + assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isPositive(); } @Test // GH-3211 @@ -1403,6 +1408,7 @@ public void hSetExUpsertConditionSetsFieldsWithExpiration() { assertThat(clusterConnection.hashCommands().hExists(KEY_1_BYTES, KEY_3_BYTES)).isTrue(); assertThat(clusterConnection.hashCommands().hGet(KEY_1_BYTES, KEY_2_BYTES)).isEqualTo(VALUE_1_BYTES); assertThat(clusterConnection.hashCommands().hGet(KEY_1_BYTES, KEY_3_BYTES)).isEqualTo(VALUE_2_BYTES); + assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isPositive(); } @Test // GH-3211 @@ -1417,6 +1423,7 @@ public void hSetExIfNoneExistConditionSucceedsWhenNoFieldsExist() { assertThat(clusterConnection.hashCommands().hExists(KEY_1_BYTES, KEY_3_BYTES)).isTrue(); assertThat(clusterConnection.hashCommands().hGet(KEY_1_BYTES, KEY_2_BYTES)).isEqualTo(VALUE_1_BYTES); assertThat(clusterConnection.hashCommands().hGet(KEY_1_BYTES, KEY_3_BYTES)).isEqualTo(VALUE_2_BYTES); + assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isPositive(); } @Test // GH-3211 @@ -1431,6 +1438,7 @@ public void hSetExIfNoneExistConditionFailsWhenSomeFieldsExist() { assertThat(result).isFalse(); assertThat(clusterConnection.hashCommands().hGet(KEY_1_BYTES, KEY_2_BYTES)).isEqualTo(VALUE_1_BYTES); // unchanged assertThat(clusterConnection.hashCommands().hExists(KEY_1_BYTES, KEY_3_BYTES)).isFalse(); // not set + assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isEqualTo(-1L); } @Test // GH-3211 @@ -1446,6 +1454,7 @@ public void hSetExIfAllExistConditionSucceedsWhenAllFieldsExist() { assertThat(result).isTrue(); assertThat(clusterConnection.hashCommands().hGet(KEY_1_BYTES, KEY_2_BYTES)).isEqualTo("new-value-1".getBytes()); // updated assertThat(clusterConnection.hashCommands().hGet(KEY_1_BYTES, KEY_3_BYTES)).isEqualTo("new-value-2".getBytes()); // updated + assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isPositive(); } @Test // GH-3211 @@ -1460,6 +1469,7 @@ public void hSetExIfAllExistConditionFailsWhenSomeFieldsMissing() { assertThat(result).isFalse(); assertThat(clusterConnection.hashCommands().hGet(KEY_1_BYTES, KEY_2_BYTES)).isEqualTo(VALUE_1_BYTES); // unchanged assertThat(clusterConnection.hashCommands().hExists(KEY_1_BYTES, KEY_3_BYTES)).isFalse(); // not set + assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isEqualTo(-1L); } @Test // DATAREDIS-315