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