2 Sample test application.
5 #include "libmemcached/common.h"
12 #include <sys/types.h>
18 #include "clients/generator.h"
19 #include "clients/execute.h"
22 #define INT64_MAX LONG_MAX
25 #define INT32_MAX INT_MAX
31 #ifdef HAVE_LIBMEMCACHEDUTIL
33 #include "libmemcached/memcached_util.h"
36 #define GLOBAL_COUNT 10000
37 #define GLOBAL2_COUNT 100
38 #define SERVERS_TO_CREATE 5
39 static uint32_t global_count
;
41 static pairs_st
*global_pairs
;
42 static const char *global_keys
[GLOBAL_COUNT
];
43 static size_t global_keys_length
[GLOBAL_COUNT
];
45 static test_return
init_test(memcached_st
*not_used
__attribute__((unused
)))
49 (void)memcached_create(&memc
);
50 memcached_free(&memc
);
55 static test_return
server_list_null_test(memcached_st
*ptr
__attribute__((unused
)))
57 memcached_server_st
*server_list
;
60 server_list
= memcached_server_list_append_with_weight(NULL
, NULL
, 0, 0, NULL
);
61 assert(server_list
== NULL
);
63 server_list
= memcached_server_list_append_with_weight(NULL
, "localhost", 0, 0, NULL
);
64 assert(server_list
== NULL
);
66 server_list
= memcached_server_list_append_with_weight(NULL
, NULL
, 0, 0, &rc
);
67 assert(server_list
== NULL
);
72 #define TEST_PORT_COUNT 7
73 uint32_t test_ports
[TEST_PORT_COUNT
];
75 static memcached_return
server_display_function(memcached_st
*ptr
__attribute__((unused
)), memcached_server_st
*server
, void *context
)
78 uint32_t bigger
= *((uint32_t *)(context
));
79 assert(bigger
<= server
->port
);
80 *((uint32_t *)(context
))= server
->port
;
82 return MEMCACHED_SUCCESS
;
85 static test_return
server_sort_test(memcached_st
*ptr
__attribute__((unused
)))
88 uint32_t bigger
= 0; /* Prime the value for the assert in server_display_function */
90 memcached_server_function callbacks
[1];
91 memcached_st
*local_memc
;
93 local_memc
= memcached_create(NULL
);
95 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
97 for (x
= 0; x
< TEST_PORT_COUNT
; x
++)
99 test_ports
[x
]= (uint32_t)random() % 64000;
100 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
101 assert(local_memc
->number_of_hosts
== x
+ 1);
102 assert(local_memc
->hosts
[0].count
== x
+1);
103 assert(rc
== MEMCACHED_SUCCESS
);
106 callbacks
[0]= server_display_function
;
107 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
110 memcached_free(local_memc
);
115 static test_return
server_sort2_test(memcached_st
*ptr
__attribute__((unused
)))
117 uint32_t bigger
= 0; /* Prime the value for the assert in server_display_function */
119 memcached_server_function callbacks
[1];
120 memcached_st
*local_memc
;
122 local_memc
= memcached_create(NULL
);
124 rc
= memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
125 assert(rc
== MEMCACHED_SUCCESS
);
127 rc
= memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43043, 0);
128 assert(rc
== MEMCACHED_SUCCESS
);
129 assert(local_memc
->hosts
[0].port
== 43043);
131 rc
= memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43042, 0);
132 assert(rc
== MEMCACHED_SUCCESS
);
133 assert(local_memc
->hosts
[0].port
== 43042);
134 assert(local_memc
->hosts
[1].port
== 43043);
136 callbacks
[0]= server_display_function
;
137 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
140 memcached_free(local_memc
);
145 static memcached_return
server_display_unsort_function(memcached_st
*ptr
__attribute__((unused
)), memcached_server_st
*server
, void *context
)
148 uint32_t x
= *((uint32_t *)(context
));
150 assert(test_ports
[x
] == server
->port
);
151 *((uint32_t *)(context
))= ++x
;
153 return MEMCACHED_SUCCESS
;
156 static test_return
server_unsort_test(memcached_st
*ptr
__attribute__((unused
)))
159 uint32_t counter
= 0; /* Prime the value for the assert in server_display_function */
160 uint32_t bigger
= 0; /* Prime the value for the assert in server_display_function */
162 memcached_server_function callbacks
[1];
163 memcached_st
*local_memc
;
165 local_memc
= memcached_create(NULL
);
168 for (x
= 0; x
< TEST_PORT_COUNT
; x
++)
170 test_ports
[x
]= (uint32_t)(random() % 64000);
171 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
172 assert(local_memc
->number_of_hosts
== x
+1);
173 assert(local_memc
->hosts
[0].count
== x
+1);
174 assert(rc
== MEMCACHED_SUCCESS
);
177 callbacks
[0]= server_display_unsort_function
;
178 memcached_server_cursor(local_memc
, callbacks
, (void *)&counter
, 1);
180 /* Now we sort old data! */
181 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
182 callbacks
[0]= server_display_function
;
183 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
186 memcached_free(local_memc
);
191 static test_return
allocation_test(memcached_st
*not_used
__attribute__((unused
)))
194 memc
= memcached_create(NULL
);
196 memcached_free(memc
);
201 static test_return
clone_test(memcached_st
*memc
)
205 memcached_st
*memc_clone
;
206 memc_clone
= memcached_clone(NULL
, NULL
);
208 memcached_free(memc_clone
);
211 /* Can we init from null? */
213 memcached_st
*memc_clone
;
214 memc_clone
= memcached_clone(NULL
, memc
);
217 assert(memc_clone
->call_free
== memc
->call_free
);
218 assert(memc_clone
->call_malloc
== memc
->call_malloc
);
219 assert(memc_clone
->call_realloc
== memc
->call_realloc
);
220 assert(memc_clone
->call_calloc
== memc
->call_calloc
);
221 assert(memc_clone
->connect_timeout
== memc
->connect_timeout
);
222 assert(memc_clone
->delete_trigger
== memc
->delete_trigger
);
223 assert(memc_clone
->distribution
== memc
->distribution
);
224 assert(memc_clone
->flags
== memc
->flags
);
225 assert(memc_clone
->get_key_failure
== memc
->get_key_failure
);
226 assert(memc_clone
->hash
== memc
->hash
);
227 assert(memc_clone
->hash_continuum
== memc
->hash_continuum
);
228 assert(memc_clone
->io_bytes_watermark
== memc
->io_bytes_watermark
);
229 assert(memc_clone
->io_msg_watermark
== memc
->io_msg_watermark
);
230 assert(memc_clone
->io_key_prefetch
== memc
->io_key_prefetch
);
231 assert(memc_clone
->on_cleanup
== memc
->on_cleanup
);
232 assert(memc_clone
->on_clone
== memc
->on_clone
);
233 assert(memc_clone
->poll_timeout
== memc
->poll_timeout
);
234 assert(memc_clone
->rcv_timeout
== memc
->rcv_timeout
);
235 assert(memc_clone
->recv_size
== memc
->recv_size
);
236 assert(memc_clone
->retry_timeout
== memc
->retry_timeout
);
237 assert(memc_clone
->send_size
== memc
->send_size
);
238 assert(memc_clone
->server_failure_limit
== memc
->server_failure_limit
);
239 assert(memc_clone
->snd_timeout
== memc
->snd_timeout
);
240 assert(memc_clone
->user_data
== memc
->user_data
);
242 memcached_free(memc_clone
);
245 /* Can we init from struct? */
247 memcached_st declared_clone
;
248 memcached_st
*memc_clone
;
249 memset(&declared_clone
, 0 , sizeof(memcached_st
));
250 memc_clone
= memcached_clone(&declared_clone
, NULL
);
252 memcached_free(memc_clone
);
255 /* Can we init from struct? */
257 memcached_st declared_clone
;
258 memcached_st
*memc_clone
;
259 memset(&declared_clone
, 0 , sizeof(memcached_st
));
260 memc_clone
= memcached_clone(&declared_clone
, memc
);
262 memcached_free(memc_clone
);
268 static test_return
userdata_test(memcached_st
*memc
)
271 assert(memcached_set_user_data(memc
, foo
) == NULL
);
272 assert(memcached_get_user_data(memc
) == foo
);
273 assert(memcached_set_user_data(memc
, NULL
) == foo
);
278 static test_return
connection_test(memcached_st
*memc
)
282 rc
= memcached_server_add_with_weight(memc
, "localhost", 0, 0);
283 assert(rc
== MEMCACHED_SUCCESS
);
288 static test_return
error_test(memcached_st
*memc
)
291 uint32_t values
[] = { 851992627U, 2337886783U, 3196981036U, 4001849190U,
292 982370485U, 1263635348U, 4242906218U, 3829656100U,
293 1891735253U, 334139633U, 2257084983U, 3088286104U,
294 13199785U, 2542027183U, 1097051614U, 199566778U,
295 2748246961U, 2465192557U, 1664094137U, 2405439045U,
296 1842224848U, 692413798U, 3479807801U, 919913813U,
297 4269430871U, 610793021U, 527273862U, 1437122909U,
298 2300930706U, 2943759320U, 674306647U, 2400528935U,
299 54481931U, 4186304426U, 1741088401U, 2979625118U,
300 4159057246U, 3425930182U};
302 // You have updated the memcache_error messages but not updated docs/tests.
303 assert(MEMCACHED_MAXIMUM_RETURN
== 38);
304 for (rc
= MEMCACHED_SUCCESS
; rc
< MEMCACHED_MAXIMUM_RETURN
; rc
++)
307 const char *msg
= memcached_strerror(memc
, rc
);
308 hash_val
= memcached_generate_hash_value(msg
, strlen(msg
),
309 MEMCACHED_HASH_JENKINS
);
310 assert(values
[rc
] == hash_val
);
316 static test_return
set_test(memcached_st
*memc
)
319 const char *key
= "foo";
320 const char *value
= "when we sanitize";
322 rc
= memcached_set(memc
, key
, strlen(key
),
323 value
, strlen(value
),
324 (time_t)0, (uint32_t)0);
325 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
330 static test_return
append_test(memcached_st
*memc
)
333 const char *key
= "fig";
334 const char *in_value
= "we";
335 char *out_value
= NULL
;
339 rc
= memcached_flush(memc
, 0);
340 assert(rc
== MEMCACHED_SUCCESS
);
342 rc
= memcached_set(memc
, key
, strlen(key
),
343 in_value
, strlen(in_value
),
344 (time_t)0, (uint32_t)0);
345 assert(rc
== MEMCACHED_SUCCESS
);
347 rc
= memcached_append(memc
, key
, strlen(key
),
348 " the", strlen(" the"),
349 (time_t)0, (uint32_t)0);
350 assert(rc
== MEMCACHED_SUCCESS
);
352 rc
= memcached_append(memc
, key
, strlen(key
),
353 " people", strlen(" people"),
354 (time_t)0, (uint32_t)0);
355 assert(rc
== MEMCACHED_SUCCESS
);
357 out_value
= memcached_get(memc
, key
, strlen(key
),
358 &value_length
, &flags
, &rc
);
359 assert(!memcmp(out_value
, "we the people", strlen("we the people")));
360 assert(strlen("we the people") == value_length
);
361 assert(rc
== MEMCACHED_SUCCESS
);
367 static test_return
append_binary_test(memcached_st
*memc
)
370 const char *key
= "numbers";
371 unsigned int *store_ptr
;
372 unsigned int store_list
[] = { 23, 56, 499, 98, 32847, 0 };
378 rc
= memcached_flush(memc
, 0);
379 assert(rc
== MEMCACHED_SUCCESS
);
381 rc
= memcached_set(memc
,
384 (time_t)0, (uint32_t)0);
385 assert(rc
== MEMCACHED_SUCCESS
);
387 for (x
= 0; store_list
[x
] ; x
++)
389 rc
= memcached_append(memc
,
391 (char *)&store_list
[x
], sizeof(unsigned int),
392 (time_t)0, (uint32_t)0);
393 assert(rc
== MEMCACHED_SUCCESS
);
396 value
= memcached_get(memc
, key
, strlen(key
),
397 &value_length
, &flags
, &rc
);
398 assert((value_length
== (sizeof(unsigned int) * x
)));
399 assert(rc
== MEMCACHED_SUCCESS
);
401 store_ptr
= (unsigned int *)value
;
403 while ((size_t)store_ptr
< (size_t)(value
+ value_length
))
405 assert(*store_ptr
== store_list
[x
++]);
413 static test_return
cas2_test(memcached_st
*memc
)
416 const char *keys
[]= {"fudge", "son", "food"};
417 size_t key_length
[]= {5, 3, 4};
418 const char *value
= "we the people";
419 size_t value_length
= strlen("we the people");
421 memcached_result_st results_obj
;
422 memcached_result_st
*results
;
425 rc
= memcached_flush(memc
, 0);
426 assert(rc
== MEMCACHED_SUCCESS
);
428 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
430 for (x
= 0; x
< 3; x
++)
432 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
433 keys
[x
], key_length
[x
],
434 (time_t)50, (uint32_t)9);
435 assert(rc
== MEMCACHED_SUCCESS
);
438 rc
= memcached_mget(memc
, keys
, key_length
, 3);
440 results
= memcached_result_create(memc
, &results_obj
);
442 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
444 assert(results
->cas
);
445 assert(rc
== MEMCACHED_SUCCESS
);
446 assert(memcached_result_cas(results
));
448 assert(!memcmp(value
, "we the people", strlen("we the people")));
449 assert(strlen("we the people") == value_length
);
450 assert(rc
== MEMCACHED_SUCCESS
);
452 memcached_result_free(&results_obj
);
457 static test_return
cas_test(memcached_st
*memc
)
460 const char *key
= "fun";
461 size_t key_length
= strlen(key
);
462 const char *value
= "we the people";
463 const char* keys
[2] = { key
, NULL
};
464 size_t keylengths
[2] = { strlen(key
), 0 };
465 size_t value_length
= strlen(value
);
466 const char *value2
= "change the value";
467 size_t value2_length
= strlen(value2
);
469 memcached_result_st results_obj
;
470 memcached_result_st
*results
;
473 rc
= memcached_flush(memc
, 0);
474 assert(rc
== MEMCACHED_SUCCESS
);
476 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
478 rc
= memcached_set(memc
, key
, strlen(key
),
479 value
, strlen(value
),
480 (time_t)0, (uint32_t)0);
481 assert(rc
== MEMCACHED_SUCCESS
);
483 rc
= memcached_mget(memc
, keys
, keylengths
, 1);
485 results
= memcached_result_create(memc
, &results_obj
);
487 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
489 assert(rc
== MEMCACHED_SUCCESS
);
490 assert(memcached_result_cas(results
));
491 assert(!memcmp(value
, memcached_result_value(results
), value_length
));
492 assert(strlen(memcached_result_value(results
)) == value_length
);
493 assert(rc
== MEMCACHED_SUCCESS
);
494 uint64_t cas
= memcached_result_cas(results
);
497 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
498 assert(rc
== MEMCACHED_END
);
499 assert(results
== NULL
);
502 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
503 assert(rc
== MEMCACHED_SUCCESS
);
506 * The item will have a new cas value, so try to set it again with the old
507 * value. This should fail!
509 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
510 assert(rc
== MEMCACHED_DATA_EXISTS
);
512 memcached_result_free(&results_obj
);
517 static test_return
prepend_test(memcached_st
*memc
)
520 const char *key
= "fig";
521 const char *value
= "people";
522 char *out_value
= NULL
;
526 rc
= memcached_flush(memc
, 0);
527 assert(rc
== MEMCACHED_SUCCESS
);
529 rc
= memcached_set(memc
, key
, strlen(key
),
530 value
, strlen(value
),
531 (time_t)0, (uint32_t)0);
532 assert(rc
== MEMCACHED_SUCCESS
);
534 rc
= memcached_prepend(memc
, key
, strlen(key
),
535 "the ", strlen("the "),
536 (time_t)0, (uint32_t)0);
537 assert(rc
== MEMCACHED_SUCCESS
);
539 rc
= memcached_prepend(memc
, key
, strlen(key
),
540 "we ", strlen("we "),
541 (time_t)0, (uint32_t)0);
542 assert(rc
== MEMCACHED_SUCCESS
);
544 out_value
= memcached_get(memc
, key
, strlen(key
),
545 &value_length
, &flags
, &rc
);
546 assert(!memcmp(out_value
, "we the people", strlen("we the people")));
547 assert(strlen("we the people") == value_length
);
548 assert(rc
== MEMCACHED_SUCCESS
);
555 Set the value, then quit to make sure it is flushed.
556 Come back in and test that add fails.
558 static test_return
add_test(memcached_st
*memc
)
561 const char *key
= "foo";
562 const char *value
= "when we sanitize";
563 unsigned long long setting_value
;
565 setting_value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
567 rc
= memcached_set(memc
, key
, strlen(key
),
568 value
, strlen(value
),
569 (time_t)0, (uint32_t)0);
570 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
571 memcached_quit(memc
);
572 rc
= memcached_add(memc
, key
, strlen(key
),
573 value
, strlen(value
),
574 (time_t)0, (uint32_t)0);
576 /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */
578 assert(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_STORED
);
580 assert(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_DATA_EXISTS
);
586 ** There was a problem of leaking filedescriptors in the initial release
587 ** of MacOSX 10.5. This test case triggers the problem. On some Solaris
588 ** systems it seems that the kernel is slow on reclaiming the resources
589 ** because the connects starts to time out (the test doesn't do much
590 ** anyway, so just loop 10 iterations)
592 static test_return
add_wrapper(memcached_st
*memc
)
595 unsigned int max
= 10000;
603 for (x
= 0; x
< max
; x
++)
609 static test_return
replace_test(memcached_st
*memc
)
612 const char *key
= "foo";
613 const char *value
= "when we sanitize";
614 const char *original
= "first we insert some data";
616 rc
= memcached_set(memc
, key
, strlen(key
),
617 original
, strlen(original
),
618 (time_t)0, (uint32_t)0);
619 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
621 rc
= memcached_replace(memc
, key
, strlen(key
),
622 value
, strlen(value
),
623 (time_t)0, (uint32_t)0);
624 assert(rc
== MEMCACHED_SUCCESS
);
629 static test_return
delete_test(memcached_st
*memc
)
632 const char *key
= "foo";
633 const char *value
= "when we sanitize";
635 rc
= memcached_set(memc
, key
, strlen(key
),
636 value
, strlen(value
),
637 (time_t)0, (uint32_t)0);
638 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
640 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
641 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
646 static test_return
flush_test(memcached_st
*memc
)
650 rc
= memcached_flush(memc
, 0);
651 assert(rc
== MEMCACHED_SUCCESS
);
656 static memcached_return
server_function(memcached_st
*ptr
__attribute__((unused
)),
657 memcached_server_st
*server
__attribute__((unused
)),
658 void *context
__attribute__((unused
)))
662 return MEMCACHED_SUCCESS
;
665 static test_return
memcached_server_cursor_test(memcached_st
*memc
)
668 strcpy(context
, "foo bad");
669 memcached_server_function callbacks
[1];
671 callbacks
[0]= server_function
;
672 memcached_server_cursor(memc
, callbacks
, context
, 1);
676 static test_return
bad_key_test(memcached_st
*memc
)
679 const char *key
= "foo bad";
681 size_t string_length
;
683 memcached_st
*memc_clone
;
685 size_t max_keylen
= 0xffff;
687 memc_clone
= memcached_clone(NULL
, memc
);
690 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
691 assert(rc
== MEMCACHED_SUCCESS
);
693 /* All keys are valid in the binary protocol (except for length) */
694 if (memcached_behavior_get(memc_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 0)
696 string
= memcached_get(memc_clone
, key
, strlen(key
),
697 &string_length
, &flags
, &rc
);
698 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
699 assert(string_length
== 0);
703 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
704 assert(rc
== MEMCACHED_SUCCESS
);
705 string
= memcached_get(memc_clone
, key
, strlen(key
),
706 &string_length
, &flags
, &rc
);
707 assert(rc
== MEMCACHED_NOTFOUND
);
708 assert(string_length
== 0);
711 /* Test multi key for bad keys */
712 const char *keys
[] = { "GoodKey", "Bad Key", "NotMine" };
713 size_t key_lengths
[] = { 7, 7, 7 };
715 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
716 assert(rc
== MEMCACHED_SUCCESS
);
718 rc
= memcached_mget(memc_clone
, keys
, key_lengths
, 3);
719 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
721 rc
= memcached_mget_by_key(memc_clone
, "foo daddy", 9, keys
, key_lengths
, 1);
722 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
726 /* The following test should be moved to the end of this function when the
727 memcached server is updated to allow max size length of the keys in the
730 rc
= memcached_callback_set(memc_clone
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
731 assert(rc
== MEMCACHED_SUCCESS
);
733 char *longkey
= malloc(max_keylen
+ 1);
736 memset(longkey
, 'a', max_keylen
+ 1);
737 string
= memcached_get(memc_clone
, longkey
, max_keylen
,
738 &string_length
, &flags
, &rc
);
739 assert(rc
== MEMCACHED_NOTFOUND
);
740 assert(string_length
== 0);
743 string
= memcached_get(memc_clone
, longkey
, max_keylen
+ 1,
744 &string_length
, &flags
, &rc
);
745 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
746 assert(string_length
== 0);
753 /* Make sure zero length keys are marked as bad */
755 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
756 assert(rc
== MEMCACHED_SUCCESS
);
757 string
= memcached_get(memc_clone
, key
, 0,
758 &string_length
, &flags
, &rc
);
759 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
760 assert(string_length
== 0);
763 memcached_free(memc_clone
);
768 #define READ_THROUGH_VALUE "set for me"
769 static memcached_return
read_through_trigger(memcached_st
*memc
__attribute__((unused
)),
770 char *key
__attribute__((unused
)),
771 size_t key_length
__attribute__((unused
)),
772 memcached_result_st
*result
)
775 return memcached_result_set_value(result
, READ_THROUGH_VALUE
, strlen(READ_THROUGH_VALUE
));
778 static test_return
read_through(memcached_st
*memc
)
781 const char *key
= "foo";
783 size_t string_length
;
785 memcached_trigger_key cb
= (memcached_trigger_key
)read_through_trigger
;
787 string
= memcached_get(memc
, key
, strlen(key
),
788 &string_length
, &flags
, &rc
);
790 assert(rc
== MEMCACHED_NOTFOUND
);
791 assert(string_length
== 0);
794 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_GET_FAILURE
,
796 assert(rc
== MEMCACHED_SUCCESS
);
798 string
= memcached_get(memc
, key
, strlen(key
),
799 &string_length
, &flags
, &rc
);
801 assert(rc
== MEMCACHED_SUCCESS
);
802 assert(string_length
== strlen(READ_THROUGH_VALUE
));
803 assert(!strcmp(READ_THROUGH_VALUE
, string
));
806 string
= memcached_get(memc
, key
, strlen(key
),
807 &string_length
, &flags
, &rc
);
809 assert(rc
== MEMCACHED_SUCCESS
);
810 assert(string_length
== strlen(READ_THROUGH_VALUE
));
811 assert(!strcmp(READ_THROUGH_VALUE
, string
));
817 static memcached_return
delete_trigger(memcached_st
*ptr
__attribute__((unused
)),
819 size_t key_length
__attribute__((unused
)))
823 return MEMCACHED_SUCCESS
;
826 static test_return
delete_through(memcached_st
*memc
)
828 memcached_trigger_delete_key callback
;
831 callback
= (memcached_trigger_delete_key
)delete_trigger
;
833 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_DELETE_TRIGGER
, *(void**)&callback
);
834 assert(rc
== MEMCACHED_SUCCESS
);
839 static test_return
get_test(memcached_st
*memc
)
842 const char *key
= "foo";
844 size_t string_length
;
847 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
848 assert(rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_NOTFOUND
);
850 string
= memcached_get(memc
, key
, strlen(key
),
851 &string_length
, &flags
, &rc
);
853 assert(rc
== MEMCACHED_NOTFOUND
);
854 assert(string_length
== 0);
860 static test_return
get_test2(memcached_st
*memc
)
863 const char *key
= "foo";
864 const char *value
= "when we sanitize";
866 size_t string_length
;
869 rc
= memcached_set(memc
, key
, strlen(key
),
870 value
, strlen(value
),
871 (time_t)0, (uint32_t)0);
872 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
874 string
= memcached_get(memc
, key
, strlen(key
),
875 &string_length
, &flags
, &rc
);
878 assert(rc
== MEMCACHED_SUCCESS
);
879 assert(string_length
== strlen(value
));
880 assert(!memcmp(string
, value
, string_length
));
887 static test_return
set_test2(memcached_st
*memc
)
890 const char *key
= "foo";
891 const char *value
= "train in the brain";
892 size_t value_length
= strlen(value
);
895 for (x
= 0; x
< 10; x
++)
897 rc
= memcached_set(memc
, key
, strlen(key
),
899 (time_t)0, (uint32_t)0);
900 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
906 static test_return
set_test3(memcached_st
*memc
)
910 size_t value_length
= 8191;
913 value
= (char*)malloc(value_length
);
916 for (x
= 0; x
< value_length
; x
++)
917 value
[x
] = (char) (x
% 127);
919 /* The dump test relies on there being at least 32 items in memcached */
920 for (x
= 0; x
< 32; x
++)
924 sprintf(key
, "foo%u", x
);
926 rc
= memcached_set(memc
, key
, strlen(key
),
928 (time_t)0, (uint32_t)0);
929 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
937 static test_return
get_test3(memcached_st
*memc
)
940 const char *key
= "foo";
942 size_t value_length
= 8191;
944 size_t string_length
;
948 value
= (char*)malloc(value_length
);
951 for (x
= 0; x
< value_length
; x
++)
952 value
[x
] = (char) (x
% 127);
954 rc
= memcached_set(memc
, key
, strlen(key
),
956 (time_t)0, (uint32_t)0);
957 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
959 string
= memcached_get(memc
, key
, strlen(key
),
960 &string_length
, &flags
, &rc
);
962 assert(rc
== MEMCACHED_SUCCESS
);
964 assert(string_length
== value_length
);
965 assert(!memcmp(string
, value
, string_length
));
973 static test_return
get_test4(memcached_st
*memc
)
976 const char *key
= "foo";
978 size_t value_length
= 8191;
980 size_t string_length
;
984 value
= (char*)malloc(value_length
);
987 for (x
= 0; x
< value_length
; x
++)
988 value
[x
] = (char) (x
% 127);
990 rc
= memcached_set(memc
, key
, strlen(key
),
992 (time_t)0, (uint32_t)0);
993 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
995 for (x
= 0; x
< 10; x
++)
997 string
= memcached_get(memc
, key
, strlen(key
),
998 &string_length
, &flags
, &rc
);
1000 assert(rc
== MEMCACHED_SUCCESS
);
1002 assert(string_length
== value_length
);
1003 assert(!memcmp(string
, value
, string_length
));
1009 return TEST_SUCCESS
;
1013 * This test verifies that memcached_read_one_response doesn't try to
1014 * dereference a NIL-pointer if you issue a multi-get and don't read out all
1015 * responses before you execute a storage command.
1017 static test_return
get_test5(memcached_st
*memc
)
1020 ** Request the same key twice, to ensure that we hash to the same server
1021 ** (so that we have multiple response values queued up) ;-)
1023 const char *keys
[]= { "key", "key" };
1024 size_t lengths
[]= { 3, 3 };
1028 memcached_return rc
= memcached_set(memc
, keys
[0], lengths
[0],
1029 keys
[0], lengths
[0], 0, 0);
1030 assert(rc
== MEMCACHED_SUCCESS
);
1031 rc
= memcached_mget(memc
, keys
, lengths
, 2);
1033 memcached_result_st results_obj
;
1034 memcached_result_st
*results
;
1035 results
=memcached_result_create(memc
, &results_obj
);
1037 results
=memcached_fetch_result(memc
, &results_obj
, &rc
);
1039 memcached_result_free(&results_obj
);
1041 /* Don't read out the second result, but issue a set instead.. */
1042 rc
= memcached_set(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0);
1043 assert(rc
== MEMCACHED_SUCCESS
);
1045 char *val
= memcached_get_by_key(memc
, keys
[0], lengths
[0], "yek", 3,
1046 &rlen
, &flags
, &rc
);
1047 assert(val
== NULL
);
1048 assert(rc
== MEMCACHED_NOTFOUND
);
1049 val
= memcached_get(memc
, keys
[0], lengths
[0], &rlen
, &flags
, &rc
);
1050 assert(val
!= NULL
);
1051 assert(rc
== MEMCACHED_SUCCESS
);
1054 return TEST_SUCCESS
;
1057 static test_return
mget_end(memcached_st
*memc
)
1059 const char *keys
[]= { "foo", "foo2" };
1060 size_t lengths
[]= { 3, 4 };
1061 const char *values
[]= { "fjord", "41" };
1063 memcached_return rc
;
1066 for (int i
= 0; i
< 2; i
++)
1068 rc
= memcached_set(memc
, keys
[i
], lengths
[i
], values
[i
], strlen(values
[i
]),
1069 (time_t)0, (uint32_t)0);
1070 assert(rc
== MEMCACHED_SUCCESS
);
1074 size_t string_length
;
1077 // retrieve both via mget
1078 rc
= memcached_mget(memc
, keys
, lengths
, 2);
1079 assert(rc
== MEMCACHED_SUCCESS
);
1081 char key
[MEMCACHED_MAX_KEY
];
1084 // this should get both
1085 for (int i
= 0; i
< 2; i
++)
1087 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
,
1089 assert(rc
== MEMCACHED_SUCCESS
);
1091 if (key_length
== 4)
1093 assert(string_length
== strlen(values
[val
]));
1094 assert(strncmp(values
[val
], string
, string_length
) == 0);
1098 // this should indicate end
1099 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1100 assert(rc
== MEMCACHED_END
);
1103 rc
= memcached_mget(memc
, keys
, lengths
, 1);
1104 assert(rc
== MEMCACHED_SUCCESS
);
1106 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1107 assert(key_length
== lengths
[0]);
1108 assert(strncmp(keys
[0], key
, key_length
) == 0);
1109 assert(string_length
== strlen(values
[0]));
1110 assert(strncmp(values
[0], string
, string_length
) == 0);
1111 assert(rc
== MEMCACHED_SUCCESS
);
1114 // this should indicate end
1115 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1116 assert(rc
== MEMCACHED_END
);
1118 return TEST_SUCCESS
;
1121 /* Do not copy the style of this code, I just access hosts to testthis function */
1122 static test_return
stats_servername_test(memcached_st
*memc
)
1124 memcached_return rc
;
1125 memcached_stat_st memc_stat
;
1126 rc
= memcached_stat_servername(&memc_stat
, NULL
,
1127 memc
->hosts
[0].hostname
,
1128 memc
->hosts
[0].port
);
1130 return TEST_SUCCESS
;
1133 static test_return
increment_test(memcached_st
*memc
)
1135 uint64_t new_number
;
1136 memcached_return rc
;
1137 const char *key
= "number";
1138 const char *value
= "0";
1140 rc
= memcached_set(memc
, key
, strlen(key
),
1141 value
, strlen(value
),
1142 (time_t)0, (uint32_t)0);
1143 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1145 rc
= memcached_increment(memc
, key
, strlen(key
),
1147 assert(rc
== MEMCACHED_SUCCESS
);
1148 assert(new_number
== 1);
1150 rc
= memcached_increment(memc
, key
, strlen(key
),
1152 assert(rc
== MEMCACHED_SUCCESS
);
1153 assert(new_number
== 2);
1155 return TEST_SUCCESS
;
1158 static test_return
increment_with_initial_test(memcached_st
*memc
)
1160 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1162 uint64_t new_number
;
1163 memcached_return rc
;
1164 const char *key
= "number";
1165 uint64_t initial
= 0;
1167 rc
= memcached_increment_with_initial(memc
, key
, strlen(key
),
1168 1, initial
, 0, &new_number
);
1169 assert(rc
== MEMCACHED_SUCCESS
);
1170 assert(new_number
== initial
);
1172 rc
= memcached_increment_with_initial(memc
, key
, strlen(key
),
1173 1, initial
, 0, &new_number
);
1174 assert(rc
== MEMCACHED_SUCCESS
);
1175 assert(new_number
== (initial
+ 1));
1177 return TEST_SUCCESS
;
1180 static test_return
decrement_test(memcached_st
*memc
)
1182 uint64_t new_number
;
1183 memcached_return rc
;
1184 const char *key
= "number";
1185 const char *value
= "3";
1187 rc
= memcached_set(memc
, key
, strlen(key
),
1188 value
, strlen(value
),
1189 (time_t)0, (uint32_t)0);
1190 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1192 rc
= memcached_decrement(memc
, key
, strlen(key
),
1194 assert(rc
== MEMCACHED_SUCCESS
);
1195 assert(new_number
== 2);
1197 rc
= memcached_decrement(memc
, key
, strlen(key
),
1199 assert(rc
== MEMCACHED_SUCCESS
);
1200 assert(new_number
== 1);
1202 return TEST_SUCCESS
;
1205 static test_return
decrement_with_initial_test(memcached_st
*memc
)
1207 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1209 uint64_t new_number
;
1210 memcached_return rc
;
1211 const char *key
= "number";
1212 uint64_t initial
= 3;
1214 rc
= memcached_decrement_with_initial(memc
, key
, strlen(key
),
1215 1, initial
, 0, &new_number
);
1216 assert(rc
== MEMCACHED_SUCCESS
);
1217 assert(new_number
== initial
);
1219 rc
= memcached_decrement_with_initial(memc
, key
, strlen(key
),
1220 1, initial
, 0, &new_number
);
1221 assert(rc
== MEMCACHED_SUCCESS
);
1222 assert(new_number
== (initial
- 1));
1224 return TEST_SUCCESS
;
1227 static test_return
quit_test(memcached_st
*memc
)
1229 memcached_return rc
;
1230 const char *key
= "fudge";
1231 const char *value
= "sanford and sun";
1233 rc
= memcached_set(memc
, key
, strlen(key
),
1234 value
, strlen(value
),
1235 (time_t)10, (uint32_t)3);
1236 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1237 memcached_quit(memc
);
1239 rc
= memcached_set(memc
, key
, strlen(key
),
1240 value
, strlen(value
),
1241 (time_t)50, (uint32_t)9);
1242 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1244 return TEST_SUCCESS
;
1247 static test_return
mget_result_test(memcached_st
*memc
)
1249 memcached_return rc
;
1250 const char *keys
[]= {"fudge", "son", "food"};
1251 size_t key_length
[]= {5, 3, 4};
1254 memcached_result_st results_obj
;
1255 memcached_result_st
*results
;
1257 results
= memcached_result_create(memc
, &results_obj
);
1259 assert(&results_obj
== results
);
1261 /* We need to empty the server before continueing test */
1262 rc
= memcached_flush(memc
, 0);
1263 assert(rc
== MEMCACHED_SUCCESS
);
1265 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1266 assert(rc
== MEMCACHED_SUCCESS
);
1268 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1273 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1275 assert(rc
== MEMCACHED_END
);
1277 for (x
= 0; x
< 3; x
++)
1279 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1280 keys
[x
], key_length
[x
],
1281 (time_t)50, (uint32_t)9);
1282 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1285 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1286 assert(rc
== MEMCACHED_SUCCESS
);
1288 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1291 assert(&results_obj
== results
);
1292 assert(rc
== MEMCACHED_SUCCESS
);
1293 assert(memcached_result_key_length(results
) == memcached_result_length(results
));
1294 assert(!memcmp(memcached_result_key_value(results
),
1295 memcached_result_value(results
),
1296 memcached_result_length(results
)));
1299 memcached_result_free(&results_obj
);
1301 return TEST_SUCCESS
;
1304 static test_return
mget_result_alloc_test(memcached_st
*memc
)
1306 memcached_return rc
;
1307 const char *keys
[]= {"fudge", "son", "food"};
1308 size_t key_length
[]= {5, 3, 4};
1311 memcached_result_st
*results
;
1313 /* We need to empty the server before continueing test */
1314 rc
= memcached_flush(memc
, 0);
1315 assert(rc
== MEMCACHED_SUCCESS
);
1317 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1318 assert(rc
== MEMCACHED_SUCCESS
);
1320 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)) != NULL
)
1325 assert(rc
== MEMCACHED_END
);
1327 for (x
= 0; x
< 3; x
++)
1329 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1330 keys
[x
], key_length
[x
],
1331 (time_t)50, (uint32_t)9);
1332 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1335 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1336 assert(rc
== MEMCACHED_SUCCESS
);
1339 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1342 assert(rc
== MEMCACHED_SUCCESS
);
1343 assert(memcached_result_key_length(results
) == memcached_result_length(results
));
1344 assert(!memcmp(memcached_result_key_value(results
),
1345 memcached_result_value(results
),
1346 memcached_result_length(results
)));
1347 memcached_result_free(results
);
1351 return TEST_SUCCESS
;
1354 /* Count the results */
1355 static memcached_return
callback_counter(memcached_st
*ptr
__attribute__((unused
)),
1356 memcached_result_st
*result
__attribute__((unused
)),
1359 unsigned int *counter
= (unsigned int *)context
;
1361 *counter
= *counter
+ 1;
1363 return MEMCACHED_SUCCESS
;
1366 static test_return
mget_result_function(memcached_st
*memc
)
1368 memcached_return rc
;
1369 const char *keys
[]= {"fudge", "son", "food"};
1370 size_t key_length
[]= {5, 3, 4};
1372 unsigned int counter
;
1373 memcached_execute_function callbacks
[1];
1375 /* We need to empty the server before continueing test */
1376 rc
= memcached_flush(memc
, 0);
1377 for (x
= 0; x
< 3; x
++)
1379 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1380 keys
[x
], key_length
[x
],
1381 (time_t)50, (uint32_t)9);
1382 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1385 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1386 assert(rc
== MEMCACHED_SUCCESS
);
1388 callbacks
[0]= &callback_counter
;
1390 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
1392 assert(counter
== 3);
1394 return TEST_SUCCESS
;
1397 static test_return
mget_test(memcached_st
*memc
)
1399 memcached_return rc
;
1400 const char *keys
[]= {"fudge", "son", "food"};
1401 size_t key_length
[]= {5, 3, 4};
1405 char return_key
[MEMCACHED_MAX_KEY
];
1406 size_t return_key_length
;
1408 size_t return_value_length
;
1410 /* We need to empty the server before continueing test */
1411 rc
= memcached_flush(memc
, 0);
1412 assert(rc
== MEMCACHED_SUCCESS
);
1414 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1415 assert(rc
== MEMCACHED_SUCCESS
);
1417 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1418 &return_value_length
, &flags
, &rc
)) != NULL
)
1420 assert(return_value
);
1422 assert(!return_value
);
1423 assert(return_value_length
== 0);
1424 assert(rc
== MEMCACHED_END
);
1426 for (x
= 0; x
< 3; x
++)
1428 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1429 keys
[x
], key_length
[x
],
1430 (time_t)50, (uint32_t)9);
1431 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1434 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1435 assert(rc
== MEMCACHED_SUCCESS
);
1438 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1439 &return_value_length
, &flags
, &rc
)))
1441 assert(return_value
);
1442 assert(rc
== MEMCACHED_SUCCESS
);
1443 assert(return_key_length
== return_value_length
);
1444 assert(!memcmp(return_value
, return_key
, return_value_length
));
1449 return TEST_SUCCESS
;
1452 static test_return
get_stats_keys(memcached_st
*memc
)
1456 memcached_stat_st memc_stat
;
1457 memcached_return rc
;
1459 list
= memcached_stat_get_keys(memc
, &memc_stat
, &rc
);
1460 assert(rc
== MEMCACHED_SUCCESS
);
1461 for (ptr
= list
; *ptr
; ptr
++)
1467 return TEST_SUCCESS
;
1470 static test_return
version_string_test(memcached_st
*memc
__attribute__((unused
)))
1472 const char *version_string
;
1474 version_string
= memcached_lib_version();
1476 assert(!strcmp(version_string
, LIBMEMCACHED_VERSION_STRING
));
1478 return TEST_SUCCESS
;
1481 static test_return
get_stats(memcached_st
*memc
)
1486 memcached_return rc
;
1487 memcached_stat_st
*memc_stat
;
1489 memc_stat
= memcached_stat(memc
, NULL
, &rc
);
1490 assert(rc
== MEMCACHED_SUCCESS
);
1492 assert(rc
== MEMCACHED_SUCCESS
);
1495 for (x
= 0; x
< memcached_server_count(memc
); x
++)
1497 list
= memcached_stat_get_keys(memc
, memc_stat
+x
, &rc
);
1498 assert(rc
== MEMCACHED_SUCCESS
);
1499 for (ptr
= list
; *ptr
; ptr
++);
1504 memcached_stat_free(NULL
, memc_stat
);
1506 return TEST_SUCCESS
;
1509 static test_return
add_host_test(memcached_st
*memc
)
1512 memcached_server_st
*servers
;
1513 memcached_return rc
;
1514 char servername
[]= "0.example.com";
1516 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
1518 assert(1 == memcached_server_list_count(servers
));
1520 for (x
= 2; x
< 20; x
++)
1522 char buffer
[SMALL_STRING_LEN
];
1524 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
1525 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
1527 assert(rc
== MEMCACHED_SUCCESS
);
1528 assert(x
== memcached_server_list_count(servers
));
1531 rc
= memcached_server_push(memc
, servers
);
1532 assert(rc
== MEMCACHED_SUCCESS
);
1533 rc
= memcached_server_push(memc
, servers
);
1534 assert(rc
== MEMCACHED_SUCCESS
);
1536 memcached_server_list_free(servers
);
1538 return TEST_SUCCESS
;
1541 static memcached_return
clone_test_callback(memcached_st
*parent
__attribute__((unused
)), memcached_st
*memc_clone
__attribute__((unused
)))
1543 return MEMCACHED_SUCCESS
;
1546 static memcached_return
cleanup_test_callback(memcached_st
*ptr
__attribute__((unused
)))
1548 return MEMCACHED_SUCCESS
;
1551 static test_return
callback_test(memcached_st
*memc
)
1553 /* Test User Data */
1557 memcached_return rc
;
1559 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_USER_DATA
, &x
);
1560 assert(rc
== MEMCACHED_SUCCESS
);
1561 test_ptr
= (int *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_USER_DATA
, &rc
);
1562 assert(*test_ptr
== x
);
1565 /* Test Clone Callback */
1567 memcached_clone_func clone_cb
= (memcached_clone_func
)clone_test_callback
;
1568 void *clone_cb_ptr
= *(void **)&clone_cb
;
1569 void *temp_function
= NULL
;
1570 memcached_return rc
;
1572 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
,
1574 assert(rc
== MEMCACHED_SUCCESS
);
1575 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1576 assert(temp_function
== clone_cb_ptr
);
1579 /* Test Cleanup Callback */
1581 memcached_cleanup_func cleanup_cb
=
1582 (memcached_cleanup_func
)cleanup_test_callback
;
1583 void *cleanup_cb_ptr
= *(void **)&cleanup_cb
;
1584 void *temp_function
= NULL
;
1585 memcached_return rc
;
1587 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
,
1589 assert(rc
== MEMCACHED_SUCCESS
);
1590 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1591 assert(temp_function
== cleanup_cb_ptr
);
1594 return TEST_SUCCESS
;
1597 /* We don't test the behavior itself, we test the switches */
1598 static test_return
behavior_test(memcached_st
*memc
)
1603 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1604 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1607 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1608 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1611 set
= MEMCACHED_HASH_MD5
;
1612 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1613 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1614 assert(value
== MEMCACHED_HASH_MD5
);
1618 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1619 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1622 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1623 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1626 set
= MEMCACHED_HASH_DEFAULT
;
1627 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1628 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1629 assert(value
== MEMCACHED_HASH_DEFAULT
);
1631 set
= MEMCACHED_HASH_CRC
;
1632 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1633 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1634 assert(value
== MEMCACHED_HASH_CRC
);
1636 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1639 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1642 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
);
1643 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, value
+ 1);
1644 assert((value
+ 1) == memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
));
1645 return TEST_SUCCESS
;
1648 static test_return
fetch_all_results(memcached_st
*memc
)
1650 memcached_return rc
= MEMCACHED_SUCCESS
;
1651 char return_key
[MEMCACHED_MAX_KEY
];
1652 size_t return_key_length
;
1654 size_t return_value_length
;
1657 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1658 &return_value_length
, &flags
, &rc
)))
1660 assert(return_value
);
1661 assert(rc
== MEMCACHED_SUCCESS
);
1665 return ((rc
== MEMCACHED_END
) || (rc
== MEMCACHED_SUCCESS
)) ? TEST_SUCCESS
: TEST_FAILURE
;
1668 /* Test case provided by Cal Haldenbrand */
1669 static test_return
user_supplied_bug1(memcached_st
*memc
)
1671 unsigned int setter
= 1;
1674 unsigned long long total
= 0;
1677 char randomstuff
[6 * 1024];
1678 memcached_return rc
;
1680 memset(randomstuff
, 0, 6 * 1024);
1682 /* We just keep looking at the same values over and over */
1685 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1686 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1690 for (x
= 0 ; total
< 20 * 1024576 ; x
++ )
1694 size
= (uint32_t)(rand() % ( 5 * 1024 ) ) + 400;
1695 memset(randomstuff
, 0, 6 * 1024);
1696 assert(size
< 6 * 1024); /* Being safe here */
1698 for (j
= 0 ; j
< size
;j
++)
1699 randomstuff
[j
] = (signed char) ((rand() % 26) + 97);
1702 sprintf(key
, "%d", x
);
1703 rc
= memcached_set(memc
, key
, strlen(key
),
1704 randomstuff
, strlen(randomstuff
), 10, 0);
1705 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1706 /* If we fail, lets try again */
1707 if (rc
!= MEMCACHED_SUCCESS
&& rc
!= MEMCACHED_BUFFERED
)
1708 rc
= memcached_set(memc
, key
, strlen(key
),
1709 randomstuff
, strlen(randomstuff
), 10, 0);
1710 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1713 return TEST_SUCCESS
;
1716 /* Test case provided by Cal Haldenbrand */
1717 static test_return
user_supplied_bug2(memcached_st
*memc
)
1720 unsigned int setter
;
1722 unsigned long long total
;
1725 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1726 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1728 setter
= 20 * 1024576;
1729 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1730 setter
= 20 * 1024576;
1731 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1732 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1733 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1735 for (x
= 0, errors
= 0, total
= 0 ; total
< 20 * 1024576 ; x
++)
1738 for (x
= 0, errors
= 0, total
= 0 ; total
< 24576 ; x
++)
1740 memcached_return rc
= MEMCACHED_SUCCESS
;
1741 char buffer
[SMALL_STRING_LEN
];
1746 memset(buffer
, 0, SMALL_STRING_LEN
);
1748 snprintf(buffer
, SMALL_STRING_LEN
, "%u", x
);
1749 getval
= memcached_get(memc
, buffer
, strlen(buffer
),
1750 &val_len
, &flags
, &rc
);
1751 if (rc
!= MEMCACHED_SUCCESS
)
1753 if (rc
== MEMCACHED_NOTFOUND
)
1767 return TEST_SUCCESS
;
1770 /* Do a large mget() over all the keys we think exist */
1771 #define KEY_COUNT 3000 // * 1024576
1772 static test_return
user_supplied_bug3(memcached_st
*memc
)
1774 memcached_return rc
;
1775 unsigned int setter
;
1778 size_t key_lengths
[KEY_COUNT
];
1781 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1782 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1784 setter
= 20 * 1024576;
1785 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1786 setter
= 20 * 1024576;
1787 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1788 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1789 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1792 keys
= calloc(KEY_COUNT
, sizeof(char *));
1794 for (x
= 0; x
< KEY_COUNT
; x
++)
1798 snprintf(buffer
, 30, "%u", x
);
1799 keys
[x
]= strdup(buffer
);
1800 key_lengths
[x
]= strlen(keys
[x
]);
1803 rc
= memcached_mget(memc
, (const char **)keys
, key_lengths
, KEY_COUNT
);
1804 assert(rc
== MEMCACHED_SUCCESS
);
1806 assert(fetch_all_results(memc
) == TEST_SUCCESS
);
1808 for (x
= 0; x
< KEY_COUNT
; x
++)
1812 return TEST_SUCCESS
;
1815 /* Make sure we behave properly if server list has no values */
1816 static test_return
user_supplied_bug4(memcached_st
*memc
)
1818 memcached_return rc
;
1819 const char *keys
[]= {"fudge", "son", "food"};
1820 size_t key_length
[]= {5, 3, 4};
1823 char return_key
[MEMCACHED_MAX_KEY
];
1824 size_t return_key_length
;
1826 size_t return_value_length
;
1828 /* Here we free everything before running a bunch of mget tests */
1830 memcached_server_list_free(memc
->hosts
);
1832 memc
->number_of_hosts
= 0;
1836 /* We need to empty the server before continueing test */
1837 rc
= memcached_flush(memc
, 0);
1838 assert(rc
== MEMCACHED_NO_SERVERS
);
1840 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1841 assert(rc
== MEMCACHED_NO_SERVERS
);
1843 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1844 &return_value_length
, &flags
, &rc
)) != NULL
)
1846 assert(return_value
);
1848 assert(!return_value
);
1849 assert(return_value_length
== 0);
1850 assert(rc
== MEMCACHED_NO_SERVERS
);
1852 for (x
= 0; x
< 3; x
++)
1854 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1855 keys
[x
], key_length
[x
],
1856 (time_t)50, (uint32_t)9);
1857 assert(rc
== MEMCACHED_NO_SERVERS
);
1860 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1861 assert(rc
== MEMCACHED_NO_SERVERS
);
1864 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1865 &return_value_length
, &flags
, &rc
)))
1867 assert(return_value
);
1868 assert(rc
== MEMCACHED_SUCCESS
);
1869 assert(return_key_length
== return_value_length
);
1870 assert(!memcmp(return_value
, return_key
, return_value_length
));
1875 return TEST_SUCCESS
;
1878 #define VALUE_SIZE_BUG5 1048064
1879 static test_return
user_supplied_bug5(memcached_st
*memc
)
1881 memcached_return rc
;
1882 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1883 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1884 char return_key
[MEMCACHED_MAX_KEY
];
1885 size_t return_key_length
;
1887 size_t value_length
;
1891 char insert_data
[VALUE_SIZE_BUG5
];
1893 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1894 insert_data
[x
]= (signed char)rand();
1896 memcached_flush(memc
, 0);
1897 value
= memcached_get(memc
, keys
[0], key_length
[0],
1898 &value_length
, &flags
, &rc
);
1899 assert(value
== NULL
);
1900 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1903 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1904 &value_length
, &flags
, &rc
)))
1908 for (x
= 0; x
< 4; x
++)
1910 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1911 insert_data
, VALUE_SIZE_BUG5
,
1912 (time_t)0, (uint32_t)0);
1913 assert(rc
== MEMCACHED_SUCCESS
);
1916 for (x
= 0; x
< 10; x
++)
1918 value
= memcached_get(memc
, keys
[0], key_length
[0],
1919 &value_length
, &flags
, &rc
);
1923 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1925 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1926 &value_length
, &flags
, &rc
)))
1934 return TEST_SUCCESS
;
1937 static test_return
user_supplied_bug6(memcached_st
*memc
)
1939 memcached_return rc
;
1940 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1941 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1942 char return_key
[MEMCACHED_MAX_KEY
];
1943 size_t return_key_length
;
1945 size_t value_length
;
1949 char insert_data
[VALUE_SIZE_BUG5
];
1951 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1952 insert_data
[x
]= (signed char)rand();
1954 memcached_flush(memc
, 0);
1955 value
= memcached_get(memc
, keys
[0], key_length
[0],
1956 &value_length
, &flags
, &rc
);
1957 assert(value
== NULL
);
1958 assert(rc
== MEMCACHED_NOTFOUND
);
1959 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1960 assert(rc
== MEMCACHED_SUCCESS
);
1963 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1964 &value_length
, &flags
, &rc
)))
1967 assert(rc
== MEMCACHED_END
);
1969 for (x
= 0; x
< 4; x
++)
1971 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1972 insert_data
, VALUE_SIZE_BUG5
,
1973 (time_t)0, (uint32_t)0);
1974 assert(rc
== MEMCACHED_SUCCESS
);
1977 for (x
= 0; x
< 2; x
++)
1979 value
= memcached_get(memc
, keys
[0], key_length
[0],
1980 &value_length
, &flags
, &rc
);
1984 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1985 assert(rc
== MEMCACHED_SUCCESS
);
1987 /* We test for purge of partial complete fetches */
1988 for (count
= 3; count
; count
--)
1990 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1991 &value_length
, &flags
, &rc
);
1992 assert(rc
== MEMCACHED_SUCCESS
);
1993 assert(!(memcmp(value
, insert_data
, value_length
)));
1994 assert(value_length
);
1999 return TEST_SUCCESS
;
2002 static test_return
user_supplied_bug8(memcached_st
*memc
__attribute__((unused
)))
2004 memcached_return rc
;
2006 memcached_st
*memc_clone
;
2008 memcached_server_st
*servers
;
2009 const 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";
2011 servers
= memcached_servers_parse(server_list
);
2014 mine
= memcached_create(NULL
);
2015 rc
= memcached_server_push(mine
, servers
);
2016 assert(rc
== MEMCACHED_SUCCESS
);
2017 memcached_server_list_free(servers
);
2020 memc_clone
= memcached_clone(NULL
, mine
);
2022 memcached_quit(mine
);
2023 memcached_quit(memc_clone
);
2026 memcached_free(mine
);
2027 memcached_free(memc_clone
);
2029 return TEST_SUCCESS
;
2032 /* Test flag store/retrieve */
2033 static test_return
user_supplied_bug7(memcached_st
*memc
)
2035 memcached_return rc
;
2036 const char *keys
= "036790384900";
2037 size_t key_length
= strlen(keys
);
2038 char return_key
[MEMCACHED_MAX_KEY
];
2039 size_t return_key_length
;
2041 size_t value_length
;
2044 char insert_data
[VALUE_SIZE_BUG5
];
2046 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2047 insert_data
[x
]= (signed char)rand();
2049 memcached_flush(memc
, 0);
2052 rc
= memcached_set(memc
, keys
, key_length
,
2053 insert_data
, VALUE_SIZE_BUG5
,
2055 assert(rc
== MEMCACHED_SUCCESS
);
2058 value
= memcached_get(memc
, keys
, key_length
,
2059 &value_length
, &flags
, &rc
);
2060 assert(flags
== 245);
2064 rc
= memcached_mget(memc
, &keys
, &key_length
, 1);
2067 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2068 &value_length
, &flags
, &rc
);
2069 assert(flags
== 245);
2074 return TEST_SUCCESS
;
2077 static test_return
user_supplied_bug9(memcached_st
*memc
)
2079 memcached_return rc
;
2080 const char *keys
[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
2081 size_t key_length
[3];
2086 char return_key
[MEMCACHED_MAX_KEY
];
2087 size_t return_key_length
;
2089 size_t return_value_length
;
2092 key_length
[0]= strlen("UDATA:edevil@sapo.pt");
2093 key_length
[1]= strlen("fudge&*@#");
2094 key_length
[2]= strlen("for^#@&$not");
2097 for (x
= 0; x
< 3; x
++)
2099 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2100 keys
[x
], key_length
[x
],
2101 (time_t)50, (uint32_t)9);
2102 assert(rc
== MEMCACHED_SUCCESS
);
2105 rc
= memcached_mget(memc
, keys
, key_length
, 3);
2106 assert(rc
== MEMCACHED_SUCCESS
);
2108 /* We need to empty the server before continueing test */
2109 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2110 &return_value_length
, &flags
, &rc
)) != NULL
)
2112 assert(return_value
);
2118 return TEST_SUCCESS
;
2121 /* We are testing with aggressive timeout to get failures */
2122 static test_return
user_supplied_bug10(memcached_st
*memc
)
2124 const char *key
= "foo";
2126 size_t value_length
= 512;
2129 memcached_return rc
;
2130 unsigned int set
= 1;
2131 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2134 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2135 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2137 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
,
2140 value
= (char*)malloc(value_length
* sizeof(char));
2142 for (x
= 0; x
< value_length
; x
++)
2143 value
[x
]= (char) (x
% 127);
2145 for (x
= 1; x
<= 100000; ++x
)
2147 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2149 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_WRITE_FAILURE
||
2150 rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_TIMEOUT
);
2152 if (rc
== MEMCACHED_WRITE_FAILURE
|| rc
== MEMCACHED_TIMEOUT
)
2157 memcached_free(mclone
);
2159 return TEST_SUCCESS
;
2163 We are looking failures in the async protocol
2165 static test_return
user_supplied_bug11(memcached_st
*memc
)
2167 const char *key
= "foo";
2169 size_t value_length
= 512;
2172 memcached_return rc
;
2173 unsigned int set
= 1;
2175 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2177 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2178 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2180 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
,
2183 timeout
= (int32_t)memcached_behavior_get(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
2185 assert(timeout
== -1);
2187 value
= (char*)malloc(value_length
* sizeof(char));
2189 for (x
= 0; x
< value_length
; x
++)
2190 value
[x
]= (char) (x
% 127);
2192 for (x
= 1; x
<= 100000; ++x
)
2194 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2198 memcached_free(mclone
);
2200 return TEST_SUCCESS
;
2204 Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
2206 static test_return
user_supplied_bug12(memcached_st
*memc
)
2208 memcached_return rc
;
2210 size_t value_length
;
2212 uint64_t number_value
;
2214 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2215 &value_length
, &flags
, &rc
);
2216 assert(value
== NULL
);
2217 assert(rc
== MEMCACHED_NOTFOUND
);
2219 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2222 assert(value
== NULL
);
2223 /* The binary protocol will set the key if it doesn't exist */
2224 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1)
2225 assert(rc
== MEMCACHED_SUCCESS
);
2227 assert(rc
== MEMCACHED_NOTFOUND
);
2229 rc
= memcached_set(memc
, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
2231 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2232 &value_length
, &flags
, &rc
);
2234 assert(rc
== MEMCACHED_SUCCESS
);
2237 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2239 assert(number_value
== 2);
2240 assert(rc
== MEMCACHED_SUCCESS
);
2242 return TEST_SUCCESS
;
2246 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2247 set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
2249 static test_return
user_supplied_bug13(memcached_st
*memc
)
2251 char key
[] = "key34567890";
2253 memcached_return rc
;
2254 size_t overflowSize
;
2256 char commandFirst
[]= "set key34567890 0 0 ";
2257 char commandLast
[] = " \r\n"; /* first line of command sent to server */
2258 size_t commandLength
;
2261 commandLength
= strlen(commandFirst
) + strlen(commandLast
) + 4; /* 4 is number of characters in size, probably 8196 */
2263 overflowSize
= MEMCACHED_MAX_BUFFER
- commandLength
;
2265 for (testSize
= overflowSize
- 1; testSize
< overflowSize
+ 1; testSize
++)
2267 overflow
= malloc(testSize
);
2268 assert(overflow
!= NULL
);
2270 memset(overflow
, 'x', testSize
);
2271 rc
= memcached_set(memc
, key
, strlen(key
),
2272 overflow
, testSize
, 0, 0);
2273 assert(rc
== MEMCACHED_SUCCESS
);
2277 return TEST_SUCCESS
;
2282 Test values of many different sizes
2283 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2284 set key34567890 0 0 8169 \r\n
2285 is sent followed by buffer of size 8169, followed by 8169
2287 static test_return
user_supplied_bug14(memcached_st
*memc
)
2290 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2291 memcached_return rc
;
2292 const char *key
= "foo";
2294 size_t value_length
= 18000;
2296 size_t string_length
;
2299 size_t current_length
;
2301 value
= (char*)malloc(value_length
);
2304 for (x
= 0; x
< value_length
; x
++)
2305 value
[x
] = (char) (x
% 127);
2307 for (current_length
= 0; current_length
< value_length
; current_length
++)
2309 rc
= memcached_set(memc
, key
, strlen(key
),
2310 value
, current_length
,
2311 (time_t)0, (uint32_t)0);
2312 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
2314 string
= memcached_get(memc
, key
, strlen(key
),
2315 &string_length
, &flags
, &rc
);
2317 assert(rc
== MEMCACHED_SUCCESS
);
2318 assert(string_length
== current_length
);
2319 assert(!memcmp(string
, value
, string_length
));
2326 return TEST_SUCCESS
;
2330 Look for zero length value problems
2332 static test_return
user_supplied_bug15(memcached_st
*memc
)
2335 memcached_return rc
;
2336 const char *key
= "mykey";
2341 for (x
= 0; x
< 2; x
++)
2343 rc
= memcached_set(memc
, key
, strlen(key
),
2345 (time_t)0, (uint32_t)0);
2347 assert(rc
== MEMCACHED_SUCCESS
);
2349 value
= memcached_get(memc
, key
, strlen(key
),
2350 &length
, &flags
, &rc
);
2352 assert(rc
== MEMCACHED_SUCCESS
);
2353 assert(value
== NULL
);
2354 assert(length
== 0);
2357 value
= memcached_get(memc
, key
, strlen(key
),
2358 &length
, &flags
, &rc
);
2360 assert(rc
== MEMCACHED_SUCCESS
);
2361 assert(value
== NULL
);
2362 assert(length
== 0);
2366 return TEST_SUCCESS
;
2369 /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
2370 static test_return
user_supplied_bug16(memcached_st
*memc
)
2372 memcached_return rc
;
2373 const char *key
= "mykey";
2378 rc
= memcached_set(memc
, key
, strlen(key
),
2380 (time_t)0, UINT32_MAX
);
2382 assert(rc
== MEMCACHED_SUCCESS
);
2384 value
= memcached_get(memc
, key
, strlen(key
),
2385 &length
, &flags
, &rc
);
2387 assert(rc
== MEMCACHED_SUCCESS
);
2388 assert(value
== NULL
);
2389 assert(length
== 0);
2390 assert(flags
== UINT32_MAX
);
2392 return TEST_SUCCESS
;
2396 /* Check the validity of chinese key*/
2397 static test_return
user_supplied_bug17(memcached_st
*memc
)
2399 memcached_return rc
;
2400 const char *key
= "豆瓣";
2401 const char *value
="我们在炎热抑郁的夏天无法停止豆瓣";
2406 rc
= memcached_set(memc
, key
, strlen(key
),
2407 value
, strlen(value
),
2410 assert(rc
== MEMCACHED_SUCCESS
);
2412 value2
= memcached_get(memc
, key
, strlen(key
),
2413 &length
, &flags
, &rc
);
2415 assert(length
==strlen(value
));
2416 assert(rc
== MEMCACHED_SUCCESS
);
2417 assert(memcmp(value
, value2
, length
)==0);
2420 return TEST_SUCCESS
;
2428 static test_return
user_supplied_bug19(memcached_st
*memc
)
2431 memcached_server_st
*s
;
2432 memcached_return res
;
2436 m
= memcached_create(NULL
);
2437 memcached_server_add_with_weight(m
, "localhost", 11311, 100);
2438 memcached_server_add_with_weight(m
, "localhost", 11312, 100);
2440 s
= memcached_server_by_key(m
, "a", 1, &res
);
2441 memcached_server_free(s
);
2445 return TEST_SUCCESS
;
2448 /* CAS test from Andei */
2449 static test_return
user_supplied_bug20(memcached_st
*memc
)
2451 memcached_return status
;
2452 memcached_result_st
*result
, result_obj
;
2453 const char *key
= "abc";
2454 size_t key_len
= strlen("abc");
2455 const char *value
= "foobar";
2456 size_t value_len
= strlen(value
);
2458 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
2460 status
= memcached_set(memc
, key
, key_len
, value
, value_len
, (time_t)0, (uint32_t)0);
2461 assert(status
== MEMCACHED_SUCCESS
);
2463 status
= memcached_mget(memc
, &key
, &key_len
, 1);
2464 assert(status
== MEMCACHED_SUCCESS
);
2466 result
= memcached_result_create(memc
, &result_obj
);
2469 memcached_result_create(memc
, &result_obj
);
2470 result
= memcached_fetch_result(memc
, &result_obj
, &status
);
2473 assert(status
== MEMCACHED_SUCCESS
);
2475 memcached_result_free(result
);
2477 return TEST_SUCCESS
;
2480 #include "ketama_test_cases.h"
2481 static test_return
user_supplied_bug18(memcached_st
*trash
)
2483 memcached_return rc
;
2486 memcached_server_st
*server_pool
;
2491 memc
= memcached_create(NULL
);
2494 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2495 assert(rc
== MEMCACHED_SUCCESS
);
2497 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2500 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2501 assert(rc
== MEMCACHED_SUCCESS
);
2503 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2504 assert(value
== MEMCACHED_HASH_MD5
);
2506 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");
2507 memcached_server_push(memc
, server_pool
);
2509 /* verify that the server list was parsed okay. */
2510 assert(memc
->number_of_hosts
== 8);
2511 assert(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
2512 assert(server_pool
[0].port
== 11211);
2513 assert(server_pool
[0].weight
== 600);
2514 assert(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
2515 assert(server_pool
[2].port
== 11211);
2516 assert(server_pool
[2].weight
== 200);
2517 assert(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
2518 assert(server_pool
[7].port
== 11211);
2519 assert(server_pool
[7].weight
== 100);
2521 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
2522 * us test the boundary wraparound.
2524 assert(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
2526 /* verify the standard ketama set. */
2527 for (x
= 0; x
< 99; x
++)
2529 uint32_t server_idx
= memcached_generate_hash(memc
, test_cases
[x
].key
, strlen(test_cases
[x
].key
));
2530 char *hostname
= memc
->hosts
[server_idx
].hostname
;
2531 assert(strcmp(hostname
, test_cases
[x
].server
) == 0);
2534 memcached_server_list_free(server_pool
);
2535 memcached_free(memc
);
2537 return TEST_SUCCESS
;
2540 /* Large mget() of missing keys with binary proto
2542 * If many binary quiet commands (such as getq's in an mget) fill the output
2543 * buffer and the server chooses not to respond, memcached_flush hangs. See
2544 * http://lists.tangent.org/pipermail/libmemcached/2009-August/000918.html
2547 void fail(int); /* sighandler_t function that always asserts false */
2549 static test_return
_user_supplied_bug21(memcached_st
* memc
, size_t key_count
)
2551 memcached_return rc
;
2554 size_t* key_lengths
;
2555 void (*oldalarm
)(int);
2556 memcached_st
*memc_clone
;
2558 memc_clone
= memcached_clone(NULL
, memc
);
2561 /* only binproto uses getq for mget */
2562 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
2564 /* empty the cache to ensure misses (hence non-responses) */
2565 rc
= memcached_flush(memc_clone
, 0);
2566 assert(rc
== MEMCACHED_SUCCESS
);
2568 key_lengths
= calloc(key_count
, sizeof(size_t));
2569 keys
= calloc(key_count
, sizeof(char *));
2571 for (x
= 0; x
< key_count
; x
++)
2575 snprintf(buffer
, 30, "%u", x
);
2576 keys
[x
]= strdup(buffer
);
2577 key_lengths
[x
]= strlen(keys
[x
]);
2580 oldalarm
= signal(SIGALRM
, fail
);
2583 rc
= memcached_mget(memc_clone
, (const char **)keys
, key_lengths
, key_count
);
2584 assert(rc
== MEMCACHED_SUCCESS
);
2587 signal(SIGALRM
, oldalarm
);
2589 assert(fetch_all_results(memc
) == TEST_SUCCESS
);
2591 for (x
= 0; x
< key_count
; x
++)
2596 memcached_free(memc_clone
);
2598 return TEST_SUCCESS
;
2601 static test_return
user_supplied_bug21(memcached_st
*memc
)
2603 memcached_return rc
;
2605 /* should work as of r580 */
2606 rc
= _user_supplied_bug21(memc
, 10);
2607 assert(rc
== TEST_SUCCESS
);
2609 /* should fail as of r580 */
2610 rc
= _user_supplied_bug21(memc
, 1000);
2611 assert(rc
== TEST_SUCCESS
);
2613 return TEST_SUCCESS
;
2616 void fail(int unused
__attribute__((unused
)))
2621 static test_return
auto_eject_hosts(memcached_st
*trash
)
2625 memcached_return rc
;
2626 memcached_st
*memc
= memcached_create(NULL
);
2629 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2630 assert(rc
== MEMCACHED_SUCCESS
);
2632 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2635 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2636 assert(rc
== MEMCACHED_SUCCESS
);
2638 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2639 assert(value
== MEMCACHED_HASH_MD5
);
2641 /* server should be removed when in delay */
2642 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
, 1);
2643 assert(rc
== MEMCACHED_SUCCESS
);
2645 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
);
2648 memcached_server_st
*server_pool
;
2649 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");
2650 memcached_server_push(memc
, server_pool
);
2652 /* verify that the server list was parsed okay. */
2653 assert(memc
->number_of_hosts
== 8);
2654 assert(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
2655 assert(server_pool
[0].port
== 11211);
2656 assert(server_pool
[0].weight
== 600);
2657 assert(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
2658 assert(server_pool
[2].port
== 11211);
2659 assert(server_pool
[2].weight
== 200);
2660 assert(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
2661 assert(server_pool
[7].port
== 11211);
2662 assert(server_pool
[7].weight
== 100);
2664 memc
->hosts
[2].next_retry
= time(NULL
) + 15;
2665 memc
->next_distribution_rebuild
= time(NULL
) - 1;
2667 for (int x
= 0; x
< 99; x
++)
2669 uint32_t server_idx
= memcached_generate_hash(memc
, test_cases
[x
].key
, strlen(test_cases
[x
].key
));
2670 assert(server_idx
!= 2);
2673 /* and re-added when it's back. */
2674 memc
->hosts
[2].next_retry
= time(NULL
) - 1;
2675 memc
->next_distribution_rebuild
= time(NULL
) - 1;
2676 run_distribution(memc
);
2677 for (int x
= 0; x
< 99; x
++)
2679 uint32_t server_idx
= memcached_generate_hash(memc
, test_cases
[x
].key
, strlen(test_cases
[x
].key
));
2680 char *hostname
= memc
->hosts
[server_idx
].hostname
;
2681 assert(strcmp(hostname
, test_cases
[x
].server
) == 0);
2684 memcached_server_list_free(server_pool
);
2685 memcached_free(memc
);
2687 return TEST_SUCCESS
;
2690 static test_return
result_static(memcached_st
*memc
)
2692 memcached_result_st result
;
2693 memcached_result_st
*result_ptr
;
2695 result_ptr
= memcached_result_create(memc
, &result
);
2696 assert(result
.is_allocated
== false);
2698 memcached_result_free(&result
);
2700 return TEST_SUCCESS
;
2703 static test_return
result_alloc(memcached_st
*memc
)
2705 memcached_result_st
*result
;
2707 result
= memcached_result_create(memc
, NULL
);
2709 memcached_result_free(result
);
2711 return TEST_SUCCESS
;
2714 static test_return
string_static_null(memcached_st
*memc
)
2716 memcached_string_st string
;
2717 memcached_string_st
*string_ptr
;
2719 string_ptr
= memcached_string_create(memc
, &string
, 0);
2720 assert(string
.is_allocated
== false);
2722 memcached_string_free(&string
);
2724 return TEST_SUCCESS
;
2727 static test_return
string_alloc_null(memcached_st
*memc
)
2729 memcached_string_st
*string
;
2731 string
= memcached_string_create(memc
, NULL
, 0);
2733 memcached_string_free(string
);
2735 return TEST_SUCCESS
;
2738 static test_return
string_alloc_with_size(memcached_st
*memc
)
2740 memcached_string_st
*string
;
2742 string
= memcached_string_create(memc
, NULL
, 1024);
2744 memcached_string_free(string
);
2746 return TEST_SUCCESS
;
2749 static test_return
string_alloc_with_size_toobig(memcached_st
*memc
)
2751 memcached_string_st
*string
;
2753 string
= memcached_string_create(memc
, NULL
, SIZE_MAX
);
2754 assert(string
== NULL
);
2756 return TEST_SUCCESS
;
2759 static test_return
string_alloc_append(memcached_st
*memc
)
2762 char buffer
[SMALL_STRING_LEN
];
2763 memcached_string_st
*string
;
2765 /* Ring the bell! */
2766 memset(buffer
, 6, SMALL_STRING_LEN
);
2768 string
= memcached_string_create(memc
, NULL
, 100);
2771 for (x
= 0; x
< 1024; x
++)
2773 memcached_return rc
;
2774 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
2775 assert(rc
== MEMCACHED_SUCCESS
);
2777 memcached_string_free(string
);
2779 return TEST_SUCCESS
;
2782 static test_return
string_alloc_append_toobig(memcached_st
*memc
)
2784 memcached_return rc
;
2786 char buffer
[SMALL_STRING_LEN
];
2787 memcached_string_st
*string
;
2789 /* Ring the bell! */
2790 memset(buffer
, 6, SMALL_STRING_LEN
);
2792 string
= memcached_string_create(memc
, NULL
, 100);
2795 for (x
= 0; x
< 1024; x
++)
2797 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
2798 assert(rc
== MEMCACHED_SUCCESS
);
2800 rc
= memcached_string_append(string
, buffer
, SIZE_MAX
);
2801 assert(rc
== MEMCACHED_MEMORY_ALLOCATION_FAILURE
);
2802 memcached_string_free(string
);
2804 return TEST_SUCCESS
;
2807 static test_return
cleanup_pairs(memcached_st
*memc
__attribute__((unused
)))
2809 pairs_free(global_pairs
);
2811 return TEST_SUCCESS
;
2814 static test_return
generate_pairs(memcached_st
*memc
__attribute__((unused
)))
2816 unsigned long long x
;
2817 global_pairs
= pairs_generate(GLOBAL_COUNT
, 400);
2818 global_count
= GLOBAL_COUNT
;
2820 for (x
= 0; x
< global_count
; x
++)
2822 global_keys
[x
]= global_pairs
[x
].key
;
2823 global_keys_length
[x
]= global_pairs
[x
].key_length
;
2826 return TEST_SUCCESS
;
2829 static test_return
generate_large_pairs(memcached_st
*memc
__attribute__((unused
)))
2831 unsigned long long x
;
2832 global_pairs
= pairs_generate(GLOBAL2_COUNT
, MEMCACHED_MAX_BUFFER
+10);
2833 global_count
= GLOBAL2_COUNT
;
2835 for (x
= 0; x
< global_count
; x
++)
2837 global_keys
[x
]= global_pairs
[x
].key
;
2838 global_keys_length
[x
]= global_pairs
[x
].key_length
;
2841 return TEST_SUCCESS
;
2844 static test_return
generate_data(memcached_st
*memc
)
2846 execute_set(memc
, global_pairs
, global_count
);
2848 return TEST_SUCCESS
;
2851 static test_return
generate_data_with_stats(memcached_st
*memc
)
2853 memcached_stat_st
*stat_p
;
2854 memcached_return rc
;
2855 uint32_t host_index
= 0;
2856 execute_set(memc
, global_pairs
, global_count
);
2858 //TODO: hosts used size stats
2859 stat_p
= memcached_stat(memc
, NULL
, &rc
);
2862 for (host_index
= 0; host_index
< SERVERS_TO_CREATE
; host_index
++)
2864 /* This test was changes so that "make test" would work properlly */
2866 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
);
2868 assert((unsigned long long)(stat_p
+ host_index
)->bytes
);
2871 memcached_stat_free(NULL
, stat_p
);
2873 return TEST_SUCCESS
;
2875 static test_return
generate_buffer_data(memcached_st
*memc
)
2880 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
2881 generate_data(memc
);
2883 return TEST_SUCCESS
;
2886 static test_return
get_read_count(memcached_st
*memc
)
2889 memcached_return rc
;
2890 memcached_st
*memc_clone
;
2892 memc_clone
= memcached_clone(NULL
, memc
);
2895 memcached_server_add_with_weight(memc_clone
, "localhost", 6666, 0);
2899 size_t return_value_length
;
2903 for (x
= count
= 0; x
< global_count
; x
++)
2905 return_value
= memcached_get(memc_clone
, global_keys
[x
], global_keys_length
[x
],
2906 &return_value_length
, &flags
, &rc
);
2907 if (rc
== MEMCACHED_SUCCESS
)
2916 memcached_free(memc_clone
);
2918 return TEST_SUCCESS
;
2921 static test_return
get_read(memcached_st
*memc
)
2924 memcached_return rc
;
2928 size_t return_value_length
;
2931 for (x
= 0; x
< global_count
; x
++)
2933 return_value
= memcached_get(memc
, global_keys
[x
], global_keys_length
[x
],
2934 &return_value_length
, &flags
, &rc
);
2936 assert(return_value);
2937 assert(rc == MEMCACHED_SUCCESS);
2939 if (rc
== MEMCACHED_SUCCESS
&& return_value
)
2944 return TEST_SUCCESS
;
2947 static test_return
mget_read(memcached_st
*memc
)
2949 memcached_return rc
;
2951 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2952 assert(rc
== MEMCACHED_SUCCESS
);
2953 assert(fetch_all_results(memc
) == TEST_SUCCESS
);
2955 return TEST_SUCCESS
;
2958 static test_return
mget_read_result(memcached_st
*memc
)
2960 memcached_return rc
;
2962 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2963 assert(rc
== MEMCACHED_SUCCESS
);
2964 /* Turn this into a help function */
2966 memcached_result_st results_obj
;
2967 memcached_result_st
*results
;
2969 results
= memcached_result_create(memc
, &results_obj
);
2971 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
2974 assert(rc
== MEMCACHED_SUCCESS
);
2977 memcached_result_free(&results_obj
);
2980 return TEST_SUCCESS
;
2983 static test_return
mget_read_function(memcached_st
*memc
)
2985 memcached_return rc
;
2986 unsigned int counter
;
2987 memcached_execute_function callbacks
[1];
2989 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2990 assert(rc
== MEMCACHED_SUCCESS
);
2992 callbacks
[0]= &callback_counter
;
2994 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
2996 return TEST_SUCCESS
;
2999 static test_return
delete_generate(memcached_st
*memc
)
3003 for (x
= 0; x
< global_count
; x
++)
3005 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3008 return TEST_SUCCESS
;
3011 static test_return
delete_buffer_generate(memcached_st
*memc
)
3017 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
3019 for (x
= 0; x
< global_count
; x
++)
3021 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3024 return TEST_SUCCESS
;
3027 static test_return
add_host_test1(memcached_st
*memc
)
3030 memcached_return rc
;
3031 char servername
[]= "0.example.com";
3032 memcached_server_st
*servers
;
3034 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
3036 assert(1 == memcached_server_list_count(servers
));
3038 for (x
= 2; x
< 20; x
++)
3040 char buffer
[SMALL_STRING_LEN
];
3042 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
3043 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
3045 assert(rc
== MEMCACHED_SUCCESS
);
3046 assert(x
== memcached_server_list_count(servers
));
3049 rc
= memcached_server_push(memc
, servers
);
3050 assert(rc
== MEMCACHED_SUCCESS
);
3051 rc
= memcached_server_push(memc
, servers
);
3052 assert(rc
== MEMCACHED_SUCCESS
);
3054 memcached_server_list_free(servers
);
3056 return TEST_SUCCESS
;
3059 static memcached_return
pre_nonblock(memcached_st
*memc
)
3061 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3063 return MEMCACHED_SUCCESS
;
3066 static memcached_return
pre_nonblock_binary(memcached_st
*memc
)
3068 memcached_return rc
= MEMCACHED_FAILURE
;
3069 memcached_st
*memc_clone
;
3071 memc_clone
= memcached_clone(NULL
, memc
);
3073 // The memcached_version needs to be done on a clone, because the server
3074 // will not toggle protocol on an connection.
3075 memcached_version(memc_clone
);
3077 if (memc_clone
->hosts
[0].major_version
>= 1 && memc_clone
->hosts
[0].minor_version
> 2)
3079 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3080 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3081 assert(rc
== MEMCACHED_SUCCESS
);
3082 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3085 memcached_free(memc_clone
);
3089 static memcached_return
pre_murmur(memcached_st
*memc
)
3091 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
3093 return MEMCACHED_SUCCESS
;
3096 static memcached_return
pre_jenkins(memcached_st
*memc
)
3098 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_JENKINS
);
3100 return MEMCACHED_SUCCESS
;
3104 static memcached_return
pre_md5(memcached_st
*memc
)
3106 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MD5
);
3108 return MEMCACHED_SUCCESS
;
3111 static memcached_return
pre_crc(memcached_st
*memc
)
3113 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_CRC
);
3115 return MEMCACHED_SUCCESS
;
3118 static memcached_return
pre_hsieh(memcached_st
*memc
)
3120 #ifdef HAVE_HSIEH_HASH
3121 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_HSIEH
);
3122 return MEMCACHED_SUCCESS
;
3125 return MEMCACHED_FAILURE
;
3129 static memcached_return
pre_hash_fnv1_64(memcached_st
*memc
)
3131 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_64
);
3133 return MEMCACHED_SUCCESS
;
3136 static memcached_return
pre_hash_fnv1a_64(memcached_st
*memc
)
3138 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_64
);
3140 return MEMCACHED_SUCCESS
;
3143 static memcached_return
pre_hash_fnv1_32(memcached_st
*memc
)
3145 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_32
);
3147 return MEMCACHED_SUCCESS
;
3150 static memcached_return
pre_hash_fnv1a_32(memcached_st
*memc
)
3152 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_32
);
3154 return MEMCACHED_SUCCESS
;
3157 static memcached_return
pre_behavior_ketama(memcached_st
*memc
)
3159 memcached_return rc
;
3162 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA
, 1);
3163 assert(rc
== MEMCACHED_SUCCESS
);
3165 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA
);
3168 return MEMCACHED_SUCCESS
;
3171 static memcached_return
pre_behavior_ketama_weighted(memcached_st
*memc
)
3173 memcached_return rc
;
3176 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
3177 assert(rc
== MEMCACHED_SUCCESS
);
3179 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
3182 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
3183 assert(rc
== MEMCACHED_SUCCESS
);
3185 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
3186 assert(value
== MEMCACHED_HASH_MD5
);
3187 return MEMCACHED_SUCCESS
;
3190 static memcached_return
pre_binary(memcached_st
*memc
)
3192 memcached_return rc
= MEMCACHED_FAILURE
;
3193 memcached_st
*memc_clone
;
3195 memc_clone
= memcached_clone(NULL
, memc
);
3197 // The memcached_version needs to be done on a clone, because the server
3198 // will not toggle protocol on an connection.
3199 memcached_version(memc_clone
);
3201 if (memc_clone
->hosts
[0].major_version
>= 1 && memc_clone
->hosts
[0].minor_version
> 2)
3203 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3204 assert(rc
== MEMCACHED_SUCCESS
);
3205 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3208 memcached_free(memc_clone
);
3212 static memcached_return
pre_replication(memcached_st
*memc
)
3214 memcached_return rc
= MEMCACHED_FAILURE
;
3215 if (pre_binary(memc
) == MEMCACHED_SUCCESS
)
3218 * Make sure that we store the item on all servers
3219 * (master + replicas == number of servers)
3221 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
,
3222 memc
->number_of_hosts
- 1);
3223 assert(rc
== MEMCACHED_SUCCESS
);
3224 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
) == memc
->number_of_hosts
- 1);
3230 static memcached_return
pre_replication_noblock(memcached_st
*memc
)
3232 memcached_return rc
= MEMCACHED_FAILURE
;
3233 if (pre_replication(memc
) == MEMCACHED_SUCCESS
&&
3234 pre_nonblock(memc
) == MEMCACHED_SUCCESS
)
3235 rc
= MEMCACHED_SUCCESS
;
3240 static void my_free(memcached_st
*ptr
__attribute__((unused
)), void *mem
)
3245 static void *my_malloc(memcached_st
*ptr
__attribute__((unused
)), const size_t size
)
3247 void *ret
= malloc(size
);
3249 memset(ret
, 0xff, size
);
3254 static void *my_realloc(memcached_st
*ptr
__attribute__((unused
)), void *mem
, const size_t size
)
3256 return realloc(mem
, size
);
3259 static void *my_calloc(memcached_st
*ptr
__attribute__((unused
)), size_t nelem
, const size_t size
)
3261 return calloc(nelem
, size
);
3264 static memcached_return
set_prefix(memcached_st
*memc
)
3266 memcached_return rc
;
3267 const char *key
= "mine";
3270 /* Make sure be default none exists */
3271 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3272 assert(rc
== MEMCACHED_FAILURE
);
3274 /* Test a clean set */
3275 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3276 assert(rc
== MEMCACHED_SUCCESS
);
3278 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3279 assert(memcmp(value
, key
, 4) == 0);
3280 assert(rc
== MEMCACHED_SUCCESS
);
3282 /* Test that we can turn it off */
3283 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3284 assert(rc
== MEMCACHED_SUCCESS
);
3286 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3287 assert(rc
== MEMCACHED_FAILURE
);
3289 /* Now setup for main test */
3290 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3291 assert(rc
== MEMCACHED_SUCCESS
);
3293 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3294 assert(rc
== MEMCACHED_SUCCESS
);
3295 assert(memcmp(value
, key
, 4) == 0);
3297 /* Set to Zero, and then Set to something too large */
3300 memset(long_key
, 0, 255);
3302 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3303 assert(rc
== MEMCACHED_SUCCESS
);
3305 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3306 assert(rc
== MEMCACHED_FAILURE
);
3307 assert(value
== NULL
);
3309 /* Test a long key for failure */
3310 /* TODO, extend test to determine based on setting, what result should be */
3311 strcpy(long_key
, "Thisismorethentheallottednumberofcharacters");
3312 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3313 //assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
3314 assert(rc
== MEMCACHED_SUCCESS
);
3316 /* Now test a key with spaces (which will fail from long key, since bad key is not set) */
3317 strcpy(long_key
, "This is more then the allotted number of characters");
3318 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3319 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3321 /* Test for a bad prefix, but with a short key */
3322 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, 1);
3323 assert(rc
== MEMCACHED_SUCCESS
);
3325 strcpy(long_key
, "dog cat");
3326 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3327 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3330 return MEMCACHED_SUCCESS
;
3333 #ifdef MEMCACHED_ENABLE_DEPRECATED
3334 static memcached_return
deprecated_set_memory_alloc(memcached_st
*memc
)
3336 void *test_ptr
= NULL
;
3339 memcached_malloc_function malloc_cb
=
3340 (memcached_malloc_function
)my_malloc
;
3341 cb_ptr
= *(void **)&malloc_cb
;
3342 memcached_return rc
;
3344 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, cb_ptr
);
3345 assert(rc
== MEMCACHED_SUCCESS
);
3346 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
3347 assert(rc
== MEMCACHED_SUCCESS
);
3348 assert(test_ptr
== cb_ptr
);
3352 memcached_realloc_function realloc_cb
=
3353 (memcached_realloc_function
)my_realloc
;
3354 cb_ptr
= *(void **)&realloc_cb
;
3355 memcached_return rc
;
3357 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, cb_ptr
);
3358 assert(rc
== MEMCACHED_SUCCESS
);
3359 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
3360 assert(rc
== MEMCACHED_SUCCESS
);
3361 assert(test_ptr
== cb_ptr
);
3365 memcached_free_function free_cb
=
3366 (memcached_free_function
)my_free
;
3367 cb_ptr
= *(void **)&free_cb
;
3368 memcached_return rc
;
3370 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, cb_ptr
);
3371 assert(rc
== MEMCACHED_SUCCESS
);
3372 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
3373 assert(rc
== MEMCACHED_SUCCESS
);
3374 assert(test_ptr
== cb_ptr
);
3376 return MEMCACHED_SUCCESS
;
3380 static memcached_return
set_memory_alloc(memcached_st
*memc
)
3382 memcached_return rc
;
3383 rc
= memcached_set_memory_allocators(memc
, NULL
, my_free
,
3384 my_realloc
, my_calloc
);
3385 assert(rc
== MEMCACHED_FAILURE
);
3387 rc
= memcached_set_memory_allocators(memc
, my_malloc
, my_free
,
3388 my_realloc
, my_calloc
);
3390 memcached_malloc_function mem_malloc
;
3391 memcached_free_function mem_free
;
3392 memcached_realloc_function mem_realloc
;
3393 memcached_calloc_function mem_calloc
;
3394 memcached_get_memory_allocators(memc
, &mem_malloc
, &mem_free
,
3395 &mem_realloc
, &mem_calloc
);
3397 assert(mem_malloc
== my_malloc
);
3398 assert(mem_realloc
== my_realloc
);
3399 assert(mem_calloc
== my_calloc
);
3400 assert(mem_free
== my_free
);
3402 return MEMCACHED_SUCCESS
;
3405 static memcached_return
enable_consistent(memcached_st
*memc
)
3407 memcached_server_distribution value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
3408 memcached_hash hash
;
3409 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
3410 if (pre_hsieh(memc
) != MEMCACHED_SUCCESS
)
3411 return MEMCACHED_FAILURE
;
3413 value
= (memcached_server_distribution
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
3414 assert(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
3416 hash
= (memcached_hash
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
3417 assert(hash
== MEMCACHED_HASH_HSIEH
);
3420 return MEMCACHED_SUCCESS
;
3423 static memcached_return
enable_cas(memcached_st
*memc
)
3425 unsigned int set
= 1;
3427 memcached_version(memc
);
3429 if ((memc
->hosts
[0].major_version
>= 1 && (memc
->hosts
[0].minor_version
== 2 && memc
->hosts
[0].micro_version
>= 4))
3430 || memc
->hosts
[0].minor_version
> 2)
3432 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
3434 return MEMCACHED_SUCCESS
;
3437 return MEMCACHED_FAILURE
;
3440 static memcached_return
check_for_1_2_3(memcached_st
*memc
)
3442 memcached_version(memc
);
3444 if ((memc
->hosts
[0].major_version
>= 1 && (memc
->hosts
[0].minor_version
== 2 && memc
->hosts
[0].micro_version
>= 4))
3445 || memc
->hosts
[0].minor_version
> 2)
3446 return MEMCACHED_SUCCESS
;
3448 return MEMCACHED_FAILURE
;
3451 static memcached_return
pre_unix_socket(memcached_st
*memc
)
3453 memcached_return rc
;
3456 memcached_server_list_free(memc
->hosts
);
3458 memc
->number_of_hosts
= 0;
3460 if (stat("/tmp/memcached.socket", &buf
))
3461 return MEMCACHED_FAILURE
;
3463 rc
= memcached_server_add_unix_socket_with_weight(memc
, "/tmp/memcached.socket", 0);
3468 static memcached_return
pre_nodelay(memcached_st
*memc
)
3470 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3471 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
3473 return MEMCACHED_SUCCESS
;
3476 static memcached_return
pre_settimer(memcached_st
*memc
)
3478 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
3479 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
3481 return MEMCACHED_SUCCESS
;
3484 static memcached_return
poll_timeout(memcached_st
*memc
)
3490 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
3492 timeout
= (size_t)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
3494 assert(timeout
== 100);
3496 return MEMCACHED_SUCCESS
;
3499 static test_return
noreply_test(memcached_st
*memc
)
3501 memcached_return ret
;
3502 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
3503 assert(ret
== MEMCACHED_SUCCESS
);
3504 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
3505 assert(ret
== MEMCACHED_SUCCESS
);
3506 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
3507 assert(ret
== MEMCACHED_SUCCESS
);
3508 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NOREPLY
) == 1);
3509 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
) == 1);
3510 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
) == 1);
3512 for (int count
=0; count
< 5; ++count
)
3514 for (int x
=0; x
< 100; ++x
)
3517 size_t len
= (size_t)sprintf(key
, "%d", x
);
3521 ret
=memcached_add(memc
, key
, len
, key
, len
, 0, 0);
3524 ret
=memcached_replace(memc
, key
, len
, key
, len
, 0, 0);
3527 ret
=memcached_set(memc
, key
, len
, key
, len
, 0, 0);
3530 ret
=memcached_append(memc
, key
, len
, key
, len
, 0, 0);
3533 ret
=memcached_prepend(memc
, key
, len
, key
, len
, 0, 0);
3539 assert(ret
== MEMCACHED_SUCCESS
|| ret
== MEMCACHED_BUFFERED
);
3543 ** NOTE: Don't ever do this in your code! this is not a supported use of the
3544 ** API and is _ONLY_ done this way to verify that the library works the
3545 ** way it is supposed to do!!!!
3548 for (uint32_t x
=0; x
< memc
->number_of_hosts
; ++x
)
3549 no_msg
+=(int)(memc
->hosts
[x
].cursor_active
);
3551 assert(no_msg
== 0);
3552 assert(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
3555 ** Now validate that all items was set properly!
3557 for (int x
=0; x
< 100; ++x
)
3560 size_t len
= (size_t)sprintf(key
, "%d", x
);
3563 char* value
=memcached_get(memc
, key
, strlen(key
),
3564 &length
, &flags
, &ret
);
3565 assert(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
3568 case 0: /* FALLTHROUGH */
3569 case 1: /* FALLTHROUGH */
3571 assert(strncmp(value
, key
, len
) == 0);
3572 assert(len
== length
);
3575 assert(length
== len
* 2);
3578 assert(length
== len
* 3);
3588 /* Try setting an illegal cas value (should not return an error to
3589 * the caller (because we don't expect a return message from the server)
3591 const char* keys
[]= {"0"};
3592 size_t lengths
[]= {1};
3595 memcached_result_st results_obj
;
3596 memcached_result_st
*results
;
3597 ret
= memcached_mget(memc
, keys
, lengths
, 1);
3598 assert(ret
== MEMCACHED_SUCCESS
);
3600 results
= memcached_result_create(memc
, &results_obj
);
3602 results
= memcached_fetch_result(memc
, &results_obj
, &ret
);
3604 assert(ret
== MEMCACHED_SUCCESS
);
3605 uint64_t cas
= memcached_result_cas(results
);
3606 memcached_result_free(&results_obj
);
3608 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
3609 assert(ret
== MEMCACHED_SUCCESS
);
3612 * The item will have a new cas value, so try to set it again with the old
3613 * value. This should fail!
3615 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
3616 assert(ret
== MEMCACHED_SUCCESS
);
3617 assert(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
3618 char* value
=memcached_get(memc
, keys
[0], lengths
[0], &length
, &flags
, &ret
);
3619 assert(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
3622 return TEST_SUCCESS
;
3625 static test_return
analyzer_test(memcached_st
*memc
)
3627 memcached_return rc
;
3628 memcached_stat_st
*memc_stat
;
3629 memcached_analysis_st
*report
;
3631 memc_stat
= memcached_stat(memc
, NULL
, &rc
);
3632 assert(rc
== MEMCACHED_SUCCESS
);
3635 report
= memcached_analyze(memc
, memc_stat
, &rc
);
3636 assert(rc
== MEMCACHED_SUCCESS
);
3640 memcached_stat_free(NULL
, memc_stat
);
3642 return TEST_SUCCESS
;
3645 /* Count the objects */
3646 static memcached_return
callback_dump_counter(memcached_st
*ptr
__attribute__((unused
)),
3647 const char *key
__attribute__((unused
)),
3648 size_t key_length
__attribute__((unused
)),
3651 uint32_t *counter
= (uint32_t *)context
;
3653 *counter
= *counter
+ 1;
3655 return MEMCACHED_SUCCESS
;
3658 static test_return
dump_test(memcached_st
*memc
)
3660 memcached_return rc
;
3661 uint32_t counter
= 0;
3662 memcached_dump_func callbacks
[1];
3663 test_return main_rc
;
3665 callbacks
[0]= &callback_dump_counter
;
3667 /* No support for Binary protocol yet */
3668 if (memc
->flags
& MEM_BINARY_PROTOCOL
)
3669 return TEST_SUCCESS
;
3671 main_rc
= set_test3(memc
);
3673 assert (main_rc
== TEST_SUCCESS
);
3675 rc
= memcached_dump(memc
, callbacks
, (void *)&counter
, 1);
3676 assert(rc
== MEMCACHED_SUCCESS
);
3678 /* We may have more then 32 if our previous flush has not completed */
3679 assert(counter
>= 32);
3681 return TEST_SUCCESS
;
3684 #ifdef HAVE_LIBMEMCACHEDUTIL
3685 static void* connection_release(void *arg
) {
3687 memcached_pool_st
* pool
;
3692 assert(memcached_pool_push(resource
->pool
, resource
->mmc
) == MEMCACHED_SUCCESS
);
3696 static test_return
connection_pool_test(memcached_st
*memc
)
3698 memcached_pool_st
* pool
= memcached_pool_create(memc
, 5, 10);
3699 assert(pool
!= NULL
);
3700 memcached_st
* mmc
[10];
3701 memcached_return rc
;
3703 for (int x
= 0; x
< 10; ++x
) {
3704 mmc
[x
]= memcached_pool_pop(pool
, false, &rc
);
3705 assert(mmc
[x
] != NULL
);
3706 assert(rc
== MEMCACHED_SUCCESS
);
3709 assert(memcached_pool_pop(pool
, false, &rc
) == NULL
);
3710 assert(rc
== MEMCACHED_SUCCESS
);
3714 memcached_pool_st
* pool
;
3716 } item
= { .pool
= pool
, .mmc
= mmc
[9] };
3717 pthread_create(&tid
, NULL
, connection_release
, &item
);
3718 mmc
[9]= memcached_pool_pop(pool
, true, &rc
);
3719 assert(rc
== MEMCACHED_SUCCESS
);
3720 pthread_join(tid
, NULL
);
3721 assert(mmc
[9] == item
.mmc
);
3722 const char *key
= "key";
3723 size_t keylen
= strlen(key
);
3725 // verify that I can do ops with all connections
3726 rc
= memcached_set(mmc
[0], key
, keylen
, "0", 1, 0, 0);
3727 assert(rc
== MEMCACHED_SUCCESS
);
3729 for (unsigned int x
= 0; x
< 10; ++x
) {
3730 uint64_t number_value
;
3731 rc
= memcached_increment(mmc
[x
], key
, keylen
, 1, &number_value
);
3732 assert(rc
== MEMCACHED_SUCCESS
);
3733 assert(number_value
== (x
+1));
3737 for (int x
= 0; x
< 10; ++x
)
3738 assert(memcached_pool_push(pool
, mmc
[x
]) == MEMCACHED_SUCCESS
);
3741 /* verify that I can set behaviors on the pool when I don't have all
3742 * of the connections in the pool. It should however be enabled
3743 * when I push the item into the pool
3745 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
3746 assert(mmc
[0] != NULL
);
3748 rc
= memcached_pool_behavior_set(pool
, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
, 9999);
3749 assert(rc
== MEMCACHED_SUCCESS
);
3751 mmc
[1]= memcached_pool_pop(pool
, false, &rc
);
3752 assert(mmc
[1] != NULL
);
3754 assert(memcached_behavior_get(mmc
[1], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
) == 9999);
3755 assert(memcached_pool_push(pool
, mmc
[1]) == MEMCACHED_SUCCESS
);
3756 assert(memcached_pool_push(pool
, mmc
[0]) == MEMCACHED_SUCCESS
);
3758 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
3759 assert(memcached_behavior_get(mmc
[0], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
) == 9999);
3760 assert(memcached_pool_push(pool
, mmc
[0]) == MEMCACHED_SUCCESS
);
3763 assert(memcached_pool_destroy(pool
) == memc
);
3764 return TEST_SUCCESS
;
3768 static test_return
replication_set_test(memcached_st
*memc
)
3770 memcached_return rc
;
3771 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
3772 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 0);
3774 rc
= memcached_set(memc
, "bubba", 5, "0", 1, 0, 0);
3775 assert(rc
== MEMCACHED_SUCCESS
);
3778 ** We are using the quiet commands to store the replicas, so we need
3779 ** to ensure that all of them are processed before we can continue.
3780 ** In the test we go directly from storing the object to trying to
3781 ** receive the object from all of the different servers, so we
3782 ** could end up in a race condition (the memcached server hasn't yet
3783 ** processed the quiet command from the replication set when it process
3784 ** the request from the other client (created by the clone)). As a
3785 ** workaround for that we call memcached_quit to send the quit command
3786 ** to the server and wait for the response ;-) If you use the test code
3787 ** as an example for your own code, please note that you shouldn't need
3790 memcached_quit(memc
);
3793 ** "bubba" should now be stored on all of our servers. We don't have an
3794 ** easy to use API to address each individual server, so I'll just iterate
3795 ** through a bunch of "master keys" and I should most likely hit all of the
3798 for (int x
= 'a'; x
<= 'z'; ++x
)
3800 char key
[2]= { [0]= (char)x
};
3803 char *val
= memcached_get_by_key(memc_clone
, key
, 1, "bubba", 5,
3805 assert(rc
== MEMCACHED_SUCCESS
);
3806 assert(val
!= NULL
);
3810 memcached_free(memc_clone
);
3812 return TEST_SUCCESS
;
3815 static test_return
replication_get_test(memcached_st
*memc
)
3817 memcached_return rc
;
3820 * Don't do the following in your code. I am abusing the internal details
3821 * within the library, and this is not a supported interface.
3822 * This is to verify correct behavior in the library
3824 for (uint32_t host
= 0; host
< memc
->number_of_hosts
; ++host
)
3826 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
3827 memc_clone
->hosts
[host
].port
= 0;
3829 for (int x
= 'a'; x
<= 'z'; ++x
)
3831 char key
[2]= { [0]= (char)x
};
3834 char *val
= memcached_get_by_key(memc_clone
, key
, 1, "bubba", 5,
3836 assert(rc
== MEMCACHED_SUCCESS
);
3837 assert(val
!= NULL
);
3841 memcached_free(memc_clone
);
3844 return TEST_SUCCESS
;
3847 static test_return
replication_mget_test(memcached_st
*memc
)
3849 memcached_return rc
;
3850 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
3851 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 0);
3853 const char *keys
[]= { "bubba", "key1", "key2", "key3" };
3854 size_t len
[]= { 5, 4, 4, 4 };
3856 for (int x
=0; x
< 4; ++x
)
3858 rc
= memcached_set(memc
, keys
[x
], len
[x
], "0", 1, 0, 0);
3859 assert(rc
== MEMCACHED_SUCCESS
);
3863 ** We are using the quiet commands to store the replicas, so we need
3864 ** to ensure that all of them are processed before we can continue.
3865 ** In the test we go directly from storing the object to trying to
3866 ** receive the object from all of the different servers, so we
3867 ** could end up in a race condition (the memcached server hasn't yet
3868 ** processed the quiet command from the replication set when it process
3869 ** the request from the other client (created by the clone)). As a
3870 ** workaround for that we call memcached_quit to send the quit command
3871 ** to the server and wait for the response ;-) If you use the test code
3872 ** as an example for your own code, please note that you shouldn't need
3875 memcached_quit(memc
);
3878 * Don't do the following in your code. I am abusing the internal details
3879 * within the library, and this is not a supported interface.
3880 * This is to verify correct behavior in the library
3882 memcached_result_st result_obj
;
3883 for (uint32_t host
= 0; host
< memc_clone
->number_of_hosts
; host
++)
3885 memcached_st
*new_clone
= memcached_clone(NULL
, memc
);
3886 new_clone
->hosts
[host
].port
= 0;
3888 for (int x
= 'a'; x
<= 'z'; ++x
)
3890 const char key
[2]= { [0]= (const char)x
};
3892 rc
= memcached_mget_by_key(new_clone
, key
, 1, keys
, len
, 4);
3893 assert(rc
== MEMCACHED_SUCCESS
);
3895 memcached_result_st
*results
= memcached_result_create(new_clone
, &result_obj
);
3899 while ((results
= memcached_fetch_result(new_clone
, &result_obj
, &rc
)) != NULL
)
3904 memcached_result_free(&result_obj
);
3907 memcached_free(new_clone
);
3910 memcached_free(memc_clone
);
3912 return TEST_SUCCESS
;
3915 static test_return
replication_delete_test(memcached_st
*memc
)
3917 memcached_return rc
;
3918 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
3919 /* Delete the items from all of the servers except 1 */
3920 uint64_t repl
= memcached_behavior_get(memc
,
3921 MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
);
3922 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, --repl
);
3924 const char *keys
[]= { "bubba", "key1", "key2", "key3" };
3925 size_t len
[]= { 5, 4, 4, 4 };
3927 for (int x
=0; x
< 4; ++x
)
3929 rc
= memcached_delete_by_key(memc
, keys
[0], len
[0], keys
[x
], len
[x
], 0);
3930 assert(rc
== MEMCACHED_SUCCESS
);
3934 * Don't do the following in your code. I am abusing the internal details
3935 * within the library, and this is not a supported interface.
3936 * This is to verify correct behavior in the library
3938 uint32_t hash
= memcached_generate_hash(memc
, keys
[0], len
[0]);
3939 for (uint32_t x
= 0; x
< (repl
+ 1); ++x
)
3941 memc_clone
->hosts
[hash
].port
= 0;
3942 if (++hash
== memc_clone
->number_of_hosts
)
3946 memcached_result_st result_obj
;
3947 for (uint32_t host
= 0; host
< memc_clone
->number_of_hosts
; ++host
)
3949 for (int x
= 'a'; x
<= 'z'; ++x
)
3951 const char key
[2]= { [0]= (const char)x
};
3953 rc
= memcached_mget_by_key(memc_clone
, key
, 1, keys
, len
, 4);
3954 assert(rc
== MEMCACHED_SUCCESS
);
3956 memcached_result_st
*results
= memcached_result_create(memc_clone
, &result_obj
);
3960 while ((results
= memcached_fetch_result(memc_clone
, &result_obj
, &rc
)) != NULL
)
3965 memcached_result_free(&result_obj
);
3968 memcached_free(memc_clone
);
3970 return TEST_SUCCESS
;
3973 static void increment_request_id(uint16_t *id
)
3976 if ((*id
& UDP_REQUEST_ID_THREAD_MASK
) != 0)
3980 static uint16_t *get_udp_request_ids(memcached_st
*memc
)
3982 uint16_t *ids
= malloc(sizeof(uint16_t) * memc
->number_of_hosts
);
3983 assert(ids
!= NULL
);
3986 for (x
= 0; x
< memc
->number_of_hosts
; x
++)
3987 ids
[x
]= get_udp_datagram_request_id((struct udp_datagram_header_st
*) memc
->hosts
[x
].write_buffer
);
3992 static test_return
post_udp_op_check(memcached_st
*memc
, uint16_t *expected_req_ids
)
3995 memcached_server_st
*cur_server
= memc
->hosts
;
3996 uint16_t *cur_req_ids
= get_udp_request_ids(memc
);
3998 for (x
= 0; x
< memc
->number_of_hosts
; x
++)
4000 assert(cur_server
[x
].cursor_active
== 0);
4001 assert(cur_req_ids
[x
] == expected_req_ids
[x
]);
4003 free(expected_req_ids
);
4006 return TEST_SUCCESS
;
4010 ** There is a little bit of a hack here, instead of removing
4011 ** the servers, I just set num host to 0 and them add then new udp servers
4013 static memcached_return
init_udp(memcached_st
*memc
)
4015 memcached_version(memc
);
4016 /* For the time being, only support udp test for >= 1.2.6 && < 1.3 */
4017 if (memc
->hosts
[0].major_version
!= 1 || memc
->hosts
[0].minor_version
!= 2
4018 || memc
->hosts
[0].micro_version
< 6)
4019 return MEMCACHED_FAILURE
;
4021 uint32_t num_hosts
= memc
->number_of_hosts
;
4023 memcached_server_st servers
[num_hosts
];
4024 memcpy(servers
, memc
->hosts
, sizeof(memcached_server_st
) * num_hosts
);
4025 for (x
= 0; x
< num_hosts
; x
++)
4026 memcached_server_free(&memc
->hosts
[x
]);
4028 memc
->number_of_hosts
= 0;
4029 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
, 1);
4030 for (x
= 0; x
< num_hosts
; x
++)
4032 assert(memcached_server_add_udp(memc
, servers
[x
].hostname
, servers
[x
].port
) == MEMCACHED_SUCCESS
);
4033 assert(memc
->hosts
[x
].write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4036 return MEMCACHED_SUCCESS
;
4039 static memcached_return
binary_init_udp(memcached_st
*memc
)
4042 return init_udp(memc
);
4045 /* Make sure that I cant add a tcp server to a udp client */
4046 static test_return
add_tcp_server_udp_client_test(memcached_st
*memc
)
4048 memcached_server_st server
;
4049 memcached_server_clone(&server
, &memc
->hosts
[0]);
4050 assert(memcached_server_remove(&(memc
->hosts
[0])) == MEMCACHED_SUCCESS
);
4051 assert(memcached_server_add(memc
, server
.hostname
, server
.port
) == MEMCACHED_INVALID_HOST_PROTOCOL
);
4052 return TEST_SUCCESS
;
4055 /* Make sure that I cant add a udp server to a tcp client */
4056 static test_return
add_udp_server_tcp_client_test(memcached_st
*memc
)
4058 memcached_server_st server
;
4059 memcached_server_clone(&server
, &memc
->hosts
[0]);
4060 assert(memcached_server_remove(&(memc
->hosts
[0])) == MEMCACHED_SUCCESS
);
4062 memcached_st tcp_client
;
4063 memcached_create(&tcp_client
);
4064 assert(memcached_server_add_udp(&tcp_client
, server
.hostname
, server
.port
) == MEMCACHED_INVALID_HOST_PROTOCOL
);
4065 return TEST_SUCCESS
;
4068 static test_return
set_udp_behavior_test(memcached_st
*memc
)
4071 memcached_quit(memc
);
4072 memc
->number_of_hosts
= 0;
4073 run_distribution(memc
);
4074 assert(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
, 1) == MEMCACHED_SUCCESS
);
4075 assert(memc
->flags
& MEM_USE_UDP
);
4076 assert(memc
->flags
& MEM_NOREPLY
);;
4078 assert(memc
->number_of_hosts
== 0);
4080 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
,0);
4081 assert(!(memc
->flags
& MEM_USE_UDP
));
4082 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
,0);
4083 assert(!(memc
->flags
& MEM_NOREPLY
));
4084 return TEST_SUCCESS
;
4087 static test_return
udp_set_test(memcached_st
*memc
)
4090 unsigned int num_iters
= 1025; //request id rolls over at 1024
4091 for (x
= 0; x
< num_iters
;x
++)
4093 memcached_return rc
;
4094 const char *key
= "foo";
4095 const char *value
= "when we sanitize";
4096 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4097 unsigned int server_key
= memcached_generate_hash(memc
,key
,strlen(key
));
4098 size_t init_offset
= memc
->hosts
[server_key
].write_buffer_offset
;
4099 rc
= memcached_set(memc
, key
, strlen(key
),
4100 value
, strlen(value
),
4101 (time_t)0, (uint32_t)0);
4102 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4103 /** NB, the check below assumes that if new write_ptr is less than
4104 * the original write_ptr that we have flushed. For large payloads, this
4105 * maybe an invalid assumption, but for the small payload we have it is OK
4107 if (rc
== MEMCACHED_SUCCESS
||
4108 memc
->hosts
[server_key
].write_buffer_offset
< init_offset
)
4109 increment_request_id(&expected_ids
[server_key
]);
4111 if (rc
== MEMCACHED_SUCCESS
)
4113 assert(memc
->hosts
[server_key
].write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4117 assert(memc
->hosts
[server_key
].write_buffer_offset
!= UDP_DATAGRAM_HEADER_LENGTH
);
4118 assert(memc
->hosts
[server_key
].write_buffer_offset
<= MAX_UDP_DATAGRAM_LENGTH
);
4120 assert(post_udp_op_check(memc
,expected_ids
) == TEST_SUCCESS
);
4122 return TEST_SUCCESS
;
4125 static test_return
udp_buffered_set_test(memcached_st
*memc
)
4127 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4128 return udp_set_test(memc
);
4131 static test_return
udp_set_too_big_test(memcached_st
*memc
)
4133 memcached_return rc
;
4134 const char *key
= "bar";
4135 char value
[MAX_UDP_DATAGRAM_LENGTH
];
4136 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4137 rc
= memcached_set(memc
, key
, strlen(key
),
4138 value
, MAX_UDP_DATAGRAM_LENGTH
,
4139 (time_t)0, (uint32_t)0);
4140 assert(rc
== MEMCACHED_WRITE_FAILURE
);
4141 return post_udp_op_check(memc
,expected_ids
);
4144 static test_return
udp_delete_test(memcached_st
*memc
)
4147 unsigned int num_iters
= 1025; //request id rolls over at 1024
4148 for (x
= 0; x
< num_iters
;x
++)
4150 memcached_return rc
;
4151 const char *key
= "foo";
4152 uint16_t *expected_ids
=get_udp_request_ids(memc
);
4153 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4154 size_t init_offset
= memc
->hosts
[server_key
].write_buffer_offset
;
4155 rc
= memcached_delete(memc
, key
, strlen(key
), 0);
4156 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4157 if (rc
== MEMCACHED_SUCCESS
|| memc
->hosts
[server_key
].write_buffer_offset
< init_offset
)
4158 increment_request_id(&expected_ids
[server_key
]);
4159 if (rc
== MEMCACHED_SUCCESS
)
4160 assert(memc
->hosts
[server_key
].write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4163 assert(memc
->hosts
[server_key
].write_buffer_offset
!= UDP_DATAGRAM_HEADER_LENGTH
);
4164 assert(memc
->hosts
[server_key
].write_buffer_offset
<= MAX_UDP_DATAGRAM_LENGTH
);
4166 assert(post_udp_op_check(memc
,expected_ids
) == TEST_SUCCESS
);
4168 return TEST_SUCCESS
;
4171 static test_return
udp_buffered_delete_test(memcached_st
*memc
)
4173 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4174 return udp_delete_test(memc
);
4177 static test_return
udp_verbosity_test(memcached_st
*memc
)
4179 memcached_return rc
;
4180 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4182 for (x
= 0; x
< memc
->number_of_hosts
;x
++)
4183 increment_request_id(&expected_ids
[x
]);
4185 rc
= memcached_verbosity(memc
,3);
4186 assert(rc
== MEMCACHED_SUCCESS
);
4187 return post_udp_op_check(memc
,expected_ids
);
4190 static test_return
udp_quit_test(memcached_st
*memc
)
4192 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4193 memcached_quit(memc
);
4194 return post_udp_op_check(memc
, expected_ids
);
4197 static test_return
udp_flush_test(memcached_st
*memc
)
4199 memcached_return rc
;
4200 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4202 for (x
= 0; x
< memc
->number_of_hosts
;x
++)
4203 increment_request_id(&expected_ids
[x
]);
4205 rc
= memcached_flush(memc
,0);
4206 assert(rc
== MEMCACHED_SUCCESS
);
4207 return post_udp_op_check(memc
,expected_ids
);
4210 static test_return
udp_incr_test(memcached_st
*memc
)
4212 memcached_return rc
;
4213 const char *key
= "incr";
4214 const char *value
= "1";
4215 rc
= memcached_set(memc
, key
, strlen(key
),
4216 value
, strlen(value
),
4217 (time_t)0, (uint32_t)0);
4219 assert(rc
== MEMCACHED_SUCCESS
);
4220 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4221 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4222 increment_request_id(&expected_ids
[server_key
]);
4224 rc
= memcached_increment(memc
, key
, strlen(key
), 1, &newvalue
);
4225 assert(rc
== MEMCACHED_SUCCESS
);
4226 return post_udp_op_check(memc
, expected_ids
);
4229 static test_return
udp_decr_test(memcached_st
*memc
)
4231 memcached_return rc
;
4232 const char *key
= "decr";
4233 const char *value
= "1";
4234 rc
= memcached_set(memc
, key
, strlen(key
),
4235 value
, strlen(value
),
4236 (time_t)0, (uint32_t)0);
4238 assert(rc
== MEMCACHED_SUCCESS
);
4239 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4240 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4241 increment_request_id(&expected_ids
[server_key
]);
4243 rc
= memcached_decrement(memc
, key
, strlen(key
), 1, &newvalue
);
4244 assert(rc
== MEMCACHED_SUCCESS
);
4245 return post_udp_op_check(memc
, expected_ids
);
4249 static test_return
udp_stat_test(memcached_st
*memc
)
4251 memcached_stat_st
* rv
= NULL
;
4252 memcached_return rc
;
4254 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4255 rv
= memcached_stat(memc
, args
, &rc
);
4257 assert(rc
== MEMCACHED_NOT_SUPPORTED
);
4258 return post_udp_op_check(memc
, expected_ids
);
4261 static test_return
udp_version_test(memcached_st
*memc
)
4263 memcached_return rc
;
4264 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4265 rc
= memcached_version(memc
);
4266 assert(rc
== MEMCACHED_NOT_SUPPORTED
);
4267 return post_udp_op_check(memc
, expected_ids
);
4270 static test_return
udp_get_test(memcached_st
*memc
)
4272 memcached_return rc
;
4273 const char *key
= "foo";
4275 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4276 char *val
= memcached_get(memc
, key
, strlen(key
), &vlen
, (uint32_t)0, &rc
);
4277 assert(rc
== MEMCACHED_NOT_SUPPORTED
);
4278 assert(val
== NULL
);
4279 return post_udp_op_check(memc
, expected_ids
);
4282 static test_return
udp_mixed_io_test(memcached_st
*memc
)
4285 test_st mixed_io_ops
[] ={
4286 {"udp_set_test", 0, udp_set_test
},
4287 {"udp_set_too_big_test", 0, udp_set_too_big_test
},
4288 {"udp_delete_test", 0, udp_delete_test
},
4289 {"udp_verbosity_test", 0, udp_verbosity_test
},
4290 {"udp_quit_test", 0, udp_quit_test
},
4291 {"udp_flush_test", 0, udp_flush_test
},
4292 {"udp_incr_test", 0, udp_incr_test
},
4293 {"udp_decr_test", 0, udp_decr_test
},
4294 {"udp_version_test", 0, udp_version_test
}
4297 for (x
= 0; x
< 500; x
++)
4299 current_op
= mixed_io_ops
[random() % 9];
4300 assert(current_op
.function(memc
) == TEST_SUCCESS
);
4302 return TEST_SUCCESS
;
4305 static test_return
hsieh_avaibility_test (memcached_st
*memc
)
4307 memcached_return expected_rc
= MEMCACHED_FAILURE
;
4308 #ifdef HAVE_HSIEH_HASH
4309 expected_rc
= MEMCACHED_SUCCESS
;
4311 memcached_return rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
,
4312 (uint64_t)MEMCACHED_HASH_HSIEH
);
4313 assert(rc
== expected_rc
);
4314 return TEST_SUCCESS
;
4317 static const char *list
[]=
4347 static test_return
md5_run (memcached_st
*memc
__attribute__((unused
)))
4351 uint32_t values
[]= { 3195025439U, 2556848621U, 3724893440U, 3332385401U,
4352 245758794U, 2550894432U, 121710495U, 3053817768U,
4353 1250994555U, 1862072655U, 2631955953U, 2951528551U,
4354 1451250070U, 2820856945U, 2060845566U, 3646985608U,
4355 2138080750U, 217675895U, 2230934345U, 1234361223U,
4356 3968582726U, 2455685270U, 1293568479U, 199067604U,
4360 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4364 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MD5
);
4365 assert(values
[x
] == hash_val
);
4368 return TEST_SUCCESS
;
4371 static test_return
crc_run (memcached_st
*memc
__attribute__((unused
)))
4375 uint32_t values
[]= { 10542U, 22009U, 14526U, 19510U, 19432U, 10199U, 20634U,
4376 9369U, 11511U, 10362U, 7893U, 31289U, 11313U, 9354U,
4377 7621U, 30628U, 15218U, 25967U, 2695U, 9380U,
4378 17300U, 28156U, 9192U, 20484U, 16925U };
4380 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4384 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_CRC
);
4385 assert(values
[x
] == hash_val
);
4388 return TEST_SUCCESS
;
4391 static test_return
fnv1_64_run (memcached_st
*memc
__attribute__((unused
)))
4395 uint32_t values
[]= { 473199127U, 4148981457U, 3971873300U, 3257986707U,
4396 1722477987U, 2991193800U, 4147007314U, 3633179701U,
4397 1805162104U, 3503289120U, 3395702895U, 3325073042U,
4398 2345265314U, 3340346032U, 2722964135U, 1173398992U,
4399 2815549194U, 2562818319U, 224996066U, 2680194749U,
4400 3035305390U, 246890365U, 2395624193U, 4145193337U,
4403 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4407 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_64
);
4408 assert(values
[x
] == hash_val
);
4411 return TEST_SUCCESS
;
4414 static test_return
fnv1a_64_run (memcached_st
*memc
__attribute__((unused
)))
4418 uint32_t values
[]= { 1488911807U, 2500855813U, 1510099634U, 1390325195U,
4419 3647689787U, 3241528582U, 1669328060U, 2604311949U,
4420 734810122U, 1516407546U, 560948863U, 1767346780U,
4421 561034892U, 4156330026U, 3716417003U, 3475297030U,
4422 1518272172U, 227211583U, 3938128828U, 126112909U,
4423 3043416448U, 3131561933U, 1328739897U, 2455664041U,
4426 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4430 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_64
);
4431 assert(values
[x
] == hash_val
);
4434 return TEST_SUCCESS
;
4437 static test_return
fnv1_32_run (memcached_st
*memc
__attribute__((unused
)))
4441 uint32_t values
[]= { 67176023U, 1190179409U, 2043204404U, 3221866419U,
4442 2567703427U, 3787535528U, 4147287986U, 3500475733U,
4443 344481048U, 3865235296U, 2181839183U, 119581266U,
4444 510234242U, 4248244304U, 1362796839U, 103389328U,
4445 1449620010U, 182962511U, 3554262370U, 3206747549U,
4446 1551306158U, 4127558461U, 1889140833U, 2774173721U,
4450 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4454 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_32
);
4455 assert(values
[x
] == hash_val
);
4458 return TEST_SUCCESS
;
4461 static test_return
fnv1a_32_run (memcached_st
*memc
__attribute__((unused
)))
4465 uint32_t values
[]= { 280767167U, 2421315013U, 3072375666U, 855001899U,
4466 459261019U, 3521085446U, 18738364U, 1625305005U,
4467 2162232970U, 777243802U, 3323728671U, 132336572U,
4468 3654473228U, 260679466U, 1169454059U, 2698319462U,
4469 1062177260U, 235516991U, 2218399068U, 405302637U,
4470 1128467232U, 3579622413U, 2138539289U, 96429129U,
4473 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4477 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_32
);
4478 assert(values
[x
] == hash_val
);
4481 return TEST_SUCCESS
;
4484 static test_return
hsieh_run (memcached_st
*memc
__attribute__((unused
)))
4488 #ifdef HAVE_HSIEH_HASH
4489 uint32_t values
[]= { 3738850110, 3636226060, 3821074029, 3489929160, 3485772682, 80540287,
4490 1805464076, 1895033657, 409795758, 979934958, 3634096985, 1284445480,
4491 2265380744, 707972988, 353823508, 1549198350, 1327930172, 9304163,
4492 4220749037, 2493964934, 2777873870, 2057831732, 1510213931, 2027828987,
4495 uint32_t values
[]= { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
4498 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4502 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_HSIEH
);
4503 assert(values
[x
] == hash_val
);
4506 return TEST_SUCCESS
;
4509 static test_return
murmur_run (memcached_st
*memc
__attribute__((unused
)))
4513 uint32_t values
[]= { 473199127U, 4148981457U, 3971873300U, 3257986707U,
4514 1722477987U, 2991193800U, 4147007314U, 3633179701U,
4515 1805162104U, 3503289120U, 3395702895U, 3325073042U,
4516 2345265314U, 3340346032U, 2722964135U, 1173398992U,
4517 2815549194U, 2562818319U, 224996066U, 2680194749U,
4518 3035305390U, 246890365U, 2395624193U, 4145193337U,
4521 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4525 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_64
);
4526 assert(values
[x
] == hash_val
);
4529 return TEST_SUCCESS
;
4532 static test_return
jenkins_run (memcached_st
*memc
__attribute__((unused
)))
4536 uint32_t values
[]= { 1442444624U, 4253821186U, 1885058256U, 2120131735U,
4537 3261968576U, 3515188778U, 4232909173U, 4288625128U,
4538 1812047395U, 3689182164U, 2502979932U, 1214050606U,
4539 2415988847U, 1494268927U, 1025545760U, 3920481083U,
4540 4153263658U, 3824871822U, 3072759809U, 798622255U,
4541 3065432577U, 1453328165U, 2691550971U, 3408888387U,
4545 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4549 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_JENKINS
);
4550 assert(values
[x
] == hash_val
);
4553 return TEST_SUCCESS
;
4556 static test_return
regression_bug_434484(memcached_st
*memc
)
4558 if (pre_binary(memc
) != TEST_SUCCESS
)
4559 return TEST_SUCCESS
;
4561 memcached_return ret
;
4562 const char *key
= "regression_bug_434484";
4563 size_t keylen
= strlen(key
);
4565 ret
= memcached_append(memc
, key
, keylen
, key
, keylen
, 0, 0);
4566 assert(ret
== MEMCACHED_NOTSTORED
);
4568 size_t size
= 2048 * 1024;
4569 void *data
= malloc(size
);
4570 assert(data
!= NULL
);
4571 ret
= memcached_set(memc
, key
, keylen
, data
, size
, 0, 0);
4572 assert(ret
== MEMCACHED_E2BIG
);
4575 return TEST_SUCCESS
;
4578 static test_return
regression_bug_434843(memcached_st
*memc
)
4580 if (pre_binary(memc
) != TEST_SUCCESS
)
4581 return TEST_SUCCESS
;
4583 memcached_return rc
;
4584 unsigned int counter
= 0;
4585 memcached_execute_function callbacks
[1]= { [0]= &callback_counter
};
4588 * I only want to hit only _one_ server so I know the number of requests I'm
4589 * sending in the pipleine to the server. Let's try to do a multiget of
4590 * 10240 (that should satisfy most users don't you tink?)
4592 uint32_t number_of_hosts
= memc
->number_of_hosts
;
4593 memc
->number_of_hosts
= 1;
4594 const size_t max_keys
= 10240;
4595 char **keys
= calloc(max_keys
, sizeof(char*));
4596 size_t *key_length
=calloc(max_keys
, sizeof(size_t));
4598 for (int x
= 0; x
< (int)max_keys
; ++x
)
4601 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%u", x
);
4603 assert(keys
[x
] != NULL
);
4607 * Run two times.. the first time we should have 100% cache miss,
4608 * and the second time we should have 100% cache hits
4610 for (int y
= 0; y
< 2; ++y
)
4612 rc
= memcached_mget(memc
, (const char**)keys
, key_length
, max_keys
);
4613 assert(rc
== MEMCACHED_SUCCESS
);
4614 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
4617 /* The first iteration should give me a 100% cache miss. verify that*/
4618 assert(counter
== 0);
4620 for (int x
= 0; x
< (int)max_keys
; ++x
)
4622 rc
= memcached_add(memc
, keys
[x
], key_length
[x
],
4623 blob
, sizeof(blob
), 0, 0);
4624 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4629 /* Verify that we received all of the key/value pairs */
4630 assert(counter
== (unsigned int)max_keys
);
4634 /* Release allocated resources */
4635 for (size_t x
= 0; x
< max_keys
; ++x
)
4640 memc
->number_of_hosts
= number_of_hosts
;
4641 return TEST_SUCCESS
;
4644 static test_return
regression_bug_434843_buffered(memcached_st
*memc
)
4646 memcached_return rc
;
4647 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4648 assert(rc
== MEMCACHED_SUCCESS
);
4650 return regression_bug_434843(memc
);
4653 static test_return
regression_bug_421108(memcached_st
*memc
)
4655 memcached_return rc
;
4656 memcached_stat_st
*memc_stat
= memcached_stat(memc
, NULL
, &rc
);
4657 assert(rc
== MEMCACHED_SUCCESS
);
4659 char *bytes
= memcached_stat_get_value(memc
, memc_stat
, "bytes", &rc
);
4660 assert(rc
== MEMCACHED_SUCCESS
);
4661 assert(bytes
!= NULL
);
4662 char *bytes_read
= memcached_stat_get_value(memc
, memc_stat
,
4664 assert(rc
== MEMCACHED_SUCCESS
);
4665 assert(bytes_read
!= NULL
);
4667 char *bytes_written
= memcached_stat_get_value(memc
, memc_stat
,
4668 "bytes_written", &rc
);
4669 assert(rc
== MEMCACHED_SUCCESS
);
4670 assert(bytes_written
!= NULL
);
4672 assert(strcmp(bytes
, bytes_read
) != 0);
4673 assert(strcmp(bytes
, bytes_written
) != 0);
4675 /* Release allocated resources */
4678 free(bytes_written
);
4679 memcached_stat_free(NULL
, memc_stat
);
4680 return TEST_SUCCESS
;
4684 * The test case isn't obvious so I should probably document why
4685 * it works the way it does. Bug 442914 was caused by a bug
4686 * in the logic in memcached_purge (it did not handle the case
4687 * where the number of bytes sent was equal to the watermark).
4688 * In this test case, create messages so that we hit that case
4689 * and then disable noreply mode and issue a new command to
4690 * verify that it isn't stuck. If we change the format for the
4691 * delete command or the watermarks, we need to update this
4694 static test_return
regression_bug_442914(memcached_st
*memc
)
4696 memcached_return rc
;
4697 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
4698 assert(rc
== MEMCACHED_SUCCESS
);
4699 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1);
4701 uint32_t number_of_hosts
= memc
->number_of_hosts
;
4702 memc
->number_of_hosts
= 1;
4707 for (int x
= 0; x
< 250; ++x
)
4709 len
= (size_t)snprintf(k
, sizeof(k
), "%0250u", x
);
4710 rc
= memcached_delete(memc
, k
, len
, 0);
4711 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4714 len
= (size_t)snprintf(k
, sizeof(k
), "%037u", 251);
4715 rc
= memcached_delete(memc
, k
, len
, 0);
4716 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4718 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0);
4719 assert(rc
== MEMCACHED_SUCCESS
);
4720 rc
= memcached_delete(memc
, k
, len
, 0);
4721 assert(rc
== MEMCACHED_NOTFOUND
);
4723 memc
->number_of_hosts
= number_of_hosts
;
4725 return TEST_SUCCESS
;
4728 test_st udp_setup_server_tests
[] ={
4729 {"set_udp_behavior_test", 0, set_udp_behavior_test
},
4730 {"add_tcp_server_udp_client_test", 0, add_tcp_server_udp_client_test
},
4731 {"add_udp_server_tcp_client_test", 0, add_udp_server_tcp_client_test
},
4735 test_st upd_io_tests
[] ={
4736 {"udp_set_test", 0, udp_set_test
},
4737 {"udp_buffered_set_test", 0, udp_buffered_set_test
},
4738 {"udp_set_too_big_test", 0, udp_set_too_big_test
},
4739 {"udp_delete_test", 0, udp_delete_test
},
4740 {"udp_buffered_delete_test", 0, udp_buffered_delete_test
},
4741 {"udp_verbosity_test", 0, udp_verbosity_test
},
4742 {"udp_quit_test", 0, udp_quit_test
},
4743 {"udp_flush_test", 0, udp_flush_test
},
4744 {"udp_incr_test", 0, udp_incr_test
},
4745 {"udp_decr_test", 0, udp_decr_test
},
4746 {"udp_stat_test", 0, udp_stat_test
},
4747 {"udp_version_test", 0, udp_version_test
},
4748 {"udp_get_test", 0, udp_get_test
},
4749 {"udp_mixed_io_test", 0, udp_mixed_io_test
},
4753 /* Clean the server before beginning testing */
4755 {"flush", 0, flush_test
},
4756 {"init", 0, init_test
},
4757 {"allocation", 0, allocation_test
},
4758 {"server_list_null_test", 0, server_list_null_test
},
4759 {"server_unsort", 0, server_unsort_test
},
4760 {"server_sort", 0, server_sort_test
},
4761 {"server_sort2", 0, server_sort2_test
},
4762 {"clone_test", 0, clone_test
},
4763 {"connection_test", 0, connection_test
},
4764 {"callback_test", 0, callback_test
},
4765 {"behavior_test", 0, behavior_test
},
4766 {"userdata_test", 0, userdata_test
},
4767 {"error", 0, error_test
},
4768 {"set", 0, set_test
},
4769 {"set2", 0, set_test2
},
4770 {"set3", 0, set_test3
},
4771 {"dump", 1, dump_test
},
4772 {"add", 1, add_test
},
4773 {"replace", 1, replace_test
},
4774 {"delete", 1, delete_test
},
4775 {"get", 1, get_test
},
4776 {"get2", 0, get_test2
},
4777 {"get3", 0, get_test3
},
4778 {"get4", 0, get_test4
},
4779 {"partial mget", 0, get_test5
},
4780 {"stats_servername", 0, stats_servername_test
},
4781 {"increment", 0, increment_test
},
4782 {"increment_with_initial", 1, increment_with_initial_test
},
4783 {"decrement", 0, decrement_test
},
4784 {"decrement_with_initial", 1, decrement_with_initial_test
},
4785 {"quit", 0, quit_test
},
4786 {"mget", 1, mget_test
},
4787 {"mget_result", 1, mget_result_test
},
4788 {"mget_result_alloc", 1, mget_result_alloc_test
},
4789 {"mget_result_function", 1, mget_result_function
},
4790 {"mget_end", 0, mget_end
},
4791 {"get_stats", 0, get_stats
},
4792 {"add_host_test", 0, add_host_test
},
4793 {"add_host_test_1", 0, add_host_test1
},
4794 {"get_stats_keys", 0, get_stats_keys
},
4795 {"behavior_test", 0, get_stats_keys
},
4796 {"callback_test", 0, get_stats_keys
},
4797 {"version_string_test", 0, version_string_test
},
4798 {"bad_key", 1, bad_key_test
},
4799 {"memcached_server_cursor", 1, memcached_server_cursor_test
},
4800 {"read_through", 1, read_through
},
4801 {"delete_through", 1, delete_through
},
4802 {"noreply", 1, noreply_test
},
4803 {"analyzer", 1, analyzer_test
},
4804 #ifdef HAVE_LIBMEMCACHEDUTIL
4805 {"connectionpool", 1, connection_pool_test
},
4810 test_st async_tests
[] ={
4811 {"add", 1, add_wrapper
},
4815 test_st string_tests
[] ={
4816 {"string static with null", 0, string_static_null
},
4817 {"string alloc with null", 0, string_alloc_null
},
4818 {"string alloc with 1K", 0, string_alloc_with_size
},
4819 {"string alloc with malloc failure", 0, string_alloc_with_size_toobig
},
4820 {"string append", 0, string_alloc_append
},
4821 {"string append failure (too big)", 0, string_alloc_append_toobig
},
4825 test_st result_tests
[] ={
4826 {"result static", 0, result_static
},
4827 {"result alloc", 0, result_alloc
},
4831 test_st version_1_2_3
[] ={
4832 {"append", 0, append_test
},
4833 {"prepend", 0, prepend_test
},
4834 {"cas", 0, cas_test
},
4835 {"cas2", 0, cas2_test
},
4836 {"append_binary", 0, append_binary_test
},
4840 test_st user_tests
[] ={
4841 {"user_supplied_bug1", 0, user_supplied_bug1
},
4842 {"user_supplied_bug2", 0, user_supplied_bug2
},
4843 {"user_supplied_bug3", 0, user_supplied_bug3
},
4844 {"user_supplied_bug4", 0, user_supplied_bug4
},
4845 {"user_supplied_bug5", 1, user_supplied_bug5
},
4846 {"user_supplied_bug6", 1, user_supplied_bug6
},
4847 {"user_supplied_bug7", 1, user_supplied_bug7
},
4848 {"user_supplied_bug8", 1, user_supplied_bug8
},
4849 {"user_supplied_bug9", 1, user_supplied_bug9
},
4850 {"user_supplied_bug10", 1, user_supplied_bug10
},
4851 {"user_supplied_bug11", 1, user_supplied_bug11
},
4852 {"user_supplied_bug12", 1, user_supplied_bug12
},
4853 {"user_supplied_bug13", 1, user_supplied_bug13
},
4854 {"user_supplied_bug14", 1, user_supplied_bug14
},
4855 {"user_supplied_bug15", 1, user_supplied_bug15
},
4856 {"user_supplied_bug16", 1, user_supplied_bug16
},
4859 ** It seems to be something weird with the character sets..
4860 ** value_fetch is unable to parse the value line (iscntrl "fails"), so I
4861 ** guess I need to find out how this is supposed to work.. Perhaps I need
4862 ** to run the test in a specific locale (I tried zh_CN.UTF-8 without success,
4863 ** so just disable the code for now...).
4865 {"user_supplied_bug17", 1, user_supplied_bug17
},
4867 {"user_supplied_bug18", 1, user_supplied_bug18
},
4868 {"user_supplied_bug19", 1, user_supplied_bug19
},
4869 {"user_supplied_bug20", 1, user_supplied_bug20
},
4870 {"user_supplied_bug21", 1, user_supplied_bug21
},
4874 test_st replication_tests
[]= {
4875 {"set", 1, replication_set_test
},
4876 {"get", 0, replication_get_test
},
4877 {"mget", 0, replication_mget_test
},
4878 {"delete", 0, replication_delete_test
},
4883 * The following test suite is used to verify that we don't introduce
4884 * regression bugs. If you want more information about the bug / test,
4885 * you should look in the bug report at
4886 * http://bugs.launchpad.net/libmemcached
4888 test_st regression_tests
[]= {
4889 {"lp:434484", 1, regression_bug_434484
},
4890 {"lp:434843", 1, regression_bug_434843
},
4891 {"lp:434843 buffered", 1, regression_bug_434843_buffered
},
4892 {"lp:421108", 1, regression_bug_421108
},
4893 {"lp:442914", 1, regression_bug_442914
},
4897 test_st generate_tests
[] ={
4898 {"generate_pairs", 1, generate_pairs
},
4899 {"generate_data", 1, generate_data
},
4900 {"get_read", 0, get_read
},
4901 {"delete_generate", 0, delete_generate
},
4902 {"generate_buffer_data", 1, generate_buffer_data
},
4903 {"delete_buffer", 0, delete_buffer_generate
},
4904 {"generate_data", 1, generate_data
},
4905 {"mget_read", 0, mget_read
},
4906 {"mget_read_result", 0, mget_read_result
},
4907 {"mget_read_function", 0, mget_read_function
},
4908 {"cleanup", 1, cleanup_pairs
},
4909 {"generate_large_pairs", 1, generate_large_pairs
},
4910 {"generate_data", 1, generate_data
},
4911 {"generate_buffer_data", 1, generate_buffer_data
},
4912 {"cleanup", 1, cleanup_pairs
},
4916 test_st consistent_tests
[] ={
4917 {"generate_pairs", 1, generate_pairs
},
4918 {"generate_data", 1, generate_data
},
4919 {"get_read", 0, get_read_count
},
4920 {"cleanup", 1, cleanup_pairs
},
4924 test_st consistent_weighted_tests
[] ={
4925 {"generate_pairs", 1, generate_pairs
},
4926 {"generate_data", 1, generate_data_with_stats
},
4927 {"get_read", 0, get_read_count
},
4928 {"cleanup", 1, cleanup_pairs
},
4932 test_st hsieh_availability
[] ={
4933 {"hsieh_avaibility_test",0,hsieh_avaibility_test
},
4937 test_st ketama_auto_eject_hosts
[] ={
4938 {"auto_eject_hosts", 1, auto_eject_hosts
},
4942 test_st hash_tests
[] ={
4943 {"md5", 0, md5_run
},
4944 {"crc", 0, crc_run
},
4945 {"fnv1_64", 0, fnv1_64_run
},
4946 {"fnv1a_64", 0, fnv1a_64_run
},
4947 {"fnv1_32", 0, fnv1_32_run
},
4948 {"fnv1a_32", 0, fnv1a_32_run
},
4949 {"hsieh", 0, hsieh_run
},
4950 {"murmur", 0, murmur_run
},
4951 {"jenkis", 0, jenkins_run
},
4955 collection_st collection
[] ={
4956 {"hsieh_availability",0,0,hsieh_availability
},
4957 {"udp_setup", init_udp
, 0, udp_setup_server_tests
},
4958 {"udp_io", init_udp
, 0, upd_io_tests
},
4959 {"udp_binary_io", binary_init_udp
, 0, upd_io_tests
},
4960 {"block", 0, 0, tests
},
4961 {"binary", pre_binary
, 0, tests
},
4962 {"nonblock", pre_nonblock
, 0, tests
},
4963 {"nodelay", pre_nodelay
, 0, tests
},
4964 {"settimer", pre_settimer
, 0, tests
},
4965 {"md5", pre_md5
, 0, tests
},
4966 {"crc", pre_crc
, 0, tests
},
4967 {"hsieh", pre_hsieh
, 0, tests
},
4968 {"jenkins", pre_jenkins
, 0, tests
},
4969 {"fnv1_64", pre_hash_fnv1_64
, 0, tests
},
4970 {"fnv1a_64", pre_hash_fnv1a_64
, 0, tests
},
4971 {"fnv1_32", pre_hash_fnv1_32
, 0, tests
},
4972 {"fnv1a_32", pre_hash_fnv1a_32
, 0, tests
},
4973 {"ketama", pre_behavior_ketama
, 0, tests
},
4974 {"ketama_auto_eject_hosts", pre_behavior_ketama
, 0, ketama_auto_eject_hosts
},
4975 {"unix_socket", pre_unix_socket
, 0, tests
},
4976 {"unix_socket_nodelay", pre_nodelay
, 0, tests
},
4977 {"poll_timeout", poll_timeout
, 0, tests
},
4978 {"gets", enable_cas
, 0, tests
},
4979 {"consistent", enable_consistent
, 0, tests
},
4980 #ifdef MEMCACHED_ENABLE_DEPRECATED
4981 {"deprecated_memory_allocators", deprecated_set_memory_alloc
, 0, tests
},
4983 {"memory_allocators", set_memory_alloc
, 0, tests
},
4984 {"prefix", set_prefix
, 0, tests
},
4985 {"version_1_2_3", check_for_1_2_3
, 0, version_1_2_3
},
4986 {"string", 0, 0, string_tests
},
4987 {"result", 0, 0, result_tests
},
4988 {"async", pre_nonblock
, 0, async_tests
},
4989 {"async_binary", pre_nonblock_binary
, 0, async_tests
},
4990 {"user", 0, 0, user_tests
},
4991 {"generate", 0, 0, generate_tests
},
4992 {"generate_hsieh", pre_hsieh
, 0, generate_tests
},
4993 {"generate_ketama", pre_behavior_ketama
, 0, generate_tests
},
4994 {"generate_hsieh_consistent", enable_consistent
, 0, generate_tests
},
4995 {"generate_md5", pre_md5
, 0, generate_tests
},
4996 {"generate_murmur", pre_murmur
, 0, generate_tests
},
4997 {"generate_jenkins", pre_jenkins
, 0, generate_tests
},
4998 {"generate_nonblock", pre_nonblock
, 0, generate_tests
},
4999 {"consistent_not", 0, 0, consistent_tests
},
5000 {"consistent_ketama", pre_behavior_ketama
, 0, consistent_tests
},
5001 {"consistent_ketama_weighted", pre_behavior_ketama_weighted
, 0, consistent_weighted_tests
},
5002 {"test_hashes", 0, 0, hash_tests
},
5003 {"replication", pre_replication
, 0, replication_tests
},
5004 {"replication_noblock", pre_replication_noblock
, 0, replication_tests
},
5005 {"regression", 0, 0, regression_tests
},
5009 #define SERVERS_TO_CREATE 5
5011 /* Prototypes for functions we will pass to test framework */
5012 void *world_create(void);
5013 void world_destroy(void *p
);
5015 void *world_create(void)
5017 server_startup_st
*construct
;
5019 construct
= calloc(sizeof(server_startup_st
), 1);
5020 construct
->count
= SERVERS_TO_CREATE
;
5022 server_startup(construct
);
5028 void world_destroy(void *p
)
5030 server_startup_st
*construct
= (server_startup_st
*)p
;
5031 memcached_server_st
*servers
= (memcached_server_st
*)construct
->servers
;
5032 memcached_server_list_free(servers
);
5034 server_shutdown(construct
);
5038 void get_world(world_st
*world
)
5040 world
->collections
= collection
;
5041 world
->create
= world_create
;
5042 world
->destroy
= world_destroy
;