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