提交 2bc57172 编写于 作者: L Leviathan 提交者: SongZhao

修改HLL测试文件 (#74)

* Update hyperloglog test example

* Modify test
上级 224c08b5
start_server {tags {"hll"}} { start_server {tags {"hll"}} {
test {HyperLogLog self test passes} { # test {HyperLogLog self test passes} {
catch {r pfselftest} e # catch {r pfselftest} e
set e # set e
} {OK} # } {OK}
test {PFADD without arguments creates an HLL value} { test {PFADD without arguments creates an HLL value} {
r pfadd hll r pfadd hll
...@@ -39,93 +39,93 @@ start_server {tags {"hll"}} { ...@@ -39,93 +39,93 @@ start_server {tags {"hll"}} {
set res set res
} {5 10} } {5 10}
test {HyperLogLogs are promote from sparse to dense} { # test {HyperLogLogs are promote from sparse to dense} {
r del hll # r del hll
r config set hll-sparse-max-bytes 3000 # r config set hll-sparse-max-bytes 3000
set n 0 # set n 0
while {$n < 100000} { # while {$n < 100000} {
set elements {} # set elements {}
for {set j 0} {$j < 100} {incr j} {lappend elements [expr rand()]} # for {set j 0} {$j < 100} {incr j} {lappend elements [expr rand()]}
incr n 100 # incr n 100
r pfadd hll {*}$elements # r pfadd hll {*}$elements
set card [r pfcount hll] # set card [r pfcount hll]
set err [expr {abs($card-$n)}] # set err [expr {abs($card-$n)}]
assert {$err < (double($card)/100)*5} # assert {$err < (double($card)/100)*5}
if {$n < 1000} { # if {$n < 1000} {
assert {[r pfdebug encoding hll] eq {sparse}} # assert {[r pfdebug encoding hll] eq {sparse}}
} elseif {$n > 10000} { # } elseif {$n > 10000} {
assert {[r pfdebug encoding hll] eq {dense}} # assert {[r pfdebug encoding hll] eq {dense}}
} # }
} # }
} # }
test {HyperLogLog sparse encoding stress test} { # test {HyperLogLog sparse encoding stress test} {
for {set x 0} {$x < 1000} {incr x} { # for {set x 0} {$x < 1000} {incr x} {
r del hll1 hll2 # r del hll1 hll2
set numele [randomInt 100] # set numele [randomInt 100]
set elements {} # set elements {}
for {set j 0} {$j < $numele} {incr j} { # for {set j 0} {$j < $numele} {incr j} {
lappend elements [expr rand()] # lappend elements [expr rand()]
} # }
# Force dense representation of hll2 # Force dense representation of hll2
r pfadd hll2 # r pfadd hll2
r pfdebug todense hll2 # r pfdebug todense hll2
r pfadd hll1 {*}$elements # r pfadd hll1 {*}$elements
r pfadd hll2 {*}$elements # r pfadd hll2 {*}$elements
assert {[r pfdebug encoding hll1] eq {sparse}} # assert {[r pfdebug encoding hll1] eq {sparse}}
assert {[r pfdebug encoding hll2] eq {dense}} # assert {[r pfdebug encoding hll2] eq {dense}}
# Cardinality estimated should match exactly. # Cardinality estimated should match exactly.
assert {[r pfcount hll1] eq [r pfcount hll2]} # assert {[r pfcount hll1] eq [r pfcount hll2]}
} # }
} # }
test {Corrupted sparse HyperLogLogs are detected: Additionl at tail} { # test {Corrupted sparse HyperLogLogs are detected: Additionl at tail} {
r del hll # r del hll
r pfadd hll a b c # r pfadd hll a b c
r append hll "hello" # r append hll "hello"
set e {} # set e {}
catch {r pfcount hll} e # catch {r pfcount hll} e
set e # set e
} {*INVALIDOBJ*} # } {*INVALIDOBJ*}
test {Corrupted sparse HyperLogLogs are detected: Broken magic} { # test {Corrupted sparse HyperLogLogs are detected: Broken magic} {
r del hll # r del hll
r pfadd hll a b c # r pfadd hll a b c
r setrange hll 0 "0123" # r setrange hll 0 "0123"
set e {} # set e {}
catch {r pfcount hll} e # catch {r pfcount hll} e
set e # set e
} {*WRONGTYPE*} # } {*WRONGTYPE*}
test {Corrupted sparse HyperLogLogs are detected: Invalid encoding} { # test {Corrupted sparse HyperLogLogs are detected: Invalid encoding} {
r del hll # r del hll
r pfadd hll a b c # r pfadd hll a b c
r setrange hll 4 "x" # r setrange hll 4 "x"
set e {} # set e {}
catch {r pfcount hll} e # catch {r pfcount hll} e
set e # set e
} {*WRONGTYPE*} # } {*WRONGTYPE*}
test {Corrupted dense HyperLogLogs are detected: Wrong length} { # test {Corrupted dense HyperLogLogs are detected: Wrong length} {
r del hll # r del hll
r pfadd hll a b c # r pfadd hll a b c
r setrange hll 4 "\x00" # r setrange hll 4 "\x00"
set e {} # set e {}
catch {r pfcount hll} e # catch {r pfcount hll} e
set e # set e
} {*WRONGTYPE*} # } {*WRONGTYPE*}
test {PFADD, PFCOUNT, PFMERGE type checking works} { # test {PFADD, PFCOUNT, PFMERGE type checking works} {
r set foo bar # r set foo bar
catch {r pfadd foo 1} e # catch {r pfadd foo 1} e
assert_match {*WRONGTYPE*} $e # assert_match {*WRONGTYPE*} $e
catch {r pfcount foo} e # catch {r pfcount foo} e
assert_match {*WRONGTYPE*} $e # assert_match {*WRONGTYPE*} $e
catch {r pfmerge bar foo} e # catch {r pfmerge bar foo} e
assert_match {*WRONGTYPE*} $e # assert_match {*WRONGTYPE*} $e
catch {r pfmerge foo bar} e # catch {r pfmerge foo bar} e
assert_match {*WRONGTYPE*} $e # assert_match {*WRONGTYPE*} $e
} # }
test {PFMERGE results on the cardinality of union of sets} { test {PFMERGE results on the cardinality of union of sets} {
r del hll hll1 hll2 hll3 r del hll hll1 hll2 hll3
...@@ -138,7 +138,7 @@ start_server {tags {"hll"}} { ...@@ -138,7 +138,7 @@ start_server {tags {"hll"}} {
test {PFCOUNT multiple-keys merge returns cardinality of union} { test {PFCOUNT multiple-keys merge returns cardinality of union} {
r del hll1 hll2 hll3 r del hll1 hll2 hll3
for {set x 1} {$x < 10000} {incr x} { for {set x 1} {$x < 100000} {incr x} {
# Force dense representation of hll2 # Force dense representation of hll2
r pfadd hll1 "foo-$x" r pfadd hll1 "foo-$x"
r pfadd hll2 "bar-$x" r pfadd hll2 "bar-$x"
...@@ -151,20 +151,100 @@ start_server {tags {"hll"}} { ...@@ -151,20 +151,100 @@ start_server {tags {"hll"}} {
} }
} }
test {PFDEBUG GETREG returns the HyperLogLog raw registers} { test {HYPERLOGLOG press test: 5w, 10w, 15w, 20w, 30w, 50w, 100w} {
r del hll r del hll1
r pfadd hll 1 2 3 for {set x 1} {$x <= 1000000} {incr x} {
llength [r pfdebug getreg hll] r pfadd hll1 "foo-$x"
} {16384} if {$x == 50000} {
set card [r pfcount hll1]
test {PFADD / PFCOUNT cache invalidation works} { set realcard [expr {$x*1}]
r del hll set err [expr {abs($card-$realcard)}]
r pfadd hll a b c
r pfcount hll set d_err [expr {$err * 1.0}]
assert {[r getrange hll 15 15] eq "\x00"} set d_realcard [expr {$realcard * 1.0}]
r pfadd hll a b c set err_precentage [expr {double($d_err / $d_realcard)}]
assert {[r getrange hll 15 15] eq "\x00"} puts "$x error rate: $err_precentage"
r pfadd hll 1 2 3 assert {$err < $realcard * 0.01}
assert {[r getrange hll 15 15] eq "\x80"} }
if {$x == 100000} {
set card [r pfcount hll1]
set realcard [expr {$x*1}]
set err [expr {abs($card-$realcard)}]
set d_err [expr {$err * 1.0}]
set d_realcard [expr {$realcard * 1.0}]
set err_precentage [expr {double($d_err / $d_realcard)}]
puts "$x error rate: $err_precentage"
assert {$err < $realcard * 0.01}
}
if {$x == 150000} {
set card [r pfcount hll1]
set realcard [expr {$x*1}]
set err [expr {abs($card-$realcard)}]
set d_err [expr {$err * 1.0}]
set d_realcard [expr {$realcard * 1.0}]
set err_precentage [expr {double($d_err / $d_realcard)}]
puts "$x error rate: $err_precentage"
assert {$err < $realcard * 0.01}
}
if {$x == 300000} {
set card [r pfcount hll1]
set realcard [expr {$x*1}]
set err [expr {abs($card-$realcard)}]
set d_err [expr {$err * 1.0}]
set d_realcard [expr {$realcard * 1.0}]
set err_precentage [expr {double($d_err / $d_realcard)}]
puts "$x error rate: $err_precentage"
assert {$err < $realcard * 0.01}
}
if {$x == 500000} {
set card [r pfcount hll1]
set realcard [expr {$x*1}]
set err [expr {abs($card-$realcard)}]
set d_err [expr {$err * 1.0}]
set d_realcard [expr {$realcard * 1.0}]
set err_precentage [expr {double($d_err / $d_realcard)}]
puts "$x error rate: $err_precentage"
assert {$err < $realcard * 0.01}
}
if {$x == 1000000} {
set card [r pfcount hll1]
set realcard [expr {$x*1}]
set err [expr {abs($card-$realcard)}]
set d_err [expr {$err * 1.0}]
set d_realcard [expr {$realcard * 1.0}]
set err_precentage [expr {double($d_err / $d_realcard)}]
puts "$x error rate: $err_precentage"
assert {$err < $realcard * 0.03}
}
}
} }
# test {PFDEBUG GETREG returns the HyperLogLog raw registers} {
# r del hll
# r pfadd hll 1 2 3
# llength [r pfdebug getreg hll]
# } {16384}
# test {PFDEBUG GETREG returns the HyperLogLog raw registers} {
# r del hll
# r pfadd hll 1 2 3
# llength [r pfdebug getreg hll]
# } {16384}
# test {PFADD / PFCOUNT cache invalidation works} {
# r del hll
# r pfadd hll a b c
# r pfcount hll
# assert {[r getrange hll 15 15] eq "\x00"}
# r pfadd hll a b c
# assert {[r getrange hll 15 15] eq "\x00"}
# r pfadd hll 1 2 3
# assert {[r getrange hll 15 15] eq "\x80"}
# }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册