@@ -60,7 +60,7 @@ func TestSetGet(t *testing.T) {
60
60
fmt .Printf ("Set/Get/Del test successful\n " )
61
61
}
62
62
63
- func BenchmarkSet (b * testing.B ) {
63
+ func BenchmarkEtcdSet (b * testing.B ) {
64
64
setVal := JSONObj {
65
65
Value : "test1" ,
66
66
}
@@ -71,18 +71,23 @@ func BenchmarkSet(b *testing.B) {
71
71
}
72
72
}
73
73
74
- func BenchmarkGet (b * testing.B ) {
74
+ func BenchmarkEtcdGet (b * testing.B ) {
75
75
var retVal JSONObj
76
76
setVal := JSONObj {
77
77
Value : "test1" ,
78
78
}
79
79
80
- if err := client .SetObj ("/contiv.io/test" , setVal ); err != nil {
81
- b .Fatalf ("Fatal setting key. Err: %v" , err )
80
+ for n := 0 ; n < b .N ; n ++ {
81
+ if err := client .SetObj ("/contiv.io/test" + strconv .Itoa (n ), setVal ); err != nil {
82
+ b .Fatalf ("Fatal setting key. Err: %v" , err )
83
+ }
82
84
}
83
85
86
+ // Reset timer so that only gets are tested
87
+ b .ResetTimer ()
88
+
84
89
for n := 0 ; n < b .N ; n ++ {
85
- if err := client .GetObj ("/contiv.io/test" , & retVal ); err != nil {
90
+ if err := client .GetObj ("/contiv.io/test" + strconv . Itoa ( n ) , & retVal ); err != nil {
86
91
b .Fatalf ("Fatal getting key. Err: %v\n " , err )
87
92
}
88
93
@@ -92,77 +97,25 @@ func BenchmarkGet(b *testing.B) {
92
97
}
93
98
}
94
99
95
- func BenchmarkDel (b * testing.B ) {
100
+ func BenchmarkEtcdDel (b * testing.B ) {
96
101
setVal := JSONObj {
97
102
Value : "test1" ,
98
103
}
99
104
100
105
for n := 0 ; n < b .N ; n ++ {
101
- if err := client .SetObj ("/contiv.io/test" , setVal ); err != nil {
106
+ if err := client .SetObj ("/contiv.io/test" + strconv . Itoa ( n ) , setVal ); err != nil {
102
107
b .Fatalf ("Fatal setting key. Err: %v" , err )
103
108
}
104
-
105
- if err := client .DelObj ("/contiv.io/test" ); err != nil {
106
- b .Fatalf ("Fatal deleting test object. Err: %v" , err )
107
- }
108
109
}
109
- }
110
-
111
- func TestSetGetPerformance (t * testing.T ) {
112
- // Set
113
- setVal := JSONObj {
114
- Value : "test1" ,
115
- }
116
- var retVal JSONObj
117
-
118
- const testCount = 1000
119
110
120
- log .Infof ("Performing %d write tests" , testCount )
111
+ // Reset timer so that only gets are tested
112
+ b .ResetTimer ()
121
113
122
- startTime := time .Now ()
123
-
124
- for i := 0 ; i < testCount ; i ++ {
125
- if err := client .SetObj ("/contiv.io/test" + strconv .Itoa (i ), setVal ); err != nil {
126
- fmt .Printf ("Fatal setting key. Err: %v\n " , err )
127
- t .Fatalf ("Fatal setting key" )
128
- }
129
- }
130
-
131
- timeTook := time .Since (startTime ).Nanoseconds () / 1000000
132
- log .Infof ("Write Test took %d milli seconds per write. %d ms total" , timeTook / testCount , timeTook )
133
-
134
- log .Infof ("Performing %d read tests" , testCount )
135
-
136
- // Get test
137
- startTime = time .Now ()
138
-
139
- for i := 0 ; i < testCount ; i ++ {
140
- if err := client .GetObj ("/contiv.io/test" + strconv .Itoa (i ), & retVal ); err != nil {
141
- fmt .Printf ("Fatal getting key. Err: %v\n " , err )
142
- t .Fatalf ("Fatal getting key" )
143
- }
144
-
145
- if retVal .Value != "test1" {
146
- fmt .Printf ("Got invalid response: %+v\n " , retVal )
147
- t .Fatalf ("Got invalid response" )
148
- }
149
- }
150
-
151
- timeTook = time .Since (startTime ).Nanoseconds () / 1000000
152
- log .Infof ("Read Test took %d milli seconds per read. %d ms total" , timeTook / testCount , timeTook )
153
-
154
- startTime = time .Now ()
155
-
156
- for i := 0 ; i < testCount ; i ++ {
157
- if err := client .DelObj ("/contiv.io/test" + strconv .Itoa (i )); err != nil {
158
- t .Fatalf ("Fatal deleting test object. Err: %v" , err )
114
+ for n := 0 ; n < b .N ; n ++ {
115
+ if err := client .DelObj ("/contiv.io/test" + strconv .Itoa (n )); err != nil {
116
+ b .Fatalf ("Fatal deleting test object. Err: %v" , err )
159
117
}
160
118
}
161
-
162
- timeTook = time .Since (startTime ).Nanoseconds () / 1000000
163
- log .Infof ("Delete Test took %d milli seconds per delete. %d ms total" , timeTook / testCount , timeTook )
164
-
165
- fmt .Printf ("Set/Get/Del test successful\n " )
166
119
}
167
120
168
121
func TestConsulClientSetGet (t * testing.T ) {
@@ -194,61 +147,62 @@ func TestConsulClientSetGet(t *testing.T) {
194
147
fmt .Printf ("Consul Set/Get/Del test successful\n " )
195
148
}
196
149
197
- func TestConsulSetGetPerformance (t * testing.T ) {
198
- // Set
150
+ func BenchmarkConsulSet (b * testing.B ) {
199
151
setVal := JSONObj {
200
152
Value : "test1" ,
201
153
}
202
- var retVal JSONObj
203
-
204
- const testCount = 1000
205
-
206
- log .Infof ("Performing %d write tests" , testCount )
207
-
208
- startTime := time .Now ()
209
-
210
- for i := 0 ; i < testCount ; i ++ {
211
- if err := consulClient .SetObj ("/contiv.io/test" + strconv .Itoa (i ), setVal ); err != nil {
212
- fmt .Printf ("Fatal setting key. Err: %v\n " , err )
213
- t .Fatalf ("Fatal setting key" )
154
+ for n := 0 ; n < b .N ; n ++ {
155
+ if err := consulClient .SetObj ("/contiv.io/test" + strconv .Itoa (n ), setVal ); err != nil {
156
+ b .Fatalf ("Fatal setting key. Err: %v" , err )
214
157
}
215
158
}
159
+ }
216
160
217
- timeTook := time .Since (startTime ).Nanoseconds () / 1000000
218
- log .Infof ("Write Test took %d milli seconds per write. %d ms total" , timeTook / testCount , timeTook )
161
+ func BenchmarkConsulGet (b * testing.B ) {
162
+ var retVal JSONObj
163
+ setVal := JSONObj {
164
+ Value : "test1" ,
165
+ }
219
166
220
- log .Infof ("Performing %d read tests" , testCount )
167
+ for n := 0 ; n < b .N ; n ++ {
168
+ if err := consulClient .SetObj ("/contiv.io/test" + strconv .Itoa (n ), setVal ); err != nil {
169
+ b .Fatalf ("Fatal setting key. Err: %v" , err )
170
+ }
171
+ }
221
172
222
- // Get test
223
- startTime = time . Now ()
173
+ // Reset timer so that only gets are tested
174
+ b . ResetTimer ()
224
175
225
- for i := 0 ; i < testCount ; i ++ {
226
- if err := consulClient .GetObj ("/contiv.io/test" + strconv .Itoa (i ), & retVal ); err != nil {
227
- fmt .Printf ("Fatal getting key. Err: %v\n " , err )
228
- t .Fatalf ("Fatal getting key" )
176
+ for n := 0 ; n < b .N ; n ++ {
177
+ if err := consulClient .GetObj ("/contiv.io/test" + strconv .Itoa (n ), & retVal ); err != nil {
178
+ b .Fatalf ("Fatal getting key. Err: %v\n " , err )
229
179
}
230
180
231
181
if retVal .Value != "test1" {
232
- fmt .Printf ("Got invalid response: %+v\n " , retVal )
233
- t .Fatalf ("Got invalid response" )
182
+ b .Fatalf ("Got invalid response: %+v\n " , retVal )
234
183
}
235
184
}
185
+ }
236
186
237
- timeTook = time . Since ( startTime ). Nanoseconds () / 1000000
238
- log . Infof ( "Read Test took %d milli seconds per read. %d ms total" , timeTook / testCount , timeTook )
239
-
240
- startTime = time . Now ()
187
+ func BenchmarkConsulDel ( b * testing. B ) {
188
+ setVal := JSONObj {
189
+ Value : "test1" ,
190
+ }
241
191
242
- for i := 0 ; i < testCount ; i ++ {
243
- if err := consulClient .DelObj ("/contiv.io/test" + strconv .Itoa (i ) ); err != nil {
244
- t .Fatalf ("Fatal deleting test object . Err: %v" , err )
192
+ for n := 0 ; n < b . N ; n ++ {
193
+ if err := consulClient .SetObj ("/contiv.io/test" + strconv .Itoa (n ), setVal ); err != nil {
194
+ b .Fatalf ("Fatal setting key . Err: %v" , err )
245
195
}
246
196
}
247
197
248
- timeTook = time . Since ( startTime ). Nanoseconds () / 1000000
249
- log . Infof ( "Delete Test took %d milli seconds per delete. %d ms total" , timeTook / testCount , timeTook )
198
+ // Reset timer so that only gets are tested
199
+ b . ResetTimer ( )
250
200
251
- fmt .Printf ("Set/Get/Del test successful\n " )
201
+ for n := 0 ; n < b .N ; n ++ {
202
+ if err := consulClient .DelObj ("/contiv.io/test" + strconv .Itoa (n )); err != nil {
203
+ b .Fatalf ("Fatal deleting test object. Err: %v" , err )
204
+ }
205
+ }
252
206
}
253
207
254
208
func TestLockAcquireRelease (t * testing.T ) {
0 commit comments