forked from scylladb/scylla-bench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
workloads_test.go
119 lines (104 loc) · 3.1 KB
/
workloads_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"fmt"
"math/rand"
"testing"
"time"
)
func TestSequentialWorkload(t *testing.T) {
generator := rand.New(rand.NewSource(int64(time.Now().Nanosecond())))
testCases := []struct {
partitionOffset int64
partitionCount int64
clusteringRowCount int64
}{
{10, 20, 30},
{0, 1, 1},
{generator.Int63n(100), generator.Int63n(100) + 100, generator.Int63n(99) + 1},
{generator.Int63n(100), generator.Int63n(100), generator.Int63n(100)},
{generator.Int63n(100), generator.Int63n(100) + 100, 1},
{0, generator.Int63n(100) + 100, generator.Int63n(99) + 1},
{0, generator.Int63n(100) + 100, generator.Int63n(99) + 1},
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("rand%d", i), func(t *testing.T) {
wrkld := NewSequentialVisitAll(tc.partitionOffset, tc.partitionCount, tc.clusteringRowCount)
expectedPk := tc.partitionOffset
expectedCk := int64(0)
for true {
if wrkld.IsDone() && expectedPk < tc.partitionOffset+tc.partitionCount {
t.Errorf("got end of stream; expected %d", expectedPk)
}
if !wrkld.IsDone() && expectedPk == tc.partitionOffset+tc.partitionCount {
t.Errorf("expected end of stream at %d", expectedPk)
}
if wrkld.IsDone() {
t.Log("got end of stream")
break
}
pk := wrkld.NextPartitionKey()
if pk != expectedPk {
t.Errorf("wrong PK; got %d; expected %d", pk, expectedPk)
} else {
t.Logf("got PK %d", pk)
}
ck := wrkld.NextClusteringKey()
if ck != expectedCk {
t.Errorf("wrong CK; got %d; expected %d", pk, expectedCk)
} else {
t.Logf("got CK %d", ck)
}
expectedCk++
if expectedCk == tc.clusteringRowCount {
if !wrkld.IsPartitionDone() {
t.Errorf("expected end of partition at %d", expectedCk)
} else {
t.Log("got end of partition")
}
expectedCk = 0
expectedPk++
} else {
if wrkld.IsPartitionDone() {
t.Errorf("got end of partition; expected %d", expectedCk)
}
}
}
})
}
}
func TestUniformWorkload(t *testing.T) {
generator := rand.New(rand.NewSource(int64(time.Now().Nanosecond())))
testCases := []struct {
partitionCount int64
clusteringRowCount int64
}{
{20, 30},
{1, 1},
{generator.Int63n(100) + 100, generator.Int63n(99) + 1},
{generator.Int63n(100), generator.Int63n(100)},
{generator.Int63n(100) + 100, 1},
{generator.Int63n(100) + 100, generator.Int63n(99) + 1},
{generator.Int63n(100) + 100, generator.Int63n(99) + 1},
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("rand%d", i), func(t *testing.T) {
wrkld := NewRandomUniform(i, tc.partitionCount, tc.clusteringRowCount)
for i := 0; i < 1000; i++ {
if wrkld.IsDone() {
t.Error("got end of stream")
}
pk := wrkld.NextPartitionKey()
if pk < 0 || pk >= tc.partitionCount {
t.Errorf("PK %d out of range: [0-%d)", pk, tc.partitionCount)
}
ck := wrkld.NextClusteringKey()
if ck < 0 || ck >= tc.clusteringRowCount {
t.Errorf("CK %d out of range: [0-%d)", pk, tc.clusteringRowCount)
}
if wrkld.IsPartitionDone() {
t.Error("got end of partition")
}
}
})
}
}