/
cc_transactions_test.go
84 lines (66 loc) · 1.56 KB
/
cc_transactions_test.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package testbed
import (
"fmt"
"testing"
"github.com/totemtang/cc-testbed/clog"
)
func TestTransactions(t *testing.T) {
fmt.Println("======================")
fmt.Println("Test Transaction Begin")
fmt.Println("======================")
*SysType = PARTITION
nKeys := int64(100)
nParts := 6
*NumPart = nParts
s := float64(1)
var pKeysArray []int64
var p Partitioner
p = &HashPartitioner{
NParts: int64(nParts),
NKeys: nKeys,
}
store := NewStore()
//Create Keys
for i := int64(0); i < nKeys; i++ {
k := Key(i)
partNum := p.GetPartition(k)
store.CreateKV(k, int64(0), SINGLEINT, partNum)
}
pKeysArray = make([]int64, nParts)
for i := int64(0); i < nKeys; i++ {
key := Key(i)
pKeysArray[p.GetPartition(key)]++
}
zk := NewZipfKey(3, nKeys, nParts, pKeysArray, s, p)
rr := float64(0)
txnLen := 5
*CrossPercent = float64(0)
maxParts := 5
generator := NewTxnGen(ADD_ONE, rr, txnLen, maxParts, zk)
//New worker
worker := NewWorker(3, store)
var q *Query
for i := 0; i < 100; i++ {
q = generator.GenOneQuery()
//printOneQuery(q)
worker.One(q)
}
//PrintStore(store, nKeys, p)
PrintPartition(store, nKeys, p, 3)
fmt.Println("====================")
fmt.Println("Test Transaction End")
fmt.Println("====================")
}
func PrintPartition(s *Store, nKeys int64, p Partitioner, partNum int) {
for i := int64(0); i < nKeys; i++ {
k := Key(i)
if p.GetPartition(k) != partNum {
continue
}
r := s.GetRecord(k, partNum)
if r == nil {
clog.Error("Error No Key")
}
clog.Info("Key %v: %v", r.GetKey(), r.Value())
}
}