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 char* keys
[2] = { (char*)key
, NULL
};
402 size_t keylengths
[2] = { strlen(key
), 0 };
403 size_t value_length
= strlen(value
);
404 const char *value2
= "change the value";
405 size_t value2_length
= strlen(value2
);
407 memcached_result_st results_obj
;
408 memcached_result_st
*results
;
411 rc
= memcached_flush(memc
, 0);
412 assert(rc
== MEMCACHED_SUCCESS
);
414 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
416 rc
= memcached_set(memc
, key
, strlen(key
),
417 value
, strlen(value
),
418 (time_t)0, (uint32_t)0);
419 assert(rc
== MEMCACHED_SUCCESS
);
421 rc
= memcached_mget(memc
, keys
, keylengths
, 1);
423 results
= memcached_result_create(memc
, &results_obj
);
425 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
427 assert(rc
== MEMCACHED_SUCCESS
);
428 WATCHPOINT_ASSERT(memcached_result_cas(results
));
429 assert(!memcmp(value
, memcached_result_value(results
), value_length
));
430 assert(strlen(memcached_result_value(results
)) == value_length
);
431 assert(rc
== MEMCACHED_SUCCESS
);
432 uint64_t cas
= memcached_result_cas(results
);
435 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
436 assert(rc
== MEMCACHED_END
);
437 assert(results
== NULL
);
440 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
441 assert(rc
== MEMCACHED_SUCCESS
);
444 * The item will have a new cas value, so try to set it again with the old
445 * value. This should fail!
447 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
448 assert(rc
== MEMCACHED_DATA_EXISTS
);
450 memcached_result_free(&results_obj
);
455 static test_return
prepend_test(memcached_st
*memc
)
459 char *value
= "people";
463 rc
= memcached_flush(memc
, 0);
464 assert(rc
== MEMCACHED_SUCCESS
);
466 rc
= memcached_set(memc
, key
, strlen(key
),
467 value
, strlen(value
),
468 (time_t)0, (uint32_t)0);
469 assert(rc
== MEMCACHED_SUCCESS
);
471 rc
= memcached_prepend(memc
, key
, strlen(key
),
472 "the ", strlen("the "),
473 (time_t)0, (uint32_t)0);
474 assert(rc
== MEMCACHED_SUCCESS
);
476 rc
= memcached_prepend(memc
, key
, strlen(key
),
477 "we ", strlen("we "),
478 (time_t)0, (uint32_t)0);
479 assert(rc
== MEMCACHED_SUCCESS
);
481 value
= memcached_get(memc
, key
, strlen(key
),
482 &value_length
, &flags
, &rc
);
483 assert(!memcmp(value
, "we the people", strlen("we the people")));
484 assert(strlen("we the people") == value_length
);
485 assert(rc
== MEMCACHED_SUCCESS
);
492 Set the value, then quit to make sure it is flushed.
493 Come back in and test that add fails.
495 static test_return
add_test(memcached_st
*memc
)
499 char *value
= "when we sanitize";
500 unsigned long long setting_value
;
502 setting_value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
504 rc
= memcached_set(memc
, key
, strlen(key
),
505 value
, strlen(value
),
506 (time_t)0, (uint32_t)0);
507 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
508 memcached_quit(memc
);
509 rc
= memcached_add(memc
, key
, strlen(key
),
510 value
, strlen(value
),
511 (time_t)0, (uint32_t)0);
513 /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */
515 assert(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_STORED
);
517 assert(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_DATA_EXISTS
);
522 static test_return
add_wrapper(memcached_st
*memc
)
526 for (x
= 0; x
< 10000; x
++)
532 static test_return
replace_test(memcached_st
*memc
)
536 char *value
= "when we sanitize";
537 char *original
= "first we insert some data";
539 rc
= memcached_set(memc
, key
, strlen(key
),
540 original
, strlen(original
),
541 (time_t)0, (uint32_t)0);
542 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
544 rc
= memcached_replace(memc
, key
, strlen(key
),
545 value
, strlen(value
),
546 (time_t)0, (uint32_t)0);
547 assert(rc
== MEMCACHED_SUCCESS
);
552 static test_return
delete_test(memcached_st
*memc
)
556 char *value
= "when we sanitize";
558 rc
= memcached_set(memc
, key
, strlen(key
),
559 value
, strlen(value
),
560 (time_t)0, (uint32_t)0);
561 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
563 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
564 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
569 static test_return
flush_test(memcached_st
*memc
)
573 rc
= memcached_flush(memc
, 0);
574 assert(rc
== MEMCACHED_SUCCESS
);
579 static memcached_return
server_function(memcached_st
*ptr
__attribute__((unused
)),
580 memcached_server_st
*server
__attribute__((unused
)),
581 void *context
__attribute__((unused
)))
585 return MEMCACHED_SUCCESS
;
588 static test_return
memcached_server_cursor_test(memcached_st
*memc
)
590 char *context
= "foo bad";
591 memcached_server_function callbacks
[1];
593 callbacks
[0]= server_function
;
594 memcached_server_cursor(memc
, callbacks
, context
, 1);
599 static test_return
bad_key_test(memcached_st
*memc
)
602 char *key
= "foo bad";
604 size_t string_length
;
608 size_t max_keylen
= 0xffff;
610 clone
= memcached_clone(NULL
, memc
);
613 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
614 assert(rc
== MEMCACHED_SUCCESS
);
616 /* All keys are valid in the binary protocol (except for length) */
617 if (memcached_behavior_get(clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 0)
619 string
= memcached_get(clone
, key
, strlen(key
),
620 &string_length
, &flags
, &rc
);
621 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
622 assert(string_length
== 0);
626 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
627 assert(rc
== MEMCACHED_SUCCESS
);
628 string
= memcached_get(clone
, key
, strlen(key
),
629 &string_length
, &flags
, &rc
);
630 assert(rc
== MEMCACHED_NOTFOUND
);
631 assert(string_length
== 0);
634 /* Test multi key for bad keys */
635 char *keys
[] = { "GoodKey", "Bad Key", "NotMine" };
636 size_t key_lengths
[] = { 7, 7, 7 };
638 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
639 assert(rc
== MEMCACHED_SUCCESS
);
641 rc
= memcached_mget(clone
, keys
, key_lengths
, 3);
642 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
644 rc
= memcached_mget_by_key(clone
, "foo daddy", 9, keys
, key_lengths
, 1);
645 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
649 /* The following test should be moved to the end of this function when the
650 memcached server is updated to allow max size length of the keys in the
653 rc
= memcached_callback_set(clone
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
654 assert(rc
== MEMCACHED_SUCCESS
);
656 char *longkey
= malloc(max_keylen
+ 1);
659 memset(longkey
, 'a', max_keylen
+ 1);
660 string
= memcached_get(clone
, longkey
, max_keylen
,
661 &string_length
, &flags
, &rc
);
662 assert(rc
== MEMCACHED_NOTFOUND
);
663 assert(string_length
== 0);
666 string
= memcached_get(clone
, longkey
, max_keylen
+ 1,
667 &string_length
, &flags
, &rc
);
668 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
669 assert(string_length
== 0);
676 /* Make sure zero length keys are marked as bad */
678 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
679 assert(rc
== MEMCACHED_SUCCESS
);
680 string
= memcached_get(clone
, key
, 0,
681 &string_length
, &flags
, &rc
);
682 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
683 assert(string_length
== 0);
686 memcached_free(clone
);
691 #define READ_THROUGH_VALUE "set for me"
692 static memcached_return
read_through_trigger(memcached_st
*memc
__attribute__((unused
)),
693 char *key
__attribute__((unused
)),
694 size_t key_length
__attribute__((unused
)),
695 memcached_result_st
*result
)
698 return memcached_result_set_value(result
, READ_THROUGH_VALUE
, strlen(READ_THROUGH_VALUE
));
701 static test_return
read_through(memcached_st
*memc
)
706 size_t string_length
;
709 string
= memcached_get(memc
, key
, strlen(key
),
710 &string_length
, &flags
, &rc
);
712 assert(rc
== MEMCACHED_NOTFOUND
);
713 assert(string_length
== 0);
716 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_GET_FAILURE
, (void *)read_through_trigger
);
717 assert(rc
== MEMCACHED_SUCCESS
);
719 string
= memcached_get(memc
, key
, strlen(key
),
720 &string_length
, &flags
, &rc
);
722 assert(rc
== MEMCACHED_SUCCESS
);
723 assert(string_length
== strlen(READ_THROUGH_VALUE
));
724 assert(!strcmp(READ_THROUGH_VALUE
, string
));
727 string
= memcached_get(memc
, key
, strlen(key
),
728 &string_length
, &flags
, &rc
);
730 assert(rc
== MEMCACHED_SUCCESS
);
731 assert(string_length
== strlen(READ_THROUGH_VALUE
));
732 assert(!strcmp(READ_THROUGH_VALUE
, string
));
738 static memcached_return
delete_trigger(memcached_st
*ptr
__attribute__((unused
)),
740 size_t key_length
__attribute__((unused
)))
744 return MEMCACHED_SUCCESS
;
747 static test_return
delete_through(memcached_st
*memc
)
749 memcached_trigger_delete_key callback
;
752 callback
= delete_trigger
;
754 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_DELETE_TRIGGER
, (void*)callback
);
755 assert(rc
== MEMCACHED_SUCCESS
);
760 static test_return
get_test(memcached_st
*memc
)
765 size_t string_length
;
768 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
769 assert(rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_NOTFOUND
);
771 string
= memcached_get(memc
, key
, strlen(key
),
772 &string_length
, &flags
, &rc
);
774 assert(rc
== MEMCACHED_NOTFOUND
);
775 assert(string_length
== 0);
781 static test_return
get_test2(memcached_st
*memc
)
785 char *value
= "when we sanitize";
787 size_t string_length
;
790 rc
= memcached_set(memc
, key
, strlen(key
),
791 value
, strlen(value
),
792 (time_t)0, (uint32_t)0);
793 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
795 string
= memcached_get(memc
, key
, strlen(key
),
796 &string_length
, &flags
, &rc
);
799 assert(rc
== MEMCACHED_SUCCESS
);
800 assert(string_length
== strlen(value
));
801 assert(!memcmp(string
, value
, string_length
));
808 static test_return
set_test2(memcached_st
*memc
)
812 char *value
= "train in the brain";
813 size_t value_length
= strlen(value
);
816 for (x
= 0; x
< 10; x
++)
818 rc
= memcached_set(memc
, key
, strlen(key
),
820 (time_t)0, (uint32_t)0);
821 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
827 static test_return
set_test3(memcached_st
*memc
)
832 size_t value_length
= 8191;
835 value
= (char*)malloc(value_length
);
838 for (x
= 0; x
< value_length
; x
++)
839 value
[x
] = (char) (x
% 127);
841 for (x
= 0; x
< 1; x
++)
843 rc
= memcached_set(memc
, key
, strlen(key
),
845 (time_t)0, (uint32_t)0);
846 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
854 static test_return
get_test3(memcached_st
*memc
)
859 size_t value_length
= 8191;
861 size_t string_length
;
865 value
= (char*)malloc(value_length
);
868 for (x
= 0; x
< value_length
; x
++)
869 value
[x
] = (char) (x
% 127);
871 rc
= memcached_set(memc
, key
, strlen(key
),
873 (time_t)0, (uint32_t)0);
874 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
876 string
= memcached_get(memc
, key
, strlen(key
),
877 &string_length
, &flags
, &rc
);
879 assert(rc
== MEMCACHED_SUCCESS
);
881 assert(string_length
== value_length
);
882 assert(!memcmp(string
, value
, string_length
));
890 static test_return
get_test4(memcached_st
*memc
)
895 size_t value_length
= 8191;
897 size_t string_length
;
901 value
= (char*)malloc(value_length
);
904 for (x
= 0; x
< value_length
; x
++)
905 value
[x
] = (char) (x
% 127);
907 rc
= memcached_set(memc
, key
, strlen(key
),
909 (time_t)0, (uint32_t)0);
910 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
912 for (x
= 0; x
< 10; x
++)
914 string
= memcached_get(memc
, key
, strlen(key
),
915 &string_length
, &flags
, &rc
);
917 assert(rc
== MEMCACHED_SUCCESS
);
919 assert(string_length
== value_length
);
920 assert(!memcmp(string
, value
, string_length
));
929 /* Do not copy the style of this code, I just access hosts to testthis function */
930 static test_return
stats_servername_test(memcached_st
*memc
)
933 memcached_stat_st stat
;
934 rc
= memcached_stat_servername(&stat
, NULL
,
935 memc
->hosts
[0].hostname
,
936 memc
->hosts
[0].port
);
941 static test_return
increment_test(memcached_st
*memc
)
948 rc
= memcached_set(memc
, key
, strlen(key
),
949 value
, strlen(value
),
950 (time_t)0, (uint32_t)0);
951 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
953 rc
= memcached_increment(memc
, key
, strlen(key
),
955 assert(rc
== MEMCACHED_SUCCESS
);
956 assert(new_number
== 1);
958 rc
= memcached_increment(memc
, key
, strlen(key
),
960 assert(rc
== MEMCACHED_SUCCESS
);
961 assert(new_number
== 2);
966 static test_return
decrement_test(memcached_st
*memc
)
973 rc
= memcached_set(memc
, key
, strlen(key
),
974 value
, strlen(value
),
975 (time_t)0, (uint32_t)0);
976 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
978 rc
= memcached_decrement(memc
, key
, strlen(key
),
980 assert(rc
== MEMCACHED_SUCCESS
);
981 assert(new_number
== 2);
983 rc
= memcached_decrement(memc
, key
, strlen(key
),
985 assert(rc
== MEMCACHED_SUCCESS
);
986 assert(new_number
== 1);
991 static test_return
quit_test(memcached_st
*memc
)
995 char *value
= "sanford and sun";
997 rc
= memcached_set(memc
, key
, strlen(key
),
998 value
, strlen(value
),
999 (time_t)10, (uint32_t)3);
1000 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1001 memcached_quit(memc
);
1003 rc
= memcached_set(memc
, key
, strlen(key
),
1004 value
, strlen(value
),
1005 (time_t)50, (uint32_t)9);
1006 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1011 static test_return
mget_result_test(memcached_st
*memc
)
1013 memcached_return rc
;
1014 char *keys
[]= {"fudge", "son", "food"};
1015 size_t key_length
[]= {5, 3, 4};
1018 memcached_result_st results_obj
;
1019 memcached_result_st
*results
;
1021 results
= memcached_result_create(memc
, &results_obj
);
1023 assert(&results_obj
== results
);
1025 /* We need to empty the server before continueing test */
1026 rc
= memcached_flush(memc
, 0);
1027 assert(rc
== MEMCACHED_SUCCESS
);
1029 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1030 assert(rc
== MEMCACHED_SUCCESS
);
1032 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1037 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1039 assert(rc
== MEMCACHED_END
);
1041 for (x
= 0; x
< 3; x
++)
1043 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1044 keys
[x
], key_length
[x
],
1045 (time_t)50, (uint32_t)9);
1046 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1049 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1050 assert(rc
== MEMCACHED_SUCCESS
);
1052 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1055 assert(&results_obj
== results
);
1056 assert(rc
== MEMCACHED_SUCCESS
);
1057 assert(memcached_result_key_length(results
) == memcached_result_length(results
));
1058 assert(!memcmp(memcached_result_key_value(results
),
1059 memcached_result_value(results
),
1060 memcached_result_length(results
)));
1063 memcached_result_free(&results_obj
);
1068 static test_return
mget_result_alloc_test(memcached_st
*memc
)
1070 memcached_return rc
;
1071 char *keys
[]= {"fudge", "son", "food"};
1072 size_t key_length
[]= {5, 3, 4};
1075 memcached_result_st
*results
;
1077 /* We need to empty the server before continueing test */
1078 rc
= memcached_flush(memc
, 0);
1079 assert(rc
== MEMCACHED_SUCCESS
);
1081 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1082 assert(rc
== MEMCACHED_SUCCESS
);
1084 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)) != NULL
)
1089 assert(rc
== MEMCACHED_END
);
1091 for (x
= 0; x
< 3; x
++)
1093 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1094 keys
[x
], key_length
[x
],
1095 (time_t)50, (uint32_t)9);
1096 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1099 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1100 assert(rc
== MEMCACHED_SUCCESS
);
1103 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1106 assert(rc
== MEMCACHED_SUCCESS
);
1107 assert(memcached_result_key_length(results
) == memcached_result_length(results
));
1108 assert(!memcmp(memcached_result_key_value(results
),
1109 memcached_result_value(results
),
1110 memcached_result_length(results
)));
1111 memcached_result_free(results
);
1118 /* Count the results */
1119 static memcached_return
callback_counter(memcached_st
*ptr
__attribute__((unused
)),
1120 memcached_result_st
*result
__attribute__((unused
)),
1123 unsigned int *counter
= (unsigned int *)context
;
1125 *counter
= *counter
+ 1;
1127 return MEMCACHED_SUCCESS
;
1130 static test_return
mget_result_function(memcached_st
*memc
)
1132 memcached_return rc
;
1133 char *keys
[]= {"fudge", "son", "food"};
1134 size_t key_length
[]= {5, 3, 4};
1136 unsigned int counter
;
1137 memcached_execute_function callbacks
[1];
1139 /* We need to empty the server before continueing test */
1140 rc
= memcached_flush(memc
, 0);
1141 for (x
= 0; x
< 3; x
++)
1143 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1144 keys
[x
], key_length
[x
],
1145 (time_t)50, (uint32_t)9);
1146 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1149 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1150 assert(rc
== MEMCACHED_SUCCESS
);
1152 callbacks
[0]= &callback_counter
;
1154 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
1156 assert(counter
== 3);
1161 static test_return
mget_test(memcached_st
*memc
)
1163 memcached_return rc
;
1164 char *keys
[]= {"fudge", "son", "food"};
1165 size_t key_length
[]= {5, 3, 4};
1169 char return_key
[MEMCACHED_MAX_KEY
];
1170 size_t return_key_length
;
1172 size_t return_value_length
;
1174 /* We need to empty the server before continueing test */
1175 rc
= memcached_flush(memc
, 0);
1176 assert(rc
== MEMCACHED_SUCCESS
);
1178 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1179 assert(rc
== MEMCACHED_SUCCESS
);
1181 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1182 &return_value_length
, &flags
, &rc
)) != NULL
)
1184 assert(return_value
);
1186 assert(!return_value
);
1187 assert(return_value_length
== 0);
1188 assert(rc
== MEMCACHED_END
);
1190 for (x
= 0; x
< 3; x
++)
1192 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1193 keys
[x
], key_length
[x
],
1194 (time_t)50, (uint32_t)9);
1195 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1198 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1199 assert(rc
== MEMCACHED_SUCCESS
);
1202 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1203 &return_value_length
, &flags
, &rc
)))
1205 assert(return_value
);
1206 assert(rc
== MEMCACHED_SUCCESS
);
1207 assert(return_key_length
== return_value_length
);
1208 assert(!memcmp(return_value
, return_key
, return_value_length
));
1216 static test_return
get_stats_keys(memcached_st
*memc
)
1220 memcached_stat_st stat
;
1221 memcached_return rc
;
1223 list
= memcached_stat_get_keys(memc
, &stat
, &rc
);
1224 assert(rc
== MEMCACHED_SUCCESS
);
1225 for (ptr
= list
; *ptr
; ptr
++)
1234 static test_return
version_string_test(memcached_st
*memc
__attribute__((unused
)))
1236 const char *version_string
;
1238 version_string
= memcached_lib_version();
1240 assert(!strcmp(version_string
, LIBMEMCACHED_VERSION_STRING
));
1245 static test_return
get_stats(memcached_st
*memc
)
1250 memcached_return rc
;
1251 memcached_stat_st
*stat
;
1253 stat
= memcached_stat(memc
, NULL
, &rc
);
1254 assert(rc
== MEMCACHED_SUCCESS
);
1256 assert(rc
== MEMCACHED_SUCCESS
);
1259 for (x
= 0; x
< memcached_server_count(memc
); x
++)
1261 list
= memcached_stat_get_keys(memc
, stat
+x
, &rc
);
1262 assert(rc
== MEMCACHED_SUCCESS
);
1263 for (ptr
= list
; *ptr
; ptr
++);
1268 memcached_stat_free(NULL
, stat
);
1273 static test_return
add_host_test(memcached_st
*memc
)
1276 memcached_server_st
*servers
;
1277 memcached_return rc
;
1278 char servername
[]= "0.example.com";
1280 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
1282 assert(1 == memcached_server_list_count(servers
));
1284 for (x
= 2; x
< 20; x
++)
1286 char buffer
[SMALL_STRING_LEN
];
1288 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
1289 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
1291 assert(rc
== MEMCACHED_SUCCESS
);
1292 assert(x
== memcached_server_list_count(servers
));
1295 rc
= memcached_server_push(memc
, servers
);
1296 assert(rc
== MEMCACHED_SUCCESS
);
1297 rc
= memcached_server_push(memc
, servers
);
1298 assert(rc
== MEMCACHED_SUCCESS
);
1300 memcached_server_list_free(servers
);
1305 static memcached_return
clone_test_callback(memcached_st
*parent
__attribute__((unused
)), memcached_st
*clone
__attribute__((unused
)))
1307 return MEMCACHED_SUCCESS
;
1310 static memcached_return
cleanup_test_callback(memcached_st
*ptr
__attribute__((unused
)))
1312 return MEMCACHED_SUCCESS
;
1315 static test_return
callback_test(memcached_st
*memc
)
1317 /* Test User Data */
1321 memcached_return rc
;
1323 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_USER_DATA
, &x
);
1324 assert(rc
== MEMCACHED_SUCCESS
);
1325 test_ptr
= (int *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_USER_DATA
, &rc
);
1326 assert(*test_ptr
== x
);
1329 /* Test Clone Callback */
1331 memcached_clone_func temp_function
;
1332 memcached_return rc
;
1334 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, (void*)clone_test_callback
);
1335 assert(rc
== MEMCACHED_SUCCESS
);
1336 temp_function
= (memcached_clone_func
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1337 assert(temp_function
== clone_test_callback
);
1340 /* Test Cleanup Callback */
1342 memcached_cleanup_func temp_function
;
1343 memcached_return rc
;
1345 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, (void*)cleanup_test_callback
);
1346 assert(rc
== MEMCACHED_SUCCESS
);
1347 temp_function
= (memcached_cleanup_func
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1348 assert(temp_function
== cleanup_test_callback
);
1354 /* We don't test the behavior itself, we test the switches */
1355 static test_return
behavior_test(memcached_st
*memc
)
1360 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1361 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1364 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1365 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1368 set
= MEMCACHED_HASH_MD5
;
1369 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1370 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1371 assert(value
== MEMCACHED_HASH_MD5
);
1375 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1376 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1379 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1380 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1383 set
= MEMCACHED_HASH_DEFAULT
;
1384 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1385 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1386 assert(value
== MEMCACHED_HASH_DEFAULT
);
1388 set
= MEMCACHED_HASH_CRC
;
1389 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1390 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1391 assert(value
== MEMCACHED_HASH_CRC
);
1393 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1396 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1402 /* Test case provided by Cal Haldenbrand */
1403 static test_return
user_supplied_bug1(memcached_st
*memc
)
1405 unsigned int setter
= 1;
1408 unsigned long long total
= 0;
1411 char randomstuff
[6 * 1024];
1412 memcached_return rc
;
1414 memset(randomstuff
, 0, 6 * 1024);
1416 /* We just keep looking at the same values over and over */
1419 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1420 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1424 for (x
= 0 ; total
< 20 * 1024576 ; x
++ )
1428 size
= (rand() % ( 5 * 1024 ) ) + 400;
1429 memset(randomstuff
, 0, 6 * 1024);
1430 assert(size
< 6 * 1024); /* Being safe here */
1432 for (j
= 0 ; j
< size
;j
++)
1433 randomstuff
[j
] = (char) (rand() % 26) + 97;
1436 sprintf(key
, "%d", x
);
1437 rc
= memcached_set(memc
, key
, strlen(key
),
1438 randomstuff
, strlen(randomstuff
), 10, 0);
1439 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1440 /* If we fail, lets try again */
1441 if (rc
!= MEMCACHED_SUCCESS
&& rc
!= MEMCACHED_BUFFERED
)
1442 rc
= memcached_set(memc
, key
, strlen(key
),
1443 randomstuff
, strlen(randomstuff
), 10, 0);
1444 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1450 /* Test case provided by Cal Haldenbrand */
1451 static test_return
user_supplied_bug2(memcached_st
*memc
)
1454 unsigned int setter
;
1456 unsigned long long total
;
1459 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1460 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1462 setter
= 20 * 1024576;
1463 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1464 setter
= 20 * 1024576;
1465 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1466 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1467 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1469 for (x
= 0, errors
= 0, total
= 0 ; total
< 20 * 1024576 ; x
++)
1472 for (x
= 0, errors
= 0, total
= 0 ; total
< 24576 ; x
++)
1474 memcached_return rc
= MEMCACHED_SUCCESS
;
1475 char buffer
[SMALL_STRING_LEN
];
1480 memset(buffer
, 0, SMALL_STRING_LEN
);
1482 snprintf(buffer
, SMALL_STRING_LEN
, "%u", x
);
1483 getval
= memcached_get(memc
, buffer
, strlen(buffer
),
1484 &val_len
, &flags
, &rc
);
1485 if (rc
!= MEMCACHED_SUCCESS
)
1487 if (rc
== MEMCACHED_NOTFOUND
)
1491 WATCHPOINT_ERROR(rc
);
1505 /* Do a large mget() over all the keys we think exist */
1506 #define KEY_COUNT 3000 // * 1024576
1507 static test_return
user_supplied_bug3(memcached_st
*memc
)
1509 memcached_return rc
;
1510 unsigned int setter
;
1513 size_t key_lengths
[KEY_COUNT
];
1516 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1517 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1519 setter
= 20 * 1024576;
1520 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1521 setter
= 20 * 1024576;
1522 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1523 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1524 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1527 keys
= (char **)malloc(sizeof(char *) * KEY_COUNT
);
1529 memset(keys
, 0, (sizeof(char *) * KEY_COUNT
));
1530 for (x
= 0; x
< KEY_COUNT
; x
++)
1534 snprintf(buffer
, 30, "%u", x
);
1535 keys
[x
]= strdup(buffer
);
1536 key_lengths
[x
]= strlen(keys
[x
]);
1539 rc
= memcached_mget(memc
, keys
, key_lengths
, KEY_COUNT
);
1540 assert(rc
== MEMCACHED_SUCCESS
);
1542 /* Turn this into a help function */
1544 char return_key
[MEMCACHED_MAX_KEY
];
1545 size_t return_key_length
;
1547 size_t return_value_length
;
1550 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1551 &return_value_length
, &flags
, &rc
)))
1553 assert(return_value
);
1554 assert(rc
== MEMCACHED_SUCCESS
);
1559 for (x
= 0; x
< KEY_COUNT
; x
++)
1566 /* Make sure we behave properly if server list has no values */
1567 static test_return
user_supplied_bug4(memcached_st
*memc
)
1569 memcached_return rc
;
1570 char *keys
[]= {"fudge", "son", "food"};
1571 size_t key_length
[]= {5, 3, 4};
1574 char return_key
[MEMCACHED_MAX_KEY
];
1575 size_t return_key_length
;
1577 size_t return_value_length
;
1579 /* Here we free everything before running a bunch of mget tests */
1581 memcached_server_list_free(memc
->hosts
);
1583 memc
->number_of_hosts
= 0;
1587 /* We need to empty the server before continueing test */
1588 rc
= memcached_flush(memc
, 0);
1589 assert(rc
== MEMCACHED_NO_SERVERS
);
1591 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1592 assert(rc
== MEMCACHED_NO_SERVERS
);
1594 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1595 &return_value_length
, &flags
, &rc
)) != NULL
)
1597 assert(return_value
);
1599 assert(!return_value
);
1600 assert(return_value_length
== 0);
1601 assert(rc
== MEMCACHED_NO_SERVERS
);
1603 for (x
= 0; x
< 3; x
++)
1605 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1606 keys
[x
], key_length
[x
],
1607 (time_t)50, (uint32_t)9);
1608 assert(rc
== MEMCACHED_NO_SERVERS
);
1611 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1612 assert(rc
== MEMCACHED_NO_SERVERS
);
1615 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1616 &return_value_length
, &flags
, &rc
)))
1618 assert(return_value
);
1619 assert(rc
== MEMCACHED_SUCCESS
);
1620 assert(return_key_length
== return_value_length
);
1621 assert(!memcmp(return_value
, return_key
, return_value_length
));
1629 #define VALUE_SIZE_BUG5 1048064
1630 static test_return
user_supplied_bug5(memcached_st
*memc
)
1632 memcached_return rc
;
1633 char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1634 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1635 char return_key
[MEMCACHED_MAX_KEY
];
1636 size_t return_key_length
;
1638 size_t value_length
;
1642 char insert_data
[VALUE_SIZE_BUG5
];
1644 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1645 insert_data
[x
]= rand();
1647 memcached_flush(memc
, 0);
1648 value
= memcached_get(memc
, keys
[0], key_length
[0],
1649 &value_length
, &flags
, &rc
);
1650 assert(value
== NULL
);
1651 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1654 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1655 &value_length
, &flags
, &rc
)))
1659 for (x
= 0; x
< 4; x
++)
1661 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1662 insert_data
, VALUE_SIZE_BUG5
,
1663 (time_t)0, (uint32_t)0);
1664 assert(rc
== MEMCACHED_SUCCESS
);
1667 for (x
= 0; x
< 10; x
++)
1669 value
= memcached_get(memc
, keys
[0], key_length
[0],
1670 &value_length
, &flags
, &rc
);
1674 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1676 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1677 &value_length
, &flags
, &rc
)))
1688 static test_return
user_supplied_bug6(memcached_st
*memc
)
1690 memcached_return rc
;
1691 char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1692 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1693 char return_key
[MEMCACHED_MAX_KEY
];
1694 size_t return_key_length
;
1696 size_t value_length
;
1700 char insert_data
[VALUE_SIZE_BUG5
];
1702 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1703 insert_data
[x
]= rand();
1705 memcached_flush(memc
, 0);
1706 value
= memcached_get(memc
, keys
[0], key_length
[0],
1707 &value_length
, &flags
, &rc
);
1708 assert(value
== NULL
);
1709 assert(rc
== MEMCACHED_NOTFOUND
);
1710 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1711 assert(rc
== MEMCACHED_SUCCESS
);
1714 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1715 &value_length
, &flags
, &rc
)))
1718 assert(rc
== MEMCACHED_END
);
1720 for (x
= 0; x
< 4; x
++)
1722 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1723 insert_data
, VALUE_SIZE_BUG5
,
1724 (time_t)0, (uint32_t)0);
1725 assert(rc
== MEMCACHED_SUCCESS
);
1728 for (x
= 0; x
< 2; x
++)
1730 value
= memcached_get(memc
, keys
[0], key_length
[0],
1731 &value_length
, &flags
, &rc
);
1735 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1736 assert(rc
== MEMCACHED_SUCCESS
);
1738 /* We test for purge of partial complete fetches */
1739 for (count
= 3; count
; count
--)
1741 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1742 &value_length
, &flags
, &rc
);
1743 assert(rc
== MEMCACHED_SUCCESS
);
1744 assert(!(memcmp(value
, insert_data
, value_length
)));
1745 assert(value_length
);
1753 static test_return
user_supplied_bug8(memcached_st
*memc
__attribute__((unused
)))
1755 memcached_return rc
;
1757 memcached_st
*clone
;
1759 memcached_server_st
*servers
;
1760 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";
1762 servers
= memcached_servers_parse(server_list
);
1765 mine
= memcached_create(NULL
);
1766 rc
= memcached_server_push(mine
, servers
);
1767 assert(rc
== MEMCACHED_SUCCESS
);
1768 memcached_server_list_free(servers
);
1771 clone
= memcached_clone(NULL
, mine
);
1773 memcached_quit(mine
);
1774 memcached_quit(clone
);
1777 memcached_free(mine
);
1778 memcached_free(clone
);
1783 /* Test flag store/retrieve */
1784 static test_return
user_supplied_bug7(memcached_st
*memc
)
1786 memcached_return rc
;
1787 char *keys
= "036790384900";
1788 size_t key_length
= strlen("036790384900");
1789 char return_key
[MEMCACHED_MAX_KEY
];
1790 size_t return_key_length
;
1792 size_t value_length
;
1795 char insert_data
[VALUE_SIZE_BUG5
];
1797 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1798 insert_data
[x
]= rand();
1800 memcached_flush(memc
, 0);
1803 rc
= memcached_set(memc
, keys
, key_length
,
1804 insert_data
, VALUE_SIZE_BUG5
,
1806 assert(rc
== MEMCACHED_SUCCESS
);
1809 value
= memcached_get(memc
, keys
, key_length
,
1810 &value_length
, &flags
, &rc
);
1811 assert(flags
== 245);
1815 rc
= memcached_mget(memc
, &keys
, &key_length
, 1);
1818 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1819 &value_length
, &flags
, &rc
);
1820 assert(flags
== 245);
1828 static test_return
user_supplied_bug9(memcached_st
*memc
)
1830 memcached_return rc
;
1831 char *keys
[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
1832 size_t key_length
[3];
1837 char return_key
[MEMCACHED_MAX_KEY
];
1838 size_t return_key_length
;
1840 size_t return_value_length
;
1843 key_length
[0]= strlen("UDATA:edevil@sapo.pt");
1844 key_length
[1]= strlen("fudge&*@#");
1845 key_length
[2]= strlen("for^#@&$not");
1848 for (x
= 0; x
< 3; x
++)
1850 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1851 keys
[x
], key_length
[x
],
1852 (time_t)50, (uint32_t)9);
1853 assert(rc
== MEMCACHED_SUCCESS
);
1856 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1857 assert(rc
== MEMCACHED_SUCCESS
);
1859 /* We need to empty the server before continueing test */
1860 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1861 &return_value_length
, &flags
, &rc
)) != NULL
)
1863 assert(return_value
);
1872 /* We are testing with aggressive timeout to get failures */
1873 static test_return
user_supplied_bug10(memcached_st
*memc
)
1877 size_t value_length
= 512;
1880 memcached_return rc
;
1881 unsigned int set
= 1;
1882 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
1885 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1886 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1888 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
1890 value
= (char*)malloc(value_length
* sizeof(char));
1892 for (x
= 0; x
< value_length
; x
++)
1893 value
[x
]= (char) (x
% 127);
1895 for (x
= 1; x
<= 100000; ++x
)
1897 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
1899 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_WRITE_FAILURE
|| rc
== MEMCACHED_BUFFERED
);
1901 if (rc
== MEMCACHED_WRITE_FAILURE
)
1906 memcached_free(mclone
);
1912 We are looking failures in the async protocol
1914 static test_return
user_supplied_bug11(memcached_st
*memc
)
1918 size_t value_length
= 512;
1921 memcached_return rc
;
1922 unsigned int set
= 1;
1924 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
1926 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1927 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1929 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
1931 timeout
= (int32_t)memcached_behavior_get(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
1933 assert(timeout
== -1);
1935 value
= (char*)malloc(value_length
* sizeof(char));
1937 for (x
= 0; x
< value_length
; x
++)
1938 value
[x
]= (char) (x
% 127);
1940 for (x
= 1; x
<= 100000; ++x
)
1942 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
1946 memcached_free(mclone
);
1952 Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
1954 static test_return
user_supplied_bug12(memcached_st
*memc
)
1956 memcached_return rc
;
1958 size_t value_length
;
1960 uint64_t number_value
;
1962 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
1963 &value_length
, &flags
, &rc
);
1964 assert(value
== NULL
);
1965 assert(rc
== MEMCACHED_NOTFOUND
);
1967 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
1970 assert(value
== NULL
);
1971 /* The binary protocol will set the key if it doesn't exist */
1972 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1)
1973 assert(rc
== MEMCACHED_SUCCESS
);
1975 assert(rc
== MEMCACHED_NOTFOUND
);
1977 rc
= memcached_set(memc
, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
1979 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
1980 &value_length
, &flags
, &rc
);
1982 assert(rc
== MEMCACHED_SUCCESS
);
1985 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
1987 assert(number_value
== 2);
1988 assert(rc
== MEMCACHED_SUCCESS
);
1994 Bug found where command total one more than MEMCACHED_MAX_BUFFER
1995 set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
1997 static test_return
user_supplied_bug13(memcached_st
*memc
)
1999 char key
[] = "key34567890";
2001 memcached_return rc
;
2002 size_t overflowSize
;
2004 char commandFirst
[]= "set key34567890 0 0 ";
2005 char commandLast
[] = " \r\n"; /* first line of command sent to server */
2006 size_t commandLength
;
2009 commandLength
= strlen(commandFirst
) + strlen(commandLast
) + 4; /* 4 is number of characters in size, probably 8196 */
2011 overflowSize
= MEMCACHED_MAX_BUFFER
- commandLength
;
2013 for (testSize
= overflowSize
- 1; testSize
< overflowSize
+ 1; testSize
++)
2015 overflow
= malloc(testSize
);
2016 assert(overflow
!= NULL
);
2018 memset(overflow
, 'x', testSize
);
2019 rc
= memcached_set(memc
, key
, strlen(key
),
2020 overflow
, testSize
, 0, 0);
2021 assert(rc
== MEMCACHED_SUCCESS
);
2030 Test values of many different sizes
2031 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2032 set key34567890 0 0 8169 \r\n
2033 is sent followed by buffer of size 8169, followed by 8169
2035 static test_return
user_supplied_bug14(memcached_st
*memc
)
2038 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2039 memcached_return rc
;
2042 size_t value_length
= 18000;
2044 size_t string_length
;
2047 size_t current_length
;
2049 value
= (char*)malloc(value_length
);
2052 for (x
= 0; x
< value_length
; x
++)
2053 value
[x
] = (char) (x
% 127);
2055 for (current_length
= 0; current_length
< value_length
; current_length
++)
2057 rc
= memcached_set(memc
, key
, strlen(key
),
2058 value
, current_length
,
2059 (time_t)0, (uint32_t)0);
2060 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
2062 string
= memcached_get(memc
, key
, strlen(key
),
2063 &string_length
, &flags
, &rc
);
2065 assert(rc
== MEMCACHED_SUCCESS
);
2066 assert(string_length
== current_length
);
2067 assert(!memcmp(string
, value
, string_length
));
2078 Look for zero length value problems
2080 static test_return
user_supplied_bug15(memcached_st
*memc
)
2083 memcached_return rc
;
2089 for (x
= 0; x
< 2; x
++)
2091 rc
= memcached_set(memc
, key
, strlen(key
),
2093 (time_t)0, (uint32_t)0);
2095 assert(rc
== MEMCACHED_SUCCESS
);
2097 value
= memcached_get(memc
, key
, strlen(key
),
2098 &length
, &flags
, &rc
);
2100 assert(rc
== MEMCACHED_SUCCESS
);
2101 assert(value
== NULL
);
2102 assert(length
== 0);
2105 value
= memcached_get(memc
, key
, strlen(key
),
2106 &length
, &flags
, &rc
);
2108 assert(rc
== MEMCACHED_SUCCESS
);
2109 assert(value
== NULL
);
2110 assert(length
== 0);
2117 /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
2118 static test_return
user_supplied_bug16(memcached_st
*memc
)
2120 memcached_return rc
;
2126 rc
= memcached_set(memc
, key
, strlen(key
),
2128 (time_t)0, UINT32_MAX
);
2130 assert(rc
== MEMCACHED_SUCCESS
);
2132 value
= memcached_get(memc
, key
, strlen(key
),
2133 &length
, &flags
, &rc
);
2135 assert(rc
== MEMCACHED_SUCCESS
);
2136 assert(value
== NULL
);
2137 assert(length
== 0);
2138 assert(flags
== UINT32_MAX
);
2143 /* Check the validity of chinese key*/
2144 static test_return
user_supplied_bug17(memcached_st
*memc
)
2146 memcached_return rc
;
2148 char *value
="我们在炎热抑郁的夏天无法停止豆瓣";
2153 rc
= memcached_set(memc
, key
, strlen(key
),
2154 value
, strlen(value
),
2157 assert(rc
== MEMCACHED_SUCCESS
);
2159 value2
= memcached_get(memc
, key
, strlen(key
),
2160 &length
, &flags
, &rc
);
2162 assert(length
==strlen(value
));
2163 assert(rc
== MEMCACHED_SUCCESS
);
2164 assert(memcmp(value
, value2
, length
)==0);
2174 test_return
user_supplied_bug19(memcached_st
*memc
)
2177 memcached_server_st
*s
;
2178 memcached_return res
;
2182 m
= memcached_create(NULL
);
2183 memcached_server_add_with_weight(m
, "localhost", 11311, 100);
2184 memcached_server_add_with_weight(m
, "localhost", 11312, 100);
2186 s
= memcached_server_by_key(m
, "a", 1, &res
);
2187 memcached_server_free(s
);
2194 /* CAS test from Andei */
2195 test_return
user_supplied_bug20(memcached_st
*memc
)
2197 memcached_return status
;
2198 memcached_result_st
*result
, result_obj
;
2200 size_t key_len
= strlen("abc");
2201 char *value
= "foobar";
2202 size_t value_len
= strlen(value
);
2204 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
2206 status
= memcached_set(memc
, key
, key_len
, value
, value_len
, (time_t)0, (uint32_t)0);
2207 assert(status
== MEMCACHED_SUCCESS
);
2209 status
= memcached_mget(memc
, &key
, &key_len
, 1);
2210 assert(status
== MEMCACHED_SUCCESS
);
2212 result
= memcached_result_create(memc
, &result_obj
);
2215 memcached_result_create(memc
, &result_obj
);
2216 result
= memcached_fetch_result(memc
, &result_obj
, &status
);
2219 assert(status
== MEMCACHED_SUCCESS
);
2221 memcached_result_free(result
);
2226 #include "ketama_test_cases.h"
2227 test_return
user_supplied_bug18(memcached_st
*trash
)
2229 memcached_return rc
;
2232 memcached_server_st
*server_pool
;
2237 memc
= memcached_create(NULL
);
2240 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2241 assert(rc
== MEMCACHED_SUCCESS
);
2243 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2246 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2247 assert(rc
== MEMCACHED_SUCCESS
);
2249 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2250 assert(value
== MEMCACHED_HASH_MD5
);
2252 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");
2253 memcached_server_push(memc
, server_pool
);
2255 /* verify that the server list was parsed okay. */
2256 assert(memc
->number_of_hosts
== 8);
2257 assert(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
2258 assert(server_pool
[0].port
== 11211);
2259 assert(server_pool
[0].weight
== 600);
2260 assert(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
2261 assert(server_pool
[2].port
== 11211);
2262 assert(server_pool
[2].weight
== 200);
2263 assert(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
2264 assert(server_pool
[7].port
== 11211);
2265 assert(server_pool
[7].weight
== 100);
2267 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
2268 * us test the boundary wraparound.
2270 assert(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
2272 /* verify the standard ketama set. */
2273 for (i
= 0; i
< 99; i
++)
2275 uint32_t server_idx
= memcached_generate_hash(memc
, test_cases
[i
].key
, strlen(test_cases
[i
].key
));
2276 char *hostname
= memc
->hosts
[server_idx
].hostname
;
2277 assert(strcmp(hostname
, test_cases
[i
].server
) == 0);
2280 memcached_server_list_free(server_pool
);
2281 memcached_free(memc
);
2286 static test_return
result_static(memcached_st
*memc
)
2288 memcached_result_st result
;
2289 memcached_result_st
*result_ptr
;
2291 result_ptr
= memcached_result_create(memc
, &result
);
2292 assert(result
.is_allocated
== false);
2294 memcached_result_free(&result
);
2299 static test_return
result_alloc(memcached_st
*memc
)
2301 memcached_result_st
*result
;
2303 result
= memcached_result_create(memc
, NULL
);
2305 memcached_result_free(result
);
2310 static test_return
string_static_null(memcached_st
*memc
)
2312 memcached_string_st string
;
2313 memcached_string_st
*string_ptr
;
2315 string_ptr
= memcached_string_create(memc
, &string
, 0);
2316 assert(string
.is_allocated
== false);
2318 memcached_string_free(&string
);
2323 static test_return
string_alloc_null(memcached_st
*memc
)
2325 memcached_string_st
*string
;
2327 string
= memcached_string_create(memc
, NULL
, 0);
2329 memcached_string_free(string
);
2334 static test_return
string_alloc_with_size(memcached_st
*memc
)
2336 memcached_string_st
*string
;
2338 string
= memcached_string_create(memc
, NULL
, 1024);
2340 memcached_string_free(string
);
2345 static test_return
string_alloc_with_size_toobig(memcached_st
*memc
)
2347 memcached_string_st
*string
;
2349 string
= memcached_string_create(memc
, NULL
, INT64_MAX
);
2350 assert(string
== NULL
);
2355 static test_return
string_alloc_append(memcached_st
*memc
)
2358 char buffer
[SMALL_STRING_LEN
];
2359 memcached_string_st
*string
;
2361 /* Ring the bell! */
2362 memset(buffer
, 6, SMALL_STRING_LEN
);
2364 string
= memcached_string_create(memc
, NULL
, 100);
2367 for (x
= 0; x
< 1024; x
++)
2369 memcached_return rc
;
2370 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
2371 assert(rc
== MEMCACHED_SUCCESS
);
2373 memcached_string_free(string
);
2378 static test_return
string_alloc_append_toobig(memcached_st
*memc
)
2380 memcached_return rc
;
2382 char buffer
[SMALL_STRING_LEN
];
2383 memcached_string_st
*string
;
2385 /* Ring the bell! */
2386 memset(buffer
, 6, SMALL_STRING_LEN
);
2388 string
= memcached_string_create(memc
, NULL
, 100);
2391 for (x
= 0; x
< 1024; x
++)
2393 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
2394 assert(rc
== MEMCACHED_SUCCESS
);
2396 rc
= memcached_string_append(string
, buffer
, INT64_MAX
);
2397 assert(rc
== MEMCACHED_MEMORY_ALLOCATION_FAILURE
);
2398 memcached_string_free(string
);
2403 static test_return
cleanup_pairs(memcached_st
*memc
__attribute__((unused
)))
2405 pairs_free(global_pairs
);
2410 static test_return
generate_pairs(memcached_st
*memc
__attribute__((unused
)))
2412 unsigned long long x
;
2413 global_pairs
= pairs_generate(GLOBAL_COUNT
, 400);
2414 global_count
= GLOBAL_COUNT
;
2416 for (x
= 0; x
< global_count
; x
++)
2418 global_keys
[x
]= global_pairs
[x
].key
;
2419 global_keys_length
[x
]= global_pairs
[x
].key_length
;
2425 static test_return
generate_large_pairs(memcached_st
*memc
__attribute__((unused
)))
2427 unsigned long long x
;
2428 global_pairs
= pairs_generate(GLOBAL2_COUNT
, MEMCACHED_MAX_BUFFER
+10);
2429 global_count
= GLOBAL2_COUNT
;
2431 for (x
= 0; x
< global_count
; x
++)
2433 global_keys
[x
]= global_pairs
[x
].key
;
2434 global_keys_length
[x
]= global_pairs
[x
].key_length
;
2440 static test_return
generate_data(memcached_st
*memc
)
2442 execute_set(memc
, global_pairs
, global_count
);
2447 static test_return
generate_data_with_stats(memcached_st
*memc
)
2449 memcached_stat_st
*stat_p
;
2450 memcached_return rc
;
2451 uint32_t host_index
= 0;
2452 execute_set(memc
, global_pairs
, global_count
);
2454 //TODO: hosts used size stats
2455 stat_p
= memcached_stat(memc
, NULL
, &rc
);
2458 for (host_index
= 0; host_index
< SERVERS_TO_CREATE
; host_index
++)
2460 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
);
2463 memcached_stat_free(NULL
, stat_p
);
2467 static test_return
generate_buffer_data(memcached_st
*memc
)
2472 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
2473 generate_data(memc
);
2478 static test_return
get_read_count(memcached_st
*memc
)
2481 memcached_return rc
;
2482 memcached_st
*clone
;
2484 clone
= memcached_clone(NULL
, memc
);
2487 memcached_server_add_with_weight(clone
, "localhost", 6666, 0);
2491 size_t return_value_length
;
2495 for (x
= count
= 0; x
< global_count
; x
++)
2497 return_value
= memcached_get(clone
, global_keys
[x
], global_keys_length
[x
],
2498 &return_value_length
, &flags
, &rc
);
2499 if (rc
== MEMCACHED_SUCCESS
)
2506 fprintf(stderr
, "\t%u -> %u", global_count
, count
);
2509 memcached_free(clone
);
2514 static test_return
get_read(memcached_st
*memc
)
2517 memcached_return rc
;
2521 size_t return_value_length
;
2524 for (x
= 0; x
< global_count
; x
++)
2526 return_value
= memcached_get(memc
, global_keys
[x
], global_keys_length
[x
],
2527 &return_value_length
, &flags
, &rc
);
2529 assert(return_value);
2530 assert(rc == MEMCACHED_SUCCESS);
2532 if (rc
== MEMCACHED_SUCCESS
&& return_value
)
2540 static test_return
mget_read(memcached_st
*memc
)
2542 memcached_return rc
;
2544 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2545 assert(rc
== MEMCACHED_SUCCESS
);
2546 /* Turn this into a help function */
2548 char return_key
[MEMCACHED_MAX_KEY
];
2549 size_t return_key_length
;
2551 size_t return_value_length
;
2554 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2555 &return_value_length
, &flags
, &rc
)))
2557 assert(return_value
);
2558 assert(rc
== MEMCACHED_SUCCESS
);
2566 static test_return
mget_read_result(memcached_st
*memc
)
2568 memcached_return rc
;
2570 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2571 assert(rc
== MEMCACHED_SUCCESS
);
2572 /* Turn this into a help function */
2574 memcached_result_st results_obj
;
2575 memcached_result_st
*results
;
2577 results
= memcached_result_create(memc
, &results_obj
);
2579 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
2582 assert(rc
== MEMCACHED_SUCCESS
);
2585 memcached_result_free(&results_obj
);
2591 static test_return
mget_read_function(memcached_st
*memc
)
2593 memcached_return rc
;
2594 unsigned int counter
;
2595 memcached_execute_function callbacks
[1];
2597 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2598 assert(rc
== MEMCACHED_SUCCESS
);
2600 callbacks
[0]= &callback_counter
;
2602 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
2607 static test_return
delete_generate(memcached_st
*memc
)
2611 for (x
= 0; x
< global_count
; x
++)
2613 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
2619 static test_return
delete_buffer_generate(memcached_st
*memc
)
2625 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
2627 for (x
= 0; x
< global_count
; x
++)
2629 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
2635 static test_return
free_data(memcached_st
*memc
__attribute__((unused
)))
2637 pairs_free(global_pairs
);
2642 static test_return
add_host_test1(memcached_st
*memc
)
2645 memcached_return rc
;
2646 char servername
[]= "0.example.com";
2647 memcached_server_st
*servers
;
2649 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
2651 assert(1 == memcached_server_list_count(servers
));
2653 for (x
= 2; x
< 20; x
++)
2655 char buffer
[SMALL_STRING_LEN
];
2657 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
2658 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
2660 assert(rc
== MEMCACHED_SUCCESS
);
2661 assert(x
== memcached_server_list_count(servers
));
2664 rc
= memcached_server_push(memc
, servers
);
2665 assert(rc
== MEMCACHED_SUCCESS
);
2666 rc
= memcached_server_push(memc
, servers
);
2667 assert(rc
== MEMCACHED_SUCCESS
);
2669 memcached_server_list_free(servers
);
2674 static memcached_return
pre_nonblock(memcached_st
*memc
)
2676 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
2678 return MEMCACHED_SUCCESS
;
2681 static memcached_return
pre_nonblock_binary(memcached_st
*memc
)
2683 memcached_return rc
= MEMCACHED_FAILURE
;
2684 memcached_st
*clone
;
2686 clone
= memcached_clone(NULL
, memc
);
2688 // The memcached_version needs to be done on a clone, because the server
2689 // will not toggle protocol on an connection.
2690 memcached_version(clone
);
2692 if (clone
->hosts
[0].major_version
>= 1 && clone
->hosts
[0].minor_version
> 2)
2694 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
2695 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
2696 assert(rc
== MEMCACHED_SUCCESS
);
2697 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
2700 memcached_free(clone
);
2704 static memcached_return
pre_murmur(memcached_st
*memc
)
2706 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
2708 return MEMCACHED_SUCCESS
;
2711 static memcached_return
pre_jenkins(memcached_st
*memc
)
2713 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_JENKINS
);
2715 return MEMCACHED_SUCCESS
;
2719 static memcached_return
pre_md5(memcached_st
*memc
)
2721 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MD5
);
2723 return MEMCACHED_SUCCESS
;
2726 static memcached_return
pre_crc(memcached_st
*memc
)
2728 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_CRC
);
2730 return MEMCACHED_SUCCESS
;
2733 static memcached_return
pre_hsieh(memcached_st
*memc
)
2735 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_HSIEH
);
2737 return MEMCACHED_SUCCESS
;
2740 static memcached_return
pre_hash_fnv1_64(memcached_st
*memc
)
2742 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_64
);
2744 return MEMCACHED_SUCCESS
;
2747 static memcached_return
pre_hash_fnv1a_64(memcached_st
*memc
)
2749 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_64
);
2751 return MEMCACHED_SUCCESS
;
2754 static memcached_return
pre_hash_fnv1_32(memcached_st
*memc
)
2756 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_32
);
2758 return MEMCACHED_SUCCESS
;
2761 static memcached_return
pre_hash_fnv1a_32(memcached_st
*memc
)
2763 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_32
);
2765 return MEMCACHED_SUCCESS
;
2768 static memcached_return
pre_behavior_ketama(memcached_st
*memc
)
2770 memcached_return rc
;
2773 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA
, 1);
2774 assert(rc
== MEMCACHED_SUCCESS
);
2776 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA
);
2779 return MEMCACHED_SUCCESS
;
2782 static memcached_return
pre_behavior_ketama_weighted(memcached_st
*memc
)
2784 memcached_return rc
;
2787 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2788 assert(rc
== MEMCACHED_SUCCESS
);
2790 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2793 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2794 assert(rc
== MEMCACHED_SUCCESS
);
2796 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2797 assert(value
== MEMCACHED_HASH_MD5
);
2798 return MEMCACHED_SUCCESS
;
2801 static memcached_return
pre_binary(memcached_st
*memc
)
2803 memcached_return rc
= MEMCACHED_FAILURE
;
2804 memcached_st
*clone
;
2806 clone
= memcached_clone(NULL
, memc
);
2808 // The memcached_version needs to be done on a clone, because the server
2809 // will not toggle protocol on an connection.
2810 memcached_version(clone
);
2812 if (clone
->hosts
[0].major_version
>= 1 && clone
->hosts
[0].minor_version
> 2)
2814 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
2815 assert(rc
== MEMCACHED_SUCCESS
);
2816 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
2819 memcached_free(clone
);
2823 static void my_free(memcached_st
*ptr
__attribute__((unused
)), void *mem
)
2828 static void *my_malloc(memcached_st
*ptr
__attribute__((unused
)), const size_t size
)
2830 return malloc(size
);
2833 static void *my_realloc(memcached_st
*ptr
__attribute__((unused
)), void *mem
, const size_t size
)
2835 return realloc(mem
, size
);
2838 static memcached_return
set_prefix(memcached_st
*memc
)
2840 memcached_return rc
;
2841 const char *key
= "mine";
2844 /* Make sure be default none exists */
2845 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2846 assert(rc
== MEMCACHED_FAILURE
);
2848 /* Test a clean set */
2849 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
2850 assert(rc
== MEMCACHED_SUCCESS
);
2852 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2853 assert(memcmp(value
, key
, 4) == 0);
2854 assert(rc
== MEMCACHED_SUCCESS
);
2856 /* Test that we can turn it off */
2857 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
2858 assert(rc
== MEMCACHED_SUCCESS
);
2860 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2861 assert(rc
== MEMCACHED_FAILURE
);
2863 /* Now setup for main test */
2864 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
2865 assert(rc
== MEMCACHED_SUCCESS
);
2867 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2868 assert(rc
== MEMCACHED_SUCCESS
);
2869 assert(memcmp(value
, key
, 4) == 0);
2871 /* Set to Zero, and then Set to something too large */
2874 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
2875 assert(rc
== MEMCACHED_SUCCESS
);
2877 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2878 assert(rc
== MEMCACHED_FAILURE
);
2879 assert(value
== NULL
);
2881 /* Test a long key for failure */
2882 /* TODO, extend test to determine based on setting, what result should be */
2883 long_key
= "Thisismorethentheallottednumberofcharacters";
2884 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
2885 //assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
2886 assert(rc
== MEMCACHED_SUCCESS
);
2888 /* Now test a key with spaces (which will fail from long key, since bad key is not set) */
2889 long_key
= "This is more then the allotted number of characters";
2890 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
2891 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
2893 /* Test for a bad prefix, but with a short key */
2894 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, 1);
2895 assert(rc
== MEMCACHED_SUCCESS
);
2897 long_key
= "dog cat";
2898 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
2899 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
2902 return MEMCACHED_SUCCESS
;
2905 static memcached_return
set_memory_alloc(memcached_st
*memc
)
2908 memcached_malloc_function test_ptr
;
2909 memcached_return rc
;
2911 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, (void*)&my_malloc
);
2912 assert(rc
== MEMCACHED_SUCCESS
);
2913 test_ptr
= (memcached_malloc_function
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
2914 assert(rc
== MEMCACHED_SUCCESS
);
2915 assert(test_ptr
== my_malloc
);
2919 memcached_realloc_function test_ptr
;
2920 memcached_return rc
;
2922 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, (void*)&my_realloc
);
2923 assert(rc
== MEMCACHED_SUCCESS
);
2924 test_ptr
= (memcached_realloc_function
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
2925 assert(rc
== MEMCACHED_SUCCESS
);
2926 assert(test_ptr
== my_realloc
);
2930 memcached_free_function test_ptr
;
2931 memcached_return rc
;
2933 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, (void*)my_free
);
2934 assert(rc
== MEMCACHED_SUCCESS
);
2935 test_ptr
= (memcached_free_function
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
2936 assert(rc
== MEMCACHED_SUCCESS
);
2937 assert(test_ptr
== my_free
);
2940 return MEMCACHED_SUCCESS
;
2943 static memcached_return
enable_consistent(memcached_st
*memc
)
2945 memcached_server_distribution value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
2946 memcached_hash hash
;
2947 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
2950 value
= (memcached_server_distribution
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
2951 assert(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
2953 hash
= (memcached_hash
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
2954 assert(hash
== MEMCACHED_HASH_HSIEH
);
2957 return MEMCACHED_SUCCESS
;
2960 static memcached_return
enable_cas(memcached_st
*memc
)
2962 unsigned int set
= 1;
2964 memcached_version(memc
);
2966 if ((memc
->hosts
[0].major_version
>= 1 && (memc
->hosts
[0].minor_version
== 2 && memc
->hosts
[0].micro_version
>= 4))
2967 || memc
->hosts
[0].minor_version
> 2)
2969 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
2971 return MEMCACHED_SUCCESS
;
2974 return MEMCACHED_FAILURE
;
2977 static memcached_return
check_for_1_2_3(memcached_st
*memc
)
2979 memcached_version(memc
);
2981 if ((memc
->hosts
[0].major_version
>= 1 && (memc
->hosts
[0].minor_version
== 2 && memc
->hosts
[0].micro_version
>= 4))
2982 || memc
->hosts
[0].minor_version
> 2)
2983 return MEMCACHED_SUCCESS
;
2985 return MEMCACHED_FAILURE
;
2988 static memcached_return
pre_unix_socket(memcached_st
*memc
)
2990 memcached_return rc
;
2993 memcached_server_list_free(memc
->hosts
);
2995 memc
->number_of_hosts
= 0;
2997 if (stat("/tmp/memcached.socket", &buf
))
2998 return MEMCACHED_FAILURE
;
3000 rc
= memcached_server_add_unix_socket_with_weight(memc
, "/tmp/memcached.socket", 0);
3005 static memcached_return
pre_nodelay(memcached_st
*memc
)
3007 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3008 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
3010 return MEMCACHED_SUCCESS
;
3013 static memcached_return
pre_settimer(memcached_st
*memc
)
3015 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
3016 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
3018 return MEMCACHED_SUCCESS
;
3021 static memcached_return
poll_timeout(memcached_st
*memc
)
3027 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
3029 timeout
= (int32_t)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
3031 assert(timeout
== 100);
3033 return MEMCACHED_SUCCESS
;
3036 static test_return
noreply_test(memcached_st
*memc
)
3038 memcached_return ret
;
3039 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
3040 assert(ret
== MEMCACHED_SUCCESS
);
3041 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
3042 assert(ret
== MEMCACHED_SUCCESS
);
3043 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NOREPLY
) == 1);
3044 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
) == 1);
3046 for (int x
= 0; x
< 100; ++x
) {
3048 size_t len
= sprintf(key
, "%d", x
);
3049 ret
= memcached_set(memc
, key
, len
, key
, len
, 0, 0);
3050 assert(ret
== MEMCACHED_SUCCESS
|| ret
== MEMCACHED_BUFFERED
);
3054 ** NOTE: Don't ever do this in your code! this is not a supported use of the
3055 ** API and is _ONLY_ done this way to verify that the library works the
3056 ** way it is supposed to do!!!!
3059 for (int x
= 0; x
< memc
->number_of_hosts
; ++x
) {
3060 no_msg
+= memc
->hosts
[x
].cursor_active
;
3064 ** The binary protocol does not implement quiet commands yet. Fix this
3065 ** test they are implemented!
3067 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1)
3068 assert(no_msg
== 100);
3070 assert(no_msg
== 0);
3072 assert(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
3073 return TEST_SUCCESS
;
3076 static memcached_return
analyzer_test(memcached_st
*memc
)
3078 memcached_return rc
;
3079 memcached_stat_st
*stat
;
3080 memcached_analysis_st
*report
;
3082 stat
= memcached_stat(memc
, NULL
, &rc
);
3083 assert(rc
== MEMCACHED_SUCCESS
);
3086 report
= memcached_analyze(memc
, stat
, &rc
);
3087 assert(rc
== MEMCACHED_SUCCESS
);
3091 memcached_stat_free(NULL
, stat
);
3093 return MEMCACHED_SUCCESS
;
3096 /* Clean the server before beginning testing */
3098 {"flush", 0, flush_test
},
3099 {"init", 0, init_test
},
3100 {"allocation", 0, allocation_test
},
3101 {"server_list_null_test", 0, server_list_null_test
},
3102 {"server_unsort", 0, server_unsort_test
},
3103 {"server_sort", 0, server_sort_test
},
3104 {"server_sort2", 0, server_sort2_test
},
3105 {"clone_test", 0, clone_test
},
3106 {"error", 0, error_test
},
3107 {"set", 0, set_test
},
3108 {"set2", 0, set_test2
},
3109 {"set3", 0, set_test3
},
3110 {"add", 1, add_test
},
3111 {"replace", 1, replace_test
},
3112 {"delete", 1, delete_test
},
3113 {"get", 1, get_test
},
3114 {"get2", 0, get_test2
},
3115 {"get3", 0, get_test3
},
3116 {"get4", 0, get_test4
},
3117 {"stats_servername", 0, stats_servername_test
},
3118 {"increment", 0, increment_test
},
3119 {"decrement", 0, decrement_test
},
3120 {"quit", 0, quit_test
},
3121 {"mget", 1, mget_test
},
3122 {"mget_result", 1, mget_result_test
},
3123 {"mget_result_alloc", 1, mget_result_alloc_test
},
3124 {"mget_result_function", 1, mget_result_function
},
3125 {"get_stats", 0, get_stats
},
3126 {"add_host_test", 0, add_host_test
},
3127 {"add_host_test_1", 0, add_host_test1
},
3128 {"get_stats_keys", 0, get_stats_keys
},
3129 {"behavior_test", 0, get_stats_keys
},
3130 {"callback_test", 0, get_stats_keys
},
3131 {"version_string_test", 0, version_string_test
},
3132 {"bad_key", 1, bad_key_test
},
3133 {"memcached_server_cursor", 1, memcached_server_cursor_test
},
3134 {"read_through", 1, read_through
},
3135 {"delete_through", 1, delete_through
},
3136 {"noreply", 1, noreply_test
},
3137 {"analyzer", 1, analyzer_test
},
3141 test_st async_tests
[] ={
3142 {"add", 1, add_wrapper
},
3146 test_st string_tests
[] ={
3147 {"string static with null", 0, string_static_null
},
3148 {"string alloc with null", 0, string_alloc_null
},
3149 {"string alloc with 1K", 0, string_alloc_with_size
},
3150 {"string alloc with malloc failure", 0, string_alloc_with_size_toobig
},
3151 {"string append", 0, string_alloc_append
},
3152 {"string append failure (too big)", 0, string_alloc_append_toobig
},
3156 test_st result_tests
[] ={
3157 {"result static", 0, result_static
},
3158 {"result alloc", 0, result_alloc
},
3162 test_st version_1_2_3
[] ={
3163 {"append", 0, append_test
},
3164 {"prepend", 0, prepend_test
},
3165 {"cas", 0, cas_test
},
3166 {"cas2", 0, cas2_test
},
3167 {"append_binary", 0, append_binary_test
},
3171 test_st user_tests
[] ={
3172 {"user_supplied_bug1", 0, user_supplied_bug1
},
3173 {"user_supplied_bug2", 0, user_supplied_bug2
},
3174 {"user_supplied_bug3", 0, user_supplied_bug3
},
3175 {"user_supplied_bug4", 0, user_supplied_bug4
},
3176 {"user_supplied_bug5", 1, user_supplied_bug5
},
3177 {"user_supplied_bug6", 1, user_supplied_bug6
},
3178 {"user_supplied_bug7", 1, user_supplied_bug7
},
3179 {"user_supplied_bug8", 1, user_supplied_bug8
},
3180 {"user_supplied_bug9", 1, user_supplied_bug9
},
3181 {"user_supplied_bug10", 1, user_supplied_bug10
},
3182 {"user_supplied_bug11", 1, user_supplied_bug11
},
3183 {"user_supplied_bug12", 1, user_supplied_bug12
},
3184 {"user_supplied_bug13", 1, user_supplied_bug13
},
3185 {"user_supplied_bug14", 1, user_supplied_bug14
},
3186 {"user_supplied_bug15", 1, user_supplied_bug15
},
3187 {"user_supplied_bug16", 1, user_supplied_bug16
},
3190 ** It seems to be something weird with the character sets..
3191 ** value_fetch is unable to parse the value line (iscntrl "fails"), so I
3192 ** guess I need to find out how this is supposed to work.. Perhaps I need
3193 ** to run the test in a specific locale (I tried zh_CN.UTF-8 without success,
3194 ** so just disable the code for now...).
3196 {"user_supplied_bug17", 1, user_supplied_bug17
},
3198 {"user_supplied_bug18", 1, user_supplied_bug18
},
3199 {"user_supplied_bug19", 1, user_supplied_bug19
},
3200 {"user_supplied_bug20", 1, user_supplied_bug20
},
3204 test_st generate_tests
[] ={
3205 {"generate_pairs", 1, generate_pairs
},
3206 {"generate_data", 1, generate_data
},
3207 {"get_read", 0, get_read
},
3208 {"delete_generate", 0, delete_generate
},
3209 {"generate_buffer_data", 1, generate_buffer_data
},
3210 {"delete_buffer", 0, delete_buffer_generate
},
3211 {"generate_data", 1, generate_data
},
3212 {"mget_read", 0, mget_read
},
3213 {"mget_read_result", 0, mget_read_result
},
3214 {"mget_read_function", 0, mget_read_function
},
3215 {"cleanup", 1, cleanup_pairs
},
3216 {"generate_large_pairs", 1, generate_large_pairs
},
3217 {"generate_data", 1, generate_data
},
3218 {"generate_buffer_data", 1, generate_buffer_data
},
3219 {"cleanup", 1, cleanup_pairs
},
3223 test_st consistent_tests
[] ={
3224 {"generate_pairs", 1, generate_pairs
},
3225 {"generate_data", 1, generate_data
},
3226 {"get_read", 0, get_read_count
},
3227 {"cleanup", 1, cleanup_pairs
},
3231 test_st consistent_weighted_tests
[] ={
3232 {"generate_pairs", 1, generate_pairs
},
3233 {"generate_data", 1, generate_data_with_stats
},
3234 {"get_read", 0, get_read_count
},
3235 {"cleanup", 1, cleanup_pairs
},
3239 collection_st collection
[] ={
3240 {"block", 0, 0, tests
},
3241 {"binary", pre_binary
, 0, tests
},
3242 {"nonblock", pre_nonblock
, 0, tests
},
3243 {"nodelay", pre_nodelay
, 0, tests
},
3244 {"settimer", pre_settimer
, 0, tests
},
3245 {"md5", pre_md5
, 0, tests
},
3246 {"crc", pre_crc
, 0, tests
},
3247 {"hsieh", pre_hsieh
, 0, tests
},
3248 {"jenkins", pre_jenkins
, 0, tests
},
3249 {"fnv1_64", pre_hash_fnv1_64
, 0, tests
},
3250 {"fnv1a_64", pre_hash_fnv1a_64
, 0, tests
},
3251 {"fnv1_32", pre_hash_fnv1_32
, 0, tests
},
3252 {"fnv1a_32", pre_hash_fnv1a_32
, 0, tests
},
3253 {"ketama", pre_behavior_ketama
, 0, tests
},
3254 {"unix_socket", pre_unix_socket
, 0, tests
},
3255 {"unix_socket_nodelay", pre_nodelay
, 0, tests
},
3256 {"poll_timeout", poll_timeout
, 0, tests
},
3257 {"gets", enable_cas
, 0, tests
},
3258 {"consistent", enable_consistent
, 0, tests
},
3259 {"memory_allocators", set_memory_alloc
, 0, tests
},
3260 {"prefix", set_prefix
, 0, tests
},
3261 {"version_1_2_3", check_for_1_2_3
, 0, version_1_2_3
},
3262 {"string", 0, 0, string_tests
},
3263 {"result", 0, 0, result_tests
},
3264 {"async", pre_nonblock
, 0, async_tests
},
3265 {"async_binary", pre_nonblock_binary
, 0, async_tests
},
3266 {"user", 0, 0, user_tests
},
3267 {"generate", 0, 0, generate_tests
},
3268 {"generate_hsieh", pre_hsieh
, 0, generate_tests
},
3269 {"generate_ketama", pre_behavior_ketama
, 0, generate_tests
},
3270 {"generate_hsieh_consistent", enable_consistent
, 0, generate_tests
},
3271 {"generate_md5", pre_md5
, 0, generate_tests
},
3272 {"generate_murmur", pre_murmur
, 0, generate_tests
},
3273 {"generate_jenkins", pre_jenkins
, 0, generate_tests
},
3274 {"generate_nonblock", pre_nonblock
, 0, generate_tests
},
3275 {"consistent_not", 0, 0, consistent_tests
},
3276 {"consistent_ketama", pre_behavior_ketama
, 0, consistent_tests
},
3277 {"consistent_ketama_weighted", pre_behavior_ketama_weighted
, 0, consistent_weighted_tests
},
3281 #define SERVERS_TO_CREATE 5
3283 /* Prototypes for functions we will pass to test framework */
3284 void *world_create(void);
3285 void world_destroy(void *p
);
3287 void *world_create(void)
3289 server_startup_st
*construct
;
3291 construct
= (server_startup_st
*)malloc(sizeof(server_startup_st
));
3292 memset(construct
, 0, sizeof(server_startup_st
));
3293 construct
->count
= SERVERS_TO_CREATE
;
3295 server_startup(construct
);
3301 void world_destroy(void *p
)
3303 server_startup_st
*construct
= (server_startup_st
*)p
;
3304 memcached_server_st
*servers
= (memcached_server_st
*)construct
->servers
;
3305 memcached_server_list_free(servers
);
3307 server_shutdown(construct
);
3311 void get_world(world_st
*world
)
3313 world
->collections
= collection
;
3314 world
->create
= world_create
;
3315 world
->destroy
= world_destroy
;