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
)
398 const char *key
= "fun";
399 size_t key_length
= strlen(key
);
400 const char *value
= "we the people";
401 size_t value_length
= strlen(value
);
402 const char *value2
= "change the value";
403 size_t value2_length
= strlen(value2
);
405 memcached_result_st results_obj
;
406 memcached_result_st
*results
;
409 rc
= memcached_flush(memc
, 0);
410 assert(rc
== MEMCACHED_SUCCESS
);
412 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
414 rc
= memcached_set(memc
, key
, strlen(key
),
415 value
, strlen(value
),
416 (time_t)0, (uint32_t)0);
417 assert(rc
== MEMCACHED_SUCCESS
);
419 rc
= memcached_mget(memc
, &key
, &key_length
, 1);
421 results
= memcached_result_create(memc
, &results_obj
);
423 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
425 assert(rc
== MEMCACHED_SUCCESS
);
426 WATCHPOINT_ASSERT(memcached_result_cas(results
));
427 assert(!memcmp(value
, memcached_result_value(results
), value_length
));
428 assert(strlen(memcached_result_value(results
)) == value_length
);
429 assert(rc
== MEMCACHED_SUCCESS
);
430 uint64_t cas
= memcached_result_cas(results
);
433 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
434 assert(rc
== MEMCACHED_END
);
435 assert(results
== NULL
);
438 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
439 assert(rc
== MEMCACHED_SUCCESS
);
442 * The item will have a new cas value, so try to set it again with the old
443 * value. This should fail!
445 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
446 assert(rc
== MEMCACHED_DATA_EXISTS
);
448 memcached_result_free(&results_obj
);
453 static test_return
prepend_test(memcached_st
*memc
)
457 char *value
= "people";
461 rc
= memcached_flush(memc
, 0);
462 assert(rc
== MEMCACHED_SUCCESS
);
464 rc
= memcached_set(memc
, key
, strlen(key
),
465 value
, strlen(value
),
466 (time_t)0, (uint32_t)0);
467 assert(rc
== MEMCACHED_SUCCESS
);
469 rc
= memcached_prepend(memc
, key
, strlen(key
),
470 "the ", strlen("the "),
471 (time_t)0, (uint32_t)0);
472 assert(rc
== MEMCACHED_SUCCESS
);
474 rc
= memcached_prepend(memc
, key
, strlen(key
),
475 "we ", strlen("we "),
476 (time_t)0, (uint32_t)0);
477 assert(rc
== MEMCACHED_SUCCESS
);
479 value
= memcached_get(memc
, key
, strlen(key
),
480 &value_length
, &flags
, &rc
);
481 assert(!memcmp(value
, "we the people", strlen("we the people")));
482 assert(strlen("we the people") == value_length
);
483 assert(rc
== MEMCACHED_SUCCESS
);
490 Set the value, then quit to make sure it is flushed.
491 Come back in and test that add fails.
493 static test_return
add_test(memcached_st
*memc
)
497 char *value
= "when we sanitize";
498 unsigned long long setting_value
;
500 setting_value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
502 rc
= memcached_set(memc
, key
, strlen(key
),
503 value
, strlen(value
),
504 (time_t)0, (uint32_t)0);
505 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
506 memcached_quit(memc
);
507 rc
= memcached_add(memc
, key
, strlen(key
),
508 value
, strlen(value
),
509 (time_t)0, (uint32_t)0);
511 /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */
513 assert(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_STORED
);
515 assert(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_DATA_EXISTS
);
520 static test_return
add_wrapper(memcached_st
*memc
)
524 for (x
= 0; x
< 10000; x
++)
530 static test_return
replace_test(memcached_st
*memc
)
534 char *value
= "when we sanitize";
535 char *original
= "first we insert some data";
537 rc
= memcached_set(memc
, key
, strlen(key
),
538 original
, strlen(original
),
539 (time_t)0, (uint32_t)0);
540 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
542 rc
= memcached_replace(memc
, key
, strlen(key
),
543 value
, strlen(value
),
544 (time_t)0, (uint32_t)0);
545 assert(rc
== MEMCACHED_SUCCESS
);
550 static test_return
delete_test(memcached_st
*memc
)
554 char *value
= "when we sanitize";
556 rc
= memcached_set(memc
, key
, strlen(key
),
557 value
, strlen(value
),
558 (time_t)0, (uint32_t)0);
559 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
561 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
562 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
567 static test_return
flush_test(memcached_st
*memc
)
571 rc
= memcached_flush(memc
, 0);
572 assert(rc
== MEMCACHED_SUCCESS
);
577 static memcached_return
server_function(memcached_st
*ptr
__attribute__((unused
)),
578 memcached_server_st
*server
__attribute__((unused
)),
579 void *context
__attribute__((unused
)))
583 return MEMCACHED_SUCCESS
;
586 static test_return
memcached_server_cursor_test(memcached_st
*memc
)
588 char *context
= "foo bad";
589 memcached_server_function callbacks
[1];
591 callbacks
[0]= server_function
;
592 memcached_server_cursor(memc
, callbacks
, context
, 1);
597 static test_return
bad_key_test(memcached_st
*memc
)
600 char *key
= "foo bad";
602 size_t string_length
;
607 clone
= memcached_clone(NULL
, memc
);
610 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
611 assert(rc
== MEMCACHED_SUCCESS
);
613 string
= memcached_get(clone
, key
, strlen(key
),
614 &string_length
, &flags
, &rc
);
615 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
616 assert(string_length
== 0);
620 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
621 assert(rc
== MEMCACHED_SUCCESS
);
622 string
= memcached_get(clone
, key
, strlen(key
),
623 &string_length
, &flags
, &rc
);
624 assert(rc
== MEMCACHED_NOTFOUND
);
625 assert(string_length
== 0);
628 /* Test multi key for bad keys */
630 char *keys
[] = { "GoodKey", "Bad Key", "NotMine" };
631 size_t key_lengths
[] = { 7, 7, 7 };
633 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
634 assert(rc
== MEMCACHED_SUCCESS
);
636 rc
= memcached_mget(clone
, keys
, key_lengths
, 3);
637 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
639 rc
= memcached_mget_by_key(clone
, "foo daddy", 9, keys
, key_lengths
, 1);
640 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
643 /* Make sure zero length keys are marked as bad */
645 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
646 assert(rc
== MEMCACHED_SUCCESS
);
647 string
= memcached_get(clone
, key
, 0,
648 &string_length
, &flags
, &rc
);
649 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
650 assert(string_length
== 0);
653 memcached_free(clone
);
658 #define READ_THROUGH_VALUE "set for me"
659 static memcached_return
read_through_trigger(memcached_st
*memc
__attribute__((unused
)),
660 char *key
__attribute__((unused
)),
661 size_t key_length
__attribute__((unused
)),
662 memcached_result_st
*result
)
665 return memcached_result_set_value(result
, READ_THROUGH_VALUE
, strlen(READ_THROUGH_VALUE
));
668 static test_return
read_through(memcached_st
*memc
)
673 size_t string_length
;
676 string
= memcached_get(memc
, key
, strlen(key
),
677 &string_length
, &flags
, &rc
);
679 assert(rc
== MEMCACHED_NOTFOUND
);
680 assert(string_length
== 0);
683 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_GET_FAILURE
, (void *)read_through_trigger
);
684 assert(rc
== MEMCACHED_SUCCESS
);
686 string
= memcached_get(memc
, key
, strlen(key
),
687 &string_length
, &flags
, &rc
);
689 assert(rc
== MEMCACHED_SUCCESS
);
690 assert(string_length
== strlen(READ_THROUGH_VALUE
));
691 assert(!strcmp(READ_THROUGH_VALUE
, string
));
694 string
= memcached_get(memc
, key
, strlen(key
),
695 &string_length
, &flags
, &rc
);
697 assert(rc
== MEMCACHED_SUCCESS
);
698 assert(string_length
== strlen(READ_THROUGH_VALUE
));
699 assert(!strcmp(READ_THROUGH_VALUE
, string
));
705 static memcached_return
delete_trigger(memcached_st
*ptr
__attribute__((unused
)),
707 size_t key_length
__attribute__((unused
)))
711 return MEMCACHED_SUCCESS
;
714 static test_return
delete_through(memcached_st
*memc
)
716 memcached_trigger_delete_key callback
;
719 callback
= delete_trigger
;
721 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_DELETE_TRIGGER
, callback
);
722 assert(rc
== MEMCACHED_SUCCESS
);
727 static test_return
get_test(memcached_st
*memc
)
732 size_t string_length
;
735 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
736 assert(rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_NOTFOUND
);
738 string
= memcached_get(memc
, key
, strlen(key
),
739 &string_length
, &flags
, &rc
);
741 assert(rc
== MEMCACHED_NOTFOUND
);
742 assert(string_length
== 0);
748 static test_return
get_test2(memcached_st
*memc
)
752 char *value
= "when we sanitize";
754 size_t string_length
;
757 rc
= memcached_set(memc
, key
, strlen(key
),
758 value
, strlen(value
),
759 (time_t)0, (uint32_t)0);
760 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
762 string
= memcached_get(memc
, key
, strlen(key
),
763 &string_length
, &flags
, &rc
);
766 assert(rc
== MEMCACHED_SUCCESS
);
767 assert(string_length
== strlen(value
));
768 assert(!memcmp(string
, value
, string_length
));
775 static test_return
set_test2(memcached_st
*memc
)
779 char *value
= "train in the brain";
780 size_t value_length
= strlen(value
);
783 for (x
= 0; x
< 10; x
++)
785 rc
= memcached_set(memc
, key
, strlen(key
),
787 (time_t)0, (uint32_t)0);
788 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
794 static test_return
set_test3(memcached_st
*memc
)
799 size_t value_length
= 8191;
802 value
= (char*)malloc(value_length
);
805 for (x
= 0; x
< value_length
; x
++)
806 value
[x
] = (char) (x
% 127);
808 for (x
= 0; x
< 1; x
++)
810 rc
= memcached_set(memc
, key
, strlen(key
),
812 (time_t)0, (uint32_t)0);
813 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
821 static test_return
get_test3(memcached_st
*memc
)
826 size_t value_length
= 8191;
828 size_t string_length
;
832 value
= (char*)malloc(value_length
);
835 for (x
= 0; x
< value_length
; x
++)
836 value
[x
] = (char) (x
% 127);
838 rc
= memcached_set(memc
, key
, strlen(key
),
840 (time_t)0, (uint32_t)0);
841 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
843 string
= memcached_get(memc
, key
, strlen(key
),
844 &string_length
, &flags
, &rc
);
846 assert(rc
== MEMCACHED_SUCCESS
);
848 assert(string_length
== value_length
);
849 assert(!memcmp(string
, value
, string_length
));
857 static test_return
get_test4(memcached_st
*memc
)
862 size_t value_length
= 8191;
864 size_t string_length
;
868 value
= (char*)malloc(value_length
);
871 for (x
= 0; x
< value_length
; x
++)
872 value
[x
] = (char) (x
% 127);
874 rc
= memcached_set(memc
, key
, strlen(key
),
876 (time_t)0, (uint32_t)0);
877 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
879 for (x
= 0; x
< 10; x
++)
881 string
= memcached_get(memc
, key
, strlen(key
),
882 &string_length
, &flags
, &rc
);
884 assert(rc
== MEMCACHED_SUCCESS
);
886 assert(string_length
== value_length
);
887 assert(!memcmp(string
, value
, string_length
));
896 /* Do not copy the style of this code, I just access hosts to testthis function */
897 static test_return
stats_servername_test(memcached_st
*memc
)
900 memcached_stat_st stat
;
901 rc
= memcached_stat_servername(&stat
, NULL
,
902 memc
->hosts
[0].hostname
,
903 memc
->hosts
[0].port
);
908 static test_return
increment_test(memcached_st
*memc
)
915 rc
= memcached_set(memc
, key
, strlen(key
),
916 value
, strlen(value
),
917 (time_t)0, (uint32_t)0);
918 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
920 rc
= memcached_increment(memc
, key
, strlen(key
),
922 assert(rc
== MEMCACHED_SUCCESS
);
923 assert(new_number
== 1);
925 rc
= memcached_increment(memc
, key
, strlen(key
),
927 assert(rc
== MEMCACHED_SUCCESS
);
928 assert(new_number
== 2);
933 static test_return
decrement_test(memcached_st
*memc
)
940 rc
= memcached_set(memc
, key
, strlen(key
),
941 value
, strlen(value
),
942 (time_t)0, (uint32_t)0);
943 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
945 rc
= memcached_decrement(memc
, key
, strlen(key
),
947 assert(rc
== MEMCACHED_SUCCESS
);
948 assert(new_number
== 2);
950 rc
= memcached_decrement(memc
, key
, strlen(key
),
952 assert(rc
== MEMCACHED_SUCCESS
);
953 assert(new_number
== 1);
958 static test_return
quit_test(memcached_st
*memc
)
962 char *value
= "sanford and sun";
964 rc
= memcached_set(memc
, key
, strlen(key
),
965 value
, strlen(value
),
966 (time_t)10, (uint32_t)3);
967 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
968 memcached_quit(memc
);
970 rc
= memcached_set(memc
, key
, strlen(key
),
971 value
, strlen(value
),
972 (time_t)50, (uint32_t)9);
973 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
978 static test_return
mget_result_test(memcached_st
*memc
)
981 char *keys
[]= {"fudge", "son", "food"};
982 size_t key_length
[]= {5, 3, 4};
985 memcached_result_st results_obj
;
986 memcached_result_st
*results
;
988 results
= memcached_result_create(memc
, &results_obj
);
990 assert(&results_obj
== results
);
992 /* We need to empty the server before continueing test */
993 rc
= memcached_flush(memc
, 0);
994 assert(rc
== MEMCACHED_SUCCESS
);
996 rc
= memcached_mget(memc
, keys
, key_length
, 3);
997 assert(rc
== MEMCACHED_SUCCESS
);
999 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1004 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1006 assert(rc
== MEMCACHED_END
);
1008 for (x
= 0; x
< 3; x
++)
1010 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1011 keys
[x
], key_length
[x
],
1012 (time_t)50, (uint32_t)9);
1013 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1016 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1017 assert(rc
== MEMCACHED_SUCCESS
);
1019 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1022 assert(&results_obj
== results
);
1023 assert(rc
== MEMCACHED_SUCCESS
);
1024 assert(memcached_result_key_length(results
) == memcached_result_length(results
));
1025 assert(!memcmp(memcached_result_key_value(results
),
1026 memcached_result_value(results
),
1027 memcached_result_length(results
)));
1030 memcached_result_free(&results_obj
);
1035 static test_return
mget_result_alloc_test(memcached_st
*memc
)
1037 memcached_return rc
;
1038 char *keys
[]= {"fudge", "son", "food"};
1039 size_t key_length
[]= {5, 3, 4};
1042 memcached_result_st
*results
;
1044 /* We need to empty the server before continueing test */
1045 rc
= memcached_flush(memc
, 0);
1046 assert(rc
== MEMCACHED_SUCCESS
);
1048 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1049 assert(rc
== MEMCACHED_SUCCESS
);
1051 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)) != NULL
)
1056 assert(rc
== MEMCACHED_END
);
1058 for (x
= 0; x
< 3; x
++)
1060 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1061 keys
[x
], key_length
[x
],
1062 (time_t)50, (uint32_t)9);
1063 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1066 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1067 assert(rc
== MEMCACHED_SUCCESS
);
1070 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1073 assert(rc
== MEMCACHED_SUCCESS
);
1074 assert(memcached_result_key_length(results
) == memcached_result_length(results
));
1075 assert(!memcmp(memcached_result_key_value(results
),
1076 memcached_result_value(results
),
1077 memcached_result_length(results
)));
1078 memcached_result_free(results
);
1085 /* Count the results */
1086 static memcached_return
callback_counter(memcached_st
*ptr
__attribute__((unused
)),
1087 memcached_result_st
*result
__attribute__((unused
)),
1090 unsigned int *counter
= (unsigned int *)context
;
1092 *counter
= *counter
+ 1;
1094 return MEMCACHED_SUCCESS
;
1097 static test_return
mget_result_function(memcached_st
*memc
)
1099 memcached_return rc
;
1100 char *keys
[]= {"fudge", "son", "food"};
1101 size_t key_length
[]= {5, 3, 4};
1103 unsigned int counter
;
1104 memcached_execute_function callbacks
[1];
1106 /* We need to empty the server before continueing test */
1107 rc
= memcached_flush(memc
, 0);
1108 for (x
= 0; x
< 3; x
++)
1110 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1111 keys
[x
], key_length
[x
],
1112 (time_t)50, (uint32_t)9);
1113 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1116 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1117 assert(rc
== MEMCACHED_SUCCESS
);
1119 callbacks
[0]= &callback_counter
;
1121 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
1123 assert(counter
== 3);
1128 static test_return
mget_test(memcached_st
*memc
)
1130 memcached_return rc
;
1131 char *keys
[]= {"fudge", "son", "food"};
1132 size_t key_length
[]= {5, 3, 4};
1136 char return_key
[MEMCACHED_MAX_KEY
];
1137 size_t return_key_length
;
1139 size_t return_value_length
;
1141 /* We need to empty the server before continueing test */
1142 rc
= memcached_flush(memc
, 0);
1143 assert(rc
== MEMCACHED_SUCCESS
);
1145 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1146 assert(rc
== MEMCACHED_SUCCESS
);
1148 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1149 &return_value_length
, &flags
, &rc
)) != NULL
)
1151 assert(return_value
);
1153 assert(!return_value
);
1154 assert(return_value_length
== 0);
1155 assert(rc
== MEMCACHED_END
);
1157 for (x
= 0; x
< 3; x
++)
1159 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1160 keys
[x
], key_length
[x
],
1161 (time_t)50, (uint32_t)9);
1162 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1165 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1166 assert(rc
== MEMCACHED_SUCCESS
);
1169 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1170 &return_value_length
, &flags
, &rc
)))
1172 assert(return_value
);
1173 assert(rc
== MEMCACHED_SUCCESS
);
1174 assert(return_key_length
== return_value_length
);
1175 assert(!memcmp(return_value
, return_key
, return_value_length
));
1183 static test_return
get_stats_keys(memcached_st
*memc
)
1187 memcached_stat_st stat
;
1188 memcached_return rc
;
1190 list
= memcached_stat_get_keys(memc
, &stat
, &rc
);
1191 assert(rc
== MEMCACHED_SUCCESS
);
1192 for (ptr
= list
; *ptr
; ptr
++)
1201 static test_return
version_string_test(memcached_st
*memc
__attribute__((unused
)))
1203 const char *version_string
;
1205 version_string
= memcached_lib_version();
1207 assert(!strcmp(version_string
, LIBMEMCACHED_VERSION_STRING
));
1212 static test_return
get_stats(memcached_st
*memc
)
1217 memcached_return rc
;
1218 memcached_stat_st
*stat
;
1220 stat
= memcached_stat(memc
, NULL
, &rc
);
1221 assert(rc
== MEMCACHED_SUCCESS
);
1223 assert(rc
== MEMCACHED_SUCCESS
);
1226 for (x
= 0; x
< memcached_server_count(memc
); x
++)
1228 list
= memcached_stat_get_keys(memc
, stat
+x
, &rc
);
1229 assert(rc
== MEMCACHED_SUCCESS
);
1230 for (ptr
= list
; *ptr
; ptr
++);
1235 memcached_stat_free(NULL
, stat
);
1240 static test_return
add_host_test(memcached_st
*memc
)
1243 memcached_server_st
*servers
;
1244 memcached_return rc
;
1245 char servername
[]= "0.example.com";
1247 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
1249 assert(1 == memcached_server_list_count(servers
));
1251 for (x
= 2; x
< 20; x
++)
1253 char buffer
[SMALL_STRING_LEN
];
1255 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
1256 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
1258 assert(rc
== MEMCACHED_SUCCESS
);
1259 assert(x
== memcached_server_list_count(servers
));
1262 rc
= memcached_server_push(memc
, servers
);
1263 assert(rc
== MEMCACHED_SUCCESS
);
1264 rc
= memcached_server_push(memc
, servers
);
1265 assert(rc
== MEMCACHED_SUCCESS
);
1267 memcached_server_list_free(servers
);
1272 static memcached_return
clone_test_callback(memcached_st
*parent
__attribute__((unused
)), memcached_st
*clone
__attribute__((unused
)))
1274 return MEMCACHED_SUCCESS
;
1277 static memcached_return
cleanup_test_callback(memcached_st
*ptr
__attribute__((unused
)))
1279 return MEMCACHED_SUCCESS
;
1282 static test_return
callback_test(memcached_st
*memc
)
1284 /* Test User Data */
1288 memcached_return rc
;
1290 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_USER_DATA
, &x
);
1291 assert(rc
== MEMCACHED_SUCCESS
);
1292 test_ptr
= (int *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_USER_DATA
, &rc
);
1293 assert(*test_ptr
== x
);
1296 /* Test Clone Callback */
1298 memcached_clone_func temp_function
;
1299 memcached_return rc
;
1301 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, clone_test_callback
);
1302 assert(rc
== MEMCACHED_SUCCESS
);
1303 temp_function
= (memcached_clone_func
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1304 assert(temp_function
== clone_test_callback
);
1307 /* Test Cleanup Callback */
1309 memcached_cleanup_func temp_function
;
1310 memcached_return rc
;
1312 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, cleanup_test_callback
);
1313 assert(rc
== MEMCACHED_SUCCESS
);
1314 temp_function
= (memcached_cleanup_func
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1315 assert(temp_function
== cleanup_test_callback
);
1321 /* We don't test the behavior itself, we test the switches */
1322 static test_return
behavior_test(memcached_st
*memc
)
1327 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1328 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1331 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1332 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1335 set
= MEMCACHED_HASH_MD5
;
1336 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1337 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1338 assert(value
== MEMCACHED_HASH_MD5
);
1342 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1343 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1346 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1347 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1350 set
= MEMCACHED_HASH_DEFAULT
;
1351 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1352 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1353 assert(value
== MEMCACHED_HASH_DEFAULT
);
1355 set
= MEMCACHED_HASH_CRC
;
1356 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1357 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1358 assert(value
== MEMCACHED_HASH_CRC
);
1360 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1363 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1369 /* Test case provided by Cal Haldenbrand */
1370 static test_return
user_supplied_bug1(memcached_st
*memc
)
1372 unsigned int setter
= 1;
1375 unsigned long long total
= 0;
1378 char randomstuff
[6 * 1024];
1379 memcached_return rc
;
1381 memset(randomstuff
, 0, 6 * 1024);
1383 /* We just keep looking at the same values over and over */
1386 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1387 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1391 for (x
= 0 ; total
< 20 * 1024576 ; x
++ )
1395 size
= (rand() % ( 5 * 1024 ) ) + 400;
1396 memset(randomstuff
, 0, 6 * 1024);
1397 assert(size
< 6 * 1024); /* Being safe here */
1399 for (j
= 0 ; j
< size
;j
++)
1400 randomstuff
[j
] = (char) (rand() % 26) + 97;
1403 sprintf(key
, "%d", x
);
1404 rc
= memcached_set(memc
, key
, strlen(key
),
1405 randomstuff
, strlen(randomstuff
), 10, 0);
1406 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1407 /* If we fail, lets try again */
1408 if (rc
!= MEMCACHED_SUCCESS
&& rc
!= MEMCACHED_BUFFERED
)
1409 rc
= memcached_set(memc
, key
, strlen(key
),
1410 randomstuff
, strlen(randomstuff
), 10, 0);
1411 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1417 /* Test case provided by Cal Haldenbrand */
1418 static test_return
user_supplied_bug2(memcached_st
*memc
)
1421 unsigned int setter
;
1423 unsigned long long total
;
1426 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1427 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1429 setter
= 20 * 1024576;
1430 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1431 setter
= 20 * 1024576;
1432 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1433 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1434 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1436 for (x
= 0, errors
= 0, total
= 0 ; total
< 20 * 1024576 ; x
++)
1439 for (x
= 0, errors
= 0, total
= 0 ; total
< 24576 ; x
++)
1441 memcached_return rc
= MEMCACHED_SUCCESS
;
1442 char buffer
[SMALL_STRING_LEN
];
1447 memset(buffer
, 0, SMALL_STRING_LEN
);
1449 snprintf(buffer
, SMALL_STRING_LEN
, "%u", x
);
1450 getval
= memcached_get(memc
, buffer
, strlen(buffer
),
1451 &val_len
, &flags
, &rc
);
1452 if (rc
!= MEMCACHED_SUCCESS
)
1454 if (rc
== MEMCACHED_NOTFOUND
)
1458 WATCHPOINT_ERROR(rc
);
1472 /* Do a large mget() over all the keys we think exist */
1473 #define KEY_COUNT 3000 // * 1024576
1474 static test_return
user_supplied_bug3(memcached_st
*memc
)
1476 memcached_return rc
;
1477 unsigned int setter
;
1480 size_t key_lengths
[KEY_COUNT
];
1483 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1484 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1486 setter
= 20 * 1024576;
1487 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1488 setter
= 20 * 1024576;
1489 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1490 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1491 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1494 keys
= (char **)malloc(sizeof(char *) * KEY_COUNT
);
1496 memset(keys
, 0, (sizeof(char *) * KEY_COUNT
));
1497 for (x
= 0; x
< KEY_COUNT
; x
++)
1501 snprintf(buffer
, 30, "%u", x
);
1502 keys
[x
]= strdup(buffer
);
1503 key_lengths
[x
]= strlen(keys
[x
]);
1506 rc
= memcached_mget(memc
, keys
, key_lengths
, KEY_COUNT
);
1507 assert(rc
== MEMCACHED_SUCCESS
);
1509 /* Turn this into a help function */
1511 char return_key
[MEMCACHED_MAX_KEY
];
1512 size_t return_key_length
;
1514 size_t return_value_length
;
1517 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1518 &return_value_length
, &flags
, &rc
)))
1520 assert(return_value
);
1521 assert(rc
== MEMCACHED_SUCCESS
);
1526 for (x
= 0; x
< KEY_COUNT
; x
++)
1533 /* Make sure we behave properly if server list has no values */
1534 static test_return
user_supplied_bug4(memcached_st
*memc
)
1536 memcached_return rc
;
1537 char *keys
[]= {"fudge", "son", "food"};
1538 size_t key_length
[]= {5, 3, 4};
1541 char return_key
[MEMCACHED_MAX_KEY
];
1542 size_t return_key_length
;
1544 size_t return_value_length
;
1546 /* Here we free everything before running a bunch of mget tests */
1548 memcached_server_list_free(memc
->hosts
);
1550 memc
->number_of_hosts
= 0;
1554 /* We need to empty the server before continueing test */
1555 rc
= memcached_flush(memc
, 0);
1556 assert(rc
== MEMCACHED_NO_SERVERS
);
1558 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1559 assert(rc
== MEMCACHED_NO_SERVERS
);
1561 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1562 &return_value_length
, &flags
, &rc
)) != NULL
)
1564 assert(return_value
);
1566 assert(!return_value
);
1567 assert(return_value_length
== 0);
1568 assert(rc
== MEMCACHED_NO_SERVERS
);
1570 for (x
= 0; x
< 3; x
++)
1572 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1573 keys
[x
], key_length
[x
],
1574 (time_t)50, (uint32_t)9);
1575 assert(rc
== MEMCACHED_NO_SERVERS
);
1578 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1579 assert(rc
== MEMCACHED_NO_SERVERS
);
1582 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1583 &return_value_length
, &flags
, &rc
)))
1585 assert(return_value
);
1586 assert(rc
== MEMCACHED_SUCCESS
);
1587 assert(return_key_length
== return_value_length
);
1588 assert(!memcmp(return_value
, return_key
, return_value_length
));
1596 #define VALUE_SIZE_BUG5 1048064
1597 static test_return
user_supplied_bug5(memcached_st
*memc
)
1599 memcached_return rc
;
1600 char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1601 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1602 char return_key
[MEMCACHED_MAX_KEY
];
1603 size_t return_key_length
;
1605 size_t value_length
;
1609 char insert_data
[VALUE_SIZE_BUG5
];
1611 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1612 insert_data
[x
]= rand();
1614 memcached_flush(memc
, 0);
1615 value
= memcached_get(memc
, keys
[0], key_length
[0],
1616 &value_length
, &flags
, &rc
);
1617 assert(value
== NULL
);
1618 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1621 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1622 &value_length
, &flags
, &rc
)))
1626 for (x
= 0; x
< 4; x
++)
1628 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1629 insert_data
, VALUE_SIZE_BUG5
,
1630 (time_t)0, (uint32_t)0);
1631 assert(rc
== MEMCACHED_SUCCESS
);
1634 for (x
= 0; x
< 10; x
++)
1636 value
= memcached_get(memc
, keys
[0], key_length
[0],
1637 &value_length
, &flags
, &rc
);
1641 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1643 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1644 &value_length
, &flags
, &rc
)))
1655 static test_return
user_supplied_bug6(memcached_st
*memc
)
1657 memcached_return rc
;
1658 char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1659 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1660 char return_key
[MEMCACHED_MAX_KEY
];
1661 size_t return_key_length
;
1663 size_t value_length
;
1667 char insert_data
[VALUE_SIZE_BUG5
];
1669 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1670 insert_data
[x
]= rand();
1672 memcached_flush(memc
, 0);
1673 value
= memcached_get(memc
, keys
[0], key_length
[0],
1674 &value_length
, &flags
, &rc
);
1675 assert(value
== NULL
);
1676 assert(rc
== MEMCACHED_NOTFOUND
);
1677 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1678 assert(rc
== MEMCACHED_SUCCESS
);
1681 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1682 &value_length
, &flags
, &rc
)))
1685 assert(rc
== MEMCACHED_END
);
1687 for (x
= 0; x
< 4; x
++)
1689 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1690 insert_data
, VALUE_SIZE_BUG5
,
1691 (time_t)0, (uint32_t)0);
1692 assert(rc
== MEMCACHED_SUCCESS
);
1695 for (x
= 0; x
< 2; x
++)
1697 value
= memcached_get(memc
, keys
[0], key_length
[0],
1698 &value_length
, &flags
, &rc
);
1702 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1703 assert(rc
== MEMCACHED_SUCCESS
);
1705 /* We test for purge of partial complete fetches */
1706 for (count
= 3; count
; count
--)
1708 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1709 &value_length
, &flags
, &rc
);
1710 assert(rc
== MEMCACHED_SUCCESS
);
1711 assert(!(memcmp(value
, insert_data
, value_length
)));
1712 assert(value_length
);
1720 static test_return
user_supplied_bug8(memcached_st
*memc
__attribute__((unused
)))
1722 memcached_return rc
;
1724 memcached_st
*clone
;
1726 memcached_server_st
*servers
;
1727 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";
1729 servers
= memcached_servers_parse(server_list
);
1732 mine
= memcached_create(NULL
);
1733 rc
= memcached_server_push(mine
, servers
);
1734 assert(rc
== MEMCACHED_SUCCESS
);
1735 memcached_server_list_free(servers
);
1738 clone
= memcached_clone(NULL
, mine
);
1740 memcached_quit(mine
);
1741 memcached_quit(clone
);
1744 memcached_free(mine
);
1745 memcached_free(clone
);
1750 /* Test flag store/retrieve */
1751 static test_return
user_supplied_bug7(memcached_st
*memc
)
1753 memcached_return rc
;
1754 char *keys
= "036790384900";
1755 size_t key_length
= strlen("036790384900");
1756 char return_key
[MEMCACHED_MAX_KEY
];
1757 size_t return_key_length
;
1759 size_t value_length
;
1762 char insert_data
[VALUE_SIZE_BUG5
];
1764 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1765 insert_data
[x
]= rand();
1767 memcached_flush(memc
, 0);
1770 rc
= memcached_set(memc
, keys
, key_length
,
1771 insert_data
, VALUE_SIZE_BUG5
,
1773 assert(rc
== MEMCACHED_SUCCESS
);
1776 value
= memcached_get(memc
, keys
, key_length
,
1777 &value_length
, &flags
, &rc
);
1778 assert(flags
== 245);
1782 rc
= memcached_mget(memc
, &keys
, &key_length
, 1);
1785 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1786 &value_length
, &flags
, &rc
);
1787 assert(flags
== 245);
1795 static test_return
user_supplied_bug9(memcached_st
*memc
)
1797 memcached_return rc
;
1798 char *keys
[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
1799 size_t key_length
[3];
1804 char return_key
[MEMCACHED_MAX_KEY
];
1805 size_t return_key_length
;
1807 size_t return_value_length
;
1810 key_length
[0]= strlen("UDATA:edevil@sapo.pt");
1811 key_length
[1]= strlen("fudge&*@#");
1812 key_length
[2]= strlen("for^#@&$not");
1815 for (x
= 0; x
< 3; x
++)
1817 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1818 keys
[x
], key_length
[x
],
1819 (time_t)50, (uint32_t)9);
1820 assert(rc
== MEMCACHED_SUCCESS
);
1823 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1824 assert(rc
== MEMCACHED_SUCCESS
);
1826 /* We need to empty the server before continueing test */
1827 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1828 &return_value_length
, &flags
, &rc
)) != NULL
)
1830 assert(return_value
);
1839 /* We are testing with aggressive timeout to get failures */
1840 static test_return
user_supplied_bug10(memcached_st
*memc
)
1844 size_t value_length
= 512;
1847 memcached_return rc
;
1848 unsigned int set
= 1;
1849 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
1852 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1853 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1855 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
1857 value
= (char*)malloc(value_length
* sizeof(char));
1859 for (x
= 0; x
< value_length
; x
++)
1860 value
[x
]= (char) (x
% 127);
1862 for (x
= 1; x
<= 100000; ++x
)
1864 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
1866 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_WRITE_FAILURE
|| rc
== MEMCACHED_BUFFERED
);
1868 if (rc
== MEMCACHED_WRITE_FAILURE
)
1873 memcached_free(mclone
);
1879 We are looking failures in the async protocol
1881 static test_return
user_supplied_bug11(memcached_st
*memc
)
1885 size_t value_length
= 512;
1888 memcached_return rc
;
1889 unsigned int set
= 1;
1891 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
1893 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1894 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1896 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
1898 timeout
= (int32_t)memcached_behavior_get(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
1900 assert(timeout
== -1);
1902 value
= (char*)malloc(value_length
* sizeof(char));
1904 for (x
= 0; x
< value_length
; x
++)
1905 value
[x
]= (char) (x
% 127);
1907 for (x
= 1; x
<= 100000; ++x
)
1909 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
1913 memcached_free(mclone
);
1919 Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
1921 static test_return
user_supplied_bug12(memcached_st
*memc
)
1923 memcached_return rc
;
1925 size_t value_length
;
1927 uint64_t number_value
;
1929 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
1930 &value_length
, &flags
, &rc
);
1931 assert(value
== NULL
);
1932 assert(rc
== MEMCACHED_NOTFOUND
);
1934 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
1937 assert(value
== NULL
);
1938 /* The binary protocol will set the key if it doesn't exist */
1939 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1)
1940 assert(rc
== MEMCACHED_SUCCESS
);
1942 assert(rc
== MEMCACHED_NOTFOUND
);
1944 rc
= memcached_set(memc
, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
1946 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
1947 &value_length
, &flags
, &rc
);
1949 assert(rc
== MEMCACHED_SUCCESS
);
1952 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
1954 assert(number_value
== 2);
1955 assert(rc
== MEMCACHED_SUCCESS
);
1961 Bug found where command total one more than MEMCACHED_MAX_BUFFER
1962 set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
1964 static test_return
user_supplied_bug13(memcached_st
*memc
)
1966 char key
[] = "key34567890";
1968 memcached_return rc
;
1969 size_t overflowSize
;
1971 char commandFirst
[]= "set key34567890 0 0 ";
1972 char commandLast
[] = " \r\n"; /* first line of command sent to server */
1973 size_t commandLength
;
1976 commandLength
= strlen(commandFirst
) + strlen(commandLast
) + 4; /* 4 is number of characters in size, probably 8196 */
1978 overflowSize
= MEMCACHED_MAX_BUFFER
- commandLength
;
1980 for (testSize
= overflowSize
- 1; testSize
< overflowSize
+ 1; testSize
++)
1982 overflow
= malloc(testSize
);
1983 assert(overflow
!= NULL
);
1985 memset(overflow
, 'x', testSize
);
1986 rc
= memcached_set(memc
, key
, strlen(key
),
1987 overflow
, testSize
, 0, 0);
1988 assert(rc
== MEMCACHED_SUCCESS
);
1997 Test values of many different sizes
1998 Bug found where command total one more than MEMCACHED_MAX_BUFFER
1999 set key34567890 0 0 8169 \r\n
2000 is sent followed by buffer of size 8169, followed by 8169
2002 static test_return
user_supplied_bug14(memcached_st
*memc
)
2005 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2006 memcached_return rc
;
2009 size_t value_length
= 18000;
2011 size_t string_length
;
2014 size_t current_length
;
2016 value
= (char*)malloc(value_length
);
2019 for (x
= 0; x
< value_length
; x
++)
2020 value
[x
] = (char) (x
% 127);
2022 for (current_length
= 0; current_length
< value_length
; current_length
++)
2024 rc
= memcached_set(memc
, key
, strlen(key
),
2025 value
, current_length
,
2026 (time_t)0, (uint32_t)0);
2027 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
2029 string
= memcached_get(memc
, key
, strlen(key
),
2030 &string_length
, &flags
, &rc
);
2032 assert(rc
== MEMCACHED_SUCCESS
);
2033 assert(string_length
== current_length
);
2034 assert(!memcmp(string
, value
, string_length
));
2045 Look for zero length value problems
2047 static test_return
user_supplied_bug15(memcached_st
*memc
)
2050 memcached_return rc
;
2056 for (x
= 0; x
< 2; x
++)
2058 rc
= memcached_set(memc
, key
, strlen(key
),
2060 (time_t)0, (uint32_t)0);
2062 assert(rc
== MEMCACHED_SUCCESS
);
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);
2072 value
= memcached_get(memc
, key
, strlen(key
),
2073 &length
, &flags
, &rc
);
2075 assert(rc
== MEMCACHED_SUCCESS
);
2076 assert(value
== NULL
);
2077 assert(length
== 0);
2084 /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
2085 static test_return
user_supplied_bug16(memcached_st
*memc
)
2087 memcached_return rc
;
2093 rc
= memcached_set(memc
, key
, strlen(key
),
2095 (time_t)0, UINT32_MAX
);
2097 assert(rc
== MEMCACHED_SUCCESS
);
2099 value
= memcached_get(memc
, key
, strlen(key
),
2100 &length
, &flags
, &rc
);
2102 assert(rc
== MEMCACHED_SUCCESS
);
2103 assert(value
== NULL
);
2104 assert(length
== 0);
2105 assert(flags
== UINT32_MAX
);
2110 /* Check the validity of chinese key*/
2111 static test_return
user_supplied_bug17(memcached_st
*memc
)
2113 memcached_return rc
;
2115 char *value
="我们在炎热抑郁的夏天无法停止豆瓣";
2120 rc
= memcached_set(memc
, key
, strlen(key
),
2121 value
, strlen(value
),
2124 assert(rc
== MEMCACHED_SUCCESS
);
2126 value2
= memcached_get(memc
, key
, strlen(key
),
2127 &length
, &flags
, &rc
);
2129 assert(length
==strlen(value
));
2130 assert(rc
== MEMCACHED_SUCCESS
);
2131 assert(memcmp(value
, value2
, length
)==0);
2141 test_return
user_supplied_bug19(memcached_st
*memc
)
2144 memcached_server_st
*s
;
2145 memcached_return res
;
2149 m
= memcached_create(NULL
);
2150 memcached_server_add_with_weight(m
, "localhost", 11311, 100);
2151 memcached_server_add_with_weight(m
, "localhost", 11312, 100);
2153 s
= memcached_server_by_key(m
, "a", 1, &res
);
2154 memcached_server_free(s
);
2161 /* CAS test from Andei */
2162 test_return
user_supplied_bug20(memcached_st
*memc
)
2164 memcached_return status
;
2165 memcached_result_st
*result
, result_obj
;
2167 size_t key_len
= strlen("abc");
2168 char *value
= "foobar";
2169 size_t value_len
= strlen(value
);
2171 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
2173 status
= memcached_set(memc
, key
, key_len
, value
, value_len
, (time_t)0, (uint32_t)0);
2174 assert(status
== MEMCACHED_SUCCESS
);
2176 status
= memcached_mget(memc
, &key
, &key_len
, 1);
2177 assert(status
== MEMCACHED_SUCCESS
);
2179 result
= memcached_result_create(memc
, &result_obj
);
2182 memcached_result_create(memc
, &result_obj
);
2183 result
= memcached_fetch_result(memc
, &result_obj
, &status
);
2186 assert(status
== MEMCACHED_SUCCESS
);
2188 memcached_result_free(result
);
2193 #include "ketama_test_cases.h"
2194 test_return
user_supplied_bug18(memcached_st
*trash
)
2196 memcached_return rc
;
2199 memcached_server_st
*server_pool
;
2204 memc
= memcached_create(NULL
);
2207 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2208 assert(rc
== MEMCACHED_SUCCESS
);
2210 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2213 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2214 assert(rc
== MEMCACHED_SUCCESS
);
2216 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2217 assert(value
== MEMCACHED_HASH_MD5
);
2219 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");
2220 memcached_server_push(memc
, server_pool
);
2222 /* verify that the server list was parsed okay. */
2223 assert(memc
->number_of_hosts
== 8);
2224 assert(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
2225 assert(server_pool
[0].port
== 11211);
2226 assert(server_pool
[0].weight
== 600);
2227 assert(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
2228 assert(server_pool
[2].port
== 11211);
2229 assert(server_pool
[2].weight
== 200);
2230 assert(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
2231 assert(server_pool
[7].port
== 11211);
2232 assert(server_pool
[7].weight
== 100);
2234 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
2235 * us test the boundary wraparound.
2237 assert(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
2239 /* verify the standard ketama set. */
2240 for (i
= 0; i
< 99; i
++)
2242 uint32_t server_idx
= memcached_generate_hash(memc
, test_cases
[i
].key
, strlen(test_cases
[i
].key
));
2243 char *hostname
= memc
->hosts
[server_idx
].hostname
;
2244 assert(strcmp(hostname
, test_cases
[i
].server
) == 0);
2247 memcached_server_list_free(server_pool
);
2248 memcached_free(memc
);
2253 static test_return
result_static(memcached_st
*memc
)
2255 memcached_result_st result
;
2256 memcached_result_st
*result_ptr
;
2258 result_ptr
= memcached_result_create(memc
, &result
);
2259 assert(result
.is_allocated
== false);
2261 memcached_result_free(&result
);
2266 static test_return
result_alloc(memcached_st
*memc
)
2268 memcached_result_st
*result
;
2270 result
= memcached_result_create(memc
, NULL
);
2272 memcached_result_free(result
);
2277 static test_return
string_static_null(memcached_st
*memc
)
2279 memcached_string_st string
;
2280 memcached_string_st
*string_ptr
;
2282 string_ptr
= memcached_string_create(memc
, &string
, 0);
2283 assert(string
.is_allocated
== false);
2285 memcached_string_free(&string
);
2290 static test_return
string_alloc_null(memcached_st
*memc
)
2292 memcached_string_st
*string
;
2294 string
= memcached_string_create(memc
, NULL
, 0);
2296 memcached_string_free(string
);
2301 static test_return
string_alloc_with_size(memcached_st
*memc
)
2303 memcached_string_st
*string
;
2305 string
= memcached_string_create(memc
, NULL
, 1024);
2307 memcached_string_free(string
);
2312 static test_return
string_alloc_with_size_toobig(memcached_st
*memc
)
2314 memcached_string_st
*string
;
2316 string
= memcached_string_create(memc
, NULL
, INT64_MAX
);
2317 assert(string
== NULL
);
2322 static test_return
string_alloc_append(memcached_st
*memc
)
2325 char buffer
[SMALL_STRING_LEN
];
2326 memcached_string_st
*string
;
2328 /* Ring the bell! */
2329 memset(buffer
, 6, SMALL_STRING_LEN
);
2331 string
= memcached_string_create(memc
, NULL
, 100);
2334 for (x
= 0; x
< 1024; x
++)
2336 memcached_return rc
;
2337 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
2338 assert(rc
== MEMCACHED_SUCCESS
);
2340 memcached_string_free(string
);
2345 static test_return
string_alloc_append_toobig(memcached_st
*memc
)
2347 memcached_return rc
;
2349 char buffer
[SMALL_STRING_LEN
];
2350 memcached_string_st
*string
;
2352 /* Ring the bell! */
2353 memset(buffer
, 6, SMALL_STRING_LEN
);
2355 string
= memcached_string_create(memc
, NULL
, 100);
2358 for (x
= 0; x
< 1024; x
++)
2360 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
2361 assert(rc
== MEMCACHED_SUCCESS
);
2363 rc
= memcached_string_append(string
, buffer
, INT64_MAX
);
2364 assert(rc
== MEMCACHED_MEMORY_ALLOCATION_FAILURE
);
2365 memcached_string_free(string
);
2370 static test_return
cleanup_pairs(memcached_st
*memc
__attribute__((unused
)))
2372 pairs_free(global_pairs
);
2377 static test_return
generate_pairs(memcached_st
*memc
__attribute__((unused
)))
2379 unsigned long long x
;
2380 global_pairs
= pairs_generate(GLOBAL_COUNT
, 400);
2381 global_count
= GLOBAL_COUNT
;
2383 for (x
= 0; x
< global_count
; x
++)
2385 global_keys
[x
]= global_pairs
[x
].key
;
2386 global_keys_length
[x
]= global_pairs
[x
].key_length
;
2392 static test_return
generate_large_pairs(memcached_st
*memc
__attribute__((unused
)))
2394 unsigned long long x
;
2395 global_pairs
= pairs_generate(GLOBAL2_COUNT
, MEMCACHED_MAX_BUFFER
+10);
2396 global_count
= GLOBAL2_COUNT
;
2398 for (x
= 0; x
< global_count
; x
++)
2400 global_keys
[x
]= global_pairs
[x
].key
;
2401 global_keys_length
[x
]= global_pairs
[x
].key_length
;
2407 static test_return
generate_data(memcached_st
*memc
)
2409 execute_set(memc
, global_pairs
, global_count
);
2414 static test_return
generate_data_with_stats(memcached_st
*memc
)
2416 memcached_stat_st
*stat_p
;
2417 memcached_return rc
;
2418 uint32_t host_index
= 0;
2419 execute_set(memc
, global_pairs
, global_count
);
2421 //TODO: hosts used size stats
2422 stat_p
= memcached_stat(memc
, NULL
, &rc
);
2425 for (host_index
= 0; host_index
< SERVERS_TO_CREATE
; host_index
++)
2427 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
);
2430 memcached_stat_free(NULL
, stat_p
);
2434 static test_return
generate_buffer_data(memcached_st
*memc
)
2439 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
2440 generate_data(memc
);
2445 static test_return
get_read_count(memcached_st
*memc
)
2448 memcached_return rc
;
2449 memcached_st
*clone
;
2451 clone
= memcached_clone(NULL
, memc
);
2454 memcached_server_add_with_weight(clone
, "localhost", 6666, 0);
2458 size_t return_value_length
;
2462 for (x
= count
= 0; x
< global_count
; x
++)
2464 return_value
= memcached_get(clone
, global_keys
[x
], global_keys_length
[x
],
2465 &return_value_length
, &flags
, &rc
);
2466 if (rc
== MEMCACHED_SUCCESS
)
2473 fprintf(stderr
, "\t%u -> %u", global_count
, count
);
2476 memcached_free(clone
);
2481 static test_return
get_read(memcached_st
*memc
)
2484 memcached_return rc
;
2488 size_t return_value_length
;
2491 for (x
= 0; x
< global_count
; x
++)
2493 return_value
= memcached_get(memc
, global_keys
[x
], global_keys_length
[x
],
2494 &return_value_length
, &flags
, &rc
);
2496 assert(return_value);
2497 assert(rc == MEMCACHED_SUCCESS);
2499 if (rc
== MEMCACHED_SUCCESS
&& return_value
)
2507 static test_return
mget_read(memcached_st
*memc
)
2509 memcached_return rc
;
2511 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2512 assert(rc
== MEMCACHED_SUCCESS
);
2513 /* Turn this into a help function */
2515 char return_key
[MEMCACHED_MAX_KEY
];
2516 size_t return_key_length
;
2518 size_t return_value_length
;
2521 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2522 &return_value_length
, &flags
, &rc
)))
2524 assert(return_value
);
2525 assert(rc
== MEMCACHED_SUCCESS
);
2533 static test_return
mget_read_result(memcached_st
*memc
)
2535 memcached_return rc
;
2537 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2538 assert(rc
== MEMCACHED_SUCCESS
);
2539 /* Turn this into a help function */
2541 memcached_result_st results_obj
;
2542 memcached_result_st
*results
;
2544 results
= memcached_result_create(memc
, &results_obj
);
2546 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
2549 assert(rc
== MEMCACHED_SUCCESS
);
2552 memcached_result_free(&results_obj
);
2558 static test_return
mget_read_function(memcached_st
*memc
)
2560 memcached_return rc
;
2561 unsigned int counter
;
2562 unsigned int (*callbacks
[1])(memcached_st
*, memcached_result_st
*, void *);
2564 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2565 assert(rc
== MEMCACHED_SUCCESS
);
2567 callbacks
[0]= &callback_counter
;
2569 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
2574 static test_return
delete_generate(memcached_st
*memc
)
2578 for (x
= 0; x
< global_count
; x
++)
2580 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
2586 static test_return
delete_buffer_generate(memcached_st
*memc
)
2592 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
2594 for (x
= 0; x
< global_count
; x
++)
2596 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
2602 static test_return
free_data(memcached_st
*memc
__attribute__((unused
)))
2604 pairs_free(global_pairs
);
2609 static test_return
add_host_test1(memcached_st
*memc
)
2612 memcached_return rc
;
2613 char servername
[]= "0.example.com";
2614 memcached_server_st
*servers
;
2616 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
2618 assert(1 == memcached_server_list_count(servers
));
2620 for (x
= 2; x
< 20; x
++)
2622 char buffer
[SMALL_STRING_LEN
];
2624 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
2625 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
2627 assert(rc
== MEMCACHED_SUCCESS
);
2628 assert(x
== memcached_server_list_count(servers
));
2631 rc
= memcached_server_push(memc
, servers
);
2632 assert(rc
== MEMCACHED_SUCCESS
);
2633 rc
= memcached_server_push(memc
, servers
);
2634 assert(rc
== MEMCACHED_SUCCESS
);
2636 memcached_server_list_free(servers
);
2641 static memcached_return
pre_nonblock(memcached_st
*memc
)
2643 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
2645 return MEMCACHED_SUCCESS
;
2648 static memcached_return
pre_nonblock_binary(memcached_st
*memc
)
2650 memcached_return rc
= MEMCACHED_FAILURE
;
2651 memcached_st
*clone
;
2653 clone
= memcached_clone(NULL
, memc
);
2655 // The memcached_version needs to be done on a clone, because the server
2656 // will not toggle protocol on an connection.
2657 memcached_version(clone
);
2659 if (clone
->hosts
[0].major_version
>= 1 && clone
->hosts
[0].minor_version
> 2)
2661 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
2662 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
2663 assert(rc
== MEMCACHED_SUCCESS
);
2664 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
2667 memcached_free(clone
);
2671 static memcached_return
pre_murmur(memcached_st
*memc
)
2673 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
2675 return MEMCACHED_SUCCESS
;
2678 static memcached_return
pre_jenkins(memcached_st
*memc
)
2680 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_JENKINS
);
2682 return MEMCACHED_SUCCESS
;
2686 static memcached_return
pre_md5(memcached_st
*memc
)
2688 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MD5
);
2690 return MEMCACHED_SUCCESS
;
2693 static memcached_return
pre_crc(memcached_st
*memc
)
2695 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_CRC
);
2697 return MEMCACHED_SUCCESS
;
2700 static memcached_return
pre_hsieh(memcached_st
*memc
)
2702 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_HSIEH
);
2704 return MEMCACHED_SUCCESS
;
2707 static memcached_return
pre_hash_fnv1_64(memcached_st
*memc
)
2709 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_64
);
2711 return MEMCACHED_SUCCESS
;
2714 static memcached_return
pre_hash_fnv1a_64(memcached_st
*memc
)
2716 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_64
);
2718 return MEMCACHED_SUCCESS
;
2721 static memcached_return
pre_hash_fnv1_32(memcached_st
*memc
)
2723 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_32
);
2725 return MEMCACHED_SUCCESS
;
2728 static memcached_return
pre_hash_fnv1a_32(memcached_st
*memc
)
2730 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_32
);
2732 return MEMCACHED_SUCCESS
;
2735 static memcached_return
pre_behavior_ketama(memcached_st
*memc
)
2737 memcached_return rc
;
2740 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA
, 1);
2741 assert(rc
== MEMCACHED_SUCCESS
);
2743 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA
);
2746 return MEMCACHED_SUCCESS
;
2749 static memcached_return
pre_behavior_ketama_weighted(memcached_st
*memc
)
2751 memcached_return rc
;
2754 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2755 assert(rc
== MEMCACHED_SUCCESS
);
2757 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2760 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2761 assert(rc
== MEMCACHED_SUCCESS
);
2763 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2764 assert(value
== MEMCACHED_HASH_MD5
);
2765 return MEMCACHED_SUCCESS
;
2768 static memcached_return
pre_binary(memcached_st
*memc
)
2770 memcached_return rc
= MEMCACHED_FAILURE
;
2771 memcached_st
*clone
;
2773 clone
= memcached_clone(NULL
, memc
);
2775 // The memcached_version needs to be done on a clone, because the server
2776 // will not toggle protocol on an connection.
2777 memcached_version(clone
);
2779 if (clone
->hosts
[0].major_version
>= 1 && clone
->hosts
[0].minor_version
> 2)
2781 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
2782 assert(rc
== MEMCACHED_SUCCESS
);
2783 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
2786 memcached_free(clone
);
2790 static void my_free(memcached_st
*ptr
__attribute__((unused
)), void *mem
)
2795 static void *my_malloc(memcached_st
*ptr
__attribute__((unused
)), const size_t size
)
2797 return malloc(size
);
2800 static void *my_realloc(memcached_st
*ptr
__attribute__((unused
)), void *mem
, const size_t size
)
2802 return realloc(mem
, size
);
2805 static memcached_return
set_prefix(memcached_st
*memc
)
2807 memcached_return rc
;
2808 const char *key
= "mine";
2811 /* Make sure be default none exists */
2812 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2813 assert(rc
== MEMCACHED_FAILURE
);
2815 /* Test a clean set */
2816 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
2817 assert(rc
== MEMCACHED_SUCCESS
);
2819 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2820 assert(memcmp(value
, key
, 4) == 0);
2821 assert(rc
== MEMCACHED_SUCCESS
);
2823 /* Test that we can turn it off */
2824 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
2825 assert(rc
== MEMCACHED_SUCCESS
);
2827 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2828 assert(rc
== MEMCACHED_FAILURE
);
2830 /* Now setup for main test */
2831 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
2832 assert(rc
== MEMCACHED_SUCCESS
);
2834 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2835 assert(rc
== MEMCACHED_SUCCESS
);
2836 assert(memcmp(value
, key
, 4) == 0);
2838 /* Set to Zero, and then Set to something too large */
2841 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
2842 assert(rc
== MEMCACHED_SUCCESS
);
2844 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2845 assert(rc
== MEMCACHED_FAILURE
);
2846 assert(value
== NULL
);
2848 /* Test a long key for failure */
2849 /* TODO, extend test to determine based on setting, what result should be */
2850 long_key
= "Thisismorethentheallottednumberofcharacters";
2851 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
2852 //assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
2853 assert(rc
== MEMCACHED_SUCCESS
);
2855 /* Now test a key with spaces (which will fail from long key, since bad key is not set) */
2856 long_key
= "This is more then the allotted number of characters";
2857 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
2858 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
2860 /* Test for a bad prefix, but with a short key */
2861 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, 1);
2862 assert(rc
== MEMCACHED_SUCCESS
);
2864 long_key
= "dog cat";
2865 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
2866 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
2869 return MEMCACHED_SUCCESS
;
2872 static memcached_return
set_memory_alloc(memcached_st
*memc
)
2875 memcached_malloc_function test_ptr
;
2876 memcached_return rc
;
2878 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &my_malloc
);
2879 assert(rc
== MEMCACHED_SUCCESS
);
2880 test_ptr
= (memcached_malloc_function
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
2881 assert(rc
== MEMCACHED_SUCCESS
);
2882 assert(test_ptr
== my_malloc
);
2886 memcached_realloc_function test_ptr
;
2887 memcached_return rc
;
2889 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &my_realloc
);
2890 assert(rc
== MEMCACHED_SUCCESS
);
2891 test_ptr
= (memcached_realloc_function
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
2892 assert(rc
== MEMCACHED_SUCCESS
);
2893 assert(test_ptr
== my_realloc
);
2897 memcached_free_function test_ptr
;
2898 memcached_return rc
;
2900 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, my_free
);
2901 assert(rc
== MEMCACHED_SUCCESS
);
2902 test_ptr
= (memcached_free_function
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
2903 assert(rc
== MEMCACHED_SUCCESS
);
2904 assert(test_ptr
== my_free
);
2907 return MEMCACHED_SUCCESS
;
2910 static memcached_return
enable_consistent(memcached_st
*memc
)
2912 memcached_server_distribution value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
2913 memcached_hash hash
;
2914 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
2917 value
= (memcached_server_distribution
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
2918 assert(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
2920 hash
= (memcached_hash
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
2921 assert(hash
== MEMCACHED_HASH_HSIEH
);
2924 return MEMCACHED_SUCCESS
;
2927 static memcached_return
enable_cas(memcached_st
*memc
)
2929 unsigned int set
= 1;
2931 memcached_version(memc
);
2933 if ((memc
->hosts
[0].major_version
>= 1 && (memc
->hosts
[0].minor_version
== 2 && memc
->hosts
[0].micro_version
>= 4))
2934 || memc
->hosts
[0].minor_version
> 2)
2936 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
2938 return MEMCACHED_SUCCESS
;
2941 return MEMCACHED_FAILURE
;
2944 static memcached_return
check_for_1_2_3(memcached_st
*memc
)
2946 memcached_version(memc
);
2948 if ((memc
->hosts
[0].major_version
>= 1 && (memc
->hosts
[0].minor_version
== 2 && memc
->hosts
[0].micro_version
>= 4))
2949 || memc
->hosts
[0].minor_version
> 2)
2950 return MEMCACHED_SUCCESS
;
2952 return MEMCACHED_FAILURE
;
2955 static memcached_return
pre_unix_socket(memcached_st
*memc
)
2957 memcached_return rc
;
2960 memcached_server_list_free(memc
->hosts
);
2962 memc
->number_of_hosts
= 0;
2964 if (stat("/tmp/memcached.socket", &buf
))
2965 return MEMCACHED_FAILURE
;
2967 rc
= memcached_server_add_unix_socket_with_weight(memc
, "/tmp/memcached.socket", 0);
2972 static memcached_return
pre_nodelay(memcached_st
*memc
)
2974 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
2975 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
2977 return MEMCACHED_SUCCESS
;
2980 static memcached_return
pre_settimer(memcached_st
*memc
)
2982 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
2983 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
2985 return MEMCACHED_SUCCESS
;
2988 static memcached_return
poll_timeout(memcached_st
*memc
)
2994 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
2996 timeout
= (int32_t)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
2998 assert(timeout
== 100);
3000 return MEMCACHED_SUCCESS
;
3004 /* Clean the server before beginning testing */
3006 {"flush", 0, flush_test
},
3007 {"init", 0, init_test
},
3008 {"allocation", 0, allocation_test
},
3009 {"server_list_null_test", 0, server_list_null_test
},
3010 {"server_unsort", 0, server_unsort_test
},
3011 {"server_sort", 0, server_sort_test
},
3012 {"server_sort2", 0, server_sort2_test
},
3013 {"clone_test", 0, clone_test
},
3014 {"error", 0, error_test
},
3015 {"set", 0, set_test
},
3016 {"set2", 0, set_test2
},
3017 {"set3", 0, set_test3
},
3018 {"add", 1, add_test
},
3019 {"replace", 1, replace_test
},
3020 {"delete", 1, delete_test
},
3021 {"get", 1, get_test
},
3022 {"get2", 0, get_test2
},
3023 {"get3", 0, get_test3
},
3024 {"get4", 0, get_test4
},
3025 {"stats_servername", 0, stats_servername_test
},
3026 {"increment", 0, increment_test
},
3027 {"decrement", 0, decrement_test
},
3028 {"quit", 0, quit_test
},
3029 {"mget", 1, mget_test
},
3030 {"mget_result", 1, mget_result_test
},
3031 {"mget_result_alloc", 1, mget_result_alloc_test
},
3032 {"mget_result_function", 1, mget_result_function
},
3033 {"get_stats", 0, get_stats
},
3034 {"add_host_test", 0, add_host_test
},
3035 {"add_host_test_1", 0, add_host_test1
},
3036 {"get_stats_keys", 0, get_stats_keys
},
3037 {"behavior_test", 0, get_stats_keys
},
3038 {"callback_test", 0, get_stats_keys
},
3039 {"version_string_test", 0, version_string_test
},
3040 {"bad_key", 1, bad_key_test
},
3041 {"memcached_server_cursor", 1, memcached_server_cursor_test
},
3042 {"read_through", 1, read_through
},
3043 {"delete_through", 1, delete_through
},
3047 test_st async_tests
[] ={
3048 {"add", 1, add_wrapper
},
3052 test_st string_tests
[] ={
3053 {"string static with null", 0, string_static_null
},
3054 {"string alloc with null", 0, string_alloc_null
},
3055 {"string alloc with 1K", 0, string_alloc_with_size
},
3056 {"string alloc with malloc failure", 0, string_alloc_with_size_toobig
},
3057 {"string append", 0, string_alloc_append
},
3058 {"string append failure (too big)", 0, string_alloc_append_toobig
},
3062 test_st result_tests
[] ={
3063 {"result static", 0, result_static
},
3064 {"result alloc", 0, result_alloc
},
3068 test_st version_1_2_3
[] ={
3069 {"append", 0, append_test
},
3070 {"prepend", 0, prepend_test
},
3071 {"cas", 0, cas_test
},
3072 {"cas2", 0, cas2_test
},
3073 {"append_binary", 0, append_binary_test
},
3077 test_st user_tests
[] ={
3078 {"user_supplied_bug1", 0, user_supplied_bug1
},
3079 {"user_supplied_bug2", 0, user_supplied_bug2
},
3080 {"user_supplied_bug3", 0, user_supplied_bug3
},
3081 {"user_supplied_bug4", 0, user_supplied_bug4
},
3082 {"user_supplied_bug5", 1, user_supplied_bug5
},
3083 {"user_supplied_bug6", 1, user_supplied_bug6
},
3084 {"user_supplied_bug7", 1, user_supplied_bug7
},
3085 {"user_supplied_bug8", 1, user_supplied_bug8
},
3086 {"user_supplied_bug9", 1, user_supplied_bug9
},
3087 {"user_supplied_bug10", 1, user_supplied_bug10
},
3088 {"user_supplied_bug11", 1, user_supplied_bug11
},
3089 {"user_supplied_bug12", 1, user_supplied_bug12
},
3090 {"user_supplied_bug13", 1, user_supplied_bug13
},
3091 {"user_supplied_bug14", 1, user_supplied_bug14
},
3092 {"user_supplied_bug15", 1, user_supplied_bug15
},
3093 {"user_supplied_bug16", 1, user_supplied_bug16
},
3096 ** It seems to be something weird with the character sets..
3097 ** value_fetch is unable to parse the value line (iscntrl "fails"), so I
3098 ** guess I need to find out how this is supposed to work.. Perhaps I need
3099 ** to run the test in a specific locale (I tried zh_CN.UTF-8 without success,
3100 ** so just disable the code for now...).
3102 {"user_supplied_bug17", 1, user_supplied_bug17
},
3104 {"user_supplied_bug18", 1, user_supplied_bug18
},
3105 {"user_supplied_bug19", 1, user_supplied_bug19
},
3106 {"user_supplied_bug20", 1, user_supplied_bug20
},
3110 test_st generate_tests
[] ={
3111 {"generate_pairs", 1, generate_pairs
},
3112 {"generate_data", 1, generate_data
},
3113 {"get_read", 0, get_read
},
3114 {"delete_generate", 0, delete_generate
},
3115 {"generate_buffer_data", 1, generate_buffer_data
},
3116 {"delete_buffer", 0, delete_buffer_generate
},
3117 {"generate_data", 1, generate_data
},
3118 {"mget_read", 0, mget_read
},
3119 {"mget_read_result", 0, mget_read_result
},
3120 {"mget_read_function", 0, mget_read_function
},
3121 {"cleanup", 1, cleanup_pairs
},
3122 {"generate_large_pairs", 1, generate_large_pairs
},
3123 {"generate_data", 1, generate_data
},
3124 {"generate_buffer_data", 1, generate_buffer_data
},
3125 {"cleanup", 1, cleanup_pairs
},
3129 test_st consistent_tests
[] ={
3130 {"generate_pairs", 1, generate_pairs
},
3131 {"generate_data", 1, generate_data
},
3132 {"get_read", 0, get_read_count
},
3133 {"cleanup", 1, cleanup_pairs
},
3137 test_st consistent_weighted_tests
[] ={
3138 {"generate_pairs", 1, generate_pairs
},
3139 {"generate_data", 1, generate_data_with_stats
},
3140 {"get_read", 0, get_read_count
},
3141 {"cleanup", 1, cleanup_pairs
},
3145 collection_st collection
[] ={
3146 {"block", 0, 0, tests
},
3147 {"binary", pre_binary
, 0, tests
},
3148 {"nonblock", pre_nonblock
, 0, tests
},
3149 {"nodelay", pre_nodelay
, 0, tests
},
3150 {"settimer", pre_settimer
, 0, tests
},
3151 {"md5", pre_md5
, 0, tests
},
3152 {"crc", pre_crc
, 0, tests
},
3153 {"hsieh", pre_hsieh
, 0, tests
},
3154 {"jenkins", pre_jenkins
, 0, tests
},
3155 {"fnv1_64", pre_hash_fnv1_64
, 0, tests
},
3156 {"fnv1a_64", pre_hash_fnv1a_64
, 0, tests
},
3157 {"fnv1_32", pre_hash_fnv1_32
, 0, tests
},
3158 {"fnv1a_32", pre_hash_fnv1a_32
, 0, tests
},
3159 {"ketama", pre_behavior_ketama
, 0, tests
},
3160 {"unix_socket", pre_unix_socket
, 0, tests
},
3161 {"unix_socket_nodelay", pre_nodelay
, 0, tests
},
3162 {"poll_timeout", poll_timeout
, 0, tests
},
3163 {"gets", enable_cas
, 0, tests
},
3164 {"consistent", enable_consistent
, 0, tests
},
3165 {"memory_allocators", set_memory_alloc
, 0, tests
},
3166 {"prefix", set_prefix
, 0, tests
},
3167 {"version_1_2_3", check_for_1_2_3
, 0, version_1_2_3
},
3168 {"string", 0, 0, string_tests
},
3169 {"result", 0, 0, result_tests
},
3170 {"async", pre_nonblock
, 0, async_tests
},
3171 {"async_binary", pre_nonblock_binary
, 0, async_tests
},
3172 {"user", 0, 0, user_tests
},
3173 {"generate", 0, 0, generate_tests
},
3174 {"generate_hsieh", pre_hsieh
, 0, generate_tests
},
3175 {"generate_ketama", pre_behavior_ketama
, 0, generate_tests
},
3176 {"generate_hsieh_consistent", enable_consistent
, 0, generate_tests
},
3177 {"generate_md5", pre_md5
, 0, generate_tests
},
3178 {"generate_murmur", pre_murmur
, 0, generate_tests
},
3179 {"generate_jenkins", pre_jenkins
, 0, generate_tests
},
3180 {"generate_nonblock", pre_nonblock
, 0, generate_tests
},
3181 {"consistent_not", 0, 0, consistent_tests
},
3182 {"consistent_ketama", pre_behavior_ketama
, 0, consistent_tests
},
3183 {"consistent_ketama_weighted", pre_behavior_ketama_weighted
, 0, consistent_weighted_tests
},
3187 #define SERVERS_TO_CREATE 5
3189 /* Prototypes for functions we will pass to test framework */
3190 void *world_create(void);
3191 void world_destroy(void *p
);
3193 void *world_create(void)
3195 server_startup_st
*construct
;
3197 construct
= (server_startup_st
*)malloc(sizeof(server_startup_st
));
3198 memset(construct
, 0, sizeof(server_startup_st
));
3199 construct
->count
= SERVERS_TO_CREATE
;
3201 server_startup(construct
);
3207 void world_destroy(void *p
)
3209 server_startup_st
*construct
= (server_startup_st
*)p
;
3210 memcached_server_st
*servers
= (memcached_server_st
*)construct
->servers
;
3211 memcached_server_list_free(servers
);
3213 server_shutdown(construct
);
3217 void get_world(world_st
*world
)
3219 world
->collections
= collection
;
3220 world
->create
= world_create
;
3221 world
->destroy
= world_destroy
;