]> git.saurik.com Git - redis.git/blob - tests/unit/archive.tcl
Add a unit test to verify that key archival works.
[redis.git] / tests / unit / archive.tcl
1 start_server {tags {"archive"}} {
2
3 test "archive - can archived keys be recovered?" {
4 # make sure to start with a blank instance
5 r flushall
6 # Turn on our key archival system
7 r config set keyarchive yes
8 # Get the current memory limit and calculate a new limit.
9 # We just add 100k to the current memory size so that it is
10 # fast for us to reach that limit.
11 set used [s used_memory]
12 set limit [expr {$used+100*1024}]
13 r config set maxmemory $limit
14 r config set maxmemory-policy allkeys-random
15 # Now add keys until the limit is almost reached.
16 set numkeys 0
17 while 1 {
18 # Odd keys are volatile
19 # Even keys are non volatile
20 if {$numkeys % 2} {
21 r setex "key:$numkeys" 10000 x
22 } else {
23 r set "key:$numkeys" x
24 }
25 if {[s used_memory]+4096 > $limit} {
26 assert {$numkeys > 10}
27 break
28 }
29 incr numkeys
30 }
31 # If we add the same number of keys already added again, we
32 # should still be under the limit.
33 for {set j 0} {$j < $numkeys} {incr j} {
34 r setex [randomKey] 10000 x
35 }
36 assert {[s used_memory] < ($limit+4096)}
37 # However all our non volatile keys should be here.
38 for {set j 0} {$j < $numkeys} {incr j 2} {
39 assert {[r exists "key:$j"]}
40 }
41 }
42
43 }