1 /* libMemcached Functions Test
2 * Copyright (C) 2006-2009 Brian Aker
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
10 Sample test application.
13 #include "libmemcached/common.h"
20 #include <sys/types.h>
26 #include "clients/generator.h"
27 #include "clients/execute.h"
30 #define INT64_MAX LONG_MAX
33 #define INT32_MAX INT_MAX
39 #ifdef HAVE_LIBMEMCACHEDUTIL
41 #include "libmemcached/memcached_util.h"
44 #include "hash_results.h"
46 #define GLOBAL_COUNT 10000
47 #define GLOBAL2_COUNT 100
48 #define SERVERS_TO_CREATE 5
49 static uint32_t global_count
;
51 static pairs_st
*global_pairs
;
52 static const char *global_keys
[GLOBAL_COUNT
];
53 static size_t global_keys_length
[GLOBAL_COUNT
];
55 static test_return_t
init_test(memcached_st
*not_used
__attribute__((unused
)))
59 (void)memcached_create(&memc
);
60 memcached_free(&memc
);
65 static test_return_t
server_list_null_test(memcached_st
*ptr
__attribute__((unused
)))
67 memcached_server_st
*server_list
;
68 memcached_return_t rc
;
70 server_list
= memcached_server_list_append_with_weight(NULL
, NULL
, 0, 0, NULL
);
71 test_truth(server_list
== NULL
);
73 server_list
= memcached_server_list_append_with_weight(NULL
, "localhost", 0, 0, NULL
);
74 test_truth(server_list
== NULL
);
76 server_list
= memcached_server_list_append_with_weight(NULL
, NULL
, 0, 0, &rc
);
77 test_truth(server_list
== NULL
);
82 #define TEST_PORT_COUNT 7
83 uint32_t test_ports
[TEST_PORT_COUNT
];
85 static memcached_return_t
server_display_function(memcached_st
*ptr
__attribute__((unused
)), memcached_server_st
*server
, void *context
)
88 uint32_t bigger
= *((uint32_t *)(context
));
89 assert(bigger
<= server
->port
);
90 *((uint32_t *)(context
))= server
->port
;
92 return MEMCACHED_SUCCESS
;
95 static test_return_t
server_sort_test(memcached_st
*ptr
__attribute__((unused
)))
98 uint32_t bigger
= 0; /* Prime the value for the test_truth in server_display_function */
99 memcached_return_t rc
;
100 memcached_server_fn callbacks
[1];
101 memcached_st
*local_memc
;
103 local_memc
= memcached_create(NULL
);
104 test_truth(local_memc
);
105 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
107 for (x
= 0; x
< TEST_PORT_COUNT
; x
++)
109 test_ports
[x
]= (uint32_t)random() % 64000;
110 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
111 test_truth(local_memc
->number_of_hosts
== x
+ 1);
112 test_truth(local_memc
->hosts
[0].count
== x
+1);
113 test_truth(rc
== MEMCACHED_SUCCESS
);
116 callbacks
[0]= server_display_function
;
117 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
120 memcached_free(local_memc
);
125 static test_return_t
server_sort2_test(memcached_st
*ptr
__attribute__((unused
)))
127 uint32_t bigger
= 0; /* Prime the value for the test_truth in server_display_function */
128 memcached_return_t rc
;
129 memcached_server_fn callbacks
[1];
130 memcached_st
*local_memc
;
132 local_memc
= memcached_create(NULL
);
133 test_truth(local_memc
);
134 rc
= memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
135 test_truth(rc
== MEMCACHED_SUCCESS
);
137 rc
= memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43043, 0);
138 test_truth(rc
== MEMCACHED_SUCCESS
);
139 test_truth(local_memc
->hosts
[0].port
== 43043);
141 rc
= memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43042, 0);
142 test_truth(rc
== MEMCACHED_SUCCESS
);
143 test_truth(local_memc
->hosts
[0].port
== 43042);
144 test_truth(local_memc
->hosts
[1].port
== 43043);
146 callbacks
[0]= server_display_function
;
147 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
150 memcached_free(local_memc
);
155 static memcached_return_t
server_display_unsort_function(memcached_st
*ptr
__attribute__((unused
)), memcached_server_st
*server
, void *context
)
158 uint32_t x
= *((uint32_t *)(context
));
160 assert(test_ports
[x
] == server
->port
);
161 *((uint32_t *)(context
))= ++x
;
163 return MEMCACHED_SUCCESS
;
166 static test_return_t
server_unsort_test(memcached_st
*ptr
__attribute__((unused
)))
169 uint32_t counter
= 0; /* Prime the value for the test_truth in server_display_function */
170 uint32_t bigger
= 0; /* Prime the value for the test_truth in server_display_function */
171 memcached_return_t rc
;
172 memcached_server_fn callbacks
[1];
173 memcached_st
*local_memc
;
175 local_memc
= memcached_create(NULL
);
176 test_truth(local_memc
);
178 for (x
= 0; x
< TEST_PORT_COUNT
; x
++)
180 test_ports
[x
]= (uint32_t)(random() % 64000);
181 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
182 test_truth(local_memc
->number_of_hosts
== x
+1);
183 test_truth(local_memc
->hosts
[0].count
== x
+1);
184 test_truth(rc
== MEMCACHED_SUCCESS
);
187 callbacks
[0]= server_display_unsort_function
;
188 memcached_server_cursor(local_memc
, callbacks
, (void *)&counter
, 1);
190 /* Now we sort old data! */
191 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
192 callbacks
[0]= server_display_function
;
193 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
196 memcached_free(local_memc
);
201 static test_return_t
allocation_test(memcached_st
*not_used
__attribute__((unused
)))
204 memc
= memcached_create(NULL
);
206 memcached_free(memc
);
211 static test_return_t
clone_test(memcached_st
*memc
)
215 memcached_st
*memc_clone
;
216 memc_clone
= memcached_clone(NULL
, NULL
);
217 test_truth(memc_clone
);
218 memcached_free(memc_clone
);
221 /* Can we init from null? */
223 memcached_st
*memc_clone
;
224 memc_clone
= memcached_clone(NULL
, memc
);
225 test_truth(memc_clone
);
227 test_truth(memc_clone
->call_free
== memc
->call_free
);
228 test_truth(memc_clone
->call_malloc
== memc
->call_malloc
);
229 test_truth(memc_clone
->call_realloc
== memc
->call_realloc
);
230 test_truth(memc_clone
->call_calloc
== memc
->call_calloc
);
231 test_truth(memc_clone
->connect_timeout
== memc
->connect_timeout
);
232 test_truth(memc_clone
->delete_trigger
== memc
->delete_trigger
);
233 test_truth(memc_clone
->distribution
== memc
->distribution
);
234 { // Test all of the flags
235 test_truth(memc_clone
->flags
.no_block
== memc
->flags
.no_block
);
236 test_truth(memc_clone
->flags
.tcp_nodelay
== memc
->flags
.tcp_nodelay
);
237 test_truth(memc_clone
->flags
.reuse_memory
== memc
->flags
.reuse_memory
);
238 test_truth(memc_clone
->flags
.use_cache_lookups
== memc
->flags
.use_cache_lookups
);
239 test_truth(memc_clone
->flags
.support_cas
== memc
->flags
.support_cas
);
240 test_truth(memc_clone
->flags
.buffer_requests
== memc
->flags
.buffer_requests
);
241 test_truth(memc_clone
->flags
.use_sort_hosts
== memc
->flags
.use_sort_hosts
);
242 test_truth(memc_clone
->flags
.verify_key
== memc
->flags
.verify_key
);
243 test_truth(memc_clone
->flags
.ketama_weighted
== memc
->flags
.ketama_weighted
);
244 test_truth(memc_clone
->flags
.binary_protocol
== memc
->flags
.binary_protocol
);
245 test_truth(memc_clone
->flags
.hash_with_prefix_key
== memc
->flags
.hash_with_prefix_key
);
246 test_truth(memc_clone
->flags
.no_reply
== memc
->flags
.no_reply
);
247 test_truth(memc_clone
->flags
.use_udp
== memc
->flags
.use_udp
);
248 test_truth(memc_clone
->flags
.auto_eject_hosts
== memc
->flags
.auto_eject_hosts
);
249 test_truth(memc_clone
->flags
.randomize_replica_read
== memc
->flags
.randomize_replica_read
);
251 test_truth(memc_clone
->get_key_failure
== memc
->get_key_failure
);
252 test_truth(memc_clone
->hash
== memc
->hash
);
253 test_truth(memc_clone
->distribution_hash
== memc
->distribution_hash
);
254 test_truth(memc_clone
->io_bytes_watermark
== memc
->io_bytes_watermark
);
255 test_truth(memc_clone
->io_msg_watermark
== memc
->io_msg_watermark
);
256 test_truth(memc_clone
->io_key_prefetch
== memc
->io_key_prefetch
);
257 test_truth(memc_clone
->on_cleanup
== memc
->on_cleanup
);
258 test_truth(memc_clone
->on_clone
== memc
->on_clone
);
259 test_truth(memc_clone
->poll_timeout
== memc
->poll_timeout
);
260 test_truth(memc_clone
->rcv_timeout
== memc
->rcv_timeout
);
261 test_truth(memc_clone
->recv_size
== memc
->recv_size
);
262 test_truth(memc_clone
->retry_timeout
== memc
->retry_timeout
);
263 test_truth(memc_clone
->send_size
== memc
->send_size
);
264 test_truth(memc_clone
->server_failure_limit
== memc
->server_failure_limit
);
265 test_truth(memc_clone
->snd_timeout
== memc
->snd_timeout
);
266 test_truth(memc_clone
->user_data
== memc
->user_data
);
268 memcached_free(memc_clone
);
271 /* Can we init from struct? */
273 memcached_st declared_clone
;
274 memcached_st
*memc_clone
;
275 memset(&declared_clone
, 0 , sizeof(memcached_st
));
276 memc_clone
= memcached_clone(&declared_clone
, NULL
);
277 test_truth(memc_clone
);
278 memcached_free(memc_clone
);
281 /* Can we init from struct? */
283 memcached_st declared_clone
;
284 memcached_st
*memc_clone
;
285 memset(&declared_clone
, 0 , sizeof(memcached_st
));
286 memc_clone
= memcached_clone(&declared_clone
, memc
);
287 test_truth(memc_clone
);
288 memcached_free(memc_clone
);
294 static test_return_t
userdata_test(memcached_st
*memc
)
297 test_truth(memcached_set_user_data(memc
, foo
) == NULL
);
298 test_truth(memcached_get_user_data(memc
) == foo
);
299 test_truth(memcached_set_user_data(memc
, NULL
) == foo
);
304 static test_return_t
connection_test(memcached_st
*memc
)
306 memcached_return_t rc
;
308 rc
= memcached_server_add_with_weight(memc
, "localhost", 0, 0);
309 test_truth(rc
== MEMCACHED_SUCCESS
);
314 static test_return_t
error_test(memcached_st
*memc
)
316 memcached_return_t rc
;
317 uint32_t values
[] = { 851992627U, 2337886783U, 3196981036U, 4001849190U,
318 982370485U, 1263635348U, 4242906218U, 3829656100U,
319 1891735253U, 334139633U, 2257084983U, 3088286104U,
320 13199785U, 2542027183U, 1097051614U, 199566778U,
321 2748246961U, 2465192557U, 1664094137U, 2405439045U,
322 1842224848U, 692413798U, 3479807801U, 919913813U,
323 4269430871U, 610793021U, 527273862U, 1437122909U,
324 2300930706U, 2943759320U, 674306647U, 2400528935U,
325 54481931U, 4186304426U, 1741088401U, 2979625118U,
326 4159057246U, 3425930182U, 2593724503U};
328 // You have updated the memcache_error messages but not updated docs/tests.
329 test_truth(MEMCACHED_MAXIMUM_RETURN
== 39);
330 for (rc
= MEMCACHED_SUCCESS
; rc
< MEMCACHED_MAXIMUM_RETURN
; rc
++)
333 const char *msg
= memcached_strerror(memc
, rc
);
334 hash_val
= memcached_generate_hash_value(msg
, strlen(msg
),
335 MEMCACHED_HASH_JENKINS
);
336 test_truth(values
[rc
] == hash_val
);
342 static test_return_t
set_test(memcached_st
*memc
)
344 memcached_return_t rc
;
345 const char *key
= "foo";
346 const char *value
= "when we sanitize";
348 rc
= memcached_set(memc
, key
, strlen(key
),
349 value
, strlen(value
),
350 (time_t)0, (uint32_t)0);
351 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
356 static test_return_t
append_test(memcached_st
*memc
)
358 memcached_return_t rc
;
359 const char *key
= "fig";
360 const char *in_value
= "we";
361 char *out_value
= NULL
;
365 rc
= memcached_flush(memc
, 0);
366 test_truth(rc
== MEMCACHED_SUCCESS
);
368 rc
= memcached_set(memc
, key
, strlen(key
),
369 in_value
, strlen(in_value
),
370 (time_t)0, (uint32_t)0);
371 test_truth(rc
== MEMCACHED_SUCCESS
);
373 rc
= memcached_append(memc
, key
, strlen(key
),
374 " the", strlen(" the"),
375 (time_t)0, (uint32_t)0);
376 test_truth(rc
== MEMCACHED_SUCCESS
);
378 rc
= memcached_append(memc
, key
, strlen(key
),
379 " people", strlen(" people"),
380 (time_t)0, (uint32_t)0);
381 test_truth(rc
== MEMCACHED_SUCCESS
);
383 out_value
= memcached_get(memc
, key
, strlen(key
),
384 &value_length
, &flags
, &rc
);
385 test_truth(!memcmp(out_value
, "we the people", strlen("we the people")));
386 test_truth(strlen("we the people") == value_length
);
387 test_truth(rc
== MEMCACHED_SUCCESS
);
393 static test_return_t
append_binary_test(memcached_st
*memc
)
395 memcached_return_t rc
;
396 const char *key
= "numbers";
397 unsigned int *store_ptr
;
398 unsigned int store_list
[] = { 23, 56, 499, 98, 32847, 0 };
404 rc
= memcached_flush(memc
, 0);
405 test_truth(rc
== MEMCACHED_SUCCESS
);
407 rc
= memcached_set(memc
,
410 (time_t)0, (uint32_t)0);
411 test_truth(rc
== MEMCACHED_SUCCESS
);
413 for (x
= 0; store_list
[x
] ; x
++)
415 rc
= memcached_append(memc
,
417 (char *)&store_list
[x
], sizeof(unsigned int),
418 (time_t)0, (uint32_t)0);
419 test_truth(rc
== MEMCACHED_SUCCESS
);
422 value
= memcached_get(memc
, key
, strlen(key
),
423 &value_length
, &flags
, &rc
);
424 test_truth((value_length
== (sizeof(unsigned int) * x
)));
425 test_truth(rc
== MEMCACHED_SUCCESS
);
427 store_ptr
= (unsigned int *)value
;
429 while ((size_t)store_ptr
< (size_t)(value
+ value_length
))
431 test_truth(*store_ptr
== store_list
[x
++]);
439 static test_return_t
cas2_test(memcached_st
*memc
)
441 memcached_return_t rc
;
442 const char *keys
[]= {"fudge", "son", "food"};
443 size_t key_length
[]= {5, 3, 4};
444 const char *value
= "we the people";
445 size_t value_length
= strlen("we the people");
447 memcached_result_st results_obj
;
448 memcached_result_st
*results
;
451 rc
= memcached_flush(memc
, 0);
452 test_truth(rc
== MEMCACHED_SUCCESS
);
454 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
456 for (x
= 0; x
< 3; x
++)
458 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
459 keys
[x
], key_length
[x
],
460 (time_t)50, (uint32_t)9);
461 test_truth(rc
== MEMCACHED_SUCCESS
);
464 rc
= memcached_mget(memc
, keys
, key_length
, 3);
466 results
= memcached_result_create(memc
, &results_obj
);
468 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
470 test_truth(results
->cas
);
471 test_truth(rc
== MEMCACHED_SUCCESS
);
472 test_truth(memcached_result_cas(results
));
474 test_truth(!memcmp(value
, "we the people", strlen("we the people")));
475 test_truth(strlen("we the people") == value_length
);
476 test_truth(rc
== MEMCACHED_SUCCESS
);
478 memcached_result_free(&results_obj
);
483 static test_return_t
cas_test(memcached_st
*memc
)
485 memcached_return_t rc
;
486 const char *key
= "fun";
487 size_t key_length
= strlen(key
);
488 const char *value
= "we the people";
489 const char* keys
[2] = { key
, NULL
};
490 size_t keylengths
[2] = { strlen(key
), 0 };
491 size_t value_length
= strlen(value
);
492 const char *value2
= "change the value";
493 size_t value2_length
= strlen(value2
);
495 memcached_result_st results_obj
;
496 memcached_result_st
*results
;
499 rc
= memcached_flush(memc
, 0);
500 test_truth(rc
== MEMCACHED_SUCCESS
);
502 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
504 rc
= memcached_set(memc
, key
, strlen(key
),
505 value
, strlen(value
),
506 (time_t)0, (uint32_t)0);
507 test_truth(rc
== MEMCACHED_SUCCESS
);
509 rc
= memcached_mget(memc
, keys
, keylengths
, 1);
511 results
= memcached_result_create(memc
, &results_obj
);
513 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
515 test_truth(rc
== MEMCACHED_SUCCESS
);
516 test_truth(memcached_result_cas(results
));
517 test_truth(!memcmp(value
, memcached_result_value(results
), value_length
));
518 test_truth(strlen(memcached_result_value(results
)) == value_length
);
519 test_truth(rc
== MEMCACHED_SUCCESS
);
520 uint64_t cas
= memcached_result_cas(results
);
523 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
524 test_truth(rc
== MEMCACHED_END
);
525 test_truth(results
== NULL
);
528 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
529 test_truth(rc
== MEMCACHED_SUCCESS
);
532 * The item will have a new cas value, so try to set it again with the old
533 * value. This should fail!
535 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
536 test_truth(rc
== MEMCACHED_DATA_EXISTS
);
538 memcached_result_free(&results_obj
);
543 static test_return_t
prepend_test(memcached_st
*memc
)
545 memcached_return_t rc
;
546 const char *key
= "fig";
547 const char *value
= "people";
548 char *out_value
= NULL
;
552 rc
= memcached_flush(memc
, 0);
553 test_truth(rc
== MEMCACHED_SUCCESS
);
555 rc
= memcached_set(memc
, key
, strlen(key
),
556 value
, strlen(value
),
557 (time_t)0, (uint32_t)0);
558 test_truth(rc
== MEMCACHED_SUCCESS
);
560 rc
= memcached_prepend(memc
, key
, strlen(key
),
561 "the ", strlen("the "),
562 (time_t)0, (uint32_t)0);
563 test_truth(rc
== MEMCACHED_SUCCESS
);
565 rc
= memcached_prepend(memc
, key
, strlen(key
),
566 "we ", strlen("we "),
567 (time_t)0, (uint32_t)0);
568 test_truth(rc
== MEMCACHED_SUCCESS
);
570 out_value
= memcached_get(memc
, key
, strlen(key
),
571 &value_length
, &flags
, &rc
);
572 test_truth(!memcmp(out_value
, "we the people", strlen("we the people")));
573 test_truth(strlen("we the people") == value_length
);
574 test_truth(rc
== MEMCACHED_SUCCESS
);
581 Set the value, then quit to make sure it is flushed.
582 Come back in and test that add fails.
584 static test_return_t
add_test(memcached_st
*memc
)
586 memcached_return_t rc
;
587 const char *key
= "foo";
588 const char *value
= "when we sanitize";
589 unsigned long long setting_value
;
591 setting_value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
593 rc
= memcached_set(memc
, key
, strlen(key
),
594 value
, strlen(value
),
595 (time_t)0, (uint32_t)0);
596 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
597 memcached_quit(memc
);
598 rc
= memcached_add(memc
, key
, strlen(key
),
599 value
, strlen(value
),
600 (time_t)0, (uint32_t)0);
602 /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */
605 test_truth(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_STORED
);
609 test_truth(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_DATA_EXISTS
);
616 ** There was a problem of leaking filedescriptors in the initial release
617 ** of MacOSX 10.5. This test case triggers the problem. On some Solaris
618 ** systems it seems that the kernel is slow on reclaiming the resources
619 ** because the connects starts to time out (the test doesn't do much
620 ** anyway, so just loop 10 iterations)
622 static test_return_t
add_wrapper(memcached_st
*memc
)
625 unsigned int max
= 10000;
633 for (x
= 0; x
< max
; x
++)
639 static test_return_t
replace_test(memcached_st
*memc
)
641 memcached_return_t rc
;
642 const char *key
= "foo";
643 const char *value
= "when we sanitize";
644 const char *original
= "first we insert some data";
646 rc
= memcached_set(memc
, key
, strlen(key
),
647 original
, strlen(original
),
648 (time_t)0, (uint32_t)0);
649 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
651 rc
= memcached_replace(memc
, key
, strlen(key
),
652 value
, strlen(value
),
653 (time_t)0, (uint32_t)0);
654 test_truth(rc
== MEMCACHED_SUCCESS
);
659 static test_return_t
delete_test(memcached_st
*memc
)
661 memcached_return_t rc
;
662 const char *key
= "foo";
663 const char *value
= "when we sanitize";
665 rc
= memcached_set(memc
, key
, strlen(key
),
666 value
, strlen(value
),
667 (time_t)0, (uint32_t)0);
668 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
670 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
671 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
676 static test_return_t
flush_test(memcached_st
*memc
)
678 memcached_return_t rc
;
680 rc
= memcached_flush(memc
, 0);
681 test_truth(rc
== MEMCACHED_SUCCESS
);
686 static memcached_return_t
server_function(memcached_st
*ptr
__attribute__((unused
)),
687 memcached_server_st
*server
__attribute__((unused
)),
688 void *context
__attribute__((unused
)))
692 return MEMCACHED_SUCCESS
;
695 static test_return_t
memcached_server_cursor_test(memcached_st
*memc
)
698 strcpy(context
, "foo bad");
699 memcached_server_fn callbacks
[1];
701 callbacks
[0]= server_function
;
702 memcached_server_cursor(memc
, callbacks
, context
, 1);
706 static test_return_t
bad_key_test(memcached_st
*memc
)
708 memcached_return_t rc
;
709 const char *key
= "foo bad";
711 size_t string_length
;
713 memcached_st
*memc_clone
;
715 size_t max_keylen
= 0xffff;
717 // Just skip if we are in binary mode.
718 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
))
721 memc_clone
= memcached_clone(NULL
, memc
);
722 test_truth(memc_clone
);
724 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
725 test_truth(rc
== MEMCACHED_SUCCESS
);
727 /* All keys are valid in the binary protocol (except for length) */
728 if (memcached_behavior_get(memc_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 0)
730 string
= memcached_get(memc_clone
, key
, strlen(key
),
731 &string_length
, &flags
, &rc
);
732 test_truth(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
733 test_truth(string_length
== 0);
737 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
738 test_truth(rc
== MEMCACHED_SUCCESS
);
739 string
= memcached_get(memc_clone
, key
, strlen(key
),
740 &string_length
, &flags
, &rc
);
741 test_truth(rc
== MEMCACHED_NOTFOUND
);
742 test_truth(string_length
== 0);
745 /* Test multi key for bad keys */
746 const char *keys
[] = { "GoodKey", "Bad Key", "NotMine" };
747 size_t key_lengths
[] = { 7, 7, 7 };
749 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
750 test_truth(rc
== MEMCACHED_SUCCESS
);
752 rc
= memcached_mget(memc_clone
, keys
, key_lengths
, 3);
753 test_truth(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
755 rc
= memcached_mget_by_key(memc_clone
, "foo daddy", 9, keys
, key_lengths
, 1);
756 test_truth(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
760 /* The following test should be moved to the end of this function when the
761 memcached server is updated to allow max size length of the keys in the
764 rc
= memcached_callback_set(memc_clone
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
765 test_truth(rc
== MEMCACHED_SUCCESS
);
767 char *longkey
= malloc(max_keylen
+ 1);
770 memset(longkey
, 'a', max_keylen
+ 1);
771 string
= memcached_get(memc_clone
, longkey
, max_keylen
,
772 &string_length
, &flags
, &rc
);
773 test_truth(rc
== MEMCACHED_NOTFOUND
);
774 test_truth(string_length
== 0);
777 string
= memcached_get(memc_clone
, longkey
, max_keylen
+ 1,
778 &string_length
, &flags
, &rc
);
779 test_truth(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
780 test_truth(string_length
== 0);
787 /* Make sure zero length keys are marked as bad */
789 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
790 test_truth(rc
== MEMCACHED_SUCCESS
);
791 string
= memcached_get(memc_clone
, key
, 0,
792 &string_length
, &flags
, &rc
);
793 test_truth(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
794 test_truth(string_length
== 0);
797 memcached_free(memc_clone
);
802 #define READ_THROUGH_VALUE "set for me"
803 static memcached_return_t
read_through_trigger(memcached_st
*memc
__attribute__((unused
)),
804 char *key
__attribute__((unused
)),
805 size_t key_length
__attribute__((unused
)),
806 memcached_result_st
*result
)
809 return memcached_result_set_value(result
, READ_THROUGH_VALUE
, strlen(READ_THROUGH_VALUE
));
812 static test_return_t
read_through(memcached_st
*memc
)
814 memcached_return_t rc
;
815 const char *key
= "foo";
817 size_t string_length
;
819 memcached_trigger_key_fn cb
= (memcached_trigger_key_fn
)read_through_trigger
;
821 string
= memcached_get(memc
, key
, strlen(key
),
822 &string_length
, &flags
, &rc
);
824 test_truth(rc
== MEMCACHED_NOTFOUND
);
825 test_false(string_length
);
828 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_GET_FAILURE
,
830 test_truth(rc
== MEMCACHED_SUCCESS
);
832 string
= memcached_get(memc
, key
, strlen(key
),
833 &string_length
, &flags
, &rc
);
835 test_truth(rc
== MEMCACHED_SUCCESS
);
836 test_truth(string_length
== strlen(READ_THROUGH_VALUE
));
837 test_strcmp(READ_THROUGH_VALUE
, string
);
840 string
= memcached_get(memc
, key
, strlen(key
),
841 &string_length
, &flags
, &rc
);
843 test_truth(rc
== MEMCACHED_SUCCESS
);
844 test_truth(string_length
== strlen(READ_THROUGH_VALUE
));
845 test_truth(!strcmp(READ_THROUGH_VALUE
, string
));
851 static memcached_return_t
delete_trigger(memcached_st
*ptr
__attribute__((unused
)),
853 size_t key_length
__attribute__((unused
)))
857 return MEMCACHED_SUCCESS
;
860 static test_return_t
delete_through(memcached_st
*memc
)
862 memcached_trigger_delete_key_fn callback
;
863 memcached_return_t rc
;
865 callback
= (memcached_trigger_delete_key_fn
)delete_trigger
;
867 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_DELETE_TRIGGER
, *(void**)&callback
);
868 test_truth(rc
== MEMCACHED_SUCCESS
);
873 static test_return_t
get_test(memcached_st
*memc
)
875 memcached_return_t rc
;
876 const char *key
= "foo";
878 size_t string_length
;
881 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
882 test_truth(rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_NOTFOUND
);
884 string
= memcached_get(memc
, key
, strlen(key
),
885 &string_length
, &flags
, &rc
);
887 test_truth(rc
== MEMCACHED_NOTFOUND
);
888 test_false(string_length
);
894 static test_return_t
get_test2(memcached_st
*memc
)
896 memcached_return_t rc
;
897 const char *key
= "foo";
898 const char *value
= "when we sanitize";
900 size_t string_length
;
903 rc
= memcached_set(memc
, key
, strlen(key
),
904 value
, strlen(value
),
905 (time_t)0, (uint32_t)0);
906 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
908 string
= memcached_get(memc
, key
, strlen(key
),
909 &string_length
, &flags
, &rc
);
912 test_truth(rc
== MEMCACHED_SUCCESS
);
913 test_truth(string_length
== strlen(value
));
914 test_truth(!memcmp(string
, value
, string_length
));
921 static test_return_t
set_test2(memcached_st
*memc
)
923 memcached_return_t rc
;
924 const char *key
= "foo";
925 const char *value
= "train in the brain";
926 size_t value_length
= strlen(value
);
929 for (x
= 0; x
< 10; x
++)
931 rc
= memcached_set(memc
, key
, strlen(key
),
933 (time_t)0, (uint32_t)0);
934 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
940 static test_return_t
set_test3(memcached_st
*memc
)
942 memcached_return_t rc
;
944 size_t value_length
= 8191;
947 value
= (char*)malloc(value_length
);
950 for (x
= 0; x
< value_length
; x
++)
951 value
[x
] = (char) (x
% 127);
953 /* The dump test relies on there being at least 32 items in memcached */
954 for (x
= 0; x
< 32; x
++)
958 sprintf(key
, "foo%u", x
);
960 rc
= memcached_set(memc
, key
, strlen(key
),
962 (time_t)0, (uint32_t)0);
963 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
971 static test_return_t
get_test3(memcached_st
*memc
)
973 memcached_return_t rc
;
974 const char *key
= "foo";
976 size_t value_length
= 8191;
978 size_t string_length
;
982 value
= (char*)malloc(value_length
);
985 for (x
= 0; x
< value_length
; x
++)
986 value
[x
] = (char) (x
% 127);
988 rc
= memcached_set(memc
, key
, strlen(key
),
990 (time_t)0, (uint32_t)0);
991 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
993 string
= memcached_get(memc
, key
, strlen(key
),
994 &string_length
, &flags
, &rc
);
996 test_truth(rc
== MEMCACHED_SUCCESS
);
998 test_truth(string_length
== value_length
);
999 test_truth(!memcmp(string
, value
, string_length
));
1004 return TEST_SUCCESS
;
1007 static test_return_t
get_test4(memcached_st
*memc
)
1009 memcached_return_t rc
;
1010 const char *key
= "foo";
1012 size_t value_length
= 8191;
1014 size_t string_length
;
1018 value
= (char*)malloc(value_length
);
1021 for (x
= 0; x
< value_length
; x
++)
1022 value
[x
] = (char) (x
% 127);
1024 rc
= memcached_set(memc
, key
, strlen(key
),
1025 value
, value_length
,
1026 (time_t)0, (uint32_t)0);
1027 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1029 for (x
= 0; x
< 10; x
++)
1031 string
= memcached_get(memc
, key
, strlen(key
),
1032 &string_length
, &flags
, &rc
);
1034 test_truth(rc
== MEMCACHED_SUCCESS
);
1036 test_truth(string_length
== value_length
);
1037 test_truth(!memcmp(string
, value
, string_length
));
1043 return TEST_SUCCESS
;
1047 * This test verifies that memcached_read_one_response doesn't try to
1048 * dereference a NIL-pointer if you issue a multi-get and don't read out all
1049 * responses before you execute a storage command.
1051 static test_return_t
get_test5(memcached_st
*memc
)
1054 ** Request the same key twice, to ensure that we hash to the same server
1055 ** (so that we have multiple response values queued up) ;-)
1057 const char *keys
[]= { "key", "key" };
1058 size_t lengths
[]= { 3, 3 };
1062 memcached_return_t rc
= memcached_set(memc
, keys
[0], lengths
[0],
1063 keys
[0], lengths
[0], 0, 0);
1064 test_truth(rc
== MEMCACHED_SUCCESS
);
1065 rc
= memcached_mget(memc
, keys
, lengths
, 2);
1067 memcached_result_st results_obj
;
1068 memcached_result_st
*results
;
1069 results
=memcached_result_create(memc
, &results_obj
);
1070 test_truth(results
);
1071 results
=memcached_fetch_result(memc
, &results_obj
, &rc
);
1072 test_truth(results
);
1073 memcached_result_free(&results_obj
);
1075 /* Don't read out the second result, but issue a set instead.. */
1076 rc
= memcached_set(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0);
1077 test_truth(rc
== MEMCACHED_SUCCESS
);
1079 char *val
= memcached_get_by_key(memc
, keys
[0], lengths
[0], "yek", 3,
1080 &rlen
, &flags
, &rc
);
1081 test_truth(val
== NULL
);
1082 test_truth(rc
== MEMCACHED_NOTFOUND
);
1083 val
= memcached_get(memc
, keys
[0], lengths
[0], &rlen
, &flags
, &rc
);
1084 test_truth(val
!= NULL
);
1085 test_truth(rc
== MEMCACHED_SUCCESS
);
1088 return TEST_SUCCESS
;
1091 static test_return_t
mget_end(memcached_st
*memc
)
1093 const char *keys
[]= { "foo", "foo2" };
1094 size_t lengths
[]= { 3, 4 };
1095 const char *values
[]= { "fjord", "41" };
1097 memcached_return_t rc
;
1100 for (int i
= 0; i
< 2; i
++)
1102 rc
= memcached_set(memc
, keys
[i
], lengths
[i
], values
[i
], strlen(values
[i
]),
1103 (time_t)0, (uint32_t)0);
1104 test_truth(rc
== MEMCACHED_SUCCESS
);
1108 size_t string_length
;
1111 // retrieve both via mget
1112 rc
= memcached_mget(memc
, keys
, lengths
, 2);
1113 test_truth(rc
== MEMCACHED_SUCCESS
);
1115 char key
[MEMCACHED_MAX_KEY
];
1118 // this should get both
1119 for (int i
= 0; i
< 2; i
++)
1121 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
,
1123 test_truth(rc
== MEMCACHED_SUCCESS
);
1125 if (key_length
== 4)
1127 test_truth(string_length
== strlen(values
[val
]));
1128 test_truth(strncmp(values
[val
], string
, string_length
) == 0);
1132 // this should indicate end
1133 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1134 test_truth(rc
== MEMCACHED_END
);
1137 rc
= memcached_mget(memc
, keys
, lengths
, 1);
1138 test_truth(rc
== MEMCACHED_SUCCESS
);
1140 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1141 test_truth(key_length
== lengths
[0]);
1142 test_truth(strncmp(keys
[0], key
, key_length
) == 0);
1143 test_truth(string_length
== strlen(values
[0]));
1144 test_truth(strncmp(values
[0], string
, string_length
) == 0);
1145 test_truth(rc
== MEMCACHED_SUCCESS
);
1148 // this should indicate end
1149 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1150 test_truth(rc
== MEMCACHED_END
);
1152 return TEST_SUCCESS
;
1155 /* Do not copy the style of this code, I just access hosts to testthis function */
1156 static test_return_t
stats_servername_test(memcached_st
*memc
)
1158 memcached_return_t rc
;
1159 memcached_stat_st memc_stat
;
1160 rc
= memcached_stat_servername(&memc_stat
, NULL
,
1161 memc
->hosts
[0].hostname
,
1162 memc
->hosts
[0].port
);
1164 return TEST_SUCCESS
;
1167 static test_return_t
increment_test(memcached_st
*memc
)
1169 uint64_t new_number
;
1170 memcached_return_t rc
;
1171 const char *key
= "number";
1172 const char *value
= "0";
1174 rc
= memcached_set(memc
, key
, strlen(key
),
1175 value
, strlen(value
),
1176 (time_t)0, (uint32_t)0);
1177 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1179 rc
= memcached_increment(memc
, key
, strlen(key
),
1181 test_truth(rc
== MEMCACHED_SUCCESS
);
1182 test_truth(new_number
== 1);
1184 rc
= memcached_increment(memc
, key
, strlen(key
),
1186 test_truth(rc
== MEMCACHED_SUCCESS
);
1187 test_truth(new_number
== 2);
1189 return TEST_SUCCESS
;
1192 static test_return_t
increment_with_initial_test(memcached_st
*memc
)
1194 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1196 uint64_t new_number
;
1197 memcached_return_t rc
;
1198 const char *key
= "number";
1199 uint64_t initial
= 0;
1201 rc
= memcached_increment_with_initial(memc
, key
, strlen(key
),
1202 1, initial
, 0, &new_number
);
1203 test_truth(rc
== MEMCACHED_SUCCESS
);
1204 test_truth(new_number
== initial
);
1206 rc
= memcached_increment_with_initial(memc
, key
, strlen(key
),
1207 1, initial
, 0, &new_number
);
1208 test_truth(rc
== MEMCACHED_SUCCESS
);
1209 test_truth(new_number
== (initial
+ 1));
1211 return TEST_SUCCESS
;
1214 static test_return_t
decrement_test(memcached_st
*memc
)
1216 uint64_t new_number
;
1217 memcached_return_t rc
;
1218 const char *key
= "number";
1219 const char *value
= "3";
1221 rc
= memcached_set(memc
, key
, strlen(key
),
1222 value
, strlen(value
),
1223 (time_t)0, (uint32_t)0);
1224 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1226 rc
= memcached_decrement(memc
, key
, strlen(key
),
1228 test_truth(rc
== MEMCACHED_SUCCESS
);
1229 test_truth(new_number
== 2);
1231 rc
= memcached_decrement(memc
, key
, strlen(key
),
1233 test_truth(rc
== MEMCACHED_SUCCESS
);
1234 test_truth(new_number
== 1);
1236 return TEST_SUCCESS
;
1239 static test_return_t
decrement_with_initial_test(memcached_st
*memc
)
1241 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1243 uint64_t new_number
;
1244 memcached_return_t rc
;
1245 const char *key
= "number";
1246 uint64_t initial
= 3;
1248 rc
= memcached_decrement_with_initial(memc
, key
, strlen(key
),
1249 1, initial
, 0, &new_number
);
1250 test_truth(rc
== MEMCACHED_SUCCESS
);
1251 test_truth(new_number
== initial
);
1253 rc
= memcached_decrement_with_initial(memc
, key
, strlen(key
),
1254 1, initial
, 0, &new_number
);
1255 test_truth(rc
== MEMCACHED_SUCCESS
);
1256 test_truth(new_number
== (initial
- 1));
1258 return TEST_SUCCESS
;
1261 static test_return_t
increment_by_key_test(memcached_st
*memc
)
1263 uint64_t new_number
;
1264 memcached_return_t rc
;
1265 const char *master_key
= "foo";
1266 const char *key
= "number";
1267 const char *value
= "0";
1269 rc
= memcached_set_by_key(memc
, master_key
, strlen(master_key
),
1271 value
, strlen(value
),
1272 (time_t)0, (uint32_t)0);
1273 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1275 rc
= memcached_increment_by_key(memc
, master_key
, strlen(master_key
), key
, strlen(key
),
1277 test_truth(rc
== MEMCACHED_SUCCESS
);
1278 test_truth(new_number
== 1);
1280 rc
= memcached_increment_by_key(memc
, master_key
, strlen(master_key
), key
, strlen(key
),
1282 test_truth(rc
== MEMCACHED_SUCCESS
);
1283 test_truth(new_number
== 2);
1285 return TEST_SUCCESS
;
1288 static test_return_t
increment_with_initial_by_key_test(memcached_st
*memc
)
1290 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1292 uint64_t new_number
;
1293 memcached_return_t rc
;
1294 const char *master_key
= "foo";
1295 const char *key
= "number";
1296 uint64_t initial
= 0;
1298 rc
= memcached_increment_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1300 1, initial
, 0, &new_number
);
1301 test_truth(rc
== MEMCACHED_SUCCESS
);
1302 test_truth(new_number
== initial
);
1304 rc
= memcached_increment_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1306 1, initial
, 0, &new_number
);
1307 test_truth(rc
== MEMCACHED_SUCCESS
);
1308 test_truth(new_number
== (initial
+ 1));
1310 return TEST_SUCCESS
;
1313 static test_return_t
decrement_by_key_test(memcached_st
*memc
)
1315 uint64_t new_number
;
1316 memcached_return_t rc
;
1317 const char *master_key
= "foo";
1318 const char *key
= "number";
1319 const char *value
= "3";
1321 rc
= memcached_set_by_key(memc
, master_key
, strlen(master_key
),
1323 value
, strlen(value
),
1324 (time_t)0, (uint32_t)0);
1325 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1327 rc
= memcached_decrement_by_key(memc
, master_key
, strlen(master_key
),
1330 test_truth(rc
== MEMCACHED_SUCCESS
);
1331 test_truth(new_number
== 2);
1333 rc
= memcached_decrement_by_key(memc
, master_key
, strlen(master_key
),
1336 test_truth(rc
== MEMCACHED_SUCCESS
);
1337 test_truth(new_number
== 1);
1339 return TEST_SUCCESS
;
1342 static test_return_t
decrement_with_initial_by_key_test(memcached_st
*memc
)
1344 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1346 uint64_t new_number
;
1347 memcached_return_t rc
;
1348 const char *master_key
= "foo";
1349 const char *key
= "number";
1350 uint64_t initial
= 3;
1352 rc
= memcached_decrement_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1354 1, initial
, 0, &new_number
);
1355 test_truth(rc
== MEMCACHED_SUCCESS
);
1356 test_truth(new_number
== initial
);
1358 rc
= memcached_decrement_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1360 1, initial
, 0, &new_number
);
1361 test_truth(rc
== MEMCACHED_SUCCESS
);
1362 test_truth(new_number
== (initial
- 1));
1364 return TEST_SUCCESS
;
1367 static test_return_t
quit_test(memcached_st
*memc
)
1369 memcached_return_t rc
;
1370 const char *key
= "fudge";
1371 const char *value
= "sanford and sun";
1373 rc
= memcached_set(memc
, key
, strlen(key
),
1374 value
, strlen(value
),
1375 (time_t)10, (uint32_t)3);
1376 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1377 memcached_quit(memc
);
1379 rc
= memcached_set(memc
, key
, strlen(key
),
1380 value
, strlen(value
),
1381 (time_t)50, (uint32_t)9);
1382 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1384 return TEST_SUCCESS
;
1387 static test_return_t
mget_result_test(memcached_st
*memc
)
1389 memcached_return_t rc
;
1390 const char *keys
[]= {"fudge", "son", "food"};
1391 size_t key_length
[]= {5, 3, 4};
1394 memcached_result_st results_obj
;
1395 memcached_result_st
*results
;
1397 results
= memcached_result_create(memc
, &results_obj
);
1398 test_truth(results
);
1399 test_truth(&results_obj
== results
);
1401 /* We need to empty the server before continueing test */
1402 rc
= memcached_flush(memc
, 0);
1403 test_truth(rc
== MEMCACHED_SUCCESS
);
1405 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1406 test_truth(rc
== MEMCACHED_SUCCESS
);
1408 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1410 test_truth(results
);
1413 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1414 test_truth(!results
);
1415 test_truth(rc
== MEMCACHED_END
);
1417 for (x
= 0; x
< 3; x
++)
1419 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1420 keys
[x
], key_length
[x
],
1421 (time_t)50, (uint32_t)9);
1422 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1425 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1426 test_truth(rc
== MEMCACHED_SUCCESS
);
1428 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1430 test_truth(results
);
1431 test_truth(&results_obj
== results
);
1432 test_truth(rc
== MEMCACHED_SUCCESS
);
1433 test_truth(memcached_result_key_length(results
) == memcached_result_length(results
));
1434 test_truth(!memcmp(memcached_result_key_value(results
),
1435 memcached_result_value(results
),
1436 memcached_result_length(results
)));
1439 memcached_result_free(&results_obj
);
1441 return TEST_SUCCESS
;
1444 static test_return_t
mget_result_alloc_test(memcached_st
*memc
)
1446 memcached_return_t rc
;
1447 const char *keys
[]= {"fudge", "son", "food"};
1448 size_t key_length
[]= {5, 3, 4};
1451 memcached_result_st
*results
;
1453 /* We need to empty the server before continueing test */
1454 rc
= memcached_flush(memc
, 0);
1455 test_truth(rc
== MEMCACHED_SUCCESS
);
1457 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1458 test_truth(rc
== MEMCACHED_SUCCESS
);
1460 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)) != NULL
)
1462 test_truth(results
);
1464 test_truth(!results
);
1465 test_truth(rc
== MEMCACHED_END
);
1467 for (x
= 0; x
< 3; x
++)
1469 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1470 keys
[x
], key_length
[x
],
1471 (time_t)50, (uint32_t)9);
1472 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1475 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1476 test_truth(rc
== MEMCACHED_SUCCESS
);
1479 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1481 test_truth(results
);
1482 test_truth(rc
== MEMCACHED_SUCCESS
);
1483 test_truth(memcached_result_key_length(results
) == memcached_result_length(results
));
1484 test_truth(!memcmp(memcached_result_key_value(results
),
1485 memcached_result_value(results
),
1486 memcached_result_length(results
)));
1487 memcached_result_free(results
);
1491 return TEST_SUCCESS
;
1494 /* Count the results */
1495 static memcached_return_t
callback_counter(memcached_st
*ptr
__attribute__((unused
)),
1496 memcached_result_st
*result
__attribute__((unused
)),
1499 unsigned int *counter
= (unsigned int *)context
;
1501 *counter
= *counter
+ 1;
1503 return MEMCACHED_SUCCESS
;
1506 static test_return_t
mget_result_function(memcached_st
*memc
)
1508 memcached_return_t rc
;
1509 const char *keys
[]= {"fudge", "son", "food"};
1510 size_t key_length
[]= {5, 3, 4};
1512 unsigned int counter
;
1513 memcached_execute_fn callbacks
[1];
1515 /* We need to empty the server before continueing test */
1516 rc
= memcached_flush(memc
, 0);
1517 for (x
= 0; x
< 3; x
++)
1519 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1520 keys
[x
], key_length
[x
],
1521 (time_t)50, (uint32_t)9);
1522 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1525 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1526 test_truth(rc
== MEMCACHED_SUCCESS
);
1528 callbacks
[0]= &callback_counter
;
1530 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
1532 test_truth(counter
== 3);
1534 return TEST_SUCCESS
;
1537 static test_return_t
mget_test(memcached_st
*memc
)
1539 memcached_return_t rc
;
1540 const char *keys
[]= {"fudge", "son", "food"};
1541 size_t key_length
[]= {5, 3, 4};
1545 char return_key
[MEMCACHED_MAX_KEY
];
1546 size_t return_key_length
;
1548 size_t return_value_length
;
1550 /* We need to empty the server before continueing test */
1551 rc
= memcached_flush(memc
, 0);
1552 test_truth(rc
== MEMCACHED_SUCCESS
);
1554 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1555 test_truth(rc
== MEMCACHED_SUCCESS
);
1557 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1558 &return_value_length
, &flags
, &rc
)) != NULL
)
1560 test_truth(return_value
);
1562 test_truth(!return_value
);
1563 test_truth(return_value_length
== 0);
1564 test_truth(rc
== MEMCACHED_END
);
1566 for (x
= 0; x
< 3; x
++)
1568 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1569 keys
[x
], key_length
[x
],
1570 (time_t)50, (uint32_t)9);
1571 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1574 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1575 test_truth(rc
== MEMCACHED_SUCCESS
);
1578 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1579 &return_value_length
, &flags
, &rc
)))
1581 test_truth(return_value
);
1582 test_truth(rc
== MEMCACHED_SUCCESS
);
1583 test_truth(return_key_length
== return_value_length
);
1584 test_truth(!memcmp(return_value
, return_key
, return_value_length
));
1589 return TEST_SUCCESS
;
1592 static test_return_t
mget_execute(memcached_st
*memc
)
1595 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1599 * I only want to hit _one_ server so I know the number of requests I'm
1600 * sending in the pipeline.
1602 uint32_t number_of_hosts
= memc
->number_of_hosts
;
1603 memc
->number_of_hosts
= 1;
1605 int max_keys
= binary
? 20480 : 1;
1608 char **keys
= calloc((size_t)max_keys
, sizeof(char*));
1609 size_t *key_length
=calloc((size_t)max_keys
, sizeof(size_t));
1611 /* First add all of the items.. */
1612 char blob
[1024] = {0};
1613 memcached_return_t rc
;
1614 for (int x
= 0; x
< max_keys
; ++x
)
1617 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%u", x
);
1619 test_truth(keys
[x
] != NULL
);
1620 rc
= memcached_add(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
1621 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1624 /* Try to get all of them with a large multiget */
1625 unsigned int counter
= 0;
1626 memcached_execute_fn callbacks
[1]= { [0]= &callback_counter
};
1627 rc
= memcached_mget_execute(memc
, (const char**)keys
, key_length
,
1628 (size_t)max_keys
, callbacks
, &counter
, 1);
1632 test_truth(rc
== MEMCACHED_SUCCESS
);
1634 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
1635 test_truth(rc
== MEMCACHED_END
);
1637 /* Verify that we got all of the items */
1638 test_truth(counter
== (unsigned int)max_keys
);
1642 test_truth(rc
== MEMCACHED_NOT_SUPPORTED
);
1643 test_truth(counter
== 0);
1646 /* Release all allocated resources */
1647 for (int x
= 0; x
< max_keys
; ++x
)
1652 memc
->number_of_hosts
= number_of_hosts
;
1653 return TEST_SUCCESS
;
1656 static test_return_t
get_stats_keys(memcached_st
*memc
)
1660 memcached_stat_st memc_stat
;
1661 memcached_return_t rc
;
1663 stat_list
= memcached_stat_get_keys(memc
, &memc_stat
, &rc
);
1664 test_truth(rc
== MEMCACHED_SUCCESS
);
1665 for (ptr
= stat_list
; *ptr
; ptr
++)
1670 return TEST_SUCCESS
;
1673 static test_return_t
version_string_test(memcached_st
*memc
__attribute__((unused
)))
1675 const char *version_string
;
1677 version_string
= memcached_lib_version();
1679 test_truth(!strcmp(version_string
, LIBMEMCACHED_VERSION_STRING
));
1681 return TEST_SUCCESS
;
1684 static test_return_t
get_stats(memcached_st
*memc
)
1689 memcached_return_t rc
;
1690 memcached_stat_st
*memc_stat
;
1692 memc_stat
= memcached_stat(memc
, NULL
, &rc
);
1693 test_truth(rc
== MEMCACHED_SUCCESS
);
1695 test_truth(rc
== MEMCACHED_SUCCESS
);
1696 test_truth(memc_stat
);
1698 for (x
= 0; x
< memcached_server_count(memc
); x
++)
1700 stat_list
= memcached_stat_get_keys(memc
, memc_stat
+x
, &rc
);
1701 test_truth(rc
== MEMCACHED_SUCCESS
);
1702 for (ptr
= stat_list
; *ptr
; ptr
++);
1707 memcached_stat_free(NULL
, memc_stat
);
1709 return TEST_SUCCESS
;
1712 static test_return_t
add_host_test(memcached_st
*memc
)
1715 memcached_server_st
*servers
;
1716 memcached_return_t rc
;
1717 char servername
[]= "0.example.com";
1719 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
1720 test_truth(servers
);
1721 test_truth(1 == memcached_server_list_count(servers
));
1723 for (x
= 2; x
< 20; x
++)
1725 char buffer
[SMALL_STRING_LEN
];
1727 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
1728 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
1730 test_truth(rc
== MEMCACHED_SUCCESS
);
1731 test_truth(x
== memcached_server_list_count(servers
));
1734 rc
= memcached_server_push(memc
, servers
);
1735 test_truth(rc
== MEMCACHED_SUCCESS
);
1736 rc
= memcached_server_push(memc
, servers
);
1737 test_truth(rc
== MEMCACHED_SUCCESS
);
1739 memcached_server_list_free(servers
);
1741 return TEST_SUCCESS
;
1744 static memcached_return_t
clone_test_callback(memcached_st
*parent
__attribute__((unused
)), memcached_st
*memc_clone
__attribute__((unused
)))
1746 return MEMCACHED_SUCCESS
;
1749 static memcached_return_t
cleanup_test_callback(memcached_st
*ptr
__attribute__((unused
)))
1751 return MEMCACHED_SUCCESS
;
1754 static test_return_t
callback_test(memcached_st
*memc
)
1756 /* Test User Data */
1760 memcached_return_t rc
;
1762 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_USER_DATA
, &x
);
1763 test_truth(rc
== MEMCACHED_SUCCESS
);
1764 test_ptr
= (int *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_USER_DATA
, &rc
);
1765 test_truth(*test_ptr
== x
);
1768 /* Test Clone Callback */
1770 memcached_clone_fn clone_cb
= (memcached_clone_fn
)clone_test_callback
;
1771 void *clone_cb_ptr
= *(void **)&clone_cb
;
1772 void *temp_function
= NULL
;
1773 memcached_return_t rc
;
1775 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
,
1777 test_truth(rc
== MEMCACHED_SUCCESS
);
1778 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1779 test_truth(temp_function
== clone_cb_ptr
);
1782 /* Test Cleanup Callback */
1784 memcached_cleanup_fn cleanup_cb
=
1785 (memcached_cleanup_fn
)cleanup_test_callback
;
1786 void *cleanup_cb_ptr
= *(void **)&cleanup_cb
;
1787 void *temp_function
= NULL
;
1788 memcached_return_t rc
;
1790 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
,
1792 test_truth(rc
== MEMCACHED_SUCCESS
);
1793 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1794 test_truth(temp_function
== cleanup_cb_ptr
);
1797 return TEST_SUCCESS
;
1800 /* We don't test the behavior itself, we test the switches */
1801 static test_return_t
behavior_test(memcached_st
*memc
)
1806 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1807 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1808 test_truth(value
== 1);
1810 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1811 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1812 test_truth(value
== 1);
1814 set
= MEMCACHED_HASH_MD5
;
1815 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1816 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1817 test_truth(value
== MEMCACHED_HASH_MD5
);
1821 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1822 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1823 test_truth(value
== 0);
1825 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1826 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1827 test_truth(value
== 0);
1829 set
= MEMCACHED_HASH_DEFAULT
;
1830 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1831 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1832 test_truth(value
== MEMCACHED_HASH_DEFAULT
);
1834 set
= MEMCACHED_HASH_CRC
;
1835 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1836 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1837 test_truth(value
== MEMCACHED_HASH_CRC
);
1839 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1840 test_truth(value
> 0);
1842 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1843 test_truth(value
> 0);
1845 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
);
1846 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, value
+ 1);
1847 test_truth((value
+ 1) == memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
));
1848 return TEST_SUCCESS
;
1851 static test_return_t
fetch_all_results(memcached_st
*memc
)
1853 memcached_return_t rc
= MEMCACHED_SUCCESS
;
1854 char return_key
[MEMCACHED_MAX_KEY
];
1855 size_t return_key_length
;
1857 size_t return_value_length
;
1860 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1861 &return_value_length
, &flags
, &rc
)))
1863 test_truth(return_value
);
1864 test_truth(rc
== MEMCACHED_SUCCESS
);
1868 return ((rc
== MEMCACHED_END
) || (rc
== MEMCACHED_SUCCESS
)) ? TEST_SUCCESS
: TEST_FAILURE
;
1871 /* Test case provided by Cal Haldenbrand */
1872 static test_return_t
user_supplied_bug1(memcached_st
*memc
)
1874 unsigned int setter
= 1;
1877 unsigned long long total
= 0;
1880 char randomstuff
[6 * 1024];
1881 memcached_return_t rc
;
1883 memset(randomstuff
, 0, 6 * 1024);
1885 /* We just keep looking at the same values over and over */
1888 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1889 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1893 for (x
= 0 ; total
< 20 * 1024576 ; x
++ )
1897 size
= (uint32_t)(rand() % ( 5 * 1024 ) ) + 400;
1898 memset(randomstuff
, 0, 6 * 1024);
1899 test_truth(size
< 6 * 1024); /* Being safe here */
1901 for (j
= 0 ; j
< size
;j
++)
1902 randomstuff
[j
] = (signed char) ((rand() % 26) + 97);
1905 sprintf(key
, "%d", x
);
1906 rc
= memcached_set(memc
, key
, strlen(key
),
1907 randomstuff
, strlen(randomstuff
), 10, 0);
1908 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1909 /* If we fail, lets try again */
1910 if (rc
!= MEMCACHED_SUCCESS
&& rc
!= MEMCACHED_BUFFERED
)
1911 rc
= memcached_set(memc
, key
, strlen(key
),
1912 randomstuff
, strlen(randomstuff
), 10, 0);
1913 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1916 return TEST_SUCCESS
;
1919 /* Test case provided by Cal Haldenbrand */
1920 static test_return_t
user_supplied_bug2(memcached_st
*memc
)
1923 unsigned int setter
;
1925 unsigned long long total
;
1928 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1929 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1931 setter
= 20 * 1024576;
1932 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1933 setter
= 20 * 1024576;
1934 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1935 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1936 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1938 for (x
= 0, errors
= 0, total
= 0 ; total
< 20 * 1024576 ; x
++)
1941 for (x
= 0, errors
= 0, total
= 0 ; total
< 24576 ; x
++)
1943 memcached_return_t rc
= MEMCACHED_SUCCESS
;
1944 char buffer
[SMALL_STRING_LEN
];
1949 memset(buffer
, 0, SMALL_STRING_LEN
);
1951 snprintf(buffer
, SMALL_STRING_LEN
, "%u", x
);
1952 getval
= memcached_get(memc
, buffer
, strlen(buffer
),
1953 &val_len
, &flags
, &rc
);
1954 if (rc
!= MEMCACHED_SUCCESS
)
1956 if (rc
== MEMCACHED_NOTFOUND
)
1970 return TEST_SUCCESS
;
1973 /* Do a large mget() over all the keys we think exist */
1974 #define KEY_COUNT 3000 // * 1024576
1975 static test_return_t
user_supplied_bug3(memcached_st
*memc
)
1977 memcached_return_t rc
;
1978 unsigned int setter
;
1981 size_t key_lengths
[KEY_COUNT
];
1984 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1985 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1987 setter
= 20 * 1024576;
1988 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1989 setter
= 20 * 1024576;
1990 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1991 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1992 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1995 keys
= calloc(KEY_COUNT
, sizeof(char *));
1997 for (x
= 0; x
< KEY_COUNT
; x
++)
2001 snprintf(buffer
, 30, "%u", x
);
2002 keys
[x
]= strdup(buffer
);
2003 key_lengths
[x
]= strlen(keys
[x
]);
2006 rc
= memcached_mget(memc
, (const char **)keys
, key_lengths
, KEY_COUNT
);
2007 test_truth(rc
== MEMCACHED_SUCCESS
);
2009 test_truth(fetch_all_results(memc
) == TEST_SUCCESS
);
2011 for (x
= 0; x
< KEY_COUNT
; x
++)
2015 return TEST_SUCCESS
;
2018 /* Make sure we behave properly if server list has no values */
2019 static test_return_t
user_supplied_bug4(memcached_st
*memc
)
2021 memcached_return_t rc
;
2022 const char *keys
[]= {"fudge", "son", "food"};
2023 size_t key_length
[]= {5, 3, 4};
2026 char return_key
[MEMCACHED_MAX_KEY
];
2027 size_t return_key_length
;
2029 size_t return_value_length
;
2031 /* Here we free everything before running a bunch of mget tests */
2033 memcached_server_list_free(memc
->hosts
);
2035 memc
->number_of_hosts
= 0;
2039 /* We need to empty the server before continueing test */
2040 rc
= memcached_flush(memc
, 0);
2041 test_truth(rc
== MEMCACHED_NO_SERVERS
);
2043 rc
= memcached_mget(memc
, keys
, key_length
, 3);
2044 test_truth(rc
== MEMCACHED_NO_SERVERS
);
2046 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2047 &return_value_length
, &flags
, &rc
)) != NULL
)
2049 test_truth(return_value
);
2051 test_truth(!return_value
);
2052 test_truth(return_value_length
== 0);
2053 test_truth(rc
== MEMCACHED_NO_SERVERS
);
2055 for (x
= 0; x
< 3; x
++)
2057 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2058 keys
[x
], key_length
[x
],
2059 (time_t)50, (uint32_t)9);
2060 test_truth(rc
== MEMCACHED_NO_SERVERS
);
2063 rc
= memcached_mget(memc
, keys
, key_length
, 3);
2064 test_truth(rc
== MEMCACHED_NO_SERVERS
);
2067 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2068 &return_value_length
, &flags
, &rc
)))
2070 test_truth(return_value
);
2071 test_truth(rc
== MEMCACHED_SUCCESS
);
2072 test_truth(return_key_length
== return_value_length
);
2073 test_truth(!memcmp(return_value
, return_key
, return_value_length
));
2078 return TEST_SUCCESS
;
2081 #define VALUE_SIZE_BUG5 1048064
2082 static test_return_t
user_supplied_bug5(memcached_st
*memc
)
2084 memcached_return_t rc
;
2085 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
2086 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
2087 char return_key
[MEMCACHED_MAX_KEY
];
2088 size_t return_key_length
;
2090 size_t value_length
;
2094 char insert_data
[VALUE_SIZE_BUG5
];
2096 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2097 insert_data
[x
]= (signed char)rand();
2099 memcached_flush(memc
, 0);
2100 value
= memcached_get(memc
, keys
[0], key_length
[0],
2101 &value_length
, &flags
, &rc
);
2102 test_truth(value
== NULL
);
2103 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2106 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2107 &value_length
, &flags
, &rc
)))
2109 test_truth(count
== 0);
2111 for (x
= 0; x
< 4; x
++)
2113 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2114 insert_data
, VALUE_SIZE_BUG5
,
2115 (time_t)0, (uint32_t)0);
2116 test_truth(rc
== MEMCACHED_SUCCESS
);
2119 for (x
= 0; x
< 10; x
++)
2121 value
= memcached_get(memc
, keys
[0], key_length
[0],
2122 &value_length
, &flags
, &rc
);
2126 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2128 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2129 &value_length
, &flags
, &rc
)))
2134 test_truth(count
== 4);
2137 return TEST_SUCCESS
;
2140 static test_return_t
user_supplied_bug6(memcached_st
*memc
)
2142 memcached_return_t rc
;
2143 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
2144 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
2145 char return_key
[MEMCACHED_MAX_KEY
];
2146 size_t return_key_length
;
2148 size_t value_length
;
2152 char insert_data
[VALUE_SIZE_BUG5
];
2154 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2155 insert_data
[x
]= (signed char)rand();
2157 memcached_flush(memc
, 0);
2158 value
= memcached_get(memc
, keys
[0], key_length
[0],
2159 &value_length
, &flags
, &rc
);
2160 test_truth(value
== NULL
);
2161 test_truth(rc
== MEMCACHED_NOTFOUND
);
2162 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2163 test_truth(rc
== MEMCACHED_SUCCESS
);
2166 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2167 &value_length
, &flags
, &rc
)))
2169 test_truth(count
== 0);
2170 test_truth(rc
== MEMCACHED_END
);
2172 for (x
= 0; x
< 4; x
++)
2174 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2175 insert_data
, VALUE_SIZE_BUG5
,
2176 (time_t)0, (uint32_t)0);
2177 test_truth(rc
== MEMCACHED_SUCCESS
);
2180 for (x
= 0; x
< 2; x
++)
2182 value
= memcached_get(memc
, keys
[0], key_length
[0],
2183 &value_length
, &flags
, &rc
);
2187 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2188 test_truth(rc
== MEMCACHED_SUCCESS
);
2190 /* We test for purge of partial complete fetches */
2191 for (count
= 3; count
; count
--)
2193 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2194 &value_length
, &flags
, &rc
);
2195 test_truth(rc
== MEMCACHED_SUCCESS
);
2196 test_truth(!(memcmp(value
, insert_data
, value_length
)));
2197 test_truth(value_length
);
2202 return TEST_SUCCESS
;
2205 static test_return_t
user_supplied_bug8(memcached_st
*memc
__attribute__((unused
)))
2207 memcached_return_t rc
;
2209 memcached_st
*memc_clone
;
2211 memcached_server_st
*servers
;
2212 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";
2214 servers
= memcached_servers_parse(server_list
);
2215 test_truth(servers
);
2217 mine
= memcached_create(NULL
);
2218 rc
= memcached_server_push(mine
, servers
);
2219 test_truth(rc
== MEMCACHED_SUCCESS
);
2220 memcached_server_list_free(servers
);
2223 memc_clone
= memcached_clone(NULL
, mine
);
2225 memcached_quit(mine
);
2226 memcached_quit(memc_clone
);
2229 memcached_free(mine
);
2230 memcached_free(memc_clone
);
2232 return TEST_SUCCESS
;
2235 /* Test flag store/retrieve */
2236 static test_return_t
user_supplied_bug7(memcached_st
*memc
)
2238 memcached_return_t rc
;
2239 const char *keys
= "036790384900";
2240 size_t key_length
= strlen(keys
);
2241 char return_key
[MEMCACHED_MAX_KEY
];
2242 size_t return_key_length
;
2244 size_t value_length
;
2247 char insert_data
[VALUE_SIZE_BUG5
];
2249 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2250 insert_data
[x
]= (signed char)rand();
2252 memcached_flush(memc
, 0);
2255 rc
= memcached_set(memc
, keys
, key_length
,
2256 insert_data
, VALUE_SIZE_BUG5
,
2258 test_truth(rc
== MEMCACHED_SUCCESS
);
2261 value
= memcached_get(memc
, keys
, key_length
,
2262 &value_length
, &flags
, &rc
);
2263 test_truth(flags
== 245);
2267 rc
= memcached_mget(memc
, &keys
, &key_length
, 1);
2270 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2271 &value_length
, &flags
, &rc
);
2272 test_truth(flags
== 245);
2277 return TEST_SUCCESS
;
2280 static test_return_t
user_supplied_bug9(memcached_st
*memc
)
2282 memcached_return_t rc
;
2283 const char *keys
[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
2284 size_t key_length
[3];
2289 char return_key
[MEMCACHED_MAX_KEY
];
2290 size_t return_key_length
;
2292 size_t return_value_length
;
2295 key_length
[0]= strlen("UDATA:edevil@sapo.pt");
2296 key_length
[1]= strlen("fudge&*@#");
2297 key_length
[2]= strlen("for^#@&$not");
2300 for (x
= 0; x
< 3; x
++)
2302 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2303 keys
[x
], key_length
[x
],
2304 (time_t)50, (uint32_t)9);
2305 test_truth(rc
== MEMCACHED_SUCCESS
);
2308 rc
= memcached_mget(memc
, keys
, key_length
, 3);
2309 test_truth(rc
== MEMCACHED_SUCCESS
);
2311 /* We need to empty the server before continueing test */
2312 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2313 &return_value_length
, &flags
, &rc
)) != NULL
)
2315 test_truth(return_value
);
2319 test_truth(count
== 3);
2321 return TEST_SUCCESS
;
2324 /* We are testing with aggressive timeout to get failures */
2325 static test_return_t
user_supplied_bug10(memcached_st
*memc
)
2327 const char *key
= "foo";
2329 size_t value_length
= 512;
2332 memcached_return_t rc
;
2333 unsigned int set
= 1;
2334 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2337 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2338 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2340 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
,
2343 value
= (char*)malloc(value_length
* sizeof(char));
2345 for (x
= 0; x
< value_length
; x
++)
2346 value
[x
]= (char) (x
% 127);
2348 for (x
= 1; x
<= 100000; ++x
)
2350 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2352 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_WRITE_FAILURE
||
2353 rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_TIMEOUT
);
2355 if (rc
== MEMCACHED_WRITE_FAILURE
|| rc
== MEMCACHED_TIMEOUT
)
2360 memcached_free(mclone
);
2362 return TEST_SUCCESS
;
2366 We are looking failures in the async protocol
2368 static test_return_t
user_supplied_bug11(memcached_st
*memc
)
2370 const char *key
= "foo";
2372 size_t value_length
= 512;
2375 memcached_return_t rc
;
2376 unsigned int set
= 1;
2378 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2380 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2381 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2383 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
,
2386 timeout
= (int32_t)memcached_behavior_get(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
2388 test_truth(timeout
== -1);
2390 value
= (char*)malloc(value_length
* sizeof(char));
2392 for (x
= 0; x
< value_length
; x
++)
2393 value
[x
]= (char) (x
% 127);
2395 for (x
= 1; x
<= 100000; ++x
)
2397 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2401 memcached_free(mclone
);
2403 return TEST_SUCCESS
;
2407 Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
2409 static test_return_t
user_supplied_bug12(memcached_st
*memc
)
2411 memcached_return_t rc
;
2413 size_t value_length
;
2415 uint64_t number_value
;
2417 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2418 &value_length
, &flags
, &rc
);
2419 test_truth(value
== NULL
);
2420 test_truth(rc
== MEMCACHED_NOTFOUND
);
2422 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2425 test_truth(value
== NULL
);
2426 /* The binary protocol will set the key if it doesn't exist */
2427 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1)
2429 test_truth(rc
== MEMCACHED_SUCCESS
);
2433 test_truth(rc
== MEMCACHED_NOTFOUND
);
2436 rc
= memcached_set(memc
, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
2438 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2439 &value_length
, &flags
, &rc
);
2441 test_truth(rc
== MEMCACHED_SUCCESS
);
2444 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2446 test_truth(number_value
== 2);
2447 test_truth(rc
== MEMCACHED_SUCCESS
);
2449 return TEST_SUCCESS
;
2453 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2454 set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
2456 static test_return_t
user_supplied_bug13(memcached_st
*memc
)
2458 char key
[] = "key34567890";
2460 memcached_return_t rc
;
2461 size_t overflowSize
;
2463 char commandFirst
[]= "set key34567890 0 0 ";
2464 char commandLast
[] = " \r\n"; /* first line of command sent to server */
2465 size_t commandLength
;
2468 commandLength
= strlen(commandFirst
) + strlen(commandLast
) + 4; /* 4 is number of characters in size, probably 8196 */
2470 overflowSize
= MEMCACHED_MAX_BUFFER
- commandLength
;
2472 for (testSize
= overflowSize
- 1; testSize
< overflowSize
+ 1; testSize
++)
2474 overflow
= malloc(testSize
);
2475 test_truth(overflow
!= NULL
);
2477 memset(overflow
, 'x', testSize
);
2478 rc
= memcached_set(memc
, key
, strlen(key
),
2479 overflow
, testSize
, 0, 0);
2480 test_truth(rc
== MEMCACHED_SUCCESS
);
2484 return TEST_SUCCESS
;
2489 Test values of many different sizes
2490 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2491 set key34567890 0 0 8169 \r\n
2492 is sent followed by buffer of size 8169, followed by 8169
2494 static test_return_t
user_supplied_bug14(memcached_st
*memc
)
2497 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2498 memcached_return_t rc
;
2499 const char *key
= "foo";
2501 size_t value_length
= 18000;
2503 size_t string_length
;
2506 size_t current_length
;
2508 value
= (char*)malloc(value_length
);
2511 for (x
= 0; x
< value_length
; x
++)
2512 value
[x
] = (char) (x
% 127);
2514 for (current_length
= 0; current_length
< value_length
; current_length
++)
2516 rc
= memcached_set(memc
, key
, strlen(key
),
2517 value
, current_length
,
2518 (time_t)0, (uint32_t)0);
2519 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
2521 string
= memcached_get(memc
, key
, strlen(key
),
2522 &string_length
, &flags
, &rc
);
2524 test_truth(rc
== MEMCACHED_SUCCESS
);
2525 test_truth(string_length
== current_length
);
2526 test_truth(!memcmp(string
, value
, string_length
));
2533 return TEST_SUCCESS
;
2537 Look for zero length value problems
2539 static test_return_t
user_supplied_bug15(memcached_st
*memc
)
2542 memcached_return_t rc
;
2543 const char *key
= "mykey";
2548 for (x
= 0; x
< 2; x
++)
2550 rc
= memcached_set(memc
, key
, strlen(key
),
2552 (time_t)0, (uint32_t)0);
2554 test_truth(rc
== MEMCACHED_SUCCESS
);
2556 value
= memcached_get(memc
, key
, strlen(key
),
2557 &length
, &flags
, &rc
);
2559 test_truth(rc
== MEMCACHED_SUCCESS
);
2560 test_truth(value
== NULL
);
2561 test_truth(length
== 0);
2562 test_truth(flags
== 0);
2564 value
= memcached_get(memc
, key
, strlen(key
),
2565 &length
, &flags
, &rc
);
2567 test_truth(rc
== MEMCACHED_SUCCESS
);
2568 test_truth(value
== NULL
);
2569 test_truth(length
== 0);
2570 test_truth(flags
== 0);
2573 return TEST_SUCCESS
;
2576 /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
2577 static test_return_t
user_supplied_bug16(memcached_st
*memc
)
2579 memcached_return_t rc
;
2580 const char *key
= "mykey";
2585 rc
= memcached_set(memc
, key
, strlen(key
),
2587 (time_t)0, UINT32_MAX
);
2589 test_truth(rc
== MEMCACHED_SUCCESS
);
2591 value
= memcached_get(memc
, key
, strlen(key
),
2592 &length
, &flags
, &rc
);
2594 test_truth(rc
== MEMCACHED_SUCCESS
);
2595 test_truth(value
== NULL
);
2596 test_truth(length
== 0);
2597 test_truth(flags
== UINT32_MAX
);
2599 return TEST_SUCCESS
;
2603 /* Check the validity of chinese key*/
2604 static test_return_t
user_supplied_bug17(memcached_st
*memc
)
2606 memcached_return_t rc
;
2607 const char *key
= "豆瓣";
2608 const char *value
="我们在炎热抑郁的夏天无法停止豆瓣";
2613 rc
= memcached_set(memc
, key
, strlen(key
),
2614 value
, strlen(value
),
2617 test_truth(rc
== MEMCACHED_SUCCESS
);
2619 value2
= memcached_get(memc
, key
, strlen(key
),
2620 &length
, &flags
, &rc
);
2622 test_truth(length
==strlen(value
));
2623 test_truth(rc
== MEMCACHED_SUCCESS
);
2624 test_truth(memcmp(value
, value2
, length
)==0);
2627 return TEST_SUCCESS
;
2635 static test_return_t
user_supplied_bug19(memcached_st
*memc
)
2638 memcached_server_st
*s
;
2639 memcached_return_t res
;
2643 m
= memcached_create(NULL
);
2644 memcached_server_add_with_weight(m
, "localhost", 11311, 100);
2645 memcached_server_add_with_weight(m
, "localhost", 11312, 100);
2647 s
= memcached_server_by_key(m
, "a", 1, &res
);
2648 memcached_server_free(s
);
2652 return TEST_SUCCESS
;
2655 /* CAS test from Andei */
2656 static test_return_t
user_supplied_bug20(memcached_st
*memc
)
2658 memcached_return_t status
;
2659 memcached_result_st
*result
, result_obj
;
2660 const char *key
= "abc";
2661 size_t key_len
= strlen("abc");
2662 const char *value
= "foobar";
2663 size_t value_len
= strlen(value
);
2665 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
2667 status
= memcached_set(memc
, key
, key_len
, value
, value_len
, (time_t)0, (uint32_t)0);
2668 test_truth(status
== MEMCACHED_SUCCESS
);
2670 status
= memcached_mget(memc
, &key
, &key_len
, 1);
2671 test_truth(status
== MEMCACHED_SUCCESS
);
2673 result
= memcached_result_create(memc
, &result_obj
);
2676 memcached_result_create(memc
, &result_obj
);
2677 result
= memcached_fetch_result(memc
, &result_obj
, &status
);
2680 test_truth(status
== MEMCACHED_SUCCESS
);
2682 memcached_result_free(result
);
2684 return TEST_SUCCESS
;
2687 #include "ketama_test_cases.h"
2688 static test_return_t
user_supplied_bug18(memcached_st
*trash
)
2690 memcached_return_t rc
;
2693 memcached_server_st
*server_pool
;
2698 memc
= memcached_create(NULL
);
2701 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2702 test_truth(rc
== MEMCACHED_SUCCESS
);
2704 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2705 test_truth(value
== 1);
2707 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2708 test_truth(rc
== MEMCACHED_SUCCESS
);
2710 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2711 test_truth(value
== MEMCACHED_HASH_MD5
);
2713 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");
2714 memcached_server_push(memc
, server_pool
);
2716 /* verify that the server list was parsed okay. */
2717 test_truth(memc
->number_of_hosts
== 8);
2718 test_truth(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
2719 test_truth(server_pool
[0].port
== 11211);
2720 test_truth(server_pool
[0].weight
== 600);
2721 test_truth(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
2722 test_truth(server_pool
[2].port
== 11211);
2723 test_truth(server_pool
[2].weight
== 200);
2724 test_truth(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
2725 test_truth(server_pool
[7].port
== 11211);
2726 test_truth(server_pool
[7].weight
== 100);
2728 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
2729 * us test the boundary wraparound.
2731 test_truth(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
2733 /* verify the standard ketama set. */
2734 for (x
= 0; x
< 99; x
++)
2736 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
2737 char *hostname
= memc
->hosts
[server_idx
].hostname
;
2738 test_strcmp(hostname
, ketama_test_cases
[x
].server
);
2741 memcached_server_list_free(server_pool
);
2742 memcached_free(memc
);
2744 return TEST_SUCCESS
;
2747 /* Large mget() of missing keys with binary proto
2749 * If many binary quiet commands (such as getq's in an mget) fill the output
2750 * buffer and the server chooses not to respond, memcached_flush hangs. See
2751 * http://lists.tangent.org/pipermail/libmemcached/2009-August/000918.html
2754 /* sighandler_t function that always asserts false */
2755 static void fail(int unused
__attribute__((unused
)))
2761 static test_return_t
_user_supplied_bug21(memcached_st
* memc
, size_t key_count
)
2763 memcached_return_t rc
;
2766 size_t* key_lengths
;
2767 void (*oldalarm
)(int);
2768 memcached_st
*memc_clone
;
2770 memc_clone
= memcached_clone(NULL
, memc
);
2771 test_truth(memc_clone
);
2773 /* only binproto uses getq for mget */
2774 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
2776 /* empty the cache to ensure misses (hence non-responses) */
2777 rc
= memcached_flush(memc_clone
, 0);
2778 test_truth(rc
== MEMCACHED_SUCCESS
);
2780 key_lengths
= calloc(key_count
, sizeof(size_t));
2781 keys
= calloc(key_count
, sizeof(char *));
2783 for (x
= 0; x
< key_count
; x
++)
2787 snprintf(buffer
, 30, "%u", x
);
2788 keys
[x
]= strdup(buffer
);
2789 key_lengths
[x
]= strlen(keys
[x
]);
2792 oldalarm
= signal(SIGALRM
, fail
);
2795 rc
= memcached_mget(memc_clone
, (const char **)keys
, key_lengths
, key_count
);
2796 test_truth(rc
== MEMCACHED_SUCCESS
);
2799 signal(SIGALRM
, oldalarm
);
2801 test_truth(fetch_all_results(memc
) == TEST_SUCCESS
);
2803 for (x
= 0; x
< key_count
; x
++)
2808 memcached_free(memc_clone
);
2810 return TEST_SUCCESS
;
2813 static test_return_t
pre_binary(memcached_st
*memc
);
2815 static test_return_t
user_supplied_bug21(memcached_st
*memc
)
2817 test_return_t test_rc
;
2818 test_rc
= pre_binary(memc
);
2820 if (test_rc
!= TEST_SUCCESS
)
2825 /* should work as of r580 */
2826 rc
= _user_supplied_bug21(memc
, 10);
2827 test_truth(rc
== TEST_SUCCESS
);
2829 /* should fail as of r580 */
2830 rc
= _user_supplied_bug21(memc
, 1000);
2831 test_truth(rc
== TEST_SUCCESS
);
2833 return TEST_SUCCESS
;
2836 static test_return_t
auto_eject_hosts(memcached_st
*trash
)
2840 memcached_return_t rc
;
2841 memcached_st
*memc
= memcached_create(NULL
);
2844 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2845 test_truth(rc
== MEMCACHED_SUCCESS
);
2847 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2848 test_truth(value
== 1);
2850 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2851 test_truth(rc
== MEMCACHED_SUCCESS
);
2853 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2854 test_truth(value
== MEMCACHED_HASH_MD5
);
2856 /* server should be removed when in delay */
2857 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
, 1);
2858 test_truth(rc
== MEMCACHED_SUCCESS
);
2860 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
);
2861 test_truth(value
== 1);
2863 memcached_server_st
*server_pool
;
2864 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");
2865 memcached_server_push(memc
, server_pool
);
2867 /* verify that the server list was parsed okay. */
2868 test_truth(memc
->number_of_hosts
== 8);
2869 test_truth(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
2870 test_truth(server_pool
[0].port
== 11211);
2871 test_truth(server_pool
[0].weight
== 600);
2872 test_truth(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
2873 test_truth(server_pool
[2].port
== 11211);
2874 test_truth(server_pool
[2].weight
== 200);
2875 test_truth(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
2876 test_truth(server_pool
[7].port
== 11211);
2877 test_truth(server_pool
[7].weight
== 100);
2879 memc
->hosts
[2].next_retry
= time(NULL
) + 15;
2880 memc
->next_distribution_rebuild
= time(NULL
) - 1;
2882 for (int x
= 0; x
< 99; x
++)
2884 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
2885 test_truth(server_idx
!= 2);
2888 /* and re-added when it's back. */
2889 memc
->hosts
[2].next_retry
= time(NULL
) - 1;
2890 memc
->next_distribution_rebuild
= time(NULL
) - 1;
2891 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
,
2892 memc
->distribution
);
2893 for (int x
= 0; x
< 99; x
++)
2895 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
2896 char *hostname
= memc
->hosts
[server_idx
].hostname
;
2897 test_truth(strcmp(hostname
, ketama_test_cases
[x
].server
) == 0);
2900 memcached_server_list_free(server_pool
);
2901 memcached_free(memc
);
2903 return TEST_SUCCESS
;
2906 static test_return_t
output_ketama_weighted_keys(memcached_st
*trash
)
2910 memcached_return_t rc
;
2911 memcached_st
*memc
= memcached_create(NULL
);
2915 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2916 test_truth(rc
== MEMCACHED_SUCCESS
);
2918 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2919 test_truth(value
== 1);
2921 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2922 test_truth(rc
== MEMCACHED_SUCCESS
);
2924 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2925 test_truth(value
== MEMCACHED_HASH_MD5
);
2928 test_truth(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
) == MEMCACHED_SUCCESS
);
2930 memcached_server_st
*server_pool
;
2931 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");
2932 memcached_server_push(memc
, server_pool
);
2934 // @todo this needs to be refactored to actually test something.
2937 if ((fp
= fopen("ketama_keys.txt", "w")))
2941 printf("cannot write to file ketama_keys.txt");
2942 return TEST_FAILURE
;
2945 for (int x
= 0; x
< 10000; x
++)
2948 sprintf(key
, "%d", x
);
2950 uint32_t server_idx
= memcached_generate_hash(memc
, key
, strlen(key
));
2951 char *hostname
= memc
->hosts
[server_idx
].hostname
;
2952 in_port_t port
= memc
->hosts
[server_idx
].port
;
2953 fprintf(fp
, "key %s is on host /%s:%u\n", key
, hostname
, port
);
2957 memcached_server_list_free(server_pool
);
2958 memcached_free(memc
);
2960 return TEST_SUCCESS
;
2964 static test_return_t
result_static(memcached_st
*memc
)
2966 memcached_result_st result
;
2967 memcached_result_st
*result_ptr
;
2969 result_ptr
= memcached_result_create(memc
, &result
);
2970 test_truth(result
.options
.is_allocated
== false);
2971 test_truth(memcached_is_initialized(&result
) == true);
2972 test_truth(result_ptr
);
2973 test_truth(result_ptr
== &result
);
2975 memcached_result_free(&result
);
2977 test_truth(result
.options
.is_allocated
== false);
2978 test_truth(memcached_is_initialized(&result
) == false);
2980 return TEST_SUCCESS
;
2983 static test_return_t
result_alloc(memcached_st
*memc
)
2985 memcached_result_st
*result_ptr
;
2987 result_ptr
= memcached_result_create(memc
, NULL
);
2988 test_truth(result_ptr
);
2989 test_truth(result_ptr
->options
.is_allocated
== true);
2990 test_truth(memcached_is_initialized(result_ptr
) == true);
2991 memcached_result_free(result_ptr
);
2993 return TEST_SUCCESS
;
2996 static test_return_t
string_static_null(memcached_st
*memc
)
2998 memcached_string_st string
;
2999 memcached_string_st
*string_ptr
;
3001 string_ptr
= memcached_string_create(memc
, &string
, 0);
3002 test_truth(string
.options
.is_initialized
== true);
3003 test_truth(string_ptr
);
3005 /* The following two better be the same! */
3006 test_truth(memcached_is_allocated(string_ptr
) == false);
3007 test_truth(memcached_is_allocated(&string
) == false);
3008 test_truth(&string
== string_ptr
);
3010 test_truth(string
.options
.is_initialized
== true);
3011 test_truth(memcached_is_initialized(&string
) == true);
3012 memcached_string_free(&string
);
3013 test_truth(memcached_is_initialized(&string
) == false);
3015 return TEST_SUCCESS
;
3018 static test_return_t
string_alloc_null(memcached_st
*memc
)
3020 memcached_string_st
*string
;
3022 string
= memcached_string_create(memc
, NULL
, 0);
3024 test_truth(memcached_is_allocated(string
) == true);
3025 test_truth(memcached_is_initialized(string
) == true);
3026 memcached_string_free(string
);
3028 return TEST_SUCCESS
;
3031 static test_return_t
string_alloc_with_size(memcached_st
*memc
)
3033 memcached_string_st
*string
;
3035 string
= memcached_string_create(memc
, NULL
, 1024);
3037 test_truth(memcached_is_allocated(string
) == true);
3038 test_truth(memcached_is_initialized(string
) == true);
3039 memcached_string_free(string
);
3041 return TEST_SUCCESS
;
3044 static test_return_t
string_alloc_with_size_toobig(memcached_st
*memc
)
3046 memcached_string_st
*string
;
3048 string
= memcached_string_create(memc
, NULL
, SIZE_MAX
);
3049 test_truth(string
== NULL
);
3051 return TEST_SUCCESS
;
3054 static test_return_t
string_alloc_append(memcached_st
*memc
)
3057 char buffer
[SMALL_STRING_LEN
];
3058 memcached_string_st
*string
;
3060 /* Ring the bell! */
3061 memset(buffer
, 6, SMALL_STRING_LEN
);
3063 string
= memcached_string_create(memc
, NULL
, 100);
3065 test_truth(memcached_is_allocated(string
) == true);
3066 test_truth(memcached_is_initialized(string
) == true);
3068 for (x
= 0; x
< 1024; x
++)
3070 memcached_return_t rc
;
3071 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
3072 test_truth(rc
== MEMCACHED_SUCCESS
);
3074 test_truth(memcached_is_allocated(string
) == true);
3075 memcached_string_free(string
);
3077 return TEST_SUCCESS
;
3080 static test_return_t
string_alloc_append_toobig(memcached_st
*memc
)
3082 memcached_return_t rc
;
3084 char buffer
[SMALL_STRING_LEN
];
3085 memcached_string_st
*string
;
3087 /* Ring the bell! */
3088 memset(buffer
, 6, SMALL_STRING_LEN
);
3090 string
= memcached_string_create(memc
, NULL
, 100);
3092 test_truth(memcached_is_allocated(string
) == true);
3093 test_truth(memcached_is_initialized(string
) == true);
3095 for (x
= 0; x
< 1024; x
++)
3097 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
3098 test_truth(rc
== MEMCACHED_SUCCESS
);
3100 rc
= memcached_string_append(string
, buffer
, SIZE_MAX
);
3101 test_truth(rc
== MEMCACHED_MEMORY_ALLOCATION_FAILURE
);
3102 test_truth(memcached_is_allocated(string
) == true);
3103 memcached_string_free(string
);
3105 return TEST_SUCCESS
;
3108 static test_return_t
cleanup_pairs(memcached_st
*memc
__attribute__((unused
)))
3110 pairs_free(global_pairs
);
3112 return TEST_SUCCESS
;
3115 static test_return_t
generate_pairs(memcached_st
*memc
__attribute__((unused
)))
3117 unsigned long long x
;
3118 global_pairs
= pairs_generate(GLOBAL_COUNT
, 400);
3119 global_count
= GLOBAL_COUNT
;
3121 for (x
= 0; x
< global_count
; x
++)
3123 global_keys
[x
]= global_pairs
[x
].key
;
3124 global_keys_length
[x
]= global_pairs
[x
].key_length
;
3127 return TEST_SUCCESS
;
3130 static test_return_t
generate_large_pairs(memcached_st
*memc
__attribute__((unused
)))
3132 unsigned long long x
;
3133 global_pairs
= pairs_generate(GLOBAL2_COUNT
, MEMCACHED_MAX_BUFFER
+10);
3134 global_count
= GLOBAL2_COUNT
;
3136 for (x
= 0; x
< global_count
; x
++)
3138 global_keys
[x
]= global_pairs
[x
].key
;
3139 global_keys_length
[x
]= global_pairs
[x
].key_length
;
3142 return TEST_SUCCESS
;
3145 static test_return_t
generate_data(memcached_st
*memc
)
3147 execute_set(memc
, global_pairs
, global_count
);
3149 return TEST_SUCCESS
;
3152 static test_return_t
generate_data_with_stats(memcached_st
*memc
)
3154 memcached_stat_st
*stat_p
;
3155 memcached_return_t rc
;
3156 uint32_t host_index
= 0;
3157 execute_set(memc
, global_pairs
, global_count
);
3159 //TODO: hosts used size stats
3160 stat_p
= memcached_stat(memc
, NULL
, &rc
);
3163 for (host_index
= 0; host_index
< SERVERS_TO_CREATE
; host_index
++)
3165 /* This test was changes so that "make test" would work properlly */
3167 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
);
3169 test_truth((unsigned long long)(stat_p
+ host_index
)->bytes
);
3172 memcached_stat_free(NULL
, stat_p
);
3174 return TEST_SUCCESS
;
3176 static test_return_t
generate_buffer_data(memcached_st
*memc
)
3181 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
3182 generate_data(memc
);
3184 return TEST_SUCCESS
;
3187 static test_return_t
get_read_count(memcached_st
*memc
)
3190 memcached_return_t rc
;
3191 memcached_st
*memc_clone
;
3193 memc_clone
= memcached_clone(NULL
, memc
);
3194 test_truth(memc_clone
);
3196 memcached_server_add_with_weight(memc_clone
, "localhost", 6666, 0);
3200 size_t return_value_length
;
3204 for (x
= count
= 0; x
< global_count
; x
++)
3206 return_value
= memcached_get(memc_clone
, global_keys
[x
], global_keys_length
[x
],
3207 &return_value_length
, &flags
, &rc
);
3208 if (rc
== MEMCACHED_SUCCESS
)
3217 memcached_free(memc_clone
);
3219 return TEST_SUCCESS
;
3222 static test_return_t
get_read(memcached_st
*memc
)
3225 memcached_return_t rc
;
3229 size_t return_value_length
;
3232 for (x
= 0; x
< global_count
; x
++)
3234 return_value
= memcached_get(memc
, global_keys
[x
], global_keys_length
[x
],
3235 &return_value_length
, &flags
, &rc
);
3237 test_truth(return_value);
3238 test_truth(rc == MEMCACHED_SUCCESS);
3240 if (rc
== MEMCACHED_SUCCESS
&& return_value
)
3245 return TEST_SUCCESS
;
3248 static test_return_t
mget_read(memcached_st
*memc
)
3250 memcached_return_t rc
;
3252 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
3253 test_truth(rc
== MEMCACHED_SUCCESS
);
3254 test_truth(fetch_all_results(memc
) == TEST_SUCCESS
);
3256 return TEST_SUCCESS
;
3259 static test_return_t
mget_read_result(memcached_st
*memc
)
3261 memcached_return_t rc
;
3263 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
3264 test_truth(rc
== MEMCACHED_SUCCESS
);
3265 /* Turn this into a help function */
3267 memcached_result_st results_obj
;
3268 memcached_result_st
*results
;
3270 results
= memcached_result_create(memc
, &results_obj
);
3272 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
3274 test_truth(results
);
3275 test_truth(rc
== MEMCACHED_SUCCESS
);
3278 memcached_result_free(&results_obj
);
3281 return TEST_SUCCESS
;
3284 static test_return_t
mget_read_function(memcached_st
*memc
)
3286 memcached_return_t rc
;
3287 unsigned int counter
;
3288 memcached_execute_fn callbacks
[1];
3290 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
3291 test_truth(rc
== MEMCACHED_SUCCESS
);
3293 callbacks
[0]= &callback_counter
;
3295 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
3297 return TEST_SUCCESS
;
3300 static test_return_t
delete_generate(memcached_st
*memc
)
3304 for (x
= 0; x
< global_count
; x
++)
3306 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3309 return TEST_SUCCESS
;
3312 static test_return_t
delete_buffer_generate(memcached_st
*memc
)
3318 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
3320 for (x
= 0; x
< global_count
; x
++)
3322 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3325 return TEST_SUCCESS
;
3328 static test_return_t
add_host_test1(memcached_st
*memc
)
3331 memcached_return_t rc
;
3332 char servername
[]= "0.example.com";
3333 memcached_server_st
*servers
;
3335 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
3336 test_truth(servers
);
3337 test_truth(1 == memcached_server_list_count(servers
));
3339 for (x
= 2; x
< 20; x
++)
3341 char buffer
[SMALL_STRING_LEN
];
3343 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
3344 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
3346 test_truth(rc
== MEMCACHED_SUCCESS
);
3347 test_truth(x
== memcached_server_list_count(servers
));
3350 rc
= memcached_server_push(memc
, servers
);
3351 test_truth(rc
== MEMCACHED_SUCCESS
);
3352 rc
= memcached_server_push(memc
, servers
);
3353 test_truth(rc
== MEMCACHED_SUCCESS
);
3355 memcached_server_list_free(servers
);
3357 return TEST_SUCCESS
;
3360 static test_return_t
pre_nonblock(memcached_st
*memc
)
3362 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3364 return TEST_SUCCESS
;
3367 static test_return_t
pre_nonblock_binary(memcached_st
*memc
)
3369 memcached_return_t rc
= MEMCACHED_FAILURE
;
3370 memcached_st
*memc_clone
;
3372 memc_clone
= memcached_clone(NULL
, memc
);
3374 // The memcached_version needs to be done on a clone, because the server
3375 // will not toggle protocol on an connection.
3376 memcached_version(memc_clone
);
3378 if (memc_clone
->hosts
[0].major_version
>= 1 && memc_clone
->hosts
[0].minor_version
> 2)
3380 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3381 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3382 test_truth(rc
== MEMCACHED_SUCCESS
);
3383 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3387 return TEST_SKIPPED
;
3390 memcached_free(memc_clone
);
3392 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3395 static test_return_t
pre_murmur(memcached_st
*memc
)
3397 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
3399 return TEST_SUCCESS
;
3402 static test_return_t
pre_jenkins(memcached_st
*memc
)
3404 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_JENKINS
);
3406 return TEST_SUCCESS
;
3410 static test_return_t
pre_md5(memcached_st
*memc
)
3412 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MD5
);
3414 return TEST_SUCCESS
;
3417 static test_return_t
pre_crc(memcached_st
*memc
)
3419 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_CRC
);
3421 return TEST_SUCCESS
;
3424 static test_return_t
pre_hsieh(memcached_st
*memc
)
3426 #ifdef HAVE_HSIEH_HASH
3427 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_HSIEH
);
3428 return TEST_SUCCESS
;
3431 return TEST_SKIPPED
;
3435 static test_return_t
pre_hash_fnv1_64(memcached_st
*memc
)
3437 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
3439 return TEST_SUCCESS
;
3442 static test_return_t
pre_hash_fnv1a_64(memcached_st
*memc
)
3444 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_64
);
3446 return TEST_SUCCESS
;
3449 static test_return_t
pre_hash_fnv1_32(memcached_st
*memc
)
3451 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_32
);
3453 return TEST_SUCCESS
;
3456 static test_return_t
pre_hash_fnv1a_32(memcached_st
*memc
)
3458 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_32
);
3460 return TEST_SUCCESS
;
3463 static test_return_t
pre_behavior_ketama(memcached_st
*memc
)
3465 memcached_return_t rc
;
3468 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA
, 1);
3469 test_truth(rc
== MEMCACHED_SUCCESS
);
3471 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA
);
3472 test_truth(value
== 1);
3474 return TEST_SUCCESS
;
3477 static test_return_t
pre_behavior_ketama_weighted(memcached_st
*memc
)
3479 memcached_return_t rc
;
3482 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
3483 test_truth(rc
== MEMCACHED_SUCCESS
);
3485 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
3486 test_truth(value
== 1);
3488 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
3489 test_truth(rc
== MEMCACHED_SUCCESS
);
3491 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
3492 test_truth(value
== MEMCACHED_HASH_MD5
);
3494 return TEST_SUCCESS
;
3498 @note This should be testing to see if the server really supports the binary protocol.
3500 static test_return_t
pre_binary(memcached_st
*memc
)
3502 memcached_return_t rc
= MEMCACHED_FAILURE
;
3503 memcached_st
*memc_clone
;
3505 memc_clone
= memcached_clone(NULL
, memc
);
3506 test_truth(memc_clone
);
3507 // The memcached_version needs to be done on a clone, because the server
3508 // will not toggle protocol on an connection.
3509 memcached_version(memc_clone
);
3511 if (memc_clone
->hosts
[0].major_version
>= 1 && memc_clone
->hosts
[0].minor_version
> 2)
3513 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3514 test_truth(rc
== MEMCACHED_SUCCESS
);
3515 test_truth(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3518 memcached_free(memc_clone
);
3520 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3523 static test_return_t
pre_replication(memcached_st
*memc
)
3525 test_return_t test_rc
;
3526 test_rc
= pre_binary(memc
);
3528 if (test_rc
!= TEST_SUCCESS
)
3532 * Make sure that we store the item on all servers
3533 * (master + replicas == number of servers)
3535 memcached_return_t rc
;
3536 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
,
3537 memc
->number_of_hosts
- 1);
3538 test_truth(rc
== MEMCACHED_SUCCESS
);
3539 test_truth(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
) == memc
->number_of_hosts
- 1);
3541 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3544 static test_return_t
pre_replication_noblock(memcached_st
*memc
)
3546 test_return_t rc
= MEMCACHED_FAILURE
;
3547 if (pre_replication(memc
) == TEST_SUCCESS
&&
3548 pre_nonblock(memc
) == TEST_SUCCESS
)
3554 static void my_free(memcached_st
*ptr
__attribute__((unused
)), void *mem
)
3556 #ifdef HARD_MALLOC_TESTS
3557 void *real_ptr
= (mem
== NULL
) ? mem
: (void*)((caddr_t
)mem
- 8);
3564 static void *my_malloc(memcached_st
*ptr
__attribute__((unused
)), const size_t size
)
3566 #ifdef HARD_MALLOC_TESTS
3567 void *ret
= malloc(size
+ 8);
3570 ret
= (void*)((caddr_t
)ret
+ 8);
3573 void *ret
= malloc(size
);
3578 memset(ret
, 0xff, size
);
3584 static void *my_realloc(memcached_st
*ptr
__attribute__((unused
)), void *mem
, const size_t size
)
3586 #ifdef HARD_MALLOC_TESTS
3587 void *real_ptr
= (mem
== NULL
) ? NULL
: (void*)((caddr_t
)mem
- 8);
3588 void *nmem
= realloc(real_ptr
, size
+ 8);
3593 ret
= (void*)((caddr_t
)nmem
+ 8);
3598 return realloc(mem
, size
);
3602 static void *my_calloc(memcached_st
*ptr
__attribute__((unused
)), size_t nelem
, const size_t size
)
3604 #ifdef HARD_MALLOC_TESTS
3605 void *mem
= my_malloc(ptr
, nelem
* size
);
3608 memset(mem
, 0, nelem
* size
);
3613 return calloc(nelem
, size
);
3617 static test_return_t
set_prefix(memcached_st
*memc
)
3619 memcached_return_t rc
;
3620 const char *key
= "mine";
3623 /* Make sure be default none exists */
3624 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3625 test_truth(rc
== MEMCACHED_FAILURE
);
3627 /* Test a clean set */
3628 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3629 test_truth(rc
== MEMCACHED_SUCCESS
);
3631 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3632 test_truth(memcmp(value
, key
, 4) == 0);
3633 test_truth(rc
== MEMCACHED_SUCCESS
);
3635 /* Test that we can turn it off */
3636 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3637 test_truth(rc
== MEMCACHED_SUCCESS
);
3639 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3640 test_truth(rc
== MEMCACHED_FAILURE
);
3642 /* Now setup for main test */
3643 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3644 test_truth(rc
== MEMCACHED_SUCCESS
);
3646 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3647 test_truth(rc
== MEMCACHED_SUCCESS
);
3648 test_truth(memcmp(value
, key
, 4) == 0);
3650 /* Set to Zero, and then Set to something too large */
3653 memset(long_key
, 0, 255);
3655 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3656 test_truth(rc
== MEMCACHED_SUCCESS
);
3658 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3659 test_truth(rc
== MEMCACHED_FAILURE
);
3660 test_truth(value
== NULL
);
3662 /* Test a long key for failure */
3663 /* TODO, extend test to determine based on setting, what result should be */
3664 strcpy(long_key
, "Thisismorethentheallottednumberofcharacters");
3665 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3666 //test_truth(rc == MEMCACHED_BAD_KEY_PROVIDED);
3667 test_truth(rc
== MEMCACHED_SUCCESS
);
3669 /* Now test a key with spaces (which will fail from long key, since bad key is not set) */
3670 strcpy(long_key
, "This is more then the allotted number of characters");
3671 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3672 test_truth(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3674 /* Test for a bad prefix, but with a short key */
3675 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, 1);
3676 test_truth(rc
== MEMCACHED_SUCCESS
);
3678 strcpy(long_key
, "dog cat");
3679 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3680 test_truth(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3683 return TEST_SUCCESS
;
3686 #ifdef MEMCACHED_ENABLE_DEPRECATED
3687 static test_return_t
deprecated_set_memory_alloc(memcached_st
*memc
)
3689 void *test_ptr
= NULL
;
3692 memcached_malloc_fn malloc_cb
=
3693 (memcached_malloc_fn
)my_malloc
;
3694 cb_ptr
= *(void **)&malloc_cb
;
3695 memcached_return_t rc
;
3697 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, cb_ptr
);
3698 test_truth(rc
== MEMCACHED_SUCCESS
);
3699 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
3700 test_truth(rc
== MEMCACHED_SUCCESS
);
3701 test_truth(test_ptr
== cb_ptr
);
3705 memcached_realloc_fn realloc_cb
=
3706 (memcached_realloc_fn
)my_realloc
;
3707 cb_ptr
= *(void **)&realloc_cb
;
3708 memcached_return_t rc
;
3710 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, cb_ptr
);
3711 test_truth(rc
== MEMCACHED_SUCCESS
);
3712 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
3713 test_truth(rc
== MEMCACHED_SUCCESS
);
3714 test_truth(test_ptr
== cb_ptr
);
3718 memcached_free_fn free_cb
=
3719 (memcached_free_fn
)my_free
;
3720 cb_ptr
= *(void **)&free_cb
;
3721 memcached_return_t rc
;
3723 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, cb_ptr
);
3724 test_truth(rc
== MEMCACHED_SUCCESS
);
3725 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
3726 test_truth(rc
== MEMCACHED_SUCCESS
);
3727 test_truth(test_ptr
== cb_ptr
);
3730 return TEST_SUCCESS
;
3734 static test_return_t
set_memory_alloc(memcached_st
*memc
)
3736 memcached_return_t rc
;
3737 rc
= memcached_set_memory_allocators(memc
, NULL
, my_free
,
3738 my_realloc
, my_calloc
);
3739 test_truth(rc
== MEMCACHED_FAILURE
);
3741 rc
= memcached_set_memory_allocators(memc
, my_malloc
, my_free
,
3742 my_realloc
, my_calloc
);
3744 memcached_malloc_fn mem_malloc
;
3745 memcached_free_fn mem_free
;
3746 memcached_realloc_fn mem_realloc
;
3747 memcached_calloc_fn mem_calloc
;
3748 memcached_get_memory_allocators(memc
, &mem_malloc
, &mem_free
,
3749 &mem_realloc
, &mem_calloc
);
3751 test_truth(mem_malloc
== my_malloc
);
3752 test_truth(mem_realloc
== my_realloc
);
3753 test_truth(mem_calloc
== my_calloc
);
3754 test_truth(mem_free
== my_free
);
3756 return TEST_SUCCESS
;
3759 static test_return_t
enable_consistent_crc(memcached_st
*memc
)
3762 memcached_server_distribution_t value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
3763 memcached_hash_t hash
;
3764 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
3765 if ((rc
= pre_crc(memc
)) != TEST_SUCCESS
)
3768 value
= (memcached_server_distribution_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
3769 test_truth(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
3771 hash
= (memcached_hash_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
3773 if (hash
!= MEMCACHED_HASH_CRC
)
3774 return TEST_SKIPPED
;
3776 return TEST_SUCCESS
;
3779 static test_return_t
enable_consistent_hsieh(memcached_st
*memc
)
3782 memcached_server_distribution_t value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
3783 memcached_hash_t hash
;
3784 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
3785 if ((rc
= pre_hsieh(memc
)) != TEST_SUCCESS
)
3788 value
= (memcached_server_distribution_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
3789 test_truth(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
3791 hash
= (memcached_hash_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
3793 if (hash
!= MEMCACHED_HASH_HSIEH
)
3794 return TEST_SKIPPED
;
3797 return TEST_SUCCESS
;
3800 static test_return_t
enable_cas(memcached_st
*memc
)
3802 unsigned int set
= 1;
3804 memcached_version(memc
);
3806 if ((memc
->hosts
[0].major_version
>= 1 && (memc
->hosts
[0].minor_version
== 2 && memc
->hosts
[0].micro_version
>= 4))
3807 || memc
->hosts
[0].minor_version
> 2)
3809 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
3811 return TEST_SUCCESS
;
3814 return TEST_SKIPPED
;
3817 static test_return_t
check_for_1_2_3(memcached_st
*memc
)
3819 memcached_version(memc
);
3821 if ((memc
->hosts
[0].major_version
>= 1 && (memc
->hosts
[0].minor_version
== 2 && memc
->hosts
[0].micro_version
>= 4))
3822 || memc
->hosts
[0].minor_version
> 2)
3823 return TEST_SUCCESS
;
3825 return TEST_SKIPPED
;
3828 static test_return_t
pre_unix_socket(memcached_st
*memc
)
3830 memcached_return_t rc
;
3833 memcached_server_list_free(memc
->hosts
);
3835 memc
->number_of_hosts
= 0;
3837 if (stat("/tmp/memcached.socket", &buf
))
3838 return TEST_SKIPPED
;
3840 rc
= memcached_server_add_unix_socket_with_weight(memc
, "/tmp/memcached.socket", 0);
3842 return ( rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_FAILURE
);
3845 static test_return_t
pre_nodelay(memcached_st
*memc
)
3847 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3848 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
3850 return TEST_SUCCESS
;
3853 static test_return_t
pre_settimer(memcached_st
*memc
)
3855 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
3856 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
3858 return TEST_SUCCESS
;
3861 static test_return_t
poll_timeout(memcached_st
*memc
)
3867 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
3869 timeout
= (size_t)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
3871 test_truth(timeout
== 100);
3873 return TEST_SUCCESS
;
3876 static test_return_t
noreply_test(memcached_st
*memc
)
3878 memcached_return_t ret
;
3879 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
3880 test_truth(ret
== MEMCACHED_SUCCESS
);
3881 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
3882 test_truth(ret
== MEMCACHED_SUCCESS
);
3883 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
3884 test_truth(ret
== MEMCACHED_SUCCESS
);
3885 test_truth(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NOREPLY
) == 1);
3886 test_truth(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
) == 1);
3887 test_truth(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
) == 1);
3889 for (int count
=0; count
< 5; ++count
)
3891 for (int x
=0; x
< 100; ++x
)
3894 size_t len
= (size_t)sprintf(key
, "%d", x
);
3898 ret
= memcached_add(memc
, key
, len
, key
, len
, 0, 0);
3901 ret
= memcached_replace(memc
, key
, len
, key
, len
, 0, 0);
3904 ret
= memcached_set(memc
, key
, len
, key
, len
, 0, 0);
3907 ret
= memcached_append(memc
, key
, len
, key
, len
, 0, 0);
3910 ret
= memcached_prepend(memc
, key
, len
, key
, len
, 0, 0);
3916 test_truth(ret
== MEMCACHED_SUCCESS
|| ret
== MEMCACHED_BUFFERED
);
3920 ** NOTE: Don't ever do this in your code! this is not a supported use of the
3921 ** API and is _ONLY_ done this way to verify that the library works the
3922 ** way it is supposed to do!!!!
3925 for (uint32_t x
=0; x
< memc
->number_of_hosts
; ++x
)
3926 no_msg
+=(int)(memc
->hosts
[x
].cursor_active
);
3928 test_truth(no_msg
== 0);
3929 test_truth(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
3932 ** Now validate that all items was set properly!
3934 for (int x
=0; x
< 100; ++x
)
3937 size_t len
= (size_t)sprintf(key
, "%d", x
);
3940 char* value
=memcached_get(memc
, key
, strlen(key
),
3941 &length
, &flags
, &ret
);
3942 test_truth(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
3945 case 0: /* FALLTHROUGH */
3946 case 1: /* FALLTHROUGH */
3948 test_truth(strncmp(value
, key
, len
) == 0);
3949 test_truth(len
== length
);
3952 test_truth(length
== len
* 2);
3955 test_truth(length
== len
* 3);
3965 /* Try setting an illegal cas value (should not return an error to
3966 * the caller (because we don't expect a return message from the server)
3968 const char* keys
[]= {"0"};
3969 size_t lengths
[]= {1};
3972 memcached_result_st results_obj
;
3973 memcached_result_st
*results
;
3974 ret
= memcached_mget(memc
, keys
, lengths
, 1);
3975 test_truth(ret
== MEMCACHED_SUCCESS
);
3977 results
= memcached_result_create(memc
, &results_obj
);
3978 test_truth(results
);
3979 results
= memcached_fetch_result(memc
, &results_obj
, &ret
);
3980 test_truth(results
);
3981 test_truth(ret
== MEMCACHED_SUCCESS
);
3982 uint64_t cas
= memcached_result_cas(results
);
3983 memcached_result_free(&results_obj
);
3985 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
3986 test_truth(ret
== MEMCACHED_SUCCESS
);
3989 * The item will have a new cas value, so try to set it again with the old
3990 * value. This should fail!
3992 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
3993 test_truth(ret
== MEMCACHED_SUCCESS
);
3994 test_truth(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
3995 char* value
=memcached_get(memc
, keys
[0], lengths
[0], &length
, &flags
, &ret
);
3996 test_truth(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
3999 return TEST_SUCCESS
;
4002 static test_return_t
analyzer_test(memcached_st
*memc
)
4004 memcached_return_t rc
;
4005 memcached_stat_st
*memc_stat
;
4006 memcached_analysis_st
*report
;
4008 memc_stat
= memcached_stat(memc
, NULL
, &rc
);
4009 test_truth(rc
== MEMCACHED_SUCCESS
);
4010 test_truth(memc_stat
);
4012 report
= memcached_analyze(memc
, memc_stat
, &rc
);
4013 test_truth(rc
== MEMCACHED_SUCCESS
);
4017 memcached_stat_free(NULL
, memc_stat
);
4019 return TEST_SUCCESS
;
4022 /* Count the objects */
4023 static memcached_return_t
callback_dump_counter(memcached_st
*ptr
__attribute__((unused
)),
4024 const char *key
__attribute__((unused
)),
4025 size_t key_length
__attribute__((unused
)),
4028 uint32_t *counter
= (uint32_t *)context
;
4030 *counter
= *counter
+ 1;
4032 return MEMCACHED_SUCCESS
;
4035 static test_return_t
dump_test(memcached_st
*memc
)
4037 memcached_return_t rc
;
4038 uint32_t counter
= 0;
4039 memcached_dump_fn callbacks
[1];
4040 test_return_t main_rc
;
4042 callbacks
[0]= &callback_dump_counter
;
4044 /* No support for Binary protocol yet */
4045 if (memc
->flags
.binary_protocol
)
4046 return TEST_SUCCESS
;
4048 main_rc
= set_test3(memc
);
4050 test_truth (main_rc
== TEST_SUCCESS
);
4052 rc
= memcached_dump(memc
, callbacks
, (void *)&counter
, 1);
4053 test_truth(rc
== MEMCACHED_SUCCESS
);
4055 /* We may have more then 32 if our previous flush has not completed */
4056 test_truth(counter
>= 32);
4058 return TEST_SUCCESS
;
4061 #ifdef HAVE_LIBMEMCACHEDUTIL
4062 static void* connection_release(void *arg
)
4065 memcached_pool_st
* pool
;
4070 assert(memcached_pool_push(resource
->pool
, resource
->mmc
) == MEMCACHED_SUCCESS
);
4074 static test_return_t
connection_pool_test(memcached_st
*memc
)
4076 memcached_pool_st
* pool
= memcached_pool_create(memc
, 5, 10);
4077 test_truth(pool
!= NULL
);
4078 memcached_st
* mmc
[10];
4079 memcached_return_t rc
;
4081 for (int x
= 0; x
< 10; ++x
) {
4082 mmc
[x
]= memcached_pool_pop(pool
, false, &rc
);
4083 test_truth(mmc
[x
] != NULL
);
4084 test_truth(rc
== MEMCACHED_SUCCESS
);
4087 test_truth(memcached_pool_pop(pool
, false, &rc
) == NULL
);
4088 test_truth(rc
== MEMCACHED_SUCCESS
);
4092 memcached_pool_st
* pool
;
4094 } item
= { .pool
= pool
, .mmc
= mmc
[9] };
4095 pthread_create(&tid
, NULL
, connection_release
, &item
);
4096 mmc
[9]= memcached_pool_pop(pool
, true, &rc
);
4097 test_truth(rc
== MEMCACHED_SUCCESS
);
4098 pthread_join(tid
, NULL
);
4099 test_truth(mmc
[9] == item
.mmc
);
4100 const char *key
= "key";
4101 size_t keylen
= strlen(key
);
4103 // verify that I can do ops with all connections
4104 rc
= memcached_set(mmc
[0], key
, keylen
, "0", 1, 0, 0);
4105 test_truth(rc
== MEMCACHED_SUCCESS
);
4107 for (unsigned int x
= 0; x
< 10; ++x
) {
4108 uint64_t number_value
;
4109 rc
= memcached_increment(mmc
[x
], key
, keylen
, 1, &number_value
);
4110 test_truth(rc
== MEMCACHED_SUCCESS
);
4111 test_truth(number_value
== (x
+1));
4115 for (int x
= 0; x
< 10; ++x
)
4116 test_truth(memcached_pool_push(pool
, mmc
[x
]) == MEMCACHED_SUCCESS
);
4119 /* verify that I can set behaviors on the pool when I don't have all
4120 * of the connections in the pool. It should however be enabled
4121 * when I push the item into the pool
4123 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
4124 test_truth(mmc
[0] != NULL
);
4126 rc
= memcached_pool_behavior_set(pool
, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
, 9999);
4127 test_truth(rc
== MEMCACHED_SUCCESS
);
4129 mmc
[1]= memcached_pool_pop(pool
, false, &rc
);
4130 test_truth(mmc
[1] != NULL
);
4132 test_truth(memcached_behavior_get(mmc
[1], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
) == 9999);
4133 test_truth(memcached_pool_push(pool
, mmc
[1]) == MEMCACHED_SUCCESS
);
4134 test_truth(memcached_pool_push(pool
, mmc
[0]) == MEMCACHED_SUCCESS
);
4136 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
4137 test_truth(memcached_behavior_get(mmc
[0], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
) == 9999);
4138 test_truth(memcached_pool_push(pool
, mmc
[0]) == MEMCACHED_SUCCESS
);
4141 test_truth(memcached_pool_destroy(pool
) == memc
);
4142 return TEST_SUCCESS
;
4146 static test_return_t
replication_set_test(memcached_st
*memc
)
4148 memcached_return_t rc
;
4149 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4150 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 0);
4152 rc
= memcached_set(memc
, "bubba", 5, "0", 1, 0, 0);
4153 test_truth(rc
== MEMCACHED_SUCCESS
);
4156 ** We are using the quiet commands to store the replicas, so we need
4157 ** to ensure that all of them are processed before we can continue.
4158 ** In the test we go directly from storing the object to trying to
4159 ** receive the object from all of the different servers, so we
4160 ** could end up in a race condition (the memcached server hasn't yet
4161 ** processed the quiet command from the replication set when it process
4162 ** the request from the other client (created by the clone)). As a
4163 ** workaround for that we call memcached_quit to send the quit command
4164 ** to the server and wait for the response ;-) If you use the test code
4165 ** as an example for your own code, please note that you shouldn't need
4168 memcached_quit(memc
);
4171 ** "bubba" should now be stored on all of our servers. We don't have an
4172 ** easy to use API to address each individual server, so I'll just iterate
4173 ** through a bunch of "master keys" and I should most likely hit all of the
4176 for (int x
= 'a'; x
<= 'z'; ++x
)
4178 char key
[2]= { [0]= (char)x
};
4181 char *val
= memcached_get_by_key(memc_clone
, key
, 1, "bubba", 5,
4183 test_truth(rc
== MEMCACHED_SUCCESS
);
4184 test_truth(val
!= NULL
);
4188 memcached_free(memc_clone
);
4190 return TEST_SUCCESS
;
4193 static test_return_t
replication_get_test(memcached_st
*memc
)
4195 memcached_return_t rc
;
4198 * Don't do the following in your code. I am abusing the internal details
4199 * within the library, and this is not a supported interface.
4200 * This is to verify correct behavior in the library
4202 for (uint32_t host
= 0; host
< memc
->number_of_hosts
; ++host
)
4204 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4205 memc_clone
->hosts
[host
].port
= 0;
4207 for (int x
= 'a'; x
<= 'z'; ++x
)
4209 char key
[2]= { [0]= (char)x
};
4212 char *val
= memcached_get_by_key(memc_clone
, key
, 1, "bubba", 5,
4214 test_truth(rc
== MEMCACHED_SUCCESS
);
4215 test_truth(val
!= NULL
);
4219 memcached_free(memc_clone
);
4222 return TEST_SUCCESS
;
4225 static test_return_t
replication_mget_test(memcached_st
*memc
)
4227 memcached_return_t rc
;
4228 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4229 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 0);
4231 const char *keys
[]= { "bubba", "key1", "key2", "key3" };
4232 size_t len
[]= { 5, 4, 4, 4 };
4234 for (int x
=0; x
< 4; ++x
)
4236 rc
= memcached_set(memc
, keys
[x
], len
[x
], "0", 1, 0, 0);
4237 test_truth(rc
== MEMCACHED_SUCCESS
);
4241 ** We are using the quiet commands to store the replicas, so we need
4242 ** to ensure that all of them are processed before we can continue.
4243 ** In the test we go directly from storing the object to trying to
4244 ** receive the object from all of the different servers, so we
4245 ** could end up in a race condition (the memcached server hasn't yet
4246 ** processed the quiet command from the replication set when it process
4247 ** the request from the other client (created by the clone)). As a
4248 ** workaround for that we call memcached_quit to send the quit command
4249 ** to the server and wait for the response ;-) If you use the test code
4250 ** as an example for your own code, please note that you shouldn't need
4253 memcached_quit(memc
);
4256 * Don't do the following in your code. I am abusing the internal details
4257 * within the library, and this is not a supported interface.
4258 * This is to verify correct behavior in the library
4260 memcached_result_st result_obj
;
4261 for (uint32_t host
= 0; host
< memc_clone
->number_of_hosts
; host
++)
4263 memcached_st
*new_clone
= memcached_clone(NULL
, memc
);
4264 new_clone
->hosts
[host
].port
= 0;
4266 for (int x
= 'a'; x
<= 'z'; ++x
)
4268 const char key
[2]= { [0]= (const char)x
};
4270 rc
= memcached_mget_by_key(new_clone
, key
, 1, keys
, len
, 4);
4271 test_truth(rc
== MEMCACHED_SUCCESS
);
4273 memcached_result_st
*results
= memcached_result_create(new_clone
, &result_obj
);
4274 test_truth(results
);
4277 while ((results
= memcached_fetch_result(new_clone
, &result_obj
, &rc
)) != NULL
)
4281 test_truth(hits
== 4);
4282 memcached_result_free(&result_obj
);
4285 memcached_free(new_clone
);
4288 memcached_free(memc_clone
);
4290 return TEST_SUCCESS
;
4293 static test_return_t
replication_randomize_mget_test(memcached_st
*memc
)
4295 memcached_result_st result_obj
;
4296 memcached_return_t rc
;
4297 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4298 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 3);
4299 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ
, 1);
4301 const char *keys
[]= { "key1", "key2", "key3", "key4", "key5", "key6", "key7" };
4302 size_t len
[]= { 4, 4, 4, 4, 4, 4, 4 };
4304 for (int x
=0; x
< 7; ++x
)
4306 rc
= memcached_set(memc
, keys
[x
], len
[x
], "1", 1, 0, 0);
4307 test_truth(rc
== MEMCACHED_SUCCESS
);
4310 memcached_quit(memc
);
4312 for (int x
=0; x
< 7; ++x
) {
4313 const char key
[2]= { [0]= (const char)x
};
4315 rc
= memcached_mget_by_key(memc_clone
, key
, 1, keys
, len
, 7);
4316 test_truth(rc
== MEMCACHED_SUCCESS
);
4318 memcached_result_st
*results
= memcached_result_create(memc_clone
, &result_obj
);
4319 test_truth(results
);
4322 while ((results
= memcached_fetch_result(memc_clone
, &result_obj
, &rc
)) != NULL
)
4326 test_truth(hits
== 7);
4327 memcached_result_free(&result_obj
);
4329 memcached_free(memc_clone
);
4330 return TEST_SUCCESS
;
4333 static test_return_t
replication_delete_test(memcached_st
*memc
)
4335 memcached_return_t rc
;
4336 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4337 /* Delete the items from all of the servers except 1 */
4338 uint64_t repl
= memcached_behavior_get(memc
,
4339 MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
);
4340 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, --repl
);
4342 const char *keys
[]= { "bubba", "key1", "key2", "key3" };
4343 size_t len
[]= { 5, 4, 4, 4 };
4345 for (int x
=0; x
< 4; ++x
)
4347 rc
= memcached_delete_by_key(memc
, keys
[0], len
[0], keys
[x
], len
[x
], 0);
4348 test_truth(rc
== MEMCACHED_SUCCESS
);
4352 * Don't do the following in your code. I am abusing the internal details
4353 * within the library, and this is not a supported interface.
4354 * This is to verify correct behavior in the library
4356 uint32_t hash
= memcached_generate_hash(memc
, keys
[0], len
[0]);
4357 for (uint32_t x
= 0; x
< (repl
+ 1); ++x
)
4359 memc_clone
->hosts
[hash
].port
= 0;
4360 if (++hash
== memc_clone
->number_of_hosts
)
4364 memcached_result_st result_obj
;
4365 for (uint32_t host
= 0; host
< memc_clone
->number_of_hosts
; ++host
)
4367 for (int x
= 'a'; x
<= 'z'; ++x
)
4369 const char key
[2]= { [0]= (const char)x
};
4371 rc
= memcached_mget_by_key(memc_clone
, key
, 1, keys
, len
, 4);
4372 test_truth(rc
== MEMCACHED_SUCCESS
);
4374 memcached_result_st
*results
= memcached_result_create(memc_clone
, &result_obj
);
4375 test_truth(results
);
4378 while ((results
= memcached_fetch_result(memc_clone
, &result_obj
, &rc
)) != NULL
)
4382 test_truth(hits
== 4);
4383 memcached_result_free(&result_obj
);
4386 memcached_free(memc_clone
);
4388 return TEST_SUCCESS
;
4391 static void increment_request_id(uint16_t *id
)
4394 if ((*id
& UDP_REQUEST_ID_THREAD_MASK
) != 0)
4398 static uint16_t *get_udp_request_ids(memcached_st
*memc
)
4400 uint16_t *ids
= malloc(sizeof(uint16_t) * memc
->number_of_hosts
);
4401 assert(ids
!= NULL
);
4404 for (x
= 0; x
< memc
->number_of_hosts
; x
++)
4405 ids
[x
]= get_udp_datagram_request_id((struct udp_datagram_header_st
*) memc
->hosts
[x
].write_buffer
);
4410 static test_return_t
post_udp_op_check(memcached_st
*memc
, uint16_t *expected_req_ids
)
4413 memcached_server_st
*cur_server
= memc
->hosts
;
4414 uint16_t *cur_req_ids
= get_udp_request_ids(memc
);
4416 for (x
= 0; x
< memc
->number_of_hosts
; x
++)
4418 test_truth(cur_server
[x
].cursor_active
== 0);
4419 test_truth(cur_req_ids
[x
] == expected_req_ids
[x
]);
4421 free(expected_req_ids
);
4424 return TEST_SUCCESS
;
4428 ** There is a little bit of a hack here, instead of removing
4429 ** the servers, I just set num host to 0 and them add then new udp servers
4431 static test_return_t
init_udp(memcached_st
*memc
)
4433 memcached_version(memc
);
4434 /* For the time being, only support udp test for >= 1.2.6 && < 1.3 */
4435 if (memc
->hosts
[0].major_version
!= 1 || memc
->hosts
[0].minor_version
!= 2
4436 || memc
->hosts
[0].micro_version
< 6)
4437 return TEST_SKIPPED
;
4439 uint32_t num_hosts
= memc
->number_of_hosts
;
4441 memcached_server_st servers
[num_hosts
];
4442 memcpy(servers
, memc
->hosts
, sizeof(memcached_server_st
) * num_hosts
);
4443 for (x
= 0; x
< num_hosts
; x
++)
4444 memcached_server_free(&memc
->hosts
[x
]);
4446 memc
->number_of_hosts
= 0;
4447 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
, 1);
4448 for (x
= 0; x
< num_hosts
; x
++)
4450 test_truth(memcached_server_add_udp(memc
, servers
[x
].hostname
, servers
[x
].port
) == MEMCACHED_SUCCESS
);
4451 test_truth(memc
->hosts
[x
].write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4454 return TEST_SUCCESS
;
4457 static test_return_t
binary_init_udp(memcached_st
*memc
)
4459 test_return_t test_rc
;
4460 test_rc
= pre_binary(memc
);
4462 if (test_rc
!= TEST_SUCCESS
)
4465 return init_udp(memc
);
4468 /* Make sure that I cant add a tcp server to a udp client */
4469 static test_return_t
add_tcp_server_udp_client_test(memcached_st
*memc
)
4471 memcached_server_st server
;
4472 memcached_server_clone(&server
, &memc
->hosts
[0]);
4473 test_truth(memcached_server_remove(&(memc
->hosts
[0])) == MEMCACHED_SUCCESS
);
4474 test_truth(memcached_server_add(memc
, server
.hostname
, server
.port
) == MEMCACHED_INVALID_HOST_PROTOCOL
);
4475 return TEST_SUCCESS
;
4478 /* Make sure that I cant add a udp server to a tcp client */
4479 static test_return_t
add_udp_server_tcp_client_test(memcached_st
*memc
)
4481 memcached_server_st server
;
4482 memcached_server_clone(&server
, &memc
->hosts
[0]);
4483 test_truth(memcached_server_remove(&(memc
->hosts
[0])) == MEMCACHED_SUCCESS
);
4485 memcached_st tcp_client
;
4486 memcached_create(&tcp_client
);
4487 test_truth(memcached_server_add_udp(&tcp_client
, server
.hostname
, server
.port
) == MEMCACHED_INVALID_HOST_PROTOCOL
);
4489 return TEST_SUCCESS
;
4492 static test_return_t
set_udp_behavior_test(memcached_st
*memc
)
4495 memcached_quit(memc
);
4496 memc
->number_of_hosts
= 0;
4497 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, memc
->distribution
);
4498 test_truth(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
, 1) == MEMCACHED_SUCCESS
);
4499 test_truth(memc
->flags
.use_udp
);
4500 test_truth(memc
->flags
.no_reply
);
4502 test_truth(memc
->number_of_hosts
== 0);
4504 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
,0);
4505 test_truth(! (memc
->flags
.use_udp
));
4506 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
,0);
4507 test_truth(! (memc
->flags
.no_reply
));
4509 return TEST_SUCCESS
;
4512 static test_return_t
udp_set_test(memcached_st
*memc
)
4515 unsigned int num_iters
= 1025; //request id rolls over at 1024
4516 for (x
= 0; x
< num_iters
;x
++)
4518 memcached_return_t rc
;
4519 const char *key
= "foo";
4520 const char *value
= "when we sanitize";
4521 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4522 unsigned int server_key
= memcached_generate_hash(memc
,key
,strlen(key
));
4523 size_t init_offset
= memc
->hosts
[server_key
].write_buffer_offset
;
4524 rc
= memcached_set(memc
, key
, strlen(key
),
4525 value
, strlen(value
),
4526 (time_t)0, (uint32_t)0);
4527 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4528 /** NB, the check below assumes that if new write_ptr is less than
4529 * the original write_ptr that we have flushed. For large payloads, this
4530 * maybe an invalid assumption, but for the small payload we have it is OK
4532 if (rc
== MEMCACHED_SUCCESS
||
4533 memc
->hosts
[server_key
].write_buffer_offset
< init_offset
)
4534 increment_request_id(&expected_ids
[server_key
]);
4536 if (rc
== MEMCACHED_SUCCESS
)
4538 test_truth(memc
->hosts
[server_key
].write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4542 test_truth(memc
->hosts
[server_key
].write_buffer_offset
!= UDP_DATAGRAM_HEADER_LENGTH
);
4543 test_truth(memc
->hosts
[server_key
].write_buffer_offset
<= MAX_UDP_DATAGRAM_LENGTH
);
4545 test_truth(post_udp_op_check(memc
,expected_ids
) == TEST_SUCCESS
);
4547 return TEST_SUCCESS
;
4550 static test_return_t
udp_buffered_set_test(memcached_st
*memc
)
4552 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4553 return udp_set_test(memc
);
4556 static test_return_t
udp_set_too_big_test(memcached_st
*memc
)
4558 memcached_return_t rc
;
4559 const char *key
= "bar";
4560 char value
[MAX_UDP_DATAGRAM_LENGTH
];
4561 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4562 rc
= memcached_set(memc
, key
, strlen(key
),
4563 value
, MAX_UDP_DATAGRAM_LENGTH
,
4564 (time_t)0, (uint32_t)0);
4565 test_truth(rc
== MEMCACHED_WRITE_FAILURE
);
4566 return post_udp_op_check(memc
,expected_ids
);
4569 static test_return_t
udp_delete_test(memcached_st
*memc
)
4572 unsigned int num_iters
= 1025; //request id rolls over at 1024
4573 for (x
= 0; x
< num_iters
;x
++)
4575 memcached_return_t rc
;
4576 const char *key
= "foo";
4577 uint16_t *expected_ids
=get_udp_request_ids(memc
);
4578 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4579 size_t init_offset
= memc
->hosts
[server_key
].write_buffer_offset
;
4580 rc
= memcached_delete(memc
, key
, strlen(key
), 0);
4581 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4582 if (rc
== MEMCACHED_SUCCESS
|| memc
->hosts
[server_key
].write_buffer_offset
< init_offset
)
4583 increment_request_id(&expected_ids
[server_key
]);
4584 if (rc
== MEMCACHED_SUCCESS
)
4586 test_truth(memc
->hosts
[server_key
].write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4590 test_truth(memc
->hosts
[server_key
].write_buffer_offset
!= UDP_DATAGRAM_HEADER_LENGTH
);
4591 test_truth(memc
->hosts
[server_key
].write_buffer_offset
<= MAX_UDP_DATAGRAM_LENGTH
);
4593 test_truth(post_udp_op_check(memc
,expected_ids
) == TEST_SUCCESS
);
4595 return TEST_SUCCESS
;
4598 static test_return_t
udp_buffered_delete_test(memcached_st
*memc
)
4600 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4601 return udp_delete_test(memc
);
4604 static test_return_t
udp_verbosity_test(memcached_st
*memc
)
4606 memcached_return_t rc
;
4607 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4609 for (x
= 0; x
< memc
->number_of_hosts
;x
++)
4610 increment_request_id(&expected_ids
[x
]);
4612 rc
= memcached_verbosity(memc
,3);
4613 test_truth(rc
== MEMCACHED_SUCCESS
);
4614 return post_udp_op_check(memc
,expected_ids
);
4617 static test_return_t
udp_quit_test(memcached_st
*memc
)
4619 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4620 memcached_quit(memc
);
4621 return post_udp_op_check(memc
, expected_ids
);
4624 static test_return_t
udp_flush_test(memcached_st
*memc
)
4626 memcached_return_t rc
;
4627 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4629 for (x
= 0; x
< memc
->number_of_hosts
;x
++)
4630 increment_request_id(&expected_ids
[x
]);
4632 rc
= memcached_flush(memc
,0);
4633 test_truth(rc
== MEMCACHED_SUCCESS
);
4634 return post_udp_op_check(memc
,expected_ids
);
4637 static test_return_t
udp_incr_test(memcached_st
*memc
)
4639 memcached_return_t rc
;
4640 const char *key
= "incr";
4641 const char *value
= "1";
4642 rc
= memcached_set(memc
, key
, strlen(key
),
4643 value
, strlen(value
),
4644 (time_t)0, (uint32_t)0);
4646 test_truth(rc
== MEMCACHED_SUCCESS
);
4647 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4648 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4649 increment_request_id(&expected_ids
[server_key
]);
4651 rc
= memcached_increment(memc
, key
, strlen(key
), 1, &newvalue
);
4652 test_truth(rc
== MEMCACHED_SUCCESS
);
4653 return post_udp_op_check(memc
, expected_ids
);
4656 static test_return_t
udp_decr_test(memcached_st
*memc
)
4658 memcached_return_t rc
;
4659 const char *key
= "decr";
4660 const char *value
= "1";
4661 rc
= memcached_set(memc
, key
, strlen(key
),
4662 value
, strlen(value
),
4663 (time_t)0, (uint32_t)0);
4665 test_truth(rc
== MEMCACHED_SUCCESS
);
4666 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4667 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4668 increment_request_id(&expected_ids
[server_key
]);
4670 rc
= memcached_decrement(memc
, key
, strlen(key
), 1, &newvalue
);
4671 test_truth(rc
== MEMCACHED_SUCCESS
);
4672 return post_udp_op_check(memc
, expected_ids
);
4676 static test_return_t
udp_stat_test(memcached_st
*memc
)
4678 memcached_stat_st
* rv
= NULL
;
4679 memcached_return_t rc
;
4681 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4682 rv
= memcached_stat(memc
, args
, &rc
);
4684 test_truth(rc
== MEMCACHED_NOT_SUPPORTED
);
4685 return post_udp_op_check(memc
, expected_ids
);
4688 static test_return_t
udp_version_test(memcached_st
*memc
)
4690 memcached_return_t rc
;
4691 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4692 rc
= memcached_version(memc
);
4693 test_truth(rc
== MEMCACHED_NOT_SUPPORTED
);
4694 return post_udp_op_check(memc
, expected_ids
);
4697 static test_return_t
udp_get_test(memcached_st
*memc
)
4699 memcached_return_t rc
;
4700 const char *key
= "foo";
4702 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4703 char *val
= memcached_get(memc
, key
, strlen(key
), &vlen
, (uint32_t)0, &rc
);
4704 test_truth(rc
== MEMCACHED_NOT_SUPPORTED
);
4705 test_truth(val
== NULL
);
4706 return post_udp_op_check(memc
, expected_ids
);
4709 static test_return_t
udp_mixed_io_test(memcached_st
*memc
)
4712 test_st mixed_io_ops
[] ={
4714 (test_callback_fn
)udp_set_test
},
4715 {"udp_set_too_big_test", 0,
4716 (test_callback_fn
)udp_set_too_big_test
},
4717 {"udp_delete_test", 0,
4718 (test_callback_fn
)udp_delete_test
},
4719 {"udp_verbosity_test", 0,
4720 (test_callback_fn
)udp_verbosity_test
},
4721 {"udp_quit_test", 0,
4722 (test_callback_fn
)udp_quit_test
},
4723 {"udp_flush_test", 0,
4724 (test_callback_fn
)udp_flush_test
},
4725 {"udp_incr_test", 0,
4726 (test_callback_fn
)udp_incr_test
},
4727 {"udp_decr_test", 0,
4728 (test_callback_fn
)udp_decr_test
},
4729 {"udp_version_test", 0,
4730 (test_callback_fn
)udp_version_test
}
4733 for (x
= 0; x
< 500; x
++)
4735 current_op
= mixed_io_ops
[random() % 9];
4736 test_truth(current_op
.test_fn(memc
) == TEST_SUCCESS
);
4738 return TEST_SUCCESS
;
4742 static test_return_t
hash_sanity_test (memcached_st
*memc
)
4746 assert(MEMCACHED_HASH_DEFAULT
== MEMCACHED_HASH_DEFAULT
);
4747 assert(MEMCACHED_HASH_MD5
== MEMCACHED_HASH_MD5
);
4748 assert(MEMCACHED_HASH_CRC
== MEMCACHED_HASH_CRC
);
4749 assert(MEMCACHED_HASH_FNV1_64
== MEMCACHED_HASH_FNV1_64
);
4750 assert(MEMCACHED_HASH_FNV1A_64
== MEMCACHED_HASH_FNV1A_64
);
4751 assert(MEMCACHED_HASH_FNV1_32
== MEMCACHED_HASH_FNV1_32
);
4752 assert(MEMCACHED_HASH_FNV1A_32
== MEMCACHED_HASH_FNV1A_32
);
4753 #ifdef HAVE_HSIEH_HASH
4754 assert(MEMCACHED_HASH_HSIEH
== MEMCACHED_HASH_HSIEH
);
4756 assert(MEMCACHED_HASH_MURMUR
== MEMCACHED_HASH_MURMUR
);
4757 assert(MEMCACHED_HASH_JENKINS
== MEMCACHED_HASH_JENKINS
);
4758 assert(MEMCACHED_HASH_MAX
== MEMCACHED_HASH_MAX
);
4760 return TEST_SUCCESS
;
4764 static test_return_t
hsieh_avaibility_test (memcached_st
*memc
)
4766 memcached_return_t expected_rc
= MEMCACHED_FAILURE
;
4767 #ifdef HAVE_HSIEH_HASH
4768 expected_rc
= MEMCACHED_SUCCESS
;
4770 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
,
4771 (uint64_t)MEMCACHED_HASH_HSIEH
);
4772 test_truth(rc
== expected_rc
);
4773 return TEST_SUCCESS
;
4776 static test_return_t
md5_run (memcached_st
*memc
__attribute__((unused
)))
4781 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4785 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MD5
);
4786 test_truth(md5_values
[x
] == hash_val
);
4789 return TEST_SUCCESS
;
4792 static test_return_t
crc_run (memcached_st
*memc
__attribute__((unused
)))
4797 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4801 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_CRC
);
4802 test_truth(crc_values
[x
] == hash_val
);
4805 return TEST_SUCCESS
;
4808 static test_return_t
fnv1_64_run (memcached_st
*memc
__attribute__((unused
)))
4813 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4817 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_64
);
4818 test_truth(fnv1_64_values
[x
] == hash_val
);
4821 return TEST_SUCCESS
;
4824 static test_return_t
fnv1a_64_run (memcached_st
*memc
__attribute__((unused
)))
4829 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4833 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_64
);
4834 test_truth(fnv1a_64_values
[x
] == hash_val
);
4837 return TEST_SUCCESS
;
4840 static test_return_t
fnv1_32_run (memcached_st
*memc
__attribute__((unused
)))
4846 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4850 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_32
);
4851 test_truth(fnv1_32_values
[x
] == hash_val
);
4854 return TEST_SUCCESS
;
4857 static test_return_t
fnv1a_32_run (memcached_st
*memc
__attribute__((unused
)))
4862 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4866 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_32
);
4867 test_truth(fnv1a_32_values
[x
] == hash_val
);
4870 return TEST_SUCCESS
;
4873 static test_return_t
hsieh_run (memcached_st
*memc
__attribute__((unused
)))
4878 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4882 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_HSIEH
);
4883 test_truth(hsieh_values
[x
] == hash_val
);
4886 return TEST_SUCCESS
;
4889 static test_return_t
murmur_run (memcached_st
*memc
__attribute__((unused
)))
4892 return TEST_SKIPPED
;
4897 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4901 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MURMUR
);
4902 test_truth(murmur_values
[x
] == hash_val
);
4905 return TEST_SUCCESS
;
4909 static test_return_t
jenkins_run (memcached_st
*memc
__attribute__((unused
)))
4915 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4919 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_JENKINS
);
4920 test_truth(jenkins_values
[x
] == hash_val
);
4923 return TEST_SUCCESS
;
4927 static test_return_t
ketama_compatibility_libmemcached(memcached_st
*trash
)
4929 memcached_return_t rc
;
4932 memcached_server_st
*server_pool
;
4937 memc
= memcached_create(NULL
);
4940 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
4941 test_truth(rc
== MEMCACHED_SUCCESS
);
4943 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
4944 test_truth(value
== 1);
4946 test_truth(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
) == MEMCACHED_SUCCESS
);
4947 test_truth(memcached_behavior_get_distribution(memc
) == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
);
4950 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");
4951 memcached_server_push(memc
, server_pool
);
4953 /* verify that the server list was parsed okay. */
4954 assert(memc
->number_of_hosts
== 8);
4955 assert(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
4956 assert(server_pool
[0].port
== 11211);
4957 assert(server_pool
[0].weight
== 600);
4958 assert(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
4959 assert(server_pool
[2].port
== 11211);
4960 assert(server_pool
[2].weight
== 200);
4961 assert(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
4962 assert(server_pool
[7].port
== 11211);
4963 assert(server_pool
[7].weight
== 100);
4965 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
4966 * us test the boundary wraparound.
4968 assert(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
4970 /* verify the standard ketama set. */
4971 for (x
= 0; x
< 99; x
++)
4973 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
4974 char *hostname
= memc
->hosts
[server_idx
].hostname
;
4975 assert(strcmp(hostname
, ketama_test_cases
[x
].server
) == 0);
4978 memcached_server_list_free(server_pool
);
4979 memcached_free(memc
);
4981 return TEST_SUCCESS
;
4984 static test_return_t
ketama_compatibility_spymemcached(memcached_st
*trash
)
4986 memcached_return_t rc
;
4989 memcached_server_st
*server_pool
;
4994 memc
= memcached_create(NULL
);
4997 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
4998 test_truth(rc
== MEMCACHED_SUCCESS
);
5000 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
5001 test_truth(value
== 1);
5003 test_truth(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
) == MEMCACHED_SUCCESS
);
5004 test_truth(memcached_behavior_get_distribution(memc
) == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
);
5006 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");
5007 memcached_server_push(memc
, server_pool
);
5009 /* verify that the server list was parsed okay. */
5010 assert(memc
->number_of_hosts
== 8);
5011 assert(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
5012 assert(server_pool
[0].port
== 11211);
5013 assert(server_pool
[0].weight
== 600);
5014 assert(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
5015 assert(server_pool
[2].port
== 11211);
5016 assert(server_pool
[2].weight
== 200);
5017 assert(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
5018 assert(server_pool
[7].port
== 11211);
5019 assert(server_pool
[7].weight
== 100);
5021 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
5022 * us test the boundary wraparound.
5024 assert(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
5026 /* verify the standard ketama set. */
5027 for (x
= 0; x
< 99; x
++)
5029 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases_spy
[x
].key
, strlen(ketama_test_cases_spy
[x
].key
));
5030 char *hostname
= memc
->hosts
[server_idx
].hostname
;
5031 assert(strcmp(hostname
, ketama_test_cases_spy
[x
].server
) == 0);
5034 memcached_server_list_free(server_pool
);
5035 memcached_free(memc
);
5037 return TEST_SUCCESS
;
5040 static test_return_t
regression_bug_434484(memcached_st
*memc
)
5042 test_return_t test_rc
;
5043 test_rc
= pre_binary(memc
);
5045 if (test_rc
!= TEST_SUCCESS
)
5048 memcached_return_t ret
;
5049 const char *key
= "regression_bug_434484";
5050 size_t keylen
= strlen(key
);
5052 ret
= memcached_append(memc
, key
, keylen
, key
, keylen
, 0, 0);
5053 assert(ret
== MEMCACHED_NOTSTORED
);
5055 size_t size
= 2048 * 1024;
5056 void *data
= calloc(1, size
);
5057 assert(data
!= NULL
);
5058 ret
= memcached_set(memc
, key
, keylen
, data
, size
, 0, 0);
5059 assert(ret
== MEMCACHED_E2BIG
);
5062 return TEST_SUCCESS
;
5065 static test_return_t
regression_bug_434843(memcached_st
*memc
)
5067 test_return_t test_rc
;
5068 test_rc
= pre_binary(memc
);
5070 if (test_rc
!= TEST_SUCCESS
)
5073 memcached_return_t rc
;
5074 unsigned int counter
= 0;
5075 memcached_execute_fn callbacks
[1]= { [0]= &callback_counter
};
5078 * I only want to hit only _one_ server so I know the number of requests I'm
5079 * sending in the pipleine to the server. Let's try to do a multiget of
5080 * 1024 (that should satisfy most users don't you think?). Future versions
5081 * will include a mget_execute function call if you need a higher number.
5083 uint32_t number_of_hosts
= memc
->number_of_hosts
;
5084 memc
->number_of_hosts
= 1;
5085 const size_t max_keys
= 1024;
5086 char **keys
= calloc(max_keys
, sizeof(char*));
5087 size_t *key_length
=calloc(max_keys
, sizeof(size_t));
5089 for (int x
= 0; x
< (int)max_keys
; ++x
)
5092 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%u", x
);
5094 assert(keys
[x
] != NULL
);
5098 * Run two times.. the first time we should have 100% cache miss,
5099 * and the second time we should have 100% cache hits
5101 for (int y
= 0; y
< 2; ++y
)
5103 rc
= memcached_mget(memc
, (const char**)keys
, key_length
, max_keys
);
5104 assert(rc
== MEMCACHED_SUCCESS
);
5105 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5108 /* The first iteration should give me a 100% cache miss. verify that*/
5109 assert(counter
== 0);
5110 char blob
[1024]= { 0 };
5111 for (int x
= 0; x
< (int)max_keys
; ++x
)
5113 rc
= memcached_add(memc
, keys
[x
], key_length
[x
],
5114 blob
, sizeof(blob
), 0, 0);
5115 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5120 /* Verify that we received all of the key/value pairs */
5121 assert(counter
== (unsigned int)max_keys
);
5125 /* Release allocated resources */
5126 for (size_t x
= 0; x
< max_keys
; ++x
)
5131 memc
->number_of_hosts
= number_of_hosts
;
5132 return TEST_SUCCESS
;
5135 static test_return_t
regression_bug_434843_buffered(memcached_st
*memc
)
5137 memcached_return_t rc
;
5138 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
5139 assert(rc
== MEMCACHED_SUCCESS
);
5141 return regression_bug_434843(memc
);
5144 static test_return_t
regression_bug_421108(memcached_st
*memc
)
5146 memcached_return_t rc
;
5147 memcached_stat_st
*memc_stat
= memcached_stat(memc
, NULL
, &rc
);
5148 assert(rc
== MEMCACHED_SUCCESS
);
5150 char *bytes
= memcached_stat_get_value(memc
, memc_stat
, "bytes", &rc
);
5151 assert(rc
== MEMCACHED_SUCCESS
);
5152 assert(bytes
!= NULL
);
5153 char *bytes_read
= memcached_stat_get_value(memc
, memc_stat
,
5155 assert(rc
== MEMCACHED_SUCCESS
);
5156 assert(bytes_read
!= NULL
);
5158 char *bytes_written
= memcached_stat_get_value(memc
, memc_stat
,
5159 "bytes_written", &rc
);
5160 assert(rc
== MEMCACHED_SUCCESS
);
5161 assert(bytes_written
!= NULL
);
5163 assert(strcmp(bytes
, bytes_read
) != 0);
5164 assert(strcmp(bytes
, bytes_written
) != 0);
5166 /* Release allocated resources */
5169 free(bytes_written
);
5170 memcached_stat_free(NULL
, memc_stat
);
5171 return TEST_SUCCESS
;
5175 * The test case isn't obvious so I should probably document why
5176 * it works the way it does. Bug 442914 was caused by a bug
5177 * in the logic in memcached_purge (it did not handle the case
5178 * where the number of bytes sent was equal to the watermark).
5179 * In this test case, create messages so that we hit that case
5180 * and then disable noreply mode and issue a new command to
5181 * verify that it isn't stuck. If we change the format for the
5182 * delete command or the watermarks, we need to update this
5185 static test_return_t
regression_bug_442914(memcached_st
*memc
)
5187 memcached_return_t rc
;
5188 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
5189 assert(rc
== MEMCACHED_SUCCESS
);
5190 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1);
5192 uint32_t number_of_hosts
= memc
->number_of_hosts
;
5193 memc
->number_of_hosts
= 1;
5198 for (int x
= 0; x
< 250; ++x
)
5200 len
= (size_t)snprintf(k
, sizeof(k
), "%0250u", x
);
5201 rc
= memcached_delete(memc
, k
, len
, 0);
5202 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5205 len
= (size_t)snprintf(k
, sizeof(k
), "%037u", 251);
5206 rc
= memcached_delete(memc
, k
, len
, 0);
5207 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5209 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0);
5210 assert(rc
== MEMCACHED_SUCCESS
);
5211 rc
= memcached_delete(memc
, k
, len
, 0);
5212 assert(rc
== MEMCACHED_NOTFOUND
);
5214 memc
->number_of_hosts
= number_of_hosts
;
5216 return TEST_SUCCESS
;
5219 static test_return_t
regression_bug_447342(memcached_st
*memc
)
5221 if (memc
->number_of_hosts
< 3 || pre_replication(memc
) != MEMCACHED_SUCCESS
)
5222 return TEST_SKIPPED
;
5224 memcached_return_t rc
;
5226 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 2);
5227 assert(rc
== MEMCACHED_SUCCESS
);
5229 const size_t max_keys
= 100;
5230 char **keys
= calloc(max_keys
, sizeof(char*));
5231 size_t *key_length
=calloc(max_keys
, sizeof(size_t));
5233 for (int x
= 0; x
< (int)max_keys
; ++x
)
5236 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%u", x
);
5238 assert(keys
[x
] != NULL
);
5239 rc
= memcached_set(memc
, k
, key_length
[x
], k
, key_length
[x
], 0, 0);
5240 assert(rc
== MEMCACHED_SUCCESS
);
5244 ** We are using the quiet commands to store the replicas, so we need
5245 ** to ensure that all of them are processed before we can continue.
5246 ** In the test we go directly from storing the object to trying to
5247 ** receive the object from all of the different servers, so we
5248 ** could end up in a race condition (the memcached server hasn't yet
5249 ** processed the quiet command from the replication set when it process
5250 ** the request from the other client (created by the clone)). As a
5251 ** workaround for that we call memcached_quit to send the quit command
5252 ** to the server and wait for the response ;-) If you use the test code
5253 ** as an example for your own code, please note that you shouldn't need
5256 memcached_quit(memc
);
5258 /* Verify that all messages are stored, and we didn't stuff too much
5261 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5262 assert(rc
== MEMCACHED_SUCCESS
);
5264 unsigned int counter
= 0;
5265 memcached_execute_fn callbacks
[1]= { [0]= &callback_counter
};
5266 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5267 /* Verify that we received all of the key/value pairs */
5268 assert(counter
== (unsigned int)max_keys
);
5270 memcached_quit(memc
);
5272 * Don't do the following in your code. I am abusing the internal details
5273 * within the library, and this is not a supported interface.
5274 * This is to verify correct behavior in the library. Fake that two servers
5277 in_port_t port0
= memc
->hosts
[0].port
;
5278 in_port_t port2
= memc
->hosts
[2].port
;
5280 memc
->hosts
[0].port
= 0;
5281 memc
->hosts
[2].port
= 0;
5283 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5284 assert(rc
== MEMCACHED_SUCCESS
);
5287 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5288 assert(counter
== (unsigned int)max_keys
);
5290 /* restore the memc handle */
5291 memc
->hosts
[0].port
= port0
;
5292 memc
->hosts
[2].port
= port2
;
5294 memcached_quit(memc
);
5296 /* Remove half of the objects */
5297 for (int x
= 0; x
< (int)max_keys
; ++x
)
5301 rc
= memcached_delete(memc
, keys
[x
], key_length
[x
], 0);
5302 assert(rc
== MEMCACHED_SUCCESS
);
5306 memcached_quit(memc
);
5307 memc
->hosts
[0].port
= 0;
5308 memc
->hosts
[2].port
= 0;
5310 /* now retry the command, this time we should have cache misses */
5311 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5312 assert(rc
== MEMCACHED_SUCCESS
);
5315 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5316 assert(counter
== (unsigned int)(max_keys
>> 1));
5318 /* Release allocated resources */
5319 for (size_t x
= 0; x
< max_keys
; ++x
)
5324 /* restore the memc handle */
5325 memc
->hosts
[0].port
= port0
;
5326 memc
->hosts
[2].port
= port2
;
5328 return TEST_SUCCESS
;
5331 static test_return_t
regression_bug_463297(memcached_st
*memc
)
5333 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
5334 assert(memc_clone
!= NULL
);
5335 assert(memcached_version(memc_clone
) == MEMCACHED_SUCCESS
);
5337 if (memc_clone
->hosts
[0].major_version
> 1 ||
5338 (memc_clone
->hosts
[0].major_version
== 1 &&
5339 memc_clone
->hosts
[0].minor_version
> 2))
5341 /* Binary protocol doesn't support deferred delete */
5342 memcached_st
*bin_clone
= memcached_clone(NULL
, memc
);
5343 assert(bin_clone
!= NULL
);
5344 assert(memcached_behavior_set(bin_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1) == MEMCACHED_SUCCESS
);
5345 assert(memcached_delete(bin_clone
, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS
);
5346 memcached_free(bin_clone
);
5348 memcached_quit(memc_clone
);
5350 /* If we know the server version, deferred delete should fail
5351 * with invalid arguments */
5352 assert(memcached_delete(memc_clone
, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS
);
5354 /* If we don't know the server version, we should get a protocol error */
5355 memcached_return_t rc
= memcached_delete(memc
, "foo", 3, 1);
5356 /* but there is a bug in some of the memcached servers (1.4) that treats
5357 * the counter as noreply so it doesn't send the proper error message
5359 assert(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5361 /* And buffered mode should be disabled and we should get protocol error */
5362 assert(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1) == MEMCACHED_SUCCESS
);
5363 rc
= memcached_delete(memc
, "foo", 3, 1);
5364 assert(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5366 /* Same goes for noreply... */
5367 assert(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1) == MEMCACHED_SUCCESS
);
5368 rc
= memcached_delete(memc
, "foo", 3, 1);
5369 assert(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5371 /* but a normal request should go through (and be buffered) */
5372 assert((rc
= memcached_delete(memc
, "foo", 3, 0)) == MEMCACHED_BUFFERED
);
5373 assert(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
5375 assert(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 0) == MEMCACHED_SUCCESS
);
5376 /* unbuffered noreply should be success */
5377 assert(memcached_delete(memc
, "foo", 3, 0) == MEMCACHED_SUCCESS
);
5378 /* unbuffered with reply should be not found... */
5379 assert(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0) == MEMCACHED_SUCCESS
);
5380 assert(memcached_delete(memc
, "foo", 3, 0) == MEMCACHED_NOTFOUND
);
5383 memcached_free(memc_clone
);
5384 return TEST_SUCCESS
;
5388 /* Test memcached_server_get_last_disconnect
5389 * For a working server set, shall be NULL
5390 * For a set of non existing server, shall not be NULL
5392 static test_return_t
test_get_last_disconnect(memcached_st
*memc
)
5394 memcached_return_t rc
;
5395 memcached_server_st
*disconnected_server
;
5397 /* With the working set of server */
5398 const char *key
= "marmotte";
5399 const char *value
= "milka";
5401 rc
= memcached_set(memc
, key
, strlen(key
),
5402 value
, strlen(value
),
5403 (time_t)0, (uint32_t)0);
5404 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5406 disconnected_server
= memcached_server_get_last_disconnect(memc
);
5407 assert(disconnected_server
== NULL
);
5409 /* With a non existing server */
5411 memcached_server_st
*servers
;
5413 const char *server_list
= "localhost:9";
5415 servers
= memcached_servers_parse(server_list
);
5417 mine
= memcached_create(NULL
);
5418 rc
= memcached_server_push(mine
, servers
);
5419 assert(rc
== MEMCACHED_SUCCESS
);
5420 memcached_server_list_free(servers
);
5423 rc
= memcached_set(mine
, key
, strlen(key
),
5424 value
, strlen(value
),
5425 (time_t)0, (uint32_t)0);
5426 assert(rc
!= MEMCACHED_SUCCESS
);
5428 disconnected_server
= memcached_server_get_last_disconnect(mine
);
5429 assert(disconnected_server
!= NULL
);
5430 assert(disconnected_server
->port
== 9);
5431 assert(strncmp(disconnected_server
->hostname
,"localhost",9) == 0);
5433 memcached_quit(mine
);
5434 memcached_free(mine
);
5436 return TEST_SUCCESS
;
5440 * This test ensures that the failure counter isn't incremented during
5441 * normal termination of the memcached instance.
5443 static test_return_t
wrong_failure_counter_test(memcached_st
*memc
)
5445 memcached_return_t rc
;
5447 /* Set value to force connection to the server */
5448 const char *key
= "marmotte";
5449 const char *value
= "milka";
5452 * Please note that I'm abusing the internal structures in libmemcached
5453 * in a non-portable way and you shouldn't be doing this. I'm only
5454 * doing this in order to verify that the library works the way it should
5456 uint32_t number_of_hosts
= memc
->number_of_hosts
;
5457 memc
->number_of_hosts
= 1;
5459 /* Ensure that we are connected to the server by setting a value */
5460 rc
= memcached_set(memc
, key
, strlen(key
),
5461 value
, strlen(value
),
5462 (time_t)0, (uint32_t)0);
5463 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5466 /* The test is to see that the memcached_quit doesn't increase the
5467 * the server failure conter, so let's ensure that it is zero
5468 * before sending quit
5470 memc
->hosts
[0].server_failure_counter
= 0;
5472 memcached_quit(memc
);
5474 /* Verify that it memcached_quit didn't increment the failure counter
5475 * Please note that this isn't bullet proof, because an error could
5478 assert(memc
->hosts
[0].server_failure_counter
== 0);
5480 /* restore the instance */
5481 memc
->number_of_hosts
= number_of_hosts
;
5483 return TEST_SUCCESS
;
5486 test_st udp_setup_server_tests
[] ={
5487 {"set_udp_behavior_test", 0, (test_callback_fn
)set_udp_behavior_test
},
5488 {"add_tcp_server_udp_client_test", 0, (test_callback_fn
)add_tcp_server_udp_client_test
},
5489 {"add_udp_server_tcp_client_test", 0, (test_callback_fn
)add_udp_server_tcp_client_test
},
5493 test_st upd_io_tests
[] ={
5494 {"udp_set_test", 0, (test_callback_fn
)udp_set_test
},
5495 {"udp_buffered_set_test", 0, (test_callback_fn
)udp_buffered_set_test
},
5496 {"udp_set_too_big_test", 0, (test_callback_fn
)udp_set_too_big_test
},
5497 {"udp_delete_test", 0, (test_callback_fn
)udp_delete_test
},
5498 {"udp_buffered_delete_test", 0, (test_callback_fn
)udp_buffered_delete_test
},
5499 {"udp_verbosity_test", 0, (test_callback_fn
)udp_verbosity_test
},
5500 {"udp_quit_test", 0, (test_callback_fn
)udp_quit_test
},
5501 {"udp_flush_test", 0, (test_callback_fn
)udp_flush_test
},
5502 {"udp_incr_test", 0, (test_callback_fn
)udp_incr_test
},
5503 {"udp_decr_test", 0, (test_callback_fn
)udp_decr_test
},
5504 {"udp_stat_test", 0, (test_callback_fn
)udp_stat_test
},
5505 {"udp_version_test", 0, (test_callback_fn
)udp_version_test
},
5506 {"udp_get_test", 0, (test_callback_fn
)udp_get_test
},
5507 {"udp_mixed_io_test", 0, (test_callback_fn
)udp_mixed_io_test
},
5511 /* Clean the server before beginning testing */
5513 {"flush", 0, (test_callback_fn
)flush_test
},
5514 {"init", 0, (test_callback_fn
)init_test
},
5515 {"allocation", 0, (test_callback_fn
)allocation_test
},
5516 {"server_list_null_test", 0, (test_callback_fn
)server_list_null_test
},
5517 {"server_unsort", 0, (test_callback_fn
)server_unsort_test
},
5518 {"server_sort", 0, (test_callback_fn
)server_sort_test
},
5519 {"server_sort2", 0, (test_callback_fn
)server_sort2_test
},
5520 {"clone_test", 0, (test_callback_fn
)clone_test
},
5521 {"connection_test", 0, (test_callback_fn
)connection_test
},
5522 {"callback_test", 0, (test_callback_fn
)callback_test
},
5523 {"behavior_test", 0, (test_callback_fn
)behavior_test
},
5524 {"userdata_test", 0, (test_callback_fn
)userdata_test
},
5525 {"error", 0, (test_callback_fn
)error_test
},
5526 {"set", 0, (test_callback_fn
)set_test
},
5527 {"set2", 0, (test_callback_fn
)set_test2
},
5528 {"set3", 0, (test_callback_fn
)set_test3
},
5529 {"dump", 1, (test_callback_fn
)dump_test
},
5530 {"add", 1, (test_callback_fn
)add_test
},
5531 {"replace", 1, (test_callback_fn
)replace_test
},
5532 {"delete", 1, (test_callback_fn
)delete_test
},
5533 {"get", 1, (test_callback_fn
)get_test
},
5534 {"get2", 0, (test_callback_fn
)get_test2
},
5535 {"get3", 0, (test_callback_fn
)get_test3
},
5536 {"get4", 0, (test_callback_fn
)get_test4
},
5537 {"partial mget", 0, (test_callback_fn
)get_test5
},
5538 {"stats_servername", 0, (test_callback_fn
)stats_servername_test
},
5539 {"increment", 0, (test_callback_fn
)increment_test
},
5540 {"increment_with_initial", 1, (test_callback_fn
)increment_with_initial_test
},
5541 {"decrement", 0, (test_callback_fn
)decrement_test
},
5542 {"decrement_with_initial", 1, (test_callback_fn
)decrement_with_initial_test
},
5543 {"increment_by_key", 0, (test_callback_fn
)increment_by_key_test
},
5544 {"increment_with_initial_by_key", 1, (test_callback_fn
)increment_with_initial_by_key_test
},
5545 {"decrement_by_key", 0, (test_callback_fn
)decrement_by_key_test
},
5546 {"decrement_with_initial_by_key", 1, (test_callback_fn
)decrement_with_initial_by_key_test
},
5547 {"quit", 0, (test_callback_fn
)quit_test
},
5548 {"mget", 1, (test_callback_fn
)mget_test
},
5549 {"mget_result", 1, (test_callback_fn
)mget_result_test
},
5550 {"mget_result_alloc", 1, (test_callback_fn
)mget_result_alloc_test
},
5551 {"mget_result_function", 1, (test_callback_fn
)mget_result_function
},
5552 {"mget_execute", 1, (test_callback_fn
)mget_execute
},
5553 {"mget_end", 0, (test_callback_fn
)mget_end
},
5554 {"get_stats", 0, (test_callback_fn
)get_stats
},
5555 {"add_host_test", 0, (test_callback_fn
)add_host_test
},
5556 {"add_host_test_1", 0, (test_callback_fn
)add_host_test1
},
5557 {"get_stats_keys", 0, (test_callback_fn
)get_stats_keys
},
5558 {"behavior_test", 0, (test_callback_fn
)get_stats_keys
},
5559 {"callback_test", 0, (test_callback_fn
)get_stats_keys
},
5560 {"version_string_test", 0, (test_callback_fn
)version_string_test
},
5561 {"bad_key", 1, (test_callback_fn
)bad_key_test
},
5562 {"memcached_server_cursor", 1, (test_callback_fn
)memcached_server_cursor_test
},
5563 {"read_through", 1, (test_callback_fn
)read_through
},
5564 {"delete_through", 1, (test_callback_fn
)delete_through
},
5565 {"noreply", 1, (test_callback_fn
)noreply_test
},
5566 {"analyzer", 1, (test_callback_fn
)analyzer_test
},
5567 #ifdef HAVE_LIBMEMCACHEDUTIL
5568 {"connectionpool", 1, (test_callback_fn
)connection_pool_test
},
5570 {"test_get_last_disconnect", 1, (test_callback_fn
)test_get_last_disconnect
},
5574 test_st async_tests
[] ={
5575 {"add", 1, (test_callback_fn
)add_wrapper
},
5579 test_st string_tests
[] ={
5580 {"string static with null", 0, (test_callback_fn
)string_static_null
},
5581 {"string alloc with null", 0, (test_callback_fn
)string_alloc_null
},
5582 {"string alloc with 1K", 0, (test_callback_fn
)string_alloc_with_size
},
5583 {"string alloc with malloc failure", 0, (test_callback_fn
)string_alloc_with_size_toobig
},
5584 {"string append", 0, (test_callback_fn
)string_alloc_append
},
5585 {"string append failure (too big)", 0, (test_callback_fn
)string_alloc_append_toobig
},
5586 {0, 0, (test_callback_fn
)0}
5589 test_st result_tests
[] ={
5590 {"result static", 0, (test_callback_fn
)result_static
},
5591 {"result alloc", 0, (test_callback_fn
)result_alloc
},
5592 {0, 0, (test_callback_fn
)0}
5595 test_st version_1_2_3
[] ={
5596 {"append", 0, (test_callback_fn
)append_test
},
5597 {"prepend", 0, (test_callback_fn
)prepend_test
},
5598 {"cas", 0, (test_callback_fn
)cas_test
},
5599 {"cas2", 0, (test_callback_fn
)cas2_test
},
5600 {"append_binary", 0, (test_callback_fn
)append_binary_test
},
5601 {0, 0, (test_callback_fn
)0}
5604 test_st user_tests
[] ={
5605 {"user_supplied_bug1", 0, (test_callback_fn
)user_supplied_bug1
},
5606 {"user_supplied_bug2", 0, (test_callback_fn
)user_supplied_bug2
},
5607 {"user_supplied_bug3", 0, (test_callback_fn
)user_supplied_bug3
},
5608 {"user_supplied_bug4", 0, (test_callback_fn
)user_supplied_bug4
},
5609 {"user_supplied_bug5", 1, (test_callback_fn
)user_supplied_bug5
},
5610 {"user_supplied_bug6", 1, (test_callback_fn
)user_supplied_bug6
},
5611 {"user_supplied_bug7", 1, (test_callback_fn
)user_supplied_bug7
},
5612 {"user_supplied_bug8", 1, (test_callback_fn
)user_supplied_bug8
},
5613 {"user_supplied_bug9", 1, (test_callback_fn
)user_supplied_bug9
},
5614 {"user_supplied_bug10", 1, (test_callback_fn
)user_supplied_bug10
},
5615 {"user_supplied_bug11", 1, (test_callback_fn
)user_supplied_bug11
},
5616 {"user_supplied_bug12", 1, (test_callback_fn
)user_supplied_bug12
},
5617 {"user_supplied_bug13", 1, (test_callback_fn
)user_supplied_bug13
},
5618 {"user_supplied_bug14", 1, (test_callback_fn
)user_supplied_bug14
},
5619 {"user_supplied_bug15", 1, (test_callback_fn
)user_supplied_bug15
},
5620 {"user_supplied_bug16", 1, (test_callback_fn
)user_supplied_bug16
},
5623 ** It seems to be something weird with the character sets..
5624 ** value_fetch is unable to parse the value line (iscntrl "fails"), so I
5625 ** guess I need to find out how this is supposed to work.. Perhaps I need
5626 ** to run the test in a specific locale (I tried zh_CN.UTF-8 without success,
5627 ** so just disable the code for now...).
5629 {"user_supplied_bug17", 1, (test_callback_fn
)user_supplied_bug17
},
5631 {"user_supplied_bug18", 1, (test_callback_fn
)user_supplied_bug18
},
5632 {"user_supplied_bug19", 1, (test_callback_fn
)user_supplied_bug19
},
5633 {"user_supplied_bug20", 1, (test_callback_fn
)user_supplied_bug20
},
5634 {"user_supplied_bug21", 1, (test_callback_fn
)user_supplied_bug21
},
5635 {"wrong_failure_counter_test", 1, (test_callback_fn
)wrong_failure_counter_test
},
5636 {0, 0, (test_callback_fn
)0}
5639 test_st replication_tests
[]= {
5640 {"set", 1, (test_callback_fn
)replication_set_test
},
5641 {"get", 0, (test_callback_fn
)replication_get_test
},
5642 {"mget", 0, (test_callback_fn
)replication_mget_test
},
5643 {"delete", 0, (test_callback_fn
)replication_delete_test
},
5644 {"rand_mget", 0, (test_callback_fn
)replication_randomize_mget_test
},
5645 {0, 0, (test_callback_fn
)0}
5649 * The following test suite is used to verify that we don't introduce
5650 * regression bugs. If you want more information about the bug / test,
5651 * you should look in the bug report at
5652 * http://bugs.launchpad.net/libmemcached
5654 test_st regression_tests
[]= {
5655 {"lp:434484", 1, (test_callback_fn
)regression_bug_434484
},
5656 {"lp:434843", 1, (test_callback_fn
)regression_bug_434843
},
5657 {"lp:434843 buffered", 1, (test_callback_fn
)regression_bug_434843_buffered
},
5658 {"lp:421108", 1, (test_callback_fn
)regression_bug_421108
},
5659 {"lp:442914", 1, (test_callback_fn
)regression_bug_442914
},
5660 {"lp:447342", 1, (test_callback_fn
)regression_bug_447342
},
5661 {"lp:463297", 1, (test_callback_fn
)regression_bug_463297
},
5662 {0, 0, (test_callback_fn
)0}
5665 test_st ketama_compatibility
[]= {
5666 {"libmemcached", 1, (test_callback_fn
)ketama_compatibility_libmemcached
},
5667 {"spymemcached", 1, (test_callback_fn
)ketama_compatibility_spymemcached
},
5668 {0, 0, (test_callback_fn
)0}
5671 test_st generate_tests
[] ={
5672 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
5673 {"generate_data", 1, (test_callback_fn
)generate_data
},
5674 {"get_read", 0, (test_callback_fn
)get_read
},
5675 {"delete_generate", 0, (test_callback_fn
)delete_generate
},
5676 {"generate_buffer_data", 1, (test_callback_fn
)generate_buffer_data
},
5677 {"delete_buffer", 0, (test_callback_fn
)delete_buffer_generate
},
5678 {"generate_data", 1, (test_callback_fn
)generate_data
},
5679 {"mget_read", 0, (test_callback_fn
)mget_read
},
5680 {"mget_read_result", 0, (test_callback_fn
)mget_read_result
},
5681 {"mget_read_function", 0, (test_callback_fn
)mget_read_function
},
5682 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5683 {"generate_large_pairs", 1, (test_callback_fn
)generate_large_pairs
},
5684 {"generate_data", 1, (test_callback_fn
)generate_data
},
5685 {"generate_buffer_data", 1, (test_callback_fn
)generate_buffer_data
},
5686 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5687 {0, 0, (test_callback_fn
)0}
5690 test_st consistent_tests
[] ={
5691 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
5692 {"generate_data", 1, (test_callback_fn
)generate_data
},
5693 {"get_read", 0, (test_callback_fn
)get_read_count
},
5694 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5695 {0, 0, (test_callback_fn
)0}
5698 test_st consistent_weighted_tests
[] ={
5699 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
5700 {"generate_data", 1, (test_callback_fn
)generate_data_with_stats
},
5701 {"get_read", 0, (test_callback_fn
)get_read_count
},
5702 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5703 {0, 0, (test_callback_fn
)0}
5706 test_st hsieh_availability
[] ={
5707 {"hsieh_avaibility_test", 0, (test_callback_fn
)hsieh_avaibility_test
},
5708 {0, 0, (test_callback_fn
)0}
5712 test_st hash_sanity
[] ={
5713 {"hash sanity", 0, (test_callback_fn
)hash_sanity_test
},
5714 {0, 0, (test_callback_fn
)0}
5718 test_st ketama_auto_eject_hosts
[] ={
5719 {"auto_eject_hosts", 1, (test_callback_fn
)auto_eject_hosts
},
5720 {"output_ketama_weighted_keys", 1, (test_callback_fn
)output_ketama_weighted_keys
},
5721 {0, 0, (test_callback_fn
)0}
5724 test_st hash_tests
[] ={
5725 {"md5", 0, (test_callback_fn
)md5_run
},
5726 {"crc", 0, (test_callback_fn
)crc_run
},
5727 {"fnv1_64", 0, (test_callback_fn
)fnv1_64_run
},
5728 {"fnv1a_64", 0, (test_callback_fn
)fnv1a_64_run
},
5729 {"fnv1_32", 0, (test_callback_fn
)fnv1_32_run
},
5730 {"fnv1a_32", 0, (test_callback_fn
)fnv1a_32_run
},
5731 {"hsieh", 0, (test_callback_fn
)hsieh_run
},
5732 {"murmur", 0, (test_callback_fn
)murmur_run
},
5733 {"jenkis", 0, (test_callback_fn
)jenkins_run
},
5734 {0, 0, (test_callback_fn
)0}
5737 collection_st collection
[] ={
5739 {"hash_sanity", 0, 0, hash_sanity
},
5741 {"hsieh_availability", 0, 0, hsieh_availability
},
5742 {"udp_setup", (test_callback_fn
)init_udp
, 0, udp_setup_server_tests
},
5743 {"udp_io", (test_callback_fn
)init_udp
, 0, upd_io_tests
},
5744 {"udp_binary_io", (test_callback_fn
)binary_init_udp
, 0, upd_io_tests
},
5745 {"block", 0, 0, tests
},
5746 {"binary", (test_callback_fn
)pre_binary
, 0, tests
},
5747 {"nonblock", (test_callback_fn
)pre_nonblock
, 0, tests
},
5748 {"nodelay", (test_callback_fn
)pre_nodelay
, 0, tests
},
5749 {"settimer", (test_callback_fn
)pre_settimer
, 0, tests
},
5750 {"md5", (test_callback_fn
)pre_md5
, 0, tests
},
5751 {"crc", (test_callback_fn
)pre_crc
, 0, tests
},
5752 {"hsieh", (test_callback_fn
)pre_hsieh
, 0, tests
},
5753 {"jenkins", (test_callback_fn
)pre_jenkins
, 0, tests
},
5754 {"fnv1_64", (test_callback_fn
)pre_hash_fnv1_64
, 0, tests
},
5755 {"fnv1a_64", (test_callback_fn
)pre_hash_fnv1a_64
, 0, tests
},
5756 {"fnv1_32", (test_callback_fn
)pre_hash_fnv1_32
, 0, tests
},
5757 {"fnv1a_32", (test_callback_fn
)pre_hash_fnv1a_32
, 0, tests
},
5758 {"ketama", (test_callback_fn
)pre_behavior_ketama
, 0, tests
},
5759 {"ketama_auto_eject_hosts", (test_callback_fn
)pre_behavior_ketama
, 0, ketama_auto_eject_hosts
},
5760 {"unix_socket", (test_callback_fn
)pre_unix_socket
, 0, tests
},
5761 {"unix_socket_nodelay", (test_callback_fn
)pre_nodelay
, 0, tests
},
5762 {"poll_timeout", (test_callback_fn
)poll_timeout
, 0, tests
},
5763 {"gets", (test_callback_fn
)enable_cas
, 0, tests
},
5764 {"consistent_crc", (test_callback_fn
)enable_consistent_crc
, 0, tests
},
5765 {"consistent_hsieh", (test_callback_fn
)enable_consistent_hsieh
, 0, tests
},
5766 #ifdef MEMCACHED_ENABLE_DEPRECATED
5767 {"deprecated_memory_allocators", (test_callback_fn
)deprecated_set_memory_alloc
, 0, tests
},
5769 {"memory_allocators", (test_callback_fn
)set_memory_alloc
, 0, tests
},
5770 {"prefix", (test_callback_fn
)set_prefix
, 0, tests
},
5771 {"version_1_2_3", (test_callback_fn
)check_for_1_2_3
, 0, version_1_2_3
},
5772 {"string", 0, 0, string_tests
},
5773 {"result", 0, 0, result_tests
},
5774 {"async", (test_callback_fn
)pre_nonblock
, 0, async_tests
},
5775 {"async_binary", (test_callback_fn
)pre_nonblock_binary
, 0, async_tests
},
5776 {"user", 0, 0, user_tests
},
5777 {"generate", 0, 0, generate_tests
},
5778 {"generate_hsieh", (test_callback_fn
)pre_hsieh
, 0, generate_tests
},
5779 {"generate_ketama", (test_callback_fn
)pre_behavior_ketama
, 0, generate_tests
},
5780 {"generate_hsieh_consistent", (test_callback_fn
)enable_consistent_hsieh
, 0, generate_tests
},
5781 {"generate_md5", (test_callback_fn
)pre_md5
, 0, generate_tests
},
5782 {"generate_murmur", (test_callback_fn
)pre_murmur
, 0, generate_tests
},
5783 {"generate_jenkins", (test_callback_fn
)pre_jenkins
, 0, generate_tests
},
5784 {"generate_nonblock", (test_callback_fn
)pre_nonblock
, 0, generate_tests
},
5785 {"consistent_not", 0, 0, consistent_tests
},
5786 {"consistent_ketama", (test_callback_fn
)pre_behavior_ketama
, 0, consistent_tests
},
5787 {"consistent_ketama_weighted", (test_callback_fn
)pre_behavior_ketama_weighted
, 0, consistent_weighted_tests
},
5788 {"ketama_compat", 0, 0, ketama_compatibility
},
5789 {"test_hashes", 0, 0, hash_tests
},
5790 {"replication", (test_callback_fn
)pre_replication
, 0, replication_tests
},
5791 {"replication_noblock", (test_callback_fn
)pre_replication_noblock
, 0, replication_tests
},
5792 {"regression", 0, 0, regression_tests
},
5796 #define SERVERS_TO_CREATE 5
5798 #include "libmemcached_world.h"
5800 void get_world(world_st
*world
)
5802 world
->collections
= collection
;
5803 world
->collection_startup
= (test_callback_fn
)world_collection_startup
;
5804 world
->flush
= (test_callback_fn
)world_flush
;
5805 world
->pre_run
= (test_callback_fn
)world_pre_run
;
5806 world
->create
= (test_callback_create_fn
)world_create
;
5807 world
->post_run
= (test_callback_fn
)world_post_run
;
5808 world
->on_error
= (test_callback_error_fn
)world_on_error
;
5809 world
->destroy
= (test_callback_fn
)world_destroy
;
5810 world
->runner
= &defualt_libmemcached_runner
;