forked from CodisLabs/codis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_hash.go
44 lines (38 loc) · 1007 Bytes
/
basic_hash.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2014 Wandoujia Inc. All Rights Reserved.
// Licensed under the MIT (MIT-LICENSE.txt) license.
package main
import (
"flag"
"fmt"
"hash/crc32"
"time"
)
type BasicHashTestCase struct {
proxy string
nkeys int
}
func init() {
testcase = &BasicHashTestCase{}
}
func (tc *BasicHashTestCase) init() {
flag.StringVar(&tc.proxy, "proxy", "", "redis host:port")
flag.IntVar(&tc.nkeys, "nkeys", 10000, "# of nkeys")
}
func (tc *BasicHashTestCase) main() {
c := NewConn(tc.proxy)
defer c.Close()
r := &Rand{time.Now().UnixNano()}
for i := 0; i < tc.nkeys; i++ {
u := NewUnit(fmt.Sprintf("basic_hash_%d_%d", r.Next(), r.Next()))
h, e := uint32(u.HashKey(c)), crc32.ChecksumIEEE([]byte(u.key))%1024
if h != e {
Panic("checksum key = '%s': return = %d, expect = %d", u.key, h, e)
}
u.key = fmt.Sprintf("%d_{%s}_%d", r.Next(), u.key, r.Next())
h = uint32(u.HashKey(c))
if h != e {
Panic("checksum key = '%s': return = %d, expect = %d", u.key, h, e)
}
ops.Incr()
}
}