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(hashkit_compare(&memc_clone
->hashkit
, &memc
->hashkit
));
262 test_true(hashkit_compare(&memc_clone
->distribution_hashkit
, &memc
->distribution_hashkit
));
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
;
3408 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CORK
, set
);
3411 return TEST_SKIPPED
;
3414 if (rc
== MEMCACHED_SUCCESS
)
3415 return TEST_SUCCESS
;
3417 return TEST_SKIPPED
;
3420 static test_return_t
pre_cork_and_nonblock(memcached_st
*memc
)
3427 return TEST_SKIPPED
;
3430 if (rc
!= TEST_SUCCESS
)
3433 return pre_nonblock(memc
);
3436 static test_return_t
pre_nonblock_binary(memcached_st
*memc
)
3438 memcached_return_t rc
= MEMCACHED_FAILURE
;
3439 memcached_st
*memc_clone
;
3440 memcached_server_instance_st
*instance
;
3442 memc_clone
= memcached_clone(NULL
, memc
);
3443 test_true(memc_clone
);
3444 // The memcached_version needs to be done on a clone, because the server
3445 // will not toggle protocol on an connection.
3446 memcached_version(memc_clone
);
3448 instance
= memcached_server_instance_fetch(memc_clone
, 0);
3450 if (instance
->major_version
>= 1 && instance
->minor_version
> 2)
3452 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3453 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3454 test_true(rc
== MEMCACHED_SUCCESS
);
3455 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3459 return TEST_SKIPPED
;
3462 memcached_free(memc_clone
);
3464 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3467 static test_return_t
pre_murmur(memcached_st
*memc
)
3469 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
3471 return TEST_SUCCESS
;
3474 static test_return_t
pre_jenkins(memcached_st
*memc
)
3476 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_JENKINS
);
3478 return TEST_SUCCESS
;
3482 static test_return_t
pre_md5(memcached_st
*memc
)
3484 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MD5
);
3486 return TEST_SUCCESS
;
3489 static test_return_t
pre_crc(memcached_st
*memc
)
3491 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_CRC
);
3493 return TEST_SUCCESS
;
3496 static test_return_t
pre_hsieh(memcached_st
*memc
)
3498 #ifdef HAVE_HSIEH_HASH
3499 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_HSIEH
);
3500 return TEST_SUCCESS
;
3503 return TEST_SKIPPED
;
3507 static test_return_t
pre_hash_fnv1_64(memcached_st
*memc
)
3509 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
3511 return TEST_SUCCESS
;
3514 static test_return_t
pre_hash_fnv1a_64(memcached_st
*memc
)
3516 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_64
);
3518 return TEST_SUCCESS
;
3521 static test_return_t
pre_hash_fnv1_32(memcached_st
*memc
)
3523 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_32
);
3525 return TEST_SUCCESS
;
3528 static test_return_t
pre_hash_fnv1a_32(memcached_st
*memc
)
3530 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_32
);
3532 return TEST_SUCCESS
;
3535 static test_return_t
pre_behavior_ketama(memcached_st
*memc
)
3537 memcached_return_t rc
;
3540 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA
, 1);
3541 test_true(rc
== MEMCACHED_SUCCESS
);
3543 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA
);
3544 test_true(value
== 1);
3546 return TEST_SUCCESS
;
3549 static test_return_t
pre_behavior_ketama_weighted(memcached_st
*memc
)
3551 memcached_return_t rc
;
3554 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
3555 test_true(rc
== MEMCACHED_SUCCESS
);
3557 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
3558 test_true(value
== 1);
3560 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
3561 test_true(rc
== MEMCACHED_SUCCESS
);
3563 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
3564 test_true(value
== MEMCACHED_HASH_MD5
);
3566 return TEST_SUCCESS
;
3570 @note This should be testing to see if the server really supports the binary protocol.
3572 static test_return_t
pre_binary(memcached_st
*memc
)
3574 memcached_return_t rc
= MEMCACHED_FAILURE
;
3575 memcached_st
*memc_clone
;
3576 memcached_server_instance_st
*instance
;
3578 memc_clone
= memcached_clone(NULL
, memc
);
3579 test_true(memc_clone
);
3580 // The memcached_version needs to be done on a clone, because the server
3581 // will not toggle protocol on an connection.
3582 memcached_version(memc_clone
);
3584 instance
= memcached_server_instance_fetch(memc_clone
, 0);
3586 if (instance
->major_version
>= 1 && instance
->minor_version
> 2)
3588 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3589 test_true(rc
== MEMCACHED_SUCCESS
);
3590 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3593 memcached_free(memc_clone
);
3595 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3599 static test_return_t
pre_replication(memcached_st
*memc
)
3601 test_return_t test_rc
;
3602 test_rc
= pre_binary(memc
);
3604 if (test_rc
!= TEST_SUCCESS
)
3608 * Make sure that we store the item on all servers
3609 * (master + replicas == number of servers)
3611 memcached_return_t rc
;
3612 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
,
3613 memcached_server_count(memc
) - 1);
3614 test_true(rc
== MEMCACHED_SUCCESS
);
3615 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
) == memcached_server_count(memc
) - 1);
3617 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3621 static test_return_t
pre_replication_noblock(memcached_st
*memc
)
3625 rc
= pre_replication(memc
);
3626 if (rc
!= TEST_SUCCESS
)
3629 rc
= pre_nonblock(memc
);
3635 static void my_free(const memcached_st
*ptr
__attribute__((unused
)), void *mem
, void *context
)
3638 #ifdef HARD_MALLOC_TESTS
3639 void *real_ptr
= (mem
== NULL
) ? mem
: (void*)((caddr_t
)mem
- 8);
3647 static void *my_malloc(const memcached_st
*ptr
__attribute__((unused
)), const size_t size
, void *context
)
3650 #ifdef HARD_MALLOC_TESTS
3651 void *ret
= malloc(size
+ 8);
3654 ret
= (void*)((caddr_t
)ret
+ 8);
3657 void *ret
= malloc(size
);
3662 memset(ret
, 0xff, size
);
3669 static void *my_realloc(const memcached_st
*ptr
__attribute__((unused
)), void *mem
, const size_t size
, void *context
)
3672 #ifdef HARD_MALLOC_TESTS
3673 void *real_ptr
= (mem
== NULL
) ? NULL
: (void*)((caddr_t
)mem
- 8);
3674 void *nmem
= realloc(real_ptr
, size
+ 8);
3679 ret
= (void*)((caddr_t
)nmem
+ 8);
3684 return realloc(mem
, size
);
3689 static void *my_calloc(const memcached_st
*ptr
__attribute__((unused
)), size_t nelem
, const size_t size
, void *context
)
3692 #ifdef HARD_MALLOC_TESTS
3693 void *mem
= my_malloc(ptr
, nelem
* size
);
3696 memset(mem
, 0, nelem
* size
);
3701 return calloc(nelem
, size
);
3706 static test_return_t
set_prefix(memcached_st
*memc
)
3708 memcached_return_t rc
;
3709 const char *key
= "mine";
3712 /* Make sure be default none exists */
3713 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3714 test_true(rc
== MEMCACHED_FAILURE
);
3716 /* Test a clean set */
3717 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3718 test_true(rc
== MEMCACHED_SUCCESS
);
3720 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3721 test_true(memcmp(value
, key
, 4) == 0);
3722 test_true(rc
== MEMCACHED_SUCCESS
);
3724 /* Test that we can turn it off */
3725 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3726 test_true(rc
== MEMCACHED_SUCCESS
);
3728 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3729 test_true(rc
== MEMCACHED_FAILURE
);
3731 /* Now setup for main test */
3732 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3733 test_true(rc
== MEMCACHED_SUCCESS
);
3735 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3736 test_true(rc
== MEMCACHED_SUCCESS
);
3737 test_true(memcmp(value
, key
, 4) == 0);
3739 /* Set to Zero, and then Set to something too large */
3742 memset(long_key
, 0, 255);
3744 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3745 test_true(rc
== MEMCACHED_SUCCESS
);
3747 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3748 test_true(rc
== MEMCACHED_FAILURE
);
3749 test_true(value
== NULL
);
3751 /* Test a long key for failure */
3752 /* TODO, extend test to determine based on setting, what result should be */
3753 strcpy(long_key
, "Thisismorethentheallottednumberofcharacters");
3754 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3755 //test_true(rc == MEMCACHED_BAD_KEY_PROVIDED);
3756 test_true(rc
== MEMCACHED_SUCCESS
);
3758 /* Now test a key with spaces (which will fail from long key, since bad key is not set) */
3759 strcpy(long_key
, "This is more then the allotted number of characters");
3760 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3761 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3763 /* Test for a bad prefix, but with a short key */
3764 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, 1);
3765 test_true(rc
== MEMCACHED_SUCCESS
);
3767 strcpy(long_key
, "dog cat");
3768 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3769 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3772 return TEST_SUCCESS
;
3776 #ifdef MEMCACHED_ENABLE_DEPRECATED
3777 static test_return_t
deprecated_set_memory_alloc(memcached_st
*memc
)
3779 void *test_ptr
= NULL
;
3782 memcached_malloc_fn malloc_cb
=
3783 (memcached_malloc_fn
)my_malloc
;
3784 cb_ptr
= *(void **)&malloc_cb
;
3785 memcached_return_t rc
;
3787 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, cb_ptr
);
3788 test_true(rc
== MEMCACHED_SUCCESS
);
3789 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
3790 test_true(rc
== MEMCACHED_SUCCESS
);
3791 test_true(test_ptr
== cb_ptr
);
3795 memcached_realloc_fn realloc_cb
=
3796 (memcached_realloc_fn
)my_realloc
;
3797 cb_ptr
= *(void **)&realloc_cb
;
3798 memcached_return_t rc
;
3800 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, cb_ptr
);
3801 test_true(rc
== MEMCACHED_SUCCESS
);
3802 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
3803 test_true(rc
== MEMCACHED_SUCCESS
);
3804 test_true(test_ptr
== cb_ptr
);
3808 memcached_free_fn free_cb
=
3809 (memcached_free_fn
)my_free
;
3810 cb_ptr
= *(void **)&free_cb
;
3811 memcached_return_t rc
;
3813 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, cb_ptr
);
3814 test_true(rc
== MEMCACHED_SUCCESS
);
3815 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
3816 test_true(rc
== MEMCACHED_SUCCESS
);
3817 test_true(test_ptr
== cb_ptr
);
3820 return TEST_SUCCESS
;
3825 static test_return_t
set_memory_alloc(memcached_st
*memc
)
3827 memcached_return_t rc
;
3828 rc
= memcached_set_memory_allocators(memc
, NULL
, my_free
,
3829 my_realloc
, my_calloc
, NULL
);
3830 test_true(rc
== MEMCACHED_FAILURE
);
3832 rc
= memcached_set_memory_allocators(memc
, my_malloc
, my_free
,
3833 my_realloc
, my_calloc
, NULL
);
3835 memcached_malloc_fn mem_malloc
;
3836 memcached_free_fn mem_free
;
3837 memcached_realloc_fn mem_realloc
;
3838 memcached_calloc_fn mem_calloc
;
3839 memcached_get_memory_allocators(memc
, &mem_malloc
, &mem_free
,
3840 &mem_realloc
, &mem_calloc
);
3842 test_true(mem_malloc
== my_malloc
);
3843 test_true(mem_realloc
== my_realloc
);
3844 test_true(mem_calloc
== my_calloc
);
3845 test_true(mem_free
== my_free
);
3847 return TEST_SUCCESS
;
3850 static test_return_t
enable_consistent_crc(memcached_st
*memc
)
3853 memcached_server_distribution_t value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
3854 memcached_hash_t hash
;
3855 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
3856 if ((rc
= pre_crc(memc
)) != TEST_SUCCESS
)
3859 value
= (memcached_server_distribution_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
3860 test_true(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
3862 hash
= (memcached_hash_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
3864 if (hash
!= MEMCACHED_HASH_CRC
)
3865 return TEST_SKIPPED
;
3867 return TEST_SUCCESS
;
3870 static test_return_t
enable_consistent_hsieh(memcached_st
*memc
)
3873 memcached_server_distribution_t value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
3874 memcached_hash_t hash
;
3875 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
3876 if ((rc
= pre_hsieh(memc
)) != TEST_SUCCESS
)
3879 value
= (memcached_server_distribution_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
3880 test_true(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
3882 hash
= (memcached_hash_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
3884 if (hash
!= MEMCACHED_HASH_HSIEH
)
3885 return TEST_SKIPPED
;
3888 return TEST_SUCCESS
;
3891 static test_return_t
enable_cas(memcached_st
*memc
)
3893 unsigned int set
= 1;
3895 memcached_server_instance_st
*instance
=
3896 memcached_server_instance_fetch(memc
, 0);
3898 memcached_version(memc
);
3900 if ((instance
->major_version
>= 1 && (instance
->minor_version
== 2 && instance
->micro_version
>= 4))
3901 || instance
->minor_version
> 2)
3903 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
3905 return TEST_SUCCESS
;
3908 return TEST_SKIPPED
;
3911 static test_return_t
check_for_1_2_3(memcached_st
*memc
)
3913 memcached_version(memc
);
3914 memcached_server_instance_st
*instance
=
3915 memcached_server_instance_fetch(memc
, 0);
3917 if ((instance
->major_version
>= 1 && (instance
->minor_version
== 2 && instance
->micro_version
>= 4))
3918 || instance
->minor_version
> 2)
3919 return TEST_SUCCESS
;
3921 return TEST_SKIPPED
;
3924 static test_return_t
pre_unix_socket(memcached_st
*memc
)
3926 memcached_return_t rc
;
3929 memcached_servers_reset(memc
);
3931 if (stat("/tmp/memcached.socket", &buf
))
3932 return TEST_SKIPPED
;
3934 rc
= memcached_server_add_unix_socket_with_weight(memc
, "/tmp/memcached.socket", 0);
3936 return ( rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_FAILURE
);
3939 static test_return_t
pre_nodelay(memcached_st
*memc
)
3941 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3942 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
3944 return TEST_SUCCESS
;
3947 static test_return_t
pre_settimer(memcached_st
*memc
)
3949 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
3950 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
3952 return TEST_SUCCESS
;
3955 static test_return_t
poll_timeout(memcached_st
*memc
)
3961 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
3963 timeout
= (size_t)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
3965 test_true(timeout
== 100);
3967 return TEST_SUCCESS
;
3970 static test_return_t
noreply_test(memcached_st
*memc
)
3972 memcached_return_t ret
;
3973 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
3974 test_true(ret
== MEMCACHED_SUCCESS
);
3975 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
3976 test_true(ret
== MEMCACHED_SUCCESS
);
3977 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
3978 test_true(ret
== MEMCACHED_SUCCESS
);
3979 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NOREPLY
) == 1);
3980 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
) == 1);
3981 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
) == 1);
3983 for (int count
=0; count
< 5; ++count
)
3985 for (size_t x
= 0; x
< 100; ++x
)
3988 size_t len
= (size_t)sprintf(key
, "%zu", x
);
3992 ret
= memcached_add(memc
, key
, len
, key
, len
, 0, 0);
3995 ret
= memcached_replace(memc
, key
, len
, key
, len
, 0, 0);
3998 ret
= memcached_set(memc
, key
, len
, key
, len
, 0, 0);
4001 ret
= memcached_append(memc
, key
, len
, key
, len
, 0, 0);
4004 ret
= memcached_prepend(memc
, key
, len
, key
, len
, 0, 0);
4010 test_true(ret
== MEMCACHED_SUCCESS
|| ret
== MEMCACHED_BUFFERED
);
4014 ** NOTE: Don't ever do this in your code! this is not a supported use of the
4015 ** API and is _ONLY_ done this way to verify that the library works the
4016 ** way it is supposed to do!!!!
4019 for (uint32_t x
= 0; x
< memcached_server_count(memc
); ++x
)
4021 memcached_server_instance_st
*instance
=
4022 memcached_server_instance_fetch(memc
, x
);
4023 no_msg
+=(int)(instance
->cursor_active
);
4026 test_true(no_msg
== 0);
4027 test_true(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
4030 ** Now validate that all items was set properly!
4032 for (size_t x
= 0; x
< 100; ++x
)
4036 size_t len
= (size_t)sprintf(key
, "%zu", x
);
4039 char* value
=memcached_get(memc
, key
, strlen(key
),
4040 &length
, &flags
, &ret
);
4041 test_true(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
4044 case 0: /* FALLTHROUGH */
4045 case 1: /* FALLTHROUGH */
4047 test_true(strncmp(value
, key
, len
) == 0);
4048 test_true(len
== length
);
4051 test_true(length
== len
* 2);
4054 test_true(length
== len
* 3);
4064 /* Try setting an illegal cas value (should not return an error to
4065 * the caller (because we don't expect a return message from the server)
4067 const char* keys
[]= {"0"};
4068 size_t lengths
[]= {1};
4071 memcached_result_st results_obj
;
4072 memcached_result_st
*results
;
4073 ret
= memcached_mget(memc
, keys
, lengths
, 1);
4074 test_true(ret
== MEMCACHED_SUCCESS
);
4076 results
= memcached_result_create(memc
, &results_obj
);
4078 results
= memcached_fetch_result(memc
, &results_obj
, &ret
);
4080 test_true(ret
== MEMCACHED_SUCCESS
);
4081 uint64_t cas
= memcached_result_cas(results
);
4082 memcached_result_free(&results_obj
);
4084 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
4085 test_true(ret
== MEMCACHED_SUCCESS
);
4088 * The item will have a new cas value, so try to set it again with the old
4089 * value. This should fail!
4091 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
4092 test_true(ret
== MEMCACHED_SUCCESS
);
4093 test_true(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
4094 char* value
=memcached_get(memc
, keys
[0], lengths
[0], &length
, &flags
, &ret
);
4095 test_true(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
4098 return TEST_SUCCESS
;
4101 static test_return_t
analyzer_test(memcached_st
*memc
)
4103 memcached_return_t rc
;
4104 memcached_stat_st
*memc_stat
;
4105 memcached_analysis_st
*report
;
4107 memc_stat
= memcached_stat(memc
, NULL
, &rc
);
4108 test_true(rc
== MEMCACHED_SUCCESS
);
4109 test_true(memc_stat
);
4111 report
= memcached_analyze(memc
, memc_stat
, &rc
);
4112 test_true(rc
== MEMCACHED_SUCCESS
);
4116 memcached_stat_free(NULL
, memc_stat
);
4118 return TEST_SUCCESS
;
4121 /* Count the objects */
4122 static memcached_return_t
callback_dump_counter(const memcached_st
*ptr
__attribute__((unused
)),
4123 const char *key
__attribute__((unused
)),
4124 size_t key_length
__attribute__((unused
)),
4127 size_t *counter
= (size_t *)context
;
4129 *counter
= *counter
+ 1;
4131 return MEMCACHED_SUCCESS
;
4134 static test_return_t
dump_test(memcached_st
*memc
)
4136 memcached_return_t rc
;
4138 memcached_dump_fn callbacks
[1];
4139 test_return_t main_rc
;
4141 callbacks
[0]= &callback_dump_counter
;
4143 /* No support for Binary protocol yet */
4144 if (memc
->flags
.binary_protocol
)
4145 return TEST_SUCCESS
;
4147 main_rc
= set_test3(memc
);
4149 test_true (main_rc
== TEST_SUCCESS
);
4151 rc
= memcached_dump(memc
, callbacks
, (void *)&counter
, 1);
4152 test_true(rc
== MEMCACHED_SUCCESS
);
4154 /* We may have more then 32 if our previous flush has not completed */
4155 test_true(counter
>= 32);
4157 return TEST_SUCCESS
;
4160 #ifdef HAVE_LIBMEMCACHEDUTIL
4161 static void* connection_release(void *arg
)
4164 memcached_pool_st
* pool
;
4169 assert(memcached_pool_push(resource
->pool
, resource
->mmc
) == MEMCACHED_SUCCESS
);
4173 static test_return_t
connection_pool_test(memcached_st
*memc
)
4175 memcached_pool_st
* pool
= memcached_pool_create(memc
, 5, 10);
4176 test_true(pool
!= NULL
);
4177 memcached_st
* mmc
[10];
4178 memcached_return_t rc
;
4180 for (size_t x
= 0; x
< 10; ++x
)
4182 mmc
[x
]= memcached_pool_pop(pool
, false, &rc
);
4183 test_true(mmc
[x
] != NULL
);
4184 test_true(rc
== MEMCACHED_SUCCESS
);
4187 test_true(memcached_pool_pop(pool
, false, &rc
) == NULL
);
4188 test_true(rc
== MEMCACHED_SUCCESS
);
4192 memcached_pool_st
* pool
;
4194 } item
= { .pool
= pool
, .mmc
= mmc
[9] };
4195 pthread_create(&tid
, NULL
, connection_release
, &item
);
4196 mmc
[9]= memcached_pool_pop(pool
, true, &rc
);
4197 test_true(rc
== MEMCACHED_SUCCESS
);
4198 pthread_join(tid
, NULL
);
4199 test_true(mmc
[9] == item
.mmc
);
4200 const char *key
= "key";
4201 size_t keylen
= strlen(key
);
4203 // verify that I can do ops with all connections
4204 rc
= memcached_set(mmc
[0], key
, keylen
, "0", 1, 0, 0);
4205 test_true(rc
== MEMCACHED_SUCCESS
);
4207 for (size_t x
= 0; x
< 10; ++x
)
4209 uint64_t number_value
;
4210 rc
= memcached_increment(mmc
[x
], key
, keylen
, 1, &number_value
);
4211 test_true(rc
== MEMCACHED_SUCCESS
);
4212 test_true(number_value
== (x
+1));
4216 for (size_t x
= 0; x
< 10; ++x
)
4218 test_true(memcached_pool_push(pool
, mmc
[x
]) == MEMCACHED_SUCCESS
);
4222 /* verify that I can set behaviors on the pool when I don't have all
4223 * of the connections in the pool. It should however be enabled
4224 * when I push the item into the pool
4226 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
4227 test_true(mmc
[0] != NULL
);
4229 rc
= memcached_pool_behavior_set(pool
, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
, 9999);
4230 test_true(rc
== MEMCACHED_SUCCESS
);
4232 mmc
[1]= memcached_pool_pop(pool
, false, &rc
);
4233 test_true(mmc
[1] != NULL
);
4235 test_true(memcached_behavior_get(mmc
[1], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
) == 9999);
4236 test_true(memcached_pool_push(pool
, mmc
[1]) == MEMCACHED_SUCCESS
);
4237 test_true(memcached_pool_push(pool
, mmc
[0]) == MEMCACHED_SUCCESS
);
4239 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
4240 test_true(memcached_behavior_get(mmc
[0], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
) == 9999);
4241 test_true(memcached_pool_push(pool
, mmc
[0]) == MEMCACHED_SUCCESS
);
4244 test_true(memcached_pool_destroy(pool
) == memc
);
4245 return TEST_SUCCESS
;
4249 static test_return_t
replication_set_test(memcached_st
*memc
)
4251 memcached_return_t rc
;
4252 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4253 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 0);
4255 rc
= memcached_set(memc
, "bubba", 5, "0", 1, 0, 0);
4256 test_true(rc
== MEMCACHED_SUCCESS
);
4259 ** We are using the quiet commands to store the replicas, so we need
4260 ** to ensure that all of them are processed before we can continue.
4261 ** In the test we go directly from storing the object to trying to
4262 ** receive the object from all of the different servers, so we
4263 ** could end up in a race condition (the memcached server hasn't yet
4264 ** processed the quiet command from the replication set when it process
4265 ** the request from the other client (created by the clone)). As a
4266 ** workaround for that we call memcached_quit to send the quit command
4267 ** to the server and wait for the response ;-) If you use the test code
4268 ** as an example for your own code, please note that you shouldn't need
4271 memcached_quit(memc
);
4274 ** "bubba" should now be stored on all of our servers. We don't have an
4275 ** easy to use API to address each individual server, so I'll just iterate
4276 ** through a bunch of "master keys" and I should most likely hit all of the
4279 for (int x
= 'a'; x
<= 'z'; ++x
)
4281 char key
[2]= { [0]= (char)x
};
4284 char *val
= memcached_get_by_key(memc_clone
, key
, 1, "bubba", 5,
4286 test_true(rc
== MEMCACHED_SUCCESS
);
4287 test_true(val
!= NULL
);
4291 memcached_free(memc_clone
);
4293 return TEST_SUCCESS
;
4296 static test_return_t
replication_get_test(memcached_st
*memc
)
4298 memcached_return_t rc
;
4301 * Don't do the following in your code. I am abusing the internal details
4302 * within the library, and this is not a supported interface.
4303 * This is to verify correct behavior in the library
4305 for (uint32_t host
= 0; host
< memcached_server_count(memc
); ++host
)
4307 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4308 memcached_server_instance_st
*instance
=
4309 memcached_server_instance_fetch(memc_clone
, host
);
4313 for (int x
= 'a'; x
<= 'z'; ++x
)
4315 char key
[2]= { [0]= (char)x
};
4318 char *val
= memcached_get_by_key(memc_clone
, key
, 1, "bubba", 5,
4320 test_true(rc
== MEMCACHED_SUCCESS
);
4321 test_true(val
!= NULL
);
4325 memcached_free(memc_clone
);
4328 return TEST_SUCCESS
;
4331 static test_return_t
replication_mget_test(memcached_st
*memc
)
4333 memcached_return_t rc
;
4334 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4335 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 0);
4337 const char *keys
[]= { "bubba", "key1", "key2", "key3" };
4338 size_t len
[]= { 5, 4, 4, 4 };
4340 for (size_t x
= 0; x
< 4; ++x
)
4342 rc
= memcached_set(memc
, keys
[x
], len
[x
], "0", 1, 0, 0);
4343 test_true(rc
== MEMCACHED_SUCCESS
);
4347 ** We are using the quiet commands to store the replicas, so we need
4348 ** to ensure that all of them are processed before we can continue.
4349 ** In the test we go directly from storing the object to trying to
4350 ** receive the object from all of the different servers, so we
4351 ** could end up in a race condition (the memcached server hasn't yet
4352 ** processed the quiet command from the replication set when it process
4353 ** the request from the other client (created by the clone)). As a
4354 ** workaround for that we call memcached_quit to send the quit command
4355 ** to the server and wait for the response ;-) If you use the test code
4356 ** as an example for your own code, please note that you shouldn't need
4359 memcached_quit(memc
);
4362 * Don't do the following in your code. I am abusing the internal details
4363 * within the library, and this is not a supported interface.
4364 * This is to verify correct behavior in the library
4366 memcached_result_st result_obj
;
4367 for (uint32_t host
= 0; host
< memc_clone
->number_of_hosts
; host
++)
4369 memcached_st
*new_clone
= memcached_clone(NULL
, memc
);
4370 memcached_server_instance_st
*instance
=
4371 memcached_server_instance_fetch(new_clone
, host
);
4374 for (int x
= 'a'; x
<= 'z'; ++x
)
4376 char key
[2]= { [0]= (char)x
, [1]= 0 };
4378 rc
= memcached_mget_by_key(new_clone
, key
, 1, keys
, len
, 4);
4379 test_true(rc
== MEMCACHED_SUCCESS
);
4381 memcached_result_st
*results
= memcached_result_create(new_clone
, &result_obj
);
4385 while ((results
= memcached_fetch_result(new_clone
, &result_obj
, &rc
)) != NULL
)
4389 test_true(hits
== 4);
4390 memcached_result_free(&result_obj
);
4393 memcached_free(new_clone
);
4396 memcached_free(memc_clone
);
4398 return TEST_SUCCESS
;
4401 static test_return_t
replication_randomize_mget_test(memcached_st
*memc
)
4403 memcached_result_st result_obj
;
4404 memcached_return_t rc
;
4405 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4406 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 3);
4407 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ
, 1);
4409 const char *keys
[]= { "key1", "key2", "key3", "key4", "key5", "key6", "key7" };
4410 size_t len
[]= { 4, 4, 4, 4, 4, 4, 4 };
4412 for (int x
=0; x
< 7; ++x
)
4414 rc
= memcached_set(memc
, keys
[x
], len
[x
], "1", 1, 0, 0);
4415 test_true(rc
== MEMCACHED_SUCCESS
);
4418 memcached_quit(memc
);
4420 for (size_t x
= 0; x
< 7; ++x
)
4422 const char key
[2]= { [0]= (const char)x
};
4424 rc
= memcached_mget_by_key(memc_clone
, key
, 1, keys
, len
, 7);
4425 test_true(rc
== MEMCACHED_SUCCESS
);
4427 memcached_result_st
*results
= memcached_result_create(memc_clone
, &result_obj
);
4431 while ((results
= memcached_fetch_result(memc_clone
, &result_obj
, &rc
)) != NULL
)
4435 test_true(hits
== 7);
4436 memcached_result_free(&result_obj
);
4438 memcached_free(memc_clone
);
4439 return TEST_SUCCESS
;
4442 static test_return_t
replication_delete_test(memcached_st
*memc
)
4444 memcached_return_t rc
;
4445 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4446 /* Delete the items from all of the servers except 1 */
4447 uint64_t repl
= memcached_behavior_get(memc
,
4448 MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
);
4449 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, --repl
);
4451 const char *keys
[]= { "bubba", "key1", "key2", "key3" };
4452 size_t len
[]= { 5, 4, 4, 4 };
4454 for (size_t x
= 0; x
< 4; ++x
)
4456 rc
= memcached_delete_by_key(memc
, keys
[0], len
[0], keys
[x
], len
[x
], 0);
4457 test_true(rc
== MEMCACHED_SUCCESS
);
4461 * Don't do the following in your code. I am abusing the internal details
4462 * within the library, and this is not a supported interface.
4463 * This is to verify correct behavior in the library
4465 uint32_t hash
= memcached_generate_hash(memc
, keys
[0], len
[0]);
4466 for (uint32_t x
= 0; x
< (repl
+ 1); ++x
)
4468 memcached_server_instance_st
*instance
=
4469 memcached_server_instance_fetch(memc_clone
, x
);
4472 if (++hash
== memc_clone
->number_of_hosts
)
4476 memcached_result_st result_obj
;
4477 for (uint32_t host
= 0; host
< memc_clone
->number_of_hosts
; ++host
)
4479 for (size_t x
= 'a'; x
<= 'z'; ++x
)
4481 const char key
[2]= { [0]= (const char)x
};
4483 rc
= memcached_mget_by_key(memc_clone
, key
, 1, keys
, len
, 4);
4484 test_true(rc
== MEMCACHED_SUCCESS
);
4486 memcached_result_st
*results
= memcached_result_create(memc_clone
, &result_obj
);
4490 while ((results
= memcached_fetch_result(memc_clone
, &result_obj
, &rc
)) != NULL
)
4494 test_true(hits
== 4);
4495 memcached_result_free(&result_obj
);
4498 memcached_free(memc_clone
);
4500 return TEST_SUCCESS
;
4503 static void increment_request_id(uint16_t *id
)
4506 if ((*id
& UDP_REQUEST_ID_THREAD_MASK
) != 0)
4510 static uint16_t *get_udp_request_ids(memcached_st
*memc
)
4512 uint16_t *ids
= malloc(sizeof(uint16_t) * memcached_server_count(memc
));
4513 assert(ids
!= NULL
);
4515 for (uint32_t x
= 0; x
< memcached_server_count(memc
); x
++)
4517 memcached_server_instance_st
*instance
=
4518 memcached_server_instance_fetch(memc
, x
);
4520 ids
[x
]= get_udp_datagram_request_id((struct udp_datagram_header_st
*) instance
->write_buffer
);
4526 static test_return_t
post_udp_op_check(memcached_st
*memc
, uint16_t *expected_req_ids
)
4528 memcached_server_st
*cur_server
= memcached_server_list(memc
);
4529 uint16_t *cur_req_ids
= get_udp_request_ids(memc
);
4531 for (size_t x
= 0; x
< memcached_server_count(memc
); x
++)
4533 test_true(cur_server
[x
].cursor_active
== 0);
4534 test_true(cur_req_ids
[x
] == expected_req_ids
[x
]);
4536 free(expected_req_ids
);
4539 return TEST_SUCCESS
;
4543 ** There is a little bit of a hack here, instead of removing
4544 ** the servers, I just set num host to 0 and them add then new udp servers
4546 static test_return_t
init_udp(memcached_st
*memc
)
4548 memcached_version(memc
);
4549 memcached_server_instance_st
*instance
=
4550 memcached_server_instance_fetch(memc
, 0);
4552 /* For the time being, only support udp test for >= 1.2.6 && < 1.3 */
4553 if (instance
->major_version
!= 1 || instance
->minor_version
!= 2
4554 || instance
->micro_version
< 6)
4555 return TEST_SKIPPED
;
4557 uint32_t num_hosts
= memcached_server_count(memc
);
4558 memcached_server_st servers
[num_hosts
];
4559 memcpy(servers
, memcached_server_list(memc
), sizeof(memcached_server_st
) * num_hosts
);
4560 for (uint32_t x
= 0; x
< num_hosts
; x
++)
4562 memcached_server_instance_st
*set_instance
=
4563 memcached_server_instance_fetch(memc
, x
);
4565 memcached_server_free(set_instance
);
4568 memc
->number_of_hosts
= 0;
4569 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
, 1);
4570 for (uint32_t x
= 0; x
< num_hosts
; x
++)
4572 memcached_server_instance_st
*set_instance
=
4573 memcached_server_instance_fetch(memc
, x
);
4575 test_true(memcached_server_add_udp(memc
, servers
[x
].hostname
, servers
[x
].port
) == MEMCACHED_SUCCESS
);
4576 test_true(set_instance
->write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4579 return TEST_SUCCESS
;
4582 static test_return_t
binary_init_udp(memcached_st
*memc
)
4584 test_return_t test_rc
;
4585 test_rc
= pre_binary(memc
);
4587 if (test_rc
!= TEST_SUCCESS
)
4590 return init_udp(memc
);
4593 /* Make sure that I cant add a tcp server to a udp client */
4594 static test_return_t
add_tcp_server_udp_client_test(memcached_st
*memc
)
4598 memcached_server_st server
;
4599 memcached_server_instance_st
*instance
=
4600 memcached_server_instance_fetch(memc
, 0);
4601 memcached_server_clone(&server
, &memc
->hosts
[0]);
4602 test_true(memcached_server_remove(&(memc
->hosts
[0])) == MEMCACHED_SUCCESS
);
4603 test_true(memcached_server_add(memc
, server
.hostname
, server
.port
) == MEMCACHED_INVALID_HOST_PROTOCOL
);
4605 return TEST_SUCCESS
;
4608 /* Make sure that I cant add a udp server to a tcp client */
4609 static test_return_t
add_udp_server_tcp_client_test(memcached_st
*memc
)
4613 memcached_server_st server
;
4614 memcached_server_instance_st
*instance
=
4615 memcached_server_instance_fetch(memc
, 0);
4616 memcached_server_clone(&server
, &memc
->hosts
[0]);
4617 test_true(memcached_server_remove(&(memc
->hosts
[0])) == MEMCACHED_SUCCESS
);
4619 memcached_st tcp_client
;
4620 memcached_create(&tcp_client
);
4621 test_true(memcached_server_add_udp(&tcp_client
, server
.hostname
, server
.port
) == MEMCACHED_INVALID_HOST_PROTOCOL
);
4624 return TEST_SUCCESS
;
4627 static test_return_t
set_udp_behavior_test(memcached_st
*memc
)
4630 memcached_quit(memc
);
4631 memc
->number_of_hosts
= 0;
4632 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, memc
->distribution
);
4633 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
, 1) == MEMCACHED_SUCCESS
);
4634 test_true(memc
->flags
.use_udp
);
4635 test_true(memc
->flags
.no_reply
);
4637 test_true(memcached_server_count(memc
) == 0);
4639 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
,0);
4640 test_true(! (memc
->flags
.use_udp
));
4641 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
,0);
4642 test_true(! (memc
->flags
.no_reply
));
4644 return TEST_SUCCESS
;
4647 static test_return_t
udp_set_test(memcached_st
*memc
)
4649 unsigned int num_iters
= 1025; //request id rolls over at 1024
4651 for (size_t x
= 0; x
< num_iters
;x
++)
4653 memcached_return_t rc
;
4654 const char *key
= "foo";
4655 const char *value
= "when we sanitize";
4656 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4657 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4658 memcached_server_instance_st
*instance
=
4659 memcached_server_instance_fetch(memc
, server_key
);
4660 size_t init_offset
= instance
->write_buffer_offset
;
4662 rc
= memcached_set(memc
, key
, strlen(key
),
4663 value
, strlen(value
),
4664 (time_t)0, (uint32_t)0);
4665 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4666 /** NB, the check below assumes that if new write_ptr is less than
4667 * the original write_ptr that we have flushed. For large payloads, this
4668 * maybe an invalid assumption, but for the small payload we have it is OK
4670 if (rc
== MEMCACHED_SUCCESS
||
4671 instance
->write_buffer_offset
< init_offset
)
4672 increment_request_id(&expected_ids
[server_key
]);
4674 if (rc
== MEMCACHED_SUCCESS
)
4676 test_true(instance
->write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4680 test_true(instance
->write_buffer_offset
!= UDP_DATAGRAM_HEADER_LENGTH
);
4681 test_true(instance
->write_buffer_offset
<= MAX_UDP_DATAGRAM_LENGTH
);
4683 test_true(post_udp_op_check(memc
, expected_ids
) == TEST_SUCCESS
);
4685 return TEST_SUCCESS
;
4688 static test_return_t
udp_buffered_set_test(memcached_st
*memc
)
4690 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4691 return udp_set_test(memc
);
4694 static test_return_t
udp_set_too_big_test(memcached_st
*memc
)
4696 memcached_return_t rc
;
4697 const char *key
= "bar";
4698 char value
[MAX_UDP_DATAGRAM_LENGTH
];
4699 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4700 rc
= memcached_set(memc
, key
, strlen(key
),
4701 value
, MAX_UDP_DATAGRAM_LENGTH
,
4702 (time_t)0, (uint32_t)0);
4703 test_true(rc
== MEMCACHED_WRITE_FAILURE
);
4705 return post_udp_op_check(memc
,expected_ids
);
4708 static test_return_t
udp_delete_test(memcached_st
*memc
)
4710 unsigned int num_iters
= 1025; //request id rolls over at 1024
4712 for (size_t x
= 0; x
< num_iters
;x
++)
4714 memcached_return_t rc
;
4715 const char *key
= "foo";
4716 uint16_t *expected_ids
=get_udp_request_ids(memc
);
4717 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4718 memcached_server_instance_st
*instance
=
4719 memcached_server_instance_fetch(memc
, server_key
);
4720 size_t init_offset
= instance
->write_buffer_offset
;
4722 rc
= memcached_delete(memc
, key
, strlen(key
), 0);
4723 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4725 if (rc
== MEMCACHED_SUCCESS
|| instance
->write_buffer_offset
< init_offset
)
4726 increment_request_id(&expected_ids
[server_key
]);
4727 if (rc
== MEMCACHED_SUCCESS
)
4729 test_true(instance
->write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4733 test_true(instance
->write_buffer_offset
!= UDP_DATAGRAM_HEADER_LENGTH
);
4734 test_true(instance
->write_buffer_offset
<= MAX_UDP_DATAGRAM_LENGTH
);
4736 test_true(post_udp_op_check(memc
,expected_ids
) == TEST_SUCCESS
);
4738 return TEST_SUCCESS
;
4741 static test_return_t
udp_buffered_delete_test(memcached_st
*memc
)
4743 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4744 return udp_delete_test(memc
);
4747 static test_return_t
udp_verbosity_test(memcached_st
*memc
)
4749 memcached_return_t rc
;
4750 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4752 for (size_t x
= 0; x
< memcached_server_count(memc
); x
++)
4754 increment_request_id(&expected_ids
[x
]);
4757 rc
= memcached_verbosity(memc
,3);
4758 test_true(rc
== MEMCACHED_SUCCESS
);
4759 return post_udp_op_check(memc
,expected_ids
);
4762 static test_return_t
udp_quit_test(memcached_st
*memc
)
4764 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4765 memcached_quit(memc
);
4766 return post_udp_op_check(memc
, expected_ids
);
4769 static test_return_t
udp_flush_test(memcached_st
*memc
)
4771 memcached_return_t rc
;
4772 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4774 for (size_t x
= 0; x
< memcached_server_count(memc
); x
++)
4776 increment_request_id(&expected_ids
[x
]);
4779 rc
= memcached_flush(memc
,0);
4780 test_true(rc
== MEMCACHED_SUCCESS
);
4781 return post_udp_op_check(memc
,expected_ids
);
4784 static test_return_t
udp_incr_test(memcached_st
*memc
)
4786 memcached_return_t rc
;
4787 const char *key
= "incr";
4788 const char *value
= "1";
4789 rc
= memcached_set(memc
, key
, strlen(key
),
4790 value
, strlen(value
),
4791 (time_t)0, (uint32_t)0);
4793 test_true(rc
== MEMCACHED_SUCCESS
);
4794 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4795 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4796 increment_request_id(&expected_ids
[server_key
]);
4798 rc
= memcached_increment(memc
, key
, strlen(key
), 1, &newvalue
);
4799 test_true(rc
== MEMCACHED_SUCCESS
);
4800 return post_udp_op_check(memc
, expected_ids
);
4803 static test_return_t
udp_decr_test(memcached_st
*memc
)
4805 memcached_return_t rc
;
4806 const char *key
= "decr";
4807 const char *value
= "1";
4808 rc
= memcached_set(memc
, key
, strlen(key
),
4809 value
, strlen(value
),
4810 (time_t)0, (uint32_t)0);
4812 test_true(rc
== MEMCACHED_SUCCESS
);
4813 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4814 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4815 increment_request_id(&expected_ids
[server_key
]);
4817 rc
= memcached_decrement(memc
, key
, strlen(key
), 1, &newvalue
);
4818 test_true(rc
== MEMCACHED_SUCCESS
);
4819 return post_udp_op_check(memc
, expected_ids
);
4823 static test_return_t
udp_stat_test(memcached_st
*memc
)
4825 memcached_stat_st
* rv
= NULL
;
4826 memcached_return_t rc
;
4828 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4829 rv
= memcached_stat(memc
, args
, &rc
);
4831 test_true(rc
== MEMCACHED_NOT_SUPPORTED
);
4832 return post_udp_op_check(memc
, expected_ids
);
4835 static test_return_t
udp_version_test(memcached_st
*memc
)
4837 memcached_return_t rc
;
4838 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4839 rc
= memcached_version(memc
);
4840 test_true(rc
== MEMCACHED_NOT_SUPPORTED
);
4841 return post_udp_op_check(memc
, expected_ids
);
4844 static test_return_t
udp_get_test(memcached_st
*memc
)
4846 memcached_return_t rc
;
4847 const char *key
= "foo";
4849 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4850 char *val
= memcached_get(memc
, key
, strlen(key
), &vlen
, (uint32_t)0, &rc
);
4851 test_true(rc
== MEMCACHED_NOT_SUPPORTED
);
4852 test_true(val
== NULL
);
4853 return post_udp_op_check(memc
, expected_ids
);
4856 static test_return_t
udp_mixed_io_test(memcached_st
*memc
)
4859 test_st mixed_io_ops
[] ={
4861 (test_callback_fn
)udp_set_test
},
4862 {"udp_set_too_big_test", 0,
4863 (test_callback_fn
)udp_set_too_big_test
},
4864 {"udp_delete_test", 0,
4865 (test_callback_fn
)udp_delete_test
},
4866 {"udp_verbosity_test", 0,
4867 (test_callback_fn
)udp_verbosity_test
},
4868 {"udp_quit_test", 0,
4869 (test_callback_fn
)udp_quit_test
},
4870 {"udp_flush_test", 0,
4871 (test_callback_fn
)udp_flush_test
},
4872 {"udp_incr_test", 0,
4873 (test_callback_fn
)udp_incr_test
},
4874 {"udp_decr_test", 0,
4875 (test_callback_fn
)udp_decr_test
},
4876 {"udp_version_test", 0,
4877 (test_callback_fn
)udp_version_test
}
4879 for (size_t x
= 0; x
< 500; x
++)
4881 current_op
= mixed_io_ops
[random() % 9];
4882 test_true(current_op
.test_fn(memc
) == TEST_SUCCESS
);
4884 return TEST_SUCCESS
;
4888 static test_return_t
hash_sanity_test (memcached_st
*memc
)
4892 assert(MEMCACHED_HASH_DEFAULT
== MEMCACHED_HASH_DEFAULT
);
4893 assert(MEMCACHED_HASH_MD5
== MEMCACHED_HASH_MD5
);
4894 assert(MEMCACHED_HASH_CRC
== MEMCACHED_HASH_CRC
);
4895 assert(MEMCACHED_HASH_FNV1_64
== MEMCACHED_HASH_FNV1_64
);
4896 assert(MEMCACHED_HASH_FNV1A_64
== MEMCACHED_HASH_FNV1A_64
);
4897 assert(MEMCACHED_HASH_FNV1_32
== MEMCACHED_HASH_FNV1_32
);
4898 assert(MEMCACHED_HASH_FNV1A_32
== MEMCACHED_HASH_FNV1A_32
);
4899 #ifdef HAVE_HSIEH_HASH
4900 assert(MEMCACHED_HASH_HSIEH
== MEMCACHED_HASH_HSIEH
);
4902 assert(MEMCACHED_HASH_MURMUR
== MEMCACHED_HASH_MURMUR
);
4903 assert(MEMCACHED_HASH_JENKINS
== MEMCACHED_HASH_JENKINS
);
4904 assert(MEMCACHED_HASH_MAX
== MEMCACHED_HASH_MAX
);
4906 return TEST_SUCCESS
;
4910 static test_return_t
hsieh_avaibility_test (memcached_st
*memc
)
4912 memcached_return_t expected_rc
= MEMCACHED_FAILURE
;
4913 #ifdef HAVE_HSIEH_HASH
4914 expected_rc
= MEMCACHED_SUCCESS
;
4916 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
,
4917 (uint64_t)MEMCACHED_HASH_HSIEH
);
4918 test_true(rc
== expected_rc
);
4920 return TEST_SUCCESS
;
4923 static test_return_t
one_at_a_time_run (memcached_st
*memc
__attribute__((unused
)))
4928 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4932 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_DEFAULT
);
4933 test_true(one_at_a_time_values
[x
] == hash_val
);
4936 return TEST_SUCCESS
;
4939 static test_return_t
md5_run (memcached_st
*memc
__attribute__((unused
)))
4944 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4948 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MD5
);
4949 test_true(md5_values
[x
] == hash_val
);
4952 return TEST_SUCCESS
;
4955 static test_return_t
crc_run (memcached_st
*memc
__attribute__((unused
)))
4960 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4964 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_CRC
);
4965 test_true(crc_values
[x
] == hash_val
);
4968 return TEST_SUCCESS
;
4971 static test_return_t
fnv1_64_run (memcached_st
*memc
__attribute__((unused
)))
4976 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4980 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_64
);
4981 test_true(fnv1_64_values
[x
] == hash_val
);
4984 return TEST_SUCCESS
;
4987 static test_return_t
fnv1a_64_run (memcached_st
*memc
__attribute__((unused
)))
4992 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4996 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_64
);
4997 test_true(fnv1a_64_values
[x
] == hash_val
);
5000 return TEST_SUCCESS
;
5003 static test_return_t
fnv1_32_run (memcached_st
*memc
__attribute__((unused
)))
5009 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
5013 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_32
);
5014 test_true(fnv1_32_values
[x
] == hash_val
);
5017 return TEST_SUCCESS
;
5020 static test_return_t
fnv1a_32_run (memcached_st
*memc
__attribute__((unused
)))
5025 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
5029 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_32
);
5030 test_true(fnv1a_32_values
[x
] == hash_val
);
5033 return TEST_SUCCESS
;
5036 static test_return_t
hsieh_run (memcached_st
*memc
__attribute__((unused
)))
5041 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
5045 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_HSIEH
);
5046 test_true(hsieh_values
[x
] == hash_val
);
5049 return TEST_SUCCESS
;
5052 static test_return_t
murmur_run (memcached_st
*memc
__attribute__((unused
)))
5055 return TEST_SKIPPED
;
5060 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
5064 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MURMUR
);
5065 test_true(murmur_values
[x
] == hash_val
);
5068 return TEST_SUCCESS
;
5072 static test_return_t
jenkins_run (memcached_st
*memc
__attribute__((unused
)))
5078 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
5082 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_JENKINS
);
5083 test_true(jenkins_values
[x
] == hash_val
);
5086 return TEST_SUCCESS
;
5090 static test_return_t
ketama_compatibility_libmemcached(memcached_st
*trash
)
5092 memcached_return_t rc
;
5095 memcached_server_st
*server_pool
;
5100 memc
= memcached_create(NULL
);
5103 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
5104 test_true(rc
== MEMCACHED_SUCCESS
);
5106 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
5107 test_true(value
== 1);
5109 test_true(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
) == MEMCACHED_SUCCESS
);
5110 test_true(memcached_behavior_get_distribution(memc
) == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
);
5113 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");
5114 memcached_server_push(memc
, server_pool
);
5116 /* verify that the server list was parsed okay. */
5117 test_true(memcached_server_count(memc
) == 8);
5118 test_strcmp(server_pool
[0].hostname
, "10.0.1.1");
5119 test_true(server_pool
[0].port
== 11211);
5120 test_true(server_pool
[0].weight
== 600);
5121 test_strcmp(server_pool
[2].hostname
, "10.0.1.3");
5122 test_true(server_pool
[2].port
== 11211);
5123 test_true(server_pool
[2].weight
== 200);
5124 test_strcmp(server_pool
[7].hostname
, "10.0.1.8");
5125 test_true(server_pool
[7].port
== 11211);
5126 test_true(server_pool
[7].weight
== 100);
5128 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
5129 * us test the boundary wraparound.
5131 test_true(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
5133 /* verify the standard ketama set. */
5134 for (x
= 0; x
< 99; x
++)
5136 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
5137 memcached_server_instance_st
*instance
=
5138 memcached_server_instance_fetch(memc
, server_idx
);
5139 char *hostname
= instance
->hostname
;
5141 test_strcmp(hostname
, ketama_test_cases
[x
].server
);
5144 memcached_server_list_free(server_pool
);
5145 memcached_free(memc
);
5147 return TEST_SUCCESS
;
5150 static test_return_t
ketama_compatibility_spymemcached(memcached_st
*trash
)
5152 memcached_return_t rc
;
5155 memcached_server_st
*server_pool
;
5160 memc
= memcached_create(NULL
);
5163 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
5164 test_true(rc
== MEMCACHED_SUCCESS
);
5166 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
5167 test_true(value
== 1);
5169 test_true(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
) == MEMCACHED_SUCCESS
);
5170 test_true(memcached_behavior_get_distribution(memc
) == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
);
5172 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");
5173 memcached_server_push(memc
, server_pool
);
5175 /* verify that the server list was parsed okay. */
5176 test_true(memcached_server_count(memc
) == 8);
5177 test_strcmp(server_pool
[0].hostname
, "10.0.1.1");
5178 test_true(server_pool
[0].port
== 11211);
5179 test_true(server_pool
[0].weight
== 600);
5180 test_strcmp(server_pool
[2].hostname
, "10.0.1.3");
5181 test_true(server_pool
[2].port
== 11211);
5182 test_true(server_pool
[2].weight
== 200);
5183 test_strcmp(server_pool
[7].hostname
, "10.0.1.8");
5184 test_true(server_pool
[7].port
== 11211);
5185 test_true(server_pool
[7].weight
== 100);
5187 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
5188 * us test the boundary wraparound.
5190 test_true(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
5192 /* verify the standard ketama set. */
5193 for (x
= 0; x
< 99; x
++)
5195 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases_spy
[x
].key
, strlen(ketama_test_cases_spy
[x
].key
));
5196 memcached_server_instance_st
*instance
=
5197 memcached_server_instance_fetch(memc
, server_idx
);
5198 char *hostname
= instance
->hostname
;
5199 test_strcmp(hostname
, ketama_test_cases_spy
[x
].server
);
5202 memcached_server_list_free(server_pool
);
5203 memcached_free(memc
);
5205 return TEST_SUCCESS
;
5208 static test_return_t
regression_bug_434484(memcached_st
*memc
)
5210 test_return_t test_rc
;
5211 test_rc
= pre_binary(memc
);
5213 if (test_rc
!= TEST_SUCCESS
)
5216 memcached_return_t ret
;
5217 const char *key
= "regression_bug_434484";
5218 size_t keylen
= strlen(key
);
5220 ret
= memcached_append(memc
, key
, keylen
, key
, keylen
, 0, 0);
5221 test_true(ret
== MEMCACHED_NOTSTORED
);
5223 size_t size
= 2048 * 1024;
5224 void *data
= calloc(1, size
);
5225 test_true(data
!= NULL
);
5226 ret
= memcached_set(memc
, key
, keylen
, data
, size
, 0, 0);
5227 test_true(ret
== MEMCACHED_E2BIG
);
5230 return TEST_SUCCESS
;
5233 static test_return_t
regression_bug_434843(memcached_st
*memc
)
5235 test_return_t test_rc
;
5236 test_rc
= pre_binary(memc
);
5238 if (test_rc
!= TEST_SUCCESS
)
5241 memcached_return_t rc
;
5243 memcached_execute_fn callbacks
[1]= { [0]= &callback_counter
};
5246 * I only want to hit only _one_ server so I know the number of requests I'm
5247 * sending in the pipleine to the server. Let's try to do a multiget of
5248 * 1024 (that should satisfy most users don't you think?). Future versions
5249 * will include a mget_execute function call if you need a higher number.
5251 uint32_t number_of_hosts
= memcached_server_count(memc
);
5252 memc
->number_of_hosts
= 1;
5253 const size_t max_keys
= 1024;
5254 char **keys
= calloc(max_keys
, sizeof(char*));
5255 size_t *key_length
=calloc(max_keys
, sizeof(size_t));
5257 for (size_t x
= 0; x
< max_keys
; ++x
)
5261 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%zu", x
);
5263 test_true(keys
[x
] != NULL
);
5267 * Run two times.. the first time we should have 100% cache miss,
5268 * and the second time we should have 100% cache hits
5270 for (size_t y
= 0; y
< 2; y
++)
5272 rc
= memcached_mget(memc
, (const char**)keys
, key_length
, max_keys
);
5273 test_true(rc
== MEMCACHED_SUCCESS
);
5274 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5278 /* The first iteration should give me a 100% cache miss. verify that*/
5279 char blob
[1024]= { 0 };
5281 test_true(counter
== 0);
5283 for (size_t x
= 0; x
< max_keys
; ++x
)
5285 rc
= memcached_add(memc
, keys
[x
], key_length
[x
],
5286 blob
, sizeof(blob
), 0, 0);
5287 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5292 /* Verify that we received all of the key/value pairs */
5293 test_true(counter
== max_keys
);
5297 /* Release allocated resources */
5298 for (size_t x
= 0; x
< max_keys
; ++x
)
5305 memc
->number_of_hosts
= number_of_hosts
;
5307 return TEST_SUCCESS
;
5310 static test_return_t
regression_bug_434843_buffered(memcached_st
*memc
)
5312 memcached_return_t rc
;
5313 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
5314 test_true(rc
== MEMCACHED_SUCCESS
);
5316 return regression_bug_434843(memc
);
5319 static test_return_t
regression_bug_421108(memcached_st
*memc
)
5321 memcached_return_t rc
;
5322 memcached_stat_st
*memc_stat
= memcached_stat(memc
, NULL
, &rc
);
5323 test_true(rc
== MEMCACHED_SUCCESS
);
5325 char *bytes
= memcached_stat_get_value(memc
, memc_stat
, "bytes", &rc
);
5326 test_true(rc
== MEMCACHED_SUCCESS
);
5327 test_true(bytes
!= NULL
);
5328 char *bytes_read
= memcached_stat_get_value(memc
, memc_stat
,
5330 test_true(rc
== MEMCACHED_SUCCESS
);
5331 test_true(bytes_read
!= NULL
);
5333 char *bytes_written
= memcached_stat_get_value(memc
, memc_stat
,
5334 "bytes_written", &rc
);
5335 test_true(rc
== MEMCACHED_SUCCESS
);
5336 test_true(bytes_written
!= NULL
);
5338 test_true(strcmp(bytes
, bytes_read
) != 0);
5339 test_true(strcmp(bytes
, bytes_written
) != 0);
5341 /* Release allocated resources */
5344 free(bytes_written
);
5345 memcached_stat_free(NULL
, memc_stat
);
5347 return TEST_SUCCESS
;
5351 * The test case isn't obvious so I should probably document why
5352 * it works the way it does. Bug 442914 was caused by a bug
5353 * in the logic in memcached_purge (it did not handle the case
5354 * where the number of bytes sent was equal to the watermark).
5355 * In this test case, create messages so that we hit that case
5356 * and then disable noreply mode and issue a new command to
5357 * verify that it isn't stuck. If we change the format for the
5358 * delete command or the watermarks, we need to update this
5361 static test_return_t
regression_bug_442914(memcached_st
*memc
)
5363 memcached_return_t rc
;
5364 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
5365 test_true(rc
== MEMCACHED_SUCCESS
);
5366 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1);
5368 uint32_t number_of_hosts
= memcached_server_count(memc
);
5369 memc
->number_of_hosts
= 1;
5374 for (uint32_t x
= 0; x
< 250; ++x
)
5376 len
= (size_t)snprintf(k
, sizeof(k
), "%0250u", x
);
5377 rc
= memcached_delete(memc
, k
, len
, 0);
5378 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5381 (void)snprintf(k
, sizeof(k
), "%037u", 251U);
5384 rc
= memcached_delete(memc
, k
, len
, 0);
5385 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5387 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0);
5388 test_true(rc
== MEMCACHED_SUCCESS
);
5389 rc
= memcached_delete(memc
, k
, len
, 0);
5390 test_true(rc
== MEMCACHED_NOTFOUND
);
5392 memc
->number_of_hosts
= number_of_hosts
;
5394 return TEST_SUCCESS
;
5397 static test_return_t
regression_bug_447342(memcached_st
*memc
)
5399 memcached_server_instance_st
*instance_one
;
5400 memcached_server_instance_st
*instance_two
;
5402 if (memcached_server_count(memc
) < 3 || pre_replication(memc
) != MEMCACHED_SUCCESS
)
5403 return TEST_SKIPPED
;
5405 memcached_return_t rc
;
5407 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 2);
5408 test_true(rc
== MEMCACHED_SUCCESS
);
5410 const size_t max_keys
= 100;
5411 char **keys
= calloc(max_keys
, sizeof(char*));
5412 size_t *key_length
= calloc(max_keys
, sizeof(size_t));
5414 for (size_t x
= 0; x
< max_keys
; ++x
)
5418 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%zu", x
);
5420 test_true(keys
[x
] != NULL
);
5421 rc
= memcached_set(memc
, k
, key_length
[x
], k
, key_length
[x
], 0, 0);
5422 test_true(rc
== MEMCACHED_SUCCESS
);
5426 ** We are using the quiet commands to store the replicas, so we need
5427 ** to ensure that all of them are processed before we can continue.
5428 ** In the test we go directly from storing the object to trying to
5429 ** receive the object from all of the different servers, so we
5430 ** could end up in a race condition (the memcached server hasn't yet
5431 ** processed the quiet command from the replication set when it process
5432 ** the request from the other client (created by the clone)). As a
5433 ** workaround for that we call memcached_quit to send the quit command
5434 ** to the server and wait for the response ;-) If you use the test code
5435 ** as an example for your own code, please note that you shouldn't need
5438 memcached_quit(memc
);
5440 /* Verify that all messages are stored, and we didn't stuff too much
5443 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5444 test_true(rc
== MEMCACHED_SUCCESS
);
5447 memcached_execute_fn callbacks
[1]= { [0]= &callback_counter
};
5448 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5449 /* Verify that we received all of the key/value pairs */
5450 test_true(counter
== max_keys
);
5452 memcached_quit(memc
);
5454 * Don't do the following in your code. I am abusing the internal details
5455 * within the library, and this is not a supported interface.
5456 * This is to verify correct behavior in the library. Fake that two servers
5459 instance_one
= memcached_server_instance_fetch(memc
, 0);
5460 instance_two
= memcached_server_instance_fetch(memc
, 2);
5461 in_port_t port0
= instance_one
->port
;
5462 in_port_t port2
= instance_two
->port
;
5464 instance_one
->port
= 0;
5465 instance_two
->port
= 0;
5467 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5468 test_true(rc
== MEMCACHED_SUCCESS
);
5471 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5472 test_true(counter
== (unsigned int)max_keys
);
5474 /* restore the memc handle */
5475 instance_one
->port
= port0
;
5476 instance_two
->port
= port2
;
5478 memcached_quit(memc
);
5480 /* Remove half of the objects */
5481 for (size_t x
= 0; x
< max_keys
; ++x
)
5485 rc
= memcached_delete(memc
, keys
[x
], key_length
[x
], 0);
5486 test_true(rc
== MEMCACHED_SUCCESS
);
5490 memcached_quit(memc
);
5491 instance_one
->port
= 0;
5492 instance_two
->port
= 0;
5494 /* now retry the command, this time we should have cache misses */
5495 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5496 test_true(rc
== MEMCACHED_SUCCESS
);
5499 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5500 test_true(counter
== (unsigned int)(max_keys
>> 1));
5502 /* Release allocated resources */
5503 for (size_t x
= 0; x
< max_keys
; ++x
)
5510 /* restore the memc handle */
5511 instance_one
->port
= port0
;
5512 instance_two
->port
= port2
;
5514 return TEST_SUCCESS
;
5517 static test_return_t
regression_bug_463297(memcached_st
*memc
)
5519 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
5520 test_true(memc_clone
!= NULL
);
5521 test_true(memcached_version(memc_clone
) == MEMCACHED_SUCCESS
);
5523 memcached_server_instance_st
*instance
=
5524 memcached_server_instance_fetch(memc_clone
, 0);
5526 if (instance
->major_version
> 1 ||
5527 (instance
->major_version
== 1 &&
5528 instance
->minor_version
> 2))
5530 /* Binary protocol doesn't support deferred delete */
5531 memcached_st
*bin_clone
= memcached_clone(NULL
, memc
);
5532 test_true(bin_clone
!= NULL
);
5533 test_true(memcached_behavior_set(bin_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1) == MEMCACHED_SUCCESS
);
5534 test_true(memcached_delete(bin_clone
, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS
);
5535 memcached_free(bin_clone
);
5537 memcached_quit(memc_clone
);
5539 /* If we know the server version, deferred delete should fail
5540 * with invalid arguments */
5541 test_true(memcached_delete(memc_clone
, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS
);
5543 /* If we don't know the server version, we should get a protocol error */
5544 memcached_return_t rc
= memcached_delete(memc
, "foo", 3, 1);
5546 /* but there is a bug in some of the memcached servers (1.4) that treats
5547 * the counter as noreply so it doesn't send the proper error message
5549 test_true(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5551 /* And buffered mode should be disabled and we should get protocol error */
5552 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1) == MEMCACHED_SUCCESS
);
5553 rc
= memcached_delete(memc
, "foo", 3, 1);
5554 test_true(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5556 /* Same goes for noreply... */
5557 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1) == MEMCACHED_SUCCESS
);
5558 rc
= memcached_delete(memc
, "foo", 3, 1);
5559 test_true(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5561 /* but a normal request should go through (and be buffered) */
5562 test_true((rc
= memcached_delete(memc
, "foo", 3, 0)) == MEMCACHED_BUFFERED
);
5563 test_true(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
5565 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 0) == MEMCACHED_SUCCESS
);
5566 /* unbuffered noreply should be success */
5567 test_true(memcached_delete(memc
, "foo", 3, 0) == MEMCACHED_SUCCESS
);
5568 /* unbuffered with reply should be not found... */
5569 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0) == MEMCACHED_SUCCESS
);
5570 test_true(memcached_delete(memc
, "foo", 3, 0) == MEMCACHED_NOTFOUND
);
5573 memcached_free(memc_clone
);
5574 return TEST_SUCCESS
;
5578 /* Test memcached_server_get_last_disconnect
5579 * For a working server set, shall be NULL
5580 * For a set of non existing server, shall not be NULL
5582 static test_return_t
test_get_last_disconnect(memcached_st
*memc
)
5584 memcached_return_t rc
;
5585 memcached_server_st
*disconnected_server
;
5587 /* With the working set of server */
5588 const char *key
= "marmotte";
5589 const char *value
= "milka";
5591 rc
= memcached_set(memc
, key
, strlen(key
),
5592 value
, strlen(value
),
5593 (time_t)0, (uint32_t)0);
5594 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5596 disconnected_server
= memcached_server_get_last_disconnect(memc
);
5597 test_true(disconnected_server
== NULL
);
5599 /* With a non existing server */
5601 memcached_server_st
*servers
;
5603 const char *server_list
= "localhost:9";
5605 servers
= memcached_servers_parse(server_list
);
5607 mine
= memcached_create(NULL
);
5608 rc
= memcached_server_push(mine
, servers
);
5609 test_true(rc
== MEMCACHED_SUCCESS
);
5610 memcached_server_list_free(servers
);
5613 rc
= memcached_set(mine
, key
, strlen(key
),
5614 value
, strlen(value
),
5615 (time_t)0, (uint32_t)0);
5616 test_true(rc
!= MEMCACHED_SUCCESS
);
5618 disconnected_server
= memcached_server_get_last_disconnect(mine
);
5619 test_true(disconnected_server
!= NULL
);
5620 test_true(disconnected_server
->port
== 9);
5621 test_true(strncmp(disconnected_server
->hostname
,"localhost",9) == 0);
5623 memcached_quit(mine
);
5624 memcached_free(mine
);
5626 return TEST_SUCCESS
;
5630 * This test ensures that the failure counter isn't incremented during
5631 * normal termination of the memcached instance.
5633 static test_return_t
wrong_failure_counter_test(memcached_st
*memc
)
5635 memcached_return_t rc
;
5636 memcached_server_instance_st
*instance
;
5638 /* Set value to force connection to the server */
5639 const char *key
= "marmotte";
5640 const char *value
= "milka";
5643 * Please note that I'm abusing the internal structures in libmemcached
5644 * in a non-portable way and you shouldn't be doing this. I'm only
5645 * doing this in order to verify that the library works the way it should
5647 uint32_t number_of_hosts
= memcached_server_count(memc
);
5648 memc
->number_of_hosts
= 1;
5650 /* Ensure that we are connected to the server by setting a value */
5651 rc
= memcached_set(memc
, key
, strlen(key
),
5652 value
, strlen(value
),
5653 (time_t)0, (uint32_t)0);
5654 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5657 instance
= memcached_server_instance_fetch(memc
, 0);
5658 /* The test is to see that the memcached_quit doesn't increase the
5659 * the server failure conter, so let's ensure that it is zero
5660 * before sending quit
5662 instance
->server_failure_counter
= 0;
5664 memcached_quit(memc
);
5666 /* Verify that it memcached_quit didn't increment the failure counter
5667 * Please note that this isn't bullet proof, because an error could
5670 test_true(instance
->server_failure_counter
== 0);
5672 /* restore the instance */
5673 memc
->number_of_hosts
= number_of_hosts
;
5675 return TEST_SUCCESS
;
5682 * Test that ensures mget_execute does not end into recursive calls that finally fails
5684 static test_return_t
regression_bug_490486(memcached_st
*memc
)
5686 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
5687 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 1);
5688 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, 1000);
5689 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, 1);
5690 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 3600);
5693 * I only want to hit _one_ server so I know the number of requests I'm
5694 * sending in the pipeline.
5696 uint32_t number_of_hosts
= memc
->number_of_hosts
;
5697 memc
->number_of_hosts
= 1;
5698 size_t max_keys
= 20480;
5701 char **keys
= calloc(max_keys
, sizeof(char*));
5702 size_t *key_length
=calloc(max_keys
, sizeof(size_t));
5704 /* First add all of the items.. */
5705 char blob
[1024]= { 0 };
5706 memcached_return rc
;
5707 for (size_t x
= 0; x
< max_keys
; ++x
)
5710 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%zu", x
);
5712 assert(keys
[x
] != NULL
);
5713 rc
= memcached_set(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
5714 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5717 /* Try to get all of them with a large multiget */
5719 memcached_execute_function callbacks
[1]= { [0]= &callback_counter
};
5720 rc
= memcached_mget_execute(memc
, (const char**)keys
, key_length
,
5721 (size_t)max_keys
, callbacks
, &counter
, 1);
5723 assert(rc
== MEMCACHED_SUCCESS
);
5724 char* the_value
= NULL
;
5725 char the_key
[MEMCACHED_MAX_KEY
];
5726 size_t the_key_length
;
5727 size_t the_value_length
;
5731 the_value
= memcached_fetch(memc
, the_key
, &the_key_length
, &the_value_length
, &the_flags
, &rc
);
5733 if ((the_value
!= NULL
) && (rc
== MEMCACHED_SUCCESS
))
5739 } while ( (the_value
!= NULL
) && (rc
== MEMCACHED_SUCCESS
));
5742 assert(rc
== MEMCACHED_END
);
5744 /* Verify that we got all of the items */
5745 assert(counter
== max_keys
);
5747 /* Release all allocated resources */
5748 for (size_t x
= 0; x
< max_keys
; ++x
)
5755 memc
->number_of_hosts
= number_of_hosts
;
5757 return TEST_SUCCESS
;
5763 test_st udp_setup_server_tests
[] ={
5764 {"set_udp_behavior_test", 0, (test_callback_fn
)set_udp_behavior_test
},
5765 {"add_tcp_server_udp_client_test", 0, (test_callback_fn
)add_tcp_server_udp_client_test
},
5766 {"add_udp_server_tcp_client_test", 0, (test_callback_fn
)add_udp_server_tcp_client_test
},
5770 test_st upd_io_tests
[] ={
5771 {"udp_set_test", 0, (test_callback_fn
)udp_set_test
},
5772 {"udp_buffered_set_test", 0, (test_callback_fn
)udp_buffered_set_test
},
5773 {"udp_set_too_big_test", 0, (test_callback_fn
)udp_set_too_big_test
},
5774 {"udp_delete_test", 0, (test_callback_fn
)udp_delete_test
},
5775 {"udp_buffered_delete_test", 0, (test_callback_fn
)udp_buffered_delete_test
},
5776 {"udp_verbosity_test", 0, (test_callback_fn
)udp_verbosity_test
},
5777 {"udp_quit_test", 0, (test_callback_fn
)udp_quit_test
},
5778 {"udp_flush_test", 0, (test_callback_fn
)udp_flush_test
},
5779 {"udp_incr_test", 0, (test_callback_fn
)udp_incr_test
},
5780 {"udp_decr_test", 0, (test_callback_fn
)udp_decr_test
},
5781 {"udp_stat_test", 0, (test_callback_fn
)udp_stat_test
},
5782 {"udp_version_test", 0, (test_callback_fn
)udp_version_test
},
5783 {"udp_get_test", 0, (test_callback_fn
)udp_get_test
},
5784 {"udp_mixed_io_test", 0, (test_callback_fn
)udp_mixed_io_test
},
5788 /* Clean the server before beginning testing */
5790 {"flush", 0, (test_callback_fn
)flush_test
},
5791 {"init", 0, (test_callback_fn
)init_test
},
5792 {"allocation", 0, (test_callback_fn
)allocation_test
},
5793 {"server_list_null_test", 0, (test_callback_fn
)server_list_null_test
},
5794 {"server_unsort", 0, (test_callback_fn
)server_unsort_test
},
5795 {"server_sort", 0, (test_callback_fn
)server_sort_test
},
5796 {"server_sort2", 0, (test_callback_fn
)server_sort2_test
},
5797 {"clone_test", 0, (test_callback_fn
)clone_test
},
5798 {"connection_test", 0, (test_callback_fn
)connection_test
},
5799 {"callback_test", 0, (test_callback_fn
)callback_test
},
5800 {"userdata_test", 0, (test_callback_fn
)userdata_test
},
5801 {"error", 0, (test_callback_fn
)error_test
},
5802 {"set", 0, (test_callback_fn
)set_test
},
5803 {"set2", 0, (test_callback_fn
)set_test2
},
5804 {"set3", 0, (test_callback_fn
)set_test3
},
5805 {"dump", 1, (test_callback_fn
)dump_test
},
5806 {"add", 1, (test_callback_fn
)add_test
},
5807 {"replace", 1, (test_callback_fn
)replace_test
},
5808 {"delete", 1, (test_callback_fn
)delete_test
},
5809 {"get", 1, (test_callback_fn
)get_test
},
5810 {"get2", 0, (test_callback_fn
)get_test2
},
5811 {"get3", 0, (test_callback_fn
)get_test3
},
5812 {"get4", 0, (test_callback_fn
)get_test4
},
5813 {"partial mget", 0, (test_callback_fn
)get_test5
},
5814 {"stats_servername", 0, (test_callback_fn
)stats_servername_test
},
5815 {"increment", 0, (test_callback_fn
)increment_test
},
5816 {"increment_with_initial", 1, (test_callback_fn
)increment_with_initial_test
},
5817 {"decrement", 0, (test_callback_fn
)decrement_test
},
5818 {"decrement_with_initial", 1, (test_callback_fn
)decrement_with_initial_test
},
5819 {"increment_by_key", 0, (test_callback_fn
)increment_by_key_test
},
5820 {"increment_with_initial_by_key", 1, (test_callback_fn
)increment_with_initial_by_key_test
},
5821 {"decrement_by_key", 0, (test_callback_fn
)decrement_by_key_test
},
5822 {"decrement_with_initial_by_key", 1, (test_callback_fn
)decrement_with_initial_by_key_test
},
5823 {"quit", 0, (test_callback_fn
)quit_test
},
5824 {"mget", 1, (test_callback_fn
)mget_test
},
5825 {"mget_result", 1, (test_callback_fn
)mget_result_test
},
5826 {"mget_result_alloc", 1, (test_callback_fn
)mget_result_alloc_test
},
5827 {"mget_result_function", 1, (test_callback_fn
)mget_result_function
},
5828 {"mget_execute", 1, (test_callback_fn
)mget_execute
},
5829 {"mget_end", 0, (test_callback_fn
)mget_end
},
5830 {"get_stats", 0, (test_callback_fn
)get_stats
},
5831 {"add_host_test", 0, (test_callback_fn
)add_host_test
},
5832 {"add_host_test_1", 0, (test_callback_fn
)add_host_test1
},
5833 {"get_stats_keys", 0, (test_callback_fn
)get_stats_keys
},
5834 {"version_string_test", 0, (test_callback_fn
)version_string_test
},
5835 {"bad_key", 1, (test_callback_fn
)bad_key_test
},
5836 {"memcached_server_cursor", 1, (test_callback_fn
)memcached_server_cursor_test
},
5837 {"read_through", 1, (test_callback_fn
)read_through
},
5838 {"delete_through", 1, (test_callback_fn
)delete_through
},
5839 {"noreply", 1, (test_callback_fn
)noreply_test
},
5840 {"analyzer", 1, (test_callback_fn
)analyzer_test
},
5841 #ifdef HAVE_LIBMEMCACHEDUTIL
5842 {"connectionpool", 1, (test_callback_fn
)connection_pool_test
},
5844 {"test_get_last_disconnect", 1, (test_callback_fn
)test_get_last_disconnect
},
5848 test_st behavior_tests
[] ={
5849 {"behavior_test", 0, (test_callback_fn
)behavior_test
},
5850 {"MEMCACHED_BEHAVIOR_CORK", 0, (test_callback_fn
)MEMCACHED_BEHAVIOR_CORK_test
},
5854 test_st async_tests
[] ={
5855 {"add", 1, (test_callback_fn
)add_wrapper
},
5859 test_st string_tests
[] ={
5860 {"string static with null", 0, (test_callback_fn
)string_static_null
},
5861 {"string alloc with null", 0, (test_callback_fn
)string_alloc_null
},
5862 {"string alloc with 1K", 0, (test_callback_fn
)string_alloc_with_size
},
5863 {"string alloc with malloc failure", 0, (test_callback_fn
)string_alloc_with_size_toobig
},
5864 {"string append", 0, (test_callback_fn
)string_alloc_append
},
5865 {"string append failure (too big)", 0, (test_callback_fn
)string_alloc_append_toobig
},
5866 {0, 0, (test_callback_fn
)0}
5869 test_st result_tests
[] ={
5870 {"result static", 0, (test_callback_fn
)result_static
},
5871 {"result alloc", 0, (test_callback_fn
)result_alloc
},
5872 {0, 0, (test_callback_fn
)0}
5875 test_st version_1_2_3
[] ={
5876 {"append", 0, (test_callback_fn
)append_test
},
5877 {"prepend", 0, (test_callback_fn
)prepend_test
},
5878 {"cas", 0, (test_callback_fn
)cas_test
},
5879 {"cas2", 0, (test_callback_fn
)cas2_test
},
5880 {"append_binary", 0, (test_callback_fn
)append_binary_test
},
5881 {0, 0, (test_callback_fn
)0}
5884 test_st user_tests
[] ={
5885 {"user_supplied_bug1", 0, (test_callback_fn
)user_supplied_bug1
},
5886 {"user_supplied_bug2", 0, (test_callback_fn
)user_supplied_bug2
},
5887 {"user_supplied_bug3", 0, (test_callback_fn
)user_supplied_bug3
},
5888 {"user_supplied_bug4", 0, (test_callback_fn
)user_supplied_bug4
},
5889 {"user_supplied_bug5", 1, (test_callback_fn
)user_supplied_bug5
},
5890 {"user_supplied_bug6", 1, (test_callback_fn
)user_supplied_bug6
},
5891 {"user_supplied_bug7", 1, (test_callback_fn
)user_supplied_bug7
},
5892 {"user_supplied_bug8", 1, (test_callback_fn
)user_supplied_bug8
},
5893 {"user_supplied_bug9", 1, (test_callback_fn
)user_supplied_bug9
},
5894 {"user_supplied_bug10", 1, (test_callback_fn
)user_supplied_bug10
},
5895 {"user_supplied_bug11", 1, (test_callback_fn
)user_supplied_bug11
},
5896 {"user_supplied_bug12", 1, (test_callback_fn
)user_supplied_bug12
},
5897 {"user_supplied_bug13", 1, (test_callback_fn
)user_supplied_bug13
},
5898 {"user_supplied_bug14", 1, (test_callback_fn
)user_supplied_bug14
},
5899 {"user_supplied_bug15", 1, (test_callback_fn
)user_supplied_bug15
},
5900 {"user_supplied_bug16", 1, (test_callback_fn
)user_supplied_bug16
},
5903 ** It seems to be something weird with the character sets..
5904 ** value_fetch is unable to parse the value line (iscntrl "fails"), so I
5905 ** guess I need to find out how this is supposed to work.. Perhaps I need
5906 ** to run the test in a specific locale (I tried zh_CN.UTF-8 without success,
5907 ** so just disable the code for now...).
5909 {"user_supplied_bug17", 1, (test_callback_fn
)user_supplied_bug17
},
5911 {"user_supplied_bug18", 1, (test_callback_fn
)user_supplied_bug18
},
5912 {"user_supplied_bug19", 1, (test_callback_fn
)user_supplied_bug19
},
5913 {"user_supplied_bug20", 1, (test_callback_fn
)user_supplied_bug20
},
5914 {"user_supplied_bug21", 1, (test_callback_fn
)user_supplied_bug21
},
5915 {"wrong_failure_counter_test", 1, (test_callback_fn
)wrong_failure_counter_test
},
5916 {0, 0, (test_callback_fn
)0}
5919 test_st replication_tests
[]= {
5920 {"set", 1, (test_callback_fn
)replication_set_test
},
5921 {"get", 0, (test_callback_fn
)replication_get_test
},
5922 {"mget", 0, (test_callback_fn
)replication_mget_test
},
5923 {"delete", 0, (test_callback_fn
)replication_delete_test
},
5924 {"rand_mget", 0, (test_callback_fn
)replication_randomize_mget_test
},
5925 {0, 0, (test_callback_fn
)0}
5929 * The following test suite is used to verify that we don't introduce
5930 * regression bugs. If you want more information about the bug / test,
5931 * you should look in the bug report at
5932 * http://bugs.launchpad.net/libmemcached
5934 test_st regression_tests
[]= {
5935 {"lp:434484", 1, (test_callback_fn
)regression_bug_434484
},
5936 {"lp:434843", 1, (test_callback_fn
)regression_bug_434843
},
5937 {"lp:434843 buffered", 1, (test_callback_fn
)regression_bug_434843_buffered
},
5938 {"lp:421108", 1, (test_callback_fn
)regression_bug_421108
},
5939 {"lp:442914", 1, (test_callback_fn
)regression_bug_442914
},
5940 {"lp:447342", 1, (test_callback_fn
)regression_bug_447342
},
5941 {"lp:463297", 1, (test_callback_fn
)regression_bug_463297
},
5942 {"lp:490486", 1, (test_callback_fn
)regression_bug_490486
},
5943 {0, 0, (test_callback_fn
)0}
5946 test_st ketama_compatibility
[]= {
5947 {"libmemcached", 1, (test_callback_fn
)ketama_compatibility_libmemcached
},
5948 {"spymemcached", 1, (test_callback_fn
)ketama_compatibility_spymemcached
},
5949 {0, 0, (test_callback_fn
)0}
5952 test_st generate_tests
[] ={
5953 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
5954 {"generate_data", 1, (test_callback_fn
)generate_data
},
5955 {"get_read", 0, (test_callback_fn
)get_read
},
5956 {"delete_generate", 0, (test_callback_fn
)delete_generate
},
5957 {"generate_buffer_data", 1, (test_callback_fn
)generate_buffer_data
},
5958 {"delete_buffer", 0, (test_callback_fn
)delete_buffer_generate
},
5959 {"generate_data", 1, (test_callback_fn
)generate_data
},
5960 {"mget_read", 0, (test_callback_fn
)mget_read
},
5961 {"mget_read_result", 0, (test_callback_fn
)mget_read_result
},
5962 {"mget_read_function", 0, (test_callback_fn
)mget_read_function
},
5963 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5964 {"generate_large_pairs", 1, (test_callback_fn
)generate_large_pairs
},
5965 {"generate_data", 1, (test_callback_fn
)generate_data
},
5966 {"generate_buffer_data", 1, (test_callback_fn
)generate_buffer_data
},
5967 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5968 {0, 0, (test_callback_fn
)0}
5971 test_st consistent_tests
[] ={
5972 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
5973 {"generate_data", 1, (test_callback_fn
)generate_data
},
5974 {"get_read", 0, (test_callback_fn
)get_read_count
},
5975 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5976 {0, 0, (test_callback_fn
)0}
5979 test_st consistent_weighted_tests
[] ={
5980 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
5981 {"generate_data", 1, (test_callback_fn
)generate_data_with_stats
},
5982 {"get_read", 0, (test_callback_fn
)get_read_count
},
5983 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5984 {0, 0, (test_callback_fn
)0}
5987 test_st hsieh_availability
[] ={
5988 {"hsieh_avaibility_test", 0, (test_callback_fn
)hsieh_avaibility_test
},
5989 {0, 0, (test_callback_fn
)0}
5993 test_st hash_sanity
[] ={
5994 {"hash sanity", 0, (test_callback_fn
)hash_sanity_test
},
5995 {0, 0, (test_callback_fn
)0}
5999 test_st ketama_auto_eject_hosts
[] ={
6000 {"auto_eject_hosts", 1, (test_callback_fn
)auto_eject_hosts
},
6001 {"output_ketama_weighted_keys", 1, (test_callback_fn
)output_ketama_weighted_keys
},
6002 {0, 0, (test_callback_fn
)0}
6005 test_st hash_tests
[] ={
6006 {"one_at_a_time_run", 0, (test_callback_fn
)one_at_a_time_run
},
6007 {"md5", 0, (test_callback_fn
)md5_run
},
6008 {"crc", 0, (test_callback_fn
)crc_run
},
6009 {"fnv1_64", 0, (test_callback_fn
)fnv1_64_run
},
6010 {"fnv1a_64", 0, (test_callback_fn
)fnv1a_64_run
},
6011 {"fnv1_32", 0, (test_callback_fn
)fnv1_32_run
},
6012 {"fnv1a_32", 0, (test_callback_fn
)fnv1a_32_run
},
6013 {"hsieh", 0, (test_callback_fn
)hsieh_run
},
6014 {"murmur", 0, (test_callback_fn
)murmur_run
},
6015 {"jenkis", 0, (test_callback_fn
)jenkins_run
},
6016 {0, 0, (test_callback_fn
)0}
6019 collection_st collection
[] ={
6021 {"hash_sanity", 0, 0, hash_sanity
},
6023 {"hsieh_availability", 0, 0, hsieh_availability
},
6024 {"udp_setup", (test_callback_fn
)init_udp
, 0, udp_setup_server_tests
},
6025 {"udp_io", (test_callback_fn
)init_udp
, 0, upd_io_tests
},
6026 {"udp_binary_io", (test_callback_fn
)binary_init_udp
, 0, upd_io_tests
},
6027 {"block", 0, 0, tests
},
6028 {"binary", (test_callback_fn
)pre_binary
, 0, tests
},
6029 {"nonblock", (test_callback_fn
)pre_nonblock
, 0, tests
},
6030 {"nodelay", (test_callback_fn
)pre_nodelay
, 0, tests
},
6031 {"settimer", (test_callback_fn
)pre_settimer
, 0, tests
},
6032 {"md5", (test_callback_fn
)pre_md5
, 0, tests
},
6033 {"crc", (test_callback_fn
)pre_crc
, 0, tests
},
6034 {"hsieh", (test_callback_fn
)pre_hsieh
, 0, tests
},
6035 {"jenkins", (test_callback_fn
)pre_jenkins
, 0, tests
},
6036 {"fnv1_64", (test_callback_fn
)pre_hash_fnv1_64
, 0, tests
},
6037 {"fnv1a_64", (test_callback_fn
)pre_hash_fnv1a_64
, 0, tests
},
6038 {"fnv1_32", (test_callback_fn
)pre_hash_fnv1_32
, 0, tests
},
6039 {"fnv1a_32", (test_callback_fn
)pre_hash_fnv1a_32
, 0, tests
},
6040 {"ketama", (test_callback_fn
)pre_behavior_ketama
, 0, tests
},
6041 {"ketama_auto_eject_hosts", (test_callback_fn
)pre_behavior_ketama
, 0, ketama_auto_eject_hosts
},
6042 {"unix_socket", (test_callback_fn
)pre_unix_socket
, 0, tests
},
6043 {"unix_socket_nodelay", (test_callback_fn
)pre_nodelay
, 0, tests
},
6044 {"poll_timeout", (test_callback_fn
)poll_timeout
, 0, tests
},
6045 {"gets", (test_callback_fn
)enable_cas
, 0, tests
},
6046 {"consistent_crc", (test_callback_fn
)enable_consistent_crc
, 0, tests
},
6047 {"consistent_hsieh", (test_callback_fn
)enable_consistent_hsieh
, 0, tests
},
6048 #ifdef MEMCACHED_ENABLE_DEPRECATED
6049 {"deprecated_memory_allocators", (test_callback_fn
)deprecated_set_memory_alloc
, 0, tests
},
6051 {"memory_allocators", (test_callback_fn
)set_memory_alloc
, 0, tests
},
6052 {"prefix", (test_callback_fn
)set_prefix
, 0, tests
},
6053 {"version_1_2_3", (test_callback_fn
)check_for_1_2_3
, 0, version_1_2_3
},
6054 {"string", 0, 0, string_tests
},
6055 {"result", 0, 0, result_tests
},
6056 {"async", (test_callback_fn
)pre_nonblock
, 0, async_tests
},
6057 {"async_binary", (test_callback_fn
)pre_nonblock_binary
, 0, async_tests
},
6058 {"user", 0, 0, user_tests
},
6059 {"generate", 0, 0, generate_tests
},
6060 {"generate_hsieh", (test_callback_fn
)pre_hsieh
, 0, generate_tests
},
6061 {"generate_ketama", (test_callback_fn
)pre_behavior_ketama
, 0, generate_tests
},
6062 {"generate_hsieh_consistent", (test_callback_fn
)enable_consistent_hsieh
, 0, generate_tests
},
6063 {"generate_md5", (test_callback_fn
)pre_md5
, 0, generate_tests
},
6064 {"generate_murmur", (test_callback_fn
)pre_murmur
, 0, generate_tests
},
6065 {"generate_jenkins", (test_callback_fn
)pre_jenkins
, 0, generate_tests
},
6066 {"generate_nonblock", (test_callback_fn
)pre_nonblock
, 0, generate_tests
},
6068 {"generate_corked", (test_callback_fn
)pre_cork
, 0, generate_tests
},
6069 {"generate_corked_and_nonblock", (test_callback_fn
)pre_cork_and_nonblock
, 0, generate_tests
},
6070 {"consistent_not", 0, 0, consistent_tests
},
6071 {"consistent_ketama", (test_callback_fn
)pre_behavior_ketama
, 0, consistent_tests
},
6072 {"consistent_ketama_weighted", (test_callback_fn
)pre_behavior_ketama_weighted
, 0, consistent_weighted_tests
},
6073 {"ketama_compat", 0, 0, ketama_compatibility
},
6074 {"test_hashes", 0, 0, hash_tests
},
6075 {"replication", (test_callback_fn
)pre_replication
, 0, replication_tests
},
6076 {"replication_noblock", (test_callback_fn
)pre_replication_noblock
, 0, replication_tests
},
6077 {"regression", 0, 0, regression_tests
},
6078 {"behaviors", 0, 0, behavior_tests
},
6082 #define SERVERS_TO_CREATE 5
6084 #include "libmemcached_world.h"
6086 void get_world(world_st
*world
)
6088 world
->collections
= collection
;
6090 world
->create
= (test_callback_create_fn
)world_create
;
6091 world
->destroy
= (test_callback_fn
)world_destroy
;
6093 world
->test
.startup
= (test_callback_fn
)world_test_startup
;
6094 world
->test
.flush
= (test_callback_fn
)world_flush
;
6095 world
->test
.pre_run
= (test_callback_fn
)world_pre_run
;
6096 world
->test
.post_run
= (test_callback_fn
)world_post_run
;
6097 world
->test
.on_error
= (test_callback_error_fn
)world_on_error
;
6099 world
->collection
.startup
= (test_callback_fn
)world_container_startup
;
6100 world
->collection
.shutdown
= (test_callback_fn
)world_container_shutdown
;
6102 world
->runner
= &defualt_libmemcached_runner
;