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_t
init_test(memcached_st
*not_used
__attribute__((unused
)))
49 (void)memcached_create(&memc
);
50 memcached_free(&memc
);
55 static test_return_t
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_t
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_t
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_t
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_t
allocation_test(memcached_st
*not_used
__attribute__((unused
)))
194 memc
= memcached_create(NULL
);
196 memcached_free(memc
);
201 static test_return_t
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_t
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_t
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_t
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, 2593724503U};
302 // You have updated the memcache_error messages but not updated docs/tests.
303 assert(MEMCACHED_MAXIMUM_RETURN
== 39);
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_t
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_t
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_t
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_t
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_t
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_t
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_t
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_t
add_wrapper(memcached_st
*memc
)
595 unsigned int max
= 10000;
603 for (x
= 0; x
< max
; x
++)
609 static test_return_t
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_t
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_t
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_t
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_t
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_t
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_t
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_t
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_t
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_t
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_t
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_t
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_t
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_t
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_t
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_t
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_t
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 rc
= memcached_increment_by_key(memc
, key
, strlen(key
),
1158 assert(rc
== MEMCACHED_SUCCESS
);
1159 assert(new_number
== 3);
1161 return TEST_SUCCESS
;
1164 static test_return_t
increment_with_initial_test(memcached_st
*memc
)
1166 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1168 uint64_t new_number
;
1169 memcached_return rc
;
1170 const char *key
= "number";
1171 uint64_t initial
= 0;
1173 rc
= memcached_increment_with_initial(memc
, key
, strlen(key
),
1174 1, initial
, 0, &new_number
);
1175 assert(rc
== MEMCACHED_SUCCESS
);
1176 assert(new_number
== initial
);
1178 rc
= memcached_increment_with_initial(memc
, key
, strlen(key
),
1179 1, initial
, 0, &new_number
);
1180 assert(rc
== MEMCACHED_SUCCESS
);
1181 assert(new_number
== (initial
+ 1));
1183 return TEST_SUCCESS
;
1186 static test_return_t
decrement_test(memcached_st
*memc
)
1188 uint64_t new_number
;
1189 memcached_return rc
;
1190 const char *key
= "number";
1191 const char *value
= "3";
1193 rc
= memcached_set(memc
, key
, strlen(key
),
1194 value
, strlen(value
),
1195 (time_t)0, (uint32_t)0);
1196 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1198 rc
= memcached_decrement(memc
, key
, strlen(key
),
1200 assert(rc
== MEMCACHED_SUCCESS
);
1201 assert(new_number
== 2);
1203 rc
= memcached_decrement(memc
, key
, strlen(key
),
1205 assert(rc
== MEMCACHED_SUCCESS
);
1206 assert(new_number
== 1);
1208 rc
= memcached_decrement_by_key(memc
, key
, strlen(key
),
1211 assert(rc
== MEMCACHED_SUCCESS
);
1212 assert(new_number
== 0);
1214 return TEST_SUCCESS
;
1217 static test_return_t
decrement_with_initial_test(memcached_st
*memc
)
1219 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1221 uint64_t new_number
;
1222 memcached_return rc
;
1223 const char *key
= "number";
1224 uint64_t initial
= 3;
1226 rc
= memcached_decrement_with_initial(memc
, key
, strlen(key
),
1227 1, initial
, 0, &new_number
);
1228 assert(rc
== MEMCACHED_SUCCESS
);
1229 assert(new_number
== initial
);
1231 rc
= memcached_decrement_with_initial(memc
, key
, strlen(key
),
1232 1, initial
, 0, &new_number
);
1233 assert(rc
== MEMCACHED_SUCCESS
);
1234 assert(new_number
== (initial
- 1));
1236 return TEST_SUCCESS
;
1239 static test_return_t
quit_test(memcached_st
*memc
)
1241 memcached_return rc
;
1242 const char *key
= "fudge";
1243 const char *value
= "sanford and sun";
1245 rc
= memcached_set(memc
, key
, strlen(key
),
1246 value
, strlen(value
),
1247 (time_t)10, (uint32_t)3);
1248 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1249 memcached_quit(memc
);
1251 rc
= memcached_set(memc
, key
, strlen(key
),
1252 value
, strlen(value
),
1253 (time_t)50, (uint32_t)9);
1254 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1256 return TEST_SUCCESS
;
1259 static test_return_t
mget_result_test(memcached_st
*memc
)
1261 memcached_return rc
;
1262 const char *keys
[]= {"fudge", "son", "food"};
1263 size_t key_length
[]= {5, 3, 4};
1266 memcached_result_st results_obj
;
1267 memcached_result_st
*results
;
1269 results
= memcached_result_create(memc
, &results_obj
);
1271 assert(&results_obj
== results
);
1273 /* We need to empty the server before continueing test */
1274 rc
= memcached_flush(memc
, 0);
1275 assert(rc
== MEMCACHED_SUCCESS
);
1277 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1278 assert(rc
== MEMCACHED_SUCCESS
);
1280 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1285 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1287 assert(rc
== MEMCACHED_END
);
1289 for (x
= 0; x
< 3; x
++)
1291 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1292 keys
[x
], key_length
[x
],
1293 (time_t)50, (uint32_t)9);
1294 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1297 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1298 assert(rc
== MEMCACHED_SUCCESS
);
1300 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1303 assert(&results_obj
== results
);
1304 assert(rc
== MEMCACHED_SUCCESS
);
1305 assert(memcached_result_key_length(results
) == memcached_result_length(results
));
1306 assert(!memcmp(memcached_result_key_value(results
),
1307 memcached_result_value(results
),
1308 memcached_result_length(results
)));
1311 memcached_result_free(&results_obj
);
1313 return TEST_SUCCESS
;
1316 static test_return_t
mget_result_alloc_test(memcached_st
*memc
)
1318 memcached_return rc
;
1319 const char *keys
[]= {"fudge", "son", "food"};
1320 size_t key_length
[]= {5, 3, 4};
1323 memcached_result_st
*results
;
1325 /* We need to empty the server before continueing test */
1326 rc
= memcached_flush(memc
, 0);
1327 assert(rc
== MEMCACHED_SUCCESS
);
1329 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1330 assert(rc
== MEMCACHED_SUCCESS
);
1332 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)) != NULL
)
1337 assert(rc
== MEMCACHED_END
);
1339 for (x
= 0; x
< 3; x
++)
1341 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1342 keys
[x
], key_length
[x
],
1343 (time_t)50, (uint32_t)9);
1344 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1347 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1348 assert(rc
== MEMCACHED_SUCCESS
);
1351 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1354 assert(rc
== MEMCACHED_SUCCESS
);
1355 assert(memcached_result_key_length(results
) == memcached_result_length(results
));
1356 assert(!memcmp(memcached_result_key_value(results
),
1357 memcached_result_value(results
),
1358 memcached_result_length(results
)));
1359 memcached_result_free(results
);
1363 return TEST_SUCCESS
;
1366 /* Count the results */
1367 static memcached_return
callback_counter(memcached_st
*ptr
__attribute__((unused
)),
1368 memcached_result_st
*result
__attribute__((unused
)),
1371 unsigned int *counter
= (unsigned int *)context
;
1373 *counter
= *counter
+ 1;
1375 return MEMCACHED_SUCCESS
;
1378 static test_return_t
mget_result_function(memcached_st
*memc
)
1380 memcached_return rc
;
1381 const char *keys
[]= {"fudge", "son", "food"};
1382 size_t key_length
[]= {5, 3, 4};
1384 unsigned int counter
;
1385 memcached_execute_function callbacks
[1];
1387 /* We need to empty the server before continueing test */
1388 rc
= memcached_flush(memc
, 0);
1389 for (x
= 0; x
< 3; x
++)
1391 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1392 keys
[x
], key_length
[x
],
1393 (time_t)50, (uint32_t)9);
1394 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1397 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1398 assert(rc
== MEMCACHED_SUCCESS
);
1400 callbacks
[0]= &callback_counter
;
1402 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
1404 assert(counter
== 3);
1406 return TEST_SUCCESS
;
1409 static test_return_t
mget_test(memcached_st
*memc
)
1411 memcached_return rc
;
1412 const char *keys
[]= {"fudge", "son", "food"};
1413 size_t key_length
[]= {5, 3, 4};
1417 char return_key
[MEMCACHED_MAX_KEY
];
1418 size_t return_key_length
;
1420 size_t return_value_length
;
1422 /* We need to empty the server before continueing test */
1423 rc
= memcached_flush(memc
, 0);
1424 assert(rc
== MEMCACHED_SUCCESS
);
1426 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1427 assert(rc
== MEMCACHED_SUCCESS
);
1429 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1430 &return_value_length
, &flags
, &rc
)) != NULL
)
1432 assert(return_value
);
1434 assert(!return_value
);
1435 assert(return_value_length
== 0);
1436 assert(rc
== MEMCACHED_END
);
1438 for (x
= 0; x
< 3; x
++)
1440 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1441 keys
[x
], key_length
[x
],
1442 (time_t)50, (uint32_t)9);
1443 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1446 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1447 assert(rc
== MEMCACHED_SUCCESS
);
1450 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1451 &return_value_length
, &flags
, &rc
)))
1453 assert(return_value
);
1454 assert(rc
== MEMCACHED_SUCCESS
);
1455 assert(return_key_length
== return_value_length
);
1456 assert(!memcmp(return_value
, return_key
, return_value_length
));
1461 return TEST_SUCCESS
;
1464 static test_return_t
mget_execute(memcached_st
*memc
)
1467 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1471 * I only want to hit _one_ server so I know the number of requests I'm
1472 * sending in the pipeline.
1474 uint32_t number_of_hosts
= memc
->number_of_hosts
;
1475 memc
->number_of_hosts
= 1;
1477 int max_keys
= binary
? 20480 : 1;
1480 char **keys
= calloc((size_t)max_keys
, sizeof(char*));
1481 size_t *key_length
=calloc((size_t)max_keys
, sizeof(size_t));
1483 /* First add all of the items.. */
1484 char blob
[1024] = {0};
1485 memcached_return rc
;
1486 for (int x
= 0; x
< max_keys
; ++x
)
1489 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%u", x
);
1491 assert(keys
[x
] != NULL
);
1492 rc
= memcached_add(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
1493 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1496 /* Try to get all of them with a large multiget */
1497 unsigned int counter
= 0;
1498 memcached_execute_function callbacks
[1]= { [0]= &callback_counter
};
1499 rc
= memcached_mget_execute(memc
, (const char**)keys
, key_length
,
1500 (size_t)max_keys
, callbacks
, &counter
, 1);
1504 assert(rc
== MEMCACHED_SUCCESS
);
1506 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
1507 assert(rc
== MEMCACHED_END
);
1509 /* Verify that we got all of the items */
1510 assert(counter
== (unsigned int)max_keys
);
1514 assert(rc
== MEMCACHED_NOT_SUPPORTED
);
1515 assert(counter
== 0);
1518 /* Release all allocated resources */
1519 for (int x
= 0; x
< max_keys
; ++x
)
1524 memc
->number_of_hosts
= number_of_hosts
;
1525 return TEST_SUCCESS
;
1528 static test_return_t
get_stats_keys(memcached_st
*memc
)
1532 memcached_stat_st memc_stat
;
1533 memcached_return rc
;
1535 list
= memcached_stat_get_keys(memc
, &memc_stat
, &rc
);
1536 assert(rc
== MEMCACHED_SUCCESS
);
1537 for (ptr
= list
; *ptr
; ptr
++)
1543 return TEST_SUCCESS
;
1546 static test_return_t
version_string_test(memcached_st
*memc
__attribute__((unused
)))
1548 const char *version_string
;
1550 version_string
= memcached_lib_version();
1552 assert(!strcmp(version_string
, LIBMEMCACHED_VERSION_STRING
));
1554 return TEST_SUCCESS
;
1557 static test_return_t
get_stats(memcached_st
*memc
)
1562 memcached_return rc
;
1563 memcached_stat_st
*memc_stat
;
1565 memc_stat
= memcached_stat(memc
, NULL
, &rc
);
1566 assert(rc
== MEMCACHED_SUCCESS
);
1568 assert(rc
== MEMCACHED_SUCCESS
);
1571 for (x
= 0; x
< memcached_server_count(memc
); x
++)
1573 list
= memcached_stat_get_keys(memc
, memc_stat
+x
, &rc
);
1574 assert(rc
== MEMCACHED_SUCCESS
);
1575 for (ptr
= list
; *ptr
; ptr
++);
1580 memcached_stat_free(NULL
, memc_stat
);
1582 return TEST_SUCCESS
;
1585 static test_return_t
add_host_test(memcached_st
*memc
)
1588 memcached_server_st
*servers
;
1589 memcached_return rc
;
1590 char servername
[]= "0.example.com";
1592 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
1594 assert(1 == memcached_server_list_count(servers
));
1596 for (x
= 2; x
< 20; x
++)
1598 char buffer
[SMALL_STRING_LEN
];
1600 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
1601 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
1603 assert(rc
== MEMCACHED_SUCCESS
);
1604 assert(x
== memcached_server_list_count(servers
));
1607 rc
= memcached_server_push(memc
, servers
);
1608 assert(rc
== MEMCACHED_SUCCESS
);
1609 rc
= memcached_server_push(memc
, servers
);
1610 assert(rc
== MEMCACHED_SUCCESS
);
1612 memcached_server_list_free(servers
);
1614 return TEST_SUCCESS
;
1617 static memcached_return
clone_test_callback(memcached_st
*parent
__attribute__((unused
)), memcached_st
*memc_clone
__attribute__((unused
)))
1619 return MEMCACHED_SUCCESS
;
1622 static memcached_return
cleanup_test_callback(memcached_st
*ptr
__attribute__((unused
)))
1624 return MEMCACHED_SUCCESS
;
1627 static test_return_t
callback_test(memcached_st
*memc
)
1629 /* Test User Data */
1633 memcached_return rc
;
1635 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_USER_DATA
, &x
);
1636 assert(rc
== MEMCACHED_SUCCESS
);
1637 test_ptr
= (int *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_USER_DATA
, &rc
);
1638 assert(*test_ptr
== x
);
1641 /* Test Clone Callback */
1643 memcached_clone_func clone_cb
= (memcached_clone_func
)clone_test_callback
;
1644 void *clone_cb_ptr
= *(void **)&clone_cb
;
1645 void *temp_function
= NULL
;
1646 memcached_return rc
;
1648 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
,
1650 assert(rc
== MEMCACHED_SUCCESS
);
1651 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1652 assert(temp_function
== clone_cb_ptr
);
1655 /* Test Cleanup Callback */
1657 memcached_cleanup_func cleanup_cb
=
1658 (memcached_cleanup_func
)cleanup_test_callback
;
1659 void *cleanup_cb_ptr
= *(void **)&cleanup_cb
;
1660 void *temp_function
= NULL
;
1661 memcached_return rc
;
1663 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
,
1665 assert(rc
== MEMCACHED_SUCCESS
);
1666 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1667 assert(temp_function
== cleanup_cb_ptr
);
1670 return TEST_SUCCESS
;
1673 /* We don't test the behavior itself, we test the switches */
1674 static test_return_t
behavior_test(memcached_st
*memc
)
1679 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1680 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1683 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1684 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1687 set
= MEMCACHED_HASH_MD5
;
1688 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1689 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1690 assert(value
== MEMCACHED_HASH_MD5
);
1694 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1695 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1698 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1699 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1702 set
= MEMCACHED_HASH_DEFAULT
;
1703 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1704 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1705 assert(value
== MEMCACHED_HASH_DEFAULT
);
1707 set
= MEMCACHED_HASH_CRC
;
1708 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1709 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1710 assert(value
== MEMCACHED_HASH_CRC
);
1712 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1715 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1718 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
);
1719 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, value
+ 1);
1720 assert((value
+ 1) == memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
));
1721 return TEST_SUCCESS
;
1724 static test_return_t
fetch_all_results(memcached_st
*memc
)
1726 memcached_return rc
= MEMCACHED_SUCCESS
;
1727 char return_key
[MEMCACHED_MAX_KEY
];
1728 size_t return_key_length
;
1730 size_t return_value_length
;
1733 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1734 &return_value_length
, &flags
, &rc
)))
1736 assert(return_value
);
1737 assert(rc
== MEMCACHED_SUCCESS
);
1741 return ((rc
== MEMCACHED_END
) || (rc
== MEMCACHED_SUCCESS
)) ? TEST_SUCCESS
: TEST_FAILURE
;
1744 /* Test case provided by Cal Haldenbrand */
1745 static test_return_t
user_supplied_bug1(memcached_st
*memc
)
1747 unsigned int setter
= 1;
1750 unsigned long long total
= 0;
1753 char randomstuff
[6 * 1024];
1754 memcached_return rc
;
1756 memset(randomstuff
, 0, 6 * 1024);
1758 /* We just keep looking at the same values over and over */
1761 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1762 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1766 for (x
= 0 ; total
< 20 * 1024576 ; x
++ )
1770 size
= (uint32_t)(rand() % ( 5 * 1024 ) ) + 400;
1771 memset(randomstuff
, 0, 6 * 1024);
1772 assert(size
< 6 * 1024); /* Being safe here */
1774 for (j
= 0 ; j
< size
;j
++)
1775 randomstuff
[j
] = (signed char) ((rand() % 26) + 97);
1778 sprintf(key
, "%d", x
);
1779 rc
= memcached_set(memc
, key
, strlen(key
),
1780 randomstuff
, strlen(randomstuff
), 10, 0);
1781 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1782 /* If we fail, lets try again */
1783 if (rc
!= MEMCACHED_SUCCESS
&& rc
!= MEMCACHED_BUFFERED
)
1784 rc
= memcached_set(memc
, key
, strlen(key
),
1785 randomstuff
, strlen(randomstuff
), 10, 0);
1786 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1789 return TEST_SUCCESS
;
1792 /* Test case provided by Cal Haldenbrand */
1793 static test_return_t
user_supplied_bug2(memcached_st
*memc
)
1796 unsigned int setter
;
1798 unsigned long long total
;
1801 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1802 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1804 setter
= 20 * 1024576;
1805 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1806 setter
= 20 * 1024576;
1807 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1808 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1809 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1811 for (x
= 0, errors
= 0, total
= 0 ; total
< 20 * 1024576 ; x
++)
1814 for (x
= 0, errors
= 0, total
= 0 ; total
< 24576 ; x
++)
1816 memcached_return rc
= MEMCACHED_SUCCESS
;
1817 char buffer
[SMALL_STRING_LEN
];
1822 memset(buffer
, 0, SMALL_STRING_LEN
);
1824 snprintf(buffer
, SMALL_STRING_LEN
, "%u", x
);
1825 getval
= memcached_get(memc
, buffer
, strlen(buffer
),
1826 &val_len
, &flags
, &rc
);
1827 if (rc
!= MEMCACHED_SUCCESS
)
1829 if (rc
== MEMCACHED_NOTFOUND
)
1843 return TEST_SUCCESS
;
1846 /* Do a large mget() over all the keys we think exist */
1847 #define KEY_COUNT 3000 // * 1024576
1848 static test_return_t
user_supplied_bug3(memcached_st
*memc
)
1850 memcached_return rc
;
1851 unsigned int setter
;
1854 size_t key_lengths
[KEY_COUNT
];
1857 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1858 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1860 setter
= 20 * 1024576;
1861 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1862 setter
= 20 * 1024576;
1863 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1864 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1865 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1868 keys
= calloc(KEY_COUNT
, sizeof(char *));
1870 for (x
= 0; x
< KEY_COUNT
; x
++)
1874 snprintf(buffer
, 30, "%u", x
);
1875 keys
[x
]= strdup(buffer
);
1876 key_lengths
[x
]= strlen(keys
[x
]);
1879 rc
= memcached_mget(memc
, (const char **)keys
, key_lengths
, KEY_COUNT
);
1880 assert(rc
== MEMCACHED_SUCCESS
);
1882 assert(fetch_all_results(memc
) == TEST_SUCCESS
);
1884 for (x
= 0; x
< KEY_COUNT
; x
++)
1888 return TEST_SUCCESS
;
1891 /* Make sure we behave properly if server list has no values */
1892 static test_return_t
user_supplied_bug4(memcached_st
*memc
)
1894 memcached_return rc
;
1895 const char *keys
[]= {"fudge", "son", "food"};
1896 size_t key_length
[]= {5, 3, 4};
1899 char return_key
[MEMCACHED_MAX_KEY
];
1900 size_t return_key_length
;
1902 size_t return_value_length
;
1904 /* Here we free everything before running a bunch of mget tests */
1906 memcached_server_list_free(memc
->hosts
);
1908 memc
->number_of_hosts
= 0;
1912 /* We need to empty the server before continueing test */
1913 rc
= memcached_flush(memc
, 0);
1914 assert(rc
== MEMCACHED_NO_SERVERS
);
1916 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1917 assert(rc
== MEMCACHED_NO_SERVERS
);
1919 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1920 &return_value_length
, &flags
, &rc
)) != NULL
)
1922 assert(return_value
);
1924 assert(!return_value
);
1925 assert(return_value_length
== 0);
1926 assert(rc
== MEMCACHED_NO_SERVERS
);
1928 for (x
= 0; x
< 3; x
++)
1930 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1931 keys
[x
], key_length
[x
],
1932 (time_t)50, (uint32_t)9);
1933 assert(rc
== MEMCACHED_NO_SERVERS
);
1936 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1937 assert(rc
== MEMCACHED_NO_SERVERS
);
1940 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1941 &return_value_length
, &flags
, &rc
)))
1943 assert(return_value
);
1944 assert(rc
== MEMCACHED_SUCCESS
);
1945 assert(return_key_length
== return_value_length
);
1946 assert(!memcmp(return_value
, return_key
, return_value_length
));
1951 return TEST_SUCCESS
;
1954 #define VALUE_SIZE_BUG5 1048064
1955 static test_return_t
user_supplied_bug5(memcached_st
*memc
)
1957 memcached_return rc
;
1958 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1959 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1960 char return_key
[MEMCACHED_MAX_KEY
];
1961 size_t return_key_length
;
1963 size_t value_length
;
1967 char insert_data
[VALUE_SIZE_BUG5
];
1969 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1970 insert_data
[x
]= (signed char)rand();
1972 memcached_flush(memc
, 0);
1973 value
= memcached_get(memc
, keys
[0], key_length
[0],
1974 &value_length
, &flags
, &rc
);
1975 assert(value
== NULL
);
1976 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1979 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1980 &value_length
, &flags
, &rc
)))
1984 for (x
= 0; x
< 4; x
++)
1986 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1987 insert_data
, VALUE_SIZE_BUG5
,
1988 (time_t)0, (uint32_t)0);
1989 assert(rc
== MEMCACHED_SUCCESS
);
1992 for (x
= 0; x
< 10; x
++)
1994 value
= memcached_get(memc
, keys
[0], key_length
[0],
1995 &value_length
, &flags
, &rc
);
1999 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2001 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2002 &value_length
, &flags
, &rc
)))
2010 return TEST_SUCCESS
;
2013 static test_return_t
user_supplied_bug6(memcached_st
*memc
)
2015 memcached_return rc
;
2016 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
2017 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
2018 char return_key
[MEMCACHED_MAX_KEY
];
2019 size_t return_key_length
;
2021 size_t value_length
;
2025 char insert_data
[VALUE_SIZE_BUG5
];
2027 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2028 insert_data
[x
]= (signed char)rand();
2030 memcached_flush(memc
, 0);
2031 value
= memcached_get(memc
, keys
[0], key_length
[0],
2032 &value_length
, &flags
, &rc
);
2033 assert(value
== NULL
);
2034 assert(rc
== MEMCACHED_NOTFOUND
);
2035 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2036 assert(rc
== MEMCACHED_SUCCESS
);
2039 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2040 &value_length
, &flags
, &rc
)))
2043 assert(rc
== MEMCACHED_END
);
2045 for (x
= 0; x
< 4; x
++)
2047 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2048 insert_data
, VALUE_SIZE_BUG5
,
2049 (time_t)0, (uint32_t)0);
2050 assert(rc
== MEMCACHED_SUCCESS
);
2053 for (x
= 0; x
< 2; x
++)
2055 value
= memcached_get(memc
, keys
[0], key_length
[0],
2056 &value_length
, &flags
, &rc
);
2060 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2061 assert(rc
== MEMCACHED_SUCCESS
);
2063 /* We test for purge of partial complete fetches */
2064 for (count
= 3; count
; count
--)
2066 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2067 &value_length
, &flags
, &rc
);
2068 assert(rc
== MEMCACHED_SUCCESS
);
2069 assert(!(memcmp(value
, insert_data
, value_length
)));
2070 assert(value_length
);
2075 return TEST_SUCCESS
;
2078 static test_return_t
user_supplied_bug8(memcached_st
*memc
__attribute__((unused
)))
2080 memcached_return rc
;
2082 memcached_st
*memc_clone
;
2084 memcached_server_st
*servers
;
2085 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";
2087 servers
= memcached_servers_parse(server_list
);
2090 mine
= memcached_create(NULL
);
2091 rc
= memcached_server_push(mine
, servers
);
2092 assert(rc
== MEMCACHED_SUCCESS
);
2093 memcached_server_list_free(servers
);
2096 memc_clone
= memcached_clone(NULL
, mine
);
2098 memcached_quit(mine
);
2099 memcached_quit(memc_clone
);
2102 memcached_free(mine
);
2103 memcached_free(memc_clone
);
2105 return TEST_SUCCESS
;
2108 /* Test flag store/retrieve */
2109 static test_return_t
user_supplied_bug7(memcached_st
*memc
)
2111 memcached_return rc
;
2112 const char *keys
= "036790384900";
2113 size_t key_length
= strlen(keys
);
2114 char return_key
[MEMCACHED_MAX_KEY
];
2115 size_t return_key_length
;
2117 size_t value_length
;
2120 char insert_data
[VALUE_SIZE_BUG5
];
2122 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2123 insert_data
[x
]= (signed char)rand();
2125 memcached_flush(memc
, 0);
2128 rc
= memcached_set(memc
, keys
, key_length
,
2129 insert_data
, VALUE_SIZE_BUG5
,
2131 assert(rc
== MEMCACHED_SUCCESS
);
2134 value
= memcached_get(memc
, keys
, key_length
,
2135 &value_length
, &flags
, &rc
);
2136 assert(flags
== 245);
2140 rc
= memcached_mget(memc
, &keys
, &key_length
, 1);
2143 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2144 &value_length
, &flags
, &rc
);
2145 assert(flags
== 245);
2150 return TEST_SUCCESS
;
2153 static test_return_t
user_supplied_bug9(memcached_st
*memc
)
2155 memcached_return rc
;
2156 const char *keys
[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
2157 size_t key_length
[3];
2162 char return_key
[MEMCACHED_MAX_KEY
];
2163 size_t return_key_length
;
2165 size_t return_value_length
;
2168 key_length
[0]= strlen("UDATA:edevil@sapo.pt");
2169 key_length
[1]= strlen("fudge&*@#");
2170 key_length
[2]= strlen("for^#@&$not");
2173 for (x
= 0; x
< 3; x
++)
2175 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2176 keys
[x
], key_length
[x
],
2177 (time_t)50, (uint32_t)9);
2178 assert(rc
== MEMCACHED_SUCCESS
);
2181 rc
= memcached_mget(memc
, keys
, key_length
, 3);
2182 assert(rc
== MEMCACHED_SUCCESS
);
2184 /* We need to empty the server before continueing test */
2185 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2186 &return_value_length
, &flags
, &rc
)) != NULL
)
2188 assert(return_value
);
2194 return TEST_SUCCESS
;
2197 /* We are testing with aggressive timeout to get failures */
2198 static test_return_t
user_supplied_bug10(memcached_st
*memc
)
2200 const char *key
= "foo";
2202 size_t value_length
= 512;
2205 memcached_return rc
;
2206 unsigned int set
= 1;
2207 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2210 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2211 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2213 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
,
2216 value
= (char*)malloc(value_length
* sizeof(char));
2218 for (x
= 0; x
< value_length
; x
++)
2219 value
[x
]= (char) (x
% 127);
2221 for (x
= 1; x
<= 100000; ++x
)
2223 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2225 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_WRITE_FAILURE
||
2226 rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_TIMEOUT
);
2228 if (rc
== MEMCACHED_WRITE_FAILURE
|| rc
== MEMCACHED_TIMEOUT
)
2233 memcached_free(mclone
);
2235 return TEST_SUCCESS
;
2239 We are looking failures in the async protocol
2241 static test_return_t
user_supplied_bug11(memcached_st
*memc
)
2243 const char *key
= "foo";
2245 size_t value_length
= 512;
2248 memcached_return rc
;
2249 unsigned int set
= 1;
2251 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2253 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2254 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2256 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
,
2259 timeout
= (int32_t)memcached_behavior_get(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
2261 assert(timeout
== -1);
2263 value
= (char*)malloc(value_length
* sizeof(char));
2265 for (x
= 0; x
< value_length
; x
++)
2266 value
[x
]= (char) (x
% 127);
2268 for (x
= 1; x
<= 100000; ++x
)
2270 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2274 memcached_free(mclone
);
2276 return TEST_SUCCESS
;
2280 Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
2282 static test_return_t
user_supplied_bug12(memcached_st
*memc
)
2284 memcached_return rc
;
2286 size_t value_length
;
2288 uint64_t number_value
;
2290 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2291 &value_length
, &flags
, &rc
);
2292 assert(value
== NULL
);
2293 assert(rc
== MEMCACHED_NOTFOUND
);
2295 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2298 assert(value
== NULL
);
2299 /* The binary protocol will set the key if it doesn't exist */
2300 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1)
2301 assert(rc
== MEMCACHED_SUCCESS
);
2303 assert(rc
== MEMCACHED_NOTFOUND
);
2305 rc
= memcached_set(memc
, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
2307 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2308 &value_length
, &flags
, &rc
);
2310 assert(rc
== MEMCACHED_SUCCESS
);
2313 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2315 assert(number_value
== 2);
2316 assert(rc
== MEMCACHED_SUCCESS
);
2318 return TEST_SUCCESS
;
2322 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2323 set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
2325 static test_return_t
user_supplied_bug13(memcached_st
*memc
)
2327 char key
[] = "key34567890";
2329 memcached_return rc
;
2330 size_t overflowSize
;
2332 char commandFirst
[]= "set key34567890 0 0 ";
2333 char commandLast
[] = " \r\n"; /* first line of command sent to server */
2334 size_t commandLength
;
2337 commandLength
= strlen(commandFirst
) + strlen(commandLast
) + 4; /* 4 is number of characters in size, probably 8196 */
2339 overflowSize
= MEMCACHED_MAX_BUFFER
- commandLength
;
2341 for (testSize
= overflowSize
- 1; testSize
< overflowSize
+ 1; testSize
++)
2343 overflow
= malloc(testSize
);
2344 assert(overflow
!= NULL
);
2346 memset(overflow
, 'x', testSize
);
2347 rc
= memcached_set(memc
, key
, strlen(key
),
2348 overflow
, testSize
, 0, 0);
2349 assert(rc
== MEMCACHED_SUCCESS
);
2353 return TEST_SUCCESS
;
2358 Test values of many different sizes
2359 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2360 set key34567890 0 0 8169 \r\n
2361 is sent followed by buffer of size 8169, followed by 8169
2363 static test_return_t
user_supplied_bug14(memcached_st
*memc
)
2366 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2367 memcached_return rc
;
2368 const char *key
= "foo";
2370 size_t value_length
= 18000;
2372 size_t string_length
;
2375 size_t current_length
;
2377 value
= (char*)malloc(value_length
);
2380 for (x
= 0; x
< value_length
; x
++)
2381 value
[x
] = (char) (x
% 127);
2383 for (current_length
= 0; current_length
< value_length
; current_length
++)
2385 rc
= memcached_set(memc
, key
, strlen(key
),
2386 value
, current_length
,
2387 (time_t)0, (uint32_t)0);
2388 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
2390 string
= memcached_get(memc
, key
, strlen(key
),
2391 &string_length
, &flags
, &rc
);
2393 assert(rc
== MEMCACHED_SUCCESS
);
2394 assert(string_length
== current_length
);
2395 assert(!memcmp(string
, value
, string_length
));
2402 return TEST_SUCCESS
;
2406 Look for zero length value problems
2408 static test_return_t
user_supplied_bug15(memcached_st
*memc
)
2411 memcached_return rc
;
2412 const char *key
= "mykey";
2417 for (x
= 0; x
< 2; x
++)
2419 rc
= memcached_set(memc
, key
, strlen(key
),
2421 (time_t)0, (uint32_t)0);
2423 assert(rc
== MEMCACHED_SUCCESS
);
2425 value
= memcached_get(memc
, key
, strlen(key
),
2426 &length
, &flags
, &rc
);
2428 assert(rc
== MEMCACHED_SUCCESS
);
2429 assert(value
== NULL
);
2430 assert(length
== 0);
2433 value
= memcached_get(memc
, key
, strlen(key
),
2434 &length
, &flags
, &rc
);
2436 assert(rc
== MEMCACHED_SUCCESS
);
2437 assert(value
== NULL
);
2438 assert(length
== 0);
2442 return TEST_SUCCESS
;
2445 /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
2446 static test_return_t
user_supplied_bug16(memcached_st
*memc
)
2448 memcached_return rc
;
2449 const char *key
= "mykey";
2454 rc
= memcached_set(memc
, key
, strlen(key
),
2456 (time_t)0, UINT32_MAX
);
2458 assert(rc
== MEMCACHED_SUCCESS
);
2460 value
= memcached_get(memc
, key
, strlen(key
),
2461 &length
, &flags
, &rc
);
2463 assert(rc
== MEMCACHED_SUCCESS
);
2464 assert(value
== NULL
);
2465 assert(length
== 0);
2466 assert(flags
== UINT32_MAX
);
2468 return TEST_SUCCESS
;
2472 /* Check the validity of chinese key*/
2473 static test_return_t
user_supplied_bug17(memcached_st
*memc
)
2475 memcached_return rc
;
2476 const char *key
= "豆瓣";
2477 const char *value
="我们在炎热抑郁的夏天无法停止豆瓣";
2482 rc
= memcached_set(memc
, key
, strlen(key
),
2483 value
, strlen(value
),
2486 assert(rc
== MEMCACHED_SUCCESS
);
2488 value2
= memcached_get(memc
, key
, strlen(key
),
2489 &length
, &flags
, &rc
);
2491 assert(length
==strlen(value
));
2492 assert(rc
== MEMCACHED_SUCCESS
);
2493 assert(memcmp(value
, value2
, length
)==0);
2496 return TEST_SUCCESS
;
2504 static test_return_t
user_supplied_bug19(memcached_st
*memc
)
2507 memcached_server_st
*s
;
2508 memcached_return res
;
2512 m
= memcached_create(NULL
);
2513 memcached_server_add_with_weight(m
, "localhost", 11311, 100);
2514 memcached_server_add_with_weight(m
, "localhost", 11312, 100);
2516 s
= memcached_server_by_key(m
, "a", 1, &res
);
2517 memcached_server_free(s
);
2521 return TEST_SUCCESS
;
2524 /* CAS test from Andei */
2525 static test_return_t
user_supplied_bug20(memcached_st
*memc
)
2527 memcached_return status
;
2528 memcached_result_st
*result
, result_obj
;
2529 const char *key
= "abc";
2530 size_t key_len
= strlen("abc");
2531 const char *value
= "foobar";
2532 size_t value_len
= strlen(value
);
2534 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
2536 status
= memcached_set(memc
, key
, key_len
, value
, value_len
, (time_t)0, (uint32_t)0);
2537 assert(status
== MEMCACHED_SUCCESS
);
2539 status
= memcached_mget(memc
, &key
, &key_len
, 1);
2540 assert(status
== MEMCACHED_SUCCESS
);
2542 result
= memcached_result_create(memc
, &result_obj
);
2545 memcached_result_create(memc
, &result_obj
);
2546 result
= memcached_fetch_result(memc
, &result_obj
, &status
);
2549 assert(status
== MEMCACHED_SUCCESS
);
2551 memcached_result_free(result
);
2553 return TEST_SUCCESS
;
2556 #include "ketama_test_cases.h"
2557 static test_return_t
user_supplied_bug18(memcached_st
*trash
)
2559 memcached_return rc
;
2562 memcached_server_st
*server_pool
;
2567 memc
= memcached_create(NULL
);
2570 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2571 assert(rc
== MEMCACHED_SUCCESS
);
2573 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2576 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2577 assert(rc
== MEMCACHED_SUCCESS
);
2579 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2580 assert(value
== MEMCACHED_HASH_MD5
);
2582 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");
2583 memcached_server_push(memc
, server_pool
);
2585 /* verify that the server list was parsed okay. */
2586 assert(memc
->number_of_hosts
== 8);
2587 assert(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
2588 assert(server_pool
[0].port
== 11211);
2589 assert(server_pool
[0].weight
== 600);
2590 assert(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
2591 assert(server_pool
[2].port
== 11211);
2592 assert(server_pool
[2].weight
== 200);
2593 assert(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
2594 assert(server_pool
[7].port
== 11211);
2595 assert(server_pool
[7].weight
== 100);
2597 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
2598 * us test the boundary wraparound.
2600 assert(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
2602 /* verify the standard ketama set. */
2603 for (x
= 0; x
< 99; x
++)
2605 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
2606 char *hostname
= memc
->hosts
[server_idx
].hostname
;
2607 assert(strcmp(hostname
, ketama_test_cases
[x
].server
) == 0);
2610 memcached_server_list_free(server_pool
);
2611 memcached_free(memc
);
2613 return TEST_SUCCESS
;
2616 /* Large mget() of missing keys with binary proto
2618 * If many binary quiet commands (such as getq's in an mget) fill the output
2619 * buffer and the server chooses not to respond, memcached_flush hangs. See
2620 * http://lists.tangent.org/pipermail/libmemcached/2009-August/000918.html
2623 /* sighandler_t function that always asserts false */
2624 static void fail(int unused
__attribute__((unused
)))
2630 static test_return_t
_user_supplied_bug21(memcached_st
* memc
, size_t key_count
)
2632 memcached_return rc
;
2635 size_t* key_lengths
;
2636 void (*oldalarm
)(int);
2637 memcached_st
*memc_clone
;
2639 memc_clone
= memcached_clone(NULL
, memc
);
2642 /* only binproto uses getq for mget */
2643 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
2645 /* empty the cache to ensure misses (hence non-responses) */
2646 rc
= memcached_flush(memc_clone
, 0);
2647 assert(rc
== MEMCACHED_SUCCESS
);
2649 key_lengths
= calloc(key_count
, sizeof(size_t));
2650 keys
= calloc(key_count
, sizeof(char *));
2652 for (x
= 0; x
< key_count
; x
++)
2656 snprintf(buffer
, 30, "%u", x
);
2657 keys
[x
]= strdup(buffer
);
2658 key_lengths
[x
]= strlen(keys
[x
]);
2661 oldalarm
= signal(SIGALRM
, fail
);
2664 rc
= memcached_mget(memc_clone
, (const char **)keys
, key_lengths
, key_count
);
2665 assert(rc
== MEMCACHED_SUCCESS
);
2668 signal(SIGALRM
, oldalarm
);
2670 assert(fetch_all_results(memc
) == TEST_SUCCESS
);
2672 for (x
= 0; x
< key_count
; x
++)
2677 memcached_free(memc_clone
);
2679 return TEST_SUCCESS
;
2682 static memcached_return
pre_binary(memcached_st
*memc
);
2684 static test_return_t
user_supplied_bug21(memcached_st
*memc
)
2686 if (pre_binary(memc
) != MEMCACHED_SUCCESS
)
2687 return TEST_SKIPPED
;
2691 /* should work as of r580 */
2692 rc
= _user_supplied_bug21(memc
, 10);
2693 assert(rc
== TEST_SUCCESS
);
2695 /* should fail as of r580 */
2696 rc
= _user_supplied_bug21(memc
, 1000);
2697 assert(rc
== TEST_SUCCESS
);
2699 return TEST_SUCCESS
;
2702 static test_return_t
auto_eject_hosts(memcached_st
*trash
)
2706 memcached_return rc
;
2707 memcached_st
*memc
= memcached_create(NULL
);
2710 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2711 assert(rc
== MEMCACHED_SUCCESS
);
2713 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2716 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2717 assert(rc
== MEMCACHED_SUCCESS
);
2719 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2720 assert(value
== MEMCACHED_HASH_MD5
);
2722 /* server should be removed when in delay */
2723 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
, 1);
2724 assert(rc
== MEMCACHED_SUCCESS
);
2726 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
);
2729 memcached_server_st
*server_pool
;
2730 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");
2731 memcached_server_push(memc
, server_pool
);
2733 /* verify that the server list was parsed okay. */
2734 assert(memc
->number_of_hosts
== 8);
2735 assert(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
2736 assert(server_pool
[0].port
== 11211);
2737 assert(server_pool
[0].weight
== 600);
2738 assert(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
2739 assert(server_pool
[2].port
== 11211);
2740 assert(server_pool
[2].weight
== 200);
2741 assert(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
2742 assert(server_pool
[7].port
== 11211);
2743 assert(server_pool
[7].weight
== 100);
2745 memc
->hosts
[2].next_retry
= time(NULL
) + 15;
2746 memc
->next_distribution_rebuild
= time(NULL
) - 1;
2748 for (int x
= 0; x
< 99; x
++)
2750 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
2751 assert(server_idx
!= 2);
2754 /* and re-added when it's back. */
2755 memc
->hosts
[2].next_retry
= time(NULL
) - 1;
2756 memc
->next_distribution_rebuild
= time(NULL
) - 1;
2757 run_distribution(memc
);
2758 for (int x
= 0; x
< 99; x
++)
2760 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
2761 char *hostname
= memc
->hosts
[server_idx
].hostname
;
2762 assert(strcmp(hostname
, ketama_test_cases
[x
].server
) == 0);
2765 memcached_server_list_free(server_pool
);
2766 memcached_free(memc
);
2768 return TEST_SUCCESS
;
2771 static test_return_t
output_ketama_weighted_keys(memcached_st
*trash
)
2775 memcached_return rc
;
2776 memcached_st
*memc
= memcached_create(NULL
);
2780 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2781 assert(rc
== MEMCACHED_SUCCESS
);
2783 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2786 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2787 assert(rc
== MEMCACHED_SUCCESS
);
2789 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2790 assert(value
== MEMCACHED_HASH_MD5
);
2793 assert(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_COMPAT_MODE
,
2794 MEMCACHED_KETAMA_COMPAT_SPY
) == MEMCACHED_SUCCESS
);
2796 memcached_server_st
*server_pool
;
2797 server_pool
= memcached_servers_parse("10.0.1.1:11211,10.0.1.2:11211,10.0.1.3:11211,10.0.1.4:11211,10.0.1.5:11211,10.0.1.6:11211,10.0.1.7:11211,10.0.1.8:11211,192.168.1.1:11211,192.168.100.1:11211");
2798 memcached_server_push(memc
, server_pool
);
2801 if ((fp
= fopen("ketama_keys.txt", "w")))
2805 printf("cannot write to file ketama_keys.txt");
2806 return TEST_FAILURE
;
2809 for (int x
= 0; x
< 10000; x
++)
2812 sprintf(key
, "%d", x
);
2814 uint32_t server_idx
= memcached_generate_hash(memc
, key
, strlen(key
));
2815 char *hostname
= memc
->hosts
[server_idx
].hostname
;
2816 unsigned int port
= memc
->hosts
[server_idx
].port
;
2817 fprintf(fp
, "key %s is on host /%s:%u\n", key
, hostname
, port
);
2820 memcached_server_list_free(server_pool
);
2821 memcached_free(memc
);
2823 return TEST_SUCCESS
;
2827 static test_return_t
result_static(memcached_st
*memc
)
2829 memcached_result_st result
;
2830 memcached_result_st
*result_ptr
;
2832 result_ptr
= memcached_result_create(memc
, &result
);
2833 assert(result
.is_allocated
== false);
2835 memcached_result_free(&result
);
2837 return TEST_SUCCESS
;
2840 static test_return_t
result_alloc(memcached_st
*memc
)
2842 memcached_result_st
*result
;
2844 result
= memcached_result_create(memc
, NULL
);
2846 memcached_result_free(result
);
2848 return TEST_SUCCESS
;
2851 static test_return_t
string_static_null(memcached_st
*memc
)
2853 memcached_string_st string
;
2854 memcached_string_st
*string_ptr
;
2856 string_ptr
= memcached_string_create(memc
, &string
, 0);
2857 assert(string
.is_allocated
== false);
2859 memcached_string_free(&string
);
2861 return TEST_SUCCESS
;
2864 static test_return_t
string_alloc_null(memcached_st
*memc
)
2866 memcached_string_st
*string
;
2868 string
= memcached_string_create(memc
, NULL
, 0);
2870 memcached_string_free(string
);
2872 return TEST_SUCCESS
;
2875 static test_return_t
string_alloc_with_size(memcached_st
*memc
)
2877 memcached_string_st
*string
;
2879 string
= memcached_string_create(memc
, NULL
, 1024);
2881 memcached_string_free(string
);
2883 return TEST_SUCCESS
;
2886 static test_return_t
string_alloc_with_size_toobig(memcached_st
*memc
)
2888 memcached_string_st
*string
;
2890 string
= memcached_string_create(memc
, NULL
, SIZE_MAX
);
2891 assert(string
== NULL
);
2893 return TEST_SUCCESS
;
2896 static test_return_t
string_alloc_append(memcached_st
*memc
)
2899 char buffer
[SMALL_STRING_LEN
];
2900 memcached_string_st
*string
;
2902 /* Ring the bell! */
2903 memset(buffer
, 6, SMALL_STRING_LEN
);
2905 string
= memcached_string_create(memc
, NULL
, 100);
2908 for (x
= 0; x
< 1024; x
++)
2910 memcached_return rc
;
2911 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
2912 assert(rc
== MEMCACHED_SUCCESS
);
2914 memcached_string_free(string
);
2916 return TEST_SUCCESS
;
2919 static test_return_t
string_alloc_append_toobig(memcached_st
*memc
)
2921 memcached_return rc
;
2923 char buffer
[SMALL_STRING_LEN
];
2924 memcached_string_st
*string
;
2926 /* Ring the bell! */
2927 memset(buffer
, 6, SMALL_STRING_LEN
);
2929 string
= memcached_string_create(memc
, NULL
, 100);
2932 for (x
= 0; x
< 1024; x
++)
2934 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
2935 assert(rc
== MEMCACHED_SUCCESS
);
2937 rc
= memcached_string_append(string
, buffer
, SIZE_MAX
);
2938 assert(rc
== MEMCACHED_MEMORY_ALLOCATION_FAILURE
);
2939 memcached_string_free(string
);
2941 return TEST_SUCCESS
;
2944 static test_return_t
cleanup_pairs(memcached_st
*memc
__attribute__((unused
)))
2946 pairs_free(global_pairs
);
2948 return TEST_SUCCESS
;
2951 static test_return_t
generate_pairs(memcached_st
*memc
__attribute__((unused
)))
2953 unsigned long long x
;
2954 global_pairs
= pairs_generate(GLOBAL_COUNT
, 400);
2955 global_count
= GLOBAL_COUNT
;
2957 for (x
= 0; x
< global_count
; x
++)
2959 global_keys
[x
]= global_pairs
[x
].key
;
2960 global_keys_length
[x
]= global_pairs
[x
].key_length
;
2963 return TEST_SUCCESS
;
2966 static test_return_t
generate_large_pairs(memcached_st
*memc
__attribute__((unused
)))
2968 unsigned long long x
;
2969 global_pairs
= pairs_generate(GLOBAL2_COUNT
, MEMCACHED_MAX_BUFFER
+10);
2970 global_count
= GLOBAL2_COUNT
;
2972 for (x
= 0; x
< global_count
; x
++)
2974 global_keys
[x
]= global_pairs
[x
].key
;
2975 global_keys_length
[x
]= global_pairs
[x
].key_length
;
2978 return TEST_SUCCESS
;
2981 static test_return_t
generate_data(memcached_st
*memc
)
2983 execute_set(memc
, global_pairs
, global_count
);
2985 return TEST_SUCCESS
;
2988 static test_return_t
generate_data_with_stats(memcached_st
*memc
)
2990 memcached_stat_st
*stat_p
;
2991 memcached_return rc
;
2992 uint32_t host_index
= 0;
2993 execute_set(memc
, global_pairs
, global_count
);
2995 //TODO: hosts used size stats
2996 stat_p
= memcached_stat(memc
, NULL
, &rc
);
2999 for (host_index
= 0; host_index
< SERVERS_TO_CREATE
; host_index
++)
3001 /* This test was changes so that "make test" would work properlly */
3003 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
);
3005 assert((unsigned long long)(stat_p
+ host_index
)->bytes
);
3008 memcached_stat_free(NULL
, stat_p
);
3010 return TEST_SUCCESS
;
3012 static test_return_t
generate_buffer_data(memcached_st
*memc
)
3017 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
3018 generate_data(memc
);
3020 return TEST_SUCCESS
;
3023 static test_return_t
get_read_count(memcached_st
*memc
)
3026 memcached_return rc
;
3027 memcached_st
*memc_clone
;
3029 memc_clone
= memcached_clone(NULL
, memc
);
3032 memcached_server_add_with_weight(memc_clone
, "localhost", 6666, 0);
3036 size_t return_value_length
;
3040 for (x
= count
= 0; x
< global_count
; x
++)
3042 return_value
= memcached_get(memc_clone
, global_keys
[x
], global_keys_length
[x
],
3043 &return_value_length
, &flags
, &rc
);
3044 if (rc
== MEMCACHED_SUCCESS
)
3053 memcached_free(memc_clone
);
3055 return TEST_SUCCESS
;
3058 static test_return_t
get_read(memcached_st
*memc
)
3061 memcached_return rc
;
3065 size_t return_value_length
;
3068 for (x
= 0; x
< global_count
; x
++)
3070 return_value
= memcached_get(memc
, global_keys
[x
], global_keys_length
[x
],
3071 &return_value_length
, &flags
, &rc
);
3073 assert(return_value);
3074 assert(rc == MEMCACHED_SUCCESS);
3076 if (rc
== MEMCACHED_SUCCESS
&& return_value
)
3081 return TEST_SUCCESS
;
3084 static test_return_t
mget_read(memcached_st
*memc
)
3086 memcached_return rc
;
3088 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
3089 assert(rc
== MEMCACHED_SUCCESS
);
3090 assert(fetch_all_results(memc
) == TEST_SUCCESS
);
3092 return TEST_SUCCESS
;
3095 static test_return_t
mget_read_result(memcached_st
*memc
)
3097 memcached_return rc
;
3099 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
3100 assert(rc
== MEMCACHED_SUCCESS
);
3101 /* Turn this into a help function */
3103 memcached_result_st results_obj
;
3104 memcached_result_st
*results
;
3106 results
= memcached_result_create(memc
, &results_obj
);
3108 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
3111 assert(rc
== MEMCACHED_SUCCESS
);
3114 memcached_result_free(&results_obj
);
3117 return TEST_SUCCESS
;
3120 static test_return_t
mget_read_function(memcached_st
*memc
)
3122 memcached_return rc
;
3123 unsigned int counter
;
3124 memcached_execute_function callbacks
[1];
3126 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
3127 assert(rc
== MEMCACHED_SUCCESS
);
3129 callbacks
[0]= &callback_counter
;
3131 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
3133 return TEST_SUCCESS
;
3136 static test_return_t
delete_generate(memcached_st
*memc
)
3140 for (x
= 0; x
< global_count
; x
++)
3142 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3145 return TEST_SUCCESS
;
3148 static test_return_t
delete_buffer_generate(memcached_st
*memc
)
3154 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
3156 for (x
= 0; x
< global_count
; x
++)
3158 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3161 return TEST_SUCCESS
;
3164 static test_return_t
add_host_test1(memcached_st
*memc
)
3167 memcached_return rc
;
3168 char servername
[]= "0.example.com";
3169 memcached_server_st
*servers
;
3171 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
3173 assert(1 == memcached_server_list_count(servers
));
3175 for (x
= 2; x
< 20; x
++)
3177 char buffer
[SMALL_STRING_LEN
];
3179 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
3180 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
3182 assert(rc
== MEMCACHED_SUCCESS
);
3183 assert(x
== memcached_server_list_count(servers
));
3186 rc
= memcached_server_push(memc
, servers
);
3187 assert(rc
== MEMCACHED_SUCCESS
);
3188 rc
= memcached_server_push(memc
, servers
);
3189 assert(rc
== MEMCACHED_SUCCESS
);
3191 memcached_server_list_free(servers
);
3193 return TEST_SUCCESS
;
3196 static memcached_return
pre_nonblock(memcached_st
*memc
)
3198 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3200 return MEMCACHED_SUCCESS
;
3203 static memcached_return
pre_nonblock_binary(memcached_st
*memc
)
3205 memcached_return rc
= MEMCACHED_FAILURE
;
3206 memcached_st
*memc_clone
;
3208 memc_clone
= memcached_clone(NULL
, memc
);
3210 // The memcached_version needs to be done on a clone, because the server
3211 // will not toggle protocol on an connection.
3212 memcached_version(memc_clone
);
3214 if (memc_clone
->hosts
[0].major_version
>= 1 && memc_clone
->hosts
[0].minor_version
> 2)
3216 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3217 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3218 assert(rc
== MEMCACHED_SUCCESS
);
3219 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3222 memcached_free(memc_clone
);
3226 static memcached_return
pre_murmur(memcached_st
*memc
)
3228 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
3230 return MEMCACHED_SUCCESS
;
3233 static memcached_return
pre_jenkins(memcached_st
*memc
)
3235 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_JENKINS
);
3237 return MEMCACHED_SUCCESS
;
3241 static memcached_return
pre_md5(memcached_st
*memc
)
3243 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MD5
);
3245 return MEMCACHED_SUCCESS
;
3248 static memcached_return
pre_crc(memcached_st
*memc
)
3250 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_CRC
);
3252 return MEMCACHED_SUCCESS
;
3255 static memcached_return
pre_hsieh(memcached_st
*memc
)
3257 #ifdef HAVE_HSIEH_HASH
3258 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_HSIEH
);
3259 return MEMCACHED_SUCCESS
;
3262 return MEMCACHED_FAILURE
;
3266 static memcached_return
pre_hash_fnv1_64(memcached_st
*memc
)
3268 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_64
);
3270 return MEMCACHED_SUCCESS
;
3273 static memcached_return
pre_hash_fnv1a_64(memcached_st
*memc
)
3275 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_64
);
3277 return MEMCACHED_SUCCESS
;
3280 static memcached_return
pre_hash_fnv1_32(memcached_st
*memc
)
3282 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_32
);
3284 return MEMCACHED_SUCCESS
;
3287 static memcached_return
pre_hash_fnv1a_32(memcached_st
*memc
)
3289 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_32
);
3291 return MEMCACHED_SUCCESS
;
3294 static memcached_return
pre_behavior_ketama(memcached_st
*memc
)
3296 memcached_return rc
;
3299 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA
, 1);
3300 assert(rc
== MEMCACHED_SUCCESS
);
3302 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA
);
3305 return MEMCACHED_SUCCESS
;
3308 static memcached_return
pre_behavior_ketama_weighted(memcached_st
*memc
)
3310 memcached_return rc
;
3313 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
3314 assert(rc
== MEMCACHED_SUCCESS
);
3316 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
3319 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
3320 assert(rc
== MEMCACHED_SUCCESS
);
3322 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
3323 assert(value
== MEMCACHED_HASH_MD5
);
3324 return MEMCACHED_SUCCESS
;
3327 static memcached_return
pre_binary(memcached_st
*memc
)
3329 memcached_return rc
= MEMCACHED_FAILURE
;
3330 memcached_st
*memc_clone
;
3332 memc_clone
= memcached_clone(NULL
, memc
);
3334 // The memcached_version needs to be done on a clone, because the server
3335 // will not toggle protocol on an connection.
3336 memcached_version(memc_clone
);
3338 if (memc_clone
->hosts
[0].major_version
>= 1 && memc_clone
->hosts
[0].minor_version
> 2)
3340 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3341 assert(rc
== MEMCACHED_SUCCESS
);
3342 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3345 memcached_free(memc_clone
);
3350 static memcached_return
pre_replication(memcached_st
*memc
)
3352 if (pre_binary(memc
) != MEMCACHED_SUCCESS
)
3353 return MEMCACHED_FAILURE
;
3356 * Make sure that we store the item on all servers
3357 * (master + replicas == number of servers)
3359 memcached_return rc
;
3360 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
,
3361 memc
->number_of_hosts
- 1);
3362 assert(rc
== MEMCACHED_SUCCESS
);
3363 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
) == memc
->number_of_hosts
- 1);
3368 static memcached_return
pre_replication_noblock(memcached_st
*memc
)
3370 memcached_return rc
= MEMCACHED_FAILURE
;
3371 if (pre_replication(memc
) == MEMCACHED_SUCCESS
&&
3372 pre_nonblock(memc
) == MEMCACHED_SUCCESS
)
3373 rc
= MEMCACHED_SUCCESS
;
3378 static void my_free(memcached_st
*ptr
__attribute__((unused
)), void *mem
)
3383 static void *my_malloc(memcached_st
*ptr
__attribute__((unused
)), const size_t size
)
3385 void *ret
= malloc(size
);
3387 memset(ret
, 0xff, size
);
3392 static void *my_realloc(memcached_st
*ptr
__attribute__((unused
)), void *mem
, const size_t size
)
3394 return realloc(mem
, size
);
3397 static void *my_calloc(memcached_st
*ptr
__attribute__((unused
)), size_t nelem
, const size_t size
)
3399 return calloc(nelem
, size
);
3402 static memcached_return
set_prefix(memcached_st
*memc
)
3404 memcached_return rc
;
3405 const char *key
= "mine";
3408 /* Make sure be default none exists */
3409 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3410 assert(rc
== MEMCACHED_FAILURE
);
3412 /* Test a clean set */
3413 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3414 assert(rc
== MEMCACHED_SUCCESS
);
3416 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3417 assert(memcmp(value
, key
, 4) == 0);
3418 assert(rc
== MEMCACHED_SUCCESS
);
3420 /* Test that we can turn it off */
3421 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3422 assert(rc
== MEMCACHED_SUCCESS
);
3424 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3425 assert(rc
== MEMCACHED_FAILURE
);
3427 /* Now setup for main test */
3428 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3429 assert(rc
== MEMCACHED_SUCCESS
);
3431 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3432 assert(rc
== MEMCACHED_SUCCESS
);
3433 assert(memcmp(value
, key
, 4) == 0);
3435 /* Set to Zero, and then Set to something too large */
3438 memset(long_key
, 0, 255);
3440 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3441 assert(rc
== MEMCACHED_SUCCESS
);
3443 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3444 assert(rc
== MEMCACHED_FAILURE
);
3445 assert(value
== NULL
);
3447 /* Test a long key for failure */
3448 /* TODO, extend test to determine based on setting, what result should be */
3449 strcpy(long_key
, "Thisismorethentheallottednumberofcharacters");
3450 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3451 //assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
3452 assert(rc
== MEMCACHED_SUCCESS
);
3454 /* Now test a key with spaces (which will fail from long key, since bad key is not set) */
3455 strcpy(long_key
, "This is more then the allotted number of characters");
3456 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3457 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3459 /* Test for a bad prefix, but with a short key */
3460 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, 1);
3461 assert(rc
== MEMCACHED_SUCCESS
);
3463 strcpy(long_key
, "dog cat");
3464 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3465 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3468 return MEMCACHED_SUCCESS
;
3471 #ifdef MEMCACHED_ENABLE_DEPRECATED
3472 static memcached_return
deprecated_set_memory_alloc(memcached_st
*memc
)
3474 void *test_ptr
= NULL
;
3477 memcached_malloc_function malloc_cb
=
3478 (memcached_malloc_function
)my_malloc
;
3479 cb_ptr
= *(void **)&malloc_cb
;
3480 memcached_return rc
;
3482 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, cb_ptr
);
3483 assert(rc
== MEMCACHED_SUCCESS
);
3484 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
3485 assert(rc
== MEMCACHED_SUCCESS
);
3486 assert(test_ptr
== cb_ptr
);
3490 memcached_realloc_function realloc_cb
=
3491 (memcached_realloc_function
)my_realloc
;
3492 cb_ptr
= *(void **)&realloc_cb
;
3493 memcached_return rc
;
3495 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, cb_ptr
);
3496 assert(rc
== MEMCACHED_SUCCESS
);
3497 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
3498 assert(rc
== MEMCACHED_SUCCESS
);
3499 assert(test_ptr
== cb_ptr
);
3503 memcached_free_function free_cb
=
3504 (memcached_free_function
)my_free
;
3505 cb_ptr
= *(void **)&free_cb
;
3506 memcached_return rc
;
3508 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, cb_ptr
);
3509 assert(rc
== MEMCACHED_SUCCESS
);
3510 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
3511 assert(rc
== MEMCACHED_SUCCESS
);
3512 assert(test_ptr
== cb_ptr
);
3514 return MEMCACHED_SUCCESS
;
3518 static memcached_return
set_memory_alloc(memcached_st
*memc
)
3520 memcached_return rc
;
3521 rc
= memcached_set_memory_allocators(memc
, NULL
, my_free
,
3522 my_realloc
, my_calloc
);
3523 assert(rc
== MEMCACHED_FAILURE
);
3525 rc
= memcached_set_memory_allocators(memc
, my_malloc
, my_free
,
3526 my_realloc
, my_calloc
);
3528 memcached_malloc_function mem_malloc
;
3529 memcached_free_function mem_free
;
3530 memcached_realloc_function mem_realloc
;
3531 memcached_calloc_function mem_calloc
;
3532 memcached_get_memory_allocators(memc
, &mem_malloc
, &mem_free
,
3533 &mem_realloc
, &mem_calloc
);
3535 assert(mem_malloc
== my_malloc
);
3536 assert(mem_realloc
== my_realloc
);
3537 assert(mem_calloc
== my_calloc
);
3538 assert(mem_free
== my_free
);
3540 return MEMCACHED_SUCCESS
;
3543 static memcached_return
enable_consistent(memcached_st
*memc
)
3545 memcached_server_distribution value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
3546 memcached_hash hash
;
3547 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
3548 if (pre_hsieh(memc
) != MEMCACHED_SUCCESS
)
3549 return MEMCACHED_FAILURE
;
3551 value
= (memcached_server_distribution
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
3552 assert(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
3554 hash
= (memcached_hash
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
3555 assert(hash
== MEMCACHED_HASH_HSIEH
);
3558 return MEMCACHED_SUCCESS
;
3561 static memcached_return
enable_cas(memcached_st
*memc
)
3563 unsigned int set
= 1;
3565 memcached_version(memc
);
3567 if ((memc
->hosts
[0].major_version
>= 1 && (memc
->hosts
[0].minor_version
== 2 && memc
->hosts
[0].micro_version
>= 4))
3568 || memc
->hosts
[0].minor_version
> 2)
3570 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
3572 return MEMCACHED_SUCCESS
;
3575 return MEMCACHED_FAILURE
;
3578 static memcached_return
check_for_1_2_3(memcached_st
*memc
)
3580 memcached_version(memc
);
3582 if ((memc
->hosts
[0].major_version
>= 1 && (memc
->hosts
[0].minor_version
== 2 && memc
->hosts
[0].micro_version
>= 4))
3583 || memc
->hosts
[0].minor_version
> 2)
3584 return MEMCACHED_SUCCESS
;
3586 return MEMCACHED_FAILURE
;
3589 static memcached_return
pre_unix_socket(memcached_st
*memc
)
3591 memcached_return rc
;
3594 memcached_server_list_free(memc
->hosts
);
3596 memc
->number_of_hosts
= 0;
3598 if (stat("/tmp/memcached.socket", &buf
))
3599 return MEMCACHED_FAILURE
;
3601 rc
= memcached_server_add_unix_socket_with_weight(memc
, "/tmp/memcached.socket", 0);
3606 static memcached_return
pre_nodelay(memcached_st
*memc
)
3608 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3609 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
3611 return MEMCACHED_SUCCESS
;
3614 static memcached_return
pre_settimer(memcached_st
*memc
)
3616 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
3617 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
3619 return MEMCACHED_SUCCESS
;
3622 static memcached_return
poll_timeout(memcached_st
*memc
)
3628 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
3630 timeout
= (size_t)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
3632 assert(timeout
== 100);
3634 return MEMCACHED_SUCCESS
;
3637 static test_return_t
noreply_test(memcached_st
*memc
)
3639 memcached_return ret
;
3640 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
3641 assert(ret
== MEMCACHED_SUCCESS
);
3642 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
3643 assert(ret
== MEMCACHED_SUCCESS
);
3644 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
3645 assert(ret
== MEMCACHED_SUCCESS
);
3646 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NOREPLY
) == 1);
3647 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
) == 1);
3648 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
) == 1);
3650 for (int count
=0; count
< 5; ++count
)
3652 for (int x
=0; x
< 100; ++x
)
3655 size_t len
= (size_t)sprintf(key
, "%d", x
);
3659 ret
=memcached_add(memc
, key
, len
, key
, len
, 0, 0);
3662 ret
=memcached_replace(memc
, key
, len
, key
, len
, 0, 0);
3665 ret
=memcached_set(memc
, key
, len
, key
, len
, 0, 0);
3668 ret
=memcached_append(memc
, key
, len
, key
, len
, 0, 0);
3671 ret
=memcached_prepend(memc
, key
, len
, key
, len
, 0, 0);
3677 assert(ret
== MEMCACHED_SUCCESS
|| ret
== MEMCACHED_BUFFERED
);
3681 ** NOTE: Don't ever do this in your code! this is not a supported use of the
3682 ** API and is _ONLY_ done this way to verify that the library works the
3683 ** way it is supposed to do!!!!
3686 for (uint32_t x
=0; x
< memc
->number_of_hosts
; ++x
)
3687 no_msg
+=(int)(memc
->hosts
[x
].cursor_active
);
3689 assert(no_msg
== 0);
3690 assert(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
3693 ** Now validate that all items was set properly!
3695 for (int x
=0; x
< 100; ++x
)
3698 size_t len
= (size_t)sprintf(key
, "%d", x
);
3701 char* value
=memcached_get(memc
, key
, strlen(key
),
3702 &length
, &flags
, &ret
);
3703 assert(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
3706 case 0: /* FALLTHROUGH */
3707 case 1: /* FALLTHROUGH */
3709 assert(strncmp(value
, key
, len
) == 0);
3710 assert(len
== length
);
3713 assert(length
== len
* 2);
3716 assert(length
== len
* 3);
3726 /* Try setting an illegal cas value (should not return an error to
3727 * the caller (because we don't expect a return message from the server)
3729 const char* keys
[]= {"0"};
3730 size_t lengths
[]= {1};
3733 memcached_result_st results_obj
;
3734 memcached_result_st
*results
;
3735 ret
= memcached_mget(memc
, keys
, lengths
, 1);
3736 assert(ret
== MEMCACHED_SUCCESS
);
3738 results
= memcached_result_create(memc
, &results_obj
);
3740 results
= memcached_fetch_result(memc
, &results_obj
, &ret
);
3742 assert(ret
== MEMCACHED_SUCCESS
);
3743 uint64_t cas
= memcached_result_cas(results
);
3744 memcached_result_free(&results_obj
);
3746 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
3747 assert(ret
== MEMCACHED_SUCCESS
);
3750 * The item will have a new cas value, so try to set it again with the old
3751 * value. This should fail!
3753 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
3754 assert(ret
== MEMCACHED_SUCCESS
);
3755 assert(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
3756 char* value
=memcached_get(memc
, keys
[0], lengths
[0], &length
, &flags
, &ret
);
3757 assert(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
3760 return TEST_SUCCESS
;
3763 static test_return_t
analyzer_test(memcached_st
*memc
)
3765 memcached_return rc
;
3766 memcached_stat_st
*memc_stat
;
3767 memcached_analysis_st
*report
;
3769 memc_stat
= memcached_stat(memc
, NULL
, &rc
);
3770 assert(rc
== MEMCACHED_SUCCESS
);
3773 report
= memcached_analyze(memc
, memc_stat
, &rc
);
3774 assert(rc
== MEMCACHED_SUCCESS
);
3778 memcached_stat_free(NULL
, memc_stat
);
3780 return TEST_SUCCESS
;
3783 /* Count the objects */
3784 static memcached_return
callback_dump_counter(memcached_st
*ptr
__attribute__((unused
)),
3785 const char *key
__attribute__((unused
)),
3786 size_t key_length
__attribute__((unused
)),
3789 uint32_t *counter
= (uint32_t *)context
;
3791 *counter
= *counter
+ 1;
3793 return MEMCACHED_SUCCESS
;
3796 static test_return_t
dump_test(memcached_st
*memc
)
3798 memcached_return rc
;
3799 uint32_t counter
= 0;
3800 memcached_dump_func callbacks
[1];
3801 test_return_t main_rc
;
3803 callbacks
[0]= &callback_dump_counter
;
3805 /* No support for Binary protocol yet */
3806 if (memc
->flags
& MEM_BINARY_PROTOCOL
)
3807 return TEST_SUCCESS
;
3809 main_rc
= set_test3(memc
);
3811 assert (main_rc
== TEST_SUCCESS
);
3813 rc
= memcached_dump(memc
, callbacks
, (void *)&counter
, 1);
3814 assert(rc
== MEMCACHED_SUCCESS
);
3816 /* We may have more then 32 if our previous flush has not completed */
3817 assert(counter
>= 32);
3819 return TEST_SUCCESS
;
3822 #ifdef HAVE_LIBMEMCACHEDUTIL
3823 static void* connection_release(void *arg
) {
3825 memcached_pool_st
* pool
;
3830 assert(memcached_pool_push(resource
->pool
, resource
->mmc
) == MEMCACHED_SUCCESS
);
3834 static test_return_t
connection_pool_test(memcached_st
*memc
)
3836 memcached_pool_st
* pool
= memcached_pool_create(memc
, 5, 10);
3837 assert(pool
!= NULL
);
3838 memcached_st
* mmc
[10];
3839 memcached_return rc
;
3841 for (int x
= 0; x
< 10; ++x
) {
3842 mmc
[x
]= memcached_pool_pop(pool
, false, &rc
);
3843 assert(mmc
[x
] != NULL
);
3844 assert(rc
== MEMCACHED_SUCCESS
);
3847 assert(memcached_pool_pop(pool
, false, &rc
) == NULL
);
3848 assert(rc
== MEMCACHED_SUCCESS
);
3852 memcached_pool_st
* pool
;
3854 } item
= { .pool
= pool
, .mmc
= mmc
[9] };
3855 pthread_create(&tid
, NULL
, connection_release
, &item
);
3856 mmc
[9]= memcached_pool_pop(pool
, true, &rc
);
3857 assert(rc
== MEMCACHED_SUCCESS
);
3858 pthread_join(tid
, NULL
);
3859 assert(mmc
[9] == item
.mmc
);
3860 const char *key
= "key";
3861 size_t keylen
= strlen(key
);
3863 // verify that I can do ops with all connections
3864 rc
= memcached_set(mmc
[0], key
, keylen
, "0", 1, 0, 0);
3865 assert(rc
== MEMCACHED_SUCCESS
);
3867 for (unsigned int x
= 0; x
< 10; ++x
) {
3868 uint64_t number_value
;
3869 rc
= memcached_increment(mmc
[x
], key
, keylen
, 1, &number_value
);
3870 assert(rc
== MEMCACHED_SUCCESS
);
3871 assert(number_value
== (x
+1));
3875 for (int x
= 0; x
< 10; ++x
)
3876 assert(memcached_pool_push(pool
, mmc
[x
]) == MEMCACHED_SUCCESS
);
3879 /* verify that I can set behaviors on the pool when I don't have all
3880 * of the connections in the pool. It should however be enabled
3881 * when I push the item into the pool
3883 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
3884 assert(mmc
[0] != NULL
);
3886 rc
= memcached_pool_behavior_set(pool
, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
, 9999);
3887 assert(rc
== MEMCACHED_SUCCESS
);
3889 mmc
[1]= memcached_pool_pop(pool
, false, &rc
);
3890 assert(mmc
[1] != NULL
);
3892 assert(memcached_behavior_get(mmc
[1], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
) == 9999);
3893 assert(memcached_pool_push(pool
, mmc
[1]) == MEMCACHED_SUCCESS
);
3894 assert(memcached_pool_push(pool
, mmc
[0]) == MEMCACHED_SUCCESS
);
3896 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
3897 assert(memcached_behavior_get(mmc
[0], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
) == 9999);
3898 assert(memcached_pool_push(pool
, mmc
[0]) == MEMCACHED_SUCCESS
);
3901 assert(memcached_pool_destroy(pool
) == memc
);
3902 return TEST_SUCCESS
;
3906 static test_return_t
replication_set_test(memcached_st
*memc
)
3908 memcached_return rc
;
3909 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
3910 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 0);
3912 rc
= memcached_set(memc
, "bubba", 5, "0", 1, 0, 0);
3913 assert(rc
== MEMCACHED_SUCCESS
);
3916 ** We are using the quiet commands to store the replicas, so we need
3917 ** to ensure that all of them are processed before we can continue.
3918 ** In the test we go directly from storing the object to trying to
3919 ** receive the object from all of the different servers, so we
3920 ** could end up in a race condition (the memcached server hasn't yet
3921 ** processed the quiet command from the replication set when it process
3922 ** the request from the other client (created by the clone)). As a
3923 ** workaround for that we call memcached_quit to send the quit command
3924 ** to the server and wait for the response ;-) If you use the test code
3925 ** as an example for your own code, please note that you shouldn't need
3928 memcached_quit(memc
);
3931 ** "bubba" should now be stored on all of our servers. We don't have an
3932 ** easy to use API to address each individual server, so I'll just iterate
3933 ** through a bunch of "master keys" and I should most likely hit all of the
3936 for (int x
= 'a'; x
<= 'z'; ++x
)
3938 char key
[2]= { [0]= (char)x
};
3941 char *val
= memcached_get_by_key(memc_clone
, key
, 1, "bubba", 5,
3943 assert(rc
== MEMCACHED_SUCCESS
);
3944 assert(val
!= NULL
);
3948 memcached_free(memc_clone
);
3950 return TEST_SUCCESS
;
3953 static test_return_t
replication_get_test(memcached_st
*memc
)
3955 memcached_return rc
;
3958 * Don't do the following in your code. I am abusing the internal details
3959 * within the library, and this is not a supported interface.
3960 * This is to verify correct behavior in the library
3962 for (uint32_t host
= 0; host
< memc
->number_of_hosts
; ++host
)
3964 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
3965 memc_clone
->hosts
[host
].port
= 0;
3967 for (int x
= 'a'; x
<= 'z'; ++x
)
3969 char key
[2]= { [0]= (char)x
};
3972 char *val
= memcached_get_by_key(memc_clone
, key
, 1, "bubba", 5,
3974 assert(rc
== MEMCACHED_SUCCESS
);
3975 assert(val
!= NULL
);
3979 memcached_free(memc_clone
);
3982 return TEST_SUCCESS
;
3985 static test_return_t
replication_mget_test(memcached_st
*memc
)
3987 memcached_return rc
;
3988 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
3989 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 0);
3991 const char *keys
[]= { "bubba", "key1", "key2", "key3" };
3992 size_t len
[]= { 5, 4, 4, 4 };
3994 for (int x
=0; x
< 4; ++x
)
3996 rc
= memcached_set(memc
, keys
[x
], len
[x
], "0", 1, 0, 0);
3997 assert(rc
== MEMCACHED_SUCCESS
);
4001 ** We are using the quiet commands to store the replicas, so we need
4002 ** to ensure that all of them are processed before we can continue.
4003 ** In the test we go directly from storing the object to trying to
4004 ** receive the object from all of the different servers, so we
4005 ** could end up in a race condition (the memcached server hasn't yet
4006 ** processed the quiet command from the replication set when it process
4007 ** the request from the other client (created by the clone)). As a
4008 ** workaround for that we call memcached_quit to send the quit command
4009 ** to the server and wait for the response ;-) If you use the test code
4010 ** as an example for your own code, please note that you shouldn't need
4013 memcached_quit(memc
);
4016 * Don't do the following in your code. I am abusing the internal details
4017 * within the library, and this is not a supported interface.
4018 * This is to verify correct behavior in the library
4020 memcached_result_st result_obj
;
4021 for (uint32_t host
= 0; host
< memc_clone
->number_of_hosts
; host
++)
4023 memcached_st
*new_clone
= memcached_clone(NULL
, memc
);
4024 new_clone
->hosts
[host
].port
= 0;
4026 for (int x
= 'a'; x
<= 'z'; ++x
)
4028 const char key
[2]= { [0]= (const char)x
};
4030 rc
= memcached_mget_by_key(new_clone
, key
, 1, keys
, len
, 4);
4031 assert(rc
== MEMCACHED_SUCCESS
);
4033 memcached_result_st
*results
= memcached_result_create(new_clone
, &result_obj
);
4037 while ((results
= memcached_fetch_result(new_clone
, &result_obj
, &rc
)) != NULL
)
4042 memcached_result_free(&result_obj
);
4045 memcached_free(new_clone
);
4048 memcached_free(memc_clone
);
4050 return TEST_SUCCESS
;
4053 static test_return_t
replication_delete_test(memcached_st
*memc
)
4055 memcached_return rc
;
4056 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4057 /* Delete the items from all of the servers except 1 */
4058 uint64_t repl
= memcached_behavior_get(memc
,
4059 MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
);
4060 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, --repl
);
4062 const char *keys
[]= { "bubba", "key1", "key2", "key3" };
4063 size_t len
[]= { 5, 4, 4, 4 };
4065 for (int x
=0; x
< 4; ++x
)
4067 rc
= memcached_delete_by_key(memc
, keys
[0], len
[0], keys
[x
], len
[x
], 0);
4068 assert(rc
== MEMCACHED_SUCCESS
);
4072 * Don't do the following in your code. I am abusing the internal details
4073 * within the library, and this is not a supported interface.
4074 * This is to verify correct behavior in the library
4076 uint32_t hash
= memcached_generate_hash(memc
, keys
[0], len
[0]);
4077 for (uint32_t x
= 0; x
< (repl
+ 1); ++x
)
4079 memc_clone
->hosts
[hash
].port
= 0;
4080 if (++hash
== memc_clone
->number_of_hosts
)
4084 memcached_result_st result_obj
;
4085 for (uint32_t host
= 0; host
< memc_clone
->number_of_hosts
; ++host
)
4087 for (int x
= 'a'; x
<= 'z'; ++x
)
4089 const char key
[2]= { [0]= (const char)x
};
4091 rc
= memcached_mget_by_key(memc_clone
, key
, 1, keys
, len
, 4);
4092 assert(rc
== MEMCACHED_SUCCESS
);
4094 memcached_result_st
*results
= memcached_result_create(memc_clone
, &result_obj
);
4098 while ((results
= memcached_fetch_result(memc_clone
, &result_obj
, &rc
)) != NULL
)
4103 memcached_result_free(&result_obj
);
4106 memcached_free(memc_clone
);
4108 return TEST_SUCCESS
;
4111 static void increment_request_id(uint16_t *id
)
4114 if ((*id
& UDP_REQUEST_ID_THREAD_MASK
) != 0)
4118 static uint16_t *get_udp_request_ids(memcached_st
*memc
)
4120 uint16_t *ids
= malloc(sizeof(uint16_t) * memc
->number_of_hosts
);
4121 assert(ids
!= NULL
);
4124 for (x
= 0; x
< memc
->number_of_hosts
; x
++)
4125 ids
[x
]= get_udp_datagram_request_id((struct udp_datagram_header_st
*) memc
->hosts
[x
].write_buffer
);
4130 static test_return_t
post_udp_op_check(memcached_st
*memc
, uint16_t *expected_req_ids
)
4133 memcached_server_st
*cur_server
= memc
->hosts
;
4134 uint16_t *cur_req_ids
= get_udp_request_ids(memc
);
4136 for (x
= 0; x
< memc
->number_of_hosts
; x
++)
4138 assert(cur_server
[x
].cursor_active
== 0);
4139 assert(cur_req_ids
[x
] == expected_req_ids
[x
]);
4141 free(expected_req_ids
);
4144 return TEST_SUCCESS
;
4148 ** There is a little bit of a hack here, instead of removing
4149 ** the servers, I just set num host to 0 and them add then new udp servers
4151 static memcached_return
init_udp(memcached_st
*memc
)
4153 memcached_version(memc
);
4154 /* For the time being, only support udp test for >= 1.2.6 && < 1.3 */
4155 if (memc
->hosts
[0].major_version
!= 1 || memc
->hosts
[0].minor_version
!= 2
4156 || memc
->hosts
[0].micro_version
< 6)
4157 return MEMCACHED_FAILURE
;
4159 uint32_t num_hosts
= memc
->number_of_hosts
;
4161 memcached_server_st servers
[num_hosts
];
4162 memcpy(servers
, memc
->hosts
, sizeof(memcached_server_st
) * num_hosts
);
4163 for (x
= 0; x
< num_hosts
; x
++)
4164 memcached_server_free(&memc
->hosts
[x
]);
4166 memc
->number_of_hosts
= 0;
4167 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
, 1);
4168 for (x
= 0; x
< num_hosts
; x
++)
4170 assert(memcached_server_add_udp(memc
, servers
[x
].hostname
, servers
[x
].port
) == MEMCACHED_SUCCESS
);
4171 assert(memc
->hosts
[x
].write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4174 return MEMCACHED_SUCCESS
;
4177 static memcached_return
binary_init_udp(memcached_st
*memc
)
4180 return init_udp(memc
);
4183 /* Make sure that I cant add a tcp server to a udp client */
4184 static test_return_t
add_tcp_server_udp_client_test(memcached_st
*memc
)
4186 memcached_server_st server
;
4187 memcached_server_clone(&server
, &memc
->hosts
[0]);
4188 assert(memcached_server_remove(&(memc
->hosts
[0])) == MEMCACHED_SUCCESS
);
4189 assert(memcached_server_add(memc
, server
.hostname
, server
.port
) == MEMCACHED_INVALID_HOST_PROTOCOL
);
4190 return TEST_SUCCESS
;
4193 /* Make sure that I cant add a udp server to a tcp client */
4194 static test_return_t
add_udp_server_tcp_client_test(memcached_st
*memc
)
4196 memcached_server_st server
;
4197 memcached_server_clone(&server
, &memc
->hosts
[0]);
4198 assert(memcached_server_remove(&(memc
->hosts
[0])) == MEMCACHED_SUCCESS
);
4200 memcached_st tcp_client
;
4201 memcached_create(&tcp_client
);
4202 assert(memcached_server_add_udp(&tcp_client
, server
.hostname
, server
.port
) == MEMCACHED_INVALID_HOST_PROTOCOL
);
4203 return TEST_SUCCESS
;
4206 static test_return_t
set_udp_behavior_test(memcached_st
*memc
)
4209 memcached_quit(memc
);
4210 memc
->number_of_hosts
= 0;
4211 run_distribution(memc
);
4212 assert(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
, 1) == MEMCACHED_SUCCESS
);
4213 assert(memc
->flags
& MEM_USE_UDP
);
4214 assert(memc
->flags
& MEM_NOREPLY
);;
4216 assert(memc
->number_of_hosts
== 0);
4218 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
,0);
4219 assert(!(memc
->flags
& MEM_USE_UDP
));
4220 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
,0);
4221 assert(!(memc
->flags
& MEM_NOREPLY
));
4222 return TEST_SUCCESS
;
4225 static test_return_t
udp_set_test(memcached_st
*memc
)
4228 unsigned int num_iters
= 1025; //request id rolls over at 1024
4229 for (x
= 0; x
< num_iters
;x
++)
4231 memcached_return rc
;
4232 const char *key
= "foo";
4233 const char *value
= "when we sanitize";
4234 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4235 unsigned int server_key
= memcached_generate_hash(memc
,key
,strlen(key
));
4236 size_t init_offset
= memc
->hosts
[server_key
].write_buffer_offset
;
4237 rc
= memcached_set(memc
, key
, strlen(key
),
4238 value
, strlen(value
),
4239 (time_t)0, (uint32_t)0);
4240 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4241 /** NB, the check below assumes that if new write_ptr is less than
4242 * the original write_ptr that we have flushed. For large payloads, this
4243 * maybe an invalid assumption, but for the small payload we have it is OK
4245 if (rc
== MEMCACHED_SUCCESS
||
4246 memc
->hosts
[server_key
].write_buffer_offset
< init_offset
)
4247 increment_request_id(&expected_ids
[server_key
]);
4249 if (rc
== MEMCACHED_SUCCESS
)
4251 assert(memc
->hosts
[server_key
].write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4255 assert(memc
->hosts
[server_key
].write_buffer_offset
!= UDP_DATAGRAM_HEADER_LENGTH
);
4256 assert(memc
->hosts
[server_key
].write_buffer_offset
<= MAX_UDP_DATAGRAM_LENGTH
);
4258 assert(post_udp_op_check(memc
,expected_ids
) == TEST_SUCCESS
);
4260 return TEST_SUCCESS
;
4263 static test_return_t
udp_buffered_set_test(memcached_st
*memc
)
4265 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4266 return udp_set_test(memc
);
4269 static test_return_t
udp_set_too_big_test(memcached_st
*memc
)
4271 memcached_return rc
;
4272 const char *key
= "bar";
4273 char value
[MAX_UDP_DATAGRAM_LENGTH
];
4274 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4275 rc
= memcached_set(memc
, key
, strlen(key
),
4276 value
, MAX_UDP_DATAGRAM_LENGTH
,
4277 (time_t)0, (uint32_t)0);
4278 assert(rc
== MEMCACHED_WRITE_FAILURE
);
4279 return post_udp_op_check(memc
,expected_ids
);
4282 static test_return_t
udp_delete_test(memcached_st
*memc
)
4285 unsigned int num_iters
= 1025; //request id rolls over at 1024
4286 for (x
= 0; x
< num_iters
;x
++)
4288 memcached_return rc
;
4289 const char *key
= "foo";
4290 uint16_t *expected_ids
=get_udp_request_ids(memc
);
4291 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4292 size_t init_offset
= memc
->hosts
[server_key
].write_buffer_offset
;
4293 rc
= memcached_delete(memc
, key
, strlen(key
), 0);
4294 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4295 if (rc
== MEMCACHED_SUCCESS
|| memc
->hosts
[server_key
].write_buffer_offset
< init_offset
)
4296 increment_request_id(&expected_ids
[server_key
]);
4297 if (rc
== MEMCACHED_SUCCESS
)
4298 assert(memc
->hosts
[server_key
].write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4301 assert(memc
->hosts
[server_key
].write_buffer_offset
!= UDP_DATAGRAM_HEADER_LENGTH
);
4302 assert(memc
->hosts
[server_key
].write_buffer_offset
<= MAX_UDP_DATAGRAM_LENGTH
);
4304 assert(post_udp_op_check(memc
,expected_ids
) == TEST_SUCCESS
);
4306 return TEST_SUCCESS
;
4309 static test_return_t
udp_buffered_delete_test(memcached_st
*memc
)
4311 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4312 return udp_delete_test(memc
);
4315 static test_return_t
udp_verbosity_test(memcached_st
*memc
)
4317 memcached_return rc
;
4318 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4320 for (x
= 0; x
< memc
->number_of_hosts
;x
++)
4321 increment_request_id(&expected_ids
[x
]);
4323 rc
= memcached_verbosity(memc
,3);
4324 assert(rc
== MEMCACHED_SUCCESS
);
4325 return post_udp_op_check(memc
,expected_ids
);
4328 static test_return_t
udp_quit_test(memcached_st
*memc
)
4330 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4331 memcached_quit(memc
);
4332 return post_udp_op_check(memc
, expected_ids
);
4335 static test_return_t
udp_flush_test(memcached_st
*memc
)
4337 memcached_return rc
;
4338 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4340 for (x
= 0; x
< memc
->number_of_hosts
;x
++)
4341 increment_request_id(&expected_ids
[x
]);
4343 rc
= memcached_flush(memc
,0);
4344 assert(rc
== MEMCACHED_SUCCESS
);
4345 return post_udp_op_check(memc
,expected_ids
);
4348 static test_return_t
udp_incr_test(memcached_st
*memc
)
4350 memcached_return rc
;
4351 const char *key
= "incr";
4352 const char *value
= "1";
4353 rc
= memcached_set(memc
, key
, strlen(key
),
4354 value
, strlen(value
),
4355 (time_t)0, (uint32_t)0);
4357 assert(rc
== MEMCACHED_SUCCESS
);
4358 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4359 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4360 increment_request_id(&expected_ids
[server_key
]);
4362 rc
= memcached_increment(memc
, key
, strlen(key
), 1, &newvalue
);
4363 assert(rc
== MEMCACHED_SUCCESS
);
4364 return post_udp_op_check(memc
, expected_ids
);
4367 static test_return_t
udp_decr_test(memcached_st
*memc
)
4369 memcached_return rc
;
4370 const char *key
= "decr";
4371 const char *value
= "1";
4372 rc
= memcached_set(memc
, key
, strlen(key
),
4373 value
, strlen(value
),
4374 (time_t)0, (uint32_t)0);
4376 assert(rc
== MEMCACHED_SUCCESS
);
4377 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4378 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4379 increment_request_id(&expected_ids
[server_key
]);
4381 rc
= memcached_decrement(memc
, key
, strlen(key
), 1, &newvalue
);
4382 assert(rc
== MEMCACHED_SUCCESS
);
4383 return post_udp_op_check(memc
, expected_ids
);
4387 static test_return_t
udp_stat_test(memcached_st
*memc
)
4389 memcached_stat_st
* rv
= NULL
;
4390 memcached_return rc
;
4392 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4393 rv
= memcached_stat(memc
, args
, &rc
);
4395 assert(rc
== MEMCACHED_NOT_SUPPORTED
);
4396 return post_udp_op_check(memc
, expected_ids
);
4399 static test_return_t
udp_version_test(memcached_st
*memc
)
4401 memcached_return rc
;
4402 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4403 rc
= memcached_version(memc
);
4404 assert(rc
== MEMCACHED_NOT_SUPPORTED
);
4405 return post_udp_op_check(memc
, expected_ids
);
4408 static test_return_t
udp_get_test(memcached_st
*memc
)
4410 memcached_return rc
;
4411 const char *key
= "foo";
4413 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4414 char *val
= memcached_get(memc
, key
, strlen(key
), &vlen
, (uint32_t)0, &rc
);
4415 assert(rc
== MEMCACHED_NOT_SUPPORTED
);
4416 assert(val
== NULL
);
4417 return post_udp_op_check(memc
, expected_ids
);
4420 static test_return_t
udp_mixed_io_test(memcached_st
*memc
)
4423 test_st mixed_io_ops
[] ={
4424 {"udp_set_test", 0, udp_set_test
},
4425 {"udp_set_too_big_test", 0, udp_set_too_big_test
},
4426 {"udp_delete_test", 0, udp_delete_test
},
4427 {"udp_verbosity_test", 0, udp_verbosity_test
},
4428 {"udp_quit_test", 0, udp_quit_test
},
4429 {"udp_flush_test", 0, udp_flush_test
},
4430 {"udp_incr_test", 0, udp_incr_test
},
4431 {"udp_decr_test", 0, udp_decr_test
},
4432 {"udp_version_test", 0, udp_version_test
}
4435 for (x
= 0; x
< 500; x
++)
4437 current_op
= mixed_io_ops
[random() % 9];
4438 assert(current_op
.function(memc
) == TEST_SUCCESS
);
4440 return TEST_SUCCESS
;
4443 static test_return_t
hsieh_avaibility_test (memcached_st
*memc
)
4445 memcached_return expected_rc
= MEMCACHED_FAILURE
;
4446 #ifdef HAVE_HSIEH_HASH
4447 expected_rc
= MEMCACHED_SUCCESS
;
4449 memcached_return rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
,
4450 (uint64_t)MEMCACHED_HASH_HSIEH
);
4451 assert(rc
== expected_rc
);
4452 return TEST_SUCCESS
;
4455 static const char *list
[]=
4485 static test_return_t
md5_run (memcached_st
*memc
__attribute__((unused
)))
4489 uint32_t values
[]= { 3195025439U, 2556848621U, 3724893440U, 3332385401U,
4490 245758794U, 2550894432U, 121710495U, 3053817768U,
4491 1250994555U, 1862072655U, 2631955953U, 2951528551U,
4492 1451250070U, 2820856945U, 2060845566U, 3646985608U,
4493 2138080750U, 217675895U, 2230934345U, 1234361223U,
4494 3968582726U, 2455685270U, 1293568479U, 199067604U,
4498 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4502 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MD5
);
4503 assert(values
[x
] == hash_val
);
4506 return TEST_SUCCESS
;
4509 static test_return_t
crc_run (memcached_st
*memc
__attribute__((unused
)))
4513 uint32_t values
[]= { 10542U, 22009U, 14526U, 19510U, 19432U, 10199U, 20634U,
4514 9369U, 11511U, 10362U, 7893U, 31289U, 11313U, 9354U,
4515 7621U, 30628U, 15218U, 25967U, 2695U, 9380U,
4516 17300U, 28156U, 9192U, 20484U, 16925U };
4518 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4522 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_CRC
);
4523 assert(values
[x
] == hash_val
);
4526 return TEST_SUCCESS
;
4529 static test_return_t
fnv1_64_run (memcached_st
*memc
__attribute__((unused
)))
4533 uint32_t values
[]= { 473199127U, 4148981457U, 3971873300U, 3257986707U,
4534 1722477987U, 2991193800U, 4147007314U, 3633179701U,
4535 1805162104U, 3503289120U, 3395702895U, 3325073042U,
4536 2345265314U, 3340346032U, 2722964135U, 1173398992U,
4537 2815549194U, 2562818319U, 224996066U, 2680194749U,
4538 3035305390U, 246890365U, 2395624193U, 4145193337U,
4541 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4545 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_64
);
4546 assert(values
[x
] == hash_val
);
4549 return TEST_SUCCESS
;
4552 static test_return_t
fnv1a_64_run (memcached_st
*memc
__attribute__((unused
)))
4556 uint32_t values
[]= { 1488911807U, 2500855813U, 1510099634U, 1390325195U,
4557 3647689787U, 3241528582U, 1669328060U, 2604311949U,
4558 734810122U, 1516407546U, 560948863U, 1767346780U,
4559 561034892U, 4156330026U, 3716417003U, 3475297030U,
4560 1518272172U, 227211583U, 3938128828U, 126112909U,
4561 3043416448U, 3131561933U, 1328739897U, 2455664041U,
4564 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4568 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_64
);
4569 assert(values
[x
] == hash_val
);
4572 return TEST_SUCCESS
;
4575 static test_return_t
fnv1_32_run (memcached_st
*memc
__attribute__((unused
)))
4579 uint32_t values
[]= { 67176023U, 1190179409U, 2043204404U, 3221866419U,
4580 2567703427U, 3787535528U, 4147287986U, 3500475733U,
4581 344481048U, 3865235296U, 2181839183U, 119581266U,
4582 510234242U, 4248244304U, 1362796839U, 103389328U,
4583 1449620010U, 182962511U, 3554262370U, 3206747549U,
4584 1551306158U, 4127558461U, 1889140833U, 2774173721U,
4588 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4592 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_32
);
4593 assert(values
[x
] == hash_val
);
4596 return TEST_SUCCESS
;
4599 static test_return_t
fnv1a_32_run (memcached_st
*memc
__attribute__((unused
)))
4603 uint32_t values
[]= { 280767167U, 2421315013U, 3072375666U, 855001899U,
4604 459261019U, 3521085446U, 18738364U, 1625305005U,
4605 2162232970U, 777243802U, 3323728671U, 132336572U,
4606 3654473228U, 260679466U, 1169454059U, 2698319462U,
4607 1062177260U, 235516991U, 2218399068U, 405302637U,
4608 1128467232U, 3579622413U, 2138539289U, 96429129U,
4611 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4615 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_32
);
4616 assert(values
[x
] == hash_val
);
4619 return TEST_SUCCESS
;
4622 static test_return_t
hsieh_run (memcached_st
*memc
__attribute__((unused
)))
4626 #ifdef HAVE_HSIEH_HASH
4627 uint32_t values
[]= { 3738850110, 3636226060, 3821074029, 3489929160, 3485772682, 80540287,
4628 1805464076, 1895033657, 409795758, 979934958, 3634096985, 1284445480,
4629 2265380744, 707972988, 353823508, 1549198350, 1327930172, 9304163,
4630 4220749037, 2493964934, 2777873870, 2057831732, 1510213931, 2027828987,
4633 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 };
4636 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4640 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_HSIEH
);
4641 assert(values
[x
] == hash_val
);
4644 return TEST_SUCCESS
;
4647 static test_return_t
murmur_run (memcached_st
*memc
__attribute__((unused
)))
4651 uint32_t values
[]= { 473199127U, 4148981457U, 3971873300U, 3257986707U,
4652 1722477987U, 2991193800U, 4147007314U, 3633179701U,
4653 1805162104U, 3503289120U, 3395702895U, 3325073042U,
4654 2345265314U, 3340346032U, 2722964135U, 1173398992U,
4655 2815549194U, 2562818319U, 224996066U, 2680194749U,
4656 3035305390U, 246890365U, 2395624193U, 4145193337U,
4659 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4663 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_64
);
4664 assert(values
[x
] == hash_val
);
4667 return TEST_SUCCESS
;
4670 static test_return_t
jenkins_run (memcached_st
*memc
__attribute__((unused
)))
4674 uint32_t values
[]= { 1442444624U, 4253821186U, 1885058256U, 2120131735U,
4675 3261968576U, 3515188778U, 4232909173U, 4288625128U,
4676 1812047395U, 3689182164U, 2502979932U, 1214050606U,
4677 2415988847U, 1494268927U, 1025545760U, 3920481083U,
4678 4153263658U, 3824871822U, 3072759809U, 798622255U,
4679 3065432577U, 1453328165U, 2691550971U, 3408888387U,
4683 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4687 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_JENKINS
);
4688 assert(values
[x
] == hash_val
);
4691 return TEST_SUCCESS
;
4695 static test_return_t
ketama_compatibility_libmemcached(memcached_st
*trash
)
4697 memcached_return rc
;
4700 memcached_server_st
*server_pool
;
4705 memc
= memcached_create(NULL
);
4708 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
4709 assert(rc
== MEMCACHED_SUCCESS
);
4711 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
4714 assert(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_COMPAT_MODE
,
4715 MEMCACHED_KETAMA_COMPAT_LIBMEMCACHED
) == MEMCACHED_SUCCESS
);
4717 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_COMPAT_MODE
) ==
4718 MEMCACHED_KETAMA_COMPAT_LIBMEMCACHED
);
4720 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");
4721 memcached_server_push(memc
, server_pool
);
4723 /* verify that the server list was parsed okay. */
4724 assert(memc
->number_of_hosts
== 8);
4725 assert(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
4726 assert(server_pool
[0].port
== 11211);
4727 assert(server_pool
[0].weight
== 600);
4728 assert(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
4729 assert(server_pool
[2].port
== 11211);
4730 assert(server_pool
[2].weight
== 200);
4731 assert(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
4732 assert(server_pool
[7].port
== 11211);
4733 assert(server_pool
[7].weight
== 100);
4735 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
4736 * us test the boundary wraparound.
4738 assert(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
4740 /* verify the standard ketama set. */
4741 for (x
= 0; x
< 99; x
++)
4743 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
4744 char *hostname
= memc
->hosts
[server_idx
].hostname
;
4745 assert(strcmp(hostname
, ketama_test_cases
[x
].server
) == 0);
4748 memcached_server_list_free(server_pool
);
4749 memcached_free(memc
);
4751 return TEST_SUCCESS
;
4754 static test_return_t
ketama_compatibility_spymemcached(memcached_st
*trash
)
4756 memcached_return rc
;
4759 memcached_server_st
*server_pool
;
4764 memc
= memcached_create(NULL
);
4767 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
4768 assert(rc
== MEMCACHED_SUCCESS
);
4770 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
4773 assert(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_COMPAT_MODE
,
4774 MEMCACHED_KETAMA_COMPAT_SPY
) == MEMCACHED_SUCCESS
);
4776 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_COMPAT_MODE
) ==
4777 MEMCACHED_KETAMA_COMPAT_SPY
);
4779 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");
4780 memcached_server_push(memc
, server_pool
);
4782 /* verify that the server list was parsed okay. */
4783 assert(memc
->number_of_hosts
== 8);
4784 assert(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
4785 assert(server_pool
[0].port
== 11211);
4786 assert(server_pool
[0].weight
== 600);
4787 assert(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
4788 assert(server_pool
[2].port
== 11211);
4789 assert(server_pool
[2].weight
== 200);
4790 assert(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
4791 assert(server_pool
[7].port
== 11211);
4792 assert(server_pool
[7].weight
== 100);
4794 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
4795 * us test the boundary wraparound.
4797 assert(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
4799 /* verify the standard ketama set. */
4800 for (x
= 0; x
< 99; x
++)
4802 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases_spy
[x
].key
, strlen(ketama_test_cases_spy
[x
].key
));
4803 char *hostname
= memc
->hosts
[server_idx
].hostname
;
4804 assert(strcmp(hostname
, ketama_test_cases_spy
[x
].server
) == 0);
4807 memcached_server_list_free(server_pool
);
4808 memcached_free(memc
);
4810 return TEST_SUCCESS
;
4813 static test_return_t
regression_bug_434484(memcached_st
*memc
)
4815 if (pre_binary(memc
) != MEMCACHED_SUCCESS
)
4816 return TEST_SKIPPED
;
4818 memcached_return ret
;
4819 const char *key
= "regression_bug_434484";
4820 size_t keylen
= strlen(key
);
4822 ret
= memcached_append(memc
, key
, keylen
, key
, keylen
, 0, 0);
4823 assert(ret
== MEMCACHED_NOTSTORED
);
4825 size_t size
= 2048 * 1024;
4826 void *data
= calloc(1, size
);
4827 assert(data
!= NULL
);
4828 ret
= memcached_set(memc
, key
, keylen
, data
, size
, 0, 0);
4829 assert(ret
== MEMCACHED_E2BIG
);
4832 return TEST_SUCCESS
;
4835 static test_return_t
regression_bug_434843(memcached_st
*memc
)
4837 if (pre_binary(memc
) != MEMCACHED_SUCCESS
)
4838 return TEST_SKIPPED
;
4840 memcached_return rc
;
4841 unsigned int counter
= 0;
4842 memcached_execute_function callbacks
[1]= { [0]= &callback_counter
};
4845 * I only want to hit only _one_ server so I know the number of requests I'm
4846 * sending in the pipleine to the server. Let's try to do a multiget of
4847 * 1024 (that should satisfy most users don't you think?). Future versions
4848 * will include a mget_execute function call if you need a higher number.
4850 uint32_t number_of_hosts
= memc
->number_of_hosts
;
4851 memc
->number_of_hosts
= 1;
4852 const size_t max_keys
= 1024;
4853 char **keys
= calloc(max_keys
, sizeof(char*));
4854 size_t *key_length
=calloc(max_keys
, sizeof(size_t));
4856 for (int x
= 0; x
< (int)max_keys
; ++x
)
4859 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%u", x
);
4861 assert(keys
[x
] != NULL
);
4865 * Run two times.. the first time we should have 100% cache miss,
4866 * and the second time we should have 100% cache hits
4868 for (int y
= 0; y
< 2; ++y
)
4870 rc
= memcached_mget(memc
, (const char**)keys
, key_length
, max_keys
);
4871 assert(rc
== MEMCACHED_SUCCESS
);
4872 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
4875 /* The first iteration should give me a 100% cache miss. verify that*/
4876 assert(counter
== 0);
4877 char blob
[1024]= { 0 };
4878 for (int x
= 0; x
< (int)max_keys
; ++x
)
4880 rc
= memcached_add(memc
, keys
[x
], key_length
[x
],
4881 blob
, sizeof(blob
), 0, 0);
4882 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4887 /* Verify that we received all of the key/value pairs */
4888 assert(counter
== (unsigned int)max_keys
);
4892 /* Release allocated resources */
4893 for (size_t x
= 0; x
< max_keys
; ++x
)
4898 memc
->number_of_hosts
= number_of_hosts
;
4899 return TEST_SUCCESS
;
4902 static test_return_t
regression_bug_434843_buffered(memcached_st
*memc
)
4904 memcached_return rc
;
4905 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4906 assert(rc
== MEMCACHED_SUCCESS
);
4908 return regression_bug_434843(memc
);
4911 static test_return_t
regression_bug_421108(memcached_st
*memc
)
4913 memcached_return rc
;
4914 memcached_stat_st
*memc_stat
= memcached_stat(memc
, NULL
, &rc
);
4915 assert(rc
== MEMCACHED_SUCCESS
);
4917 char *bytes
= memcached_stat_get_value(memc
, memc_stat
, "bytes", &rc
);
4918 assert(rc
== MEMCACHED_SUCCESS
);
4919 assert(bytes
!= NULL
);
4920 char *bytes_read
= memcached_stat_get_value(memc
, memc_stat
,
4922 assert(rc
== MEMCACHED_SUCCESS
);
4923 assert(bytes_read
!= NULL
);
4925 char *bytes_written
= memcached_stat_get_value(memc
, memc_stat
,
4926 "bytes_written", &rc
);
4927 assert(rc
== MEMCACHED_SUCCESS
);
4928 assert(bytes_written
!= NULL
);
4930 assert(strcmp(bytes
, bytes_read
) != 0);
4931 assert(strcmp(bytes
, bytes_written
) != 0);
4933 /* Release allocated resources */
4936 free(bytes_written
);
4937 memcached_stat_free(NULL
, memc_stat
);
4938 return TEST_SUCCESS
;
4942 * The test case isn't obvious so I should probably document why
4943 * it works the way it does. Bug 442914 was caused by a bug
4944 * in the logic in memcached_purge (it did not handle the case
4945 * where the number of bytes sent was equal to the watermark).
4946 * In this test case, create messages so that we hit that case
4947 * and then disable noreply mode and issue a new command to
4948 * verify that it isn't stuck. If we change the format for the
4949 * delete command or the watermarks, we need to update this
4952 static test_return_t
regression_bug_442914(memcached_st
*memc
)
4954 memcached_return rc
;
4955 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
4956 assert(rc
== MEMCACHED_SUCCESS
);
4957 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1);
4959 uint32_t number_of_hosts
= memc
->number_of_hosts
;
4960 memc
->number_of_hosts
= 1;
4965 for (int x
= 0; x
< 250; ++x
)
4967 len
= (size_t)snprintf(k
, sizeof(k
), "%0250u", x
);
4968 rc
= memcached_delete(memc
, k
, len
, 0);
4969 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4972 len
= (size_t)snprintf(k
, sizeof(k
), "%037u", 251);
4973 rc
= memcached_delete(memc
, k
, len
, 0);
4974 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4976 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0);
4977 assert(rc
== MEMCACHED_SUCCESS
);
4978 rc
= memcached_delete(memc
, k
, len
, 0);
4979 assert(rc
== MEMCACHED_NOTFOUND
);
4981 memc
->number_of_hosts
= number_of_hosts
;
4983 return TEST_SUCCESS
;
4986 static test_return_t
regression_bug_447342(memcached_st
*memc
)
4988 if (memc
->number_of_hosts
< 3 || pre_replication(memc
) != MEMCACHED_SUCCESS
)
4989 return TEST_SKIPPED
;
4991 memcached_return rc
;
4993 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 2);
4994 assert(rc
== MEMCACHED_SUCCESS
);
4996 const size_t max_keys
= 100;
4997 char **keys
= calloc(max_keys
, sizeof(char*));
4998 size_t *key_length
=calloc(max_keys
, sizeof(size_t));
5000 for (int x
= 0; x
< (int)max_keys
; ++x
)
5003 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%u", x
);
5005 assert(keys
[x
] != NULL
);
5006 rc
= memcached_set(memc
, k
, key_length
[x
], k
, key_length
[x
], 0, 0);
5007 assert(rc
== MEMCACHED_SUCCESS
);
5011 ** We are using the quiet commands to store the replicas, so we need
5012 ** to ensure that all of them are processed before we can continue.
5013 ** In the test we go directly from storing the object to trying to
5014 ** receive the object from all of the different servers, so we
5015 ** could end up in a race condition (the memcached server hasn't yet
5016 ** processed the quiet command from the replication set when it process
5017 ** the request from the other client (created by the clone)). As a
5018 ** workaround for that we call memcached_quit to send the quit command
5019 ** to the server and wait for the response ;-) If you use the test code
5020 ** as an example for your own code, please note that you shouldn't need
5023 memcached_quit(memc
);
5025 /* Verify that all messages are stored, and we didn't stuff too much
5028 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5029 assert(rc
== MEMCACHED_SUCCESS
);
5031 unsigned int counter
= 0;
5032 memcached_execute_function callbacks
[1]= { [0]= &callback_counter
};
5033 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5034 /* Verify that we received all of the key/value pairs */
5035 assert(counter
== (unsigned int)max_keys
);
5037 memcached_quit(memc
);
5039 * Don't do the following in your code. I am abusing the internal details
5040 * within the library, and this is not a supported interface.
5041 * This is to verify correct behavior in the library. Fake that two servers
5044 unsigned int port0
= memc
->hosts
[0].port
;
5045 unsigned int port2
= memc
->hosts
[2].port
;
5046 memc
->hosts
[0].port
= 0;
5047 memc
->hosts
[2].port
= 0;
5049 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5050 assert(rc
== MEMCACHED_SUCCESS
);
5053 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5054 assert(counter
== (unsigned int)max_keys
);
5056 /* restore the memc handle */
5057 memc
->hosts
[0].port
= port0
;
5058 memc
->hosts
[2].port
= port2
;
5060 memcached_quit(memc
);
5062 /* Remove half of the objects */
5063 for (int x
= 0; x
< (int)max_keys
; ++x
)
5066 rc
= memcached_delete(memc
, keys
[x
], key_length
[x
], 0);
5067 assert(rc
== MEMCACHED_SUCCESS
);
5070 memcached_quit(memc
);
5071 memc
->hosts
[0].port
= 0;
5072 memc
->hosts
[2].port
= 0;
5074 /* now retry the command, this time we should have cache misses */
5075 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5076 assert(rc
== MEMCACHED_SUCCESS
);
5079 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5080 assert(counter
== (unsigned int)(max_keys
>> 1));
5082 /* Release allocated resources */
5083 for (size_t x
= 0; x
< max_keys
; ++x
)
5088 /* restore the memc handle */
5089 memc
->hosts
[0].port
= port0
;
5090 memc
->hosts
[2].port
= port2
;
5091 return TEST_SUCCESS
;
5094 static test_return_t
regression_bug_463297(memcached_st
*memc
)
5096 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
5097 assert(memc_clone
!= NULL
);
5098 assert(memcached_version(memc_clone
) == MEMCACHED_SUCCESS
);
5100 if (memc_clone
->hosts
[0].major_version
> 1 ||
5101 (memc_clone
->hosts
[0].major_version
== 1 &&
5102 memc_clone
->hosts
[0].minor_version
> 2))
5104 /* Binary protocol doesn't support deferred delete */
5105 memcached_st
*bin_clone
= memcached_clone(NULL
, memc
);
5106 assert(bin_clone
!= NULL
);
5107 assert(memcached_behavior_set(bin_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1) == MEMCACHED_SUCCESS
);
5108 assert(memcached_delete(bin_clone
, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS
);
5109 memcached_free(bin_clone
);
5111 memcached_quit(memc_clone
);
5113 /* If we know the server version, deferred delete should fail
5114 * with invalid arguments */
5115 assert(memcached_delete(memc_clone
, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS
);
5117 /* If we don't know the server version, we should get a protocol error */
5118 memcached_return rc
= memcached_delete(memc
, "foo", 3, 1);
5119 /* but there is a bug in some of the memcached servers (1.4) that treats
5120 * the counter as noreply so it doesn't send the proper error message
5122 assert(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5124 /* And buffered mode should be disabled and we should get protocol error */
5125 assert(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1) == MEMCACHED_SUCCESS
);
5126 rc
= memcached_delete(memc
, "foo", 3, 1);
5127 assert(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5129 /* Same goes for noreply... */
5130 assert(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1) == MEMCACHED_SUCCESS
);
5131 rc
= memcached_delete(memc
, "foo", 3, 1);
5132 assert(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5134 /* but a normal request should go through (and be buffered) */
5135 assert((rc
= memcached_delete(memc
, "foo", 3, 0)) == MEMCACHED_BUFFERED
);
5136 assert(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
5138 assert(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 0) == MEMCACHED_SUCCESS
);
5139 /* unbuffered noreply should be success */
5140 assert(memcached_delete(memc
, "foo", 3, 0) == MEMCACHED_SUCCESS
);
5141 /* unbuffered with reply should be not found... */
5142 assert(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0) == MEMCACHED_SUCCESS
);
5143 assert(memcached_delete(memc
, "foo", 3, 0) == MEMCACHED_NOTFOUND
);
5146 memcached_free(memc_clone
);
5147 return TEST_SUCCESS
;
5151 /* Test memcached_server_get_last_disconnect
5152 * For a working server set, shall be NULL
5153 * For a set of non existing server, shall not be NULL
5155 static test_return_t
test_get_last_disconnect(memcached_st
*memc
)
5157 memcached_return rc
;
5158 memcached_server_st
*disconnected_server
;
5160 /* With the working set of server */
5161 const char *key
= "marmotte";
5162 const char *value
= "milka";
5164 rc
= memcached_set(memc
, key
, strlen(key
),
5165 value
, strlen(value
),
5166 (time_t)0, (uint32_t)0);
5167 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5169 disconnected_server
= memcached_server_get_last_disconnect(memc
);
5170 assert(disconnected_server
== NULL
);
5172 /* With a non existing server */
5174 memcached_server_st
*servers
;
5176 const char *server_list
= "localhost:9";
5178 servers
= memcached_servers_parse(server_list
);
5180 mine
= memcached_create(NULL
);
5181 rc
= memcached_server_push(mine
, servers
);
5182 assert(rc
== MEMCACHED_SUCCESS
);
5183 memcached_server_list_free(servers
);
5186 rc
= memcached_set(mine
, key
, strlen(key
),
5187 value
, strlen(value
),
5188 (time_t)0, (uint32_t)0);
5189 assert(rc
!= MEMCACHED_SUCCESS
);
5191 disconnected_server
= memcached_server_get_last_disconnect(mine
);
5192 assert(disconnected_server
!= NULL
);
5193 assert(disconnected_server
->port
== 9);
5194 assert(strncmp(disconnected_server
->hostname
,"localhost",9) == 0);
5196 memcached_quit(mine
);
5197 memcached_free(mine
);
5199 return TEST_SUCCESS
;
5203 * This test ensures that the failure counter isn't incremented during
5204 * normal termination of the memcached instance.
5206 static test_return_t
wrong_failure_counter_test(memcached_st
*memc
)
5208 memcached_return rc
;
5210 /* Set value to force connection to the server */
5211 const char *key
= "marmotte";
5212 const char *value
= "milka";
5215 * Please note that I'm abusing the internal structures in libmemcached
5216 * in a non-portable way and you shouldn't be doing this. I'm only
5217 * doing this in order to verify that the library works the way it should
5219 uint32_t number_of_hosts
= memc
->number_of_hosts
;
5220 memc
->number_of_hosts
= 1;
5222 /* Ensure that we are connected to the server by setting a value */
5223 rc
= memcached_set(memc
, key
, strlen(key
),
5224 value
, strlen(value
),
5225 (time_t)0, (uint32_t)0);
5226 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5229 /* The test is to see that the memcached_quit doesn't increase the
5230 * the server failure conter, so let's ensure that it is zero
5231 * before sending quit
5233 memc
->hosts
[0].server_failure_counter
= 0;
5235 memcached_quit(memc
);
5237 /* Verify that it memcached_quit didn't increment the failure counter
5238 * Please note that this isn't bullet proof, because an error could
5241 assert(memc
->hosts
[0].server_failure_counter
== 0);
5243 /* restore the instance */
5244 memc
->number_of_hosts
= number_of_hosts
;
5246 return TEST_SUCCESS
;
5249 test_st udp_setup_server_tests
[] ={
5250 {"set_udp_behavior_test", 0, set_udp_behavior_test
},
5251 {"add_tcp_server_udp_client_test", 0, add_tcp_server_udp_client_test
},
5252 {"add_udp_server_tcp_client_test", 0, add_udp_server_tcp_client_test
},
5256 test_st upd_io_tests
[] ={
5257 {"udp_set_test", 0, udp_set_test
},
5258 {"udp_buffered_set_test", 0, udp_buffered_set_test
},
5259 {"udp_set_too_big_test", 0, udp_set_too_big_test
},
5260 {"udp_delete_test", 0, udp_delete_test
},
5261 {"udp_buffered_delete_test", 0, udp_buffered_delete_test
},
5262 {"udp_verbosity_test", 0, udp_verbosity_test
},
5263 {"udp_quit_test", 0, udp_quit_test
},
5264 {"udp_flush_test", 0, udp_flush_test
},
5265 {"udp_incr_test", 0, udp_incr_test
},
5266 {"udp_decr_test", 0, udp_decr_test
},
5267 {"udp_stat_test", 0, udp_stat_test
},
5268 {"udp_version_test", 0, udp_version_test
},
5269 {"udp_get_test", 0, udp_get_test
},
5270 {"udp_mixed_io_test", 0, udp_mixed_io_test
},
5274 /* Clean the server before beginning testing */
5276 {"flush", 0, flush_test
},
5277 {"init", 0, init_test
},
5278 {"allocation", 0, allocation_test
},
5279 {"server_list_null_test", 0, server_list_null_test
},
5280 {"server_unsort", 0, server_unsort_test
},
5281 {"server_sort", 0, server_sort_test
},
5282 {"server_sort2", 0, server_sort2_test
},
5283 {"clone_test", 0, clone_test
},
5284 {"connection_test", 0, connection_test
},
5285 {"callback_test", 0, callback_test
},
5286 {"behavior_test", 0, behavior_test
},
5287 {"userdata_test", 0, userdata_test
},
5288 {"error", 0, error_test
},
5289 {"set", 0, set_test
},
5290 {"set2", 0, set_test2
},
5291 {"set3", 0, set_test3
},
5292 {"dump", 1, dump_test
},
5293 {"add", 1, add_test
},
5294 {"replace", 1, replace_test
},
5295 {"delete", 1, delete_test
},
5296 {"get", 1, get_test
},
5297 {"get2", 0, get_test2
},
5298 {"get3", 0, get_test3
},
5299 {"get4", 0, get_test4
},
5300 {"partial mget", 0, get_test5
},
5301 {"stats_servername", 0, stats_servername_test
},
5302 {"increment", 0, increment_test
},
5303 {"increment_with_initial", 1, increment_with_initial_test
},
5304 {"decrement", 0, decrement_test
},
5305 {"decrement_with_initial", 1, decrement_with_initial_test
},
5306 {"quit", 0, quit_test
},
5307 {"mget", 1, mget_test
},
5308 {"mget_result", 1, mget_result_test
},
5309 {"mget_result_alloc", 1, mget_result_alloc_test
},
5310 {"mget_result_function", 1, mget_result_function
},
5311 {"mget_execute", 1, mget_execute
},
5312 {"mget_end", 0, mget_end
},
5313 {"get_stats", 0, get_stats
},
5314 {"add_host_test", 0, add_host_test
},
5315 {"add_host_test_1", 0, add_host_test1
},
5316 {"get_stats_keys", 0, get_stats_keys
},
5317 {"behavior_test", 0, get_stats_keys
},
5318 {"callback_test", 0, get_stats_keys
},
5319 {"version_string_test", 0, version_string_test
},
5320 {"bad_key", 1, bad_key_test
},
5321 {"memcached_server_cursor", 1, memcached_server_cursor_test
},
5322 {"read_through", 1, read_through
},
5323 {"delete_through", 1, delete_through
},
5324 {"noreply", 1, noreply_test
},
5325 {"analyzer", 1, analyzer_test
},
5326 #ifdef HAVE_LIBMEMCACHEDUTIL
5327 {"connectionpool", 1, connection_pool_test
},
5329 {"test_get_last_disconnect", 1, test_get_last_disconnect
},
5333 test_st async_tests
[] ={
5334 {"add", 1, add_wrapper
},
5338 test_st string_tests
[] ={
5339 {"string static with null", 0, string_static_null
},
5340 {"string alloc with null", 0, string_alloc_null
},
5341 {"string alloc with 1K", 0, string_alloc_with_size
},
5342 {"string alloc with malloc failure", 0, string_alloc_with_size_toobig
},
5343 {"string append", 0, string_alloc_append
},
5344 {"string append failure (too big)", 0, string_alloc_append_toobig
},
5348 test_st result_tests
[] ={
5349 {"result static", 0, result_static
},
5350 {"result alloc", 0, result_alloc
},
5354 test_st version_1_2_3
[] ={
5355 {"append", 0, append_test
},
5356 {"prepend", 0, prepend_test
},
5357 {"cas", 0, cas_test
},
5358 {"cas2", 0, cas2_test
},
5359 {"append_binary", 0, append_binary_test
},
5363 test_st user_tests
[] ={
5364 {"user_supplied_bug1", 0, user_supplied_bug1
},
5365 {"user_supplied_bug2", 0, user_supplied_bug2
},
5366 {"user_supplied_bug3", 0, user_supplied_bug3
},
5367 {"user_supplied_bug4", 0, user_supplied_bug4
},
5368 {"user_supplied_bug5", 1, user_supplied_bug5
},
5369 {"user_supplied_bug6", 1, user_supplied_bug6
},
5370 {"user_supplied_bug7", 1, user_supplied_bug7
},
5371 {"user_supplied_bug8", 1, user_supplied_bug8
},
5372 {"user_supplied_bug9", 1, user_supplied_bug9
},
5373 {"user_supplied_bug10", 1, user_supplied_bug10
},
5374 {"user_supplied_bug11", 1, user_supplied_bug11
},
5375 {"user_supplied_bug12", 1, user_supplied_bug12
},
5376 {"user_supplied_bug13", 1, user_supplied_bug13
},
5377 {"user_supplied_bug14", 1, user_supplied_bug14
},
5378 {"user_supplied_bug15", 1, user_supplied_bug15
},
5379 {"user_supplied_bug16", 1, user_supplied_bug16
},
5382 ** It seems to be something weird with the character sets..
5383 ** value_fetch is unable to parse the value line (iscntrl "fails"), so I
5384 ** guess I need to find out how this is supposed to work.. Perhaps I need
5385 ** to run the test in a specific locale (I tried zh_CN.UTF-8 without success,
5386 ** so just disable the code for now...).
5388 {"user_supplied_bug17", 1, user_supplied_bug17
},
5390 {"user_supplied_bug18", 1, user_supplied_bug18
},
5391 {"user_supplied_bug19", 1, user_supplied_bug19
},
5392 {"user_supplied_bug20", 1, user_supplied_bug20
},
5393 {"user_supplied_bug21", 1, user_supplied_bug21
},
5394 {"wrong_failure_counter_test", 1, wrong_failure_counter_test
},
5398 test_st replication_tests
[]= {
5399 {"set", 1, replication_set_test
},
5400 {"get", 0, replication_get_test
},
5401 {"mget", 0, replication_mget_test
},
5402 {"delete", 0, replication_delete_test
},
5407 * The following test suite is used to verify that we don't introduce
5408 * regression bugs. If you want more information about the bug / test,
5409 * you should look in the bug report at
5410 * http://bugs.launchpad.net/libmemcached
5412 test_st regression_tests
[]= {
5413 {"lp:434484", 1, regression_bug_434484
},
5414 {"lp:434843", 1, regression_bug_434843
},
5415 {"lp:434843 buffered", 1, regression_bug_434843_buffered
},
5416 {"lp:421108", 1, regression_bug_421108
},
5417 {"lp:442914", 1, regression_bug_442914
},
5418 {"lp:447342", 1, regression_bug_447342
},
5419 {"lp:463297", 1, regression_bug_463297
},
5423 test_st ketama_compatibility
[]= {
5424 {"libmemcached", 1, ketama_compatibility_libmemcached
},
5425 {"spymemcached", 1, ketama_compatibility_spymemcached
},
5429 test_st generate_tests
[] ={
5430 {"generate_pairs", 1, generate_pairs
},
5431 {"generate_data", 1, generate_data
},
5432 {"get_read", 0, get_read
},
5433 {"delete_generate", 0, delete_generate
},
5434 {"generate_buffer_data", 1, generate_buffer_data
},
5435 {"delete_buffer", 0, delete_buffer_generate
},
5436 {"generate_data", 1, generate_data
},
5437 {"mget_read", 0, mget_read
},
5438 {"mget_read_result", 0, mget_read_result
},
5439 {"mget_read_function", 0, mget_read_function
},
5440 {"cleanup", 1, cleanup_pairs
},
5441 {"generate_large_pairs", 1, generate_large_pairs
},
5442 {"generate_data", 1, generate_data
},
5443 {"generate_buffer_data", 1, generate_buffer_data
},
5444 {"cleanup", 1, cleanup_pairs
},
5448 test_st consistent_tests
[] ={
5449 {"generate_pairs", 1, generate_pairs
},
5450 {"generate_data", 1, generate_data
},
5451 {"get_read", 0, get_read_count
},
5452 {"cleanup", 1, cleanup_pairs
},
5456 test_st consistent_weighted_tests
[] ={
5457 {"generate_pairs", 1, generate_pairs
},
5458 {"generate_data", 1, generate_data_with_stats
},
5459 {"get_read", 0, get_read_count
},
5460 {"cleanup", 1, cleanup_pairs
},
5464 test_st hsieh_availability
[] ={
5465 {"hsieh_avaibility_test",0,hsieh_avaibility_test
},
5469 test_st ketama_auto_eject_hosts
[] ={
5470 {"auto_eject_hosts", 1, auto_eject_hosts
},
5471 {"output_ketama_weighted_keys", 1, output_ketama_weighted_keys
},
5475 test_st hash_tests
[] ={
5476 {"md5", 0, md5_run
},
5477 {"crc", 0, crc_run
},
5478 {"fnv1_64", 0, fnv1_64_run
},
5479 {"fnv1a_64", 0, fnv1a_64_run
},
5480 {"fnv1_32", 0, fnv1_32_run
},
5481 {"fnv1a_32", 0, fnv1a_32_run
},
5482 {"hsieh", 0, hsieh_run
},
5483 {"murmur", 0, murmur_run
},
5484 {"jenkis", 0, jenkins_run
},
5488 collection_st collection
[] ={
5489 {"hsieh_availability",0,0,hsieh_availability
},
5490 {"udp_setup", init_udp
, 0, udp_setup_server_tests
},
5491 {"udp_io", init_udp
, 0, upd_io_tests
},
5492 {"udp_binary_io", binary_init_udp
, 0, upd_io_tests
},
5493 {"block", 0, 0, tests
},
5494 {"binary", pre_binary
, 0, tests
},
5495 {"nonblock", pre_nonblock
, 0, tests
},
5496 {"nodelay", pre_nodelay
, 0, tests
},
5497 {"settimer", pre_settimer
, 0, tests
},
5498 {"md5", pre_md5
, 0, tests
},
5499 {"crc", pre_crc
, 0, tests
},
5500 {"hsieh", pre_hsieh
, 0, tests
},
5501 {"jenkins", pre_jenkins
, 0, tests
},
5502 {"fnv1_64", pre_hash_fnv1_64
, 0, tests
},
5503 {"fnv1a_64", pre_hash_fnv1a_64
, 0, tests
},
5504 {"fnv1_32", pre_hash_fnv1_32
, 0, tests
},
5505 {"fnv1a_32", pre_hash_fnv1a_32
, 0, tests
},
5506 {"ketama", pre_behavior_ketama
, 0, tests
},
5507 {"ketama_auto_eject_hosts", pre_behavior_ketama
, 0, ketama_auto_eject_hosts
},
5508 {"unix_socket", pre_unix_socket
, 0, tests
},
5509 {"unix_socket_nodelay", pre_nodelay
, 0, tests
},
5510 {"poll_timeout", poll_timeout
, 0, tests
},
5511 {"gets", enable_cas
, 0, tests
},
5512 {"consistent", enable_consistent
, 0, tests
},
5513 #ifdef MEMCACHED_ENABLE_DEPRECATED
5514 {"deprecated_memory_allocators", deprecated_set_memory_alloc
, 0, tests
},
5516 {"memory_allocators", set_memory_alloc
, 0, tests
},
5517 {"prefix", set_prefix
, 0, tests
},
5518 {"version_1_2_3", check_for_1_2_3
, 0, version_1_2_3
},
5519 {"string", 0, 0, string_tests
},
5520 {"result", 0, 0, result_tests
},
5521 {"async", pre_nonblock
, 0, async_tests
},
5522 {"async_binary", pre_nonblock_binary
, 0, async_tests
},
5523 {"user", 0, 0, user_tests
},
5524 {"generate", 0, 0, generate_tests
},
5525 {"generate_hsieh", pre_hsieh
, 0, generate_tests
},
5526 {"generate_ketama", pre_behavior_ketama
, 0, generate_tests
},
5527 {"generate_hsieh_consistent", enable_consistent
, 0, generate_tests
},
5528 {"generate_md5", pre_md5
, 0, generate_tests
},
5529 {"generate_murmur", pre_murmur
, 0, generate_tests
},
5530 {"generate_jenkins", pre_jenkins
, 0, generate_tests
},
5531 {"generate_nonblock", pre_nonblock
, 0, generate_tests
},
5532 {"consistent_not", 0, 0, consistent_tests
},
5533 {"consistent_ketama", pre_behavior_ketama
, 0, consistent_tests
},
5534 {"consistent_ketama_weighted", pre_behavior_ketama_weighted
, 0, consistent_weighted_tests
},
5535 {"ketama_compat", 0, 0, ketama_compatibility
},
5536 {"test_hashes", 0, 0, hash_tests
},
5537 {"replication", pre_replication
, 0, replication_tests
},
5538 {"replication_noblock", pre_replication_noblock
, 0, replication_tests
},
5539 {"regression", 0, 0, regression_tests
},
5543 #define SERVERS_TO_CREATE 5
5545 /* Prototypes for functions we will pass to test framework */
5546 void *world_create(void);
5547 void world_destroy(void *p
);
5549 void *world_create(void)
5551 server_startup_st
*construct
;
5553 construct
= calloc(sizeof(server_startup_st
), 1);
5554 construct
->count
= SERVERS_TO_CREATE
;
5556 server_startup(construct
);
5562 void world_destroy(void *p
)
5564 server_startup_st
*construct
= (server_startup_st
*)p
;
5565 memcached_server_st
*servers
= (memcached_server_st
*)construct
->servers
;
5566 memcached_server_list_free(servers
);
5568 server_shutdown(construct
);
5572 void get_world(world_st
*world
)
5574 world
->collections
= collection
;
5575 world
->create
= world_create
;
5576 world
->destroy
= world_destroy
;