Skip to content

Commit 0d9487b

Browse files
committed
Polishing.
Adds a few more TTL asssertions to JedisClusterConnectionTests and also updates the counterpart in Lettuce (LettuceClusterConnectionTests) w/ the same assertions. Signed-off-by: Chris Bono <[email protected]>
1 parent b2b0672 commit 0d9487b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,7 @@ public void hGetExMultipleFieldsReturnsValuesAndSetsExpiration() {
13801380
assertThat(clusterConnection.hashCommands().hExists(KEY_1_BYTES, KEY_3_BYTES)).isTrue();
13811381
assertThat(clusterConnection.hashCommands().hExists(KEY_1_BYTES, "field3".getBytes())).isTrue();
13821382
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isPositive();
1383+
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_3_BYTES).get(0)).isPositive();
13831384
}
13841385

13851386
@Test // GH-3211
@@ -1396,6 +1397,7 @@ public void hGetExMultipleFieldsWithNonExistentFields() {
13961397
assertThat(result.get(1)).isNull();
13971398
assertThat(clusterConnection.hashCommands().hExists(KEY_1_BYTES, KEY_2_BYTES)).isTrue();
13981399
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isPositive();
1400+
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_3_BYTES).get(0)).isEqualTo(-2L);
13991401
}
14001402

14011403
@Test // GH-3211
@@ -1412,6 +1414,7 @@ public void hSetExUpsertConditionSetsFieldsWithExpiration() {
14121414
assertThat(clusterConnection.hashCommands().hGet(KEY_1_BYTES, KEY_2_BYTES)).isEqualTo(VALUE_1_BYTES);
14131415
assertThat(clusterConnection.hashCommands().hGet(KEY_1_BYTES, KEY_3_BYTES)).isEqualTo(VALUE_2_BYTES);
14141416
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isPositive();
1417+
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_3_BYTES).get(0)).isPositive();
14151418
}
14161419

14171420
@Test // GH-3211
@@ -1428,6 +1431,7 @@ public void hSetExIfNoneExistConditionSucceedsWhenNoFieldsExist() {
14281431
assertThat(clusterConnection.hashCommands().hGet(KEY_1_BYTES, KEY_2_BYTES)).isEqualTo(VALUE_1_BYTES);
14291432
assertThat(clusterConnection.hashCommands().hGet(KEY_1_BYTES, KEY_3_BYTES)).isEqualTo(VALUE_2_BYTES);
14301433
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isPositive();
1434+
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_3_BYTES).get(0)).isPositive();
14311435
}
14321436

14331437
@Test // GH-3211
@@ -1461,6 +1465,7 @@ public void hSetExIfAllExistConditionSucceedsWhenAllFieldsExist() {
14611465
assertThat(clusterConnection.hashCommands().hGet(KEY_1_BYTES, KEY_2_BYTES)).isEqualTo("new-value-1".getBytes()); // updated
14621466
assertThat(clusterConnection.hashCommands().hGet(KEY_1_BYTES, KEY_3_BYTES)).isEqualTo("new-value-2".getBytes()); // updated
14631467
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isPositive();
1468+
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_3_BYTES).get(0)).isPositive();
14641469
}
14651470

14661471
@Test // GH-3211

src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,7 @@ public void hGetExReturnsValueAndSetsExpiration() {
14001400
assertThat(result.get(0)).isEqualTo(VALUE_1_BYTES);
14011401
assertThat(clusterConnection.hExists(KEY_1_BYTES, KEY_2_BYTES)).isTrue();
14021402
assertThat(clusterConnection.hExists(KEY_1_BYTES, KEY_3_BYTES)).isTrue();
1403+
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isPositive();
14031404
}
14041405

14051406
@Test // GH-3211
@@ -1412,6 +1413,7 @@ public void hGetExReturnsNullWhenFieldDoesNotExist() {
14121413
assertThat(result).hasSize(1);
14131414
assertThat(result.get(0)).isNull();
14141415
assertThat(clusterConnection.hExists(KEY_1_BYTES, KEY_2_BYTES)).isTrue();
1416+
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isEqualTo(-1L);
14151417
}
14161418

14171419
@Test // GH-3211
@@ -1421,6 +1423,7 @@ public void hGetExReturnsNullWhenKeyDoesNotExist() {
14211423
List<byte[]> result = clusterConnection.hashCommands().hGetEx(KEY_1_BYTES, Expiration.seconds(60), KEY_2_BYTES);
14221424
assertThat(result).hasSize(1);
14231425
assertThat(result.get(0)).isNull();
1426+
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isEqualTo(-2L);
14241427
}
14251428

