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 100000
28 #define GLOBAL2_COUNT 1000
29 static uint32_t global_count
;
31 static pairs_st
*global_pairs
;
32 static char *global_keys
[GLOBAL_COUNT
];
33 static size_t global_keys_length
[GLOBAL_COUNT
];
35 test_return
init_test(memcached_st
*not_used
)
39 (void)memcached_create(&memc
);
40 memcached_free(&memc
);
45 test_return
server_list_null_test(memcached_st
*ptr
)
47 memcached_server_st
*server_list
;
50 server_list
= memcached_server_list_append(NULL
, NULL
, 0, NULL
);
51 assert(server_list
== NULL
);
53 server_list
= memcached_server_list_append(NULL
, "localhost", 0, NULL
);
54 assert(server_list
== NULL
);
56 server_list
= memcached_server_list_append(NULL
, NULL
, 0, &rc
);
57 assert(server_list
== NULL
);
62 #define TEST_PORT_COUNT 7
63 uint32_t test_ports
[TEST_PORT_COUNT
];
65 memcached_return
server_display_function(memcached_st
*ptr
, memcached_server_st
*server
, void *context
)
68 uint32_t bigger
= *((uint32_t *)(context
));
69 assert(bigger
<= server
->port
);
70 *((uint32_t *)(context
))= server
->port
;
72 return MEMCACHED_SUCCESS
;
75 test_return
server_sort_test(memcached_st
*ptr
)
78 uint32_t bigger
= 0; /* Prime the value for the assert in server_display_function */
80 memcached_server_function callbacks
[1];
81 memcached_st
*local_memc
;
83 local_memc
= memcached_create(NULL
);
85 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
87 for (x
= 0; x
< TEST_PORT_COUNT
; x
++)
89 test_ports
[x
]= random() % 64000;
90 rc
= memcached_server_add(local_memc
, "localhost", test_ports
[x
]);
91 assert(local_memc
->number_of_hosts
== x
+1);
92 assert(local_memc
->hosts
[0].count
== x
+1);
93 assert(rc
== MEMCACHED_SUCCESS
);
96 callbacks
[0]= server_display_function
;
97 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
100 memcached_free(local_memc
);
105 memcached_return
server_display_unsort_function(memcached_st
*ptr
, memcached_server_st
*server
, void *context
)
108 uint32_t x
= *((uint32_t *)(context
));
110 assert(test_ports
[x
] == server
->port
);
111 *((uint32_t *)(context
))= ++x
;
113 return MEMCACHED_SUCCESS
;
116 test_return
server_unsort_test(memcached_st
*ptr
)
119 uint32_t counter
= 0; /* Prime the value for the assert in server_display_function */
120 uint32_t bigger
= 0; /* Prime the value for the assert in server_display_function */
122 memcached_server_function callbacks
[1];
123 memcached_st
*local_memc
;
125 local_memc
= memcached_create(NULL
);
128 for (x
= 0; x
< TEST_PORT_COUNT
; x
++)
130 test_ports
[x
]= random() % 64000;
131 rc
= memcached_server_add(local_memc
, "localhost", test_ports
[x
]);
132 assert(local_memc
->number_of_hosts
== x
+1);
133 assert(local_memc
->hosts
[0].count
== x
+1);
134 assert(rc
== MEMCACHED_SUCCESS
);
137 callbacks
[0]= server_display_unsort_function
;
138 memcached_server_cursor(local_memc
, callbacks
, (void *)&counter
, 1);
140 /* Now we sort old data! */
141 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
142 callbacks
[0]= server_display_function
;
143 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
146 memcached_free(local_memc
);
151 test_return
allocation_test(memcached_st
*not_used
)
154 memc
= memcached_create(NULL
);
156 memcached_free(memc
);
161 test_return
clone_test(memcached_st
*memc
)
166 clone
= memcached_clone(NULL
, NULL
);
168 memcached_free(clone
);
171 /* Can we init from null? */
174 clone
= memcached_clone(NULL
, memc
);
176 memcached_free(clone
);
179 /* Can we init from struct? */
181 memcached_st declared_clone
;
183 clone
= memcached_clone(&declared_clone
, NULL
);
185 memcached_free(clone
);
188 /* Can we init from struct? */
190 memcached_st declared_clone
;
192 clone
= memcached_clone(&declared_clone
, memc
);
194 memcached_free(clone
);
200 test_return
connection_test(memcached_st
*memc
)
204 rc
= memcached_server_add(memc
, "localhost", 0);
205 assert(rc
== MEMCACHED_SUCCESS
);
210 test_return
error_test(memcached_st
*memc
)
214 for (rc
= MEMCACHED_SUCCESS
; rc
< MEMCACHED_MAXIMUM_RETURN
; rc
++)
216 printf("Error %d -> %s\n", rc
, memcached_strerror(memc
, rc
));
222 test_return
set_test(memcached_st
*memc
)
226 char *value
= "when we sanitize";
228 rc
= memcached_set(memc
, key
, strlen(key
),
229 value
, strlen(value
),
230 (time_t)0, (uint32_t)0);
231 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
236 test_return
append_test(memcached_st
*memc
)
244 rc
= memcached_flush(memc
, 0);
245 assert(rc
== MEMCACHED_SUCCESS
);
247 rc
= memcached_set(memc
, key
, strlen(key
),
248 value
, strlen(value
),
249 (time_t)0, (uint32_t)0);
250 assert(rc
== MEMCACHED_SUCCESS
);
252 rc
= memcached_append(memc
, key
, strlen(key
),
253 " the", strlen(" the"),
254 (time_t)0, (uint32_t)0);
255 assert(rc
== MEMCACHED_SUCCESS
);
257 rc
= memcached_append(memc
, key
, strlen(key
),
258 " people", strlen(" people"),
259 (time_t)0, (uint32_t)0);
260 assert(rc
== MEMCACHED_SUCCESS
);
262 value
= memcached_get(memc
, key
, strlen(key
),
263 &value_length
, &flags
, &rc
);
264 assert(!memcmp(value
, "we the people", strlen("we the people")));
265 assert(strlen("we the people") == value_length
);
266 assert(rc
== MEMCACHED_SUCCESS
);
272 test_return
append_binary_test(memcached_st
*memc
)
275 char *key
= "numbers";
276 unsigned int *store_ptr
;
277 unsigned int store_list
[] = { 23, 56, 499, 98, 32847, 0 };
283 rc
= memcached_flush(memc
, 0);
284 assert(rc
== MEMCACHED_SUCCESS
);
286 rc
= memcached_set(memc
,
289 (time_t)0, (uint32_t)0);
290 assert(rc
== MEMCACHED_SUCCESS
);
292 for (x
= 0; store_list
[x
] ; x
++)
294 rc
= memcached_append(memc
,
296 (char *)&store_list
[x
], sizeof(unsigned int),
297 (time_t)0, (uint32_t)0);
298 assert(rc
== MEMCACHED_SUCCESS
);
301 value
= memcached_get(memc
, key
, strlen(key
),
302 &value_length
, &flags
, &rc
);
303 assert((value_length
== (sizeof(unsigned int) * x
)));
304 assert(rc
== MEMCACHED_SUCCESS
);
306 store_ptr
= (unsigned int *)value
;
308 while ((size_t)store_ptr
< (size_t)(value
+ value_length
))
310 assert(*store_ptr
== store_list
[x
++]);
318 test_return
cas2_test(memcached_st
*memc
)
321 char *keys
[]= {"fudge", "son", "food"};
322 size_t key_length
[]= {5, 3, 4};
323 char *value
= "we the people";
324 size_t value_length
= strlen("we the people");
326 memcached_result_st results_obj
;
327 memcached_result_st
*results
;
330 rc
= memcached_flush(memc
, 0);
331 assert(rc
== MEMCACHED_SUCCESS
);
333 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
335 for (x
= 0; x
< 3; x
++)
337 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
338 keys
[x
], key_length
[x
],
339 (time_t)50, (uint32_t)9);
340 assert(rc
== MEMCACHED_SUCCESS
);
343 rc
= memcached_mget(memc
, keys
, key_length
, 3);
345 results
= memcached_result_create(memc
, &results_obj
);
347 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
349 assert(results
->cas
);
350 assert(rc
== MEMCACHED_SUCCESS
);
351 WATCHPOINT_ASSERT(memcached_result_cas(results
));
353 assert(!memcmp(value
, "we the people", strlen("we the people")));
354 assert(strlen("we the people") == value_length
);
355 assert(rc
== MEMCACHED_SUCCESS
);
357 memcached_result_free(&results_obj
);
362 test_return
cas_test(memcached_st
*memc
)
366 size_t key_length
= strlen("fun");
367 char *value
= "we the people";
368 size_t value_length
= strlen("we the people");
369 memcached_result_st results_obj
;
370 memcached_result_st
*results
;
373 rc
= memcached_flush(memc
, 0);
374 assert(rc
== MEMCACHED_SUCCESS
);
376 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
378 rc
= memcached_set(memc
, key
, strlen(key
),
379 value
, strlen(value
),
380 (time_t)0, (uint32_t)0);
381 assert(rc
== MEMCACHED_SUCCESS
);
383 rc
= memcached_mget(memc
, &key
, &key_length
, 1);
385 results
= memcached_result_create(memc
, &results_obj
);
387 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
389 assert(rc
== MEMCACHED_SUCCESS
);
390 WATCHPOINT_ASSERT(memcached_result_cas(results
));
392 assert(!memcmp(value
, "we the people", strlen("we the people")));
393 assert(strlen("we the people") == value_length
);
394 assert(rc
== MEMCACHED_SUCCESS
);
396 rc
= memcached_cas(memc
, key
, key_length
,
397 "change the value", strlen("change the value"),
398 0, 0, memcached_result_cas(results
));
400 assert(rc
== MEMCACHED_SUCCESS
);
402 rc
= memcached_cas(memc
, key
, key_length
,
403 "change the value", strlen("change the value"),
406 assert(rc
== MEMCACHED_DATA_EXISTS
);
409 memcached_result_free(&results_obj
);
414 test_return
prepend_test(memcached_st
*memc
)
418 char *value
= "people";
422 rc
= memcached_flush(memc
, 0);
423 assert(rc
== MEMCACHED_SUCCESS
);
425 rc
= memcached_set(memc
, key
, strlen(key
),
426 value
, strlen(value
),
427 (time_t)0, (uint32_t)0);
428 assert(rc
== MEMCACHED_SUCCESS
);
430 rc
= memcached_prepend(memc
, key
, strlen(key
),
431 "the ", strlen("the "),
432 (time_t)0, (uint32_t)0);
433 assert(rc
== MEMCACHED_SUCCESS
);
435 rc
= memcached_prepend(memc
, key
, strlen(key
),
436 "we ", strlen("we "),
437 (time_t)0, (uint32_t)0);
438 assert(rc
== MEMCACHED_SUCCESS
);
440 value
= memcached_get(memc
, key
, strlen(key
),
441 &value_length
, &flags
, &rc
);
442 assert(!memcmp(value
, "we the people", strlen("we the people")));
443 assert(strlen("we the people") == value_length
);
444 assert(rc
== MEMCACHED_SUCCESS
);
451 Set the value, then quit to make sure it is flushed.
452 Come back in and test that add fails.
454 test_return
add_test(memcached_st
*memc
)
458 char *value
= "when we sanitize";
459 unsigned long long setting_value
;
461 setting_value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
463 rc
= memcached_set(memc
, key
, strlen(key
),
464 value
, strlen(value
),
465 (time_t)0, (uint32_t)0);
466 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
467 memcached_quit(memc
);
468 rc
= memcached_add(memc
, key
, strlen(key
),
469 value
, strlen(value
),
470 (time_t)0, (uint32_t)0);
472 /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */
474 assert(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_STORED
);
476 assert(rc
== MEMCACHED_NOTSTORED
);
481 test_return
add_wrapper(memcached_st
*memc
)
485 for (x
= 0; x
< 10000; x
++)
491 test_return
replace_test(memcached_st
*memc
)
495 char *value
= "when we sanitize";
496 char *original
= "first we insert some data";
498 rc
= memcached_set(memc
, key
, strlen(key
),
499 original
, strlen(original
),
500 (time_t)0, (uint32_t)0);
501 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
503 rc
= memcached_replace(memc
, key
, strlen(key
),
504 value
, strlen(value
),
505 (time_t)0, (uint32_t)0);
506 assert(rc
== MEMCACHED_SUCCESS
);
511 test_return
delete_test(memcached_st
*memc
)
515 char *value
= "when we sanitize";
517 rc
= memcached_set(memc
, key
, strlen(key
),
518 value
, strlen(value
),
519 (time_t)0, (uint32_t)0);
520 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
522 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
523 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
528 test_return
flush_test(memcached_st
*memc
)
532 rc
= memcached_flush(memc
, 0);
533 assert(rc
== MEMCACHED_SUCCESS
);
538 memcached_return
server_function(memcached_st
*ptr
, memcached_server_st
*server
, void *context
)
542 return MEMCACHED_SUCCESS
;
545 test_return
memcached_server_cursor_test(memcached_st
*memc
)
547 char *context
= "foo bad";
548 memcached_server_function callbacks
[1];
550 callbacks
[0]= server_function
;
551 memcached_server_cursor(memc
, callbacks
, context
, 1);
556 test_return
bad_key_test(memcached_st
*memc
)
559 char *key
= "foo bad";
561 size_t string_length
;
566 clone
= memcached_clone(NULL
, memc
);
569 (void)memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
571 string
= memcached_get(clone
, key
, strlen(key
),
572 &string_length
, &flags
, &rc
);
573 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
574 assert(string_length
== 0);
578 (void)memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
579 string
= memcached_get(clone
, key
, strlen(key
),
580 &string_length
, &flags
, &rc
);
581 assert(rc
== MEMCACHED_NOTFOUND
);
582 assert(string_length
== 0);
585 memcached_free(clone
);
590 #define READ_THROUGH_VALUE "set for me"
591 memcached_return
read_through_trigger(memcached_st
*memc
,
592 char *key
, size_t key_length
,
593 memcached_result_st
*result
)
596 return memcached_result_set_value(result
, READ_THROUGH_VALUE
, strlen(READ_THROUGH_VALUE
));
599 test_return
read_through(memcached_st
*memc
)
604 size_t string_length
;
607 string
= memcached_get(memc
, key
, strlen(key
),
608 &string_length
, &flags
, &rc
);
610 assert(rc
== MEMCACHED_NOTFOUND
);
611 assert(string_length
== 0);
614 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_GET_FAILURE
, read_through_trigger
);
615 assert(rc
== MEMCACHED_SUCCESS
);
617 string
= memcached_get(memc
, key
, strlen(key
),
618 &string_length
, &flags
, &rc
);
620 assert(rc
== MEMCACHED_SUCCESS
);
621 assert(string_length
== strlen(READ_THROUGH_VALUE
));
622 assert(!strcmp(READ_THROUGH_VALUE
, string
));
625 string
= memcached_get(memc
, key
, strlen(key
),
626 &string_length
, &flags
, &rc
);
628 assert(rc
== MEMCACHED_SUCCESS
);
629 assert(string_length
== strlen(READ_THROUGH_VALUE
));
630 assert(!strcmp(READ_THROUGH_VALUE
, string
));
636 memcached_return
delete_trigger(memcached_st
*ptr
, char *key
, size_t key_length
)
640 return MEMCACHED_SUCCESS
;
643 test_return
delete_through(memcached_st
*memc
)
645 memcached_trigger_delete_key callback
;
648 callback
= delete_trigger
;
650 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_DELETE_TRIGGER
, callback
);
651 assert(rc
== MEMCACHED_SUCCESS
);
656 test_return
get_test(memcached_st
*memc
)
661 size_t string_length
;
664 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
665 assert(rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_NOTFOUND
);
667 string
= memcached_get(memc
, key
, strlen(key
),
668 &string_length
, &flags
, &rc
);
670 assert(rc
== MEMCACHED_NOTFOUND
);
671 assert(string_length
== 0);
677 test_return
get_test2(memcached_st
*memc
)
681 char *value
= "when we sanitize";
683 size_t string_length
;
686 rc
= memcached_set(memc
, key
, strlen(key
),
687 value
, strlen(value
),
688 (time_t)0, (uint32_t)0);
689 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
691 string
= memcached_get(memc
, key
, strlen(key
),
692 &string_length
, &flags
, &rc
);
695 assert(rc
== MEMCACHED_SUCCESS
);
696 assert(string_length
== strlen(value
));
697 assert(!memcmp(string
, value
, string_length
));
704 test_return
set_test2(memcached_st
*memc
)
708 char *value
= "train in the brain";
709 size_t value_length
= strlen(value
);
712 for (x
= 0; x
< 10; x
++)
714 rc
= memcached_set(memc
, key
, strlen(key
),
716 (time_t)0, (uint32_t)0);
717 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
723 test_return
set_test3(memcached_st
*memc
)
728 size_t value_length
= 8191;
731 value
= (char*)malloc(value_length
);
734 for (x
= 0; x
< value_length
; x
++)
735 value
[x
] = (char) (x
% 127);
737 for (x
= 0; x
< 1; x
++)
739 rc
= memcached_set(memc
, key
, strlen(key
),
741 (time_t)0, (uint32_t)0);
742 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
750 test_return
get_test3(memcached_st
*memc
)
755 size_t value_length
= 8191;
757 size_t string_length
;
761 value
= (char*)malloc(value_length
);
764 for (x
= 0; x
< value_length
; x
++)
765 value
[x
] = (char) (x
% 127);
767 rc
= memcached_set(memc
, key
, strlen(key
),
769 (time_t)0, (uint32_t)0);
770 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
772 string
= memcached_get(memc
, key
, strlen(key
),
773 &string_length
, &flags
, &rc
);
775 assert(rc
== MEMCACHED_SUCCESS
);
777 assert(string_length
== value_length
);
778 assert(!memcmp(string
, value
, string_length
));
786 test_return
get_test4(memcached_st
*memc
)
791 size_t value_length
= 8191;
793 size_t string_length
;
797 value
= (char*)malloc(value_length
);
800 for (x
= 0; x
< value_length
; x
++)
801 value
[x
] = (char) (x
% 127);
803 rc
= memcached_set(memc
, key
, strlen(key
),
805 (time_t)0, (uint32_t)0);
806 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
808 for (x
= 0; x
< 10; x
++)
810 string
= memcached_get(memc
, key
, strlen(key
),
811 &string_length
, &flags
, &rc
);
813 assert(rc
== MEMCACHED_SUCCESS
);
815 assert(string_length
== value_length
);
816 assert(!memcmp(string
, value
, string_length
));
825 /* Do not copy the style of this code, I just access hosts to testthis function */
826 test_return
stats_servername_test(memcached_st
*memc
)
829 memcached_stat_st stat
;
830 rc
= memcached_stat_servername(&stat
, NULL
,
831 memc
->hosts
[0].hostname
,
832 memc
->hosts
[0].port
);
837 test_return
increment_test(memcached_st
*memc
)
844 rc
= memcached_set(memc
, key
, strlen(key
),
845 value
, strlen(value
),
846 (time_t)0, (uint32_t)0);
847 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
849 rc
= memcached_increment(memc
, key
, strlen(key
),
851 assert(rc
== MEMCACHED_SUCCESS
);
852 assert(new_number
== 1);
854 rc
= memcached_increment(memc
, key
, strlen(key
),
856 assert(rc
== MEMCACHED_SUCCESS
);
857 assert(new_number
== 2);
862 test_return
decrement_test(memcached_st
*memc
)
869 rc
= memcached_set(memc
, key
, strlen(key
),
870 value
, strlen(value
),
871 (time_t)0, (uint32_t)0);
872 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
874 rc
= memcached_decrement(memc
, key
, strlen(key
),
876 assert(rc
== MEMCACHED_SUCCESS
);
877 assert(new_number
== 2);
879 rc
= memcached_decrement(memc
, key
, strlen(key
),
881 assert(rc
== MEMCACHED_SUCCESS
);
882 assert(new_number
== 1);
887 test_return
quit_test(memcached_st
*memc
)
891 char *value
= "sanford and sun";
893 rc
= memcached_set(memc
, key
, strlen(key
),
894 value
, strlen(value
),
895 (time_t)10, (uint32_t)3);
896 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
897 memcached_quit(memc
);
899 rc
= memcached_set(memc
, key
, strlen(key
),
900 value
, strlen(value
),
901 (time_t)50, (uint32_t)9);
902 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
907 test_return
mget_result_test(memcached_st
*memc
)
910 char *keys
[]= {"fudge", "son", "food"};
911 size_t key_length
[]= {5, 3, 4};
914 memcached_result_st results_obj
;
915 memcached_result_st
*results
;
917 results
= memcached_result_create(memc
, &results_obj
);
919 assert(&results_obj
== results
);
921 /* We need to empty the server before continueing test */
922 rc
= memcached_flush(memc
, 0);
923 assert(rc
== MEMCACHED_SUCCESS
);
925 rc
= memcached_mget(memc
, keys
, key_length
, 3);
926 assert(rc
== MEMCACHED_SUCCESS
);
928 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
933 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
935 assert(rc
== MEMCACHED_END
);
937 for (x
= 0; x
< 3; x
++)
939 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
940 keys
[x
], key_length
[x
],
941 (time_t)50, (uint32_t)9);
942 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
945 rc
= memcached_mget(memc
, keys
, key_length
, 3);
946 assert(rc
== MEMCACHED_SUCCESS
);
948 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
951 assert(&results_obj
== results
);
952 assert(rc
== MEMCACHED_SUCCESS
);
953 assert(memcached_result_key_length(results
) == memcached_result_length(results
));
954 assert(!memcmp(memcached_result_key_value(results
),
955 memcached_result_value(results
),
956 memcached_result_length(results
)));
959 memcached_result_free(&results_obj
);
964 test_return
mget_result_alloc_test(memcached_st
*memc
)
967 char *keys
[]= {"fudge", "son", "food"};
968 size_t key_length
[]= {5, 3, 4};
971 memcached_result_st
*results
;
973 /* We need to empty the server before continueing test */
974 rc
= memcached_flush(memc
, 0);
975 assert(rc
== MEMCACHED_SUCCESS
);
977 rc
= memcached_mget(memc
, keys
, key_length
, 3);
978 assert(rc
== MEMCACHED_SUCCESS
);
980 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)) != NULL
)
985 assert(rc
== MEMCACHED_END
);
987 for (x
= 0; x
< 3; x
++)
989 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
990 keys
[x
], key_length
[x
],
991 (time_t)50, (uint32_t)9);
992 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
995 rc
= memcached_mget(memc
, keys
, key_length
, 3);
996 assert(rc
== MEMCACHED_SUCCESS
);
999 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1002 assert(rc
== MEMCACHED_SUCCESS
);
1003 assert(memcached_result_key_length(results
) == memcached_result_length(results
));
1004 assert(!memcmp(memcached_result_key_value(results
),
1005 memcached_result_value(results
),
1006 memcached_result_length(results
)));
1007 memcached_result_free(results
);
1014 /* Count the results */
1015 unsigned int callback_counter(memcached_st
*ptr
, memcached_result_st
*result
, void *context
)
1017 unsigned int *counter
= (unsigned int *)context
;
1019 *counter
= *counter
+ 1;
1024 test_return
mget_result_function(memcached_st
*memc
)
1026 memcached_return rc
;
1027 char *keys
[]= {"fudge", "son", "food"};
1028 size_t key_length
[]= {5, 3, 4};
1030 unsigned int counter
;
1031 memcached_execute_function callbacks
[1];
1033 /* We need to empty the server before continueing test */
1034 rc
= memcached_flush(memc
, 0);
1035 for (x
= 0; x
< 3; x
++)
1037 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1038 keys
[x
], key_length
[x
],
1039 (time_t)50, (uint32_t)9);
1040 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1043 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1044 assert(rc
== MEMCACHED_SUCCESS
);
1046 callbacks
[0]= &callback_counter
;
1048 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
1050 assert(counter
== 3);
1055 test_return
mget_test(memcached_st
*memc
)
1057 memcached_return rc
;
1058 char *keys
[]= {"fudge", "son", "food"};
1059 size_t key_length
[]= {5, 3, 4};
1063 char return_key
[MEMCACHED_MAX_KEY
];
1064 size_t return_key_length
;
1066 size_t return_value_length
;
1068 /* We need to empty the server before continueing test */
1069 rc
= memcached_flush(memc
, 0);
1070 assert(rc
== MEMCACHED_SUCCESS
);
1072 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1073 assert(rc
== MEMCACHED_SUCCESS
);
1075 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1076 &return_value_length
, &flags
, &rc
)) != NULL
)
1078 assert(return_value
);
1080 assert(!return_value
);
1081 assert(return_value_length
== 0);
1082 assert(rc
== MEMCACHED_END
);
1084 for (x
= 0; x
< 3; x
++)
1086 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1087 keys
[x
], key_length
[x
],
1088 (time_t)50, (uint32_t)9);
1089 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1092 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1093 assert(rc
== MEMCACHED_SUCCESS
);
1096 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1097 &return_value_length
, &flags
, &rc
)))
1099 assert(return_value
);
1100 assert(rc
== MEMCACHED_SUCCESS
);
1101 assert(return_key_length
== return_value_length
);
1102 assert(!memcmp(return_value
, return_key
, return_value_length
));
1110 test_return
get_stats_keys(memcached_st
*memc
)
1114 memcached_stat_st stat
;
1115 memcached_return rc
;
1117 list
= memcached_stat_get_keys(memc
, &stat
, &rc
);
1118 assert(rc
== MEMCACHED_SUCCESS
);
1119 for (ptr
= list
; *ptr
; ptr
++)
1128 test_return
version_string_test(memcached_st
*memc
)
1130 const char *version_string
;
1132 version_string
= memcached_lib_version();
1134 assert(!strcmp(version_string
, LIBMEMCACHED_VERSION_STRING
));
1139 test_return
get_stats(memcached_st
*memc
)
1144 memcached_return rc
;
1145 memcached_stat_st
*stat
;
1147 stat
= memcached_stat(memc
, NULL
, &rc
);
1148 assert(rc
== MEMCACHED_SUCCESS
);
1150 assert(rc
== MEMCACHED_SUCCESS
);
1153 for (x
= 0; x
< memcached_server_count(memc
); x
++)
1155 list
= memcached_stat_get_keys(memc
, stat
+x
, &rc
);
1156 assert(rc
== MEMCACHED_SUCCESS
);
1157 for (ptr
= list
; *ptr
; ptr
++);
1162 memcached_stat_free(NULL
, stat
);
1167 test_return
add_host_test(memcached_st
*memc
)
1170 memcached_server_st
*servers
;
1171 memcached_return rc
;
1172 char servername
[]= "0.example.com";
1174 servers
= memcached_server_list_append(NULL
, servername
, 400, &rc
);
1176 assert(1 == memcached_server_list_count(servers
));
1178 for (x
= 2; x
< 20; x
++)
1180 char buffer
[SMALL_STRING_LEN
];
1182 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
1183 servers
= memcached_server_list_append(servers
, buffer
, 401,
1185 assert(rc
== MEMCACHED_SUCCESS
);
1186 assert(x
== memcached_server_list_count(servers
));
1189 rc
= memcached_server_push(memc
, servers
);
1190 assert(rc
== MEMCACHED_SUCCESS
);
1191 rc
= memcached_server_push(memc
, servers
);
1192 assert(rc
== MEMCACHED_SUCCESS
);
1194 memcached_server_list_free(servers
);
1199 memcached_return
clone_test_callback(memcached_st
*parent
, memcached_st
*clone
)
1201 return MEMCACHED_SUCCESS
;
1204 memcached_return
cleanup_test_callback(memcached_st
*ptr
)
1206 return MEMCACHED_SUCCESS
;
1209 test_return
callback_test(memcached_st
*memc
)
1211 /* Test User Data */
1215 memcached_return rc
;
1217 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_USER_DATA
, &x
);
1218 assert(rc
== MEMCACHED_SUCCESS
);
1219 test_ptr
= (int *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_USER_DATA
, &rc
);
1220 assert(*test_ptr
== x
);
1223 /* Test Clone Callback */
1225 memcached_clone_func temp_function
;
1226 memcached_return rc
;
1228 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, clone_test_callback
);
1229 assert(rc
== MEMCACHED_SUCCESS
);
1230 temp_function
= (memcached_clone_func
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1231 assert(temp_function
== clone_test_callback
);
1234 /* Test Cleanup Callback */
1236 memcached_cleanup_func temp_function
;
1237 memcached_return rc
;
1239 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, cleanup_test_callback
);
1240 assert(rc
== MEMCACHED_SUCCESS
);
1241 temp_function
= (memcached_cleanup_func
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1242 assert(temp_function
== cleanup_test_callback
);
1248 /* We don't test the behavior itself, we test the switches */
1249 test_return
behavior_test(memcached_st
*memc
)
1251 unsigned long long value
;
1252 unsigned int set
= 1;
1254 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1255 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1258 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1259 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1262 set
= MEMCACHED_HASH_MD5
;
1263 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1264 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1265 assert(value
== MEMCACHED_HASH_MD5
);
1269 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1270 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1273 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1274 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1277 set
= MEMCACHED_HASH_DEFAULT
;
1278 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1279 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1280 assert(value
== MEMCACHED_HASH_DEFAULT
);
1282 set
= MEMCACHED_HASH_CRC
;
1283 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1284 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1285 assert(value
== MEMCACHED_HASH_CRC
);
1287 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1290 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1296 /* Test case provided by Cal Haldenbrand */
1297 test_return
user_supplied_bug1(memcached_st
*memc
)
1299 unsigned int setter
= 1;
1302 unsigned long long total
= 0;
1305 char randomstuff
[6 * 1024];
1306 memcached_return rc
;
1308 memset(randomstuff
, 0, 6 * 1024);
1310 /* We just keep looking at the same values over and over */
1313 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1314 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1318 for (x
= 0 ; total
< 20 * 1024576 ; x
++ )
1322 size
= (rand() % ( 5 * 1024 ) ) + 400;
1323 memset(randomstuff
, 0, 6 * 1024);
1324 assert(size
< 6 * 1024); /* Being safe here */
1326 for (j
= 0 ; j
< size
;j
++)
1327 randomstuff
[j
] = (char) (rand() % 26) + 97;
1330 sprintf(key
, "%d", x
);
1331 rc
= memcached_set(memc
, key
, strlen(key
),
1332 randomstuff
, strlen(randomstuff
), 10, 0);
1333 /* If we fail, lets try again */
1334 if (rc
!= MEMCACHED_SUCCESS
&& rc
!= MEMCACHED_BUFFERED
)
1335 rc
= memcached_set(memc
, key
, strlen(key
),
1336 randomstuff
, strlen(randomstuff
), 10, 0);
1337 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1343 /* Test case provided by Cal Haldenbrand */
1344 test_return
user_supplied_bug2(memcached_st
*memc
)
1347 unsigned int setter
;
1349 unsigned long long total
;
1352 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1353 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1355 setter
= 20 * 1024576;
1356 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1357 setter
= 20 * 1024576;
1358 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1359 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1360 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1362 for (x
= 0, errors
= 0, total
= 0 ; total
< 20 * 1024576 ; x
++)
1365 for (x
= 0, errors
= 0, total
= 0 ; total
< 24576 ; x
++)
1367 memcached_return rc
= MEMCACHED_SUCCESS
;
1368 char buffer
[SMALL_STRING_LEN
];
1373 memset(buffer
, 0, SMALL_STRING_LEN
);
1375 snprintf(buffer
, SMALL_STRING_LEN
, "%u", x
);
1376 getval
= memcached_get(memc
, buffer
, strlen(buffer
),
1377 &val_len
, &flags
, &rc
);
1378 if (rc
!= MEMCACHED_SUCCESS
)
1380 if (rc
== MEMCACHED_NOTFOUND
)
1384 WATCHPOINT_ERROR(rc
);
1398 /* Do a large mget() over all the keys we think exist */
1399 #define KEY_COUNT 3000 // * 1024576
1400 test_return
user_supplied_bug3(memcached_st
*memc
)
1402 memcached_return rc
;
1403 unsigned int setter
;
1406 size_t key_lengths
[KEY_COUNT
];
1409 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1410 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1412 setter
= 20 * 1024576;
1413 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1414 setter
= 20 * 1024576;
1415 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1416 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1417 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1420 keys
= (char **)malloc(sizeof(char *) * KEY_COUNT
);
1422 memset(keys
, 0, (sizeof(char *) * KEY_COUNT
));
1423 for (x
= 0; x
< KEY_COUNT
; x
++)
1427 snprintf(buffer
, 30, "%u", x
);
1428 keys
[x
]= strdup(buffer
);
1429 key_lengths
[x
]= strlen(keys
[x
]);
1432 rc
= memcached_mget(memc
, keys
, key_lengths
, KEY_COUNT
);
1433 assert(rc
== MEMCACHED_SUCCESS
);
1435 /* Turn this into a help function */
1437 char return_key
[MEMCACHED_MAX_KEY
];
1438 size_t return_key_length
;
1440 size_t return_value_length
;
1443 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1444 &return_value_length
, &flags
, &rc
)))
1446 assert(return_value
);
1447 assert(rc
== MEMCACHED_SUCCESS
);
1452 for (x
= 0; x
< KEY_COUNT
; x
++)
1459 /* Make sure we behave properly if server list has no values */
1460 test_return
user_supplied_bug4(memcached_st
*memc
)
1462 memcached_return rc
;
1463 char *keys
[]= {"fudge", "son", "food"};
1464 size_t key_length
[]= {5, 3, 4};
1467 char return_key
[MEMCACHED_MAX_KEY
];
1468 size_t return_key_length
;
1470 size_t return_value_length
;
1472 /* Here we free everything before running a bunch of mget tests */
1474 memcached_server_list_free(memc
->hosts
);
1476 memc
->number_of_hosts
= 0;
1480 /* We need to empty the server before continueing test */
1481 rc
= memcached_flush(memc
, 0);
1482 assert(rc
== MEMCACHED_NO_SERVERS
);
1484 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1485 assert(rc
== MEMCACHED_NO_SERVERS
);
1487 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1488 &return_value_length
, &flags
, &rc
)) != NULL
)
1490 assert(return_value
);
1492 assert(!return_value
);
1493 assert(return_value_length
== 0);
1494 assert(rc
== MEMCACHED_NO_SERVERS
);
1496 for (x
= 0; x
< 3; x
++)
1498 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1499 keys
[x
], key_length
[x
],
1500 (time_t)50, (uint32_t)9);
1501 assert(rc
== MEMCACHED_NO_SERVERS
);
1504 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1505 assert(rc
== MEMCACHED_NO_SERVERS
);
1508 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1509 &return_value_length
, &flags
, &rc
)))
1511 assert(return_value
);
1512 assert(rc
== MEMCACHED_SUCCESS
);
1513 assert(return_key_length
== return_value_length
);
1514 assert(!memcmp(return_value
, return_key
, return_value_length
));
1522 #define VALUE_SIZE_BUG5 1048064
1523 test_return
user_supplied_bug5(memcached_st
*memc
)
1525 memcached_return rc
;
1526 char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1527 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1528 char return_key
[MEMCACHED_MAX_KEY
];
1529 size_t return_key_length
;
1531 size_t value_length
;
1535 char insert_data
[VALUE_SIZE_BUG5
];
1537 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1538 insert_data
[x
]= rand();
1540 memcached_flush(memc
, 0);
1541 value
= memcached_get(memc
, keys
[0], key_length
[0],
1542 &value_length
, &flags
, &rc
);
1543 assert(value
== NULL
);
1544 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1547 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1548 &value_length
, &flags
, &rc
)))
1552 for (x
= 0; x
< 4; x
++)
1554 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1555 insert_data
, VALUE_SIZE_BUG5
,
1556 (time_t)0, (uint32_t)0);
1557 assert(rc
== MEMCACHED_SUCCESS
);
1560 for (x
= 0; x
< 10; x
++)
1562 value
= memcached_get(memc
, keys
[0], key_length
[0],
1563 &value_length
, &flags
, &rc
);
1567 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1569 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1570 &value_length
, &flags
, &rc
)))
1581 test_return
user_supplied_bug6(memcached_st
*memc
)
1583 memcached_return rc
;
1584 char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1585 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1586 char return_key
[MEMCACHED_MAX_KEY
];
1587 size_t return_key_length
;
1589 size_t value_length
;
1593 char insert_data
[VALUE_SIZE_BUG5
];
1595 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1596 insert_data
[x
]= rand();
1598 memcached_flush(memc
, 0);
1599 value
= memcached_get(memc
, keys
[0], key_length
[0],
1600 &value_length
, &flags
, &rc
);
1601 assert(value
== NULL
);
1602 assert(rc
== MEMCACHED_NOTFOUND
);
1603 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1604 assert(rc
== MEMCACHED_SUCCESS
);
1607 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1608 &value_length
, &flags
, &rc
)))
1611 assert(rc
== MEMCACHED_END
);
1613 for (x
= 0; x
< 4; x
++)
1615 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1616 insert_data
, VALUE_SIZE_BUG5
,
1617 (time_t)0, (uint32_t)0);
1618 assert(rc
== MEMCACHED_SUCCESS
);
1621 for (x
= 0; x
< 2; x
++)
1623 value
= memcached_get(memc
, keys
[0], key_length
[0],
1624 &value_length
, &flags
, &rc
);
1628 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1629 assert(rc
== MEMCACHED_SUCCESS
);
1631 /* We test for purge of partial complete fetches */
1632 for (count
= 3; count
; count
--)
1634 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1635 &value_length
, &flags
, &rc
);
1636 assert(rc
== MEMCACHED_SUCCESS
);
1637 assert(!(memcmp(value
, insert_data
, value_length
)));
1638 assert(value_length
);
1646 test_return
user_supplied_bug8(memcached_st
*memc
)
1648 memcached_return rc
;
1650 memcached_st
*clone
;
1652 memcached_server_st
*servers
;
1653 char *server_list
= "memcache1.memcache.bk.sapo.pt:11211, memcache1.memcache.bk.sapo.pt:11212, memcache1.memcache.bk.sapo.pt:11213, memcache1.memcache.bk.sapo.pt:11214, memcache2.memcache.bk.sapo.pt:11211, memcache2.memcache.bk.sapo.pt:11212, memcache2.memcache.bk.sapo.pt:11213, memcache2.memcache.bk.sapo.pt:11214";
1655 servers
= memcached_servers_parse(server_list
);
1658 mine
= memcached_create(NULL
);
1659 rc
= memcached_server_push(mine
, servers
);
1660 assert(rc
== MEMCACHED_SUCCESS
);
1661 memcached_server_list_free(servers
);
1664 clone
= memcached_clone(NULL
, mine
);
1666 memcached_quit(mine
);
1667 memcached_quit(clone
);
1670 memcached_free(mine
);
1671 memcached_free(clone
);
1676 /* Test flag store/retrieve */
1677 test_return
user_supplied_bug7(memcached_st
*memc
)
1679 memcached_return rc
;
1680 char *keys
= "036790384900";
1681 size_t key_length
= strlen("036790384900");
1682 char return_key
[MEMCACHED_MAX_KEY
];
1683 size_t return_key_length
;
1685 size_t value_length
;
1688 char insert_data
[VALUE_SIZE_BUG5
];
1690 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1691 insert_data
[x
]= rand();
1693 memcached_flush(memc
, 0);
1696 rc
= memcached_set(memc
, keys
, key_length
,
1697 insert_data
, VALUE_SIZE_BUG5
,
1699 assert(rc
== MEMCACHED_SUCCESS
);
1702 value
= memcached_get(memc
, keys
, key_length
,
1703 &value_length
, &flags
, &rc
);
1704 assert(flags
== 245);
1708 rc
= memcached_mget(memc
, &keys
, &key_length
, 1);
1711 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1712 &value_length
, &flags
, &rc
);
1713 assert(flags
== 245);
1721 test_return
user_supplied_bug9(memcached_st
*memc
)
1723 memcached_return rc
;
1724 char *keys
[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
1725 size_t key_length
[3];
1730 char return_key
[MEMCACHED_MAX_KEY
];
1731 size_t return_key_length
;
1733 size_t return_value_length
;
1736 key_length
[0]= strlen("UDATA:edevil@sapo.pt");
1737 key_length
[1]= strlen("fudge&*@#");
1738 key_length
[2]= strlen("for^#@&$not");
1741 for (x
= 0; x
< 3; x
++)
1743 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1744 keys
[x
], key_length
[x
],
1745 (time_t)50, (uint32_t)9);
1746 assert(rc
== MEMCACHED_SUCCESS
);
1749 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1750 assert(rc
== MEMCACHED_SUCCESS
);
1752 /* We need to empty the server before continueing test */
1753 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1754 &return_value_length
, &flags
, &rc
)) != NULL
)
1756 assert(return_value
);
1765 /* We are testing with aggressive timeout to get failures */
1766 test_return
user_supplied_bug10(memcached_st
*memc
)
1770 size_t value_length
= 512;
1773 memcached_return rc
;
1774 unsigned int set
= 1;
1775 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
1778 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1779 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1781 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
1783 value
= (char*)malloc(value_length
* sizeof(char));
1785 for (x
= 0; x
< value_length
; x
++)
1786 value
[x
]= (char) (x
% 127);
1788 for (x
= 1; x
<= 100000; ++x
)
1790 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
1792 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_WRITE_FAILURE
|| rc
== MEMCACHED_BUFFERED
);
1794 if (rc
== MEMCACHED_WRITE_FAILURE
)
1799 memcached_free(mclone
);
1805 We are looking failures in the async protocol
1807 test_return
user_supplied_bug11(memcached_st
*memc
)
1811 size_t value_length
= 512;
1814 memcached_return rc
;
1815 unsigned int set
= 1;
1817 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
1819 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1820 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1822 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
1824 timeout
= (int32_t)memcached_behavior_get(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
1826 assert(timeout
== -1);
1828 value
= (char*)malloc(value_length
* sizeof(char));
1830 for (x
= 0; x
< value_length
; x
++)
1831 value
[x
]= (char) (x
% 127);
1833 for (x
= 1; x
<= 100000; ++x
)
1835 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
1839 memcached_free(mclone
);
1845 Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
1847 test_return
user_supplied_bug12(memcached_st
*memc
)
1849 memcached_return rc
;
1851 size_t value_length
;
1853 uint64_t number_value
;
1855 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
1856 &value_length
, &flags
, &rc
);
1857 assert(value
== NULL
);
1858 assert(rc
== MEMCACHED_NOTFOUND
);
1860 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
1863 assert(value
== NULL
);
1864 assert(rc
== MEMCACHED_NOTFOUND
);
1866 rc
= memcached_set(memc
, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
1868 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
1869 &value_length
, &flags
, &rc
);
1871 assert(rc
== MEMCACHED_SUCCESS
);
1874 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
1876 assert(number_value
== 2);
1877 assert(rc
== MEMCACHED_SUCCESS
);
1883 Bug found where command total one more than MEMCACHED_MAX_BUFFER
1884 set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
1886 test_return
user_supplied_bug13(memcached_st
*memc
)
1888 char key
[] = "key34567890";
1890 memcached_return rc
;
1891 size_t overflowSize
;
1893 char commandFirst
[]= "set key34567890 0 0 ";
1894 char commandLast
[] = " \r\n"; /* first line of command sent to server */
1895 size_t commandLength
;
1898 commandLength
= strlen(commandFirst
) + strlen(commandLast
) + 4; /* 4 is number of characters in size, probably 8196 */
1900 overflowSize
= MEMCACHED_MAX_BUFFER
- commandLength
;
1902 for (testSize
= overflowSize
- 1; testSize
< overflowSize
+ 1; testSize
++)
1904 overflow
= malloc(testSize
);
1905 assert(overflow
!= NULL
);
1907 memset(overflow
, 'x', testSize
);
1908 rc
= memcached_set(memc
, key
, strlen(key
),
1909 overflow
, testSize
, 0, 0);
1910 assert(rc
== MEMCACHED_SUCCESS
);
1919 Test values of many different sizes
1920 Bug found where command total one more than MEMCACHED_MAX_BUFFER
1921 set key34567890 0 0 8169 \r\n
1922 is sent followed by buffer of size 8169, followed by 8169
1924 test_return
user_supplied_bug14(memcached_st
*memc
)
1927 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1928 memcached_return rc
;
1931 size_t value_length
= 18000;
1933 size_t string_length
;
1936 size_t current_length
;
1938 value
= (char*)malloc(value_length
);
1941 for (x
= 0; x
< value_length
; x
++)
1942 value
[x
] = (char) (x
% 127);
1944 for (current_length
= 0; current_length
< value_length
; current_length
++)
1946 rc
= memcached_set(memc
, key
, strlen(key
),
1947 value
, current_length
,
1948 (time_t)0, (uint32_t)0);
1949 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1951 string
= memcached_get(memc
, key
, strlen(key
),
1952 &string_length
, &flags
, &rc
);
1954 assert(rc
== MEMCACHED_SUCCESS
);
1955 assert(string_length
== current_length
);
1956 assert(!memcmp(string
, value
, string_length
));
1967 Look for zero length value problems
1969 test_return
user_supplied_bug15(memcached_st
*memc
)
1972 memcached_return rc
;
1978 for (x
= 0; x
< 2; x
++)
1980 rc
= memcached_set(memc
, key
, strlen(key
),
1982 (time_t)0, (uint32_t)0);
1984 assert(rc
== MEMCACHED_SUCCESS
);
1986 value
= memcached_get(memc
, key
, strlen(key
),
1987 &length
, &flags
, &rc
);
1989 assert(rc
== MEMCACHED_SUCCESS
);
1990 assert(value
== NULL
);
1991 assert(length
== 0);
1994 value
= memcached_get(memc
, key
, strlen(key
),
1995 &length
, &flags
, &rc
);
1997 assert(rc
== MEMCACHED_SUCCESS
);
1998 assert(value
== NULL
);
1999 assert(length
== 0);
2006 test_return
result_static(memcached_st
*memc
)
2008 memcached_result_st result
;
2009 memcached_result_st
*result_ptr
;
2011 result_ptr
= memcached_result_create(memc
, &result
);
2012 assert(result
.is_allocated
== MEMCACHED_NOT_ALLOCATED
);
2014 memcached_result_free(&result
);
2019 test_return
result_alloc(memcached_st
*memc
)
2021 memcached_result_st
*result
;
2023 result
= memcached_result_create(memc
, NULL
);
2025 memcached_result_free(result
);
2030 test_return
string_static_null(memcached_st
*memc
)
2032 memcached_string_st string
;
2033 memcached_string_st
*string_ptr
;
2035 string_ptr
= memcached_string_create(memc
, &string
, 0);
2036 assert(string
.is_allocated
== MEMCACHED_NOT_ALLOCATED
);
2038 memcached_string_free(&string
);
2043 test_return
string_alloc_null(memcached_st
*memc
)
2045 memcached_string_st
*string
;
2047 string
= memcached_string_create(memc
, NULL
, 0);
2049 memcached_string_free(string
);
2054 test_return
string_alloc_with_size(memcached_st
*memc
)
2056 memcached_string_st
*string
;
2058 string
= memcached_string_create(memc
, NULL
, 1024);
2060 memcached_string_free(string
);
2065 test_return
string_alloc_with_size_toobig(memcached_st
*memc
)
2067 memcached_string_st
*string
;
2069 string
= memcached_string_create(memc
, NULL
, INT64_MAX
);
2070 assert(string
== NULL
);
2075 test_return
string_alloc_append(memcached_st
*memc
)
2078 char buffer
[SMALL_STRING_LEN
];
2079 memcached_string_st
*string
;
2081 /* Ring the bell! */
2082 memset(buffer
, 6, SMALL_STRING_LEN
);
2084 string
= memcached_string_create(memc
, NULL
, 100);
2087 for (x
= 0; x
< 1024; x
++)
2089 memcached_return rc
;
2090 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
2091 assert(rc
== MEMCACHED_SUCCESS
);
2093 memcached_string_free(string
);
2098 test_return
string_alloc_append_toobig(memcached_st
*memc
)
2100 memcached_return rc
;
2102 char buffer
[SMALL_STRING_LEN
];
2103 memcached_string_st
*string
;
2105 /* Ring the bell! */
2106 memset(buffer
, 6, SMALL_STRING_LEN
);
2108 string
= memcached_string_create(memc
, NULL
, 100);
2111 for (x
= 0; x
< 1024; x
++)
2113 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
2114 assert(rc
== MEMCACHED_SUCCESS
);
2116 rc
= memcached_string_append(string
, buffer
, INT64_MAX
);
2117 assert(rc
== MEMCACHED_MEMORY_ALLOCATION_FAILURE
);
2118 memcached_string_free(string
);
2123 test_return
cleanup_pairs(memcached_st
*memc
)
2125 pairs_free(global_pairs
);
2130 test_return
generate_pairs(memcached_st
*memc
)
2132 unsigned long long x
;
2133 global_pairs
= pairs_generate(GLOBAL_COUNT
, 400);
2134 global_count
= GLOBAL_COUNT
;
2136 for (x
= 0; x
< global_count
; x
++)
2138 global_keys
[x
]= global_pairs
[x
].key
;
2139 global_keys_length
[x
]= global_pairs
[x
].key_length
;
2145 test_return
generate_large_pairs(memcached_st
*memc
)
2147 unsigned long long x
;
2148 global_pairs
= pairs_generate(GLOBAL2_COUNT
, MEMCACHED_MAX_BUFFER
+10);
2149 global_count
= GLOBAL2_COUNT
;
2151 for (x
= 0; x
< global_count
; x
++)
2153 global_keys
[x
]= global_pairs
[x
].key
;
2154 global_keys_length
[x
]= global_pairs
[x
].key_length
;
2160 test_return
generate_data(memcached_st
*memc
)
2162 execute_set(memc
, global_pairs
, global_count
);
2167 test_return
generate_buffer_data(memcached_st
*memc
)
2172 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
2173 generate_data(memc
);
2178 test_return
get_read_count(memcached_st
*memc
)
2181 memcached_return rc
;
2182 memcached_st
*clone
;
2184 clone
= memcached_clone(NULL
, memc
);
2187 memcached_server_add(clone
, "localhost", 6666);
2191 size_t return_value_length
;
2195 for (x
= count
= 0; x
< global_count
; x
++)
2197 return_value
= memcached_get(clone
, global_keys
[x
], global_keys_length
[x
],
2198 &return_value_length
, &flags
, &rc
);
2199 if (rc
== MEMCACHED_SUCCESS
)
2206 fprintf(stderr
, "\t%u -> %u", global_count
, count
);
2209 memcached_free(clone
);
2214 test_return
get_read(memcached_st
*memc
)
2217 memcached_return rc
;
2221 size_t return_value_length
;
2224 for (x
= 0; x
< global_count
; x
++)
2226 return_value
= memcached_get(memc
, global_keys
[x
], global_keys_length
[x
],
2227 &return_value_length
, &flags
, &rc
);
2229 assert(return_value);
2230 assert(rc == MEMCACHED_SUCCESS);
2232 if (rc
== MEMCACHED_SUCCESS
&& return_value
)
2240 test_return
mget_read(memcached_st
*memc
)
2242 memcached_return rc
;
2244 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2245 assert(rc
== MEMCACHED_SUCCESS
);
2246 /* Turn this into a help function */
2248 char return_key
[MEMCACHED_MAX_KEY
];
2249 size_t return_key_length
;
2251 size_t return_value_length
;
2254 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2255 &return_value_length
, &flags
, &rc
)))
2257 assert(return_value
);
2258 assert(rc
== MEMCACHED_SUCCESS
);
2266 test_return
mget_read_result(memcached_st
*memc
)
2268 memcached_return rc
;
2270 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2271 assert(rc
== MEMCACHED_SUCCESS
);
2272 /* Turn this into a help function */
2274 memcached_result_st results_obj
;
2275 memcached_result_st
*results
;
2277 results
= memcached_result_create(memc
, &results_obj
);
2279 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
2282 assert(rc
== MEMCACHED_SUCCESS
);
2285 memcached_result_free(&results_obj
);
2291 test_return
mget_read_function(memcached_st
*memc
)
2293 memcached_return rc
;
2294 unsigned int counter
;
2295 unsigned int (*callbacks
[1])(memcached_st
*, memcached_result_st
*, void *);
2297 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2298 assert(rc
== MEMCACHED_SUCCESS
);
2300 callbacks
[0]= &callback_counter
;
2302 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
2307 test_return
delete_generate(memcached_st
*memc
)
2311 for (x
= 0; x
< global_count
; x
++)
2313 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
2319 test_return
delete_buffer_generate(memcached_st
*memc
)
2325 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
2327 for (x
= 0; x
< global_count
; x
++)
2329 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
2335 test_return
free_data(memcached_st
*memc
)
2337 pairs_free(global_pairs
);
2342 test_return
add_host_test1(memcached_st
*memc
)
2345 memcached_return rc
;
2346 char servername
[]= "0.example.com";
2347 memcached_server_st
*servers
;
2349 servers
= memcached_server_list_append(NULL
, servername
, 400, &rc
);
2351 assert(1 == memcached_server_list_count(servers
));
2353 for (x
= 2; x
< 20; x
++)
2355 char buffer
[SMALL_STRING_LEN
];
2357 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
2358 servers
= memcached_server_list_append(servers
, buffer
, 401,
2360 assert(rc
== MEMCACHED_SUCCESS
);
2361 assert(x
== memcached_server_list_count(servers
));
2364 rc
= memcached_server_push(memc
, servers
);
2365 assert(rc
== MEMCACHED_SUCCESS
);
2366 rc
= memcached_server_push(memc
, servers
);
2367 assert(rc
== MEMCACHED_SUCCESS
);
2369 memcached_server_list_free(servers
);
2374 memcached_return
pre_nonblock(memcached_st
*memc
)
2376 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
2378 return MEMCACHED_SUCCESS
;
2381 memcached_return
pre_murmur(memcached_st
*memc
)
2383 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
2385 return MEMCACHED_SUCCESS
;
2388 memcached_return
pre_md5(memcached_st
*memc
)
2390 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MD5
);
2392 return MEMCACHED_SUCCESS
;
2395 memcached_return
pre_crc(memcached_st
*memc
)
2397 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_CRC
);
2399 return MEMCACHED_SUCCESS
;
2402 memcached_return
pre_hsieh(memcached_st
*memc
)
2404 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_HSIEH
);
2406 return MEMCACHED_SUCCESS
;
2409 memcached_return
pre_hash_fnv1_64(memcached_st
*memc
)
2411 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_64
);
2413 return MEMCACHED_SUCCESS
;
2416 memcached_return
pre_hash_fnv1a_64(memcached_st
*memc
)
2418 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_64
);
2420 return MEMCACHED_SUCCESS
;
2423 memcached_return
pre_hash_fnv1_32(memcached_st
*memc
)
2425 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_32
);
2427 return MEMCACHED_SUCCESS
;
2430 memcached_return
pre_hash_fnv1a_32(memcached_st
*memc
)
2432 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_32
);
2434 return MEMCACHED_SUCCESS
;
2437 memcached_return
pre_behavior_ketama(memcached_st
*memc
)
2439 memcached_return rc
;
2442 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA
, 1);
2443 assert(rc
== MEMCACHED_SUCCESS
);
2445 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA
);
2448 return MEMCACHED_SUCCESS
;
2451 void my_free(memcached_st
*ptr
, void *mem
)
2456 void *my_malloc(memcached_st
*ptr
, const size_t size
)
2458 return malloc(size
);
2461 void *my_realloc(memcached_st
*ptr
, void *mem
, const size_t size
)
2463 return realloc(mem
, size
);
2466 memcached_return
set_memory_alloc(memcached_st
*memc
)
2469 memcached_malloc_function test_ptr
;
2470 memcached_return rc
;
2472 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &my_malloc
);
2473 assert(rc
== MEMCACHED_SUCCESS
);
2474 test_ptr
= (memcached_malloc_function
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
2475 assert(rc
== MEMCACHED_SUCCESS
);
2476 assert(test_ptr
== my_malloc
);
2480 memcached_realloc_function test_ptr
;
2481 memcached_return rc
;
2483 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &my_realloc
);
2484 assert(rc
== MEMCACHED_SUCCESS
);
2485 test_ptr
= (memcached_realloc_function
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
2486 assert(rc
== MEMCACHED_SUCCESS
);
2487 assert(test_ptr
== my_realloc
);
2491 memcached_free_function test_ptr
;
2492 memcached_return rc
;
2494 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, my_free
);
2495 assert(rc
== MEMCACHED_SUCCESS
);
2496 test_ptr
= (memcached_free_function
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
2497 assert(rc
== MEMCACHED_SUCCESS
);
2498 assert(test_ptr
== my_free
);
2501 return MEMCACHED_SUCCESS
;
2504 memcached_return
enable_wheel(memcached_st
*memc
)
2506 memcached_server_distribution value
= MEMCACHED_DISTRIBUTION_CONSISTENT_WHEEL
;
2507 memcached_hash hash
;
2508 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
2511 value
= (memcached_server_distribution
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
2512 assert(value
== MEMCACHED_DISTRIBUTION_CONSISTENT_WHEEL
);
2514 hash
= (memcached_hash
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
2515 assert(hash
== MEMCACHED_HASH_HSIEH
);
2518 return MEMCACHED_SUCCESS
;
2521 memcached_return
enable_consistent(memcached_st
*memc
)
2523 memcached_server_distribution value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
2524 memcached_hash hash
;
2525 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
2528 value
= (memcached_server_distribution
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
2529 assert(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
2531 hash
= (memcached_hash
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
2532 assert(hash
== MEMCACHED_HASH_HSIEH
);
2535 return MEMCACHED_SUCCESS
;
2538 memcached_return
enable_cas(memcached_st
*memc
)
2540 unsigned int set
= 1;
2542 memcached_version(memc
);
2544 if (memc
->hosts
[0].major_version
>= 1 &&
2545 memc
->hosts
[0].minor_version
>= 2 &&
2546 memc
->hosts
[0].micro_version
>= 4)
2548 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
2550 return MEMCACHED_SUCCESS
;
2553 return MEMCACHED_FAILURE
;
2556 memcached_return
check_for_1_2_3(memcached_st
*memc
)
2558 memcached_version(memc
);
2560 if (memc
->hosts
[0].major_version
>= 1 &&
2561 memc
->hosts
[0].minor_version
>= 2 &&
2562 memc
->hosts
[0].micro_version
>= 4)
2563 return MEMCACHED_SUCCESS
;
2565 return MEMCACHED_FAILURE
;
2568 memcached_return
pre_unix_socket(memcached_st
*memc
)
2570 memcached_return rc
;
2573 memcached_server_list_free(memc
->hosts
);
2575 memc
->number_of_hosts
= 0;
2577 if (stat("/tmp/memcached.socket", &buf
))
2578 return MEMCACHED_FAILURE
;
2580 rc
= memcached_server_add_unix_socket(memc
, "/tmp/memcached.socket");
2585 memcached_return
pre_udp(memcached_st
*memc
)
2587 memcached_return rc
;
2589 memcached_server_list_free(memc
->hosts
);
2591 memc
->number_of_hosts
= 0;
2594 return MEMCACHED_FAILURE
;
2596 rc
= memcached_server_add_udp(memc
, "localhost", MEMCACHED_DEFAULT_PORT
);
2601 memcached_return
pre_nodelay(memcached_st
*memc
)
2603 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
2604 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
2606 return MEMCACHED_SUCCESS
;
2609 memcached_return
poll_timeout(memcached_st
*memc
)
2615 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
2617 timeout
= (int32_t)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
2619 assert(timeout
== 100);
2621 return MEMCACHED_SUCCESS
;
2625 /* Clean the server before beginning testing */
2627 {"flush", 0, flush_test
},
2628 {"init", 0, init_test
},
2629 {"allocation", 0, allocation_test
},
2630 {"server_list_null_test", 0, server_list_null_test
},
2631 {"server_unsort", 0, server_unsort_test
},
2632 {"server_sort", 0, server_sort_test
},
2633 {"clone_test", 0, clone_test
},
2634 {"error", 0, error_test
},
2635 {"set", 0, set_test
},
2636 {"set2", 0, set_test2
},
2637 {"set3", 0, set_test3
},
2638 {"add", 1, add_test
},
2639 {"replace", 1, replace_test
},
2640 {"delete", 1, delete_test
},
2641 {"get", 1, get_test
},
2642 {"get2", 0, get_test2
},
2643 {"get3", 0, get_test3
},
2644 {"get4", 0, get_test4
},
2645 {"stats_servername", 0, stats_servername_test
},
2646 {"increment", 0, increment_test
},
2647 {"decrement", 0, decrement_test
},
2648 {"quit", 0, quit_test
},
2649 {"mget", 1, mget_test
},
2650 {"mget_result", 1, mget_result_test
},
2651 {"mget_result_alloc", 1, mget_result_alloc_test
},
2652 {"mget_result_function", 1, mget_result_function
},
2653 {"get_stats", 0, get_stats
},
2654 {"add_host_test", 0, add_host_test
},
2655 {"get_stats_keys", 0, get_stats_keys
},
2656 {"behavior_test", 0, get_stats_keys
},
2657 {"callback_test", 0, get_stats_keys
},
2658 {"version_string_test", 0, version_string_test
},
2659 {"bad_key", 1, bad_key_test
},
2660 {"memcached_server_cursor", 1, memcached_server_cursor_test
},
2661 {"read_through", 1, read_through
},
2662 {"delete_through", 1, delete_through
},
2666 test_st async_tests
[] ={
2667 {"add", 1, add_wrapper
},
2671 test_st string_tests
[] ={
2672 {"string static with null", 0, string_static_null
},
2673 {"string alloc with null", 0, string_alloc_null
},
2674 {"string alloc with 1K", 0, string_alloc_with_size
},
2675 {"string alloc with malloc failure", 0, string_alloc_with_size_toobig
},
2676 {"string append", 0, string_alloc_append
},
2677 {"string append failure (too big)", 0, string_alloc_append_toobig
},
2681 test_st result_tests
[] ={
2682 {"result static", 0, result_static
},
2683 {"result alloc", 0, result_alloc
},
2687 test_st version_1_2_3
[] ={
2688 {"append", 0, append_test
},
2689 {"prepend", 0, prepend_test
},
2690 {"cas", 0, cas_test
},
2691 {"cas2", 0, cas2_test
},
2692 {"append_binary", 0, append_binary_test
},
2696 test_st user_tests
[] ={
2697 {"user_supplied_bug1", 0, user_supplied_bug1
},
2698 {"user_supplied_bug2", 0, user_supplied_bug2
},
2699 {"user_supplied_bug3", 0, user_supplied_bug3
},
2700 {"user_supplied_bug4", 0, user_supplied_bug4
},
2701 {"user_supplied_bug5", 1, user_supplied_bug5
},
2702 {"user_supplied_bug6", 1, user_supplied_bug6
},
2703 {"user_supplied_bug7", 1, user_supplied_bug7
},
2704 {"user_supplied_bug8", 1, user_supplied_bug8
},
2705 {"user_supplied_bug9", 1, user_supplied_bug9
},
2706 {"user_supplied_bug10", 1, user_supplied_bug10
},
2707 {"user_supplied_bug11", 1, user_supplied_bug11
},
2708 {"user_supplied_bug12", 1, user_supplied_bug12
},
2709 {"user_supplied_bug13", 1, user_supplied_bug13
},
2710 {"user_supplied_bug14", 1, user_supplied_bug14
},
2711 {"user_supplied_bug15", 1, user_supplied_bug15
},
2715 test_st generate_tests
[] ={
2716 {"generate_pairs", 1, generate_pairs
},
2717 {"generate_data", 1, generate_data
},
2718 {"get_read", 0, get_read
},
2719 {"delete_generate", 0, delete_generate
},
2720 {"generate_buffer_data", 1, generate_buffer_data
},
2721 {"delete_buffer", 0, delete_buffer_generate
},
2722 {"generate_data", 1, generate_data
},
2723 {"mget_read", 0, mget_read
},
2724 {"mget_read_result", 0, mget_read_result
},
2725 {"mget_read_function", 0, mget_read_function
},
2726 {"cleanup", 1, cleanup_pairs
},
2727 {"generate_large_pairs", 1, generate_large_pairs
},
2728 {"generate_data", 1, generate_data
},
2729 {"generate_buffer_data", 1, generate_buffer_data
},
2730 {"cleanup", 1, cleanup_pairs
},
2734 test_st consistent_tests
[] ={
2735 {"generate_pairs", 1, generate_pairs
},
2736 {"generate_data", 1, generate_data
},
2737 {"get_read", 0, get_read_count
},
2738 {"cleanup", 1, cleanup_pairs
},
2742 collection_st collection
[] ={
2743 {"block", 0, 0, tests
},
2744 {"nonblock", pre_nonblock
, 0, tests
},
2745 {"nodelay", pre_nodelay
, 0, tests
},
2746 {"md5", pre_md5
, 0, tests
},
2747 {"crc", pre_crc
, 0, tests
},
2748 {"hsieh", pre_hsieh
, 0, tests
},
2749 {"fnv1_64", pre_hash_fnv1_64
, 0, tests
},
2750 {"fnv1a_64", pre_hash_fnv1a_64
, 0, tests
},
2751 {"fnv1_32", pre_hash_fnv1_32
, 0, tests
},
2752 {"fnv1a_32", pre_hash_fnv1a_32
, 0, tests
},
2753 {"ketama", pre_behavior_ketama
, 0, tests
},
2754 {"unix_socket", pre_unix_socket
, 0, tests
},
2755 {"unix_socket_nodelay", pre_nodelay
, 0, tests
},
2756 {"poll_timeout", poll_timeout
, 0, tests
},
2757 {"gets", enable_cas
, 0, tests
},
2758 {"consistent", enable_consistent
, 0, tests
},
2759 {"wheel", enable_wheel
, 0, tests
},
2760 {"memory_allocators", set_memory_alloc
, 0, tests
},
2761 // {"udp", pre_udp, 0, tests},
2762 {"version_1_2_3", check_for_1_2_3
, 0, version_1_2_3
},
2763 {"string", 0, 0, string_tests
},
2764 {"result", 0, 0, result_tests
},
2765 {"async", pre_nonblock
, 0, async_tests
},
2766 {"user", 0, 0, user_tests
},
2767 {"generate", 0, 0, generate_tests
},
2768 {"generate_hsieh", pre_hsieh
, 0, generate_tests
},
2769 {"generate_ketama", pre_behavior_ketama
, 0, generate_tests
},
2770 {"generate_hsieh_consistent", enable_consistent
, 0, generate_tests
},
2771 {"generate_md5", pre_md5
, 0, generate_tests
},
2772 {"generate_murmur", pre_murmur
, 0, generate_tests
},
2773 {"generate_nonblock", pre_nonblock
, 0, generate_tests
},
2774 {"consistent_not", 0, 0, consistent_tests
},
2775 {"consistent_ketama", pre_behavior_ketama
, 0, consistent_tests
},
2776 {"consistent_wheel", enable_wheel
, 0, consistent_tests
},
2780 #define SERVERS_TO_CREATE 5
2782 void *world_create(void)
2784 server_startup_st
*construct
;
2786 construct
= (server_startup_st
*)malloc(sizeof(server_startup_st
));
2787 memset(construct
, 0, sizeof(server_startup_st
));
2788 construct
->count
= SERVERS_TO_CREATE
;
2790 server_startup(construct
);
2795 void world_destroy(void *p
)
2797 server_startup_st
*construct
= (server_startup_st
*)p
;
2798 memcached_server_st
*servers
= (memcached_server_st
*)construct
->servers
;
2799 memcached_server_list_free(servers
);
2801 server_shutdown(construct
);
2805 void get_world(world_st
*world
)
2807 world
->collections
= collection
;
2808 world
->create
= world_create
;
2809 world
->destroy
= world_destroy
;