2 Sample test application.
14 #include "../clients/generator.h"
15 #include "../clients/execute.h"
18 #define INT64_MAX LONG_MAX
21 #define INT32_MAX INT_MAX
27 #define GLOBAL_COUNT 10000
28 #define GLOBAL2_COUNT 100
29 #define SERVERS_TO_CREATE 5
30 static uint32_t global_count
;
32 static pairs_st
*global_pairs
;
33 static char *global_keys
[GLOBAL_COUNT
];
34 static size_t global_keys_length
[GLOBAL_COUNT
];
36 static test_return
init_test(memcached_st
*not_used
__attribute__((unused
)))
40 (void)memcached_create(&memc
);
41 memcached_free(&memc
);
46 static test_return
server_list_null_test(memcached_st
*ptr
__attribute__((unused
)))
48 memcached_server_st
*server_list
;
51 server_list
= memcached_server_list_append_with_weight(NULL
, NULL
, 0, 0, NULL
);
52 assert(server_list
== NULL
);
54 server_list
= memcached_server_list_append_with_weight(NULL
, "localhost", 0, 0, NULL
);
55 assert(server_list
== NULL
);
57 server_list
= memcached_server_list_append_with_weight(NULL
, NULL
, 0, 0, &rc
);
58 assert(server_list
== NULL
);
63 #define TEST_PORT_COUNT 7
64 uint32_t test_ports
[TEST_PORT_COUNT
];
66 static memcached_return
server_display_function(memcached_st
*ptr
__attribute__((unused
)), memcached_server_st
*server
, void *context
)
69 uint32_t bigger
= *((uint32_t *)(context
));
70 assert(bigger
<= server
->port
);
71 *((uint32_t *)(context
))= server
->port
;
73 return MEMCACHED_SUCCESS
;
76 static test_return
server_sort_test(memcached_st
*ptr
__attribute__((unused
)))
79 uint32_t bigger
= 0; /* Prime the value for the assert in server_display_function */
81 memcached_server_function callbacks
[1];
82 memcached_st
*local_memc
;
84 local_memc
= memcached_create(NULL
);
86 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
88 for (x
= 0; x
< TEST_PORT_COUNT
; x
++)
90 test_ports
[x
]= random() % 64000;
91 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
92 assert(local_memc
->number_of_hosts
== x
+ 1);
93 assert(local_memc
->hosts
[0].count
== x
+1);
94 assert(rc
== MEMCACHED_SUCCESS
);
97 callbacks
[0]= server_display_function
;
98 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
101 memcached_free(local_memc
);
106 static test_return
server_sort2_test(memcached_st
*ptr
__attribute__((unused
)))
108 uint32_t bigger
= 0; /* Prime the value for the assert in server_display_function */
110 memcached_server_function callbacks
[1];
111 memcached_st
*local_memc
;
113 local_memc
= memcached_create(NULL
);
115 rc
= memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
116 assert(rc
== MEMCACHED_SUCCESS
);
118 rc
= memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43043, 0);
119 assert(rc
== MEMCACHED_SUCCESS
);
120 assert(local_memc
->hosts
[0].port
== 43043);
122 rc
= memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43042, 0);
123 assert(rc
== MEMCACHED_SUCCESS
);
124 assert(local_memc
->hosts
[0].port
== 43042);
125 assert(local_memc
->hosts
[1].port
== 43043);
127 callbacks
[0]= server_display_function
;
128 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
131 memcached_free(local_memc
);
136 static memcached_return
server_display_unsort_function(memcached_st
*ptr
__attribute__((unused
)), memcached_server_st
*server
, void *context
)
139 uint32_t x
= *((uint32_t *)(context
));
141 assert(test_ports
[x
] == server
->port
);
142 *((uint32_t *)(context
))= ++x
;
144 return MEMCACHED_SUCCESS
;
147 static test_return
server_unsort_test(memcached_st
*ptr
__attribute__((unused
)))
150 uint32_t counter
= 0; /* Prime the value for the assert in server_display_function */
151 uint32_t bigger
= 0; /* Prime the value for the assert in server_display_function */
153 memcached_server_function callbacks
[1];
154 memcached_st
*local_memc
;
156 local_memc
= memcached_create(NULL
);
159 for (x
= 0; x
< TEST_PORT_COUNT
; x
++)
161 test_ports
[x
]= random() % 64000;
162 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
163 assert(local_memc
->number_of_hosts
== x
+1);
164 assert(local_memc
->hosts
[0].count
== x
+1);
165 assert(rc
== MEMCACHED_SUCCESS
);
168 callbacks
[0]= server_display_unsort_function
;
169 memcached_server_cursor(local_memc
, callbacks
, (void *)&counter
, 1);
171 /* Now we sort old data! */
172 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
173 callbacks
[0]= server_display_function
;
174 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
177 memcached_free(local_memc
);
182 static test_return
allocation_test(memcached_st
*not_used
__attribute__((unused
)))
185 memc
= memcached_create(NULL
);
187 memcached_free(memc
);
192 static test_return
clone_test(memcached_st
*memc
)
197 clone
= memcached_clone(NULL
, NULL
);
199 memcached_free(clone
);
202 /* Can we init from null? */
205 clone
= memcached_clone(NULL
, memc
);
207 memcached_free(clone
);
210 /* Can we init from struct? */
212 memcached_st declared_clone
;
214 memset(&declared_clone
, 0 , sizeof(memcached_st
));
215 clone
= memcached_clone(&declared_clone
, NULL
);
217 memcached_free(clone
);
220 /* Can we init from struct? */
222 memcached_st declared_clone
;
224 memset(&declared_clone
, 0 , sizeof(memcached_st
));
225 clone
= memcached_clone(&declared_clone
, memc
);
227 memcached_free(clone
);
233 static test_return
connection_test(memcached_st
*memc
)
237 rc
= memcached_server_add_with_weight(memc
, "localhost", 0, 0);
238 assert(rc
== MEMCACHED_SUCCESS
);
243 static test_return
error_test(memcached_st
*memc
)
247 for (rc
= MEMCACHED_SUCCESS
; rc
< MEMCACHED_MAXIMUM_RETURN
; rc
++)
249 printf("Error %d -> %s\n", rc
, memcached_strerror(memc
, rc
));
255 static test_return
set_test(memcached_st
*memc
)
259 char *value
= "when we sanitize";
261 rc
= memcached_set(memc
, key
, strlen(key
),
262 value
, strlen(value
),
263 (time_t)0, (uint32_t)0);
264 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
269 static test_return
append_test(memcached_st
*memc
)
277 rc
= memcached_flush(memc
, 0);
278 assert(rc
== MEMCACHED_SUCCESS
);
280 rc
= memcached_set(memc
, key
, strlen(key
),
281 value
, strlen(value
),
282 (time_t)0, (uint32_t)0);
283 assert(rc
== MEMCACHED_SUCCESS
);
285 rc
= memcached_append(memc
, key
, strlen(key
),
286 " the", strlen(" the"),
287 (time_t)0, (uint32_t)0);
288 assert(rc
== MEMCACHED_SUCCESS
);
290 rc
= memcached_append(memc
, key
, strlen(key
),
291 " people", strlen(" people"),
292 (time_t)0, (uint32_t)0);
293 assert(rc
== MEMCACHED_SUCCESS
);
295 value
= memcached_get(memc
, key
, strlen(key
),
296 &value_length
, &flags
, &rc
);
297 assert(!memcmp(value
, "we the people", strlen("we the people")));
298 assert(strlen("we the people") == value_length
);
299 assert(rc
== MEMCACHED_SUCCESS
);
305 static test_return
append_binary_test(memcached_st
*memc
)
308 char *key
= "numbers";
309 unsigned int *store_ptr
;
310 unsigned int store_list
[] = { 23, 56, 499, 98, 32847, 0 };
316 rc
= memcached_flush(memc
, 0);
317 assert(rc
== MEMCACHED_SUCCESS
);
319 rc
= memcached_set(memc
,
322 (time_t)0, (uint32_t)0);
323 assert(rc
== MEMCACHED_SUCCESS
);
325 for (x
= 0; store_list
[x
] ; x
++)
327 rc
= memcached_append(memc
,
329 (char *)&store_list
[x
], sizeof(unsigned int),
330 (time_t)0, (uint32_t)0);
331 assert(rc
== MEMCACHED_SUCCESS
);
334 value
= memcached_get(memc
, key
, strlen(key
),
335 &value_length
, &flags
, &rc
);
336 assert((value_length
== (sizeof(unsigned int) * x
)));
337 assert(rc
== MEMCACHED_SUCCESS
);
339 store_ptr
= (unsigned int *)value
;
341 while ((size_t)store_ptr
< (size_t)(value
+ value_length
))
343 assert(*store_ptr
== store_list
[x
++]);
351 static test_return
cas2_test(memcached_st
*memc
)
354 char *keys
[]= {"fudge", "son", "food"};
355 size_t key_length
[]= {5, 3, 4};
356 char *value
= "we the people";
357 size_t value_length
= strlen("we the people");
359 memcached_result_st results_obj
;
360 memcached_result_st
*results
;
363 rc
= memcached_flush(memc
, 0);
364 assert(rc
== MEMCACHED_SUCCESS
);
366 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
368 for (x
= 0; x
< 3; x
++)
370 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
371 keys
[x
], key_length
[x
],
372 (time_t)50, (uint32_t)9);
373 assert(rc
== MEMCACHED_SUCCESS
);
376 rc
= memcached_mget(memc
, keys
, key_length
, 3);
378 results
= memcached_result_create(memc
, &results_obj
);
380 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
382 assert(results
->cas
);
383 assert(rc
== MEMCACHED_SUCCESS
);
384 WATCHPOINT_ASSERT(memcached_result_cas(results
));
386 assert(!memcmp(value
, "we the people", strlen("we the people")));
387 assert(strlen("we the people") == value_length
);
388 assert(rc
== MEMCACHED_SUCCESS
);
390 memcached_result_free(&results_obj
);
395 static test_return
cas_test(memcached_st
*memc
)
399 size_t key_length
= strlen("fun");
400 char *value
= "we the people";
401 size_t value_length
= strlen("we the people");
402 memcached_result_st results_obj
;
403 memcached_result_st
*results
;
406 rc
= memcached_flush(memc
, 0);
407 assert(rc
== MEMCACHED_SUCCESS
);
409 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
411 rc
= memcached_set(memc
, key
, strlen(key
),
412 value
, strlen(value
),
413 (time_t)0, (uint32_t)0);
414 assert(rc
== MEMCACHED_SUCCESS
);
416 rc
= memcached_mget(memc
, &key
, &key_length
, 1);
418 results
= memcached_result_create(memc
, &results_obj
);
420 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
422 assert(rc
== MEMCACHED_SUCCESS
);
423 WATCHPOINT_ASSERT(memcached_result_cas(results
));
425 assert(!memcmp(value
, "we the people", strlen("we the people")));
426 assert(strlen("we the people") == value_length
);
427 assert(rc
== MEMCACHED_SUCCESS
);
429 rc
= memcached_cas(memc
, key
, key_length
,
430 "change the value", strlen("change the value"),
431 0, 0, memcached_result_cas(results
));
433 assert(rc
== MEMCACHED_SUCCESS
);
435 rc
= memcached_cas(memc
, key
, key_length
,
436 "change the value", strlen("change the value"),
439 assert(rc
== MEMCACHED_DATA_EXISTS
);
442 memcached_result_free(&results_obj
);
447 static test_return
prepend_test(memcached_st
*memc
)
451 char *value
= "people";
455 rc
= memcached_flush(memc
, 0);
456 assert(rc
== MEMCACHED_SUCCESS
);
458 rc
= memcached_set(memc
, key
, strlen(key
),
459 value
, strlen(value
),
460 (time_t)0, (uint32_t)0);
461 assert(rc
== MEMCACHED_SUCCESS
);
463 rc
= memcached_prepend(memc
, key
, strlen(key
),
464 "the ", strlen("the "),
465 (time_t)0, (uint32_t)0);
466 assert(rc
== MEMCACHED_SUCCESS
);
468 rc
= memcached_prepend(memc
, key
, strlen(key
),
469 "we ", strlen("we "),
470 (time_t)0, (uint32_t)0);
471 assert(rc
== MEMCACHED_SUCCESS
);
473 value
= memcached_get(memc
, key
, strlen(key
),
474 &value_length
, &flags
, &rc
);
475 assert(!memcmp(value
, "we the people", strlen("we the people")));
476 assert(strlen("we the people") == value_length
);
477 assert(rc
== MEMCACHED_SUCCESS
);
484 Set the value, then quit to make sure it is flushed.
485 Come back in and test that add fails.
487 static test_return
add_test(memcached_st
*memc
)
491 char *value
= "when we sanitize";
492 unsigned long long setting_value
;
494 setting_value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
496 rc
= memcached_set(memc
, key
, strlen(key
),
497 value
, strlen(value
),
498 (time_t)0, (uint32_t)0);
499 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
500 memcached_quit(memc
);
501 rc
= memcached_add(memc
, key
, strlen(key
),
502 value
, strlen(value
),
503 (time_t)0, (uint32_t)0);
505 /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */
507 assert(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_STORED
);
509 assert(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_DATA_EXISTS
);
514 static test_return
add_wrapper(memcached_st
*memc
)
518 for (x
= 0; x
< 10000; x
++)
524 static test_return
replace_test(memcached_st
*memc
)
528 char *value
= "when we sanitize";
529 char *original
= "first we insert some data";
531 rc
= memcached_set(memc
, key
, strlen(key
),
532 original
, strlen(original
),
533 (time_t)0, (uint32_t)0);
534 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
536 rc
= memcached_replace(memc
, key
, strlen(key
),
537 value
, strlen(value
),
538 (time_t)0, (uint32_t)0);
539 assert(rc
== MEMCACHED_SUCCESS
);
544 static test_return
delete_test(memcached_st
*memc
)
548 char *value
= "when we sanitize";
550 rc
= memcached_set(memc
, key
, strlen(key
),
551 value
, strlen(value
),
552 (time_t)0, (uint32_t)0);
553 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
555 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
556 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
561 static test_return
flush_test(memcached_st
*memc
)
565 rc
= memcached_flush(memc
, 0);
566 assert(rc
== MEMCACHED_SUCCESS
);
571 static memcached_return
server_function(memcached_st
*ptr
__attribute__((unused
)),
572 memcached_server_st
*server
__attribute__((unused
)),
573 void *context
__attribute__((unused
)))
577 return MEMCACHED_SUCCESS
;
580 static test_return
memcached_server_cursor_test(memcached_st
*memc
)
582 char *context
= "foo bad";
583 memcached_server_function callbacks
[1];
585 callbacks
[0]= server_function
;
586 memcached_server_cursor(memc
, callbacks
, context
, 1);
591 static test_return
bad_key_test(memcached_st
*memc
)
594 char *key
= "foo bad";
596 size_t string_length
;
601 clone
= memcached_clone(NULL
, memc
);
604 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
605 assert(rc
== MEMCACHED_SUCCESS
);
607 string
= memcached_get(clone
, key
, strlen(key
),
608 &string_length
, &flags
, &rc
);
609 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
610 assert(string_length
== 0);
614 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
615 assert(rc
== MEMCACHED_SUCCESS
);
616 string
= memcached_get(clone
, key
, strlen(key
),
617 &string_length
, &flags
, &rc
);
618 assert(rc
== MEMCACHED_NOTFOUND
);
619 assert(string_length
== 0);
622 /* Test multi key for bad keys */
624 char *keys
[] = { "GoodKey", "Bad Key", "NotMine" };
625 size_t key_lengths
[] = { 7, 7, 7 };
627 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
628 assert(rc
== MEMCACHED_SUCCESS
);
630 rc
= memcached_mget(clone
, keys
, key_lengths
, 3);
631 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
633 rc
= memcached_mget_by_key(clone
, "foo daddy", 9, keys
, key_lengths
, 1);
634 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
637 /* Make sure zero length keys are marked as bad */
639 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
640 assert(rc
== MEMCACHED_SUCCESS
);
641 string
= memcached_get(clone
, key
, 0,
642 &string_length
, &flags
, &rc
);
643 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
644 assert(string_length
== 0);
647 memcached_free(clone
);
652 #define READ_THROUGH_VALUE "set for me"
653 static memcached_return
read_through_trigger(memcached_st
*memc
__attribute__((unused
)),
654 char *key
__attribute__((unused
)),
655 size_t key_length
__attribute__((unused
)),
656 memcached_result_st
*result
)
659 return memcached_result_set_value(result
, READ_THROUGH_VALUE
, strlen(READ_THROUGH_VALUE
));
662 static test_return
read_through(memcached_st
*memc
)
667 size_t string_length
;
670 string
= memcached_get(memc
, key
, strlen(key
),
671 &string_length
, &flags
, &rc
);
673 assert(rc
== MEMCACHED_NOTFOUND
);
674 assert(string_length
== 0);
677 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_GET_FAILURE
, (void *)read_through_trigger
);
678 assert(rc
== MEMCACHED_SUCCESS
);
680 string
= memcached_get(memc
, key
, strlen(key
),
681 &string_length
, &flags
, &rc
);
683 assert(rc
== MEMCACHED_SUCCESS
);
684 assert(string_length
== strlen(READ_THROUGH_VALUE
));
685 assert(!strcmp(READ_THROUGH_VALUE
, string
));
688 string
= memcached_get(memc
, key
, strlen(key
),
689 &string_length
, &flags
, &rc
);
691 assert(rc
== MEMCACHED_SUCCESS
);
692 assert(string_length
== strlen(READ_THROUGH_VALUE
));
693 assert(!strcmp(READ_THROUGH_VALUE
, string
));
699 static memcached_return
delete_trigger(memcached_st
*ptr
__attribute__((unused
)),
701 size_t key_length
__attribute__((unused
)))
705 return MEMCACHED_SUCCESS
;
708 static test_return
delete_through(memcached_st
*memc
)
710 memcached_trigger_delete_key callback
;
713 callback
= delete_trigger
;
715 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_DELETE_TRIGGER
, callback
);
716 assert(rc
== MEMCACHED_SUCCESS
);
721 static test_return
get_test(memcached_st
*memc
)
726 size_t string_length
;
729 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
730 assert(rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_NOTFOUND
);
732 string
= memcached_get(memc
, key
, strlen(key
),
733 &string_length
, &flags
, &rc
);
735 assert(rc
== MEMCACHED_NOTFOUND
);
736 assert(string_length
== 0);
742 static test_return
get_test2(memcached_st
*memc
)
746 char *value
= "when we sanitize";
748 size_t string_length
;
751 rc
= memcached_set(memc
, key
, strlen(key
),
752 value
, strlen(value
),
753 (time_t)0, (uint32_t)0);
754 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
756 string
= memcached_get(memc
, key
, strlen(key
),
757 &string_length
, &flags
, &rc
);
760 assert(rc
== MEMCACHED_SUCCESS
);
761 assert(string_length
== strlen(value
));
762 assert(!memcmp(string
, value
, string_length
));
769 static test_return
set_test2(memcached_st
*memc
)
773 char *value
= "train in the brain";
774 size_t value_length
= strlen(value
);
777 for (x
= 0; x
< 10; x
++)
779 rc
= memcached_set(memc
, key
, strlen(key
),
781 (time_t)0, (uint32_t)0);
782 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
788 static test_return
set_test3(memcached_st
*memc
)
793 size_t value_length
= 8191;
796 value
= (char*)malloc(value_length
);
799 for (x
= 0; x
< value_length
; x
++)
800 value
[x
] = (char) (x
% 127);
802 for (x
= 0; x
< 1; x
++)
804 rc
= memcached_set(memc
, key
, strlen(key
),
806 (time_t)0, (uint32_t)0);
807 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
815 static test_return
get_test3(memcached_st
*memc
)
820 size_t value_length
= 8191;
822 size_t string_length
;
826 value
= (char*)malloc(value_length
);
829 for (x
= 0; x
< value_length
; x
++)
830 value
[x
] = (char) (x
% 127);
832 rc
= memcached_set(memc
, key
, strlen(key
),
834 (time_t)0, (uint32_t)0);
835 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
837 string
= memcached_get(memc
, key
, strlen(key
),
838 &string_length
, &flags
, &rc
);
840 assert(rc
== MEMCACHED_SUCCESS
);
842 assert(string_length
== value_length
);
843 assert(!memcmp(string
, value
, string_length
));
851 static test_return
get_test4(memcached_st
*memc
)
856 size_t value_length
= 8191;
858 size_t string_length
;
862 value
= (char*)malloc(value_length
);
865 for (x
= 0; x
< value_length
; x
++)
866 value
[x
] = (char) (x
% 127);
868 rc
= memcached_set(memc
, key
, strlen(key
),
870 (time_t)0, (uint32_t)0);
871 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
873 for (x
= 0; x
< 10; x
++)
875 string
= memcached_get(memc
, key
, strlen(key
),
876 &string_length
, &flags
, &rc
);
878 assert(rc
== MEMCACHED_SUCCESS
);
880 assert(string_length
== value_length
);
881 assert(!memcmp(string
, value
, string_length
));
890 /* Do not copy the style of this code, I just access hosts to testthis function */
891 static test_return
stats_servername_test(memcached_st
*memc
)
894 memcached_stat_st stat
;
895 rc
= memcached_stat_servername(&stat
, NULL
,
896 memc
->hosts
[0].hostname
,
897 memc
->hosts
[0].port
);
902 static test_return
increment_test(memcached_st
*memc
)
909 rc
= memcached_set(memc
, key
, strlen(key
),
910 value
, strlen(value
),
911 (time_t)0, (uint32_t)0);
912 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
914 rc
= memcached_increment(memc
, key
, strlen(key
),
916 assert(rc
== MEMCACHED_SUCCESS
);
917 assert(new_number
== 1);
919 rc
= memcached_increment(memc
, key
, strlen(key
),
921 assert(rc
== MEMCACHED_SUCCESS
);
922 assert(new_number
== 2);
927 static test_return
decrement_test(memcached_st
*memc
)
934 rc
= memcached_set(memc
, key
, strlen(key
),
935 value
, strlen(value
),
936 (time_t)0, (uint32_t)0);
937 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
939 rc
= memcached_decrement(memc
, key
, strlen(key
),
941 assert(rc
== MEMCACHED_SUCCESS
);
942 assert(new_number
== 2);
944 rc
= memcached_decrement(memc
, key
, strlen(key
),
946 assert(rc
== MEMCACHED_SUCCESS
);
947 assert(new_number
== 1);
952 static test_return
quit_test(memcached_st
*memc
)
956 char *value
= "sanford and sun";
958 rc
= memcached_set(memc
, key
, strlen(key
),
959 value
, strlen(value
),
960 (time_t)10, (uint32_t)3);
961 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
962 memcached_quit(memc
);
964 rc
= memcached_set(memc
, key
, strlen(key
),
965 value
, strlen(value
),
966 (time_t)50, (uint32_t)9);
967 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
972 static test_return
mget_result_test(memcached_st
*memc
)
975 char *keys
[]= {"fudge", "son", "food"};
976 size_t key_length
[]= {5, 3, 4};
979 memcached_result_st results_obj
;
980 memcached_result_st
*results
;
982 results
= memcached_result_create(memc
, &results_obj
);
984 assert(&results_obj
== results
);
986 /* We need to empty the server before continueing test */
987 rc
= memcached_flush(memc
, 0);
988 assert(rc
== MEMCACHED_SUCCESS
);
990 rc
= memcached_mget(memc
, keys
, key_length
, 3);
991 assert(rc
== MEMCACHED_SUCCESS
);
993 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
998 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1000 assert(rc
== MEMCACHED_END
);
1002 for (x
= 0; x
< 3; x
++)
1004 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1005 keys
[x
], key_length
[x
],
1006 (time_t)50, (uint32_t)9);
1007 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1010 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1011 assert(rc
== MEMCACHED_SUCCESS
);
1013 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1016 assert(&results_obj
== results
);
1017 assert(rc
== MEMCACHED_SUCCESS
);
1018 assert(memcached_result_key_length(results
) == memcached_result_length(results
));
1019 assert(!memcmp(memcached_result_key_value(results
),
1020 memcached_result_value(results
),
1021 memcached_result_length(results
)));
1024 memcached_result_free(&results_obj
);
1029 static test_return
mget_result_alloc_test(memcached_st
*memc
)
1031 memcached_return rc
;
1032 char *keys
[]= {"fudge", "son", "food"};
1033 size_t key_length
[]= {5, 3, 4};
1036 memcached_result_st
*results
;
1038 /* We need to empty the server before continueing test */
1039 rc
= memcached_flush(memc
, 0);
1040 assert(rc
== MEMCACHED_SUCCESS
);
1042 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1043 assert(rc
== MEMCACHED_SUCCESS
);
1045 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)) != NULL
)
1050 assert(rc
== MEMCACHED_END
);
1052 for (x
= 0; x
< 3; x
++)
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
);
1060 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1061 assert(rc
== MEMCACHED_SUCCESS
);
1064 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1067 assert(rc
== MEMCACHED_SUCCESS
);
1068 assert(memcached_result_key_length(results
) == memcached_result_length(results
));
1069 assert(!memcmp(memcached_result_key_value(results
),
1070 memcached_result_value(results
),
1071 memcached_result_length(results
)));
1072 memcached_result_free(results
);
1079 /* Count the results */
1080 static memcached_return
callback_counter(memcached_st
*ptr
__attribute__((unused
)),
1081 memcached_result_st
*result
__attribute__((unused
)),
1084 unsigned int *counter
= (unsigned int *)context
;
1086 *counter
= *counter
+ 1;
1088 return MEMCACHED_SUCCESS
;
1091 static test_return
mget_result_function(memcached_st
*memc
)
1093 memcached_return rc
;
1094 char *keys
[]= {"fudge", "son", "food"};
1095 size_t key_length
[]= {5, 3, 4};
1097 unsigned int counter
;
1098 memcached_execute_function callbacks
[1];
1100 /* We need to empty the server before continueing test */
1101 rc
= memcached_flush(memc
, 0);
1102 for (x
= 0; x
< 3; x
++)
1104 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1105 keys
[x
], key_length
[x
],
1106 (time_t)50, (uint32_t)9);
1107 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1110 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1111 assert(rc
== MEMCACHED_SUCCESS
);
1113 callbacks
[0]= &callback_counter
;
1115 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
1117 assert(counter
== 3);
1122 static test_return
mget_test(memcached_st
*memc
)
1124 memcached_return rc
;
1125 char *keys
[]= {"fudge", "son", "food"};
1126 size_t key_length
[]= {5, 3, 4};
1130 char return_key
[MEMCACHED_MAX_KEY
];
1131 size_t return_key_length
;
1133 size_t return_value_length
;
1135 /* We need to empty the server before continueing test */
1136 rc
= memcached_flush(memc
, 0);
1137 assert(rc
== MEMCACHED_SUCCESS
);
1139 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1140 assert(rc
== MEMCACHED_SUCCESS
);
1142 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1143 &return_value_length
, &flags
, &rc
)) != NULL
)
1145 assert(return_value
);
1147 assert(!return_value
);
1148 assert(return_value_length
== 0);
1149 assert(rc
== MEMCACHED_END
);
1151 for (x
= 0; x
< 3; x
++)
1153 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1154 keys
[x
], key_length
[x
],
1155 (time_t)50, (uint32_t)9);
1156 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1159 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1160 assert(rc
== MEMCACHED_SUCCESS
);
1163 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1164 &return_value_length
, &flags
, &rc
)))
1166 assert(return_value
);
1167 assert(rc
== MEMCACHED_SUCCESS
);
1168 assert(return_key_length
== return_value_length
);
1169 assert(!memcmp(return_value
, return_key
, return_value_length
));
1177 static test_return
get_stats_keys(memcached_st
*memc
)
1181 memcached_stat_st stat
;
1182 memcached_return rc
;
1184 list
= memcached_stat_get_keys(memc
, &stat
, &rc
);
1185 assert(rc
== MEMCACHED_SUCCESS
);
1186 for (ptr
= list
; *ptr
; ptr
++)
1195 static test_return
version_string_test(memcached_st
*memc
__attribute__((unused
)))
1197 const char *version_string
;
1199 version_string
= memcached_lib_version();
1201 assert(!strcmp(version_string
, LIBMEMCACHED_VERSION_STRING
));
1206 static test_return
get_stats(memcached_st
*memc
)
1211 memcached_return rc
;
1212 memcached_stat_st
*stat
;
1214 stat
= memcached_stat(memc
, NULL
, &rc
);
1215 assert(rc
== MEMCACHED_SUCCESS
);
1217 assert(rc
== MEMCACHED_SUCCESS
);
1220 for (x
= 0; x
< memcached_server_count(memc
); x
++)
1222 list
= memcached_stat_get_keys(memc
, stat
+x
, &rc
);
1223 assert(rc
== MEMCACHED_SUCCESS
);
1224 for (ptr
= list
; *ptr
; ptr
++);
1229 memcached_stat_free(NULL
, stat
);
1234 static test_return
add_host_test(memcached_st
*memc
)
1237 memcached_server_st
*servers
;
1238 memcached_return rc
;
1239 char servername
[]= "0.example.com";
1241 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
1243 assert(1 == memcached_server_list_count(servers
));
1245 for (x
= 2; x
< 20; x
++)
1247 char buffer
[SMALL_STRING_LEN
];
1249 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
1250 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
1252 assert(rc
== MEMCACHED_SUCCESS
);
1253 assert(x
== memcached_server_list_count(servers
));
1256 rc
= memcached_server_push(memc
, servers
);
1257 assert(rc
== MEMCACHED_SUCCESS
);
1258 rc
= memcached_server_push(memc
, servers
);
1259 assert(rc
== MEMCACHED_SUCCESS
);
1261 memcached_server_list_free(servers
);
1266 static memcached_return
clone_test_callback(memcached_st
*parent
__attribute__((unused
)), memcached_st
*clone
__attribute__((unused
)))
1268 return MEMCACHED_SUCCESS
;
1271 static memcached_return
cleanup_test_callback(memcached_st
*ptr
__attribute__((unused
)))
1273 return MEMCACHED_SUCCESS
;
1276 static test_return
callback_test(memcached_st
*memc
)
1278 /* Test User Data */
1282 memcached_return rc
;
1284 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_USER_DATA
, &x
);
1285 assert(rc
== MEMCACHED_SUCCESS
);
1286 test_ptr
= (int *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_USER_DATA
, &rc
);
1287 assert(*test_ptr
== x
);
1290 /* Test Clone Callback */
1292 memcached_clone_func temp_function
;
1293 memcached_return rc
;
1295 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, clone_test_callback
);
1296 assert(rc
== MEMCACHED_SUCCESS
);
1297 temp_function
= (memcached_clone_func
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1298 assert(temp_function
== clone_test_callback
);
1301 /* Test Cleanup Callback */
1303 memcached_cleanup_func temp_function
;
1304 memcached_return rc
;
1306 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, cleanup_test_callback
);
1307 assert(rc
== MEMCACHED_SUCCESS
);
1308 temp_function
= (memcached_cleanup_func
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1309 assert(temp_function
== cleanup_test_callback
);
1315 /* We don't test the behavior itself, we test the switches */
1316 static test_return
behavior_test(memcached_st
*memc
)
1321 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1322 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1325 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1326 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1329 set
= MEMCACHED_HASH_MD5
;
1330 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1331 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1332 assert(value
== MEMCACHED_HASH_MD5
);
1336 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1337 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1340 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1341 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1344 set
= MEMCACHED_HASH_DEFAULT
;
1345 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1346 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1347 assert(value
== MEMCACHED_HASH_DEFAULT
);
1349 set
= MEMCACHED_HASH_CRC
;
1350 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1351 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1352 assert(value
== MEMCACHED_HASH_CRC
);
1354 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1357 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1363 /* Test case provided by Cal Haldenbrand */
1364 static test_return
user_supplied_bug1(memcached_st
*memc
)
1366 unsigned int setter
= 1;
1369 unsigned long long total
= 0;
1372 char randomstuff
[6 * 1024];
1373 memcached_return rc
;
1375 memset(randomstuff
, 0, 6 * 1024);
1377 /* We just keep looking at the same values over and over */
1380 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1381 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1385 for (x
= 0 ; total
< 20 * 1024576 ; x
++ )
1389 size
= (rand() % ( 5 * 1024 ) ) + 400;
1390 memset(randomstuff
, 0, 6 * 1024);
1391 assert(size
< 6 * 1024); /* Being safe here */
1393 for (j
= 0 ; j
< size
;j
++)
1394 randomstuff
[j
] = (char) (rand() % 26) + 97;
1397 sprintf(key
, "%d", x
);
1398 rc
= memcached_set(memc
, key
, strlen(key
),
1399 randomstuff
, strlen(randomstuff
), 10, 0);
1400 WATCHPOINT_ERROR(rc
);
1401 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1402 /* If we fail, lets try again */
1403 if (rc
!= MEMCACHED_SUCCESS
&& rc
!= MEMCACHED_BUFFERED
)
1404 rc
= memcached_set(memc
, key
, strlen(key
),
1405 randomstuff
, strlen(randomstuff
), 10, 0);
1406 WATCHPOINT_ERROR(rc
);
1407 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1413 /* Test case provided by Cal Haldenbrand */
1414 static test_return
user_supplied_bug2(memcached_st
*memc
)
1417 unsigned int setter
;
1419 unsigned long long total
;
1422 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1423 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1425 setter
= 20 * 1024576;
1426 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1427 setter
= 20 * 1024576;
1428 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1429 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1430 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1432 for (x
= 0, errors
= 0, total
= 0 ; total
< 20 * 1024576 ; x
++)
1435 for (x
= 0, errors
= 0, total
= 0 ; total
< 24576 ; x
++)
1437 memcached_return rc
= MEMCACHED_SUCCESS
;
1438 char buffer
[SMALL_STRING_LEN
];
1443 memset(buffer
, 0, SMALL_STRING_LEN
);
1445 snprintf(buffer
, SMALL_STRING_LEN
, "%u", x
);
1446 getval
= memcached_get(memc
, buffer
, strlen(buffer
),
1447 &val_len
, &flags
, &rc
);
1448 if (rc
!= MEMCACHED_SUCCESS
)
1450 if (rc
== MEMCACHED_NOTFOUND
)
1454 WATCHPOINT_ERROR(rc
);
1468 /* Do a large mget() over all the keys we think exist */
1469 #define KEY_COUNT 3000 // * 1024576
1470 static test_return
user_supplied_bug3(memcached_st
*memc
)
1472 memcached_return rc
;
1473 unsigned int setter
;
1476 size_t key_lengths
[KEY_COUNT
];
1479 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1480 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1482 setter
= 20 * 1024576;
1483 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1484 setter
= 20 * 1024576;
1485 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1486 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1487 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1490 keys
= (char **)malloc(sizeof(char *) * KEY_COUNT
);
1492 memset(keys
, 0, (sizeof(char *) * KEY_COUNT
));
1493 for (x
= 0; x
< KEY_COUNT
; x
++)
1497 snprintf(buffer
, 30, "%u", x
);
1498 keys
[x
]= strdup(buffer
);
1499 key_lengths
[x
]= strlen(keys
[x
]);
1502 rc
= memcached_mget(memc
, keys
, key_lengths
, KEY_COUNT
);
1503 assert(rc
== MEMCACHED_SUCCESS
);
1505 /* Turn this into a help function */
1507 char return_key
[MEMCACHED_MAX_KEY
];
1508 size_t return_key_length
;
1510 size_t return_value_length
;
1513 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1514 &return_value_length
, &flags
, &rc
)))
1516 assert(return_value
);
1517 assert(rc
== MEMCACHED_SUCCESS
);
1522 for (x
= 0; x
< KEY_COUNT
; x
++)
1529 /* Make sure we behave properly if server list has no values */
1530 static test_return
user_supplied_bug4(memcached_st
*memc
)
1532 memcached_return rc
;
1533 char *keys
[]= {"fudge", "son", "food"};
1534 size_t key_length
[]= {5, 3, 4};
1537 char return_key
[MEMCACHED_MAX_KEY
];
1538 size_t return_key_length
;
1540 size_t return_value_length
;
1542 /* Here we free everything before running a bunch of mget tests */
1544 memcached_server_list_free(memc
->hosts
);
1546 memc
->number_of_hosts
= 0;
1550 /* We need to empty the server before continueing test */
1551 rc
= memcached_flush(memc
, 0);
1552 assert(rc
== MEMCACHED_NO_SERVERS
);
1554 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1555 assert(rc
== MEMCACHED_NO_SERVERS
);
1557 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1558 &return_value_length
, &flags
, &rc
)) != NULL
)
1560 assert(return_value
);
1562 assert(!return_value
);
1563 assert(return_value_length
== 0);
1564 assert(rc
== MEMCACHED_NO_SERVERS
);
1566 for (x
= 0; x
< 3; x
++)
1568 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1569 keys
[x
], key_length
[x
],
1570 (time_t)50, (uint32_t)9);
1571 assert(rc
== MEMCACHED_NO_SERVERS
);
1574 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1575 assert(rc
== MEMCACHED_NO_SERVERS
);
1578 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1579 &return_value_length
, &flags
, &rc
)))
1581 assert(return_value
);
1582 assert(rc
== MEMCACHED_SUCCESS
);
1583 assert(return_key_length
== return_value_length
);
1584 assert(!memcmp(return_value
, return_key
, return_value_length
));
1592 #define VALUE_SIZE_BUG5 1048064
1593 static test_return
user_supplied_bug5(memcached_st
*memc
)
1595 memcached_return rc
;
1596 char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1597 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1598 char return_key
[MEMCACHED_MAX_KEY
];
1599 size_t return_key_length
;
1601 size_t value_length
;
1605 char insert_data
[VALUE_SIZE_BUG5
];
1607 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1608 insert_data
[x
]= rand();
1610 memcached_flush(memc
, 0);
1611 value
= memcached_get(memc
, keys
[0], key_length
[0],
1612 &value_length
, &flags
, &rc
);
1613 assert(value
== NULL
);
1614 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1617 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1618 &value_length
, &flags
, &rc
)))
1622 for (x
= 0; x
< 4; x
++)
1624 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1625 insert_data
, VALUE_SIZE_BUG5
,
1626 (time_t)0, (uint32_t)0);
1627 assert(rc
== MEMCACHED_SUCCESS
);
1630 for (x
= 0; x
< 10; x
++)
1632 value
= memcached_get(memc
, keys
[0], key_length
[0],
1633 &value_length
, &flags
, &rc
);
1637 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1639 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1640 &value_length
, &flags
, &rc
)))
1651 static test_return
user_supplied_bug6(memcached_st
*memc
)
1653 memcached_return rc
;
1654 char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1655 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1656 char return_key
[MEMCACHED_MAX_KEY
];
1657 size_t return_key_length
;
1659 size_t value_length
;
1663 char insert_data
[VALUE_SIZE_BUG5
];
1665 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1666 insert_data
[x
]= rand();
1668 memcached_flush(memc
, 0);
1669 value
= memcached_get(memc
, keys
[0], key_length
[0],
1670 &value_length
, &flags
, &rc
);
1671 assert(value
== NULL
);
1672 assert(rc
== MEMCACHED_NOTFOUND
);
1673 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1674 assert(rc
== MEMCACHED_SUCCESS
);
1677 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1678 &value_length
, &flags
, &rc
)))
1681 assert(rc
== MEMCACHED_END
);
1683 for (x
= 0; x
< 4; x
++)
1685 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1686 insert_data
, VALUE_SIZE_BUG5
,
1687 (time_t)0, (uint32_t)0);
1688 assert(rc
== MEMCACHED_SUCCESS
);
1691 for (x
= 0; x
< 2; x
++)
1693 value
= memcached_get(memc
, keys
[0], key_length
[0],
1694 &value_length
, &flags
, &rc
);
1698 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1699 assert(rc
== MEMCACHED_SUCCESS
);
1701 /* We test for purge of partial complete fetches */
1702 for (count
= 3; count
; count
--)
1704 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1705 &value_length
, &flags
, &rc
);
1706 assert(rc
== MEMCACHED_SUCCESS
);
1707 assert(!(memcmp(value
, insert_data
, value_length
)));
1708 assert(value_length
);
1716 static test_return
user_supplied_bug8(memcached_st
*memc
__attribute__((unused
)))
1718 memcached_return rc
;
1720 memcached_st
*clone
;
1722 memcached_server_st
*servers
;
1723 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";
1725 servers
= memcached_servers_parse(server_list
);
1728 mine
= memcached_create(NULL
);
1729 rc
= memcached_server_push(mine
, servers
);
1730 assert(rc
== MEMCACHED_SUCCESS
);
1731 memcached_server_list_free(servers
);
1734 clone
= memcached_clone(NULL
, mine
);
1736 memcached_quit(mine
);
1737 memcached_quit(clone
);
1740 memcached_free(mine
);
1741 memcached_free(clone
);
1746 /* Test flag store/retrieve */
1747 static test_return
user_supplied_bug7(memcached_st
*memc
)
1749 memcached_return rc
;
1750 char *keys
= "036790384900";
1751 size_t key_length
= strlen("036790384900");
1752 char return_key
[MEMCACHED_MAX_KEY
];
1753 size_t return_key_length
;
1755 size_t value_length
;
1758 char insert_data
[VALUE_SIZE_BUG5
];
1760 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1761 insert_data
[x
]= rand();
1763 memcached_flush(memc
, 0);
1766 rc
= memcached_set(memc
, keys
, key_length
,
1767 insert_data
, VALUE_SIZE_BUG5
,
1769 assert(rc
== MEMCACHED_SUCCESS
);
1772 value
= memcached_get(memc
, keys
, key_length
,
1773 &value_length
, &flags
, &rc
);
1774 assert(flags
== 245);
1778 rc
= memcached_mget(memc
, &keys
, &key_length
, 1);
1781 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1782 &value_length
, &flags
, &rc
);
1783 assert(flags
== 245);
1791 static test_return
user_supplied_bug9(memcached_st
*memc
)
1793 memcached_return rc
;
1794 char *keys
[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
1795 size_t key_length
[3];
1800 char return_key
[MEMCACHED_MAX_KEY
];
1801 size_t return_key_length
;
1803 size_t return_value_length
;
1806 key_length
[0]= strlen("UDATA:edevil@sapo.pt");
1807 key_length
[1]= strlen("fudge&*@#");
1808 key_length
[2]= strlen("for^#@&$not");
1811 for (x
= 0; x
< 3; x
++)
1813 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1814 keys
[x
], key_length
[x
],
1815 (time_t)50, (uint32_t)9);
1816 assert(rc
== MEMCACHED_SUCCESS
);
1819 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1820 assert(rc
== MEMCACHED_SUCCESS
);
1822 /* We need to empty the server before continueing test */
1823 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1824 &return_value_length
, &flags
, &rc
)) != NULL
)
1826 assert(return_value
);
1835 /* We are testing with aggressive timeout to get failures */
1836 static test_return
user_supplied_bug10(memcached_st
*memc
)
1840 size_t value_length
= 512;
1843 memcached_return rc
;
1844 unsigned int set
= 1;
1845 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
1848 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1849 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1851 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
1853 value
= (char*)malloc(value_length
* sizeof(char));
1855 for (x
= 0; x
< value_length
; x
++)
1856 value
[x
]= (char) (x
% 127);
1858 for (x
= 1; x
<= 100000; ++x
)
1860 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
1862 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_WRITE_FAILURE
|| rc
== MEMCACHED_BUFFERED
);
1864 if (rc
== MEMCACHED_WRITE_FAILURE
)
1869 memcached_free(mclone
);
1875 We are looking failures in the async protocol
1877 static test_return
user_supplied_bug11(memcached_st
*memc
)
1881 size_t value_length
= 512;
1884 memcached_return rc
;
1885 unsigned int set
= 1;
1887 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
1889 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1890 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1892 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
1894 timeout
= (int32_t)memcached_behavior_get(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
1896 assert(timeout
== -1);
1898 value
= (char*)malloc(value_length
* sizeof(char));
1900 for (x
= 0; x
< value_length
; x
++)
1901 value
[x
]= (char) (x
% 127);
1903 for (x
= 1; x
<= 100000; ++x
)
1905 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
1909 memcached_free(mclone
);
1915 Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
1917 static test_return
user_supplied_bug12(memcached_st
*memc
)
1919 memcached_return rc
;
1921 size_t value_length
;
1923 uint64_t number_value
;
1925 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
1926 &value_length
, &flags
, &rc
);
1927 assert(value
== NULL
);
1928 assert(rc
== MEMCACHED_NOTFOUND
);
1930 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
1933 assert(value
== NULL
);
1934 assert(rc
== MEMCACHED_NOTFOUND
);
1936 rc
= memcached_set(memc
, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
1938 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
1939 &value_length
, &flags
, &rc
);
1941 assert(rc
== MEMCACHED_SUCCESS
);
1944 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
1946 assert(number_value
== 2);
1947 assert(rc
== MEMCACHED_SUCCESS
);
1953 Bug found where command total one more than MEMCACHED_MAX_BUFFER
1954 set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
1956 static test_return
user_supplied_bug13(memcached_st
*memc
)
1958 char key
[] = "key34567890";
1960 memcached_return rc
;
1961 size_t overflowSize
;
1963 char commandFirst
[]= "set key34567890 0 0 ";
1964 char commandLast
[] = " \r\n"; /* first line of command sent to server */
1965 size_t commandLength
;
1968 commandLength
= strlen(commandFirst
) + strlen(commandLast
) + 4; /* 4 is number of characters in size, probably 8196 */
1970 overflowSize
= MEMCACHED_MAX_BUFFER
- commandLength
;
1972 for (testSize
= overflowSize
- 1; testSize
< overflowSize
+ 1; testSize
++)
1974 overflow
= malloc(testSize
);
1975 assert(overflow
!= NULL
);
1977 memset(overflow
, 'x', testSize
);
1978 rc
= memcached_set(memc
, key
, strlen(key
),
1979 overflow
, testSize
, 0, 0);
1980 assert(rc
== MEMCACHED_SUCCESS
);
1989 Test values of many different sizes
1990 Bug found where command total one more than MEMCACHED_MAX_BUFFER
1991 set key34567890 0 0 8169 \r\n
1992 is sent followed by buffer of size 8169, followed by 8169
1994 static test_return
user_supplied_bug14(memcached_st
*memc
)
1997 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1998 memcached_return rc
;
2001 size_t value_length
= 18000;
2003 size_t string_length
;
2006 size_t current_length
;
2008 value
= (char*)malloc(value_length
);
2011 for (x
= 0; x
< value_length
; x
++)
2012 value
[x
] = (char) (x
% 127);
2014 for (current_length
= 0; current_length
< value_length
; current_length
++)
2016 rc
= memcached_set(memc
, key
, strlen(key
),
2017 value
, current_length
,
2018 (time_t)0, (uint32_t)0);
2019 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
2021 string
= memcached_get(memc
, key
, strlen(key
),
2022 &string_length
, &flags
, &rc
);
2024 assert(rc
== MEMCACHED_SUCCESS
);
2025 assert(string_length
== current_length
);
2026 assert(!memcmp(string
, value
, string_length
));
2037 Look for zero length value problems
2039 static test_return
user_supplied_bug15(memcached_st
*memc
)
2042 memcached_return rc
;
2048 for (x
= 0; x
< 2; x
++)
2050 rc
= memcached_set(memc
, key
, strlen(key
),
2052 (time_t)0, (uint32_t)0);
2054 assert(rc
== MEMCACHED_SUCCESS
);
2056 value
= memcached_get(memc
, key
, strlen(key
),
2057 &length
, &flags
, &rc
);
2059 assert(rc
== MEMCACHED_SUCCESS
);
2060 assert(value
== NULL
);
2061 assert(length
== 0);
2064 value
= memcached_get(memc
, key
, strlen(key
),
2065 &length
, &flags
, &rc
);
2067 assert(rc
== MEMCACHED_SUCCESS
);
2068 assert(value
== NULL
);
2069 assert(length
== 0);
2076 /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
2077 static test_return
user_supplied_bug16(memcached_st
*memc
)
2079 memcached_return rc
;
2085 rc
= memcached_set(memc
, key
, strlen(key
),
2087 (time_t)0, UINT32_MAX
);
2089 assert(rc
== MEMCACHED_SUCCESS
);
2091 value
= memcached_get(memc
, key
, strlen(key
),
2092 &length
, &flags
, &rc
);
2094 assert(rc
== MEMCACHED_SUCCESS
);
2095 assert(value
== NULL
);
2096 assert(length
== 0);
2097 assert(flags
== UINT32_MAX
);
2102 /* Check the validity of chinese key*/
2103 static test_return
user_supplied_bug17(memcached_st
*memc
)
2105 memcached_return rc
;
2107 char *value
="我们在炎热抑郁的夏天无法停止豆瓣";
2112 rc
= memcached_set(memc
, key
, strlen(key
),
2113 value
, strlen(value
),
2116 assert(rc
== MEMCACHED_SUCCESS
);
2118 value2
= memcached_get(memc
, key
, strlen(key
),
2119 &length
, &flags
, &rc
);
2121 assert(length
==strlen(value
));
2122 assert(rc
== MEMCACHED_SUCCESS
);
2123 assert(memcmp(value
, value2
, length
)==0);
2133 test_return
user_supplied_bug19(memcached_st
*memc
)
2136 memcached_server_st
*s
;
2137 memcached_return res
;
2141 m
= memcached_create(NULL
);
2142 memcached_server_add_with_weight(m
, "localhost", 11311, 100);
2143 memcached_server_add_with_weight(m
, "localhost", 11312, 100);
2145 s
= memcached_server_by_key(m
, "a", 1, &res
);
2146 memcached_server_free(s
);
2153 #include "ketama_test_cases.h"
2154 test_return
user_supplied_bug18(memcached_st
*trash
)
2156 memcached_return rc
;
2159 memcached_server_st
*server_pool
;
2164 memc
= memcached_create(NULL
);
2167 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2168 assert(rc
== MEMCACHED_SUCCESS
);
2170 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2173 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2174 assert(rc
== MEMCACHED_SUCCESS
);
2176 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2177 assert(value
== MEMCACHED_HASH_MD5
);
2179 server_pool
= memcached_servers_parse("10.0.1.1:11211 600,10.0.1.2:11211 300,10.0.1.3:11211 200,10.0.1.4:11211 350,10.0.1.5:11211 1000,10.0.1.6:11211 800,10.0.1.7:11211 950,10.0.1.8:11211 100");
2180 memcached_server_push(memc
, server_pool
);
2182 /* verify that the server list was parsed okay. */
2183 assert(memc
->number_of_hosts
== 8);
2184 assert(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
2185 assert(server_pool
[0].port
== 11211);
2186 assert(server_pool
[0].weight
== 600);
2187 assert(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
2188 assert(server_pool
[2].port
== 11211);
2189 assert(server_pool
[2].weight
== 200);
2190 assert(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
2191 assert(server_pool
[7].port
== 11211);
2192 assert(server_pool
[7].weight
== 100);
2194 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
2195 * us test the boundary wraparound.
2197 assert(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
2199 /* verify the standard ketama set. */
2200 for (i
= 0; i
< 99; i
++)
2202 uint32_t server_idx
= memcached_generate_hash(memc
, test_cases
[i
].key
, strlen(test_cases
[i
].key
));
2203 char *hostname
= memc
->hosts
[server_idx
].hostname
;
2204 assert(strcmp(hostname
, test_cases
[i
].server
) == 0);
2207 memcached_server_list_free(server_pool
);
2208 memcached_free(memc
);
2213 static test_return
result_static(memcached_st
*memc
)
2215 memcached_result_st result
;
2216 memcached_result_st
*result_ptr
;
2218 result_ptr
= memcached_result_create(memc
, &result
);
2219 assert(result
.is_allocated
== false);
2221 memcached_result_free(&result
);
2226 static test_return
result_alloc(memcached_st
*memc
)
2228 memcached_result_st
*result
;
2230 result
= memcached_result_create(memc
, NULL
);
2232 memcached_result_free(result
);
2237 static test_return
string_static_null(memcached_st
*memc
)
2239 memcached_string_st string
;
2240 memcached_string_st
*string_ptr
;
2242 string_ptr
= memcached_string_create(memc
, &string
, 0);
2243 assert(string
.is_allocated
== false);
2245 memcached_string_free(&string
);
2250 static test_return
string_alloc_null(memcached_st
*memc
)
2252 memcached_string_st
*string
;
2254 string
= memcached_string_create(memc
, NULL
, 0);
2256 memcached_string_free(string
);
2261 static test_return
string_alloc_with_size(memcached_st
*memc
)
2263 memcached_string_st
*string
;
2265 string
= memcached_string_create(memc
, NULL
, 1024);
2267 memcached_string_free(string
);
2272 static test_return
string_alloc_with_size_toobig(memcached_st
*memc
)
2274 memcached_string_st
*string
;
2276 string
= memcached_string_create(memc
, NULL
, INT64_MAX
);
2277 assert(string
== NULL
);
2282 static test_return
string_alloc_append(memcached_st
*memc
)
2285 char buffer
[SMALL_STRING_LEN
];
2286 memcached_string_st
*string
;
2288 /* Ring the bell! */
2289 memset(buffer
, 6, SMALL_STRING_LEN
);
2291 string
= memcached_string_create(memc
, NULL
, 100);
2294 for (x
= 0; x
< 1024; x
++)
2296 memcached_return rc
;
2297 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
2298 assert(rc
== MEMCACHED_SUCCESS
);
2300 memcached_string_free(string
);
2305 static test_return
string_alloc_append_toobig(memcached_st
*memc
)
2307 memcached_return rc
;
2309 char buffer
[SMALL_STRING_LEN
];
2310 memcached_string_st
*string
;
2312 /* Ring the bell! */
2313 memset(buffer
, 6, SMALL_STRING_LEN
);
2315 string
= memcached_string_create(memc
, NULL
, 100);
2318 for (x
= 0; x
< 1024; x
++)
2320 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
2321 assert(rc
== MEMCACHED_SUCCESS
);
2323 rc
= memcached_string_append(string
, buffer
, INT64_MAX
);
2324 assert(rc
== MEMCACHED_MEMORY_ALLOCATION_FAILURE
);
2325 memcached_string_free(string
);
2330 static test_return
cleanup_pairs(memcached_st
*memc
__attribute__((unused
)))
2332 pairs_free(global_pairs
);
2337 static test_return
generate_pairs(memcached_st
*memc
__attribute__((unused
)))
2339 unsigned long long x
;
2340 global_pairs
= pairs_generate(GLOBAL_COUNT
, 400);
2341 global_count
= GLOBAL_COUNT
;
2343 for (x
= 0; x
< global_count
; x
++)
2345 global_keys
[x
]= global_pairs
[x
].key
;
2346 global_keys_length
[x
]= global_pairs
[x
].key_length
;
2352 static test_return
generate_large_pairs(memcached_st
*memc
__attribute__((unused
)))
2354 unsigned long long x
;
2355 global_pairs
= pairs_generate(GLOBAL2_COUNT
, MEMCACHED_MAX_BUFFER
+10);
2356 global_count
= GLOBAL2_COUNT
;
2358 for (x
= 0; x
< global_count
; x
++)
2360 global_keys
[x
]= global_pairs
[x
].key
;
2361 global_keys_length
[x
]= global_pairs
[x
].key_length
;
2367 static test_return
generate_data(memcached_st
*memc
)
2369 execute_set(memc
, global_pairs
, global_count
);
2374 static test_return
generate_data_with_stats(memcached_st
*memc
)
2376 memcached_stat_st
*stat_p
;
2377 memcached_return rc
;
2378 uint32_t host_index
= 0;
2379 execute_set(memc
, global_pairs
, global_count
);
2381 //TODO: hosts used size stats
2382 stat_p
= memcached_stat(memc
, NULL
, &rc
);
2385 for (host_index
= 0; host_index
< SERVERS_TO_CREATE
; host_index
++)
2387 printf("\nserver %u|%s|%u bytes: %llu\n", host_index
, (memc
->hosts
)[host_index
].hostname
, (memc
->hosts
)[host_index
].port
, (unsigned long long)(stat_p
+ host_index
)->bytes
);
2390 memcached_stat_free(NULL
, stat_p
);
2394 static test_return
generate_buffer_data(memcached_st
*memc
)
2399 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
2400 generate_data(memc
);
2405 static test_return
get_read_count(memcached_st
*memc
)
2408 memcached_return rc
;
2409 memcached_st
*clone
;
2411 clone
= memcached_clone(NULL
, memc
);
2414 memcached_server_add_with_weight(clone
, "localhost", 6666, 0);
2418 size_t return_value_length
;
2422 for (x
= count
= 0; x
< global_count
; x
++)
2424 return_value
= memcached_get(clone
, global_keys
[x
], global_keys_length
[x
],
2425 &return_value_length
, &flags
, &rc
);
2426 if (rc
== MEMCACHED_SUCCESS
)
2433 fprintf(stderr
, "\t%u -> %u", global_count
, count
);
2436 memcached_free(clone
);
2441 static test_return
get_read(memcached_st
*memc
)
2444 memcached_return rc
;
2448 size_t return_value_length
;
2451 for (x
= 0; x
< global_count
; x
++)
2453 return_value
= memcached_get(memc
, global_keys
[x
], global_keys_length
[x
],
2454 &return_value_length
, &flags
, &rc
);
2456 assert(return_value);
2457 assert(rc == MEMCACHED_SUCCESS);
2459 if (rc
== MEMCACHED_SUCCESS
&& return_value
)
2467 static test_return
mget_read(memcached_st
*memc
)
2469 memcached_return rc
;
2471 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2472 assert(rc
== MEMCACHED_SUCCESS
);
2473 /* Turn this into a help function */
2475 char return_key
[MEMCACHED_MAX_KEY
];
2476 size_t return_key_length
;
2478 size_t return_value_length
;
2481 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2482 &return_value_length
, &flags
, &rc
)))
2484 assert(return_value
);
2485 assert(rc
== MEMCACHED_SUCCESS
);
2493 static test_return
mget_read_result(memcached_st
*memc
)
2495 memcached_return rc
;
2497 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2498 assert(rc
== MEMCACHED_SUCCESS
);
2499 /* Turn this into a help function */
2501 memcached_result_st results_obj
;
2502 memcached_result_st
*results
;
2504 results
= memcached_result_create(memc
, &results_obj
);
2506 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
2509 assert(rc
== MEMCACHED_SUCCESS
);
2512 memcached_result_free(&results_obj
);
2518 static test_return
mget_read_function(memcached_st
*memc
)
2520 memcached_return rc
;
2521 unsigned int counter
;
2522 unsigned int (*callbacks
[1])(memcached_st
*, memcached_result_st
*, void *);
2524 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2525 assert(rc
== MEMCACHED_SUCCESS
);
2527 callbacks
[0]= &callback_counter
;
2529 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
2534 static test_return
delete_generate(memcached_st
*memc
)
2538 for (x
= 0; x
< global_count
; x
++)
2540 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
2546 static test_return
delete_buffer_generate(memcached_st
*memc
)
2552 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
2554 for (x
= 0; x
< global_count
; x
++)
2556 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
2562 static test_return
free_data(memcached_st
*memc
__attribute__((unused
)))
2564 pairs_free(global_pairs
);
2569 static test_return
add_host_test1(memcached_st
*memc
)
2572 memcached_return rc
;
2573 char servername
[]= "0.example.com";
2574 memcached_server_st
*servers
;
2576 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
2578 assert(1 == memcached_server_list_count(servers
));
2580 for (x
= 2; x
< 20; x
++)
2582 char buffer
[SMALL_STRING_LEN
];
2584 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
2585 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
2587 assert(rc
== MEMCACHED_SUCCESS
);
2588 assert(x
== memcached_server_list_count(servers
));
2591 rc
= memcached_server_push(memc
, servers
);
2592 assert(rc
== MEMCACHED_SUCCESS
);
2593 rc
= memcached_server_push(memc
, servers
);
2594 assert(rc
== MEMCACHED_SUCCESS
);
2596 memcached_server_list_free(servers
);
2601 static memcached_return
pre_nonblock(memcached_st
*memc
)
2603 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
2605 return MEMCACHED_SUCCESS
;
2608 static memcached_return
pre_murmur(memcached_st
*memc
)
2610 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
2612 return MEMCACHED_SUCCESS
;
2615 static memcached_return
pre_jenkins(memcached_st
*memc
)
2617 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_JENKINS
);
2619 return MEMCACHED_SUCCESS
;
2623 static memcached_return
pre_md5(memcached_st
*memc
)
2625 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MD5
);
2627 return MEMCACHED_SUCCESS
;
2630 static memcached_return
pre_crc(memcached_st
*memc
)
2632 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_CRC
);
2634 return MEMCACHED_SUCCESS
;
2637 static memcached_return
pre_hsieh(memcached_st
*memc
)
2639 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_HSIEH
);
2641 return MEMCACHED_SUCCESS
;
2644 static memcached_return
pre_hash_fnv1_64(memcached_st
*memc
)
2646 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_64
);
2648 return MEMCACHED_SUCCESS
;
2651 static memcached_return
pre_hash_fnv1a_64(memcached_st
*memc
)
2653 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_64
);
2655 return MEMCACHED_SUCCESS
;
2658 static memcached_return
pre_hash_fnv1_32(memcached_st
*memc
)
2660 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_32
);
2662 return MEMCACHED_SUCCESS
;
2665 static memcached_return
pre_hash_fnv1a_32(memcached_st
*memc
)
2667 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_32
);
2669 return MEMCACHED_SUCCESS
;
2672 static memcached_return
pre_behavior_ketama(memcached_st
*memc
)
2674 memcached_return rc
;
2677 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA
, 1);
2678 assert(rc
== MEMCACHED_SUCCESS
);
2680 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA
);
2683 return MEMCACHED_SUCCESS
;
2686 static memcached_return
pre_behavior_ketama_weighted(memcached_st
*memc
)
2688 memcached_return rc
;
2691 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2692 assert(rc
== MEMCACHED_SUCCESS
);
2694 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2697 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2698 assert(rc
== MEMCACHED_SUCCESS
);
2700 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2701 assert(value
== MEMCACHED_HASH_MD5
);
2702 return MEMCACHED_SUCCESS
;
2705 static memcached_return
pre_binary(memcached_st
*memc
)
2707 memcached_return rc
= MEMCACHED_FAILURE
;
2708 memcached_st
*clone
;
2710 clone
= memcached_clone(NULL
, memc
);
2712 // The memcached_version needs to be done on a clone, because the server
2713 // will not toggle protocol on an connection.
2714 memcached_version(clone
);
2716 if (clone
->hosts
[0].major_version
>= 1 && clone
->hosts
[0].minor_version
> 2)
2718 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
2719 assert(rc
== MEMCACHED_SUCCESS
);
2720 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
2723 memcached_free(clone
);
2727 static void my_free(memcached_st
*ptr
__attribute__((unused
)), void *mem
)
2732 static void *my_malloc(memcached_st
*ptr
__attribute__((unused
)), const size_t size
)
2734 return malloc(size
);
2737 static void *my_realloc(memcached_st
*ptr
__attribute__((unused
)), void *mem
, const size_t size
)
2739 return realloc(mem
, size
);
2742 static memcached_return
set_prefix(memcached_st
*memc
)
2744 memcached_return rc
;
2745 const char *key
= "mine";
2748 /* Make sure be default none exists */
2749 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2750 assert(rc
== MEMCACHED_FAILURE
);
2752 /* Test a clean set */
2753 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
2754 assert(rc
== MEMCACHED_SUCCESS
);
2756 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2757 assert(memcmp(value
, key
, 4) == 0);
2758 assert(rc
== MEMCACHED_SUCCESS
);
2760 /* Test that we can turn it off */
2761 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
2762 assert(rc
== MEMCACHED_SUCCESS
);
2764 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2765 assert(rc
== MEMCACHED_FAILURE
);
2767 /* Now setup for main test */
2768 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
2769 assert(rc
== MEMCACHED_SUCCESS
);
2771 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2772 assert(rc
== MEMCACHED_SUCCESS
);
2773 assert(memcmp(value
, key
, 4) == 0);
2775 /* Set to Zero, and then Set to something too large */
2778 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
2779 assert(rc
== MEMCACHED_SUCCESS
);
2781 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2782 assert(rc
== MEMCACHED_FAILURE
);
2783 assert(value
== NULL
);
2785 /* Test a long key for failure */
2786 /* TODO, extend test to determine based on setting, what result should be */
2787 long_key
= "Thisismorethentheallottednumberofcharacters";
2788 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
2789 //assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
2790 assert(rc
== MEMCACHED_SUCCESS
);
2792 /* Now test a key with spaces (which will fail from long key, since bad key is not set) */
2793 long_key
= "This is more then the allotted number of characters";
2794 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
2795 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
2797 /* Test for a bad prefix, but with a short key */
2798 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, 1);
2799 assert(rc
== MEMCACHED_SUCCESS
);
2801 long_key
= "dog cat";
2802 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
2803 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
2806 return MEMCACHED_SUCCESS
;
2809 static memcached_return
set_memory_alloc(memcached_st
*memc
)
2812 memcached_malloc_function test_ptr
;
2813 memcached_return rc
;
2815 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &my_malloc
);
2816 assert(rc
== MEMCACHED_SUCCESS
);
2817 test_ptr
= (memcached_malloc_function
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
2818 assert(rc
== MEMCACHED_SUCCESS
);
2819 assert(test_ptr
== my_malloc
);
2823 memcached_realloc_function test_ptr
;
2824 memcached_return rc
;
2826 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &my_realloc
);
2827 assert(rc
== MEMCACHED_SUCCESS
);
2828 test_ptr
= (memcached_realloc_function
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
2829 assert(rc
== MEMCACHED_SUCCESS
);
2830 assert(test_ptr
== my_realloc
);
2834 memcached_free_function test_ptr
;
2835 memcached_return rc
;
2837 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, my_free
);
2838 assert(rc
== MEMCACHED_SUCCESS
);
2839 test_ptr
= (memcached_free_function
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
2840 assert(rc
== MEMCACHED_SUCCESS
);
2841 assert(test_ptr
== my_free
);
2844 return MEMCACHED_SUCCESS
;
2847 static memcached_return
enable_consistent(memcached_st
*memc
)
2849 memcached_server_distribution value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
2850 memcached_hash hash
;
2851 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
2854 value
= (memcached_server_distribution
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
2855 assert(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
2857 hash
= (memcached_hash
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
2858 assert(hash
== MEMCACHED_HASH_HSIEH
);
2861 return MEMCACHED_SUCCESS
;
2864 static memcached_return
enable_cas(memcached_st
*memc
)
2866 unsigned int set
= 1;
2868 memcached_version(memc
);
2870 if ((memc
->hosts
[0].major_version
>= 1 && (memc
->hosts
[0].minor_version
== 2 && memc
->hosts
[0].micro_version
>= 4))
2871 || memc
->hosts
[0].minor_version
> 2)
2873 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
2875 return MEMCACHED_SUCCESS
;
2878 return MEMCACHED_FAILURE
;
2881 static memcached_return
check_for_1_2_3(memcached_st
*memc
)
2883 memcached_version(memc
);
2885 if ((memc
->hosts
[0].major_version
>= 1 && (memc
->hosts
[0].minor_version
== 2 && memc
->hosts
[0].micro_version
>= 4))
2886 || memc
->hosts
[0].minor_version
> 2)
2887 return MEMCACHED_SUCCESS
;
2889 return MEMCACHED_FAILURE
;
2892 static memcached_return
pre_unix_socket(memcached_st
*memc
)
2894 memcached_return rc
;
2897 memcached_server_list_free(memc
->hosts
);
2899 memc
->number_of_hosts
= 0;
2901 if (stat("/tmp/memcached.socket", &buf
))
2902 return MEMCACHED_FAILURE
;
2904 rc
= memcached_server_add_unix_socket_with_weight(memc
, "/tmp/memcached.socket", 0);
2909 static memcached_return
pre_nodelay(memcached_st
*memc
)
2911 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
2912 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
2914 return MEMCACHED_SUCCESS
;
2917 static memcached_return
pre_settimer(memcached_st
*memc
)
2919 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
2920 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
2922 return MEMCACHED_SUCCESS
;
2925 static memcached_return
poll_timeout(memcached_st
*memc
)
2931 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
2933 timeout
= (int32_t)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
2935 assert(timeout
== 100);
2937 return MEMCACHED_SUCCESS
;
2941 /* Clean the server before beginning testing */
2943 {"flush", 0, flush_test
},
2944 {"init", 0, init_test
},
2945 {"allocation", 0, allocation_test
},
2946 {"server_list_null_test", 0, server_list_null_test
},
2947 {"server_unsort", 0, server_unsort_test
},
2948 {"server_sort", 0, server_sort_test
},
2949 {"server_sort2", 0, server_sort2_test
},
2950 {"clone_test", 0, clone_test
},
2951 {"error", 0, error_test
},
2952 {"set", 0, set_test
},
2953 {"set2", 0, set_test2
},
2954 {"set3", 0, set_test3
},
2955 {"add", 1, add_test
},
2956 {"replace", 1, replace_test
},
2957 {"delete", 1, delete_test
},
2958 {"get", 1, get_test
},
2959 {"get2", 0, get_test2
},
2960 {"get3", 0, get_test3
},
2961 {"get4", 0, get_test4
},
2962 {"stats_servername", 0, stats_servername_test
},
2963 {"increment", 0, increment_test
},
2964 {"decrement", 0, decrement_test
},
2965 {"quit", 0, quit_test
},
2966 {"mget", 1, mget_test
},
2967 {"mget_result", 1, mget_result_test
},
2968 {"mget_result_alloc", 1, mget_result_alloc_test
},
2969 {"mget_result_function", 1, mget_result_function
},
2970 {"get_stats", 0, get_stats
},
2971 {"add_host_test", 0, add_host_test
},
2972 {"add_host_test_1", 0, add_host_test1
},
2973 {"get_stats_keys", 0, get_stats_keys
},
2974 {"behavior_test", 0, get_stats_keys
},
2975 {"callback_test", 0, get_stats_keys
},
2976 {"version_string_test", 0, version_string_test
},
2977 {"bad_key", 1, bad_key_test
},
2978 {"memcached_server_cursor", 1, memcached_server_cursor_test
},
2979 {"read_through", 1, read_through
},
2980 {"delete_through", 1, delete_through
},
2984 test_st async_tests
[] ={
2985 {"add", 1, add_wrapper
},
2989 test_st string_tests
[] ={
2990 {"string static with null", 0, string_static_null
},
2991 {"string alloc with null", 0, string_alloc_null
},
2992 {"string alloc with 1K", 0, string_alloc_with_size
},
2993 {"string alloc with malloc failure", 0, string_alloc_with_size_toobig
},
2994 {"string append", 0, string_alloc_append
},
2995 {"string append failure (too big)", 0, string_alloc_append_toobig
},
2999 test_st result_tests
[] ={
3000 {"result static", 0, result_static
},
3001 {"result alloc", 0, result_alloc
},
3005 test_st version_1_2_3
[] ={
3006 {"append", 0, append_test
},
3007 {"prepend", 0, prepend_test
},
3008 {"cas", 0, cas_test
},
3009 {"cas2", 0, cas2_test
},
3010 {"append_binary", 0, append_binary_test
},
3014 test_st user_tests
[] ={
3015 {"user_supplied_bug1", 0, user_supplied_bug1
},
3016 {"user_supplied_bug2", 0, user_supplied_bug2
},
3017 {"user_supplied_bug3", 0, user_supplied_bug3
},
3018 {"user_supplied_bug4", 0, user_supplied_bug4
},
3019 {"user_supplied_bug5", 1, user_supplied_bug5
},
3020 {"user_supplied_bug6", 1, user_supplied_bug6
},
3021 {"user_supplied_bug7", 1, user_supplied_bug7
},
3022 {"user_supplied_bug8", 1, user_supplied_bug8
},
3023 {"user_supplied_bug9", 1, user_supplied_bug9
},
3024 {"user_supplied_bug10", 1, user_supplied_bug10
},
3025 // {"user_supplied_bug11", 1, user_supplied_bug11 },
3026 {"user_supplied_bug12", 1, user_supplied_bug12
},
3027 {"user_supplied_bug13", 1, user_supplied_bug13
},
3028 {"user_supplied_bug14", 1, user_supplied_bug14
},
3029 {"user_supplied_bug15", 1, user_supplied_bug15
},
3030 {"user_supplied_bug16", 1, user_supplied_bug16
},
3033 ** It seems to be something weird with the character sets..
3034 ** value_fetch is unable to parse the value line (iscntrl "fails"), so I
3035 ** guess I need to find out how this is supposed to work.. Perhaps I need
3036 ** to run the test in a specific locale (I tried zh_CN.UTF-8 without success,
3037 ** so just disable the code for now...).
3039 {"user_supplied_bug17", 1, user_supplied_bug17
},
3041 {"user_supplied_bug18", 1, user_supplied_bug18
},
3042 {"user_supplied_bug19", 1, user_supplied_bug19
},
3046 test_st generate_tests
[] ={
3047 {"generate_pairs", 1, generate_pairs
},
3048 {"generate_data", 1, generate_data
},
3049 {"get_read", 0, get_read
},
3050 {"delete_generate", 0, delete_generate
},
3051 {"generate_buffer_data", 1, generate_buffer_data
},
3052 {"delete_buffer", 0, delete_buffer_generate
},
3053 {"generate_data", 1, generate_data
},
3054 {"mget_read", 0, mget_read
},
3055 {"mget_read_result", 0, mget_read_result
},
3056 {"mget_read_function", 0, mget_read_function
},
3057 {"cleanup", 1, cleanup_pairs
},
3058 {"generate_large_pairs", 1, generate_large_pairs
},
3059 {"generate_data", 1, generate_data
},
3060 {"generate_buffer_data", 1, generate_buffer_data
},
3061 {"cleanup", 1, cleanup_pairs
},
3065 test_st consistent_tests
[] ={
3066 {"generate_pairs", 1, generate_pairs
},
3067 {"generate_data", 1, generate_data
},
3068 {"get_read", 0, get_read_count
},
3069 {"cleanup", 1, cleanup_pairs
},
3073 test_st consistent_weighted_tests
[] ={
3074 {"generate_pairs", 1, generate_pairs
},
3075 {"generate_data", 1, generate_data_with_stats
},
3076 {"get_read", 0, get_read_count
},
3077 {"cleanup", 1, cleanup_pairs
},
3081 collection_st collection
[] ={
3082 {"block", 0, 0, tests
},
3083 {"binary", pre_binary
, 0, tests
},
3084 {"nonblock", pre_nonblock
, 0, tests
},
3085 {"nodelay", pre_nodelay
, 0, tests
},
3086 {"settimer", pre_settimer
, 0, tests
},
3087 {"md5", pre_md5
, 0, tests
},
3088 {"crc", pre_crc
, 0, tests
},
3089 {"hsieh", pre_hsieh
, 0, tests
},
3090 {"jenkins", pre_jenkins
, 0, tests
},
3091 {"fnv1_64", pre_hash_fnv1_64
, 0, tests
},
3092 {"fnv1a_64", pre_hash_fnv1a_64
, 0, tests
},
3093 {"fnv1_32", pre_hash_fnv1_32
, 0, tests
},
3094 {"fnv1a_32", pre_hash_fnv1a_32
, 0, tests
},
3095 {"ketama", pre_behavior_ketama
, 0, tests
},
3096 {"unix_socket", pre_unix_socket
, 0, tests
},
3097 {"unix_socket_nodelay", pre_nodelay
, 0, tests
},
3098 {"poll_timeout", poll_timeout
, 0, tests
},
3099 {"gets", enable_cas
, 0, tests
},
3100 {"consistent", enable_consistent
, 0, tests
},
3101 {"memory_allocators", set_memory_alloc
, 0, tests
},
3102 {"prefix", set_prefix
, 0, tests
},
3103 {"version_1_2_3", check_for_1_2_3
, 0, version_1_2_3
},
3104 {"string", 0, 0, string_tests
},
3105 {"result", 0, 0, result_tests
},
3106 {"async", pre_nonblock
, 0, async_tests
},
3107 {"user", 0, 0, user_tests
},
3108 {"generate", 0, 0, generate_tests
},
3109 {"generate_hsieh", pre_hsieh
, 0, generate_tests
},
3110 {"generate_ketama", pre_behavior_ketama
, 0, generate_tests
},
3111 {"generate_hsieh_consistent", enable_consistent
, 0, generate_tests
},
3112 {"generate_md5", pre_md5
, 0, generate_tests
},
3113 {"generate_murmur", pre_murmur
, 0, generate_tests
},
3114 {"generate_jenkins", pre_jenkins
, 0, generate_tests
},
3115 {"generate_nonblock", pre_nonblock
, 0, generate_tests
},
3116 {"consistent_not", 0, 0, consistent_tests
},
3117 {"consistent_ketama", pre_behavior_ketama
, 0, consistent_tests
},
3118 {"consistent_ketama_weighted", pre_behavior_ketama_weighted
, 0, consistent_weighted_tests
},
3122 #define SERVERS_TO_CREATE 5
3124 /* Prototypes for functions we will pass to test framework */
3125 void *world_create(void);
3126 void world_destroy(void *p
);
3128 void *world_create(void)
3130 server_startup_st
*construct
;
3132 construct
= (server_startup_st
*)malloc(sizeof(server_startup_st
));
3133 memset(construct
, 0, sizeof(server_startup_st
));
3134 construct
->count
= SERVERS_TO_CREATE
;
3136 server_startup(construct
);
3142 void world_destroy(void *p
)
3144 server_startup_st
*construct
= (server_startup_st
*)p
;
3145 memcached_server_st
*servers
= (memcached_server_st
*)construct
->servers
;
3146 memcached_server_list_free(servers
);
3148 server_shutdown(construct
);
3152 void get_world(world_st
*world
)
3154 world
->collections
= collection
;
3155 world
->create
= world_create
;
3156 world
->destroy
= world_destroy
;