14261429
@Test // GH-3211
@@ -1440,6 +1443,8 @@ public void hGetExMultipleFieldsReturnsValuesAndSetsExpiration() {
14401443
assertThat(clusterConnection.hExists(KEY_1_BYTES, KEY_2_BYTES)).isTrue();
14411444
assertThat(clusterConnection.hExists(KEY_1_BYTES, KEY_3_BYTES)).isTrue();
14421445
assertThat(clusterConnection.hExists(KEY_1_BYTES, "field3".getBytes())).isTrue();
1446+
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isPositive();
1447+
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_3_BYTES).get(0)).isPositive();
14431448
}
14441449

14451450
@Test // GH-3211
@@ -1455,6 +1460,8 @@ public void hGetExMultipleFieldsWithNonExistentFields() {
14551460
assertThat(result.get(0)).isEqualTo(VALUE_1_BYTES);
14561461
assertThat(result.get(1)).isNull();
14571462
assertThat(clusterConnection.hExists(KEY_1_BYTES, KEY_2_BYTES)).isTrue();
1463+
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isPositive();
1464+
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_3_BYTES).get(0)).isEqualTo(-2L);
14581465
}
14591466

14601467
@Test // GH-3211
@@ -1470,6 +1477,8 @@ public void hSetExUpsertConditionSetsFieldsWithExpiration() {
14701477
assertThat(clusterConnection.hExists(KEY_1_BYTES, KEY_3_BYTES)).isTrue();
14711478
assertThat(clusterConnection.hGet(KEY_1_BYTES, KEY_2_BYTES)).isEqualTo(VALUE_1_BYTES);
14721479
assertThat(clusterConnection.hGet(KEY_1_BYTES, KEY_3_BYTES)).isEqualTo(VALUE_2_BYTES);
1480+
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isPositive();
1481+
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_3_BYTES).get(0)).isPositive();
14731482
}
14741483

14751484
@Test // GH-3211
@@ -1485,6 +1494,8 @@ public void hSetExIfNoneExistConditionSucceedsWhenNoFieldsExist() {
14851494
assertThat(clusterConnection.hExists(KEY_1_BYTES, KEY_3_BYTES)).isTrue();
14861495
assertThat(clusterConnection.hGet(KEY_1_BYTES, KEY_2_BYTES)).isEqualTo(VALUE_1_BYTES);
14871496
assertThat(clusterConnection.hGet(KEY_1_BYTES, KEY_3_BYTES)).isEqualTo(VALUE_2_BYTES);
1497+
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isPositive();
1498+
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_3_BYTES).get(0)).isPositive();
14881499
}
14891500

14901501
@Test // GH-3211
@@ -1500,6 +1511,7 @@ public void hSetExIfNoneExistConditionFailsWhenSomeFieldsExist() {
15001511
assertThat(result).isFalse();
15011512
assertThat(clusterConnection.hGet(KEY_1_BYTES, KEY_2_BYTES)).isEqualTo(VALUE_1_BYTES); // unchanged
15021513
assertThat(clusterConnection.hExists(KEY_1_BYTES, KEY_3_BYTES)).isFalse(); // not set
1514+
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isEqualTo(-1L);
15031515
}
15041516

15051517
@Test // GH-3211
@@ -1516,6 +1528,8 @@ public void hSetExIfAllExistConditionSucceedsWhenAllFieldsExist() {
15161528
assertThat(result).isTrue();
15171529
assertThat(clusterConnection.hGet(KEY_1_BYTES, KEY_2_BYTES)).isEqualTo("new-value-1".getBytes()); // updated
15181530
assertThat(clusterConnection.hGet(KEY_1_BYTES, KEY_3_BYTES)).isEqualTo("new-value-2".getBytes()); // updated
1531+
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isPositive();
1532+
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_3_BYTES).get(0)).isPositive();
15191533
}
15201534

15211535
@Test // GH-3211
@@ -1531,6 +1545,7 @@ public void hSetExIfAllExistConditionFailsWhenSomeFieldsMissing() {
15311545
assertThat(result).isFalse();
15321546
assertThat(clusterConnection.hGet(KEY_1_BYTES, KEY_2_BYTES)).isEqualTo(VALUE_1_BYTES); // unchanged
15331547
assertThat(clusterConnection.hExists(KEY_1_BYTES, KEY_3_BYTES)).isFalse(); // not set
1548+
assertThat(clusterConnection.hashCommands().hTtl(KEY_1_BYTES, KEY_2_BYTES).get(0)).isEqualTo(-1L);
15341549
}
15351550

15361551
@Test // DATAREDIS-315

0 commit comments

Comments
 (0)