Skip to content

Commit

Permalink
chore(kv): enhance test case (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
caojiajun committed Aug 9, 2024
1 parent 51a66bd commit 3139894
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ public static void testHash(CamelliaRedisTemplate template) {
Long hset2 = template.hset(key, "f1", "v1");
assertEquals(hset2, 0L);

Long hset3 = template.hset(key, "f1", "v2");
assertEquals(hset3, 0L);

Map<String, String> stringStringMap = template.hgetAll(key);
assertEquals(stringStringMap.size(), 1);
}
template.del(key);
{
Long hset1 = template.hset(key, "f1", "v1");
assertEquals(hset1, 1L);

Long hset2 = template.hset(key, "f1", "v1");
assertEquals(hset2, 0L);

Long hlen1 = template.hlen(key);
assertEquals(hlen1, 1L);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ public static void testHash(CamelliaRedisTemplate template) {
Long hset2 = template.hset(key, "f1", "v1");
assertEquals(hset2, 1L);

Long hset3 = template.hset(key, "f1", "v2");
assertEquals(hset3, 1L);

Map<String, String> stringStringMap = template.hgetAll(key);
assertEquals(stringStringMap.size(), 1);
}
template.del(key);
{
Long hset1 = template.hset(key, "f1", "v1");
assertEquals(hset1, 1L);

Long hset2 = template.hset(key, "f1", "v1");
assertEquals(hset2, 1L);

Long hlen1 = template.hlen(key);
assertEquals(hlen1, 1L);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ public static void testSet(CamelliaRedisTemplate template) {
String key = UUID.randomUUID().toString().replace("-", "");
keyThreadLocal.set(key);
//
template.del(key);
{
Long sadd = template.sadd(key, "a", "b", "c", "d", "e", "f");
assertEquals(sadd, 6L);

Long sadd1 = template.sadd(key, "a", "b", "c", "d", "e", "f", "g");
assertEquals(sadd1, 1L);

Long sadd2 = template.sadd(key, "a", "b");
assertEquals(sadd2, 0L);

Set<String> smembers = template.smembers(key);
assertEquals(smembers.size(), 7);
}

template.del(key);
{
Long sadd = template.sadd(key, "a", "b", "c", "d", "e", "f");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ public static void testSet(CamelliaRedisTemplate template) {

template.sadd(key, "a", "b", "c", "d", "e", "f", "g");

template.sadd(key, "a", "b");

Set<String> smembers = template.smembers(key);
assertEquals(smembers.size(), 7);
}
//
template.del(key);
{
template.sadd(key, "a", "b", "c", "d", "e", "f");

template.sadd(key, "a", "b", "c", "d", "e", "f", "g");

Set<String> smembers = template.smembers(key);
assertEquals(smembers.size(), 7);
assertEquals(smembers.contains("a"), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,33 @@ public static void testZSet(CamelliaRedisTemplate template) {

keyThreadLocal.set(key);

template.del(key);
{
Map<String, Double> map1 = new HashMap<>();
map1.put("v1", 1.0);
map1.put("v2", 2.0);
map1.put("v3", 3.0);
map1.put("v4", 4.0);
map1.put("v5", 5.0);
map1.put("v6", 6.0);
Long zadd = template.zadd(key, map1);
assertEquals(zadd, 6L);

Long zadd1 = template.zadd(key, map1);
assertEquals(zadd1, 0L);

map1.put("v7", 7.0);

Long zadd2 = template.zadd(key, map1);
assertEquals(zadd2, 1L);

Set<String> zrange = template.zrange(key, 0, -1);
assertEquals(zrange.size(), 7);

Set<String> strings = template.zrangeByScore(key, 0, 100);
assertEquals(strings.size(), 7);
}

template.del(key);

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,33 @@ public static void testZSet(CamelliaRedisTemplate template) {
String key = UUID.randomUUID().toString().replace("-", "");
keyThreadLocal.set(key);

template.del(key);
{
Map<String, Double> map1 = new HashMap<>();
map1.put("v1", 1.0);
map1.put("v2", 2.0);
map1.put("v3", 3.0);
map1.put("v4", 4.0);
map1.put("v5", 5.0);
map1.put("v6", 6.0);
Long zadd = template.zadd(key, map1);
assertEquals(zadd, 6L);

Long zadd1 = template.zadd(key, map1);
assertEquals(zadd1, 0L);

map1.put("v7", 7.0);

Long zadd2 = template.zadd(key, map1);
assertEquals(zadd2, 1L);

Set<String> zrange = template.zrange(key, 0, -1);
assertEquals(zrange.size(), 7);

Set<String> strings = template.zrangeByScore(key, 0, 100);
assertEquals(strings.size(), 7);
}

template.del(key);

{
Expand Down

0 comments on commit 3139894

Please sign in to comment.