diff options
Diffstat (limited to 'examples/redis-unstable/tests/unit/moduleapi/zset.tcl')
| -rw-r--r-- | examples/redis-unstable/tests/unit/moduleapi/zset.tcl | 121 |
1 files changed, 0 insertions, 121 deletions
diff --git a/examples/redis-unstable/tests/unit/moduleapi/zset.tcl b/examples/redis-unstable/tests/unit/moduleapi/zset.tcl deleted file mode 100644 index f2a324c..0000000 --- a/examples/redis-unstable/tests/unit/moduleapi/zset.tcl +++ /dev/null | |||
| @@ -1,121 +0,0 @@ | |||
| 1 | set testmodule [file normalize tests/modules/zset.so] | ||
| 2 | |||
| 3 | start_server {tags {"modules external:skip"}} { | ||
| 4 | r module load $testmodule | ||
| 5 | |||
| 6 | test {Module zset rem} { | ||
| 7 | r del k | ||
| 8 | r zadd k 100 hello 200 world | ||
| 9 | assert_equal 1 [r zset.rem k hello] | ||
| 10 | assert_equal 0 [r zset.rem k hello] | ||
| 11 | assert_equal 1 [r exists k] | ||
| 12 | # Check that removing the last element deletes the key | ||
| 13 | assert_equal 1 [r zset.rem k world] | ||
| 14 | assert_equal 0 [r exists k] | ||
| 15 | } | ||
| 16 | |||
| 17 | test {Module zset add} { | ||
| 18 | r del k | ||
| 19 | # Check that failure does not create empty key | ||
| 20 | assert_error "ERR ZsetAdd failed" {r zset.add k nan hello} | ||
| 21 | assert_equal 0 [r exists k] | ||
| 22 | |||
| 23 | r zset.add k 100 hello | ||
| 24 | assert_equal {hello 100} [r zrange k 0 -1 withscores] | ||
| 25 | } | ||
| 26 | |||
| 27 | test {Module zset incrby} { | ||
| 28 | r del k | ||
| 29 | # Check that failure does not create empty key | ||
| 30 | assert_error "ERR ZsetIncrby failed" {r zset.incrby k hello nan} | ||
| 31 | assert_equal 0 [r exists k] | ||
| 32 | |||
| 33 | r zset.incrby k hello 100 | ||
| 34 | assert_equal {hello 100} [r zrange k 0 -1 withscores] | ||
| 35 | } | ||
| 36 | |||
| 37 | test {Module zset - KEYSIZES is updated as expected (like test at hash.tcl)} { | ||
| 38 | proc run_cmd_verify_hist {cmd expOutput {retries 1}} { | ||
| 39 | proc K {} {return [string map { "db0_distrib_zsets_items" "db0_ZSET" "# Keysizes" "" " " "" "\n" "" "\r" "" } [r info keysizes] ]} | ||
| 40 | uplevel 1 $cmd | ||
| 41 | wait_for_condition 50 $retries { | ||
| 42 | $expOutput eq [K] | ||
| 43 | } else { fail "Expected: \n`$expOutput`\n Actual:\n`[K]`.\nFailed after command: $cmd" } | ||
| 44 | } | ||
| 45 | |||
| 46 | r select 0 | ||
| 47 | |||
| 48 | #RedisModule_ZsetAdd, RedisModule_ZsetRem | ||
| 49 | run_cmd_verify_hist {r FLUSHALL} {} | ||
| 50 | run_cmd_verify_hist {r zset.add k 100 hello} {db0_ZSET:1=1} | ||
| 51 | run_cmd_verify_hist {r zset.add k 101 bye} {db0_ZSET:2=1} | ||
| 52 | run_cmd_verify_hist {r zset.rem k hello} {db0_ZSET:1=1} | ||
| 53 | run_cmd_verify_hist {r zset.rem k bye} {} | ||
| 54 | |||
| 55 | #RM_ZsetIncrby | ||
| 56 | run_cmd_verify_hist {r FLUSHALL} {} | ||
| 57 | run_cmd_verify_hist {r zset.incrby k hello 100} {db0_ZSET:1=1} | ||
| 58 | run_cmd_verify_hist {r zset.incrby k hello 100} {db0_ZSET:1=1} | ||
| 59 | run_cmd_verify_hist {r zset.rem k hello} {} | ||
| 60 | |||
| 61 | # Check lazy expire | ||
| 62 | r debug set-active-expire 0 | ||
| 63 | run_cmd_verify_hist {r zset.add k 100 hello} {db0_ZSET:1=1} | ||
| 64 | run_cmd_verify_hist {r pexpire k 2} {db0_ZSET:1=1} | ||
| 65 | run_cmd_verify_hist {after 5} {db0_ZSET:1=1} | ||
| 66 | r debug set-active-expire 1 | ||
| 67 | run_cmd_verify_hist {after 5} {} 50 | ||
| 68 | } | ||
| 69 | |||
| 70 | test {Module zset DELALL functionality} { | ||
| 71 | # Clean up any existing keys | ||
| 72 | r flushall | ||
| 73 | |||
| 74 | # Create some zsets and other types of keys | ||
| 75 | r zadd zset1 100 hello 200 world | ||
| 76 | r zadd zset2 300 foo 400 bar | ||
| 77 | r zadd zset3 500 baz | ||
| 78 | r set string1 "value1" | ||
| 79 | r hset hash1 field1 value1 | ||
| 80 | r lpush list1 item1 | ||
| 81 | |||
| 82 | # Verify we have the expected keys | ||
| 83 | assert_equal 6 [r dbsize] | ||
| 84 | assert_equal 3 [llength [r keys zset*]] | ||
| 85 | |||
| 86 | # Run zset.delall | ||
| 87 | set deleted [r zset.delall] | ||
| 88 | assert_equal 3 $deleted | ||
| 89 | |||
| 90 | # Verify only zsets were deleted | ||
| 91 | assert_equal 3 [r dbsize] | ||
| 92 | assert_equal 0 [llength [r keys zset*]] | ||
| 93 | assert_equal 1 [r exists string1] | ||
| 94 | assert_equal 1 [r exists hash1] | ||
| 95 | assert_equal 1 [r exists list1] | ||
| 96 | |||
| 97 | # Test with no zsets | ||
| 98 | set deleted [r zset.delall] | ||
| 99 | assert_equal 0 $deleted | ||
| 100 | assert_equal 3 [r dbsize] | ||
| 101 | } | ||
| 102 | |||
| 103 | test {Module zset DELALL not in transaction} { | ||
| 104 | set repl [attach_to_replication_stream] | ||
| 105 | r zadd z1 1 e1 | ||
| 106 | r zadd z2 1 e1 | ||
| 107 | r zset.delall | ||
| 108 | assert_replication_stream $repl { | ||
| 109 | {select *} | ||
| 110 | {zadd z1 1 e1} | ||
| 111 | {zadd z2 1 e1} | ||
| 112 | {del z*} | ||
| 113 | {del z*} | ||
| 114 | } | ||
| 115 | close_replication_stream $repl | ||
| 116 | } {} {needs:repl} | ||
| 117 | |||
| 118 | test "Unload the module - zset" { | ||
| 119 | assert_equal {OK} [r module unload zset] | ||
| 120 | } | ||
| 121 | } | ||
