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_true(server_list
== NULL
);
73 server_list
= memcached_server_list_append_with_weight(NULL
, "localhost", 0, 0, NULL
);
74 test_true(server_list
== NULL
);
76 server_list
= memcached_server_list_append_with_weight(NULL
, NULL
, 0, 0, &rc
);
77 test_true(server_list
== NULL
);
82 #define TEST_PORT_COUNT 7
83 in_port_t test_ports
[TEST_PORT_COUNT
];
85 static memcached_return_t
server_display_function(const memcached_st
*ptr
__attribute__((unused
)),
86 memcached_server_st
*server
, void *context
)
89 size_t bigger
= *((size_t *)(context
));
90 assert(bigger
<= server
->port
);
91 *((size_t *)(context
))= server
->port
;
93 return MEMCACHED_SUCCESS
;
96 static test_return_t
server_sort_test(memcached_st
*ptr
__attribute__((unused
)))
98 size_t bigger
= 0; /* Prime the value for the test_true in server_display_function */
100 memcached_return_t rc
;
101 memcached_server_fn callbacks
[1];
102 memcached_st
*local_memc
;
104 local_memc
= memcached_create(NULL
);
105 test_true(local_memc
);
106 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
108 for (size_t x
= 0; x
< TEST_PORT_COUNT
; x
++)
110 test_ports
[x
]= (in_port_t
)random() % 64000;
111 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
112 test_true(memcached_server_count(local_memc
) == x
+ 1);
113 test_true(memcached_servers_count(memcached_server_list(local_memc
)) == x
+1);
114 test_true(rc
== MEMCACHED_SUCCESS
);
117 callbacks
[0]= server_display_function
;
118 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
121 memcached_free(local_memc
);
126 static test_return_t
server_sort2_test(memcached_st
*ptr
__attribute__((unused
)))
128 size_t bigger
= 0; /* Prime the value for the test_true in server_display_function */
129 memcached_return_t rc
;
130 memcached_server_fn callbacks
[1];
131 memcached_st
*local_memc
;
132 memcached_server_instance_st
*instance
;
134 local_memc
= memcached_create(NULL
);
135 test_true(local_memc
);
136 rc
= memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
137 test_true(rc
== MEMCACHED_SUCCESS
);
139 rc
= memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43043, 0);
140 test_true(rc
== MEMCACHED_SUCCESS
);
141 instance
= memcached_server_instance_fetch(local_memc
, 0);
142 test_true(instance
->port
== 43043);
144 rc
= memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43042, 0);
145 test_true(rc
== MEMCACHED_SUCCESS
);
147 instance
= memcached_server_instance_fetch(local_memc
, 0);
148 test_true(instance
->port
== 43042);
150 instance
= memcached_server_instance_fetch(local_memc
, 1);
151 test_true(instance
->port
== 43043);
153 callbacks
[0]= server_display_function
;
154 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
157 memcached_free(local_memc
);
162 static memcached_return_t
server_display_unsort_function(const memcached_st
*ptr
__attribute__((unused
)), memcached_server_st
*server
, void *context
)
165 uint32_t x
= *((uint32_t *)(context
));
167 assert(test_ports
[x
] == server
->port
);
168 *((uint32_t *)(context
))= ++x
;
170 return MEMCACHED_SUCCESS
;
173 static test_return_t
server_unsort_test(memcached_st
*ptr
__attribute__((unused
)))
175 size_t counter
= 0; /* Prime the value for the test_true in server_display_function */
176 size_t bigger
= 0; /* Prime the value for the test_true in server_display_function */
177 memcached_return_t rc
;
178 memcached_server_fn callbacks
[1];
179 memcached_st
*local_memc
;
181 local_memc
= memcached_create(NULL
);
182 test_true(local_memc
);
184 for (size_t x
= 0; x
< TEST_PORT_COUNT
; x
++)
186 test_ports
[x
]= (in_port_t
)(random() % 64000);
187 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
188 test_true(memcached_server_count(local_memc
) == x
+1);
189 test_true(memcached_servers_count(memcached_server_list(local_memc
)) == x
+1);
190 test_true(rc
== MEMCACHED_SUCCESS
);
193 callbacks
[0]= server_display_unsort_function
;
194 memcached_server_cursor(local_memc
, callbacks
, (void *)&counter
, 1);
196 /* Now we sort old data! */
197 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
198 callbacks
[0]= server_display_function
;
199 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
202 memcached_free(local_memc
);
207 static test_return_t
allocation_test(memcached_st
*not_used
__attribute__((unused
)))
210 memc
= memcached_create(NULL
);
212 memcached_free(memc
);
217 static test_return_t
clone_test(memcached_st
*memc
)
221 memcached_st
*memc_clone
;
222 memc_clone
= memcached_clone(NULL
, NULL
);
223 test_true(memc_clone
);
224 memcached_free(memc_clone
);
227 /* Can we init from null? */
229 memcached_st
*memc_clone
;
230 memc_clone
= memcached_clone(NULL
, memc
);
231 test_true(memc_clone
);
234 test_true(memc_clone
->allocators
.free
== memc
->allocators
.free
);
235 test_true(memc_clone
->allocators
.malloc
== memc
->allocators
.malloc
);
236 test_true(memc_clone
->allocators
.realloc
== memc
->allocators
.realloc
);
237 test_true(memc_clone
->allocators
.calloc
== memc
->allocators
.calloc
);
240 test_true(memc_clone
->connect_timeout
== memc
->connect_timeout
);
241 test_true(memc_clone
->delete_trigger
== memc
->delete_trigger
);
242 test_true(memc_clone
->distribution
== memc
->distribution
);
243 { // Test all of the flags
244 test_true(memc_clone
->flags
.no_block
== memc
->flags
.no_block
);
245 test_true(memc_clone
->flags
.tcp_nodelay
== memc
->flags
.tcp_nodelay
);
246 test_true(memc_clone
->flags
.reuse_memory
== memc
->flags
.reuse_memory
);
247 test_true(memc_clone
->flags
.use_cache_lookups
== memc
->flags
.use_cache_lookups
);
248 test_true(memc_clone
->flags
.support_cas
== memc
->flags
.support_cas
);
249 test_true(memc_clone
->flags
.buffer_requests
== memc
->flags
.buffer_requests
);
250 test_true(memc_clone
->flags
.use_sort_hosts
== memc
->flags
.use_sort_hosts
);
251 test_true(memc_clone
->flags
.verify_key
== memc
->flags
.verify_key
);
252 test_true(memc_clone
->flags
.ketama_weighted
== memc
->flags
.ketama_weighted
);
253 test_true(memc_clone
->flags
.binary_protocol
== memc
->flags
.binary_protocol
);
254 test_true(memc_clone
->flags
.hash_with_prefix_key
== memc
->flags
.hash_with_prefix_key
);
255 test_true(memc_clone
->flags
.no_reply
== memc
->flags
.no_reply
);
256 test_true(memc_clone
->flags
.use_udp
== memc
->flags
.use_udp
);
257 test_true(memc_clone
->flags
.auto_eject_hosts
== memc
->flags
.auto_eject_hosts
);
258 test_true(memc_clone
->flags
.randomize_replica_read
== memc
->flags
.randomize_replica_read
);
260 test_true(memc_clone
->get_key_failure
== memc
->get_key_failure
);
261 test_true(memc_clone
->hash
== memc
->hash
);
262 test_true(memc_clone
->distribution_hash
== memc
->distribution_hash
);
263 test_true(memc_clone
->io_bytes_watermark
== memc
->io_bytes_watermark
);
264 test_true(memc_clone
->io_msg_watermark
== memc
->io_msg_watermark
);
265 test_true(memc_clone
->io_key_prefetch
== memc
->io_key_prefetch
);
266 test_true(memc_clone
->on_cleanup
== memc
->on_cleanup
);
267 test_true(memc_clone
->on_clone
== memc
->on_clone
);
268 test_true(memc_clone
->poll_timeout
== memc
->poll_timeout
);
269 test_true(memc_clone
->rcv_timeout
== memc
->rcv_timeout
);
270 test_true(memc_clone
->recv_size
== memc
->recv_size
);
271 test_true(memc_clone
->retry_timeout
== memc
->retry_timeout
);
272 test_true(memc_clone
->send_size
== memc
->send_size
);
273 test_true(memc_clone
->server_failure_limit
== memc
->server_failure_limit
);
274 test_true(memc_clone
->snd_timeout
== memc
->snd_timeout
);
275 test_true(memc_clone
->user_data
== memc
->user_data
);
277 memcached_free(memc_clone
);
280 /* Can we init from struct? */
282 memcached_st declared_clone
;
283 memcached_st
*memc_clone
;
284 memset(&declared_clone
, 0 , sizeof(memcached_st
));
285 memc_clone
= memcached_clone(&declared_clone
, NULL
);
286 test_true(memc_clone
);
287 memcached_free(memc_clone
);
290 /* Can we init from struct? */
292 memcached_st declared_clone
;
293 memcached_st
*memc_clone
;
294 memset(&declared_clone
, 0 , sizeof(memcached_st
));
295 memc_clone
= memcached_clone(&declared_clone
, memc
);
296 test_true(memc_clone
);
297 memcached_free(memc_clone
);
303 static test_return_t
userdata_test(memcached_st
*memc
)
306 test_true(memcached_set_user_data(memc
, foo
) == NULL
);
307 test_true(memcached_get_user_data(memc
) == foo
);
308 test_true(memcached_set_user_data(memc
, NULL
) == foo
);
313 static test_return_t
connection_test(memcached_st
*memc
)
315 memcached_return_t rc
;
317 rc
= memcached_server_add_with_weight(memc
, "localhost", 0, 0);
318 test_true(rc
== MEMCACHED_SUCCESS
);
323 static test_return_t
error_test(memcached_st
*memc
)
325 memcached_return_t rc
;
326 uint32_t values
[] = { 851992627U, 2337886783U, 3196981036U, 4001849190U,
327 982370485U, 1263635348U, 4242906218U, 3829656100U,
328 1891735253U, 334139633U, 2257084983U, 3088286104U,
329 13199785U, 2542027183U, 1097051614U, 199566778U,
330 2748246961U, 2465192557U, 1664094137U, 2405439045U,
331 1842224848U, 692413798U, 3479807801U, 919913813U,
332 4269430871U, 610793021U, 527273862U, 1437122909U,
333 2300930706U, 2943759320U, 674306647U, 2400528935U,
334 54481931U, 4186304426U, 1741088401U, 2979625118U,
335 4159057246U, 3425930182U, 2593724503U, 1868899624U};
337 // You have updated the memcache_error messages but not updated docs/tests.
338 test_true(MEMCACHED_MAXIMUM_RETURN
== 40);
339 for (rc
= MEMCACHED_SUCCESS
; rc
< MEMCACHED_MAXIMUM_RETURN
; rc
++)
342 const char *msg
= memcached_strerror(memc
, rc
);
343 hash_val
= memcached_generate_hash_value(msg
, strlen(msg
),
344 MEMCACHED_HASH_JENKINS
);
345 if (values
[rc
] != hash_val
)
347 fprintf(stderr
, "\n\nYou have updated memcached_return_t without updating the error_test\n");
348 fprintf(stderr
, "%u, %s, (%u)\n\n", (uint32_t)rc
, memcached_strerror(memc
, rc
), hash_val
);
350 test_true(values
[rc
] == hash_val
);
356 static test_return_t
set_test(memcached_st
*memc
)
358 memcached_return_t rc
;
359 const char *key
= "foo";
360 const char *value
= "when we sanitize";
362 rc
= memcached_set(memc
, key
, strlen(key
),
363 value
, strlen(value
),
364 (time_t)0, (uint32_t)0);
365 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
370 static test_return_t
append_test(memcached_st
*memc
)
372 memcached_return_t rc
;
373 const char *key
= "fig";
374 const char *in_value
= "we";
375 char *out_value
= NULL
;
379 rc
= memcached_flush(memc
, 0);
380 test_true(rc
== MEMCACHED_SUCCESS
);
382 rc
= memcached_set(memc
, key
, strlen(key
),
383 in_value
, strlen(in_value
),
384 (time_t)0, (uint32_t)0);
385 test_true(rc
== MEMCACHED_SUCCESS
);
387 rc
= memcached_append(memc
, key
, strlen(key
),
388 " the", strlen(" the"),
389 (time_t)0, (uint32_t)0);
390 test_true(rc
== MEMCACHED_SUCCESS
);
392 rc
= memcached_append(memc
, key
, strlen(key
),
393 " people", strlen(" people"),
394 (time_t)0, (uint32_t)0);
395 test_true(rc
== MEMCACHED_SUCCESS
);
397 out_value
= memcached_get(memc
, key
, strlen(key
),
398 &value_length
, &flags
, &rc
);
399 test_true(!memcmp(out_value
, "we the people", strlen("we the people")));
400 test_true(strlen("we the people") == value_length
);
401 test_true(rc
== MEMCACHED_SUCCESS
);
407 static test_return_t
append_binary_test(memcached_st
*memc
)
409 memcached_return_t rc
;
410 const char *key
= "numbers";
411 uint32_t store_list
[] = { 23, 56, 499, 98, 32847, 0 };
417 rc
= memcached_flush(memc
, 0);
418 test_true(rc
== MEMCACHED_SUCCESS
);
420 rc
= memcached_set(memc
,
423 (time_t)0, (uint32_t)0);
424 test_true(rc
== MEMCACHED_SUCCESS
);
426 for (x
= 0; store_list
[x
] ; x
++)
428 rc
= memcached_append(memc
,
430 (char *)&store_list
[x
], sizeof(uint32_t),
431 (time_t)0, (uint32_t)0);
432 test_true(rc
== MEMCACHED_SUCCESS
);
435 value
= (uint32_t *)memcached_get(memc
, key
, strlen(key
),
436 &value_length
, &flags
, &rc
);
437 test_true((value_length
== (sizeof(uint32_t) * x
)));
438 test_true(rc
== MEMCACHED_SUCCESS
);
440 for (uint32_t counter
= x
, *ptr
= value
; counter
; counter
--)
442 test_true(*ptr
== store_list
[x
- counter
]);
450 static test_return_t
cas2_test(memcached_st
*memc
)
452 memcached_return_t rc
;
453 const char *keys
[]= {"fudge", "son", "food"};
454 size_t key_length
[]= {5, 3, 4};
455 const char *value
= "we the people";
456 size_t value_length
= strlen("we the people");
458 memcached_result_st results_obj
;
459 memcached_result_st
*results
;
462 rc
= memcached_flush(memc
, 0);
463 test_true(rc
== MEMCACHED_SUCCESS
);
465 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
467 for (x
= 0; x
< 3; x
++)
469 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
470 keys
[x
], key_length
[x
],
471 (time_t)50, (uint32_t)9);
472 test_true(rc
== MEMCACHED_SUCCESS
);
475 rc
= memcached_mget(memc
, keys
, key_length
, 3);
477 results
= memcached_result_create(memc
, &results_obj
);
479 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
481 test_true(results
->item_cas
);
482 test_true(rc
== MEMCACHED_SUCCESS
);
483 test_true(memcached_result_cas(results
));
485 test_true(!memcmp(value
, "we the people", strlen("we the people")));
486 test_true(strlen("we the people") == value_length
);
487 test_true(rc
== MEMCACHED_SUCCESS
);
489 memcached_result_free(&results_obj
);
494 static test_return_t
cas_test(memcached_st
*memc
)
496 memcached_return_t rc
;
497 const char *key
= "fun";
498 size_t key_length
= strlen(key
);
499 const char *value
= "we the people";
500 const char* keys
[2] = { key
, NULL
};
501 size_t keylengths
[2] = { strlen(key
), 0 };
502 size_t value_length
= strlen(value
);
503 const char *value2
= "change the value";
504 size_t value2_length
= strlen(value2
);
506 memcached_result_st results_obj
;
507 memcached_result_st
*results
;
510 rc
= memcached_flush(memc
, 0);
511 test_true(rc
== MEMCACHED_SUCCESS
);
513 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
515 rc
= memcached_set(memc
, key
, strlen(key
),
516 value
, strlen(value
),
517 (time_t)0, (uint32_t)0);
518 test_true(rc
== MEMCACHED_SUCCESS
);
520 rc
= memcached_mget(memc
, keys
, keylengths
, 1);
522 results
= memcached_result_create(memc
, &results_obj
);
524 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
526 test_true(rc
== MEMCACHED_SUCCESS
);
527 test_true(memcached_result_cas(results
));
528 test_true(!memcmp(value
, memcached_result_value(results
), value_length
));
529 test_true(strlen(memcached_result_value(results
)) == value_length
);
530 test_true(rc
== MEMCACHED_SUCCESS
);
531 uint64_t cas
= memcached_result_cas(results
);
534 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
535 test_true(rc
== MEMCACHED_END
);
536 test_true(results
== NULL
);
539 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
540 test_true(rc
== MEMCACHED_SUCCESS
);
543 * The item will have a new cas value, so try to set it again with the old
544 * value. This should fail!
546 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
547 test_true(rc
== MEMCACHED_DATA_EXISTS
);
549 memcached_result_free(&results_obj
);
554 static test_return_t
prepend_test(memcached_st
*memc
)
556 memcached_return_t rc
;
557 const char *key
= "fig";
558 const char *value
= "people";
559 char *out_value
= NULL
;
563 rc
= memcached_flush(memc
, 0);
564 test_true(rc
== MEMCACHED_SUCCESS
);
566 rc
= memcached_set(memc
, key
, strlen(key
),
567 value
, strlen(value
),
568 (time_t)0, (uint32_t)0);
569 test_true(rc
== MEMCACHED_SUCCESS
);
571 rc
= memcached_prepend(memc
, key
, strlen(key
),
572 "the ", strlen("the "),
573 (time_t)0, (uint32_t)0);
574 test_true(rc
== MEMCACHED_SUCCESS
);
576 rc
= memcached_prepend(memc
, key
, strlen(key
),
577 "we ", strlen("we "),
578 (time_t)0, (uint32_t)0);
579 test_true(rc
== MEMCACHED_SUCCESS
);
581 out_value
= memcached_get(memc
, key
, strlen(key
),
582 &value_length
, &flags
, &rc
);
583 test_true(!memcmp(out_value
, "we the people", strlen("we the people")));
584 test_true(strlen("we the people") == value_length
);
585 test_true(rc
== MEMCACHED_SUCCESS
);
592 Set the value, then quit to make sure it is flushed.
593 Come back in and test that add fails.
595 static test_return_t
add_test(memcached_st
*memc
)
597 memcached_return_t rc
;
598 const char *key
= "foo";
599 const char *value
= "when we sanitize";
600 unsigned long long setting_value
;
602 setting_value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
604 rc
= memcached_set(memc
, key
, strlen(key
),
605 value
, strlen(value
),
606 (time_t)0, (uint32_t)0);
607 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
608 memcached_quit(memc
);
609 rc
= memcached_add(memc
, key
, strlen(key
),
610 value
, strlen(value
),
611 (time_t)0, (uint32_t)0);
613 /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */
616 test_true(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_STORED
);
620 test_true(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_DATA_EXISTS
);
627 ** There was a problem of leaking filedescriptors in the initial release
628 ** of MacOSX 10.5. This test case triggers the problem. On some Solaris
629 ** systems it seems that the kernel is slow on reclaiming the resources
630 ** because the connects starts to time out (the test doesn't do much
631 ** anyway, so just loop 10 iterations)
633 static test_return_t
add_wrapper(memcached_st
*memc
)
636 unsigned int max
= 10000;
644 for (x
= 0; x
< max
; x
++)
650 static test_return_t
replace_test(memcached_st
*memc
)
652 memcached_return_t rc
;
653 const char *key
= "foo";
654 const char *value
= "when we sanitize";
655 const char *original
= "first we insert some data";
657 rc
= memcached_set(memc
, key
, strlen(key
),
658 original
, strlen(original
),
659 (time_t)0, (uint32_t)0);
660 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
662 rc
= memcached_replace(memc
, key
, strlen(key
),
663 value
, strlen(value
),
664 (time_t)0, (uint32_t)0);
665 test_true(rc
== MEMCACHED_SUCCESS
);
670 static test_return_t
delete_test(memcached_st
*memc
)
672 memcached_return_t rc
;
673 const char *key
= "foo";
674 const char *value
= "when we sanitize";
676 rc
= memcached_set(memc
, key
, strlen(key
),
677 value
, strlen(value
),
678 (time_t)0, (uint32_t)0);
679 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
681 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
682 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
687 static test_return_t
flush_test(memcached_st
*memc
)
689 memcached_return_t rc
;
691 rc
= memcached_flush(memc
, 0);
692 test_true(rc
== MEMCACHED_SUCCESS
);
697 static memcached_return_t
server_function(const memcached_st
*ptr
__attribute__((unused
)),
698 memcached_server_st
*server
__attribute__((unused
)),
699 void *context
__attribute__((unused
)))
703 return MEMCACHED_SUCCESS
;
706 static test_return_t
memcached_server_cursor_test(memcached_st
*memc
)
709 strcpy(context
, "foo bad");
710 memcached_server_fn callbacks
[1];
712 callbacks
[0]= server_function
;
713 memcached_server_cursor(memc
, callbacks
, context
, 1);
717 static test_return_t
bad_key_test(memcached_st
*memc
)
719 memcached_return_t rc
;
720 const char *key
= "foo bad";
722 size_t string_length
;
724 memcached_st
*memc_clone
;
726 size_t max_keylen
= 0xffff;
728 // Just skip if we are in binary mode.
729 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
))
732 memc_clone
= memcached_clone(NULL
, memc
);
733 test_true(memc_clone
);
735 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
736 test_true(rc
== MEMCACHED_SUCCESS
);
738 /* All keys are valid in the binary protocol (except for length) */
739 if (memcached_behavior_get(memc_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 0)
741 string
= memcached_get(memc_clone
, key
, strlen(key
),
742 &string_length
, &flags
, &rc
);
743 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
744 test_true(string_length
== 0);
748 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
749 test_true(rc
== MEMCACHED_SUCCESS
);
750 string
= memcached_get(memc_clone
, key
, strlen(key
),
751 &string_length
, &flags
, &rc
);
752 test_true(rc
== MEMCACHED_NOTFOUND
);
753 test_true(string_length
== 0);
756 /* Test multi key for bad keys */
757 const char *keys
[] = { "GoodKey", "Bad Key", "NotMine" };
758 size_t key_lengths
[] = { 7, 7, 7 };
760 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
761 test_true(rc
== MEMCACHED_SUCCESS
);
763 rc
= memcached_mget(memc_clone
, keys
, key_lengths
, 3);
764 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
766 rc
= memcached_mget_by_key(memc_clone
, "foo daddy", 9, keys
, key_lengths
, 1);
767 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
771 /* The following test should be moved to the end of this function when the
772 memcached server is updated to allow max size length of the keys in the
775 rc
= memcached_callback_set(memc_clone
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
776 test_true(rc
== MEMCACHED_SUCCESS
);
778 char *longkey
= malloc(max_keylen
+ 1);
781 memset(longkey
, 'a', max_keylen
+ 1);
782 string
= memcached_get(memc_clone
, longkey
, max_keylen
,
783 &string_length
, &flags
, &rc
);
784 test_true(rc
== MEMCACHED_NOTFOUND
);
785 test_true(string_length
== 0);
788 string
= memcached_get(memc_clone
, longkey
, max_keylen
+ 1,
789 &string_length
, &flags
, &rc
);
790 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
791 test_true(string_length
== 0);
798 /* Make sure zero length keys are marked as bad */
800 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
801 test_true(rc
== MEMCACHED_SUCCESS
);
802 string
= memcached_get(memc_clone
, key
, 0,
803 &string_length
, &flags
, &rc
);
804 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
805 test_true(string_length
== 0);
808 memcached_free(memc_clone
);
813 #define READ_THROUGH_VALUE "set for me"
814 static memcached_return_t
read_through_trigger(memcached_st
*memc
__attribute__((unused
)),
815 char *key
__attribute__((unused
)),
816 size_t key_length
__attribute__((unused
)),
817 memcached_result_st
*result
)
820 return memcached_result_set_value(result
, READ_THROUGH_VALUE
, strlen(READ_THROUGH_VALUE
));
823 static test_return_t
read_through(memcached_st
*memc
)
825 memcached_return_t rc
;
826 const char *key
= "foo";
828 size_t string_length
;
830 memcached_trigger_key_fn cb
= (memcached_trigger_key_fn
)read_through_trigger
;
832 string
= memcached_get(memc
, key
, strlen(key
),
833 &string_length
, &flags
, &rc
);
835 test_true(rc
== MEMCACHED_NOTFOUND
);
836 test_false(string_length
);
839 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_GET_FAILURE
,
841 test_true(rc
== MEMCACHED_SUCCESS
);
843 string
= memcached_get(memc
, key
, strlen(key
),
844 &string_length
, &flags
, &rc
);
846 test_true(rc
== MEMCACHED_SUCCESS
);
847 test_true(string_length
== strlen(READ_THROUGH_VALUE
));
848 test_strcmp(READ_THROUGH_VALUE
, string
);
851 string
= memcached_get(memc
, key
, strlen(key
),
852 &string_length
, &flags
, &rc
);
854 test_true(rc
== MEMCACHED_SUCCESS
);
855 test_true(string_length
== strlen(READ_THROUGH_VALUE
));
856 test_true(!strcmp(READ_THROUGH_VALUE
, string
));
862 static memcached_return_t
delete_trigger(memcached_st
*ptr
__attribute__((unused
)),
864 size_t key_length
__attribute__((unused
)))
868 return MEMCACHED_SUCCESS
;
871 static test_return_t
delete_through(memcached_st
*memc
)
873 memcached_trigger_delete_key_fn callback
;
874 memcached_return_t rc
;
876 callback
= (memcached_trigger_delete_key_fn
)delete_trigger
;
878 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_DELETE_TRIGGER
, *(void**)&callback
);
879 test_true(rc
== MEMCACHED_SUCCESS
);
884 static test_return_t
get_test(memcached_st
*memc
)
886 memcached_return_t rc
;
887 const char *key
= "foo";
889 size_t string_length
;
892 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
893 test_true(rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_NOTFOUND
);
895 string
= memcached_get(memc
, key
, strlen(key
),
896 &string_length
, &flags
, &rc
);
898 test_true(rc
== MEMCACHED_NOTFOUND
);
899 test_false(string_length
);
905 static test_return_t
get_test2(memcached_st
*memc
)
907 memcached_return_t rc
;
908 const char *key
= "foo";
909 const char *value
= "when we sanitize";
911 size_t string_length
;
914 rc
= memcached_set(memc
, key
, strlen(key
),
915 value
, strlen(value
),
916 (time_t)0, (uint32_t)0);
917 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
919 string
= memcached_get(memc
, key
, strlen(key
),
920 &string_length
, &flags
, &rc
);
923 test_true(rc
== MEMCACHED_SUCCESS
);
924 test_true(string_length
== strlen(value
));
925 test_true(!memcmp(string
, value
, string_length
));
932 static test_return_t
set_test2(memcached_st
*memc
)
934 memcached_return_t rc
;
935 const char *key
= "foo";
936 const char *value
= "train in the brain";
937 size_t value_length
= strlen(value
);
940 for (x
= 0; x
< 10; x
++)
942 rc
= memcached_set(memc
, key
, strlen(key
),
944 (time_t)0, (uint32_t)0);
945 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
951 static test_return_t
set_test3(memcached_st
*memc
)
953 memcached_return_t rc
;
955 size_t value_length
= 8191;
958 value
= (char*)malloc(value_length
);
961 for (x
= 0; x
< value_length
; x
++)
962 value
[x
] = (char) (x
% 127);
964 /* The dump test relies on there being at least 32 items in memcached */
965 for (x
= 0; x
< 32; x
++)
969 sprintf(key
, "foo%u", x
);
971 rc
= memcached_set(memc
, key
, strlen(key
),
973 (time_t)0, (uint32_t)0);
974 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
982 static test_return_t
get_test3(memcached_st
*memc
)
984 memcached_return_t rc
;
985 const char *key
= "foo";
987 size_t value_length
= 8191;
989 size_t string_length
;
993 value
= (char*)malloc(value_length
);
996 for (x
= 0; x
< value_length
; x
++)
997 value
[x
] = (char) (x
% 127);
999 rc
= memcached_set(memc
, key
, strlen(key
),
1000 value
, value_length
,
1001 (time_t)0, (uint32_t)0);
1002 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1004 string
= memcached_get(memc
, key
, strlen(key
),
1005 &string_length
, &flags
, &rc
);
1007 test_true(rc
== MEMCACHED_SUCCESS
);
1009 test_true(string_length
== value_length
);
1010 test_true(!memcmp(string
, value
, string_length
));
1015 return TEST_SUCCESS
;
1018 static test_return_t
get_test4(memcached_st
*memc
)
1020 memcached_return_t rc
;
1021 const char *key
= "foo";
1023 size_t value_length
= 8191;
1025 size_t string_length
;
1029 value
= (char*)malloc(value_length
);
1032 for (x
= 0; x
< value_length
; x
++)
1033 value
[x
] = (char) (x
% 127);
1035 rc
= memcached_set(memc
, key
, strlen(key
),
1036 value
, value_length
,
1037 (time_t)0, (uint32_t)0);
1038 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1040 for (x
= 0; x
< 10; x
++)
1042 string
= memcached_get(memc
, key
, strlen(key
),
1043 &string_length
, &flags
, &rc
);
1045 test_true(rc
== MEMCACHED_SUCCESS
);
1047 test_true(string_length
== value_length
);
1048 test_true(!memcmp(string
, value
, string_length
));
1054 return TEST_SUCCESS
;
1058 * This test verifies that memcached_read_one_response doesn't try to
1059 * dereference a NIL-pointer if you issue a multi-get and don't read out all
1060 * responses before you execute a storage command.
1062 static test_return_t
get_test5(memcached_st
*memc
)
1065 ** Request the same key twice, to ensure that we hash to the same server
1066 ** (so that we have multiple response values queued up) ;-)
1068 const char *keys
[]= { "key", "key" };
1069 size_t lengths
[]= { 3, 3 };
1073 memcached_return_t rc
= memcached_set(memc
, keys
[0], lengths
[0],
1074 keys
[0], lengths
[0], 0, 0);
1075 test_true(rc
== MEMCACHED_SUCCESS
);
1076 rc
= memcached_mget(memc
, keys
, lengths
, 2);
1078 memcached_result_st results_obj
;
1079 memcached_result_st
*results
;
1080 results
=memcached_result_create(memc
, &results_obj
);
1082 results
=memcached_fetch_result(memc
, &results_obj
, &rc
);
1084 memcached_result_free(&results_obj
);
1086 /* Don't read out the second result, but issue a set instead.. */
1087 rc
= memcached_set(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0);
1088 test_true(rc
== MEMCACHED_SUCCESS
);
1090 char *val
= memcached_get_by_key(memc
, keys
[0], lengths
[0], "yek", 3,
1091 &rlen
, &flags
, &rc
);
1092 test_true(val
== NULL
);
1093 test_true(rc
== MEMCACHED_NOTFOUND
);
1094 val
= memcached_get(memc
, keys
[0], lengths
[0], &rlen
, &flags
, &rc
);
1095 test_true(val
!= NULL
);
1096 test_true(rc
== MEMCACHED_SUCCESS
);
1099 return TEST_SUCCESS
;
1102 static test_return_t
mget_end(memcached_st
*memc
)
1104 const char *keys
[]= { "foo", "foo2" };
1105 size_t lengths
[]= { 3, 4 };
1106 const char *values
[]= { "fjord", "41" };
1108 memcached_return_t rc
;
1111 for (int i
= 0; i
< 2; i
++)
1113 rc
= memcached_set(memc
, keys
[i
], lengths
[i
], values
[i
], strlen(values
[i
]),
1114 (time_t)0, (uint32_t)0);
1115 test_true(rc
== MEMCACHED_SUCCESS
);
1119 size_t string_length
;
1122 // retrieve both via mget
1123 rc
= memcached_mget(memc
, keys
, lengths
, 2);
1124 test_true(rc
== MEMCACHED_SUCCESS
);
1126 char key
[MEMCACHED_MAX_KEY
];
1129 // this should get both
1130 for (int i
= 0; i
< 2; i
++)
1132 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
,
1134 test_true(rc
== MEMCACHED_SUCCESS
);
1136 if (key_length
== 4)
1138 test_true(string_length
== strlen(values
[val
]));
1139 test_true(strncmp(values
[val
], string
, string_length
) == 0);
1143 // this should indicate end
1144 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1145 test_true(rc
== MEMCACHED_END
);
1148 rc
= memcached_mget(memc
, keys
, lengths
, 1);
1149 test_true(rc
== MEMCACHED_SUCCESS
);
1151 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1152 test_true(key_length
== lengths
[0]);
1153 test_true(strncmp(keys
[0], key
, key_length
) == 0);
1154 test_true(string_length
== strlen(values
[0]));
1155 test_true(strncmp(values
[0], string
, string_length
) == 0);
1156 test_true(rc
== MEMCACHED_SUCCESS
);
1159 // this should indicate end
1160 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1161 test_true(rc
== MEMCACHED_END
);
1163 return TEST_SUCCESS
;
1166 /* Do not copy the style of this code, I just access hosts to testthis function */
1167 static test_return_t
stats_servername_test(memcached_st
*memc
)
1169 memcached_return_t rc
;
1170 memcached_stat_st memc_stat
;
1171 memcached_server_instance_st
*instance
=
1172 memcached_server_instance_fetch(memc
, 0);
1174 rc
= memcached_stat_servername(&memc_stat
, NULL
,
1178 return TEST_SUCCESS
;
1181 static test_return_t
increment_test(memcached_st
*memc
)
1183 uint64_t new_number
;
1184 memcached_return_t rc
;
1185 const char *key
= "number";
1186 const char *value
= "0";
1188 rc
= memcached_set(memc
, key
, strlen(key
),
1189 value
, strlen(value
),
1190 (time_t)0, (uint32_t)0);
1191 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1193 rc
= memcached_increment(memc
, key
, strlen(key
),
1195 test_true(rc
== MEMCACHED_SUCCESS
);
1196 test_true(new_number
== 1);
1198 rc
= memcached_increment(memc
, key
, strlen(key
),
1200 test_true(rc
== MEMCACHED_SUCCESS
);
1201 test_true(new_number
== 2);
1203 return TEST_SUCCESS
;
1206 static test_return_t
increment_with_initial_test(memcached_st
*memc
)
1208 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1210 uint64_t new_number
;
1211 memcached_return_t rc
;
1212 const char *key
= "number";
1213 uint64_t initial
= 0;
1215 rc
= memcached_increment_with_initial(memc
, key
, strlen(key
),
1216 1, initial
, 0, &new_number
);
1217 test_true(rc
== MEMCACHED_SUCCESS
);
1218 test_true(new_number
== initial
);
1220 rc
= memcached_increment_with_initial(memc
, key
, strlen(key
),
1221 1, initial
, 0, &new_number
);
1222 test_true(rc
== MEMCACHED_SUCCESS
);
1223 test_true(new_number
== (initial
+ 1));
1225 return TEST_SUCCESS
;
1228 static test_return_t
decrement_test(memcached_st
*memc
)
1230 uint64_t new_number
;
1231 memcached_return_t rc
;
1232 const char *key
= "number";
1233 const char *value
= "3";
1235 rc
= memcached_set(memc
, key
, strlen(key
),
1236 value
, strlen(value
),
1237 (time_t)0, (uint32_t)0);
1238 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1240 rc
= memcached_decrement(memc
, key
, strlen(key
),
1242 test_true(rc
== MEMCACHED_SUCCESS
);
1243 test_true(new_number
== 2);
1245 rc
= memcached_decrement(memc
, key
, strlen(key
),
1247 test_true(rc
== MEMCACHED_SUCCESS
);
1248 test_true(new_number
== 1);
1250 return TEST_SUCCESS
;
1253 static test_return_t
decrement_with_initial_test(memcached_st
*memc
)
1255 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1257 uint64_t new_number
;
1258 memcached_return_t rc
;
1259 const char *key
= "number";
1260 uint64_t initial
= 3;
1262 rc
= memcached_decrement_with_initial(memc
, key
, strlen(key
),
1263 1, initial
, 0, &new_number
);
1264 test_true(rc
== MEMCACHED_SUCCESS
);
1265 test_true(new_number
== initial
);
1267 rc
= memcached_decrement_with_initial(memc
, key
, strlen(key
),
1268 1, initial
, 0, &new_number
);
1269 test_true(rc
== MEMCACHED_SUCCESS
);
1270 test_true(new_number
== (initial
- 1));
1272 return TEST_SUCCESS
;
1275 static test_return_t
increment_by_key_test(memcached_st
*memc
)
1277 uint64_t new_number
;
1278 memcached_return_t rc
;
1279 const char *master_key
= "foo";
1280 const char *key
= "number";
1281 const char *value
= "0";
1283 rc
= memcached_set_by_key(memc
, master_key
, strlen(master_key
),
1285 value
, strlen(value
),
1286 (time_t)0, (uint32_t)0);
1287 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1289 rc
= memcached_increment_by_key(memc
, master_key
, strlen(master_key
), key
, strlen(key
),
1291 test_true(rc
== MEMCACHED_SUCCESS
);
1292 test_true(new_number
== 1);
1294 rc
= memcached_increment_by_key(memc
, master_key
, strlen(master_key
), key
, strlen(key
),
1296 test_true(rc
== MEMCACHED_SUCCESS
);
1297 test_true(new_number
== 2);
1299 return TEST_SUCCESS
;
1302 static test_return_t
increment_with_initial_by_key_test(memcached_st
*memc
)
1304 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1306 uint64_t new_number
;
1307 memcached_return_t rc
;
1308 const char *master_key
= "foo";
1309 const char *key
= "number";
1310 uint64_t initial
= 0;
1312 rc
= memcached_increment_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1314 1, initial
, 0, &new_number
);
1315 test_true(rc
== MEMCACHED_SUCCESS
);
1316 test_true(new_number
== initial
);
1318 rc
= memcached_increment_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1320 1, initial
, 0, &new_number
);
1321 test_true(rc
== MEMCACHED_SUCCESS
);
1322 test_true(new_number
== (initial
+ 1));
1324 return TEST_SUCCESS
;
1327 static test_return_t
decrement_by_key_test(memcached_st
*memc
)
1329 uint64_t new_number
;
1330 memcached_return_t rc
;
1331 const char *master_key
= "foo";
1332 const char *key
= "number";
1333 const char *value
= "3";
1335 rc
= memcached_set_by_key(memc
, master_key
, strlen(master_key
),
1337 value
, strlen(value
),
1338 (time_t)0, (uint32_t)0);
1339 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1341 rc
= memcached_decrement_by_key(memc
, master_key
, strlen(master_key
),
1344 test_true(rc
== MEMCACHED_SUCCESS
);
1345 test_true(new_number
== 2);
1347 rc
= memcached_decrement_by_key(memc
, master_key
, strlen(master_key
),
1350 test_true(rc
== MEMCACHED_SUCCESS
);
1351 test_true(new_number
== 1);
1353 return TEST_SUCCESS
;
1356 static test_return_t
decrement_with_initial_by_key_test(memcached_st
*memc
)
1358 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1360 uint64_t new_number
;
1361 memcached_return_t rc
;
1362 const char *master_key
= "foo";
1363 const char *key
= "number";
1364 uint64_t initial
= 3;
1366 rc
= memcached_decrement_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1368 1, initial
, 0, &new_number
);
1369 test_true(rc
== MEMCACHED_SUCCESS
);
1370 test_true(new_number
== initial
);
1372 rc
= memcached_decrement_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1374 1, initial
, 0, &new_number
);
1375 test_true(rc
== MEMCACHED_SUCCESS
);
1376 test_true(new_number
== (initial
- 1));
1378 return TEST_SUCCESS
;
1381 static test_return_t
quit_test(memcached_st
*memc
)
1383 memcached_return_t rc
;
1384 const char *key
= "fudge";
1385 const char *value
= "sanford and sun";
1387 rc
= memcached_set(memc
, key
, strlen(key
),
1388 value
, strlen(value
),
1389 (time_t)10, (uint32_t)3);
1390 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1391 memcached_quit(memc
);
1393 rc
= memcached_set(memc
, key
, strlen(key
),
1394 value
, strlen(value
),
1395 (time_t)50, (uint32_t)9);
1396 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1398 return TEST_SUCCESS
;
1401 static test_return_t
mget_result_test(memcached_st
*memc
)
1403 memcached_return_t rc
;
1404 const char *keys
[]= {"fudge", "son", "food"};
1405 size_t key_length
[]= {5, 3, 4};
1408 memcached_result_st results_obj
;
1409 memcached_result_st
*results
;
1411 results
= memcached_result_create(memc
, &results_obj
);
1413 test_true(&results_obj
== results
);
1415 /* We need to empty the server before continueing test */
1416 rc
= memcached_flush(memc
, 0);
1417 test_true(rc
== MEMCACHED_SUCCESS
);
1419 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1420 test_true(rc
== MEMCACHED_SUCCESS
);
1422 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1427 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1428 test_true(!results
);
1429 test_true(rc
== MEMCACHED_END
);
1431 for (x
= 0; x
< 3; x
++)
1433 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1434 keys
[x
], key_length
[x
],
1435 (time_t)50, (uint32_t)9);
1436 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1439 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1440 test_true(rc
== MEMCACHED_SUCCESS
);
1442 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1445 test_true(&results_obj
== results
);
1446 test_true(rc
== MEMCACHED_SUCCESS
);
1447 test_true(memcached_result_key_length(results
) == memcached_result_length(results
));
1448 test_true(!memcmp(memcached_result_key_value(results
),
1449 memcached_result_value(results
),
1450 memcached_result_length(results
)));
1453 memcached_result_free(&results_obj
);
1455 return TEST_SUCCESS
;
1458 static test_return_t
mget_result_alloc_test(memcached_st
*memc
)
1460 memcached_return_t rc
;
1461 const char *keys
[]= {"fudge", "son", "food"};
1462 size_t key_length
[]= {5, 3, 4};
1465 memcached_result_st
*results
;
1467 /* We need to empty the server before continueing test */
1468 rc
= memcached_flush(memc
, 0);
1469 test_true(rc
== MEMCACHED_SUCCESS
);
1471 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1472 test_true(rc
== MEMCACHED_SUCCESS
);
1474 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)) != NULL
)
1478 test_true(!results
);
1479 test_true(rc
== MEMCACHED_END
);
1481 for (x
= 0; x
< 3; x
++)
1483 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1484 keys
[x
], key_length
[x
],
1485 (time_t)50, (uint32_t)9);
1486 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1489 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1490 test_true(rc
== MEMCACHED_SUCCESS
);
1493 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1496 test_true(rc
== MEMCACHED_SUCCESS
);
1497 test_true(memcached_result_key_length(results
) == memcached_result_length(results
));
1498 test_true(!memcmp(memcached_result_key_value(results
),
1499 memcached_result_value(results
),
1500 memcached_result_length(results
)));
1501 memcached_result_free(results
);
1505 return TEST_SUCCESS
;
1508 /* Count the results */
1509 static memcached_return_t
callback_counter(const memcached_st
*ptr
__attribute__((unused
)),
1510 memcached_result_st
*result
__attribute__((unused
)),
1513 size_t *counter
= (size_t *)context
;
1515 *counter
= *counter
+ 1;
1517 return MEMCACHED_SUCCESS
;
1520 static test_return_t
mget_result_function(memcached_st
*memc
)
1522 memcached_return_t rc
;
1523 const char *keys
[]= {"fudge", "son", "food"};
1524 size_t key_length
[]= {5, 3, 4};
1527 memcached_execute_fn callbacks
[1];
1529 /* We need to empty the server before continueing test */
1530 rc
= memcached_flush(memc
, 0);
1531 for (x
= 0; x
< 3; x
++)
1533 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1534 keys
[x
], key_length
[x
],
1535 (time_t)50, (uint32_t)9);
1536 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1539 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1540 test_true(rc
== MEMCACHED_SUCCESS
);
1542 callbacks
[0]= &callback_counter
;
1544 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
1546 test_true(counter
== 3);
1548 return TEST_SUCCESS
;
1551 static test_return_t
mget_test(memcached_st
*memc
)
1553 memcached_return_t rc
;
1554 const char *keys
[]= {"fudge", "son", "food"};
1555 size_t key_length
[]= {5, 3, 4};
1559 char return_key
[MEMCACHED_MAX_KEY
];
1560 size_t return_key_length
;
1562 size_t return_value_length
;
1564 /* We need to empty the server before continueing test */
1565 rc
= memcached_flush(memc
, 0);
1566 test_true(rc
== MEMCACHED_SUCCESS
);
1568 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1569 test_true(rc
== MEMCACHED_SUCCESS
);
1571 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1572 &return_value_length
, &flags
, &rc
)) != NULL
)
1574 test_true(return_value
);
1576 test_true(!return_value
);
1577 test_true(return_value_length
== 0);
1578 test_true(rc
== MEMCACHED_END
);
1580 for (x
= 0; x
< 3; x
++)
1582 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1583 keys
[x
], key_length
[x
],
1584 (time_t)50, (uint32_t)9);
1585 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1588 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1589 test_true(rc
== MEMCACHED_SUCCESS
);
1592 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1593 &return_value_length
, &flags
, &rc
)))
1595 test_true(return_value
);
1596 test_true(rc
== MEMCACHED_SUCCESS
);
1597 test_true(return_key_length
== return_value_length
);
1598 test_true(!memcmp(return_value
, return_key
, return_value_length
));
1603 return TEST_SUCCESS
;
1606 static test_return_t
mget_execute(memcached_st
*memc
)
1610 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1614 * I only want to hit _one_ server so I know the number of requests I'm
1615 * sending in the pipeline.
1617 uint32_t number_of_hosts
= memc
->number_of_hosts
;
1618 memc
->number_of_hosts
= 1;
1620 size_t max_keys
= binary
? 20480 : 1;
1623 char **keys
= calloc(max_keys
, sizeof(char*));
1624 size_t *key_length
=calloc(max_keys
, sizeof(size_t));
1626 /* First add all of the items.. */
1627 char blob
[1024] = {0};
1628 memcached_return_t rc
;
1629 for (size_t x
= 0; x
< max_keys
; ++x
)
1633 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%zu", x
);
1635 test_true(keys
[x
] != NULL
);
1636 rc
= memcached_add(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
1637 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1640 /* Try to get all of them with a large multiget */
1642 memcached_execute_fn callbacks
[1]= { [0]= &callback_counter
};
1643 rc
= memcached_mget_execute(memc
, (const char**)keys
, key_length
,
1644 max_keys
, callbacks
, &counter
, 1);
1648 test_true(rc
== MEMCACHED_SUCCESS
);
1650 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
1651 test_true(rc
== MEMCACHED_END
);
1653 /* Verify that we got all of the items */
1654 test_true(counter
== max_keys
);
1658 test_true(rc
== MEMCACHED_NOT_SUPPORTED
);
1659 test_true(counter
== 0);
1662 /* Release all allocated resources */
1663 for (size_t x
= 0; x
< max_keys
; ++x
)
1670 memc
->number_of_hosts
= number_of_hosts
;
1671 return TEST_SUCCESS
;
1674 static test_return_t
get_stats_keys(memcached_st
*memc
)
1678 memcached_stat_st memc_stat
;
1679 memcached_return_t rc
;
1681 stat_list
= memcached_stat_get_keys(memc
, &memc_stat
, &rc
);
1682 test_true(rc
== MEMCACHED_SUCCESS
);
1683 for (ptr
= stat_list
; *ptr
; ptr
++)
1688 return TEST_SUCCESS
;
1691 static test_return_t
version_string_test(memcached_st
*memc
__attribute__((unused
)))
1693 const char *version_string
;
1695 version_string
= memcached_lib_version();
1697 test_true(!strcmp(version_string
, LIBMEMCACHED_VERSION_STRING
));
1699 return TEST_SUCCESS
;
1702 static test_return_t
get_stats(memcached_st
*memc
)
1706 memcached_return_t rc
;
1707 memcached_stat_st
*memc_stat
;
1709 memc_stat
= memcached_stat(memc
, NULL
, &rc
);
1710 test_true(rc
== MEMCACHED_SUCCESS
);
1712 test_true(rc
== MEMCACHED_SUCCESS
);
1713 test_true(memc_stat
);
1715 for (uint32_t x
= 0; x
< memcached_server_count(memc
); x
++)
1717 stat_list
= memcached_stat_get_keys(memc
, memc_stat
+x
, &rc
);
1718 test_true(rc
== MEMCACHED_SUCCESS
);
1719 for (ptr
= stat_list
; *ptr
; ptr
++);
1724 memcached_stat_free(NULL
, memc_stat
);
1726 return TEST_SUCCESS
;
1729 static test_return_t
add_host_test(memcached_st
*memc
)
1732 memcached_server_st
*servers
;
1733 memcached_return_t rc
;
1734 char servername
[]= "0.example.com";
1736 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
1738 test_true(1 == memcached_server_list_count(servers
));
1740 for (x
= 2; x
< 20; x
++)
1742 char buffer
[SMALL_STRING_LEN
];
1744 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
1745 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
1747 test_true(rc
== MEMCACHED_SUCCESS
);
1748 test_true(x
== memcached_server_list_count(servers
));
1751 rc
= memcached_server_push(memc
, servers
);
1752 test_true(rc
== MEMCACHED_SUCCESS
);
1753 rc
= memcached_server_push(memc
, servers
);
1754 test_true(rc
== MEMCACHED_SUCCESS
);
1756 memcached_server_list_free(servers
);
1758 return TEST_SUCCESS
;
1761 static memcached_return_t
clone_test_callback(memcached_st
*parent
__attribute__((unused
)), memcached_st
*memc_clone
__attribute__((unused
)))
1763 return MEMCACHED_SUCCESS
;
1766 static memcached_return_t
cleanup_test_callback(memcached_st
*ptr
__attribute__((unused
)))
1768 return MEMCACHED_SUCCESS
;
1771 static test_return_t
callback_test(memcached_st
*memc
)
1773 /* Test User Data */
1777 memcached_return_t rc
;
1779 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_USER_DATA
, &x
);
1780 test_true(rc
== MEMCACHED_SUCCESS
);
1781 test_ptr
= (int *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_USER_DATA
, &rc
);
1782 test_true(*test_ptr
== x
);
1785 /* Test Clone Callback */
1787 memcached_clone_fn clone_cb
= (memcached_clone_fn
)clone_test_callback
;
1788 void *clone_cb_ptr
= *(void **)&clone_cb
;
1789 void *temp_function
= NULL
;
1790 memcached_return_t rc
;
1792 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
,
1794 test_true(rc
== MEMCACHED_SUCCESS
);
1795 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1796 test_true(temp_function
== clone_cb_ptr
);
1799 /* Test Cleanup Callback */
1801 memcached_cleanup_fn cleanup_cb
=
1802 (memcached_cleanup_fn
)cleanup_test_callback
;
1803 void *cleanup_cb_ptr
= *(void **)&cleanup_cb
;
1804 void *temp_function
= NULL
;
1805 memcached_return_t rc
;
1807 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
,
1809 test_true(rc
== MEMCACHED_SUCCESS
);
1810 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1811 test_true(temp_function
== cleanup_cb_ptr
);
1814 return TEST_SUCCESS
;
1817 /* We don't test the behavior itself, we test the switches */
1818 static test_return_t
behavior_test(memcached_st
*memc
)
1823 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1824 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1825 test_true(value
== 1);
1827 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1828 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1829 test_true(value
== 1);
1831 set
= MEMCACHED_HASH_MD5
;
1832 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1833 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1834 test_true(value
== MEMCACHED_HASH_MD5
);
1838 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1839 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1840 test_true(value
== 0);
1842 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1843 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1844 test_true(value
== 0);
1846 set
= MEMCACHED_HASH_DEFAULT
;
1847 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1848 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1849 test_true(value
== MEMCACHED_HASH_DEFAULT
);
1851 set
= MEMCACHED_HASH_CRC
;
1852 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1853 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1854 test_true(value
== MEMCACHED_HASH_CRC
);
1856 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1857 test_true(value
> 0);
1859 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1860 test_true(value
> 0);
1862 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
);
1863 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, value
+ 1);
1864 test_true((value
+ 1) == memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
));
1866 return TEST_SUCCESS
;
1869 static test_return_t
MEMCACHED_BEHAVIOR_CORK_test(memcached_st
*memc
)
1871 memcached_return_t rc
;
1875 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CORK
, set
);
1876 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_NOT_SUPPORTED
);
1878 value
= (bool)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_CORK
);
1880 if (rc
== MEMCACHED_SUCCESS
)
1882 test_true((bool)value
== set
);
1886 test_false((bool)value
== set
);
1889 return TEST_SUCCESS
;
1892 static test_return_t
fetch_all_results(memcached_st
*memc
)
1894 memcached_return_t rc
= MEMCACHED_SUCCESS
;
1895 char return_key
[MEMCACHED_MAX_KEY
];
1896 size_t return_key_length
;
1898 size_t return_value_length
;
1901 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1902 &return_value_length
, &flags
, &rc
)))
1904 test_true(return_value
);
1905 test_true(rc
== MEMCACHED_SUCCESS
);
1909 return ((rc
== MEMCACHED_END
) || (rc
== MEMCACHED_SUCCESS
)) ? TEST_SUCCESS
: TEST_FAILURE
;
1912 /* Test case provided by Cal Haldenbrand */
1913 static test_return_t
user_supplied_bug1(memcached_st
*memc
)
1915 unsigned int setter
= 1;
1917 unsigned long long total
= 0;
1920 char randomstuff
[6 * 1024];
1921 memcached_return_t rc
;
1923 memset(randomstuff
, 0, 6 * 1024);
1925 /* We just keep looking at the same values over and over */
1928 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1929 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1933 for (uint32_t x
= 0 ; total
< 20 * 1024576 ; x
++ )
1937 size
= (uint32_t)(rand() % ( 5 * 1024 ) ) + 400;
1938 memset(randomstuff
, 0, 6 * 1024);
1939 test_true(size
< 6 * 1024); /* Being safe here */
1941 for (j
= 0 ; j
< size
;j
++)
1942 randomstuff
[j
] = (signed char) ((rand() % 26) + 97);
1945 snprintf(key
, sizeof(key
), "%u", x
);
1946 rc
= memcached_set(memc
, key
, strlen(key
),
1947 randomstuff
, strlen(randomstuff
), 10, 0);
1948 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1949 /* If we fail, lets try again */
1950 if (rc
!= MEMCACHED_SUCCESS
&& rc
!= MEMCACHED_BUFFERED
)
1951 rc
= memcached_set(memc
, key
, strlen(key
),
1952 randomstuff
, strlen(randomstuff
), 10, 0);
1953 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1956 return TEST_SUCCESS
;
1959 /* Test case provided by Cal Haldenbrand */
1960 static test_return_t
user_supplied_bug2(memcached_st
*memc
)
1962 unsigned int setter
;
1966 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1967 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1969 setter
= 20 * 1024576;
1970 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1971 setter
= 20 * 1024576;
1972 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1973 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1974 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1976 for (x
= 0, errors
= 0; total
< 20 * 1024576 ; x
++)
1979 for (uint32_t x
= 0, errors
= 0; total
< 24576 ; x
++)
1981 memcached_return_t rc
= MEMCACHED_SUCCESS
;
1982 char buffer
[SMALL_STRING_LEN
];
1987 memset(buffer
, 0, SMALL_STRING_LEN
);
1989 snprintf(buffer
, sizeof(buffer
), "%u", x
);
1990 getval
= memcached_get(memc
, buffer
, strlen(buffer
),
1991 &val_len
, &flags
, &rc
);
1992 if (rc
!= MEMCACHED_SUCCESS
)
1994 if (rc
== MEMCACHED_NOTFOUND
)
2008 return TEST_SUCCESS
;
2011 /* Do a large mget() over all the keys we think exist */
2012 #define KEY_COUNT 3000 // * 1024576
2013 static test_return_t
user_supplied_bug3(memcached_st
*memc
)
2015 memcached_return_t rc
;
2016 unsigned int setter
;
2019 size_t key_lengths
[KEY_COUNT
];
2022 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
2023 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2025 setter
= 20 * 1024576;
2026 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
2027 setter
= 20 * 1024576;
2028 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
2029 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
2030 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
2033 keys
= calloc(KEY_COUNT
, sizeof(char *));
2035 for (x
= 0; x
< KEY_COUNT
; x
++)
2039 snprintf(buffer
, 30, "%u", x
);
2040 keys
[x
]= strdup(buffer
);
2041 key_lengths
[x
]= strlen(keys
[x
]);
2044 rc
= memcached_mget(memc
, (const char **)keys
, key_lengths
, KEY_COUNT
);
2045 test_true(rc
== MEMCACHED_SUCCESS
);
2047 test_true(fetch_all_results(memc
) == TEST_SUCCESS
);
2049 for (x
= 0; x
< KEY_COUNT
; x
++)
2053 return TEST_SUCCESS
;
2056 /* Make sure we behave properly if server list has no values */
2057 static test_return_t
user_supplied_bug4(memcached_st
*memc
)
2059 memcached_return_t rc
;
2060 const char *keys
[]= {"fudge", "son", "food"};
2061 size_t key_length
[]= {5, 3, 4};
2064 char return_key
[MEMCACHED_MAX_KEY
];
2065 size_t return_key_length
;
2067 size_t return_value_length
;
2069 /* Here we free everything before running a bunch of mget tests */
2070 memcached_servers_reset(memc
);
2073 /* We need to empty the server before continueing test */
2074 rc
= memcached_flush(memc
, 0);
2075 test_true(rc
== MEMCACHED_NO_SERVERS
);
2077 rc
= memcached_mget(memc
, keys
, key_length
, 3);
2078 test_true(rc
== MEMCACHED_NO_SERVERS
);
2080 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2081 &return_value_length
, &flags
, &rc
)) != NULL
)
2083 test_true(return_value
);
2085 test_true(!return_value
);
2086 test_true(return_value_length
== 0);
2087 test_true(rc
== MEMCACHED_NO_SERVERS
);
2089 for (x
= 0; x
< 3; x
++)
2091 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2092 keys
[x
], key_length
[x
],
2093 (time_t)50, (uint32_t)9);
2094 test_true(rc
== MEMCACHED_NO_SERVERS
);
2097 rc
= memcached_mget(memc
, keys
, key_length
, 3);
2098 test_true(rc
== MEMCACHED_NO_SERVERS
);
2101 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2102 &return_value_length
, &flags
, &rc
)))
2104 test_true(return_value
);
2105 test_true(rc
== MEMCACHED_SUCCESS
);
2106 test_true(return_key_length
== return_value_length
);
2107 test_true(!memcmp(return_value
, return_key
, return_value_length
));
2112 return TEST_SUCCESS
;
2115 #define VALUE_SIZE_BUG5 1048064
2116 static test_return_t
user_supplied_bug5(memcached_st
*memc
)
2118 memcached_return_t rc
;
2119 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
2120 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
2121 char return_key
[MEMCACHED_MAX_KEY
];
2122 size_t return_key_length
;
2124 size_t value_length
;
2128 char insert_data
[VALUE_SIZE_BUG5
];
2130 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2131 insert_data
[x
]= (signed char)rand();
2133 memcached_flush(memc
, 0);
2134 value
= memcached_get(memc
, keys
[0], key_length
[0],
2135 &value_length
, &flags
, &rc
);
2136 test_true(value
== NULL
);
2137 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2140 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2141 &value_length
, &flags
, &rc
)))
2143 test_true(count
== 0);
2145 for (x
= 0; x
< 4; x
++)
2147 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2148 insert_data
, VALUE_SIZE_BUG5
,
2149 (time_t)0, (uint32_t)0);
2150 test_true(rc
== MEMCACHED_SUCCESS
);
2153 for (x
= 0; x
< 10; x
++)
2155 value
= memcached_get(memc
, keys
[0], key_length
[0],
2156 &value_length
, &flags
, &rc
);
2160 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2162 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2163 &value_length
, &flags
, &rc
)))
2168 test_true(count
== 4);
2171 return TEST_SUCCESS
;
2174 static test_return_t
user_supplied_bug6(memcached_st
*memc
)
2176 memcached_return_t rc
;
2177 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
2178 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
2179 char return_key
[MEMCACHED_MAX_KEY
];
2180 size_t return_key_length
;
2182 size_t value_length
;
2186 char insert_data
[VALUE_SIZE_BUG5
];
2188 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2189 insert_data
[x
]= (signed char)rand();
2191 memcached_flush(memc
, 0);
2192 value
= memcached_get(memc
, keys
[0], key_length
[0],
2193 &value_length
, &flags
, &rc
);
2194 test_true(value
== NULL
);
2195 test_true(rc
== MEMCACHED_NOTFOUND
);
2196 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2197 test_true(rc
== MEMCACHED_SUCCESS
);
2200 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2201 &value_length
, &flags
, &rc
)))
2203 test_true(count
== 0);
2204 test_true(rc
== MEMCACHED_END
);
2206 for (x
= 0; x
< 4; x
++)
2208 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2209 insert_data
, VALUE_SIZE_BUG5
,
2210 (time_t)0, (uint32_t)0);
2211 test_true(rc
== MEMCACHED_SUCCESS
);
2214 for (x
= 0; x
< 2; x
++)
2216 value
= memcached_get(memc
, keys
[0], key_length
[0],
2217 &value_length
, &flags
, &rc
);
2221 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2222 test_true(rc
== MEMCACHED_SUCCESS
);
2224 /* We test for purge of partial complete fetches */
2225 for (count
= 3; count
; count
--)
2227 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2228 &value_length
, &flags
, &rc
);
2229 test_true(rc
== MEMCACHED_SUCCESS
);
2230 test_true(!(memcmp(value
, insert_data
, value_length
)));
2231 test_true(value_length
);
2236 return TEST_SUCCESS
;
2239 static test_return_t
user_supplied_bug8(memcached_st
*memc
__attribute__((unused
)))
2241 memcached_return_t rc
;
2243 memcached_st
*memc_clone
;
2245 memcached_server_st
*servers
;
2246 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";
2248 servers
= memcached_servers_parse(server_list
);
2251 mine
= memcached_create(NULL
);
2252 rc
= memcached_server_push(mine
, servers
);
2253 test_true(rc
== MEMCACHED_SUCCESS
);
2254 memcached_server_list_free(servers
);
2257 memc_clone
= memcached_clone(NULL
, mine
);
2259 memcached_quit(mine
);
2260 memcached_quit(memc_clone
);
2263 memcached_free(mine
);
2264 memcached_free(memc_clone
);
2266 return TEST_SUCCESS
;
2269 /* Test flag store/retrieve */
2270 static test_return_t
user_supplied_bug7(memcached_st
*memc
)
2272 memcached_return_t rc
;
2273 const char *keys
= "036790384900";
2274 size_t key_length
= strlen(keys
);
2275 char return_key
[MEMCACHED_MAX_KEY
];
2276 size_t return_key_length
;
2278 size_t value_length
;
2281 char insert_data
[VALUE_SIZE_BUG5
];
2283 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2284 insert_data
[x
]= (signed char)rand();
2286 memcached_flush(memc
, 0);
2289 rc
= memcached_set(memc
, keys
, key_length
,
2290 insert_data
, VALUE_SIZE_BUG5
,
2292 test_true(rc
== MEMCACHED_SUCCESS
);
2295 value
= memcached_get(memc
, keys
, key_length
,
2296 &value_length
, &flags
, &rc
);
2297 test_true(flags
== 245);
2301 rc
= memcached_mget(memc
, &keys
, &key_length
, 1);
2304 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2305 &value_length
, &flags
, &rc
);
2306 test_true(flags
== 245);
2311 return TEST_SUCCESS
;
2314 static test_return_t
user_supplied_bug9(memcached_st
*memc
)
2316 memcached_return_t rc
;
2317 const char *keys
[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
2318 size_t key_length
[3];
2323 char return_key
[MEMCACHED_MAX_KEY
];
2324 size_t return_key_length
;
2326 size_t return_value_length
;
2329 key_length
[0]= strlen("UDATA:edevil@sapo.pt");
2330 key_length
[1]= strlen("fudge&*@#");
2331 key_length
[2]= strlen("for^#@&$not");
2334 for (x
= 0; x
< 3; x
++)
2336 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2337 keys
[x
], key_length
[x
],
2338 (time_t)50, (uint32_t)9);
2339 test_true(rc
== MEMCACHED_SUCCESS
);
2342 rc
= memcached_mget(memc
, keys
, key_length
, 3);
2343 test_true(rc
== MEMCACHED_SUCCESS
);
2345 /* We need to empty the server before continueing test */
2346 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2347 &return_value_length
, &flags
, &rc
)) != NULL
)
2349 test_true(return_value
);
2353 test_true(count
== 3);
2355 return TEST_SUCCESS
;
2358 /* We are testing with aggressive timeout to get failures */
2359 static test_return_t
user_supplied_bug10(memcached_st
*memc
)
2361 const char *key
= "foo";
2363 size_t value_length
= 512;
2366 memcached_return_t rc
;
2367 unsigned int set
= 1;
2368 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2371 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2372 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2374 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
,
2377 value
= (char*)malloc(value_length
* sizeof(char));
2379 for (x
= 0; x
< value_length
; x
++)
2380 value
[x
]= (char) (x
% 127);
2382 for (x
= 1; x
<= 100000; ++x
)
2384 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2386 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_WRITE_FAILURE
||
2387 rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_TIMEOUT
);
2389 if (rc
== MEMCACHED_WRITE_FAILURE
|| rc
== MEMCACHED_TIMEOUT
)
2394 memcached_free(mclone
);
2396 return TEST_SUCCESS
;
2400 We are looking failures in the async protocol
2402 static test_return_t
user_supplied_bug11(memcached_st
*memc
)
2404 const char *key
= "foo";
2406 size_t value_length
= 512;
2409 memcached_return_t rc
;
2410 unsigned int set
= 1;
2412 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2414 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2415 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2417 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
,
2420 timeout
= (int32_t)memcached_behavior_get(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
2422 test_true(timeout
== -1);
2424 value
= (char*)malloc(value_length
* sizeof(char));
2426 for (x
= 0; x
< value_length
; x
++)
2427 value
[x
]= (char) (x
% 127);
2429 for (x
= 1; x
<= 100000; ++x
)
2431 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2435 memcached_free(mclone
);
2437 return TEST_SUCCESS
;
2441 Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
2443 static test_return_t
user_supplied_bug12(memcached_st
*memc
)
2445 memcached_return_t rc
;
2447 size_t value_length
;
2449 uint64_t number_value
;
2451 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2452 &value_length
, &flags
, &rc
);
2453 test_true(value
== NULL
);
2454 test_true(rc
== MEMCACHED_NOTFOUND
);
2456 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2459 test_true(value
== NULL
);
2460 /* The binary protocol will set the key if it doesn't exist */
2461 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1)
2463 test_true(rc
== MEMCACHED_SUCCESS
);
2467 test_true(rc
== MEMCACHED_NOTFOUND
);
2470 rc
= memcached_set(memc
, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
2472 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2473 &value_length
, &flags
, &rc
);
2475 test_true(rc
== MEMCACHED_SUCCESS
);
2478 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2480 test_true(number_value
== 2);
2481 test_true(rc
== MEMCACHED_SUCCESS
);
2483 return TEST_SUCCESS
;
2487 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2488 set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
2490 static test_return_t
user_supplied_bug13(memcached_st
*memc
)
2492 char key
[] = "key34567890";
2494 memcached_return_t rc
;
2495 size_t overflowSize
;
2497 char commandFirst
[]= "set key34567890 0 0 ";
2498 char commandLast
[] = " \r\n"; /* first line of command sent to server */
2499 size_t commandLength
;
2502 commandLength
= strlen(commandFirst
) + strlen(commandLast
) + 4; /* 4 is number of characters in size, probably 8196 */
2504 overflowSize
= MEMCACHED_MAX_BUFFER
- commandLength
;
2506 for (testSize
= overflowSize
- 1; testSize
< overflowSize
+ 1; testSize
++)
2508 overflow
= malloc(testSize
);
2509 test_true(overflow
!= NULL
);
2511 memset(overflow
, 'x', testSize
);
2512 rc
= memcached_set(memc
, key
, strlen(key
),
2513 overflow
, testSize
, 0, 0);
2514 test_true(rc
== MEMCACHED_SUCCESS
);
2518 return TEST_SUCCESS
;
2523 Test values of many different sizes
2524 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2525 set key34567890 0 0 8169 \r\n
2526 is sent followed by buffer of size 8169, followed by 8169
2528 static test_return_t
user_supplied_bug14(memcached_st
*memc
)
2531 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2532 memcached_return_t rc
;
2533 const char *key
= "foo";
2535 size_t value_length
= 18000;
2537 size_t string_length
;
2540 size_t current_length
;
2542 value
= (char*)malloc(value_length
);
2545 for (x
= 0; x
< value_length
; x
++)
2546 value
[x
] = (char) (x
% 127);
2548 for (current_length
= 0; current_length
< value_length
; current_length
++)
2550 rc
= memcached_set(memc
, key
, strlen(key
),
2551 value
, current_length
,
2552 (time_t)0, (uint32_t)0);
2553 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
2555 string
= memcached_get(memc
, key
, strlen(key
),
2556 &string_length
, &flags
, &rc
);
2558 test_true(rc
== MEMCACHED_SUCCESS
);
2559 test_true(string_length
== current_length
);
2560 test_true(!memcmp(string
, value
, string_length
));
2567 return TEST_SUCCESS
;
2571 Look for zero length value problems
2573 static test_return_t
user_supplied_bug15(memcached_st
*memc
)
2576 memcached_return_t rc
;
2577 const char *key
= "mykey";
2582 for (x
= 0; x
< 2; x
++)
2584 rc
= memcached_set(memc
, key
, strlen(key
),
2586 (time_t)0, (uint32_t)0);
2588 test_true(rc
== MEMCACHED_SUCCESS
);
2590 value
= memcached_get(memc
, key
, strlen(key
),
2591 &length
, &flags
, &rc
);
2593 test_true(rc
== MEMCACHED_SUCCESS
);
2594 test_true(value
== NULL
);
2595 test_true(length
== 0);
2596 test_true(flags
== 0);
2598 value
= memcached_get(memc
, key
, strlen(key
),
2599 &length
, &flags
, &rc
);
2601 test_true(rc
== MEMCACHED_SUCCESS
);
2602 test_true(value
== NULL
);
2603 test_true(length
== 0);
2604 test_true(flags
== 0);
2607 return TEST_SUCCESS
;
2610 /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
2611 static test_return_t
user_supplied_bug16(memcached_st
*memc
)
2613 memcached_return_t rc
;
2614 const char *key
= "mykey";
2619 rc
= memcached_set(memc
, key
, strlen(key
),
2621 (time_t)0, UINT32_MAX
);
2623 test_true(rc
== MEMCACHED_SUCCESS
);
2625 value
= memcached_get(memc
, key
, strlen(key
),
2626 &length
, &flags
, &rc
);
2628 test_true(rc
== MEMCACHED_SUCCESS
);
2629 test_true(value
== NULL
);
2630 test_true(length
== 0);
2631 test_true(flags
== UINT32_MAX
);
2633 return TEST_SUCCESS
;
2637 /* Check the validity of chinese key*/
2638 static test_return_t
user_supplied_bug17(memcached_st
*memc
)
2640 memcached_return_t rc
;
2641 const char *key
= "豆瓣";
2642 const char *value
="我们在炎热抑郁的夏天无法停止豆瓣";
2647 rc
= memcached_set(memc
, key
, strlen(key
),
2648 value
, strlen(value
),
2651 test_true(rc
== MEMCACHED_SUCCESS
);
2653 value2
= memcached_get(memc
, key
, strlen(key
),
2654 &length
, &flags
, &rc
);
2656 test_true(length
==strlen(value
));
2657 test_true(rc
== MEMCACHED_SUCCESS
);
2658 test_true(memcmp(value
, value2
, length
)==0);
2661 return TEST_SUCCESS
;
2669 static test_return_t
user_supplied_bug19(memcached_st
*memc
)
2672 memcached_server_st
*s
;
2673 memcached_return_t res
;
2677 m
= memcached_create(NULL
);
2678 memcached_server_add_with_weight(m
, "localhost", 11311, 100);
2679 memcached_server_add_with_weight(m
, "localhost", 11312, 100);
2681 s
= memcached_server_by_key(m
, "a", 1, &res
);
2682 memcached_server_free(s
);
2686 return TEST_SUCCESS
;
2689 /* CAS test from Andei */
2690 static test_return_t
user_supplied_bug20(memcached_st
*memc
)
2692 memcached_return_t status
;
2693 memcached_result_st
*result
, result_obj
;
2694 const char *key
= "abc";
2695 size_t key_len
= strlen("abc");
2696 const char *value
= "foobar";
2697 size_t value_len
= strlen(value
);
2699 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
2701 status
= memcached_set(memc
, key
, key_len
, value
, value_len
, (time_t)0, (uint32_t)0);
2702 test_true(status
== MEMCACHED_SUCCESS
);
2704 status
= memcached_mget(memc
, &key
, &key_len
, 1);
2705 test_true(status
== MEMCACHED_SUCCESS
);
2707 result
= memcached_result_create(memc
, &result_obj
);
2710 memcached_result_create(memc
, &result_obj
);
2711 result
= memcached_fetch_result(memc
, &result_obj
, &status
);
2714 test_true(status
== MEMCACHED_SUCCESS
);
2716 memcached_result_free(result
);
2718 return TEST_SUCCESS
;
2721 #include "ketama_test_cases.h"
2722 static test_return_t
user_supplied_bug18(memcached_st
*trash
)
2724 memcached_return_t rc
;
2727 memcached_server_st
*server_pool
;
2732 memc
= memcached_create(NULL
);
2735 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2736 test_true(rc
== MEMCACHED_SUCCESS
);
2738 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2739 test_true(value
== 1);
2741 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2742 test_true(rc
== MEMCACHED_SUCCESS
);
2744 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2745 test_true(value
== MEMCACHED_HASH_MD5
);
2747 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");
2748 memcached_server_push(memc
, server_pool
);
2750 /* verify that the server list was parsed okay. */
2751 test_true(memcached_server_count(memc
) == 8);
2752 test_true(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
2753 test_true(server_pool
[0].port
== 11211);
2754 test_true(server_pool
[0].weight
== 600);
2755 test_true(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
2756 test_true(server_pool
[2].port
== 11211);
2757 test_true(server_pool
[2].weight
== 200);
2758 test_true(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
2759 test_true(server_pool
[7].port
== 11211);
2760 test_true(server_pool
[7].weight
== 100);
2762 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
2763 * us test the boundary wraparound.
2765 test_true(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
2767 /* verify the standard ketama set. */
2768 for (x
= 0; x
< 99; x
++)
2770 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
2771 memcached_server_instance_st
*instance
=
2772 memcached_server_instance_fetch(memc
, server_idx
);
2773 char *hostname
= instance
->hostname
;
2774 test_strcmp(hostname
, ketama_test_cases
[x
].server
);
2777 memcached_server_list_free(server_pool
);
2778 memcached_free(memc
);
2780 return TEST_SUCCESS
;
2783 /* Large mget() of missing keys with binary proto
2785 * If many binary quiet commands (such as getq's in an mget) fill the output
2786 * buffer and the server chooses not to respond, memcached_flush hangs. See
2787 * http://lists.tangent.org/pipermail/libmemcached/2009-August/000918.html
2790 /* sighandler_t function that always asserts false */
2791 static void fail(int unused
__attribute__((unused
)))
2797 static test_return_t
_user_supplied_bug21(memcached_st
* memc
, size_t key_count
)
2799 memcached_return_t rc
;
2802 size_t* key_lengths
;
2803 void (*oldalarm
)(int);
2804 memcached_st
*memc_clone
;
2806 memc_clone
= memcached_clone(NULL
, memc
);
2807 test_true(memc_clone
);
2809 /* only binproto uses getq for mget */
2810 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
2812 /* empty the cache to ensure misses (hence non-responses) */
2813 rc
= memcached_flush(memc_clone
, 0);
2814 test_true(rc
== MEMCACHED_SUCCESS
);
2816 key_lengths
= calloc(key_count
, sizeof(size_t));
2817 keys
= calloc(key_count
, sizeof(char *));
2819 for (x
= 0; x
< key_count
; x
++)
2823 snprintf(buffer
, 30, "%u", x
);
2824 keys
[x
]= strdup(buffer
);
2825 key_lengths
[x
]= strlen(keys
[x
]);
2828 oldalarm
= signal(SIGALRM
, fail
);
2831 rc
= memcached_mget(memc_clone
, (const char **)keys
, key_lengths
, key_count
);
2832 test_true(rc
== MEMCACHED_SUCCESS
);
2835 signal(SIGALRM
, oldalarm
);
2837 test_true(fetch_all_results(memc
) == TEST_SUCCESS
);
2839 for (x
= 0; x
< key_count
; x
++)
2844 memcached_free(memc_clone
);
2846 return TEST_SUCCESS
;
2849 static test_return_t
pre_binary(memcached_st
*memc
);
2851 static test_return_t
user_supplied_bug21(memcached_st
*memc
)
2853 test_return_t test_rc
;
2854 test_rc
= pre_binary(memc
);
2856 if (test_rc
!= TEST_SUCCESS
)
2861 /* should work as of r580 */
2862 rc
= _user_supplied_bug21(memc
, 10);
2863 test_true(rc
== TEST_SUCCESS
);
2865 /* should fail as of r580 */
2866 rc
= _user_supplied_bug21(memc
, 1000);
2867 test_true(rc
== TEST_SUCCESS
);
2869 return TEST_SUCCESS
;
2872 static test_return_t
auto_eject_hosts(memcached_st
*trash
)
2875 memcached_server_instance_st
*instance
;
2877 memcached_return_t rc
;
2878 memcached_st
*memc
= memcached_create(NULL
);
2881 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2882 test_true(rc
== MEMCACHED_SUCCESS
);
2884 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2885 test_true(value
== 1);
2887 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2888 test_true(rc
== MEMCACHED_SUCCESS
);
2890 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2891 test_true(value
== MEMCACHED_HASH_MD5
);
2893 /* server should be removed when in delay */
2894 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
, 1);
2895 test_true(rc
== MEMCACHED_SUCCESS
);
2897 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
);
2898 test_true(value
== 1);
2900 memcached_server_st
*server_pool
;
2901 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");
2902 memcached_server_push(memc
, server_pool
);
2904 /* verify that the server list was parsed okay. */
2905 test_true(memcached_server_count(memc
) == 8);
2906 test_true(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
2907 test_true(server_pool
[0].port
== 11211);
2908 test_true(server_pool
[0].weight
== 600);
2909 test_true(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
2910 test_true(server_pool
[2].port
== 11211);
2911 test_true(server_pool
[2].weight
== 200);
2912 test_true(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
2913 test_true(server_pool
[7].port
== 11211);
2914 test_true(server_pool
[7].weight
== 100);
2916 instance
= memcached_server_instance_fetch(memc
, 2);
2917 instance
->next_retry
= time(NULL
) + 15;
2918 memc
->next_distribution_rebuild
= time(NULL
) - 1;
2920 for (size_t x
= 0; x
< 99; x
++)
2922 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
2923 test_true(server_idx
!= 2);
2926 /* and re-added when it's back. */
2927 instance
->next_retry
= time(NULL
) - 1;
2928 memc
->next_distribution_rebuild
= time(NULL
) - 1;
2929 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
,
2930 memc
->distribution
);
2931 for (size_t x
= 0; x
< 99; x
++)
2933 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
2934 // We re-use instance from above.
2936 memcached_server_instance_fetch(memc
, server_idx
);
2937 char *hostname
= instance
->hostname
;
2938 test_true(strcmp(hostname
, ketama_test_cases
[x
].server
) == 0);
2941 memcached_server_list_free(server_pool
);
2942 memcached_free(memc
);
2944 return TEST_SUCCESS
;
2947 static test_return_t
output_ketama_weighted_keys(memcached_st
*trash
)
2951 memcached_return_t rc
;
2952 memcached_st
*memc
= memcached_create(NULL
);
2956 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2957 test_true(rc
== MEMCACHED_SUCCESS
);
2959 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2960 test_true(value
== 1);
2962 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2963 test_true(rc
== MEMCACHED_SUCCESS
);
2965 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2966 test_true(value
== MEMCACHED_HASH_MD5
);
2969 test_true(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
) == MEMCACHED_SUCCESS
);
2971 memcached_server_st
*server_pool
;
2972 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");
2973 memcached_server_push(memc
, server_pool
);
2975 // @todo this needs to be refactored to actually test something.
2978 if ((fp
= fopen("ketama_keys.txt", "w")))
2982 printf("cannot write to file ketama_keys.txt");
2983 return TEST_FAILURE
;
2986 for (int x
= 0; x
< 10000; x
++)
2989 sprintf(key
, "%d", x
);
2991 uint32_t server_idx
= memcached_generate_hash(memc
, key
, strlen(key
));
2992 char *hostname
= memc
->hosts
[server_idx
].hostname
;
2993 in_port_t port
= memc
->hosts
[server_idx
].port
;
2994 fprintf(fp
, "key %s is on host /%s:%u\n", key
, hostname
, port
);
2998 memcached_server_list_free(server_pool
);
2999 memcached_free(memc
);
3001 return TEST_SUCCESS
;
3005 static test_return_t
result_static(memcached_st
*memc
)
3007 memcached_result_st result
;
3008 memcached_result_st
*result_ptr
;
3010 result_ptr
= memcached_result_create(memc
, &result
);
3011 test_true(result
.options
.is_allocated
== false);
3012 test_true(memcached_is_initialized(&result
) == true);
3013 test_true(result_ptr
);
3014 test_true(result_ptr
== &result
);
3016 memcached_result_free(&result
);
3018 test_true(result
.options
.is_allocated
== false);
3019 test_true(memcached_is_initialized(&result
) == false);
3021 return TEST_SUCCESS
;
3024 static test_return_t
result_alloc(memcached_st
*memc
)
3026 memcached_result_st
*result_ptr
;
3028 result_ptr
= memcached_result_create(memc
, NULL
);
3029 test_true(result_ptr
);
3030 test_true(result_ptr
->options
.is_allocated
== true);
3031 test_true(memcached_is_initialized(result_ptr
) == true);
3032 memcached_result_free(result_ptr
);
3034 return TEST_SUCCESS
;
3037 static test_return_t
string_static_null(memcached_st
*memc
)
3039 memcached_string_st string
;
3040 memcached_string_st
*string_ptr
;
3042 string_ptr
= memcached_string_create(memc
, &string
, 0);
3043 test_true(string
.options
.is_initialized
== true);
3044 test_true(string_ptr
);
3046 /* The following two better be the same! */
3047 test_true(memcached_is_allocated(string_ptr
) == false);
3048 test_true(memcached_is_allocated(&string
) == false);
3049 test_true(&string
== string_ptr
);
3051 test_true(string
.options
.is_initialized
== true);
3052 test_true(memcached_is_initialized(&string
) == true);
3053 memcached_string_free(&string
);
3054 test_true(memcached_is_initialized(&string
) == false);
3056 return TEST_SUCCESS
;
3059 static test_return_t
string_alloc_null(memcached_st
*memc
)
3061 memcached_string_st
*string
;
3063 string
= memcached_string_create(memc
, NULL
, 0);
3065 test_true(memcached_is_allocated(string
) == true);
3066 test_true(memcached_is_initialized(string
) == true);
3067 memcached_string_free(string
);
3069 return TEST_SUCCESS
;
3072 static test_return_t
string_alloc_with_size(memcached_st
*memc
)
3074 memcached_string_st
*string
;
3076 string
= memcached_string_create(memc
, NULL
, 1024);
3078 test_true(memcached_is_allocated(string
) == true);
3079 test_true(memcached_is_initialized(string
) == true);
3080 memcached_string_free(string
);
3082 return TEST_SUCCESS
;
3085 static test_return_t
string_alloc_with_size_toobig(memcached_st
*memc
)
3087 memcached_string_st
*string
;
3089 string
= memcached_string_create(memc
, NULL
, SIZE_MAX
);
3090 test_true(string
== NULL
);
3092 return TEST_SUCCESS
;
3095 static test_return_t
string_alloc_append(memcached_st
*memc
)
3098 char buffer
[SMALL_STRING_LEN
];
3099 memcached_string_st
*string
;
3101 /* Ring the bell! */
3102 memset(buffer
, 6, SMALL_STRING_LEN
);
3104 string
= memcached_string_create(memc
, NULL
, 100);
3106 test_true(memcached_is_allocated(string
) == true);
3107 test_true(memcached_is_initialized(string
) == true);
3109 for (x
= 0; x
< 1024; x
++)
3111 memcached_return_t rc
;
3112 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
3113 test_true(rc
== MEMCACHED_SUCCESS
);
3115 test_true(memcached_is_allocated(string
) == true);
3116 memcached_string_free(string
);
3118 return TEST_SUCCESS
;
3121 static test_return_t
string_alloc_append_toobig(memcached_st
*memc
)
3123 memcached_return_t rc
;
3125 char buffer
[SMALL_STRING_LEN
];
3126 memcached_string_st
*string
;
3128 /* Ring the bell! */
3129 memset(buffer
, 6, SMALL_STRING_LEN
);
3131 string
= memcached_string_create(memc
, NULL
, 100);
3133 test_true(memcached_is_allocated(string
) == true);
3134 test_true(memcached_is_initialized(string
) == true);
3136 for (x
= 0; x
< 1024; x
++)
3138 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
3139 test_true(rc
== MEMCACHED_SUCCESS
);
3141 rc
= memcached_string_append(string
, buffer
, SIZE_MAX
);
3142 test_true(rc
== MEMCACHED_MEMORY_ALLOCATION_FAILURE
);
3143 test_true(memcached_is_allocated(string
) == true);
3144 memcached_string_free(string
);
3146 return TEST_SUCCESS
;
3149 static test_return_t
cleanup_pairs(memcached_st
*memc
__attribute__((unused
)))
3151 pairs_free(global_pairs
);
3153 return TEST_SUCCESS
;
3156 static test_return_t
generate_pairs(memcached_st
*memc
__attribute__((unused
)))
3158 global_pairs
= pairs_generate(GLOBAL_COUNT
, 400);
3159 global_count
= GLOBAL_COUNT
;
3161 for (size_t x
= 0; x
< global_count
; x
++)
3163 global_keys
[x
]= global_pairs
[x
].key
;
3164 global_keys_length
[x
]= global_pairs
[x
].key_length
;
3167 return TEST_SUCCESS
;
3170 static test_return_t
generate_large_pairs(memcached_st
*memc
__attribute__((unused
)))
3172 global_pairs
= pairs_generate(GLOBAL2_COUNT
, MEMCACHED_MAX_BUFFER
+10);
3173 global_count
= GLOBAL2_COUNT
;
3175 for (size_t x
= 0; x
< global_count
; x
++)
3177 global_keys
[x
]= global_pairs
[x
].key
;
3178 global_keys_length
[x
]= global_pairs
[x
].key_length
;
3181 return TEST_SUCCESS
;
3184 static test_return_t
generate_data(memcached_st
*memc
)
3186 execute_set(memc
, global_pairs
, global_count
);
3188 return TEST_SUCCESS
;
3191 static test_return_t
generate_data_with_stats(memcached_st
*memc
)
3193 memcached_stat_st
*stat_p
;
3194 memcached_return_t rc
;
3195 uint32_t host_index
= 0;
3196 execute_set(memc
, global_pairs
, global_count
);
3198 //TODO: hosts used size stats
3199 stat_p
= memcached_stat(memc
, NULL
, &rc
);
3202 for (host_index
= 0; host_index
< SERVERS_TO_CREATE
; host_index
++)
3204 /* This test was changes so that "make test" would work properlly */
3206 memcached_server_instance_st
*instance
=
3207 memcached_server_instance_fetch(memc
, host_index
);
3209 printf("\nserver %u|%s|%u bytes: %llu\n", host_index
, instance
->hostname
, instance
->port
, (unsigned long long)(stat_p
+ host_index
)->bytes
);
3211 test_true((unsigned long long)(stat_p
+ host_index
)->bytes
);
3214 memcached_stat_free(NULL
, stat_p
);
3216 return TEST_SUCCESS
;
3218 static test_return_t
generate_buffer_data(memcached_st
*memc
)
3223 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
3224 generate_data(memc
);
3226 return TEST_SUCCESS
;
3229 static test_return_t
get_read_count(memcached_st
*memc
)
3231 memcached_return_t rc
;
3232 memcached_st
*memc_clone
;
3234 memc_clone
= memcached_clone(NULL
, memc
);
3235 test_true(memc_clone
);
3237 memcached_server_add_with_weight(memc_clone
, "localhost", 6666, 0);
3241 size_t return_value_length
;
3245 for (size_t x
= count
= 0; x
< global_count
; x
++)
3247 return_value
= memcached_get(memc_clone
, global_keys
[x
], global_keys_length
[x
],
3248 &return_value_length
, &flags
, &rc
);
3249 if (rc
== MEMCACHED_SUCCESS
)
3258 memcached_free(memc_clone
);
3260 return TEST_SUCCESS
;
3263 static test_return_t
get_read(memcached_st
*memc
)
3265 memcached_return_t rc
;
3269 size_t return_value_length
;
3272 for (size_t x
= 0; x
< global_count
; x
++)
3274 return_value
= memcached_get(memc
, global_keys
[x
], global_keys_length
[x
],
3275 &return_value_length
, &flags
, &rc
);
3277 test_true(return_value);
3278 test_true(rc == MEMCACHED_SUCCESS);
3280 if (rc
== MEMCACHED_SUCCESS
&& return_value
)
3285 return TEST_SUCCESS
;
3288 static test_return_t
mget_read(memcached_st
*memc
)
3290 memcached_return_t rc
;
3292 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
3293 test_true(rc
== MEMCACHED_SUCCESS
);
3294 test_true(fetch_all_results(memc
) == TEST_SUCCESS
);
3296 return TEST_SUCCESS
;
3299 static test_return_t
mget_read_result(memcached_st
*memc
)
3301 memcached_return_t rc
;
3303 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
3304 test_true(rc
== MEMCACHED_SUCCESS
);
3305 /* Turn this into a help function */
3307 memcached_result_st results_obj
;
3308 memcached_result_st
*results
;
3310 results
= memcached_result_create(memc
, &results_obj
);
3312 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
3315 test_true(rc
== MEMCACHED_SUCCESS
);
3318 memcached_result_free(&results_obj
);
3321 return TEST_SUCCESS
;
3324 static test_return_t
mget_read_function(memcached_st
*memc
)
3326 memcached_return_t rc
;
3328 memcached_execute_fn callbacks
[1];
3330 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
3331 test_true(rc
== MEMCACHED_SUCCESS
);
3333 callbacks
[0]= &callback_counter
;
3335 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
3337 return TEST_SUCCESS
;
3340 static test_return_t
delete_generate(memcached_st
*memc
)
3342 for (size_t x
= 0; x
< global_count
; x
++)
3344 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3347 return TEST_SUCCESS
;
3350 static test_return_t
delete_buffer_generate(memcached_st
*memc
)
3355 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
3357 for (size_t x
= 0; x
< global_count
; x
++)
3359 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3362 return TEST_SUCCESS
;
3365 static test_return_t
add_host_test1(memcached_st
*memc
)
3367 memcached_return_t rc
;
3368 char servername
[]= "0.example.com";
3369 memcached_server_st
*servers
;
3371 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
3373 test_true(1 == memcached_server_list_count(servers
));
3375 for (size_t x
= 2; x
< 20; x
++)
3377 char buffer
[SMALL_STRING_LEN
];
3379 snprintf(buffer
, SMALL_STRING_LEN
, "%zu.example.com", 400+x
);
3380 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
3382 test_true(rc
== MEMCACHED_SUCCESS
);
3383 test_true(x
== memcached_server_list_count(servers
));
3386 rc
= memcached_server_push(memc
, servers
);
3387 test_true(rc
== MEMCACHED_SUCCESS
);
3388 rc
= memcached_server_push(memc
, servers
);
3389 test_true(rc
== MEMCACHED_SUCCESS
);
3391 memcached_server_list_free(servers
);
3393 return TEST_SUCCESS
;
3396 static test_return_t
pre_nonblock(memcached_st
*memc
)
3398 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3400 return TEST_SUCCESS
;
3403 static test_return_t
pre_cork(memcached_st
*memc
)
3405 memcached_return_t rc
;
3407 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CORK
, set
);
3409 if (rc
== MEMCACHED_SUCCESS
)
3410 return TEST_SUCCESS
;
3412 return TEST_SKIPPED
;
3415 static test_return_t
pre_cork_and_nonblock(memcached_st
*memc
)
3421 if (rc
!= TEST_SUCCESS
)
3424 return pre_nonblock(memc
);
3427 static test_return_t
pre_nonblock_binary(memcached_st
*memc
)
3429 memcached_return_t rc
= MEMCACHED_FAILURE
;
3430 memcached_st
*memc_clone
;
3431 memcached_server_instance_st
*instance
;
3433 memc_clone
= memcached_clone(NULL
, memc
);
3434 test_true(memc_clone
);
3435 // The memcached_version needs to be done on a clone, because the server
3436 // will not toggle protocol on an connection.
3437 memcached_version(memc_clone
);
3439 instance
= memcached_server_instance_fetch(memc_clone
, 0);
3441 if (instance
->major_version
>= 1 && instance
->minor_version
> 2)
3443 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3444 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3445 test_true(rc
== MEMCACHED_SUCCESS
);
3446 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3450 return TEST_SKIPPED
;
3453 memcached_free(memc_clone
);
3455 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3458 static test_return_t
pre_murmur(memcached_st
*memc
)
3460 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
3462 return TEST_SUCCESS
;
3465 static test_return_t
pre_jenkins(memcached_st
*memc
)
3467 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_JENKINS
);
3469 return TEST_SUCCESS
;
3473 static test_return_t
pre_md5(memcached_st
*memc
)
3475 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MD5
);
3477 return TEST_SUCCESS
;
3480 static test_return_t
pre_crc(memcached_st
*memc
)
3482 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_CRC
);
3484 return TEST_SUCCESS
;
3487 static test_return_t
pre_hsieh(memcached_st
*memc
)
3489 #ifdef HAVE_HSIEH_HASH
3490 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_HSIEH
);
3491 return TEST_SUCCESS
;
3494 return TEST_SKIPPED
;
3498 static test_return_t
pre_hash_fnv1_64(memcached_st
*memc
)
3500 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
3502 return TEST_SUCCESS
;
3505 static test_return_t
pre_hash_fnv1a_64(memcached_st
*memc
)
3507 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_64
);
3509 return TEST_SUCCESS
;
3512 static test_return_t
pre_hash_fnv1_32(memcached_st
*memc
)
3514 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_32
);
3516 return TEST_SUCCESS
;
3519 static test_return_t
pre_hash_fnv1a_32(memcached_st
*memc
)
3521 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_32
);
3523 return TEST_SUCCESS
;
3526 static test_return_t
pre_behavior_ketama(memcached_st
*memc
)
3528 memcached_return_t rc
;
3531 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA
, 1);
3532 test_true(rc
== MEMCACHED_SUCCESS
);
3534 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA
);
3535 test_true(value
== 1);
3537 return TEST_SUCCESS
;
3540 static test_return_t
pre_behavior_ketama_weighted(memcached_st
*memc
)
3542 memcached_return_t rc
;
3545 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
3546 test_true(rc
== MEMCACHED_SUCCESS
);
3548 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
3549 test_true(value
== 1);
3551 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
3552 test_true(rc
== MEMCACHED_SUCCESS
);
3554 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
3555 test_true(value
== MEMCACHED_HASH_MD5
);
3557 return TEST_SUCCESS
;
3561 @note This should be testing to see if the server really supports the binary protocol.
3563 static test_return_t
pre_binary(memcached_st
*memc
)
3565 memcached_return_t rc
= MEMCACHED_FAILURE
;
3566 memcached_st
*memc_clone
;
3567 memcached_server_instance_st
*instance
;
3569 memc_clone
= memcached_clone(NULL
, memc
);
3570 test_true(memc_clone
);
3571 // The memcached_version needs to be done on a clone, because the server
3572 // will not toggle protocol on an connection.
3573 memcached_version(memc_clone
);
3575 instance
= memcached_server_instance_fetch(memc_clone
, 0);
3577 if (instance
->major_version
>= 1 && instance
->minor_version
> 2)
3579 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3580 test_true(rc
== MEMCACHED_SUCCESS
);
3581 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3584 memcached_free(memc_clone
);
3586 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3590 static test_return_t
pre_replication(memcached_st
*memc
)
3592 test_return_t test_rc
;
3593 test_rc
= pre_binary(memc
);
3595 if (test_rc
!= TEST_SUCCESS
)
3599 * Make sure that we store the item on all servers
3600 * (master + replicas == number of servers)
3602 memcached_return_t rc
;
3603 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
,
3604 memcached_server_count(memc
) - 1);
3605 test_true(rc
== MEMCACHED_SUCCESS
);
3606 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
) == memcached_server_count(memc
) - 1);
3608 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3612 static test_return_t
pre_replication_noblock(memcached_st
*memc
)
3616 rc
= pre_replication(memc
);
3617 if (rc
!= TEST_SUCCESS
)
3620 rc
= pre_nonblock(memc
);
3626 static void my_free(const memcached_st
*ptr
__attribute__((unused
)), void *mem
, void *context
)
3629 #ifdef HARD_MALLOC_TESTS
3630 void *real_ptr
= (mem
== NULL
) ? mem
: (void*)((caddr_t
)mem
- 8);
3638 static void *my_malloc(const memcached_st
*ptr
__attribute__((unused
)), const size_t size
, void *context
)
3641 #ifdef HARD_MALLOC_TESTS
3642 void *ret
= malloc(size
+ 8);
3645 ret
= (void*)((caddr_t
)ret
+ 8);
3648 void *ret
= malloc(size
);
3653 memset(ret
, 0xff, size
);
3660 static void *my_realloc(const memcached_st
*ptr
__attribute__((unused
)), void *mem
, const size_t size
, void *context
)
3663 #ifdef HARD_MALLOC_TESTS
3664 void *real_ptr
= (mem
== NULL
) ? NULL
: (void*)((caddr_t
)mem
- 8);
3665 void *nmem
= realloc(real_ptr
, size
+ 8);
3670 ret
= (void*)((caddr_t
)nmem
+ 8);
3675 return realloc(mem
, size
);
3680 static void *my_calloc(const memcached_st
*ptr
__attribute__((unused
)), size_t nelem
, const size_t size
, void *context
)
3683 #ifdef HARD_MALLOC_TESTS
3684 void *mem
= my_malloc(ptr
, nelem
* size
);
3687 memset(mem
, 0, nelem
* size
);
3692 return calloc(nelem
, size
);
3697 static test_return_t
set_prefix(memcached_st
*memc
)
3699 memcached_return_t rc
;
3700 const char *key
= "mine";
3703 /* Make sure be default none exists */
3704 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3705 test_true(rc
== MEMCACHED_FAILURE
);
3707 /* Test a clean set */
3708 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3709 test_true(rc
== MEMCACHED_SUCCESS
);
3711 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3712 test_true(memcmp(value
, key
, 4) == 0);
3713 test_true(rc
== MEMCACHED_SUCCESS
);
3715 /* Test that we can turn it off */
3716 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3717 test_true(rc
== MEMCACHED_SUCCESS
);
3719 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3720 test_true(rc
== MEMCACHED_FAILURE
);
3722 /* Now setup for main test */
3723 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3724 test_true(rc
== MEMCACHED_SUCCESS
);
3726 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3727 test_true(rc
== MEMCACHED_SUCCESS
);
3728 test_true(memcmp(value
, key
, 4) == 0);
3730 /* Set to Zero, and then Set to something too large */
3733 memset(long_key
, 0, 255);
3735 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3736 test_true(rc
== MEMCACHED_SUCCESS
);
3738 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3739 test_true(rc
== MEMCACHED_FAILURE
);
3740 test_true(value
== NULL
);
3742 /* Test a long key for failure */
3743 /* TODO, extend test to determine based on setting, what result should be */
3744 strcpy(long_key
, "Thisismorethentheallottednumberofcharacters");
3745 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3746 //test_true(rc == MEMCACHED_BAD_KEY_PROVIDED);
3747 test_true(rc
== MEMCACHED_SUCCESS
);
3749 /* Now test a key with spaces (which will fail from long key, since bad key is not set) */
3750 strcpy(long_key
, "This is more then the allotted number of characters");
3751 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3752 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3754 /* Test for a bad prefix, but with a short key */
3755 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, 1);
3756 test_true(rc
== MEMCACHED_SUCCESS
);
3758 strcpy(long_key
, "dog cat");
3759 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3760 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3763 return TEST_SUCCESS
;
3767 #ifdef MEMCACHED_ENABLE_DEPRECATED
3768 static test_return_t
deprecated_set_memory_alloc(memcached_st
*memc
)
3770 void *test_ptr
= NULL
;
3773 memcached_malloc_fn malloc_cb
=
3774 (memcached_malloc_fn
)my_malloc
;
3775 cb_ptr
= *(void **)&malloc_cb
;
3776 memcached_return_t rc
;
3778 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, cb_ptr
);
3779 test_true(rc
== MEMCACHED_SUCCESS
);
3780 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
3781 test_true(rc
== MEMCACHED_SUCCESS
);
3782 test_true(test_ptr
== cb_ptr
);
3786 memcached_realloc_fn realloc_cb
=
3787 (memcached_realloc_fn
)my_realloc
;
3788 cb_ptr
= *(void **)&realloc_cb
;
3789 memcached_return_t rc
;
3791 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, cb_ptr
);
3792 test_true(rc
== MEMCACHED_SUCCESS
);
3793 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
3794 test_true(rc
== MEMCACHED_SUCCESS
);
3795 test_true(test_ptr
== cb_ptr
);
3799 memcached_free_fn free_cb
=
3800 (memcached_free_fn
)my_free
;
3801 cb_ptr
= *(void **)&free_cb
;
3802 memcached_return_t rc
;
3804 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, cb_ptr
);
3805 test_true(rc
== MEMCACHED_SUCCESS
);
3806 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
3807 test_true(rc
== MEMCACHED_SUCCESS
);
3808 test_true(test_ptr
== cb_ptr
);
3811 return TEST_SUCCESS
;
3816 static test_return_t
set_memory_alloc(memcached_st
*memc
)
3818 memcached_return_t rc
;
3819 rc
= memcached_set_memory_allocators(memc
, NULL
, my_free
,
3820 my_realloc
, my_calloc
, NULL
);
3821 test_true(rc
== MEMCACHED_FAILURE
);
3823 rc
= memcached_set_memory_allocators(memc
, my_malloc
, my_free
,
3824 my_realloc
, my_calloc
, NULL
);
3826 memcached_malloc_fn mem_malloc
;
3827 memcached_free_fn mem_free
;
3828 memcached_realloc_fn mem_realloc
;
3829 memcached_calloc_fn mem_calloc
;
3830 memcached_get_memory_allocators(memc
, &mem_malloc
, &mem_free
,
3831 &mem_realloc
, &mem_calloc
);
3833 test_true(mem_malloc
== my_malloc
);
3834 test_true(mem_realloc
== my_realloc
);
3835 test_true(mem_calloc
== my_calloc
);
3836 test_true(mem_free
== my_free
);
3838 return TEST_SUCCESS
;
3841 static test_return_t
enable_consistent_crc(memcached_st
*memc
)
3844 memcached_server_distribution_t value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
3845 memcached_hash_t hash
;
3846 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
3847 if ((rc
= pre_crc(memc
)) != TEST_SUCCESS
)
3850 value
= (memcached_server_distribution_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
3851 test_true(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
3853 hash
= (memcached_hash_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
3855 if (hash
!= MEMCACHED_HASH_CRC
)
3856 return TEST_SKIPPED
;
3858 return TEST_SUCCESS
;
3861 static test_return_t
enable_consistent_hsieh(memcached_st
*memc
)
3864 memcached_server_distribution_t value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
3865 memcached_hash_t hash
;
3866 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
3867 if ((rc
= pre_hsieh(memc
)) != TEST_SUCCESS
)
3870 value
= (memcached_server_distribution_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
3871 test_true(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
3873 hash
= (memcached_hash_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
3875 if (hash
!= MEMCACHED_HASH_HSIEH
)
3876 return TEST_SKIPPED
;
3879 return TEST_SUCCESS
;
3882 static test_return_t
enable_cas(memcached_st
*memc
)
3884 unsigned int set
= 1;
3886 memcached_server_instance_st
*instance
=
3887 memcached_server_instance_fetch(memc
, 0);
3889 memcached_version(memc
);
3891 if ((instance
->major_version
>= 1 && (instance
->minor_version
== 2 && instance
->micro_version
>= 4))
3892 || instance
->minor_version
> 2)
3894 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
3896 return TEST_SUCCESS
;
3899 return TEST_SKIPPED
;
3902 static test_return_t
check_for_1_2_3(memcached_st
*memc
)
3904 memcached_version(memc
);
3905 memcached_server_instance_st
*instance
=
3906 memcached_server_instance_fetch(memc
, 0);
3908 if ((instance
->major_version
>= 1 && (instance
->minor_version
== 2 && instance
->micro_version
>= 4))
3909 || instance
->minor_version
> 2)
3910 return TEST_SUCCESS
;
3912 return TEST_SKIPPED
;
3915 static test_return_t
pre_unix_socket(memcached_st
*memc
)
3917 memcached_return_t rc
;
3920 memcached_servers_reset(memc
);
3922 if (stat("/tmp/memcached.socket", &buf
))
3923 return TEST_SKIPPED
;
3925 rc
= memcached_server_add_unix_socket_with_weight(memc
, "/tmp/memcached.socket", 0);
3927 return ( rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_FAILURE
);
3930 static test_return_t
pre_nodelay(memcached_st
*memc
)
3932 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3933 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
3935 return TEST_SUCCESS
;
3938 static test_return_t
pre_settimer(memcached_st
*memc
)
3940 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
3941 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
3943 return TEST_SUCCESS
;
3946 static test_return_t
poll_timeout(memcached_st
*memc
)
3952 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
3954 timeout
= (size_t)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
3956 test_true(timeout
== 100);
3958 return TEST_SUCCESS
;
3961 static test_return_t
noreply_test(memcached_st
*memc
)
3963 memcached_return_t ret
;
3964 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
3965 test_true(ret
== MEMCACHED_SUCCESS
);
3966 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
3967 test_true(ret
== MEMCACHED_SUCCESS
);
3968 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
3969 test_true(ret
== MEMCACHED_SUCCESS
);
3970 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NOREPLY
) == 1);
3971 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
) == 1);
3972 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
) == 1);
3974 for (int count
=0; count
< 5; ++count
)
3976 for (size_t x
= 0; x
< 100; ++x
)
3979 size_t len
= (size_t)sprintf(key
, "%zu", x
);
3983 ret
= memcached_add(memc
, key
, len
, key
, len
, 0, 0);
3986 ret
= memcached_replace(memc
, key
, len
, key
, len
, 0, 0);
3989 ret
= memcached_set(memc
, key
, len
, key
, len
, 0, 0);
3992 ret
= memcached_append(memc
, key
, len
, key
, len
, 0, 0);
3995 ret
= memcached_prepend(memc
, key
, len
, key
, len
, 0, 0);
4001 test_true(ret
== MEMCACHED_SUCCESS
|| ret
== MEMCACHED_BUFFERED
);
4005 ** NOTE: Don't ever do this in your code! this is not a supported use of the
4006 ** API and is _ONLY_ done this way to verify that the library works the
4007 ** way it is supposed to do!!!!
4010 for (uint32_t x
= 0; x
< memcached_server_count(memc
); ++x
)
4012 memcached_server_instance_st
*instance
=
4013 memcached_server_instance_fetch(memc
, x
);
4014 no_msg
+=(int)(instance
->cursor_active
);
4017 test_true(no_msg
== 0);
4018 test_true(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
4021 ** Now validate that all items was set properly!
4023 for (size_t x
= 0; x
< 100; ++x
)
4027 size_t len
= (size_t)sprintf(key
, "%zu", x
);
4030 char* value
=memcached_get(memc
, key
, strlen(key
),
4031 &length
, &flags
, &ret
);
4032 test_true(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
4035 case 0: /* FALLTHROUGH */
4036 case 1: /* FALLTHROUGH */
4038 test_true(strncmp(value
, key
, len
) == 0);
4039 test_true(len
== length
);
4042 test_true(length
== len
* 2);
4045 test_true(length
== len
* 3);
4055 /* Try setting an illegal cas value (should not return an error to
4056 * the caller (because we don't expect a return message from the server)
4058 const char* keys
[]= {"0"};
4059 size_t lengths
[]= {1};
4062 memcached_result_st results_obj
;
4063 memcached_result_st
*results
;
4064 ret
= memcached_mget(memc
, keys
, lengths
, 1);
4065 test_true(ret
== MEMCACHED_SUCCESS
);
4067 results
= memcached_result_create(memc
, &results_obj
);
4069 results
= memcached_fetch_result(memc
, &results_obj
, &ret
);
4071 test_true(ret
== MEMCACHED_SUCCESS
);
4072 uint64_t cas
= memcached_result_cas(results
);
4073 memcached_result_free(&results_obj
);
4075 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
4076 test_true(ret
== MEMCACHED_SUCCESS
);
4079 * The item will have a new cas value, so try to set it again with the old
4080 * value. This should fail!
4082 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
4083 test_true(ret
== MEMCACHED_SUCCESS
);
4084 test_true(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
4085 char* value
=memcached_get(memc
, keys
[0], lengths
[0], &length
, &flags
, &ret
);
4086 test_true(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
4089 return TEST_SUCCESS
;
4092 static test_return_t
analyzer_test(memcached_st
*memc
)
4094 memcached_return_t rc
;
4095 memcached_stat_st
*memc_stat
;
4096 memcached_analysis_st
*report
;
4098 memc_stat
= memcached_stat(memc
, NULL
, &rc
);
4099 test_true(rc
== MEMCACHED_SUCCESS
);
4100 test_true(memc_stat
);
4102 report
= memcached_analyze(memc
, memc_stat
, &rc
);
4103 test_true(rc
== MEMCACHED_SUCCESS
);
4107 memcached_stat_free(NULL
, memc_stat
);
4109 return TEST_SUCCESS
;
4112 /* Count the objects */
4113 static memcached_return_t
callback_dump_counter(const memcached_st
*ptr
__attribute__((unused
)),
4114 const char *key
__attribute__((unused
)),
4115 size_t key_length
__attribute__((unused
)),
4118 size_t *counter
= (size_t *)context
;
4120 *counter
= *counter
+ 1;
4122 return MEMCACHED_SUCCESS
;
4125 static test_return_t
dump_test(memcached_st
*memc
)
4127 memcached_return_t rc
;
4129 memcached_dump_fn callbacks
[1];
4130 test_return_t main_rc
;
4132 callbacks
[0]= &callback_dump_counter
;
4134 /* No support for Binary protocol yet */
4135 if (memc
->flags
.binary_protocol
)
4136 return TEST_SUCCESS
;
4138 main_rc
= set_test3(memc
);
4140 test_true (main_rc
== TEST_SUCCESS
);
4142 rc
= memcached_dump(memc
, callbacks
, (void *)&counter
, 1);
4143 test_true(rc
== MEMCACHED_SUCCESS
);
4145 /* We may have more then 32 if our previous flush has not completed */
4146 test_true(counter
>= 32);
4148 return TEST_SUCCESS
;
4151 #ifdef HAVE_LIBMEMCACHEDUTIL
4152 static void* connection_release(void *arg
)
4155 memcached_pool_st
* pool
;
4160 assert(memcached_pool_push(resource
->pool
, resource
->mmc
) == MEMCACHED_SUCCESS
);
4164 static test_return_t
connection_pool_test(memcached_st
*memc
)
4166 memcached_pool_st
* pool
= memcached_pool_create(memc
, 5, 10);
4167 test_true(pool
!= NULL
);
4168 memcached_st
* mmc
[10];
4169 memcached_return_t rc
;
4171 for (size_t x
= 0; x
< 10; ++x
)
4173 mmc
[x
]= memcached_pool_pop(pool
, false, &rc
);
4174 test_true(mmc
[x
] != NULL
);
4175 test_true(rc
== MEMCACHED_SUCCESS
);
4178 test_true(memcached_pool_pop(pool
, false, &rc
) == NULL
);
4179 test_true(rc
== MEMCACHED_SUCCESS
);
4183 memcached_pool_st
* pool
;
4185 } item
= { .pool
= pool
, .mmc
= mmc
[9] };
4186 pthread_create(&tid
, NULL
, connection_release
, &item
);
4187 mmc
[9]= memcached_pool_pop(pool
, true, &rc
);
4188 test_true(rc
== MEMCACHED_SUCCESS
);
4189 pthread_join(tid
, NULL
);
4190 test_true(mmc
[9] == item
.mmc
);
4191 const char *key
= "key";
4192 size_t keylen
= strlen(key
);
4194 // verify that I can do ops with all connections
4195 rc
= memcached_set(mmc
[0], key
, keylen
, "0", 1, 0, 0);
4196 test_true(rc
== MEMCACHED_SUCCESS
);
4198 for (size_t x
= 0; x
< 10; ++x
)
4200 uint64_t number_value
;
4201 rc
= memcached_increment(mmc
[x
], key
, keylen
, 1, &number_value
);
4202 test_true(rc
== MEMCACHED_SUCCESS
);
4203 test_true(number_value
== (x
+1));
4207 for (size_t x
= 0; x
< 10; ++x
)
4209 test_true(memcached_pool_push(pool
, mmc
[x
]) == MEMCACHED_SUCCESS
);
4213 /* verify that I can set behaviors on the pool when I don't have all
4214 * of the connections in the pool. It should however be enabled
4215 * when I push the item into the pool
4217 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
4218 test_true(mmc
[0] != NULL
);
4220 rc
= memcached_pool_behavior_set(pool
, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
, 9999);
4221 test_true(rc
== MEMCACHED_SUCCESS
);
4223 mmc
[1]= memcached_pool_pop(pool
, false, &rc
);
4224 test_true(mmc
[1] != NULL
);
4226 test_true(memcached_behavior_get(mmc
[1], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
) == 9999);
4227 test_true(memcached_pool_push(pool
, mmc
[1]) == MEMCACHED_SUCCESS
);
4228 test_true(memcached_pool_push(pool
, mmc
[0]) == MEMCACHED_SUCCESS
);
4230 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
4231 test_true(memcached_behavior_get(mmc
[0], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
) == 9999);
4232 test_true(memcached_pool_push(pool
, mmc
[0]) == MEMCACHED_SUCCESS
);
4235 test_true(memcached_pool_destroy(pool
) == memc
);
4236 return TEST_SUCCESS
;
4240 static test_return_t
replication_set_test(memcached_st
*memc
)
4242 memcached_return_t rc
;
4243 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4244 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 0);
4246 rc
= memcached_set(memc
, "bubba", 5, "0", 1, 0, 0);
4247 test_true(rc
== MEMCACHED_SUCCESS
);
4250 ** We are using the quiet commands to store the replicas, so we need
4251 ** to ensure that all of them are processed before we can continue.
4252 ** In the test we go directly from storing the object to trying to
4253 ** receive the object from all of the different servers, so we
4254 ** could end up in a race condition (the memcached server hasn't yet
4255 ** processed the quiet command from the replication set when it process
4256 ** the request from the other client (created by the clone)). As a
4257 ** workaround for that we call memcached_quit to send the quit command
4258 ** to the server and wait for the response ;-) If you use the test code
4259 ** as an example for your own code, please note that you shouldn't need
4262 memcached_quit(memc
);
4265 ** "bubba" should now be stored on all of our servers. We don't have an
4266 ** easy to use API to address each individual server, so I'll just iterate
4267 ** through a bunch of "master keys" and I should most likely hit all of the
4270 for (int x
= 'a'; x
<= 'z'; ++x
)
4272 char key
[2]= { [0]= (char)x
};
4275 char *val
= memcached_get_by_key(memc_clone
, key
, 1, "bubba", 5,
4277 test_true(rc
== MEMCACHED_SUCCESS
);
4278 test_true(val
!= NULL
);
4282 memcached_free(memc_clone
);
4284 return TEST_SUCCESS
;
4287 static test_return_t
replication_get_test(memcached_st
*memc
)
4289 memcached_return_t rc
;
4292 * Don't do the following in your code. I am abusing the internal details
4293 * within the library, and this is not a supported interface.
4294 * This is to verify correct behavior in the library
4296 for (uint32_t host
= 0; host
< memcached_server_count(memc
); ++host
)
4298 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4299 memcached_server_instance_st
*instance
=
4300 memcached_server_instance_fetch(memc_clone
, host
);
4304 for (int x
= 'a'; x
<= 'z'; ++x
)
4306 char key
[2]= { [0]= (char)x
};
4309 char *val
= memcached_get_by_key(memc_clone
, key
, 1, "bubba", 5,
4311 test_true(rc
== MEMCACHED_SUCCESS
);
4312 test_true(val
!= NULL
);
4316 memcached_free(memc_clone
);
4319 return TEST_SUCCESS
;
4322 static test_return_t
replication_mget_test(memcached_st
*memc
)
4324 memcached_return_t rc
;
4325 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4326 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 0);
4328 const char *keys
[]= { "bubba", "key1", "key2", "key3" };
4329 size_t len
[]= { 5, 4, 4, 4 };
4331 for (size_t x
= 0; x
< 4; ++x
)
4333 rc
= memcached_set(memc
, keys
[x
], len
[x
], "0", 1, 0, 0);
4334 test_true(rc
== MEMCACHED_SUCCESS
);
4338 ** We are using the quiet commands to store the replicas, so we need
4339 ** to ensure that all of them are processed before we can continue.
4340 ** In the test we go directly from storing the object to trying to
4341 ** receive the object from all of the different servers, so we
4342 ** could end up in a race condition (the memcached server hasn't yet
4343 ** processed the quiet command from the replication set when it process
4344 ** the request from the other client (created by the clone)). As a
4345 ** workaround for that we call memcached_quit to send the quit command
4346 ** to the server and wait for the response ;-) If you use the test code
4347 ** as an example for your own code, please note that you shouldn't need
4350 memcached_quit(memc
);
4353 * Don't do the following in your code. I am abusing the internal details
4354 * within the library, and this is not a supported interface.
4355 * This is to verify correct behavior in the library
4357 memcached_result_st result_obj
;
4358 for (uint32_t host
= 0; host
< memc_clone
->number_of_hosts
; host
++)
4360 memcached_st
*new_clone
= memcached_clone(NULL
, memc
);
4361 memcached_server_instance_st
*instance
=
4362 memcached_server_instance_fetch(new_clone
, host
);
4365 for (int x
= 'a'; x
<= 'z'; ++x
)
4367 char key
[2]= { [0]= (char)x
, [1]= 0 };
4369 rc
= memcached_mget_by_key(new_clone
, key
, 1, keys
, len
, 4);
4370 test_true(rc
== MEMCACHED_SUCCESS
);
4372 memcached_result_st
*results
= memcached_result_create(new_clone
, &result_obj
);
4376 while ((results
= memcached_fetch_result(new_clone
, &result_obj
, &rc
)) != NULL
)
4380 test_true(hits
== 4);
4381 memcached_result_free(&result_obj
);
4384 memcached_free(new_clone
);
4387 memcached_free(memc_clone
);
4389 return TEST_SUCCESS
;
4392 static test_return_t
replication_randomize_mget_test(memcached_st
*memc
)
4394 memcached_result_st result_obj
;
4395 memcached_return_t rc
;
4396 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4397 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 3);
4398 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ
, 1);
4400 const char *keys
[]= { "key1", "key2", "key3", "key4", "key5", "key6", "key7" };
4401 size_t len
[]= { 4, 4, 4, 4, 4, 4, 4 };
4403 for (int x
=0; x
< 7; ++x
)
4405 rc
= memcached_set(memc
, keys
[x
], len
[x
], "1", 1, 0, 0);
4406 test_true(rc
== MEMCACHED_SUCCESS
);
4409 memcached_quit(memc
);
4411 for (size_t x
= 0; x
< 7; ++x
)
4413 const char key
[2]= { [0]= (const char)x
};
4415 rc
= memcached_mget_by_key(memc_clone
, key
, 1, keys
, len
, 7);
4416 test_true(rc
== MEMCACHED_SUCCESS
);
4418 memcached_result_st
*results
= memcached_result_create(memc_clone
, &result_obj
);
4422 while ((results
= memcached_fetch_result(memc_clone
, &result_obj
, &rc
)) != NULL
)
4426 test_true(hits
== 7);
4427 memcached_result_free(&result_obj
);
4429 memcached_free(memc_clone
);
4430 return TEST_SUCCESS
;
4433 static test_return_t
replication_delete_test(memcached_st
*memc
)
4435 memcached_return_t rc
;
4436 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4437 /* Delete the items from all of the servers except 1 */
4438 uint64_t repl
= memcached_behavior_get(memc
,
4439 MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
);
4440 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, --repl
);
4442 const char *keys
[]= { "bubba", "key1", "key2", "key3" };
4443 size_t len
[]= { 5, 4, 4, 4 };
4445 for (size_t x
= 0; x
< 4; ++x
)
4447 rc
= memcached_delete_by_key(memc
, keys
[0], len
[0], keys
[x
], len
[x
], 0);
4448 test_true(rc
== MEMCACHED_SUCCESS
);
4452 * Don't do the following in your code. I am abusing the internal details
4453 * within the library, and this is not a supported interface.
4454 * This is to verify correct behavior in the library
4456 uint32_t hash
= memcached_generate_hash(memc
, keys
[0], len
[0]);
4457 for (uint32_t x
= 0; x
< (repl
+ 1); ++x
)
4459 memcached_server_instance_st
*instance
=
4460 memcached_server_instance_fetch(memc_clone
, x
);
4463 if (++hash
== memc_clone
->number_of_hosts
)
4467 memcached_result_st result_obj
;
4468 for (uint32_t host
= 0; host
< memc_clone
->number_of_hosts
; ++host
)
4470 for (size_t x
= 'a'; x
<= 'z'; ++x
)
4472 const char key
[2]= { [0]= (const char)x
};
4474 rc
= memcached_mget_by_key(memc_clone
, key
, 1, keys
, len
, 4);
4475 test_true(rc
== MEMCACHED_SUCCESS
);
4477 memcached_result_st
*results
= memcached_result_create(memc_clone
, &result_obj
);
4481 while ((results
= memcached_fetch_result(memc_clone
, &result_obj
, &rc
)) != NULL
)
4485 test_true(hits
== 4);
4486 memcached_result_free(&result_obj
);
4489 memcached_free(memc_clone
);
4491 return TEST_SUCCESS
;
4494 static void increment_request_id(uint16_t *id
)
4497 if ((*id
& UDP_REQUEST_ID_THREAD_MASK
) != 0)
4501 static uint16_t *get_udp_request_ids(memcached_st
*memc
)
4503 uint16_t *ids
= malloc(sizeof(uint16_t) * memcached_server_count(memc
));
4504 assert(ids
!= NULL
);
4506 for (uint32_t x
= 0; x
< memcached_server_count(memc
); x
++)
4508 memcached_server_instance_st
*instance
=
4509 memcached_server_instance_fetch(memc
, x
);
4511 ids
[x
]= get_udp_datagram_request_id((struct udp_datagram_header_st
*) instance
->write_buffer
);
4517 static test_return_t
post_udp_op_check(memcached_st
*memc
, uint16_t *expected_req_ids
)
4519 memcached_server_st
*cur_server
= memcached_server_list(memc
);
4520 uint16_t *cur_req_ids
= get_udp_request_ids(memc
);
4522 for (size_t x
= 0; x
< memcached_server_count(memc
); x
++)
4524 test_true(cur_server
[x
].cursor_active
== 0);
4525 test_true(cur_req_ids
[x
] == expected_req_ids
[x
]);
4527 free(expected_req_ids
);
4530 return TEST_SUCCESS
;
4534 ** There is a little bit of a hack here, instead of removing
4535 ** the servers, I just set num host to 0 and them add then new udp servers
4537 static test_return_t
init_udp(memcached_st
*memc
)
4539 memcached_version(memc
);
4540 memcached_server_instance_st
*instance
=
4541 memcached_server_instance_fetch(memc
, 0);
4543 /* For the time being, only support udp test for >= 1.2.6 && < 1.3 */
4544 if (instance
->major_version
!= 1 || instance
->minor_version
!= 2
4545 || instance
->micro_version
< 6)
4546 return TEST_SKIPPED
;
4548 uint32_t num_hosts
= memcached_server_count(memc
);
4549 memcached_server_st servers
[num_hosts
];
4550 memcpy(servers
, memcached_server_list(memc
), sizeof(memcached_server_st
) * num_hosts
);
4551 for (uint32_t x
= 0; x
< num_hosts
; x
++)
4553 memcached_server_instance_st
*set_instance
=
4554 memcached_server_instance_fetch(memc
, x
);
4556 memcached_server_free(set_instance
);
4559 memc
->number_of_hosts
= 0;
4560 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
, 1);
4561 for (uint32_t x
= 0; x
< num_hosts
; x
++)
4563 memcached_server_instance_st
*set_instance
=
4564 memcached_server_instance_fetch(memc
, x
);
4566 test_true(memcached_server_add_udp(memc
, servers
[x
].hostname
, servers
[x
].port
) == MEMCACHED_SUCCESS
);
4567 test_true(set_instance
->write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4570 return TEST_SUCCESS
;
4573 static test_return_t
binary_init_udp(memcached_st
*memc
)
4575 test_return_t test_rc
;
4576 test_rc
= pre_binary(memc
);
4578 if (test_rc
!= TEST_SUCCESS
)
4581 return init_udp(memc
);
4584 /* Make sure that I cant add a tcp server to a udp client */
4585 static test_return_t
add_tcp_server_udp_client_test(memcached_st
*memc
)
4589 memcached_server_st server
;
4590 memcached_server_instance_st
*instance
=
4591 memcached_server_instance_fetch(memc
, 0);
4592 memcached_server_clone(&server
, &memc
->hosts
[0]);
4593 test_true(memcached_server_remove(&(memc
->hosts
[0])) == MEMCACHED_SUCCESS
);
4594 test_true(memcached_server_add(memc
, server
.hostname
, server
.port
) == MEMCACHED_INVALID_HOST_PROTOCOL
);
4596 return TEST_SUCCESS
;
4599 /* Make sure that I cant add a udp server to a tcp client */
4600 static test_return_t
add_udp_server_tcp_client_test(memcached_st
*memc
)
4604 memcached_server_st server
;
4605 memcached_server_instance_st
*instance
=
4606 memcached_server_instance_fetch(memc
, 0);
4607 memcached_server_clone(&server
, &memc
->hosts
[0]);
4608 test_true(memcached_server_remove(&(memc
->hosts
[0])) == MEMCACHED_SUCCESS
);
4610 memcached_st tcp_client
;
4611 memcached_create(&tcp_client
);
4612 test_true(memcached_server_add_udp(&tcp_client
, server
.hostname
, server
.port
) == MEMCACHED_INVALID_HOST_PROTOCOL
);
4615 return TEST_SUCCESS
;
4618 static test_return_t
set_udp_behavior_test(memcached_st
*memc
)
4621 memcached_quit(memc
);
4622 memc
->number_of_hosts
= 0;
4623 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, memc
->distribution
);
4624 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
, 1) == MEMCACHED_SUCCESS
);
4625 test_true(memc
->flags
.use_udp
);
4626 test_true(memc
->flags
.no_reply
);
4628 test_true(memcached_server_count(memc
) == 0);
4630 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
,0);
4631 test_true(! (memc
->flags
.use_udp
));
4632 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
,0);
4633 test_true(! (memc
->flags
.no_reply
));
4635 return TEST_SUCCESS
;
4638 static test_return_t
udp_set_test(memcached_st
*memc
)
4640 unsigned int num_iters
= 1025; //request id rolls over at 1024
4642 for (size_t x
= 0; x
< num_iters
;x
++)
4644 memcached_return_t rc
;
4645 const char *key
= "foo";
4646 const char *value
= "when we sanitize";
4647 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4648 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4649 memcached_server_instance_st
*instance
=
4650 memcached_server_instance_fetch(memc
, server_key
);
4651 size_t init_offset
= instance
->write_buffer_offset
;
4653 rc
= memcached_set(memc
, key
, strlen(key
),
4654 value
, strlen(value
),
4655 (time_t)0, (uint32_t)0);
4656 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4657 /** NB, the check below assumes that if new write_ptr is less than
4658 * the original write_ptr that we have flushed. For large payloads, this
4659 * maybe an invalid assumption, but for the small payload we have it is OK
4661 if (rc
== MEMCACHED_SUCCESS
||
4662 instance
->write_buffer_offset
< init_offset
)
4663 increment_request_id(&expected_ids
[server_key
]);
4665 if (rc
== MEMCACHED_SUCCESS
)
4667 test_true(instance
->write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4671 test_true(instance
->write_buffer_offset
!= UDP_DATAGRAM_HEADER_LENGTH
);
4672 test_true(instance
->write_buffer_offset
<= MAX_UDP_DATAGRAM_LENGTH
);
4674 test_true(post_udp_op_check(memc
, expected_ids
) == TEST_SUCCESS
);
4676 return TEST_SUCCESS
;
4679 static test_return_t
udp_buffered_set_test(memcached_st
*memc
)
4681 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4682 return udp_set_test(memc
);
4685 static test_return_t
udp_set_too_big_test(memcached_st
*memc
)
4687 memcached_return_t rc
;
4688 const char *key
= "bar";
4689 char value
[MAX_UDP_DATAGRAM_LENGTH
];
4690 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4691 rc
= memcached_set(memc
, key
, strlen(key
),
4692 value
, MAX_UDP_DATAGRAM_LENGTH
,
4693 (time_t)0, (uint32_t)0);
4694 test_true(rc
== MEMCACHED_WRITE_FAILURE
);
4696 return post_udp_op_check(memc
,expected_ids
);
4699 static test_return_t
udp_delete_test(memcached_st
*memc
)
4701 unsigned int num_iters
= 1025; //request id rolls over at 1024
4703 for (size_t x
= 0; x
< num_iters
;x
++)
4705 memcached_return_t rc
;
4706 const char *key
= "foo";
4707 uint16_t *expected_ids
=get_udp_request_ids(memc
);
4708 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4709 memcached_server_instance_st
*instance
=
4710 memcached_server_instance_fetch(memc
, server_key
);
4711 size_t init_offset
= instance
->write_buffer_offset
;
4713 rc
= memcached_delete(memc
, key
, strlen(key
), 0);
4714 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4716 if (rc
== MEMCACHED_SUCCESS
|| instance
->write_buffer_offset
< init_offset
)
4717 increment_request_id(&expected_ids
[server_key
]);
4718 if (rc
== MEMCACHED_SUCCESS
)
4720 test_true(instance
->write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4724 test_true(instance
->write_buffer_offset
!= UDP_DATAGRAM_HEADER_LENGTH
);
4725 test_true(instance
->write_buffer_offset
<= MAX_UDP_DATAGRAM_LENGTH
);
4727 test_true(post_udp_op_check(memc
,expected_ids
) == TEST_SUCCESS
);
4729 return TEST_SUCCESS
;
4732 static test_return_t
udp_buffered_delete_test(memcached_st
*memc
)
4734 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4735 return udp_delete_test(memc
);
4738 static test_return_t
udp_verbosity_test(memcached_st
*memc
)
4740 memcached_return_t rc
;
4741 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4743 for (size_t x
= 0; x
< memcached_server_count(memc
); x
++)
4745 increment_request_id(&expected_ids
[x
]);
4748 rc
= memcached_verbosity(memc
,3);
4749 test_true(rc
== MEMCACHED_SUCCESS
);
4750 return post_udp_op_check(memc
,expected_ids
);
4753 static test_return_t
udp_quit_test(memcached_st
*memc
)
4755 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4756 memcached_quit(memc
);
4757 return post_udp_op_check(memc
, expected_ids
);
4760 static test_return_t
udp_flush_test(memcached_st
*memc
)
4762 memcached_return_t rc
;
4763 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4765 for (size_t x
= 0; x
< memcached_server_count(memc
); x
++)
4767 increment_request_id(&expected_ids
[x
]);
4770 rc
= memcached_flush(memc
,0);
4771 test_true(rc
== MEMCACHED_SUCCESS
);
4772 return post_udp_op_check(memc
,expected_ids
);
4775 static test_return_t
udp_incr_test(memcached_st
*memc
)
4777 memcached_return_t rc
;
4778 const char *key
= "incr";
4779 const char *value
= "1";
4780 rc
= memcached_set(memc
, key
, strlen(key
),
4781 value
, strlen(value
),
4782 (time_t)0, (uint32_t)0);
4784 test_true(rc
== MEMCACHED_SUCCESS
);
4785 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4786 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4787 increment_request_id(&expected_ids
[server_key
]);
4789 rc
= memcached_increment(memc
, key
, strlen(key
), 1, &newvalue
);
4790 test_true(rc
== MEMCACHED_SUCCESS
);
4791 return post_udp_op_check(memc
, expected_ids
);
4794 static test_return_t
udp_decr_test(memcached_st
*memc
)
4796 memcached_return_t rc
;
4797 const char *key
= "decr";
4798 const char *value
= "1";
4799 rc
= memcached_set(memc
, key
, strlen(key
),
4800 value
, strlen(value
),
4801 (time_t)0, (uint32_t)0);
4803 test_true(rc
== MEMCACHED_SUCCESS
);
4804 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4805 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4806 increment_request_id(&expected_ids
[server_key
]);
4808 rc
= memcached_decrement(memc
, key
, strlen(key
), 1, &newvalue
);
4809 test_true(rc
== MEMCACHED_SUCCESS
);
4810 return post_udp_op_check(memc
, expected_ids
);
4814 static test_return_t
udp_stat_test(memcached_st
*memc
)
4816 memcached_stat_st
* rv
= NULL
;
4817 memcached_return_t rc
;
4819 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4820 rv
= memcached_stat(memc
, args
, &rc
);
4822 test_true(rc
== MEMCACHED_NOT_SUPPORTED
);
4823 return post_udp_op_check(memc
, expected_ids
);
4826 static test_return_t
udp_version_test(memcached_st
*memc
)
4828 memcached_return_t rc
;
4829 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4830 rc
= memcached_version(memc
);
4831 test_true(rc
== MEMCACHED_NOT_SUPPORTED
);
4832 return post_udp_op_check(memc
, expected_ids
);
4835 static test_return_t
udp_get_test(memcached_st
*memc
)
4837 memcached_return_t rc
;
4838 const char *key
= "foo";
4840 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4841 char *val
= memcached_get(memc
, key
, strlen(key
), &vlen
, (uint32_t)0, &rc
);
4842 test_true(rc
== MEMCACHED_NOT_SUPPORTED
);
4843 test_true(val
== NULL
);
4844 return post_udp_op_check(memc
, expected_ids
);
4847 static test_return_t
udp_mixed_io_test(memcached_st
*memc
)
4850 test_st mixed_io_ops
[] ={
4852 (test_callback_fn
)udp_set_test
},
4853 {"udp_set_too_big_test", 0,
4854 (test_callback_fn
)udp_set_too_big_test
},
4855 {"udp_delete_test", 0,
4856 (test_callback_fn
)udp_delete_test
},
4857 {"udp_verbosity_test", 0,
4858 (test_callback_fn
)udp_verbosity_test
},
4859 {"udp_quit_test", 0,
4860 (test_callback_fn
)udp_quit_test
},
4861 {"udp_flush_test", 0,
4862 (test_callback_fn
)udp_flush_test
},
4863 {"udp_incr_test", 0,
4864 (test_callback_fn
)udp_incr_test
},
4865 {"udp_decr_test", 0,
4866 (test_callback_fn
)udp_decr_test
},
4867 {"udp_version_test", 0,
4868 (test_callback_fn
)udp_version_test
}
4870 for (size_t x
= 0; x
< 500; x
++)
4872 current_op
= mixed_io_ops
[random() % 9];
4873 test_true(current_op
.test_fn(memc
) == TEST_SUCCESS
);
4875 return TEST_SUCCESS
;
4879 static test_return_t
hash_sanity_test (memcached_st
*memc
)
4883 assert(MEMCACHED_HASH_DEFAULT
== MEMCACHED_HASH_DEFAULT
);
4884 assert(MEMCACHED_HASH_MD5
== MEMCACHED_HASH_MD5
);
4885 assert(MEMCACHED_HASH_CRC
== MEMCACHED_HASH_CRC
);
4886 assert(MEMCACHED_HASH_FNV1_64
== MEMCACHED_HASH_FNV1_64
);
4887 assert(MEMCACHED_HASH_FNV1A_64
== MEMCACHED_HASH_FNV1A_64
);
4888 assert(MEMCACHED_HASH_FNV1_32
== MEMCACHED_HASH_FNV1_32
);
4889 assert(MEMCACHED_HASH_FNV1A_32
== MEMCACHED_HASH_FNV1A_32
);
4890 #ifdef HAVE_HSIEH_HASH
4891 assert(MEMCACHED_HASH_HSIEH
== MEMCACHED_HASH_HSIEH
);
4893 assert(MEMCACHED_HASH_MURMUR
== MEMCACHED_HASH_MURMUR
);
4894 assert(MEMCACHED_HASH_JENKINS
== MEMCACHED_HASH_JENKINS
);
4895 assert(MEMCACHED_HASH_MAX
== MEMCACHED_HASH_MAX
);
4897 return TEST_SUCCESS
;
4901 static test_return_t
hsieh_avaibility_test (memcached_st
*memc
)
4903 memcached_return_t expected_rc
= MEMCACHED_FAILURE
;
4904 #ifdef HAVE_HSIEH_HASH
4905 expected_rc
= MEMCACHED_SUCCESS
;
4907 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
,
4908 (uint64_t)MEMCACHED_HASH_HSIEH
);
4909 test_true(rc
== expected_rc
);
4911 return TEST_SUCCESS
;
4914 static test_return_t
one_at_a_time_run (memcached_st
*memc
__attribute__((unused
)))
4919 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4923 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_DEFAULT
);
4924 test_true(one_at_a_time_values
[x
] == hash_val
);
4927 return TEST_SUCCESS
;
4930 static test_return_t
md5_run (memcached_st
*memc
__attribute__((unused
)))
4935 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4939 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MD5
);
4940 test_true(md5_values
[x
] == hash_val
);
4943 return TEST_SUCCESS
;
4946 static test_return_t
crc_run (memcached_st
*memc
__attribute__((unused
)))
4951 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4955 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_CRC
);
4956 test_true(crc_values
[x
] == hash_val
);
4959 return TEST_SUCCESS
;
4962 static test_return_t
fnv1_64_run (memcached_st
*memc
__attribute__((unused
)))
4967 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4971 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_64
);
4972 test_true(fnv1_64_values
[x
] == hash_val
);
4975 return TEST_SUCCESS
;
4978 static test_return_t
fnv1a_64_run (memcached_st
*memc
__attribute__((unused
)))
4983 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4987 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_64
);
4988 test_true(fnv1a_64_values
[x
] == hash_val
);
4991 return TEST_SUCCESS
;
4994 static test_return_t
fnv1_32_run (memcached_st
*memc
__attribute__((unused
)))
5000 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
5004 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_32
);
5005 test_true(fnv1_32_values
[x
] == hash_val
);
5008 return TEST_SUCCESS
;
5011 static test_return_t
fnv1a_32_run (memcached_st
*memc
__attribute__((unused
)))
5016 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
5020 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_32
);
5021 test_true(fnv1a_32_values
[x
] == hash_val
);
5024 return TEST_SUCCESS
;
5027 static test_return_t
hsieh_run (memcached_st
*memc
__attribute__((unused
)))
5032 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
5036 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_HSIEH
);
5037 test_true(hsieh_values
[x
] == hash_val
);
5040 return TEST_SUCCESS
;
5043 static test_return_t
murmur_run (memcached_st
*memc
__attribute__((unused
)))
5046 return TEST_SKIPPED
;
5051 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
5055 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MURMUR
);
5056 test_true(murmur_values
[x
] == hash_val
);
5059 return TEST_SUCCESS
;
5063 static test_return_t
jenkins_run (memcached_st
*memc
__attribute__((unused
)))
5069 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
5073 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_JENKINS
);
5074 test_true(jenkins_values
[x
] == hash_val
);
5077 return TEST_SUCCESS
;
5081 static test_return_t
ketama_compatibility_libmemcached(memcached_st
*trash
)
5083 memcached_return_t rc
;
5086 memcached_server_st
*server_pool
;
5091 memc
= memcached_create(NULL
);
5094 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
5095 test_true(rc
== MEMCACHED_SUCCESS
);
5097 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
5098 test_true(value
== 1);
5100 test_true(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
) == MEMCACHED_SUCCESS
);
5101 test_true(memcached_behavior_get_distribution(memc
) == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
);
5104 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");
5105 memcached_server_push(memc
, server_pool
);
5107 /* verify that the server list was parsed okay. */
5108 test_true(memcached_server_count(memc
) == 8);
5109 test_strcmp(server_pool
[0].hostname
, "10.0.1.1");
5110 test_true(server_pool
[0].port
== 11211);
5111 test_true(server_pool
[0].weight
== 600);
5112 test_strcmp(server_pool
[2].hostname
, "10.0.1.3");
5113 test_true(server_pool
[2].port
== 11211);
5114 test_true(server_pool
[2].weight
== 200);
5115 test_strcmp(server_pool
[7].hostname
, "10.0.1.8");
5116 test_true(server_pool
[7].port
== 11211);
5117 test_true(server_pool
[7].weight
== 100);
5119 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
5120 * us test the boundary wraparound.
5122 test_true(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
5124 /* verify the standard ketama set. */
5125 for (x
= 0; x
< 99; x
++)
5127 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
5128 memcached_server_instance_st
*instance
=
5129 memcached_server_instance_fetch(memc
, server_idx
);
5130 char *hostname
= instance
->hostname
;
5132 test_strcmp(hostname
, ketama_test_cases
[x
].server
);
5135 memcached_server_list_free(server_pool
);
5136 memcached_free(memc
);
5138 return TEST_SUCCESS
;
5141 static test_return_t
ketama_compatibility_spymemcached(memcached_st
*trash
)
5143 memcached_return_t rc
;
5146 memcached_server_st
*server_pool
;
5151 memc
= memcached_create(NULL
);
5154 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
5155 test_true(rc
== MEMCACHED_SUCCESS
);
5157 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
5158 test_true(value
== 1);
5160 test_true(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
) == MEMCACHED_SUCCESS
);
5161 test_true(memcached_behavior_get_distribution(memc
) == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
);
5163 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");
5164 memcached_server_push(memc
, server_pool
);
5166 /* verify that the server list was parsed okay. */
5167 test_true(memcached_server_count(memc
) == 8);
5168 test_strcmp(server_pool
[0].hostname
, "10.0.1.1");
5169 test_true(server_pool
[0].port
== 11211);
5170 test_true(server_pool
[0].weight
== 600);
5171 test_strcmp(server_pool
[2].hostname
, "10.0.1.3");
5172 test_true(server_pool
[2].port
== 11211);
5173 test_true(server_pool
[2].weight
== 200);
5174 test_strcmp(server_pool
[7].hostname
, "10.0.1.8");
5175 test_true(server_pool
[7].port
== 11211);
5176 test_true(server_pool
[7].weight
== 100);
5178 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
5179 * us test the boundary wraparound.
5181 test_true(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
5183 /* verify the standard ketama set. */
5184 for (x
= 0; x
< 99; x
++)
5186 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases_spy
[x
].key
, strlen(ketama_test_cases_spy
[x
].key
));
5187 memcached_server_instance_st
*instance
=
5188 memcached_server_instance_fetch(memc
, server_idx
);
5189 char *hostname
= instance
->hostname
;
5190 test_strcmp(hostname
, ketama_test_cases_spy
[x
].server
);
5193 memcached_server_list_free(server_pool
);
5194 memcached_free(memc
);
5196 return TEST_SUCCESS
;
5199 static test_return_t
regression_bug_434484(memcached_st
*memc
)
5201 test_return_t test_rc
;
5202 test_rc
= pre_binary(memc
);
5204 if (test_rc
!= TEST_SUCCESS
)
5207 memcached_return_t ret
;
5208 const char *key
= "regression_bug_434484";
5209 size_t keylen
= strlen(key
);
5211 ret
= memcached_append(memc
, key
, keylen
, key
, keylen
, 0, 0);
5212 test_true(ret
== MEMCACHED_NOTSTORED
);
5214 size_t size
= 2048 * 1024;
5215 void *data
= calloc(1, size
);
5216 test_true(data
!= NULL
);
5217 ret
= memcached_set(memc
, key
, keylen
, data
, size
, 0, 0);
5218 test_true(ret
== MEMCACHED_E2BIG
);
5221 return TEST_SUCCESS
;
5224 static test_return_t
regression_bug_434843(memcached_st
*memc
)
5226 test_return_t test_rc
;
5227 test_rc
= pre_binary(memc
);
5229 if (test_rc
!= TEST_SUCCESS
)
5232 memcached_return_t rc
;
5234 memcached_execute_fn callbacks
[1]= { [0]= &callback_counter
};
5237 * I only want to hit only _one_ server so I know the number of requests I'm
5238 * sending in the pipleine to the server. Let's try to do a multiget of
5239 * 1024 (that should satisfy most users don't you think?). Future versions
5240 * will include a mget_execute function call if you need a higher number.
5242 uint32_t number_of_hosts
= memcached_server_count(memc
);
5243 memc
->number_of_hosts
= 1;
5244 const size_t max_keys
= 1024;
5245 char **keys
= calloc(max_keys
, sizeof(char*));
5246 size_t *key_length
=calloc(max_keys
, sizeof(size_t));
5248 for (size_t x
= 0; x
< max_keys
; ++x
)
5252 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%zu", x
);
5254 test_true(keys
[x
] != NULL
);
5258 * Run two times.. the first time we should have 100% cache miss,
5259 * and the second time we should have 100% cache hits
5261 for (size_t y
= 0; y
< 2; y
++)
5263 rc
= memcached_mget(memc
, (const char**)keys
, key_length
, max_keys
);
5264 test_true(rc
== MEMCACHED_SUCCESS
);
5265 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5269 /* The first iteration should give me a 100% cache miss. verify that*/
5270 char blob
[1024]= { 0 };
5272 test_true(counter
== 0);
5274 for (size_t x
= 0; x
< max_keys
; ++x
)
5276 rc
= memcached_add(memc
, keys
[x
], key_length
[x
],
5277 blob
, sizeof(blob
), 0, 0);
5278 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5283 /* Verify that we received all of the key/value pairs */
5284 test_true(counter
== max_keys
);
5288 /* Release allocated resources */
5289 for (size_t x
= 0; x
< max_keys
; ++x
)
5296 memc
->number_of_hosts
= number_of_hosts
;
5298 return TEST_SUCCESS
;
5301 static test_return_t
regression_bug_434843_buffered(memcached_st
*memc
)
5303 memcached_return_t rc
;
5304 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
5305 test_true(rc
== MEMCACHED_SUCCESS
);
5307 return regression_bug_434843(memc
);
5310 static test_return_t
regression_bug_421108(memcached_st
*memc
)
5312 memcached_return_t rc
;
5313 memcached_stat_st
*memc_stat
= memcached_stat(memc
, NULL
, &rc
);
5314 test_true(rc
== MEMCACHED_SUCCESS
);
5316 char *bytes
= memcached_stat_get_value(memc
, memc_stat
, "bytes", &rc
);
5317 test_true(rc
== MEMCACHED_SUCCESS
);
5318 test_true(bytes
!= NULL
);
5319 char *bytes_read
= memcached_stat_get_value(memc
, memc_stat
,
5321 test_true(rc
== MEMCACHED_SUCCESS
);
5322 test_true(bytes_read
!= NULL
);
5324 char *bytes_written
= memcached_stat_get_value(memc
, memc_stat
,
5325 "bytes_written", &rc
);
5326 test_true(rc
== MEMCACHED_SUCCESS
);
5327 test_true(bytes_written
!= NULL
);
5329 test_true(strcmp(bytes
, bytes_read
) != 0);
5330 test_true(strcmp(bytes
, bytes_written
) != 0);
5332 /* Release allocated resources */
5335 free(bytes_written
);
5336 memcached_stat_free(NULL
, memc_stat
);
5338 return TEST_SUCCESS
;
5342 * The test case isn't obvious so I should probably document why
5343 * it works the way it does. Bug 442914 was caused by a bug
5344 * in the logic in memcached_purge (it did not handle the case
5345 * where the number of bytes sent was equal to the watermark).
5346 * In this test case, create messages so that we hit that case
5347 * and then disable noreply mode and issue a new command to
5348 * verify that it isn't stuck. If we change the format for the
5349 * delete command or the watermarks, we need to update this
5352 static test_return_t
regression_bug_442914(memcached_st
*memc
)
5354 memcached_return_t rc
;
5355 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
5356 test_true(rc
== MEMCACHED_SUCCESS
);
5357 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1);
5359 uint32_t number_of_hosts
= memcached_server_count(memc
);
5360 memc
->number_of_hosts
= 1;
5365 for (uint32_t x
= 0; x
< 250; ++x
)
5367 len
= (size_t)snprintf(k
, sizeof(k
), "%0250u", x
);
5368 rc
= memcached_delete(memc
, k
, len
, 0);
5369 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5372 (void)snprintf(k
, sizeof(k
), "%037u", 251U);
5375 rc
= memcached_delete(memc
, k
, len
, 0);
5376 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5378 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0);
5379 test_true(rc
== MEMCACHED_SUCCESS
);
5380 rc
= memcached_delete(memc
, k
, len
, 0);
5381 test_true(rc
== MEMCACHED_NOTFOUND
);
5383 memc
->number_of_hosts
= number_of_hosts
;
5385 return TEST_SUCCESS
;
5388 static test_return_t
regression_bug_447342(memcached_st
*memc
)
5390 memcached_server_instance_st
*instance_one
;
5391 memcached_server_instance_st
*instance_two
;
5393 if (memcached_server_count(memc
) < 3 || pre_replication(memc
) != MEMCACHED_SUCCESS
)
5394 return TEST_SKIPPED
;
5396 memcached_return_t rc
;
5398 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 2);
5399 test_true(rc
== MEMCACHED_SUCCESS
);
5401 const size_t max_keys
= 100;
5402 char **keys
= calloc(max_keys
, sizeof(char*));
5403 size_t *key_length
= calloc(max_keys
, sizeof(size_t));
5405 for (size_t x
= 0; x
< max_keys
; ++x
)
5409 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%zu", x
);
5411 test_true(keys
[x
] != NULL
);
5412 rc
= memcached_set(memc
, k
, key_length
[x
], k
, key_length
[x
], 0, 0);
5413 test_true(rc
== MEMCACHED_SUCCESS
);
5417 ** We are using the quiet commands to store the replicas, so we need
5418 ** to ensure that all of them are processed before we can continue.
5419 ** In the test we go directly from storing the object to trying to
5420 ** receive the object from all of the different servers, so we
5421 ** could end up in a race condition (the memcached server hasn't yet
5422 ** processed the quiet command from the replication set when it process
5423 ** the request from the other client (created by the clone)). As a
5424 ** workaround for that we call memcached_quit to send the quit command
5425 ** to the server and wait for the response ;-) If you use the test code
5426 ** as an example for your own code, please note that you shouldn't need
5429 memcached_quit(memc
);
5431 /* Verify that all messages are stored, and we didn't stuff too much
5434 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5435 test_true(rc
== MEMCACHED_SUCCESS
);
5438 memcached_execute_fn callbacks
[1]= { [0]= &callback_counter
};
5439 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5440 /* Verify that we received all of the key/value pairs */
5441 test_true(counter
== max_keys
);
5443 memcached_quit(memc
);
5445 * Don't do the following in your code. I am abusing the internal details
5446 * within the library, and this is not a supported interface.
5447 * This is to verify correct behavior in the library. Fake that two servers
5450 instance_one
= memcached_server_instance_fetch(memc
, 0);
5451 instance_two
= memcached_server_instance_fetch(memc
, 2);
5452 in_port_t port0
= instance_one
->port
;
5453 in_port_t port2
= instance_two
->port
;
5455 instance_one
->port
= 0;
5456 instance_two
->port
= 0;
5458 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5459 test_true(rc
== MEMCACHED_SUCCESS
);
5462 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5463 test_true(counter
== (unsigned int)max_keys
);
5465 /* restore the memc handle */
5466 instance_one
->port
= port0
;
5467 instance_two
->port
= port2
;
5469 memcached_quit(memc
);
5471 /* Remove half of the objects */
5472 for (size_t x
= 0; x
< max_keys
; ++x
)
5476 rc
= memcached_delete(memc
, keys
[x
], key_length
[x
], 0);
5477 test_true(rc
== MEMCACHED_SUCCESS
);
5481 memcached_quit(memc
);
5482 instance_one
->port
= 0;
5483 instance_two
->port
= 0;
5485 /* now retry the command, this time we should have cache misses */
5486 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5487 test_true(rc
== MEMCACHED_SUCCESS
);
5490 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5491 test_true(counter
== (unsigned int)(max_keys
>> 1));
5493 /* Release allocated resources */
5494 for (size_t x
= 0; x
< max_keys
; ++x
)
5501 /* restore the memc handle */
5502 instance_one
->port
= port0
;
5503 instance_two
->port
= port2
;
5505 return TEST_SUCCESS
;
5508 static test_return_t
regression_bug_463297(memcached_st
*memc
)
5510 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
5511 test_true(memc_clone
!= NULL
);
5512 test_true(memcached_version(memc_clone
) == MEMCACHED_SUCCESS
);
5514 memcached_server_instance_st
*instance
=
5515 memcached_server_instance_fetch(memc_clone
, 0);
5517 if (instance
->major_version
> 1 ||
5518 (instance
->major_version
== 1 &&
5519 instance
->minor_version
> 2))
5521 /* Binary protocol doesn't support deferred delete */
5522 memcached_st
*bin_clone
= memcached_clone(NULL
, memc
);
5523 test_true(bin_clone
!= NULL
);
5524 test_true(memcached_behavior_set(bin_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1) == MEMCACHED_SUCCESS
);
5525 test_true(memcached_delete(bin_clone
, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS
);
5526 memcached_free(bin_clone
);
5528 memcached_quit(memc_clone
);
5530 /* If we know the server version, deferred delete should fail
5531 * with invalid arguments */
5532 test_true(memcached_delete(memc_clone
, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS
);
5534 /* If we don't know the server version, we should get a protocol error */
5535 memcached_return_t rc
= memcached_delete(memc
, "foo", 3, 1);
5537 /* but there is a bug in some of the memcached servers (1.4) that treats
5538 * the counter as noreply so it doesn't send the proper error message
5540 test_true(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5542 /* And buffered mode should be disabled and we should get protocol error */
5543 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1) == MEMCACHED_SUCCESS
);
5544 rc
= memcached_delete(memc
, "foo", 3, 1);
5545 test_true(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5547 /* Same goes for noreply... */
5548 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1) == MEMCACHED_SUCCESS
);
5549 rc
= memcached_delete(memc
, "foo", 3, 1);
5550 test_true(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5552 /* but a normal request should go through (and be buffered) */
5553 test_true((rc
= memcached_delete(memc
, "foo", 3, 0)) == MEMCACHED_BUFFERED
);
5554 test_true(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
5556 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 0) == MEMCACHED_SUCCESS
);
5557 /* unbuffered noreply should be success */
5558 test_true(memcached_delete(memc
, "foo", 3, 0) == MEMCACHED_SUCCESS
);
5559 /* unbuffered with reply should be not found... */
5560 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0) == MEMCACHED_SUCCESS
);
5561 test_true(memcached_delete(memc
, "foo", 3, 0) == MEMCACHED_NOTFOUND
);
5564 memcached_free(memc_clone
);
5565 return TEST_SUCCESS
;
5569 /* Test memcached_server_get_last_disconnect
5570 * For a working server set, shall be NULL
5571 * For a set of non existing server, shall not be NULL
5573 static test_return_t
test_get_last_disconnect(memcached_st
*memc
)
5575 memcached_return_t rc
;
5576 memcached_server_st
*disconnected_server
;
5578 /* With the working set of server */
5579 const char *key
= "marmotte";
5580 const char *value
= "milka";
5582 rc
= memcached_set(memc
, key
, strlen(key
),
5583 value
, strlen(value
),
5584 (time_t)0, (uint32_t)0);
5585 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5587 disconnected_server
= memcached_server_get_last_disconnect(memc
);
5588 test_true(disconnected_server
== NULL
);
5590 /* With a non existing server */
5592 memcached_server_st
*servers
;
5594 const char *server_list
= "localhost:9";
5596 servers
= memcached_servers_parse(server_list
);
5598 mine
= memcached_create(NULL
);
5599 rc
= memcached_server_push(mine
, servers
);
5600 test_true(rc
== MEMCACHED_SUCCESS
);
5601 memcached_server_list_free(servers
);
5604 rc
= memcached_set(mine
, key
, strlen(key
),
5605 value
, strlen(value
),
5606 (time_t)0, (uint32_t)0);
5607 test_true(rc
!= MEMCACHED_SUCCESS
);
5609 disconnected_server
= memcached_server_get_last_disconnect(mine
);
5610 test_true(disconnected_server
!= NULL
);
5611 test_true(disconnected_server
->port
== 9);
5612 test_true(strncmp(disconnected_server
->hostname
,"localhost",9) == 0);
5614 memcached_quit(mine
);
5615 memcached_free(mine
);
5617 return TEST_SUCCESS
;
5621 * This test ensures that the failure counter isn't incremented during
5622 * normal termination of the memcached instance.
5624 static test_return_t
wrong_failure_counter_test(memcached_st
*memc
)
5626 memcached_return_t rc
;
5627 memcached_server_instance_st
*instance
;
5629 /* Set value to force connection to the server */
5630 const char *key
= "marmotte";
5631 const char *value
= "milka";
5634 * Please note that I'm abusing the internal structures in libmemcached
5635 * in a non-portable way and you shouldn't be doing this. I'm only
5636 * doing this in order to verify that the library works the way it should
5638 uint32_t number_of_hosts
= memcached_server_count(memc
);
5639 memc
->number_of_hosts
= 1;
5641 /* Ensure that we are connected to the server by setting a value */
5642 rc
= memcached_set(memc
, key
, strlen(key
),
5643 value
, strlen(value
),
5644 (time_t)0, (uint32_t)0);
5645 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5648 instance
= memcached_server_instance_fetch(memc
, 0);
5649 /* The test is to see that the memcached_quit doesn't increase the
5650 * the server failure conter, so let's ensure that it is zero
5651 * before sending quit
5653 instance
->server_failure_counter
= 0;
5655 memcached_quit(memc
);
5657 /* Verify that it memcached_quit didn't increment the failure counter
5658 * Please note that this isn't bullet proof, because an error could
5661 test_true(instance
->server_failure_counter
== 0);
5663 /* restore the instance */
5664 memc
->number_of_hosts
= number_of_hosts
;
5666 return TEST_SUCCESS
;
5673 * Test that ensures mget_execute does not end into recursive calls that finally fails
5675 static test_return_t
regression_bug_490486(memcached_st
*memc
)
5677 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
5678 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 1);
5679 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, 1000);
5680 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, 1);
5681 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 3600);
5684 * I only want to hit _one_ server so I know the number of requests I'm
5685 * sending in the pipeline.
5687 uint32_t number_of_hosts
= memc
->number_of_hosts
;
5688 memc
->number_of_hosts
= 1;
5689 size_t max_keys
= 20480;
5692 char **keys
= calloc(max_keys
, sizeof(char*));
5693 size_t *key_length
=calloc(max_keys
, sizeof(size_t));
5695 /* First add all of the items.. */
5696 char blob
[1024]= { 0 };
5697 memcached_return rc
;
5698 for (size_t x
= 0; x
< max_keys
; ++x
)
5701 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%zu", x
);
5703 assert(keys
[x
] != NULL
);
5704 rc
= memcached_set(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
5705 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5708 /* Try to get all of them with a large multiget */
5710 memcached_execute_function callbacks
[1]= { [0]= &callback_counter
};
5711 rc
= memcached_mget_execute(memc
, (const char**)keys
, key_length
,
5712 (size_t)max_keys
, callbacks
, &counter
, 1);
5714 assert(rc
== MEMCACHED_SUCCESS
);
5715 char* the_value
= NULL
;
5716 char the_key
[MEMCACHED_MAX_KEY
];
5717 size_t the_key_length
;
5718 size_t the_value_length
;
5722 the_value
= memcached_fetch(memc
, the_key
, &the_key_length
, &the_value_length
, &the_flags
, &rc
);
5724 if ((the_value
!= NULL
) && (rc
== MEMCACHED_SUCCESS
))
5730 } while ( (the_value
!= NULL
) && (rc
== MEMCACHED_SUCCESS
));
5733 assert(rc
== MEMCACHED_END
);
5735 /* Verify that we got all of the items */
5736 assert(counter
== max_keys
);
5738 /* Release all allocated resources */
5739 for (size_t x
= 0; x
< max_keys
; ++x
)
5746 memc
->number_of_hosts
= number_of_hosts
;
5748 return TEST_SUCCESS
;
5754 test_st udp_setup_server_tests
[] ={
5755 {"set_udp_behavior_test", 0, (test_callback_fn
)set_udp_behavior_test
},
5756 {"add_tcp_server_udp_client_test", 0, (test_callback_fn
)add_tcp_server_udp_client_test
},
5757 {"add_udp_server_tcp_client_test", 0, (test_callback_fn
)add_udp_server_tcp_client_test
},
5761 test_st upd_io_tests
[] ={
5762 {"udp_set_test", 0, (test_callback_fn
)udp_set_test
},
5763 {"udp_buffered_set_test", 0, (test_callback_fn
)udp_buffered_set_test
},
5764 {"udp_set_too_big_test", 0, (test_callback_fn
)udp_set_too_big_test
},
5765 {"udp_delete_test", 0, (test_callback_fn
)udp_delete_test
},
5766 {"udp_buffered_delete_test", 0, (test_callback_fn
)udp_buffered_delete_test
},
5767 {"udp_verbosity_test", 0, (test_callback_fn
)udp_verbosity_test
},
5768 {"udp_quit_test", 0, (test_callback_fn
)udp_quit_test
},
5769 {"udp_flush_test", 0, (test_callback_fn
)udp_flush_test
},
5770 {"udp_incr_test", 0, (test_callback_fn
)udp_incr_test
},
5771 {"udp_decr_test", 0, (test_callback_fn
)udp_decr_test
},
5772 {"udp_stat_test", 0, (test_callback_fn
)udp_stat_test
},
5773 {"udp_version_test", 0, (test_callback_fn
)udp_version_test
},
5774 {"udp_get_test", 0, (test_callback_fn
)udp_get_test
},
5775 {"udp_mixed_io_test", 0, (test_callback_fn
)udp_mixed_io_test
},
5779 /* Clean the server before beginning testing */
5781 {"flush", 0, (test_callback_fn
)flush_test
},
5782 {"init", 0, (test_callback_fn
)init_test
},
5783 {"allocation", 0, (test_callback_fn
)allocation_test
},
5784 {"server_list_null_test", 0, (test_callback_fn
)server_list_null_test
},
5785 {"server_unsort", 0, (test_callback_fn
)server_unsort_test
},
5786 {"server_sort", 0, (test_callback_fn
)server_sort_test
},
5787 {"server_sort2", 0, (test_callback_fn
)server_sort2_test
},
5788 {"clone_test", 0, (test_callback_fn
)clone_test
},
5789 {"connection_test", 0, (test_callback_fn
)connection_test
},
5790 {"callback_test", 0, (test_callback_fn
)callback_test
},
5791 {"userdata_test", 0, (test_callback_fn
)userdata_test
},
5792 {"error", 0, (test_callback_fn
)error_test
},
5793 {"set", 0, (test_callback_fn
)set_test
},
5794 {"set2", 0, (test_callback_fn
)set_test2
},
5795 {"set3", 0, (test_callback_fn
)set_test3
},
5796 {"dump", 1, (test_callback_fn
)dump_test
},
5797 {"add", 1, (test_callback_fn
)add_test
},
5798 {"replace", 1, (test_callback_fn
)replace_test
},
5799 {"delete", 1, (test_callback_fn
)delete_test
},
5800 {"get", 1, (test_callback_fn
)get_test
},
5801 {"get2", 0, (test_callback_fn
)get_test2
},
5802 {"get3", 0, (test_callback_fn
)get_test3
},
5803 {"get4", 0, (test_callback_fn
)get_test4
},
5804 {"partial mget", 0, (test_callback_fn
)get_test5
},
5805 {"stats_servername", 0, (test_callback_fn
)stats_servername_test
},
5806 {"increment", 0, (test_callback_fn
)increment_test
},
5807 {"increment_with_initial", 1, (test_callback_fn
)increment_with_initial_test
},
5808 {"decrement", 0, (test_callback_fn
)decrement_test
},
5809 {"decrement_with_initial", 1, (test_callback_fn
)decrement_with_initial_test
},
5810 {"increment_by_key", 0, (test_callback_fn
)increment_by_key_test
},
5811 {"increment_with_initial_by_key", 1, (test_callback_fn
)increment_with_initial_by_key_test
},
5812 {"decrement_by_key", 0, (test_callback_fn
)decrement_by_key_test
},
5813 {"decrement_with_initial_by_key", 1, (test_callback_fn
)decrement_with_initial_by_key_test
},
5814 {"quit", 0, (test_callback_fn
)quit_test
},
5815 {"mget", 1, (test_callback_fn
)mget_test
},
5816 {"mget_result", 1, (test_callback_fn
)mget_result_test
},
5817 {"mget_result_alloc", 1, (test_callback_fn
)mget_result_alloc_test
},
5818 {"mget_result_function", 1, (test_callback_fn
)mget_result_function
},
5819 {"mget_execute", 1, (test_callback_fn
)mget_execute
},
5820 {"mget_end", 0, (test_callback_fn
)mget_end
},
5821 {"get_stats", 0, (test_callback_fn
)get_stats
},
5822 {"add_host_test", 0, (test_callback_fn
)add_host_test
},
5823 {"add_host_test_1", 0, (test_callback_fn
)add_host_test1
},
5824 {"get_stats_keys", 0, (test_callback_fn
)get_stats_keys
},
5825 {"version_string_test", 0, (test_callback_fn
)version_string_test
},
5826 {"bad_key", 1, (test_callback_fn
)bad_key_test
},
5827 {"memcached_server_cursor", 1, (test_callback_fn
)memcached_server_cursor_test
},
5828 {"read_through", 1, (test_callback_fn
)read_through
},
5829 {"delete_through", 1, (test_callback_fn
)delete_through
},
5830 {"noreply", 1, (test_callback_fn
)noreply_test
},
5831 {"analyzer", 1, (test_callback_fn
)analyzer_test
},
5832 #ifdef HAVE_LIBMEMCACHEDUTIL
5833 {"connectionpool", 1, (test_callback_fn
)connection_pool_test
},
5835 {"test_get_last_disconnect", 1, (test_callback_fn
)test_get_last_disconnect
},
5839 test_st behavior_tests
[] ={
5840 {"behavior_test", 0, (test_callback_fn
)behavior_test
},
5841 {"MEMCACHED_BEHAVIOR_CORK", 0, (test_callback_fn
)MEMCACHED_BEHAVIOR_CORK_test
},
5845 test_st async_tests
[] ={
5846 {"add", 1, (test_callback_fn
)add_wrapper
},
5850 test_st string_tests
[] ={
5851 {"string static with null", 0, (test_callback_fn
)string_static_null
},
5852 {"string alloc with null", 0, (test_callback_fn
)string_alloc_null
},
5853 {"string alloc with 1K", 0, (test_callback_fn
)string_alloc_with_size
},
5854 {"string alloc with malloc failure", 0, (test_callback_fn
)string_alloc_with_size_toobig
},
5855 {"string append", 0, (test_callback_fn
)string_alloc_append
},
5856 {"string append failure (too big)", 0, (test_callback_fn
)string_alloc_append_toobig
},
5857 {0, 0, (test_callback_fn
)0}
5860 test_st result_tests
[] ={
5861 {"result static", 0, (test_callback_fn
)result_static
},
5862 {"result alloc", 0, (test_callback_fn
)result_alloc
},
5863 {0, 0, (test_callback_fn
)0}
5866 test_st version_1_2_3
[] ={
5867 {"append", 0, (test_callback_fn
)append_test
},
5868 {"prepend", 0, (test_callback_fn
)prepend_test
},
5869 {"cas", 0, (test_callback_fn
)cas_test
},
5870 {"cas2", 0, (test_callback_fn
)cas2_test
},
5871 {"append_binary", 0, (test_callback_fn
)append_binary_test
},
5872 {0, 0, (test_callback_fn
)0}
5875 test_st user_tests
[] ={
5876 {"user_supplied_bug1", 0, (test_callback_fn
)user_supplied_bug1
},
5877 {"user_supplied_bug2", 0, (test_callback_fn
)user_supplied_bug2
},
5878 {"user_supplied_bug3", 0, (test_callback_fn
)user_supplied_bug3
},
5879 {"user_supplied_bug4", 0, (test_callback_fn
)user_supplied_bug4
},
5880 {"user_supplied_bug5", 1, (test_callback_fn
)user_supplied_bug5
},
5881 {"user_supplied_bug6", 1, (test_callback_fn
)user_supplied_bug6
},
5882 {"user_supplied_bug7", 1, (test_callback_fn
)user_supplied_bug7
},
5883 {"user_supplied_bug8", 1, (test_callback_fn
)user_supplied_bug8
},
5884 {"user_supplied_bug9", 1, (test_callback_fn
)user_supplied_bug9
},
5885 {"user_supplied_bug10", 1, (test_callback_fn
)user_supplied_bug10
},
5886 {"user_supplied_bug11", 1, (test_callback_fn
)user_supplied_bug11
},
5887 {"user_supplied_bug12", 1, (test_callback_fn
)user_supplied_bug12
},
5888 {"user_supplied_bug13", 1, (test_callback_fn
)user_supplied_bug13
},
5889 {"user_supplied_bug14", 1, (test_callback_fn
)user_supplied_bug14
},
5890 {"user_supplied_bug15", 1, (test_callback_fn
)user_supplied_bug15
},
5891 {"user_supplied_bug16", 1, (test_callback_fn
)user_supplied_bug16
},
5894 ** It seems to be something weird with the character sets..
5895 ** value_fetch is unable to parse the value line (iscntrl "fails"), so I
5896 ** guess I need to find out how this is supposed to work.. Perhaps I need
5897 ** to run the test in a specific locale (I tried zh_CN.UTF-8 without success,
5898 ** so just disable the code for now...).
5900 {"user_supplied_bug17", 1, (test_callback_fn
)user_supplied_bug17
},
5902 {"user_supplied_bug18", 1, (test_callback_fn
)user_supplied_bug18
},
5903 {"user_supplied_bug19", 1, (test_callback_fn
)user_supplied_bug19
},
5904 {"user_supplied_bug20", 1, (test_callback_fn
)user_supplied_bug20
},
5905 {"user_supplied_bug21", 1, (test_callback_fn
)user_supplied_bug21
},
5906 {"wrong_failure_counter_test", 1, (test_callback_fn
)wrong_failure_counter_test
},
5907 {0, 0, (test_callback_fn
)0}
5910 test_st replication_tests
[]= {
5911 {"set", 1, (test_callback_fn
)replication_set_test
},
5912 {"get", 0, (test_callback_fn
)replication_get_test
},
5913 {"mget", 0, (test_callback_fn
)replication_mget_test
},
5914 {"delete", 0, (test_callback_fn
)replication_delete_test
},
5915 {"rand_mget", 0, (test_callback_fn
)replication_randomize_mget_test
},
5916 {0, 0, (test_callback_fn
)0}
5920 * The following test suite is used to verify that we don't introduce
5921 * regression bugs. If you want more information about the bug / test,
5922 * you should look in the bug report at
5923 * http://bugs.launchpad.net/libmemcached
5925 test_st regression_tests
[]= {
5926 {"lp:434484", 1, (test_callback_fn
)regression_bug_434484
},
5927 {"lp:434843", 1, (test_callback_fn
)regression_bug_434843
},
5928 {"lp:434843 buffered", 1, (test_callback_fn
)regression_bug_434843_buffered
},
5929 {"lp:421108", 1, (test_callback_fn
)regression_bug_421108
},
5930 {"lp:442914", 1, (test_callback_fn
)regression_bug_442914
},
5931 {"lp:447342", 1, (test_callback_fn
)regression_bug_447342
},
5932 {"lp:463297", 1, (test_callback_fn
)regression_bug_463297
},
5933 {"lp:490486", 1, (test_callback_fn
)regression_bug_490486
},
5934 {0, 0, (test_callback_fn
)0}
5937 test_st ketama_compatibility
[]= {
5938 {"libmemcached", 1, (test_callback_fn
)ketama_compatibility_libmemcached
},
5939 {"spymemcached", 1, (test_callback_fn
)ketama_compatibility_spymemcached
},
5940 {0, 0, (test_callback_fn
)0}
5943 test_st generate_tests
[] ={
5944 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
5945 {"generate_data", 1, (test_callback_fn
)generate_data
},
5946 {"get_read", 0, (test_callback_fn
)get_read
},
5947 {"delete_generate", 0, (test_callback_fn
)delete_generate
},
5948 {"generate_buffer_data", 1, (test_callback_fn
)generate_buffer_data
},
5949 {"delete_buffer", 0, (test_callback_fn
)delete_buffer_generate
},
5950 {"generate_data", 1, (test_callback_fn
)generate_data
},
5951 {"mget_read", 0, (test_callback_fn
)mget_read
},
5952 {"mget_read_result", 0, (test_callback_fn
)mget_read_result
},
5953 {"mget_read_function", 0, (test_callback_fn
)mget_read_function
},
5954 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5955 {"generate_large_pairs", 1, (test_callback_fn
)generate_large_pairs
},
5956 {"generate_data", 1, (test_callback_fn
)generate_data
},
5957 {"generate_buffer_data", 1, (test_callback_fn
)generate_buffer_data
},
5958 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5959 {0, 0, (test_callback_fn
)0}
5962 test_st consistent_tests
[] ={
5963 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
5964 {"generate_data", 1, (test_callback_fn
)generate_data
},
5965 {"get_read", 0, (test_callback_fn
)get_read_count
},
5966 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5967 {0, 0, (test_callback_fn
)0}
5970 test_st consistent_weighted_tests
[] ={
5971 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
5972 {"generate_data", 1, (test_callback_fn
)generate_data_with_stats
},
5973 {"get_read", 0, (test_callback_fn
)get_read_count
},
5974 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5975 {0, 0, (test_callback_fn
)0}
5978 test_st hsieh_availability
[] ={
5979 {"hsieh_avaibility_test", 0, (test_callback_fn
)hsieh_avaibility_test
},
5980 {0, 0, (test_callback_fn
)0}
5984 test_st hash_sanity
[] ={
5985 {"hash sanity", 0, (test_callback_fn
)hash_sanity_test
},
5986 {0, 0, (test_callback_fn
)0}
5990 test_st ketama_auto_eject_hosts
[] ={
5991 {"auto_eject_hosts", 1, (test_callback_fn
)auto_eject_hosts
},
5992 {"output_ketama_weighted_keys", 1, (test_callback_fn
)output_ketama_weighted_keys
},
5993 {0, 0, (test_callback_fn
)0}
5996 test_st hash_tests
[] ={
5997 {"one_at_a_time_run", 0, (test_callback_fn
)one_at_a_time_run
},
5998 {"md5", 0, (test_callback_fn
)md5_run
},
5999 {"crc", 0, (test_callback_fn
)crc_run
},
6000 {"fnv1_64", 0, (test_callback_fn
)fnv1_64_run
},
6001 {"fnv1a_64", 0, (test_callback_fn
)fnv1a_64_run
},
6002 {"fnv1_32", 0, (test_callback_fn
)fnv1_32_run
},
6003 {"fnv1a_32", 0, (test_callback_fn
)fnv1a_32_run
},
6004 {"hsieh", 0, (test_callback_fn
)hsieh_run
},
6005 {"murmur", 0, (test_callback_fn
)murmur_run
},
6006 {"jenkis", 0, (test_callback_fn
)jenkins_run
},
6007 {0, 0, (test_callback_fn
)0}
6010 collection_st collection
[] ={
6012 {"hash_sanity", 0, 0, hash_sanity
},
6014 {"hsieh_availability", 0, 0, hsieh_availability
},
6015 {"udp_setup", (test_callback_fn
)init_udp
, 0, udp_setup_server_tests
},
6016 {"udp_io", (test_callback_fn
)init_udp
, 0, upd_io_tests
},
6017 {"udp_binary_io", (test_callback_fn
)binary_init_udp
, 0, upd_io_tests
},
6018 {"block", 0, 0, tests
},
6019 {"binary", (test_callback_fn
)pre_binary
, 0, tests
},
6020 {"nonblock", (test_callback_fn
)pre_nonblock
, 0, tests
},
6021 {"nodelay", (test_callback_fn
)pre_nodelay
, 0, tests
},
6022 {"settimer", (test_callback_fn
)pre_settimer
, 0, tests
},
6023 {"md5", (test_callback_fn
)pre_md5
, 0, tests
},
6024 {"crc", (test_callback_fn
)pre_crc
, 0, tests
},
6025 {"hsieh", (test_callback_fn
)pre_hsieh
, 0, tests
},
6026 {"jenkins", (test_callback_fn
)pre_jenkins
, 0, tests
},
6027 {"fnv1_64", (test_callback_fn
)pre_hash_fnv1_64
, 0, tests
},
6028 {"fnv1a_64", (test_callback_fn
)pre_hash_fnv1a_64
, 0, tests
},
6029 {"fnv1_32", (test_callback_fn
)pre_hash_fnv1_32
, 0, tests
},
6030 {"fnv1a_32", (test_callback_fn
)pre_hash_fnv1a_32
, 0, tests
},
6031 {"ketama", (test_callback_fn
)pre_behavior_ketama
, 0, tests
},
6032 {"ketama_auto_eject_hosts", (test_callback_fn
)pre_behavior_ketama
, 0, ketama_auto_eject_hosts
},
6033 {"unix_socket", (test_callback_fn
)pre_unix_socket
, 0, tests
},
6034 {"unix_socket_nodelay", (test_callback_fn
)pre_nodelay
, 0, tests
},
6035 {"poll_timeout", (test_callback_fn
)poll_timeout
, 0, tests
},
6036 {"gets", (test_callback_fn
)enable_cas
, 0, tests
},
6037 {"consistent_crc", (test_callback_fn
)enable_consistent_crc
, 0, tests
},
6038 {"consistent_hsieh", (test_callback_fn
)enable_consistent_hsieh
, 0, tests
},
6039 #ifdef MEMCACHED_ENABLE_DEPRECATED
6040 {"deprecated_memory_allocators", (test_callback_fn
)deprecated_set_memory_alloc
, 0, tests
},
6042 {"memory_allocators", (test_callback_fn
)set_memory_alloc
, 0, tests
},
6043 {"prefix", (test_callback_fn
)set_prefix
, 0, tests
},
6044 {"version_1_2_3", (test_callback_fn
)check_for_1_2_3
, 0, version_1_2_3
},
6045 {"string", 0, 0, string_tests
},
6046 {"result", 0, 0, result_tests
},
6047 {"async", (test_callback_fn
)pre_nonblock
, 0, async_tests
},
6048 {"async_binary", (test_callback_fn
)pre_nonblock_binary
, 0, async_tests
},
6049 {"user", 0, 0, user_tests
},
6050 {"generate", 0, 0, generate_tests
},
6051 {"generate_hsieh", (test_callback_fn
)pre_hsieh
, 0, generate_tests
},
6052 {"generate_ketama", (test_callback_fn
)pre_behavior_ketama
, 0, generate_tests
},
6053 {"generate_hsieh_consistent", (test_callback_fn
)enable_consistent_hsieh
, 0, generate_tests
},
6054 {"generate_md5", (test_callback_fn
)pre_md5
, 0, generate_tests
},
6055 {"generate_murmur", (test_callback_fn
)pre_murmur
, 0, generate_tests
},
6056 {"generate_jenkins", (test_callback_fn
)pre_jenkins
, 0, generate_tests
},
6057 {"generate_nonblock", (test_callback_fn
)pre_nonblock
, 0, generate_tests
},
6059 {"generate_corked", (test_callback_fn
)pre_cork
, 0, generate_tests
},
6060 {"generate_corked_and_nonblock", (test_callback_fn
)pre_cork_and_nonblock
, 0, generate_tests
},
6061 {"consistent_not", 0, 0, consistent_tests
},
6062 {"consistent_ketama", (test_callback_fn
)pre_behavior_ketama
, 0, consistent_tests
},
6063 {"consistent_ketama_weighted", (test_callback_fn
)pre_behavior_ketama_weighted
, 0, consistent_weighted_tests
},
6064 {"ketama_compat", 0, 0, ketama_compatibility
},
6065 {"test_hashes", 0, 0, hash_tests
},
6066 {"replication", (test_callback_fn
)pre_replication
, 0, replication_tests
},
6067 {"replication_noblock", (test_callback_fn
)pre_replication_noblock
, 0, replication_tests
},
6068 {"regression", 0, 0, regression_tests
},
6069 {"behaviors", 0, 0, behavior_tests
},
6073 #define SERVERS_TO_CREATE 5
6075 #include "libmemcached_world.h"
6077 void get_world(world_st
*world
)
6079 world
->collections
= collection
;
6081 world
->create
= (test_callback_create_fn
)world_create
;
6082 world
->destroy
= (test_callback_fn
)world_destroy
;
6084 world
->test
.startup
= (test_callback_fn
)world_test_startup
;
6085 world
->test
.flush
= (test_callback_fn
)world_flush
;
6086 world
->test
.pre_run
= (test_callback_fn
)world_pre_run
;
6087 world
->test
.post_run
= (test_callback_fn
)world_post_run
;
6088 world
->test
.on_error
= (test_callback_error_fn
)world_on_error
;
6090 world
->collection
.startup
= (test_callback_fn
)world_container_startup
;
6091 world
->collection
.shutdown
= (test_callback_fn
)world_container_shutdown
;
6093 world
->runner
= &defualt_libmemcached_runner
;