-
Notifications
You must be signed in to change notification settings - Fork 7
/
session_integration_bench_test.go
145 lines (121 loc) · 3.2 KB
/
session_integration_bench_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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//go:build integration
package scylla
import (
"context"
"os/signal"
"syscall"
"testing"
)
func BenchmarkSessionQueryIntegration(b *testing.B) {
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGABRT, syscall.SIGTERM)
defer cancel()
session := newTestSession(ctx, b)
defer session.Close()
initStmts := []string{
"CREATE KEYSPACE IF NOT EXISTS mykeyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}",
"CREATE TABLE IF NOT EXISTS mykeyspace.triples (pk bigint PRIMARY KEY, v1 bigint, v2 bigint)",
"TRUNCATE TABLE mykeyspace.triples",
}
for _, stmt := range initStmts {
q := session.Query(stmt)
if _, err := q.Exec(ctx); err != nil {
b.Fatal(err)
}
}
insertQuery, err := session.Prepare(ctx, insertStmt)
if err != nil {
b.Fatal(err)
}
selectQuery, err := session.Prepare(ctx, selectStmt)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := int64(0); i < int64(b.N); i++ {
insertQuery.BindInt64(0, i).BindInt64(1, 2*i).BindInt64(2, 3*i)
_, err := insertQuery.Exec(ctx)
if err != nil {
b.Fatal(err)
}
}
for i := int64(0); i < int64(b.N); i++ {
selectQuery.BindInt64(0, i)
res, err := selectQuery.Exec(ctx)
if err != nil {
b.Fatal(err)
}
if len(res.Rows) != 1 {
b.Fatalf("expected 1 row, got %d", len(res.Rows))
}
v1, err := res.Rows[0][0].AsInt64()
if err != nil {
b.Fatal(err)
}
v2, err := res.Rows[0][1].AsInt64()
if err != nil {
b.Fatal(err)
}
if v1 != 2*i || v2 != 3*i {
b.Fatalf("expected (%d, %d), got (%d, %d)", 2*i, 3*i, v1, v2)
}
}
}
func BenchmarkSessionAsyncQueryIntegration(b *testing.B) {
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGABRT, syscall.SIGTERM)
defer cancel()
session := newTestSession(ctx, b)
defer session.Close()
initStmts := []string{
"CREATE KEYSPACE IF NOT EXISTS mykeyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}",
"CREATE TABLE IF NOT EXISTS mykeyspace.triples (pk bigint PRIMARY KEY, v1 bigint, v2 bigint)",
"TRUNCATE TABLE mykeyspace.triples",
}
for _, stmt := range initStmts {
q := session.Query(stmt)
if _, err := q.Exec(ctx); err != nil {
b.Fatal(err)
}
}
insertQuery, err := session.Prepare(ctx, insertStmt)
if err != nil {
b.Fatal(err)
}
selectQuery, err := session.Prepare(ctx, selectStmt)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := int64(0); i < int64(b.N); i++ {
insertQuery.BindInt64(0, i).BindInt64(1, 2*i).BindInt64(2, 3*i)
insertQuery.AsyncExec(ctx)
}
for i := int64(0); i < int64(b.N); i++ {
if _, err = insertQuery.Fetch(); err != nil {
b.Fatal(err)
}
}
for i := int64(0); i < int64(b.N); i++ {
selectQuery.BindInt64(0, i)
selectQuery.AsyncExec(ctx)
}
for i := int64(0); i < int64(b.N); i++ {
res, err := selectQuery.Fetch()
if err != nil {
b.Fatal(err)
}
if len(res.Rows) != 1 {
b.Fatalf("expected 1 row, got %d", len(res.Rows))
}
v1, err := res.Rows[0][0].AsInt64()
if err != nil {
b.Fatal(err)
}
v2, err := res.Rows[0][1].AsInt64()
if err != nil {
b.Fatal(err)
}
if v1 != 2*i || v2 != 3*i {
b.Fatalf("expected (%d, %d), got (%d, %d)", 2*i, 3*i, v1, v2)
}
}
}