X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/d84f776e873ea93f22dc230e2b10ee70a8a6cd2e..989a7820ca0cb1b88493797fdecd2e7168558859:/tests/unit/dump.tcl diff --git a/tests/unit/dump.tcl b/tests/unit/dump.tcl index b73cde0c..5c729136 100644 --- a/tests/unit/dump.tcl +++ b/tests/unit/dump.tcl @@ -23,10 +23,47 @@ start_server {tags {"dump"}} { set e } {*is busy*} + test {RESTORE can overwrite an existing key with REPLACE} { + r set foo bar1 + set encoded1 [r dump foo] + r set foo bar2 + set encoded2 [r dump foo] + r del foo + r restore foo 0 $encoded1 + r restore foo 0 $encoded2 replace + r get foo + } {bar2} + + test {RESTORE can detect a syntax error for unrecongized options} { + catch {r restore foo 0 "..." invalid-option} e + set e + } {*syntax*} + test {DUMP of non existing key returns nil} { r dump nonexisting_key } {} + test {MIGRATE is caching connections} { + # Note, we run this as first test so that the connection cache + # is empty. + set first [srv 0 client] + r set key "Some Value" + start_server {tags {"repl"}} { + set second [srv 0 client] + set second_host [srv 0 host] + set second_port [srv 0 port] + + assert_match {*migrate_cached_sockets:0*} [r -1 info] + r -1 migrate $second_host $second_port key 9 1000 + assert_match {*migrate_cached_sockets:1*} [r -1 info] + } + } + + test {MIGRATE cached connections are released after some time} { + after 15000 + assert_match {*migrate_cached_sockets:0*} [r info] + } + test {MIGRATE is able to migrate a key between two instances} { set first [srv 0 client] r set key "Some Value" @@ -46,6 +83,47 @@ start_server {tags {"dump"}} { } } + test {MIGRATE is able to copy a key between two instances} { + set first [srv 0 client] + r del list + r lpush list a b c d + start_server {tags {"repl"}} { + set second [srv 0 client] + set second_host [srv 0 host] + set second_port [srv 0 port] + + assert {[$first exists list] == 1} + assert {[$second exists list] == 0} + set ret [r -1 migrate $second_host $second_port list 9 5000 copy] + assert {$ret eq {OK}} + assert {[$first exists list] == 1} + assert {[$second exists list] == 1} + assert {[$first lrange list 0 -1] eq [$second lrange list 0 -1]} + } + } + + test {MIGRATE will not overwrite existing keys, unless REPLACE is used} { + set first [srv 0 client] + r del list + r lpush list a b c d + start_server {tags {"repl"}} { + set second [srv 0 client] + set second_host [srv 0 host] + set second_port [srv 0 port] + + assert {[$first exists list] == 1} + assert {[$second exists list] == 0} + $second set list somevalue + catch {r -1 migrate $second_host $second_port list 9 5000 copy} e + assert_match {ERR*} $e + set res [r -1 migrate $second_host $second_port list 9 5000 copy replace] + assert {$ret eq {OK}} + assert {[$first exists list] == 1} + assert {[$second exists list] == 1} + assert {[$first lrange list 0 -1] eq [$second lrange list 0 -1]} + } + } + test {MIGRATE propagates TTL correctly} { set first [srv 0 client] r set key "Some Value" @@ -91,6 +169,26 @@ start_server {tags {"dump"}} { } } + test {MIGRATE can correctly transfer hashes} { + set first [srv 0 client] + r del key + r hmset key field1 "item 1" field2 "item 2" field3 "item 3" \ + field4 "item 4" field5 "item 5" field6 "item 6" + start_server {tags {"repl"}} { + set second [srv 0 client] + set second_host [srv 0 host] + set second_port [srv 0 port] + + assert {[$first exists key] == 1} + assert {[$second exists key] == 0} + set ret [r -1 migrate $second_host $second_port key 9 10000] + assert {$ret eq {OK}} + assert {[$first exists key] == 0} + assert {[$second exists key] == 1} + assert {[$second ttl key] == -1} + } + } + test {MIGRATE timeout actually works} { set first [srv 0 client] r set key "Some Value" @@ -103,9 +201,9 @@ start_server {tags {"dump"}} { assert {[$second exists key] == 0} set rd [redis_deferring_client] - $rd debug sleep 5.0 ; # Make second server unable to reply. + $rd debug sleep 1.0 ; # Make second server unable to reply. set e {} - catch {r -1 migrate $second_host $second_port key 9 1000} e + catch {r -1 migrate $second_host $second_port key 9 500} e assert_match {IOERR*} $e } }