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 const memcached_server_st
*server
,
90 size_t bigger
= *((size_t *)(context
));
91 assert(bigger
<= memcached_server_port(server
));
92 *((size_t *)(context
))= memcached_server_port(server
);
94 return MEMCACHED_SUCCESS
;
97 static test_return_t
server_sort_test(memcached_st
*ptr
__attribute__((unused
)))
99 size_t bigger
= 0; /* Prime the value for the test_true in server_display_function */
101 memcached_return_t rc
;
102 memcached_server_fn callbacks
[1];
103 memcached_st
*local_memc
;
105 local_memc
= memcached_create(NULL
);
106 test_true(local_memc
);
107 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
109 for (size_t x
= 0; x
< TEST_PORT_COUNT
; x
++)
111 test_ports
[x
]= (in_port_t
)random() % 64000;
112 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
113 test_true(memcached_server_count(local_memc
) == x
+ 1);
115 test_true(memcached_server_list_count(memcached_server_list(local_memc
)) == x
+1);
117 test_true(rc
== MEMCACHED_SUCCESS
);
120 callbacks
[0]= server_display_function
;
121 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
124 memcached_free(local_memc
);
129 static test_return_t
server_sort2_test(memcached_st
*ptr
__attribute__((unused
)))
131 size_t bigger
= 0; /* Prime the value for the test_true in server_display_function */
132 memcached_return_t rc
;
133 memcached_server_fn callbacks
[1];
134 memcached_st
*local_memc
;
135 memcached_server_instance_st instance
;
137 local_memc
= memcached_create(NULL
);
138 test_true(local_memc
);
139 rc
= memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
140 test_true(rc
== MEMCACHED_SUCCESS
);
142 rc
= memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43043, 0);
143 test_true(rc
== MEMCACHED_SUCCESS
);
144 instance
= memcached_server_instance_by_position(local_memc
, 0);
145 test_true(memcached_server_port(instance
) == 43043);
147 rc
= memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43042, 0);
148 test_true(rc
== MEMCACHED_SUCCESS
);
150 instance
= memcached_server_instance_by_position(local_memc
, 0);
151 test_true(memcached_server_port(instance
) == 43042);
153 instance
= memcached_server_instance_by_position(local_memc
, 1);
154 test_true(memcached_server_port(instance
) == 43043);
156 callbacks
[0]= server_display_function
;
157 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
160 memcached_free(local_memc
);
165 static memcached_return_t
server_print_callback(const memcached_st
*ptr
__attribute__((unused
)),
166 const memcached_server_st
*server
,
167 void *context
__attribute__((unused
)))
169 (void)server
; // Just in case we aren't printing.
172 fprintf(stderr
, "%s(%d)", memcached_server_name(server
), memcached_server_port(server
));
175 return MEMCACHED_SUCCESS
;
178 static test_return_t
memcached_server_remove_test(memcached_st
*ptr
__attribute__((unused
)))
180 memcached_return_t rc
;
181 memcached_st local_memc
;
183 memcached_server_st
*servers
;
184 memcached_server_fn callbacks
[1];
186 const char *server_string
= "localhost:4444, localhost:4445, localhost:4446, localhost:4447, localhost, 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";
188 memc
= memcached_create(&local_memc
);
190 servers
= memcached_servers_parse(server_string
);
192 rc
= memcached_server_push(memc
, servers
);
193 memcached_server_list_free(servers
);
195 callbacks
[0]= server_print_callback
;
196 memcached_server_cursor(memc
, callbacks
, NULL
, 1);
198 memcached_free(memc
);
203 static memcached_return_t
server_display_unsort_function(const memcached_st
*ptr
__attribute__((unused
)),
204 const memcached_server_st
*server
,
208 uint32_t x
= *((uint32_t *)(context
));
210 assert(test_ports
[x
] == server
->port
);
211 *((uint32_t *)(context
))= ++x
;
213 return MEMCACHED_SUCCESS
;
216 static test_return_t
server_unsort_test(memcached_st
*ptr
__attribute__((unused
)))
218 size_t counter
= 0; /* Prime the value for the test_true in server_display_function */
219 size_t bigger
= 0; /* Prime the value for the test_true in server_display_function */
220 memcached_return_t rc
;
221 memcached_server_fn callbacks
[1];
222 memcached_st
*local_memc
;
224 local_memc
= memcached_create(NULL
);
225 test_true(local_memc
);
227 for (size_t x
= 0; x
< TEST_PORT_COUNT
; x
++)
229 test_ports
[x
]= (in_port_t
)(random() % 64000);
230 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
231 test_true(memcached_server_count(local_memc
) == x
+1);
233 test_true(memcached_server_list_count(memcached_server_list(local_memc
)) == x
+1);
235 test_true(rc
== MEMCACHED_SUCCESS
);
238 callbacks
[0]= server_display_unsort_function
;
239 memcached_server_cursor(local_memc
, callbacks
, (void *)&counter
, 1);
241 /* Now we sort old data! */
242 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
243 callbacks
[0]= server_display_function
;
244 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
247 memcached_free(local_memc
);
252 static test_return_t
allocation_test(memcached_st
*not_used
__attribute__((unused
)))
255 memc
= memcached_create(NULL
);
257 memcached_free(memc
);
262 static test_return_t
clone_test(memcached_st
*memc
)
266 memcached_st
*memc_clone
;
267 memc_clone
= memcached_clone(NULL
, NULL
);
268 test_true(memc_clone
);
269 memcached_free(memc_clone
);
272 /* Can we init from null? */
274 memcached_st
*memc_clone
;
275 memc_clone
= memcached_clone(NULL
, memc
);
276 test_true(memc_clone
);
279 test_true(memc_clone
->allocators
.free
== memc
->allocators
.free
);
280 test_true(memc_clone
->allocators
.malloc
== memc
->allocators
.malloc
);
281 test_true(memc_clone
->allocators
.realloc
== memc
->allocators
.realloc
);
282 test_true(memc_clone
->allocators
.calloc
== memc
->allocators
.calloc
);
285 test_true(memc_clone
->connect_timeout
== memc
->connect_timeout
);
286 test_true(memc_clone
->delete_trigger
== memc
->delete_trigger
);
287 test_true(memc_clone
->distribution
== memc
->distribution
);
288 { // Test all of the flags
289 test_true(memc_clone
->flags
.no_block
== memc
->flags
.no_block
);
290 test_true(memc_clone
->flags
.tcp_nodelay
== memc
->flags
.tcp_nodelay
);
291 test_true(memc_clone
->flags
.reuse_memory
== memc
->flags
.reuse_memory
);
292 test_true(memc_clone
->flags
.use_cache_lookups
== memc
->flags
.use_cache_lookups
);
293 test_true(memc_clone
->flags
.support_cas
== memc
->flags
.support_cas
);
294 test_true(memc_clone
->flags
.buffer_requests
== memc
->flags
.buffer_requests
);
295 test_true(memc_clone
->flags
.use_sort_hosts
== memc
->flags
.use_sort_hosts
);
296 test_true(memc_clone
->flags
.verify_key
== memc
->flags
.verify_key
);
297 test_true(memc_clone
->flags
.ketama_weighted
== memc
->flags
.ketama_weighted
);
298 test_true(memc_clone
->flags
.binary_protocol
== memc
->flags
.binary_protocol
);
299 test_true(memc_clone
->flags
.hash_with_prefix_key
== memc
->flags
.hash_with_prefix_key
);
300 test_true(memc_clone
->flags
.no_reply
== memc
->flags
.no_reply
);
301 test_true(memc_clone
->flags
.use_udp
== memc
->flags
.use_udp
);
302 test_true(memc_clone
->flags
.auto_eject_hosts
== memc
->flags
.auto_eject_hosts
);
303 test_true(memc_clone
->flags
.randomize_replica_read
== memc
->flags
.randomize_replica_read
);
305 test_true(memc_clone
->get_key_failure
== memc
->get_key_failure
);
306 test_true(hashkit_compare(&memc_clone
->hashkit
, &memc
->hashkit
));
307 test_true(hashkit_compare(&memc_clone
->distribution_hashkit
, &memc
->distribution_hashkit
));
308 test_true(memc_clone
->io_bytes_watermark
== memc
->io_bytes_watermark
);
309 test_true(memc_clone
->io_msg_watermark
== memc
->io_msg_watermark
);
310 test_true(memc_clone
->io_key_prefetch
== memc
->io_key_prefetch
);
311 test_true(memc_clone
->on_cleanup
== memc
->on_cleanup
);
312 test_true(memc_clone
->on_clone
== memc
->on_clone
);
313 test_true(memc_clone
->poll_timeout
== memc
->poll_timeout
);
314 test_true(memc_clone
->rcv_timeout
== memc
->rcv_timeout
);
315 test_true(memc_clone
->recv_size
== memc
->recv_size
);
316 test_true(memc_clone
->retry_timeout
== memc
->retry_timeout
);
317 test_true(memc_clone
->send_size
== memc
->send_size
);
318 test_true(memc_clone
->server_failure_limit
== memc
->server_failure_limit
);
319 test_true(memc_clone
->snd_timeout
== memc
->snd_timeout
);
320 test_true(memc_clone
->user_data
== memc
->user_data
);
322 memcached_free(memc_clone
);
325 /* Can we init from struct? */
327 memcached_st declared_clone
;
328 memcached_st
*memc_clone
;
329 memset(&declared_clone
, 0 , sizeof(memcached_st
));
330 memc_clone
= memcached_clone(&declared_clone
, NULL
);
331 test_true(memc_clone
);
332 memcached_free(memc_clone
);
335 /* Can we init from struct? */
337 memcached_st declared_clone
;
338 memcached_st
*memc_clone
;
339 memset(&declared_clone
, 0 , sizeof(memcached_st
));
340 memc_clone
= memcached_clone(&declared_clone
, memc
);
341 test_true(memc_clone
);
342 memcached_free(memc_clone
);
348 static test_return_t
userdata_test(memcached_st
*memc
)
351 test_true(memcached_set_user_data(memc
, foo
) == NULL
);
352 test_true(memcached_get_user_data(memc
) == foo
);
353 test_true(memcached_set_user_data(memc
, NULL
) == foo
);
358 static test_return_t
connection_test(memcached_st
*memc
)
360 memcached_return_t rc
;
362 rc
= memcached_server_add_with_weight(memc
, "localhost", 0, 0);
363 test_true(rc
== MEMCACHED_SUCCESS
);
368 static test_return_t
error_test(memcached_st
*memc
)
370 memcached_return_t rc
;
371 uint32_t values
[] = { 851992627U, 2337886783U, 3196981036U, 4001849190U,
372 982370485U, 1263635348U, 4242906218U, 3829656100U,
373 1891735253U, 334139633U, 2257084983U, 3088286104U,
374 13199785U, 2542027183U, 1097051614U, 199566778U,
375 2748246961U, 2465192557U, 1664094137U, 2405439045U,
376 1842224848U, 692413798U, 3479807801U, 919913813U,
377 4269430871U, 610793021U, 527273862U, 1437122909U,
378 2300930706U, 2943759320U, 674306647U, 2400528935U,
379 54481931U, 4186304426U, 1741088401U, 2979625118U,
380 4159057246U, 3425930182U, 2593724503U, 1868899624U,
381 1769812374U, 2302537950U, 1110330676U };
383 // You have updated the memcache_error messages but not updated docs/tests.
384 test_true(MEMCACHED_MAXIMUM_RETURN
== 43);
385 for (rc
= MEMCACHED_SUCCESS
; rc
< MEMCACHED_MAXIMUM_RETURN
; rc
++)
388 const char *msg
= memcached_strerror(memc
, rc
);
389 hash_val
= memcached_generate_hash_value(msg
, strlen(msg
),
390 MEMCACHED_HASH_JENKINS
);
391 if (values
[rc
] != hash_val
)
393 fprintf(stderr
, "\n\nYou have updated memcached_return_t without updating the error_test\n");
394 fprintf(stderr
, "%u, %s, (%u)\n\n", (uint32_t)rc
, memcached_strerror(memc
, rc
), hash_val
);
396 test_true(values
[rc
] == hash_val
);
402 static test_return_t
set_test(memcached_st
*memc
)
404 memcached_return_t rc
;
405 const char *key
= "foo";
406 const char *value
= "when we sanitize";
408 rc
= memcached_set(memc
, key
, strlen(key
),
409 value
, strlen(value
),
410 (time_t)0, (uint32_t)0);
411 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
416 static test_return_t
append_test(memcached_st
*memc
)
418 memcached_return_t rc
;
419 const char *key
= "fig";
420 const char *in_value
= "we";
421 char *out_value
= NULL
;
425 rc
= memcached_flush(memc
, 0);
426 test_true(rc
== MEMCACHED_SUCCESS
);
428 rc
= memcached_set(memc
, key
, strlen(key
),
429 in_value
, strlen(in_value
),
430 (time_t)0, (uint32_t)0);
431 test_true(rc
== MEMCACHED_SUCCESS
);
433 rc
= memcached_append(memc
, key
, strlen(key
),
434 " the", strlen(" the"),
435 (time_t)0, (uint32_t)0);
436 test_true(rc
== MEMCACHED_SUCCESS
);
438 rc
= memcached_append(memc
, key
, strlen(key
),
439 " people", strlen(" people"),
440 (time_t)0, (uint32_t)0);
441 test_true(rc
== MEMCACHED_SUCCESS
);
443 out_value
= memcached_get(memc
, key
, strlen(key
),
444 &value_length
, &flags
, &rc
);
445 test_true(!memcmp(out_value
, "we the people", strlen("we the people")));
446 test_true(strlen("we the people") == value_length
);
447 test_true(rc
== MEMCACHED_SUCCESS
);
453 static test_return_t
append_binary_test(memcached_st
*memc
)
455 memcached_return_t rc
;
456 const char *key
= "numbers";
457 uint32_t store_list
[] = { 23, 56, 499, 98, 32847, 0 };
463 rc
= memcached_flush(memc
, 0);
464 test_true(rc
== MEMCACHED_SUCCESS
);
466 rc
= memcached_set(memc
,
469 (time_t)0, (uint32_t)0);
470 test_true(rc
== MEMCACHED_SUCCESS
);
472 for (x
= 0; store_list
[x
] ; x
++)
474 rc
= memcached_append(memc
,
476 (char *)&store_list
[x
], sizeof(uint32_t),
477 (time_t)0, (uint32_t)0);
478 test_true(rc
== MEMCACHED_SUCCESS
);
481 value
= (uint32_t *)memcached_get(memc
, key
, strlen(key
),
482 &value_length
, &flags
, &rc
);
483 test_true((value_length
== (sizeof(uint32_t) * x
)));
484 test_true(rc
== MEMCACHED_SUCCESS
);
486 for (uint32_t counter
= x
, *ptr
= value
; counter
; counter
--)
488 test_true(*ptr
== store_list
[x
- counter
]);
496 static test_return_t
cas2_test(memcached_st
*memc
)
498 memcached_return_t rc
;
499 const char *keys
[]= {"fudge", "son", "food"};
500 size_t key_length
[]= {5, 3, 4};
501 const char *value
= "we the people";
502 size_t value_length
= strlen("we the people");
504 memcached_result_st results_obj
;
505 memcached_result_st
*results
;
508 rc
= memcached_flush(memc
, 0);
509 test_true(rc
== MEMCACHED_SUCCESS
);
511 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
513 for (x
= 0; x
< 3; x
++)
515 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
516 keys
[x
], key_length
[x
],
517 (time_t)50, (uint32_t)9);
518 test_true(rc
== MEMCACHED_SUCCESS
);
521 rc
= memcached_mget(memc
, keys
, key_length
, 3);
523 results
= memcached_result_create(memc
, &results_obj
);
525 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
527 test_true(results
->item_cas
);
528 test_true(rc
== MEMCACHED_SUCCESS
);
529 test_true(memcached_result_cas(results
));
531 test_true(!memcmp(value
, "we the people", strlen("we the people")));
532 test_true(strlen("we the people") == value_length
);
533 test_true(rc
== MEMCACHED_SUCCESS
);
535 memcached_result_free(&results_obj
);
540 static test_return_t
cas_test(memcached_st
*memc
)
542 memcached_return_t rc
;
543 const char *key
= "fun";
544 size_t key_length
= strlen(key
);
545 const char *value
= "we the people";
546 const char* keys
[2] = { key
, NULL
};
547 size_t keylengths
[2] = { strlen(key
), 0 };
548 size_t value_length
= strlen(value
);
549 const char *value2
= "change the value";
550 size_t value2_length
= strlen(value2
);
552 memcached_result_st results_obj
;
553 memcached_result_st
*results
;
556 rc
= memcached_flush(memc
, 0);
557 test_true(rc
== MEMCACHED_SUCCESS
);
559 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
561 rc
= memcached_set(memc
, key
, strlen(key
),
562 value
, strlen(value
),
563 (time_t)0, (uint32_t)0);
564 test_true(rc
== MEMCACHED_SUCCESS
);
566 rc
= memcached_mget(memc
, keys
, keylengths
, 1);
568 results
= memcached_result_create(memc
, &results_obj
);
570 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
572 test_true(rc
== MEMCACHED_SUCCESS
);
573 test_true(memcached_result_cas(results
));
574 test_true(!memcmp(value
, memcached_result_value(results
), value_length
));
575 test_true(strlen(memcached_result_value(results
)) == value_length
);
576 test_true(rc
== MEMCACHED_SUCCESS
);
577 uint64_t cas
= memcached_result_cas(results
);
580 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
581 test_true(rc
== MEMCACHED_END
);
582 test_true(results
== NULL
);
585 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
586 test_true(rc
== MEMCACHED_SUCCESS
);
589 * The item will have a new cas value, so try to set it again with the old
590 * value. This should fail!
592 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
593 test_true(rc
== MEMCACHED_DATA_EXISTS
);
595 memcached_result_free(&results_obj
);
600 static test_return_t
prepend_test(memcached_st
*memc
)
602 memcached_return_t rc
;
603 const char *key
= "fig";
604 const char *value
= "people";
605 char *out_value
= NULL
;
609 rc
= memcached_flush(memc
, 0);
610 test_true(rc
== MEMCACHED_SUCCESS
);
612 rc
= memcached_set(memc
, key
, strlen(key
),
613 value
, strlen(value
),
614 (time_t)0, (uint32_t)0);
615 test_true(rc
== MEMCACHED_SUCCESS
);
617 rc
= memcached_prepend(memc
, key
, strlen(key
),
618 "the ", strlen("the "),
619 (time_t)0, (uint32_t)0);
620 test_true(rc
== MEMCACHED_SUCCESS
);
622 rc
= memcached_prepend(memc
, key
, strlen(key
),
623 "we ", strlen("we "),
624 (time_t)0, (uint32_t)0);
625 test_true(rc
== MEMCACHED_SUCCESS
);
627 out_value
= memcached_get(memc
, key
, strlen(key
),
628 &value_length
, &flags
, &rc
);
629 test_true(!memcmp(out_value
, "we the people", strlen("we the people")));
630 test_true(strlen("we the people") == value_length
);
631 test_true(rc
== MEMCACHED_SUCCESS
);
638 Set the value, then quit to make sure it is flushed.
639 Come back in and test that add fails.
641 static test_return_t
add_test(memcached_st
*memc
)
643 memcached_return_t rc
;
644 const char *key
= "foo";
645 const char *value
= "when we sanitize";
646 unsigned long long setting_value
;
648 setting_value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
650 rc
= memcached_set(memc
, key
, strlen(key
),
651 value
, strlen(value
),
652 (time_t)0, (uint32_t)0);
653 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
654 memcached_quit(memc
);
655 rc
= memcached_add(memc
, key
, strlen(key
),
656 value
, strlen(value
),
657 (time_t)0, (uint32_t)0);
659 /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */
662 test_true(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_STORED
);
666 test_true(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_DATA_EXISTS
);
673 ** There was a problem of leaking filedescriptors in the initial release
674 ** of MacOSX 10.5. This test case triggers the problem. On some Solaris
675 ** systems it seems that the kernel is slow on reclaiming the resources
676 ** because the connects starts to time out (the test doesn't do much
677 ** anyway, so just loop 10 iterations)
679 static test_return_t
add_wrapper(memcached_st
*memc
)
682 unsigned int max
= 10000;
690 for (x
= 0; x
< max
; x
++)
696 static test_return_t
replace_test(memcached_st
*memc
)
698 memcached_return_t rc
;
699 const char *key
= "foo";
700 const char *value
= "when we sanitize";
701 const char *original
= "first we insert some data";
703 rc
= memcached_set(memc
, key
, strlen(key
),
704 original
, strlen(original
),
705 (time_t)0, (uint32_t)0);
706 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
708 rc
= memcached_replace(memc
, key
, strlen(key
),
709 value
, strlen(value
),
710 (time_t)0, (uint32_t)0);
711 test_true(rc
== MEMCACHED_SUCCESS
);
716 static test_return_t
delete_test(memcached_st
*memc
)
718 memcached_return_t rc
;
719 const char *key
= "foo";
720 const char *value
= "when we sanitize";
722 rc
= memcached_set(memc
, key
, strlen(key
),
723 value
, strlen(value
),
724 (time_t)0, (uint32_t)0);
725 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
727 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
728 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
733 static test_return_t
flush_test(memcached_st
*memc
)
735 memcached_return_t rc
;
737 rc
= memcached_flush(memc
, 0);
738 test_true(rc
== MEMCACHED_SUCCESS
);
743 static memcached_return_t
server_function(const memcached_st
*ptr
__attribute__((unused
)),
744 const memcached_server_st
*server
__attribute__((unused
)),
745 void *context
__attribute__((unused
)))
749 return MEMCACHED_SUCCESS
;
752 static test_return_t
memcached_server_cursor_test(memcached_st
*memc
)
755 strcpy(context
, "foo bad");
756 memcached_server_fn callbacks
[1];
758 callbacks
[0]= server_function
;
759 memcached_server_cursor(memc
, callbacks
, context
, 1);
763 static test_return_t
bad_key_test(memcached_st
*memc
)
765 memcached_return_t rc
;
766 const char *key
= "foo bad";
768 size_t string_length
;
770 memcached_st
*memc_clone
;
772 size_t max_keylen
= 0xffff;
774 // Just skip if we are in binary mode.
775 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
))
778 memc_clone
= memcached_clone(NULL
, memc
);
779 test_true(memc_clone
);
781 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
782 test_true(rc
== MEMCACHED_SUCCESS
);
784 /* All keys are valid in the binary protocol (except for length) */
785 if (memcached_behavior_get(memc_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 0)
787 string
= memcached_get(memc_clone
, key
, strlen(key
),
788 &string_length
, &flags
, &rc
);
789 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
790 test_true(string_length
== 0);
794 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
795 test_true(rc
== MEMCACHED_SUCCESS
);
796 string
= memcached_get(memc_clone
, key
, strlen(key
),
797 &string_length
, &flags
, &rc
);
798 test_true(rc
== MEMCACHED_NOTFOUND
);
799 test_true(string_length
== 0);
802 /* Test multi key for bad keys */
803 const char *keys
[] = { "GoodKey", "Bad Key", "NotMine" };
804 size_t key_lengths
[] = { 7, 7, 7 };
806 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
807 test_true(rc
== MEMCACHED_SUCCESS
);
809 rc
= memcached_mget(memc_clone
, keys
, key_lengths
, 3);
810 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
812 rc
= memcached_mget_by_key(memc_clone
, "foo daddy", 9, keys
, key_lengths
, 1);
813 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
817 /* The following test should be moved to the end of this function when the
818 memcached server is updated to allow max size length of the keys in the
821 rc
= memcached_callback_set(memc_clone
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
822 test_true(rc
== MEMCACHED_SUCCESS
);
824 char *longkey
= malloc(max_keylen
+ 1);
827 memset(longkey
, 'a', max_keylen
+ 1);
828 string
= memcached_get(memc_clone
, longkey
, max_keylen
,
829 &string_length
, &flags
, &rc
);
830 test_true(rc
== MEMCACHED_NOTFOUND
);
831 test_true(string_length
== 0);
834 string
= memcached_get(memc_clone
, longkey
, max_keylen
+ 1,
835 &string_length
, &flags
, &rc
);
836 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
837 test_true(string_length
== 0);
844 /* Make sure zero length keys are marked as bad */
846 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
847 test_true(rc
== MEMCACHED_SUCCESS
);
848 string
= memcached_get(memc_clone
, key
, 0,
849 &string_length
, &flags
, &rc
);
850 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
851 test_true(string_length
== 0);
854 memcached_free(memc_clone
);
859 #define READ_THROUGH_VALUE "set for me"
860 static memcached_return_t
read_through_trigger(memcached_st
*memc
__attribute__((unused
)),
861 char *key
__attribute__((unused
)),
862 size_t key_length
__attribute__((unused
)),
863 memcached_result_st
*result
)
866 return memcached_result_set_value(result
, READ_THROUGH_VALUE
, strlen(READ_THROUGH_VALUE
));
869 static test_return_t
read_through(memcached_st
*memc
)
871 memcached_return_t rc
;
872 const char *key
= "foo";
874 size_t string_length
;
876 memcached_trigger_key_fn cb
= (memcached_trigger_key_fn
)read_through_trigger
;
878 string
= memcached_get(memc
, key
, strlen(key
),
879 &string_length
, &flags
, &rc
);
881 test_true(rc
== MEMCACHED_NOTFOUND
);
882 test_false(string_length
);
885 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_GET_FAILURE
,
887 test_true(rc
== MEMCACHED_SUCCESS
);
889 string
= memcached_get(memc
, key
, strlen(key
),
890 &string_length
, &flags
, &rc
);
892 test_true(rc
== MEMCACHED_SUCCESS
);
893 test_true(string_length
== strlen(READ_THROUGH_VALUE
));
894 test_strcmp(READ_THROUGH_VALUE
, string
);
897 string
= memcached_get(memc
, key
, strlen(key
),
898 &string_length
, &flags
, &rc
);
900 test_true(rc
== MEMCACHED_SUCCESS
);
901 test_true(string_length
== strlen(READ_THROUGH_VALUE
));
902 test_true(!strcmp(READ_THROUGH_VALUE
, string
));
908 static memcached_return_t
delete_trigger(memcached_st
*ptr
__attribute__((unused
)),
910 size_t key_length
__attribute__((unused
)))
914 return MEMCACHED_SUCCESS
;
917 static test_return_t
delete_through(memcached_st
*memc
)
919 memcached_trigger_delete_key_fn callback
;
920 memcached_return_t rc
;
922 callback
= (memcached_trigger_delete_key_fn
)delete_trigger
;
924 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_DELETE_TRIGGER
, *(void**)&callback
);
925 test_true(rc
== MEMCACHED_SUCCESS
);
930 static test_return_t
get_test(memcached_st
*memc
)
932 memcached_return_t rc
;
933 const char *key
= "foo";
935 size_t string_length
;
938 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
939 test_true(rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_NOTFOUND
);
941 string
= memcached_get(memc
, key
, strlen(key
),
942 &string_length
, &flags
, &rc
);
944 test_true(rc
== MEMCACHED_NOTFOUND
);
945 test_false(string_length
);
951 static test_return_t
get_test2(memcached_st
*memc
)
953 memcached_return_t rc
;
954 const char *key
= "foo";
955 const char *value
= "when we sanitize";
957 size_t string_length
;
960 rc
= memcached_set(memc
, key
, strlen(key
),
961 value
, strlen(value
),
962 (time_t)0, (uint32_t)0);
963 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
965 string
= memcached_get(memc
, key
, strlen(key
),
966 &string_length
, &flags
, &rc
);
969 test_true(rc
== MEMCACHED_SUCCESS
);
970 test_true(string_length
== strlen(value
));
971 test_true(!memcmp(string
, value
, string_length
));
978 static test_return_t
set_test2(memcached_st
*memc
)
980 memcached_return_t rc
;
981 const char *key
= "foo";
982 const char *value
= "train in the brain";
983 size_t value_length
= strlen(value
);
986 for (x
= 0; x
< 10; x
++)
988 rc
= memcached_set(memc
, key
, strlen(key
),
990 (time_t)0, (uint32_t)0);
991 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
997 static test_return_t
set_test3(memcached_st
*memc
)
999 memcached_return_t rc
;
1001 size_t value_length
= 8191;
1004 value
= (char*)malloc(value_length
);
1007 for (x
= 0; x
< value_length
; x
++)
1008 value
[x
] = (char) (x
% 127);
1010 /* The dump test relies on there being at least 32 items in memcached */
1011 for (x
= 0; x
< 32; x
++)
1015 sprintf(key
, "foo%u", x
);
1017 rc
= memcached_set(memc
, key
, strlen(key
),
1018 value
, value_length
,
1019 (time_t)0, (uint32_t)0);
1020 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1025 return TEST_SUCCESS
;
1028 static test_return_t
get_test3(memcached_st
*memc
)
1030 memcached_return_t rc
;
1031 const char *key
= "foo";
1033 size_t value_length
= 8191;
1035 size_t string_length
;
1039 value
= (char*)malloc(value_length
);
1042 for (x
= 0; x
< value_length
; x
++)
1043 value
[x
] = (char) (x
% 127);
1045 rc
= memcached_set(memc
, key
, strlen(key
),
1046 value
, value_length
,
1047 (time_t)0, (uint32_t)0);
1048 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1050 string
= memcached_get(memc
, key
, strlen(key
),
1051 &string_length
, &flags
, &rc
);
1053 test_true(rc
== MEMCACHED_SUCCESS
);
1055 test_true(string_length
== value_length
);
1056 test_true(!memcmp(string
, value
, string_length
));
1061 return TEST_SUCCESS
;
1064 static test_return_t
get_test4(memcached_st
*memc
)
1066 memcached_return_t rc
;
1067 const char *key
= "foo";
1069 size_t value_length
= 8191;
1071 size_t string_length
;
1075 value
= (char*)malloc(value_length
);
1078 for (x
= 0; x
< value_length
; x
++)
1079 value
[x
] = (char) (x
% 127);
1081 rc
= memcached_set(memc
, key
, strlen(key
),
1082 value
, value_length
,
1083 (time_t)0, (uint32_t)0);
1084 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1086 for (x
= 0; x
< 10; x
++)
1088 string
= memcached_get(memc
, key
, strlen(key
),
1089 &string_length
, &flags
, &rc
);
1091 test_true(rc
== MEMCACHED_SUCCESS
);
1093 test_true(string_length
== value_length
);
1094 test_true(!memcmp(string
, value
, string_length
));
1100 return TEST_SUCCESS
;
1104 * This test verifies that memcached_read_one_response doesn't try to
1105 * dereference a NIL-pointer if you issue a multi-get and don't read out all
1106 * responses before you execute a storage command.
1108 static test_return_t
get_test5(memcached_st
*memc
)
1111 ** Request the same key twice, to ensure that we hash to the same server
1112 ** (so that we have multiple response values queued up) ;-)
1114 const char *keys
[]= { "key", "key" };
1115 size_t lengths
[]= { 3, 3 };
1119 memcached_return_t rc
= memcached_set(memc
, keys
[0], lengths
[0],
1120 keys
[0], lengths
[0], 0, 0);
1121 test_true(rc
== MEMCACHED_SUCCESS
);
1122 rc
= memcached_mget(memc
, keys
, lengths
, 2);
1124 memcached_result_st results_obj
;
1125 memcached_result_st
*results
;
1126 results
=memcached_result_create(memc
, &results_obj
);
1128 results
=memcached_fetch_result(memc
, &results_obj
, &rc
);
1130 memcached_result_free(&results_obj
);
1132 /* Don't read out the second result, but issue a set instead.. */
1133 rc
= memcached_set(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0);
1134 test_true(rc
== MEMCACHED_SUCCESS
);
1136 char *val
= memcached_get_by_key(memc
, keys
[0], lengths
[0], "yek", 3,
1137 &rlen
, &flags
, &rc
);
1138 test_true(val
== NULL
);
1139 test_true(rc
== MEMCACHED_NOTFOUND
);
1140 val
= memcached_get(memc
, keys
[0], lengths
[0], &rlen
, &flags
, &rc
);
1141 test_true(val
!= NULL
);
1142 test_true(rc
== MEMCACHED_SUCCESS
);
1145 return TEST_SUCCESS
;
1148 static test_return_t
mget_end(memcached_st
*memc
)
1150 const char *keys
[]= { "foo", "foo2" };
1151 size_t lengths
[]= { 3, 4 };
1152 const char *values
[]= { "fjord", "41" };
1154 memcached_return_t rc
;
1157 for (int i
= 0; i
< 2; i
++)
1159 rc
= memcached_set(memc
, keys
[i
], lengths
[i
], values
[i
], strlen(values
[i
]),
1160 (time_t)0, (uint32_t)0);
1161 test_true(rc
== MEMCACHED_SUCCESS
);
1165 size_t string_length
;
1168 // retrieve both via mget
1169 rc
= memcached_mget(memc
, keys
, lengths
, 2);
1170 test_true(rc
== MEMCACHED_SUCCESS
);
1172 char key
[MEMCACHED_MAX_KEY
];
1175 // this should get both
1176 for (int i
= 0; i
< 2; i
++)
1178 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
,
1180 test_true(rc
== MEMCACHED_SUCCESS
);
1182 if (key_length
== 4)
1184 test_true(string_length
== strlen(values
[val
]));
1185 test_true(strncmp(values
[val
], string
, string_length
) == 0);
1189 // this should indicate end
1190 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1191 test_true(rc
== MEMCACHED_END
);
1194 rc
= memcached_mget(memc
, keys
, lengths
, 1);
1195 test_true(rc
== MEMCACHED_SUCCESS
);
1197 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1198 test_true(key_length
== lengths
[0]);
1199 test_true(strncmp(keys
[0], key
, key_length
) == 0);
1200 test_true(string_length
== strlen(values
[0]));
1201 test_true(strncmp(values
[0], string
, string_length
) == 0);
1202 test_true(rc
== MEMCACHED_SUCCESS
);
1205 // this should indicate end
1206 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1207 test_true(rc
== MEMCACHED_END
);
1209 return TEST_SUCCESS
;
1212 /* Do not copy the style of this code, I just access hosts to testthis function */
1213 static test_return_t
stats_servername_test(memcached_st
*memc
)
1215 memcached_return_t rc
;
1216 memcached_stat_st memc_stat
;
1217 memcached_server_instance_st instance
=
1218 memcached_server_instance_by_position(memc
, 0);
1220 #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
1221 if (memcached_get_sasl_callbacks(memc
) != NULL
)
1222 return TEST_SKIPPED
;
1224 rc
= memcached_stat_servername(&memc_stat
, NULL
,
1225 memcached_server_name(instance
),
1226 memcached_server_port(instance
));
1228 return TEST_SUCCESS
;
1231 static test_return_t
increment_test(memcached_st
*memc
)
1233 uint64_t new_number
;
1234 memcached_return_t rc
;
1235 const char *key
= "number";
1236 const char *value
= "0";
1238 rc
= memcached_set(memc
, key
, strlen(key
),
1239 value
, strlen(value
),
1240 (time_t)0, (uint32_t)0);
1241 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1243 rc
= memcached_increment(memc
, key
, strlen(key
),
1245 test_true(rc
== MEMCACHED_SUCCESS
);
1246 test_true(new_number
== 1);
1248 rc
= memcached_increment(memc
, key
, strlen(key
),
1250 test_true(rc
== MEMCACHED_SUCCESS
);
1251 test_true(new_number
== 2);
1253 return TEST_SUCCESS
;
1256 static test_return_t
increment_with_initial_test(memcached_st
*memc
)
1258 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1260 uint64_t new_number
;
1261 memcached_return_t rc
;
1262 const char *key
= "number";
1263 uint64_t initial
= 0;
1265 rc
= memcached_increment_with_initial(memc
, key
, strlen(key
),
1266 1, initial
, 0, &new_number
);
1267 test_true(rc
== MEMCACHED_SUCCESS
);
1268 test_true(new_number
== initial
);
1270 rc
= memcached_increment_with_initial(memc
, key
, strlen(key
),
1271 1, initial
, 0, &new_number
);
1272 test_true(rc
== MEMCACHED_SUCCESS
);
1273 test_true(new_number
== (initial
+ 1));
1275 return TEST_SUCCESS
;
1278 static test_return_t
decrement_test(memcached_st
*memc
)
1280 uint64_t new_number
;
1281 memcached_return_t rc
;
1282 const char *key
= "number";
1283 const char *value
= "3";
1285 rc
= memcached_set(memc
, key
, strlen(key
),
1286 value
, strlen(value
),
1287 (time_t)0, (uint32_t)0);
1288 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1290 rc
= memcached_decrement(memc
, key
, strlen(key
),
1292 test_true(rc
== MEMCACHED_SUCCESS
);
1293 test_true(new_number
== 2);
1295 rc
= memcached_decrement(memc
, key
, strlen(key
),
1297 test_true(rc
== MEMCACHED_SUCCESS
);
1298 test_true(new_number
== 1);
1300 return TEST_SUCCESS
;
1303 static test_return_t
decrement_with_initial_test(memcached_st
*memc
)
1305 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1307 uint64_t new_number
;
1308 memcached_return_t rc
;
1309 const char *key
= "number";
1310 uint64_t initial
= 3;
1312 rc
= memcached_decrement_with_initial(memc
, key
, strlen(key
),
1313 1, initial
, 0, &new_number
);
1314 test_true(rc
== MEMCACHED_SUCCESS
);
1315 test_true(new_number
== initial
);
1317 rc
= memcached_decrement_with_initial(memc
, key
, strlen(key
),
1318 1, initial
, 0, &new_number
);
1319 test_true(rc
== MEMCACHED_SUCCESS
);
1320 test_true(new_number
== (initial
- 1));
1322 return TEST_SUCCESS
;
1325 static test_return_t
increment_by_key_test(memcached_st
*memc
)
1327 uint64_t new_number
;
1328 memcached_return_t rc
;
1329 const char *master_key
= "foo";
1330 const char *key
= "number";
1331 const char *value
= "0";
1333 rc
= memcached_set_by_key(memc
, master_key
, strlen(master_key
),
1335 value
, strlen(value
),
1336 (time_t)0, (uint32_t)0);
1337 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1339 rc
= memcached_increment_by_key(memc
, master_key
, strlen(master_key
), key
, strlen(key
),
1341 test_true(rc
== MEMCACHED_SUCCESS
);
1342 test_true(new_number
== 1);
1344 rc
= memcached_increment_by_key(memc
, master_key
, strlen(master_key
), key
, strlen(key
),
1346 test_true(rc
== MEMCACHED_SUCCESS
);
1347 test_true(new_number
== 2);
1349 return TEST_SUCCESS
;
1352 static test_return_t
increment_with_initial_by_key_test(memcached_st
*memc
)
1354 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1356 uint64_t new_number
;
1357 memcached_return_t rc
;
1358 const char *master_key
= "foo";
1359 const char *key
= "number";
1360 uint64_t initial
= 0;
1362 rc
= memcached_increment_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1364 1, initial
, 0, &new_number
);
1365 test_true(rc
== MEMCACHED_SUCCESS
);
1366 test_true(new_number
== initial
);
1368 rc
= memcached_increment_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1370 1, initial
, 0, &new_number
);
1371 test_true(rc
== MEMCACHED_SUCCESS
);
1372 test_true(new_number
== (initial
+ 1));
1374 return TEST_SUCCESS
;
1377 static test_return_t
decrement_by_key_test(memcached_st
*memc
)
1379 uint64_t new_number
;
1380 memcached_return_t rc
;
1381 const char *master_key
= "foo";
1382 const char *key
= "number";
1383 const char *value
= "3";
1385 rc
= memcached_set_by_key(memc
, master_key
, strlen(master_key
),
1387 value
, strlen(value
),
1388 (time_t)0, (uint32_t)0);
1389 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1391 rc
= memcached_decrement_by_key(memc
, master_key
, strlen(master_key
),
1394 test_true(rc
== MEMCACHED_SUCCESS
);
1395 test_true(new_number
== 2);
1397 rc
= memcached_decrement_by_key(memc
, master_key
, strlen(master_key
),
1400 test_true(rc
== MEMCACHED_SUCCESS
);
1401 test_true(new_number
== 1);
1403 return TEST_SUCCESS
;
1406 static test_return_t
decrement_with_initial_by_key_test(memcached_st
*memc
)
1408 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1410 uint64_t new_number
;
1411 memcached_return_t rc
;
1412 const char *master_key
= "foo";
1413 const char *key
= "number";
1414 uint64_t initial
= 3;
1416 rc
= memcached_decrement_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1418 1, initial
, 0, &new_number
);
1419 test_true(rc
== MEMCACHED_SUCCESS
);
1420 test_true(new_number
== initial
);
1422 rc
= memcached_decrement_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1424 1, initial
, 0, &new_number
);
1425 test_true(rc
== MEMCACHED_SUCCESS
);
1426 test_true(new_number
== (initial
- 1));
1428 return TEST_SUCCESS
;
1431 static test_return_t
quit_test(memcached_st
*memc
)
1433 memcached_return_t rc
;
1434 const char *key
= "fudge";
1435 const char *value
= "sanford and sun";
1437 rc
= memcached_set(memc
, key
, strlen(key
),
1438 value
, strlen(value
),
1439 (time_t)10, (uint32_t)3);
1440 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1441 memcached_quit(memc
);
1443 rc
= memcached_set(memc
, key
, strlen(key
),
1444 value
, strlen(value
),
1445 (time_t)50, (uint32_t)9);
1446 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1448 return TEST_SUCCESS
;
1451 static test_return_t
mget_result_test(memcached_st
*memc
)
1453 memcached_return_t rc
;
1454 const char *keys
[]= {"fudge", "son", "food"};
1455 size_t key_length
[]= {5, 3, 4};
1458 memcached_result_st results_obj
;
1459 memcached_result_st
*results
;
1461 results
= memcached_result_create(memc
, &results_obj
);
1463 test_true(&results_obj
== results
);
1465 /* We need to empty the server before continueing test */
1466 rc
= memcached_flush(memc
, 0);
1467 test_true(rc
== MEMCACHED_SUCCESS
);
1469 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1470 test_true(rc
== MEMCACHED_SUCCESS
);
1472 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1477 while ((results
= memcached_fetch_result(memc
, &results_obj
, &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
);
1492 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1495 test_true(&results_obj
== results
);
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
)));
1503 memcached_result_free(&results_obj
);
1505 return TEST_SUCCESS
;
1508 static test_return_t
mget_result_alloc_test(memcached_st
*memc
)
1510 memcached_return_t rc
;
1511 const char *keys
[]= {"fudge", "son", "food"};
1512 size_t key_length
[]= {5, 3, 4};
1515 memcached_result_st
*results
;
1517 /* We need to empty the server before continueing test */
1518 rc
= memcached_flush(memc
, 0);
1519 test_true(rc
== MEMCACHED_SUCCESS
);
1521 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1522 test_true(rc
== MEMCACHED_SUCCESS
);
1524 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)) != NULL
)
1528 test_true(!results
);
1529 test_true(rc
== MEMCACHED_END
);
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
);
1543 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1546 test_true(rc
== MEMCACHED_SUCCESS
);
1547 test_true(memcached_result_key_length(results
) == memcached_result_length(results
));
1548 test_true(!memcmp(memcached_result_key_value(results
),
1549 memcached_result_value(results
),
1550 memcached_result_length(results
)));
1551 memcached_result_free(results
);
1555 return TEST_SUCCESS
;
1558 /* Count the results */
1559 static memcached_return_t
callback_counter(const memcached_st
*ptr
__attribute__((unused
)),
1560 memcached_result_st
*result
__attribute__((unused
)),
1563 size_t *counter
= (size_t *)context
;
1565 *counter
= *counter
+ 1;
1567 return MEMCACHED_SUCCESS
;
1570 static test_return_t
mget_result_function(memcached_st
*memc
)
1572 memcached_return_t rc
;
1573 const char *keys
[]= {"fudge", "son", "food"};
1574 size_t key_length
[]= {5, 3, 4};
1577 memcached_execute_fn callbacks
[1];
1579 /* We need to empty the server before continueing test */
1580 rc
= memcached_flush(memc
, 0);
1581 for (x
= 0; x
< 3; x
++)
1583 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1584 keys
[x
], key_length
[x
],
1585 (time_t)50, (uint32_t)9);
1586 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1589 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1590 test_true(rc
== MEMCACHED_SUCCESS
);
1592 callbacks
[0]= &callback_counter
;
1594 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
1596 test_true(counter
== 3);
1598 return TEST_SUCCESS
;
1601 static test_return_t
mget_test(memcached_st
*memc
)
1603 memcached_return_t rc
;
1604 const char *keys
[]= {"fudge", "son", "food"};
1605 size_t key_length
[]= {5, 3, 4};
1609 char return_key
[MEMCACHED_MAX_KEY
];
1610 size_t return_key_length
;
1612 size_t return_value_length
;
1614 /* We need to empty the server before continueing test */
1615 rc
= memcached_flush(memc
, 0);
1616 test_true(rc
== MEMCACHED_SUCCESS
);
1618 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1619 test_true(rc
== MEMCACHED_SUCCESS
);
1621 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1622 &return_value_length
, &flags
, &rc
)) != NULL
)
1624 test_true(return_value
);
1626 test_true(!return_value
);
1627 test_true(return_value_length
== 0);
1628 test_true(rc
== MEMCACHED_END
);
1630 for (x
= 0; x
< 3; x
++)
1632 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1633 keys
[x
], key_length
[x
],
1634 (time_t)50, (uint32_t)9);
1635 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1638 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1639 test_true(rc
== MEMCACHED_SUCCESS
);
1642 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1643 &return_value_length
, &flags
, &rc
)))
1645 test_true(return_value
);
1646 test_true(rc
== MEMCACHED_SUCCESS
);
1647 test_true(return_key_length
== return_value_length
);
1648 test_true(!memcmp(return_value
, return_key
, return_value_length
));
1653 return TEST_SUCCESS
;
1656 static test_return_t
mget_execute(memcached_st
*memc
)
1660 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1664 * I only want to hit _one_ server so I know the number of requests I'm
1665 * sending in the pipeline.
1667 uint32_t number_of_hosts
= memc
->number_of_hosts
;
1668 memc
->number_of_hosts
= 1;
1670 size_t max_keys
= binary
? 20480 : 1;
1673 char **keys
= calloc(max_keys
, sizeof(char*));
1674 size_t *key_length
=calloc(max_keys
, sizeof(size_t));
1676 /* First add all of the items.. */
1677 char blob
[1024] = {0};
1678 memcached_return_t rc
;
1679 for (size_t x
= 0; x
< max_keys
; ++x
)
1683 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%zu", x
);
1685 test_true(keys
[x
] != NULL
);
1686 rc
= memcached_add(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
1687 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1690 /* Try to get all of them with a large multiget */
1692 memcached_execute_fn callbacks
[1]= { [0]= &callback_counter
};
1693 rc
= memcached_mget_execute(memc
, (const char**)keys
, key_length
,
1694 max_keys
, callbacks
, &counter
, 1);
1698 test_true(rc
== MEMCACHED_SUCCESS
);
1700 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
1701 test_true(rc
== MEMCACHED_END
);
1703 /* Verify that we got all of the items */
1704 test_true(counter
== max_keys
);
1708 test_true(rc
== MEMCACHED_NOT_SUPPORTED
);
1709 test_true(counter
== 0);
1712 /* Release all allocated resources */
1713 for (size_t x
= 0; x
< max_keys
; ++x
)
1720 memc
->number_of_hosts
= number_of_hosts
;
1721 return TEST_SUCCESS
;
1724 static test_return_t
get_stats_keys(memcached_st
*memc
)
1728 memcached_stat_st memc_stat
;
1729 memcached_return_t rc
;
1731 stat_list
= memcached_stat_get_keys(memc
, &memc_stat
, &rc
);
1732 test_true(rc
== MEMCACHED_SUCCESS
);
1733 for (ptr
= stat_list
; *ptr
; ptr
++)
1738 return TEST_SUCCESS
;
1741 static test_return_t
version_string_test(memcached_st
*memc
__attribute__((unused
)))
1743 const char *version_string
;
1745 version_string
= memcached_lib_version();
1747 test_true(!strcmp(version_string
, LIBMEMCACHED_VERSION_STRING
));
1749 return TEST_SUCCESS
;
1752 static test_return_t
get_stats(memcached_st
*memc
)
1756 memcached_return_t rc
;
1757 memcached_stat_st
*memc_stat
;
1759 memc_stat
= memcached_stat(memc
, NULL
, &rc
);
1760 test_true(rc
== MEMCACHED_SUCCESS
);
1762 test_true(rc
== MEMCACHED_SUCCESS
);
1763 test_true(memc_stat
);
1765 for (uint32_t x
= 0; x
< memcached_server_count(memc
); x
++)
1767 stat_list
= memcached_stat_get_keys(memc
, memc_stat
+x
, &rc
);
1768 test_true(rc
== MEMCACHED_SUCCESS
);
1769 for (ptr
= stat_list
; *ptr
; ptr
++);
1774 memcached_stat_free(NULL
, memc_stat
);
1776 return TEST_SUCCESS
;
1779 static test_return_t
add_host_test(memcached_st
*memc
)
1782 memcached_server_st
*servers
;
1783 memcached_return_t rc
;
1784 char servername
[]= "0.example.com";
1786 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
1788 test_true(1 == memcached_server_list_count(servers
));
1790 for (x
= 2; x
< 20; x
++)
1792 char buffer
[SMALL_STRING_LEN
];
1794 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
1795 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
1797 test_true(rc
== MEMCACHED_SUCCESS
);
1798 test_true(x
== memcached_server_list_count(servers
));
1801 rc
= memcached_server_push(memc
, servers
);
1802 test_true(rc
== MEMCACHED_SUCCESS
);
1803 rc
= memcached_server_push(memc
, servers
);
1804 test_true(rc
== MEMCACHED_SUCCESS
);
1806 memcached_server_list_free(servers
);
1808 return TEST_SUCCESS
;
1811 static memcached_return_t
clone_test_callback(memcached_st
*parent
__attribute__((unused
)), memcached_st
*memc_clone
__attribute__((unused
)))
1813 return MEMCACHED_SUCCESS
;
1816 static memcached_return_t
cleanup_test_callback(memcached_st
*ptr
__attribute__((unused
)))
1818 return MEMCACHED_SUCCESS
;
1821 static test_return_t
callback_test(memcached_st
*memc
)
1823 /* Test User Data */
1827 memcached_return_t rc
;
1829 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_USER_DATA
, &x
);
1830 test_true(rc
== MEMCACHED_SUCCESS
);
1831 test_ptr
= (int *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_USER_DATA
, &rc
);
1832 test_true(*test_ptr
== x
);
1835 /* Test Clone Callback */
1837 memcached_clone_fn clone_cb
= (memcached_clone_fn
)clone_test_callback
;
1838 void *clone_cb_ptr
= *(void **)&clone_cb
;
1839 void *temp_function
= NULL
;
1840 memcached_return_t rc
;
1842 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
,
1844 test_true(rc
== MEMCACHED_SUCCESS
);
1845 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1846 test_true(temp_function
== clone_cb_ptr
);
1849 /* Test Cleanup Callback */
1851 memcached_cleanup_fn cleanup_cb
=
1852 (memcached_cleanup_fn
)cleanup_test_callback
;
1853 void *cleanup_cb_ptr
= *(void **)&cleanup_cb
;
1854 void *temp_function
= NULL
;
1855 memcached_return_t rc
;
1857 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
,
1859 test_true(rc
== MEMCACHED_SUCCESS
);
1860 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1861 test_true(temp_function
== cleanup_cb_ptr
);
1864 return TEST_SUCCESS
;
1867 /* We don't test the behavior itself, we test the switches */
1868 static test_return_t
behavior_test(memcached_st
*memc
)
1873 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1874 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1875 test_true(value
== 1);
1877 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1878 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1879 test_true(value
== 1);
1881 set
= MEMCACHED_HASH_MD5
;
1882 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1883 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1884 test_true(value
== MEMCACHED_HASH_MD5
);
1888 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1889 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1890 test_true(value
== 0);
1892 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1893 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1894 test_true(value
== 0);
1896 set
= MEMCACHED_HASH_DEFAULT
;
1897 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1898 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1899 test_true(value
== MEMCACHED_HASH_DEFAULT
);
1901 set
= MEMCACHED_HASH_CRC
;
1902 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1903 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1904 test_true(value
== MEMCACHED_HASH_CRC
);
1906 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1907 test_true(value
> 0);
1909 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1910 test_true(value
> 0);
1912 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
);
1913 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, value
+ 1);
1914 test_true((value
+ 1) == memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
));
1916 return TEST_SUCCESS
;
1919 static test_return_t
MEMCACHED_BEHAVIOR_CORK_test(memcached_st
*memc
)
1921 memcached_return_t rc
;
1925 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CORK
, set
);
1926 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_NOT_SUPPORTED
);
1928 value
= (bool)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_CORK
);
1930 if (rc
== MEMCACHED_SUCCESS
)
1932 test_true((bool)value
== set
);
1936 test_false((bool)value
== set
);
1939 return TEST_SUCCESS
;
1943 static test_return_t
MEMCACHED_BEHAVIOR_TCP_KEEPALIVE_test(memcached_st
*memc
)
1945 memcached_return_t rc
;
1949 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE
, set
);
1950 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_NOT_SUPPORTED
);
1952 value
= (bool)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE
);
1954 if (rc
== MEMCACHED_SUCCESS
)
1956 test_true((bool)value
== set
);
1960 test_false((bool)value
== set
);
1963 return TEST_SUCCESS
;
1967 static test_return_t
MEMCACHED_BEHAVIOR_TCP_KEEPIDLE_test(memcached_st
*memc
)
1969 memcached_return_t rc
;
1973 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_KEEPIDLE
, set
);
1974 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_NOT_SUPPORTED
);
1976 value
= (bool)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_KEEPIDLE
);
1978 if (rc
== MEMCACHED_SUCCESS
)
1980 test_true((bool)value
== set
);
1984 test_false((bool)value
== set
);
1987 return TEST_SUCCESS
;
1990 static test_return_t
fetch_all_results(memcached_st
*memc
)
1992 memcached_return_t rc
= MEMCACHED_SUCCESS
;
1993 char return_key
[MEMCACHED_MAX_KEY
];
1994 size_t return_key_length
;
1996 size_t return_value_length
;
1999 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2000 &return_value_length
, &flags
, &rc
)))
2002 test_true(return_value
);
2003 test_true(rc
== MEMCACHED_SUCCESS
);
2007 return ((rc
== MEMCACHED_END
) || (rc
== MEMCACHED_SUCCESS
)) ? TEST_SUCCESS
: TEST_FAILURE
;
2010 /* Test case provided by Cal Haldenbrand */
2011 static test_return_t
user_supplied_bug1(memcached_st
*memc
)
2013 unsigned int setter
= 1;
2015 unsigned long long total
= 0;
2018 char randomstuff
[6 * 1024];
2019 memcached_return_t rc
;
2021 memset(randomstuff
, 0, 6 * 1024);
2023 /* We just keep looking at the same values over and over */
2026 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
2027 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2031 for (uint32_t x
= 0 ; total
< 20 * 1024576 ; x
++ )
2035 size
= (uint32_t)(rand() % ( 5 * 1024 ) ) + 400;
2036 memset(randomstuff
, 0, 6 * 1024);
2037 test_true(size
< 6 * 1024); /* Being safe here */
2039 for (j
= 0 ; j
< size
;j
++)
2040 randomstuff
[j
] = (signed char) ((rand() % 26) + 97);
2043 snprintf(key
, sizeof(key
), "%u", x
);
2044 rc
= memcached_set(memc
, key
, strlen(key
),
2045 randomstuff
, strlen(randomstuff
), 10, 0);
2046 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
2047 /* If we fail, lets try again */
2048 if (rc
!= MEMCACHED_SUCCESS
&& rc
!= MEMCACHED_BUFFERED
)
2049 rc
= memcached_set(memc
, key
, strlen(key
),
2050 randomstuff
, strlen(randomstuff
), 10, 0);
2051 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
2054 return TEST_SUCCESS
;
2057 /* Test case provided by Cal Haldenbrand */
2058 static test_return_t
user_supplied_bug2(memcached_st
*memc
)
2060 unsigned int setter
;
2064 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
2065 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2067 setter
= 20 * 1024576;
2068 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
2069 setter
= 20 * 1024576;
2070 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
2071 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
2072 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
2074 for (x
= 0, errors
= 0; total
< 20 * 1024576 ; x
++)
2077 for (uint32_t x
= 0, errors
= 0; total
< 24576 ; x
++)
2079 memcached_return_t rc
= MEMCACHED_SUCCESS
;
2080 char buffer
[SMALL_STRING_LEN
];
2085 memset(buffer
, 0, SMALL_STRING_LEN
);
2087 snprintf(buffer
, sizeof(buffer
), "%u", x
);
2088 getval
= memcached_get(memc
, buffer
, strlen(buffer
),
2089 &val_len
, &flags
, &rc
);
2090 if (rc
!= MEMCACHED_SUCCESS
)
2092 if (rc
== MEMCACHED_NOTFOUND
)
2106 return TEST_SUCCESS
;
2109 /* Do a large mget() over all the keys we think exist */
2110 #define KEY_COUNT 3000 // * 1024576
2111 static test_return_t
user_supplied_bug3(memcached_st
*memc
)
2113 memcached_return_t rc
;
2114 unsigned int setter
;
2117 size_t key_lengths
[KEY_COUNT
];
2120 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
2121 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2123 setter
= 20 * 1024576;
2124 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
2125 setter
= 20 * 1024576;
2126 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
2127 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
2128 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
2131 keys
= calloc(KEY_COUNT
, sizeof(char *));
2133 for (x
= 0; x
< KEY_COUNT
; x
++)
2137 snprintf(buffer
, 30, "%u", x
);
2138 keys
[x
]= strdup(buffer
);
2139 key_lengths
[x
]= strlen(keys
[x
]);
2142 rc
= memcached_mget(memc
, (const char **)keys
, key_lengths
, KEY_COUNT
);
2143 test_true(rc
== MEMCACHED_SUCCESS
);
2145 test_true(fetch_all_results(memc
) == TEST_SUCCESS
);
2147 for (x
= 0; x
< KEY_COUNT
; x
++)
2151 return TEST_SUCCESS
;
2154 /* Make sure we behave properly if server list has no values */
2155 static test_return_t
user_supplied_bug4(memcached_st
*memc
)
2157 memcached_return_t rc
;
2158 const char *keys
[]= {"fudge", "son", "food"};
2159 size_t key_length
[]= {5, 3, 4};
2162 char return_key
[MEMCACHED_MAX_KEY
];
2163 size_t return_key_length
;
2165 size_t return_value_length
;
2167 /* Here we free everything before running a bunch of mget tests */
2168 memcached_servers_reset(memc
);
2171 /* We need to empty the server before continueing test */
2172 rc
= memcached_flush(memc
, 0);
2173 test_true(rc
== MEMCACHED_NO_SERVERS
);
2175 rc
= memcached_mget(memc
, keys
, key_length
, 3);
2176 test_true(rc
== MEMCACHED_NO_SERVERS
);
2178 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2179 &return_value_length
, &flags
, &rc
)) != NULL
)
2181 test_true(return_value
);
2183 test_true(!return_value
);
2184 test_true(return_value_length
== 0);
2185 test_true(rc
== MEMCACHED_NO_SERVERS
);
2187 for (x
= 0; x
< 3; x
++)
2189 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2190 keys
[x
], key_length
[x
],
2191 (time_t)50, (uint32_t)9);
2192 test_true(rc
== MEMCACHED_NO_SERVERS
);
2195 rc
= memcached_mget(memc
, keys
, key_length
, 3);
2196 test_true(rc
== MEMCACHED_NO_SERVERS
);
2199 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2200 &return_value_length
, &flags
, &rc
)))
2202 test_true(return_value
);
2203 test_true(rc
== MEMCACHED_SUCCESS
);
2204 test_true(return_key_length
== return_value_length
);
2205 test_true(!memcmp(return_value
, return_key
, return_value_length
));
2210 return TEST_SUCCESS
;
2213 #define VALUE_SIZE_BUG5 1048064
2214 static test_return_t
user_supplied_bug5(memcached_st
*memc
)
2216 memcached_return_t rc
;
2217 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
2218 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
2219 char return_key
[MEMCACHED_MAX_KEY
];
2220 size_t return_key_length
;
2222 size_t value_length
;
2226 char insert_data
[VALUE_SIZE_BUG5
];
2228 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2229 insert_data
[x
]= (signed char)rand();
2231 memcached_flush(memc
, 0);
2232 value
= memcached_get(memc
, keys
[0], key_length
[0],
2233 &value_length
, &flags
, &rc
);
2234 test_true(value
== NULL
);
2235 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2238 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2239 &value_length
, &flags
, &rc
)))
2241 test_true(count
== 0);
2243 for (x
= 0; x
< 4; x
++)
2245 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2246 insert_data
, VALUE_SIZE_BUG5
,
2247 (time_t)0, (uint32_t)0);
2248 test_true(rc
== MEMCACHED_SUCCESS
);
2251 for (x
= 0; x
< 10; x
++)
2253 value
= memcached_get(memc
, keys
[0], key_length
[0],
2254 &value_length
, &flags
, &rc
);
2258 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2260 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2261 &value_length
, &flags
, &rc
)))
2266 test_true(count
== 4);
2269 return TEST_SUCCESS
;
2272 static test_return_t
user_supplied_bug6(memcached_st
*memc
)
2274 memcached_return_t rc
;
2275 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
2276 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
2277 char return_key
[MEMCACHED_MAX_KEY
];
2278 size_t return_key_length
;
2280 size_t value_length
;
2284 char insert_data
[VALUE_SIZE_BUG5
];
2286 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2287 insert_data
[x
]= (signed char)rand();
2289 memcached_flush(memc
, 0);
2290 value
= memcached_get(memc
, keys
[0], key_length
[0],
2291 &value_length
, &flags
, &rc
);
2292 test_true(value
== NULL
);
2293 test_true(rc
== MEMCACHED_NOTFOUND
);
2294 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2295 test_true(rc
== MEMCACHED_SUCCESS
);
2298 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2299 &value_length
, &flags
, &rc
)))
2301 test_true(count
== 0);
2302 test_true(rc
== MEMCACHED_END
);
2304 for (x
= 0; x
< 4; x
++)
2306 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2307 insert_data
, VALUE_SIZE_BUG5
,
2308 (time_t)0, (uint32_t)0);
2309 test_true(rc
== MEMCACHED_SUCCESS
);
2312 for (x
= 0; x
< 2; x
++)
2314 value
= memcached_get(memc
, keys
[0], key_length
[0],
2315 &value_length
, &flags
, &rc
);
2319 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2320 test_true(rc
== MEMCACHED_SUCCESS
);
2322 /* We test for purge of partial complete fetches */
2323 for (count
= 3; count
; count
--)
2325 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2326 &value_length
, &flags
, &rc
);
2327 test_true(rc
== MEMCACHED_SUCCESS
);
2328 test_true(!(memcmp(value
, insert_data
, value_length
)));
2329 test_true(value_length
);
2334 return TEST_SUCCESS
;
2337 static test_return_t
user_supplied_bug8(memcached_st
*memc
__attribute__((unused
)))
2339 memcached_return_t rc
;
2341 memcached_st
*memc_clone
;
2343 memcached_server_st
*servers
;
2344 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";
2346 servers
= memcached_servers_parse(server_list
);
2349 mine
= memcached_create(NULL
);
2350 rc
= memcached_server_push(mine
, servers
);
2351 test_true(rc
== MEMCACHED_SUCCESS
);
2352 memcached_server_list_free(servers
);
2355 memc_clone
= memcached_clone(NULL
, mine
);
2357 memcached_quit(mine
);
2358 memcached_quit(memc_clone
);
2361 memcached_free(mine
);
2362 memcached_free(memc_clone
);
2364 return TEST_SUCCESS
;
2367 /* Test flag store/retrieve */
2368 static test_return_t
user_supplied_bug7(memcached_st
*memc
)
2370 memcached_return_t rc
;
2371 const char *keys
= "036790384900";
2372 size_t key_length
= strlen(keys
);
2373 char return_key
[MEMCACHED_MAX_KEY
];
2374 size_t return_key_length
;
2376 size_t value_length
;
2379 char insert_data
[VALUE_SIZE_BUG5
];
2381 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2382 insert_data
[x
]= (signed char)rand();
2384 memcached_flush(memc
, 0);
2387 rc
= memcached_set(memc
, keys
, key_length
,
2388 insert_data
, VALUE_SIZE_BUG5
,
2390 test_true(rc
== MEMCACHED_SUCCESS
);
2393 value
= memcached_get(memc
, keys
, key_length
,
2394 &value_length
, &flags
, &rc
);
2395 test_true(flags
== 245);
2399 rc
= memcached_mget(memc
, &keys
, &key_length
, 1);
2402 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2403 &value_length
, &flags
, &rc
);
2404 test_true(flags
== 245);
2409 return TEST_SUCCESS
;
2412 static test_return_t
user_supplied_bug9(memcached_st
*memc
)
2414 memcached_return_t rc
;
2415 const char *keys
[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
2416 size_t key_length
[3];
2421 char return_key
[MEMCACHED_MAX_KEY
];
2422 size_t return_key_length
;
2424 size_t return_value_length
;
2427 key_length
[0]= strlen("UDATA:edevil@sapo.pt");
2428 key_length
[1]= strlen("fudge&*@#");
2429 key_length
[2]= strlen("for^#@&$not");
2432 for (x
= 0; x
< 3; x
++)
2434 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2435 keys
[x
], key_length
[x
],
2436 (time_t)50, (uint32_t)9);
2437 test_true(rc
== MEMCACHED_SUCCESS
);
2440 rc
= memcached_mget(memc
, keys
, key_length
, 3);
2441 test_true(rc
== MEMCACHED_SUCCESS
);
2443 /* We need to empty the server before continueing test */
2444 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2445 &return_value_length
, &flags
, &rc
)) != NULL
)
2447 test_true(return_value
);
2451 test_true(count
== 3);
2453 return TEST_SUCCESS
;
2456 /* We are testing with aggressive timeout to get failures */
2457 static test_return_t
user_supplied_bug10(memcached_st
*memc
)
2459 const char *key
= "foo";
2461 size_t value_length
= 512;
2464 memcached_return_t rc
;
2465 unsigned int set
= 1;
2466 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2469 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2470 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2472 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
,
2475 value
= (char*)malloc(value_length
* sizeof(char));
2477 for (x
= 0; x
< value_length
; x
++)
2478 value
[x
]= (char) (x
% 127);
2480 for (x
= 1; x
<= 100000; ++x
)
2482 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2484 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_WRITE_FAILURE
||
2485 rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_TIMEOUT
);
2487 if (rc
== MEMCACHED_WRITE_FAILURE
|| rc
== MEMCACHED_TIMEOUT
)
2492 memcached_free(mclone
);
2494 return TEST_SUCCESS
;
2498 We are looking failures in the async protocol
2500 static test_return_t
user_supplied_bug11(memcached_st
*memc
)
2502 const char *key
= "foo";
2504 size_t value_length
= 512;
2507 memcached_return_t rc
;
2508 unsigned int set
= 1;
2510 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2512 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2513 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2515 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
,
2518 timeout
= (int32_t)memcached_behavior_get(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
2520 test_true(timeout
== -1);
2522 value
= (char*)malloc(value_length
* sizeof(char));
2524 for (x
= 0; x
< value_length
; x
++)
2525 value
[x
]= (char) (x
% 127);
2527 for (x
= 1; x
<= 100000; ++x
)
2529 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2533 memcached_free(mclone
);
2535 return TEST_SUCCESS
;
2539 Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
2541 static test_return_t
user_supplied_bug12(memcached_st
*memc
)
2543 memcached_return_t rc
;
2545 size_t value_length
;
2547 uint64_t number_value
;
2549 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2550 &value_length
, &flags
, &rc
);
2551 test_true(value
== NULL
);
2552 test_true(rc
== MEMCACHED_NOTFOUND
);
2554 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2557 test_true(value
== NULL
);
2558 /* The binary protocol will set the key if it doesn't exist */
2559 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1)
2561 test_true(rc
== MEMCACHED_SUCCESS
);
2565 test_true(rc
== MEMCACHED_NOTFOUND
);
2568 rc
= memcached_set(memc
, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
2570 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2571 &value_length
, &flags
, &rc
);
2573 test_true(rc
== MEMCACHED_SUCCESS
);
2576 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2578 test_true(number_value
== 2);
2579 test_true(rc
== MEMCACHED_SUCCESS
);
2581 return TEST_SUCCESS
;
2585 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2586 set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
2588 static test_return_t
user_supplied_bug13(memcached_st
*memc
)
2590 char key
[] = "key34567890";
2592 memcached_return_t rc
;
2593 size_t overflowSize
;
2595 char commandFirst
[]= "set key34567890 0 0 ";
2596 char commandLast
[] = " \r\n"; /* first line of command sent to server */
2597 size_t commandLength
;
2600 commandLength
= strlen(commandFirst
) + strlen(commandLast
) + 4; /* 4 is number of characters in size, probably 8196 */
2602 overflowSize
= MEMCACHED_MAX_BUFFER
- commandLength
;
2604 for (testSize
= overflowSize
- 1; testSize
< overflowSize
+ 1; testSize
++)
2606 overflow
= malloc(testSize
);
2607 test_true(overflow
!= NULL
);
2609 memset(overflow
, 'x', testSize
);
2610 rc
= memcached_set(memc
, key
, strlen(key
),
2611 overflow
, testSize
, 0, 0);
2612 test_true(rc
== MEMCACHED_SUCCESS
);
2616 return TEST_SUCCESS
;
2621 Test values of many different sizes
2622 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2623 set key34567890 0 0 8169 \r\n
2624 is sent followed by buffer of size 8169, followed by 8169
2626 static test_return_t
user_supplied_bug14(memcached_st
*memc
)
2629 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2630 memcached_return_t rc
;
2631 const char *key
= "foo";
2633 size_t value_length
= 18000;
2635 size_t string_length
;
2638 size_t current_length
;
2640 value
= (char*)malloc(value_length
);
2643 for (x
= 0; x
< value_length
; x
++)
2644 value
[x
] = (char) (x
% 127);
2646 for (current_length
= 0; current_length
< value_length
; current_length
++)
2648 rc
= memcached_set(memc
, key
, strlen(key
),
2649 value
, current_length
,
2650 (time_t)0, (uint32_t)0);
2651 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
2653 string
= memcached_get(memc
, key
, strlen(key
),
2654 &string_length
, &flags
, &rc
);
2656 test_true(rc
== MEMCACHED_SUCCESS
);
2657 test_true(string_length
== current_length
);
2658 test_true(!memcmp(string
, value
, string_length
));
2665 return TEST_SUCCESS
;
2669 Look for zero length value problems
2671 static test_return_t
user_supplied_bug15(memcached_st
*memc
)
2674 memcached_return_t rc
;
2675 const char *key
= "mykey";
2680 for (x
= 0; x
< 2; x
++)
2682 rc
= memcached_set(memc
, key
, strlen(key
),
2684 (time_t)0, (uint32_t)0);
2686 test_true(rc
== MEMCACHED_SUCCESS
);
2688 value
= memcached_get(memc
, key
, strlen(key
),
2689 &length
, &flags
, &rc
);
2691 test_true(rc
== MEMCACHED_SUCCESS
);
2692 test_true(value
== NULL
);
2693 test_true(length
== 0);
2694 test_true(flags
== 0);
2696 value
= memcached_get(memc
, key
, strlen(key
),
2697 &length
, &flags
, &rc
);
2699 test_true(rc
== MEMCACHED_SUCCESS
);
2700 test_true(value
== NULL
);
2701 test_true(length
== 0);
2702 test_true(flags
== 0);
2705 return TEST_SUCCESS
;
2708 /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
2709 static test_return_t
user_supplied_bug16(memcached_st
*memc
)
2711 memcached_return_t rc
;
2712 const char *key
= "mykey";
2717 rc
= memcached_set(memc
, key
, strlen(key
),
2719 (time_t)0, UINT32_MAX
);
2721 test_true(rc
== MEMCACHED_SUCCESS
);
2723 value
= memcached_get(memc
, key
, strlen(key
),
2724 &length
, &flags
, &rc
);
2726 test_true(rc
== MEMCACHED_SUCCESS
);
2727 test_true(value
== NULL
);
2728 test_true(length
== 0);
2729 test_true(flags
== UINT32_MAX
);
2731 return TEST_SUCCESS
;
2735 /* Check the validity of chinese key*/
2736 static test_return_t
user_supplied_bug17(memcached_st
*memc
)
2738 memcached_return_t rc
;
2739 const char *key
= "豆瓣";
2740 const char *value
="我们在炎热抑郁的夏天无法停止豆瓣";
2745 rc
= memcached_set(memc
, key
, strlen(key
),
2746 value
, strlen(value
),
2749 test_true(rc
== MEMCACHED_SUCCESS
);
2751 value2
= memcached_get(memc
, key
, strlen(key
),
2752 &length
, &flags
, &rc
);
2754 test_true(length
==strlen(value
));
2755 test_true(rc
== MEMCACHED_SUCCESS
);
2756 test_true(memcmp(value
, value2
, length
)==0);
2759 return TEST_SUCCESS
;
2767 static test_return_t
user_supplied_bug19(memcached_st
*not_used
)
2770 const memcached_server_st
*server
;
2771 memcached_return_t res
;
2775 memc
= memcached_create(NULL
);
2776 memcached_server_add_with_weight(memc
, "localhost", 11311, 100);
2777 memcached_server_add_with_weight(memc
, "localhost", 11312, 100);
2779 server
= memcached_server_by_key(memc
, "a", 1, &res
);
2781 memcached_free(memc
);
2783 return TEST_SUCCESS
;
2786 /* CAS test from Andei */
2787 static test_return_t
user_supplied_bug20(memcached_st
*memc
)
2789 memcached_return_t status
;
2790 memcached_result_st
*result
, result_obj
;
2791 const char *key
= "abc";
2792 size_t key_len
= strlen("abc");
2793 const char *value
= "foobar";
2794 size_t value_len
= strlen(value
);
2796 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
2798 status
= memcached_set(memc
, key
, key_len
, value
, value_len
, (time_t)0, (uint32_t)0);
2799 test_true(status
== MEMCACHED_SUCCESS
);
2801 status
= memcached_mget(memc
, &key
, &key_len
, 1);
2802 test_true(status
== MEMCACHED_SUCCESS
);
2804 result
= memcached_result_create(memc
, &result_obj
);
2807 memcached_result_create(memc
, &result_obj
);
2808 result
= memcached_fetch_result(memc
, &result_obj
, &status
);
2811 test_true(status
== MEMCACHED_SUCCESS
);
2813 memcached_result_free(result
);
2815 return TEST_SUCCESS
;
2818 #include "ketama_test_cases.h"
2819 static test_return_t
user_supplied_bug18(memcached_st
*trash
)
2821 memcached_return_t rc
;
2824 memcached_server_st
*server_pool
;
2829 memc
= memcached_create(NULL
);
2832 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2833 test_true(rc
== MEMCACHED_SUCCESS
);
2835 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2836 test_true(value
== 1);
2838 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2839 test_true(rc
== MEMCACHED_SUCCESS
);
2841 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2842 test_true(value
== MEMCACHED_HASH_MD5
);
2844 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");
2845 memcached_server_push(memc
, server_pool
);
2847 /* verify that the server list was parsed okay. */
2848 test_true(memcached_server_count(memc
) == 8);
2849 test_true(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
2850 test_true(server_pool
[0].port
== 11211);
2851 test_true(server_pool
[0].weight
== 600);
2852 test_true(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
2853 test_true(server_pool
[2].port
== 11211);
2854 test_true(server_pool
[2].weight
== 200);
2855 test_true(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
2856 test_true(server_pool
[7].port
== 11211);
2857 test_true(server_pool
[7].weight
== 100);
2859 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
2860 * us test the boundary wraparound.
2862 test_true(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
2864 /* verify the standard ketama set. */
2865 for (x
= 0; x
< 99; x
++)
2867 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
2869 memcached_server_instance_st instance
=
2870 memcached_server_instance_by_position(memc
, server_idx
);
2872 const char *hostname
= memcached_server_name(instance
);
2873 test_strcmp(hostname
, ketama_test_cases
[x
].server
);
2876 memcached_server_list_free(server_pool
);
2877 memcached_free(memc
);
2879 return TEST_SUCCESS
;
2882 /* Large mget() of missing keys with binary proto
2884 * If many binary quiet commands (such as getq's in an mget) fill the output
2885 * buffer and the server chooses not to respond, memcached_flush hangs. See
2886 * http://lists.tangent.org/pipermail/libmemcached/2009-August/000918.html
2889 /* sighandler_t function that always asserts false */
2890 static void fail(int unused
__attribute__((unused
)))
2896 static test_return_t
_user_supplied_bug21(memcached_st
* memc
, size_t key_count
)
2898 memcached_return_t rc
;
2901 size_t* key_lengths
;
2902 void (*oldalarm
)(int);
2903 memcached_st
*memc_clone
;
2905 memc_clone
= memcached_clone(NULL
, memc
);
2906 test_true(memc_clone
);
2908 /* only binproto uses getq for mget */
2909 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
2911 /* empty the cache to ensure misses (hence non-responses) */
2912 rc
= memcached_flush(memc_clone
, 0);
2913 test_true(rc
== MEMCACHED_SUCCESS
);
2915 key_lengths
= calloc(key_count
, sizeof(size_t));
2916 keys
= calloc(key_count
, sizeof(char *));
2918 for (x
= 0; x
< key_count
; x
++)
2922 snprintf(buffer
, 30, "%u", x
);
2923 keys
[x
]= strdup(buffer
);
2924 key_lengths
[x
]= strlen(keys
[x
]);
2927 oldalarm
= signal(SIGALRM
, fail
);
2930 rc
= memcached_mget(memc_clone
, (const char **)keys
, key_lengths
, key_count
);
2931 test_true(rc
== MEMCACHED_SUCCESS
);
2934 signal(SIGALRM
, oldalarm
);
2936 test_true(fetch_all_results(memc
) == TEST_SUCCESS
);
2938 for (x
= 0; x
< key_count
; x
++)
2943 memcached_free(memc_clone
);
2945 return TEST_SUCCESS
;
2948 static test_return_t
pre_binary(memcached_st
*memc
);
2950 static test_return_t
user_supplied_bug21(memcached_st
*memc
)
2952 test_return_t test_rc
;
2953 test_rc
= pre_binary(memc
);
2955 if (test_rc
!= TEST_SUCCESS
)
2960 /* should work as of r580 */
2961 rc
= _user_supplied_bug21(memc
, 10);
2962 test_true(rc
== TEST_SUCCESS
);
2964 /* should fail as of r580 */
2965 rc
= _user_supplied_bug21(memc
, 1000);
2966 test_true(rc
== TEST_SUCCESS
);
2968 return TEST_SUCCESS
;
2971 static test_return_t
auto_eject_hosts(memcached_st
*trash
)
2974 memcached_server_instance_st instance
;
2976 memcached_return_t rc
;
2977 memcached_st
*memc
= memcached_create(NULL
);
2980 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2981 test_true(rc
== MEMCACHED_SUCCESS
);
2983 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2984 test_true(value
== 1);
2986 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2987 test_true(rc
== MEMCACHED_SUCCESS
);
2989 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2990 test_true(value
== MEMCACHED_HASH_MD5
);
2992 /* server should be removed when in delay */
2993 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
, 1);
2994 test_true(rc
== MEMCACHED_SUCCESS
);
2996 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
);
2997 test_true(value
== 1);
2999 memcached_server_st
*server_pool
;
3000 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");
3001 memcached_server_push(memc
, server_pool
);
3003 /* verify that the server list was parsed okay. */
3004 test_true(memcached_server_count(memc
) == 8);
3005 test_true(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
3006 test_true(server_pool
[0].port
== 11211);
3007 test_true(server_pool
[0].weight
== 600);
3008 test_true(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
3009 test_true(server_pool
[2].port
== 11211);
3010 test_true(server_pool
[2].weight
== 200);
3011 test_true(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
3012 test_true(server_pool
[7].port
== 11211);
3013 test_true(server_pool
[7].weight
== 100);
3015 instance
= memcached_server_instance_by_position(memc
, 2);
3016 ((memcached_server_write_instance_st
)instance
)->next_retry
= time(NULL
) + 15;
3017 memc
->next_distribution_rebuild
= time(NULL
) - 1;
3020 This would not work if there were only two hosts.
3022 for (size_t x
= 0; x
< 99; x
++)
3024 memcached_autoeject(memc
);
3025 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
3026 test_true(server_idx
!= 2);
3029 /* and re-added when it's back. */
3030 ((memcached_server_write_instance_st
)instance
)->next_retry
= time(NULL
) - 1;
3031 memc
->next_distribution_rebuild
= time(NULL
) - 1;
3032 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
,
3033 memc
->distribution
);
3034 for (size_t x
= 0; x
< 99; x
++)
3036 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
3037 // We re-use instance from above.
3039 memcached_server_instance_by_position(memc
, server_idx
);
3040 const char *hostname
= memcached_server_name(instance
);
3041 test_true(strcmp(hostname
, ketama_test_cases
[x
].server
) == 0);
3044 memcached_server_list_free(server_pool
);
3045 memcached_free(memc
);
3047 return TEST_SUCCESS
;
3050 static test_return_t
output_ketama_weighted_keys(memcached_st
*trash
)
3054 memcached_return_t rc
;
3055 memcached_st
*memc
= memcached_create(NULL
);
3059 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
3060 test_true(rc
== MEMCACHED_SUCCESS
);
3062 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
3063 test_true(value
== 1);
3065 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
3066 test_true(rc
== MEMCACHED_SUCCESS
);
3068 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
3069 test_true(value
== MEMCACHED_HASH_MD5
);
3072 test_true(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
) == MEMCACHED_SUCCESS
);
3074 memcached_server_st
*server_pool
;
3075 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");
3076 memcached_server_push(memc
, server_pool
);
3078 // @todo this needs to be refactored to actually test something.
3081 if ((fp
= fopen("ketama_keys.txt", "w")))
3085 printf("cannot write to file ketama_keys.txt");
3086 return TEST_FAILURE
;
3089 for (int x
= 0; x
< 10000; x
++)
3092 sprintf(key
, "%d", x
);
3094 uint32_t server_idx
= memcached_generate_hash(memc
, key
, strlen(key
));
3095 char *hostname
= memc
->hosts
[server_idx
].hostname
;
3096 in_port_t port
= memc
->hosts
[server_idx
].port
;
3097 fprintf(fp
, "key %s is on host /%s:%u\n", key
, hostname
, port
);
3101 memcached_server_list_free(server_pool
);
3102 memcached_free(memc
);
3104 return TEST_SUCCESS
;
3108 static test_return_t
result_static(memcached_st
*memc
)
3110 memcached_result_st result
;
3111 memcached_result_st
*result_ptr
;
3113 result_ptr
= memcached_result_create(memc
, &result
);
3114 test_true(result
.options
.is_allocated
== false);
3115 test_true(memcached_is_initialized(&result
) == true);
3116 test_true(result_ptr
);
3117 test_true(result_ptr
== &result
);
3119 memcached_result_free(&result
);
3121 test_true(result
.options
.is_allocated
== false);
3122 test_true(memcached_is_initialized(&result
) == false);
3124 return TEST_SUCCESS
;
3127 static test_return_t
result_alloc(memcached_st
*memc
)
3129 memcached_result_st
*result_ptr
;
3131 result_ptr
= memcached_result_create(memc
, NULL
);
3132 test_true(result_ptr
);
3133 test_true(result_ptr
->options
.is_allocated
== true);
3134 test_true(memcached_is_initialized(result_ptr
) == true);
3135 memcached_result_free(result_ptr
);
3137 return TEST_SUCCESS
;
3140 static test_return_t
string_static_null(memcached_st
*memc
)
3142 memcached_string_st string
;
3143 memcached_string_st
*string_ptr
;
3145 string_ptr
= memcached_string_create(memc
, &string
, 0);
3146 test_true(string
.options
.is_initialized
== true);
3147 test_true(string_ptr
);
3149 /* The following two better be the same! */
3150 test_true(memcached_is_allocated(string_ptr
) == false);
3151 test_true(memcached_is_allocated(&string
) == false);
3152 test_true(&string
== string_ptr
);
3154 test_true(string
.options
.is_initialized
== true);
3155 test_true(memcached_is_initialized(&string
) == true);
3156 memcached_string_free(&string
);
3157 test_true(memcached_is_initialized(&string
) == false);
3159 return TEST_SUCCESS
;
3162 static test_return_t
string_alloc_null(memcached_st
*memc
)
3164 memcached_string_st
*string
;
3166 string
= memcached_string_create(memc
, NULL
, 0);
3168 test_true(memcached_is_allocated(string
) == true);
3169 test_true(memcached_is_initialized(string
) == true);
3170 memcached_string_free(string
);
3172 return TEST_SUCCESS
;
3175 static test_return_t
string_alloc_with_size(memcached_st
*memc
)
3177 memcached_string_st
*string
;
3179 string
= memcached_string_create(memc
, NULL
, 1024);
3181 test_true(memcached_is_allocated(string
) == true);
3182 test_true(memcached_is_initialized(string
) == true);
3183 memcached_string_free(string
);
3185 return TEST_SUCCESS
;
3188 static test_return_t
string_alloc_with_size_toobig(memcached_st
*memc
)
3190 memcached_string_st
*string
;
3192 string
= memcached_string_create(memc
, NULL
, SIZE_MAX
);
3193 test_true(string
== NULL
);
3195 return TEST_SUCCESS
;
3198 static test_return_t
string_alloc_append(memcached_st
*memc
)
3201 char buffer
[SMALL_STRING_LEN
];
3202 memcached_string_st
*string
;
3204 /* Ring the bell! */
3205 memset(buffer
, 6, SMALL_STRING_LEN
);
3207 string
= memcached_string_create(memc
, NULL
, 100);
3209 test_true(memcached_is_allocated(string
) == true);
3210 test_true(memcached_is_initialized(string
) == true);
3212 for (x
= 0; x
< 1024; x
++)
3214 memcached_return_t rc
;
3215 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
3216 test_true(rc
== MEMCACHED_SUCCESS
);
3218 test_true(memcached_is_allocated(string
) == true);
3219 memcached_string_free(string
);
3221 return TEST_SUCCESS
;
3224 static test_return_t
string_alloc_append_toobig(memcached_st
*memc
)
3226 memcached_return_t rc
;
3228 char buffer
[SMALL_STRING_LEN
];
3229 memcached_string_st
*string
;
3231 /* Ring the bell! */
3232 memset(buffer
, 6, SMALL_STRING_LEN
);
3234 string
= memcached_string_create(memc
, NULL
, 100);
3236 test_true(memcached_is_allocated(string
) == true);
3237 test_true(memcached_is_initialized(string
) == true);
3239 for (x
= 0; x
< 1024; x
++)
3241 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
3242 test_true(rc
== MEMCACHED_SUCCESS
);
3244 rc
= memcached_string_append(string
, buffer
, SIZE_MAX
);
3245 test_true(rc
== MEMCACHED_MEMORY_ALLOCATION_FAILURE
);
3246 test_true(memcached_is_allocated(string
) == true);
3247 memcached_string_free(string
);
3249 return TEST_SUCCESS
;
3252 static test_return_t
cleanup_pairs(memcached_st
*memc
__attribute__((unused
)))
3254 pairs_free(global_pairs
);
3256 return TEST_SUCCESS
;
3259 static test_return_t
generate_pairs(memcached_st
*memc
__attribute__((unused
)))
3261 global_pairs
= pairs_generate(GLOBAL_COUNT
, 400);
3262 global_count
= GLOBAL_COUNT
;
3264 for (size_t x
= 0; x
< global_count
; x
++)
3266 global_keys
[x
]= global_pairs
[x
].key
;
3267 global_keys_length
[x
]= global_pairs
[x
].key_length
;
3270 return TEST_SUCCESS
;
3273 static test_return_t
generate_large_pairs(memcached_st
*memc
__attribute__((unused
)))
3275 global_pairs
= pairs_generate(GLOBAL2_COUNT
, MEMCACHED_MAX_BUFFER
+10);
3276 global_count
= GLOBAL2_COUNT
;
3278 for (size_t x
= 0; x
< global_count
; x
++)
3280 global_keys
[x
]= global_pairs
[x
].key
;
3281 global_keys_length
[x
]= global_pairs
[x
].key_length
;
3284 return TEST_SUCCESS
;
3287 static test_return_t
generate_data(memcached_st
*memc
)
3289 execute_set(memc
, global_pairs
, global_count
);
3291 return TEST_SUCCESS
;
3294 static test_return_t
generate_data_with_stats(memcached_st
*memc
)
3296 memcached_stat_st
*stat_p
;
3297 memcached_return_t rc
;
3298 uint32_t host_index
= 0;
3299 execute_set(memc
, global_pairs
, global_count
);
3301 //TODO: hosts used size stats
3302 stat_p
= memcached_stat(memc
, NULL
, &rc
);
3305 for (host_index
= 0; host_index
< SERVERS_TO_CREATE
; host_index
++)
3307 /* This test was changes so that "make test" would work properlly */
3309 memcached_server_instance_st instance
=
3310 memcached_server_instance_by_position(memc
, host_index
);
3312 printf("\nserver %u|%s|%u bytes: %llu\n", host_index
, instance
->hostname
, instance
->port
, (unsigned long long)(stat_p
+ host_index
)->bytes
);
3314 test_true((unsigned long long)(stat_p
+ host_index
)->bytes
);
3317 memcached_stat_free(NULL
, stat_p
);
3319 return TEST_SUCCESS
;
3321 static test_return_t
generate_buffer_data(memcached_st
*memc
)
3326 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
3327 generate_data(memc
);
3329 return TEST_SUCCESS
;
3332 static test_return_t
get_read_count(memcached_st
*memc
)
3334 memcached_return_t rc
;
3335 memcached_st
*memc_clone
;
3337 memc_clone
= memcached_clone(NULL
, memc
);
3338 test_true(memc_clone
);
3340 memcached_server_add_with_weight(memc_clone
, "localhost", 6666, 0);
3344 size_t return_value_length
;
3348 for (size_t x
= count
= 0; x
< global_count
; x
++)
3350 return_value
= memcached_get(memc_clone
, global_keys
[x
], global_keys_length
[x
],
3351 &return_value_length
, &flags
, &rc
);
3352 if (rc
== MEMCACHED_SUCCESS
)
3361 memcached_free(memc_clone
);
3363 return TEST_SUCCESS
;
3366 static test_return_t
get_read(memcached_st
*memc
)
3368 memcached_return_t rc
;
3372 size_t return_value_length
;
3375 for (size_t x
= 0; x
< global_count
; x
++)
3377 return_value
= memcached_get(memc
, global_keys
[x
], global_keys_length
[x
],
3378 &return_value_length
, &flags
, &rc
);
3380 test_true(return_value);
3381 test_true(rc == MEMCACHED_SUCCESS);
3383 if (rc
== MEMCACHED_SUCCESS
&& return_value
)
3388 return TEST_SUCCESS
;
3391 static test_return_t
mget_read(memcached_st
*memc
)
3393 memcached_return_t rc
;
3395 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
3396 test_true(rc
== MEMCACHED_SUCCESS
);
3397 test_true(fetch_all_results(memc
) == TEST_SUCCESS
);
3399 return TEST_SUCCESS
;
3402 static test_return_t
mget_read_result(memcached_st
*memc
)
3404 memcached_return_t rc
;
3406 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
3407 test_true(rc
== MEMCACHED_SUCCESS
);
3408 /* Turn this into a help function */
3410 memcached_result_st results_obj
;
3411 memcached_result_st
*results
;
3413 results
= memcached_result_create(memc
, &results_obj
);
3415 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
3418 test_true(rc
== MEMCACHED_SUCCESS
);
3421 memcached_result_free(&results_obj
);
3424 return TEST_SUCCESS
;
3427 static test_return_t
mget_read_function(memcached_st
*memc
)
3429 memcached_return_t rc
;
3431 memcached_execute_fn callbacks
[1];
3433 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
3434 test_true(rc
== MEMCACHED_SUCCESS
);
3436 callbacks
[0]= &callback_counter
;
3438 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
3440 return TEST_SUCCESS
;
3443 static test_return_t
delete_generate(memcached_st
*memc
)
3445 for (size_t x
= 0; x
< global_count
; x
++)
3447 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3450 return TEST_SUCCESS
;
3453 static test_return_t
delete_buffer_generate(memcached_st
*memc
)
3458 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
3460 for (size_t x
= 0; x
< global_count
; x
++)
3462 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3465 return TEST_SUCCESS
;
3468 static test_return_t
add_host_test1(memcached_st
*memc
)
3470 memcached_return_t rc
;
3471 char servername
[]= "0.example.com";
3472 memcached_server_st
*servers
;
3474 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
3476 test_true(1 == memcached_server_list_count(servers
));
3478 for (size_t x
= 2; x
< 20; x
++)
3480 char buffer
[SMALL_STRING_LEN
];
3482 snprintf(buffer
, SMALL_STRING_LEN
, "%zu.example.com", 400+x
);
3483 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
3485 test_true(rc
== MEMCACHED_SUCCESS
);
3486 test_true(x
== memcached_server_list_count(servers
));
3489 rc
= memcached_server_push(memc
, servers
);
3490 test_true(rc
== MEMCACHED_SUCCESS
);
3491 rc
= memcached_server_push(memc
, servers
);
3492 test_true(rc
== MEMCACHED_SUCCESS
);
3494 memcached_server_list_free(servers
);
3496 return TEST_SUCCESS
;
3499 static test_return_t
pre_nonblock(memcached_st
*memc
)
3501 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3503 return TEST_SUCCESS
;
3506 static test_return_t
pre_cork(memcached_st
*memc
)
3508 memcached_return_t rc
;
3511 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CORK
, set
);
3514 return TEST_SKIPPED
;
3517 if (rc
== MEMCACHED_SUCCESS
)
3518 return TEST_SUCCESS
;
3520 return TEST_SKIPPED
;
3523 static test_return_t
pre_cork_and_nonblock(memcached_st
*memc
)
3530 return TEST_SKIPPED
;
3533 if (rc
!= TEST_SUCCESS
)
3536 return pre_nonblock(memc
);
3539 static test_return_t
pre_nonblock_binary(memcached_st
*memc
)
3541 memcached_return_t rc
= MEMCACHED_FAILURE
;
3542 memcached_st
*memc_clone
;
3543 memcached_server_instance_st instance
;
3545 memc_clone
= memcached_clone(NULL
, memc
);
3546 test_true(memc_clone
);
3547 // The memcached_version needs to be done on a clone, because the server
3548 // will not toggle protocol on an connection.
3549 memcached_version(memc_clone
);
3551 instance
= memcached_server_instance_by_position(memc_clone
, 0);
3553 if (instance
->major_version
>= 1 && instance
->minor_version
> 2)
3555 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3556 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3557 test_true(rc
== MEMCACHED_SUCCESS
);
3558 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3562 return TEST_SKIPPED
;
3565 memcached_free(memc_clone
);
3567 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3570 static test_return_t
pre_murmur(memcached_st
*memc
)
3572 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
3574 return TEST_SUCCESS
;
3577 static test_return_t
pre_jenkins(memcached_st
*memc
)
3579 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_JENKINS
);
3581 return TEST_SUCCESS
;
3585 static test_return_t
pre_md5(memcached_st
*memc
)
3587 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MD5
);
3589 return TEST_SUCCESS
;
3592 static test_return_t
pre_crc(memcached_st
*memc
)
3594 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_CRC
);
3596 return TEST_SUCCESS
;
3599 static test_return_t
pre_hsieh(memcached_st
*memc
)
3601 #ifdef HAVE_HSIEH_HASH
3602 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_HSIEH
);
3603 return TEST_SUCCESS
;
3606 return TEST_SKIPPED
;
3610 static test_return_t
pre_hash_fnv1_64(memcached_st
*memc
)
3612 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
3614 return TEST_SUCCESS
;
3617 static test_return_t
pre_hash_fnv1a_64(memcached_st
*memc
)
3619 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_64
);
3621 return TEST_SUCCESS
;
3624 static test_return_t
pre_hash_fnv1_32(memcached_st
*memc
)
3626 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_32
);
3628 return TEST_SUCCESS
;
3631 static test_return_t
pre_hash_fnv1a_32(memcached_st
*memc
)
3633 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_32
);
3635 return TEST_SUCCESS
;
3638 static test_return_t
pre_behavior_ketama(memcached_st
*memc
)
3640 memcached_return_t rc
;
3643 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA
, 1);
3644 test_true(rc
== MEMCACHED_SUCCESS
);
3646 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA
);
3647 test_true(value
== 1);
3649 return TEST_SUCCESS
;
3652 static test_return_t
pre_behavior_ketama_weighted(memcached_st
*memc
)
3654 memcached_return_t rc
;
3657 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
3658 test_true(rc
== MEMCACHED_SUCCESS
);
3660 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
3661 test_true(value
== 1);
3663 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
3664 test_true(rc
== MEMCACHED_SUCCESS
);
3666 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
3667 test_true(value
== MEMCACHED_HASH_MD5
);
3669 return TEST_SUCCESS
;
3673 @note This should be testing to see if the server really supports the binary protocol.
3675 static test_return_t
pre_binary(memcached_st
*memc
)
3677 memcached_return_t rc
= MEMCACHED_FAILURE
;
3678 memcached_st
*memc_clone
;
3679 memcached_server_instance_st instance
;
3681 memc_clone
= memcached_clone(NULL
, memc
);
3682 test_true(memc_clone
);
3683 // The memcached_version needs to be done on a clone, because the server
3684 // will not toggle protocol on an connection.
3685 memcached_version(memc_clone
);
3687 instance
= memcached_server_instance_by_position(memc_clone
, 0);
3689 if (instance
->major_version
>= 1 && instance
->minor_version
> 2)
3691 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3692 test_true(rc
== MEMCACHED_SUCCESS
);
3693 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3696 memcached_free(memc_clone
);
3698 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3701 static test_return_t
pre_sasl(memcached_st
*memc
)
3703 memcached_return_t rc
= MEMCACHED_FAILURE
;
3705 #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
3706 const char *server
= getenv("LIBMEMCACHED_TEST_SASL_SERVER");
3707 const char *user
= getenv("LIBMEMCACHED_TEST_SASL_USERNAME");
3708 const char *pass
= getenv("LIBMEMCACHED_TEST_SASL_PASSWORD");
3710 if (server
!= NULL
&& user
!= NULL
&& pass
!= NULL
)
3712 memcached_server_st
*servers
= memcached_servers_parse(server
);
3713 test_true(servers
!= NULL
);
3714 memcached_servers_reset(memc
);
3715 test_true(memcached_server_push(memc
, servers
) == MEMCACHED_SUCCESS
);
3716 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3717 rc
= memcached_set_sasl_auth_data(memc
, user
, pass
);
3718 test_true(rc
== MEMCACHED_SUCCESS
);
3724 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3727 static test_return_t
pre_replication(memcached_st
*memc
)
3729 test_return_t test_rc
;
3730 test_rc
= pre_binary(memc
);
3732 if (test_rc
!= TEST_SUCCESS
)
3736 * Make sure that we store the item on all servers
3737 * (master + replicas == number of servers)
3739 memcached_return_t rc
;
3740 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
,
3741 memcached_server_count(memc
) - 1);
3742 test_true(rc
== MEMCACHED_SUCCESS
);
3743 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
) == memcached_server_count(memc
) - 1);
3745 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3749 static test_return_t
pre_replication_noblock(memcached_st
*memc
)
3753 rc
= pre_replication(memc
);
3754 if (rc
!= TEST_SUCCESS
)
3757 rc
= pre_nonblock(memc
);
3763 static void my_free(const memcached_st
*ptr
__attribute__((unused
)), void *mem
, void *context
)
3766 #ifdef HARD_MALLOC_TESTS
3767 void *real_ptr
= (mem
== NULL
) ? mem
: (void*)((caddr_t
)mem
- 8);
3775 static void *my_malloc(const memcached_st
*ptr
__attribute__((unused
)), const size_t size
, void *context
)
3778 #ifdef HARD_MALLOC_TESTS
3779 void *ret
= malloc(size
+ 8);
3782 ret
= (void*)((caddr_t
)ret
+ 8);
3785 void *ret
= malloc(size
);
3790 memset(ret
, 0xff, size
);
3797 static void *my_realloc(const memcached_st
*ptr
__attribute__((unused
)), void *mem
, const size_t size
, void *context
)
3800 #ifdef HARD_MALLOC_TESTS
3801 void *real_ptr
= (mem
== NULL
) ? NULL
: (void*)((caddr_t
)mem
- 8);
3802 void *nmem
= realloc(real_ptr
, size
+ 8);
3807 ret
= (void*)((caddr_t
)nmem
+ 8);
3812 return realloc(mem
, size
);
3817 static void *my_calloc(const memcached_st
*ptr
__attribute__((unused
)), size_t nelem
, const size_t size
, void *context
)
3820 #ifdef HARD_MALLOC_TESTS
3821 void *mem
= my_malloc(ptr
, nelem
* size
);
3824 memset(mem
, 0, nelem
* size
);
3829 return calloc(nelem
, size
);
3834 static test_return_t
set_prefix(memcached_st
*memc
)
3836 memcached_return_t rc
;
3837 const char *key
= "mine";
3840 /* Make sure be default none exists */
3841 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3842 test_true(rc
== MEMCACHED_FAILURE
);
3844 /* Test a clean set */
3845 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3846 test_true(rc
== MEMCACHED_SUCCESS
);
3848 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3849 test_true(memcmp(value
, key
, 4) == 0);
3850 test_true(rc
== MEMCACHED_SUCCESS
);
3852 /* Test that we can turn it off */
3853 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3854 test_true(rc
== MEMCACHED_SUCCESS
);
3856 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3857 test_true(rc
== MEMCACHED_FAILURE
);
3859 /* Now setup for main test */
3860 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3861 test_true(rc
== MEMCACHED_SUCCESS
);
3863 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3864 test_true(rc
== MEMCACHED_SUCCESS
);
3865 test_true(memcmp(value
, key
, 4) == 0);
3867 /* Set to Zero, and then Set to something too large */
3870 memset(long_key
, 0, 255);
3872 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3873 test_true(rc
== MEMCACHED_SUCCESS
);
3875 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3876 test_true(rc
== MEMCACHED_FAILURE
);
3877 test_true(value
== NULL
);
3879 /* Test a long key for failure */
3880 /* TODO, extend test to determine based on setting, what result should be */
3881 strcpy(long_key
, "Thisismorethentheallottednumberofcharacters");
3882 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3883 //test_true(rc == MEMCACHED_BAD_KEY_PROVIDED);
3884 test_true(rc
== MEMCACHED_SUCCESS
);
3886 /* Now test a key with spaces (which will fail from long key, since bad key is not set) */
3887 strcpy(long_key
, "This is more then the allotted number of characters");
3888 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3889 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3891 /* Test for a bad prefix, but with a short key */
3892 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, 1);
3893 test_true(rc
== MEMCACHED_SUCCESS
);
3895 strcpy(long_key
, "dog cat");
3896 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3897 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3900 return TEST_SUCCESS
;
3904 #ifdef MEMCACHED_ENABLE_DEPRECATED
3905 static test_return_t
deprecated_set_memory_alloc(memcached_st
*memc
)
3907 void *test_ptr
= NULL
;
3910 memcached_malloc_fn malloc_cb
=
3911 (memcached_malloc_fn
)my_malloc
;
3912 cb_ptr
= *(void **)&malloc_cb
;
3913 memcached_return_t rc
;
3915 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, cb_ptr
);
3916 test_true(rc
== MEMCACHED_SUCCESS
);
3917 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
3918 test_true(rc
== MEMCACHED_SUCCESS
);
3919 test_true(test_ptr
== cb_ptr
);
3923 memcached_realloc_fn realloc_cb
=
3924 (memcached_realloc_fn
)my_realloc
;
3925 cb_ptr
= *(void **)&realloc_cb
;
3926 memcached_return_t rc
;
3928 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, cb_ptr
);
3929 test_true(rc
== MEMCACHED_SUCCESS
);
3930 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
3931 test_true(rc
== MEMCACHED_SUCCESS
);
3932 test_true(test_ptr
== cb_ptr
);
3936 memcached_free_fn free_cb
=
3937 (memcached_free_fn
)my_free
;
3938 cb_ptr
= *(void **)&free_cb
;
3939 memcached_return_t rc
;
3941 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, cb_ptr
);
3942 test_true(rc
== MEMCACHED_SUCCESS
);
3943 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
3944 test_true(rc
== MEMCACHED_SUCCESS
);
3945 test_true(test_ptr
== cb_ptr
);
3948 return TEST_SUCCESS
;
3953 static test_return_t
set_memory_alloc(memcached_st
*memc
)
3955 memcached_return_t rc
;
3956 rc
= memcached_set_memory_allocators(memc
, NULL
, my_free
,
3957 my_realloc
, my_calloc
, NULL
);
3958 test_true(rc
== MEMCACHED_FAILURE
);
3960 rc
= memcached_set_memory_allocators(memc
, my_malloc
, my_free
,
3961 my_realloc
, my_calloc
, NULL
);
3963 memcached_malloc_fn mem_malloc
;
3964 memcached_free_fn mem_free
;
3965 memcached_realloc_fn mem_realloc
;
3966 memcached_calloc_fn mem_calloc
;
3967 memcached_get_memory_allocators(memc
, &mem_malloc
, &mem_free
,
3968 &mem_realloc
, &mem_calloc
);
3970 test_true(mem_malloc
== my_malloc
);
3971 test_true(mem_realloc
== my_realloc
);
3972 test_true(mem_calloc
== my_calloc
);
3973 test_true(mem_free
== my_free
);
3975 return TEST_SUCCESS
;
3978 static test_return_t
enable_consistent_crc(memcached_st
*memc
)
3981 memcached_server_distribution_t value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
3982 memcached_hash_t hash
;
3983 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
3984 if ((rc
= pre_crc(memc
)) != TEST_SUCCESS
)
3987 value
= (memcached_server_distribution_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
3988 test_true(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
3990 hash
= (memcached_hash_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
3992 if (hash
!= MEMCACHED_HASH_CRC
)
3993 return TEST_SKIPPED
;
3995 return TEST_SUCCESS
;
3998 static test_return_t
enable_consistent_hsieh(memcached_st
*memc
)
4001 memcached_server_distribution_t value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
4002 memcached_hash_t hash
;
4003 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
4004 if ((rc
= pre_hsieh(memc
)) != TEST_SUCCESS
)
4007 value
= (memcached_server_distribution_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
4008 test_true(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
4010 hash
= (memcached_hash_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
4012 if (hash
!= MEMCACHED_HASH_HSIEH
)
4013 return TEST_SKIPPED
;
4016 return TEST_SUCCESS
;
4019 static test_return_t
enable_cas(memcached_st
*memc
)
4021 unsigned int set
= 1;
4023 memcached_server_instance_st instance
=
4024 memcached_server_instance_by_position(memc
, 0);
4026 memcached_version(memc
);
4028 if ((instance
->major_version
>= 1 && (instance
->minor_version
== 2 && instance
->micro_version
>= 4))
4029 || instance
->minor_version
> 2)
4031 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
4033 return TEST_SUCCESS
;
4036 return TEST_SKIPPED
;
4039 static test_return_t
check_for_1_2_3(memcached_st
*memc
)
4041 memcached_version(memc
);
4043 memcached_server_instance_st instance
=
4044 memcached_server_instance_by_position(memc
, 0);
4046 if ((instance
->major_version
>= 1 && (instance
->minor_version
== 2 && instance
->micro_version
>= 4))
4047 || instance
->minor_version
> 2)
4048 return TEST_SUCCESS
;
4050 return TEST_SKIPPED
;
4053 static test_return_t
pre_unix_socket(memcached_st
*memc
)
4055 memcached_return_t rc
;
4058 memcached_servers_reset(memc
);
4060 if (stat("/tmp/memcached.socket", &buf
))
4061 return TEST_SKIPPED
;
4063 rc
= memcached_server_add_unix_socket_with_weight(memc
, "/tmp/memcached.socket", 0);
4065 return ( rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_FAILURE
);
4068 static test_return_t
pre_nodelay(memcached_st
*memc
)
4070 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
4071 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
4073 return TEST_SUCCESS
;
4076 static test_return_t
pre_settimer(memcached_st
*memc
)
4078 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
4079 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
4081 return TEST_SUCCESS
;
4084 static test_return_t
poll_timeout(memcached_st
*memc
)
4090 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
4092 timeout
= (size_t)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
4094 test_true(timeout
== 100);
4096 return TEST_SUCCESS
;
4099 static test_return_t
noreply_test(memcached_st
*memc
)
4101 memcached_return_t ret
;
4102 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
4103 test_true(ret
== MEMCACHED_SUCCESS
);
4104 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4105 test_true(ret
== MEMCACHED_SUCCESS
);
4106 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
4107 test_true(ret
== MEMCACHED_SUCCESS
);
4108 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NOREPLY
) == 1);
4109 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
) == 1);
4110 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
) == 1);
4112 for (int count
=0; count
< 5; ++count
)
4114 for (size_t x
= 0; x
< 100; ++x
)
4117 size_t len
= (size_t)sprintf(key
, "%zu", x
);
4121 ret
= memcached_add(memc
, key
, len
, key
, len
, 0, 0);
4124 ret
= memcached_replace(memc
, key
, len
, key
, len
, 0, 0);
4127 ret
= memcached_set(memc
, key
, len
, key
, len
, 0, 0);
4130 ret
= memcached_append(memc
, key
, len
, key
, len
, 0, 0);
4133 ret
= memcached_prepend(memc
, key
, len
, key
, len
, 0, 0);
4139 test_true(ret
== MEMCACHED_SUCCESS
|| ret
== MEMCACHED_BUFFERED
);
4143 ** NOTE: Don't ever do this in your code! this is not a supported use of the
4144 ** API and is _ONLY_ done this way to verify that the library works the
4145 ** way it is supposed to do!!!!
4148 for (uint32_t x
= 0; x
< memcached_server_count(memc
); ++x
)
4150 memcached_server_instance_st instance
=
4151 memcached_server_instance_by_position(memc
, x
);
4152 no_msg
+=(int)(instance
->cursor_active
);
4155 test_true(no_msg
== 0);
4156 test_true(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
4159 ** Now validate that all items was set properly!
4161 for (size_t x
= 0; x
< 100; ++x
)
4165 size_t len
= (size_t)sprintf(key
, "%zu", x
);
4168 char* value
=memcached_get(memc
, key
, strlen(key
),
4169 &length
, &flags
, &ret
);
4170 test_true(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
4173 case 0: /* FALLTHROUGH */
4174 case 1: /* FALLTHROUGH */
4176 test_true(strncmp(value
, key
, len
) == 0);
4177 test_true(len
== length
);
4180 test_true(length
== len
* 2);
4183 test_true(length
== len
* 3);
4193 /* Try setting an illegal cas value (should not return an error to
4194 * the caller (because we don't expect a return message from the server)
4196 const char* keys
[]= {"0"};
4197 size_t lengths
[]= {1};
4200 memcached_result_st results_obj
;
4201 memcached_result_st
*results
;
4202 ret
= memcached_mget(memc
, keys
, lengths
, 1);
4203 test_true(ret
== MEMCACHED_SUCCESS
);
4205 results
= memcached_result_create(memc
, &results_obj
);
4207 results
= memcached_fetch_result(memc
, &results_obj
, &ret
);
4209 test_true(ret
== MEMCACHED_SUCCESS
);
4210 uint64_t cas
= memcached_result_cas(results
);
4211 memcached_result_free(&results_obj
);
4213 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
4214 test_true(ret
== MEMCACHED_SUCCESS
);
4217 * The item will have a new cas value, so try to set it again with the old
4218 * value. This should fail!
4220 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
4221 test_true(ret
== MEMCACHED_SUCCESS
);
4222 test_true(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
4223 char* value
=memcached_get(memc
, keys
[0], lengths
[0], &length
, &flags
, &ret
);
4224 test_true(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
4227 return TEST_SUCCESS
;
4230 static test_return_t
analyzer_test(memcached_st
*memc
)
4232 memcached_return_t rc
;
4233 memcached_stat_st
*memc_stat
;
4234 memcached_analysis_st
*report
;
4236 memc_stat
= memcached_stat(memc
, NULL
, &rc
);
4237 test_true(rc
== MEMCACHED_SUCCESS
);
4238 test_true(memc_stat
);
4240 report
= memcached_analyze(memc
, memc_stat
, &rc
);
4241 test_true(rc
== MEMCACHED_SUCCESS
);
4245 memcached_stat_free(NULL
, memc_stat
);
4247 return TEST_SUCCESS
;
4250 /* Count the objects */
4251 static memcached_return_t
callback_dump_counter(const memcached_st
*ptr
__attribute__((unused
)),
4252 const char *key
__attribute__((unused
)),
4253 size_t key_length
__attribute__((unused
)),
4256 size_t *counter
= (size_t *)context
;
4258 *counter
= *counter
+ 1;
4260 return MEMCACHED_SUCCESS
;
4263 static test_return_t
dump_test(memcached_st
*memc
)
4265 memcached_return_t rc
;
4267 memcached_dump_fn callbacks
[1];
4268 test_return_t main_rc
;
4270 callbacks
[0]= &callback_dump_counter
;
4272 /* No support for Binary protocol yet */
4273 if (memc
->flags
.binary_protocol
)
4274 return TEST_SUCCESS
;
4276 main_rc
= set_test3(memc
);
4278 test_true (main_rc
== TEST_SUCCESS
);
4280 rc
= memcached_dump(memc
, callbacks
, (void *)&counter
, 1);
4281 test_true(rc
== MEMCACHED_SUCCESS
);
4283 /* We may have more then 32 if our previous flush has not completed */
4284 test_true(counter
>= 32);
4286 return TEST_SUCCESS
;
4289 #ifdef HAVE_LIBMEMCACHEDUTIL
4290 static void* connection_release(void *arg
)
4293 memcached_pool_st
* pool
;
4298 assert(memcached_pool_push(resource
->pool
, resource
->mmc
) == MEMCACHED_SUCCESS
);
4302 static test_return_t
connection_pool_test(memcached_st
*memc
)
4304 memcached_pool_st
* pool
= memcached_pool_create(memc
, 5, 10);
4305 test_true(pool
!= NULL
);
4306 memcached_st
* mmc
[10];
4307 memcached_return_t rc
;
4309 for (size_t x
= 0; x
< 10; ++x
)
4311 mmc
[x
]= memcached_pool_pop(pool
, false, &rc
);
4312 test_true(mmc
[x
] != NULL
);
4313 test_true(rc
== MEMCACHED_SUCCESS
);
4316 test_true(memcached_pool_pop(pool
, false, &rc
) == NULL
);
4317 test_true(rc
== MEMCACHED_SUCCESS
);
4321 memcached_pool_st
* pool
;
4323 } item
= { .pool
= pool
, .mmc
= mmc
[9] };
4324 pthread_create(&tid
, NULL
, connection_release
, &item
);
4325 mmc
[9]= memcached_pool_pop(pool
, true, &rc
);
4326 test_true(rc
== MEMCACHED_SUCCESS
);
4327 pthread_join(tid
, NULL
);
4328 test_true(mmc
[9] == item
.mmc
);
4329 const char *key
= "key";
4330 size_t keylen
= strlen(key
);
4332 // verify that I can do ops with all connections
4333 rc
= memcached_set(mmc
[0], key
, keylen
, "0", 1, 0, 0);
4334 test_true(rc
== MEMCACHED_SUCCESS
);
4336 for (size_t x
= 0; x
< 10; ++x
)
4338 uint64_t number_value
;
4339 rc
= memcached_increment(mmc
[x
], key
, keylen
, 1, &number_value
);
4340 test_true(rc
== MEMCACHED_SUCCESS
);
4341 test_true(number_value
== (x
+1));
4345 for (size_t x
= 0; x
< 10; ++x
)
4347 test_true(memcached_pool_push(pool
, mmc
[x
]) == MEMCACHED_SUCCESS
);
4351 /* verify that I can set behaviors on the pool when I don't have all
4352 * of the connections in the pool. It should however be enabled
4353 * when I push the item into the pool
4355 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
4356 test_true(mmc
[0] != NULL
);
4358 rc
= memcached_pool_behavior_set(pool
, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
, 9999);
4359 test_true(rc
== MEMCACHED_SUCCESS
);
4361 mmc
[1]= memcached_pool_pop(pool
, false, &rc
);
4362 test_true(mmc
[1] != NULL
);
4364 test_true(memcached_behavior_get(mmc
[1], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
) == 9999);
4365 test_true(memcached_pool_push(pool
, mmc
[1]) == MEMCACHED_SUCCESS
);
4366 test_true(memcached_pool_push(pool
, mmc
[0]) == MEMCACHED_SUCCESS
);
4368 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
4369 test_true(memcached_behavior_get(mmc
[0], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
) == 9999);
4370 test_true(memcached_pool_push(pool
, mmc
[0]) == MEMCACHED_SUCCESS
);
4373 test_true(memcached_pool_destroy(pool
) == memc
);
4374 return TEST_SUCCESS
;
4378 static test_return_t
replication_set_test(memcached_st
*memc
)
4380 memcached_return_t rc
;
4381 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4382 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 0);
4384 rc
= memcached_set(memc
, "bubba", 5, "0", 1, 0, 0);
4385 test_true(rc
== MEMCACHED_SUCCESS
);
4388 ** We are using the quiet commands to store the replicas, so we need
4389 ** to ensure that all of them are processed before we can continue.
4390 ** In the test we go directly from storing the object to trying to
4391 ** receive the object from all of the different servers, so we
4392 ** could end up in a race condition (the memcached server hasn't yet
4393 ** processed the quiet command from the replication set when it process
4394 ** the request from the other client (created by the clone)). As a
4395 ** workaround for that we call memcached_quit to send the quit command
4396 ** to the server and wait for the response ;-) If you use the test code
4397 ** as an example for your own code, please note that you shouldn't need
4400 memcached_quit(memc
);
4403 ** "bubba" should now be stored on all of our servers. We don't have an
4404 ** easy to use API to address each individual server, so I'll just iterate
4405 ** through a bunch of "master keys" and I should most likely hit all of the
4408 for (int x
= 'a'; x
<= 'z'; ++x
)
4410 char key
[2]= { [0]= (char)x
};
4413 char *val
= memcached_get_by_key(memc_clone
, key
, 1, "bubba", 5,
4415 test_true(rc
== MEMCACHED_SUCCESS
);
4416 test_true(val
!= NULL
);
4420 memcached_free(memc_clone
);
4422 return TEST_SUCCESS
;
4425 static test_return_t
replication_get_test(memcached_st
*memc
)
4427 memcached_return_t rc
;
4430 * Don't do the following in your code. I am abusing the internal details
4431 * within the library, and this is not a supported interface.
4432 * This is to verify correct behavior in the library
4434 for (uint32_t host
= 0; host
< memcached_server_count(memc
); ++host
)
4436 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4437 memcached_server_instance_st instance
=
4438 memcached_server_instance_by_position(memc_clone
, host
);
4440 ((memcached_server_write_instance_st
)instance
)->port
= 0;
4442 for (int x
= 'a'; x
<= 'z'; ++x
)
4444 char key
[2]= { [0]= (char)x
};
4447 char *val
= memcached_get_by_key(memc_clone
, key
, 1, "bubba", 5,
4449 test_true(rc
== MEMCACHED_SUCCESS
);
4450 test_true(val
!= NULL
);
4454 memcached_free(memc_clone
);
4457 return TEST_SUCCESS
;
4460 static test_return_t
replication_mget_test(memcached_st
*memc
)
4462 memcached_return_t rc
;
4463 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4464 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 0);
4466 const char *keys
[]= { "bubba", "key1", "key2", "key3" };
4467 size_t len
[]= { 5, 4, 4, 4 };
4469 for (size_t x
= 0; x
< 4; ++x
)
4471 rc
= memcached_set(memc
, keys
[x
], len
[x
], "0", 1, 0, 0);
4472 test_true(rc
== MEMCACHED_SUCCESS
);
4476 ** We are using the quiet commands to store the replicas, so we need
4477 ** to ensure that all of them are processed before we can continue.
4478 ** In the test we go directly from storing the object to trying to
4479 ** receive the object from all of the different servers, so we
4480 ** could end up in a race condition (the memcached server hasn't yet
4481 ** processed the quiet command from the replication set when it process
4482 ** the request from the other client (created by the clone)). As a
4483 ** workaround for that we call memcached_quit to send the quit command
4484 ** to the server and wait for the response ;-) If you use the test code
4485 ** as an example for your own code, please note that you shouldn't need
4488 memcached_quit(memc
);
4491 * Don't do the following in your code. I am abusing the internal details
4492 * within the library, and this is not a supported interface.
4493 * This is to verify correct behavior in the library
4495 memcached_result_st result_obj
;
4496 for (uint32_t host
= 0; host
< memc_clone
->number_of_hosts
; host
++)
4498 memcached_st
*new_clone
= memcached_clone(NULL
, memc
);
4499 memcached_server_instance_st instance
=
4500 memcached_server_instance_by_position(new_clone
, host
);
4501 ((memcached_server_write_instance_st
)instance
)->port
= 0;
4503 for (int x
= 'a'; x
<= 'z'; ++x
)
4505 char key
[2]= { [0]= (char)x
, [1]= 0 };
4507 rc
= memcached_mget_by_key(new_clone
, key
, 1, keys
, len
, 4);
4508 test_true(rc
== MEMCACHED_SUCCESS
);
4510 memcached_result_st
*results
= memcached_result_create(new_clone
, &result_obj
);
4514 while ((results
= memcached_fetch_result(new_clone
, &result_obj
, &rc
)) != NULL
)
4518 test_true(hits
== 4);
4519 memcached_result_free(&result_obj
);
4522 memcached_free(new_clone
);
4525 memcached_free(memc_clone
);
4527 return TEST_SUCCESS
;
4530 static test_return_t
replication_randomize_mget_test(memcached_st
*memc
)
4532 memcached_result_st result_obj
;
4533 memcached_return_t rc
;
4534 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4535 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 3);
4536 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ
, 1);
4538 const char *keys
[]= { "key1", "key2", "key3", "key4", "key5", "key6", "key7" };
4539 size_t len
[]= { 4, 4, 4, 4, 4, 4, 4 };
4541 for (size_t x
= 0; x
< 7; ++x
)
4543 rc
= memcached_set(memc
, keys
[x
], len
[x
], "1", 1, 0, 0);
4544 test_true(rc
== MEMCACHED_SUCCESS
);
4547 memcached_quit(memc
);
4549 for (size_t x
= 0; x
< 7; ++x
)
4551 const char key
[2]= { [0]= (const char)x
};
4553 rc
= memcached_mget_by_key(memc_clone
, key
, 1, keys
, len
, 7);
4554 test_true(rc
== MEMCACHED_SUCCESS
);
4556 memcached_result_st
*results
= memcached_result_create(memc_clone
, &result_obj
);
4560 while ((results
= memcached_fetch_result(memc_clone
, &result_obj
, &rc
)) != NULL
)
4564 test_true(hits
== 7);
4565 memcached_result_free(&result_obj
);
4567 memcached_free(memc_clone
);
4568 return TEST_SUCCESS
;
4571 static test_return_t
replication_delete_test(memcached_st
*memc
)
4573 memcached_return_t rc
;
4574 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4575 /* Delete the items from all of the servers except 1 */
4576 uint64_t repl
= memcached_behavior_get(memc
,
4577 MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
);
4578 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, --repl
);
4580 const char *keys
[]= { "bubba", "key1", "key2", "key3" };
4581 size_t len
[]= { 5, 4, 4, 4 };
4583 for (size_t x
= 0; x
< 4; ++x
)
4585 rc
= memcached_delete_by_key(memc
, keys
[0], len
[0], keys
[x
], len
[x
], 0);
4586 test_true(rc
== MEMCACHED_SUCCESS
);
4590 * Don't do the following in your code. I am abusing the internal details
4591 * within the library, and this is not a supported interface.
4592 * This is to verify correct behavior in the library
4594 uint32_t hash
= memcached_generate_hash(memc
, keys
[0], len
[0]);
4595 for (uint32_t x
= 0; x
< (repl
+ 1); ++x
)
4597 memcached_server_instance_st instance
=
4598 memcached_server_instance_by_position(memc_clone
, x
);
4600 ((memcached_server_write_instance_st
)instance
)->port
= 0;
4601 if (++hash
== memc_clone
->number_of_hosts
)
4605 memcached_result_st result_obj
;
4606 for (uint32_t host
= 0; host
< memc_clone
->number_of_hosts
; ++host
)
4608 for (size_t x
= 'a'; x
<= 'z'; ++x
)
4610 const char key
[2]= { [0]= (const char)x
};
4612 rc
= memcached_mget_by_key(memc_clone
, key
, 1, keys
, len
, 4);
4613 test_true(rc
== MEMCACHED_SUCCESS
);
4615 memcached_result_st
*results
= memcached_result_create(memc_clone
, &result_obj
);
4619 while ((results
= memcached_fetch_result(memc_clone
, &result_obj
, &rc
)) != NULL
)
4623 test_true(hits
== 4);
4624 memcached_result_free(&result_obj
);
4627 memcached_free(memc_clone
);
4629 return TEST_SUCCESS
;
4633 static test_return_t
hash_sanity_test (memcached_st
*memc
)
4637 assert(MEMCACHED_HASH_DEFAULT
== MEMCACHED_HASH_DEFAULT
);
4638 assert(MEMCACHED_HASH_MD5
== MEMCACHED_HASH_MD5
);
4639 assert(MEMCACHED_HASH_CRC
== MEMCACHED_HASH_CRC
);
4640 assert(MEMCACHED_HASH_FNV1_64
== MEMCACHED_HASH_FNV1_64
);
4641 assert(MEMCACHED_HASH_FNV1A_64
== MEMCACHED_HASH_FNV1A_64
);
4642 assert(MEMCACHED_HASH_FNV1_32
== MEMCACHED_HASH_FNV1_32
);
4643 assert(MEMCACHED_HASH_FNV1A_32
== MEMCACHED_HASH_FNV1A_32
);
4644 #ifdef HAVE_HSIEH_HASH
4645 assert(MEMCACHED_HASH_HSIEH
== MEMCACHED_HASH_HSIEH
);
4647 assert(MEMCACHED_HASH_MURMUR
== MEMCACHED_HASH_MURMUR
);
4648 assert(MEMCACHED_HASH_JENKINS
== MEMCACHED_HASH_JENKINS
);
4649 assert(MEMCACHED_HASH_MAX
== MEMCACHED_HASH_MAX
);
4651 return TEST_SUCCESS
;
4655 static test_return_t
hsieh_avaibility_test (memcached_st
*memc
)
4657 memcached_return_t expected_rc
= MEMCACHED_FAILURE
;
4658 #ifdef HAVE_HSIEH_HASH
4659 expected_rc
= MEMCACHED_SUCCESS
;
4661 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
,
4662 (uint64_t)MEMCACHED_HASH_HSIEH
);
4663 test_true(rc
== expected_rc
);
4665 return TEST_SUCCESS
;
4668 static test_return_t
one_at_a_time_run (memcached_st
*memc
__attribute__((unused
)))
4673 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4677 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_DEFAULT
);
4678 test_true(one_at_a_time_values
[x
] == hash_val
);
4681 return TEST_SUCCESS
;
4684 static test_return_t
md5_run (memcached_st
*memc
__attribute__((unused
)))
4689 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4693 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MD5
);
4694 test_true(md5_values
[x
] == hash_val
);
4697 return TEST_SUCCESS
;
4700 static test_return_t
crc_run (memcached_st
*memc
__attribute__((unused
)))
4705 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4709 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_CRC
);
4710 test_true(crc_values
[x
] == hash_val
);
4713 return TEST_SUCCESS
;
4716 static test_return_t
fnv1_64_run (memcached_st
*memc
__attribute__((unused
)))
4721 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4725 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_64
);
4726 test_true(fnv1_64_values
[x
] == hash_val
);
4729 return TEST_SUCCESS
;
4732 static test_return_t
fnv1a_64_run (memcached_st
*memc
__attribute__((unused
)))
4737 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4741 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_64
);
4742 test_true(fnv1a_64_values
[x
] == hash_val
);
4745 return TEST_SUCCESS
;
4748 static test_return_t
fnv1_32_run (memcached_st
*memc
__attribute__((unused
)))
4754 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4758 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_32
);
4759 test_true(fnv1_32_values
[x
] == hash_val
);
4762 return TEST_SUCCESS
;
4765 static test_return_t
fnv1a_32_run (memcached_st
*memc
__attribute__((unused
)))
4770 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4774 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_32
);
4775 test_true(fnv1a_32_values
[x
] == hash_val
);
4778 return TEST_SUCCESS
;
4781 static test_return_t
hsieh_run (memcached_st
*memc
__attribute__((unused
)))
4786 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4790 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_HSIEH
);
4791 test_true(hsieh_values
[x
] == hash_val
);
4794 return TEST_SUCCESS
;
4797 static test_return_t
murmur_run (memcached_st
*memc
__attribute__((unused
)))
4799 #ifdef WORDS_BIGENDIAN
4800 return TEST_SKIPPED
;
4805 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4809 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MURMUR
);
4810 test_true(murmur_values
[x
] == hash_val
);
4813 return TEST_SUCCESS
;
4817 static test_return_t
jenkins_run (memcached_st
*memc
__attribute__((unused
)))
4823 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4827 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_JENKINS
);
4828 test_true(jenkins_values
[x
] == hash_val
);
4831 return TEST_SUCCESS
;
4834 static uint32_t hash_md5_test_function(const char *string
, size_t string_length
, void *context
)
4837 return libhashkit_md5(string
, string_length
);
4840 static uint32_t hash_crc_test_function(const char *string
, size_t string_length
, void *context
)
4843 return libhashkit_crc32(string
, string_length
);
4846 static test_return_t
memcached_get_hashkit_test (memcached_st
*memc
)
4850 const hashkit_st
*kit
;
4852 hashkit_return_t hash_rc
;
4854 uint32_t md5_hosts
[]= {4U, 1U, 0U, 1U, 4U, 2U, 0U, 3U, 0U, 0U, 3U, 1U, 0U, 0U, 1U, 3U, 0U, 0U, 0U, 3U, 1U, 0U, 4U, 4U, 3U};
4855 uint32_t crc_hosts
[]= {2U, 4U, 1U, 0U, 2U, 4U, 4U, 4U, 1U, 2U, 3U, 4U, 3U, 4U, 1U, 3U, 3U, 2U, 0U, 0U, 0U, 1U, 2U, 4U, 0U};
4857 kit
= memcached_get_hashkit(memc
);
4859 hashkit_clone(&new_kit
, kit
);
4860 hash_rc
= hashkit_set_custom_function(&new_kit
, hash_md5_test_function
, NULL
);
4861 test_true(hash_rc
== HASHKIT_SUCCESS
);
4863 memcached_set_hashkit(memc
, &new_kit
);
4866 Verify Setting the hash.
4868 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4872 hash_val
= hashkit_digest(kit
, *ptr
, strlen(*ptr
));
4873 test_true(md5_values
[x
] == hash_val
);
4878 Now check memcached_st.
4880 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4884 hash_val
= memcached_generate_hash(memc
, *ptr
, strlen(*ptr
));
4885 test_true(md5_hosts
[x
] == hash_val
);
4888 hash_rc
= hashkit_set_custom_function(&new_kit
, hash_crc_test_function
, NULL
);
4889 test_true(hash_rc
== HASHKIT_SUCCESS
);
4891 memcached_set_hashkit(memc
, &new_kit
);
4894 Verify Setting the hash.
4896 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4900 hash_val
= hashkit_digest(kit
, *ptr
, strlen(*ptr
));
4901 test_true(crc_values
[x
] == hash_val
);
4904 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4908 hash_val
= memcached_generate_hash(memc
, *ptr
, strlen(*ptr
));
4909 test_true(crc_hosts
[x
] == hash_val
);
4912 return TEST_SUCCESS
;
4916 static test_return_t
ketama_compatibility_libmemcached(memcached_st
*trash
)
4918 memcached_return_t rc
;
4921 memcached_server_st
*server_pool
;
4926 memc
= memcached_create(NULL
);
4929 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
4930 test_true(rc
== MEMCACHED_SUCCESS
);
4932 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
4933 test_true(value
== 1);
4935 test_true(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
) == MEMCACHED_SUCCESS
);
4936 test_true(memcached_behavior_get_distribution(memc
) == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
);
4939 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");
4940 memcached_server_push(memc
, server_pool
);
4942 /* verify that the server list was parsed okay. */
4943 test_true(memcached_server_count(memc
) == 8);
4944 test_strcmp(server_pool
[0].hostname
, "10.0.1.1");
4945 test_true(server_pool
[0].port
== 11211);
4946 test_true(server_pool
[0].weight
== 600);
4947 test_strcmp(server_pool
[2].hostname
, "10.0.1.3");
4948 test_true(server_pool
[2].port
== 11211);
4949 test_true(server_pool
[2].weight
== 200);
4950 test_strcmp(server_pool
[7].hostname
, "10.0.1.8");
4951 test_true(server_pool
[7].port
== 11211);
4952 test_true(server_pool
[7].weight
== 100);
4954 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
4955 * us test the boundary wraparound.
4957 test_true(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
4959 /* verify the standard ketama set. */
4960 for (x
= 0; x
< 99; x
++)
4962 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
4963 memcached_server_instance_st instance
=
4964 memcached_server_instance_by_position(memc
, server_idx
);
4965 const char *hostname
= memcached_server_name(instance
);
4967 test_strcmp(hostname
, ketama_test_cases
[x
].server
);
4970 memcached_server_list_free(server_pool
);
4971 memcached_free(memc
);
4973 return TEST_SUCCESS
;
4976 static test_return_t
ketama_compatibility_spymemcached(memcached_st
*trash
)
4978 memcached_return_t rc
;
4981 memcached_server_st
*server_pool
;
4986 memc
= memcached_create(NULL
);
4989 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
4990 test_true(rc
== MEMCACHED_SUCCESS
);
4992 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
4993 test_true(value
== 1);
4995 test_true(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
) == MEMCACHED_SUCCESS
);
4996 test_true(memcached_behavior_get_distribution(memc
) == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
);
4998 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");
4999 memcached_server_push(memc
, server_pool
);
5001 /* verify that the server list was parsed okay. */
5002 test_true(memcached_server_count(memc
) == 8);
5003 test_strcmp(server_pool
[0].hostname
, "10.0.1.1");
5004 test_true(server_pool
[0].port
== 11211);
5005 test_true(server_pool
[0].weight
== 600);
5006 test_strcmp(server_pool
[2].hostname
, "10.0.1.3");
5007 test_true(server_pool
[2].port
== 11211);
5008 test_true(server_pool
[2].weight
== 200);
5009 test_strcmp(server_pool
[7].hostname
, "10.0.1.8");
5010 test_true(server_pool
[7].port
== 11211);
5011 test_true(server_pool
[7].weight
== 100);
5013 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
5014 * us test the boundary wraparound.
5016 test_true(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
5018 /* verify the standard ketama set. */
5019 for (x
= 0; x
< 99; x
++)
5021 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases_spy
[x
].key
, strlen(ketama_test_cases_spy
[x
].key
));
5023 memcached_server_instance_st instance
=
5024 memcached_server_instance_by_position(memc
, server_idx
);
5026 const char *hostname
= memcached_server_name(instance
);
5028 test_strcmp(hostname
, ketama_test_cases_spy
[x
].server
);
5031 memcached_server_list_free(server_pool
);
5032 memcached_free(memc
);
5034 return TEST_SUCCESS
;
5037 static test_return_t
regression_bug_434484(memcached_st
*memc
)
5039 test_return_t test_rc
;
5040 test_rc
= pre_binary(memc
);
5042 if (test_rc
!= TEST_SUCCESS
)
5045 memcached_return_t ret
;
5046 const char *key
= "regression_bug_434484";
5047 size_t keylen
= strlen(key
);
5049 ret
= memcached_append(memc
, key
, keylen
, key
, keylen
, 0, 0);
5050 test_true(ret
== MEMCACHED_NOTSTORED
);
5052 size_t size
= 2048 * 1024;
5053 void *data
= calloc(1, size
);
5054 test_true(data
!= NULL
);
5055 ret
= memcached_set(memc
, key
, keylen
, data
, size
, 0, 0);
5056 test_true(ret
== MEMCACHED_E2BIG
);
5059 return TEST_SUCCESS
;
5062 static test_return_t
regression_bug_434843(memcached_st
*memc
)
5064 test_return_t test_rc
;
5065 test_rc
= pre_binary(memc
);
5067 if (test_rc
!= TEST_SUCCESS
)
5070 memcached_return_t rc
;
5072 memcached_execute_fn callbacks
[1]= { [0]= &callback_counter
};
5075 * I only want to hit only _one_ server so I know the number of requests I'm
5076 * sending in the pipleine to the server. Let's try to do a multiget of
5077 * 1024 (that should satisfy most users don't you think?). Future versions
5078 * will include a mget_execute function call if you need a higher number.
5080 uint32_t number_of_hosts
= memcached_server_count(memc
);
5081 memc
->number_of_hosts
= 1;
5082 const size_t max_keys
= 1024;
5083 char **keys
= calloc(max_keys
, sizeof(char*));
5084 size_t *key_length
=calloc(max_keys
, sizeof(size_t));
5086 for (size_t x
= 0; x
< max_keys
; ++x
)
5090 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%zu", x
);
5092 test_true(keys
[x
] != NULL
);
5096 * Run two times.. the first time we should have 100% cache miss,
5097 * and the second time we should have 100% cache hits
5099 for (size_t y
= 0; y
< 2; y
++)
5101 rc
= memcached_mget(memc
, (const char**)keys
, key_length
, max_keys
);
5102 test_true(rc
== MEMCACHED_SUCCESS
);
5103 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5107 /* The first iteration should give me a 100% cache miss. verify that*/
5108 char blob
[1024]= { 0 };
5110 test_true(counter
== 0);
5112 for (size_t x
= 0; x
< max_keys
; ++x
)
5114 rc
= memcached_add(memc
, keys
[x
], key_length
[x
],
5115 blob
, sizeof(blob
), 0, 0);
5116 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5121 /* Verify that we received all of the key/value pairs */
5122 test_true(counter
== max_keys
);
5126 /* Release allocated resources */
5127 for (size_t x
= 0; x
< max_keys
; ++x
)
5134 memc
->number_of_hosts
= number_of_hosts
;
5136 return TEST_SUCCESS
;
5139 static test_return_t
regression_bug_434843_buffered(memcached_st
*memc
)
5141 memcached_return_t rc
;
5142 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
5143 test_true(rc
== MEMCACHED_SUCCESS
);
5145 return regression_bug_434843(memc
);
5148 static test_return_t
regression_bug_421108(memcached_st
*memc
)
5150 memcached_return_t rc
;
5151 memcached_stat_st
*memc_stat
= memcached_stat(memc
, NULL
, &rc
);
5152 test_true(rc
== MEMCACHED_SUCCESS
);
5154 char *bytes
= memcached_stat_get_value(memc
, memc_stat
, "bytes", &rc
);
5155 test_true(rc
== MEMCACHED_SUCCESS
);
5156 test_true(bytes
!= NULL
);
5157 char *bytes_read
= memcached_stat_get_value(memc
, memc_stat
,
5159 test_true(rc
== MEMCACHED_SUCCESS
);
5160 test_true(bytes_read
!= NULL
);
5162 char *bytes_written
= memcached_stat_get_value(memc
, memc_stat
,
5163 "bytes_written", &rc
);
5164 test_true(rc
== MEMCACHED_SUCCESS
);
5165 test_true(bytes_written
!= NULL
);
5167 test_true(strcmp(bytes
, bytes_read
) != 0);
5168 test_true(strcmp(bytes
, bytes_written
) != 0);
5170 /* Release allocated resources */
5173 free(bytes_written
);
5174 memcached_stat_free(NULL
, memc_stat
);
5176 return TEST_SUCCESS
;
5180 * The test case isn't obvious so I should probably document why
5181 * it works the way it does. Bug 442914 was caused by a bug
5182 * in the logic in memcached_purge (it did not handle the case
5183 * where the number of bytes sent was equal to the watermark).
5184 * In this test case, create messages so that we hit that case
5185 * and then disable noreply mode and issue a new command to
5186 * verify that it isn't stuck. If we change the format for the
5187 * delete command or the watermarks, we need to update this
5190 static test_return_t
regression_bug_442914(memcached_st
*memc
)
5192 memcached_return_t rc
;
5193 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
5194 test_true(rc
== MEMCACHED_SUCCESS
);
5195 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1);
5197 uint32_t number_of_hosts
= memcached_server_count(memc
);
5198 memc
->number_of_hosts
= 1;
5203 for (uint32_t x
= 0; x
< 250; ++x
)
5205 len
= (size_t)snprintf(k
, sizeof(k
), "%0250u", x
);
5206 rc
= memcached_delete(memc
, k
, len
, 0);
5207 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5210 (void)snprintf(k
, sizeof(k
), "%037u", 251U);
5213 rc
= memcached_delete(memc
, k
, len
, 0);
5214 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5216 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0);
5217 test_true(rc
== MEMCACHED_SUCCESS
);
5218 rc
= memcached_delete(memc
, k
, len
, 0);
5219 test_true(rc
== MEMCACHED_NOTFOUND
);
5221 memc
->number_of_hosts
= number_of_hosts
;
5223 return TEST_SUCCESS
;
5226 static test_return_t
regression_bug_447342(memcached_st
*memc
)
5228 memcached_server_instance_st instance_one
;
5229 memcached_server_instance_st instance_two
;
5231 if (memcached_server_count(memc
) < 3 || pre_replication(memc
) != MEMCACHED_SUCCESS
)
5232 return TEST_SKIPPED
;
5234 memcached_return_t rc
;
5236 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 2);
5237 test_true(rc
== MEMCACHED_SUCCESS
);
5239 const size_t max_keys
= 100;
5240 char **keys
= calloc(max_keys
, sizeof(char*));
5241 size_t *key_length
= calloc(max_keys
, sizeof(size_t));
5243 for (size_t x
= 0; x
< max_keys
; ++x
)
5247 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%zu", x
);
5249 test_true(keys
[x
] != NULL
);
5250 rc
= memcached_set(memc
, k
, key_length
[x
], k
, key_length
[x
], 0, 0);
5251 test_true(rc
== MEMCACHED_SUCCESS
);
5255 ** We are using the quiet commands to store the replicas, so we need
5256 ** to ensure that all of them are processed before we can continue.
5257 ** In the test we go directly from storing the object to trying to
5258 ** receive the object from all of the different servers, so we
5259 ** could end up in a race condition (the memcached server hasn't yet
5260 ** processed the quiet command from the replication set when it process
5261 ** the request from the other client (created by the clone)). As a
5262 ** workaround for that we call memcached_quit to send the quit command
5263 ** to the server and wait for the response ;-) If you use the test code
5264 ** as an example for your own code, please note that you shouldn't need
5267 memcached_quit(memc
);
5269 /* Verify that all messages are stored, and we didn't stuff too much
5272 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5273 test_true(rc
== MEMCACHED_SUCCESS
);
5276 memcached_execute_fn callbacks
[1]= { [0]= &callback_counter
};
5277 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5278 /* Verify that we received all of the key/value pairs */
5279 test_true(counter
== max_keys
);
5281 memcached_quit(memc
);
5283 * Don't do the following in your code. I am abusing the internal details
5284 * within the library, and this is not a supported interface.
5285 * This is to verify correct behavior in the library. Fake that two servers
5288 instance_one
= memcached_server_instance_by_position(memc
, 0);
5289 instance_two
= memcached_server_instance_by_position(memc
, 2);
5290 in_port_t port0
= instance_one
->port
;
5291 in_port_t port2
= instance_two
->port
;
5293 ((memcached_server_write_instance_st
)instance_one
)->port
= 0;
5294 ((memcached_server_write_instance_st
)instance_two
)->port
= 0;
5296 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5297 test_true(rc
== MEMCACHED_SUCCESS
);
5300 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5301 test_true(counter
== (unsigned int)max_keys
);
5303 /* restore the memc handle */
5304 ((memcached_server_write_instance_st
)instance_one
)->port
= port0
;
5305 ((memcached_server_write_instance_st
)instance_two
)->port
= port2
;
5307 memcached_quit(memc
);
5309 /* Remove half of the objects */
5310 for (size_t x
= 0; x
< max_keys
; ++x
)
5314 rc
= memcached_delete(memc
, keys
[x
], key_length
[x
], 0);
5315 test_true(rc
== MEMCACHED_SUCCESS
);
5319 memcached_quit(memc
);
5320 ((memcached_server_write_instance_st
)instance_one
)->port
= 0;
5321 ((memcached_server_write_instance_st
)instance_two
)->port
= 0;
5323 /* now retry the command, this time we should have cache misses */
5324 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5325 test_true(rc
== MEMCACHED_SUCCESS
);
5328 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5329 test_true(counter
== (unsigned int)(max_keys
>> 1));
5331 /* Release allocated resources */
5332 for (size_t x
= 0; x
< max_keys
; ++x
)
5339 /* restore the memc handle */
5340 ((memcached_server_write_instance_st
)instance_one
)->port
= port0
;
5341 ((memcached_server_write_instance_st
)instance_two
)->port
= port2
;
5343 return TEST_SUCCESS
;
5346 static test_return_t
regression_bug_463297(memcached_st
*memc
)
5348 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
5349 test_true(memc_clone
!= NULL
);
5350 test_true(memcached_version(memc_clone
) == MEMCACHED_SUCCESS
);
5352 memcached_server_instance_st instance
=
5353 memcached_server_instance_by_position(memc_clone
, 0);
5355 if (instance
->major_version
> 1 ||
5356 (instance
->major_version
== 1 &&
5357 instance
->minor_version
> 2))
5359 /* Binary protocol doesn't support deferred delete */
5360 memcached_st
*bin_clone
= memcached_clone(NULL
, memc
);
5361 test_true(bin_clone
!= NULL
);
5362 test_true(memcached_behavior_set(bin_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1) == MEMCACHED_SUCCESS
);
5363 test_true(memcached_delete(bin_clone
, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS
);
5364 memcached_free(bin_clone
);
5366 memcached_quit(memc_clone
);
5368 /* If we know the server version, deferred delete should fail
5369 * with invalid arguments */
5370 test_true(memcached_delete(memc_clone
, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS
);
5372 /* If we don't know the server version, we should get a protocol error */
5373 memcached_return_t rc
= memcached_delete(memc
, "foo", 3, 1);
5375 /* but there is a bug in some of the memcached servers (1.4) that treats
5376 * the counter as noreply so it doesn't send the proper error message
5378 test_true(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5380 /* And buffered mode should be disabled and we should get protocol error */
5381 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1) == MEMCACHED_SUCCESS
);
5382 rc
= memcached_delete(memc
, "foo", 3, 1);
5383 test_true(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5385 /* Same goes for noreply... */
5386 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1) == MEMCACHED_SUCCESS
);
5387 rc
= memcached_delete(memc
, "foo", 3, 1);
5388 test_true(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5390 /* but a normal request should go through (and be buffered) */
5391 test_true((rc
= memcached_delete(memc
, "foo", 3, 0)) == MEMCACHED_BUFFERED
);
5392 test_true(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
5394 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 0) == MEMCACHED_SUCCESS
);
5395 /* unbuffered noreply should be success */
5396 test_true(memcached_delete(memc
, "foo", 3, 0) == MEMCACHED_SUCCESS
);
5397 /* unbuffered with reply should be not found... */
5398 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0) == MEMCACHED_SUCCESS
);
5399 test_true(memcached_delete(memc
, "foo", 3, 0) == MEMCACHED_NOTFOUND
);
5402 memcached_free(memc_clone
);
5403 return TEST_SUCCESS
;
5407 /* Test memcached_server_get_last_disconnect
5408 * For a working server set, shall be NULL
5409 * For a set of non existing server, shall not be NULL
5411 static test_return_t
test_get_last_disconnect(memcached_st
*memc
)
5413 memcached_return_t rc
;
5414 memcached_server_instance_st disconnected_server
;
5416 /* With the working set of server */
5417 const char *key
= "marmotte";
5418 const char *value
= "milka";
5420 rc
= memcached_set(memc
, key
, strlen(key
),
5421 value
, strlen(value
),
5422 (time_t)0, (uint32_t)0);
5423 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5425 disconnected_server
= memcached_server_get_last_disconnect(memc
);
5426 test_true(disconnected_server
== NULL
);
5428 /* With a non existing server */
5430 memcached_server_st
*servers
;
5432 const char *server_list
= "localhost:9";
5434 servers
= memcached_servers_parse(server_list
);
5436 mine
= memcached_create(NULL
);
5437 rc
= memcached_server_push(mine
, servers
);
5438 test_true(rc
== MEMCACHED_SUCCESS
);
5439 memcached_server_list_free(servers
);
5442 rc
= memcached_set(mine
, key
, strlen(key
),
5443 value
, strlen(value
),
5444 (time_t)0, (uint32_t)0);
5445 test_true(rc
!= MEMCACHED_SUCCESS
);
5447 disconnected_server
= memcached_server_get_last_disconnect(mine
);
5448 test_true(disconnected_server
!= NULL
);
5449 test_true(memcached_server_port(disconnected_server
)== 9);
5450 test_true(strncmp(memcached_server_name(disconnected_server
),"localhost",9) == 0);
5452 memcached_quit(mine
);
5453 memcached_free(mine
);
5455 return TEST_SUCCESS
;
5458 static test_return_t
test_verbosity(memcached_st
*memc
)
5460 memcached_verbosity(memc
, 3);
5462 return TEST_SUCCESS
;
5465 static test_return_t
test_server_failure(memcached_st
*memc
)
5467 memcached_st
*local_memc
;
5468 memcached_server_instance_st instance
= memcached_server_instance_by_position(memc
, 0);
5470 local_memc
= memcached_create(NULL
);
5472 memcached_server_add(local_memc
, memcached_server_name(instance
), memcached_server_port(instance
));
5473 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, 2);
5475 uint32_t server_count
= memcached_server_count(local_memc
);
5477 test_true(server_count
== 1);
5479 // Disable the server
5480 instance
= memcached_server_instance_by_position(local_memc
, 0);
5481 ((memcached_server_write_instance_st
)instance
)->server_failure_counter
= 2;
5483 memcached_return_t rc
;
5484 rc
= memcached_set(local_memc
, "foo", strlen("foo"),
5486 (time_t)0, (uint32_t)0);
5487 test_true(rc
== MEMCACHED_SERVER_MARKED_DEAD
);
5489 ((memcached_server_write_instance_st
)instance
)->server_failure_counter
= 0;
5490 rc
= memcached_set(local_memc
, "foo", strlen("foo"),
5492 (time_t)0, (uint32_t)0);
5493 test_true(rc
== MEMCACHED_SUCCESS
);
5496 memcached_free(local_memc
);
5498 return TEST_SUCCESS
;
5501 static test_return_t
test_cull_servers(memcached_st
*memc
)
5503 uint32_t count
= memcached_server_count(memc
);
5505 // Do not do this in your code, it is not supported.
5506 memc
->servers
[1].state
.is_dead
= true;
5507 memc
->state
.is_time_for_rebuild
= true;
5509 uint32_t new_count
= memcached_server_count(memc
);
5510 test_true(count
== new_count
);
5513 test_true(count
== new_count
+ 1 );
5516 return TEST_SUCCESS
;
5520 * This test ensures that the failure counter isn't incremented during
5521 * normal termination of the memcached instance.
5523 static test_return_t
wrong_failure_counter_test(memcached_st
*memc
)
5525 memcached_return_t rc
;
5526 memcached_server_instance_st instance
;
5528 /* Set value to force connection to the server */
5529 const char *key
= "marmotte";
5530 const char *value
= "milka";
5533 * Please note that I'm abusing the internal structures in libmemcached
5534 * in a non-portable way and you shouldn't be doing this. I'm only
5535 * doing this in order to verify that the library works the way it should
5537 uint32_t number_of_hosts
= memcached_server_count(memc
);
5538 memc
->number_of_hosts
= 1;
5540 /* Ensure that we are connected to the server by setting a value */
5541 rc
= memcached_set(memc
, key
, strlen(key
),
5542 value
, strlen(value
),
5543 (time_t)0, (uint32_t)0);
5544 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5547 instance
= memcached_server_instance_by_position(memc
, 0);
5548 /* The test is to see that the memcached_quit doesn't increase the
5549 * the server failure conter, so let's ensure that it is zero
5550 * before sending quit
5552 ((memcached_server_write_instance_st
)instance
)->server_failure_counter
= 0;
5554 memcached_quit(memc
);
5556 /* Verify that it memcached_quit didn't increment the failure counter
5557 * Please note that this isn't bullet proof, because an error could
5560 test_true(instance
->server_failure_counter
== 0);
5562 /* restore the instance */
5563 memc
->number_of_hosts
= number_of_hosts
;
5565 return TEST_SUCCESS
;
5572 * Test that ensures mget_execute does not end into recursive calls that finally fails
5574 static test_return_t
regression_bug_490486(memcached_st
*memc
)
5576 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
5577 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 1);
5578 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, 1000);
5579 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, 1);
5580 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 3600);
5583 * I only want to hit _one_ server so I know the number of requests I'm
5584 * sending in the pipeline.
5586 uint32_t number_of_hosts
= memc
->number_of_hosts
;
5587 memc
->number_of_hosts
= 1;
5588 size_t max_keys
= 20480;
5591 char **keys
= calloc(max_keys
, sizeof(char*));
5592 size_t *key_length
=calloc(max_keys
, sizeof(size_t));
5594 /* First add all of the items.. */
5595 char blob
[1024]= { 0 };
5596 memcached_return rc
;
5597 for (size_t x
= 0; x
< max_keys
; ++x
)
5600 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%zu", x
);
5602 assert(keys
[x
] != NULL
);
5603 rc
= memcached_set(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
5604 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5607 /* Try to get all of them with a large multiget */
5609 memcached_execute_function callbacks
[1]= { [0]= &callback_counter
};
5610 rc
= memcached_mget_execute(memc
, (const char**)keys
, key_length
,
5611 (size_t)max_keys
, callbacks
, &counter
, 1);
5613 assert(rc
== MEMCACHED_SUCCESS
);
5614 char* the_value
= NULL
;
5615 char the_key
[MEMCACHED_MAX_KEY
];
5616 size_t the_key_length
;
5617 size_t the_value_length
;
5621 the_value
= memcached_fetch(memc
, the_key
, &the_key_length
, &the_value_length
, &the_flags
, &rc
);
5623 if ((the_value
!= NULL
) && (rc
== MEMCACHED_SUCCESS
))
5629 } while ( (the_value
!= NULL
) && (rc
== MEMCACHED_SUCCESS
));
5632 assert(rc
== MEMCACHED_END
);
5634 /* Verify that we got all of the items */
5635 assert(counter
== max_keys
);
5637 /* Release all allocated resources */
5638 for (size_t x
= 0; x
< max_keys
; ++x
)
5645 memc
->number_of_hosts
= number_of_hosts
;
5647 return TEST_SUCCESS
;
5650 static void memcached_die(memcached_st
* mc
, memcached_return error
, const char* what
, int it
)
5652 fprintf(stderr
, "Iteration #%i: ", it
);
5654 if(error
== MEMCACHED_ERRNO
)
5656 fprintf(stderr
, "system error %d from %s: %s\n",
5657 errno
, what
, strerror(errno
));
5661 fprintf(stderr
, "error %d from %s: %s\n", error
, what
,
5662 memcached_strerror(mc
, error
));
5668 #define TEST_CONSTANT_CREATION 400
5670 static test_return_t
regression_bug_(memcached_st
*memc
)
5672 memcached_server_instance_st instance
= memcached_server_instance_by_position(memc
, 0);
5673 const char *servername
= memcached_server_name(instance
);
5674 in_port_t port
= memcached_server_port(instance
);
5676 for (uint32_t x
= 0; x
< TEST_CONSTANT_CREATION
; x
++)
5678 memcached_st
* mc
= memcached_create(NULL
);
5679 memcached_return rc
;
5681 rc
= memcached_behavior_set(mc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
5682 if (rc
!= MEMCACHED_SUCCESS
)
5684 memcached_die(mc
, rc
, "memcached_behavior_set", x
);
5687 rc
= memcached_behavior_set(mc
, MEMCACHED_BEHAVIOR_CACHE_LOOKUPS
, 1);
5688 if (rc
!= MEMCACHED_SUCCESS
)
5690 memcached_die(mc
, rc
, "memcached_behavior_set", x
);
5693 rc
= memcached_server_add(mc
, servername
, port
);
5694 if(rc
!= MEMCACHED_SUCCESS
)
5696 memcached_die(mc
, rc
, "memcached_server_add", x
);
5699 const char *set_key
= "akey";
5700 const size_t set_key_len
= strlen(set_key
);
5701 const char *set_value
= "a value";
5702 const size_t set_value_len
= strlen(set_value
);
5704 char *get_value
=NULL
;
5705 size_t get_value_len
=0;
5706 uint32_t get_value_flags
=0;
5709 get_value
= memcached_get(mc
, set_key
, set_key_len
, &get_value_len
,
5710 &get_value_flags
, &rc
);
5711 if (rc
!= MEMCACHED_SUCCESS
)
5713 memcached_die(mc
, rc
, "memcached_get", x
);
5717 (get_value_len
!= set_value_len
5718 || 0!=strncmp(get_value
, set_value
, get_value_len
)))
5720 fprintf(stderr
, "Values don't match?\n");
5727 rc
= memcached_set(mc
,
5728 set_key
, set_key_len
,
5729 set_value
, set_value_len
,
5733 if (rc
!= MEMCACHED_SUCCESS
)
5735 memcached_die(mc
, rc
, "memcached_set", x
);
5742 return MEMCACHED_SUCCESS
;
5746 * Test that the sasl authentication works. We cannot use the default
5747 * pool of servers, because that would require that all servers we want
5748 * to test supports SASL authentication, and that they use the default
5751 static test_return_t
sasl_auth_test(memcached_st
*memc
)
5753 #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
5754 memcached_return_t rc
;
5756 rc
= memcached_set(memc
, "foo", 3, "bar", 3, (time_t)0, (uint32_t)0);
5757 test_true(rc
== MEMCACHED_SUCCESS
);
5758 test_true((rc
= memcached_delete(memc
, "foo", 3, 0)) == MEMCACHED_SUCCESS
);
5759 test_true((rc
= memcached_destroy_sasl_auth_data(memc
)) == MEMCACHED_SUCCESS
);
5760 test_true((rc
= memcached_destroy_sasl_auth_data(memc
)) == MEMCACHED_FAILURE
);
5761 test_true((rc
= memcached_destroy_sasl_auth_data(NULL
)) == MEMCACHED_FAILURE
);
5762 memcached_quit(memc
);
5764 rc
= memcached_set_sasl_auth_data(memc
,
5765 getenv("LIBMEMCACHED_TEST_SASL_USERNAME"),
5766 getenv("LIBMEMCACHED_TEST_SASL_SERVER"));
5767 test_true(rc
== MEMCACHED_SUCCESS
);
5769 rc
= memcached_set(memc
, "foo", 3, "bar", 3, (time_t)0, (uint32_t)0);
5770 test_true(rc
== MEMCACHED_AUTH_FAILURE
);
5771 test_true(memcached_destroy_sasl_auth_data(memc
) == MEMCACHED_SUCCESS
);
5773 memcached_quit(memc
);
5774 return TEST_SUCCESS
;
5777 return TEST_FAILURE
;
5781 /* Clean the server before beginning testing */
5783 {"flush", 0, (test_callback_fn
)flush_test
},
5784 {"init", 0, (test_callback_fn
)init_test
},
5785 {"allocation", 0, (test_callback_fn
)allocation_test
},
5786 {"server_list_null_test", 0, (test_callback_fn
)server_list_null_test
},
5787 {"server_unsort", 0, (test_callback_fn
)server_unsort_test
},
5788 {"server_sort", 0, (test_callback_fn
)server_sort_test
},
5789 {"server_sort2", 0, (test_callback_fn
)server_sort2_test
},
5790 {"memcached_server_remove", 0, (test_callback_fn
)memcached_server_remove_test
},
5791 {"clone_test", 0, (test_callback_fn
)clone_test
},
5792 {"connection_test", 0, (test_callback_fn
)connection_test
},
5793 {"callback_test", 0, (test_callback_fn
)callback_test
},
5794 {"userdata_test", 0, (test_callback_fn
)userdata_test
},
5795 {"error", 0, (test_callback_fn
)error_test
},
5796 {"set", 0, (test_callback_fn
)set_test
},
5797 {"set2", 0, (test_callback_fn
)set_test2
},
5798 {"set3", 0, (test_callback_fn
)set_test3
},
5799 {"dump", 1, (test_callback_fn
)dump_test
},
5800 {"add", 1, (test_callback_fn
)add_test
},
5801 {"replace", 1, (test_callback_fn
)replace_test
},
5802 {"delete", 1, (test_callback_fn
)delete_test
},
5803 {"get", 1, (test_callback_fn
)get_test
},
5804 {"get2", 0, (test_callback_fn
)get_test2
},
5805 {"get3", 0, (test_callback_fn
)get_test3
},
5806 {"get4", 0, (test_callback_fn
)get_test4
},
5807 {"partial mget", 0, (test_callback_fn
)get_test5
},
5808 {"stats_servername", 0, (test_callback_fn
)stats_servername_test
},
5809 {"increment", 0, (test_callback_fn
)increment_test
},
5810 {"increment_with_initial", 1, (test_callback_fn
)increment_with_initial_test
},
5811 {"decrement", 0, (test_callback_fn
)decrement_test
},
5812 {"decrement_with_initial", 1, (test_callback_fn
)decrement_with_initial_test
},
5813 {"increment_by_key", 0, (test_callback_fn
)increment_by_key_test
},
5814 {"increment_with_initial_by_key", 1, (test_callback_fn
)increment_with_initial_by_key_test
},
5815 {"decrement_by_key", 0, (test_callback_fn
)decrement_by_key_test
},
5816 {"decrement_with_initial_by_key", 1, (test_callback_fn
)decrement_with_initial_by_key_test
},
5817 {"quit", 0, (test_callback_fn
)quit_test
},
5818 {"mget", 1, (test_callback_fn
)mget_test
},
5819 {"mget_result", 1, (test_callback_fn
)mget_result_test
},
5820 {"mget_result_alloc", 1, (test_callback_fn
)mget_result_alloc_test
},
5821 {"mget_result_function", 1, (test_callback_fn
)mget_result_function
},
5822 {"mget_execute", 1, (test_callback_fn
)mget_execute
},
5823 {"mget_end", 0, (test_callback_fn
)mget_end
},
5824 {"get_stats", 0, (test_callback_fn
)get_stats
},
5825 {"add_host_test", 0, (test_callback_fn
)add_host_test
},
5826 {"add_host_test_1", 0, (test_callback_fn
)add_host_test1
},
5827 {"get_stats_keys", 0, (test_callback_fn
)get_stats_keys
},
5828 {"version_string_test", 0, (test_callback_fn
)version_string_test
},
5829 {"bad_key", 1, (test_callback_fn
)bad_key_test
},
5830 {"memcached_server_cursor", 1, (test_callback_fn
)memcached_server_cursor_test
},
5831 {"read_through", 1, (test_callback_fn
)read_through
},
5832 {"delete_through", 1, (test_callback_fn
)delete_through
},
5833 {"noreply", 1, (test_callback_fn
)noreply_test
},
5834 {"analyzer", 1, (test_callback_fn
)analyzer_test
},
5835 #ifdef HAVE_LIBMEMCACHEDUTIL
5836 {"connectionpool", 1, (test_callback_fn
)connection_pool_test
},
5838 {"test_get_last_disconnect", 1, (test_callback_fn
)test_get_last_disconnect
},
5839 {"verbosity", 1, (test_callback_fn
)test_verbosity
},
5840 {"test_server_failure", 1, (test_callback_fn
)test_server_failure
},
5841 {"cull_servers", 1, (test_callback_fn
)test_cull_servers
},
5845 test_st behavior_tests
[] ={
5846 {"behavior_test", 0, (test_callback_fn
)behavior_test
},
5847 {"MEMCACHED_BEHAVIOR_CORK", 0, (test_callback_fn
)MEMCACHED_BEHAVIOR_CORK_test
},
5848 {"MEMCACHED_BEHAVIOR_TCP_KEEPALIVE", 0, (test_callback_fn
)MEMCACHED_BEHAVIOR_TCP_KEEPALIVE_test
},
5849 {"MEMCACHED_BEHAVIOR_TCP_KEEPIDLE", 0, (test_callback_fn
)MEMCACHED_BEHAVIOR_TCP_KEEPIDLE_test
},
5853 test_st async_tests
[] ={
5854 {"add", 1, (test_callback_fn
)add_wrapper
},
5858 test_st string_tests
[] ={
5859 {"string static with null", 0, (test_callback_fn
)string_static_null
},
5860 {"string alloc with null", 0, (test_callback_fn
)string_alloc_null
},
5861 {"string alloc with 1K", 0, (test_callback_fn
)string_alloc_with_size
},
5862 {"string alloc with malloc failure", 0, (test_callback_fn
)string_alloc_with_size_toobig
},
5863 {"string append", 0, (test_callback_fn
)string_alloc_append
},
5864 {"string append failure (too big)", 0, (test_callback_fn
)string_alloc_append_toobig
},
5865 {0, 0, (test_callback_fn
)0}
5868 test_st result_tests
[] ={
5869 {"result static", 0, (test_callback_fn
)result_static
},
5870 {"result alloc", 0, (test_callback_fn
)result_alloc
},
5871 {0, 0, (test_callback_fn
)0}
5874 test_st version_1_2_3
[] ={
5875 {"append", 0, (test_callback_fn
)append_test
},
5876 {"prepend", 0, (test_callback_fn
)prepend_test
},
5877 {"cas", 0, (test_callback_fn
)cas_test
},
5878 {"cas2", 0, (test_callback_fn
)cas2_test
},
5879 {"append_binary", 0, (test_callback_fn
)append_binary_test
},
5880 {0, 0, (test_callback_fn
)0}
5883 test_st user_tests
[] ={
5884 {"user_supplied_bug1", 0, (test_callback_fn
)user_supplied_bug1
},
5885 {"user_supplied_bug2", 0, (test_callback_fn
)user_supplied_bug2
},
5886 {"user_supplied_bug3", 0, (test_callback_fn
)user_supplied_bug3
},
5887 {"user_supplied_bug4", 0, (test_callback_fn
)user_supplied_bug4
},
5888 {"user_supplied_bug5", 1, (test_callback_fn
)user_supplied_bug5
},
5889 {"user_supplied_bug6", 1, (test_callback_fn
)user_supplied_bug6
},
5890 {"user_supplied_bug7", 1, (test_callback_fn
)user_supplied_bug7
},
5891 {"user_supplied_bug8", 1, (test_callback_fn
)user_supplied_bug8
},
5892 {"user_supplied_bug9", 1, (test_callback_fn
)user_supplied_bug9
},
5893 {"user_supplied_bug10", 1, (test_callback_fn
)user_supplied_bug10
},
5894 {"user_supplied_bug11", 1, (test_callback_fn
)user_supplied_bug11
},
5895 {"user_supplied_bug12", 1, (test_callback_fn
)user_supplied_bug12
},
5896 {"user_supplied_bug13", 1, (test_callback_fn
)user_supplied_bug13
},
5897 {"user_supplied_bug14", 1, (test_callback_fn
)user_supplied_bug14
},
5898 {"user_supplied_bug15", 1, (test_callback_fn
)user_supplied_bug15
},
5899 {"user_supplied_bug16", 1, (test_callback_fn
)user_supplied_bug16
},
5902 ** It seems to be something weird with the character sets..
5903 ** value_fetch is unable to parse the value line (iscntrl "fails"), so I
5904 ** guess I need to find out how this is supposed to work.. Perhaps I need
5905 ** to run the test in a specific locale (I tried zh_CN.UTF-8 without success,
5906 ** so just disable the code for now...).
5908 {"user_supplied_bug17", 1, (test_callback_fn
)user_supplied_bug17
},
5910 {"user_supplied_bug18", 1, (test_callback_fn
)user_supplied_bug18
},
5911 {"user_supplied_bug19", 1, (test_callback_fn
)user_supplied_bug19
},
5912 {"user_supplied_bug20", 1, (test_callback_fn
)user_supplied_bug20
},
5913 {"user_supplied_bug21", 1, (test_callback_fn
)user_supplied_bug21
},
5914 {"wrong_failure_counter_test", 1, (test_callback_fn
)wrong_failure_counter_test
},
5915 {0, 0, (test_callback_fn
)0}
5918 test_st replication_tests
[]= {
5919 {"set", 1, (test_callback_fn
)replication_set_test
},
5920 {"get", 0, (test_callback_fn
)replication_get_test
},
5921 {"mget", 0, (test_callback_fn
)replication_mget_test
},
5922 {"delete", 0, (test_callback_fn
)replication_delete_test
},
5923 {"rand_mget", 0, (test_callback_fn
)replication_randomize_mget_test
},
5924 {0, 0, (test_callback_fn
)0}
5928 * The following test suite is used to verify that we don't introduce
5929 * regression bugs. If you want more information about the bug / test,
5930 * you should look in the bug report at
5931 * http://bugs.launchpad.net/libmemcached
5933 test_st regression_tests
[]= {
5934 {"lp:434484", 1, (test_callback_fn
)regression_bug_434484
},
5935 {"lp:434843", 1, (test_callback_fn
)regression_bug_434843
},
5936 {"lp:434843 buffered", 1, (test_callback_fn
)regression_bug_434843_buffered
},
5937 {"lp:421108", 1, (test_callback_fn
)regression_bug_421108
},
5938 {"lp:442914", 1, (test_callback_fn
)regression_bug_442914
},
5939 {"lp:447342", 1, (test_callback_fn
)regression_bug_447342
},
5940 {"lp:463297", 1, (test_callback_fn
)regression_bug_463297
},
5941 {"lp:490486", 1, (test_callback_fn
)regression_bug_490486
},
5942 {"lp:?", 1, (test_callback_fn
)regression_bug_
},
5943 {0, 0, (test_callback_fn
)0}
5946 test_st sasl_auth_tests
[]= {
5947 {"sasl_auth", 1, (test_callback_fn
)sasl_auth_test
},
5948 {0, 0, (test_callback_fn
)0}
5951 test_st ketama_compatibility
[]= {
5952 {"libmemcached", 1, (test_callback_fn
)ketama_compatibility_libmemcached
},
5953 {"spymemcached", 1, (test_callback_fn
)ketama_compatibility_spymemcached
},
5954 {0, 0, (test_callback_fn
)0}
5957 test_st generate_tests
[] ={
5958 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
5959 {"generate_data", 1, (test_callback_fn
)generate_data
},
5960 {"get_read", 0, (test_callback_fn
)get_read
},
5961 {"delete_generate", 0, (test_callback_fn
)delete_generate
},
5962 {"generate_buffer_data", 1, (test_callback_fn
)generate_buffer_data
},
5963 {"delete_buffer", 0, (test_callback_fn
)delete_buffer_generate
},
5964 {"generate_data", 1, (test_callback_fn
)generate_data
},
5965 {"mget_read", 0, (test_callback_fn
)mget_read
},
5966 {"mget_read_result", 0, (test_callback_fn
)mget_read_result
},
5967 {"mget_read_function", 0, (test_callback_fn
)mget_read_function
},
5968 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5969 {"generate_large_pairs", 1, (test_callback_fn
)generate_large_pairs
},
5970 {"generate_data", 1, (test_callback_fn
)generate_data
},
5971 {"generate_buffer_data", 1, (test_callback_fn
)generate_buffer_data
},
5972 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5973 {0, 0, (test_callback_fn
)0}
5976 test_st consistent_tests
[] ={
5977 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
5978 {"generate_data", 1, (test_callback_fn
)generate_data
},
5979 {"get_read", 0, (test_callback_fn
)get_read_count
},
5980 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5981 {0, 0, (test_callback_fn
)0}
5984 test_st consistent_weighted_tests
[] ={
5985 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
5986 {"generate_data", 1, (test_callback_fn
)generate_data_with_stats
},
5987 {"get_read", 0, (test_callback_fn
)get_read_count
},
5988 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5989 {0, 0, (test_callback_fn
)0}
5992 test_st hsieh_availability
[] ={
5993 {"hsieh_avaibility_test", 0, (test_callback_fn
)hsieh_avaibility_test
},
5994 {0, 0, (test_callback_fn
)0}
5998 test_st hash_sanity
[] ={
5999 {"hash sanity", 0, (test_callback_fn
)hash_sanity_test
},
6000 {0, 0, (test_callback_fn
)0}
6004 test_st ketama_auto_eject_hosts
[] ={
6005 {"auto_eject_hosts", 1, (test_callback_fn
)auto_eject_hosts
},
6006 {"output_ketama_weighted_keys", 1, (test_callback_fn
)output_ketama_weighted_keys
},
6007 {0, 0, (test_callback_fn
)0}
6010 test_st hash_tests
[] ={
6011 {"one_at_a_time_run", 0, (test_callback_fn
)one_at_a_time_run
},
6012 {"md5", 0, (test_callback_fn
)md5_run
},
6013 {"crc", 0, (test_callback_fn
)crc_run
},
6014 {"fnv1_64", 0, (test_callback_fn
)fnv1_64_run
},
6015 {"fnv1a_64", 0, (test_callback_fn
)fnv1a_64_run
},
6016 {"fnv1_32", 0, (test_callback_fn
)fnv1_32_run
},
6017 {"fnv1a_32", 0, (test_callback_fn
)fnv1a_32_run
},
6018 {"hsieh", 0, (test_callback_fn
)hsieh_run
},
6019 {"murmur", 0, (test_callback_fn
)murmur_run
},
6020 {"jenkis", 0, (test_callback_fn
)jenkins_run
},
6021 {"memcached_get_hashkit", 0, (test_callback_fn
)memcached_get_hashkit_test
},
6022 {0, 0, (test_callback_fn
)0}
6025 collection_st collection
[] ={
6027 {"hash_sanity", 0, 0, hash_sanity
},
6029 {"hsieh_availability", 0, 0, hsieh_availability
},
6030 {"block", 0, 0, tests
},
6031 {"binary", (test_callback_fn
)pre_binary
, 0, tests
},
6032 {"nonblock", (test_callback_fn
)pre_nonblock
, 0, tests
},
6033 {"nodelay", (test_callback_fn
)pre_nodelay
, 0, tests
},
6034 {"settimer", (test_callback_fn
)pre_settimer
, 0, tests
},
6035 {"md5", (test_callback_fn
)pre_md5
, 0, tests
},
6036 {"crc", (test_callback_fn
)pre_crc
, 0, tests
},
6037 {"hsieh", (test_callback_fn
)pre_hsieh
, 0, tests
},
6038 {"jenkins", (test_callback_fn
)pre_jenkins
, 0, tests
},
6039 {"fnv1_64", (test_callback_fn
)pre_hash_fnv1_64
, 0, tests
},
6040 {"fnv1a_64", (test_callback_fn
)pre_hash_fnv1a_64
, 0, tests
},
6041 {"fnv1_32", (test_callback_fn
)pre_hash_fnv1_32
, 0, tests
},
6042 {"fnv1a_32", (test_callback_fn
)pre_hash_fnv1a_32
, 0, tests
},
6043 {"ketama", (test_callback_fn
)pre_behavior_ketama
, 0, tests
},
6044 {"ketama_auto_eject_hosts", (test_callback_fn
)pre_behavior_ketama
, 0, ketama_auto_eject_hosts
},
6045 {"unix_socket", (test_callback_fn
)pre_unix_socket
, 0, tests
},
6046 {"unix_socket_nodelay", (test_callback_fn
)pre_nodelay
, 0, tests
},
6047 {"poll_timeout", (test_callback_fn
)poll_timeout
, 0, tests
},
6048 {"gets", (test_callback_fn
)enable_cas
, 0, tests
},
6049 {"consistent_crc", (test_callback_fn
)enable_consistent_crc
, 0, tests
},
6050 {"consistent_hsieh", (test_callback_fn
)enable_consistent_hsieh
, 0, tests
},
6051 #ifdef MEMCACHED_ENABLE_DEPRECATED
6052 {"deprecated_memory_allocators", (test_callback_fn
)deprecated_set_memory_alloc
, 0, tests
},
6054 {"memory_allocators", (test_callback_fn
)set_memory_alloc
, 0, tests
},
6055 {"prefix", (test_callback_fn
)set_prefix
, 0, tests
},
6056 {"sasl_auth", (test_callback_fn
)pre_sasl
, 0, sasl_auth_tests
},
6057 {"sasl", (test_callback_fn
)pre_sasl
, 0, tests
},
6058 {"version_1_2_3", (test_callback_fn
)check_for_1_2_3
, 0, version_1_2_3
},
6059 {"string", 0, 0, string_tests
},
6060 {"result", 0, 0, result_tests
},
6061 {"async", (test_callback_fn
)pre_nonblock
, 0, async_tests
},
6062 {"async_binary", (test_callback_fn
)pre_nonblock_binary
, 0, async_tests
},
6063 {"user", 0, 0, user_tests
},
6064 {"generate", 0, 0, generate_tests
},
6065 {"generate_hsieh", (test_callback_fn
)pre_hsieh
, 0, generate_tests
},
6066 {"generate_ketama", (test_callback_fn
)pre_behavior_ketama
, 0, generate_tests
},
6067 {"generate_hsieh_consistent", (test_callback_fn
)enable_consistent_hsieh
, 0, generate_tests
},
6068 {"generate_md5", (test_callback_fn
)pre_md5
, 0, generate_tests
},
6069 {"generate_murmur", (test_callback_fn
)pre_murmur
, 0, generate_tests
},
6070 {"generate_jenkins", (test_callback_fn
)pre_jenkins
, 0, generate_tests
},
6071 {"generate_nonblock", (test_callback_fn
)pre_nonblock
, 0, generate_tests
},
6073 {"generate_corked", (test_callback_fn
)pre_cork
, 0, generate_tests
},
6074 {"generate_corked_and_nonblock", (test_callback_fn
)pre_cork_and_nonblock
, 0, generate_tests
},
6075 {"consistent_not", 0, 0, consistent_tests
},
6076 {"consistent_ketama", (test_callback_fn
)pre_behavior_ketama
, 0, consistent_tests
},
6077 {"consistent_ketama_weighted", (test_callback_fn
)pre_behavior_ketama_weighted
, 0, consistent_weighted_tests
},
6078 {"ketama_compat", 0, 0, ketama_compatibility
},
6079 {"test_hashes", 0, 0, hash_tests
},
6080 {"replication", (test_callback_fn
)pre_replication
, 0, replication_tests
},
6081 {"replication_noblock", (test_callback_fn
)pre_replication_noblock
, 0, replication_tests
},
6082 {"regression", 0, 0, regression_tests
},
6083 {"behaviors", 0, 0, behavior_tests
},
6087 #define SERVERS_TO_CREATE 5
6089 #include "libmemcached_world.h"
6091 void get_world(world_st
*world
)
6093 world
->collections
= collection
;
6095 world
->create
= (test_callback_create_fn
)world_create
;
6096 world
->destroy
= (test_callback_fn
)world_destroy
;
6098 world
->test
.startup
= (test_callback_fn
)world_test_startup
;
6099 world
->test
.flush
= (test_callback_fn
)world_flush
;
6100 world
->test
.pre_run
= (test_callback_fn
)world_pre_run
;
6101 world
->test
.post_run
= (test_callback_fn
)world_post_run
;
6102 world
->test
.on_error
= (test_callback_error_fn
)world_on_error
;
6104 world
->collection
.startup
= (test_callback_fn
)world_container_startup
;
6105 world
->collection
.shutdown
= (test_callback_fn
)world_container_shutdown
;
6107 world
->runner
= &defualt_libmemcached_runner
;