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
;
606 size_t max_keylen
= 0xffff;
608 clone
= memcached_clone(NULL
, memc
);
611 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
612 assert(rc
== MEMCACHED_SUCCESS
);
614 /* All keys are valid in the binary protocol (except for length) */
615 if (memcached_behavior_get(clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 0)
617 string
= memcached_get(clone
, key
, strlen(key
),
618 &string_length
, &flags
, &rc
);
619 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
620 assert(string_length
== 0);
624 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
625 assert(rc
== MEMCACHED_SUCCESS
);
626 string
= memcached_get(clone
, key
, strlen(key
),
627 &string_length
, &flags
, &rc
);
628 assert(rc
== MEMCACHED_NOTFOUND
);
629 assert(string_length
== 0);
632 /* Test multi key for bad keys */
633 char *keys
[] = { "GoodKey", "Bad Key", "NotMine" };
634 size_t key_lengths
[] = { 7, 7, 7 };
636 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
637 assert(rc
== MEMCACHED_SUCCESS
);
639 rc
= memcached_mget(clone
, keys
, key_lengths
, 3);
640 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
642 rc
= memcached_mget_by_key(clone
, "foo daddy", 9, keys
, key_lengths
, 1);
643 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
647 /* The following test should be moved to the end of this function when the
648 memcached server is updated to allow max size length of the keys in the
651 rc
= memcached_callback_set(clone
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
652 assert(rc
== MEMCACHED_SUCCESS
);
654 char *longkey
= malloc(max_keylen
+ 1);
657 memset(longkey
, 'a', max_keylen
+ 1);
658 string
= memcached_get(clone
, longkey
, max_keylen
,
659 &string_length
, &flags
, &rc
);
660 assert(rc
== MEMCACHED_NOTFOUND
);
661 assert(string_length
== 0);
664 string
= memcached_get(clone
, longkey
, max_keylen
+ 1,
665 &string_length
, &flags
, &rc
);
666 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
667 assert(string_length
== 0);
674 /* Make sure zero length keys are marked as bad */
676 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
677 assert(rc
== MEMCACHED_SUCCESS
);
678 string
= memcached_get(clone
, key
, 0,
679 &string_length
, &flags
, &rc
);
680 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
681 assert(string_length
== 0);
684 memcached_free(clone
);
689 #define READ_THROUGH_VALUE "set for me"
690 static memcached_return
read_through_trigger(memcached_st
*memc
__attribute__((unused
)),
691 char *key
__attribute__((unused
)),
692 size_t key_length
__attribute__((unused
)),
693 memcached_result_st
*result
)
696 return memcached_result_set_value(result
, READ_THROUGH_VALUE
, strlen(READ_THROUGH_VALUE
));
699 static test_return
read_through(memcached_st
*memc
)
704 size_t string_length
;
707 string
= memcached_get(memc
, key
, strlen(key
),
708 &string_length
, &flags
, &rc
);
710 assert(rc
== MEMCACHED_NOTFOUND
);
711 assert(string_length
== 0);
714 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_GET_FAILURE
, (void *)read_through_trigger
);
715 assert(rc
== MEMCACHED_SUCCESS
);
717 string
= memcached_get(memc
, key
, strlen(key
),
718 &string_length
, &flags
, &rc
);
720 assert(rc
== MEMCACHED_SUCCESS
);
721 assert(string_length
== strlen(READ_THROUGH_VALUE
));
722 assert(!strcmp(READ_THROUGH_VALUE
, string
));
725 string
= memcached_get(memc
, key
, strlen(key
),
726 &string_length
, &flags
, &rc
);
728 assert(rc
== MEMCACHED_SUCCESS
);
729 assert(string_length
== strlen(READ_THROUGH_VALUE
));
730 assert(!strcmp(READ_THROUGH_VALUE
, string
));
736 static memcached_return
delete_trigger(memcached_st
*ptr
__attribute__((unused
)),
738 size_t key_length
__attribute__((unused
)))
742 return MEMCACHED_SUCCESS
;
745 static test_return
delete_through(memcached_st
*memc
)
747 memcached_trigger_delete_key callback
;
750 callback
= delete_trigger
;
752 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_DELETE_TRIGGER
, callback
);
753 assert(rc
== MEMCACHED_SUCCESS
);
758 static test_return
get_test(memcached_st
*memc
)
763 size_t string_length
;
766 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
767 assert(rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_NOTFOUND
);
769 string
= memcached_get(memc
, key
, strlen(key
),
770 &string_length
, &flags
, &rc
);
772 assert(rc
== MEMCACHED_NOTFOUND
);
773 assert(string_length
== 0);
779 static test_return
get_test2(memcached_st
*memc
)
783 char *value
= "when we sanitize";
785 size_t string_length
;
788 rc
= memcached_set(memc
, key
, strlen(key
),
789 value
, strlen(value
),
790 (time_t)0, (uint32_t)0);
791 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
793 string
= memcached_get(memc
, key
, strlen(key
),
794 &string_length
, &flags
, &rc
);
797 assert(rc
== MEMCACHED_SUCCESS
);
798 assert(string_length
== strlen(value
));
799 assert(!memcmp(string
, value
, string_length
));
806 static test_return
set_test2(memcached_st
*memc
)
810 char *value
= "train in the brain";
811 size_t value_length
= strlen(value
);
814 for (x
= 0; x
< 10; x
++)
816 rc
= memcached_set(memc
, key
, strlen(key
),
818 (time_t)0, (uint32_t)0);
819 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
825 static test_return
set_test3(memcached_st
*memc
)
830 size_t value_length
= 8191;
833 value
= (char*)malloc(value_length
);
836 for (x
= 0; x
< value_length
; x
++)
837 value
[x
] = (char) (x
% 127);
839 for (x
= 0; x
< 1; x
++)
841 rc
= memcached_set(memc
, key
, strlen(key
),
843 (time_t)0, (uint32_t)0);
844 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
852 static test_return
get_test3(memcached_st
*memc
)
857 size_t value_length
= 8191;
859 size_t string_length
;
863 value
= (char*)malloc(value_length
);
866 for (x
= 0; x
< value_length
; x
++)
867 value
[x
] = (char) (x
% 127);
869 rc
= memcached_set(memc
, key
, strlen(key
),
871 (time_t)0, (uint32_t)0);
872 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
874 string
= memcached_get(memc
, key
, strlen(key
),
875 &string_length
, &flags
, &rc
);
877 assert(rc
== MEMCACHED_SUCCESS
);
879 assert(string_length
== value_length
);
880 assert(!memcmp(string
, value
, string_length
));
888 static test_return
get_test4(memcached_st
*memc
)
893 size_t value_length
= 8191;
895 size_t string_length
;
899 value
= (char*)malloc(value_length
);
902 for (x
= 0; x
< value_length
; x
++)
903 value
[x
] = (char) (x
% 127);
905 rc
= memcached_set(memc
, key
, strlen(key
),
907 (time_t)0, (uint32_t)0);
908 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
910 for (x
= 0; x
< 10; x
++)
912 string
= memcached_get(memc
, key
, strlen(key
),
913 &string_length
, &flags
, &rc
);
915 assert(rc
== MEMCACHED_SUCCESS
);
917 assert(string_length
== value_length
);
918 assert(!memcmp(string
, value
, string_length
));
927 /* Do not copy the style of this code, I just access hosts to testthis function */
928 static test_return
stats_servername_test(memcached_st
*memc
)
931 memcached_stat_st stat
;
932 rc
= memcached_stat_servername(&stat
, NULL
,
933 memc
->hosts
[0].hostname
,
934 memc
->hosts
[0].port
);
939 static test_return
increment_test(memcached_st
*memc
)
946 rc
= memcached_set(memc
, key
, strlen(key
),
947 value
, strlen(value
),
948 (time_t)0, (uint32_t)0);
949 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
951 rc
= memcached_increment(memc
, key
, strlen(key
),
953 assert(rc
== MEMCACHED_SUCCESS
);
954 assert(new_number
== 1);
956 rc
= memcached_increment(memc
, key
, strlen(key
),
958 assert(rc
== MEMCACHED_SUCCESS
);
959 assert(new_number
== 2);
964 static test_return
decrement_test(memcached_st
*memc
)
971 rc
= memcached_set(memc
, key
, strlen(key
),
972 value
, strlen(value
),
973 (time_t)0, (uint32_t)0);
974 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
976 rc
= memcached_decrement(memc
, key
, strlen(key
),
978 assert(rc
== MEMCACHED_SUCCESS
);
979 assert(new_number
== 2);
981 rc
= memcached_decrement(memc
, key
, strlen(key
),
983 assert(rc
== MEMCACHED_SUCCESS
);
984 assert(new_number
== 1);
989 static test_return
quit_test(memcached_st
*memc
)
993 char *value
= "sanford and sun";
995 rc
= memcached_set(memc
, key
, strlen(key
),
996 value
, strlen(value
),
997 (time_t)10, (uint32_t)3);
998 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
999 memcached_quit(memc
);
1001 rc
= memcached_set(memc
, key
, strlen(key
),
1002 value
, strlen(value
),
1003 (time_t)50, (uint32_t)9);
1004 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1009 static test_return
mget_result_test(memcached_st
*memc
)
1011 memcached_return rc
;
1012 char *keys
[]= {"fudge", "son", "food"};
1013 size_t key_length
[]= {5, 3, 4};
1016 memcached_result_st results_obj
;
1017 memcached_result_st
*results
;
1019 results
= memcached_result_create(memc
, &results_obj
);
1021 assert(&results_obj
== results
);
1023 /* We need to empty the server before continueing test */
1024 rc
= memcached_flush(memc
, 0);
1025 assert(rc
== MEMCACHED_SUCCESS
);
1027 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1028 assert(rc
== MEMCACHED_SUCCESS
);
1030 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1035 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1037 assert(rc
== MEMCACHED_END
);
1039 for (x
= 0; x
< 3; x
++)
1041 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1042 keys
[x
], key_length
[x
],
1043 (time_t)50, (uint32_t)9);
1044 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1047 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1048 assert(rc
== MEMCACHED_SUCCESS
);
1050 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1053 assert(&results_obj
== results
);
1054 assert(rc
== MEMCACHED_SUCCESS
);
1055 assert(memcached_result_key_length(results
) == memcached_result_length(results
));
1056 assert(!memcmp(memcached_result_key_value(results
),
1057 memcached_result_value(results
),
1058 memcached_result_length(results
)));
1061 memcached_result_free(&results_obj
);
1066 static test_return
mget_result_alloc_test(memcached_st
*memc
)
1068 memcached_return rc
;
1069 char *keys
[]= {"fudge", "son", "food"};
1070 size_t key_length
[]= {5, 3, 4};
1073 memcached_result_st
*results
;
1075 /* We need to empty the server before continueing test */
1076 rc
= memcached_flush(memc
, 0);
1077 assert(rc
== MEMCACHED_SUCCESS
);
1079 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1080 assert(rc
== MEMCACHED_SUCCESS
);
1082 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)) != NULL
)
1087 assert(rc
== MEMCACHED_END
);
1089 for (x
= 0; x
< 3; x
++)
1091 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1092 keys
[x
], key_length
[x
],
1093 (time_t)50, (uint32_t)9);
1094 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1097 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1098 assert(rc
== MEMCACHED_SUCCESS
);
1101 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1104 assert(rc
== MEMCACHED_SUCCESS
);
1105 assert(memcached_result_key_length(results
) == memcached_result_length(results
));
1106 assert(!memcmp(memcached_result_key_value(results
),
1107 memcached_result_value(results
),
1108 memcached_result_length(results
)));
1109 memcached_result_free(results
);
1116 /* Count the results */
1117 static memcached_return
callback_counter(memcached_st
*ptr
__attribute__((unused
)),
1118 memcached_result_st
*result
__attribute__((unused
)),
1121 unsigned int *counter
= (unsigned int *)context
;
1123 *counter
= *counter
+ 1;
1125 return MEMCACHED_SUCCESS
;
1128 static test_return
mget_result_function(memcached_st
*memc
)
1130 memcached_return rc
;
1131 char *keys
[]= {"fudge", "son", "food"};
1132 size_t key_length
[]= {5, 3, 4};
1134 unsigned int counter
;
1135 memcached_execute_function callbacks
[1];
1137 /* We need to empty the server before continueing test */
1138 rc
= memcached_flush(memc
, 0);
1139 for (x
= 0; x
< 3; x
++)
1141 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1142 keys
[x
], key_length
[x
],
1143 (time_t)50, (uint32_t)9);
1144 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1147 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1148 assert(rc
== MEMCACHED_SUCCESS
);
1150 callbacks
[0]= &callback_counter
;
1152 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
1154 assert(counter
== 3);
1159 static test_return
mget_test(memcached_st
*memc
)
1161 memcached_return rc
;
1162 char *keys
[]= {"fudge", "son", "food"};
1163 size_t key_length
[]= {5, 3, 4};
1167 char return_key
[MEMCACHED_MAX_KEY
];
1168 size_t return_key_length
;
1170 size_t return_value_length
;
1172 /* We need to empty the server before continueing test */
1173 rc
= memcached_flush(memc
, 0);
1174 assert(rc
== MEMCACHED_SUCCESS
);
1176 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1177 assert(rc
== MEMCACHED_SUCCESS
);
1179 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1180 &return_value_length
, &flags
, &rc
)) != NULL
)
1182 assert(return_value
);
1184 assert(!return_value
);
1185 assert(return_value_length
== 0);
1186 assert(rc
== MEMCACHED_END
);
1188 for (x
= 0; x
< 3; x
++)
1190 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1191 keys
[x
], key_length
[x
],
1192 (time_t)50, (uint32_t)9);
1193 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1196 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1197 assert(rc
== MEMCACHED_SUCCESS
);
1200 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1201 &return_value_length
, &flags
, &rc
)))
1203 assert(return_value
);
1204 assert(rc
== MEMCACHED_SUCCESS
);
1205 assert(return_key_length
== return_value_length
);
1206 assert(!memcmp(return_value
, return_key
, return_value_length
));
1214 static test_return
get_stats_keys(memcached_st
*memc
)
1218 memcached_stat_st stat
;
1219 memcached_return rc
;
1221 list
= memcached_stat_get_keys(memc
, &stat
, &rc
);
1222 assert(rc
== MEMCACHED_SUCCESS
);
1223 for (ptr
= list
; *ptr
; ptr
++)
1232 static test_return
version_string_test(memcached_st
*memc
__attribute__((unused
)))
1234 const char *version_string
;
1236 version_string
= memcached_lib_version();
1238 assert(!strcmp(version_string
, LIBMEMCACHED_VERSION_STRING
));
1243 static test_return
get_stats(memcached_st
*memc
)
1248 memcached_return rc
;
1249 memcached_stat_st
*stat
;
1251 stat
= memcached_stat(memc
, NULL
, &rc
);
1252 assert(rc
== MEMCACHED_SUCCESS
);
1254 assert(rc
== MEMCACHED_SUCCESS
);
1257 for (x
= 0; x
< memcached_server_count(memc
); x
++)
1259 list
= memcached_stat_get_keys(memc
, stat
+x
, &rc
);
1260 assert(rc
== MEMCACHED_SUCCESS
);
1261 for (ptr
= list
; *ptr
; ptr
++);
1266 memcached_stat_free(NULL
, stat
);
1271 static test_return
add_host_test(memcached_st
*memc
)
1274 memcached_server_st
*servers
;
1275 memcached_return rc
;
1276 char servername
[]= "0.example.com";
1278 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
1280 assert(1 == memcached_server_list_count(servers
));
1282 for (x
= 2; x
< 20; x
++)
1284 char buffer
[SMALL_STRING_LEN
];
1286 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
1287 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
1289 assert(rc
== MEMCACHED_SUCCESS
);
1290 assert(x
== memcached_server_list_count(servers
));
1293 rc
= memcached_server_push(memc
, servers
);
1294 assert(rc
== MEMCACHED_SUCCESS
);
1295 rc
= memcached_server_push(memc
, servers
);
1296 assert(rc
== MEMCACHED_SUCCESS
);
1298 memcached_server_list_free(servers
);
1303 static memcached_return
clone_test_callback(memcached_st
*parent
__attribute__((unused
)), memcached_st
*clone
__attribute__((unused
)))
1305 return MEMCACHED_SUCCESS
;
1308 static memcached_return
cleanup_test_callback(memcached_st
*ptr
__attribute__((unused
)))
1310 return MEMCACHED_SUCCESS
;
1313 static test_return
callback_test(memcached_st
*memc
)
1315 /* Test User Data */
1319 memcached_return rc
;
1321 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_USER_DATA
, &x
);
1322 assert(rc
== MEMCACHED_SUCCESS
);
1323 test_ptr
= (int *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_USER_DATA
, &rc
);
1324 assert(*test_ptr
== x
);
1327 /* Test Clone Callback */
1329 memcached_clone_func temp_function
;
1330 memcached_return rc
;
1332 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, clone_test_callback
);
1333 assert(rc
== MEMCACHED_SUCCESS
);
1334 temp_function
= (memcached_clone_func
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1335 assert(temp_function
== clone_test_callback
);
1338 /* Test Cleanup Callback */
1340 memcached_cleanup_func temp_function
;
1341 memcached_return rc
;
1343 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, cleanup_test_callback
);
1344 assert(rc
== MEMCACHED_SUCCESS
);
1345 temp_function
= (memcached_cleanup_func
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1346 assert(temp_function
== cleanup_test_callback
);
1352 /* We don't test the behavior itself, we test the switches */
1353 static test_return
behavior_test(memcached_st
*memc
)
1358 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1359 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1362 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1363 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1366 set
= MEMCACHED_HASH_MD5
;
1367 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1368 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1369 assert(value
== MEMCACHED_HASH_MD5
);
1373 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1374 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1377 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1378 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1381 set
= MEMCACHED_HASH_DEFAULT
;
1382 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1383 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1384 assert(value
== MEMCACHED_HASH_DEFAULT
);
1386 set
= MEMCACHED_HASH_CRC
;
1387 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1388 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1389 assert(value
== MEMCACHED_HASH_CRC
);
1391 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1394 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1400 /* Test case provided by Cal Haldenbrand */
1401 static test_return
user_supplied_bug1(memcached_st
*memc
)
1403 unsigned int setter
= 1;
1406 unsigned long long total
= 0;
1409 char randomstuff
[6 * 1024];
1410 memcached_return rc
;
1412 memset(randomstuff
, 0, 6 * 1024);
1414 /* We just keep looking at the same values over and over */
1417 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1418 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1422 for (x
= 0 ; total
< 20 * 1024576 ; x
++ )
1426 size
= (rand() % ( 5 * 1024 ) ) + 400;
1427 memset(randomstuff
, 0, 6 * 1024);
1428 assert(size
< 6 * 1024); /* Being safe here */
1430 for (j
= 0 ; j
< size
;j
++)
1431 randomstuff
[j
] = (char) (rand() % 26) + 97;
1434 sprintf(key
, "%d", x
);
1435 rc
= memcached_set(memc
, key
, strlen(key
),
1436 randomstuff
, strlen(randomstuff
), 10, 0);
1437 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1438 /* If we fail, lets try again */
1439 if (rc
!= MEMCACHED_SUCCESS
&& rc
!= MEMCACHED_BUFFERED
)
1440 rc
= memcached_set(memc
, key
, strlen(key
),
1441 randomstuff
, strlen(randomstuff
), 10, 0);
1442 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1448 /* Test case provided by Cal Haldenbrand */
1449 static test_return
user_supplied_bug2(memcached_st
*memc
)
1452 unsigned int setter
;
1454 unsigned long long total
;
1457 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1458 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1460 setter
= 20 * 1024576;
1461 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1462 setter
= 20 * 1024576;
1463 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1464 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1465 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1467 for (x
= 0, errors
= 0, total
= 0 ; total
< 20 * 1024576 ; x
++)
1470 for (x
= 0, errors
= 0, total
= 0 ; total
< 24576 ; x
++)
1472 memcached_return rc
= MEMCACHED_SUCCESS
;
1473 char buffer
[SMALL_STRING_LEN
];
1478 memset(buffer
, 0, SMALL_STRING_LEN
);
1480 snprintf(buffer
, SMALL_STRING_LEN
, "%u", x
);
1481 getval
= memcached_get(memc
, buffer
, strlen(buffer
),
1482 &val_len
, &flags
, &rc
);
1483 if (rc
!= MEMCACHED_SUCCESS
)
1485 if (rc
== MEMCACHED_NOTFOUND
)
1489 WATCHPOINT_ERROR(rc
);
1503 /* Do a large mget() over all the keys we think exist */
1504 #define KEY_COUNT 3000 // * 1024576
1505 static test_return
user_supplied_bug3(memcached_st
*memc
)
1507 memcached_return rc
;
1508 unsigned int setter
;
1511 size_t key_lengths
[KEY_COUNT
];
1514 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1515 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1517 setter
= 20 * 1024576;
1518 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1519 setter
= 20 * 1024576;
1520 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1521 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1522 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1525 keys
= (char **)malloc(sizeof(char *) * KEY_COUNT
);
1527 memset(keys
, 0, (sizeof(char *) * KEY_COUNT
));
1528 for (x
= 0; x
< KEY_COUNT
; x
++)
1532 snprintf(buffer
, 30, "%u", x
);
1533 keys
[x
]= strdup(buffer
);
1534 key_lengths
[x
]= strlen(keys
[x
]);
1537 rc
= memcached_mget(memc
, keys
, key_lengths
, KEY_COUNT
);
1538 assert(rc
== MEMCACHED_SUCCESS
);
1540 /* Turn this into a help function */
1542 char return_key
[MEMCACHED_MAX_KEY
];
1543 size_t return_key_length
;
1545 size_t return_value_length
;
1548 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1549 &return_value_length
, &flags
, &rc
)))
1551 assert(return_value
);
1552 assert(rc
== MEMCACHED_SUCCESS
);
1557 for (x
= 0; x
< KEY_COUNT
; x
++)
1564 /* Make sure we behave properly if server list has no values */
1565 static test_return
user_supplied_bug4(memcached_st
*memc
)
1567 memcached_return rc
;
1568 char *keys
[]= {"fudge", "son", "food"};
1569 size_t key_length
[]= {5, 3, 4};
1572 char return_key
[MEMCACHED_MAX_KEY
];
1573 size_t return_key_length
;
1575 size_t return_value_length
;
1577 /* Here we free everything before running a bunch of mget tests */
1579 memcached_server_list_free(memc
->hosts
);
1581 memc
->number_of_hosts
= 0;
1585 /* We need to empty the server before continueing test */
1586 rc
= memcached_flush(memc
, 0);
1587 assert(rc
== MEMCACHED_NO_SERVERS
);
1589 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1590 assert(rc
== MEMCACHED_NO_SERVERS
);
1592 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1593 &return_value_length
, &flags
, &rc
)) != NULL
)
1595 assert(return_value
);
1597 assert(!return_value
);
1598 assert(return_value_length
== 0);
1599 assert(rc
== MEMCACHED_NO_SERVERS
);
1601 for (x
= 0; x
< 3; x
++)
1603 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1604 keys
[x
], key_length
[x
],
1605 (time_t)50, (uint32_t)9);
1606 assert(rc
== MEMCACHED_NO_SERVERS
);
1609 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1610 assert(rc
== MEMCACHED_NO_SERVERS
);
1613 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1614 &return_value_length
, &flags
, &rc
)))
1616 assert(return_value
);
1617 assert(rc
== MEMCACHED_SUCCESS
);
1618 assert(return_key_length
== return_value_length
);
1619 assert(!memcmp(return_value
, return_key
, return_value_length
));
1627 #define VALUE_SIZE_BUG5 1048064
1628 static test_return
user_supplied_bug5(memcached_st
*memc
)
1630 memcached_return rc
;
1631 char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1632 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1633 char return_key
[MEMCACHED_MAX_KEY
];
1634 size_t return_key_length
;
1636 size_t value_length
;
1640 char insert_data
[VALUE_SIZE_BUG5
];
1642 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1643 insert_data
[x
]= rand();
1645 memcached_flush(memc
, 0);
1646 value
= memcached_get(memc
, keys
[0], key_length
[0],
1647 &value_length
, &flags
, &rc
);
1648 assert(value
== NULL
);
1649 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1652 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1653 &value_length
, &flags
, &rc
)))
1657 for (x
= 0; x
< 4; x
++)
1659 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1660 insert_data
, VALUE_SIZE_BUG5
,
1661 (time_t)0, (uint32_t)0);
1662 assert(rc
== MEMCACHED_SUCCESS
);
1665 for (x
= 0; x
< 10; x
++)
1667 value
= memcached_get(memc
, keys
[0], key_length
[0],
1668 &value_length
, &flags
, &rc
);
1672 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1674 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1675 &value_length
, &flags
, &rc
)))
1686 static test_return
user_supplied_bug6(memcached_st
*memc
)
1688 memcached_return rc
;
1689 char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1690 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1691 char return_key
[MEMCACHED_MAX_KEY
];
1692 size_t return_key_length
;
1694 size_t value_length
;
1698 char insert_data
[VALUE_SIZE_BUG5
];
1700 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1701 insert_data
[x
]= rand();
1703 memcached_flush(memc
, 0);
1704 value
= memcached_get(memc
, keys
[0], key_length
[0],
1705 &value_length
, &flags
, &rc
);
1706 assert(value
== NULL
);
1707 assert(rc
== MEMCACHED_NOTFOUND
);
1708 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1709 assert(rc
== MEMCACHED_SUCCESS
);
1712 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1713 &value_length
, &flags
, &rc
)))
1716 assert(rc
== MEMCACHED_END
);
1718 for (x
= 0; x
< 4; x
++)
1720 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1721 insert_data
, VALUE_SIZE_BUG5
,
1722 (time_t)0, (uint32_t)0);
1723 assert(rc
== MEMCACHED_SUCCESS
);
1726 for (x
= 0; x
< 2; x
++)
1728 value
= memcached_get(memc
, keys
[0], key_length
[0],
1729 &value_length
, &flags
, &rc
);
1733 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1734 assert(rc
== MEMCACHED_SUCCESS
);
1736 /* We test for purge of partial complete fetches */
1737 for (count
= 3; count
; count
--)
1739 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1740 &value_length
, &flags
, &rc
);
1741 assert(rc
== MEMCACHED_SUCCESS
);
1742 assert(!(memcmp(value
, insert_data
, value_length
)));
1743 assert(value_length
);
1751 static test_return
user_supplied_bug8(memcached_st
*memc
__attribute__((unused
)))
1753 memcached_return rc
;
1755 memcached_st
*clone
;
1757 memcached_server_st
*servers
;
1758 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";
1760 servers
= memcached_servers_parse(server_list
);
1763 mine
= memcached_create(NULL
);
1764 rc
= memcached_server_push(mine
, servers
);
1765 assert(rc
== MEMCACHED_SUCCESS
);
1766 memcached_server_list_free(servers
);
1769 clone
= memcached_clone(NULL
, mine
);
1771 memcached_quit(mine
);
1772 memcached_quit(clone
);
1775 memcached_free(mine
);
1776 memcached_free(clone
);
1781 /* Test flag store/retrieve */
1782 static test_return
user_supplied_bug7(memcached_st
*memc
)
1784 memcached_return rc
;
1785 char *keys
= "036790384900";
1786 size_t key_length
= strlen("036790384900");
1787 char return_key
[MEMCACHED_MAX_KEY
];
1788 size_t return_key_length
;
1790 size_t value_length
;
1793 char insert_data
[VALUE_SIZE_BUG5
];
1795 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1796 insert_data
[x
]= rand();
1798 memcached_flush(memc
, 0);
1801 rc
= memcached_set(memc
, keys
, key_length
,
1802 insert_data
, VALUE_SIZE_BUG5
,
1804 assert(rc
== MEMCACHED_SUCCESS
);
1807 value
= memcached_get(memc
, keys
, key_length
,
1808 &value_length
, &flags
, &rc
);
1809 assert(flags
== 245);
1813 rc
= memcached_mget(memc
, &keys
, &key_length
, 1);
1816 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1817 &value_length
, &flags
, &rc
);
1818 assert(flags
== 245);
1826 static test_return
user_supplied_bug9(memcached_st
*memc
)
1828 memcached_return rc
;
1829 char *keys
[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
1830 size_t key_length
[3];
1835 char return_key
[MEMCACHED_MAX_KEY
];
1836 size_t return_key_length
;
1838 size_t return_value_length
;
1841 key_length
[0]= strlen("UDATA:edevil@sapo.pt");
1842 key_length
[1]= strlen("fudge&*@#");
1843 key_length
[2]= strlen("for^#@&$not");
1846 for (x
= 0; x
< 3; x
++)
1848 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1849 keys
[x
], key_length
[x
],
1850 (time_t)50, (uint32_t)9);
1851 assert(rc
== MEMCACHED_SUCCESS
);
1854 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1855 assert(rc
== MEMCACHED_SUCCESS
);
1857 /* We need to empty the server before continueing test */
1858 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1859 &return_value_length
, &flags
, &rc
)) != NULL
)
1861 assert(return_value
);
1870 /* We are testing with aggressive timeout to get failures */
1871 static test_return
user_supplied_bug10(memcached_st
*memc
)
1875 size_t value_length
= 512;
1878 memcached_return rc
;
1879 unsigned int set
= 1;
1880 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
1883 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1884 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1886 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
1888 value
= (char*)malloc(value_length
* sizeof(char));
1890 for (x
= 0; x
< value_length
; x
++)
1891 value
[x
]= (char) (x
% 127);
1893 for (x
= 1; x
<= 100000; ++x
)
1895 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
1897 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_WRITE_FAILURE
|| rc
== MEMCACHED_BUFFERED
);
1899 if (rc
== MEMCACHED_WRITE_FAILURE
)
1904 memcached_free(mclone
);
1910 We are looking failures in the async protocol
1912 static test_return
user_supplied_bug11(memcached_st
*memc
)
1916 size_t value_length
= 512;
1919 memcached_return rc
;
1920 unsigned int set
= 1;
1922 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
1924 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1925 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1927 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
1929 timeout
= (int32_t)memcached_behavior_get(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
1931 assert(timeout
== -1);
1933 value
= (char*)malloc(value_length
* sizeof(char));
1935 for (x
= 0; x
< value_length
; x
++)
1936 value
[x
]= (char) (x
% 127);
1938 for (x
= 1; x
<= 100000; ++x
)
1940 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
1944 memcached_free(mclone
);
1950 Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
1952 static test_return
user_supplied_bug12(memcached_st
*memc
)
1954 memcached_return rc
;
1956 size_t value_length
;
1958 uint64_t number_value
;
1960 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
1961 &value_length
, &flags
, &rc
);
1962 assert(value
== NULL
);
1963 assert(rc
== MEMCACHED_NOTFOUND
);
1965 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
1968 assert(value
== NULL
);
1969 /* The binary protocol will set the key if it doesn't exist */
1970 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1)
1971 assert(rc
== MEMCACHED_SUCCESS
);
1973 assert(rc
== MEMCACHED_NOTFOUND
);
1975 rc
= memcached_set(memc
, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
1977 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
1978 &value_length
, &flags
, &rc
);
1980 assert(rc
== MEMCACHED_SUCCESS
);
1983 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
1985 assert(number_value
== 2);
1986 assert(rc
== MEMCACHED_SUCCESS
);
1992 Bug found where command total one more than MEMCACHED_MAX_BUFFER
1993 set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
1995 static test_return
user_supplied_bug13(memcached_st
*memc
)
1997 char key
[] = "key34567890";
1999 memcached_return rc
;
2000 size_t overflowSize
;
2002 char commandFirst
[]= "set key34567890 0 0 ";
2003 char commandLast
[] = " \r\n"; /* first line of command sent to server */
2004 size_t commandLength
;
2007 commandLength
= strlen(commandFirst
) + strlen(commandLast
) + 4; /* 4 is number of characters in size, probably 8196 */
2009 overflowSize
= MEMCACHED_MAX_BUFFER
- commandLength
;
2011 for (testSize
= overflowSize
- 1; testSize
< overflowSize
+ 1; testSize
++)
2013 overflow
= malloc(testSize
);
2014 assert(overflow
!= NULL
);
2016 memset(overflow
, 'x', testSize
);
2017 rc
= memcached_set(memc
, key
, strlen(key
),
2018 overflow
, testSize
, 0, 0);
2019 assert(rc
== MEMCACHED_SUCCESS
);
2028 Test values of many different sizes
2029 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2030 set key34567890 0 0 8169 \r\n
2031 is sent followed by buffer of size 8169, followed by 8169
2033 static test_return
user_supplied_bug14(memcached_st
*memc
)
2036 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2037 memcached_return rc
;
2040 size_t value_length
= 18000;
2042 size_t string_length
;
2045 size_t current_length
;
2047 value
= (char*)malloc(value_length
);
2050 for (x
= 0; x
< value_length
; x
++)
2051 value
[x
] = (char) (x
% 127);
2053 for (current_length
= 0; current_length
< value_length
; current_length
++)
2055 rc
= memcached_set(memc
, key
, strlen(key
),
2056 value
, current_length
,
2057 (time_t)0, (uint32_t)0);
2058 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
2060 string
= memcached_get(memc
, key
, strlen(key
),
2061 &string_length
, &flags
, &rc
);
2063 assert(rc
== MEMCACHED_SUCCESS
);
2064 assert(string_length
== current_length
);
2065 assert(!memcmp(string
, value
, string_length
));
2076 Look for zero length value problems
2078 static test_return
user_supplied_bug15(memcached_st
*memc
)
2081 memcached_return rc
;
2087 for (x
= 0; x
< 2; x
++)
2089 rc
= memcached_set(memc
, key
, strlen(key
),
2091 (time_t)0, (uint32_t)0);
2093 assert(rc
== MEMCACHED_SUCCESS
);
2095 value
= memcached_get(memc
, key
, strlen(key
),
2096 &length
, &flags
, &rc
);
2098 assert(rc
== MEMCACHED_SUCCESS
);
2099 assert(value
== NULL
);
2100 assert(length
== 0);
2103 value
= memcached_get(memc
, key
, strlen(key
),
2104 &length
, &flags
, &rc
);
2106 assert(rc
== MEMCACHED_SUCCESS
);
2107 assert(value
== NULL
);
2108 assert(length
== 0);
2115 /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
2116 static test_return
user_supplied_bug16(memcached_st
*memc
)
2118 memcached_return rc
;
2124 rc
= memcached_set(memc
, key
, strlen(key
),
2126 (time_t)0, UINT32_MAX
);
2128 assert(rc
== MEMCACHED_SUCCESS
);
2130 value
= memcached_get(memc
, key
, strlen(key
),
2131 &length
, &flags
, &rc
);
2133 assert(rc
== MEMCACHED_SUCCESS
);
2134 assert(value
== NULL
);
2135 assert(length
== 0);
2136 assert(flags
== UINT32_MAX
);
2141 /* Check the validity of chinese key*/
2142 static test_return
user_supplied_bug17(memcached_st
*memc
)
2144 memcached_return rc
;
2146 char *value
="我们在炎热抑郁的夏天无法停止豆瓣";
2151 rc
= memcached_set(memc
, key
, strlen(key
),
2152 value
, strlen(value
),
2155 assert(rc
== MEMCACHED_SUCCESS
);
2157 value2
= memcached_get(memc
, key
, strlen(key
),
2158 &length
, &flags
, &rc
);
2160 assert(length
==strlen(value
));
2161 assert(rc
== MEMCACHED_SUCCESS
);
2162 assert(memcmp(value
, value2
, length
)==0);
2172 test_return
user_supplied_bug19(memcached_st
*memc
)
2175 memcached_server_st
*s
;
2176 memcached_return res
;
2180 m
= memcached_create(NULL
);
2181 memcached_server_add_with_weight(m
, "localhost", 11311, 100);
2182 memcached_server_add_with_weight(m
, "localhost", 11312, 100);
2184 s
= memcached_server_by_key(m
, "a", 1, &res
);
2185 memcached_server_free(s
);
2192 /* CAS test from Andei */
2193 test_return
user_supplied_bug20(memcached_st
*memc
)
2195 memcached_return status
;
2196 memcached_result_st
*result
, result_obj
;
2198 size_t key_len
= strlen("abc");
2199 char *value
= "foobar";
2200 size_t value_len
= strlen(value
);
2202 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
2204 status
= memcached_set(memc
, key
, key_len
, value
, value_len
, (time_t)0, (uint32_t)0);
2205 assert(status
== MEMCACHED_SUCCESS
);
2207 status
= memcached_mget(memc
, &key
, &key_len
, 1);
2208 assert(status
== MEMCACHED_SUCCESS
);
2210 result
= memcached_result_create(memc
, &result_obj
);
2213 memcached_result_create(memc
, &result_obj
);
2214 result
= memcached_fetch_result(memc
, &result_obj
, &status
);
2217 assert(status
== MEMCACHED_SUCCESS
);
2219 memcached_result_free(result
);
2224 #include "ketama_test_cases.h"
2225 test_return
user_supplied_bug18(memcached_st
*trash
)
2227 memcached_return rc
;
2230 memcached_server_st
*server_pool
;
2235 memc
= memcached_create(NULL
);
2238 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2239 assert(rc
== MEMCACHED_SUCCESS
);
2241 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2244 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2245 assert(rc
== MEMCACHED_SUCCESS
);
2247 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2248 assert(value
== MEMCACHED_HASH_MD5
);
2250 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");
2251 memcached_server_push(memc
, server_pool
);
2253 /* verify that the server list was parsed okay. */
2254 assert(memc
->number_of_hosts
== 8);
2255 assert(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
2256 assert(server_pool
[0].port
== 11211);
2257 assert(server_pool
[0].weight
== 600);
2258 assert(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
2259 assert(server_pool
[2].port
== 11211);
2260 assert(server_pool
[2].weight
== 200);
2261 assert(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
2262 assert(server_pool
[7].port
== 11211);
2263 assert(server_pool
[7].weight
== 100);
2265 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
2266 * us test the boundary wraparound.
2268 assert(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
2270 /* verify the standard ketama set. */
2271 for (i
= 0; i
< 99; i
++)
2273 uint32_t server_idx
= memcached_generate_hash(memc
, test_cases
[i
].key
, strlen(test_cases
[i
].key
));
2274 char *hostname
= memc
->hosts
[server_idx
].hostname
;
2275 assert(strcmp(hostname
, test_cases
[i
].server
) == 0);
2278 memcached_server_list_free(server_pool
);
2279 memcached_free(memc
);
2284 static test_return
result_static(memcached_st
*memc
)
2286 memcached_result_st result
;
2287 memcached_result_st
*result_ptr
;
2289 result_ptr
= memcached_result_create(memc
, &result
);
2290 assert(result
.is_allocated
== false);
2292 memcached_result_free(&result
);
2297 static test_return
result_alloc(memcached_st
*memc
)
2299 memcached_result_st
*result
;
2301 result
= memcached_result_create(memc
, NULL
);
2303 memcached_result_free(result
);
2308 static test_return
string_static_null(memcached_st
*memc
)
2310 memcached_string_st string
;
2311 memcached_string_st
*string_ptr
;
2313 string_ptr
= memcached_string_create(memc
, &string
, 0);
2314 assert(string
.is_allocated
== false);
2316 memcached_string_free(&string
);
2321 static test_return
string_alloc_null(memcached_st
*memc
)
2323 memcached_string_st
*string
;
2325 string
= memcached_string_create(memc
, NULL
, 0);
2327 memcached_string_free(string
);
2332 static test_return
string_alloc_with_size(memcached_st
*memc
)
2334 memcached_string_st
*string
;
2336 string
= memcached_string_create(memc
, NULL
, 1024);
2338 memcached_string_free(string
);
2343 static test_return
string_alloc_with_size_toobig(memcached_st
*memc
)
2345 memcached_string_st
*string
;
2347 string
= memcached_string_create(memc
, NULL
, INT64_MAX
);
2348 assert(string
== NULL
);
2353 static test_return
string_alloc_append(memcached_st
*memc
)
2356 char buffer
[SMALL_STRING_LEN
];
2357 memcached_string_st
*string
;
2359 /* Ring the bell! */
2360 memset(buffer
, 6, SMALL_STRING_LEN
);
2362 string
= memcached_string_create(memc
, NULL
, 100);
2365 for (x
= 0; x
< 1024; x
++)
2367 memcached_return rc
;
2368 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
2369 assert(rc
== MEMCACHED_SUCCESS
);
2371 memcached_string_free(string
);
2376 static test_return
string_alloc_append_toobig(memcached_st
*memc
)
2378 memcached_return rc
;
2380 char buffer
[SMALL_STRING_LEN
];
2381 memcached_string_st
*string
;
2383 /* Ring the bell! */
2384 memset(buffer
, 6, SMALL_STRING_LEN
);
2386 string
= memcached_string_create(memc
, NULL
, 100);
2389 for (x
= 0; x
< 1024; x
++)
2391 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
2392 assert(rc
== MEMCACHED_SUCCESS
);
2394 rc
= memcached_string_append(string
, buffer
, INT64_MAX
);
2395 assert(rc
== MEMCACHED_MEMORY_ALLOCATION_FAILURE
);
2396 memcached_string_free(string
);
2401 static test_return
cleanup_pairs(memcached_st
*memc
__attribute__((unused
)))
2403 pairs_free(global_pairs
);
2408 static test_return
generate_pairs(memcached_st
*memc
__attribute__((unused
)))
2410 unsigned long long x
;
2411 global_pairs
= pairs_generate(GLOBAL_COUNT
, 400);
2412 global_count
= GLOBAL_COUNT
;
2414 for (x
= 0; x
< global_count
; x
++)
2416 global_keys
[x
]= global_pairs
[x
].key
;
2417 global_keys_length
[x
]= global_pairs
[x
].key_length
;
2423 static test_return
generate_large_pairs(memcached_st
*memc
__attribute__((unused
)))
2425 unsigned long long x
;
2426 global_pairs
= pairs_generate(GLOBAL2_COUNT
, MEMCACHED_MAX_BUFFER
+10);
2427 global_count
= GLOBAL2_COUNT
;
2429 for (x
= 0; x
< global_count
; x
++)
2431 global_keys
[x
]= global_pairs
[x
].key
;
2432 global_keys_length
[x
]= global_pairs
[x
].key_length
;
2438 static test_return
generate_data(memcached_st
*memc
)
2440 execute_set(memc
, global_pairs
, global_count
);
2445 static test_return
generate_data_with_stats(memcached_st
*memc
)
2447 memcached_stat_st
*stat_p
;
2448 memcached_return rc
;
2449 uint32_t host_index
= 0;
2450 execute_set(memc
, global_pairs
, global_count
);
2452 //TODO: hosts used size stats
2453 stat_p
= memcached_stat(memc
, NULL
, &rc
);
2456 for (host_index
= 0; host_index
< SERVERS_TO_CREATE
; host_index
++)
2458 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
);
2461 memcached_stat_free(NULL
, stat_p
);
2465 static test_return
generate_buffer_data(memcached_st
*memc
)
2470 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
2471 generate_data(memc
);
2476 static test_return
get_read_count(memcached_st
*memc
)
2479 memcached_return rc
;
2480 memcached_st
*clone
;
2482 clone
= memcached_clone(NULL
, memc
);
2485 memcached_server_add_with_weight(clone
, "localhost", 6666, 0);
2489 size_t return_value_length
;
2493 for (x
= count
= 0; x
< global_count
; x
++)
2495 return_value
= memcached_get(clone
, global_keys
[x
], global_keys_length
[x
],
2496 &return_value_length
, &flags
, &rc
);
2497 if (rc
== MEMCACHED_SUCCESS
)
2504 fprintf(stderr
, "\t%u -> %u", global_count
, count
);
2507 memcached_free(clone
);
2512 static test_return
get_read(memcached_st
*memc
)
2515 memcached_return rc
;
2519 size_t return_value_length
;
2522 for (x
= 0; x
< global_count
; x
++)
2524 return_value
= memcached_get(memc
, global_keys
[x
], global_keys_length
[x
],
2525 &return_value_length
, &flags
, &rc
);
2527 assert(return_value);
2528 assert(rc == MEMCACHED_SUCCESS);
2530 if (rc
== MEMCACHED_SUCCESS
&& return_value
)
2538 static test_return
mget_read(memcached_st
*memc
)
2540 memcached_return rc
;
2542 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2543 assert(rc
== MEMCACHED_SUCCESS
);
2544 /* Turn this into a help function */
2546 char return_key
[MEMCACHED_MAX_KEY
];
2547 size_t return_key_length
;
2549 size_t return_value_length
;
2552 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2553 &return_value_length
, &flags
, &rc
)))
2555 assert(return_value
);
2556 assert(rc
== MEMCACHED_SUCCESS
);
2564 static test_return
mget_read_result(memcached_st
*memc
)
2566 memcached_return rc
;
2568 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2569 assert(rc
== MEMCACHED_SUCCESS
);
2570 /* Turn this into a help function */
2572 memcached_result_st results_obj
;
2573 memcached_result_st
*results
;
2575 results
= memcached_result_create(memc
, &results_obj
);
2577 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
2580 assert(rc
== MEMCACHED_SUCCESS
);
2583 memcached_result_free(&results_obj
);
2589 static test_return
mget_read_function(memcached_st
*memc
)
2591 memcached_return rc
;
2592 unsigned int counter
;
2593 unsigned int (*callbacks
[1])(memcached_st
*, memcached_result_st
*, void *);
2595 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2596 assert(rc
== MEMCACHED_SUCCESS
);
2598 callbacks
[0]= &callback_counter
;
2600 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
2605 static test_return
delete_generate(memcached_st
*memc
)
2609 for (x
= 0; x
< global_count
; x
++)
2611 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
2617 static test_return
delete_buffer_generate(memcached_st
*memc
)
2623 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
2625 for (x
= 0; x
< global_count
; x
++)
2627 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
2633 static test_return
free_data(memcached_st
*memc
__attribute__((unused
)))
2635 pairs_free(global_pairs
);
2640 static test_return
add_host_test1(memcached_st
*memc
)
2643 memcached_return rc
;
2644 char servername
[]= "0.example.com";
2645 memcached_server_st
*servers
;
2647 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
2649 assert(1 == memcached_server_list_count(servers
));
2651 for (x
= 2; x
< 20; x
++)
2653 char buffer
[SMALL_STRING_LEN
];
2655 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
2656 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
2658 assert(rc
== MEMCACHED_SUCCESS
);
2659 assert(x
== memcached_server_list_count(servers
));
2662 rc
= memcached_server_push(memc
, servers
);
2663 assert(rc
== MEMCACHED_SUCCESS
);
2664 rc
= memcached_server_push(memc
, servers
);
2665 assert(rc
== MEMCACHED_SUCCESS
);
2667 memcached_server_list_free(servers
);
2672 static memcached_return
pre_nonblock(memcached_st
*memc
)
2674 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
2676 return MEMCACHED_SUCCESS
;
2679 static memcached_return
pre_nonblock_binary(memcached_st
*memc
)
2681 memcached_return rc
= MEMCACHED_FAILURE
;
2682 memcached_st
*clone
;
2684 clone
= memcached_clone(NULL
, memc
);
2686 // The memcached_version needs to be done on a clone, because the server
2687 // will not toggle protocol on an connection.
2688 memcached_version(clone
);
2690 if (clone
->hosts
[0].major_version
>= 1 && clone
->hosts
[0].minor_version
> 2)
2692 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
2693 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
2694 assert(rc
== MEMCACHED_SUCCESS
);
2695 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
2698 memcached_free(clone
);
2702 static memcached_return
pre_murmur(memcached_st
*memc
)
2704 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
2706 return MEMCACHED_SUCCESS
;
2709 static memcached_return
pre_jenkins(memcached_st
*memc
)
2711 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_JENKINS
);
2713 return MEMCACHED_SUCCESS
;
2717 static memcached_return
pre_md5(memcached_st
*memc
)
2719 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MD5
);
2721 return MEMCACHED_SUCCESS
;
2724 static memcached_return
pre_crc(memcached_st
*memc
)
2726 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_CRC
);
2728 return MEMCACHED_SUCCESS
;
2731 static memcached_return
pre_hsieh(memcached_st
*memc
)
2733 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_HSIEH
);
2735 return MEMCACHED_SUCCESS
;
2738 static memcached_return
pre_hash_fnv1_64(memcached_st
*memc
)
2740 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_64
);
2742 return MEMCACHED_SUCCESS
;
2745 static memcached_return
pre_hash_fnv1a_64(memcached_st
*memc
)
2747 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_64
);
2749 return MEMCACHED_SUCCESS
;
2752 static memcached_return
pre_hash_fnv1_32(memcached_st
*memc
)
2754 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_32
);
2756 return MEMCACHED_SUCCESS
;
2759 static memcached_return
pre_hash_fnv1a_32(memcached_st
*memc
)
2761 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_32
);
2763 return MEMCACHED_SUCCESS
;
2766 static memcached_return
pre_behavior_ketama(memcached_st
*memc
)
2768 memcached_return rc
;
2771 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA
, 1);
2772 assert(rc
== MEMCACHED_SUCCESS
);
2774 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA
);
2777 return MEMCACHED_SUCCESS
;
2780 static memcached_return
pre_behavior_ketama_weighted(memcached_st
*memc
)
2782 memcached_return rc
;
2785 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2786 assert(rc
== MEMCACHED_SUCCESS
);
2788 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2791 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2792 assert(rc
== MEMCACHED_SUCCESS
);
2794 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2795 assert(value
== MEMCACHED_HASH_MD5
);
2796 return MEMCACHED_SUCCESS
;
2799 static memcached_return
pre_binary(memcached_st
*memc
)
2801 memcached_return rc
= MEMCACHED_FAILURE
;
2802 memcached_st
*clone
;
2804 clone
= memcached_clone(NULL
, memc
);
2806 // The memcached_version needs to be done on a clone, because the server
2807 // will not toggle protocol on an connection.
2808 memcached_version(clone
);
2810 if (clone
->hosts
[0].major_version
>= 1 && clone
->hosts
[0].minor_version
> 2)
2812 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
2813 assert(rc
== MEMCACHED_SUCCESS
);
2814 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
2817 memcached_free(clone
);
2821 static void my_free(memcached_st
*ptr
__attribute__((unused
)), void *mem
)
2826 static void *my_malloc(memcached_st
*ptr
__attribute__((unused
)), const size_t size
)
2828 return malloc(size
);
2831 static void *my_realloc(memcached_st
*ptr
__attribute__((unused
)), void *mem
, const size_t size
)
2833 return realloc(mem
, size
);
2836 static memcached_return
set_prefix(memcached_st
*memc
)
2838 memcached_return rc
;
2839 const char *key
= "mine";
2842 /* Make sure be default none exists */
2843 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2844 assert(rc
== MEMCACHED_FAILURE
);
2846 /* Test a clean set */
2847 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
2848 assert(rc
== MEMCACHED_SUCCESS
);
2850 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2851 assert(memcmp(value
, key
, 4) == 0);
2852 assert(rc
== MEMCACHED_SUCCESS
);
2854 /* Test that we can turn it off */
2855 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
2856 assert(rc
== MEMCACHED_SUCCESS
);
2858 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2859 assert(rc
== MEMCACHED_FAILURE
);
2861 /* Now setup for main test */
2862 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
2863 assert(rc
== MEMCACHED_SUCCESS
);
2865 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2866 assert(rc
== MEMCACHED_SUCCESS
);
2867 assert(memcmp(value
, key
, 4) == 0);
2869 /* Set to Zero, and then Set to something too large */
2872 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
2873 assert(rc
== MEMCACHED_SUCCESS
);
2875 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2876 assert(rc
== MEMCACHED_FAILURE
);
2877 assert(value
== NULL
);
2879 /* Test a long key for failure */
2880 /* TODO, extend test to determine based on setting, what result should be */
2881 long_key
= "Thisismorethentheallottednumberofcharacters";
2882 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
2883 //assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
2884 assert(rc
== MEMCACHED_SUCCESS
);
2886 /* Now test a key with spaces (which will fail from long key, since bad key is not set) */
2887 long_key
= "This is more then the allotted number of characters";
2888 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
2889 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
2891 /* Test for a bad prefix, but with a short key */
2892 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, 1);
2893 assert(rc
== MEMCACHED_SUCCESS
);
2895 long_key
= "dog cat";
2896 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
2897 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
2900 return MEMCACHED_SUCCESS
;
2903 static memcached_return
set_memory_alloc(memcached_st
*memc
)
2906 memcached_malloc_function test_ptr
;
2907 memcached_return rc
;
2909 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &my_malloc
);
2910 assert(rc
== MEMCACHED_SUCCESS
);
2911 test_ptr
= (memcached_malloc_function
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
2912 assert(rc
== MEMCACHED_SUCCESS
);
2913 assert(test_ptr
== my_malloc
);
2917 memcached_realloc_function test_ptr
;
2918 memcached_return rc
;
2920 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &my_realloc
);
2921 assert(rc
== MEMCACHED_SUCCESS
);
2922 test_ptr
= (memcached_realloc_function
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
2923 assert(rc
== MEMCACHED_SUCCESS
);
2924 assert(test_ptr
== my_realloc
);
2928 memcached_free_function test_ptr
;
2929 memcached_return rc
;
2931 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, my_free
);
2932 assert(rc
== MEMCACHED_SUCCESS
);
2933 test_ptr
= (memcached_free_function
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
2934 assert(rc
== MEMCACHED_SUCCESS
);
2935 assert(test_ptr
== my_free
);
2938 return MEMCACHED_SUCCESS
;
2941 static memcached_return
enable_consistent(memcached_st
*memc
)
2943 memcached_server_distribution value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
2944 memcached_hash hash
;
2945 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
2948 value
= (memcached_server_distribution
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
2949 assert(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
2951 hash
= (memcached_hash
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
2952 assert(hash
== MEMCACHED_HASH_HSIEH
);
2955 return MEMCACHED_SUCCESS
;
2958 static memcached_return
enable_cas(memcached_st
*memc
)
2960 unsigned int set
= 1;
2962 memcached_version(memc
);
2964 if ((memc
->hosts
[0].major_version
>= 1 && (memc
->hosts
[0].minor_version
== 2 && memc
->hosts
[0].micro_version
>= 4))
2965 || memc
->hosts
[0].minor_version
> 2)
2967 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
2969 return MEMCACHED_SUCCESS
;
2972 return MEMCACHED_FAILURE
;
2975 static memcached_return
check_for_1_2_3(memcached_st
*memc
)
2977 memcached_version(memc
);
2979 if ((memc
->hosts
[0].major_version
>= 1 && (memc
->hosts
[0].minor_version
== 2 && memc
->hosts
[0].micro_version
>= 4))
2980 || memc
->hosts
[0].minor_version
> 2)
2981 return MEMCACHED_SUCCESS
;
2983 return MEMCACHED_FAILURE
;
2986 static memcached_return
pre_unix_socket(memcached_st
*memc
)
2988 memcached_return rc
;
2991 memcached_server_list_free(memc
->hosts
);
2993 memc
->number_of_hosts
= 0;
2995 if (stat("/tmp/memcached.socket", &buf
))
2996 return MEMCACHED_FAILURE
;
2998 rc
= memcached_server_add_unix_socket_with_weight(memc
, "/tmp/memcached.socket", 0);
3003 static memcached_return
pre_nodelay(memcached_st
*memc
)
3005 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3006 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
3008 return MEMCACHED_SUCCESS
;
3011 static memcached_return
pre_settimer(memcached_st
*memc
)
3013 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
3014 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
3016 return MEMCACHED_SUCCESS
;
3019 static memcached_return
poll_timeout(memcached_st
*memc
)
3025 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
3027 timeout
= (int32_t)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
3029 assert(timeout
== 100);
3031 return MEMCACHED_SUCCESS
;
3034 static memcached_return
noreply_test(memcached_st
*memc
)
3036 memcached_return ret
;
3037 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
3038 assert(ret
== MEMCACHED_SUCCESS
);
3039 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
3040 assert(ret
== MEMCACHED_SUCCESS
);
3041 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NOREPLY
) == 1);
3042 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
) == 1);
3044 for (int x
= 0; x
< 100; ++x
) {
3046 size_t len
= sprintf(key
, "%d", x
);
3047 ret
= memcached_set(memc
, key
, len
, key
, len
, 0, 0);
3048 assert(ret
== MEMCACHED_SUCCESS
|| ret
== MEMCACHED_BUFFERED
);
3052 ** NOTE: Don't ever do this in your code! this is not a supported use of the
3053 ** API and is _ONLY_ done this way to verify that the library works the
3054 ** way it is supposed to do!!!!
3057 for (int x
= 0; x
< memc
->number_of_hosts
; ++x
) {
3058 no_msg
+= memc
->hosts
[x
].cursor_active
;
3062 ** The binary protocol does not implement quiet commands yet. Fix this
3063 ** test they are implemented!
3065 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1)
3066 assert(no_msg
== 100);
3068 assert(no_msg
== 0);
3070 return MEMCACHED_SUCCESS
;
3073 /* Clean the server before beginning testing */
3075 {"flush", 0, flush_test
},
3076 {"init", 0, init_test
},
3077 {"allocation", 0, allocation_test
},
3078 {"server_list_null_test", 0, server_list_null_test
},
3079 {"server_unsort", 0, server_unsort_test
},
3080 {"server_sort", 0, server_sort_test
},
3081 {"server_sort2", 0, server_sort2_test
},
3082 {"clone_test", 0, clone_test
},
3083 {"error", 0, error_test
},
3084 {"set", 0, set_test
},
3085 {"set2", 0, set_test2
},
3086 {"set3", 0, set_test3
},
3087 {"add", 1, add_test
},
3088 {"replace", 1, replace_test
},
3089 {"delete", 1, delete_test
},
3090 {"get", 1, get_test
},
3091 {"get2", 0, get_test2
},
3092 {"get3", 0, get_test3
},
3093 {"get4", 0, get_test4
},
3094 {"stats_servername", 0, stats_servername_test
},
3095 {"increment", 0, increment_test
},
3096 {"decrement", 0, decrement_test
},
3097 {"quit", 0, quit_test
},
3098 {"mget", 1, mget_test
},
3099 {"mget_result", 1, mget_result_test
},
3100 {"mget_result_alloc", 1, mget_result_alloc_test
},
3101 {"mget_result_function", 1, mget_result_function
},
3102 {"get_stats", 0, get_stats
},
3103 {"add_host_test", 0, add_host_test
},
3104 {"add_host_test_1", 0, add_host_test1
},
3105 {"get_stats_keys", 0, get_stats_keys
},
3106 {"behavior_test", 0, get_stats_keys
},
3107 {"callback_test", 0, get_stats_keys
},
3108 {"version_string_test", 0, version_string_test
},
3109 {"bad_key", 1, bad_key_test
},
3110 {"memcached_server_cursor", 1, memcached_server_cursor_test
},
3111 {"read_through", 1, read_through
},
3112 {"delete_through", 1, delete_through
},
3113 {"noreply", 1, noreply_test
},
3117 test_st async_tests
[] ={
3118 {"add", 1, add_wrapper
},
3122 test_st string_tests
[] ={
3123 {"string static with null", 0, string_static_null
},
3124 {"string alloc with null", 0, string_alloc_null
},
3125 {"string alloc with 1K", 0, string_alloc_with_size
},
3126 {"string alloc with malloc failure", 0, string_alloc_with_size_toobig
},
3127 {"string append", 0, string_alloc_append
},
3128 {"string append failure (too big)", 0, string_alloc_append_toobig
},
3132 test_st result_tests
[] ={
3133 {"result static", 0, result_static
},
3134 {"result alloc", 0, result_alloc
},
3138 test_st version_1_2_3
[] ={
3139 {"append", 0, append_test
},
3140 {"prepend", 0, prepend_test
},
3141 {"cas", 0, cas_test
},
3142 {"cas2", 0, cas2_test
},
3143 {"append_binary", 0, append_binary_test
},
3147 test_st user_tests
[] ={
3148 {"user_supplied_bug1", 0, user_supplied_bug1
},
3149 {"user_supplied_bug2", 0, user_supplied_bug2
},
3150 {"user_supplied_bug3", 0, user_supplied_bug3
},
3151 {"user_supplied_bug4", 0, user_supplied_bug4
},
3152 {"user_supplied_bug5", 1, user_supplied_bug5
},
3153 {"user_supplied_bug6", 1, user_supplied_bug6
},
3154 {"user_supplied_bug7", 1, user_supplied_bug7
},
3155 {"user_supplied_bug8", 1, user_supplied_bug8
},
3156 {"user_supplied_bug9", 1, user_supplied_bug9
},
3157 {"user_supplied_bug10", 1, user_supplied_bug10
},
3158 {"user_supplied_bug11", 1, user_supplied_bug11
},
3159 {"user_supplied_bug12", 1, user_supplied_bug12
},
3160 {"user_supplied_bug13", 1, user_supplied_bug13
},
3161 {"user_supplied_bug14", 1, user_supplied_bug14
},
3162 {"user_supplied_bug15", 1, user_supplied_bug15
},
3163 {"user_supplied_bug16", 1, user_supplied_bug16
},
3166 ** It seems to be something weird with the character sets..
3167 ** value_fetch is unable to parse the value line (iscntrl "fails"), so I
3168 ** guess I need to find out how this is supposed to work.. Perhaps I need
3169 ** to run the test in a specific locale (I tried zh_CN.UTF-8 without success,
3170 ** so just disable the code for now...).
3172 {"user_supplied_bug17", 1, user_supplied_bug17
},
3174 {"user_supplied_bug18", 1, user_supplied_bug18
},
3175 {"user_supplied_bug19", 1, user_supplied_bug19
},
3176 {"user_supplied_bug20", 1, user_supplied_bug20
},
3180 test_st generate_tests
[] ={
3181 {"generate_pairs", 1, generate_pairs
},
3182 {"generate_data", 1, generate_data
},
3183 {"get_read", 0, get_read
},
3184 {"delete_generate", 0, delete_generate
},
3185 {"generate_buffer_data", 1, generate_buffer_data
},
3186 {"delete_buffer", 0, delete_buffer_generate
},
3187 {"generate_data", 1, generate_data
},
3188 {"mget_read", 0, mget_read
},
3189 {"mget_read_result", 0, mget_read_result
},
3190 {"mget_read_function", 0, mget_read_function
},
3191 {"cleanup", 1, cleanup_pairs
},
3192 {"generate_large_pairs", 1, generate_large_pairs
},
3193 {"generate_data", 1, generate_data
},
3194 {"generate_buffer_data", 1, generate_buffer_data
},
3195 {"cleanup", 1, cleanup_pairs
},
3199 test_st consistent_tests
[] ={
3200 {"generate_pairs", 1, generate_pairs
},
3201 {"generate_data", 1, generate_data
},
3202 {"get_read", 0, get_read_count
},
3203 {"cleanup", 1, cleanup_pairs
},
3207 test_st consistent_weighted_tests
[] ={
3208 {"generate_pairs", 1, generate_pairs
},
3209 {"generate_data", 1, generate_data_with_stats
},
3210 {"get_read", 0, get_read_count
},
3211 {"cleanup", 1, cleanup_pairs
},
3215 collection_st collection
[] ={
3216 {"block", 0, 0, tests
},
3217 {"binary", pre_binary
, 0, tests
},
3218 {"nonblock", pre_nonblock
, 0, tests
},
3219 {"nodelay", pre_nodelay
, 0, tests
},
3220 {"settimer", pre_settimer
, 0, tests
},
3221 {"md5", pre_md5
, 0, tests
},
3222 {"crc", pre_crc
, 0, tests
},
3223 {"hsieh", pre_hsieh
, 0, tests
},
3224 {"jenkins", pre_jenkins
, 0, tests
},
3225 {"fnv1_64", pre_hash_fnv1_64
, 0, tests
},
3226 {"fnv1a_64", pre_hash_fnv1a_64
, 0, tests
},
3227 {"fnv1_32", pre_hash_fnv1_32
, 0, tests
},
3228 {"fnv1a_32", pre_hash_fnv1a_32
, 0, tests
},
3229 {"ketama", pre_behavior_ketama
, 0, tests
},
3230 {"unix_socket", pre_unix_socket
, 0, tests
},
3231 {"unix_socket_nodelay", pre_nodelay
, 0, tests
},
3232 {"poll_timeout", poll_timeout
, 0, tests
},
3233 {"gets", enable_cas
, 0, tests
},
3234 {"consistent", enable_consistent
, 0, tests
},
3235 {"memory_allocators", set_memory_alloc
, 0, tests
},
3236 {"prefix", set_prefix
, 0, tests
},
3237 {"version_1_2_3", check_for_1_2_3
, 0, version_1_2_3
},
3238 {"string", 0, 0, string_tests
},
3239 {"result", 0, 0, result_tests
},
3240 {"async", pre_nonblock
, 0, async_tests
},
3241 {"async_binary", pre_nonblock_binary
, 0, async_tests
},
3242 {"user", 0, 0, user_tests
},
3243 {"generate", 0, 0, generate_tests
},
3244 {"generate_hsieh", pre_hsieh
, 0, generate_tests
},
3245 {"generate_ketama", pre_behavior_ketama
, 0, generate_tests
},
3246 {"generate_hsieh_consistent", enable_consistent
, 0, generate_tests
},
3247 {"generate_md5", pre_md5
, 0, generate_tests
},
3248 {"generate_murmur", pre_murmur
, 0, generate_tests
},
3249 {"generate_jenkins", pre_jenkins
, 0, generate_tests
},
3250 {"generate_nonblock", pre_nonblock
, 0, generate_tests
},
3251 {"consistent_not", 0, 0, consistent_tests
},
3252 {"consistent_ketama", pre_behavior_ketama
, 0, consistent_tests
},
3253 {"consistent_ketama_weighted", pre_behavior_ketama_weighted
, 0, consistent_weighted_tests
},
3257 #define SERVERS_TO_CREATE 5
3259 /* Prototypes for functions we will pass to test framework */
3260 void *world_create(void);
3261 void world_destroy(void *p
);
3263 void *world_create(void)
3265 server_startup_st
*construct
;
3267 construct
= (server_startup_st
*)malloc(sizeof(server_startup_st
));
3268 memset(construct
, 0, sizeof(server_startup_st
));
3269 construct
->count
= SERVERS_TO_CREATE
;
3271 server_startup(construct
);
3277 void world_destroy(void *p
)
3279 server_startup_st
*construct
= (server_startup_st
*)p
;
3280 memcached_server_st
*servers
= (memcached_server_st
*)construct
->servers
;
3281 memcached_server_list_free(servers
);
3283 server_shutdown(construct
);
3287 void get_world(world_st
*world
)
3289 world
->collections
= collection
;
3290 world
->create
= world_create
;
3291 world
->destroy
= world_destroy
;