Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 436 lines (375 sloc) 13.436 kb
b78b722 @trondn fixup review comments
trondn authored
1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
2 /*
3 * Copyright 2012 Couchbase, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
0e1088e @trondn Remove mock-unit-tests.h
trondn authored
17 #include "config.h"
18 #include <gtest/gtest.h>
19 #include <libcouchbase/couchbase.h>
20
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
21 #include "server.h"
db50394 @mnunberg Make tests more modular
mnunberg authored
22 #include "mock-unit-test.h"
69a4ea3 @trondn Split up mock-unit-test.h
trondn authored
23 #include "mock-environment.h"
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
24
d521bf4 @mnunberg Instantiate the mock only once
mnunberg authored
25 /**
26 * Keep these around in case we do something useful here in the future
27 */
28 void MockUnitTest::SetUpTestCase() { }
29 void MockUnitTest::TearDownTestCase() { }
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
30
31 extern "C" {
19a3e34 @trondn Refactor the API
trondn authored
32 static void error_callback(lcb_t instance,
33 lcb_error_t err,
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
34 const char *errinfo)
35 {
19a3e34 @trondn Refactor the API
trondn authored
36 std::cerr << "Error " << lcb_strerror(instance, err);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
37 if (errinfo) {
38 std::cerr << errinfo;
39 }
40
41 ASSERT_TRUE(false);
42 }
43 }
44
19a3e34 @trondn Refactor the API
trondn authored
45 void MockUnitTest::createConnection(lcb_t &instance)
46 {
3df652b @trondn The mockenv should provide createConnection
trondn authored
47 MockEnvironment::getInstance()->createConnection(instance);
19a3e34 @trondn Refactor the API
trondn authored
48 (void)lcb_set_error_callback(instance, error_callback);
49 ASSERT_EQ(LCB_SUCCESS, lcb_connect(instance));
50 lcb_wait(instance);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
51 }
52
5b074bb @trondn Add server version test
trondn authored
53 extern "C" {
19a3e34 @trondn Refactor the API
trondn authored
54 static void flags_store_callback(lcb_t,
55 const void *,
56 lcb_storage_t operation,
57 lcb_error_t error,
58 const lcb_store_resp_t *resp)
59 {
60 ASSERT_EQ(LCB_SUCCESS, error);
61 ASSERT_EQ(5, resp->v.v0.nkey);
62 ASSERT_EQ(0, memcmp(resp->v.v0.key, "flags", 5));
63 ASSERT_EQ(LCB_SET, operation);
64 }
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
65
19a3e34 @trondn Refactor the API
trondn authored
66 static void flags_get_callback(lcb_t, const void *,
67 lcb_error_t error,
68 const lcb_get_resp_t *resp)
69 {
70 ASSERT_EQ(LCB_SUCCESS, error);
71 ASSERT_EQ(5, resp->v.v0.nkey);
72 ASSERT_EQ(0, memcmp(resp->v.v0.key, "flags", 5));
73 ASSERT_EQ(1, resp->v.v0.nbytes);
74 ASSERT_EQ(0, memcmp(resp->v.v0.bytes, "x", 1));
75 ASSERT_EQ(0xdeadbeef, resp->v.v0.flags);
76 }
77 }
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
78
19a3e34 @trondn Refactor the API
trondn authored
79 TEST_F(MockUnitTest, testFlags)
80 {
81 lcb_t instance;
82 createConnection(instance);
83 (void)lcb_set_get_callback(instance, flags_get_callback);
84 (void)lcb_set_store_callback(instance, flags_store_callback);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
85
19a3e34 @trondn Refactor the API
trondn authored
86 lcb_store_cmd_t storeCommand(LCB_SET, "flags", 5, "x", 1, 0xdeadbeef);
959a7c2 @avsej Reformat code
avsej authored
87 lcb_store_cmd_t *storeCommands[] = { &storeCommand };
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
88
19a3e34 @trondn Refactor the API
trondn authored
89 ASSERT_EQ(LCB_SUCCESS, lcb_store(instance, NULL, 1, storeCommands));
90 // Wait for it to be persisted
91 lcb_wait(instance);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
92
19a3e34 @trondn Refactor the API
trondn authored
93 lcb_get_cmd_t cmd("flags", 5);
94 lcb_get_cmd_t *cmds[] = { &cmd };
95 ASSERT_EQ(LCB_SUCCESS, lcb_get(instance, NULL, 1, cmds));
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
96
19a3e34 @trondn Refactor the API
trondn authored
97 /* Wait for it to be received */
98 lcb_wait(instance);
99 }
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
100
101
102 extern "C" {
19a3e34 @trondn Refactor the API
trondn authored
103 static void syncmode_store_callback(lcb_t,
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
104 const void *cookie,
19a3e34 @trondn Refactor the API
trondn authored
105 lcb_storage_t,
106 lcb_error_t error,
107 const lcb_store_resp_t *)
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
108 {
109 int *status = (int *)cookie;
110 *status = error;
111 }
112 }
113
114 TEST_F(MockUnitTest, testSyncmodeDefault)
115 {
116
19a3e34 @trondn Refactor the API
trondn authored
117 lcb_t instance;
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
118 createConnection(instance);
19a3e34 @trondn Refactor the API
trondn authored
119 ASSERT_EQ(LCB_ASYNCHRONOUS, lcb_behavior_get_syncmode(instance));
120 lcb_destroy(instance);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
121 }
122
123 TEST_F(MockUnitTest, testSyncmodeBehaviorToggle)
124 {
19a3e34 @trondn Refactor the API
trondn authored
125 lcb_t instance;
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
126 createConnection(instance);
19a3e34 @trondn Refactor the API
trondn authored
127 lcb_behavior_set_syncmode(instance, LCB_SYNCHRONOUS);
128 ASSERT_EQ(LCB_SYNCHRONOUS, lcb_behavior_get_syncmode(instance));
129 lcb_destroy(instance);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
130 }
131
132 TEST_F(MockUnitTest, testSyncStore)
133 {
19a3e34 @trondn Refactor the API
trondn authored
134 lcb_t instance;
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
135 createConnection(instance);
19a3e34 @trondn Refactor the API
trondn authored
136 lcb_behavior_set_syncmode(instance, LCB_SYNCHRONOUS);
137 ASSERT_EQ(LCB_SYNCHRONOUS, lcb_behavior_get_syncmode(instance));
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
138
19a3e34 @trondn Refactor the API
trondn authored
139 lcb_set_store_callback(instance, syncmode_store_callback);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
140
141 int cookie = 0xffff;
19a3e34 @trondn Refactor the API
trondn authored
142 lcb_store_cmd_t cmd(LCB_SET, "key", 3);
143 lcb_store_cmd_t *cmds[] = { &cmd };
144 lcb_error_t ret = lcb_store(instance, &cookie, 1, cmds);
145 ASSERT_EQ(LCB_SUCCESS, ret);
146 ASSERT_EQ((int)LCB_SUCCESS, cookie);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
147 cookie = 0xffff;
19a3e34 @trondn Refactor the API
trondn authored
148
149 cmd.v.v0.operation = LCB_ADD;
150 ret = lcb_store(instance, &cookie, 1, cmds);
151 ASSERT_TRUE(ret == LCB_KEY_EEXISTS &&
152 cookie == LCB_KEY_EEXISTS);
153 lcb_destroy(instance);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
154 }
155
156 extern "C" {
19a3e34 @trondn Refactor the API
trondn authored
157 static void timings_callback(lcb_t,
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
158 const void *cookie,
19a3e34 @trondn Refactor the API
trondn authored
159 lcb_timeunit_t timeunit,
160 lcb_uint32_t min,
161 lcb_uint32_t max,
162 lcb_uint32_t total,
163 lcb_uint32_t maxtotal)
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
164 {
19a3e34 @trondn Refactor the API
trondn authored
165 FILE *fp = (FILE *)cookie;
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
166 if (fp != NULL) {
167 fprintf(fp, "[%3u - %3u]", min, max);
168
169 switch (timeunit) {
19a3e34 @trondn Refactor the API
trondn authored
170 case LCB_TIMEUNIT_NSEC:
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
171 fprintf(fp, "ns");
172 break;
19a3e34 @trondn Refactor the API
trondn authored
173 case LCB_TIMEUNIT_USEC:
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
174 fprintf(fp, "us");
175 break;
19a3e34 @trondn Refactor the API
trondn authored
176 case LCB_TIMEUNIT_MSEC:
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
177 fprintf(fp, "ms");
178 break;
19a3e34 @trondn Refactor the API
trondn authored
179 case LCB_TIMEUNIT_SEC:
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
180 fprintf(fp, "s");
181 break;
182 default:
183 ;
184 }
185
186 int num = (int)((float)20.0 * (float)total / (float)maxtotal);
187
188 fprintf(fp, " |");
189 for (int ii = 0; ii < num; ++ii) {
190 fprintf(fp, "#");
191 }
192
193 fprintf(fp, " - %u\n", total);
194 }
195 }
196 }
197
198 TEST_F(MockUnitTest, testTimings)
199 {
200 FILE *fp = stdout;
19a3e34 @trondn Refactor the API
trondn authored
201 if (getenv("LCB_VERBOSE_TESTS") == NULL) {
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
202 fp = NULL;
203 }
204
19a3e34 @trondn Refactor the API
trondn authored
205 lcb_t instance;
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
206 createConnection(instance);
19a3e34 @trondn Refactor the API
trondn authored
207 lcb_enable_timings(instance);
208
209 lcb_store_cmd_t storecmd(LCB_SET, "counter", 7, "0", 1);
210 lcb_store_cmd_t *storecmds[] = { &storecmd };
211
212 lcb_store(instance, NULL, 1, storecmds);
213 lcb_wait(instance);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
214 for (int ii = 0; ii < 100; ++ii) {
19a3e34 @trondn Refactor the API
trondn authored
215 lcb_arithmetic_cmd_t acmd("counter", 7, 1);
216 lcb_arithmetic_cmd_t *acmds[] = { &acmd };
217 lcb_arithmetic(instance, NULL, 1, acmds);
218 lcb_wait(instance);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
219 }
220 if (fp) {
221 fprintf(fp, " +---------+---------+\n");
222 }
19a3e34 @trondn Refactor the API
trondn authored
223 lcb_get_timings(instance, fp, timings_callback);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
224 if (fp) {
225 fprintf(fp, " +--------------------\n");
226 }
19a3e34 @trondn Refactor the API
trondn authored
227 lcb_disable_timings(instance);
228 lcb_destroy(instance);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
229 }
230
231
232 extern "C" {
19a3e34 @trondn Refactor the API
trondn authored
233 static void timeout_error_callback(lcb_t instance,
234 lcb_error_t err,
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
235 const char *errinfo)
236 {
19a3e34 @trondn Refactor the API
trondn authored
237 if (err == LCB_ETIMEDOUT) {
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
238 return;
239 }
19a3e34 @trondn Refactor the API
trondn authored
240 std::cerr << "Error " << lcb_strerror(instance, err);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
241 if (errinfo) {
242 std::cerr << errinfo;
243 }
244 std::cerr << std::endl;
245 abort();
246 }
247
248 int timeout_seqno = 0;
249 int timeout_stats_done = 0;
250
19a3e34 @trondn Refactor the API
trondn authored
251 static void timeout_store_callback(lcb_t,
252 const void *cookie,
253 lcb_storage_t,
254 lcb_error_t error,
255 const lcb_store_resp_t *)
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
256 {
ed20aeb @trondn Refactor: lcb_create_io_ops should take struct
trondn authored
257 lcb_io_opt_t io = (lcb_io_opt_t)cookie;
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
258
19a3e34 @trondn Refactor the API
trondn authored
259 ASSERT_EQ(LCB_SUCCESS, error);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
260 timeout_seqno--;
261 if (timeout_stats_done && timeout_seqno == 0) {
262 io->stop_event_loop(io);
263 }
264 }
265
19a3e34 @trondn Refactor the API
trondn authored
266 static void timeout_stat_callback(lcb_t instance,
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
267 const void *cookie,
19a3e34 @trondn Refactor the API
trondn authored
268 lcb_error_t error,
cadb610 @trondn Refactor: server_version/stat should take struct
trondn authored
269 const lcb_server_stat_resp_t *resp)
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
270 {
19a3e34 @trondn Refactor the API
trondn authored
271 lcb_error_t err;
ed20aeb @trondn Refactor: lcb_create_io_ops should take struct
trondn authored
272 lcb_io_opt_t io = (lcb_io_opt_t)cookie;
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
273 char *statkey;
19a3e34 @trondn Refactor the API
trondn authored
274 lcb_size_t nstatkey;
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
275
cadb610 @trondn Refactor: server_version/stat should take struct
trondn authored
276 ASSERT_EQ(0, resp->version);
277 const char *server_endpoint = resp->v.v0.server_endpoint;
278 const void *key = resp->v.v0.key;
279 lcb_size_t nkey = resp->v.v0.nkey;
280 const void *bytes = resp->v.v0.bytes;
281 lcb_size_t nbytes = resp->v.v0.nbytes;
282
19a3e34 @trondn Refactor the API
trondn authored
283 ASSERT_EQ(LCB_SUCCESS, error);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
284 if (server_endpoint != NULL) {
285 nstatkey = strlen(server_endpoint) + nkey + 2;
286 statkey = new char[nstatkey];
19a3e34 @trondn Refactor the API
trondn authored
287 snprintf(statkey, nstatkey, "%s-%s", server_endpoint,
288 (const char *)key);
289
290 lcb_store_cmd_t storecmd(LCB_SET, statkey, nstatkey, bytes, nbytes);
291 lcb_store_cmd_t *storecmds[] = { &storecmd };
292 err = lcb_store(instance, io, 1, storecmds);
293 ASSERT_EQ(LCB_SUCCESS, err);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
294 timeout_seqno++;
295 delete []statkey;
296 } else {
297 timeout_stats_done = 1;
298 }
299 }
300 }
301
302 TEST_F(MockUnitTest, testTimeout)
303 {
304 // @todo we need to have a test that actually tests the timeout callback..
19a3e34 @trondn Refactor the API
trondn authored
305 lcb_t instance;
ed20aeb @trondn Refactor: lcb_create_io_ops should take struct
trondn authored
306 lcb_io_opt_t io;
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
307 createConnection(instance);
308
19a3e34 @trondn Refactor the API
trondn authored
309 (void)lcb_set_error_callback(instance, timeout_error_callback);
310 (void)lcb_set_stat_callback(instance, timeout_stat_callback);
311 (void)lcb_set_store_callback(instance, timeout_store_callback);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
312
ed20aeb @trondn Refactor: lcb_create_io_ops should take struct
trondn authored
313 io = (lcb_io_opt_t)lcb_get_cookie(instance);
cadb610 @trondn Refactor: server_version/stat should take struct
trondn authored
314
315 lcb_server_stats_cmd_t stat;
959a7c2 @avsej Reformat code
avsej authored
316 lcb_server_stats_cmd_t *commands[] = {&stat };
cadb610 @trondn Refactor: server_version/stat should take struct
trondn authored
317
318 ASSERT_EQ(LCB_SUCCESS, lcb_server_stats(instance, io, 1, commands));
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
319 io->run_event_loop(io);
19a3e34 @trondn Refactor the API
trondn authored
320 lcb_destroy(instance);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
321 }
322
323
324 TEST_F(MockUnitTest, testIssue59)
325 {
19a3e34 @trondn Refactor the API
trondn authored
326 // lcb_wait() blocks forever if there is nothing queued
327 lcb_t instance;
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
328 createConnection(instance);
19a3e34 @trondn Refactor the API
trondn authored
329 lcb_wait(instance);
330 lcb_wait(instance);
331 lcb_wait(instance);
332 lcb_wait(instance);
333 lcb_wait(instance);
334 lcb_wait(instance);
335 lcb_wait(instance);
336 lcb_wait(instance);
337 lcb_destroy(instance);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
338 }
339
340 extern "C" {
341 struct rvbuf {
19a3e34 @trondn Refactor the API
trondn authored
342 lcb_error_t error;
343 lcb_cas_t cas1;
344 lcb_cas_t cas2;
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
345 };
346
19a3e34 @trondn Refactor the API
trondn authored
347 static void df_store_callback1(lcb_t instance,
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
348 const void *cookie,
19a3e34 @trondn Refactor the API
trondn authored
349 lcb_storage_t,
350 lcb_error_t error,
351 const lcb_store_resp_t *)
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
352 {
353 struct rvbuf *rv = (struct rvbuf *)cookie;
354 rv->error = error;
ed20aeb @trondn Refactor: lcb_create_io_ops should take struct
trondn authored
355 lcb_io_opt_t io = (lcb_io_opt_t)lcb_get_cookie(instance);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
356 io->stop_event_loop(io);
357 }
358
19a3e34 @trondn Refactor the API
trondn authored
359 static void df_store_callback2(lcb_t instance,
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
360 const void *cookie,
19a3e34 @trondn Refactor the API
trondn authored
361 lcb_storage_t,
362 lcb_error_t error,
363 const lcb_store_resp_t *resp)
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
364 {
365 struct rvbuf *rv = (struct rvbuf *)cookie;
366 rv->error = error;
19a3e34 @trondn Refactor the API
trondn authored
367 rv->cas2 = resp->v.v0.cas;
ed20aeb @trondn Refactor: lcb_create_io_ops should take struct
trondn authored
368 lcb_io_opt_t io = (lcb_io_opt_t)lcb_get_cookie(instance);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
369 io->stop_event_loop(io);
370 }
371
19a3e34 @trondn Refactor the API
trondn authored
372 static void df_get_callback(lcb_t instance,
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
373 const void *cookie,
19a3e34 @trondn Refactor the API
trondn authored
374 lcb_error_t error,
375 const lcb_get_resp_t *resp)
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
376 {
377 struct rvbuf *rv = (struct rvbuf *)cookie;
378 const char *value = "{\"bar\"=>1, \"baz\"=>2}";
19a3e34 @trondn Refactor the API
trondn authored
379 lcb_size_t nvalue = strlen(value);
380 lcb_error_t err;
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
381
382 rv->error = error;
19a3e34 @trondn Refactor the API
trondn authored
383 rv->cas1 = resp->v.v0.cas;
384 lcb_store_cmd_t storecmd(LCB_SET, resp->v.v0.key, resp->v.v0.nkey,
385 value, nvalue, 0, 0, resp->v.v0.cas);
386 lcb_store_cmd_t *storecmds[] = { &storecmd };
387
388 err = lcb_store(instance, rv, 1, storecmds);
389 ASSERT_EQ(LCB_SUCCESS, err);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
390 }
391 }
392
393 TEST_F(MockUnitTest, testDoubleFreeError)
394 {
19a3e34 @trondn Refactor the API
trondn authored
395 lcb_error_t err;
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
396 struct rvbuf rv;
397 const char *key = "test_compare_and_swap_async_", *value = "{\"bar\" => 1}";
19a3e34 @trondn Refactor the API
trondn authored
398 lcb_size_t nkey = strlen(key), nvalue = strlen(value);
ed20aeb @trondn Refactor: lcb_create_io_ops should take struct
trondn authored
399 lcb_io_opt_t io;
19a3e34 @trondn Refactor the API
trondn authored
400 lcb_t instance;
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
401
402 createConnection(instance);
ed20aeb @trondn Refactor: lcb_create_io_ops should take struct
trondn authored
403 io = (lcb_io_opt_t)lcb_get_cookie(instance);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
404
405 /* prefill the bucket */
19a3e34 @trondn Refactor the API
trondn authored
406 (void)lcb_set_store_callback(instance, df_store_callback1);
407
408 lcb_store_cmd_t storecmd(LCB_SET, key, nkey, value, nvalue);
409 lcb_store_cmd_t *storecmds[] = { &storecmd };
410
411 err = lcb_store(instance, &rv, 1, storecmds);
412 ASSERT_EQ(LCB_SUCCESS, err);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
413 io->run_event_loop(io);
19a3e34 @trondn Refactor the API
trondn authored
414 ASSERT_EQ(LCB_SUCCESS, rv.error);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
415
416 /* run exercise
417 *
418 * 1. get the valueue and its cas
419 * 2. atomic set new valueue using old cas
420 */
19a3e34 @trondn Refactor the API
trondn authored
421 (void)lcb_set_store_callback(instance, df_store_callback2);
422 (void)lcb_set_get_callback(instance, df_get_callback);
423
424 lcb_get_cmd_t getcmd(key, nkey);
425 lcb_get_cmd_t *getcmds[] = { &getcmd };
426
427 err = lcb_get(instance, &rv, 1, getcmds);
428 ASSERT_EQ(LCB_SUCCESS, err);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
429 rv.cas1 = rv.cas2 = 0;
430 io->run_event_loop(io);
19a3e34 @trondn Refactor the API
trondn authored
431 ASSERT_EQ(LCB_SUCCESS, rv.error);
54cec5e @trondn Run some of the mock tests through gtest
trondn authored
432 ASSERT_GT(rv.cas1, 0);
433 ASSERT_GT(rv.cas2, 0);
434 ASSERT_NE(rv.cas1, rv.cas2);
435 }
Something went wrong with that request. Please try again.