015fa49ca377353dd05fb17eaf040977f1efba74
[awesomized/libmemcached] / tests / function.c
1 /*
2 Sample test application.
3 */
4 #include <assert.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <sys/time.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <unistd.h>
12 #include <time.h>
13 #include "server.h"
14 #include "../clients/generator.h"
15 #include "../clients/execute.h"
16
17 #ifndef INT64_MAX
18 #define INT64_MAX LONG_MAX
19 #endif
20 #ifndef INT32_MAX
21 #define INT32_MAX INT_MAX
22 #endif
23
24
25 #include "test.h"
26
27 #define GLOBAL_COUNT 100000
28 #define GLOBAL2_COUNT 1000
29 static uint32_t global_count;
30
31 static pairs_st *global_pairs;
32 static char *global_keys[GLOBAL_COUNT];
33 static size_t global_keys_length[GLOBAL_COUNT];
34
35 test_return init_test(memcached_st *not_used)
36 {
37 memcached_st memc;
38
39 (void)memcached_create(&memc);
40 memcached_free(&memc);
41
42 return 0;
43 }
44
45 test_return server_list_null_test(memcached_st *ptr)
46 {
47 memcached_server_st *server_list;
48 memcached_return rc;
49
50 server_list= memcached_server_list_append(NULL, NULL, 0, NULL);
51 assert(server_list == NULL);
52
53 server_list= memcached_server_list_append(NULL, "localhost", 0, NULL);
54 assert(server_list == NULL);
55
56 server_list= memcached_server_list_append(NULL, NULL, 0, &rc);
57 assert(server_list == NULL);
58
59 return 0;
60 }
61
62 #define TEST_PORT_COUNT 7
63 uint32_t test_ports[TEST_PORT_COUNT];
64
65 memcached_return server_display_function(memcached_st *ptr, memcached_server_st *server, void *context)
66 {
67 /* Do Nothing */
68 uint32_t bigger= *((uint32_t *)(context));
69 assert(bigger <= server->port);
70 *((uint32_t *)(context))= server->port;
71
72 return MEMCACHED_SUCCESS;
73 }
74
75 test_return server_sort_test(memcached_st *ptr)
76 {
77 uint8_t x;
78 uint32_t bigger= 0; /* Prime the value for the assert in server_display_function */
79 memcached_return rc;
80 memcached_server_function callbacks[1];
81 memcached_st *local_memc;
82
83 local_memc= memcached_create(NULL);
84 assert(local_memc);
85 memcached_behavior_set(local_memc, MEMCACHED_BEHAVIOR_SORT_HOSTS, 1);
86
87 for (x= 0; x < TEST_PORT_COUNT; x++)
88 {
89 test_ports[x]= random() % 64000;
90 rc= memcached_server_add(local_memc, "localhost", test_ports[x]);
91 assert(local_memc->number_of_hosts == x+1);
92 assert(local_memc->hosts[0].count == x+1);
93 assert(rc == MEMCACHED_SUCCESS);
94 }
95
96 callbacks[0]= server_display_function;
97 memcached_server_cursor(local_memc, callbacks, (void *)&bigger, 1);
98
99
100 memcached_free(local_memc);
101
102 return 0;
103 }
104
105 memcached_return server_display_unsort_function(memcached_st *ptr, memcached_server_st *server, void *context)
106 {
107 /* Do Nothing */
108 uint32_t x= *((uint32_t *)(context));
109
110 assert(test_ports[x] == server->port);
111 *((uint32_t *)(context))= ++x;
112
113 return MEMCACHED_SUCCESS;
114 }
115
116 test_return server_unsort_test(memcached_st *ptr)
117 {
118 uint8_t x;
119 uint32_t counter= 0; /* Prime the value for the assert in server_display_function */
120 uint32_t bigger= 0; /* Prime the value for the assert in server_display_function */
121 memcached_return rc;
122 memcached_server_function callbacks[1];
123 memcached_st *local_memc;
124
125 local_memc= memcached_create(NULL);
126 assert(local_memc);
127
128 for (x= 0; x < TEST_PORT_COUNT; x++)
129 {
130 test_ports[x]= random() % 64000;
131 rc= memcached_server_add(local_memc, "localhost", test_ports[x]);
132 assert(local_memc->number_of_hosts == x+1);
133 assert(local_memc->hosts[0].count == x+1);
134 assert(rc == MEMCACHED_SUCCESS);
135 }
136
137 callbacks[0]= server_display_unsort_function;
138 memcached_server_cursor(local_memc, callbacks, (void *)&counter, 1);
139
140 /* Now we sort old data! */
141 memcached_behavior_set(local_memc, MEMCACHED_BEHAVIOR_SORT_HOSTS, 1);
142 callbacks[0]= server_display_function;
143 memcached_server_cursor(local_memc, callbacks, (void *)&bigger, 1);
144
145
146 memcached_free(local_memc);
147
148 return 0;
149 }
150
151 test_return allocation_test(memcached_st *not_used)
152 {
153 memcached_st *memc;
154 memc= memcached_create(NULL);
155 assert(memc);
156 memcached_free(memc);
157
158 return 0;
159 }
160
161 test_return clone_test(memcached_st *memc)
162 {
163 /* All null? */
164 {
165 memcached_st *clone;
166 clone= memcached_clone(NULL, NULL);
167 assert(clone);
168 memcached_free(clone);
169 }
170
171 /* Can we init from null? */
172 {
173 memcached_st *clone;
174 clone= memcached_clone(NULL, memc);
175 assert(clone);
176 memcached_free(clone);
177 }
178
179 /* Can we init from struct? */
180 {
181 memcached_st declared_clone;
182 memcached_st *clone;
183 clone= memcached_clone(&declared_clone, NULL);
184 assert(clone);
185 memcached_free(clone);
186 }
187
188 /* Can we init from struct? */
189 {
190 memcached_st declared_clone;
191 memcached_st *clone;
192 clone= memcached_clone(&declared_clone, memc);
193 assert(clone);
194 memcached_free(clone);
195 }
196
197 return 0;
198 }
199
200 test_return connection_test(memcached_st *memc)
201 {
202 memcached_return rc;
203
204 rc= memcached_server_add(memc, "localhost", 0);
205 assert(rc == MEMCACHED_SUCCESS);
206
207 return 0;
208 }
209
210 test_return error_test(memcached_st *memc)
211 {
212 memcached_return rc;
213
214 for (rc= MEMCACHED_SUCCESS; rc < MEMCACHED_MAXIMUM_RETURN; rc++)
215 {
216 printf("Error %d -> %s\n", rc, memcached_strerror(memc, rc));
217 }
218
219 return 0;
220 }
221
222 test_return set_test(memcached_st *memc)
223 {
224 memcached_return rc;
225 char *key= "foo";
226 char *value= "when we sanitize";
227
228 rc= memcached_set(memc, key, strlen(key),
229 value, strlen(value),
230 (time_t)0, (uint32_t)0);
231 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
232
233 return 0;
234 }
235
236 test_return append_test(memcached_st *memc)
237 {
238 memcached_return rc;
239 char *key= "fig";
240 char *value= "we";
241 size_t value_length;
242 uint32_t flags;
243
244 rc= memcached_flush(memc, 0);
245 assert(rc == MEMCACHED_SUCCESS);
246
247 rc= memcached_set(memc, key, strlen(key),
248 value, strlen(value),
249 (time_t)0, (uint32_t)0);
250 assert(rc == MEMCACHED_SUCCESS);
251
252 rc= memcached_append(memc, key, strlen(key),
253 " the", strlen(" the"),
254 (time_t)0, (uint32_t)0);
255 assert(rc == MEMCACHED_SUCCESS);
256
257 rc= memcached_append(memc, key, strlen(key),
258 " people", strlen(" people"),
259 (time_t)0, (uint32_t)0);
260 assert(rc == MEMCACHED_SUCCESS);
261
262 value= memcached_get(memc, key, strlen(key),
263 &value_length, &flags, &rc);
264 assert(!memcmp(value, "we the people", strlen("we the people")));
265 assert(strlen("we the people") == value_length);
266 assert(rc == MEMCACHED_SUCCESS);
267 free(value);
268
269 return 0;
270 }
271
272 test_return append_binary_test(memcached_st *memc)
273 {
274 memcached_return rc;
275 char *key= "numbers";
276 unsigned int *store_ptr;
277 unsigned int store_list[] = { 23, 56, 499, 98, 32847, 0 };
278 char *value;
279 size_t value_length;
280 uint32_t flags;
281 unsigned int x;
282
283 rc= memcached_flush(memc, 0);
284 assert(rc == MEMCACHED_SUCCESS);
285
286 rc= memcached_set(memc,
287 key, strlen(key),
288 NULL, 0,
289 (time_t)0, (uint32_t)0);
290 assert(rc == MEMCACHED_SUCCESS);
291
292 for (x= 0; store_list[x] ; x++)
293 {
294 rc= memcached_append(memc,
295 key, strlen(key),
296 (char *)&store_list[x], sizeof(unsigned int),
297 (time_t)0, (uint32_t)0);
298 assert(rc == MEMCACHED_SUCCESS);
299 }
300
301 value= memcached_get(memc, key, strlen(key),
302 &value_length, &flags, &rc);
303 assert((value_length == (sizeof(unsigned int) * x)));
304 assert(rc == MEMCACHED_SUCCESS);
305
306 store_ptr= (unsigned int *)value;
307 x= 0;
308 while ((size_t)store_ptr < (size_t)(value + value_length))
309 {
310 assert(*store_ptr == store_list[x++]);
311 store_ptr++;
312 }
313 free(value);
314
315 return 0;
316 }
317
318 test_return cas2_test(memcached_st *memc)
319 {
320 memcached_return rc;
321 char *keys[]= {"fudge", "son", "food"};
322 size_t key_length[]= {5, 3, 4};
323 char *value= "we the people";
324 size_t value_length= strlen("we the people");
325 unsigned int x;
326 memcached_result_st results_obj;
327 memcached_result_st *results;
328 unsigned int set= 1;
329
330 rc= memcached_flush(memc, 0);
331 assert(rc == MEMCACHED_SUCCESS);
332
333 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, set);
334
335 for (x= 0; x < 3; x++)
336 {
337 rc= memcached_set(memc, keys[x], key_length[x],
338 keys[x], key_length[x],
339 (time_t)50, (uint32_t)9);
340 assert(rc == MEMCACHED_SUCCESS);
341 }
342
343 rc= memcached_mget(memc, keys, key_length, 3);
344
345 results= memcached_result_create(memc, &results_obj);
346
347 results= memcached_fetch_result(memc, &results_obj, &rc);
348 assert(results);
349 assert(results->cas);
350 assert(rc == MEMCACHED_SUCCESS);
351 WATCHPOINT_ASSERT(memcached_result_cas(results));
352
353 assert(!memcmp(value, "we the people", strlen("we the people")));
354 assert(strlen("we the people") == value_length);
355 assert(rc == MEMCACHED_SUCCESS);
356
357 memcached_result_free(&results_obj);
358
359 return 0;
360 }
361
362 test_return cas_test(memcached_st *memc)
363 {
364 memcached_return rc;
365 char *key= "fun";
366 size_t key_length= strlen("fun");
367 char *value= "we the people";
368 size_t value_length= strlen("we the people");
369 memcached_result_st results_obj;
370 memcached_result_st *results;
371 unsigned int set= 1;
372
373 rc= memcached_flush(memc, 0);
374 assert(rc == MEMCACHED_SUCCESS);
375
376 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, set);
377
378 rc= memcached_set(memc, key, strlen(key),
379 value, strlen(value),
380 (time_t)0, (uint32_t)0);
381 assert(rc == MEMCACHED_SUCCESS);
382
383 rc= memcached_mget(memc, &key, &key_length, 1);
384
385 results= memcached_result_create(memc, &results_obj);
386
387 results= memcached_fetch_result(memc, &results_obj, &rc);
388 assert(results);
389 assert(rc == MEMCACHED_SUCCESS);
390 WATCHPOINT_ASSERT(memcached_result_cas(results));
391
392 assert(!memcmp(value, "we the people", strlen("we the people")));
393 assert(strlen("we the people") == value_length);
394 assert(rc == MEMCACHED_SUCCESS);
395
396 rc= memcached_cas(memc, key, key_length,
397 "change the value", strlen("change the value"),
398 0, 0, memcached_result_cas(results));
399
400 assert(rc == MEMCACHED_SUCCESS);
401
402 rc= memcached_cas(memc, key, key_length,
403 "change the value", strlen("change the value"),
404 0, 0, 23);
405
406 assert(rc == MEMCACHED_DATA_EXISTS);
407
408
409 memcached_result_free(&results_obj);
410
411 return 0;
412 }
413
414 test_return prepend_test(memcached_st *memc)
415 {
416 memcached_return rc;
417 char *key= "fig";
418 char *value= "people";
419 size_t value_length;
420 uint32_t flags;
421
422 rc= memcached_flush(memc, 0);
423 assert(rc == MEMCACHED_SUCCESS);
424
425 rc= memcached_set(memc, key, strlen(key),
426 value, strlen(value),
427 (time_t)0, (uint32_t)0);
428 assert(rc == MEMCACHED_SUCCESS);
429
430 rc= memcached_prepend(memc, key, strlen(key),
431 "the ", strlen("the "),
432 (time_t)0, (uint32_t)0);
433 assert(rc == MEMCACHED_SUCCESS);
434
435 rc= memcached_prepend(memc, key, strlen(key),
436 "we ", strlen("we "),
437 (time_t)0, (uint32_t)0);
438 assert(rc == MEMCACHED_SUCCESS);
439
440 value= memcached_get(memc, key, strlen(key),
441 &value_length, &flags, &rc);
442 assert(!memcmp(value, "we the people", strlen("we the people")));
443 assert(strlen("we the people") == value_length);
444 assert(rc == MEMCACHED_SUCCESS);
445 free(value);
446
447 return 0;
448 }
449
450 /*
451 Set the value, then quit to make sure it is flushed.
452 Come back in and test that add fails.
453 */
454 test_return add_test(memcached_st *memc)
455 {
456 memcached_return rc;
457 char *key= "foo";
458 char *value= "when we sanitize";
459 unsigned long long setting_value;
460
461 setting_value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK);
462
463 rc= memcached_set(memc, key, strlen(key),
464 value, strlen(value),
465 (time_t)0, (uint32_t)0);
466 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
467 memcached_quit(memc);
468 rc= memcached_add(memc, key, strlen(key),
469 value, strlen(value),
470 (time_t)0, (uint32_t)0);
471
472 /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */
473 if (setting_value)
474 assert(rc == MEMCACHED_NOTSTORED || rc == MEMCACHED_STORED);
475 else
476 assert(rc == MEMCACHED_NOTSTORED);
477
478 return 0;
479 }
480
481 test_return add_wrapper(memcached_st *memc)
482 {
483 unsigned int x;
484
485 for (x= 0; x < 10000; x++)
486 add_test(memc);
487
488 return 0;
489 }
490
491 test_return replace_test(memcached_st *memc)
492 {
493 memcached_return rc;
494 char *key= "foo";
495 char *value= "when we sanitize";
496 char *original= "first we insert some data";
497
498 rc= memcached_set(memc, key, strlen(key),
499 original, strlen(original),
500 (time_t)0, (uint32_t)0);
501 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
502
503 rc= memcached_replace(memc, key, strlen(key),
504 value, strlen(value),
505 (time_t)0, (uint32_t)0);
506 assert(rc == MEMCACHED_SUCCESS);
507
508 return 0;
509 }
510
511 test_return delete_test(memcached_st *memc)
512 {
513 memcached_return rc;
514 char *key= "foo";
515 char *value= "when we sanitize";
516
517 rc= memcached_set(memc, key, strlen(key),
518 value, strlen(value),
519 (time_t)0, (uint32_t)0);
520 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
521
522 rc= memcached_delete(memc, key, strlen(key), (time_t)0);
523 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
524
525 return 0;
526 }
527
528 test_return flush_test(memcached_st *memc)
529 {
530 memcached_return rc;
531
532 rc= memcached_flush(memc, 0);
533 assert(rc == MEMCACHED_SUCCESS);
534
535 return 0;
536 }
537
538 memcached_return server_function(memcached_st *ptr, memcached_server_st *server, void *context)
539 {
540 /* Do Nothing */
541
542 return MEMCACHED_SUCCESS;
543 }
544
545 test_return memcached_server_cursor_test(memcached_st *memc)
546 {
547 char *context= "foo bad";
548 memcached_server_function callbacks[1];
549
550 callbacks[0]= server_function;
551 memcached_server_cursor(memc, callbacks, context, 1);
552
553 return 0;
554 }
555
556 test_return bad_key_test(memcached_st *memc)
557 {
558 memcached_return rc;
559 char *key= "foo bad";
560 char *string;
561 size_t string_length;
562 uint32_t flags;
563 memcached_st *clone;
564 unsigned int set= 1;
565
566 clone= memcached_clone(NULL, memc);
567 assert(clone);
568
569 (void)memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set);
570
571 string= memcached_get(clone, key, strlen(key),
572 &string_length, &flags, &rc);
573 assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
574 assert(string_length == 0);
575 assert(!string);
576
577 set= 0;
578 (void)memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set);
579 string= memcached_get(clone, key, strlen(key),
580 &string_length, &flags, &rc);
581 assert(rc == MEMCACHED_NOTFOUND);
582 assert(string_length == 0);
583 assert(!string);
584
585 memcached_free(clone);
586
587 return 0;
588 }
589
590 #define READ_THROUGH_VALUE "set for me"
591 memcached_return read_through_trigger(memcached_st *memc,
592 char *key, size_t key_length,
593 memcached_result_st *result)
594 {
595
596 return memcached_result_set_value(result, READ_THROUGH_VALUE, strlen(READ_THROUGH_VALUE));
597 }
598
599 test_return read_through(memcached_st *memc)
600 {
601 memcached_return rc;
602 char *key= "foo";
603 char *string;
604 size_t string_length;
605 uint32_t flags;
606
607 string= memcached_get(memc, key, strlen(key),
608 &string_length, &flags, &rc);
609
610 assert(rc == MEMCACHED_NOTFOUND);
611 assert(string_length == 0);
612 assert(!string);
613
614 rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_GET_FAILURE, read_through_trigger);
615 assert(rc == MEMCACHED_SUCCESS);
616
617 string= memcached_get(memc, key, strlen(key),
618 &string_length, &flags, &rc);
619
620 assert(rc == MEMCACHED_SUCCESS);
621 assert(string_length == strlen(READ_THROUGH_VALUE));
622 assert(!strcmp(READ_THROUGH_VALUE, string));
623 free(string);
624
625 string= memcached_get(memc, key, strlen(key),
626 &string_length, &flags, &rc);
627
628 assert(rc == MEMCACHED_SUCCESS);
629 assert(string_length == strlen(READ_THROUGH_VALUE));
630 assert(!strcmp(READ_THROUGH_VALUE, string));
631 free(string);
632
633 return 0;
634 }
635
636 memcached_return delete_trigger(memcached_st *ptr, const char *key, size_t key_length)
637 {
638 assert(key);
639
640 return MEMCACHED_SUCCESS;
641 }
642
643 test_return delete_through(memcached_st *memc)
644 {
645 memcached_trigger_delete_key callback;
646 memcached_return rc;
647
648 callback= delete_trigger;
649
650 rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_DELETE_TRIGGER, callback);
651 assert(rc == MEMCACHED_SUCCESS);
652
653 return 0;
654 }
655
656 test_return get_test(memcached_st *memc)
657 {
658 memcached_return rc;
659 char *key= "foo";
660 char *string;
661 size_t string_length;
662 uint32_t flags;
663
664 rc= memcached_delete(memc, key, strlen(key), (time_t)0);
665 assert(rc == MEMCACHED_BUFFERED || rc == MEMCACHED_NOTFOUND);
666
667 string= memcached_get(memc, key, strlen(key),
668 &string_length, &flags, &rc);
669
670 assert(rc == MEMCACHED_NOTFOUND);
671 assert(string_length == 0);
672 assert(!string);
673
674 return 0;
675 }
676
677 test_return get_test2(memcached_st *memc)
678 {
679 memcached_return rc;
680 char *key= "foo";
681 char *value= "when we sanitize";
682 char *string;
683 size_t string_length;
684 uint32_t flags;
685
686 rc= memcached_set(memc, key, strlen(key),
687 value, strlen(value),
688 (time_t)0, (uint32_t)0);
689 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
690
691 string= memcached_get(memc, key, strlen(key),
692 &string_length, &flags, &rc);
693
694 assert(string);
695 assert(rc == MEMCACHED_SUCCESS);
696 assert(string_length == strlen(value));
697 assert(!memcmp(string, value, string_length));
698
699 free(string);
700
701 return 0;
702 }
703
704 test_return set_test2(memcached_st *memc)
705 {
706 memcached_return rc;
707 char *key= "foo";
708 char *value= "train in the brain";
709 size_t value_length= strlen(value);
710 unsigned int x;
711
712 for (x= 0; x < 10; x++)
713 {
714 rc= memcached_set(memc, key, strlen(key),
715 value, value_length,
716 (time_t)0, (uint32_t)0);
717 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
718 }
719
720 return 0;
721 }
722
723 test_return set_test3(memcached_st *memc)
724 {
725 memcached_return rc;
726 char *key= "foo";
727 char *value;
728 size_t value_length= 8191;
729 unsigned int x;
730
731 value = (char*)malloc(value_length);
732 assert(value);
733
734 for (x= 0; x < value_length; x++)
735 value[x] = (char) (x % 127);
736
737 for (x= 0; x < 1; x++)
738 {
739 rc= memcached_set(memc, key, strlen(key),
740 value, value_length,
741 (time_t)0, (uint32_t)0);
742 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
743 }
744
745 free(value);
746
747 return 0;
748 }
749
750 test_return get_test3(memcached_st *memc)
751 {
752 memcached_return rc;
753 char *key= "foo";
754 char *value;
755 size_t value_length= 8191;
756 char *string;
757 size_t string_length;
758 uint32_t flags;
759 int x;
760
761 value = (char*)malloc(value_length);
762 assert(value);
763
764 for (x= 0; x < value_length; x++)
765 value[x] = (char) (x % 127);
766
767 rc= memcached_set(memc, key, strlen(key),
768 value, value_length,
769 (time_t)0, (uint32_t)0);
770 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
771
772 string= memcached_get(memc, key, strlen(key),
773 &string_length, &flags, &rc);
774
775 assert(rc == MEMCACHED_SUCCESS);
776 assert(string);
777 assert(string_length == value_length);
778 assert(!memcmp(string, value, string_length));
779
780 free(string);
781 free(value);
782
783 return 0;
784 }
785
786 test_return get_test4(memcached_st *memc)
787 {
788 memcached_return rc;
789 char *key= "foo";
790 char *value;
791 size_t value_length= 8191;
792 char *string;
793 size_t string_length;
794 uint32_t flags;
795 int x;
796
797 value = (char*)malloc(value_length);
798 assert(value);
799
800 for (x= 0; x < value_length; x++)
801 value[x] = (char) (x % 127);
802
803 rc= memcached_set(memc, key, strlen(key),
804 value, value_length,
805 (time_t)0, (uint32_t)0);
806 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
807
808 for (x= 0; x < 10; x++)
809 {
810 string= memcached_get(memc, key, strlen(key),
811 &string_length, &flags, &rc);
812
813 assert(rc == MEMCACHED_SUCCESS);
814 assert(string);
815 assert(string_length == value_length);
816 assert(!memcmp(string, value, string_length));
817 free(string);
818 }
819
820 free(value);
821
822 return 0;
823 }
824
825 /* Do not copy the style of this code, I just access hosts to testthis function */
826 test_return stats_servername_test(memcached_st *memc)
827 {
828 memcached_return rc;
829 memcached_stat_st stat;
830 rc= memcached_stat_servername(&stat, NULL,
831 memc->hosts[0].hostname,
832 memc->hosts[0].port);
833
834 return 0;
835 }
836
837 test_return increment_test(memcached_st *memc)
838 {
839 uint64_t new_number;
840 memcached_return rc;
841 char *key= "number";
842 char *value= "0";
843
844 rc= memcached_set(memc, key, strlen(key),
845 value, strlen(value),
846 (time_t)0, (uint32_t)0);
847 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
848
849 rc= memcached_increment(memc, key, strlen(key),
850 1, &new_number);
851 assert(rc == MEMCACHED_SUCCESS);
852 assert(new_number == 1);
853
854 rc= memcached_increment(memc, key, strlen(key),
855 1, &new_number);
856 assert(rc == MEMCACHED_SUCCESS);
857 assert(new_number == 2);
858
859 return 0;
860 }
861
862 test_return decrement_test(memcached_st *memc)
863 {
864 uint64_t new_number;
865 memcached_return rc;
866 char *key= "number";
867 char *value= "3";
868
869 rc= memcached_set(memc, key, strlen(key),
870 value, strlen(value),
871 (time_t)0, (uint32_t)0);
872 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
873
874 rc= memcached_decrement(memc, key, strlen(key),
875 1, &new_number);
876 assert(rc == MEMCACHED_SUCCESS);
877 assert(new_number == 2);
878
879 rc= memcached_decrement(memc, key, strlen(key),
880 1, &new_number);
881 assert(rc == MEMCACHED_SUCCESS);
882 assert(new_number == 1);
883
884 return 0;
885 }
886
887 test_return quit_test(memcached_st *memc)
888 {
889 memcached_return rc;
890 char *key= "fudge";
891 char *value= "sanford and sun";
892
893 rc= memcached_set(memc, key, strlen(key),
894 value, strlen(value),
895 (time_t)10, (uint32_t)3);
896 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
897 memcached_quit(memc);
898
899 rc= memcached_set(memc, key, strlen(key),
900 value, strlen(value),
901 (time_t)50, (uint32_t)9);
902 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
903
904 return 0;
905 }
906
907 test_return mget_result_test(memcached_st *memc)
908 {
909 memcached_return rc;
910 char *keys[]= {"fudge", "son", "food"};
911 size_t key_length[]= {5, 3, 4};
912 unsigned int x;
913
914 memcached_result_st results_obj;
915 memcached_result_st *results;
916
917 results= memcached_result_create(memc, &results_obj);
918 assert(results);
919 assert(&results_obj == results);
920
921 /* We need to empty the server before continueing test */
922 rc= memcached_flush(memc, 0);
923 assert(rc == MEMCACHED_SUCCESS);
924
925 rc= memcached_mget(memc, keys, key_length, 3);
926 assert(rc == MEMCACHED_SUCCESS);
927
928 while ((results= memcached_fetch_result(memc, &results_obj, &rc)) != NULL)
929 {
930 assert(results);
931 }
932
933 while ((results= memcached_fetch_result(memc, &results_obj, &rc)) != NULL)
934 assert(!results);
935 assert(rc == MEMCACHED_END);
936
937 for (x= 0; x < 3; x++)
938 {
939 rc= memcached_set(memc, keys[x], key_length[x],
940 keys[x], key_length[x],
941 (time_t)50, (uint32_t)9);
942 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
943 }
944
945 rc= memcached_mget(memc, keys, key_length, 3);
946 assert(rc == MEMCACHED_SUCCESS);
947
948 while ((results= memcached_fetch_result(memc, &results_obj, &rc)))
949 {
950 assert(results);
951 assert(&results_obj == results);
952 assert(rc == MEMCACHED_SUCCESS);
953 assert(memcached_result_key_length(results) == memcached_result_length(results));
954 assert(!memcmp(memcached_result_key_value(results),
955 memcached_result_value(results),
956 memcached_result_length(results)));
957 }
958
959 memcached_result_free(&results_obj);
960
961 return 0;
962 }
963
964 test_return mget_result_alloc_test(memcached_st *memc)
965 {
966 memcached_return rc;
967 char *keys[]= {"fudge", "son", "food"};
968 size_t key_length[]= {5, 3, 4};
969 unsigned int x;
970
971 memcached_result_st *results;
972
973 /* We need to empty the server before continueing test */
974 rc= memcached_flush(memc, 0);
975 assert(rc == MEMCACHED_SUCCESS);
976
977 rc= memcached_mget(memc, keys, key_length, 3);
978 assert(rc == MEMCACHED_SUCCESS);
979
980 while ((results= memcached_fetch_result(memc, NULL, &rc)) != NULL)
981 {
982 assert(results);
983 }
984 assert(!results);
985 assert(rc == MEMCACHED_END);
986
987 for (x= 0; x < 3; x++)
988 {
989 rc= memcached_set(memc, keys[x], key_length[x],
990 keys[x], key_length[x],
991 (time_t)50, (uint32_t)9);
992 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
993 }
994
995 rc= memcached_mget(memc, keys, key_length, 3);
996 assert(rc == MEMCACHED_SUCCESS);
997
998 x= 0;
999 while ((results= memcached_fetch_result(memc, NULL, &rc)))
1000 {
1001 assert(results);
1002 assert(rc == MEMCACHED_SUCCESS);
1003 assert(memcached_result_key_length(results) == memcached_result_length(results));
1004 assert(!memcmp(memcached_result_key_value(results),
1005 memcached_result_value(results),
1006 memcached_result_length(results)));
1007 memcached_result_free(results);
1008 x++;
1009 }
1010
1011 return 0;
1012 }
1013
1014 /* Count the results */
1015 unsigned int callback_counter(memcached_st *ptr, memcached_result_st *result, void *context)
1016 {
1017 unsigned int *counter= (unsigned int *)context;
1018
1019 *counter= *counter + 1;
1020
1021 return 0;
1022 }
1023
1024 test_return mget_result_function(memcached_st *memc)
1025 {
1026 memcached_return rc;
1027 char *keys[]= {"fudge", "son", "food"};
1028 size_t key_length[]= {5, 3, 4};
1029 unsigned int x;
1030 unsigned int counter;
1031 memcached_execute_function callbacks[1];
1032
1033 /* We need to empty the server before continueing test */
1034 rc= memcached_flush(memc, 0);
1035 for (x= 0; x < 3; x++)
1036 {
1037 rc= memcached_set(memc, keys[x], key_length[x],
1038 keys[x], key_length[x],
1039 (time_t)50, (uint32_t)9);
1040 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
1041 }
1042
1043 rc= memcached_mget(memc, keys, key_length, 3);
1044 assert(rc == MEMCACHED_SUCCESS);
1045
1046 callbacks[0]= &callback_counter;
1047 counter= 0;
1048 rc= memcached_fetch_execute(memc, callbacks, (void *)&counter, 1);
1049
1050 assert(counter == 3);
1051
1052 return 0;
1053 }
1054
1055 test_return mget_test(memcached_st *memc)
1056 {
1057 memcached_return rc;
1058 char *keys[]= {"fudge", "son", "food"};
1059 size_t key_length[]= {5, 3, 4};
1060 unsigned int x;
1061 uint32_t flags;
1062
1063 char return_key[MEMCACHED_MAX_KEY];
1064 size_t return_key_length;
1065 char *return_value;
1066 size_t return_value_length;
1067
1068 /* We need to empty the server before continueing test */
1069 rc= memcached_flush(memc, 0);
1070 assert(rc == MEMCACHED_SUCCESS);
1071
1072 rc= memcached_mget(memc, keys, key_length, 3);
1073 assert(rc == MEMCACHED_SUCCESS);
1074
1075 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
1076 &return_value_length, &flags, &rc)) != NULL)
1077 {
1078 assert(return_value);
1079 }
1080 assert(!return_value);
1081 assert(return_value_length == 0);
1082 assert(rc == MEMCACHED_END);
1083
1084 for (x= 0; x < 3; x++)
1085 {
1086 rc= memcached_set(memc, keys[x], key_length[x],
1087 keys[x], key_length[x],
1088 (time_t)50, (uint32_t)9);
1089 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
1090 }
1091
1092 rc= memcached_mget(memc, keys, key_length, 3);
1093 assert(rc == MEMCACHED_SUCCESS);
1094
1095 x= 0;
1096 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
1097 &return_value_length, &flags, &rc)))
1098 {
1099 assert(return_value);
1100 assert(rc == MEMCACHED_SUCCESS);
1101 assert(return_key_length == return_value_length);
1102 assert(!memcmp(return_value, return_key, return_value_length));
1103 free(return_value);
1104 x++;
1105 }
1106
1107 return 0;
1108 }
1109
1110 test_return get_stats_keys(memcached_st *memc)
1111 {
1112 char **list;
1113 char **ptr;
1114 memcached_stat_st stat;
1115 memcached_return rc;
1116
1117 list= memcached_stat_get_keys(memc, &stat, &rc);
1118 assert(rc == MEMCACHED_SUCCESS);
1119 for (ptr= list; *ptr; ptr++)
1120 assert(*ptr);
1121 fflush(stdout);
1122
1123 free(list);
1124
1125 return 0;
1126 }
1127
1128 test_return version_string_test(memcached_st *memc)
1129 {
1130 const char *version_string;
1131
1132 version_string= memcached_lib_version();
1133
1134 assert(!strcmp(version_string, LIBMEMCACHED_VERSION_STRING));
1135
1136 return 0;
1137 }
1138
1139 test_return get_stats(memcached_st *memc)
1140 {
1141 unsigned int x;
1142 char **list;
1143 char **ptr;
1144 memcached_return rc;
1145 memcached_stat_st *stat;
1146
1147 stat= memcached_stat(memc, NULL, &rc);
1148 assert(rc == MEMCACHED_SUCCESS);
1149
1150 assert(rc == MEMCACHED_SUCCESS);
1151 assert(stat);
1152
1153 for (x= 0; x < memcached_server_count(memc); x++)
1154 {
1155 list= memcached_stat_get_keys(memc, stat+x, &rc);
1156 assert(rc == MEMCACHED_SUCCESS);
1157 for (ptr= list; *ptr; ptr++);
1158
1159 free(list);
1160 }
1161
1162 memcached_stat_free(NULL, stat);
1163
1164 return 0;
1165 }
1166
1167 test_return add_host_test(memcached_st *memc)
1168 {
1169 unsigned int x;
1170 memcached_server_st *servers;
1171 memcached_return rc;
1172 char servername[]= "0.example.com";
1173
1174 servers= memcached_server_list_append(NULL, servername, 400, &rc);
1175 assert(servers);
1176 assert(1 == memcached_server_list_count(servers));
1177
1178 for (x= 2; x < 20; x++)
1179 {
1180 char buffer[SMALL_STRING_LEN];
1181
1182 snprintf(buffer, SMALL_STRING_LEN, "%u.example.com", 400+x);
1183 servers= memcached_server_list_append(servers, buffer, 401,
1184 &rc);
1185 assert(rc == MEMCACHED_SUCCESS);
1186 assert(x == memcached_server_list_count(servers));
1187 }
1188
1189 rc= memcached_server_push(memc, servers);
1190 assert(rc == MEMCACHED_SUCCESS);
1191 rc= memcached_server_push(memc, servers);
1192 assert(rc == MEMCACHED_SUCCESS);
1193
1194 memcached_server_list_free(servers);
1195
1196 return 0;
1197 }
1198
1199 memcached_return clone_test_callback(memcached_st *parent, memcached_st *clone)
1200 {
1201 return MEMCACHED_SUCCESS;
1202 }
1203
1204 memcached_return cleanup_test_callback(memcached_st *ptr)
1205 {
1206 return MEMCACHED_SUCCESS;
1207 }
1208
1209 test_return callback_test(memcached_st *memc)
1210 {
1211 /* Test User Data */
1212 {
1213 int x= 5;
1214 int *test_ptr;
1215 memcached_return rc;
1216
1217 rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_USER_DATA, &x);
1218 assert(rc == MEMCACHED_SUCCESS);
1219 test_ptr= (int *)memcached_callback_get(memc, MEMCACHED_CALLBACK_USER_DATA, &rc);
1220 assert(*test_ptr == x);
1221 }
1222
1223 /* Test Clone Callback */
1224 {
1225 memcached_clone_func temp_function;
1226 memcached_return rc;
1227
1228 rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, clone_test_callback);
1229 assert(rc == MEMCACHED_SUCCESS);
1230 temp_function= (memcached_clone_func)memcached_callback_get(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, &rc);
1231 assert(temp_function == clone_test_callback);
1232 }
1233
1234 /* Test Cleanup Callback */
1235 {
1236 memcached_cleanup_func temp_function;
1237 memcached_return rc;
1238
1239 rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, cleanup_test_callback);
1240 assert(rc == MEMCACHED_SUCCESS);
1241 temp_function= (memcached_cleanup_func)memcached_callback_get(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, &rc);
1242 assert(temp_function == cleanup_test_callback);
1243 }
1244
1245 return 0;
1246 }
1247
1248 /* We don't test the behavior itself, we test the switches */
1249 test_return behavior_test(memcached_st *memc)
1250 {
1251 unsigned long long value;
1252 unsigned int set= 1;
1253
1254 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, set);
1255 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK);
1256 assert(value == 1);
1257
1258 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, set);
1259 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY);
1260 assert(value == 1);
1261
1262 set= MEMCACHED_HASH_MD5;
1263 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, set);
1264 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
1265 assert(value == MEMCACHED_HASH_MD5);
1266
1267 set= 0;
1268
1269 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, set);
1270 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK);
1271 assert(value == 0);
1272
1273 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, set);
1274 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY);
1275 assert(value == 0);
1276
1277 set= MEMCACHED_HASH_DEFAULT;
1278 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, set);
1279 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
1280 assert(value == MEMCACHED_HASH_DEFAULT);
1281
1282 set= MEMCACHED_HASH_CRC;
1283 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, set);
1284 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
1285 assert(value == MEMCACHED_HASH_CRC);
1286
1287 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE);
1288 assert(value > 0);
1289
1290 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE);
1291 assert(value > 0);
1292
1293 return 0;
1294 }
1295
1296 /* Test case provided by Cal Haldenbrand */
1297 test_return user_supplied_bug1(memcached_st *memc)
1298 {
1299 unsigned int setter= 1;
1300 unsigned int x;
1301
1302 unsigned long long total= 0;
1303 int size= 0;
1304 char key[10];
1305 char randomstuff[6 * 1024];
1306 memcached_return rc;
1307
1308 memset(randomstuff, 0, 6 * 1024);
1309
1310 /* We just keep looking at the same values over and over */
1311 srandom(10);
1312
1313 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, setter);
1314 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, setter);
1315
1316
1317 /* add key */
1318 for (x= 0 ; total < 20 * 1024576 ; x++ )
1319 {
1320 unsigned int j= 0;
1321
1322 size= (rand() % ( 5 * 1024 ) ) + 400;
1323 memset(randomstuff, 0, 6 * 1024);
1324 assert(size < 6 * 1024); /* Being safe here */
1325
1326 for (j= 0 ; j < size ;j++)
1327 randomstuff[j] = (char) (rand() % 26) + 97;
1328
1329 total += size;
1330 sprintf(key, "%d", x);
1331 rc = memcached_set(memc, key, strlen(key),
1332 randomstuff, strlen(randomstuff), 10, 0);
1333 /* If we fail, lets try again */
1334 if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_BUFFERED)
1335 rc = memcached_set(memc, key, strlen(key),
1336 randomstuff, strlen(randomstuff), 10, 0);
1337 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
1338 }
1339
1340 return 0;
1341 }
1342
1343 /* Test case provided by Cal Haldenbrand */
1344 test_return user_supplied_bug2(memcached_st *memc)
1345 {
1346 int errors;
1347 unsigned int setter;
1348 unsigned int x;
1349 unsigned long long total;
1350
1351 setter= 1;
1352 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, setter);
1353 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, setter);
1354 #ifdef NOT_YET
1355 setter = 20 * 1024576;
1356 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, setter);
1357 setter = 20 * 1024576;
1358 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, setter);
1359 getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE);
1360 getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE);
1361
1362 for (x= 0, errors= 0, total= 0 ; total < 20 * 1024576 ; x++)
1363 #endif
1364
1365 for (x= 0, errors= 0, total= 0 ; total < 24576 ; x++)
1366 {
1367 memcached_return rc= MEMCACHED_SUCCESS;
1368 char buffer[SMALL_STRING_LEN];
1369 uint32_t flags= 0;
1370 size_t val_len= 0;
1371 char *getval;
1372
1373 memset(buffer, 0, SMALL_STRING_LEN);
1374
1375 snprintf(buffer, SMALL_STRING_LEN, "%u", x);
1376 getval= memcached_get(memc, buffer, strlen(buffer),
1377 &val_len, &flags, &rc);
1378 if (rc != MEMCACHED_SUCCESS)
1379 {
1380 if (rc == MEMCACHED_NOTFOUND)
1381 errors++;
1382 else
1383 {
1384 WATCHPOINT_ERROR(rc);
1385 assert(0);
1386 }
1387
1388 continue;
1389 }
1390 total+= val_len;
1391 errors= 0;
1392 free(getval);
1393 }
1394
1395 return 0;
1396 }
1397
1398 /* Do a large mget() over all the keys we think exist */
1399 #define KEY_COUNT 3000 // * 1024576
1400 test_return user_supplied_bug3(memcached_st *memc)
1401 {
1402 memcached_return rc;
1403 unsigned int setter;
1404 unsigned int x;
1405 char **keys;
1406 size_t key_lengths[KEY_COUNT];
1407
1408 setter= 1;
1409 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, setter);
1410 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, setter);
1411 #ifdef NOT_YET
1412 setter = 20 * 1024576;
1413 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, setter);
1414 setter = 20 * 1024576;
1415 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, setter);
1416 getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE);
1417 getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE);
1418 #endif
1419
1420 keys= (char **)malloc(sizeof(char *) * KEY_COUNT);
1421 assert(keys);
1422 memset(keys, 0, (sizeof(char *) * KEY_COUNT));
1423 for (x= 0; x < KEY_COUNT; x++)
1424 {
1425 char buffer[30];
1426
1427 snprintf(buffer, 30, "%u", x);
1428 keys[x]= strdup(buffer);
1429 key_lengths[x]= strlen(keys[x]);
1430 }
1431
1432 rc= memcached_mget(memc, keys, key_lengths, KEY_COUNT);
1433 assert(rc == MEMCACHED_SUCCESS);
1434
1435 /* Turn this into a help function */
1436 {
1437 char return_key[MEMCACHED_MAX_KEY];
1438 size_t return_key_length;
1439 char *return_value;
1440 size_t return_value_length;
1441 uint32_t flags;
1442
1443 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
1444 &return_value_length, &flags, &rc)))
1445 {
1446 assert(return_value);
1447 assert(rc == MEMCACHED_SUCCESS);
1448 free(return_value);
1449 }
1450 }
1451
1452 for (x= 0; x < KEY_COUNT; x++)
1453 free(keys[x]);
1454 free(keys);
1455
1456 return 0;
1457 }
1458
1459 /* Make sure we behave properly if server list has no values */
1460 test_return user_supplied_bug4(memcached_st *memc)
1461 {
1462 memcached_return rc;
1463 char *keys[]= {"fudge", "son", "food"};
1464 size_t key_length[]= {5, 3, 4};
1465 unsigned int x;
1466 uint32_t flags;
1467 char return_key[MEMCACHED_MAX_KEY];
1468 size_t return_key_length;
1469 char *return_value;
1470 size_t return_value_length;
1471
1472 /* Here we free everything before running a bunch of mget tests */
1473 {
1474 memcached_server_list_free(memc->hosts);
1475 memc->hosts= NULL;
1476 memc->number_of_hosts= 0;
1477 }
1478
1479
1480 /* We need to empty the server before continueing test */
1481 rc= memcached_flush(memc, 0);
1482 assert(rc == MEMCACHED_NO_SERVERS);
1483
1484 rc= memcached_mget(memc, keys, key_length, 3);
1485 assert(rc == MEMCACHED_NO_SERVERS);
1486
1487 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
1488 &return_value_length, &flags, &rc)) != NULL)
1489 {
1490 assert(return_value);
1491 }
1492 assert(!return_value);
1493 assert(return_value_length == 0);
1494 assert(rc == MEMCACHED_NO_SERVERS);
1495
1496 for (x= 0; x < 3; x++)
1497 {
1498 rc= memcached_set(memc, keys[x], key_length[x],
1499 keys[x], key_length[x],
1500 (time_t)50, (uint32_t)9);
1501 assert(rc == MEMCACHED_NO_SERVERS);
1502 }
1503
1504 rc= memcached_mget(memc, keys, key_length, 3);
1505 assert(rc == MEMCACHED_NO_SERVERS);
1506
1507 x= 0;
1508 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
1509 &return_value_length, &flags, &rc)))
1510 {
1511 assert(return_value);
1512 assert(rc == MEMCACHED_SUCCESS);
1513 assert(return_key_length == return_value_length);
1514 assert(!memcmp(return_value, return_key, return_value_length));
1515 free(return_value);
1516 x++;
1517 }
1518
1519 return 0;
1520 }
1521
1522 #define VALUE_SIZE_BUG5 1048064
1523 test_return user_supplied_bug5(memcached_st *memc)
1524 {
1525 memcached_return rc;
1526 char *keys[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1527 size_t key_length[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1528 char return_key[MEMCACHED_MAX_KEY];
1529 size_t return_key_length;
1530 char *value;
1531 size_t value_length;
1532 uint32_t flags;
1533 unsigned int count;
1534 unsigned int x;
1535 char insert_data[VALUE_SIZE_BUG5];
1536
1537 for (x= 0; x < VALUE_SIZE_BUG5; x++)
1538 insert_data[x]= rand();
1539
1540 memcached_flush(memc, 0);
1541 value= memcached_get(memc, keys[0], key_length[0],
1542 &value_length, &flags, &rc);
1543 assert(value == NULL);
1544 rc= memcached_mget(memc, keys, key_length, 4);
1545
1546 count= 0;
1547 while ((value= memcached_fetch(memc, return_key, &return_key_length,
1548 &value_length, &flags, &rc)))
1549 count++;
1550 assert(count == 0);
1551
1552 for (x= 0; x < 4; x++)
1553 {
1554 rc= memcached_set(memc, keys[x], key_length[x],
1555 insert_data, VALUE_SIZE_BUG5,
1556 (time_t)0, (uint32_t)0);
1557 assert(rc == MEMCACHED_SUCCESS);
1558 }
1559
1560 for (x= 0; x < 10; x++)
1561 {
1562 value= memcached_get(memc, keys[0], key_length[0],
1563 &value_length, &flags, &rc);
1564 assert(value);
1565 free(value);
1566
1567 rc= memcached_mget(memc, keys, key_length, 4);
1568 count= 0;
1569 while ((value= memcached_fetch(memc, return_key, &return_key_length,
1570 &value_length, &flags, &rc)))
1571 {
1572 count++;
1573 free(value);
1574 }
1575 assert(count == 4);
1576 }
1577
1578 return 0;
1579 }
1580
1581 test_return user_supplied_bug6(memcached_st *memc)
1582 {
1583 memcached_return rc;
1584 char *keys[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1585 size_t key_length[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1586 char return_key[MEMCACHED_MAX_KEY];
1587 size_t return_key_length;
1588 char *value;
1589 size_t value_length;
1590 uint32_t flags;
1591 unsigned int count;
1592 unsigned int x;
1593 char insert_data[VALUE_SIZE_BUG5];
1594
1595 for (x= 0; x < VALUE_SIZE_BUG5; x++)
1596 insert_data[x]= rand();
1597
1598 memcached_flush(memc, 0);
1599 value= memcached_get(memc, keys[0], key_length[0],
1600 &value_length, &flags, &rc);
1601 assert(value == NULL);
1602 assert(rc == MEMCACHED_NOTFOUND);
1603 rc= memcached_mget(memc, keys, key_length, 4);
1604 assert(rc == MEMCACHED_SUCCESS);
1605
1606 count= 0;
1607 while ((value= memcached_fetch(memc, return_key, &return_key_length,
1608 &value_length, &flags, &rc)))
1609 count++;
1610 assert(count == 0);
1611 assert(rc == MEMCACHED_END);
1612
1613 for (x= 0; x < 4; x++)
1614 {
1615 rc= memcached_set(memc, keys[x], key_length[x],
1616 insert_data, VALUE_SIZE_BUG5,
1617 (time_t)0, (uint32_t)0);
1618 assert(rc == MEMCACHED_SUCCESS);
1619 }
1620
1621 for (x= 0; x < 2; x++)
1622 {
1623 value= memcached_get(memc, keys[0], key_length[0],
1624 &value_length, &flags, &rc);
1625 assert(value);
1626 free(value);
1627
1628 rc= memcached_mget(memc, keys, key_length, 4);
1629 assert(rc == MEMCACHED_SUCCESS);
1630 count= 3;
1631 /* We test for purge of partial complete fetches */
1632 for (count= 3; count; count--)
1633 {
1634 value= memcached_fetch(memc, return_key, &return_key_length,
1635 &value_length, &flags, &rc);
1636 assert(rc == MEMCACHED_SUCCESS);
1637 assert(!(memcmp(value, insert_data, value_length)));
1638 assert(value_length);
1639 free(value);
1640 }
1641 }
1642
1643 return 0;
1644 }
1645
1646 test_return user_supplied_bug8(memcached_st *memc)
1647 {
1648 memcached_return rc;
1649 memcached_st *mine;
1650 memcached_st *clone;
1651
1652 memcached_server_st *servers;
1653 char *server_list= "memcache1.memcache.bk.sapo.pt:11211, memcache1.memcache.bk.sapo.pt:11212, memcache1.memcache.bk.sapo.pt:11213, memcache1.memcache.bk.sapo.pt:11214, memcache2.memcache.bk.sapo.pt:11211, memcache2.memcache.bk.sapo.pt:11212, memcache2.memcache.bk.sapo.pt:11213, memcache2.memcache.bk.sapo.pt:11214";
1654
1655 servers= memcached_servers_parse(server_list);
1656 assert(servers);
1657
1658 mine= memcached_create(NULL);
1659 rc= memcached_server_push(mine, servers);
1660 assert(rc == MEMCACHED_SUCCESS);
1661 memcached_server_list_free(servers);
1662
1663 assert(mine);
1664 clone= memcached_clone(NULL, mine);
1665
1666 memcached_quit(mine);
1667 memcached_quit(clone);
1668
1669
1670 memcached_free(mine);
1671 memcached_free(clone);
1672
1673 return 0;
1674 }
1675
1676 /* Test flag store/retrieve */
1677 test_return user_supplied_bug7(memcached_st *memc)
1678 {
1679 memcached_return rc;
1680 char *keys= "036790384900";
1681 size_t key_length= strlen("036790384900");
1682 char return_key[MEMCACHED_MAX_KEY];
1683 size_t return_key_length;
1684 char *value;
1685 size_t value_length;
1686 uint32_t flags;
1687 unsigned int x;
1688 char insert_data[VALUE_SIZE_BUG5];
1689
1690 for (x= 0; x < VALUE_SIZE_BUG5; x++)
1691 insert_data[x]= rand();
1692
1693 memcached_flush(memc, 0);
1694
1695 flags= 245;
1696 rc= memcached_set(memc, keys, key_length,
1697 insert_data, VALUE_SIZE_BUG5,
1698 (time_t)0, flags);
1699 assert(rc == MEMCACHED_SUCCESS);
1700
1701 flags= 0;
1702 value= memcached_get(memc, keys, key_length,
1703 &value_length, &flags, &rc);
1704 assert(flags == 245);
1705 assert(value);
1706 free(value);
1707
1708 rc= memcached_mget(memc, &keys, &key_length, 1);
1709
1710 flags= 0;
1711 value= memcached_fetch(memc, return_key, &return_key_length,
1712 &value_length, &flags, &rc);
1713 assert(flags == 245);
1714 assert(value);
1715 free(value);
1716
1717
1718 return 0;
1719 }
1720
1721 test_return user_supplied_bug9(memcached_st *memc)
1722 {
1723 memcached_return rc;
1724 char *keys[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
1725 size_t key_length[3];
1726 unsigned int x;
1727 uint32_t flags;
1728 unsigned count= 0;
1729
1730 char return_key[MEMCACHED_MAX_KEY];
1731 size_t return_key_length;
1732 char *return_value;
1733 size_t return_value_length;
1734
1735
1736 key_length[0]= strlen("UDATA:edevil@sapo.pt");
1737 key_length[1]= strlen("fudge&*@#");
1738 key_length[2]= strlen("for^#@&$not");
1739
1740
1741 for (x= 0; x < 3; x++)
1742 {
1743 rc= memcached_set(memc, keys[x], key_length[x],
1744 keys[x], key_length[x],
1745 (time_t)50, (uint32_t)9);
1746 assert(rc == MEMCACHED_SUCCESS);
1747 }
1748
1749 rc= memcached_mget(memc, keys, key_length, 3);
1750 assert(rc == MEMCACHED_SUCCESS);
1751
1752 /* We need to empty the server before continueing test */
1753 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
1754 &return_value_length, &flags, &rc)) != NULL)
1755 {
1756 assert(return_value);
1757 free(return_value);
1758 count++;
1759 }
1760 assert(count == 3);
1761
1762 return 0;
1763 }
1764
1765 /* We are testing with aggressive timeout to get failures */
1766 test_return user_supplied_bug10(memcached_st *memc)
1767 {
1768 char *key= "foo";
1769 char *value;
1770 size_t value_length= 512;
1771 unsigned int x;
1772 int key_len= 3;
1773 memcached_return rc;
1774 unsigned int set= 1;
1775 memcached_st *mclone= memcached_clone(NULL, memc);
1776 int32_t timeout;
1777
1778 memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, set);
1779 memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, set);
1780 timeout= 2;
1781 memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, timeout);
1782
1783 value = (char*)malloc(value_length * sizeof(char));
1784
1785 for (x= 0; x < value_length; x++)
1786 value[x]= (char) (x % 127);
1787
1788 for (x= 1; x <= 100000; ++x)
1789 {
1790 rc= memcached_set(mclone, key, key_len,value, value_length, 0, 0);
1791
1792 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_WRITE_FAILURE || rc == MEMCACHED_BUFFERED);
1793
1794 if (rc == MEMCACHED_WRITE_FAILURE)
1795 x--;
1796 }
1797
1798 free(value);
1799 memcached_free(mclone);
1800
1801 return 0;
1802 }
1803
1804 /*
1805 We are looking failures in the async protocol
1806 */
1807 test_return user_supplied_bug11(memcached_st *memc)
1808 {
1809 char *key= "foo";
1810 char *value;
1811 size_t value_length= 512;
1812 unsigned int x;
1813 int key_len= 3;
1814 memcached_return rc;
1815 unsigned int set= 1;
1816 int32_t timeout;
1817 memcached_st *mclone= memcached_clone(NULL, memc);
1818
1819 memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, set);
1820 memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, set);
1821 timeout= -1;
1822 memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, timeout);
1823
1824 timeout= (int32_t)memcached_behavior_get(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT);
1825
1826 assert(timeout == -1);
1827
1828 value = (char*)malloc(value_length * sizeof(char));
1829
1830 for (x= 0; x < value_length; x++)
1831 value[x]= (char) (x % 127);
1832
1833 for (x= 1; x <= 100000; ++x)
1834 {
1835 rc= memcached_set(mclone, key, key_len,value, value_length, 0, 0);
1836 }
1837
1838 free(value);
1839 memcached_free(mclone);
1840
1841 return 0;
1842 }
1843
1844 /*
1845 Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
1846 */
1847 test_return user_supplied_bug12(memcached_st *memc)
1848 {
1849 memcached_return rc;
1850 uint32_t flags;
1851 size_t value_length;
1852 char *value;
1853 uint64_t number_value;
1854
1855 value= memcached_get(memc, "autoincrement", strlen("autoincrement"),
1856 &value_length, &flags, &rc);
1857 assert(value == NULL);
1858 assert(rc == MEMCACHED_NOTFOUND);
1859
1860 rc= memcached_increment(memc, "autoincrement", strlen("autoincrement"),
1861 1, &number_value);
1862
1863 assert(value == NULL);
1864 assert(rc == MEMCACHED_NOTFOUND);
1865
1866 rc= memcached_set(memc, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
1867
1868 value= memcached_get(memc, "autoincrement", strlen("autoincrement"),
1869 &value_length, &flags, &rc);
1870 assert(value);
1871 assert(rc == MEMCACHED_SUCCESS);
1872 free(value);
1873
1874 rc= memcached_increment(memc, "autoincrement", strlen("autoincrement"),
1875 1, &number_value);
1876 assert(number_value == 2);
1877 assert(rc == MEMCACHED_SUCCESS);
1878
1879 return 0;
1880 }
1881
1882 /*
1883 Bug found where command total one more than MEMCACHED_MAX_BUFFER
1884 set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
1885 */
1886 test_return user_supplied_bug13(memcached_st *memc)
1887 {
1888 char key[] = "key34567890";
1889 char *overflow;
1890 memcached_return rc;
1891 size_t overflowSize;
1892
1893 char commandFirst[]= "set key34567890 0 0 ";
1894 char commandLast[] = " \r\n"; /* first line of command sent to server */
1895 size_t commandLength;
1896 size_t testSize;
1897
1898 commandLength = strlen(commandFirst) + strlen(commandLast) + 4; /* 4 is number of characters in size, probably 8196 */
1899
1900 overflowSize = MEMCACHED_MAX_BUFFER - commandLength;
1901
1902 for (testSize= overflowSize - 1; testSize < overflowSize + 1; testSize++)
1903 {
1904 overflow= malloc(testSize);
1905 assert(overflow != NULL);
1906
1907 memset(overflow, 'x', testSize);
1908 rc= memcached_set(memc, key, strlen(key),
1909 overflow, testSize, 0, 0);
1910 assert(rc == MEMCACHED_SUCCESS);
1911 free(overflow);
1912 }
1913
1914 return 0;
1915 }
1916
1917
1918 /*
1919 Test values of many different sizes
1920 Bug found where command total one more than MEMCACHED_MAX_BUFFER
1921 set key34567890 0 0 8169 \r\n
1922 is sent followed by buffer of size 8169, followed by 8169
1923 */
1924 test_return user_supplied_bug14(memcached_st *memc)
1925 {
1926 int setter= 1;
1927 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, setter);
1928 memcached_return rc;
1929 char *key= "foo";
1930 char *value;
1931 size_t value_length= 18000;
1932 char *string;
1933 size_t string_length;
1934 uint32_t flags;
1935 unsigned int x;
1936 size_t current_length;
1937
1938 value = (char*)malloc(value_length);
1939 assert(value);
1940
1941 for (x= 0; x < value_length; x++)
1942 value[x] = (char) (x % 127);
1943
1944 for (current_length= 0; current_length < value_length; current_length++)
1945 {
1946 rc= memcached_set(memc, key, strlen(key),
1947 value, current_length,
1948 (time_t)0, (uint32_t)0);
1949 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
1950
1951 string= memcached_get(memc, key, strlen(key),
1952 &string_length, &flags, &rc);
1953
1954 assert(rc == MEMCACHED_SUCCESS);
1955 assert(string_length == current_length);
1956 assert(!memcmp(string, value, string_length));
1957
1958 free(string);
1959 }
1960
1961 free(value);
1962
1963 return 0;
1964 }
1965
1966 /*
1967 Look for zero length value problems
1968 */
1969 test_return user_supplied_bug15(memcached_st *memc)
1970 {
1971 uint32_t x;
1972 memcached_return rc;
1973 char *key= "mykey";
1974 char *value;
1975 size_t length;
1976 uint32_t flags;
1977
1978 for (x= 0; x < 2; x++)
1979 {
1980 rc= memcached_set(memc, key, strlen(key),
1981 NULL, 0,
1982 (time_t)0, (uint32_t)0);
1983
1984 assert(rc == MEMCACHED_SUCCESS);
1985
1986 value= memcached_get(memc, key, strlen(key),
1987 &length, &flags, &rc);
1988
1989 assert(rc == MEMCACHED_SUCCESS);
1990 assert(value == NULL);
1991 assert(length == 0);
1992 assert(flags == 0);
1993
1994 value= memcached_get(memc, key, strlen(key),
1995 &length, &flags, &rc);
1996
1997 assert(rc == MEMCACHED_SUCCESS);
1998 assert(value == NULL);
1999 assert(length == 0);
2000 assert(flags == 0);
2001 }
2002
2003 return 0;
2004 }
2005
2006 /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
2007 test_return user_supplied_bug16(memcached_st *memc)
2008 {
2009 uint32_t x;
2010 memcached_return rc;
2011 char *key= "mykey";
2012 char *value;
2013 size_t length;
2014 uint32_t flags;
2015
2016 rc= memcached_set(memc, key, strlen(key),
2017 NULL, 0,
2018 (time_t)0, UINT32_MAX);
2019
2020 assert(rc == MEMCACHED_SUCCESS);
2021
2022 value= memcached_get(memc, key, strlen(key),
2023 &length, &flags, &rc);
2024
2025 assert(rc == MEMCACHED_SUCCESS);
2026 assert(value == NULL);
2027 assert(length == 0);
2028 assert(flags == UINT32_MAX);
2029
2030 return 0;
2031 }
2032
2033 test_return result_static(memcached_st *memc)
2034 {
2035 memcached_result_st result;
2036 memcached_result_st *result_ptr;
2037
2038 result_ptr= memcached_result_create(memc, &result);
2039 assert(result.is_allocated == MEMCACHED_NOT_ALLOCATED);
2040 assert(result_ptr);
2041 memcached_result_free(&result);
2042
2043 return 0;
2044 }
2045
2046 test_return result_alloc(memcached_st *memc)
2047 {
2048 memcached_result_st *result;
2049
2050 result= memcached_result_create(memc, NULL);
2051 assert(result);
2052 memcached_result_free(result);
2053
2054 return 0;
2055 }
2056
2057 test_return string_static_null(memcached_st *memc)
2058 {
2059 memcached_string_st string;
2060 memcached_string_st *string_ptr;
2061
2062 string_ptr= memcached_string_create(memc, &string, 0);
2063 assert(string.is_allocated == MEMCACHED_NOT_ALLOCATED);
2064 assert(string_ptr);
2065 memcached_string_free(&string);
2066
2067 return 0;
2068 }
2069
2070 test_return string_alloc_null(memcached_st *memc)
2071 {
2072 memcached_string_st *string;
2073
2074 string= memcached_string_create(memc, NULL, 0);
2075 assert(string);
2076 memcached_string_free(string);
2077
2078 return 0;
2079 }
2080
2081 test_return string_alloc_with_size(memcached_st *memc)
2082 {
2083 memcached_string_st *string;
2084
2085 string= memcached_string_create(memc, NULL, 1024);
2086 assert(string);
2087 memcached_string_free(string);
2088
2089 return 0;
2090 }
2091
2092 test_return string_alloc_with_size_toobig(memcached_st *memc)
2093 {
2094 memcached_string_st *string;
2095
2096 string= memcached_string_create(memc, NULL, INT64_MAX);
2097 assert(string == NULL);
2098
2099 return 0;
2100 }
2101
2102 test_return string_alloc_append(memcached_st *memc)
2103 {
2104 unsigned int x;
2105 char buffer[SMALL_STRING_LEN];
2106 memcached_string_st *string;
2107
2108 /* Ring the bell! */
2109 memset(buffer, 6, SMALL_STRING_LEN);
2110
2111 string= memcached_string_create(memc, NULL, 100);
2112 assert(string);
2113
2114 for (x= 0; x < 1024; x++)
2115 {
2116 memcached_return rc;
2117 rc= memcached_string_append(string, buffer, SMALL_STRING_LEN);
2118 assert(rc == MEMCACHED_SUCCESS);
2119 }
2120 memcached_string_free(string);
2121
2122 return 0;
2123 }
2124
2125 test_return string_alloc_append_toobig(memcached_st *memc)
2126 {
2127 memcached_return rc;
2128 unsigned int x;
2129 char buffer[SMALL_STRING_LEN];
2130 memcached_string_st *string;
2131
2132 /* Ring the bell! */
2133 memset(buffer, 6, SMALL_STRING_LEN);
2134
2135 string= memcached_string_create(memc, NULL, 100);
2136 assert(string);
2137
2138 for (x= 0; x < 1024; x++)
2139 {
2140 rc= memcached_string_append(string, buffer, SMALL_STRING_LEN);
2141 assert(rc == MEMCACHED_SUCCESS);
2142 }
2143 rc= memcached_string_append(string, buffer, INT64_MAX);
2144 assert(rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE);
2145 memcached_string_free(string);
2146
2147 return 0;
2148 }
2149
2150 test_return cleanup_pairs(memcached_st *memc)
2151 {
2152 pairs_free(global_pairs);
2153
2154 return 0;
2155 }
2156
2157 test_return generate_pairs(memcached_st *memc)
2158 {
2159 unsigned long long x;
2160 global_pairs= pairs_generate(GLOBAL_COUNT, 400);
2161 global_count= GLOBAL_COUNT;
2162
2163 for (x= 0; x < global_count; x++)
2164 {
2165 global_keys[x]= global_pairs[x].key;
2166 global_keys_length[x]= global_pairs[x].key_length;
2167 }
2168
2169 return 0;
2170 }
2171
2172 test_return generate_large_pairs(memcached_st *memc)
2173 {
2174 unsigned long long x;
2175 global_pairs= pairs_generate(GLOBAL2_COUNT, MEMCACHED_MAX_BUFFER+10);
2176 global_count= GLOBAL2_COUNT;
2177
2178 for (x= 0; x < global_count; x++)
2179 {
2180 global_keys[x]= global_pairs[x].key;
2181 global_keys_length[x]= global_pairs[x].key_length;
2182 }
2183
2184 return 0;
2185 }
2186
2187 test_return generate_data(memcached_st *memc)
2188 {
2189 execute_set(memc, global_pairs, global_count);
2190
2191 return 0;
2192 }
2193
2194 test_return generate_buffer_data(memcached_st *memc)
2195 {
2196 int latch= 0;
2197
2198 latch= 1;
2199 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, latch);
2200 generate_data(memc);
2201
2202 return 0;
2203 }
2204
2205 test_return get_read_count(memcached_st *memc)
2206 {
2207 unsigned int x;
2208 memcached_return rc;
2209 memcached_st *clone;
2210
2211 clone= memcached_clone(NULL, memc);
2212 assert(clone);
2213
2214 memcached_server_add(clone, "localhost", 6666);
2215
2216 {
2217 char *return_value;
2218 size_t return_value_length;
2219 uint32_t flags;
2220 uint32_t count;
2221
2222 for (x= count= 0; x < global_count; x++)
2223 {
2224 return_value= memcached_get(clone, global_keys[x], global_keys_length[x],
2225 &return_value_length, &flags, &rc);
2226 if (rc == MEMCACHED_SUCCESS)
2227 {
2228 count++;
2229 if (return_value)
2230 free(return_value);
2231 }
2232 }
2233 fprintf(stderr, "\t%u -> %u", global_count, count);
2234 }
2235
2236 memcached_free(clone);
2237
2238 return 0;
2239 }
2240
2241 test_return get_read(memcached_st *memc)
2242 {
2243 unsigned int x;
2244 memcached_return rc;
2245
2246 {
2247 char *return_value;
2248 size_t return_value_length;
2249 uint32_t flags;
2250
2251 for (x= 0; x < global_count; x++)
2252 {
2253 return_value= memcached_get(memc, global_keys[x], global_keys_length[x],
2254 &return_value_length, &flags, &rc);
2255 /*
2256 assert(return_value);
2257 assert(rc == MEMCACHED_SUCCESS);
2258 */
2259 if (rc == MEMCACHED_SUCCESS && return_value)
2260 free(return_value);
2261 }
2262 }
2263
2264 return 0;
2265 }
2266
2267 test_return mget_read(memcached_st *memc)
2268 {
2269 memcached_return rc;
2270
2271 rc= memcached_mget(memc, global_keys, global_keys_length, global_count);
2272 assert(rc == MEMCACHED_SUCCESS);
2273 /* Turn this into a help function */
2274 {
2275 char return_key[MEMCACHED_MAX_KEY];
2276 size_t return_key_length;
2277 char *return_value;
2278 size_t return_value_length;
2279 uint32_t flags;
2280
2281 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
2282 &return_value_length, &flags, &rc)))
2283 {
2284 assert(return_value);
2285 assert(rc == MEMCACHED_SUCCESS);
2286 free(return_value);
2287 }
2288 }
2289
2290 return 0;
2291 }
2292
2293 test_return mget_read_result(memcached_st *memc)
2294 {
2295 memcached_return rc;
2296
2297 rc= memcached_mget(memc, global_keys, global_keys_length, global_count);
2298 assert(rc == MEMCACHED_SUCCESS);
2299 /* Turn this into a help function */
2300 {
2301 memcached_result_st results_obj;
2302 memcached_result_st *results;
2303
2304 results= memcached_result_create(memc, &results_obj);
2305
2306 while ((results= memcached_fetch_result(memc, &results_obj, &rc)))
2307 {
2308 assert(results);
2309 assert(rc == MEMCACHED_SUCCESS);
2310 }
2311
2312 memcached_result_free(&results_obj);
2313 }
2314
2315 return 0;
2316 }
2317
2318 test_return mget_read_function(memcached_st *memc)
2319 {
2320 memcached_return rc;
2321 unsigned int counter;
2322 unsigned int (*callbacks[1])(memcached_st *, memcached_result_st *, void *);
2323
2324 rc= memcached_mget(memc, global_keys, global_keys_length, global_count);
2325 assert(rc == MEMCACHED_SUCCESS);
2326
2327 callbacks[0]= &callback_counter;
2328 counter= 0;
2329 rc= memcached_fetch_execute(memc, callbacks, (void *)&counter, 1);
2330
2331 return 0;
2332 }
2333
2334 test_return delete_generate(memcached_st *memc)
2335 {
2336 unsigned int x;
2337
2338 for (x= 0; x < global_count; x++)
2339 {
2340 (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0);
2341 }
2342
2343 return 0;
2344 }
2345
2346 test_return delete_buffer_generate(memcached_st *memc)
2347 {
2348 int latch= 0;
2349 unsigned int x;
2350
2351 latch= 1;
2352 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, latch);
2353
2354 for (x= 0; x < global_count; x++)
2355 {
2356 (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0);
2357 }
2358
2359 return 0;
2360 }
2361
2362 test_return free_data(memcached_st *memc)
2363 {
2364 pairs_free(global_pairs);
2365
2366 return 0;
2367 }
2368
2369 test_return add_host_test1(memcached_st *memc)
2370 {
2371 unsigned int x;
2372 memcached_return rc;
2373 char servername[]= "0.example.com";
2374 memcached_server_st *servers;
2375
2376 servers= memcached_server_list_append(NULL, servername, 400, &rc);
2377 assert(servers);
2378 assert(1 == memcached_server_list_count(servers));
2379
2380 for (x= 2; x < 20; x++)
2381 {
2382 char buffer[SMALL_STRING_LEN];
2383
2384 snprintf(buffer, SMALL_STRING_LEN, "%u.example.com", 400+x);
2385 servers= memcached_server_list_append(servers, buffer, 401,
2386 &rc);
2387 assert(rc == MEMCACHED_SUCCESS);
2388 assert(x == memcached_server_list_count(servers));
2389 }
2390
2391 rc= memcached_server_push(memc, servers);
2392 assert(rc == MEMCACHED_SUCCESS);
2393 rc= memcached_server_push(memc, servers);
2394 assert(rc == MEMCACHED_SUCCESS);
2395
2396 memcached_server_list_free(servers);
2397
2398 return 0;
2399 }
2400
2401 memcached_return pre_nonblock(memcached_st *memc)
2402 {
2403 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 0);
2404
2405 return MEMCACHED_SUCCESS;
2406 }
2407
2408 memcached_return pre_murmur(memcached_st *memc)
2409 {
2410 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_MURMUR);
2411
2412 return MEMCACHED_SUCCESS;
2413 }
2414
2415 memcached_return pre_md5(memcached_st *memc)
2416 {
2417 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_MD5);
2418
2419 return MEMCACHED_SUCCESS;
2420 }
2421
2422 memcached_return pre_crc(memcached_st *memc)
2423 {
2424 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_CRC);
2425
2426 return MEMCACHED_SUCCESS;
2427 }
2428
2429 memcached_return pre_hsieh(memcached_st *memc)
2430 {
2431 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_HSIEH);
2432
2433 return MEMCACHED_SUCCESS;
2434 }
2435
2436 memcached_return pre_hash_fnv1_64(memcached_st *memc)
2437 {
2438 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_FNV1_64);
2439
2440 return MEMCACHED_SUCCESS;
2441 }
2442
2443 memcached_return pre_hash_fnv1a_64(memcached_st *memc)
2444 {
2445 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_FNV1A_64);
2446
2447 return MEMCACHED_SUCCESS;
2448 }
2449
2450 memcached_return pre_hash_fnv1_32(memcached_st *memc)
2451 {
2452 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_FNV1_32);
2453
2454 return MEMCACHED_SUCCESS;
2455 }
2456
2457 memcached_return pre_hash_fnv1a_32(memcached_st *memc)
2458 {
2459 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_FNV1A_32);
2460
2461 return MEMCACHED_SUCCESS;
2462 }
2463
2464 memcached_return pre_behavior_ketama(memcached_st *memc)
2465 {
2466 memcached_return rc;
2467 uint64_t value;
2468
2469 rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA, 1);
2470 assert(rc == MEMCACHED_SUCCESS);
2471
2472 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA);
2473 assert(value == 1);
2474
2475 return MEMCACHED_SUCCESS;
2476 }
2477
2478 void my_free(memcached_st *ptr, void *mem)
2479 {
2480 free(mem);
2481 }
2482
2483 void *my_malloc(memcached_st *ptr, const size_t size)
2484 {
2485 return malloc(size);
2486 }
2487
2488 void *my_realloc(memcached_st *ptr, void *mem, const size_t size)
2489 {
2490 return realloc(mem, size);
2491 }
2492
2493 memcached_return set_prefix(memcached_st *memc)
2494 {
2495 memcached_return rc;
2496 const char *key= "mine";
2497 char *value;
2498
2499 /* Make sure be default none exists */
2500 value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc);
2501 assert(rc == MEMCACHED_FAILURE);
2502
2503 /* Test a clean set */
2504 rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, (void *)key);
2505 assert(rc == MEMCACHED_SUCCESS);
2506
2507 value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc);
2508 assert(memcmp(value, key, 4) == 0);
2509 assert(rc == MEMCACHED_SUCCESS);
2510
2511 /* Test that we can turn it off */
2512 rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, NULL);
2513 assert(rc == MEMCACHED_SUCCESS);
2514
2515 value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc);
2516 assert(rc == MEMCACHED_FAILURE);
2517
2518 /* Now setup for main test */
2519 rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, (void *)key);
2520 assert(rc == MEMCACHED_SUCCESS);
2521
2522 value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc);
2523 assert(rc == MEMCACHED_SUCCESS);
2524 assert(memcmp(value, key, 4) == 0);
2525
2526 return MEMCACHED_SUCCESS;
2527 }
2528
2529 memcached_return set_memory_alloc(memcached_st *memc)
2530 {
2531 {
2532 memcached_malloc_function test_ptr;
2533 memcached_return rc;
2534
2535 rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_MALLOC_FUNCTION, &my_malloc);
2536 assert(rc == MEMCACHED_SUCCESS);
2537 test_ptr= (memcached_malloc_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_MALLOC_FUNCTION, &rc);
2538 assert(rc == MEMCACHED_SUCCESS);
2539 assert(test_ptr == my_malloc);
2540 }
2541
2542 {
2543 memcached_realloc_function test_ptr;
2544 memcached_return rc;
2545
2546 rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_REALLOC_FUNCTION, &my_realloc);
2547 assert(rc == MEMCACHED_SUCCESS);
2548 test_ptr= (memcached_realloc_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_REALLOC_FUNCTION, &rc);
2549 assert(rc == MEMCACHED_SUCCESS);
2550 assert(test_ptr == my_realloc);
2551 }
2552
2553 {
2554 memcached_free_function test_ptr;
2555 memcached_return rc;
2556
2557 rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_FREE_FUNCTION, my_free);
2558 assert(rc == MEMCACHED_SUCCESS);
2559 test_ptr= (memcached_free_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_FREE_FUNCTION, &rc);
2560 assert(rc == MEMCACHED_SUCCESS);
2561 assert(test_ptr == my_free);
2562 }
2563
2564 return MEMCACHED_SUCCESS;
2565 }
2566
2567 memcached_return enable_wheel(memcached_st *memc)
2568 {
2569 memcached_server_distribution value= MEMCACHED_DISTRIBUTION_CONSISTENT_WHEEL;
2570 memcached_hash hash;
2571 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, value);
2572 pre_hsieh(memc);
2573
2574 value= (memcached_server_distribution)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION);
2575 assert(value == MEMCACHED_DISTRIBUTION_CONSISTENT_WHEEL);
2576
2577 hash= (memcached_hash)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
2578 assert(hash == MEMCACHED_HASH_HSIEH);
2579
2580
2581 return MEMCACHED_SUCCESS;
2582 }
2583
2584 memcached_return enable_consistent(memcached_st *memc)
2585 {
2586 memcached_server_distribution value= MEMCACHED_DISTRIBUTION_CONSISTENT;
2587 memcached_hash hash;
2588 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, value);
2589 pre_hsieh(memc);
2590
2591 value= (memcached_server_distribution)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION);
2592 assert(value == MEMCACHED_DISTRIBUTION_CONSISTENT);
2593
2594 hash= (memcached_hash)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
2595 assert(hash == MEMCACHED_HASH_HSIEH);
2596
2597
2598 return MEMCACHED_SUCCESS;
2599 }
2600
2601 memcached_return enable_cas(memcached_st *memc)
2602 {
2603 unsigned int set= 1;
2604
2605 memcached_version(memc);
2606
2607 if (memc->hosts[0].major_version >= 1 &&
2608 memc->hosts[0].minor_version >= 2 &&
2609 memc->hosts[0].micro_version >= 4)
2610 {
2611 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, set);
2612
2613 return MEMCACHED_SUCCESS;
2614 }
2615
2616 return MEMCACHED_FAILURE;
2617 }
2618
2619 memcached_return check_for_1_2_3(memcached_st *memc)
2620 {
2621 memcached_version(memc);
2622
2623 if (memc->hosts[0].major_version >= 1 &&
2624 memc->hosts[0].minor_version >= 2 &&
2625 memc->hosts[0].micro_version >= 4)
2626 return MEMCACHED_SUCCESS;
2627
2628 return MEMCACHED_FAILURE;
2629 }
2630
2631 memcached_return pre_unix_socket(memcached_st *memc)
2632 {
2633 memcached_return rc;
2634 struct stat buf;
2635
2636 memcached_server_list_free(memc->hosts);
2637 memc->hosts= NULL;
2638 memc->number_of_hosts= 0;
2639
2640 if (stat("/tmp/memcached.socket", &buf))
2641 return MEMCACHED_FAILURE;
2642
2643 rc= memcached_server_add_unix_socket(memc, "/tmp/memcached.socket");
2644
2645 return rc;
2646 }
2647
2648 memcached_return pre_udp(memcached_st *memc)
2649 {
2650 memcached_return rc;
2651
2652 memcached_server_list_free(memc->hosts);
2653 memc->hosts= NULL;
2654 memc->number_of_hosts= 0;
2655
2656 if (0)
2657 return MEMCACHED_FAILURE;
2658
2659 rc= memcached_server_add_udp(memc, "localhost", MEMCACHED_DEFAULT_PORT);
2660
2661 return rc;
2662 }
2663
2664 memcached_return pre_nodelay(memcached_st *memc)
2665 {
2666 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 0);
2667 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, 0);
2668
2669 return MEMCACHED_SUCCESS;
2670 }
2671
2672 memcached_return poll_timeout(memcached_st *memc)
2673 {
2674 int32_t timeout;
2675
2676 timeout= 100;
2677
2678 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, timeout);
2679
2680 timeout= (int32_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT);
2681
2682 assert(timeout == 100);
2683
2684 return MEMCACHED_SUCCESS;
2685 }
2686
2687
2688 /* Clean the server before beginning testing */
2689 test_st tests[] ={
2690 {"flush", 0, flush_test },
2691 {"init", 0, init_test },
2692 {"allocation", 0, allocation_test },
2693 {"server_list_null_test", 0, server_list_null_test},
2694 {"server_unsort", 0, server_unsort_test},
2695 {"server_sort", 0, server_sort_test},
2696 {"clone_test", 0, clone_test },
2697 {"error", 0, error_test },
2698 {"set", 0, set_test },
2699 {"set2", 0, set_test2 },
2700 {"set3", 0, set_test3 },
2701 {"add", 1, add_test },
2702 {"replace", 1, replace_test },
2703 {"delete", 1, delete_test },
2704 {"get", 1, get_test },
2705 {"get2", 0, get_test2 },
2706 {"get3", 0, get_test3 },
2707 {"get4", 0, get_test4 },
2708 {"stats_servername", 0, stats_servername_test },
2709 {"increment", 0, increment_test },
2710 {"decrement", 0, decrement_test },
2711 {"quit", 0, quit_test },
2712 {"mget", 1, mget_test },
2713 {"mget_result", 1, mget_result_test },
2714 {"mget_result_alloc", 1, mget_result_alloc_test },
2715 {"mget_result_function", 1, mget_result_function },
2716 {"get_stats", 0, get_stats },
2717 {"add_host_test", 0, add_host_test },
2718 {"get_stats_keys", 0, get_stats_keys },
2719 {"behavior_test", 0, get_stats_keys },
2720 {"callback_test", 0, get_stats_keys },
2721 {"version_string_test", 0, version_string_test},
2722 {"bad_key", 1, bad_key_test },
2723 {"memcached_server_cursor", 1, memcached_server_cursor_test },
2724 {"read_through", 1, read_through },
2725 {"delete_through", 1, delete_through },
2726 {0, 0, 0}
2727 };
2728
2729 test_st async_tests[] ={
2730 {"add", 1, add_wrapper },
2731 {0, 0, 0}
2732 };
2733
2734 test_st string_tests[] ={
2735 {"string static with null", 0, string_static_null },
2736 {"string alloc with null", 0, string_alloc_null },
2737 {"string alloc with 1K", 0, string_alloc_with_size },
2738 {"string alloc with malloc failure", 0, string_alloc_with_size_toobig },
2739 {"string append", 0, string_alloc_append },
2740 {"string append failure (too big)", 0, string_alloc_append_toobig },
2741 {0, 0, 0}
2742 };
2743
2744 test_st result_tests[] ={
2745 {"result static", 0, result_static},
2746 {"result alloc", 0, result_alloc},
2747 {0, 0, 0}
2748 };
2749
2750 test_st version_1_2_3[] ={
2751 {"append", 0, append_test },
2752 {"prepend", 0, prepend_test },
2753 {"cas", 0, cas_test },
2754 {"cas2", 0, cas2_test },
2755 {"append_binary", 0, append_binary_test },
2756 {0, 0, 0}
2757 };
2758
2759 test_st user_tests[] ={
2760 {"user_supplied_bug1", 0, user_supplied_bug1 },
2761 {"user_supplied_bug2", 0, user_supplied_bug2 },
2762 {"user_supplied_bug3", 0, user_supplied_bug3 },
2763 {"user_supplied_bug4", 0, user_supplied_bug4 },
2764 {"user_supplied_bug5", 1, user_supplied_bug5 },
2765 {"user_supplied_bug6", 1, user_supplied_bug6 },
2766 {"user_supplied_bug7", 1, user_supplied_bug7 },
2767 {"user_supplied_bug8", 1, user_supplied_bug8 },
2768 {"user_supplied_bug9", 1, user_supplied_bug9 },
2769 {"user_supplied_bug10", 1, user_supplied_bug10 },
2770 {"user_supplied_bug11", 1, user_supplied_bug11 },
2771 {"user_supplied_bug12", 1, user_supplied_bug12 },
2772 {"user_supplied_bug13", 1, user_supplied_bug13 },
2773 {"user_supplied_bug14", 1, user_supplied_bug14 },
2774 {"user_supplied_bug15", 1, user_supplied_bug15 },
2775 {"user_supplied_bug16", 1, user_supplied_bug16 },
2776 {0, 0, 0}
2777 };
2778
2779 test_st generate_tests[] ={
2780 {"generate_pairs", 1, generate_pairs },
2781 {"generate_data", 1, generate_data },
2782 {"get_read", 0, get_read },
2783 {"delete_generate", 0, delete_generate },
2784 {"generate_buffer_data", 1, generate_buffer_data },
2785 {"delete_buffer", 0, delete_buffer_generate},
2786 {"generate_data", 1, generate_data },
2787 {"mget_read", 0, mget_read },
2788 {"mget_read_result", 0, mget_read_result },
2789 {"mget_read_function", 0, mget_read_function },
2790 {"cleanup", 1, cleanup_pairs },
2791 {"generate_large_pairs", 1, generate_large_pairs },
2792 {"generate_data", 1, generate_data },
2793 {"generate_buffer_data", 1, generate_buffer_data },
2794 {"cleanup", 1, cleanup_pairs },
2795 {0, 0, 0}
2796 };
2797
2798 test_st consistent_tests[] ={
2799 {"generate_pairs", 1, generate_pairs },
2800 {"generate_data", 1, generate_data },
2801 {"get_read", 0, get_read_count },
2802 {"cleanup", 1, cleanup_pairs },
2803 {0, 0, 0}
2804 };
2805
2806 collection_st collection[] ={
2807 {"block", 0, 0, tests},
2808 {"nonblock", pre_nonblock, 0, tests},
2809 {"nodelay", pre_nodelay, 0, tests},
2810 {"md5", pre_md5, 0, tests},
2811 {"crc", pre_crc, 0, tests},
2812 {"hsieh", pre_hsieh, 0, tests},
2813 {"fnv1_64", pre_hash_fnv1_64, 0, tests},
2814 {"fnv1a_64", pre_hash_fnv1a_64, 0, tests},
2815 {"fnv1_32", pre_hash_fnv1_32, 0, tests},
2816 {"fnv1a_32", pre_hash_fnv1a_32, 0, tests},
2817 {"ketama", pre_behavior_ketama, 0, tests},
2818 {"unix_socket", pre_unix_socket, 0, tests},
2819 {"unix_socket_nodelay", pre_nodelay, 0, tests},
2820 {"poll_timeout", poll_timeout, 0, tests},
2821 {"gets", enable_cas, 0, tests},
2822 {"consistent", enable_consistent, 0, tests},
2823 {"wheel", enable_wheel, 0, tests},
2824 {"memory_allocators", set_memory_alloc, 0, tests},
2825 {"prefix", set_prefix, 0, tests},
2826 // {"udp", pre_udp, 0, tests},
2827 {"version_1_2_3", check_for_1_2_3, 0, version_1_2_3},
2828 {"string", 0, 0, string_tests},
2829 {"result", 0, 0, result_tests},
2830 {"async", pre_nonblock, 0, async_tests},
2831 {"user", 0, 0, user_tests},
2832 {"generate", 0, 0, generate_tests},
2833 {"generate_hsieh", pre_hsieh, 0, generate_tests},
2834 {"generate_ketama", pre_behavior_ketama, 0, generate_tests},
2835 {"generate_hsieh_consistent", enable_consistent, 0, generate_tests},
2836 {"generate_md5", pre_md5, 0, generate_tests},
2837 {"generate_murmur", pre_murmur, 0, generate_tests},
2838 {"generate_nonblock", pre_nonblock, 0, generate_tests},
2839 {"consistent_not", 0, 0, consistent_tests},
2840 {"consistent_ketama", pre_behavior_ketama, 0, consistent_tests},
2841 {"consistent_wheel", enable_wheel, 0, consistent_tests},
2842 {0, 0, 0, 0}
2843 };
2844
2845 #define SERVERS_TO_CREATE 5
2846
2847 void *world_create(void)
2848 {
2849 server_startup_st *construct;
2850
2851 construct= (server_startup_st *)malloc(sizeof(server_startup_st));
2852 memset(construct, 0, sizeof(server_startup_st));
2853 construct->count= SERVERS_TO_CREATE;
2854 construct->udp= 0;
2855 server_startup(construct);
2856
2857 return construct;
2858 }
2859
2860 void world_destroy(void *p)
2861 {
2862 server_startup_st *construct= (server_startup_st *)p;
2863 memcached_server_st *servers= (memcached_server_st *)construct->servers;
2864 memcached_server_list_free(servers);
2865
2866 server_shutdown(construct);
2867 free(construct);
2868 }
2869
2870 void get_world(world_st *world)
2871 {
2872 world->collections= collection;
2873 world->create= world_create;
2874 world->destroy= world_destroy;
2875 }