1 /* libMemcached Functions Test
2 * Copyright (C) 2006-2009 Brian Aker
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
10 Sample test application.
13 #include "libmemcached/common.h"
20 #include <sys/types.h>
26 #include "clients/generator.h"
27 #include "clients/execute.h"
30 #define INT64_MAX LONG_MAX
33 #define INT32_MAX INT_MAX
39 #ifdef HAVE_LIBMEMCACHEDUTIL
41 #include "libmemcached/memcached_util.h"
44 #include "hash_results.h"
46 #define GLOBAL_COUNT 10000
47 #define GLOBAL2_COUNT 100
48 #define SERVERS_TO_CREATE 5
49 static uint32_t global_count
;
51 static pairs_st
*global_pairs
;
52 static const char *global_keys
[GLOBAL_COUNT
];
53 static size_t global_keys_length
[GLOBAL_COUNT
];
55 static test_return_t
init_test(memcached_st
*not_used
__attribute__((unused
)))
59 (void)memcached_create(&memc
);
60 memcached_free(&memc
);
65 static test_return_t
server_list_null_test(memcached_st
*ptr
__attribute__((unused
)))
67 memcached_server_st
*server_list
;
68 memcached_return_t rc
;
70 server_list
= memcached_server_list_append_with_weight(NULL
, NULL
, 0, 0, NULL
);
71 test_truth(server_list
== NULL
);
73 server_list
= memcached_server_list_append_with_weight(NULL
, "localhost", 0, 0, NULL
);
74 test_truth(server_list
== NULL
);
76 server_list
= memcached_server_list_append_with_weight(NULL
, NULL
, 0, 0, &rc
);
77 test_truth(server_list
== NULL
);
82 #define TEST_PORT_COUNT 7
83 uint32_t test_ports
[TEST_PORT_COUNT
];
85 static memcached_return_t
server_display_function(memcached_st
*ptr
__attribute__((unused
)), memcached_server_st
*server
, void *context
)
88 uint32_t bigger
= *((uint32_t *)(context
));
89 assert(bigger
<= server
->port
);
90 *((uint32_t *)(context
))= server
->port
;
92 return MEMCACHED_SUCCESS
;
95 static test_return_t
server_sort_test(memcached_st
*ptr
__attribute__((unused
)))
98 uint32_t bigger
= 0; /* Prime the value for the test_truth in server_display_function */
99 memcached_return_t rc
;
100 memcached_server_fn callbacks
[1];
101 memcached_st
*local_memc
;
103 local_memc
= memcached_create(NULL
);
104 test_truth(local_memc
);
105 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
107 for (x
= 0; x
< TEST_PORT_COUNT
; x
++)
109 test_ports
[x
]= (uint32_t)random() % 64000;
110 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
111 test_truth(memcached_server_count(local_memc
) == x
+ 1);
112 test_truth(memcached_servers_count(memcached_server_list(local_memc
)) == x
+1);
113 test_truth(rc
== MEMCACHED_SUCCESS
);
116 callbacks
[0]= server_display_function
;
117 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
120 memcached_free(local_memc
);
125 static test_return_t
server_sort2_test(memcached_st
*ptr
__attribute__((unused
)))
127 uint32_t bigger
= 0; /* Prime the value for the test_truth in server_display_function */
128 memcached_return_t rc
;
129 memcached_server_fn callbacks
[1];
130 memcached_st
*local_memc
;
131 memcached_server_instance_st
*instance
;
133 local_memc
= memcached_create(NULL
);
134 test_truth(local_memc
);
135 rc
= memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
136 test_truth(rc
== MEMCACHED_SUCCESS
);
138 rc
= memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43043, 0);
139 test_truth(rc
== MEMCACHED_SUCCESS
);
140 instance
= memcached_server_instance_fetch(local_memc
, 0);
141 test_truth(instance
->port
== 43043);
143 rc
= memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43042, 0);
144 test_truth(rc
== MEMCACHED_SUCCESS
);
146 instance
= memcached_server_instance_fetch(local_memc
, 0);
147 test_truth(instance
->port
== 43042);
149 instance
= memcached_server_instance_fetch(local_memc
, 1);
150 test_truth(instance
->port
== 43043);
152 callbacks
[0]= server_display_function
;
153 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
156 memcached_free(local_memc
);
161 static memcached_return_t
server_display_unsort_function(memcached_st
*ptr
__attribute__((unused
)), memcached_server_st
*server
, void *context
)
164 uint32_t x
= *((uint32_t *)(context
));
166 assert(test_ports
[x
] == server
->port
);
167 *((uint32_t *)(context
))= ++x
;
169 return MEMCACHED_SUCCESS
;
172 static test_return_t
server_unsort_test(memcached_st
*ptr
__attribute__((unused
)))
175 uint32_t counter
= 0; /* Prime the value for the test_truth in server_display_function */
176 uint32_t bigger
= 0; /* Prime the value for the test_truth in server_display_function */
177 memcached_return_t rc
;
178 memcached_server_fn callbacks
[1];
179 memcached_st
*local_memc
;
181 local_memc
= memcached_create(NULL
);
182 test_truth(local_memc
);
184 for (x
= 0; x
< TEST_PORT_COUNT
; x
++)
186 test_ports
[x
]= (uint32_t)(random() % 64000);
187 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
188 test_truth(memcached_server_count(local_memc
) == x
+1);
189 test_truth(memcached_servers_count(memcached_server_list(local_memc
)) == x
+1);
190 test_truth(rc
== MEMCACHED_SUCCESS
);
193 callbacks
[0]= server_display_unsort_function
;
194 memcached_server_cursor(local_memc
, callbacks
, (void *)&counter
, 1);
196 /* Now we sort old data! */
197 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
198 callbacks
[0]= server_display_function
;
199 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
202 memcached_free(local_memc
);
207 static test_return_t
allocation_test(memcached_st
*not_used
__attribute__((unused
)))
210 memc
= memcached_create(NULL
);
212 memcached_free(memc
);
217 static test_return_t
clone_test(memcached_st
*memc
)
221 memcached_st
*memc_clone
;
222 memc_clone
= memcached_clone(NULL
, NULL
);
223 test_truth(memc_clone
);
224 memcached_free(memc_clone
);
227 /* Can we init from null? */
229 memcached_st
*memc_clone
;
230 memc_clone
= memcached_clone(NULL
, memc
);
231 test_truth(memc_clone
);
233 test_truth(memc_clone
->call_free
== memc
->call_free
);
234 test_truth(memc_clone
->call_malloc
== memc
->call_malloc
);
235 test_truth(memc_clone
->call_realloc
== memc
->call_realloc
);
236 test_truth(memc_clone
->call_calloc
== memc
->call_calloc
);
237 test_truth(memc_clone
->connect_timeout
== memc
->connect_timeout
);
238 test_truth(memc_clone
->delete_trigger
== memc
->delete_trigger
);
239 test_truth(memc_clone
->distribution
== memc
->distribution
);
240 { // Test all of the flags
241 test_truth(memc_clone
->flags
.no_block
== memc
->flags
.no_block
);
242 test_truth(memc_clone
->flags
.tcp_nodelay
== memc
->flags
.tcp_nodelay
);
243 test_truth(memc_clone
->flags
.reuse_memory
== memc
->flags
.reuse_memory
);
244 test_truth(memc_clone
->flags
.use_cache_lookups
== memc
->flags
.use_cache_lookups
);
245 test_truth(memc_clone
->flags
.support_cas
== memc
->flags
.support_cas
);
246 test_truth(memc_clone
->flags
.buffer_requests
== memc
->flags
.buffer_requests
);
247 test_truth(memc_clone
->flags
.use_sort_hosts
== memc
->flags
.use_sort_hosts
);
248 test_truth(memc_clone
->flags
.verify_key
== memc
->flags
.verify_key
);
249 test_truth(memc_clone
->flags
.ketama_weighted
== memc
->flags
.ketama_weighted
);
250 test_truth(memc_clone
->flags
.binary_protocol
== memc
->flags
.binary_protocol
);
251 test_truth(memc_clone
->flags
.hash_with_prefix_key
== memc
->flags
.hash_with_prefix_key
);
252 test_truth(memc_clone
->flags
.no_reply
== memc
->flags
.no_reply
);
253 test_truth(memc_clone
->flags
.use_udp
== memc
->flags
.use_udp
);
254 test_truth(memc_clone
->flags
.auto_eject_hosts
== memc
->flags
.auto_eject_hosts
);
255 test_truth(memc_clone
->flags
.randomize_replica_read
== memc
->flags
.randomize_replica_read
);
257 test_truth(memc_clone
->get_key_failure
== memc
->get_key_failure
);
258 test_truth(memc_clone
->hash
== memc
->hash
);
259 test_truth(memc_clone
->distribution_hash
== memc
->distribution_hash
);
260 test_truth(memc_clone
->io_bytes_watermark
== memc
->io_bytes_watermark
);
261 test_truth(memc_clone
->io_msg_watermark
== memc
->io_msg_watermark
);
262 test_truth(memc_clone
->io_key_prefetch
== memc
->io_key_prefetch
);
263 test_truth(memc_clone
->on_cleanup
== memc
->on_cleanup
);
264 test_truth(memc_clone
->on_clone
== memc
->on_clone
);
265 test_truth(memc_clone
->poll_timeout
== memc
->poll_timeout
);
266 test_truth(memc_clone
->rcv_timeout
== memc
->rcv_timeout
);
267 test_truth(memc_clone
->recv_size
== memc
->recv_size
);
268 test_truth(memc_clone
->retry_timeout
== memc
->retry_timeout
);
269 test_truth(memc_clone
->send_size
== memc
->send_size
);
270 test_truth(memc_clone
->server_failure_limit
== memc
->server_failure_limit
);
271 test_truth(memc_clone
->snd_timeout
== memc
->snd_timeout
);
272 test_truth(memc_clone
->user_data
== memc
->user_data
);
274 memcached_free(memc_clone
);
277 /* Can we init from struct? */
279 memcached_st declared_clone
;
280 memcached_st
*memc_clone
;
281 memset(&declared_clone
, 0 , sizeof(memcached_st
));
282 memc_clone
= memcached_clone(&declared_clone
, NULL
);
283 test_truth(memc_clone
);
284 memcached_free(memc_clone
);
287 /* Can we init from struct? */
289 memcached_st declared_clone
;
290 memcached_st
*memc_clone
;
291 memset(&declared_clone
, 0 , sizeof(memcached_st
));
292 memc_clone
= memcached_clone(&declared_clone
, memc
);
293 test_truth(memc_clone
);
294 memcached_free(memc_clone
);
300 static test_return_t
userdata_test(memcached_st
*memc
)
303 test_truth(memcached_set_user_data(memc
, foo
) == NULL
);
304 test_truth(memcached_get_user_data(memc
) == foo
);
305 test_truth(memcached_set_user_data(memc
, NULL
) == foo
);
310 static test_return_t
connection_test(memcached_st
*memc
)
312 memcached_return_t rc
;
314 rc
= memcached_server_add_with_weight(memc
, "localhost", 0, 0);
315 test_truth(rc
== MEMCACHED_SUCCESS
);
320 static test_return_t
error_test(memcached_st
*memc
)
322 memcached_return_t rc
;
323 uint32_t values
[] = { 851992627U, 2337886783U, 3196981036U, 4001849190U,
324 982370485U, 1263635348U, 4242906218U, 3829656100U,
325 1891735253U, 334139633U, 2257084983U, 3088286104U,
326 13199785U, 2542027183U, 1097051614U, 199566778U,
327 2748246961U, 2465192557U, 1664094137U, 2405439045U,
328 1842224848U, 692413798U, 3479807801U, 919913813U,
329 4269430871U, 610793021U, 527273862U, 1437122909U,
330 2300930706U, 2943759320U, 674306647U, 2400528935U,
331 54481931U, 4186304426U, 1741088401U, 2979625118U,
332 4159057246U, 3425930182U, 2593724503U};
334 // You have updated the memcache_error messages but not updated docs/tests.
335 test_truth(MEMCACHED_MAXIMUM_RETURN
== 39);
336 for (rc
= MEMCACHED_SUCCESS
; rc
< MEMCACHED_MAXIMUM_RETURN
; rc
++)
339 const char *msg
= memcached_strerror(memc
, rc
);
340 hash_val
= memcached_generate_hash_value(msg
, strlen(msg
),
341 MEMCACHED_HASH_JENKINS
);
342 test_truth(values
[rc
] == hash_val
);
348 static test_return_t
set_test(memcached_st
*memc
)
350 memcached_return_t rc
;
351 const char *key
= "foo";
352 const char *value
= "when we sanitize";
354 rc
= memcached_set(memc
, key
, strlen(key
),
355 value
, strlen(value
),
356 (time_t)0, (uint32_t)0);
357 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
362 static test_return_t
append_test(memcached_st
*memc
)
364 memcached_return_t rc
;
365 const char *key
= "fig";
366 const char *in_value
= "we";
367 char *out_value
= NULL
;
371 rc
= memcached_flush(memc
, 0);
372 test_truth(rc
== MEMCACHED_SUCCESS
);
374 rc
= memcached_set(memc
, key
, strlen(key
),
375 in_value
, strlen(in_value
),
376 (time_t)0, (uint32_t)0);
377 test_truth(rc
== MEMCACHED_SUCCESS
);
379 rc
= memcached_append(memc
, key
, strlen(key
),
380 " the", strlen(" the"),
381 (time_t)0, (uint32_t)0);
382 test_truth(rc
== MEMCACHED_SUCCESS
);
384 rc
= memcached_append(memc
, key
, strlen(key
),
385 " people", strlen(" people"),
386 (time_t)0, (uint32_t)0);
387 test_truth(rc
== MEMCACHED_SUCCESS
);
389 out_value
= memcached_get(memc
, key
, strlen(key
),
390 &value_length
, &flags
, &rc
);
391 test_truth(!memcmp(out_value
, "we the people", strlen("we the people")));
392 test_truth(strlen("we the people") == value_length
);
393 test_truth(rc
== MEMCACHED_SUCCESS
);
399 static test_return_t
append_binary_test(memcached_st
*memc
)
401 memcached_return_t rc
;
402 const char *key
= "numbers";
403 unsigned int *store_ptr
;
404 unsigned int store_list
[] = { 23, 56, 499, 98, 32847, 0 };
410 rc
= memcached_flush(memc
, 0);
411 test_truth(rc
== MEMCACHED_SUCCESS
);
413 rc
= memcached_set(memc
,
416 (time_t)0, (uint32_t)0);
417 test_truth(rc
== MEMCACHED_SUCCESS
);
419 for (x
= 0; store_list
[x
] ; x
++)
421 rc
= memcached_append(memc
,
423 (char *)&store_list
[x
], sizeof(unsigned int),
424 (time_t)0, (uint32_t)0);
425 test_truth(rc
== MEMCACHED_SUCCESS
);
428 value
= memcached_get(memc
, key
, strlen(key
),
429 &value_length
, &flags
, &rc
);
430 test_truth((value_length
== (sizeof(unsigned int) * x
)));
431 test_truth(rc
== MEMCACHED_SUCCESS
);
433 store_ptr
= (unsigned int *)value
;
435 while ((size_t)store_ptr
< (size_t)(value
+ value_length
))
437 test_truth(*store_ptr
== store_list
[x
++]);
445 static test_return_t
cas2_test(memcached_st
*memc
)
447 memcached_return_t rc
;
448 const char *keys
[]= {"fudge", "son", "food"};
449 size_t key_length
[]= {5, 3, 4};
450 const char *value
= "we the people";
451 size_t value_length
= strlen("we the people");
453 memcached_result_st results_obj
;
454 memcached_result_st
*results
;
457 rc
= memcached_flush(memc
, 0);
458 test_truth(rc
== MEMCACHED_SUCCESS
);
460 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
462 for (x
= 0; x
< 3; x
++)
464 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
465 keys
[x
], key_length
[x
],
466 (time_t)50, (uint32_t)9);
467 test_truth(rc
== MEMCACHED_SUCCESS
);
470 rc
= memcached_mget(memc
, keys
, key_length
, 3);
472 results
= memcached_result_create(memc
, &results_obj
);
474 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
476 test_truth(results
->cas
);
477 test_truth(rc
== MEMCACHED_SUCCESS
);
478 test_truth(memcached_result_cas(results
));
480 test_truth(!memcmp(value
, "we the people", strlen("we the people")));
481 test_truth(strlen("we the people") == value_length
);
482 test_truth(rc
== MEMCACHED_SUCCESS
);
484 memcached_result_free(&results_obj
);
489 static test_return_t
cas_test(memcached_st
*memc
)
491 memcached_return_t rc
;
492 const char *key
= "fun";
493 size_t key_length
= strlen(key
);
494 const char *value
= "we the people";
495 const char* keys
[2] = { key
, NULL
};
496 size_t keylengths
[2] = { strlen(key
), 0 };
497 size_t value_length
= strlen(value
);
498 const char *value2
= "change the value";
499 size_t value2_length
= strlen(value2
);
501 memcached_result_st results_obj
;
502 memcached_result_st
*results
;
505 rc
= memcached_flush(memc
, 0);
506 test_truth(rc
== MEMCACHED_SUCCESS
);
508 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
510 rc
= memcached_set(memc
, key
, strlen(key
),
511 value
, strlen(value
),
512 (time_t)0, (uint32_t)0);
513 test_truth(rc
== MEMCACHED_SUCCESS
);
515 rc
= memcached_mget(memc
, keys
, keylengths
, 1);
517 results
= memcached_result_create(memc
, &results_obj
);
519 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
521 test_truth(rc
== MEMCACHED_SUCCESS
);
522 test_truth(memcached_result_cas(results
));
523 test_truth(!memcmp(value
, memcached_result_value(results
), value_length
));
524 test_truth(strlen(memcached_result_value(results
)) == value_length
);
525 test_truth(rc
== MEMCACHED_SUCCESS
);
526 uint64_t cas
= memcached_result_cas(results
);
529 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
530 test_truth(rc
== MEMCACHED_END
);
531 test_truth(results
== NULL
);
534 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
535 test_truth(rc
== MEMCACHED_SUCCESS
);
538 * The item will have a new cas value, so try to set it again with the old
539 * value. This should fail!
541 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
542 test_truth(rc
== MEMCACHED_DATA_EXISTS
);
544 memcached_result_free(&results_obj
);
549 static test_return_t
prepend_test(memcached_st
*memc
)
551 memcached_return_t rc
;
552 const char *key
= "fig";
553 const char *value
= "people";
554 char *out_value
= NULL
;
558 rc
= memcached_flush(memc
, 0);
559 test_truth(rc
== MEMCACHED_SUCCESS
);
561 rc
= memcached_set(memc
, key
, strlen(key
),
562 value
, strlen(value
),
563 (time_t)0, (uint32_t)0);
564 test_truth(rc
== MEMCACHED_SUCCESS
);
566 rc
= memcached_prepend(memc
, key
, strlen(key
),
567 "the ", strlen("the "),
568 (time_t)0, (uint32_t)0);
569 test_truth(rc
== MEMCACHED_SUCCESS
);
571 rc
= memcached_prepend(memc
, key
, strlen(key
),
572 "we ", strlen("we "),
573 (time_t)0, (uint32_t)0);
574 test_truth(rc
== MEMCACHED_SUCCESS
);
576 out_value
= memcached_get(memc
, key
, strlen(key
),
577 &value_length
, &flags
, &rc
);
578 test_truth(!memcmp(out_value
, "we the people", strlen("we the people")));
579 test_truth(strlen("we the people") == value_length
);
580 test_truth(rc
== MEMCACHED_SUCCESS
);
587 Set the value, then quit to make sure it is flushed.
588 Come back in and test that add fails.
590 static test_return_t
add_test(memcached_st
*memc
)
592 memcached_return_t rc
;
593 const char *key
= "foo";
594 const char *value
= "when we sanitize";
595 unsigned long long setting_value
;
597 setting_value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
599 rc
= memcached_set(memc
, key
, strlen(key
),
600 value
, strlen(value
),
601 (time_t)0, (uint32_t)0);
602 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
603 memcached_quit(memc
);
604 rc
= memcached_add(memc
, key
, strlen(key
),
605 value
, strlen(value
),
606 (time_t)0, (uint32_t)0);
608 /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */
611 test_truth(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_STORED
);
615 test_truth(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_DATA_EXISTS
);
622 ** There was a problem of leaking filedescriptors in the initial release
623 ** of MacOSX 10.5. This test case triggers the problem. On some Solaris
624 ** systems it seems that the kernel is slow on reclaiming the resources
625 ** because the connects starts to time out (the test doesn't do much
626 ** anyway, so just loop 10 iterations)
628 static test_return_t
add_wrapper(memcached_st
*memc
)
631 unsigned int max
= 10000;
639 for (x
= 0; x
< max
; x
++)
645 static test_return_t
replace_test(memcached_st
*memc
)
647 memcached_return_t rc
;
648 const char *key
= "foo";
649 const char *value
= "when we sanitize";
650 const char *original
= "first we insert some data";
652 rc
= memcached_set(memc
, key
, strlen(key
),
653 original
, strlen(original
),
654 (time_t)0, (uint32_t)0);
655 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
657 rc
= memcached_replace(memc
, key
, strlen(key
),
658 value
, strlen(value
),
659 (time_t)0, (uint32_t)0);
660 test_truth(rc
== MEMCACHED_SUCCESS
);
665 static test_return_t
delete_test(memcached_st
*memc
)
667 memcached_return_t rc
;
668 const char *key
= "foo";
669 const char *value
= "when we sanitize";
671 rc
= memcached_set(memc
, key
, strlen(key
),
672 value
, strlen(value
),
673 (time_t)0, (uint32_t)0);
674 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
676 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
677 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
682 static test_return_t
flush_test(memcached_st
*memc
)
684 memcached_return_t rc
;
686 rc
= memcached_flush(memc
, 0);
687 test_truth(rc
== MEMCACHED_SUCCESS
);
692 static memcached_return_t
server_function(memcached_st
*ptr
__attribute__((unused
)),
693 memcached_server_st
*server
__attribute__((unused
)),
694 void *context
__attribute__((unused
)))
698 return MEMCACHED_SUCCESS
;
701 static test_return_t
memcached_server_cursor_test(memcached_st
*memc
)
704 strcpy(context
, "foo bad");
705 memcached_server_fn callbacks
[1];
707 callbacks
[0]= server_function
;
708 memcached_server_cursor(memc
, callbacks
, context
, 1);
712 static test_return_t
bad_key_test(memcached_st
*memc
)
714 memcached_return_t rc
;
715 const char *key
= "foo bad";
717 size_t string_length
;
719 memcached_st
*memc_clone
;
721 size_t max_keylen
= 0xffff;
723 // Just skip if we are in binary mode.
724 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
))
727 memc_clone
= memcached_clone(NULL
, memc
);
728 test_truth(memc_clone
);
730 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
731 test_truth(rc
== MEMCACHED_SUCCESS
);
733 /* All keys are valid in the binary protocol (except for length) */
734 if (memcached_behavior_get(memc_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 0)
736 string
= memcached_get(memc_clone
, key
, strlen(key
),
737 &string_length
, &flags
, &rc
);
738 test_truth(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
739 test_truth(string_length
== 0);
743 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
744 test_truth(rc
== MEMCACHED_SUCCESS
);
745 string
= memcached_get(memc_clone
, key
, strlen(key
),
746 &string_length
, &flags
, &rc
);
747 test_truth(rc
== MEMCACHED_NOTFOUND
);
748 test_truth(string_length
== 0);
751 /* Test multi key for bad keys */
752 const char *keys
[] = { "GoodKey", "Bad Key", "NotMine" };
753 size_t key_lengths
[] = { 7, 7, 7 };
755 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
756 test_truth(rc
== MEMCACHED_SUCCESS
);
758 rc
= memcached_mget(memc_clone
, keys
, key_lengths
, 3);
759 test_truth(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
761 rc
= memcached_mget_by_key(memc_clone
, "foo daddy", 9, keys
, key_lengths
, 1);
762 test_truth(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
766 /* The following test should be moved to the end of this function when the
767 memcached server is updated to allow max size length of the keys in the
770 rc
= memcached_callback_set(memc_clone
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
771 test_truth(rc
== MEMCACHED_SUCCESS
);
773 char *longkey
= malloc(max_keylen
+ 1);
776 memset(longkey
, 'a', max_keylen
+ 1);
777 string
= memcached_get(memc_clone
, longkey
, max_keylen
,
778 &string_length
, &flags
, &rc
);
779 test_truth(rc
== MEMCACHED_NOTFOUND
);
780 test_truth(string_length
== 0);
783 string
= memcached_get(memc_clone
, longkey
, max_keylen
+ 1,
784 &string_length
, &flags
, &rc
);
785 test_truth(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
786 test_truth(string_length
== 0);
793 /* Make sure zero length keys are marked as bad */
795 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
796 test_truth(rc
== MEMCACHED_SUCCESS
);
797 string
= memcached_get(memc_clone
, key
, 0,
798 &string_length
, &flags
, &rc
);
799 test_truth(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
800 test_truth(string_length
== 0);
803 memcached_free(memc_clone
);
808 #define READ_THROUGH_VALUE "set for me"
809 static memcached_return_t
read_through_trigger(memcached_st
*memc
__attribute__((unused
)),
810 char *key
__attribute__((unused
)),
811 size_t key_length
__attribute__((unused
)),
812 memcached_result_st
*result
)
815 return memcached_result_set_value(result
, READ_THROUGH_VALUE
, strlen(READ_THROUGH_VALUE
));
818 static test_return_t
read_through(memcached_st
*memc
)
820 memcached_return_t rc
;
821 const char *key
= "foo";
823 size_t string_length
;
825 memcached_trigger_key_fn cb
= (memcached_trigger_key_fn
)read_through_trigger
;
827 string
= memcached_get(memc
, key
, strlen(key
),
828 &string_length
, &flags
, &rc
);
830 test_truth(rc
== MEMCACHED_NOTFOUND
);
831 test_false(string_length
);
834 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_GET_FAILURE
,
836 test_truth(rc
== MEMCACHED_SUCCESS
);
838 string
= memcached_get(memc
, key
, strlen(key
),
839 &string_length
, &flags
, &rc
);
841 test_truth(rc
== MEMCACHED_SUCCESS
);
842 test_truth(string_length
== strlen(READ_THROUGH_VALUE
));
843 test_strcmp(READ_THROUGH_VALUE
, string
);
846 string
= memcached_get(memc
, key
, strlen(key
),
847 &string_length
, &flags
, &rc
);
849 test_truth(rc
== MEMCACHED_SUCCESS
);
850 test_truth(string_length
== strlen(READ_THROUGH_VALUE
));
851 test_truth(!strcmp(READ_THROUGH_VALUE
, string
));
857 static memcached_return_t
delete_trigger(memcached_st
*ptr
__attribute__((unused
)),
859 size_t key_length
__attribute__((unused
)))
863 return MEMCACHED_SUCCESS
;
866 static test_return_t
delete_through(memcached_st
*memc
)
868 memcached_trigger_delete_key_fn callback
;
869 memcached_return_t rc
;
871 callback
= (memcached_trigger_delete_key_fn
)delete_trigger
;
873 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_DELETE_TRIGGER
, *(void**)&callback
);
874 test_truth(rc
== MEMCACHED_SUCCESS
);
879 static test_return_t
get_test(memcached_st
*memc
)
881 memcached_return_t rc
;
882 const char *key
= "foo";
884 size_t string_length
;
887 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
888 test_truth(rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_NOTFOUND
);
890 string
= memcached_get(memc
, key
, strlen(key
),
891 &string_length
, &flags
, &rc
);
893 test_truth(rc
== MEMCACHED_NOTFOUND
);
894 test_false(string_length
);
900 static test_return_t
get_test2(memcached_st
*memc
)
902 memcached_return_t rc
;
903 const char *key
= "foo";
904 const char *value
= "when we sanitize";
906 size_t string_length
;
909 rc
= memcached_set(memc
, key
, strlen(key
),
910 value
, strlen(value
),
911 (time_t)0, (uint32_t)0);
912 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
914 string
= memcached_get(memc
, key
, strlen(key
),
915 &string_length
, &flags
, &rc
);
918 test_truth(rc
== MEMCACHED_SUCCESS
);
919 test_truth(string_length
== strlen(value
));
920 test_truth(!memcmp(string
, value
, string_length
));
927 static test_return_t
set_test2(memcached_st
*memc
)
929 memcached_return_t rc
;
930 const char *key
= "foo";
931 const char *value
= "train in the brain";
932 size_t value_length
= strlen(value
);
935 for (x
= 0; x
< 10; x
++)
937 rc
= memcached_set(memc
, key
, strlen(key
),
939 (time_t)0, (uint32_t)0);
940 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
946 static test_return_t
set_test3(memcached_st
*memc
)
948 memcached_return_t rc
;
950 size_t value_length
= 8191;
953 value
= (char*)malloc(value_length
);
956 for (x
= 0; x
< value_length
; x
++)
957 value
[x
] = (char) (x
% 127);
959 /* The dump test relies on there being at least 32 items in memcached */
960 for (x
= 0; x
< 32; x
++)
964 sprintf(key
, "foo%u", x
);
966 rc
= memcached_set(memc
, key
, strlen(key
),
968 (time_t)0, (uint32_t)0);
969 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
977 static test_return_t
get_test3(memcached_st
*memc
)
979 memcached_return_t rc
;
980 const char *key
= "foo";
982 size_t value_length
= 8191;
984 size_t string_length
;
988 value
= (char*)malloc(value_length
);
991 for (x
= 0; x
< value_length
; x
++)
992 value
[x
] = (char) (x
% 127);
994 rc
= memcached_set(memc
, key
, strlen(key
),
996 (time_t)0, (uint32_t)0);
997 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
999 string
= memcached_get(memc
, key
, strlen(key
),
1000 &string_length
, &flags
, &rc
);
1002 test_truth(rc
== MEMCACHED_SUCCESS
);
1004 test_truth(string_length
== value_length
);
1005 test_truth(!memcmp(string
, value
, string_length
));
1010 return TEST_SUCCESS
;
1013 static test_return_t
get_test4(memcached_st
*memc
)
1015 memcached_return_t rc
;
1016 const char *key
= "foo";
1018 size_t value_length
= 8191;
1020 size_t string_length
;
1024 value
= (char*)malloc(value_length
);
1027 for (x
= 0; x
< value_length
; x
++)
1028 value
[x
] = (char) (x
% 127);
1030 rc
= memcached_set(memc
, key
, strlen(key
),
1031 value
, value_length
,
1032 (time_t)0, (uint32_t)0);
1033 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1035 for (x
= 0; x
< 10; x
++)
1037 string
= memcached_get(memc
, key
, strlen(key
),
1038 &string_length
, &flags
, &rc
);
1040 test_truth(rc
== MEMCACHED_SUCCESS
);
1042 test_truth(string_length
== value_length
);
1043 test_truth(!memcmp(string
, value
, string_length
));
1049 return TEST_SUCCESS
;
1053 * This test verifies that memcached_read_one_response doesn't try to
1054 * dereference a NIL-pointer if you issue a multi-get and don't read out all
1055 * responses before you execute a storage command.
1057 static test_return_t
get_test5(memcached_st
*memc
)
1060 ** Request the same key twice, to ensure that we hash to the same server
1061 ** (so that we have multiple response values queued up) ;-)
1063 const char *keys
[]= { "key", "key" };
1064 size_t lengths
[]= { 3, 3 };
1068 memcached_return_t rc
= memcached_set(memc
, keys
[0], lengths
[0],
1069 keys
[0], lengths
[0], 0, 0);
1070 test_truth(rc
== MEMCACHED_SUCCESS
);
1071 rc
= memcached_mget(memc
, keys
, lengths
, 2);
1073 memcached_result_st results_obj
;
1074 memcached_result_st
*results
;
1075 results
=memcached_result_create(memc
, &results_obj
);
1076 test_truth(results
);
1077 results
=memcached_fetch_result(memc
, &results_obj
, &rc
);
1078 test_truth(results
);
1079 memcached_result_free(&results_obj
);
1081 /* Don't read out the second result, but issue a set instead.. */
1082 rc
= memcached_set(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0);
1083 test_truth(rc
== MEMCACHED_SUCCESS
);
1085 char *val
= memcached_get_by_key(memc
, keys
[0], lengths
[0], "yek", 3,
1086 &rlen
, &flags
, &rc
);
1087 test_truth(val
== NULL
);
1088 test_truth(rc
== MEMCACHED_NOTFOUND
);
1089 val
= memcached_get(memc
, keys
[0], lengths
[0], &rlen
, &flags
, &rc
);
1090 test_truth(val
!= NULL
);
1091 test_truth(rc
== MEMCACHED_SUCCESS
);
1094 return TEST_SUCCESS
;
1097 static test_return_t
mget_end(memcached_st
*memc
)
1099 const char *keys
[]= { "foo", "foo2" };
1100 size_t lengths
[]= { 3, 4 };
1101 const char *values
[]= { "fjord", "41" };
1103 memcached_return_t rc
;
1106 for (int i
= 0; i
< 2; i
++)
1108 rc
= memcached_set(memc
, keys
[i
], lengths
[i
], values
[i
], strlen(values
[i
]),
1109 (time_t)0, (uint32_t)0);
1110 test_truth(rc
== MEMCACHED_SUCCESS
);
1114 size_t string_length
;
1117 // retrieve both via mget
1118 rc
= memcached_mget(memc
, keys
, lengths
, 2);
1119 test_truth(rc
== MEMCACHED_SUCCESS
);
1121 char key
[MEMCACHED_MAX_KEY
];
1124 // this should get both
1125 for (int i
= 0; i
< 2; i
++)
1127 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
,
1129 test_truth(rc
== MEMCACHED_SUCCESS
);
1131 if (key_length
== 4)
1133 test_truth(string_length
== strlen(values
[val
]));
1134 test_truth(strncmp(values
[val
], string
, string_length
) == 0);
1138 // this should indicate end
1139 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1140 test_truth(rc
== MEMCACHED_END
);
1143 rc
= memcached_mget(memc
, keys
, lengths
, 1);
1144 test_truth(rc
== MEMCACHED_SUCCESS
);
1146 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1147 test_truth(key_length
== lengths
[0]);
1148 test_truth(strncmp(keys
[0], key
, key_length
) == 0);
1149 test_truth(string_length
== strlen(values
[0]));
1150 test_truth(strncmp(values
[0], string
, string_length
) == 0);
1151 test_truth(rc
== MEMCACHED_SUCCESS
);
1154 // this should indicate end
1155 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1156 test_truth(rc
== MEMCACHED_END
);
1158 return TEST_SUCCESS
;
1161 /* Do not copy the style of this code, I just access hosts to testthis function */
1162 static test_return_t
stats_servername_test(memcached_st
*memc
)
1164 memcached_return_t rc
;
1165 memcached_stat_st memc_stat
;
1166 memcached_server_instance_st
*instance
=
1167 memcached_server_instance_fetch(memc
, 0);
1169 rc
= memcached_stat_servername(&memc_stat
, NULL
,
1173 return TEST_SUCCESS
;
1176 static test_return_t
increment_test(memcached_st
*memc
)
1178 uint64_t new_number
;
1179 memcached_return_t rc
;
1180 const char *key
= "number";
1181 const char *value
= "0";
1183 rc
= memcached_set(memc
, key
, strlen(key
),
1184 value
, strlen(value
),
1185 (time_t)0, (uint32_t)0);
1186 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1188 rc
= memcached_increment(memc
, key
, strlen(key
),
1190 test_truth(rc
== MEMCACHED_SUCCESS
);
1191 test_truth(new_number
== 1);
1193 rc
= memcached_increment(memc
, key
, strlen(key
),
1195 test_truth(rc
== MEMCACHED_SUCCESS
);
1196 test_truth(new_number
== 2);
1198 return TEST_SUCCESS
;
1201 static test_return_t
increment_with_initial_test(memcached_st
*memc
)
1203 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1205 uint64_t new_number
;
1206 memcached_return_t rc
;
1207 const char *key
= "number";
1208 uint64_t initial
= 0;
1210 rc
= memcached_increment_with_initial(memc
, key
, strlen(key
),
1211 1, initial
, 0, &new_number
);
1212 test_truth(rc
== MEMCACHED_SUCCESS
);
1213 test_truth(new_number
== initial
);
1215 rc
= memcached_increment_with_initial(memc
, key
, strlen(key
),
1216 1, initial
, 0, &new_number
);
1217 test_truth(rc
== MEMCACHED_SUCCESS
);
1218 test_truth(new_number
== (initial
+ 1));
1220 return TEST_SUCCESS
;
1223 static test_return_t
decrement_test(memcached_st
*memc
)
1225 uint64_t new_number
;
1226 memcached_return_t rc
;
1227 const char *key
= "number";
1228 const char *value
= "3";
1230 rc
= memcached_set(memc
, key
, strlen(key
),
1231 value
, strlen(value
),
1232 (time_t)0, (uint32_t)0);
1233 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1235 rc
= memcached_decrement(memc
, key
, strlen(key
),
1237 test_truth(rc
== MEMCACHED_SUCCESS
);
1238 test_truth(new_number
== 2);
1240 rc
= memcached_decrement(memc
, key
, strlen(key
),
1242 test_truth(rc
== MEMCACHED_SUCCESS
);
1243 test_truth(new_number
== 1);
1245 return TEST_SUCCESS
;
1248 static test_return_t
decrement_with_initial_test(memcached_st
*memc
)
1250 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1252 uint64_t new_number
;
1253 memcached_return_t rc
;
1254 const char *key
= "number";
1255 uint64_t initial
= 3;
1257 rc
= memcached_decrement_with_initial(memc
, key
, strlen(key
),
1258 1, initial
, 0, &new_number
);
1259 test_truth(rc
== MEMCACHED_SUCCESS
);
1260 test_truth(new_number
== initial
);
1262 rc
= memcached_decrement_with_initial(memc
, key
, strlen(key
),
1263 1, initial
, 0, &new_number
);
1264 test_truth(rc
== MEMCACHED_SUCCESS
);
1265 test_truth(new_number
== (initial
- 1));
1267 return TEST_SUCCESS
;
1270 static test_return_t
increment_by_key_test(memcached_st
*memc
)
1272 uint64_t new_number
;
1273 memcached_return_t rc
;
1274 const char *master_key
= "foo";
1275 const char *key
= "number";
1276 const char *value
= "0";
1278 rc
= memcached_set_by_key(memc
, master_key
, strlen(master_key
),
1280 value
, strlen(value
),
1281 (time_t)0, (uint32_t)0);
1282 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1284 rc
= memcached_increment_by_key(memc
, master_key
, strlen(master_key
), key
, strlen(key
),
1286 test_truth(rc
== MEMCACHED_SUCCESS
);
1287 test_truth(new_number
== 1);
1289 rc
= memcached_increment_by_key(memc
, master_key
, strlen(master_key
), key
, strlen(key
),
1291 test_truth(rc
== MEMCACHED_SUCCESS
);
1292 test_truth(new_number
== 2);
1294 return TEST_SUCCESS
;
1297 static test_return_t
increment_with_initial_by_key_test(memcached_st
*memc
)
1299 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1301 uint64_t new_number
;
1302 memcached_return_t rc
;
1303 const char *master_key
= "foo";
1304 const char *key
= "number";
1305 uint64_t initial
= 0;
1307 rc
= memcached_increment_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1309 1, initial
, 0, &new_number
);
1310 test_truth(rc
== MEMCACHED_SUCCESS
);
1311 test_truth(new_number
== initial
);
1313 rc
= memcached_increment_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1315 1, initial
, 0, &new_number
);
1316 test_truth(rc
== MEMCACHED_SUCCESS
);
1317 test_truth(new_number
== (initial
+ 1));
1319 return TEST_SUCCESS
;
1322 static test_return_t
decrement_by_key_test(memcached_st
*memc
)
1324 uint64_t new_number
;
1325 memcached_return_t rc
;
1326 const char *master_key
= "foo";
1327 const char *key
= "number";
1328 const char *value
= "3";
1330 rc
= memcached_set_by_key(memc
, master_key
, strlen(master_key
),
1332 value
, strlen(value
),
1333 (time_t)0, (uint32_t)0);
1334 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1336 rc
= memcached_decrement_by_key(memc
, master_key
, strlen(master_key
),
1339 test_truth(rc
== MEMCACHED_SUCCESS
);
1340 test_truth(new_number
== 2);
1342 rc
= memcached_decrement_by_key(memc
, master_key
, strlen(master_key
),
1345 test_truth(rc
== MEMCACHED_SUCCESS
);
1346 test_truth(new_number
== 1);
1348 return TEST_SUCCESS
;
1351 static test_return_t
decrement_with_initial_by_key_test(memcached_st
*memc
)
1353 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1355 uint64_t new_number
;
1356 memcached_return_t rc
;
1357 const char *master_key
= "foo";
1358 const char *key
= "number";
1359 uint64_t initial
= 3;
1361 rc
= memcached_decrement_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1363 1, initial
, 0, &new_number
);
1364 test_truth(rc
== MEMCACHED_SUCCESS
);
1365 test_truth(new_number
== initial
);
1367 rc
= memcached_decrement_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1369 1, initial
, 0, &new_number
);
1370 test_truth(rc
== MEMCACHED_SUCCESS
);
1371 test_truth(new_number
== (initial
- 1));
1373 return TEST_SUCCESS
;
1376 static test_return_t
quit_test(memcached_st
*memc
)
1378 memcached_return_t rc
;
1379 const char *key
= "fudge";
1380 const char *value
= "sanford and sun";
1382 rc
= memcached_set(memc
, key
, strlen(key
),
1383 value
, strlen(value
),
1384 (time_t)10, (uint32_t)3);
1385 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1386 memcached_quit(memc
);
1388 rc
= memcached_set(memc
, key
, strlen(key
),
1389 value
, strlen(value
),
1390 (time_t)50, (uint32_t)9);
1391 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1393 return TEST_SUCCESS
;
1396 static test_return_t
mget_result_test(memcached_st
*memc
)
1398 memcached_return_t rc
;
1399 const char *keys
[]= {"fudge", "son", "food"};
1400 size_t key_length
[]= {5, 3, 4};
1403 memcached_result_st results_obj
;
1404 memcached_result_st
*results
;
1406 results
= memcached_result_create(memc
, &results_obj
);
1407 test_truth(results
);
1408 test_truth(&results_obj
== results
);
1410 /* We need to empty the server before continueing test */
1411 rc
= memcached_flush(memc
, 0);
1412 test_truth(rc
== MEMCACHED_SUCCESS
);
1414 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1415 test_truth(rc
== MEMCACHED_SUCCESS
);
1417 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1419 test_truth(results
);
1422 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1423 test_truth(!results
);
1424 test_truth(rc
== MEMCACHED_END
);
1426 for (x
= 0; x
< 3; x
++)
1428 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1429 keys
[x
], key_length
[x
],
1430 (time_t)50, (uint32_t)9);
1431 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1434 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1435 test_truth(rc
== MEMCACHED_SUCCESS
);
1437 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1439 test_truth(results
);
1440 test_truth(&results_obj
== results
);
1441 test_truth(rc
== MEMCACHED_SUCCESS
);
1442 test_truth(memcached_result_key_length(results
) == memcached_result_length(results
));
1443 test_truth(!memcmp(memcached_result_key_value(results
),
1444 memcached_result_value(results
),
1445 memcached_result_length(results
)));
1448 memcached_result_free(&results_obj
);
1450 return TEST_SUCCESS
;
1453 static test_return_t
mget_result_alloc_test(memcached_st
*memc
)
1455 memcached_return_t rc
;
1456 const char *keys
[]= {"fudge", "son", "food"};
1457 size_t key_length
[]= {5, 3, 4};
1460 memcached_result_st
*results
;
1462 /* We need to empty the server before continueing test */
1463 rc
= memcached_flush(memc
, 0);
1464 test_truth(rc
== MEMCACHED_SUCCESS
);
1466 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1467 test_truth(rc
== MEMCACHED_SUCCESS
);
1469 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)) != NULL
)
1471 test_truth(results
);
1473 test_truth(!results
);
1474 test_truth(rc
== MEMCACHED_END
);
1476 for (x
= 0; x
< 3; x
++)
1478 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1479 keys
[x
], key_length
[x
],
1480 (time_t)50, (uint32_t)9);
1481 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1484 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1485 test_truth(rc
== MEMCACHED_SUCCESS
);
1488 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1490 test_truth(results
);
1491 test_truth(rc
== MEMCACHED_SUCCESS
);
1492 test_truth(memcached_result_key_length(results
) == memcached_result_length(results
));
1493 test_truth(!memcmp(memcached_result_key_value(results
),
1494 memcached_result_value(results
),
1495 memcached_result_length(results
)));
1496 memcached_result_free(results
);
1500 return TEST_SUCCESS
;
1503 /* Count the results */
1504 static memcached_return_t
callback_counter(memcached_st
*ptr
__attribute__((unused
)),
1505 memcached_result_st
*result
__attribute__((unused
)),
1508 unsigned int *counter
= (unsigned int *)context
;
1510 *counter
= *counter
+ 1;
1512 return MEMCACHED_SUCCESS
;
1515 static test_return_t
mget_result_function(memcached_st
*memc
)
1517 memcached_return_t rc
;
1518 const char *keys
[]= {"fudge", "son", "food"};
1519 size_t key_length
[]= {5, 3, 4};
1521 unsigned int counter
;
1522 memcached_execute_fn callbacks
[1];
1524 /* We need to empty the server before continueing test */
1525 rc
= memcached_flush(memc
, 0);
1526 for (x
= 0; x
< 3; x
++)
1528 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1529 keys
[x
], key_length
[x
],
1530 (time_t)50, (uint32_t)9);
1531 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1534 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1535 test_truth(rc
== MEMCACHED_SUCCESS
);
1537 callbacks
[0]= &callback_counter
;
1539 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
1541 test_truth(counter
== 3);
1543 return TEST_SUCCESS
;
1546 static test_return_t
mget_test(memcached_st
*memc
)
1548 memcached_return_t rc
;
1549 const char *keys
[]= {"fudge", "son", "food"};
1550 size_t key_length
[]= {5, 3, 4};
1554 char return_key
[MEMCACHED_MAX_KEY
];
1555 size_t return_key_length
;
1557 size_t return_value_length
;
1559 /* We need to empty the server before continueing test */
1560 rc
= memcached_flush(memc
, 0);
1561 test_truth(rc
== MEMCACHED_SUCCESS
);
1563 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1564 test_truth(rc
== MEMCACHED_SUCCESS
);
1566 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1567 &return_value_length
, &flags
, &rc
)) != NULL
)
1569 test_truth(return_value
);
1571 test_truth(!return_value
);
1572 test_truth(return_value_length
== 0);
1573 test_truth(rc
== MEMCACHED_END
);
1575 for (x
= 0; x
< 3; x
++)
1577 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1578 keys
[x
], key_length
[x
],
1579 (time_t)50, (uint32_t)9);
1580 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1583 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1584 test_truth(rc
== MEMCACHED_SUCCESS
);
1587 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1588 &return_value_length
, &flags
, &rc
)))
1590 test_truth(return_value
);
1591 test_truth(rc
== MEMCACHED_SUCCESS
);
1592 test_truth(return_key_length
== return_value_length
);
1593 test_truth(!memcmp(return_value
, return_key
, return_value_length
));
1598 return TEST_SUCCESS
;
1601 static test_return_t
mget_execute(memcached_st
*memc
)
1604 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1608 * I only want to hit _one_ server so I know the number of requests I'm
1609 * sending in the pipeline.
1611 uint32_t number_of_hosts
= memc
->number_of_hosts
;
1612 memc
->number_of_hosts
= 1;
1614 int max_keys
= binary
? 20480 : 1;
1617 char **keys
= calloc((size_t)max_keys
, sizeof(char*));
1618 size_t *key_length
=calloc((size_t)max_keys
, sizeof(size_t));
1620 /* First add all of the items.. */
1621 char blob
[1024] = {0};
1622 memcached_return_t rc
;
1623 for (int x
= 0; x
< max_keys
; ++x
)
1626 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%u", x
);
1628 test_truth(keys
[x
] != NULL
);
1629 rc
= memcached_add(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
1630 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1633 /* Try to get all of them with a large multiget */
1634 unsigned int counter
= 0;
1635 memcached_execute_fn callbacks
[1]= { [0]= &callback_counter
};
1636 rc
= memcached_mget_execute(memc
, (const char**)keys
, key_length
,
1637 (size_t)max_keys
, callbacks
, &counter
, 1);
1641 test_truth(rc
== MEMCACHED_SUCCESS
);
1643 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
1644 test_truth(rc
== MEMCACHED_END
);
1646 /* Verify that we got all of the items */
1647 test_truth(counter
== (unsigned int)max_keys
);
1651 test_truth(rc
== MEMCACHED_NOT_SUPPORTED
);
1652 test_truth(counter
== 0);
1655 /* Release all allocated resources */
1656 for (int x
= 0; x
< max_keys
; ++x
)
1661 memc
->number_of_hosts
= number_of_hosts
;
1662 return TEST_SUCCESS
;
1665 static test_return_t
get_stats_keys(memcached_st
*memc
)
1669 memcached_stat_st memc_stat
;
1670 memcached_return_t rc
;
1672 stat_list
= memcached_stat_get_keys(memc
, &memc_stat
, &rc
);
1673 test_truth(rc
== MEMCACHED_SUCCESS
);
1674 for (ptr
= stat_list
; *ptr
; ptr
++)
1679 return TEST_SUCCESS
;
1682 static test_return_t
version_string_test(memcached_st
*memc
__attribute__((unused
)))
1684 const char *version_string
;
1686 version_string
= memcached_lib_version();
1688 test_truth(!strcmp(version_string
, LIBMEMCACHED_VERSION_STRING
));
1690 return TEST_SUCCESS
;
1693 static test_return_t
get_stats(memcached_st
*memc
)
1698 memcached_return_t rc
;
1699 memcached_stat_st
*memc_stat
;
1701 memc_stat
= memcached_stat(memc
, NULL
, &rc
);
1702 test_truth(rc
== MEMCACHED_SUCCESS
);
1704 test_truth(rc
== MEMCACHED_SUCCESS
);
1705 test_truth(memc_stat
);
1707 for (x
= 0; x
< memcached_server_count(memc
); x
++)
1709 stat_list
= memcached_stat_get_keys(memc
, memc_stat
+x
, &rc
);
1710 test_truth(rc
== MEMCACHED_SUCCESS
);
1711 for (ptr
= stat_list
; *ptr
; ptr
++);
1716 memcached_stat_free(NULL
, memc_stat
);
1718 return TEST_SUCCESS
;
1721 static test_return_t
add_host_test(memcached_st
*memc
)
1724 memcached_server_st
*servers
;
1725 memcached_return_t rc
;
1726 char servername
[]= "0.example.com";
1728 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
1729 test_truth(servers
);
1730 test_truth(1 == memcached_server_list_count(servers
));
1732 for (x
= 2; x
< 20; x
++)
1734 char buffer
[SMALL_STRING_LEN
];
1736 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
1737 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
1739 test_truth(rc
== MEMCACHED_SUCCESS
);
1740 test_truth(x
== memcached_server_list_count(servers
));
1743 rc
= memcached_server_push(memc
, servers
);
1744 test_truth(rc
== MEMCACHED_SUCCESS
);
1745 rc
= memcached_server_push(memc
, servers
);
1746 test_truth(rc
== MEMCACHED_SUCCESS
);
1748 memcached_server_list_free(servers
);
1750 return TEST_SUCCESS
;
1753 static memcached_return_t
clone_test_callback(memcached_st
*parent
__attribute__((unused
)), memcached_st
*memc_clone
__attribute__((unused
)))
1755 return MEMCACHED_SUCCESS
;
1758 static memcached_return_t
cleanup_test_callback(memcached_st
*ptr
__attribute__((unused
)))
1760 return MEMCACHED_SUCCESS
;
1763 static test_return_t
callback_test(memcached_st
*memc
)
1765 /* Test User Data */
1769 memcached_return_t rc
;
1771 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_USER_DATA
, &x
);
1772 test_truth(rc
== MEMCACHED_SUCCESS
);
1773 test_ptr
= (int *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_USER_DATA
, &rc
);
1774 test_truth(*test_ptr
== x
);
1777 /* Test Clone Callback */
1779 memcached_clone_fn clone_cb
= (memcached_clone_fn
)clone_test_callback
;
1780 void *clone_cb_ptr
= *(void **)&clone_cb
;
1781 void *temp_function
= NULL
;
1782 memcached_return_t rc
;
1784 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
,
1786 test_truth(rc
== MEMCACHED_SUCCESS
);
1787 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1788 test_truth(temp_function
== clone_cb_ptr
);
1791 /* Test Cleanup Callback */
1793 memcached_cleanup_fn cleanup_cb
=
1794 (memcached_cleanup_fn
)cleanup_test_callback
;
1795 void *cleanup_cb_ptr
= *(void **)&cleanup_cb
;
1796 void *temp_function
= NULL
;
1797 memcached_return_t rc
;
1799 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
,
1801 test_truth(rc
== MEMCACHED_SUCCESS
);
1802 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1803 test_truth(temp_function
== cleanup_cb_ptr
);
1806 return TEST_SUCCESS
;
1809 /* We don't test the behavior itself, we test the switches */
1810 static test_return_t
behavior_test(memcached_st
*memc
)
1815 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1816 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1817 test_truth(value
== 1);
1819 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1820 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1821 test_truth(value
== 1);
1823 set
= MEMCACHED_HASH_MD5
;
1824 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1825 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1826 test_truth(value
== MEMCACHED_HASH_MD5
);
1830 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1831 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1832 test_truth(value
== 0);
1834 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1835 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1836 test_truth(value
== 0);
1838 set
= MEMCACHED_HASH_DEFAULT
;
1839 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1840 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1841 test_truth(value
== MEMCACHED_HASH_DEFAULT
);
1843 set
= MEMCACHED_HASH_CRC
;
1844 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1845 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1846 test_truth(value
== MEMCACHED_HASH_CRC
);
1848 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1849 test_truth(value
> 0);
1851 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1852 test_truth(value
> 0);
1854 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
);
1855 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, value
+ 1);
1856 test_truth((value
+ 1) == memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
));
1858 return TEST_SUCCESS
;
1861 static test_return_t
fetch_all_results(memcached_st
*memc
)
1863 memcached_return_t rc
= MEMCACHED_SUCCESS
;
1864 char return_key
[MEMCACHED_MAX_KEY
];
1865 size_t return_key_length
;
1867 size_t return_value_length
;
1870 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1871 &return_value_length
, &flags
, &rc
)))
1873 test_truth(return_value
);
1874 test_truth(rc
== MEMCACHED_SUCCESS
);
1878 return ((rc
== MEMCACHED_END
) || (rc
== MEMCACHED_SUCCESS
)) ? TEST_SUCCESS
: TEST_FAILURE
;
1881 /* Test case provided by Cal Haldenbrand */
1882 static test_return_t
user_supplied_bug1(memcached_st
*memc
)
1884 unsigned int setter
= 1;
1887 unsigned long long total
= 0;
1890 char randomstuff
[6 * 1024];
1891 memcached_return_t rc
;
1893 memset(randomstuff
, 0, 6 * 1024);
1895 /* We just keep looking at the same values over and over */
1898 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1899 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1903 for (x
= 0 ; total
< 20 * 1024576 ; x
++ )
1907 size
= (uint32_t)(rand() % ( 5 * 1024 ) ) + 400;
1908 memset(randomstuff
, 0, 6 * 1024);
1909 test_truth(size
< 6 * 1024); /* Being safe here */
1911 for (j
= 0 ; j
< size
;j
++)
1912 randomstuff
[j
] = (signed char) ((rand() % 26) + 97);
1915 sprintf(key
, "%d", x
);
1916 rc
= memcached_set(memc
, key
, strlen(key
),
1917 randomstuff
, strlen(randomstuff
), 10, 0);
1918 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1919 /* If we fail, lets try again */
1920 if (rc
!= MEMCACHED_SUCCESS
&& rc
!= MEMCACHED_BUFFERED
)
1921 rc
= memcached_set(memc
, key
, strlen(key
),
1922 randomstuff
, strlen(randomstuff
), 10, 0);
1923 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1926 return TEST_SUCCESS
;
1929 /* Test case provided by Cal Haldenbrand */
1930 static test_return_t
user_supplied_bug2(memcached_st
*memc
)
1933 unsigned int setter
;
1935 unsigned long long total
;
1938 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1939 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1941 setter
= 20 * 1024576;
1942 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1943 setter
= 20 * 1024576;
1944 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1945 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1946 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1948 for (x
= 0, errors
= 0, total
= 0 ; total
< 20 * 1024576 ; x
++)
1951 for (x
= 0, errors
= 0, total
= 0 ; total
< 24576 ; x
++)
1953 memcached_return_t rc
= MEMCACHED_SUCCESS
;
1954 char buffer
[SMALL_STRING_LEN
];
1959 memset(buffer
, 0, SMALL_STRING_LEN
);
1961 snprintf(buffer
, SMALL_STRING_LEN
, "%u", x
);
1962 getval
= memcached_get(memc
, buffer
, strlen(buffer
),
1963 &val_len
, &flags
, &rc
);
1964 if (rc
!= MEMCACHED_SUCCESS
)
1966 if (rc
== MEMCACHED_NOTFOUND
)
1980 return TEST_SUCCESS
;
1983 /* Do a large mget() over all the keys we think exist */
1984 #define KEY_COUNT 3000 // * 1024576
1985 static test_return_t
user_supplied_bug3(memcached_st
*memc
)
1987 memcached_return_t rc
;
1988 unsigned int setter
;
1991 size_t key_lengths
[KEY_COUNT
];
1994 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1995 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1997 setter
= 20 * 1024576;
1998 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1999 setter
= 20 * 1024576;
2000 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
2001 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
2002 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
2005 keys
= calloc(KEY_COUNT
, sizeof(char *));
2007 for (x
= 0; x
< KEY_COUNT
; x
++)
2011 snprintf(buffer
, 30, "%u", x
);
2012 keys
[x
]= strdup(buffer
);
2013 key_lengths
[x
]= strlen(keys
[x
]);
2016 rc
= memcached_mget(memc
, (const char **)keys
, key_lengths
, KEY_COUNT
);
2017 test_truth(rc
== MEMCACHED_SUCCESS
);
2019 test_truth(fetch_all_results(memc
) == TEST_SUCCESS
);
2021 for (x
= 0; x
< KEY_COUNT
; x
++)
2025 return TEST_SUCCESS
;
2028 /* Make sure we behave properly if server list has no values */
2029 static test_return_t
user_supplied_bug4(memcached_st
*memc
)
2031 memcached_return_t rc
;
2032 const char *keys
[]= {"fudge", "son", "food"};
2033 size_t key_length
[]= {5, 3, 4};
2036 char return_key
[MEMCACHED_MAX_KEY
];
2037 size_t return_key_length
;
2039 size_t return_value_length
;
2041 /* Here we free everything before running a bunch of mget tests */
2042 memcached_servers_reset(memc
);
2045 /* We need to empty the server before continueing test */
2046 rc
= memcached_flush(memc
, 0);
2047 test_truth(rc
== MEMCACHED_NO_SERVERS
);
2049 rc
= memcached_mget(memc
, keys
, key_length
, 3);
2050 test_truth(rc
== MEMCACHED_NO_SERVERS
);
2052 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2053 &return_value_length
, &flags
, &rc
)) != NULL
)
2055 test_truth(return_value
);
2057 test_truth(!return_value
);
2058 test_truth(return_value_length
== 0);
2059 test_truth(rc
== MEMCACHED_NO_SERVERS
);
2061 for (x
= 0; x
< 3; x
++)
2063 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2064 keys
[x
], key_length
[x
],
2065 (time_t)50, (uint32_t)9);
2066 test_truth(rc
== MEMCACHED_NO_SERVERS
);
2069 rc
= memcached_mget(memc
, keys
, key_length
, 3);
2070 test_truth(rc
== MEMCACHED_NO_SERVERS
);
2073 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2074 &return_value_length
, &flags
, &rc
)))
2076 test_truth(return_value
);
2077 test_truth(rc
== MEMCACHED_SUCCESS
);
2078 test_truth(return_key_length
== return_value_length
);
2079 test_truth(!memcmp(return_value
, return_key
, return_value_length
));
2084 return TEST_SUCCESS
;
2087 #define VALUE_SIZE_BUG5 1048064
2088 static test_return_t
user_supplied_bug5(memcached_st
*memc
)
2090 memcached_return_t rc
;
2091 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
2092 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
2093 char return_key
[MEMCACHED_MAX_KEY
];
2094 size_t return_key_length
;
2096 size_t value_length
;
2100 char insert_data
[VALUE_SIZE_BUG5
];
2102 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2103 insert_data
[x
]= (signed char)rand();
2105 memcached_flush(memc
, 0);
2106 value
= memcached_get(memc
, keys
[0], key_length
[0],
2107 &value_length
, &flags
, &rc
);
2108 test_truth(value
== NULL
);
2109 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2112 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2113 &value_length
, &flags
, &rc
)))
2115 test_truth(count
== 0);
2117 for (x
= 0; x
< 4; x
++)
2119 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2120 insert_data
, VALUE_SIZE_BUG5
,
2121 (time_t)0, (uint32_t)0);
2122 test_truth(rc
== MEMCACHED_SUCCESS
);
2125 for (x
= 0; x
< 10; x
++)
2127 value
= memcached_get(memc
, keys
[0], key_length
[0],
2128 &value_length
, &flags
, &rc
);
2132 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2134 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2135 &value_length
, &flags
, &rc
)))
2140 test_truth(count
== 4);
2143 return TEST_SUCCESS
;
2146 static test_return_t
user_supplied_bug6(memcached_st
*memc
)
2148 memcached_return_t rc
;
2149 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
2150 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
2151 char return_key
[MEMCACHED_MAX_KEY
];
2152 size_t return_key_length
;
2154 size_t value_length
;
2158 char insert_data
[VALUE_SIZE_BUG5
];
2160 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2161 insert_data
[x
]= (signed char)rand();
2163 memcached_flush(memc
, 0);
2164 value
= memcached_get(memc
, keys
[0], key_length
[0],
2165 &value_length
, &flags
, &rc
);
2166 test_truth(value
== NULL
);
2167 test_truth(rc
== MEMCACHED_NOTFOUND
);
2168 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2169 test_truth(rc
== MEMCACHED_SUCCESS
);
2172 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2173 &value_length
, &flags
, &rc
)))
2175 test_truth(count
== 0);
2176 test_truth(rc
== MEMCACHED_END
);
2178 for (x
= 0; x
< 4; x
++)
2180 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2181 insert_data
, VALUE_SIZE_BUG5
,
2182 (time_t)0, (uint32_t)0);
2183 test_truth(rc
== MEMCACHED_SUCCESS
);
2186 for (x
= 0; x
< 2; x
++)
2188 value
= memcached_get(memc
, keys
[0], key_length
[0],
2189 &value_length
, &flags
, &rc
);
2193 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2194 test_truth(rc
== MEMCACHED_SUCCESS
);
2196 /* We test for purge of partial complete fetches */
2197 for (count
= 3; count
; count
--)
2199 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2200 &value_length
, &flags
, &rc
);
2201 test_truth(rc
== MEMCACHED_SUCCESS
);
2202 test_truth(!(memcmp(value
, insert_data
, value_length
)));
2203 test_truth(value_length
);
2208 return TEST_SUCCESS
;
2211 static test_return_t
user_supplied_bug8(memcached_st
*memc
__attribute__((unused
)))
2213 memcached_return_t rc
;
2215 memcached_st
*memc_clone
;
2217 memcached_server_st
*servers
;
2218 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";
2220 servers
= memcached_servers_parse(server_list
);
2221 test_truth(servers
);
2223 mine
= memcached_create(NULL
);
2224 rc
= memcached_server_push(mine
, servers
);
2225 test_truth(rc
== MEMCACHED_SUCCESS
);
2226 memcached_server_list_free(servers
);
2229 memc_clone
= memcached_clone(NULL
, mine
);
2231 memcached_quit(mine
);
2232 memcached_quit(memc_clone
);
2235 memcached_free(mine
);
2236 memcached_free(memc_clone
);
2238 return TEST_SUCCESS
;
2241 /* Test flag store/retrieve */
2242 static test_return_t
user_supplied_bug7(memcached_st
*memc
)
2244 memcached_return_t rc
;
2245 const char *keys
= "036790384900";
2246 size_t key_length
= strlen(keys
);
2247 char return_key
[MEMCACHED_MAX_KEY
];
2248 size_t return_key_length
;
2250 size_t value_length
;
2253 char insert_data
[VALUE_SIZE_BUG5
];
2255 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2256 insert_data
[x
]= (signed char)rand();
2258 memcached_flush(memc
, 0);
2261 rc
= memcached_set(memc
, keys
, key_length
,
2262 insert_data
, VALUE_SIZE_BUG5
,
2264 test_truth(rc
== MEMCACHED_SUCCESS
);
2267 value
= memcached_get(memc
, keys
, key_length
,
2268 &value_length
, &flags
, &rc
);
2269 test_truth(flags
== 245);
2273 rc
= memcached_mget(memc
, &keys
, &key_length
, 1);
2276 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2277 &value_length
, &flags
, &rc
);
2278 test_truth(flags
== 245);
2283 return TEST_SUCCESS
;
2286 static test_return_t
user_supplied_bug9(memcached_st
*memc
)
2288 memcached_return_t rc
;
2289 const char *keys
[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
2290 size_t key_length
[3];
2295 char return_key
[MEMCACHED_MAX_KEY
];
2296 size_t return_key_length
;
2298 size_t return_value_length
;
2301 key_length
[0]= strlen("UDATA:edevil@sapo.pt");
2302 key_length
[1]= strlen("fudge&*@#");
2303 key_length
[2]= strlen("for^#@&$not");
2306 for (x
= 0; x
< 3; x
++)
2308 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2309 keys
[x
], key_length
[x
],
2310 (time_t)50, (uint32_t)9);
2311 test_truth(rc
== MEMCACHED_SUCCESS
);
2314 rc
= memcached_mget(memc
, keys
, key_length
, 3);
2315 test_truth(rc
== MEMCACHED_SUCCESS
);
2317 /* We need to empty the server before continueing test */
2318 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2319 &return_value_length
, &flags
, &rc
)) != NULL
)
2321 test_truth(return_value
);
2325 test_truth(count
== 3);
2327 return TEST_SUCCESS
;
2330 /* We are testing with aggressive timeout to get failures */
2331 static test_return_t
user_supplied_bug10(memcached_st
*memc
)
2333 const char *key
= "foo";
2335 size_t value_length
= 512;
2338 memcached_return_t rc
;
2339 unsigned int set
= 1;
2340 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2343 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2344 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2346 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
,
2349 value
= (char*)malloc(value_length
* sizeof(char));
2351 for (x
= 0; x
< value_length
; x
++)
2352 value
[x
]= (char) (x
% 127);
2354 for (x
= 1; x
<= 100000; ++x
)
2356 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2358 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_WRITE_FAILURE
||
2359 rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_TIMEOUT
);
2361 if (rc
== MEMCACHED_WRITE_FAILURE
|| rc
== MEMCACHED_TIMEOUT
)
2366 memcached_free(mclone
);
2368 return TEST_SUCCESS
;
2372 We are looking failures in the async protocol
2374 static test_return_t
user_supplied_bug11(memcached_st
*memc
)
2376 const char *key
= "foo";
2378 size_t value_length
= 512;
2381 memcached_return_t rc
;
2382 unsigned int set
= 1;
2384 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2386 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2387 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2389 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
,
2392 timeout
= (int32_t)memcached_behavior_get(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
2394 test_truth(timeout
== -1);
2396 value
= (char*)malloc(value_length
* sizeof(char));
2398 for (x
= 0; x
< value_length
; x
++)
2399 value
[x
]= (char) (x
% 127);
2401 for (x
= 1; x
<= 100000; ++x
)
2403 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2407 memcached_free(mclone
);
2409 return TEST_SUCCESS
;
2413 Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
2415 static test_return_t
user_supplied_bug12(memcached_st
*memc
)
2417 memcached_return_t rc
;
2419 size_t value_length
;
2421 uint64_t number_value
;
2423 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2424 &value_length
, &flags
, &rc
);
2425 test_truth(value
== NULL
);
2426 test_truth(rc
== MEMCACHED_NOTFOUND
);
2428 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2431 test_truth(value
== NULL
);
2432 /* The binary protocol will set the key if it doesn't exist */
2433 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1)
2435 test_truth(rc
== MEMCACHED_SUCCESS
);
2439 test_truth(rc
== MEMCACHED_NOTFOUND
);
2442 rc
= memcached_set(memc
, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
2444 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2445 &value_length
, &flags
, &rc
);
2447 test_truth(rc
== MEMCACHED_SUCCESS
);
2450 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2452 test_truth(number_value
== 2);
2453 test_truth(rc
== MEMCACHED_SUCCESS
);
2455 return TEST_SUCCESS
;
2459 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2460 set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
2462 static test_return_t
user_supplied_bug13(memcached_st
*memc
)
2464 char key
[] = "key34567890";
2466 memcached_return_t rc
;
2467 size_t overflowSize
;
2469 char commandFirst
[]= "set key34567890 0 0 ";
2470 char commandLast
[] = " \r\n"; /* first line of command sent to server */
2471 size_t commandLength
;
2474 commandLength
= strlen(commandFirst
) + strlen(commandLast
) + 4; /* 4 is number of characters in size, probably 8196 */
2476 overflowSize
= MEMCACHED_MAX_BUFFER
- commandLength
;
2478 for (testSize
= overflowSize
- 1; testSize
< overflowSize
+ 1; testSize
++)
2480 overflow
= malloc(testSize
);
2481 test_truth(overflow
!= NULL
);
2483 memset(overflow
, 'x', testSize
);
2484 rc
= memcached_set(memc
, key
, strlen(key
),
2485 overflow
, testSize
, 0, 0);
2486 test_truth(rc
== MEMCACHED_SUCCESS
);
2490 return TEST_SUCCESS
;
2495 Test values of many different sizes
2496 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2497 set key34567890 0 0 8169 \r\n
2498 is sent followed by buffer of size 8169, followed by 8169
2500 static test_return_t
user_supplied_bug14(memcached_st
*memc
)
2503 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2504 memcached_return_t rc
;
2505 const char *key
= "foo";
2507 size_t value_length
= 18000;
2509 size_t string_length
;
2512 size_t current_length
;
2514 value
= (char*)malloc(value_length
);
2517 for (x
= 0; x
< value_length
; x
++)
2518 value
[x
] = (char) (x
% 127);
2520 for (current_length
= 0; current_length
< value_length
; current_length
++)
2522 rc
= memcached_set(memc
, key
, strlen(key
),
2523 value
, current_length
,
2524 (time_t)0, (uint32_t)0);
2525 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
2527 string
= memcached_get(memc
, key
, strlen(key
),
2528 &string_length
, &flags
, &rc
);
2530 test_truth(rc
== MEMCACHED_SUCCESS
);
2531 test_truth(string_length
== current_length
);
2532 test_truth(!memcmp(string
, value
, string_length
));
2539 return TEST_SUCCESS
;
2543 Look for zero length value problems
2545 static test_return_t
user_supplied_bug15(memcached_st
*memc
)
2548 memcached_return_t rc
;
2549 const char *key
= "mykey";
2554 for (x
= 0; x
< 2; x
++)
2556 rc
= memcached_set(memc
, key
, strlen(key
),
2558 (time_t)0, (uint32_t)0);
2560 test_truth(rc
== MEMCACHED_SUCCESS
);
2562 value
= memcached_get(memc
, key
, strlen(key
),
2563 &length
, &flags
, &rc
);
2565 test_truth(rc
== MEMCACHED_SUCCESS
);
2566 test_truth(value
== NULL
);
2567 test_truth(length
== 0);
2568 test_truth(flags
== 0);
2570 value
= memcached_get(memc
, key
, strlen(key
),
2571 &length
, &flags
, &rc
);
2573 test_truth(rc
== MEMCACHED_SUCCESS
);
2574 test_truth(value
== NULL
);
2575 test_truth(length
== 0);
2576 test_truth(flags
== 0);
2579 return TEST_SUCCESS
;
2582 /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
2583 static test_return_t
user_supplied_bug16(memcached_st
*memc
)
2585 memcached_return_t rc
;
2586 const char *key
= "mykey";
2591 rc
= memcached_set(memc
, key
, strlen(key
),
2593 (time_t)0, UINT32_MAX
);
2595 test_truth(rc
== MEMCACHED_SUCCESS
);
2597 value
= memcached_get(memc
, key
, strlen(key
),
2598 &length
, &flags
, &rc
);
2600 test_truth(rc
== MEMCACHED_SUCCESS
);
2601 test_truth(value
== NULL
);
2602 test_truth(length
== 0);
2603 test_truth(flags
== UINT32_MAX
);
2605 return TEST_SUCCESS
;
2609 /* Check the validity of chinese key*/
2610 static test_return_t
user_supplied_bug17(memcached_st
*memc
)
2612 memcached_return_t rc
;
2613 const char *key
= "豆瓣";
2614 const char *value
="我们在炎热抑郁的夏天无法停止豆瓣";
2619 rc
= memcached_set(memc
, key
, strlen(key
),
2620 value
, strlen(value
),
2623 test_truth(rc
== MEMCACHED_SUCCESS
);
2625 value2
= memcached_get(memc
, key
, strlen(key
),
2626 &length
, &flags
, &rc
);
2628 test_truth(length
==strlen(value
));
2629 test_truth(rc
== MEMCACHED_SUCCESS
);
2630 test_truth(memcmp(value
, value2
, length
)==0);
2633 return TEST_SUCCESS
;
2641 static test_return_t
user_supplied_bug19(memcached_st
*memc
)
2644 memcached_server_st
*s
;
2645 memcached_return_t res
;
2649 m
= memcached_create(NULL
);
2650 memcached_server_add_with_weight(m
, "localhost", 11311, 100);
2651 memcached_server_add_with_weight(m
, "localhost", 11312, 100);
2653 s
= memcached_server_by_key(m
, "a", 1, &res
);
2654 memcached_server_free(s
);
2658 return TEST_SUCCESS
;
2661 /* CAS test from Andei */
2662 static test_return_t
user_supplied_bug20(memcached_st
*memc
)
2664 memcached_return_t status
;
2665 memcached_result_st
*result
, result_obj
;
2666 const char *key
= "abc";
2667 size_t key_len
= strlen("abc");
2668 const char *value
= "foobar";
2669 size_t value_len
= strlen(value
);
2671 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
2673 status
= memcached_set(memc
, key
, key_len
, value
, value_len
, (time_t)0, (uint32_t)0);
2674 test_truth(status
== MEMCACHED_SUCCESS
);
2676 status
= memcached_mget(memc
, &key
, &key_len
, 1);
2677 test_truth(status
== MEMCACHED_SUCCESS
);
2679 result
= memcached_result_create(memc
, &result_obj
);
2682 memcached_result_create(memc
, &result_obj
);
2683 result
= memcached_fetch_result(memc
, &result_obj
, &status
);
2686 test_truth(status
== MEMCACHED_SUCCESS
);
2688 memcached_result_free(result
);
2690 return TEST_SUCCESS
;
2693 #include "ketama_test_cases.h"
2694 static test_return_t
user_supplied_bug18(memcached_st
*trash
)
2696 memcached_return_t rc
;
2699 memcached_server_st
*server_pool
;
2704 memc
= memcached_create(NULL
);
2707 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2708 test_truth(rc
== MEMCACHED_SUCCESS
);
2710 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2711 test_truth(value
== 1);
2713 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2714 test_truth(rc
== MEMCACHED_SUCCESS
);
2716 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2717 test_truth(value
== MEMCACHED_HASH_MD5
);
2719 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");
2720 memcached_server_push(memc
, server_pool
);
2722 /* verify that the server list was parsed okay. */
2723 test_truth(memcached_server_count(memc
) == 8);
2724 test_truth(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
2725 test_truth(server_pool
[0].port
== 11211);
2726 test_truth(server_pool
[0].weight
== 600);
2727 test_truth(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
2728 test_truth(server_pool
[2].port
== 11211);
2729 test_truth(server_pool
[2].weight
== 200);
2730 test_truth(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
2731 test_truth(server_pool
[7].port
== 11211);
2732 test_truth(server_pool
[7].weight
== 100);
2734 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
2735 * us test the boundary wraparound.
2737 test_truth(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
2739 /* verify the standard ketama set. */
2740 for (x
= 0; x
< 99; x
++)
2742 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
2743 memcached_server_instance_st
*instance
=
2744 memcached_server_instance_fetch(memc
, server_idx
);
2745 char *hostname
= instance
->hostname
;
2746 test_strcmp(hostname
, ketama_test_cases
[x
].server
);
2749 memcached_server_list_free(server_pool
);
2750 memcached_free(memc
);
2752 return TEST_SUCCESS
;
2755 /* Large mget() of missing keys with binary proto
2757 * If many binary quiet commands (such as getq's in an mget) fill the output
2758 * buffer and the server chooses not to respond, memcached_flush hangs. See
2759 * http://lists.tangent.org/pipermail/libmemcached/2009-August/000918.html
2762 /* sighandler_t function that always asserts false */
2763 static void fail(int unused
__attribute__((unused
)))
2769 static test_return_t
_user_supplied_bug21(memcached_st
* memc
, size_t key_count
)
2771 memcached_return_t rc
;
2774 size_t* key_lengths
;
2775 void (*oldalarm
)(int);
2776 memcached_st
*memc_clone
;
2778 memc_clone
= memcached_clone(NULL
, memc
);
2779 test_truth(memc_clone
);
2781 /* only binproto uses getq for mget */
2782 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
2784 /* empty the cache to ensure misses (hence non-responses) */
2785 rc
= memcached_flush(memc_clone
, 0);
2786 test_truth(rc
== MEMCACHED_SUCCESS
);
2788 key_lengths
= calloc(key_count
, sizeof(size_t));
2789 keys
= calloc(key_count
, sizeof(char *));
2791 for (x
= 0; x
< key_count
; x
++)
2795 snprintf(buffer
, 30, "%u", x
);
2796 keys
[x
]= strdup(buffer
);
2797 key_lengths
[x
]= strlen(keys
[x
]);
2800 oldalarm
= signal(SIGALRM
, fail
);
2803 rc
= memcached_mget(memc_clone
, (const char **)keys
, key_lengths
, key_count
);
2804 test_truth(rc
== MEMCACHED_SUCCESS
);
2807 signal(SIGALRM
, oldalarm
);
2809 test_truth(fetch_all_results(memc
) == TEST_SUCCESS
);
2811 for (x
= 0; x
< key_count
; x
++)
2816 memcached_free(memc_clone
);
2818 return TEST_SUCCESS
;
2821 static test_return_t
pre_binary(memcached_st
*memc
);
2823 static test_return_t
user_supplied_bug21(memcached_st
*memc
)
2825 test_return_t test_rc
;
2826 test_rc
= pre_binary(memc
);
2828 if (test_rc
!= TEST_SUCCESS
)
2833 /* should work as of r580 */
2834 rc
= _user_supplied_bug21(memc
, 10);
2835 test_truth(rc
== TEST_SUCCESS
);
2837 /* should fail as of r580 */
2838 rc
= _user_supplied_bug21(memc
, 1000);
2839 test_truth(rc
== TEST_SUCCESS
);
2841 return TEST_SUCCESS
;
2844 static test_return_t
auto_eject_hosts(memcached_st
*trash
)
2847 memcached_server_instance_st
*instance
;
2849 memcached_return_t rc
;
2850 memcached_st
*memc
= memcached_create(NULL
);
2853 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2854 test_truth(rc
== MEMCACHED_SUCCESS
);
2856 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2857 test_truth(value
== 1);
2859 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2860 test_truth(rc
== MEMCACHED_SUCCESS
);
2862 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2863 test_truth(value
== MEMCACHED_HASH_MD5
);
2865 /* server should be removed when in delay */
2866 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
, 1);
2867 test_truth(rc
== MEMCACHED_SUCCESS
);
2869 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
);
2870 test_truth(value
== 1);
2872 memcached_server_st
*server_pool
;
2873 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");
2874 memcached_server_push(memc
, server_pool
);
2876 /* verify that the server list was parsed okay. */
2877 test_truth(memcached_server_count(memc
) == 8);
2878 test_truth(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
2879 test_truth(server_pool
[0].port
== 11211);
2880 test_truth(server_pool
[0].weight
== 600);
2881 test_truth(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
2882 test_truth(server_pool
[2].port
== 11211);
2883 test_truth(server_pool
[2].weight
== 200);
2884 test_truth(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
2885 test_truth(server_pool
[7].port
== 11211);
2886 test_truth(server_pool
[7].weight
== 100);
2888 instance
= memcached_server_instance_fetch(memc
, 2);
2889 instance
->next_retry
= time(NULL
) + 15;
2890 memc
->next_distribution_rebuild
= time(NULL
) - 1;
2892 for (int x
= 0; x
< 99; x
++)
2894 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
2895 test_truth(server_idx
!= 2);
2898 /* and re-added when it's back. */
2899 instance
->next_retry
= time(NULL
) - 1;
2900 memc
->next_distribution_rebuild
= time(NULL
) - 1;
2901 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
,
2902 memc
->distribution
);
2903 for (int x
= 0; x
< 99; x
++)
2905 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
2906 // We re-use instance from above.
2908 memcached_server_instance_fetch(memc
, server_idx
);
2909 char *hostname
= instance
->hostname
;
2910 test_truth(strcmp(hostname
, ketama_test_cases
[x
].server
) == 0);
2913 memcached_server_list_free(server_pool
);
2914 memcached_free(memc
);
2916 return TEST_SUCCESS
;
2919 static test_return_t
output_ketama_weighted_keys(memcached_st
*trash
)
2923 memcached_return_t rc
;
2924 memcached_st
*memc
= memcached_create(NULL
);
2928 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2929 test_truth(rc
== MEMCACHED_SUCCESS
);
2931 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2932 test_truth(value
== 1);
2934 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2935 test_truth(rc
== MEMCACHED_SUCCESS
);
2937 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2938 test_truth(value
== MEMCACHED_HASH_MD5
);
2941 test_truth(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
) == MEMCACHED_SUCCESS
);
2943 memcached_server_st
*server_pool
;
2944 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");
2945 memcached_server_push(memc
, server_pool
);
2947 // @todo this needs to be refactored to actually test something.
2950 if ((fp
= fopen("ketama_keys.txt", "w")))
2954 printf("cannot write to file ketama_keys.txt");
2955 return TEST_FAILURE
;
2958 for (int x
= 0; x
< 10000; x
++)
2961 sprintf(key
, "%d", x
);
2963 uint32_t server_idx
= memcached_generate_hash(memc
, key
, strlen(key
));
2964 char *hostname
= memc
->hosts
[server_idx
].hostname
;
2965 in_port_t port
= memc
->hosts
[server_idx
].port
;
2966 fprintf(fp
, "key %s is on host /%s:%u\n", key
, hostname
, port
);
2970 memcached_server_list_free(server_pool
);
2971 memcached_free(memc
);
2973 return TEST_SUCCESS
;
2977 static test_return_t
result_static(memcached_st
*memc
)
2979 memcached_result_st result
;
2980 memcached_result_st
*result_ptr
;
2982 result_ptr
= memcached_result_create(memc
, &result
);
2983 test_truth(result
.options
.is_allocated
== false);
2984 test_truth(memcached_is_initialized(&result
) == true);
2985 test_truth(result_ptr
);
2986 test_truth(result_ptr
== &result
);
2988 memcached_result_free(&result
);
2990 test_truth(result
.options
.is_allocated
== false);
2991 test_truth(memcached_is_initialized(&result
) == false);
2993 return TEST_SUCCESS
;
2996 static test_return_t
result_alloc(memcached_st
*memc
)
2998 memcached_result_st
*result_ptr
;
3000 result_ptr
= memcached_result_create(memc
, NULL
);
3001 test_truth(result_ptr
);
3002 test_truth(result_ptr
->options
.is_allocated
== true);
3003 test_truth(memcached_is_initialized(result_ptr
) == true);
3004 memcached_result_free(result_ptr
);
3006 return TEST_SUCCESS
;
3009 static test_return_t
string_static_null(memcached_st
*memc
)
3011 memcached_string_st string
;
3012 memcached_string_st
*string_ptr
;
3014 string_ptr
= memcached_string_create(memc
, &string
, 0);
3015 test_truth(string
.options
.is_initialized
== true);
3016 test_truth(string_ptr
);
3018 /* The following two better be the same! */
3019 test_truth(memcached_is_allocated(string_ptr
) == false);
3020 test_truth(memcached_is_allocated(&string
) == false);
3021 test_truth(&string
== string_ptr
);
3023 test_truth(string
.options
.is_initialized
== true);
3024 test_truth(memcached_is_initialized(&string
) == true);
3025 memcached_string_free(&string
);
3026 test_truth(memcached_is_initialized(&string
) == false);
3028 return TEST_SUCCESS
;
3031 static test_return_t
string_alloc_null(memcached_st
*memc
)
3033 memcached_string_st
*string
;
3035 string
= memcached_string_create(memc
, NULL
, 0);
3037 test_truth(memcached_is_allocated(string
) == true);
3038 test_truth(memcached_is_initialized(string
) == true);
3039 memcached_string_free(string
);
3041 return TEST_SUCCESS
;
3044 static test_return_t
string_alloc_with_size(memcached_st
*memc
)
3046 memcached_string_st
*string
;
3048 string
= memcached_string_create(memc
, NULL
, 1024);
3050 test_truth(memcached_is_allocated(string
) == true);
3051 test_truth(memcached_is_initialized(string
) == true);
3052 memcached_string_free(string
);
3054 return TEST_SUCCESS
;
3057 static test_return_t
string_alloc_with_size_toobig(memcached_st
*memc
)
3059 memcached_string_st
*string
;
3061 string
= memcached_string_create(memc
, NULL
, SIZE_MAX
);
3062 test_truth(string
== NULL
);
3064 return TEST_SUCCESS
;
3067 static test_return_t
string_alloc_append(memcached_st
*memc
)
3070 char buffer
[SMALL_STRING_LEN
];
3071 memcached_string_st
*string
;
3073 /* Ring the bell! */
3074 memset(buffer
, 6, SMALL_STRING_LEN
);
3076 string
= memcached_string_create(memc
, NULL
, 100);
3078 test_truth(memcached_is_allocated(string
) == true);
3079 test_truth(memcached_is_initialized(string
) == true);
3081 for (x
= 0; x
< 1024; x
++)
3083 memcached_return_t rc
;
3084 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
3085 test_truth(rc
== MEMCACHED_SUCCESS
);
3087 test_truth(memcached_is_allocated(string
) == true);
3088 memcached_string_free(string
);
3090 return TEST_SUCCESS
;
3093 static test_return_t
string_alloc_append_toobig(memcached_st
*memc
)
3095 memcached_return_t rc
;
3097 char buffer
[SMALL_STRING_LEN
];
3098 memcached_string_st
*string
;
3100 /* Ring the bell! */
3101 memset(buffer
, 6, SMALL_STRING_LEN
);
3103 string
= memcached_string_create(memc
, NULL
, 100);
3105 test_truth(memcached_is_allocated(string
) == true);
3106 test_truth(memcached_is_initialized(string
) == true);
3108 for (x
= 0; x
< 1024; x
++)
3110 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
3111 test_truth(rc
== MEMCACHED_SUCCESS
);
3113 rc
= memcached_string_append(string
, buffer
, SIZE_MAX
);
3114 test_truth(rc
== MEMCACHED_MEMORY_ALLOCATION_FAILURE
);
3115 test_truth(memcached_is_allocated(string
) == true);
3116 memcached_string_free(string
);
3118 return TEST_SUCCESS
;
3121 static test_return_t
cleanup_pairs(memcached_st
*memc
__attribute__((unused
)))
3123 pairs_free(global_pairs
);
3125 return TEST_SUCCESS
;
3128 static test_return_t
generate_pairs(memcached_st
*memc
__attribute__((unused
)))
3130 unsigned long long x
;
3131 global_pairs
= pairs_generate(GLOBAL_COUNT
, 400);
3132 global_count
= GLOBAL_COUNT
;
3134 for (x
= 0; x
< global_count
; x
++)
3136 global_keys
[x
]= global_pairs
[x
].key
;
3137 global_keys_length
[x
]= global_pairs
[x
].key_length
;
3140 return TEST_SUCCESS
;
3143 static test_return_t
generate_large_pairs(memcached_st
*memc
__attribute__((unused
)))
3145 unsigned long long x
;
3146 global_pairs
= pairs_generate(GLOBAL2_COUNT
, MEMCACHED_MAX_BUFFER
+10);
3147 global_count
= GLOBAL2_COUNT
;
3149 for (x
= 0; x
< global_count
; x
++)
3151 global_keys
[x
]= global_pairs
[x
].key
;
3152 global_keys_length
[x
]= global_pairs
[x
].key_length
;
3155 return TEST_SUCCESS
;
3158 static test_return_t
generate_data(memcached_st
*memc
)
3160 execute_set(memc
, global_pairs
, global_count
);
3162 return TEST_SUCCESS
;
3165 static test_return_t
generate_data_with_stats(memcached_st
*memc
)
3167 memcached_stat_st
*stat_p
;
3168 memcached_return_t rc
;
3169 uint32_t host_index
= 0;
3170 execute_set(memc
, global_pairs
, global_count
);
3172 //TODO: hosts used size stats
3173 stat_p
= memcached_stat(memc
, NULL
, &rc
);
3176 for (host_index
= 0; host_index
< SERVERS_TO_CREATE
; host_index
++)
3178 /* This test was changes so that "make test" would work properlly */
3180 printf("\nserver %u|%s|%u bytes: %llu\n", host_index
, (memc
->hosts
)[host_index
].hostname
, (memc
->hosts
)[host_index
].port
, (unsigned long long)(stat_p
+ host_index
)->bytes
);
3182 test_truth((unsigned long long)(stat_p
+ host_index
)->bytes
);
3185 memcached_stat_free(NULL
, stat_p
);
3187 return TEST_SUCCESS
;
3189 static test_return_t
generate_buffer_data(memcached_st
*memc
)
3194 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
3195 generate_data(memc
);
3197 return TEST_SUCCESS
;
3200 static test_return_t
get_read_count(memcached_st
*memc
)
3203 memcached_return_t rc
;
3204 memcached_st
*memc_clone
;
3206 memc_clone
= memcached_clone(NULL
, memc
);
3207 test_truth(memc_clone
);
3209 memcached_server_add_with_weight(memc_clone
, "localhost", 6666, 0);
3213 size_t return_value_length
;
3217 for (x
= count
= 0; x
< global_count
; x
++)
3219 return_value
= memcached_get(memc_clone
, global_keys
[x
], global_keys_length
[x
],
3220 &return_value_length
, &flags
, &rc
);
3221 if (rc
== MEMCACHED_SUCCESS
)
3230 memcached_free(memc_clone
);
3232 return TEST_SUCCESS
;
3235 static test_return_t
get_read(memcached_st
*memc
)
3238 memcached_return_t rc
;
3242 size_t return_value_length
;
3245 for (x
= 0; x
< global_count
; x
++)
3247 return_value
= memcached_get(memc
, global_keys
[x
], global_keys_length
[x
],
3248 &return_value_length
, &flags
, &rc
);
3250 test_truth(return_value);
3251 test_truth(rc == MEMCACHED_SUCCESS);
3253 if (rc
== MEMCACHED_SUCCESS
&& return_value
)
3258 return TEST_SUCCESS
;
3261 static test_return_t
mget_read(memcached_st
*memc
)
3263 memcached_return_t rc
;
3265 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
3266 test_truth(rc
== MEMCACHED_SUCCESS
);
3267 test_truth(fetch_all_results(memc
) == TEST_SUCCESS
);
3269 return TEST_SUCCESS
;
3272 static test_return_t
mget_read_result(memcached_st
*memc
)
3274 memcached_return_t rc
;
3276 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
3277 test_truth(rc
== MEMCACHED_SUCCESS
);
3278 /* Turn this into a help function */
3280 memcached_result_st results_obj
;
3281 memcached_result_st
*results
;
3283 results
= memcached_result_create(memc
, &results_obj
);
3285 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
3287 test_truth(results
);
3288 test_truth(rc
== MEMCACHED_SUCCESS
);
3291 memcached_result_free(&results_obj
);
3294 return TEST_SUCCESS
;
3297 static test_return_t
mget_read_function(memcached_st
*memc
)
3299 memcached_return_t rc
;
3300 unsigned int counter
;
3301 memcached_execute_fn callbacks
[1];
3303 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
3304 test_truth(rc
== MEMCACHED_SUCCESS
);
3306 callbacks
[0]= &callback_counter
;
3308 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
3310 return TEST_SUCCESS
;
3313 static test_return_t
delete_generate(memcached_st
*memc
)
3317 for (x
= 0; x
< global_count
; x
++)
3319 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3322 return TEST_SUCCESS
;
3325 static test_return_t
delete_buffer_generate(memcached_st
*memc
)
3331 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
3333 for (x
= 0; x
< global_count
; x
++)
3335 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3338 return TEST_SUCCESS
;
3341 static test_return_t
add_host_test1(memcached_st
*memc
)
3344 memcached_return_t rc
;
3345 char servername
[]= "0.example.com";
3346 memcached_server_st
*servers
;
3348 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
3349 test_truth(servers
);
3350 test_truth(1 == memcached_server_list_count(servers
));
3352 for (x
= 2; x
< 20; x
++)
3354 char buffer
[SMALL_STRING_LEN
];
3356 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
3357 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
3359 test_truth(rc
== MEMCACHED_SUCCESS
);
3360 test_truth(x
== memcached_server_list_count(servers
));
3363 rc
= memcached_server_push(memc
, servers
);
3364 test_truth(rc
== MEMCACHED_SUCCESS
);
3365 rc
= memcached_server_push(memc
, servers
);
3366 test_truth(rc
== MEMCACHED_SUCCESS
);
3368 memcached_server_list_free(servers
);
3370 return TEST_SUCCESS
;
3373 static test_return_t
pre_nonblock(memcached_st
*memc
)
3375 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3377 return TEST_SUCCESS
;
3380 static test_return_t
pre_nonblock_binary(memcached_st
*memc
)
3382 memcached_return_t rc
= MEMCACHED_FAILURE
;
3383 memcached_st
*memc_clone
;
3384 memcached_server_instance_st
*instance
;
3386 memc_clone
= memcached_clone(NULL
, memc
);
3387 test_truth(memc_clone
);
3388 // The memcached_version needs to be done on a clone, because the server
3389 // will not toggle protocol on an connection.
3390 memcached_version(memc_clone
);
3392 instance
= memcached_server_instance_fetch(memc_clone
, 0);
3394 if (instance
->major_version
>= 1 && instance
->minor_version
> 2)
3396 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3397 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3398 test_truth(rc
== MEMCACHED_SUCCESS
);
3399 test_truth(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3403 return TEST_SKIPPED
;
3406 memcached_free(memc_clone
);
3408 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3411 static test_return_t
pre_murmur(memcached_st
*memc
)
3413 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
3415 return TEST_SUCCESS
;
3418 static test_return_t
pre_jenkins(memcached_st
*memc
)
3420 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_JENKINS
);
3422 return TEST_SUCCESS
;
3426 static test_return_t
pre_md5(memcached_st
*memc
)
3428 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MD5
);
3430 return TEST_SUCCESS
;
3433 static test_return_t
pre_crc(memcached_st
*memc
)
3435 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_CRC
);
3437 return TEST_SUCCESS
;
3440 static test_return_t
pre_hsieh(memcached_st
*memc
)
3442 #ifdef HAVE_HSIEH_HASH
3443 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_HSIEH
);
3444 return TEST_SUCCESS
;
3447 return TEST_SKIPPED
;
3451 static test_return_t
pre_hash_fnv1_64(memcached_st
*memc
)
3453 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
3455 return TEST_SUCCESS
;
3458 static test_return_t
pre_hash_fnv1a_64(memcached_st
*memc
)
3460 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_64
);
3462 return TEST_SUCCESS
;
3465 static test_return_t
pre_hash_fnv1_32(memcached_st
*memc
)
3467 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_32
);
3469 return TEST_SUCCESS
;
3472 static test_return_t
pre_hash_fnv1a_32(memcached_st
*memc
)
3474 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_32
);
3476 return TEST_SUCCESS
;
3479 static test_return_t
pre_behavior_ketama(memcached_st
*memc
)
3481 memcached_return_t rc
;
3484 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA
, 1);
3485 test_truth(rc
== MEMCACHED_SUCCESS
);
3487 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA
);
3488 test_truth(value
== 1);
3490 return TEST_SUCCESS
;
3493 static test_return_t
pre_behavior_ketama_weighted(memcached_st
*memc
)
3495 memcached_return_t rc
;
3498 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
3499 test_truth(rc
== MEMCACHED_SUCCESS
);
3501 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
3502 test_truth(value
== 1);
3504 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
3505 test_truth(rc
== MEMCACHED_SUCCESS
);
3507 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
3508 test_truth(value
== MEMCACHED_HASH_MD5
);
3510 return TEST_SUCCESS
;
3514 @note This should be testing to see if the server really supports the binary protocol.
3516 static test_return_t
pre_binary(memcached_st
*memc
)
3518 memcached_return_t rc
= MEMCACHED_FAILURE
;
3519 memcached_st
*memc_clone
;
3520 memcached_server_instance_st
*instance
;
3522 memc_clone
= memcached_clone(NULL
, memc
);
3523 test_truth(memc_clone
);
3524 // The memcached_version needs to be done on a clone, because the server
3525 // will not toggle protocol on an connection.
3526 memcached_version(memc_clone
);
3528 instance
= memcached_server_instance_fetch(memc_clone
, 0);
3530 if (instance
->major_version
>= 1 && instance
->minor_version
> 2)
3532 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3533 test_truth(rc
== MEMCACHED_SUCCESS
);
3534 test_truth(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3537 memcached_free(memc_clone
);
3539 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3543 static test_return_t
pre_replication(memcached_st
*memc
)
3545 test_return_t test_rc
;
3546 test_rc
= pre_binary(memc
);
3548 if (test_rc
!= TEST_SUCCESS
)
3552 * Make sure that we store the item on all servers
3553 * (master + replicas == number of servers)
3555 memcached_return_t rc
;
3556 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
,
3557 memcached_server_count(memc
) - 1);
3558 test_truth(rc
== MEMCACHED_SUCCESS
);
3559 test_truth(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
) == memcached_server_count(memc
) - 1);
3561 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3565 static test_return_t
pre_replication_noblock(memcached_st
*memc
)
3569 rc
= pre_replication(memc
);
3570 if (rc
!= TEST_SUCCESS
)
3573 rc
= pre_nonblock(memc
);
3579 static void my_free(memcached_st
*ptr
__attribute__((unused
)), void *mem
)
3581 #ifdef HARD_MALLOC_TESTS
3582 void *real_ptr
= (mem
== NULL
) ? mem
: (void*)((caddr_t
)mem
- 8);
3590 static void *my_malloc(memcached_st
*ptr
__attribute__((unused
)), const size_t size
)
3592 #ifdef HARD_MALLOC_TESTS
3593 void *ret
= malloc(size
+ 8);
3596 ret
= (void*)((caddr_t
)ret
+ 8);
3599 void *ret
= malloc(size
);
3604 memset(ret
, 0xff, size
);
3611 static void *my_realloc(memcached_st
*ptr
__attribute__((unused
)), void *mem
, const size_t size
)
3613 #ifdef HARD_MALLOC_TESTS
3614 void *real_ptr
= (mem
== NULL
) ? NULL
: (void*)((caddr_t
)mem
- 8);
3615 void *nmem
= realloc(real_ptr
, size
+ 8);
3620 ret
= (void*)((caddr_t
)nmem
+ 8);
3625 return realloc(mem
, size
);
3630 static void *my_calloc(memcached_st
*ptr
__attribute__((unused
)), size_t nelem
, const size_t size
)
3632 #ifdef HARD_MALLOC_TESTS
3633 void *mem
= my_malloc(ptr
, nelem
* size
);
3636 memset(mem
, 0, nelem
* size
);
3641 return calloc(nelem
, size
);
3646 static test_return_t
set_prefix(memcached_st
*memc
)
3648 memcached_return_t rc
;
3649 const char *key
= "mine";
3652 /* Make sure be default none exists */
3653 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3654 test_truth(rc
== MEMCACHED_FAILURE
);
3656 /* Test a clean set */
3657 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3658 test_truth(rc
== MEMCACHED_SUCCESS
);
3660 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3661 test_truth(memcmp(value
, key
, 4) == 0);
3662 test_truth(rc
== MEMCACHED_SUCCESS
);
3664 /* Test that we can turn it off */
3665 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3666 test_truth(rc
== MEMCACHED_SUCCESS
);
3668 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3669 test_truth(rc
== MEMCACHED_FAILURE
);
3671 /* Now setup for main test */
3672 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3673 test_truth(rc
== MEMCACHED_SUCCESS
);
3675 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3676 test_truth(rc
== MEMCACHED_SUCCESS
);
3677 test_truth(memcmp(value
, key
, 4) == 0);
3679 /* Set to Zero, and then Set to something too large */
3682 memset(long_key
, 0, 255);
3684 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3685 test_truth(rc
== MEMCACHED_SUCCESS
);
3687 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3688 test_truth(rc
== MEMCACHED_FAILURE
);
3689 test_truth(value
== NULL
);
3691 /* Test a long key for failure */
3692 /* TODO, extend test to determine based on setting, what result should be */
3693 strcpy(long_key
, "Thisismorethentheallottednumberofcharacters");
3694 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3695 //test_truth(rc == MEMCACHED_BAD_KEY_PROVIDED);
3696 test_truth(rc
== MEMCACHED_SUCCESS
);
3698 /* Now test a key with spaces (which will fail from long key, since bad key is not set) */
3699 strcpy(long_key
, "This is more then the allotted number of characters");
3700 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3701 test_truth(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3703 /* Test for a bad prefix, but with a short key */
3704 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, 1);
3705 test_truth(rc
== MEMCACHED_SUCCESS
);
3707 strcpy(long_key
, "dog cat");
3708 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3709 test_truth(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3712 return TEST_SUCCESS
;
3716 #ifdef MEMCACHED_ENABLE_DEPRECATED
3717 static test_return_t
deprecated_set_memory_alloc(memcached_st
*memc
)
3719 void *test_ptr
= NULL
;
3722 memcached_malloc_fn malloc_cb
=
3723 (memcached_malloc_fn
)my_malloc
;
3724 cb_ptr
= *(void **)&malloc_cb
;
3725 memcached_return_t rc
;
3727 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, cb_ptr
);
3728 test_truth(rc
== MEMCACHED_SUCCESS
);
3729 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
3730 test_truth(rc
== MEMCACHED_SUCCESS
);
3731 test_truth(test_ptr
== cb_ptr
);
3735 memcached_realloc_fn realloc_cb
=
3736 (memcached_realloc_fn
)my_realloc
;
3737 cb_ptr
= *(void **)&realloc_cb
;
3738 memcached_return_t rc
;
3740 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, cb_ptr
);
3741 test_truth(rc
== MEMCACHED_SUCCESS
);
3742 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
3743 test_truth(rc
== MEMCACHED_SUCCESS
);
3744 test_truth(test_ptr
== cb_ptr
);
3748 memcached_free_fn free_cb
=
3749 (memcached_free_fn
)my_free
;
3750 cb_ptr
= *(void **)&free_cb
;
3751 memcached_return_t rc
;
3753 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, cb_ptr
);
3754 test_truth(rc
== MEMCACHED_SUCCESS
);
3755 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
3756 test_truth(rc
== MEMCACHED_SUCCESS
);
3757 test_truth(test_ptr
== cb_ptr
);
3760 return TEST_SUCCESS
;
3765 static test_return_t
set_memory_alloc(memcached_st
*memc
)
3767 memcached_return_t rc
;
3768 rc
= memcached_set_memory_allocators(memc
, NULL
, my_free
,
3769 my_realloc
, my_calloc
);
3770 test_truth(rc
== MEMCACHED_FAILURE
);
3772 rc
= memcached_set_memory_allocators(memc
, my_malloc
, my_free
,
3773 my_realloc
, my_calloc
);
3775 memcached_malloc_fn mem_malloc
;
3776 memcached_free_fn mem_free
;
3777 memcached_realloc_fn mem_realloc
;
3778 memcached_calloc_fn mem_calloc
;
3779 memcached_get_memory_allocators(memc
, &mem_malloc
, &mem_free
,
3780 &mem_realloc
, &mem_calloc
);
3782 test_truth(mem_malloc
== my_malloc
);
3783 test_truth(mem_realloc
== my_realloc
);
3784 test_truth(mem_calloc
== my_calloc
);
3785 test_truth(mem_free
== my_free
);
3787 return TEST_SUCCESS
;
3790 static test_return_t
enable_consistent_crc(memcached_st
*memc
)
3793 memcached_server_distribution_t value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
3794 memcached_hash_t hash
;
3795 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
3796 if ((rc
= pre_crc(memc
)) != TEST_SUCCESS
)
3799 value
= (memcached_server_distribution_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
3800 test_truth(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
3802 hash
= (memcached_hash_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
3804 if (hash
!= MEMCACHED_HASH_CRC
)
3805 return TEST_SKIPPED
;
3807 return TEST_SUCCESS
;
3810 static test_return_t
enable_consistent_hsieh(memcached_st
*memc
)
3813 memcached_server_distribution_t value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
3814 memcached_hash_t hash
;
3815 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
3816 if ((rc
= pre_hsieh(memc
)) != TEST_SUCCESS
)
3819 value
= (memcached_server_distribution_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
3820 test_truth(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
3822 hash
= (memcached_hash_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
3824 if (hash
!= MEMCACHED_HASH_HSIEH
)
3825 return TEST_SKIPPED
;
3828 return TEST_SUCCESS
;
3831 static test_return_t
enable_cas(memcached_st
*memc
)
3833 unsigned int set
= 1;
3835 memcached_server_instance_st
*instance
=
3836 memcached_server_instance_fetch(memc
, 0);
3838 memcached_version(memc
);
3840 if ((instance
->major_version
>= 1 && (instance
->minor_version
== 2 && instance
->micro_version
>= 4))
3841 || instance
->minor_version
> 2)
3843 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
3845 return TEST_SUCCESS
;
3848 return TEST_SKIPPED
;
3851 static test_return_t
check_for_1_2_3(memcached_st
*memc
)
3853 memcached_version(memc
);
3854 memcached_server_instance_st
*instance
=
3855 memcached_server_instance_fetch(memc
, 0);
3857 if ((instance
->major_version
>= 1 && (instance
->minor_version
== 2 && instance
->micro_version
>= 4))
3858 || instance
->minor_version
> 2)
3859 return TEST_SUCCESS
;
3861 return TEST_SKIPPED
;
3864 static test_return_t
pre_unix_socket(memcached_st
*memc
)
3866 memcached_return_t rc
;
3869 memcached_servers_reset(memc
);
3871 if (stat("/tmp/memcached.socket", &buf
))
3872 return TEST_SKIPPED
;
3874 rc
= memcached_server_add_unix_socket_with_weight(memc
, "/tmp/memcached.socket", 0);
3876 return ( rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_FAILURE
);
3879 static test_return_t
pre_nodelay(memcached_st
*memc
)
3881 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3882 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
3884 return TEST_SUCCESS
;
3887 static test_return_t
pre_settimer(memcached_st
*memc
)
3889 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
3890 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
3892 return TEST_SUCCESS
;
3895 static test_return_t
poll_timeout(memcached_st
*memc
)
3901 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
3903 timeout
= (size_t)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
3905 test_truth(timeout
== 100);
3907 return TEST_SUCCESS
;
3910 static test_return_t
noreply_test(memcached_st
*memc
)
3912 memcached_return_t ret
;
3913 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
3914 test_truth(ret
== MEMCACHED_SUCCESS
);
3915 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
3916 test_truth(ret
== MEMCACHED_SUCCESS
);
3917 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
3918 test_truth(ret
== MEMCACHED_SUCCESS
);
3919 test_truth(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NOREPLY
) == 1);
3920 test_truth(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
) == 1);
3921 test_truth(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
) == 1);
3923 for (int count
=0; count
< 5; ++count
)
3925 for (int x
=0; x
< 100; ++x
)
3928 size_t len
= (size_t)sprintf(key
, "%d", x
);
3932 ret
= memcached_add(memc
, key
, len
, key
, len
, 0, 0);
3935 ret
= memcached_replace(memc
, key
, len
, key
, len
, 0, 0);
3938 ret
= memcached_set(memc
, key
, len
, key
, len
, 0, 0);
3941 ret
= memcached_append(memc
, key
, len
, key
, len
, 0, 0);
3944 ret
= memcached_prepend(memc
, key
, len
, key
, len
, 0, 0);
3950 test_truth(ret
== MEMCACHED_SUCCESS
|| ret
== MEMCACHED_BUFFERED
);
3954 ** NOTE: Don't ever do this in your code! this is not a supported use of the
3955 ** API and is _ONLY_ done this way to verify that the library works the
3956 ** way it is supposed to do!!!!
3959 for (uint32_t x
=0; x
< memcached_server_count(memc
); ++x
)
3961 memcached_server_instance_st
*instance
=
3962 memcached_server_instance_fetch(memc
, x
);
3963 no_msg
+=(int)(instance
->cursor_active
);
3966 test_truth(no_msg
== 0);
3967 test_truth(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
3970 ** Now validate that all items was set properly!
3972 for (int x
=0; x
< 100; ++x
)
3975 size_t len
= (size_t)sprintf(key
, "%d", x
);
3978 char* value
=memcached_get(memc
, key
, strlen(key
),
3979 &length
, &flags
, &ret
);
3980 test_truth(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
3983 case 0: /* FALLTHROUGH */
3984 case 1: /* FALLTHROUGH */
3986 test_truth(strncmp(value
, key
, len
) == 0);
3987 test_truth(len
== length
);
3990 test_truth(length
== len
* 2);
3993 test_truth(length
== len
* 3);
4003 /* Try setting an illegal cas value (should not return an error to
4004 * the caller (because we don't expect a return message from the server)
4006 const char* keys
[]= {"0"};
4007 size_t lengths
[]= {1};
4010 memcached_result_st results_obj
;
4011 memcached_result_st
*results
;
4012 ret
= memcached_mget(memc
, keys
, lengths
, 1);
4013 test_truth(ret
== MEMCACHED_SUCCESS
);
4015 results
= memcached_result_create(memc
, &results_obj
);
4016 test_truth(results
);
4017 results
= memcached_fetch_result(memc
, &results_obj
, &ret
);
4018 test_truth(results
);
4019 test_truth(ret
== MEMCACHED_SUCCESS
);
4020 uint64_t cas
= memcached_result_cas(results
);
4021 memcached_result_free(&results_obj
);
4023 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
4024 test_truth(ret
== MEMCACHED_SUCCESS
);
4027 * The item will have a new cas value, so try to set it again with the old
4028 * value. This should fail!
4030 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
4031 test_truth(ret
== MEMCACHED_SUCCESS
);
4032 test_truth(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
4033 char* value
=memcached_get(memc
, keys
[0], lengths
[0], &length
, &flags
, &ret
);
4034 test_truth(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
4037 return TEST_SUCCESS
;
4040 static test_return_t
analyzer_test(memcached_st
*memc
)
4042 memcached_return_t rc
;
4043 memcached_stat_st
*memc_stat
;
4044 memcached_analysis_st
*report
;
4046 memc_stat
= memcached_stat(memc
, NULL
, &rc
);
4047 test_truth(rc
== MEMCACHED_SUCCESS
);
4048 test_truth(memc_stat
);
4050 report
= memcached_analyze(memc
, memc_stat
, &rc
);
4051 test_truth(rc
== MEMCACHED_SUCCESS
);
4055 memcached_stat_free(NULL
, memc_stat
);
4057 return TEST_SUCCESS
;
4060 /* Count the objects */
4061 static memcached_return_t
callback_dump_counter(memcached_st
*ptr
__attribute__((unused
)),
4062 const char *key
__attribute__((unused
)),
4063 size_t key_length
__attribute__((unused
)),
4066 uint32_t *counter
= (uint32_t *)context
;
4068 *counter
= *counter
+ 1;
4070 return MEMCACHED_SUCCESS
;
4073 static test_return_t
dump_test(memcached_st
*memc
)
4075 memcached_return_t rc
;
4076 uint32_t counter
= 0;
4077 memcached_dump_fn callbacks
[1];
4078 test_return_t main_rc
;
4080 callbacks
[0]= &callback_dump_counter
;
4082 /* No support for Binary protocol yet */
4083 if (memc
->flags
.binary_protocol
)
4084 return TEST_SUCCESS
;
4086 main_rc
= set_test3(memc
);
4088 test_truth (main_rc
== TEST_SUCCESS
);
4090 rc
= memcached_dump(memc
, callbacks
, (void *)&counter
, 1);
4091 test_truth(rc
== MEMCACHED_SUCCESS
);
4093 /* We may have more then 32 if our previous flush has not completed */
4094 test_truth(counter
>= 32);
4096 return TEST_SUCCESS
;
4099 #ifdef HAVE_LIBMEMCACHEDUTIL
4100 static void* connection_release(void *arg
)
4103 memcached_pool_st
* pool
;
4108 assert(memcached_pool_push(resource
->pool
, resource
->mmc
) == MEMCACHED_SUCCESS
);
4112 static test_return_t
connection_pool_test(memcached_st
*memc
)
4114 memcached_pool_st
* pool
= memcached_pool_create(memc
, 5, 10);
4115 test_truth(pool
!= NULL
);
4116 memcached_st
* mmc
[10];
4117 memcached_return_t rc
;
4119 for (int x
= 0; x
< 10; ++x
) {
4120 mmc
[x
]= memcached_pool_pop(pool
, false, &rc
);
4121 test_truth(mmc
[x
] != NULL
);
4122 test_truth(rc
== MEMCACHED_SUCCESS
);
4125 test_truth(memcached_pool_pop(pool
, false, &rc
) == NULL
);
4126 test_truth(rc
== MEMCACHED_SUCCESS
);
4130 memcached_pool_st
* pool
;
4132 } item
= { .pool
= pool
, .mmc
= mmc
[9] };
4133 pthread_create(&tid
, NULL
, connection_release
, &item
);
4134 mmc
[9]= memcached_pool_pop(pool
, true, &rc
);
4135 test_truth(rc
== MEMCACHED_SUCCESS
);
4136 pthread_join(tid
, NULL
);
4137 test_truth(mmc
[9] == item
.mmc
);
4138 const char *key
= "key";
4139 size_t keylen
= strlen(key
);
4141 // verify that I can do ops with all connections
4142 rc
= memcached_set(mmc
[0], key
, keylen
, "0", 1, 0, 0);
4143 test_truth(rc
== MEMCACHED_SUCCESS
);
4145 for (unsigned int x
= 0; x
< 10; ++x
) {
4146 uint64_t number_value
;
4147 rc
= memcached_increment(mmc
[x
], key
, keylen
, 1, &number_value
);
4148 test_truth(rc
== MEMCACHED_SUCCESS
);
4149 test_truth(number_value
== (x
+1));
4153 for (int x
= 0; x
< 10; ++x
)
4154 test_truth(memcached_pool_push(pool
, mmc
[x
]) == MEMCACHED_SUCCESS
);
4157 /* verify that I can set behaviors on the pool when I don't have all
4158 * of the connections in the pool. It should however be enabled
4159 * when I push the item into the pool
4161 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
4162 test_truth(mmc
[0] != NULL
);
4164 rc
= memcached_pool_behavior_set(pool
, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
, 9999);
4165 test_truth(rc
== MEMCACHED_SUCCESS
);
4167 mmc
[1]= memcached_pool_pop(pool
, false, &rc
);
4168 test_truth(mmc
[1] != NULL
);
4170 test_truth(memcached_behavior_get(mmc
[1], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
) == 9999);
4171 test_truth(memcached_pool_push(pool
, mmc
[1]) == MEMCACHED_SUCCESS
);
4172 test_truth(memcached_pool_push(pool
, mmc
[0]) == MEMCACHED_SUCCESS
);
4174 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
4175 test_truth(memcached_behavior_get(mmc
[0], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
) == 9999);
4176 test_truth(memcached_pool_push(pool
, mmc
[0]) == MEMCACHED_SUCCESS
);
4179 test_truth(memcached_pool_destroy(pool
) == memc
);
4180 return TEST_SUCCESS
;
4184 static test_return_t
replication_set_test(memcached_st
*memc
)
4186 memcached_return_t rc
;
4187 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4188 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 0);
4190 rc
= memcached_set(memc
, "bubba", 5, "0", 1, 0, 0);
4191 test_truth(rc
== MEMCACHED_SUCCESS
);
4194 ** We are using the quiet commands to store the replicas, so we need
4195 ** to ensure that all of them are processed before we can continue.
4196 ** In the test we go directly from storing the object to trying to
4197 ** receive the object from all of the different servers, so we
4198 ** could end up in a race condition (the memcached server hasn't yet
4199 ** processed the quiet command from the replication set when it process
4200 ** the request from the other client (created by the clone)). As a
4201 ** workaround for that we call memcached_quit to send the quit command
4202 ** to the server and wait for the response ;-) If you use the test code
4203 ** as an example for your own code, please note that you shouldn't need
4206 memcached_quit(memc
);
4209 ** "bubba" should now be stored on all of our servers. We don't have an
4210 ** easy to use API to address each individual server, so I'll just iterate
4211 ** through a bunch of "master keys" and I should most likely hit all of the
4214 for (int x
= 'a'; x
<= 'z'; ++x
)
4216 char key
[2]= { [0]= (char)x
};
4219 char *val
= memcached_get_by_key(memc_clone
, key
, 1, "bubba", 5,
4221 test_truth(rc
== MEMCACHED_SUCCESS
);
4222 test_truth(val
!= NULL
);
4226 memcached_free(memc_clone
);
4228 return TEST_SUCCESS
;
4231 static test_return_t
replication_get_test(memcached_st
*memc
)
4233 memcached_return_t rc
;
4236 * Don't do the following in your code. I am abusing the internal details
4237 * within the library, and this is not a supported interface.
4238 * This is to verify correct behavior in the library
4240 for (uint32_t host
= 0; host
< memcached_server_count(memc
); ++host
)
4242 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4243 memcached_server_instance_st
*instance
=
4244 memcached_server_instance_fetch(memc_clone
, host
);
4248 for (int x
= 'a'; x
<= 'z'; ++x
)
4250 char key
[2]= { [0]= (char)x
};
4253 char *val
= memcached_get_by_key(memc_clone
, key
, 1, "bubba", 5,
4255 test_truth(rc
== MEMCACHED_SUCCESS
);
4256 test_truth(val
!= NULL
);
4260 memcached_free(memc_clone
);
4263 return TEST_SUCCESS
;
4266 static test_return_t
replication_mget_test(memcached_st
*memc
)
4268 memcached_return_t rc
;
4269 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4270 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 0);
4272 const char *keys
[]= { "bubba", "key1", "key2", "key3" };
4273 size_t len
[]= { 5, 4, 4, 4 };
4275 for (int x
=0; x
< 4; ++x
)
4277 rc
= memcached_set(memc
, keys
[x
], len
[x
], "0", 1, 0, 0);
4278 test_truth(rc
== MEMCACHED_SUCCESS
);
4282 ** We are using the quiet commands to store the replicas, so we need
4283 ** to ensure that all of them are processed before we can continue.
4284 ** In the test we go directly from storing the object to trying to
4285 ** receive the object from all of the different servers, so we
4286 ** could end up in a race condition (the memcached server hasn't yet
4287 ** processed the quiet command from the replication set when it process
4288 ** the request from the other client (created by the clone)). As a
4289 ** workaround for that we call memcached_quit to send the quit command
4290 ** to the server and wait for the response ;-) If you use the test code
4291 ** as an example for your own code, please note that you shouldn't need
4294 memcached_quit(memc
);
4297 * Don't do the following in your code. I am abusing the internal details
4298 * within the library, and this is not a supported interface.
4299 * This is to verify correct behavior in the library
4301 memcached_result_st result_obj
;
4302 for (uint32_t host
= 0; host
< memc_clone
->number_of_hosts
; host
++)
4304 memcached_st
*new_clone
= memcached_clone(NULL
, memc
);
4305 memcached_server_instance_st
*instance
=
4306 memcached_server_instance_fetch(new_clone
, host
);
4309 for (int x
= 'a'; x
<= 'z'; ++x
)
4311 const char key
[2]= { [0]= (const char)x
};
4313 rc
= memcached_mget_by_key(new_clone
, key
, 1, keys
, len
, 4);
4314 test_truth(rc
== MEMCACHED_SUCCESS
);
4316 memcached_result_st
*results
= memcached_result_create(new_clone
, &result_obj
);
4317 test_truth(results
);
4320 while ((results
= memcached_fetch_result(new_clone
, &result_obj
, &rc
)) != NULL
)
4324 test_truth(hits
== 4);
4325 memcached_result_free(&result_obj
);
4328 memcached_free(new_clone
);
4331 memcached_free(memc_clone
);
4333 return TEST_SUCCESS
;
4336 static test_return_t
replication_randomize_mget_test(memcached_st
*memc
)
4338 memcached_result_st result_obj
;
4339 memcached_return_t rc
;
4340 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4341 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 3);
4342 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ
, 1);
4344 const char *keys
[]= { "key1", "key2", "key3", "key4", "key5", "key6", "key7" };
4345 size_t len
[]= { 4, 4, 4, 4, 4, 4, 4 };
4347 for (int x
=0; x
< 7; ++x
)
4349 rc
= memcached_set(memc
, keys
[x
], len
[x
], "1", 1, 0, 0);
4350 test_truth(rc
== MEMCACHED_SUCCESS
);
4353 memcached_quit(memc
);
4355 for (int x
=0; x
< 7; ++x
) {
4356 const char key
[2]= { [0]= (const char)x
};
4358 rc
= memcached_mget_by_key(memc_clone
, key
, 1, keys
, len
, 7);
4359 test_truth(rc
== MEMCACHED_SUCCESS
);
4361 memcached_result_st
*results
= memcached_result_create(memc_clone
, &result_obj
);
4362 test_truth(results
);
4365 while ((results
= memcached_fetch_result(memc_clone
, &result_obj
, &rc
)) != NULL
)
4369 test_truth(hits
== 7);
4370 memcached_result_free(&result_obj
);
4372 memcached_free(memc_clone
);
4373 return TEST_SUCCESS
;
4376 static test_return_t
replication_delete_test(memcached_st
*memc
)
4378 memcached_return_t rc
;
4379 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4380 /* Delete the items from all of the servers except 1 */
4381 uint64_t repl
= memcached_behavior_get(memc
,
4382 MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
);
4383 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, --repl
);
4385 const char *keys
[]= { "bubba", "key1", "key2", "key3" };
4386 size_t len
[]= { 5, 4, 4, 4 };
4388 for (int x
=0; x
< 4; ++x
)
4390 rc
= memcached_delete_by_key(memc
, keys
[0], len
[0], keys
[x
], len
[x
], 0);
4391 test_truth(rc
== MEMCACHED_SUCCESS
);
4395 * Don't do the following in your code. I am abusing the internal details
4396 * within the library, and this is not a supported interface.
4397 * This is to verify correct behavior in the library
4399 uint32_t hash
= memcached_generate_hash(memc
, keys
[0], len
[0]);
4400 for (uint32_t x
= 0; x
< (repl
+ 1); ++x
)
4402 memcached_server_instance_st
*instance
=
4403 memcached_server_instance_fetch(memc_clone
, x
);
4406 if (++hash
== memc_clone
->number_of_hosts
)
4410 memcached_result_st result_obj
;
4411 for (uint32_t host
= 0; host
< memc_clone
->number_of_hosts
; ++host
)
4413 for (int x
= 'a'; x
<= 'z'; ++x
)
4415 const char key
[2]= { [0]= (const char)x
};
4417 rc
= memcached_mget_by_key(memc_clone
, key
, 1, keys
, len
, 4);
4418 test_truth(rc
== MEMCACHED_SUCCESS
);
4420 memcached_result_st
*results
= memcached_result_create(memc_clone
, &result_obj
);
4421 test_truth(results
);
4424 while ((results
= memcached_fetch_result(memc_clone
, &result_obj
, &rc
)) != NULL
)
4428 test_truth(hits
== 4);
4429 memcached_result_free(&result_obj
);
4432 memcached_free(memc_clone
);
4434 return TEST_SUCCESS
;
4437 static void increment_request_id(uint16_t *id
)
4440 if ((*id
& UDP_REQUEST_ID_THREAD_MASK
) != 0)
4444 static uint16_t *get_udp_request_ids(memcached_st
*memc
)
4446 uint16_t *ids
= malloc(sizeof(uint16_t) * memcached_server_count(memc
));
4447 assert(ids
!= NULL
);
4450 for (x
= 0; x
< memcached_server_count(memc
); x
++)
4452 memcached_server_instance_st
*instance
=
4453 memcached_server_instance_fetch(memc
, x
);
4455 ids
[x
]= get_udp_datagram_request_id((struct udp_datagram_header_st
*) instance
->write_buffer
);
4461 static test_return_t
post_udp_op_check(memcached_st
*memc
, uint16_t *expected_req_ids
)
4464 memcached_server_st
*cur_server
= memcached_server_list(memc
);
4465 uint16_t *cur_req_ids
= get_udp_request_ids(memc
);
4467 for (x
= 0; x
< memcached_server_count(memc
); x
++)
4469 test_truth(cur_server
[x
].cursor_active
== 0);
4470 test_truth(cur_req_ids
[x
] == expected_req_ids
[x
]);
4472 free(expected_req_ids
);
4475 return TEST_SUCCESS
;
4479 ** There is a little bit of a hack here, instead of removing
4480 ** the servers, I just set num host to 0 and them add then new udp servers
4482 static test_return_t
init_udp(memcached_st
*memc
)
4484 memcached_version(memc
);
4485 memcached_server_instance_st
*instance
=
4486 memcached_server_instance_fetch(memc
, 0);
4488 /* For the time being, only support udp test for >= 1.2.6 && < 1.3 */
4489 if (instance
->major_version
!= 1 || instance
->minor_version
!= 2
4490 || instance
->micro_version
< 6)
4491 return TEST_SKIPPED
;
4493 uint32_t num_hosts
= memcached_server_count(memc
);
4495 memcached_server_st servers
[num_hosts
];
4496 memcpy(servers
, memcached_server_list(memc
), sizeof(memcached_server_st
) * num_hosts
);
4497 for (x
= 0; x
< num_hosts
; x
++)
4499 memcached_server_instance_st
*set_instance
=
4500 memcached_server_instance_fetch(memc
, x
);
4502 memcached_server_free(set_instance
);
4505 memc
->number_of_hosts
= 0;
4506 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
, 1);
4507 for (x
= 0; x
< num_hosts
; x
++)
4509 memcached_server_instance_st
*set_instance
=
4510 memcached_server_instance_fetch(memc
, x
);
4512 test_truth(memcached_server_add_udp(memc
, servers
[x
].hostname
, servers
[x
].port
) == MEMCACHED_SUCCESS
);
4513 test_truth(set_instance
->write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4516 return TEST_SUCCESS
;
4519 static test_return_t
binary_init_udp(memcached_st
*memc
)
4521 test_return_t test_rc
;
4522 test_rc
= pre_binary(memc
);
4524 if (test_rc
!= TEST_SUCCESS
)
4527 return init_udp(memc
);
4530 /* Make sure that I cant add a tcp server to a udp client */
4531 static test_return_t
add_tcp_server_udp_client_test(memcached_st
*memc
)
4535 memcached_server_st server
;
4536 memcached_server_instance_st
*instance
=
4537 memcached_server_instance_fetch(memc
, 0);
4538 memcached_server_clone(&server
, &memc
->hosts
[0]);
4539 test_truth(memcached_server_remove(&(memc
->hosts
[0])) == MEMCACHED_SUCCESS
);
4540 test_truth(memcached_server_add(memc
, server
.hostname
, server
.port
) == MEMCACHED_INVALID_HOST_PROTOCOL
);
4542 return TEST_SUCCESS
;
4545 /* Make sure that I cant add a udp server to a tcp client */
4546 static test_return_t
add_udp_server_tcp_client_test(memcached_st
*memc
)
4550 memcached_server_st server
;
4551 memcached_server_instance_st
*instance
=
4552 memcached_server_instance_fetch(memc
, 0);
4553 memcached_server_clone(&server
, &memc
->hosts
[0]);
4554 test_truth(memcached_server_remove(&(memc
->hosts
[0])) == MEMCACHED_SUCCESS
);
4556 memcached_st tcp_client
;
4557 memcached_create(&tcp_client
);
4558 test_truth(memcached_server_add_udp(&tcp_client
, server
.hostname
, server
.port
) == MEMCACHED_INVALID_HOST_PROTOCOL
);
4561 return TEST_SUCCESS
;
4564 static test_return_t
set_udp_behavior_test(memcached_st
*memc
)
4567 memcached_quit(memc
);
4568 memc
->number_of_hosts
= 0;
4569 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, memc
->distribution
);
4570 test_truth(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
, 1) == MEMCACHED_SUCCESS
);
4571 test_truth(memc
->flags
.use_udp
);
4572 test_truth(memc
->flags
.no_reply
);
4574 test_truth(memcached_server_count(memc
) == 0);
4576 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
,0);
4577 test_truth(! (memc
->flags
.use_udp
));
4578 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
,0);
4579 test_truth(! (memc
->flags
.no_reply
));
4581 return TEST_SUCCESS
;
4584 static test_return_t
udp_set_test(memcached_st
*memc
)
4587 unsigned int num_iters
= 1025; //request id rolls over at 1024
4588 for (x
= 0; x
< num_iters
;x
++)
4590 memcached_return_t rc
;
4591 const char *key
= "foo";
4592 const char *value
= "when we sanitize";
4593 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4594 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4595 memcached_server_instance_st
*instance
=
4596 memcached_server_instance_fetch(memc
, server_key
);
4597 size_t init_offset
= instance
->write_buffer_offset
;
4599 rc
= memcached_set(memc
, key
, strlen(key
),
4600 value
, strlen(value
),
4601 (time_t)0, (uint32_t)0);
4602 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4603 /** NB, the check below assumes that if new write_ptr is less than
4604 * the original write_ptr that we have flushed. For large payloads, this
4605 * maybe an invalid assumption, but for the small payload we have it is OK
4607 if (rc
== MEMCACHED_SUCCESS
||
4608 instance
->write_buffer_offset
< init_offset
)
4609 increment_request_id(&expected_ids
[server_key
]);
4611 if (rc
== MEMCACHED_SUCCESS
)
4613 test_truth(instance
->write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4617 test_truth(instance
->write_buffer_offset
!= UDP_DATAGRAM_HEADER_LENGTH
);
4618 test_truth(instance
->write_buffer_offset
<= MAX_UDP_DATAGRAM_LENGTH
);
4620 test_truth(post_udp_op_check(memc
, expected_ids
) == TEST_SUCCESS
);
4622 return TEST_SUCCESS
;
4625 static test_return_t
udp_buffered_set_test(memcached_st
*memc
)
4627 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4628 return udp_set_test(memc
);
4631 static test_return_t
udp_set_too_big_test(memcached_st
*memc
)
4633 memcached_return_t rc
;
4634 const char *key
= "bar";
4635 char value
[MAX_UDP_DATAGRAM_LENGTH
];
4636 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4637 rc
= memcached_set(memc
, key
, strlen(key
),
4638 value
, MAX_UDP_DATAGRAM_LENGTH
,
4639 (time_t)0, (uint32_t)0);
4640 test_truth(rc
== MEMCACHED_WRITE_FAILURE
);
4641 return post_udp_op_check(memc
,expected_ids
);
4644 static test_return_t
udp_delete_test(memcached_st
*memc
)
4647 unsigned int num_iters
= 1025; //request id rolls over at 1024
4648 for (x
= 0; x
< num_iters
;x
++)
4650 memcached_return_t rc
;
4651 const char *key
= "foo";
4652 uint16_t *expected_ids
=get_udp_request_ids(memc
);
4653 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4654 memcached_server_instance_st
*instance
=
4655 memcached_server_instance_fetch(memc
, server_key
);
4656 size_t init_offset
= instance
->write_buffer_offset
;
4658 rc
= memcached_delete(memc
, key
, strlen(key
), 0);
4659 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4661 if (rc
== MEMCACHED_SUCCESS
|| instance
->write_buffer_offset
< init_offset
)
4662 increment_request_id(&expected_ids
[server_key
]);
4663 if (rc
== MEMCACHED_SUCCESS
)
4665 test_truth(instance
->write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4669 test_truth(instance
->write_buffer_offset
!= UDP_DATAGRAM_HEADER_LENGTH
);
4670 test_truth(instance
->write_buffer_offset
<= MAX_UDP_DATAGRAM_LENGTH
);
4672 test_truth(post_udp_op_check(memc
,expected_ids
) == TEST_SUCCESS
);
4674 return TEST_SUCCESS
;
4677 static test_return_t
udp_buffered_delete_test(memcached_st
*memc
)
4679 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4680 return udp_delete_test(memc
);
4683 static test_return_t
udp_verbosity_test(memcached_st
*memc
)
4685 memcached_return_t rc
;
4686 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4688 for (x
= 0; x
< memcached_server_count(memc
); x
++)
4689 increment_request_id(&expected_ids
[x
]);
4691 rc
= memcached_verbosity(memc
,3);
4692 test_truth(rc
== MEMCACHED_SUCCESS
);
4693 return post_udp_op_check(memc
,expected_ids
);
4696 static test_return_t
udp_quit_test(memcached_st
*memc
)
4698 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4699 memcached_quit(memc
);
4700 return post_udp_op_check(memc
, expected_ids
);
4703 static test_return_t
udp_flush_test(memcached_st
*memc
)
4705 memcached_return_t rc
;
4706 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4708 for (x
= 0; x
< memcached_server_count(memc
);x
++)
4709 increment_request_id(&expected_ids
[x
]);
4711 rc
= memcached_flush(memc
,0);
4712 test_truth(rc
== MEMCACHED_SUCCESS
);
4713 return post_udp_op_check(memc
,expected_ids
);
4716 static test_return_t
udp_incr_test(memcached_st
*memc
)
4718 memcached_return_t rc
;
4719 const char *key
= "incr";
4720 const char *value
= "1";
4721 rc
= memcached_set(memc
, key
, strlen(key
),
4722 value
, strlen(value
),
4723 (time_t)0, (uint32_t)0);
4725 test_truth(rc
== MEMCACHED_SUCCESS
);
4726 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4727 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4728 increment_request_id(&expected_ids
[server_key
]);
4730 rc
= memcached_increment(memc
, key
, strlen(key
), 1, &newvalue
);
4731 test_truth(rc
== MEMCACHED_SUCCESS
);
4732 return post_udp_op_check(memc
, expected_ids
);
4735 static test_return_t
udp_decr_test(memcached_st
*memc
)
4737 memcached_return_t rc
;
4738 const char *key
= "decr";
4739 const char *value
= "1";
4740 rc
= memcached_set(memc
, key
, strlen(key
),
4741 value
, strlen(value
),
4742 (time_t)0, (uint32_t)0);
4744 test_truth(rc
== MEMCACHED_SUCCESS
);
4745 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4746 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4747 increment_request_id(&expected_ids
[server_key
]);
4749 rc
= memcached_decrement(memc
, key
, strlen(key
), 1, &newvalue
);
4750 test_truth(rc
== MEMCACHED_SUCCESS
);
4751 return post_udp_op_check(memc
, expected_ids
);
4755 static test_return_t
udp_stat_test(memcached_st
*memc
)
4757 memcached_stat_st
* rv
= NULL
;
4758 memcached_return_t rc
;
4760 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4761 rv
= memcached_stat(memc
, args
, &rc
);
4763 test_truth(rc
== MEMCACHED_NOT_SUPPORTED
);
4764 return post_udp_op_check(memc
, expected_ids
);
4767 static test_return_t
udp_version_test(memcached_st
*memc
)
4769 memcached_return_t rc
;
4770 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4771 rc
= memcached_version(memc
);
4772 test_truth(rc
== MEMCACHED_NOT_SUPPORTED
);
4773 return post_udp_op_check(memc
, expected_ids
);
4776 static test_return_t
udp_get_test(memcached_st
*memc
)
4778 memcached_return_t rc
;
4779 const char *key
= "foo";
4781 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4782 char *val
= memcached_get(memc
, key
, strlen(key
), &vlen
, (uint32_t)0, &rc
);
4783 test_truth(rc
== MEMCACHED_NOT_SUPPORTED
);
4784 test_truth(val
== NULL
);
4785 return post_udp_op_check(memc
, expected_ids
);
4788 static test_return_t
udp_mixed_io_test(memcached_st
*memc
)
4791 test_st mixed_io_ops
[] ={
4793 (test_callback_fn
)udp_set_test
},
4794 {"udp_set_too_big_test", 0,
4795 (test_callback_fn
)udp_set_too_big_test
},
4796 {"udp_delete_test", 0,
4797 (test_callback_fn
)udp_delete_test
},
4798 {"udp_verbosity_test", 0,
4799 (test_callback_fn
)udp_verbosity_test
},
4800 {"udp_quit_test", 0,
4801 (test_callback_fn
)udp_quit_test
},
4802 {"udp_flush_test", 0,
4803 (test_callback_fn
)udp_flush_test
},
4804 {"udp_incr_test", 0,
4805 (test_callback_fn
)udp_incr_test
},
4806 {"udp_decr_test", 0,
4807 (test_callback_fn
)udp_decr_test
},
4808 {"udp_version_test", 0,
4809 (test_callback_fn
)udp_version_test
}
4812 for (x
= 0; x
< 500; x
++)
4814 current_op
= mixed_io_ops
[random() % 9];
4815 test_truth(current_op
.test_fn(memc
) == TEST_SUCCESS
);
4817 return TEST_SUCCESS
;
4821 static test_return_t
hash_sanity_test (memcached_st
*memc
)
4825 assert(MEMCACHED_HASH_DEFAULT
== MEMCACHED_HASH_DEFAULT
);
4826 assert(MEMCACHED_HASH_MD5
== MEMCACHED_HASH_MD5
);
4827 assert(MEMCACHED_HASH_CRC
== MEMCACHED_HASH_CRC
);
4828 assert(MEMCACHED_HASH_FNV1_64
== MEMCACHED_HASH_FNV1_64
);
4829 assert(MEMCACHED_HASH_FNV1A_64
== MEMCACHED_HASH_FNV1A_64
);
4830 assert(MEMCACHED_HASH_FNV1_32
== MEMCACHED_HASH_FNV1_32
);
4831 assert(MEMCACHED_HASH_FNV1A_32
== MEMCACHED_HASH_FNV1A_32
);
4832 #ifdef HAVE_HSIEH_HASH
4833 assert(MEMCACHED_HASH_HSIEH
== MEMCACHED_HASH_HSIEH
);
4835 assert(MEMCACHED_HASH_MURMUR
== MEMCACHED_HASH_MURMUR
);
4836 assert(MEMCACHED_HASH_JENKINS
== MEMCACHED_HASH_JENKINS
);
4837 assert(MEMCACHED_HASH_MAX
== MEMCACHED_HASH_MAX
);
4839 return TEST_SUCCESS
;
4843 static test_return_t
hsieh_avaibility_test (memcached_st
*memc
)
4845 memcached_return_t expected_rc
= MEMCACHED_FAILURE
;
4846 #ifdef HAVE_HSIEH_HASH
4847 expected_rc
= MEMCACHED_SUCCESS
;
4849 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
,
4850 (uint64_t)MEMCACHED_HASH_HSIEH
);
4851 test_truth(rc
== expected_rc
);
4852 return TEST_SUCCESS
;
4855 static test_return_t
md5_run (memcached_st
*memc
__attribute__((unused
)))
4860 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4864 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MD5
);
4865 test_truth(md5_values
[x
] == hash_val
);
4868 return TEST_SUCCESS
;
4871 static test_return_t
crc_run (memcached_st
*memc
__attribute__((unused
)))
4876 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4880 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_CRC
);
4881 test_truth(crc_values
[x
] == hash_val
);
4884 return TEST_SUCCESS
;
4887 static test_return_t
fnv1_64_run (memcached_st
*memc
__attribute__((unused
)))
4892 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4896 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_64
);
4897 test_truth(fnv1_64_values
[x
] == hash_val
);
4900 return TEST_SUCCESS
;
4903 static test_return_t
fnv1a_64_run (memcached_st
*memc
__attribute__((unused
)))
4908 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4912 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_64
);
4913 test_truth(fnv1a_64_values
[x
] == hash_val
);
4916 return TEST_SUCCESS
;
4919 static test_return_t
fnv1_32_run (memcached_st
*memc
__attribute__((unused
)))
4925 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4929 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_32
);
4930 test_truth(fnv1_32_values
[x
] == hash_val
);
4933 return TEST_SUCCESS
;
4936 static test_return_t
fnv1a_32_run (memcached_st
*memc
__attribute__((unused
)))
4941 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4945 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_32
);
4946 test_truth(fnv1a_32_values
[x
] == hash_val
);
4949 return TEST_SUCCESS
;
4952 static test_return_t
hsieh_run (memcached_st
*memc
__attribute__((unused
)))
4957 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4961 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_HSIEH
);
4962 test_truth(hsieh_values
[x
] == hash_val
);
4965 return TEST_SUCCESS
;
4968 static test_return_t
murmur_run (memcached_st
*memc
__attribute__((unused
)))
4971 return TEST_SKIPPED
;
4976 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4980 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MURMUR
);
4981 test_truth(murmur_values
[x
] == hash_val
);
4984 return TEST_SUCCESS
;
4988 static test_return_t
jenkins_run (memcached_st
*memc
__attribute__((unused
)))
4994 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4998 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_JENKINS
);
4999 test_truth(jenkins_values
[x
] == hash_val
);
5002 return TEST_SUCCESS
;
5006 static test_return_t
ketama_compatibility_libmemcached(memcached_st
*trash
)
5008 memcached_return_t rc
;
5011 memcached_server_st
*server_pool
;
5016 memc
= memcached_create(NULL
);
5019 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
5020 test_truth(rc
== MEMCACHED_SUCCESS
);
5022 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
5023 test_truth(value
== 1);
5025 test_truth(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
) == MEMCACHED_SUCCESS
);
5026 test_truth(memcached_behavior_get_distribution(memc
) == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
);
5029 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");
5030 memcached_server_push(memc
, server_pool
);
5032 /* verify that the server list was parsed okay. */
5033 test_truth(memcached_server_count(memc
) == 8);
5034 test_strcmp(server_pool
[0].hostname
, "10.0.1.1");
5035 test_truth(server_pool
[0].port
== 11211);
5036 test_truth(server_pool
[0].weight
== 600);
5037 test_strcmp(server_pool
[2].hostname
, "10.0.1.3");
5038 test_truth(server_pool
[2].port
== 11211);
5039 test_truth(server_pool
[2].weight
== 200);
5040 test_strcmp(server_pool
[7].hostname
, "10.0.1.8");
5041 test_truth(server_pool
[7].port
== 11211);
5042 test_truth(server_pool
[7].weight
== 100);
5044 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
5045 * us test the boundary wraparound.
5047 test_truth(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
5049 /* verify the standard ketama set. */
5050 for (x
= 0; x
< 99; x
++)
5052 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
5053 memcached_server_instance_st
*instance
=
5054 memcached_server_instance_fetch(memc
, server_idx
);
5055 char *hostname
= instance
->hostname
;
5057 test_strcmp(hostname
, ketama_test_cases
[x
].server
);
5060 memcached_server_list_free(server_pool
);
5061 memcached_free(memc
);
5063 return TEST_SUCCESS
;
5066 static test_return_t
ketama_compatibility_spymemcached(memcached_st
*trash
)
5068 memcached_return_t rc
;
5071 memcached_server_st
*server_pool
;
5076 memc
= memcached_create(NULL
);
5079 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
5080 test_truth(rc
== MEMCACHED_SUCCESS
);
5082 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
5083 test_truth(value
== 1);
5085 test_truth(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
) == MEMCACHED_SUCCESS
);
5086 test_truth(memcached_behavior_get_distribution(memc
) == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
);
5088 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");
5089 memcached_server_push(memc
, server_pool
);
5091 /* verify that the server list was parsed okay. */
5092 test_truth(memcached_server_count(memc
) == 8);
5093 test_strcmp(server_pool
[0].hostname
, "10.0.1.1");
5094 test_truth(server_pool
[0].port
== 11211);
5095 test_truth(server_pool
[0].weight
== 600);
5096 test_strcmp(server_pool
[2].hostname
, "10.0.1.3");
5097 test_truth(server_pool
[2].port
== 11211);
5098 test_truth(server_pool
[2].weight
== 200);
5099 test_strcmp(server_pool
[7].hostname
, "10.0.1.8");
5100 test_truth(server_pool
[7].port
== 11211);
5101 test_truth(server_pool
[7].weight
== 100);
5103 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
5104 * us test the boundary wraparound.
5106 test_truth(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
5108 /* verify the standard ketama set. */
5109 for (x
= 0; x
< 99; x
++)
5111 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases_spy
[x
].key
, strlen(ketama_test_cases_spy
[x
].key
));
5112 memcached_server_instance_st
*instance
=
5113 memcached_server_instance_fetch(memc
, server_idx
);
5114 char *hostname
= instance
->hostname
;
5115 test_strcmp(hostname
, ketama_test_cases_spy
[x
].server
);
5118 memcached_server_list_free(server_pool
);
5119 memcached_free(memc
);
5121 return TEST_SUCCESS
;
5124 static test_return_t
regression_bug_434484(memcached_st
*memc
)
5126 test_return_t test_rc
;
5127 test_rc
= pre_binary(memc
);
5129 if (test_rc
!= TEST_SUCCESS
)
5132 memcached_return_t ret
;
5133 const char *key
= "regression_bug_434484";
5134 size_t keylen
= strlen(key
);
5136 ret
= memcached_append(memc
, key
, keylen
, key
, keylen
, 0, 0);
5137 test_truth(ret
== MEMCACHED_NOTSTORED
);
5139 size_t size
= 2048 * 1024;
5140 void *data
= calloc(1, size
);
5141 test_truth(data
!= NULL
);
5142 ret
= memcached_set(memc
, key
, keylen
, data
, size
, 0, 0);
5143 test_truth(ret
== MEMCACHED_E2BIG
);
5146 return TEST_SUCCESS
;
5149 static test_return_t
regression_bug_434843(memcached_st
*memc
)
5151 test_return_t test_rc
;
5152 test_rc
= pre_binary(memc
);
5154 if (test_rc
!= TEST_SUCCESS
)
5157 memcached_return_t rc
;
5158 unsigned int counter
= 0;
5159 memcached_execute_fn callbacks
[1]= { [0]= &callback_counter
};
5162 * I only want to hit only _one_ server so I know the number of requests I'm
5163 * sending in the pipleine to the server. Let's try to do a multiget of
5164 * 1024 (that should satisfy most users don't you think?). Future versions
5165 * will include a mget_execute function call if you need a higher number.
5167 uint32_t number_of_hosts
= memcached_server_count(memc
);
5168 memc
->number_of_hosts
= 1;
5169 const size_t max_keys
= 1024;
5170 char **keys
= calloc(max_keys
, sizeof(char*));
5171 size_t *key_length
=calloc(max_keys
, sizeof(size_t));
5173 for (int x
= 0; x
< (int)max_keys
; ++x
)
5176 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%u", x
);
5178 test_truth(keys
[x
] != NULL
);
5182 * Run two times.. the first time we should have 100% cache miss,
5183 * and the second time we should have 100% cache hits
5185 for (int y
= 0; y
< 2; ++y
)
5187 rc
= memcached_mget(memc
, (const char**)keys
, key_length
, max_keys
);
5188 test_truth(rc
== MEMCACHED_SUCCESS
);
5189 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5192 /* The first iteration should give me a 100% cache miss. verify that*/
5193 test_truth(counter
== 0);
5194 char blob
[1024]= { 0 };
5195 for (int x
= 0; x
< (int)max_keys
; ++x
)
5197 rc
= memcached_add(memc
, keys
[x
], key_length
[x
],
5198 blob
, sizeof(blob
), 0, 0);
5199 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5204 /* Verify that we received all of the key/value pairs */
5205 test_truth(counter
== (unsigned int)max_keys
);
5209 /* Release allocated resources */
5210 for (size_t x
= 0; x
< max_keys
; ++x
)
5215 memc
->number_of_hosts
= number_of_hosts
;
5217 return TEST_SUCCESS
;
5220 static test_return_t
regression_bug_434843_buffered(memcached_st
*memc
)
5222 memcached_return_t rc
;
5223 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
5224 test_truth(rc
== MEMCACHED_SUCCESS
);
5226 return regression_bug_434843(memc
);
5229 static test_return_t
regression_bug_421108(memcached_st
*memc
)
5231 memcached_return_t rc
;
5232 memcached_stat_st
*memc_stat
= memcached_stat(memc
, NULL
, &rc
);
5233 test_truth(rc
== MEMCACHED_SUCCESS
);
5235 char *bytes
= memcached_stat_get_value(memc
, memc_stat
, "bytes", &rc
);
5236 test_truth(rc
== MEMCACHED_SUCCESS
);
5237 test_truth(bytes
!= NULL
);
5238 char *bytes_read
= memcached_stat_get_value(memc
, memc_stat
,
5240 test_truth(rc
== MEMCACHED_SUCCESS
);
5241 test_truth(bytes_read
!= NULL
);
5243 char *bytes_written
= memcached_stat_get_value(memc
, memc_stat
,
5244 "bytes_written", &rc
);
5245 test_truth(rc
== MEMCACHED_SUCCESS
);
5246 test_truth(bytes_written
!= NULL
);
5248 test_truth(strcmp(bytes
, bytes_read
) != 0);
5249 test_truth(strcmp(bytes
, bytes_written
) != 0);
5251 /* Release allocated resources */
5254 free(bytes_written
);
5255 memcached_stat_free(NULL
, memc_stat
);
5257 return TEST_SUCCESS
;
5261 * The test case isn't obvious so I should probably document why
5262 * it works the way it does. Bug 442914 was caused by a bug
5263 * in the logic in memcached_purge (it did not handle the case
5264 * where the number of bytes sent was equal to the watermark).
5265 * In this test case, create messages so that we hit that case
5266 * and then disable noreply mode and issue a new command to
5267 * verify that it isn't stuck. If we change the format for the
5268 * delete command or the watermarks, we need to update this
5271 static test_return_t
regression_bug_442914(memcached_st
*memc
)
5273 memcached_return_t rc
;
5274 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
5275 test_truth(rc
== MEMCACHED_SUCCESS
);
5276 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1);
5278 uint32_t number_of_hosts
= memcached_server_count(memc
);
5279 memc
->number_of_hosts
= 1;
5284 for (int x
= 0; x
< 250; ++x
)
5286 len
= (size_t)snprintf(k
, sizeof(k
), "%0250u", x
);
5287 rc
= memcached_delete(memc
, k
, len
, 0);
5288 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5291 len
= (size_t)snprintf(k
, sizeof(k
), "%037u", 251);
5292 rc
= memcached_delete(memc
, k
, len
, 0);
5293 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5295 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0);
5296 test_truth(rc
== MEMCACHED_SUCCESS
);
5297 rc
= memcached_delete(memc
, k
, len
, 0);
5298 test_truth(rc
== MEMCACHED_NOTFOUND
);
5300 memc
->number_of_hosts
= number_of_hosts
;
5302 return TEST_SUCCESS
;
5305 static test_return_t
regression_bug_447342(memcached_st
*memc
)
5307 memcached_server_instance_st
*instance_one
;
5308 memcached_server_instance_st
*instance_two
;
5310 if (memcached_server_count(memc
) < 3 || pre_replication(memc
) != MEMCACHED_SUCCESS
)
5311 return TEST_SKIPPED
;
5313 memcached_return_t rc
;
5315 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 2);
5316 test_truth(rc
== MEMCACHED_SUCCESS
);
5318 const size_t max_keys
= 100;
5319 char **keys
= calloc(max_keys
, sizeof(char*));
5320 size_t *key_length
= calloc(max_keys
, sizeof(size_t));
5322 for (uint64_t x
= 0; x
< max_keys
; ++x
)
5325 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%"PRIu64
, x
);
5327 test_truth(keys
[x
] != NULL
);
5328 rc
= memcached_set(memc
, k
, key_length
[x
], k
, key_length
[x
], 0, 0);
5329 test_truth(rc
== MEMCACHED_SUCCESS
);
5333 ** We are using the quiet commands to store the replicas, so we need
5334 ** to ensure that all of them are processed before we can continue.
5335 ** In the test we go directly from storing the object to trying to
5336 ** receive the object from all of the different servers, so we
5337 ** could end up in a race condition (the memcached server hasn't yet
5338 ** processed the quiet command from the replication set when it process
5339 ** the request from the other client (created by the clone)). As a
5340 ** workaround for that we call memcached_quit to send the quit command
5341 ** to the server and wait for the response ;-) If you use the test code
5342 ** as an example for your own code, please note that you shouldn't need
5345 memcached_quit(memc
);
5347 /* Verify that all messages are stored, and we didn't stuff too much
5350 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5351 test_truth(rc
== MEMCACHED_SUCCESS
);
5353 unsigned int counter
= 0;
5354 memcached_execute_fn callbacks
[1]= { [0]= &callback_counter
};
5355 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5356 /* Verify that we received all of the key/value pairs */
5357 test_truth(counter
== (unsigned int)max_keys
);
5359 memcached_quit(memc
);
5361 * Don't do the following in your code. I am abusing the internal details
5362 * within the library, and this is not a supported interface.
5363 * This is to verify correct behavior in the library. Fake that two servers
5366 instance_one
= memcached_server_instance_fetch(memc
, 0);
5367 instance_two
= memcached_server_instance_fetch(memc
, 2);
5368 in_port_t port0
= instance_one
->port
;
5369 in_port_t port2
= instance_two
->port
;
5371 instance_one
->port
= 0;
5372 instance_two
->port
= 0;
5374 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5375 test_truth(rc
== MEMCACHED_SUCCESS
);
5378 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5379 test_truth(counter
== (unsigned int)max_keys
);
5381 /* restore the memc handle */
5382 instance_one
->port
= port0
;
5383 instance_two
->port
= port2
;
5385 memcached_quit(memc
);
5387 /* Remove half of the objects */
5388 for (size_t x
= 0; x
< max_keys
; ++x
)
5392 rc
= memcached_delete(memc
, keys
[x
], key_length
[x
], 0);
5393 test_truth(rc
== MEMCACHED_SUCCESS
);
5397 memcached_quit(memc
);
5398 instance_one
->port
= 0;
5399 instance_two
->port
= 0;
5401 /* now retry the command, this time we should have cache misses */
5402 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5403 test_truth(rc
== MEMCACHED_SUCCESS
);
5406 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5407 test_truth(counter
== (unsigned int)(max_keys
>> 1));
5409 /* Release allocated resources */
5410 for (size_t x
= 0; x
< max_keys
; ++x
)
5417 /* restore the memc handle */
5418 instance_one
->port
= port0
;
5419 instance_two
->port
= port2
;
5421 return TEST_SUCCESS
;
5424 static test_return_t
regression_bug_463297(memcached_st
*memc
)
5426 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
5427 test_truth(memc_clone
!= NULL
);
5428 test_truth(memcached_version(memc_clone
) == MEMCACHED_SUCCESS
);
5430 memcached_server_instance_st
*instance
=
5431 memcached_server_instance_fetch(memc_clone
, 0);
5433 if (instance
->major_version
> 1 ||
5434 (instance
->major_version
== 1 &&
5435 instance
->minor_version
> 2))
5437 /* Binary protocol doesn't support deferred delete */
5438 memcached_st
*bin_clone
= memcached_clone(NULL
, memc
);
5439 test_truth(bin_clone
!= NULL
);
5440 test_truth(memcached_behavior_set(bin_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1) == MEMCACHED_SUCCESS
);
5441 test_truth(memcached_delete(bin_clone
, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS
);
5442 memcached_free(bin_clone
);
5444 memcached_quit(memc_clone
);
5446 /* If we know the server version, deferred delete should fail
5447 * with invalid arguments */
5448 test_truth(memcached_delete(memc_clone
, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS
);
5450 /* If we don't know the server version, we should get a protocol error */
5451 memcached_return_t rc
= memcached_delete(memc
, "foo", 3, 1);
5453 /* but there is a bug in some of the memcached servers (1.4) that treats
5454 * the counter as noreply so it doesn't send the proper error message
5456 test_truth(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5458 /* And buffered mode should be disabled and we should get protocol error */
5459 test_truth(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1) == MEMCACHED_SUCCESS
);
5460 rc
= memcached_delete(memc
, "foo", 3, 1);
5461 test_truth(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5463 /* Same goes for noreply... */
5464 test_truth(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1) == MEMCACHED_SUCCESS
);
5465 rc
= memcached_delete(memc
, "foo", 3, 1);
5466 test_truth(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5468 /* but a normal request should go through (and be buffered) */
5469 test_truth((rc
= memcached_delete(memc
, "foo", 3, 0)) == MEMCACHED_BUFFERED
);
5470 test_truth(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
5472 test_truth(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 0) == MEMCACHED_SUCCESS
);
5473 /* unbuffered noreply should be success */
5474 test_truth(memcached_delete(memc
, "foo", 3, 0) == MEMCACHED_SUCCESS
);
5475 /* unbuffered with reply should be not found... */
5476 test_truth(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0) == MEMCACHED_SUCCESS
);
5477 test_truth(memcached_delete(memc
, "foo", 3, 0) == MEMCACHED_NOTFOUND
);
5480 memcached_free(memc_clone
);
5481 return TEST_SUCCESS
;
5485 /* Test memcached_server_get_last_disconnect
5486 * For a working server set, shall be NULL
5487 * For a set of non existing server, shall not be NULL
5489 static test_return_t
test_get_last_disconnect(memcached_st
*memc
)
5491 memcached_return_t rc
;
5492 memcached_server_st
*disconnected_server
;
5494 /* With the working set of server */
5495 const char *key
= "marmotte";
5496 const char *value
= "milka";
5498 rc
= memcached_set(memc
, key
, strlen(key
),
5499 value
, strlen(value
),
5500 (time_t)0, (uint32_t)0);
5501 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5503 disconnected_server
= memcached_server_get_last_disconnect(memc
);
5504 test_truth(disconnected_server
== NULL
);
5506 /* With a non existing server */
5508 memcached_server_st
*servers
;
5510 const char *server_list
= "localhost:9";
5512 servers
= memcached_servers_parse(server_list
);
5513 test_truth(servers
);
5514 mine
= memcached_create(NULL
);
5515 rc
= memcached_server_push(mine
, servers
);
5516 test_truth(rc
== MEMCACHED_SUCCESS
);
5517 memcached_server_list_free(servers
);
5520 rc
= memcached_set(mine
, key
, strlen(key
),
5521 value
, strlen(value
),
5522 (time_t)0, (uint32_t)0);
5523 test_truth(rc
!= MEMCACHED_SUCCESS
);
5525 disconnected_server
= memcached_server_get_last_disconnect(mine
);
5526 test_truth(disconnected_server
!= NULL
);
5527 test_truth(disconnected_server
->port
== 9);
5528 test_truth(strncmp(disconnected_server
->hostname
,"localhost",9) == 0);
5530 memcached_quit(mine
);
5531 memcached_free(mine
);
5533 return TEST_SUCCESS
;
5537 * This test ensures that the failure counter isn't incremented during
5538 * normal termination of the memcached instance.
5540 static test_return_t
wrong_failure_counter_test(memcached_st
*memc
)
5542 memcached_return_t rc
;
5543 memcached_server_instance_st
*instance
;
5545 /* Set value to force connection to the server */
5546 const char *key
= "marmotte";
5547 const char *value
= "milka";
5550 * Please note that I'm abusing the internal structures in libmemcached
5551 * in a non-portable way and you shouldn't be doing this. I'm only
5552 * doing this in order to verify that the library works the way it should
5554 uint32_t number_of_hosts
= memcached_server_count(memc
);
5555 memc
->number_of_hosts
= 1;
5557 /* Ensure that we are connected to the server by setting a value */
5558 rc
= memcached_set(memc
, key
, strlen(key
),
5559 value
, strlen(value
),
5560 (time_t)0, (uint32_t)0);
5561 test_truth(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5564 instance
= memcached_server_instance_fetch(memc
, 0);
5565 /* The test is to see that the memcached_quit doesn't increase the
5566 * the server failure conter, so let's ensure that it is zero
5567 * before sending quit
5569 instance
->server_failure_counter
= 0;
5571 memcached_quit(memc
);
5573 /* Verify that it memcached_quit didn't increment the failure counter
5574 * Please note that this isn't bullet proof, because an error could
5577 test_truth(instance
->server_failure_counter
== 0);
5579 /* restore the instance */
5580 memc
->number_of_hosts
= number_of_hosts
;
5582 return TEST_SUCCESS
;
5585 test_st udp_setup_server_tests
[] ={
5586 {"set_udp_behavior_test", 0, (test_callback_fn
)set_udp_behavior_test
},
5587 {"add_tcp_server_udp_client_test", 0, (test_callback_fn
)add_tcp_server_udp_client_test
},
5588 {"add_udp_server_tcp_client_test", 0, (test_callback_fn
)add_udp_server_tcp_client_test
},
5592 test_st upd_io_tests
[] ={
5593 {"udp_set_test", 0, (test_callback_fn
)udp_set_test
},
5594 {"udp_buffered_set_test", 0, (test_callback_fn
)udp_buffered_set_test
},
5595 {"udp_set_too_big_test", 0, (test_callback_fn
)udp_set_too_big_test
},
5596 {"udp_delete_test", 0, (test_callback_fn
)udp_delete_test
},
5597 {"udp_buffered_delete_test", 0, (test_callback_fn
)udp_buffered_delete_test
},
5598 {"udp_verbosity_test", 0, (test_callback_fn
)udp_verbosity_test
},
5599 {"udp_quit_test", 0, (test_callback_fn
)udp_quit_test
},
5600 {"udp_flush_test", 0, (test_callback_fn
)udp_flush_test
},
5601 {"udp_incr_test", 0, (test_callback_fn
)udp_incr_test
},
5602 {"udp_decr_test", 0, (test_callback_fn
)udp_decr_test
},
5603 {"udp_stat_test", 0, (test_callback_fn
)udp_stat_test
},
5604 {"udp_version_test", 0, (test_callback_fn
)udp_version_test
},
5605 {"udp_get_test", 0, (test_callback_fn
)udp_get_test
},
5606 {"udp_mixed_io_test", 0, (test_callback_fn
)udp_mixed_io_test
},
5610 /* Clean the server before beginning testing */
5612 {"flush", 0, (test_callback_fn
)flush_test
},
5613 {"init", 0, (test_callback_fn
)init_test
},
5614 {"allocation", 0, (test_callback_fn
)allocation_test
},
5615 {"server_list_null_test", 0, (test_callback_fn
)server_list_null_test
},
5616 {"server_unsort", 0, (test_callback_fn
)server_unsort_test
},
5617 {"server_sort", 0, (test_callback_fn
)server_sort_test
},
5618 {"server_sort2", 0, (test_callback_fn
)server_sort2_test
},
5619 {"clone_test", 0, (test_callback_fn
)clone_test
},
5620 {"connection_test", 0, (test_callback_fn
)connection_test
},
5621 {"callback_test", 0, (test_callback_fn
)callback_test
},
5622 {"userdata_test", 0, (test_callback_fn
)userdata_test
},
5623 {"error", 0, (test_callback_fn
)error_test
},
5624 {"set", 0, (test_callback_fn
)set_test
},
5625 {"set2", 0, (test_callback_fn
)set_test2
},
5626 {"set3", 0, (test_callback_fn
)set_test3
},
5627 {"dump", 1, (test_callback_fn
)dump_test
},
5628 {"add", 1, (test_callback_fn
)add_test
},
5629 {"replace", 1, (test_callback_fn
)replace_test
},
5630 {"delete", 1, (test_callback_fn
)delete_test
},
5631 {"get", 1, (test_callback_fn
)get_test
},
5632 {"get2", 0, (test_callback_fn
)get_test2
},
5633 {"get3", 0, (test_callback_fn
)get_test3
},
5634 {"get4", 0, (test_callback_fn
)get_test4
},
5635 {"partial mget", 0, (test_callback_fn
)get_test5
},
5636 {"stats_servername", 0, (test_callback_fn
)stats_servername_test
},
5637 {"increment", 0, (test_callback_fn
)increment_test
},
5638 {"increment_with_initial", 1, (test_callback_fn
)increment_with_initial_test
},
5639 {"decrement", 0, (test_callback_fn
)decrement_test
},
5640 {"decrement_with_initial", 1, (test_callback_fn
)decrement_with_initial_test
},
5641 {"increment_by_key", 0, (test_callback_fn
)increment_by_key_test
},
5642 {"increment_with_initial_by_key", 1, (test_callback_fn
)increment_with_initial_by_key_test
},
5643 {"decrement_by_key", 0, (test_callback_fn
)decrement_by_key_test
},
5644 {"decrement_with_initial_by_key", 1, (test_callback_fn
)decrement_with_initial_by_key_test
},
5645 {"quit", 0, (test_callback_fn
)quit_test
},
5646 {"mget", 1, (test_callback_fn
)mget_test
},
5647 {"mget_result", 1, (test_callback_fn
)mget_result_test
},
5648 {"mget_result_alloc", 1, (test_callback_fn
)mget_result_alloc_test
},
5649 {"mget_result_function", 1, (test_callback_fn
)mget_result_function
},
5650 {"mget_execute", 1, (test_callback_fn
)mget_execute
},
5651 {"mget_end", 0, (test_callback_fn
)mget_end
},
5652 {"get_stats", 0, (test_callback_fn
)get_stats
},
5653 {"add_host_test", 0, (test_callback_fn
)add_host_test
},
5654 {"add_host_test_1", 0, (test_callback_fn
)add_host_test1
},
5655 {"get_stats_keys", 0, (test_callback_fn
)get_stats_keys
},
5656 {"version_string_test", 0, (test_callback_fn
)version_string_test
},
5657 {"bad_key", 1, (test_callback_fn
)bad_key_test
},
5658 {"memcached_server_cursor", 1, (test_callback_fn
)memcached_server_cursor_test
},
5659 {"read_through", 1, (test_callback_fn
)read_through
},
5660 {"delete_through", 1, (test_callback_fn
)delete_through
},
5661 {"noreply", 1, (test_callback_fn
)noreply_test
},
5662 {"analyzer", 1, (test_callback_fn
)analyzer_test
},
5663 #ifdef HAVE_LIBMEMCACHEDUTIL
5664 {"connectionpool", 1, (test_callback_fn
)connection_pool_test
},
5666 {"test_get_last_disconnect", 1, (test_callback_fn
)test_get_last_disconnect
},
5670 test_st behavior_tests
[] ={
5671 {"behavior_test", 0, (test_callback_fn
)behavior_test
},
5675 test_st async_tests
[] ={
5676 {"add", 1, (test_callback_fn
)add_wrapper
},
5680 test_st string_tests
[] ={
5681 {"string static with null", 0, (test_callback_fn
)string_static_null
},
5682 {"string alloc with null", 0, (test_callback_fn
)string_alloc_null
},
5683 {"string alloc with 1K", 0, (test_callback_fn
)string_alloc_with_size
},
5684 {"string alloc with malloc failure", 0, (test_callback_fn
)string_alloc_with_size_toobig
},
5685 {"string append", 0, (test_callback_fn
)string_alloc_append
},
5686 {"string append failure (too big)", 0, (test_callback_fn
)string_alloc_append_toobig
},
5687 {0, 0, (test_callback_fn
)0}
5690 test_st result_tests
[] ={
5691 {"result static", 0, (test_callback_fn
)result_static
},
5692 {"result alloc", 0, (test_callback_fn
)result_alloc
},
5693 {0, 0, (test_callback_fn
)0}
5696 test_st version_1_2_3
[] ={
5697 {"append", 0, (test_callback_fn
)append_test
},
5698 {"prepend", 0, (test_callback_fn
)prepend_test
},
5699 {"cas", 0, (test_callback_fn
)cas_test
},
5700 {"cas2", 0, (test_callback_fn
)cas2_test
},
5701 {"append_binary", 0, (test_callback_fn
)append_binary_test
},
5702 {0, 0, (test_callback_fn
)0}
5705 test_st user_tests
[] ={
5706 {"user_supplied_bug1", 0, (test_callback_fn
)user_supplied_bug1
},
5707 {"user_supplied_bug2", 0, (test_callback_fn
)user_supplied_bug2
},
5708 {"user_supplied_bug3", 0, (test_callback_fn
)user_supplied_bug3
},
5709 {"user_supplied_bug4", 0, (test_callback_fn
)user_supplied_bug4
},
5710 {"user_supplied_bug5", 1, (test_callback_fn
)user_supplied_bug5
},
5711 {"user_supplied_bug6", 1, (test_callback_fn
)user_supplied_bug6
},
5712 {"user_supplied_bug7", 1, (test_callback_fn
)user_supplied_bug7
},
5713 {"user_supplied_bug8", 1, (test_callback_fn
)user_supplied_bug8
},
5714 {"user_supplied_bug9", 1, (test_callback_fn
)user_supplied_bug9
},
5715 {"user_supplied_bug10", 1, (test_callback_fn
)user_supplied_bug10
},
5716 {"user_supplied_bug11", 1, (test_callback_fn
)user_supplied_bug11
},
5717 {"user_supplied_bug12", 1, (test_callback_fn
)user_supplied_bug12
},
5718 {"user_supplied_bug13", 1, (test_callback_fn
)user_supplied_bug13
},
5719 {"user_supplied_bug14", 1, (test_callback_fn
)user_supplied_bug14
},
5720 {"user_supplied_bug15", 1, (test_callback_fn
)user_supplied_bug15
},
5721 {"user_supplied_bug16", 1, (test_callback_fn
)user_supplied_bug16
},
5724 ** It seems to be something weird with the character sets..
5725 ** value_fetch is unable to parse the value line (iscntrl "fails"), so I
5726 ** guess I need to find out how this is supposed to work.. Perhaps I need
5727 ** to run the test in a specific locale (I tried zh_CN.UTF-8 without success,
5728 ** so just disable the code for now...).
5730 {"user_supplied_bug17", 1, (test_callback_fn
)user_supplied_bug17
},
5732 {"user_supplied_bug18", 1, (test_callback_fn
)user_supplied_bug18
},
5733 {"user_supplied_bug19", 1, (test_callback_fn
)user_supplied_bug19
},
5734 {"user_supplied_bug20", 1, (test_callback_fn
)user_supplied_bug20
},
5735 {"user_supplied_bug21", 1, (test_callback_fn
)user_supplied_bug21
},
5736 {"wrong_failure_counter_test", 1, (test_callback_fn
)wrong_failure_counter_test
},
5737 {0, 0, (test_callback_fn
)0}
5740 test_st replication_tests
[]= {
5741 {"set", 1, (test_callback_fn
)replication_set_test
},
5742 {"get", 0, (test_callback_fn
)replication_get_test
},
5743 {"mget", 0, (test_callback_fn
)replication_mget_test
},
5744 {"delete", 0, (test_callback_fn
)replication_delete_test
},
5745 {"rand_mget", 0, (test_callback_fn
)replication_randomize_mget_test
},
5746 {0, 0, (test_callback_fn
)0}
5750 * The following test suite is used to verify that we don't introduce
5751 * regression bugs. If you want more information about the bug / test,
5752 * you should look in the bug report at
5753 * http://bugs.launchpad.net/libmemcached
5755 test_st regression_tests
[]= {
5756 {"lp:434484", 1, (test_callback_fn
)regression_bug_434484
},
5757 {"lp:434843", 1, (test_callback_fn
)regression_bug_434843
},
5758 {"lp:434843 buffered", 1, (test_callback_fn
)regression_bug_434843_buffered
},
5759 {"lp:421108", 1, (test_callback_fn
)regression_bug_421108
},
5760 {"lp:442914", 1, (test_callback_fn
)regression_bug_442914
},
5761 {"lp:447342", 1, (test_callback_fn
)regression_bug_447342
},
5762 {"lp:463297", 1, (test_callback_fn
)regression_bug_463297
},
5763 {0, 0, (test_callback_fn
)0}
5766 test_st ketama_compatibility
[]= {
5767 {"libmemcached", 1, (test_callback_fn
)ketama_compatibility_libmemcached
},
5768 {"spymemcached", 1, (test_callback_fn
)ketama_compatibility_spymemcached
},
5769 {0, 0, (test_callback_fn
)0}
5772 test_st generate_tests
[] ={
5773 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
5774 {"generate_data", 1, (test_callback_fn
)generate_data
},
5775 {"get_read", 0, (test_callback_fn
)get_read
},
5776 {"delete_generate", 0, (test_callback_fn
)delete_generate
},
5777 {"generate_buffer_data", 1, (test_callback_fn
)generate_buffer_data
},
5778 {"delete_buffer", 0, (test_callback_fn
)delete_buffer_generate
},
5779 {"generate_data", 1, (test_callback_fn
)generate_data
},
5780 {"mget_read", 0, (test_callback_fn
)mget_read
},
5781 {"mget_read_result", 0, (test_callback_fn
)mget_read_result
},
5782 {"mget_read_function", 0, (test_callback_fn
)mget_read_function
},
5783 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5784 {"generate_large_pairs", 1, (test_callback_fn
)generate_large_pairs
},
5785 {"generate_data", 1, (test_callback_fn
)generate_data
},
5786 {"generate_buffer_data", 1, (test_callback_fn
)generate_buffer_data
},
5787 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5788 {0, 0, (test_callback_fn
)0}
5791 test_st consistent_tests
[] ={
5792 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
5793 {"generate_data", 1, (test_callback_fn
)generate_data
},
5794 {"get_read", 0, (test_callback_fn
)get_read_count
},
5795 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5796 {0, 0, (test_callback_fn
)0}
5799 test_st consistent_weighted_tests
[] ={
5800 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
5801 {"generate_data", 1, (test_callback_fn
)generate_data_with_stats
},
5802 {"get_read", 0, (test_callback_fn
)get_read_count
},
5803 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5804 {0, 0, (test_callback_fn
)0}
5807 test_st hsieh_availability
[] ={
5808 {"hsieh_avaibility_test", 0, (test_callback_fn
)hsieh_avaibility_test
},
5809 {0, 0, (test_callback_fn
)0}
5813 test_st hash_sanity
[] ={
5814 {"hash sanity", 0, (test_callback_fn
)hash_sanity_test
},
5815 {0, 0, (test_callback_fn
)0}
5819 test_st ketama_auto_eject_hosts
[] ={
5820 {"auto_eject_hosts", 1, (test_callback_fn
)auto_eject_hosts
},
5821 {"output_ketama_weighted_keys", 1, (test_callback_fn
)output_ketama_weighted_keys
},
5822 {0, 0, (test_callback_fn
)0}
5825 test_st hash_tests
[] ={
5826 {"md5", 0, (test_callback_fn
)md5_run
},
5827 {"crc", 0, (test_callback_fn
)crc_run
},
5828 {"fnv1_64", 0, (test_callback_fn
)fnv1_64_run
},
5829 {"fnv1a_64", 0, (test_callback_fn
)fnv1a_64_run
},
5830 {"fnv1_32", 0, (test_callback_fn
)fnv1_32_run
},
5831 {"fnv1a_32", 0, (test_callback_fn
)fnv1a_32_run
},
5832 {"hsieh", 0, (test_callback_fn
)hsieh_run
},
5833 {"murmur", 0, (test_callback_fn
)murmur_run
},
5834 {"jenkis", 0, (test_callback_fn
)jenkins_run
},
5835 {0, 0, (test_callback_fn
)0}
5838 collection_st collection
[] ={
5840 {"hash_sanity", 0, 0, hash_sanity
},
5842 {"hsieh_availability", 0, 0, hsieh_availability
},
5843 {"udp_setup", (test_callback_fn
)init_udp
, 0, udp_setup_server_tests
},
5844 {"udp_io", (test_callback_fn
)init_udp
, 0, upd_io_tests
},
5845 {"udp_binary_io", (test_callback_fn
)binary_init_udp
, 0, upd_io_tests
},
5846 {"block", 0, 0, tests
},
5847 {"binary", (test_callback_fn
)pre_binary
, 0, tests
},
5848 {"nonblock", (test_callback_fn
)pre_nonblock
, 0, tests
},
5849 {"nodelay", (test_callback_fn
)pre_nodelay
, 0, tests
},
5850 {"settimer", (test_callback_fn
)pre_settimer
, 0, tests
},
5851 {"md5", (test_callback_fn
)pre_md5
, 0, tests
},
5852 {"crc", (test_callback_fn
)pre_crc
, 0, tests
},
5853 {"hsieh", (test_callback_fn
)pre_hsieh
, 0, tests
},
5854 {"jenkins", (test_callback_fn
)pre_jenkins
, 0, tests
},
5855 {"fnv1_64", (test_callback_fn
)pre_hash_fnv1_64
, 0, tests
},
5856 {"fnv1a_64", (test_callback_fn
)pre_hash_fnv1a_64
, 0, tests
},
5857 {"fnv1_32", (test_callback_fn
)pre_hash_fnv1_32
, 0, tests
},
5858 {"fnv1a_32", (test_callback_fn
)pre_hash_fnv1a_32
, 0, tests
},
5859 {"ketama", (test_callback_fn
)pre_behavior_ketama
, 0, tests
},
5860 {"ketama_auto_eject_hosts", (test_callback_fn
)pre_behavior_ketama
, 0, ketama_auto_eject_hosts
},
5861 {"unix_socket", (test_callback_fn
)pre_unix_socket
, 0, tests
},
5862 {"unix_socket_nodelay", (test_callback_fn
)pre_nodelay
, 0, tests
},
5863 {"poll_timeout", (test_callback_fn
)poll_timeout
, 0, tests
},
5864 {"gets", (test_callback_fn
)enable_cas
, 0, tests
},
5865 {"consistent_crc", (test_callback_fn
)enable_consistent_crc
, 0, tests
},
5866 {"consistent_hsieh", (test_callback_fn
)enable_consistent_hsieh
, 0, tests
},
5867 #ifdef MEMCACHED_ENABLE_DEPRECATED
5868 {"deprecated_memory_allocators", (test_callback_fn
)deprecated_set_memory_alloc
, 0, tests
},
5870 {"memory_allocators", (test_callback_fn
)set_memory_alloc
, 0, tests
},
5871 {"prefix", (test_callback_fn
)set_prefix
, 0, tests
},
5872 {"version_1_2_3", (test_callback_fn
)check_for_1_2_3
, 0, version_1_2_3
},
5873 {"string", 0, 0, string_tests
},
5874 {"result", 0, 0, result_tests
},
5875 {"async", (test_callback_fn
)pre_nonblock
, 0, async_tests
},
5876 {"async_binary", (test_callback_fn
)pre_nonblock_binary
, 0, async_tests
},
5877 {"user", 0, 0, user_tests
},
5878 {"generate", 0, 0, generate_tests
},
5879 {"generate_hsieh", (test_callback_fn
)pre_hsieh
, 0, generate_tests
},
5880 {"generate_ketama", (test_callback_fn
)pre_behavior_ketama
, 0, generate_tests
},
5881 {"generate_hsieh_consistent", (test_callback_fn
)enable_consistent_hsieh
, 0, generate_tests
},
5882 {"generate_md5", (test_callback_fn
)pre_md5
, 0, generate_tests
},
5883 {"generate_murmur", (test_callback_fn
)pre_murmur
, 0, generate_tests
},
5884 {"generate_jenkins", (test_callback_fn
)pre_jenkins
, 0, generate_tests
},
5885 {"generate_nonblock", (test_callback_fn
)pre_nonblock
, 0, generate_tests
},
5886 {"consistent_not", 0, 0, consistent_tests
},
5887 {"consistent_ketama", (test_callback_fn
)pre_behavior_ketama
, 0, consistent_tests
},
5888 {"consistent_ketama_weighted", (test_callback_fn
)pre_behavior_ketama_weighted
, 0, consistent_weighted_tests
},
5889 {"ketama_compat", 0, 0, ketama_compatibility
},
5890 {"test_hashes", 0, 0, hash_tests
},
5891 {"replication", (test_callback_fn
)pre_replication
, 0, replication_tests
},
5892 {"replication_noblock", (test_callback_fn
)pre_replication_noblock
, 0, replication_tests
},
5893 {"regression", 0, 0, regression_tests
},
5894 {"behaviors", 0, 0, behavior_tests
},
5898 #define SERVERS_TO_CREATE 5
5900 #include "libmemcached_world.h"
5902 void get_world(world_st
*world
)
5904 world
->collections
= collection
;
5906 world
->create
= (test_callback_create_fn
)world_create
;
5907 world
->destroy
= (test_callback_fn
)world_destroy
;
5909 world
->test
.startup
= (test_callback_fn
)world_test_startup
;
5910 world
->test
.flush
= (test_callback_fn
)world_flush
;
5911 world
->test
.pre_run
= (test_callback_fn
)world_pre_run
;
5912 world
->test
.post_run
= (test_callback_fn
)world_post_run
;
5913 world
->test
.on_error
= (test_callback_error_fn
)world_on_error
;
5915 world
->collection
.startup
= (test_callback_fn
)world_container_startup
;
5916 world
->collection
.shutdown
= (test_callback_fn
)world_container_shutdown
;
5918 world
->runner
= &defualt_libmemcached_runner
;