1 /* libMemcached Functions Test
2 * Copyright (C) 2006-2009 Brian Aker
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
10 Sample test application.
13 #include "libmemcached/common.h"
20 #include <sys/types.h>
26 #include "clients/generator.h"
27 #include "clients/execute.h"
30 #define INT64_MAX LONG_MAX
33 #define INT32_MAX INT_MAX
39 #ifdef HAVE_LIBMEMCACHEDUTIL
41 #include "libmemcached/memcached_util.h"
44 #include "hash_results.h"
46 #define GLOBAL_COUNT 10000
47 #define GLOBAL2_COUNT 100
48 #define SERVERS_TO_CREATE 5
49 static uint32_t global_count
;
51 static pairs_st
*global_pairs
;
52 static const char *global_keys
[GLOBAL_COUNT
];
53 static size_t global_keys_length
[GLOBAL_COUNT
];
55 static test_return_t
init_test(memcached_st
*not_used
__attribute__((unused
)))
59 (void)memcached_create(&memc
);
60 memcached_free(&memc
);
65 static test_return_t
server_list_null_test(memcached_st
*ptr
__attribute__((unused
)))
67 memcached_server_st
*server_list
;
68 memcached_return_t rc
;
70 server_list
= memcached_server_list_append_with_weight(NULL
, NULL
, 0, 0, NULL
);
71 test_true(server_list
== NULL
);
73 server_list
= memcached_server_list_append_with_weight(NULL
, "localhost", 0, 0, NULL
);
74 test_true(server_list
== NULL
);
76 server_list
= memcached_server_list_append_with_weight(NULL
, NULL
, 0, 0, &rc
);
77 test_true(server_list
== NULL
);
82 #define TEST_PORT_COUNT 7
83 in_port_t test_ports
[TEST_PORT_COUNT
];
85 static memcached_return_t
server_display_function(const memcached_st
*ptr
__attribute__((unused
)),
86 memcached_server_st
*server
, void *context
)
89 size_t bigger
= *((size_t *)(context
));
90 assert(bigger
<= server
->port
);
91 *((size_t *)(context
))= server
->port
;
93 return MEMCACHED_SUCCESS
;
96 static test_return_t
server_sort_test(memcached_st
*ptr
__attribute__((unused
)))
98 size_t bigger
= 0; /* Prime the value for the test_true in server_display_function */
100 memcached_return_t rc
;
101 memcached_server_fn callbacks
[1];
102 memcached_st
*local_memc
;
104 local_memc
= memcached_create(NULL
);
105 test_true(local_memc
);
106 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
108 for (size_t x
= 0; x
< TEST_PORT_COUNT
; x
++)
110 test_ports
[x
]= (in_port_t
)random() % 64000;
111 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
112 test_true(memcached_server_count(local_memc
) == x
+ 1);
113 test_true(memcached_servers_count(memcached_server_list(local_memc
)) == x
+1);
114 test_true(rc
== MEMCACHED_SUCCESS
);
117 callbacks
[0]= server_display_function
;
118 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
121 memcached_free(local_memc
);
126 static test_return_t
server_sort2_test(memcached_st
*ptr
__attribute__((unused
)))
128 size_t bigger
= 0; /* Prime the value for the test_true in server_display_function */
129 memcached_return_t rc
;
130 memcached_server_fn callbacks
[1];
131 memcached_st
*local_memc
;
132 memcached_server_instance_st
*instance
;
134 local_memc
= memcached_create(NULL
);
135 test_true(local_memc
);
136 rc
= memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
137 test_true(rc
== MEMCACHED_SUCCESS
);
139 rc
= memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43043, 0);
140 test_true(rc
== MEMCACHED_SUCCESS
);
141 instance
= memcached_server_instance_fetch(local_memc
, 0);
142 test_true(instance
->port
== 43043);
144 rc
= memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43042, 0);
145 test_true(rc
== MEMCACHED_SUCCESS
);
147 instance
= memcached_server_instance_fetch(local_memc
, 0);
148 test_true(instance
->port
== 43042);
150 instance
= memcached_server_instance_fetch(local_memc
, 1);
151 test_true(instance
->port
== 43043);
153 callbacks
[0]= server_display_function
;
154 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
157 memcached_free(local_memc
);
162 static memcached_return_t
server_display_unsort_function(const memcached_st
*ptr
__attribute__((unused
)), memcached_server_st
*server
, void *context
)
165 uint32_t x
= *((uint32_t *)(context
));
167 assert(test_ports
[x
] == server
->port
);
168 *((uint32_t *)(context
))= ++x
;
170 return MEMCACHED_SUCCESS
;
173 static test_return_t
server_unsort_test(memcached_st
*ptr
__attribute__((unused
)))
175 size_t counter
= 0; /* Prime the value for the test_true in server_display_function */
176 size_t bigger
= 0; /* Prime the value for the test_true in server_display_function */
177 memcached_return_t rc
;
178 memcached_server_fn callbacks
[1];
179 memcached_st
*local_memc
;
181 local_memc
= memcached_create(NULL
);
182 test_true(local_memc
);
184 for (size_t x
= 0; x
< TEST_PORT_COUNT
; x
++)
186 test_ports
[x
]= (in_port_t
)(random() % 64000);
187 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
188 test_true(memcached_server_count(local_memc
) == x
+1);
189 test_true(memcached_servers_count(memcached_server_list(local_memc
)) == x
+1);
190 test_true(rc
== MEMCACHED_SUCCESS
);
193 callbacks
[0]= server_display_unsort_function
;
194 memcached_server_cursor(local_memc
, callbacks
, (void *)&counter
, 1);
196 /* Now we sort old data! */
197 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
198 callbacks
[0]= server_display_function
;
199 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
202 memcached_free(local_memc
);
207 static test_return_t
allocation_test(memcached_st
*not_used
__attribute__((unused
)))
210 memc
= memcached_create(NULL
);
212 memcached_free(memc
);
217 static test_return_t
clone_test(memcached_st
*memc
)
221 memcached_st
*memc_clone
;
222 memc_clone
= memcached_clone(NULL
, NULL
);
223 test_true(memc_clone
);
224 memcached_free(memc_clone
);
227 /* Can we init from null? */
229 memcached_st
*memc_clone
;
230 memc_clone
= memcached_clone(NULL
, memc
);
231 test_true(memc_clone
);
233 test_true(memc_clone
->call_free
== memc
->call_free
);
234 test_true(memc_clone
->call_malloc
== memc
->call_malloc
);
235 test_true(memc_clone
->call_realloc
== memc
->call_realloc
);
236 test_true(memc_clone
->call_calloc
== memc
->call_calloc
);
237 test_true(memc_clone
->connect_timeout
== memc
->connect_timeout
);
238 test_true(memc_clone
->delete_trigger
== memc
->delete_trigger
);
239 test_true(memc_clone
->distribution
== memc
->distribution
);
240 { // Test all of the flags
241 test_true(memc_clone
->flags
.no_block
== memc
->flags
.no_block
);
242 test_true(memc_clone
->flags
.tcp_nodelay
== memc
->flags
.tcp_nodelay
);
243 test_true(memc_clone
->flags
.reuse_memory
== memc
->flags
.reuse_memory
);
244 test_true(memc_clone
->flags
.use_cache_lookups
== memc
->flags
.use_cache_lookups
);
245 test_true(memc_clone
->flags
.support_cas
== memc
->flags
.support_cas
);
246 test_true(memc_clone
->flags
.buffer_requests
== memc
->flags
.buffer_requests
);
247 test_true(memc_clone
->flags
.use_sort_hosts
== memc
->flags
.use_sort_hosts
);
248 test_true(memc_clone
->flags
.verify_key
== memc
->flags
.verify_key
);
249 test_true(memc_clone
->flags
.ketama_weighted
== memc
->flags
.ketama_weighted
);
250 test_true(memc_clone
->flags
.binary_protocol
== memc
->flags
.binary_protocol
);
251 test_true(memc_clone
->flags
.hash_with_prefix_key
== memc
->flags
.hash_with_prefix_key
);
252 test_true(memc_clone
->flags
.no_reply
== memc
->flags
.no_reply
);
253 test_true(memc_clone
->flags
.use_udp
== memc
->flags
.use_udp
);
254 test_true(memc_clone
->flags
.auto_eject_hosts
== memc
->flags
.auto_eject_hosts
);
255 test_true(memc_clone
->flags
.randomize_replica_read
== memc
->flags
.randomize_replica_read
);
257 test_true(memc_clone
->get_key_failure
== memc
->get_key_failure
);
258 test_true(memc_clone
->hash
== memc
->hash
);
259 test_true(memc_clone
->distribution_hash
== memc
->distribution_hash
);
260 test_true(memc_clone
->io_bytes_watermark
== memc
->io_bytes_watermark
);
261 test_true(memc_clone
->io_msg_watermark
== memc
->io_msg_watermark
);
262 test_true(memc_clone
->io_key_prefetch
== memc
->io_key_prefetch
);
263 test_true(memc_clone
->on_cleanup
== memc
->on_cleanup
);
264 test_true(memc_clone
->on_clone
== memc
->on_clone
);
265 test_true(memc_clone
->poll_timeout
== memc
->poll_timeout
);
266 test_true(memc_clone
->rcv_timeout
== memc
->rcv_timeout
);
267 test_true(memc_clone
->recv_size
== memc
->recv_size
);
268 test_true(memc_clone
->retry_timeout
== memc
->retry_timeout
);
269 test_true(memc_clone
->send_size
== memc
->send_size
);
270 test_true(memc_clone
->server_failure_limit
== memc
->server_failure_limit
);
271 test_true(memc_clone
->snd_timeout
== memc
->snd_timeout
);
272 test_true(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_true(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_true(memc_clone
);
294 memcached_free(memc_clone
);
300 static test_return_t
userdata_test(memcached_st
*memc
)
303 test_true(memcached_set_user_data(memc
, foo
) == NULL
);
304 test_true(memcached_get_user_data(memc
) == foo
);
305 test_true(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_true(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_true(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_true(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_true(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_true(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_true(rc
== MEMCACHED_SUCCESS
);
379 rc
= memcached_append(memc
, key
, strlen(key
),
380 " the", strlen(" the"),
381 (time_t)0, (uint32_t)0);
382 test_true(rc
== MEMCACHED_SUCCESS
);
384 rc
= memcached_append(memc
, key
, strlen(key
),
385 " people", strlen(" people"),
386 (time_t)0, (uint32_t)0);
387 test_true(rc
== MEMCACHED_SUCCESS
);
389 out_value
= memcached_get(memc
, key
, strlen(key
),
390 &value_length
, &flags
, &rc
);
391 test_true(!memcmp(out_value
, "we the people", strlen("we the people")));
392 test_true(strlen("we the people") == value_length
);
393 test_true(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 uint32_t store_list
[] = { 23, 56, 499, 98, 32847, 0 };
409 rc
= memcached_flush(memc
, 0);
410 test_true(rc
== MEMCACHED_SUCCESS
);
412 rc
= memcached_set(memc
,
415 (time_t)0, (uint32_t)0);
416 test_true(rc
== MEMCACHED_SUCCESS
);
418 for (x
= 0; store_list
[x
] ; x
++)
420 rc
= memcached_append(memc
,
422 (char *)&store_list
[x
], sizeof(uint32_t),
423 (time_t)0, (uint32_t)0);
424 test_true(rc
== MEMCACHED_SUCCESS
);
427 value
= (uint32_t *)memcached_get(memc
, key
, strlen(key
),
428 &value_length
, &flags
, &rc
);
429 test_true((value_length
== (sizeof(uint32_t) * x
)));
430 test_true(rc
== MEMCACHED_SUCCESS
);
432 for (uint32_t counter
= x
, *ptr
= value
; counter
; counter
--)
434 test_true(*ptr
== store_list
[x
- counter
]);
442 static test_return_t
cas2_test(memcached_st
*memc
)
444 memcached_return_t rc
;
445 const char *keys
[]= {"fudge", "son", "food"};
446 size_t key_length
[]= {5, 3, 4};
447 const char *value
= "we the people";
448 size_t value_length
= strlen("we the people");
450 memcached_result_st results_obj
;
451 memcached_result_st
*results
;
454 rc
= memcached_flush(memc
, 0);
455 test_true(rc
== MEMCACHED_SUCCESS
);
457 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
459 for (x
= 0; x
< 3; x
++)
461 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
462 keys
[x
], key_length
[x
],
463 (time_t)50, (uint32_t)9);
464 test_true(rc
== MEMCACHED_SUCCESS
);
467 rc
= memcached_mget(memc
, keys
, key_length
, 3);
469 results
= memcached_result_create(memc
, &results_obj
);
471 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
473 test_true(results
->cas
);
474 test_true(rc
== MEMCACHED_SUCCESS
);
475 test_true(memcached_result_cas(results
));
477 test_true(!memcmp(value
, "we the people", strlen("we the people")));
478 test_true(strlen("we the people") == value_length
);
479 test_true(rc
== MEMCACHED_SUCCESS
);
481 memcached_result_free(&results_obj
);
486 static test_return_t
cas_test(memcached_st
*memc
)
488 memcached_return_t rc
;
489 const char *key
= "fun";
490 size_t key_length
= strlen(key
);
491 const char *value
= "we the people";
492 const char* keys
[2] = { key
, NULL
};
493 size_t keylengths
[2] = { strlen(key
), 0 };
494 size_t value_length
= strlen(value
);
495 const char *value2
= "change the value";
496 size_t value2_length
= strlen(value2
);
498 memcached_result_st results_obj
;
499 memcached_result_st
*results
;
502 rc
= memcached_flush(memc
, 0);
503 test_true(rc
== MEMCACHED_SUCCESS
);
505 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
507 rc
= memcached_set(memc
, key
, strlen(key
),
508 value
, strlen(value
),
509 (time_t)0, (uint32_t)0);
510 test_true(rc
== MEMCACHED_SUCCESS
);
512 rc
= memcached_mget(memc
, keys
, keylengths
, 1);
514 results
= memcached_result_create(memc
, &results_obj
);
516 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
518 test_true(rc
== MEMCACHED_SUCCESS
);
519 test_true(memcached_result_cas(results
));
520 test_true(!memcmp(value
, memcached_result_value(results
), value_length
));
521 test_true(strlen(memcached_result_value(results
)) == value_length
);
522 test_true(rc
== MEMCACHED_SUCCESS
);
523 uint64_t cas
= memcached_result_cas(results
);
526 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
527 test_true(rc
== MEMCACHED_END
);
528 test_true(results
== NULL
);
531 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
532 test_true(rc
== MEMCACHED_SUCCESS
);
535 * The item will have a new cas value, so try to set it again with the old
536 * value. This should fail!
538 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
539 test_true(rc
== MEMCACHED_DATA_EXISTS
);
541 memcached_result_free(&results_obj
);
546 static test_return_t
prepend_test(memcached_st
*memc
)
548 memcached_return_t rc
;
549 const char *key
= "fig";
550 const char *value
= "people";
551 char *out_value
= NULL
;
555 rc
= memcached_flush(memc
, 0);
556 test_true(rc
== MEMCACHED_SUCCESS
);
558 rc
= memcached_set(memc
, key
, strlen(key
),
559 value
, strlen(value
),
560 (time_t)0, (uint32_t)0);
561 test_true(rc
== MEMCACHED_SUCCESS
);
563 rc
= memcached_prepend(memc
, key
, strlen(key
),
564 "the ", strlen("the "),
565 (time_t)0, (uint32_t)0);
566 test_true(rc
== MEMCACHED_SUCCESS
);
568 rc
= memcached_prepend(memc
, key
, strlen(key
),
569 "we ", strlen("we "),
570 (time_t)0, (uint32_t)0);
571 test_true(rc
== MEMCACHED_SUCCESS
);
573 out_value
= memcached_get(memc
, key
, strlen(key
),
574 &value_length
, &flags
, &rc
);
575 test_true(!memcmp(out_value
, "we the people", strlen("we the people")));
576 test_true(strlen("we the people") == value_length
);
577 test_true(rc
== MEMCACHED_SUCCESS
);
584 Set the value, then quit to make sure it is flushed.
585 Come back in and test that add fails.
587 static test_return_t
add_test(memcached_st
*memc
)
589 memcached_return_t rc
;
590 const char *key
= "foo";
591 const char *value
= "when we sanitize";
592 unsigned long long setting_value
;
594 setting_value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
596 rc
= memcached_set(memc
, key
, strlen(key
),
597 value
, strlen(value
),
598 (time_t)0, (uint32_t)0);
599 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
600 memcached_quit(memc
);
601 rc
= memcached_add(memc
, key
, strlen(key
),
602 value
, strlen(value
),
603 (time_t)0, (uint32_t)0);
605 /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */
608 test_true(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_STORED
);
612 test_true(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_DATA_EXISTS
);
619 ** There was a problem of leaking filedescriptors in the initial release
620 ** of MacOSX 10.5. This test case triggers the problem. On some Solaris
621 ** systems it seems that the kernel is slow on reclaiming the resources
622 ** because the connects starts to time out (the test doesn't do much
623 ** anyway, so just loop 10 iterations)
625 static test_return_t
add_wrapper(memcached_st
*memc
)
628 unsigned int max
= 10000;
636 for (x
= 0; x
< max
; x
++)
642 static test_return_t
replace_test(memcached_st
*memc
)
644 memcached_return_t rc
;
645 const char *key
= "foo";
646 const char *value
= "when we sanitize";
647 const char *original
= "first we insert some data";
649 rc
= memcached_set(memc
, key
, strlen(key
),
650 original
, strlen(original
),
651 (time_t)0, (uint32_t)0);
652 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
654 rc
= memcached_replace(memc
, key
, strlen(key
),
655 value
, strlen(value
),
656 (time_t)0, (uint32_t)0);
657 test_true(rc
== MEMCACHED_SUCCESS
);
662 static test_return_t
delete_test(memcached_st
*memc
)
664 memcached_return_t rc
;
665 const char *key
= "foo";
666 const char *value
= "when we sanitize";
668 rc
= memcached_set(memc
, key
, strlen(key
),
669 value
, strlen(value
),
670 (time_t)0, (uint32_t)0);
671 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
673 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
674 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
679 static test_return_t
flush_test(memcached_st
*memc
)
681 memcached_return_t rc
;
683 rc
= memcached_flush(memc
, 0);
684 test_true(rc
== MEMCACHED_SUCCESS
);
689 static memcached_return_t
server_function(const memcached_st
*ptr
__attribute__((unused
)),
690 memcached_server_st
*server
__attribute__((unused
)),
691 void *context
__attribute__((unused
)))
695 return MEMCACHED_SUCCESS
;
698 static test_return_t
memcached_server_cursor_test(memcached_st
*memc
)
701 strcpy(context
, "foo bad");
702 memcached_server_fn callbacks
[1];
704 callbacks
[0]= server_function
;
705 memcached_server_cursor(memc
, callbacks
, context
, 1);
709 static test_return_t
bad_key_test(memcached_st
*memc
)
711 memcached_return_t rc
;
712 const char *key
= "foo bad";
714 size_t string_length
;
716 memcached_st
*memc_clone
;
718 size_t max_keylen
= 0xffff;
720 // Just skip if we are in binary mode.
721 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
))
724 memc_clone
= memcached_clone(NULL
, memc
);
725 test_true(memc_clone
);
727 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
728 test_true(rc
== MEMCACHED_SUCCESS
);
730 /* All keys are valid in the binary protocol (except for length) */
731 if (memcached_behavior_get(memc_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 0)
733 string
= memcached_get(memc_clone
, key
, strlen(key
),
734 &string_length
, &flags
, &rc
);
735 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
736 test_true(string_length
== 0);
740 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
741 test_true(rc
== MEMCACHED_SUCCESS
);
742 string
= memcached_get(memc_clone
, key
, strlen(key
),
743 &string_length
, &flags
, &rc
);
744 test_true(rc
== MEMCACHED_NOTFOUND
);
745 test_true(string_length
== 0);
748 /* Test multi key for bad keys */
749 const char *keys
[] = { "GoodKey", "Bad Key", "NotMine" };
750 size_t key_lengths
[] = { 7, 7, 7 };
752 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
753 test_true(rc
== MEMCACHED_SUCCESS
);
755 rc
= memcached_mget(memc_clone
, keys
, key_lengths
, 3);
756 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
758 rc
= memcached_mget_by_key(memc_clone
, "foo daddy", 9, keys
, key_lengths
, 1);
759 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
763 /* The following test should be moved to the end of this function when the
764 memcached server is updated to allow max size length of the keys in the
767 rc
= memcached_callback_set(memc_clone
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
768 test_true(rc
== MEMCACHED_SUCCESS
);
770 char *longkey
= malloc(max_keylen
+ 1);
773 memset(longkey
, 'a', max_keylen
+ 1);
774 string
= memcached_get(memc_clone
, longkey
, max_keylen
,
775 &string_length
, &flags
, &rc
);
776 test_true(rc
== MEMCACHED_NOTFOUND
);
777 test_true(string_length
== 0);
780 string
= memcached_get(memc_clone
, longkey
, max_keylen
+ 1,
781 &string_length
, &flags
, &rc
);
782 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
783 test_true(string_length
== 0);
790 /* Make sure zero length keys are marked as bad */
792 rc
= memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
793 test_true(rc
== MEMCACHED_SUCCESS
);
794 string
= memcached_get(memc_clone
, key
, 0,
795 &string_length
, &flags
, &rc
);
796 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
797 test_true(string_length
== 0);
800 memcached_free(memc_clone
);
805 #define READ_THROUGH_VALUE "set for me"
806 static memcached_return_t
read_through_trigger(memcached_st
*memc
__attribute__((unused
)),
807 char *key
__attribute__((unused
)),
808 size_t key_length
__attribute__((unused
)),
809 memcached_result_st
*result
)
812 return memcached_result_set_value(result
, READ_THROUGH_VALUE
, strlen(READ_THROUGH_VALUE
));
815 static test_return_t
read_through(memcached_st
*memc
)
817 memcached_return_t rc
;
818 const char *key
= "foo";
820 size_t string_length
;
822 memcached_trigger_key_fn cb
= (memcached_trigger_key_fn
)read_through_trigger
;
824 string
= memcached_get(memc
, key
, strlen(key
),
825 &string_length
, &flags
, &rc
);
827 test_true(rc
== MEMCACHED_NOTFOUND
);
828 test_false(string_length
);
831 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_GET_FAILURE
,
833 test_true(rc
== MEMCACHED_SUCCESS
);
835 string
= memcached_get(memc
, key
, strlen(key
),
836 &string_length
, &flags
, &rc
);
838 test_true(rc
== MEMCACHED_SUCCESS
);
839 test_true(string_length
== strlen(READ_THROUGH_VALUE
));
840 test_strcmp(READ_THROUGH_VALUE
, string
);
843 string
= memcached_get(memc
, key
, strlen(key
),
844 &string_length
, &flags
, &rc
);
846 test_true(rc
== MEMCACHED_SUCCESS
);
847 test_true(string_length
== strlen(READ_THROUGH_VALUE
));
848 test_true(!strcmp(READ_THROUGH_VALUE
, string
));
854 static memcached_return_t
delete_trigger(memcached_st
*ptr
__attribute__((unused
)),
856 size_t key_length
__attribute__((unused
)))
860 return MEMCACHED_SUCCESS
;
863 static test_return_t
delete_through(memcached_st
*memc
)
865 memcached_trigger_delete_key_fn callback
;
866 memcached_return_t rc
;
868 callback
= (memcached_trigger_delete_key_fn
)delete_trigger
;
870 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_DELETE_TRIGGER
, *(void**)&callback
);
871 test_true(rc
== MEMCACHED_SUCCESS
);
876 static test_return_t
get_test(memcached_st
*memc
)
878 memcached_return_t rc
;
879 const char *key
= "foo";
881 size_t string_length
;
884 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
885 test_true(rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_NOTFOUND
);
887 string
= memcached_get(memc
, key
, strlen(key
),
888 &string_length
, &flags
, &rc
);
890 test_true(rc
== MEMCACHED_NOTFOUND
);
891 test_false(string_length
);
897 static test_return_t
get_test2(memcached_st
*memc
)
899 memcached_return_t rc
;
900 const char *key
= "foo";
901 const char *value
= "when we sanitize";
903 size_t string_length
;
906 rc
= memcached_set(memc
, key
, strlen(key
),
907 value
, strlen(value
),
908 (time_t)0, (uint32_t)0);
909 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
911 string
= memcached_get(memc
, key
, strlen(key
),
912 &string_length
, &flags
, &rc
);
915 test_true(rc
== MEMCACHED_SUCCESS
);
916 test_true(string_length
== strlen(value
));
917 test_true(!memcmp(string
, value
, string_length
));
924 static test_return_t
set_test2(memcached_st
*memc
)
926 memcached_return_t rc
;
927 const char *key
= "foo";
928 const char *value
= "train in the brain";
929 size_t value_length
= strlen(value
);
932 for (x
= 0; x
< 10; x
++)
934 rc
= memcached_set(memc
, key
, strlen(key
),
936 (time_t)0, (uint32_t)0);
937 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
943 static test_return_t
set_test3(memcached_st
*memc
)
945 memcached_return_t rc
;
947 size_t value_length
= 8191;
950 value
= (char*)malloc(value_length
);
953 for (x
= 0; x
< value_length
; x
++)
954 value
[x
] = (char) (x
% 127);
956 /* The dump test relies on there being at least 32 items in memcached */
957 for (x
= 0; x
< 32; x
++)
961 sprintf(key
, "foo%u", x
);
963 rc
= memcached_set(memc
, key
, strlen(key
),
965 (time_t)0, (uint32_t)0);
966 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
974 static test_return_t
get_test3(memcached_st
*memc
)
976 memcached_return_t rc
;
977 const char *key
= "foo";
979 size_t value_length
= 8191;
981 size_t string_length
;
985 value
= (char*)malloc(value_length
);
988 for (x
= 0; x
< value_length
; x
++)
989 value
[x
] = (char) (x
% 127);
991 rc
= memcached_set(memc
, key
, strlen(key
),
993 (time_t)0, (uint32_t)0);
994 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
996 string
= memcached_get(memc
, key
, strlen(key
),
997 &string_length
, &flags
, &rc
);
999 test_true(rc
== MEMCACHED_SUCCESS
);
1001 test_true(string_length
== value_length
);
1002 test_true(!memcmp(string
, value
, string_length
));
1007 return TEST_SUCCESS
;
1010 static test_return_t
get_test4(memcached_st
*memc
)
1012 memcached_return_t rc
;
1013 const char *key
= "foo";
1015 size_t value_length
= 8191;
1017 size_t string_length
;
1021 value
= (char*)malloc(value_length
);
1024 for (x
= 0; x
< value_length
; x
++)
1025 value
[x
] = (char) (x
% 127);
1027 rc
= memcached_set(memc
, key
, strlen(key
),
1028 value
, value_length
,
1029 (time_t)0, (uint32_t)0);
1030 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1032 for (x
= 0; x
< 10; x
++)
1034 string
= memcached_get(memc
, key
, strlen(key
),
1035 &string_length
, &flags
, &rc
);
1037 test_true(rc
== MEMCACHED_SUCCESS
);
1039 test_true(string_length
== value_length
);
1040 test_true(!memcmp(string
, value
, string_length
));
1046 return TEST_SUCCESS
;
1050 * This test verifies that memcached_read_one_response doesn't try to
1051 * dereference a NIL-pointer if you issue a multi-get and don't read out all
1052 * responses before you execute a storage command.
1054 static test_return_t
get_test5(memcached_st
*memc
)
1057 ** Request the same key twice, to ensure that we hash to the same server
1058 ** (so that we have multiple response values queued up) ;-)
1060 const char *keys
[]= { "key", "key" };
1061 size_t lengths
[]= { 3, 3 };
1065 memcached_return_t rc
= memcached_set(memc
, keys
[0], lengths
[0],
1066 keys
[0], lengths
[0], 0, 0);
1067 test_true(rc
== MEMCACHED_SUCCESS
);
1068 rc
= memcached_mget(memc
, keys
, lengths
, 2);
1070 memcached_result_st results_obj
;
1071 memcached_result_st
*results
;
1072 results
=memcached_result_create(memc
, &results_obj
);
1074 results
=memcached_fetch_result(memc
, &results_obj
, &rc
);
1076 memcached_result_free(&results_obj
);
1078 /* Don't read out the second result, but issue a set instead.. */
1079 rc
= memcached_set(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0);
1080 test_true(rc
== MEMCACHED_SUCCESS
);
1082 char *val
= memcached_get_by_key(memc
, keys
[0], lengths
[0], "yek", 3,
1083 &rlen
, &flags
, &rc
);
1084 test_true(val
== NULL
);
1085 test_true(rc
== MEMCACHED_NOTFOUND
);
1086 val
= memcached_get(memc
, keys
[0], lengths
[0], &rlen
, &flags
, &rc
);
1087 test_true(val
!= NULL
);
1088 test_true(rc
== MEMCACHED_SUCCESS
);
1091 return TEST_SUCCESS
;
1094 static test_return_t
mget_end(memcached_st
*memc
)
1096 const char *keys
[]= { "foo", "foo2" };
1097 size_t lengths
[]= { 3, 4 };
1098 const char *values
[]= { "fjord", "41" };
1100 memcached_return_t rc
;
1103 for (int i
= 0; i
< 2; i
++)
1105 rc
= memcached_set(memc
, keys
[i
], lengths
[i
], values
[i
], strlen(values
[i
]),
1106 (time_t)0, (uint32_t)0);
1107 test_true(rc
== MEMCACHED_SUCCESS
);
1111 size_t string_length
;
1114 // retrieve both via mget
1115 rc
= memcached_mget(memc
, keys
, lengths
, 2);
1116 test_true(rc
== MEMCACHED_SUCCESS
);
1118 char key
[MEMCACHED_MAX_KEY
];
1121 // this should get both
1122 for (int i
= 0; i
< 2; i
++)
1124 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
,
1126 test_true(rc
== MEMCACHED_SUCCESS
);
1128 if (key_length
== 4)
1130 test_true(string_length
== strlen(values
[val
]));
1131 test_true(strncmp(values
[val
], string
, string_length
) == 0);
1135 // this should indicate end
1136 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1137 test_true(rc
== MEMCACHED_END
);
1140 rc
= memcached_mget(memc
, keys
, lengths
, 1);
1141 test_true(rc
== MEMCACHED_SUCCESS
);
1143 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1144 test_true(key_length
== lengths
[0]);
1145 test_true(strncmp(keys
[0], key
, key_length
) == 0);
1146 test_true(string_length
== strlen(values
[0]));
1147 test_true(strncmp(values
[0], string
, string_length
) == 0);
1148 test_true(rc
== MEMCACHED_SUCCESS
);
1151 // this should indicate end
1152 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1153 test_true(rc
== MEMCACHED_END
);
1155 return TEST_SUCCESS
;
1158 /* Do not copy the style of this code, I just access hosts to testthis function */
1159 static test_return_t
stats_servername_test(memcached_st
*memc
)
1161 memcached_return_t rc
;
1162 memcached_stat_st memc_stat
;
1163 memcached_server_instance_st
*instance
=
1164 memcached_server_instance_fetch(memc
, 0);
1166 rc
= memcached_stat_servername(&memc_stat
, NULL
,
1170 return TEST_SUCCESS
;
1173 static test_return_t
increment_test(memcached_st
*memc
)
1175 uint64_t new_number
;
1176 memcached_return_t rc
;
1177 const char *key
= "number";
1178 const char *value
= "0";
1180 rc
= memcached_set(memc
, key
, strlen(key
),
1181 value
, strlen(value
),
1182 (time_t)0, (uint32_t)0);
1183 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1185 rc
= memcached_increment(memc
, key
, strlen(key
),
1187 test_true(rc
== MEMCACHED_SUCCESS
);
1188 test_true(new_number
== 1);
1190 rc
= memcached_increment(memc
, key
, strlen(key
),
1192 test_true(rc
== MEMCACHED_SUCCESS
);
1193 test_true(new_number
== 2);
1195 return TEST_SUCCESS
;
1198 static test_return_t
increment_with_initial_test(memcached_st
*memc
)
1200 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1202 uint64_t new_number
;
1203 memcached_return_t rc
;
1204 const char *key
= "number";
1205 uint64_t initial
= 0;
1207 rc
= memcached_increment_with_initial(memc
, key
, strlen(key
),
1208 1, initial
, 0, &new_number
);
1209 test_true(rc
== MEMCACHED_SUCCESS
);
1210 test_true(new_number
== initial
);
1212 rc
= memcached_increment_with_initial(memc
, key
, strlen(key
),
1213 1, initial
, 0, &new_number
);
1214 test_true(rc
== MEMCACHED_SUCCESS
);
1215 test_true(new_number
== (initial
+ 1));
1217 return TEST_SUCCESS
;
1220 static test_return_t
decrement_test(memcached_st
*memc
)
1222 uint64_t new_number
;
1223 memcached_return_t rc
;
1224 const char *key
= "number";
1225 const char *value
= "3";
1227 rc
= memcached_set(memc
, key
, strlen(key
),
1228 value
, strlen(value
),
1229 (time_t)0, (uint32_t)0);
1230 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1232 rc
= memcached_decrement(memc
, key
, strlen(key
),
1234 test_true(rc
== MEMCACHED_SUCCESS
);
1235 test_true(new_number
== 2);
1237 rc
= memcached_decrement(memc
, key
, strlen(key
),
1239 test_true(rc
== MEMCACHED_SUCCESS
);
1240 test_true(new_number
== 1);
1242 return TEST_SUCCESS
;
1245 static test_return_t
decrement_with_initial_test(memcached_st
*memc
)
1247 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1249 uint64_t new_number
;
1250 memcached_return_t rc
;
1251 const char *key
= "number";
1252 uint64_t initial
= 3;
1254 rc
= memcached_decrement_with_initial(memc
, key
, strlen(key
),
1255 1, initial
, 0, &new_number
);
1256 test_true(rc
== MEMCACHED_SUCCESS
);
1257 test_true(new_number
== initial
);
1259 rc
= memcached_decrement_with_initial(memc
, key
, strlen(key
),
1260 1, initial
, 0, &new_number
);
1261 test_true(rc
== MEMCACHED_SUCCESS
);
1262 test_true(new_number
== (initial
- 1));
1264 return TEST_SUCCESS
;
1267 static test_return_t
increment_by_key_test(memcached_st
*memc
)
1269 uint64_t new_number
;
1270 memcached_return_t rc
;
1271 const char *master_key
= "foo";
1272 const char *key
= "number";
1273 const char *value
= "0";
1275 rc
= memcached_set_by_key(memc
, master_key
, strlen(master_key
),
1277 value
, strlen(value
),
1278 (time_t)0, (uint32_t)0);
1279 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1281 rc
= memcached_increment_by_key(memc
, master_key
, strlen(master_key
), key
, strlen(key
),
1283 test_true(rc
== MEMCACHED_SUCCESS
);
1284 test_true(new_number
== 1);
1286 rc
= memcached_increment_by_key(memc
, master_key
, strlen(master_key
), key
, strlen(key
),
1288 test_true(rc
== MEMCACHED_SUCCESS
);
1289 test_true(new_number
== 2);
1291 return TEST_SUCCESS
;
1294 static test_return_t
increment_with_initial_by_key_test(memcached_st
*memc
)
1296 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1298 uint64_t new_number
;
1299 memcached_return_t rc
;
1300 const char *master_key
= "foo";
1301 const char *key
= "number";
1302 uint64_t initial
= 0;
1304 rc
= memcached_increment_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1306 1, initial
, 0, &new_number
);
1307 test_true(rc
== MEMCACHED_SUCCESS
);
1308 test_true(new_number
== initial
);
1310 rc
= memcached_increment_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1312 1, initial
, 0, &new_number
);
1313 test_true(rc
== MEMCACHED_SUCCESS
);
1314 test_true(new_number
== (initial
+ 1));
1316 return TEST_SUCCESS
;
1319 static test_return_t
decrement_by_key_test(memcached_st
*memc
)
1321 uint64_t new_number
;
1322 memcached_return_t rc
;
1323 const char *master_key
= "foo";
1324 const char *key
= "number";
1325 const char *value
= "3";
1327 rc
= memcached_set_by_key(memc
, master_key
, strlen(master_key
),
1329 value
, strlen(value
),
1330 (time_t)0, (uint32_t)0);
1331 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1333 rc
= memcached_decrement_by_key(memc
, master_key
, strlen(master_key
),
1336 test_true(rc
== MEMCACHED_SUCCESS
);
1337 test_true(new_number
== 2);
1339 rc
= memcached_decrement_by_key(memc
, master_key
, strlen(master_key
),
1342 test_true(rc
== MEMCACHED_SUCCESS
);
1343 test_true(new_number
== 1);
1345 return TEST_SUCCESS
;
1348 static test_return_t
decrement_with_initial_by_key_test(memcached_st
*memc
)
1350 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1352 uint64_t new_number
;
1353 memcached_return_t rc
;
1354 const char *master_key
= "foo";
1355 const char *key
= "number";
1356 uint64_t initial
= 3;
1358 rc
= memcached_decrement_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1360 1, initial
, 0, &new_number
);
1361 test_true(rc
== MEMCACHED_SUCCESS
);
1362 test_true(new_number
== initial
);
1364 rc
= memcached_decrement_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1366 1, initial
, 0, &new_number
);
1367 test_true(rc
== MEMCACHED_SUCCESS
);
1368 test_true(new_number
== (initial
- 1));
1370 return TEST_SUCCESS
;
1373 static test_return_t
quit_test(memcached_st
*memc
)
1375 memcached_return_t rc
;
1376 const char *key
= "fudge";
1377 const char *value
= "sanford and sun";
1379 rc
= memcached_set(memc
, key
, strlen(key
),
1380 value
, strlen(value
),
1381 (time_t)10, (uint32_t)3);
1382 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1383 memcached_quit(memc
);
1385 rc
= memcached_set(memc
, key
, strlen(key
),
1386 value
, strlen(value
),
1387 (time_t)50, (uint32_t)9);
1388 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1390 return TEST_SUCCESS
;
1393 static test_return_t
mget_result_test(memcached_st
*memc
)
1395 memcached_return_t rc
;
1396 const char *keys
[]= {"fudge", "son", "food"};
1397 size_t key_length
[]= {5, 3, 4};
1400 memcached_result_st results_obj
;
1401 memcached_result_st
*results
;
1403 results
= memcached_result_create(memc
, &results_obj
);
1405 test_true(&results_obj
== results
);
1407 /* We need to empty the server before continueing test */
1408 rc
= memcached_flush(memc
, 0);
1409 test_true(rc
== MEMCACHED_SUCCESS
);
1411 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1412 test_true(rc
== MEMCACHED_SUCCESS
);
1414 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1419 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1420 test_true(!results
);
1421 test_true(rc
== MEMCACHED_END
);
1423 for (x
= 0; x
< 3; x
++)
1425 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1426 keys
[x
], key_length
[x
],
1427 (time_t)50, (uint32_t)9);
1428 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1431 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1432 test_true(rc
== MEMCACHED_SUCCESS
);
1434 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1437 test_true(&results_obj
== results
);
1438 test_true(rc
== MEMCACHED_SUCCESS
);
1439 test_true(memcached_result_key_length(results
) == memcached_result_length(results
));
1440 test_true(!memcmp(memcached_result_key_value(results
),
1441 memcached_result_value(results
),
1442 memcached_result_length(results
)));
1445 memcached_result_free(&results_obj
);
1447 return TEST_SUCCESS
;
1450 static test_return_t
mget_result_alloc_test(memcached_st
*memc
)
1452 memcached_return_t rc
;
1453 const char *keys
[]= {"fudge", "son", "food"};
1454 size_t key_length
[]= {5, 3, 4};
1457 memcached_result_st
*results
;
1459 /* We need to empty the server before continueing test */
1460 rc
= memcached_flush(memc
, 0);
1461 test_true(rc
== MEMCACHED_SUCCESS
);
1463 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1464 test_true(rc
== MEMCACHED_SUCCESS
);
1466 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)) != NULL
)
1470 test_true(!results
);
1471 test_true(rc
== MEMCACHED_END
);
1473 for (x
= 0; x
< 3; x
++)
1475 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1476 keys
[x
], key_length
[x
],
1477 (time_t)50, (uint32_t)9);
1478 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1481 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1482 test_true(rc
== MEMCACHED_SUCCESS
);
1485 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1488 test_true(rc
== MEMCACHED_SUCCESS
);
1489 test_true(memcached_result_key_length(results
) == memcached_result_length(results
));
1490 test_true(!memcmp(memcached_result_key_value(results
),
1491 memcached_result_value(results
),
1492 memcached_result_length(results
)));
1493 memcached_result_free(results
);
1497 return TEST_SUCCESS
;
1500 /* Count the results */
1501 static memcached_return_t
callback_counter(const memcached_st
*ptr
__attribute__((unused
)),
1502 memcached_result_st
*result
__attribute__((unused
)),
1505 size_t *counter
= (size_t *)context
;
1507 *counter
= *counter
+ 1;
1509 return MEMCACHED_SUCCESS
;
1512 static test_return_t
mget_result_function(memcached_st
*memc
)
1514 memcached_return_t rc
;
1515 const char *keys
[]= {"fudge", "son", "food"};
1516 size_t key_length
[]= {5, 3, 4};
1519 memcached_execute_fn callbacks
[1];
1521 /* We need to empty the server before continueing test */
1522 rc
= memcached_flush(memc
, 0);
1523 for (x
= 0; x
< 3; x
++)
1525 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1526 keys
[x
], key_length
[x
],
1527 (time_t)50, (uint32_t)9);
1528 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1531 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1532 test_true(rc
== MEMCACHED_SUCCESS
);
1534 callbacks
[0]= &callback_counter
;
1536 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
1538 test_true(counter
== 3);
1540 return TEST_SUCCESS
;
1543 static test_return_t
mget_test(memcached_st
*memc
)
1545 memcached_return_t rc
;
1546 const char *keys
[]= {"fudge", "son", "food"};
1547 size_t key_length
[]= {5, 3, 4};
1551 char return_key
[MEMCACHED_MAX_KEY
];
1552 size_t return_key_length
;
1554 size_t return_value_length
;
1556 /* We need to empty the server before continueing test */
1557 rc
= memcached_flush(memc
, 0);
1558 test_true(rc
== MEMCACHED_SUCCESS
);
1560 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1561 test_true(rc
== MEMCACHED_SUCCESS
);
1563 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1564 &return_value_length
, &flags
, &rc
)) != NULL
)
1566 test_true(return_value
);
1568 test_true(!return_value
);
1569 test_true(return_value_length
== 0);
1570 test_true(rc
== MEMCACHED_END
);
1572 for (x
= 0; x
< 3; x
++)
1574 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1575 keys
[x
], key_length
[x
],
1576 (time_t)50, (uint32_t)9);
1577 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1580 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1581 test_true(rc
== MEMCACHED_SUCCESS
);
1584 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1585 &return_value_length
, &flags
, &rc
)))
1587 test_true(return_value
);
1588 test_true(rc
== MEMCACHED_SUCCESS
);
1589 test_true(return_key_length
== return_value_length
);
1590 test_true(!memcmp(return_value
, return_key
, return_value_length
));
1595 return TEST_SUCCESS
;
1598 static test_return_t
mget_execute(memcached_st
*memc
)
1602 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1606 * I only want to hit _one_ server so I know the number of requests I'm
1607 * sending in the pipeline.
1609 uint32_t number_of_hosts
= memc
->number_of_hosts
;
1610 memc
->number_of_hosts
= 1;
1612 size_t max_keys
= binary
? 20480 : 1;
1615 char **keys
= calloc(max_keys
, sizeof(char*));
1616 size_t *key_length
=calloc(max_keys
, sizeof(size_t));
1618 /* First add all of the items.. */
1619 char blob
[1024] = {0};
1620 memcached_return_t rc
;
1621 for (size_t x
= 0; x
< max_keys
; ++x
)
1625 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%zu", x
);
1627 test_true(keys
[x
] != NULL
);
1628 rc
= memcached_add(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
1629 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1632 /* Try to get all of them with a large multiget */
1634 memcached_execute_fn callbacks
[1]= { [0]= &callback_counter
};
1635 rc
= memcached_mget_execute(memc
, (const char**)keys
, key_length
,
1636 max_keys
, callbacks
, &counter
, 1);
1640 test_true(rc
== MEMCACHED_SUCCESS
);
1642 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
1643 test_true(rc
== MEMCACHED_END
);
1645 /* Verify that we got all of the items */
1646 test_true(counter
== max_keys
);
1650 test_true(rc
== MEMCACHED_NOT_SUPPORTED
);
1651 test_true(counter
== 0);
1654 /* Release all allocated resources */
1655 for (size_t x
= 0; x
< max_keys
; ++x
)
1662 memc
->number_of_hosts
= number_of_hosts
;
1663 return TEST_SUCCESS
;
1666 static test_return_t
get_stats_keys(memcached_st
*memc
)
1670 memcached_stat_st memc_stat
;
1671 memcached_return_t rc
;
1673 stat_list
= memcached_stat_get_keys(memc
, &memc_stat
, &rc
);
1674 test_true(rc
== MEMCACHED_SUCCESS
);
1675 for (ptr
= stat_list
; *ptr
; ptr
++)
1680 return TEST_SUCCESS
;
1683 static test_return_t
version_string_test(memcached_st
*memc
__attribute__((unused
)))
1685 const char *version_string
;
1687 version_string
= memcached_lib_version();
1689 test_true(!strcmp(version_string
, LIBMEMCACHED_VERSION_STRING
));
1691 return TEST_SUCCESS
;
1694 static test_return_t
get_stats(memcached_st
*memc
)
1699 memcached_return_t rc
;
1700 memcached_stat_st
*memc_stat
;
1702 memc_stat
= memcached_stat(memc
, NULL
, &rc
);
1703 test_true(rc
== MEMCACHED_SUCCESS
);
1705 test_true(rc
== MEMCACHED_SUCCESS
);
1706 test_true(memc_stat
);
1708 for (x
= 0; x
< memcached_server_count(memc
); x
++)
1710 stat_list
= memcached_stat_get_keys(memc
, memc_stat
+x
, &rc
);
1711 test_true(rc
== MEMCACHED_SUCCESS
);
1712 for (ptr
= stat_list
; *ptr
; ptr
++);
1717 memcached_stat_free(NULL
, memc_stat
);
1719 return TEST_SUCCESS
;
1722 static test_return_t
add_host_test(memcached_st
*memc
)
1725 memcached_server_st
*servers
;
1726 memcached_return_t rc
;
1727 char servername
[]= "0.example.com";
1729 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
1731 test_true(1 == memcached_server_list_count(servers
));
1733 for (x
= 2; x
< 20; x
++)
1735 char buffer
[SMALL_STRING_LEN
];
1737 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
1738 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
1740 test_true(rc
== MEMCACHED_SUCCESS
);
1741 test_true(x
== memcached_server_list_count(servers
));
1744 rc
= memcached_server_push(memc
, servers
);
1745 test_true(rc
== MEMCACHED_SUCCESS
);
1746 rc
= memcached_server_push(memc
, servers
);
1747 test_true(rc
== MEMCACHED_SUCCESS
);
1749 memcached_server_list_free(servers
);
1751 return TEST_SUCCESS
;
1754 static memcached_return_t
clone_test_callback(memcached_st
*parent
__attribute__((unused
)), memcached_st
*memc_clone
__attribute__((unused
)))
1756 return MEMCACHED_SUCCESS
;
1759 static memcached_return_t
cleanup_test_callback(memcached_st
*ptr
__attribute__((unused
)))
1761 return MEMCACHED_SUCCESS
;
1764 static test_return_t
callback_test(memcached_st
*memc
)
1766 /* Test User Data */
1770 memcached_return_t rc
;
1772 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_USER_DATA
, &x
);
1773 test_true(rc
== MEMCACHED_SUCCESS
);
1774 test_ptr
= (int *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_USER_DATA
, &rc
);
1775 test_true(*test_ptr
== x
);
1778 /* Test Clone Callback */
1780 memcached_clone_fn clone_cb
= (memcached_clone_fn
)clone_test_callback
;
1781 void *clone_cb_ptr
= *(void **)&clone_cb
;
1782 void *temp_function
= NULL
;
1783 memcached_return_t rc
;
1785 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
,
1787 test_true(rc
== MEMCACHED_SUCCESS
);
1788 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1789 test_true(temp_function
== clone_cb_ptr
);
1792 /* Test Cleanup Callback */
1794 memcached_cleanup_fn cleanup_cb
=
1795 (memcached_cleanup_fn
)cleanup_test_callback
;
1796 void *cleanup_cb_ptr
= *(void **)&cleanup_cb
;
1797 void *temp_function
= NULL
;
1798 memcached_return_t rc
;
1800 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
,
1802 test_true(rc
== MEMCACHED_SUCCESS
);
1803 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1804 test_true(temp_function
== cleanup_cb_ptr
);
1807 return TEST_SUCCESS
;
1810 /* We don't test the behavior itself, we test the switches */
1811 static test_return_t
behavior_test(memcached_st
*memc
)
1816 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1817 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1818 test_true(value
== 1);
1820 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1821 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1822 test_true(value
== 1);
1824 set
= MEMCACHED_HASH_MD5
;
1825 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1826 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1827 test_true(value
== MEMCACHED_HASH_MD5
);
1831 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1832 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1833 test_true(value
== 0);
1835 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1836 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1837 test_true(value
== 0);
1839 set
= MEMCACHED_HASH_DEFAULT
;
1840 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1841 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1842 test_true(value
== MEMCACHED_HASH_DEFAULT
);
1844 set
= MEMCACHED_HASH_CRC
;
1845 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1846 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1847 test_true(value
== MEMCACHED_HASH_CRC
);
1849 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1850 test_true(value
> 0);
1852 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1853 test_true(value
> 0);
1855 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
);
1856 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, value
+ 1);
1857 test_true((value
+ 1) == memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
));
1859 return TEST_SUCCESS
;
1862 static test_return_t
MEMCACHED_BEHAVIOR_CORK_test(memcached_st
*memc
)
1864 memcached_return_t rc
;
1868 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CORK
, set
);
1869 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_NOT_SUPPORTED
);
1871 value
= (bool)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_CORK
);
1873 if (rc
== MEMCACHED_SUCCESS
)
1875 test_true((bool)value
== set
);
1879 test_false((bool)value
== set
);
1882 return TEST_SUCCESS
;
1885 static test_return_t
fetch_all_results(memcached_st
*memc
)
1887 memcached_return_t rc
= MEMCACHED_SUCCESS
;
1888 char return_key
[MEMCACHED_MAX_KEY
];
1889 size_t return_key_length
;
1891 size_t return_value_length
;
1894 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1895 &return_value_length
, &flags
, &rc
)))
1897 test_true(return_value
);
1898 test_true(rc
== MEMCACHED_SUCCESS
);
1902 return ((rc
== MEMCACHED_END
) || (rc
== MEMCACHED_SUCCESS
)) ? TEST_SUCCESS
: TEST_FAILURE
;
1905 /* Test case provided by Cal Haldenbrand */
1906 static test_return_t
user_supplied_bug1(memcached_st
*memc
)
1908 unsigned int setter
= 1;
1910 unsigned long long total
= 0;
1913 char randomstuff
[6 * 1024];
1914 memcached_return_t rc
;
1916 memset(randomstuff
, 0, 6 * 1024);
1918 /* We just keep looking at the same values over and over */
1921 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1922 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1926 for (uint32_t x
= 0 ; total
< 20 * 1024576 ; x
++ )
1930 size
= (uint32_t)(rand() % ( 5 * 1024 ) ) + 400;
1931 memset(randomstuff
, 0, 6 * 1024);
1932 test_true(size
< 6 * 1024); /* Being safe here */
1934 for (j
= 0 ; j
< size
;j
++)
1935 randomstuff
[j
] = (signed char) ((rand() % 26) + 97);
1938 snprintf(key
, sizeof(key
), "%u", x
);
1939 rc
= memcached_set(memc
, key
, strlen(key
),
1940 randomstuff
, strlen(randomstuff
), 10, 0);
1941 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1942 /* If we fail, lets try again */
1943 if (rc
!= MEMCACHED_SUCCESS
&& rc
!= MEMCACHED_BUFFERED
)
1944 rc
= memcached_set(memc
, key
, strlen(key
),
1945 randomstuff
, strlen(randomstuff
), 10, 0);
1946 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1949 return TEST_SUCCESS
;
1952 /* Test case provided by Cal Haldenbrand */
1953 static test_return_t
user_supplied_bug2(memcached_st
*memc
)
1955 unsigned int setter
;
1959 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1960 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1962 setter
= 20 * 1024576;
1963 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1964 setter
= 20 * 1024576;
1965 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1966 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1967 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1969 for (x
= 0, errors
= 0; total
< 20 * 1024576 ; x
++)
1972 for (uint32_t x
= 0, errors
= 0; total
< 24576 ; x
++)
1974 memcached_return_t rc
= MEMCACHED_SUCCESS
;
1975 char buffer
[SMALL_STRING_LEN
];
1980 memset(buffer
, 0, SMALL_STRING_LEN
);
1982 snprintf(buffer
, sizeof(buffer
), "%u", x
);
1983 getval
= memcached_get(memc
, buffer
, strlen(buffer
),
1984 &val_len
, &flags
, &rc
);
1985 if (rc
!= MEMCACHED_SUCCESS
)
1987 if (rc
== MEMCACHED_NOTFOUND
)
2001 return TEST_SUCCESS
;
2004 /* Do a large mget() over all the keys we think exist */
2005 #define KEY_COUNT 3000 // * 1024576
2006 static test_return_t
user_supplied_bug3(memcached_st
*memc
)
2008 memcached_return_t rc
;
2009 unsigned int setter
;
2012 size_t key_lengths
[KEY_COUNT
];
2015 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
2016 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2018 setter
= 20 * 1024576;
2019 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
2020 setter
= 20 * 1024576;
2021 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
2022 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
2023 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
2026 keys
= calloc(KEY_COUNT
, sizeof(char *));
2028 for (x
= 0; x
< KEY_COUNT
; x
++)
2032 snprintf(buffer
, 30, "%u", x
);
2033 keys
[x
]= strdup(buffer
);
2034 key_lengths
[x
]= strlen(keys
[x
]);
2037 rc
= memcached_mget(memc
, (const char **)keys
, key_lengths
, KEY_COUNT
);
2038 test_true(rc
== MEMCACHED_SUCCESS
);
2040 test_true(fetch_all_results(memc
) == TEST_SUCCESS
);
2042 for (x
= 0; x
< KEY_COUNT
; x
++)
2046 return TEST_SUCCESS
;
2049 /* Make sure we behave properly if server list has no values */
2050 static test_return_t
user_supplied_bug4(memcached_st
*memc
)
2052 memcached_return_t rc
;
2053 const char *keys
[]= {"fudge", "son", "food"};
2054 size_t key_length
[]= {5, 3, 4};
2057 char return_key
[MEMCACHED_MAX_KEY
];
2058 size_t return_key_length
;
2060 size_t return_value_length
;
2062 /* Here we free everything before running a bunch of mget tests */
2063 memcached_servers_reset(memc
);
2066 /* We need to empty the server before continueing test */
2067 rc
= memcached_flush(memc
, 0);
2068 test_true(rc
== MEMCACHED_NO_SERVERS
);
2070 rc
= memcached_mget(memc
, keys
, key_length
, 3);
2071 test_true(rc
== MEMCACHED_NO_SERVERS
);
2073 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2074 &return_value_length
, &flags
, &rc
)) != NULL
)
2076 test_true(return_value
);
2078 test_true(!return_value
);
2079 test_true(return_value_length
== 0);
2080 test_true(rc
== MEMCACHED_NO_SERVERS
);
2082 for (x
= 0; x
< 3; x
++)
2084 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2085 keys
[x
], key_length
[x
],
2086 (time_t)50, (uint32_t)9);
2087 test_true(rc
== MEMCACHED_NO_SERVERS
);
2090 rc
= memcached_mget(memc
, keys
, key_length
, 3);
2091 test_true(rc
== MEMCACHED_NO_SERVERS
);
2094 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2095 &return_value_length
, &flags
, &rc
)))
2097 test_true(return_value
);
2098 test_true(rc
== MEMCACHED_SUCCESS
);
2099 test_true(return_key_length
== return_value_length
);
2100 test_true(!memcmp(return_value
, return_key
, return_value_length
));
2105 return TEST_SUCCESS
;
2108 #define VALUE_SIZE_BUG5 1048064
2109 static test_return_t
user_supplied_bug5(memcached_st
*memc
)
2111 memcached_return_t rc
;
2112 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
2113 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
2114 char return_key
[MEMCACHED_MAX_KEY
];
2115 size_t return_key_length
;
2117 size_t value_length
;
2121 char insert_data
[VALUE_SIZE_BUG5
];
2123 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2124 insert_data
[x
]= (signed char)rand();
2126 memcached_flush(memc
, 0);
2127 value
= memcached_get(memc
, keys
[0], key_length
[0],
2128 &value_length
, &flags
, &rc
);
2129 test_true(value
== NULL
);
2130 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2133 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2134 &value_length
, &flags
, &rc
)))
2136 test_true(count
== 0);
2138 for (x
= 0; x
< 4; x
++)
2140 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2141 insert_data
, VALUE_SIZE_BUG5
,
2142 (time_t)0, (uint32_t)0);
2143 test_true(rc
== MEMCACHED_SUCCESS
);
2146 for (x
= 0; x
< 10; x
++)
2148 value
= memcached_get(memc
, keys
[0], key_length
[0],
2149 &value_length
, &flags
, &rc
);
2153 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2155 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2156 &value_length
, &flags
, &rc
)))
2161 test_true(count
== 4);
2164 return TEST_SUCCESS
;
2167 static test_return_t
user_supplied_bug6(memcached_st
*memc
)
2169 memcached_return_t rc
;
2170 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
2171 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
2172 char return_key
[MEMCACHED_MAX_KEY
];
2173 size_t return_key_length
;
2175 size_t value_length
;
2179 char insert_data
[VALUE_SIZE_BUG5
];
2181 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2182 insert_data
[x
]= (signed char)rand();
2184 memcached_flush(memc
, 0);
2185 value
= memcached_get(memc
, keys
[0], key_length
[0],
2186 &value_length
, &flags
, &rc
);
2187 test_true(value
== NULL
);
2188 test_true(rc
== MEMCACHED_NOTFOUND
);
2189 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2190 test_true(rc
== MEMCACHED_SUCCESS
);
2193 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2194 &value_length
, &flags
, &rc
)))
2196 test_true(count
== 0);
2197 test_true(rc
== MEMCACHED_END
);
2199 for (x
= 0; x
< 4; x
++)
2201 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2202 insert_data
, VALUE_SIZE_BUG5
,
2203 (time_t)0, (uint32_t)0);
2204 test_true(rc
== MEMCACHED_SUCCESS
);
2207 for (x
= 0; x
< 2; x
++)
2209 value
= memcached_get(memc
, keys
[0], key_length
[0],
2210 &value_length
, &flags
, &rc
);
2214 rc
= memcached_mget(memc
, keys
, key_length
, 4);
2215 test_true(rc
== MEMCACHED_SUCCESS
);
2217 /* We test for purge of partial complete fetches */
2218 for (count
= 3; count
; count
--)
2220 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2221 &value_length
, &flags
, &rc
);
2222 test_true(rc
== MEMCACHED_SUCCESS
);
2223 test_true(!(memcmp(value
, insert_data
, value_length
)));
2224 test_true(value_length
);
2229 return TEST_SUCCESS
;
2232 static test_return_t
user_supplied_bug8(memcached_st
*memc
__attribute__((unused
)))
2234 memcached_return_t rc
;
2236 memcached_st
*memc_clone
;
2238 memcached_server_st
*servers
;
2239 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";
2241 servers
= memcached_servers_parse(server_list
);
2244 mine
= memcached_create(NULL
);
2245 rc
= memcached_server_push(mine
, servers
);
2246 test_true(rc
== MEMCACHED_SUCCESS
);
2247 memcached_server_list_free(servers
);
2250 memc_clone
= memcached_clone(NULL
, mine
);
2252 memcached_quit(mine
);
2253 memcached_quit(memc_clone
);
2256 memcached_free(mine
);
2257 memcached_free(memc_clone
);
2259 return TEST_SUCCESS
;
2262 /* Test flag store/retrieve */
2263 static test_return_t
user_supplied_bug7(memcached_st
*memc
)
2265 memcached_return_t rc
;
2266 const char *keys
= "036790384900";
2267 size_t key_length
= strlen(keys
);
2268 char return_key
[MEMCACHED_MAX_KEY
];
2269 size_t return_key_length
;
2271 size_t value_length
;
2274 char insert_data
[VALUE_SIZE_BUG5
];
2276 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2277 insert_data
[x
]= (signed char)rand();
2279 memcached_flush(memc
, 0);
2282 rc
= memcached_set(memc
, keys
, key_length
,
2283 insert_data
, VALUE_SIZE_BUG5
,
2285 test_true(rc
== MEMCACHED_SUCCESS
);
2288 value
= memcached_get(memc
, keys
, key_length
,
2289 &value_length
, &flags
, &rc
);
2290 test_true(flags
== 245);
2294 rc
= memcached_mget(memc
, &keys
, &key_length
, 1);
2297 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2298 &value_length
, &flags
, &rc
);
2299 test_true(flags
== 245);
2304 return TEST_SUCCESS
;
2307 static test_return_t
user_supplied_bug9(memcached_st
*memc
)
2309 memcached_return_t rc
;
2310 const char *keys
[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
2311 size_t key_length
[3];
2316 char return_key
[MEMCACHED_MAX_KEY
];
2317 size_t return_key_length
;
2319 size_t return_value_length
;
2322 key_length
[0]= strlen("UDATA:edevil@sapo.pt");
2323 key_length
[1]= strlen("fudge&*@#");
2324 key_length
[2]= strlen("for^#@&$not");
2327 for (x
= 0; x
< 3; x
++)
2329 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2330 keys
[x
], key_length
[x
],
2331 (time_t)50, (uint32_t)9);
2332 test_true(rc
== MEMCACHED_SUCCESS
);
2335 rc
= memcached_mget(memc
, keys
, key_length
, 3);
2336 test_true(rc
== MEMCACHED_SUCCESS
);
2338 /* We need to empty the server before continueing test */
2339 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2340 &return_value_length
, &flags
, &rc
)) != NULL
)
2342 test_true(return_value
);
2346 test_true(count
== 3);
2348 return TEST_SUCCESS
;
2351 /* We are testing with aggressive timeout to get failures */
2352 static test_return_t
user_supplied_bug10(memcached_st
*memc
)
2354 const char *key
= "foo";
2356 size_t value_length
= 512;
2359 memcached_return_t rc
;
2360 unsigned int set
= 1;
2361 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2364 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2365 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2367 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
,
2370 value
= (char*)malloc(value_length
* sizeof(char));
2372 for (x
= 0; x
< value_length
; x
++)
2373 value
[x
]= (char) (x
% 127);
2375 for (x
= 1; x
<= 100000; ++x
)
2377 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2379 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_WRITE_FAILURE
||
2380 rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_TIMEOUT
);
2382 if (rc
== MEMCACHED_WRITE_FAILURE
|| rc
== MEMCACHED_TIMEOUT
)
2387 memcached_free(mclone
);
2389 return TEST_SUCCESS
;
2393 We are looking failures in the async protocol
2395 static test_return_t
user_supplied_bug11(memcached_st
*memc
)
2397 const char *key
= "foo";
2399 size_t value_length
= 512;
2402 memcached_return_t rc
;
2403 unsigned int set
= 1;
2405 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2407 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2408 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2410 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
,
2413 timeout
= (int32_t)memcached_behavior_get(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
2415 test_true(timeout
== -1);
2417 value
= (char*)malloc(value_length
* sizeof(char));
2419 for (x
= 0; x
< value_length
; x
++)
2420 value
[x
]= (char) (x
% 127);
2422 for (x
= 1; x
<= 100000; ++x
)
2424 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2428 memcached_free(mclone
);
2430 return TEST_SUCCESS
;
2434 Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
2436 static test_return_t
user_supplied_bug12(memcached_st
*memc
)
2438 memcached_return_t rc
;
2440 size_t value_length
;
2442 uint64_t number_value
;
2444 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2445 &value_length
, &flags
, &rc
);
2446 test_true(value
== NULL
);
2447 test_true(rc
== MEMCACHED_NOTFOUND
);
2449 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2452 test_true(value
== NULL
);
2453 /* The binary protocol will set the key if it doesn't exist */
2454 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1)
2456 test_true(rc
== MEMCACHED_SUCCESS
);
2460 test_true(rc
== MEMCACHED_NOTFOUND
);
2463 rc
= memcached_set(memc
, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
2465 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2466 &value_length
, &flags
, &rc
);
2468 test_true(rc
== MEMCACHED_SUCCESS
);
2471 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2473 test_true(number_value
== 2);
2474 test_true(rc
== MEMCACHED_SUCCESS
);
2476 return TEST_SUCCESS
;
2480 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2481 set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
2483 static test_return_t
user_supplied_bug13(memcached_st
*memc
)
2485 char key
[] = "key34567890";
2487 memcached_return_t rc
;
2488 size_t overflowSize
;
2490 char commandFirst
[]= "set key34567890 0 0 ";
2491 char commandLast
[] = " \r\n"; /* first line of command sent to server */
2492 size_t commandLength
;
2495 commandLength
= strlen(commandFirst
) + strlen(commandLast
) + 4; /* 4 is number of characters in size, probably 8196 */
2497 overflowSize
= MEMCACHED_MAX_BUFFER
- commandLength
;
2499 for (testSize
= overflowSize
- 1; testSize
< overflowSize
+ 1; testSize
++)
2501 overflow
= malloc(testSize
);
2502 test_true(overflow
!= NULL
);
2504 memset(overflow
, 'x', testSize
);
2505 rc
= memcached_set(memc
, key
, strlen(key
),
2506 overflow
, testSize
, 0, 0);
2507 test_true(rc
== MEMCACHED_SUCCESS
);
2511 return TEST_SUCCESS
;
2516 Test values of many different sizes
2517 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2518 set key34567890 0 0 8169 \r\n
2519 is sent followed by buffer of size 8169, followed by 8169
2521 static test_return_t
user_supplied_bug14(memcached_st
*memc
)
2524 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2525 memcached_return_t rc
;
2526 const char *key
= "foo";
2528 size_t value_length
= 18000;
2530 size_t string_length
;
2533 size_t current_length
;
2535 value
= (char*)malloc(value_length
);
2538 for (x
= 0; x
< value_length
; x
++)
2539 value
[x
] = (char) (x
% 127);
2541 for (current_length
= 0; current_length
< value_length
; current_length
++)
2543 rc
= memcached_set(memc
, key
, strlen(key
),
2544 value
, current_length
,
2545 (time_t)0, (uint32_t)0);
2546 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
2548 string
= memcached_get(memc
, key
, strlen(key
),
2549 &string_length
, &flags
, &rc
);
2551 test_true(rc
== MEMCACHED_SUCCESS
);
2552 test_true(string_length
== current_length
);
2553 test_true(!memcmp(string
, value
, string_length
));
2560 return TEST_SUCCESS
;
2564 Look for zero length value problems
2566 static test_return_t
user_supplied_bug15(memcached_st
*memc
)
2569 memcached_return_t rc
;
2570 const char *key
= "mykey";
2575 for (x
= 0; x
< 2; x
++)
2577 rc
= memcached_set(memc
, key
, strlen(key
),
2579 (time_t)0, (uint32_t)0);
2581 test_true(rc
== MEMCACHED_SUCCESS
);
2583 value
= memcached_get(memc
, key
, strlen(key
),
2584 &length
, &flags
, &rc
);
2586 test_true(rc
== MEMCACHED_SUCCESS
);
2587 test_true(value
== NULL
);
2588 test_true(length
== 0);
2589 test_true(flags
== 0);
2591 value
= memcached_get(memc
, key
, strlen(key
),
2592 &length
, &flags
, &rc
);
2594 test_true(rc
== MEMCACHED_SUCCESS
);
2595 test_true(value
== NULL
);
2596 test_true(length
== 0);
2597 test_true(flags
== 0);
2600 return TEST_SUCCESS
;
2603 /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
2604 static test_return_t
user_supplied_bug16(memcached_st
*memc
)
2606 memcached_return_t rc
;
2607 const char *key
= "mykey";
2612 rc
= memcached_set(memc
, key
, strlen(key
),
2614 (time_t)0, UINT32_MAX
);
2616 test_true(rc
== MEMCACHED_SUCCESS
);
2618 value
= memcached_get(memc
, key
, strlen(key
),
2619 &length
, &flags
, &rc
);
2621 test_true(rc
== MEMCACHED_SUCCESS
);
2622 test_true(value
== NULL
);
2623 test_true(length
== 0);
2624 test_true(flags
== UINT32_MAX
);
2626 return TEST_SUCCESS
;
2630 /* Check the validity of chinese key*/
2631 static test_return_t
user_supplied_bug17(memcached_st
*memc
)
2633 memcached_return_t rc
;
2634 const char *key
= "豆瓣";
2635 const char *value
="我们在炎热抑郁的夏天无法停止豆瓣";
2640 rc
= memcached_set(memc
, key
, strlen(key
),
2641 value
, strlen(value
),
2644 test_true(rc
== MEMCACHED_SUCCESS
);
2646 value2
= memcached_get(memc
, key
, strlen(key
),
2647 &length
, &flags
, &rc
);
2649 test_true(length
==strlen(value
));
2650 test_true(rc
== MEMCACHED_SUCCESS
);
2651 test_true(memcmp(value
, value2
, length
)==0);
2654 return TEST_SUCCESS
;
2662 static test_return_t
user_supplied_bug19(memcached_st
*memc
)
2665 memcached_server_st
*s
;
2666 memcached_return_t res
;
2670 m
= memcached_create(NULL
);
2671 memcached_server_add_with_weight(m
, "localhost", 11311, 100);
2672 memcached_server_add_with_weight(m
, "localhost", 11312, 100);
2674 s
= memcached_server_by_key(m
, "a", 1, &res
);
2675 memcached_server_free(s
);
2679 return TEST_SUCCESS
;
2682 /* CAS test from Andei */
2683 static test_return_t
user_supplied_bug20(memcached_st
*memc
)
2685 memcached_return_t status
;
2686 memcached_result_st
*result
, result_obj
;
2687 const char *key
= "abc";
2688 size_t key_len
= strlen("abc");
2689 const char *value
= "foobar";
2690 size_t value_len
= strlen(value
);
2692 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
2694 status
= memcached_set(memc
, key
, key_len
, value
, value_len
, (time_t)0, (uint32_t)0);
2695 test_true(status
== MEMCACHED_SUCCESS
);
2697 status
= memcached_mget(memc
, &key
, &key_len
, 1);
2698 test_true(status
== MEMCACHED_SUCCESS
);
2700 result
= memcached_result_create(memc
, &result_obj
);
2703 memcached_result_create(memc
, &result_obj
);
2704 result
= memcached_fetch_result(memc
, &result_obj
, &status
);
2707 test_true(status
== MEMCACHED_SUCCESS
);
2709 memcached_result_free(result
);
2711 return TEST_SUCCESS
;
2714 #include "ketama_test_cases.h"
2715 static test_return_t
user_supplied_bug18(memcached_st
*trash
)
2717 memcached_return_t rc
;
2720 memcached_server_st
*server_pool
;
2725 memc
= memcached_create(NULL
);
2728 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2729 test_true(rc
== MEMCACHED_SUCCESS
);
2731 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2732 test_true(value
== 1);
2734 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2735 test_true(rc
== MEMCACHED_SUCCESS
);
2737 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2738 test_true(value
== MEMCACHED_HASH_MD5
);
2740 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");
2741 memcached_server_push(memc
, server_pool
);
2743 /* verify that the server list was parsed okay. */
2744 test_true(memcached_server_count(memc
) == 8);
2745 test_true(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
2746 test_true(server_pool
[0].port
== 11211);
2747 test_true(server_pool
[0].weight
== 600);
2748 test_true(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
2749 test_true(server_pool
[2].port
== 11211);
2750 test_true(server_pool
[2].weight
== 200);
2751 test_true(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
2752 test_true(server_pool
[7].port
== 11211);
2753 test_true(server_pool
[7].weight
== 100);
2755 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
2756 * us test the boundary wraparound.
2758 test_true(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
2760 /* verify the standard ketama set. */
2761 for (x
= 0; x
< 99; x
++)
2763 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
2764 memcached_server_instance_st
*instance
=
2765 memcached_server_instance_fetch(memc
, server_idx
);
2766 char *hostname
= instance
->hostname
;
2767 test_strcmp(hostname
, ketama_test_cases
[x
].server
);
2770 memcached_server_list_free(server_pool
);
2771 memcached_free(memc
);
2773 return TEST_SUCCESS
;
2776 /* Large mget() of missing keys with binary proto
2778 * If many binary quiet commands (such as getq's in an mget) fill the output
2779 * buffer and the server chooses not to respond, memcached_flush hangs. See
2780 * http://lists.tangent.org/pipermail/libmemcached/2009-August/000918.html
2783 /* sighandler_t function that always asserts false */
2784 static void fail(int unused
__attribute__((unused
)))
2790 static test_return_t
_user_supplied_bug21(memcached_st
* memc
, size_t key_count
)
2792 memcached_return_t rc
;
2795 size_t* key_lengths
;
2796 void (*oldalarm
)(int);
2797 memcached_st
*memc_clone
;
2799 memc_clone
= memcached_clone(NULL
, memc
);
2800 test_true(memc_clone
);
2802 /* only binproto uses getq for mget */
2803 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
2805 /* empty the cache to ensure misses (hence non-responses) */
2806 rc
= memcached_flush(memc_clone
, 0);
2807 test_true(rc
== MEMCACHED_SUCCESS
);
2809 key_lengths
= calloc(key_count
, sizeof(size_t));
2810 keys
= calloc(key_count
, sizeof(char *));
2812 for (x
= 0; x
< key_count
; x
++)
2816 snprintf(buffer
, 30, "%u", x
);
2817 keys
[x
]= strdup(buffer
);
2818 key_lengths
[x
]= strlen(keys
[x
]);
2821 oldalarm
= signal(SIGALRM
, fail
);
2824 rc
= memcached_mget(memc_clone
, (const char **)keys
, key_lengths
, key_count
);
2825 test_true(rc
== MEMCACHED_SUCCESS
);
2828 signal(SIGALRM
, oldalarm
);
2830 test_true(fetch_all_results(memc
) == TEST_SUCCESS
);
2832 for (x
= 0; x
< key_count
; x
++)
2837 memcached_free(memc_clone
);
2839 return TEST_SUCCESS
;
2842 static test_return_t
pre_binary(memcached_st
*memc
);
2844 static test_return_t
user_supplied_bug21(memcached_st
*memc
)
2846 test_return_t test_rc
;
2847 test_rc
= pre_binary(memc
);
2849 if (test_rc
!= TEST_SUCCESS
)
2854 /* should work as of r580 */
2855 rc
= _user_supplied_bug21(memc
, 10);
2856 test_true(rc
== TEST_SUCCESS
);
2858 /* should fail as of r580 */
2859 rc
= _user_supplied_bug21(memc
, 1000);
2860 test_true(rc
== TEST_SUCCESS
);
2862 return TEST_SUCCESS
;
2865 static test_return_t
auto_eject_hosts(memcached_st
*trash
)
2868 memcached_server_instance_st
*instance
;
2870 memcached_return_t rc
;
2871 memcached_st
*memc
= memcached_create(NULL
);
2874 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2875 test_true(rc
== MEMCACHED_SUCCESS
);
2877 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2878 test_true(value
== 1);
2880 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2881 test_true(rc
== MEMCACHED_SUCCESS
);
2883 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2884 test_true(value
== MEMCACHED_HASH_MD5
);
2886 /* server should be removed when in delay */
2887 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
, 1);
2888 test_true(rc
== MEMCACHED_SUCCESS
);
2890 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
);
2891 test_true(value
== 1);
2893 memcached_server_st
*server_pool
;
2894 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");
2895 memcached_server_push(memc
, server_pool
);
2897 /* verify that the server list was parsed okay. */
2898 test_true(memcached_server_count(memc
) == 8);
2899 test_true(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
2900 test_true(server_pool
[0].port
== 11211);
2901 test_true(server_pool
[0].weight
== 600);
2902 test_true(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
2903 test_true(server_pool
[2].port
== 11211);
2904 test_true(server_pool
[2].weight
== 200);
2905 test_true(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
2906 test_true(server_pool
[7].port
== 11211);
2907 test_true(server_pool
[7].weight
== 100);
2909 instance
= memcached_server_instance_fetch(memc
, 2);
2910 instance
->next_retry
= time(NULL
) + 15;
2911 memc
->next_distribution_rebuild
= time(NULL
) - 1;
2913 for (size_t x
= 0; x
< 99; x
++)
2915 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
2916 test_true(server_idx
!= 2);
2919 /* and re-added when it's back. */
2920 instance
->next_retry
= time(NULL
) - 1;
2921 memc
->next_distribution_rebuild
= time(NULL
) - 1;
2922 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
,
2923 memc
->distribution
);
2924 for (size_t x
= 0; x
< 99; x
++)
2926 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
2927 // We re-use instance from above.
2929 memcached_server_instance_fetch(memc
, server_idx
);
2930 char *hostname
= instance
->hostname
;
2931 test_true(strcmp(hostname
, ketama_test_cases
[x
].server
) == 0);
2934 memcached_server_list_free(server_pool
);
2935 memcached_free(memc
);
2937 return TEST_SUCCESS
;
2940 static test_return_t
output_ketama_weighted_keys(memcached_st
*trash
)
2944 memcached_return_t rc
;
2945 memcached_st
*memc
= memcached_create(NULL
);
2949 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2950 test_true(rc
== MEMCACHED_SUCCESS
);
2952 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2953 test_true(value
== 1);
2955 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2956 test_true(rc
== MEMCACHED_SUCCESS
);
2958 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2959 test_true(value
== MEMCACHED_HASH_MD5
);
2962 test_true(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
) == MEMCACHED_SUCCESS
);
2964 memcached_server_st
*server_pool
;
2965 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");
2966 memcached_server_push(memc
, server_pool
);
2968 // @todo this needs to be refactored to actually test something.
2971 if ((fp
= fopen("ketama_keys.txt", "w")))
2975 printf("cannot write to file ketama_keys.txt");
2976 return TEST_FAILURE
;
2979 for (int x
= 0; x
< 10000; x
++)
2982 sprintf(key
, "%d", x
);
2984 uint32_t server_idx
= memcached_generate_hash(memc
, key
, strlen(key
));
2985 char *hostname
= memc
->hosts
[server_idx
].hostname
;
2986 in_port_t port
= memc
->hosts
[server_idx
].port
;
2987 fprintf(fp
, "key %s is on host /%s:%u\n", key
, hostname
, port
);
2991 memcached_server_list_free(server_pool
);
2992 memcached_free(memc
);
2994 return TEST_SUCCESS
;
2998 static test_return_t
result_static(memcached_st
*memc
)
3000 memcached_result_st result
;
3001 memcached_result_st
*result_ptr
;
3003 result_ptr
= memcached_result_create(memc
, &result
);
3004 test_true(result
.options
.is_allocated
== false);
3005 test_true(memcached_is_initialized(&result
) == true);
3006 test_true(result_ptr
);
3007 test_true(result_ptr
== &result
);
3009 memcached_result_free(&result
);
3011 test_true(result
.options
.is_allocated
== false);
3012 test_true(memcached_is_initialized(&result
) == false);
3014 return TEST_SUCCESS
;
3017 static test_return_t
result_alloc(memcached_st
*memc
)
3019 memcached_result_st
*result_ptr
;
3021 result_ptr
= memcached_result_create(memc
, NULL
);
3022 test_true(result_ptr
);
3023 test_true(result_ptr
->options
.is_allocated
== true);
3024 test_true(memcached_is_initialized(result_ptr
) == true);
3025 memcached_result_free(result_ptr
);
3027 return TEST_SUCCESS
;
3030 static test_return_t
string_static_null(memcached_st
*memc
)
3032 memcached_string_st string
;
3033 memcached_string_st
*string_ptr
;
3035 string_ptr
= memcached_string_create(memc
, &string
, 0);
3036 test_true(string
.options
.is_initialized
== true);
3037 test_true(string_ptr
);
3039 /* The following two better be the same! */
3040 test_true(memcached_is_allocated(string_ptr
) == false);
3041 test_true(memcached_is_allocated(&string
) == false);
3042 test_true(&string
== string_ptr
);
3044 test_true(string
.options
.is_initialized
== true);
3045 test_true(memcached_is_initialized(&string
) == true);
3046 memcached_string_free(&string
);
3047 test_true(memcached_is_initialized(&string
) == false);
3049 return TEST_SUCCESS
;
3052 static test_return_t
string_alloc_null(memcached_st
*memc
)
3054 memcached_string_st
*string
;
3056 string
= memcached_string_create(memc
, NULL
, 0);
3058 test_true(memcached_is_allocated(string
) == true);
3059 test_true(memcached_is_initialized(string
) == true);
3060 memcached_string_free(string
);
3062 return TEST_SUCCESS
;
3065 static test_return_t
string_alloc_with_size(memcached_st
*memc
)
3067 memcached_string_st
*string
;
3069 string
= memcached_string_create(memc
, NULL
, 1024);
3071 test_true(memcached_is_allocated(string
) == true);
3072 test_true(memcached_is_initialized(string
) == true);
3073 memcached_string_free(string
);
3075 return TEST_SUCCESS
;
3078 static test_return_t
string_alloc_with_size_toobig(memcached_st
*memc
)
3080 memcached_string_st
*string
;
3082 string
= memcached_string_create(memc
, NULL
, SIZE_MAX
);
3083 test_true(string
== NULL
);
3085 return TEST_SUCCESS
;
3088 static test_return_t
string_alloc_append(memcached_st
*memc
)
3091 char buffer
[SMALL_STRING_LEN
];
3092 memcached_string_st
*string
;
3094 /* Ring the bell! */
3095 memset(buffer
, 6, SMALL_STRING_LEN
);
3097 string
= memcached_string_create(memc
, NULL
, 100);
3099 test_true(memcached_is_allocated(string
) == true);
3100 test_true(memcached_is_initialized(string
) == true);
3102 for (x
= 0; x
< 1024; x
++)
3104 memcached_return_t rc
;
3105 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
3106 test_true(rc
== MEMCACHED_SUCCESS
);
3108 test_true(memcached_is_allocated(string
) == true);
3109 memcached_string_free(string
);
3111 return TEST_SUCCESS
;
3114 static test_return_t
string_alloc_append_toobig(memcached_st
*memc
)
3116 memcached_return_t rc
;
3118 char buffer
[SMALL_STRING_LEN
];
3119 memcached_string_st
*string
;
3121 /* Ring the bell! */
3122 memset(buffer
, 6, SMALL_STRING_LEN
);
3124 string
= memcached_string_create(memc
, NULL
, 100);
3126 test_true(memcached_is_allocated(string
) == true);
3127 test_true(memcached_is_initialized(string
) == true);
3129 for (x
= 0; x
< 1024; x
++)
3131 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
3132 test_true(rc
== MEMCACHED_SUCCESS
);
3134 rc
= memcached_string_append(string
, buffer
, SIZE_MAX
);
3135 test_true(rc
== MEMCACHED_MEMORY_ALLOCATION_FAILURE
);
3136 test_true(memcached_is_allocated(string
) == true);
3137 memcached_string_free(string
);
3139 return TEST_SUCCESS
;
3142 static test_return_t
cleanup_pairs(memcached_st
*memc
__attribute__((unused
)))
3144 pairs_free(global_pairs
);
3146 return TEST_SUCCESS
;
3149 static test_return_t
generate_pairs(memcached_st
*memc
__attribute__((unused
)))
3151 global_pairs
= pairs_generate(GLOBAL_COUNT
, 400);
3152 global_count
= GLOBAL_COUNT
;
3154 for (size_t x
= 0; x
< global_count
; x
++)
3156 global_keys
[x
]= global_pairs
[x
].key
;
3157 global_keys_length
[x
]= global_pairs
[x
].key_length
;
3160 return TEST_SUCCESS
;
3163 static test_return_t
generate_large_pairs(memcached_st
*memc
__attribute__((unused
)))
3165 global_pairs
= pairs_generate(GLOBAL2_COUNT
, MEMCACHED_MAX_BUFFER
+10);
3166 global_count
= GLOBAL2_COUNT
;
3168 for (size_t x
= 0; x
< global_count
; x
++)
3170 global_keys
[x
]= global_pairs
[x
].key
;
3171 global_keys_length
[x
]= global_pairs
[x
].key_length
;
3174 return TEST_SUCCESS
;
3177 static test_return_t
generate_data(memcached_st
*memc
)
3179 execute_set(memc
, global_pairs
, global_count
);
3181 return TEST_SUCCESS
;
3184 static test_return_t
generate_data_with_stats(memcached_st
*memc
)
3186 memcached_stat_st
*stat_p
;
3187 memcached_return_t rc
;
3188 uint32_t host_index
= 0;
3189 execute_set(memc
, global_pairs
, global_count
);
3191 //TODO: hosts used size stats
3192 stat_p
= memcached_stat(memc
, NULL
, &rc
);
3195 for (host_index
= 0; host_index
< SERVERS_TO_CREATE
; host_index
++)
3197 /* This test was changes so that "make test" would work properlly */
3199 memcached_server_instance_st
*instance
=
3200 memcached_server_instance_fetch(memc
, host_index
);
3202 printf("\nserver %u|%s|%u bytes: %llu\n", host_index
, instance
->hostname
, instance
->port
, (unsigned long long)(stat_p
+ host_index
)->bytes
);
3204 test_true((unsigned long long)(stat_p
+ host_index
)->bytes
);
3207 memcached_stat_free(NULL
, stat_p
);
3209 return TEST_SUCCESS
;
3211 static test_return_t
generate_buffer_data(memcached_st
*memc
)
3216 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
3217 generate_data(memc
);
3219 return TEST_SUCCESS
;
3222 static test_return_t
get_read_count(memcached_st
*memc
)
3224 memcached_return_t rc
;
3225 memcached_st
*memc_clone
;
3227 memc_clone
= memcached_clone(NULL
, memc
);
3228 test_true(memc_clone
);
3230 memcached_server_add_with_weight(memc_clone
, "localhost", 6666, 0);
3234 size_t return_value_length
;
3238 for (size_t x
= count
= 0; x
< global_count
; x
++)
3240 return_value
= memcached_get(memc_clone
, global_keys
[x
], global_keys_length
[x
],
3241 &return_value_length
, &flags
, &rc
);
3242 if (rc
== MEMCACHED_SUCCESS
)
3251 memcached_free(memc_clone
);
3253 return TEST_SUCCESS
;
3256 static test_return_t
get_read(memcached_st
*memc
)
3258 memcached_return_t rc
;
3262 size_t return_value_length
;
3265 for (size_t x
= 0; x
< global_count
; x
++)
3267 return_value
= memcached_get(memc
, global_keys
[x
], global_keys_length
[x
],
3268 &return_value_length
, &flags
, &rc
);
3270 test_true(return_value);
3271 test_true(rc == MEMCACHED_SUCCESS);
3273 if (rc
== MEMCACHED_SUCCESS
&& return_value
)
3278 return TEST_SUCCESS
;
3281 static test_return_t
mget_read(memcached_st
*memc
)
3283 memcached_return_t rc
;
3285 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
3286 test_true(rc
== MEMCACHED_SUCCESS
);
3287 test_true(fetch_all_results(memc
) == TEST_SUCCESS
);
3289 return TEST_SUCCESS
;
3292 static test_return_t
mget_read_result(memcached_st
*memc
)
3294 memcached_return_t rc
;
3296 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
3297 test_true(rc
== MEMCACHED_SUCCESS
);
3298 /* Turn this into a help function */
3300 memcached_result_st results_obj
;
3301 memcached_result_st
*results
;
3303 results
= memcached_result_create(memc
, &results_obj
);
3305 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
3308 test_true(rc
== MEMCACHED_SUCCESS
);
3311 memcached_result_free(&results_obj
);
3314 return TEST_SUCCESS
;
3317 static test_return_t
mget_read_function(memcached_st
*memc
)
3319 memcached_return_t rc
;
3321 memcached_execute_fn callbacks
[1];
3323 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
3324 test_true(rc
== MEMCACHED_SUCCESS
);
3326 callbacks
[0]= &callback_counter
;
3328 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
3330 return TEST_SUCCESS
;
3333 static test_return_t
delete_generate(memcached_st
*memc
)
3335 for (size_t x
= 0; x
< global_count
; x
++)
3337 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3340 return TEST_SUCCESS
;
3343 static test_return_t
delete_buffer_generate(memcached_st
*memc
)
3348 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
3350 for (size_t x
= 0; x
< global_count
; x
++)
3352 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3355 return TEST_SUCCESS
;
3358 static test_return_t
add_host_test1(memcached_st
*memc
)
3360 memcached_return_t rc
;
3361 char servername
[]= "0.example.com";
3362 memcached_server_st
*servers
;
3364 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
3366 test_true(1 == memcached_server_list_count(servers
));
3368 for (size_t x
= 2; x
< 20; x
++)
3370 char buffer
[SMALL_STRING_LEN
];
3372 snprintf(buffer
, SMALL_STRING_LEN
, "%zu.example.com", 400+x
);
3373 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
3375 test_true(rc
== MEMCACHED_SUCCESS
);
3376 test_true(x
== memcached_server_list_count(servers
));
3379 rc
= memcached_server_push(memc
, servers
);
3380 test_true(rc
== MEMCACHED_SUCCESS
);
3381 rc
= memcached_server_push(memc
, servers
);
3382 test_true(rc
== MEMCACHED_SUCCESS
);
3384 memcached_server_list_free(servers
);
3386 return TEST_SUCCESS
;
3389 static test_return_t
pre_nonblock(memcached_st
*memc
)
3391 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3393 return TEST_SUCCESS
;
3396 static test_return_t
pre_cork(memcached_st
*memc
)
3398 memcached_return_t rc
;
3400 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CORK
, set
);
3402 if (rc
== MEMCACHED_SUCCESS
)
3403 return TEST_SUCCESS
;
3405 return TEST_SKIPPED
;
3408 static test_return_t
pre_cork_and_nonblock(memcached_st
*memc
)
3414 if (rc
!= TEST_SUCCESS
)
3417 return pre_nonblock(memc
);
3420 static test_return_t
pre_nonblock_binary(memcached_st
*memc
)
3422 memcached_return_t rc
= MEMCACHED_FAILURE
;
3423 memcached_st
*memc_clone
;
3424 memcached_server_instance_st
*instance
;
3426 memc_clone
= memcached_clone(NULL
, memc
);
3427 test_true(memc_clone
);
3428 // The memcached_version needs to be done on a clone, because the server
3429 // will not toggle protocol on an connection.
3430 memcached_version(memc_clone
);
3432 instance
= memcached_server_instance_fetch(memc_clone
, 0);
3434 if (instance
->major_version
>= 1 && instance
->minor_version
> 2)
3436 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3437 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3438 test_true(rc
== MEMCACHED_SUCCESS
);
3439 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3443 return TEST_SKIPPED
;
3446 memcached_free(memc_clone
);
3448 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3451 static test_return_t
pre_murmur(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_jenkins(memcached_st
*memc
)
3460 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_JENKINS
);
3462 return TEST_SUCCESS
;
3466 static test_return_t
pre_md5(memcached_st
*memc
)
3468 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MD5
);
3470 return TEST_SUCCESS
;
3473 static test_return_t
pre_crc(memcached_st
*memc
)
3475 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_CRC
);
3477 return TEST_SUCCESS
;
3480 static test_return_t
pre_hsieh(memcached_st
*memc
)
3482 #ifdef HAVE_HSIEH_HASH
3483 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_HSIEH
);
3484 return TEST_SUCCESS
;
3487 return TEST_SKIPPED
;
3491 static test_return_t
pre_hash_fnv1_64(memcached_st
*memc
)
3493 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
3495 return TEST_SUCCESS
;
3498 static test_return_t
pre_hash_fnv1a_64(memcached_st
*memc
)
3500 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_64
);
3502 return TEST_SUCCESS
;
3505 static test_return_t
pre_hash_fnv1_32(memcached_st
*memc
)
3507 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_32
);
3509 return TEST_SUCCESS
;
3512 static test_return_t
pre_hash_fnv1a_32(memcached_st
*memc
)
3514 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_32
);
3516 return TEST_SUCCESS
;
3519 static test_return_t
pre_behavior_ketama(memcached_st
*memc
)
3521 memcached_return_t rc
;
3524 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA
, 1);
3525 test_true(rc
== MEMCACHED_SUCCESS
);
3527 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA
);
3528 test_true(value
== 1);
3530 return TEST_SUCCESS
;
3533 static test_return_t
pre_behavior_ketama_weighted(memcached_st
*memc
)
3535 memcached_return_t rc
;
3538 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
3539 test_true(rc
== MEMCACHED_SUCCESS
);
3541 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
3542 test_true(value
== 1);
3544 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
3545 test_true(rc
== MEMCACHED_SUCCESS
);
3547 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
3548 test_true(value
== MEMCACHED_HASH_MD5
);
3550 return TEST_SUCCESS
;
3554 @note This should be testing to see if the server really supports the binary protocol.
3556 static test_return_t
pre_binary(memcached_st
*memc
)
3558 memcached_return_t rc
= MEMCACHED_FAILURE
;
3559 memcached_st
*memc_clone
;
3560 memcached_server_instance_st
*instance
;
3562 memc_clone
= memcached_clone(NULL
, memc
);
3563 test_true(memc_clone
);
3564 // The memcached_version needs to be done on a clone, because the server
3565 // will not toggle protocol on an connection.
3566 memcached_version(memc_clone
);
3568 instance
= memcached_server_instance_fetch(memc_clone
, 0);
3570 if (instance
->major_version
>= 1 && instance
->minor_version
> 2)
3572 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3573 test_true(rc
== MEMCACHED_SUCCESS
);
3574 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3577 memcached_free(memc_clone
);
3579 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3583 static test_return_t
pre_replication(memcached_st
*memc
)
3585 test_return_t test_rc
;
3586 test_rc
= pre_binary(memc
);
3588 if (test_rc
!= TEST_SUCCESS
)
3592 * Make sure that we store the item on all servers
3593 * (master + replicas == number of servers)
3595 memcached_return_t rc
;
3596 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
,
3597 memcached_server_count(memc
) - 1);
3598 test_true(rc
== MEMCACHED_SUCCESS
);
3599 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
) == memcached_server_count(memc
) - 1);
3601 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3605 static test_return_t
pre_replication_noblock(memcached_st
*memc
)
3609 rc
= pre_replication(memc
);
3610 if (rc
!= TEST_SUCCESS
)
3613 rc
= pre_nonblock(memc
);
3619 static void my_free(const memcached_st
*ptr
__attribute__((unused
)), void *mem
)
3621 #ifdef HARD_MALLOC_TESTS
3622 void *real_ptr
= (mem
== NULL
) ? mem
: (void*)((caddr_t
)mem
- 8);
3630 static void *my_malloc(const memcached_st
*ptr
__attribute__((unused
)), const size_t size
)
3632 #ifdef HARD_MALLOC_TESTS
3633 void *ret
= malloc(size
+ 8);
3636 ret
= (void*)((caddr_t
)ret
+ 8);
3639 void *ret
= malloc(size
);
3644 memset(ret
, 0xff, size
);
3651 static void *my_realloc(const memcached_st
*ptr
__attribute__((unused
)), void *mem
, const size_t size
)
3653 #ifdef HARD_MALLOC_TESTS
3654 void *real_ptr
= (mem
== NULL
) ? NULL
: (void*)((caddr_t
)mem
- 8);
3655 void *nmem
= realloc(real_ptr
, size
+ 8);
3660 ret
= (void*)((caddr_t
)nmem
+ 8);
3665 return realloc(mem
, size
);
3670 static void *my_calloc(const memcached_st
*ptr
__attribute__((unused
)), size_t nelem
, const size_t size
)
3672 #ifdef HARD_MALLOC_TESTS
3673 void *mem
= my_malloc(ptr
, nelem
* size
);
3676 memset(mem
, 0, nelem
* size
);
3681 return calloc(nelem
, size
);
3686 static test_return_t
set_prefix(memcached_st
*memc
)
3688 memcached_return_t rc
;
3689 const char *key
= "mine";
3692 /* Make sure be default none exists */
3693 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3694 test_true(rc
== MEMCACHED_FAILURE
);
3696 /* Test a clean set */
3697 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3698 test_true(rc
== MEMCACHED_SUCCESS
);
3700 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3701 test_true(memcmp(value
, key
, 4) == 0);
3702 test_true(rc
== MEMCACHED_SUCCESS
);
3704 /* Test that we can turn it off */
3705 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3706 test_true(rc
== MEMCACHED_SUCCESS
);
3708 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3709 test_true(rc
== MEMCACHED_FAILURE
);
3711 /* Now setup for main test */
3712 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3713 test_true(rc
== MEMCACHED_SUCCESS
);
3715 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3716 test_true(rc
== MEMCACHED_SUCCESS
);
3717 test_true(memcmp(value
, key
, 4) == 0);
3719 /* Set to Zero, and then Set to something too large */
3722 memset(long_key
, 0, 255);
3724 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3725 test_true(rc
== MEMCACHED_SUCCESS
);
3727 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3728 test_true(rc
== MEMCACHED_FAILURE
);
3729 test_true(value
== NULL
);
3731 /* Test a long key for failure */
3732 /* TODO, extend test to determine based on setting, what result should be */
3733 strcpy(long_key
, "Thisismorethentheallottednumberofcharacters");
3734 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3735 //test_true(rc == MEMCACHED_BAD_KEY_PROVIDED);
3736 test_true(rc
== MEMCACHED_SUCCESS
);
3738 /* Now test a key with spaces (which will fail from long key, since bad key is not set) */
3739 strcpy(long_key
, "This is more then the allotted number of characters");
3740 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3741 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3743 /* Test for a bad prefix, but with a short key */
3744 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, 1);
3745 test_true(rc
== MEMCACHED_SUCCESS
);
3747 strcpy(long_key
, "dog cat");
3748 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3749 test_true(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3752 return TEST_SUCCESS
;
3756 #ifdef MEMCACHED_ENABLE_DEPRECATED
3757 static test_return_t
deprecated_set_memory_alloc(memcached_st
*memc
)
3759 void *test_ptr
= NULL
;
3762 memcached_malloc_fn malloc_cb
=
3763 (memcached_malloc_fn
)my_malloc
;
3764 cb_ptr
= *(void **)&malloc_cb
;
3765 memcached_return_t rc
;
3767 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, cb_ptr
);
3768 test_true(rc
== MEMCACHED_SUCCESS
);
3769 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
3770 test_true(rc
== MEMCACHED_SUCCESS
);
3771 test_true(test_ptr
== cb_ptr
);
3775 memcached_realloc_fn realloc_cb
=
3776 (memcached_realloc_fn
)my_realloc
;
3777 cb_ptr
= *(void **)&realloc_cb
;
3778 memcached_return_t rc
;
3780 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, cb_ptr
);
3781 test_true(rc
== MEMCACHED_SUCCESS
);
3782 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
3783 test_true(rc
== MEMCACHED_SUCCESS
);
3784 test_true(test_ptr
== cb_ptr
);
3788 memcached_free_fn free_cb
=
3789 (memcached_free_fn
)my_free
;
3790 cb_ptr
= *(void **)&free_cb
;
3791 memcached_return_t rc
;
3793 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, cb_ptr
);
3794 test_true(rc
== MEMCACHED_SUCCESS
);
3795 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
3796 test_true(rc
== MEMCACHED_SUCCESS
);
3797 test_true(test_ptr
== cb_ptr
);
3800 return TEST_SUCCESS
;
3805 static test_return_t
set_memory_alloc(memcached_st
*memc
)
3807 memcached_return_t rc
;
3808 rc
= memcached_set_memory_allocators(memc
, NULL
, my_free
,
3809 my_realloc
, my_calloc
);
3810 test_true(rc
== MEMCACHED_FAILURE
);
3812 rc
= memcached_set_memory_allocators(memc
, my_malloc
, my_free
,
3813 my_realloc
, my_calloc
);
3815 memcached_malloc_fn mem_malloc
;
3816 memcached_free_fn mem_free
;
3817 memcached_realloc_fn mem_realloc
;
3818 memcached_calloc_fn mem_calloc
;
3819 memcached_get_memory_allocators(memc
, &mem_malloc
, &mem_free
,
3820 &mem_realloc
, &mem_calloc
);
3822 test_true(mem_malloc
== my_malloc
);
3823 test_true(mem_realloc
== my_realloc
);
3824 test_true(mem_calloc
== my_calloc
);
3825 test_true(mem_free
== my_free
);
3827 return TEST_SUCCESS
;
3830 static test_return_t
enable_consistent_crc(memcached_st
*memc
)
3833 memcached_server_distribution_t value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
3834 memcached_hash_t hash
;
3835 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
3836 if ((rc
= pre_crc(memc
)) != TEST_SUCCESS
)
3839 value
= (memcached_server_distribution_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
3840 test_true(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
3842 hash
= (memcached_hash_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
3844 if (hash
!= MEMCACHED_HASH_CRC
)
3845 return TEST_SKIPPED
;
3847 return TEST_SUCCESS
;
3850 static test_return_t
enable_consistent_hsieh(memcached_st
*memc
)
3853 memcached_server_distribution_t value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
3854 memcached_hash_t hash
;
3855 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
3856 if ((rc
= pre_hsieh(memc
)) != TEST_SUCCESS
)
3859 value
= (memcached_server_distribution_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
3860 test_true(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
3862 hash
= (memcached_hash_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
3864 if (hash
!= MEMCACHED_HASH_HSIEH
)
3865 return TEST_SKIPPED
;
3868 return TEST_SUCCESS
;
3871 static test_return_t
enable_cas(memcached_st
*memc
)
3873 unsigned int set
= 1;
3875 memcached_server_instance_st
*instance
=
3876 memcached_server_instance_fetch(memc
, 0);
3878 memcached_version(memc
);
3880 if ((instance
->major_version
>= 1 && (instance
->minor_version
== 2 && instance
->micro_version
>= 4))
3881 || instance
->minor_version
> 2)
3883 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
3885 return TEST_SUCCESS
;
3888 return TEST_SKIPPED
;
3891 static test_return_t
check_for_1_2_3(memcached_st
*memc
)
3893 memcached_version(memc
);
3894 memcached_server_instance_st
*instance
=
3895 memcached_server_instance_fetch(memc
, 0);
3897 if ((instance
->major_version
>= 1 && (instance
->minor_version
== 2 && instance
->micro_version
>= 4))
3898 || instance
->minor_version
> 2)
3899 return TEST_SUCCESS
;
3901 return TEST_SKIPPED
;
3904 static test_return_t
pre_unix_socket(memcached_st
*memc
)
3906 memcached_return_t rc
;
3909 memcached_servers_reset(memc
);
3911 if (stat("/tmp/memcached.socket", &buf
))
3912 return TEST_SKIPPED
;
3914 rc
= memcached_server_add_unix_socket_with_weight(memc
, "/tmp/memcached.socket", 0);
3916 return ( rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_FAILURE
);
3919 static test_return_t
pre_nodelay(memcached_st
*memc
)
3921 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3922 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
3924 return TEST_SUCCESS
;
3927 static test_return_t
pre_settimer(memcached_st
*memc
)
3929 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
3930 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
3932 return TEST_SUCCESS
;
3935 static test_return_t
poll_timeout(memcached_st
*memc
)
3941 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
3943 timeout
= (size_t)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
3945 test_true(timeout
== 100);
3947 return TEST_SUCCESS
;
3950 static test_return_t
noreply_test(memcached_st
*memc
)
3952 memcached_return_t ret
;
3953 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
3954 test_true(ret
== MEMCACHED_SUCCESS
);
3955 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
3956 test_true(ret
== MEMCACHED_SUCCESS
);
3957 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
3958 test_true(ret
== MEMCACHED_SUCCESS
);
3959 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NOREPLY
) == 1);
3960 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
) == 1);
3961 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
) == 1);
3963 for (int count
=0; count
< 5; ++count
)
3965 for (size_t x
= 0; x
< 100; ++x
)
3968 size_t len
= (size_t)sprintf(key
, "%zu", x
);
3972 ret
= memcached_add(memc
, key
, len
, key
, len
, 0, 0);
3975 ret
= memcached_replace(memc
, key
, len
, key
, len
, 0, 0);
3978 ret
= memcached_set(memc
, key
, len
, key
, len
, 0, 0);
3981 ret
= memcached_append(memc
, key
, len
, key
, len
, 0, 0);
3984 ret
= memcached_prepend(memc
, key
, len
, key
, len
, 0, 0);
3990 test_true(ret
== MEMCACHED_SUCCESS
|| ret
== MEMCACHED_BUFFERED
);
3994 ** NOTE: Don't ever do this in your code! this is not a supported use of the
3995 ** API and is _ONLY_ done this way to verify that the library works the
3996 ** way it is supposed to do!!!!
3999 for (uint32_t x
= 0; x
< memcached_server_count(memc
); ++x
)
4001 memcached_server_instance_st
*instance
=
4002 memcached_server_instance_fetch(memc
, x
);
4003 no_msg
+=(int)(instance
->cursor_active
);
4006 test_true(no_msg
== 0);
4007 test_true(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
4010 ** Now validate that all items was set properly!
4012 for (size_t x
= 0; x
< 100; ++x
)
4016 size_t len
= (size_t)sprintf(key
, "%zu", x
);
4019 char* value
=memcached_get(memc
, key
, strlen(key
),
4020 &length
, &flags
, &ret
);
4021 test_true(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
4024 case 0: /* FALLTHROUGH */
4025 case 1: /* FALLTHROUGH */
4027 test_true(strncmp(value
, key
, len
) == 0);
4028 test_true(len
== length
);
4031 test_true(length
== len
* 2);
4034 test_true(length
== len
* 3);
4044 /* Try setting an illegal cas value (should not return an error to
4045 * the caller (because we don't expect a return message from the server)
4047 const char* keys
[]= {"0"};
4048 size_t lengths
[]= {1};
4051 memcached_result_st results_obj
;
4052 memcached_result_st
*results
;
4053 ret
= memcached_mget(memc
, keys
, lengths
, 1);
4054 test_true(ret
== MEMCACHED_SUCCESS
);
4056 results
= memcached_result_create(memc
, &results_obj
);
4058 results
= memcached_fetch_result(memc
, &results_obj
, &ret
);
4060 test_true(ret
== MEMCACHED_SUCCESS
);
4061 uint64_t cas
= memcached_result_cas(results
);
4062 memcached_result_free(&results_obj
);
4064 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
4065 test_true(ret
== MEMCACHED_SUCCESS
);
4068 * The item will have a new cas value, so try to set it again with the old
4069 * value. This should fail!
4071 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
4072 test_true(ret
== MEMCACHED_SUCCESS
);
4073 test_true(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
4074 char* value
=memcached_get(memc
, keys
[0], lengths
[0], &length
, &flags
, &ret
);
4075 test_true(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
4078 return TEST_SUCCESS
;
4081 static test_return_t
analyzer_test(memcached_st
*memc
)
4083 memcached_return_t rc
;
4084 memcached_stat_st
*memc_stat
;
4085 memcached_analysis_st
*report
;
4087 memc_stat
= memcached_stat(memc
, NULL
, &rc
);
4088 test_true(rc
== MEMCACHED_SUCCESS
);
4089 test_true(memc_stat
);
4091 report
= memcached_analyze(memc
, memc_stat
, &rc
);
4092 test_true(rc
== MEMCACHED_SUCCESS
);
4096 memcached_stat_free(NULL
, memc_stat
);
4098 return TEST_SUCCESS
;
4101 /* Count the objects */
4102 static memcached_return_t
callback_dump_counter(const memcached_st
*ptr
__attribute__((unused
)),
4103 const char *key
__attribute__((unused
)),
4104 size_t key_length
__attribute__((unused
)),
4107 size_t *counter
= (size_t *)context
;
4109 *counter
= *counter
+ 1;
4111 return MEMCACHED_SUCCESS
;
4114 static test_return_t
dump_test(memcached_st
*memc
)
4116 memcached_return_t rc
;
4118 memcached_dump_fn callbacks
[1];
4119 test_return_t main_rc
;
4121 callbacks
[0]= &callback_dump_counter
;
4123 /* No support for Binary protocol yet */
4124 if (memc
->flags
.binary_protocol
)
4125 return TEST_SUCCESS
;
4127 main_rc
= set_test3(memc
);
4129 test_true (main_rc
== TEST_SUCCESS
);
4131 rc
= memcached_dump(memc
, callbacks
, (void *)&counter
, 1);
4132 test_true(rc
== MEMCACHED_SUCCESS
);
4134 /* We may have more then 32 if our previous flush has not completed */
4135 test_true(counter
>= 32);
4137 return TEST_SUCCESS
;
4140 #ifdef HAVE_LIBMEMCACHEDUTIL
4141 static void* connection_release(void *arg
)
4144 memcached_pool_st
* pool
;
4149 assert(memcached_pool_push(resource
->pool
, resource
->mmc
) == MEMCACHED_SUCCESS
);
4153 static test_return_t
connection_pool_test(memcached_st
*memc
)
4155 memcached_pool_st
* pool
= memcached_pool_create(memc
, 5, 10);
4156 test_true(pool
!= NULL
);
4157 memcached_st
* mmc
[10];
4158 memcached_return_t rc
;
4160 for (size_t x
= 0; x
< 10; ++x
)
4162 mmc
[x
]= memcached_pool_pop(pool
, false, &rc
);
4163 test_true(mmc
[x
] != NULL
);
4164 test_true(rc
== MEMCACHED_SUCCESS
);
4167 test_true(memcached_pool_pop(pool
, false, &rc
) == NULL
);
4168 test_true(rc
== MEMCACHED_SUCCESS
);
4172 memcached_pool_st
* pool
;
4174 } item
= { .pool
= pool
, .mmc
= mmc
[9] };
4175 pthread_create(&tid
, NULL
, connection_release
, &item
);
4176 mmc
[9]= memcached_pool_pop(pool
, true, &rc
);
4177 test_true(rc
== MEMCACHED_SUCCESS
);
4178 pthread_join(tid
, NULL
);
4179 test_true(mmc
[9] == item
.mmc
);
4180 const char *key
= "key";
4181 size_t keylen
= strlen(key
);
4183 // verify that I can do ops with all connections
4184 rc
= memcached_set(mmc
[0], key
, keylen
, "0", 1, 0, 0);
4185 test_true(rc
== MEMCACHED_SUCCESS
);
4187 for (size_t x
= 0; x
< 10; ++x
)
4189 uint64_t number_value
;
4190 rc
= memcached_increment(mmc
[x
], key
, keylen
, 1, &number_value
);
4191 test_true(rc
== MEMCACHED_SUCCESS
);
4192 test_true(number_value
== (x
+1));
4196 for (size_t x
= 0; x
< 10; ++x
)
4198 test_true(memcached_pool_push(pool
, mmc
[x
]) == MEMCACHED_SUCCESS
);
4202 /* verify that I can set behaviors on the pool when I don't have all
4203 * of the connections in the pool. It should however be enabled
4204 * when I push the item into the pool
4206 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
4207 test_true(mmc
[0] != NULL
);
4209 rc
= memcached_pool_behavior_set(pool
, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
, 9999);
4210 test_true(rc
== MEMCACHED_SUCCESS
);
4212 mmc
[1]= memcached_pool_pop(pool
, false, &rc
);
4213 test_true(mmc
[1] != NULL
);
4215 test_true(memcached_behavior_get(mmc
[1], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
) == 9999);
4216 test_true(memcached_pool_push(pool
, mmc
[1]) == MEMCACHED_SUCCESS
);
4217 test_true(memcached_pool_push(pool
, mmc
[0]) == MEMCACHED_SUCCESS
);
4219 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
4220 test_true(memcached_behavior_get(mmc
[0], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
) == 9999);
4221 test_true(memcached_pool_push(pool
, mmc
[0]) == MEMCACHED_SUCCESS
);
4224 test_true(memcached_pool_destroy(pool
) == memc
);
4225 return TEST_SUCCESS
;
4229 static test_return_t
replication_set_test(memcached_st
*memc
)
4231 memcached_return_t rc
;
4232 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4233 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 0);
4235 rc
= memcached_set(memc
, "bubba", 5, "0", 1, 0, 0);
4236 test_true(rc
== MEMCACHED_SUCCESS
);
4239 ** We are using the quiet commands to store the replicas, so we need
4240 ** to ensure that all of them are processed before we can continue.
4241 ** In the test we go directly from storing the object to trying to
4242 ** receive the object from all of the different servers, so we
4243 ** could end up in a race condition (the memcached server hasn't yet
4244 ** processed the quiet command from the replication set when it process
4245 ** the request from the other client (created by the clone)). As a
4246 ** workaround for that we call memcached_quit to send the quit command
4247 ** to the server and wait for the response ;-) If you use the test code
4248 ** as an example for your own code, please note that you shouldn't need
4251 memcached_quit(memc
);
4254 ** "bubba" should now be stored on all of our servers. We don't have an
4255 ** easy to use API to address each individual server, so I'll just iterate
4256 ** through a bunch of "master keys" and I should most likely hit all of the
4259 for (int x
= 'a'; x
<= 'z'; ++x
)
4261 char key
[2]= { [0]= (char)x
};
4264 char *val
= memcached_get_by_key(memc_clone
, key
, 1, "bubba", 5,
4266 test_true(rc
== MEMCACHED_SUCCESS
);
4267 test_true(val
!= NULL
);
4271 memcached_free(memc_clone
);
4273 return TEST_SUCCESS
;
4276 static test_return_t
replication_get_test(memcached_st
*memc
)
4278 memcached_return_t rc
;
4281 * Don't do the following in your code. I am abusing the internal details
4282 * within the library, and this is not a supported interface.
4283 * This is to verify correct behavior in the library
4285 for (uint32_t host
= 0; host
< memcached_server_count(memc
); ++host
)
4287 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4288 memcached_server_instance_st
*instance
=
4289 memcached_server_instance_fetch(memc_clone
, host
);
4293 for (int x
= 'a'; x
<= 'z'; ++x
)
4295 char key
[2]= { [0]= (char)x
};
4298 char *val
= memcached_get_by_key(memc_clone
, key
, 1, "bubba", 5,
4300 test_true(rc
== MEMCACHED_SUCCESS
);
4301 test_true(val
!= NULL
);
4305 memcached_free(memc_clone
);
4308 return TEST_SUCCESS
;
4311 static test_return_t
replication_mget_test(memcached_st
*memc
)
4313 memcached_return_t rc
;
4314 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4315 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 0);
4317 const char *keys
[]= { "bubba", "key1", "key2", "key3" };
4318 size_t len
[]= { 5, 4, 4, 4 };
4320 for (size_t x
= 0; x
< 4; ++x
)
4322 rc
= memcached_set(memc
, keys
[x
], len
[x
], "0", 1, 0, 0);
4323 test_true(rc
== MEMCACHED_SUCCESS
);
4327 ** We are using the quiet commands to store the replicas, so we need
4328 ** to ensure that all of them are processed before we can continue.
4329 ** In the test we go directly from storing the object to trying to
4330 ** receive the object from all of the different servers, so we
4331 ** could end up in a race condition (the memcached server hasn't yet
4332 ** processed the quiet command from the replication set when it process
4333 ** the request from the other client (created by the clone)). As a
4334 ** workaround for that we call memcached_quit to send the quit command
4335 ** to the server and wait for the response ;-) If you use the test code
4336 ** as an example for your own code, please note that you shouldn't need
4339 memcached_quit(memc
);
4342 * Don't do the following in your code. I am abusing the internal details
4343 * within the library, and this is not a supported interface.
4344 * This is to verify correct behavior in the library
4346 memcached_result_st result_obj
;
4347 for (uint32_t host
= 0; host
< memc_clone
->number_of_hosts
; host
++)
4349 memcached_st
*new_clone
= memcached_clone(NULL
, memc
);
4350 memcached_server_instance_st
*instance
=
4351 memcached_server_instance_fetch(new_clone
, host
);
4354 for (int x
= 'a'; x
<= 'z'; ++x
)
4356 char key
[2]= { [0]= (char)x
, [1]= 0 };
4358 rc
= memcached_mget_by_key(new_clone
, key
, 1, keys
, len
, 4);
4359 test_true(rc
== MEMCACHED_SUCCESS
);
4361 memcached_result_st
*results
= memcached_result_create(new_clone
, &result_obj
);
4365 while ((results
= memcached_fetch_result(new_clone
, &result_obj
, &rc
)) != NULL
)
4369 test_true(hits
== 4);
4370 memcached_result_free(&result_obj
);
4373 memcached_free(new_clone
);
4376 memcached_free(memc_clone
);
4378 return TEST_SUCCESS
;
4381 static test_return_t
replication_randomize_mget_test(memcached_st
*memc
)
4383 memcached_result_st result_obj
;
4384 memcached_return_t rc
;
4385 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4386 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 3);
4387 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ
, 1);
4389 const char *keys
[]= { "key1", "key2", "key3", "key4", "key5", "key6", "key7" };
4390 size_t len
[]= { 4, 4, 4, 4, 4, 4, 4 };
4392 for (int x
=0; x
< 7; ++x
)
4394 rc
= memcached_set(memc
, keys
[x
], len
[x
], "1", 1, 0, 0);
4395 test_true(rc
== MEMCACHED_SUCCESS
);
4398 memcached_quit(memc
);
4400 for (size_t x
= 0; x
< 7; ++x
)
4402 const char key
[2]= { [0]= (const char)x
};
4404 rc
= memcached_mget_by_key(memc_clone
, key
, 1, keys
, len
, 7);
4405 test_true(rc
== MEMCACHED_SUCCESS
);
4407 memcached_result_st
*results
= memcached_result_create(memc_clone
, &result_obj
);
4411 while ((results
= memcached_fetch_result(memc_clone
, &result_obj
, &rc
)) != NULL
)
4415 test_true(hits
== 7);
4416 memcached_result_free(&result_obj
);
4418 memcached_free(memc_clone
);
4419 return TEST_SUCCESS
;
4422 static test_return_t
replication_delete_test(memcached_st
*memc
)
4424 memcached_return_t rc
;
4425 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4426 /* Delete the items from all of the servers except 1 */
4427 uint64_t repl
= memcached_behavior_get(memc
,
4428 MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
);
4429 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, --repl
);
4431 const char *keys
[]= { "bubba", "key1", "key2", "key3" };
4432 size_t len
[]= { 5, 4, 4, 4 };
4434 for (size_t x
= 0; x
< 4; ++x
)
4436 rc
= memcached_delete_by_key(memc
, keys
[0], len
[0], keys
[x
], len
[x
], 0);
4437 test_true(rc
== MEMCACHED_SUCCESS
);
4441 * Don't do the following in your code. I am abusing the internal details
4442 * within the library, and this is not a supported interface.
4443 * This is to verify correct behavior in the library
4445 uint32_t hash
= memcached_generate_hash(memc
, keys
[0], len
[0]);
4446 for (uint32_t x
= 0; x
< (repl
+ 1); ++x
)
4448 memcached_server_instance_st
*instance
=
4449 memcached_server_instance_fetch(memc_clone
, x
);
4452 if (++hash
== memc_clone
->number_of_hosts
)
4456 memcached_result_st result_obj
;
4457 for (uint32_t host
= 0; host
< memc_clone
->number_of_hosts
; ++host
)
4459 for (size_t x
= 'a'; x
<= 'z'; ++x
)
4461 const char key
[2]= { [0]= (const char)x
};
4463 rc
= memcached_mget_by_key(memc_clone
, key
, 1, keys
, len
, 4);
4464 test_true(rc
== MEMCACHED_SUCCESS
);
4466 memcached_result_st
*results
= memcached_result_create(memc_clone
, &result_obj
);
4470 while ((results
= memcached_fetch_result(memc_clone
, &result_obj
, &rc
)) != NULL
)
4474 test_true(hits
== 4);
4475 memcached_result_free(&result_obj
);
4478 memcached_free(memc_clone
);
4480 return TEST_SUCCESS
;
4483 static void increment_request_id(uint16_t *id
)
4486 if ((*id
& UDP_REQUEST_ID_THREAD_MASK
) != 0)
4490 static uint16_t *get_udp_request_ids(memcached_st
*memc
)
4492 uint16_t *ids
= malloc(sizeof(uint16_t) * memcached_server_count(memc
));
4493 assert(ids
!= NULL
);
4495 for (uint32_t x
= 0; x
< memcached_server_count(memc
); x
++)
4497 memcached_server_instance_st
*instance
=
4498 memcached_server_instance_fetch(memc
, x
);
4500 ids
[x
]= get_udp_datagram_request_id((struct udp_datagram_header_st
*) instance
->write_buffer
);
4506 static test_return_t
post_udp_op_check(memcached_st
*memc
, uint16_t *expected_req_ids
)
4508 memcached_server_st
*cur_server
= memcached_server_list(memc
);
4509 uint16_t *cur_req_ids
= get_udp_request_ids(memc
);
4511 for (size_t x
= 0; x
< memcached_server_count(memc
); x
++)
4513 test_true(cur_server
[x
].cursor_active
== 0);
4514 test_true(cur_req_ids
[x
] == expected_req_ids
[x
]);
4516 free(expected_req_ids
);
4519 return TEST_SUCCESS
;
4523 ** There is a little bit of a hack here, instead of removing
4524 ** the servers, I just set num host to 0 and them add then new udp servers
4526 static test_return_t
init_udp(memcached_st
*memc
)
4528 memcached_version(memc
);
4529 memcached_server_instance_st
*instance
=
4530 memcached_server_instance_fetch(memc
, 0);
4532 /* For the time being, only support udp test for >= 1.2.6 && < 1.3 */
4533 if (instance
->major_version
!= 1 || instance
->minor_version
!= 2
4534 || instance
->micro_version
< 6)
4535 return TEST_SKIPPED
;
4537 uint32_t num_hosts
= memcached_server_count(memc
);
4538 memcached_server_st servers
[num_hosts
];
4539 memcpy(servers
, memcached_server_list(memc
), sizeof(memcached_server_st
) * num_hosts
);
4540 for (uint32_t x
= 0; x
< num_hosts
; x
++)
4542 memcached_server_instance_st
*set_instance
=
4543 memcached_server_instance_fetch(memc
, x
);
4545 memcached_server_free(set_instance
);
4548 memc
->number_of_hosts
= 0;
4549 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
, 1);
4550 for (uint32_t x
= 0; x
< num_hosts
; x
++)
4552 memcached_server_instance_st
*set_instance
=
4553 memcached_server_instance_fetch(memc
, x
);
4555 test_true(memcached_server_add_udp(memc
, servers
[x
].hostname
, servers
[x
].port
) == MEMCACHED_SUCCESS
);
4556 test_true(set_instance
->write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4559 return TEST_SUCCESS
;
4562 static test_return_t
binary_init_udp(memcached_st
*memc
)
4564 test_return_t test_rc
;
4565 test_rc
= pre_binary(memc
);
4567 if (test_rc
!= TEST_SUCCESS
)
4570 return init_udp(memc
);
4573 /* Make sure that I cant add a tcp server to a udp client */
4574 static test_return_t
add_tcp_server_udp_client_test(memcached_st
*memc
)
4578 memcached_server_st server
;
4579 memcached_server_instance_st
*instance
=
4580 memcached_server_instance_fetch(memc
, 0);
4581 memcached_server_clone(&server
, &memc
->hosts
[0]);
4582 test_true(memcached_server_remove(&(memc
->hosts
[0])) == MEMCACHED_SUCCESS
);
4583 test_true(memcached_server_add(memc
, server
.hostname
, server
.port
) == MEMCACHED_INVALID_HOST_PROTOCOL
);
4585 return TEST_SUCCESS
;
4588 /* Make sure that I cant add a udp server to a tcp client */
4589 static test_return_t
add_udp_server_tcp_client_test(memcached_st
*memc
)
4593 memcached_server_st server
;
4594 memcached_server_instance_st
*instance
=
4595 memcached_server_instance_fetch(memc
, 0);
4596 memcached_server_clone(&server
, &memc
->hosts
[0]);
4597 test_true(memcached_server_remove(&(memc
->hosts
[0])) == MEMCACHED_SUCCESS
);
4599 memcached_st tcp_client
;
4600 memcached_create(&tcp_client
);
4601 test_true(memcached_server_add_udp(&tcp_client
, server
.hostname
, server
.port
) == MEMCACHED_INVALID_HOST_PROTOCOL
);
4604 return TEST_SUCCESS
;
4607 static test_return_t
set_udp_behavior_test(memcached_st
*memc
)
4610 memcached_quit(memc
);
4611 memc
->number_of_hosts
= 0;
4612 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, memc
->distribution
);
4613 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
, 1) == MEMCACHED_SUCCESS
);
4614 test_true(memc
->flags
.use_udp
);
4615 test_true(memc
->flags
.no_reply
);
4617 test_true(memcached_server_count(memc
) == 0);
4619 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
,0);
4620 test_true(! (memc
->flags
.use_udp
));
4621 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
,0);
4622 test_true(! (memc
->flags
.no_reply
));
4624 return TEST_SUCCESS
;
4627 static test_return_t
udp_set_test(memcached_st
*memc
)
4629 unsigned int num_iters
= 1025; //request id rolls over at 1024
4631 for (size_t x
= 0; x
< num_iters
;x
++)
4633 memcached_return_t rc
;
4634 const char *key
= "foo";
4635 const char *value
= "when we sanitize";
4636 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4637 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4638 memcached_server_instance_st
*instance
=
4639 memcached_server_instance_fetch(memc
, server_key
);
4640 size_t init_offset
= instance
->write_buffer_offset
;
4642 rc
= memcached_set(memc
, key
, strlen(key
),
4643 value
, strlen(value
),
4644 (time_t)0, (uint32_t)0);
4645 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4646 /** NB, the check below assumes that if new write_ptr is less than
4647 * the original write_ptr that we have flushed. For large payloads, this
4648 * maybe an invalid assumption, but for the small payload we have it is OK
4650 if (rc
== MEMCACHED_SUCCESS
||
4651 instance
->write_buffer_offset
< init_offset
)
4652 increment_request_id(&expected_ids
[server_key
]);
4654 if (rc
== MEMCACHED_SUCCESS
)
4656 test_true(instance
->write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4660 test_true(instance
->write_buffer_offset
!= UDP_DATAGRAM_HEADER_LENGTH
);
4661 test_true(instance
->write_buffer_offset
<= MAX_UDP_DATAGRAM_LENGTH
);
4663 test_true(post_udp_op_check(memc
, expected_ids
) == TEST_SUCCESS
);
4665 return TEST_SUCCESS
;
4668 static test_return_t
udp_buffered_set_test(memcached_st
*memc
)
4670 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4671 return udp_set_test(memc
);
4674 static test_return_t
udp_set_too_big_test(memcached_st
*memc
)
4676 memcached_return_t rc
;
4677 const char *key
= "bar";
4678 char value
[MAX_UDP_DATAGRAM_LENGTH
];
4679 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4680 rc
= memcached_set(memc
, key
, strlen(key
),
4681 value
, MAX_UDP_DATAGRAM_LENGTH
,
4682 (time_t)0, (uint32_t)0);
4683 test_true(rc
== MEMCACHED_WRITE_FAILURE
);
4685 return post_udp_op_check(memc
,expected_ids
);
4688 static test_return_t
udp_delete_test(memcached_st
*memc
)
4690 unsigned int num_iters
= 1025; //request id rolls over at 1024
4692 for (size_t x
= 0; x
< num_iters
;x
++)
4694 memcached_return_t rc
;
4695 const char *key
= "foo";
4696 uint16_t *expected_ids
=get_udp_request_ids(memc
);
4697 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4698 memcached_server_instance_st
*instance
=
4699 memcached_server_instance_fetch(memc
, server_key
);
4700 size_t init_offset
= instance
->write_buffer_offset
;
4702 rc
= memcached_delete(memc
, key
, strlen(key
), 0);
4703 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4705 if (rc
== MEMCACHED_SUCCESS
|| instance
->write_buffer_offset
< init_offset
)
4706 increment_request_id(&expected_ids
[server_key
]);
4707 if (rc
== MEMCACHED_SUCCESS
)
4709 test_true(instance
->write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
4713 test_true(instance
->write_buffer_offset
!= UDP_DATAGRAM_HEADER_LENGTH
);
4714 test_true(instance
->write_buffer_offset
<= MAX_UDP_DATAGRAM_LENGTH
);
4716 test_true(post_udp_op_check(memc
,expected_ids
) == TEST_SUCCESS
);
4718 return TEST_SUCCESS
;
4721 static test_return_t
udp_buffered_delete_test(memcached_st
*memc
)
4723 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4724 return udp_delete_test(memc
);
4727 static test_return_t
udp_verbosity_test(memcached_st
*memc
)
4729 memcached_return_t rc
;
4730 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4732 for (size_t x
= 0; x
< memcached_server_count(memc
); x
++)
4734 increment_request_id(&expected_ids
[x
]);
4737 rc
= memcached_verbosity(memc
,3);
4738 test_true(rc
== MEMCACHED_SUCCESS
);
4739 return post_udp_op_check(memc
,expected_ids
);
4742 static test_return_t
udp_quit_test(memcached_st
*memc
)
4744 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4745 memcached_quit(memc
);
4746 return post_udp_op_check(memc
, expected_ids
);
4749 static test_return_t
udp_flush_test(memcached_st
*memc
)
4751 memcached_return_t rc
;
4752 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4754 for (size_t x
= 0; x
< memcached_server_count(memc
); x
++)
4756 increment_request_id(&expected_ids
[x
]);
4759 rc
= memcached_flush(memc
,0);
4760 test_true(rc
== MEMCACHED_SUCCESS
);
4761 return post_udp_op_check(memc
,expected_ids
);
4764 static test_return_t
udp_incr_test(memcached_st
*memc
)
4766 memcached_return_t rc
;
4767 const char *key
= "incr";
4768 const char *value
= "1";
4769 rc
= memcached_set(memc
, key
, strlen(key
),
4770 value
, strlen(value
),
4771 (time_t)0, (uint32_t)0);
4773 test_true(rc
== MEMCACHED_SUCCESS
);
4774 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4775 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4776 increment_request_id(&expected_ids
[server_key
]);
4778 rc
= memcached_increment(memc
, key
, strlen(key
), 1, &newvalue
);
4779 test_true(rc
== MEMCACHED_SUCCESS
);
4780 return post_udp_op_check(memc
, expected_ids
);
4783 static test_return_t
udp_decr_test(memcached_st
*memc
)
4785 memcached_return_t rc
;
4786 const char *key
= "decr";
4787 const char *value
= "1";
4788 rc
= memcached_set(memc
, key
, strlen(key
),
4789 value
, strlen(value
),
4790 (time_t)0, (uint32_t)0);
4792 test_true(rc
== MEMCACHED_SUCCESS
);
4793 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4794 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
4795 increment_request_id(&expected_ids
[server_key
]);
4797 rc
= memcached_decrement(memc
, key
, strlen(key
), 1, &newvalue
);
4798 test_true(rc
== MEMCACHED_SUCCESS
);
4799 return post_udp_op_check(memc
, expected_ids
);
4803 static test_return_t
udp_stat_test(memcached_st
*memc
)
4805 memcached_stat_st
* rv
= NULL
;
4806 memcached_return_t rc
;
4808 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4809 rv
= memcached_stat(memc
, args
, &rc
);
4811 test_true(rc
== MEMCACHED_NOT_SUPPORTED
);
4812 return post_udp_op_check(memc
, expected_ids
);
4815 static test_return_t
udp_version_test(memcached_st
*memc
)
4817 memcached_return_t rc
;
4818 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4819 rc
= memcached_version(memc
);
4820 test_true(rc
== MEMCACHED_NOT_SUPPORTED
);
4821 return post_udp_op_check(memc
, expected_ids
);
4824 static test_return_t
udp_get_test(memcached_st
*memc
)
4826 memcached_return_t rc
;
4827 const char *key
= "foo";
4829 uint16_t *expected_ids
= get_udp_request_ids(memc
);
4830 char *val
= memcached_get(memc
, key
, strlen(key
), &vlen
, (uint32_t)0, &rc
);
4831 test_true(rc
== MEMCACHED_NOT_SUPPORTED
);
4832 test_true(val
== NULL
);
4833 return post_udp_op_check(memc
, expected_ids
);
4836 static test_return_t
udp_mixed_io_test(memcached_st
*memc
)
4839 test_st mixed_io_ops
[] ={
4841 (test_callback_fn
)udp_set_test
},
4842 {"udp_set_too_big_test", 0,
4843 (test_callback_fn
)udp_set_too_big_test
},
4844 {"udp_delete_test", 0,
4845 (test_callback_fn
)udp_delete_test
},
4846 {"udp_verbosity_test", 0,
4847 (test_callback_fn
)udp_verbosity_test
},
4848 {"udp_quit_test", 0,
4849 (test_callback_fn
)udp_quit_test
},
4850 {"udp_flush_test", 0,
4851 (test_callback_fn
)udp_flush_test
},
4852 {"udp_incr_test", 0,
4853 (test_callback_fn
)udp_incr_test
},
4854 {"udp_decr_test", 0,
4855 (test_callback_fn
)udp_decr_test
},
4856 {"udp_version_test", 0,
4857 (test_callback_fn
)udp_version_test
}
4859 for (size_t x
= 0; x
< 500; x
++)
4861 current_op
= mixed_io_ops
[random() % 9];
4862 test_true(current_op
.test_fn(memc
) == TEST_SUCCESS
);
4864 return TEST_SUCCESS
;
4868 static test_return_t
hash_sanity_test (memcached_st
*memc
)
4872 assert(MEMCACHED_HASH_DEFAULT
== MEMCACHED_HASH_DEFAULT
);
4873 assert(MEMCACHED_HASH_MD5
== MEMCACHED_HASH_MD5
);
4874 assert(MEMCACHED_HASH_CRC
== MEMCACHED_HASH_CRC
);
4875 assert(MEMCACHED_HASH_FNV1_64
== MEMCACHED_HASH_FNV1_64
);
4876 assert(MEMCACHED_HASH_FNV1A_64
== MEMCACHED_HASH_FNV1A_64
);
4877 assert(MEMCACHED_HASH_FNV1_32
== MEMCACHED_HASH_FNV1_32
);
4878 assert(MEMCACHED_HASH_FNV1A_32
== MEMCACHED_HASH_FNV1A_32
);
4879 #ifdef HAVE_HSIEH_HASH
4880 assert(MEMCACHED_HASH_HSIEH
== MEMCACHED_HASH_HSIEH
);
4882 assert(MEMCACHED_HASH_MURMUR
== MEMCACHED_HASH_MURMUR
);
4883 assert(MEMCACHED_HASH_JENKINS
== MEMCACHED_HASH_JENKINS
);
4884 assert(MEMCACHED_HASH_MAX
== MEMCACHED_HASH_MAX
);
4886 return TEST_SUCCESS
;
4890 static test_return_t
hsieh_avaibility_test (memcached_st
*memc
)
4892 memcached_return_t expected_rc
= MEMCACHED_FAILURE
;
4893 #ifdef HAVE_HSIEH_HASH
4894 expected_rc
= MEMCACHED_SUCCESS
;
4896 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
,
4897 (uint64_t)MEMCACHED_HASH_HSIEH
);
4898 test_true(rc
== expected_rc
);
4900 return TEST_SUCCESS
;
4903 static test_return_t
md5_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_MD5
);
4913 test_true(md5_values
[x
] == hash_val
);
4916 return TEST_SUCCESS
;
4919 static test_return_t
crc_run (memcached_st
*memc
__attribute__((unused
)))
4924 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4928 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_CRC
);
4929 test_true(crc_values
[x
] == hash_val
);
4932 return TEST_SUCCESS
;
4935 static test_return_t
fnv1_64_run (memcached_st
*memc
__attribute__((unused
)))
4940 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4944 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_64
);
4945 test_true(fnv1_64_values
[x
] == hash_val
);
4948 return TEST_SUCCESS
;
4951 static test_return_t
fnv1a_64_run (memcached_st
*memc
__attribute__((unused
)))
4956 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4960 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_64
);
4961 test_true(fnv1a_64_values
[x
] == hash_val
);
4964 return TEST_SUCCESS
;
4967 static test_return_t
fnv1_32_run (memcached_st
*memc
__attribute__((unused
)))
4973 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4977 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_32
);
4978 test_true(fnv1_32_values
[x
] == hash_val
);
4981 return TEST_SUCCESS
;
4984 static test_return_t
fnv1a_32_run (memcached_st
*memc
__attribute__((unused
)))
4989 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4993 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_32
);
4994 test_true(fnv1a_32_values
[x
] == hash_val
);
4997 return TEST_SUCCESS
;
5000 static test_return_t
hsieh_run (memcached_st
*memc
__attribute__((unused
)))
5005 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
5009 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_HSIEH
);
5010 test_true(hsieh_values
[x
] == hash_val
);
5013 return TEST_SUCCESS
;
5016 static test_return_t
murmur_run (memcached_st
*memc
__attribute__((unused
)))
5019 return TEST_SKIPPED
;
5024 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
5028 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MURMUR
);
5029 test_true(murmur_values
[x
] == hash_val
);
5032 return TEST_SUCCESS
;
5036 static test_return_t
jenkins_run (memcached_st
*memc
__attribute__((unused
)))
5042 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
5046 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_JENKINS
);
5047 test_true(jenkins_values
[x
] == hash_val
);
5050 return TEST_SUCCESS
;
5054 static test_return_t
ketama_compatibility_libmemcached(memcached_st
*trash
)
5056 memcached_return_t rc
;
5059 memcached_server_st
*server_pool
;
5064 memc
= memcached_create(NULL
);
5067 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
5068 test_true(rc
== MEMCACHED_SUCCESS
);
5070 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
5071 test_true(value
== 1);
5073 test_true(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
) == MEMCACHED_SUCCESS
);
5074 test_true(memcached_behavior_get_distribution(memc
) == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
);
5077 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");
5078 memcached_server_push(memc
, server_pool
);
5080 /* verify that the server list was parsed okay. */
5081 test_true(memcached_server_count(memc
) == 8);
5082 test_strcmp(server_pool
[0].hostname
, "10.0.1.1");
5083 test_true(server_pool
[0].port
== 11211);
5084 test_true(server_pool
[0].weight
== 600);
5085 test_strcmp(server_pool
[2].hostname
, "10.0.1.3");
5086 test_true(server_pool
[2].port
== 11211);
5087 test_true(server_pool
[2].weight
== 200);
5088 test_strcmp(server_pool
[7].hostname
, "10.0.1.8");
5089 test_true(server_pool
[7].port
== 11211);
5090 test_true(server_pool
[7].weight
== 100);
5092 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
5093 * us test the boundary wraparound.
5095 test_true(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
5097 /* verify the standard ketama set. */
5098 for (x
= 0; x
< 99; x
++)
5100 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
5101 memcached_server_instance_st
*instance
=
5102 memcached_server_instance_fetch(memc
, server_idx
);
5103 char *hostname
= instance
->hostname
;
5105 test_strcmp(hostname
, ketama_test_cases
[x
].server
);
5108 memcached_server_list_free(server_pool
);
5109 memcached_free(memc
);
5111 return TEST_SUCCESS
;
5114 static test_return_t
ketama_compatibility_spymemcached(memcached_st
*trash
)
5116 memcached_return_t rc
;
5119 memcached_server_st
*server_pool
;
5124 memc
= memcached_create(NULL
);
5127 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
5128 test_true(rc
== MEMCACHED_SUCCESS
);
5130 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
5131 test_true(value
== 1);
5133 test_true(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
) == MEMCACHED_SUCCESS
);
5134 test_true(memcached_behavior_get_distribution(memc
) == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
);
5136 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");
5137 memcached_server_push(memc
, server_pool
);
5139 /* verify that the server list was parsed okay. */
5140 test_true(memcached_server_count(memc
) == 8);
5141 test_strcmp(server_pool
[0].hostname
, "10.0.1.1");
5142 test_true(server_pool
[0].port
== 11211);
5143 test_true(server_pool
[0].weight
== 600);
5144 test_strcmp(server_pool
[2].hostname
, "10.0.1.3");
5145 test_true(server_pool
[2].port
== 11211);
5146 test_true(server_pool
[2].weight
== 200);
5147 test_strcmp(server_pool
[7].hostname
, "10.0.1.8");
5148 test_true(server_pool
[7].port
== 11211);
5149 test_true(server_pool
[7].weight
== 100);
5151 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
5152 * us test the boundary wraparound.
5154 test_true(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
5156 /* verify the standard ketama set. */
5157 for (x
= 0; x
< 99; x
++)
5159 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases_spy
[x
].key
, strlen(ketama_test_cases_spy
[x
].key
));
5160 memcached_server_instance_st
*instance
=
5161 memcached_server_instance_fetch(memc
, server_idx
);
5162 char *hostname
= instance
->hostname
;
5163 test_strcmp(hostname
, ketama_test_cases_spy
[x
].server
);
5166 memcached_server_list_free(server_pool
);
5167 memcached_free(memc
);
5169 return TEST_SUCCESS
;
5172 static test_return_t
regression_bug_434484(memcached_st
*memc
)
5174 test_return_t test_rc
;
5175 test_rc
= pre_binary(memc
);
5177 if (test_rc
!= TEST_SUCCESS
)
5180 memcached_return_t ret
;
5181 const char *key
= "regression_bug_434484";
5182 size_t keylen
= strlen(key
);
5184 ret
= memcached_append(memc
, key
, keylen
, key
, keylen
, 0, 0);
5185 test_true(ret
== MEMCACHED_NOTSTORED
);
5187 size_t size
= 2048 * 1024;
5188 void *data
= calloc(1, size
);
5189 test_true(data
!= NULL
);
5190 ret
= memcached_set(memc
, key
, keylen
, data
, size
, 0, 0);
5191 test_true(ret
== MEMCACHED_E2BIG
);
5194 return TEST_SUCCESS
;
5197 static test_return_t
regression_bug_434843(memcached_st
*memc
)
5199 test_return_t test_rc
;
5200 test_rc
= pre_binary(memc
);
5202 if (test_rc
!= TEST_SUCCESS
)
5205 memcached_return_t rc
;
5207 memcached_execute_fn callbacks
[1]= { [0]= &callback_counter
};
5210 * I only want to hit only _one_ server so I know the number of requests I'm
5211 * sending in the pipleine to the server. Let's try to do a multiget of
5212 * 1024 (that should satisfy most users don't you think?). Future versions
5213 * will include a mget_execute function call if you need a higher number.
5215 uint32_t number_of_hosts
= memcached_server_count(memc
);
5216 memc
->number_of_hosts
= 1;
5217 const size_t max_keys
= 1024;
5218 char **keys
= calloc(max_keys
, sizeof(char*));
5219 size_t *key_length
=calloc(max_keys
, sizeof(size_t));
5221 for (size_t x
= 0; x
< max_keys
; ++x
)
5225 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%zu", x
);
5227 test_true(keys
[x
] != NULL
);
5231 * Run two times.. the first time we should have 100% cache miss,
5232 * and the second time we should have 100% cache hits
5234 for (size_t y
= 0; y
< 2; y
++)
5236 rc
= memcached_mget(memc
, (const char**)keys
, key_length
, max_keys
);
5237 test_true(rc
== MEMCACHED_SUCCESS
);
5238 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5242 /* The first iteration should give me a 100% cache miss. verify that*/
5243 char blob
[1024]= { 0 };
5245 test_true(counter
== 0);
5247 for (size_t x
= 0; x
< max_keys
; ++x
)
5249 rc
= memcached_add(memc
, keys
[x
], key_length
[x
],
5250 blob
, sizeof(blob
), 0, 0);
5251 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5256 /* Verify that we received all of the key/value pairs */
5257 test_true(counter
== max_keys
);
5261 /* Release allocated resources */
5262 for (size_t x
= 0; x
< max_keys
; ++x
)
5269 memc
->number_of_hosts
= number_of_hosts
;
5271 return TEST_SUCCESS
;
5274 static test_return_t
regression_bug_434843_buffered(memcached_st
*memc
)
5276 memcached_return_t rc
;
5277 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
5278 test_true(rc
== MEMCACHED_SUCCESS
);
5280 return regression_bug_434843(memc
);
5283 static test_return_t
regression_bug_421108(memcached_st
*memc
)
5285 memcached_return_t rc
;
5286 memcached_stat_st
*memc_stat
= memcached_stat(memc
, NULL
, &rc
);
5287 test_true(rc
== MEMCACHED_SUCCESS
);
5289 char *bytes
= memcached_stat_get_value(memc
, memc_stat
, "bytes", &rc
);
5290 test_true(rc
== MEMCACHED_SUCCESS
);
5291 test_true(bytes
!= NULL
);
5292 char *bytes_read
= memcached_stat_get_value(memc
, memc_stat
,
5294 test_true(rc
== MEMCACHED_SUCCESS
);
5295 test_true(bytes_read
!= NULL
);
5297 char *bytes_written
= memcached_stat_get_value(memc
, memc_stat
,
5298 "bytes_written", &rc
);
5299 test_true(rc
== MEMCACHED_SUCCESS
);
5300 test_true(bytes_written
!= NULL
);
5302 test_true(strcmp(bytes
, bytes_read
) != 0);
5303 test_true(strcmp(bytes
, bytes_written
) != 0);
5305 /* Release allocated resources */
5308 free(bytes_written
);
5309 memcached_stat_free(NULL
, memc_stat
);
5311 return TEST_SUCCESS
;
5315 * The test case isn't obvious so I should probably document why
5316 * it works the way it does. Bug 442914 was caused by a bug
5317 * in the logic in memcached_purge (it did not handle the case
5318 * where the number of bytes sent was equal to the watermark).
5319 * In this test case, create messages so that we hit that case
5320 * and then disable noreply mode and issue a new command to
5321 * verify that it isn't stuck. If we change the format for the
5322 * delete command or the watermarks, we need to update this
5325 static test_return_t
regression_bug_442914(memcached_st
*memc
)
5327 memcached_return_t rc
;
5328 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
5329 test_true(rc
== MEMCACHED_SUCCESS
);
5330 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1);
5332 uint32_t number_of_hosts
= memcached_server_count(memc
);
5333 memc
->number_of_hosts
= 1;
5338 for (uint32_t x
= 0; x
< 250; ++x
)
5340 len
= (size_t)snprintf(k
, sizeof(k
), "%0250u", x
);
5341 rc
= memcached_delete(memc
, k
, len
, 0);
5342 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5345 (void)snprintf(k
, sizeof(k
), "%037u", 251U);
5348 rc
= memcached_delete(memc
, k
, len
, 0);
5349 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5351 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0);
5352 test_true(rc
== MEMCACHED_SUCCESS
);
5353 rc
= memcached_delete(memc
, k
, len
, 0);
5354 test_true(rc
== MEMCACHED_NOTFOUND
);
5356 memc
->number_of_hosts
= number_of_hosts
;
5358 return TEST_SUCCESS
;
5361 static test_return_t
regression_bug_447342(memcached_st
*memc
)
5363 memcached_server_instance_st
*instance_one
;
5364 memcached_server_instance_st
*instance_two
;
5366 if (memcached_server_count(memc
) < 3 || pre_replication(memc
) != MEMCACHED_SUCCESS
)
5367 return TEST_SKIPPED
;
5369 memcached_return_t rc
;
5371 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 2);
5372 test_true(rc
== MEMCACHED_SUCCESS
);
5374 const size_t max_keys
= 100;
5375 char **keys
= calloc(max_keys
, sizeof(char*));
5376 size_t *key_length
= calloc(max_keys
, sizeof(size_t));
5378 for (size_t x
= 0; x
< max_keys
; ++x
)
5382 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%zu", x
);
5384 test_true(keys
[x
] != NULL
);
5385 rc
= memcached_set(memc
, k
, key_length
[x
], k
, key_length
[x
], 0, 0);
5386 test_true(rc
== MEMCACHED_SUCCESS
);
5390 ** We are using the quiet commands to store the replicas, so we need
5391 ** to ensure that all of them are processed before we can continue.
5392 ** In the test we go directly from storing the object to trying to
5393 ** receive the object from all of the different servers, so we
5394 ** could end up in a race condition (the memcached server hasn't yet
5395 ** processed the quiet command from the replication set when it process
5396 ** the request from the other client (created by the clone)). As a
5397 ** workaround for that we call memcached_quit to send the quit command
5398 ** to the server and wait for the response ;-) If you use the test code
5399 ** as an example for your own code, please note that you shouldn't need
5402 memcached_quit(memc
);
5404 /* Verify that all messages are stored, and we didn't stuff too much
5407 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5408 test_true(rc
== MEMCACHED_SUCCESS
);
5411 memcached_execute_fn callbacks
[1]= { [0]= &callback_counter
};
5412 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5413 /* Verify that we received all of the key/value pairs */
5414 test_true(counter
== max_keys
);
5416 memcached_quit(memc
);
5418 * Don't do the following in your code. I am abusing the internal details
5419 * within the library, and this is not a supported interface.
5420 * This is to verify correct behavior in the library. Fake that two servers
5423 instance_one
= memcached_server_instance_fetch(memc
, 0);
5424 instance_two
= memcached_server_instance_fetch(memc
, 2);
5425 in_port_t port0
= instance_one
->port
;
5426 in_port_t port2
= instance_two
->port
;
5428 instance_one
->port
= 0;
5429 instance_two
->port
= 0;
5431 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5432 test_true(rc
== MEMCACHED_SUCCESS
);
5435 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5436 test_true(counter
== (unsigned int)max_keys
);
5438 /* restore the memc handle */
5439 instance_one
->port
= port0
;
5440 instance_two
->port
= port2
;
5442 memcached_quit(memc
);
5444 /* Remove half of the objects */
5445 for (size_t x
= 0; x
< max_keys
; ++x
)
5449 rc
= memcached_delete(memc
, keys
[x
], key_length
[x
], 0);
5450 test_true(rc
== MEMCACHED_SUCCESS
);
5454 memcached_quit(memc
);
5455 instance_one
->port
= 0;
5456 instance_two
->port
= 0;
5458 /* now retry the command, this time we should have cache misses */
5459 rc
= memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
);
5460 test_true(rc
== MEMCACHED_SUCCESS
);
5463 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
5464 test_true(counter
== (unsigned int)(max_keys
>> 1));
5466 /* Release allocated resources */
5467 for (size_t x
= 0; x
< max_keys
; ++x
)
5474 /* restore the memc handle */
5475 instance_one
->port
= port0
;
5476 instance_two
->port
= port2
;
5478 return TEST_SUCCESS
;
5481 static test_return_t
regression_bug_463297(memcached_st
*memc
)
5483 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
5484 test_true(memc_clone
!= NULL
);
5485 test_true(memcached_version(memc_clone
) == MEMCACHED_SUCCESS
);
5487 memcached_server_instance_st
*instance
=
5488 memcached_server_instance_fetch(memc_clone
, 0);
5490 if (instance
->major_version
> 1 ||
5491 (instance
->major_version
== 1 &&
5492 instance
->minor_version
> 2))
5494 /* Binary protocol doesn't support deferred delete */
5495 memcached_st
*bin_clone
= memcached_clone(NULL
, memc
);
5496 test_true(bin_clone
!= NULL
);
5497 test_true(memcached_behavior_set(bin_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1) == MEMCACHED_SUCCESS
);
5498 test_true(memcached_delete(bin_clone
, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS
);
5499 memcached_free(bin_clone
);
5501 memcached_quit(memc_clone
);
5503 /* If we know the server version, deferred delete should fail
5504 * with invalid arguments */
5505 test_true(memcached_delete(memc_clone
, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS
);
5507 /* If we don't know the server version, we should get a protocol error */
5508 memcached_return_t rc
= memcached_delete(memc
, "foo", 3, 1);
5510 /* but there is a bug in some of the memcached servers (1.4) that treats
5511 * the counter as noreply so it doesn't send the proper error message
5513 test_true(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5515 /* And buffered mode should be disabled and we should get protocol error */
5516 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1) == MEMCACHED_SUCCESS
);
5517 rc
= memcached_delete(memc
, "foo", 3, 1);
5518 test_true(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5520 /* Same goes for noreply... */
5521 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1) == MEMCACHED_SUCCESS
);
5522 rc
= memcached_delete(memc
, "foo", 3, 1);
5523 test_true(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
);
5525 /* but a normal request should go through (and be buffered) */
5526 test_true((rc
= memcached_delete(memc
, "foo", 3, 0)) == MEMCACHED_BUFFERED
);
5527 test_true(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
5529 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 0) == MEMCACHED_SUCCESS
);
5530 /* unbuffered noreply should be success */
5531 test_true(memcached_delete(memc
, "foo", 3, 0) == MEMCACHED_SUCCESS
);
5532 /* unbuffered with reply should be not found... */
5533 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0) == MEMCACHED_SUCCESS
);
5534 test_true(memcached_delete(memc
, "foo", 3, 0) == MEMCACHED_NOTFOUND
);
5537 memcached_free(memc_clone
);
5538 return TEST_SUCCESS
;
5542 /* Test memcached_server_get_last_disconnect
5543 * For a working server set, shall be NULL
5544 * For a set of non existing server, shall not be NULL
5546 static test_return_t
test_get_last_disconnect(memcached_st
*memc
)
5548 memcached_return_t rc
;
5549 memcached_server_st
*disconnected_server
;
5551 /* With the working set of server */
5552 const char *key
= "marmotte";
5553 const char *value
= "milka";
5555 rc
= memcached_set(memc
, key
, strlen(key
),
5556 value
, strlen(value
),
5557 (time_t)0, (uint32_t)0);
5558 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5560 disconnected_server
= memcached_server_get_last_disconnect(memc
);
5561 test_true(disconnected_server
== NULL
);
5563 /* With a non existing server */
5565 memcached_server_st
*servers
;
5567 const char *server_list
= "localhost:9";
5569 servers
= memcached_servers_parse(server_list
);
5571 mine
= memcached_create(NULL
);
5572 rc
= memcached_server_push(mine
, servers
);
5573 test_true(rc
== MEMCACHED_SUCCESS
);
5574 memcached_server_list_free(servers
);
5577 rc
= memcached_set(mine
, key
, strlen(key
),
5578 value
, strlen(value
),
5579 (time_t)0, (uint32_t)0);
5580 test_true(rc
!= MEMCACHED_SUCCESS
);
5582 disconnected_server
= memcached_server_get_last_disconnect(mine
);
5583 test_true(disconnected_server
!= NULL
);
5584 test_true(disconnected_server
->port
== 9);
5585 test_true(strncmp(disconnected_server
->hostname
,"localhost",9) == 0);
5587 memcached_quit(mine
);
5588 memcached_free(mine
);
5590 return TEST_SUCCESS
;
5594 * This test ensures that the failure counter isn't incremented during
5595 * normal termination of the memcached instance.
5597 static test_return_t
wrong_failure_counter_test(memcached_st
*memc
)
5599 memcached_return_t rc
;
5600 memcached_server_instance_st
*instance
;
5602 /* Set value to force connection to the server */
5603 const char *key
= "marmotte";
5604 const char *value
= "milka";
5607 * Please note that I'm abusing the internal structures in libmemcached
5608 * in a non-portable way and you shouldn't be doing this. I'm only
5609 * doing this in order to verify that the library works the way it should
5611 uint32_t number_of_hosts
= memcached_server_count(memc
);
5612 memc
->number_of_hosts
= 1;
5614 /* Ensure that we are connected to the server by setting a value */
5615 rc
= memcached_set(memc
, key
, strlen(key
),
5616 value
, strlen(value
),
5617 (time_t)0, (uint32_t)0);
5618 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5621 instance
= memcached_server_instance_fetch(memc
, 0);
5622 /* The test is to see that the memcached_quit doesn't increase the
5623 * the server failure conter, so let's ensure that it is zero
5624 * before sending quit
5626 instance
->server_failure_counter
= 0;
5628 memcached_quit(memc
);
5630 /* Verify that it memcached_quit didn't increment the failure counter
5631 * Please note that this isn't bullet proof, because an error could
5634 test_true(instance
->server_failure_counter
== 0);
5636 /* restore the instance */
5637 memc
->number_of_hosts
= number_of_hosts
;
5639 return TEST_SUCCESS
;
5646 * Test that ensures mget_execute does not end into recursive calls that finally fails
5648 static test_return_t
regression_bug_490486(memcached_st
*memc
)
5650 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
5651 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 1);
5652 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, 1000);
5653 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, 1);
5654 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 3600);
5657 * I only want to hit _one_ server so I know the number of requests I'm
5658 * sending in the pipeline.
5660 uint32_t number_of_hosts
= memc
->number_of_hosts
;
5661 memc
->number_of_hosts
= 1;
5662 size_t max_keys
= 20480;
5665 char **keys
= calloc(max_keys
, sizeof(char*));
5666 size_t *key_length
=calloc(max_keys
, sizeof(size_t));
5668 /* First add all of the items.. */
5669 char blob
[1024]= { 0 };
5670 memcached_return rc
;
5671 for (size_t x
= 0; x
< max_keys
; ++x
)
5674 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%zu", x
);
5676 assert(keys
[x
] != NULL
);
5677 rc
= memcached_set(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
5678 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5681 /* Try to get all of them with a large multiget */
5683 memcached_execute_function callbacks
[1]= { [0]= &callback_counter
};
5684 rc
= memcached_mget_execute(memc
, (const char**)keys
, key_length
,
5685 (size_t)max_keys
, callbacks
, &counter
, 1);
5687 assert(rc
== MEMCACHED_SUCCESS
);
5688 char* the_value
= NULL
;
5689 char the_key
[MEMCACHED_MAX_KEY
];
5690 size_t the_key_length
;
5691 size_t the_value_length
;
5695 the_value
= memcached_fetch(memc
, the_key
, &the_key_length
, &the_value_length
, &the_flags
, &rc
);
5697 if ((the_value
!= NULL
) && (rc
== MEMCACHED_SUCCESS
))
5703 } while ( (the_value
!= NULL
) && (rc
== MEMCACHED_SUCCESS
));
5706 assert(rc
== MEMCACHED_END
);
5708 /* Verify that we got all of the items */
5709 assert(counter
== max_keys
);
5711 /* Release all allocated resources */
5712 for (size_t x
= 0; x
< max_keys
; ++x
)
5719 memc
->number_of_hosts
= number_of_hosts
;
5721 return TEST_SUCCESS
;
5727 test_st udp_setup_server_tests
[] ={
5728 {"set_udp_behavior_test", 0, (test_callback_fn
)set_udp_behavior_test
},
5729 {"add_tcp_server_udp_client_test", 0, (test_callback_fn
)add_tcp_server_udp_client_test
},
5730 {"add_udp_server_tcp_client_test", 0, (test_callback_fn
)add_udp_server_tcp_client_test
},
5734 test_st upd_io_tests
[] ={
5735 {"udp_set_test", 0, (test_callback_fn
)udp_set_test
},
5736 {"udp_buffered_set_test", 0, (test_callback_fn
)udp_buffered_set_test
},
5737 {"udp_set_too_big_test", 0, (test_callback_fn
)udp_set_too_big_test
},
5738 {"udp_delete_test", 0, (test_callback_fn
)udp_delete_test
},
5739 {"udp_buffered_delete_test", 0, (test_callback_fn
)udp_buffered_delete_test
},
5740 {"udp_verbosity_test", 0, (test_callback_fn
)udp_verbosity_test
},
5741 {"udp_quit_test", 0, (test_callback_fn
)udp_quit_test
},
5742 {"udp_flush_test", 0, (test_callback_fn
)udp_flush_test
},
5743 {"udp_incr_test", 0, (test_callback_fn
)udp_incr_test
},
5744 {"udp_decr_test", 0, (test_callback_fn
)udp_decr_test
},
5745 {"udp_stat_test", 0, (test_callback_fn
)udp_stat_test
},
5746 {"udp_version_test", 0, (test_callback_fn
)udp_version_test
},
5747 {"udp_get_test", 0, (test_callback_fn
)udp_get_test
},
5748 {"udp_mixed_io_test", 0, (test_callback_fn
)udp_mixed_io_test
},
5752 /* Clean the server before beginning testing */
5754 {"flush", 0, (test_callback_fn
)flush_test
},
5755 {"init", 0, (test_callback_fn
)init_test
},
5756 {"allocation", 0, (test_callback_fn
)allocation_test
},
5757 {"server_list_null_test", 0, (test_callback_fn
)server_list_null_test
},
5758 {"server_unsort", 0, (test_callback_fn
)server_unsort_test
},
5759 {"server_sort", 0, (test_callback_fn
)server_sort_test
},
5760 {"server_sort2", 0, (test_callback_fn
)server_sort2_test
},
5761 {"clone_test", 0, (test_callback_fn
)clone_test
},
5762 {"connection_test", 0, (test_callback_fn
)connection_test
},
5763 {"callback_test", 0, (test_callback_fn
)callback_test
},
5764 {"userdata_test", 0, (test_callback_fn
)userdata_test
},
5765 {"error", 0, (test_callback_fn
)error_test
},
5766 {"set", 0, (test_callback_fn
)set_test
},
5767 {"set2", 0, (test_callback_fn
)set_test2
},
5768 {"set3", 0, (test_callback_fn
)set_test3
},
5769 {"dump", 1, (test_callback_fn
)dump_test
},
5770 {"add", 1, (test_callback_fn
)add_test
},
5771 {"replace", 1, (test_callback_fn
)replace_test
},
5772 {"delete", 1, (test_callback_fn
)delete_test
},
5773 {"get", 1, (test_callback_fn
)get_test
},
5774 {"get2", 0, (test_callback_fn
)get_test2
},
5775 {"get3", 0, (test_callback_fn
)get_test3
},
5776 {"get4", 0, (test_callback_fn
)get_test4
},
5777 {"partial mget", 0, (test_callback_fn
)get_test5
},
5778 {"stats_servername", 0, (test_callback_fn
)stats_servername_test
},
5779 {"increment", 0, (test_callback_fn
)increment_test
},
5780 {"increment_with_initial", 1, (test_callback_fn
)increment_with_initial_test
},
5781 {"decrement", 0, (test_callback_fn
)decrement_test
},
5782 {"decrement_with_initial", 1, (test_callback_fn
)decrement_with_initial_test
},
5783 {"increment_by_key", 0, (test_callback_fn
)increment_by_key_test
},
5784 {"increment_with_initial_by_key", 1, (test_callback_fn
)increment_with_initial_by_key_test
},
5785 {"decrement_by_key", 0, (test_callback_fn
)decrement_by_key_test
},
5786 {"decrement_with_initial_by_key", 1, (test_callback_fn
)decrement_with_initial_by_key_test
},
5787 {"quit", 0, (test_callback_fn
)quit_test
},
5788 {"mget", 1, (test_callback_fn
)mget_test
},
5789 {"mget_result", 1, (test_callback_fn
)mget_result_test
},
5790 {"mget_result_alloc", 1, (test_callback_fn
)mget_result_alloc_test
},
5791 {"mget_result_function", 1, (test_callback_fn
)mget_result_function
},
5792 {"mget_execute", 1, (test_callback_fn
)mget_execute
},
5793 {"mget_end", 0, (test_callback_fn
)mget_end
},
5794 {"get_stats", 0, (test_callback_fn
)get_stats
},
5795 {"add_host_test", 0, (test_callback_fn
)add_host_test
},
5796 {"add_host_test_1", 0, (test_callback_fn
)add_host_test1
},
5797 {"get_stats_keys", 0, (test_callback_fn
)get_stats_keys
},
5798 {"version_string_test", 0, (test_callback_fn
)version_string_test
},
5799 {"bad_key", 1, (test_callback_fn
)bad_key_test
},
5800 {"memcached_server_cursor", 1, (test_callback_fn
)memcached_server_cursor_test
},
5801 {"read_through", 1, (test_callback_fn
)read_through
},
5802 {"delete_through", 1, (test_callback_fn
)delete_through
},
5803 {"noreply", 1, (test_callback_fn
)noreply_test
},
5804 {"analyzer", 1, (test_callback_fn
)analyzer_test
},
5805 #ifdef HAVE_LIBMEMCACHEDUTIL
5806 {"connectionpool", 1, (test_callback_fn
)connection_pool_test
},
5808 {"test_get_last_disconnect", 1, (test_callback_fn
)test_get_last_disconnect
},
5812 test_st behavior_tests
[] ={
5813 {"behavior_test", 0, (test_callback_fn
)behavior_test
},
5814 {"MEMCACHED_BEHAVIOR_CORK", 0, (test_callback_fn
)MEMCACHED_BEHAVIOR_CORK_test
},
5818 test_st async_tests
[] ={
5819 {"add", 1, (test_callback_fn
)add_wrapper
},
5823 test_st string_tests
[] ={
5824 {"string static with null", 0, (test_callback_fn
)string_static_null
},
5825 {"string alloc with null", 0, (test_callback_fn
)string_alloc_null
},
5826 {"string alloc with 1K", 0, (test_callback_fn
)string_alloc_with_size
},
5827 {"string alloc with malloc failure", 0, (test_callback_fn
)string_alloc_with_size_toobig
},
5828 {"string append", 0, (test_callback_fn
)string_alloc_append
},
5829 {"string append failure (too big)", 0, (test_callback_fn
)string_alloc_append_toobig
},
5830 {0, 0, (test_callback_fn
)0}
5833 test_st result_tests
[] ={
5834 {"result static", 0, (test_callback_fn
)result_static
},
5835 {"result alloc", 0, (test_callback_fn
)result_alloc
},
5836 {0, 0, (test_callback_fn
)0}
5839 test_st version_1_2_3
[] ={
5840 {"append", 0, (test_callback_fn
)append_test
},
5841 {"prepend", 0, (test_callback_fn
)prepend_test
},
5842 {"cas", 0, (test_callback_fn
)cas_test
},
5843 {"cas2", 0, (test_callback_fn
)cas2_test
},
5844 {"append_binary", 0, (test_callback_fn
)append_binary_test
},
5845 {0, 0, (test_callback_fn
)0}
5848 test_st user_tests
[] ={
5849 {"user_supplied_bug1", 0, (test_callback_fn
)user_supplied_bug1
},
5850 {"user_supplied_bug2", 0, (test_callback_fn
)user_supplied_bug2
},
5851 {"user_supplied_bug3", 0, (test_callback_fn
)user_supplied_bug3
},
5852 {"user_supplied_bug4", 0, (test_callback_fn
)user_supplied_bug4
},
5853 {"user_supplied_bug5", 1, (test_callback_fn
)user_supplied_bug5
},
5854 {"user_supplied_bug6", 1, (test_callback_fn
)user_supplied_bug6
},
5855 {"user_supplied_bug7", 1, (test_callback_fn
)user_supplied_bug7
},
5856 {"user_supplied_bug8", 1, (test_callback_fn
)user_supplied_bug8
},
5857 {"user_supplied_bug9", 1, (test_callback_fn
)user_supplied_bug9
},
5858 {"user_supplied_bug10", 1, (test_callback_fn
)user_supplied_bug10
},
5859 {"user_supplied_bug11", 1, (test_callback_fn
)user_supplied_bug11
},
5860 {"user_supplied_bug12", 1, (test_callback_fn
)user_supplied_bug12
},
5861 {"user_supplied_bug13", 1, (test_callback_fn
)user_supplied_bug13
},
5862 {"user_supplied_bug14", 1, (test_callback_fn
)user_supplied_bug14
},
5863 {"user_supplied_bug15", 1, (test_callback_fn
)user_supplied_bug15
},
5864 {"user_supplied_bug16", 1, (test_callback_fn
)user_supplied_bug16
},
5867 ** It seems to be something weird with the character sets..
5868 ** value_fetch is unable to parse the value line (iscntrl "fails"), so I
5869 ** guess I need to find out how this is supposed to work.. Perhaps I need
5870 ** to run the test in a specific locale (I tried zh_CN.UTF-8 without success,
5871 ** so just disable the code for now...).
5873 {"user_supplied_bug17", 1, (test_callback_fn
)user_supplied_bug17
},
5875 {"user_supplied_bug18", 1, (test_callback_fn
)user_supplied_bug18
},
5876 {"user_supplied_bug19", 1, (test_callback_fn
)user_supplied_bug19
},
5877 {"user_supplied_bug20", 1, (test_callback_fn
)user_supplied_bug20
},
5878 {"user_supplied_bug21", 1, (test_callback_fn
)user_supplied_bug21
},
5879 {"wrong_failure_counter_test", 1, (test_callback_fn
)wrong_failure_counter_test
},
5880 {0, 0, (test_callback_fn
)0}
5883 test_st replication_tests
[]= {
5884 {"set", 1, (test_callback_fn
)replication_set_test
},
5885 {"get", 0, (test_callback_fn
)replication_get_test
},
5886 {"mget", 0, (test_callback_fn
)replication_mget_test
},
5887 {"delete", 0, (test_callback_fn
)replication_delete_test
},
5888 {"rand_mget", 0, (test_callback_fn
)replication_randomize_mget_test
},
5889 {0, 0, (test_callback_fn
)0}
5893 * The following test suite is used to verify that we don't introduce
5894 * regression bugs. If you want more information about the bug / test,
5895 * you should look in the bug report at
5896 * http://bugs.launchpad.net/libmemcached
5898 test_st regression_tests
[]= {
5899 {"lp:434484", 1, (test_callback_fn
)regression_bug_434484
},
5900 {"lp:434843", 1, (test_callback_fn
)regression_bug_434843
},
5901 {"lp:434843 buffered", 1, (test_callback_fn
)regression_bug_434843_buffered
},
5902 {"lp:421108", 1, (test_callback_fn
)regression_bug_421108
},
5903 {"lp:442914", 1, (test_callback_fn
)regression_bug_442914
},
5904 {"lp:447342", 1, (test_callback_fn
)regression_bug_447342
},
5905 {"lp:463297", 1, (test_callback_fn
)regression_bug_463297
},
5906 {"lp:490486", 1, (test_callback_fn
)regression_bug_490486
},
5907 {0, 0, (test_callback_fn
)0}
5910 test_st ketama_compatibility
[]= {
5911 {"libmemcached", 1, (test_callback_fn
)ketama_compatibility_libmemcached
},
5912 {"spymemcached", 1, (test_callback_fn
)ketama_compatibility_spymemcached
},
5913 {0, 0, (test_callback_fn
)0}
5916 test_st generate_tests
[] ={
5917 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
5918 {"generate_data", 1, (test_callback_fn
)generate_data
},
5919 {"get_read", 0, (test_callback_fn
)get_read
},
5920 {"delete_generate", 0, (test_callback_fn
)delete_generate
},
5921 {"generate_buffer_data", 1, (test_callback_fn
)generate_buffer_data
},
5922 {"delete_buffer", 0, (test_callback_fn
)delete_buffer_generate
},
5923 {"generate_data", 1, (test_callback_fn
)generate_data
},
5924 {"mget_read", 0, (test_callback_fn
)mget_read
},
5925 {"mget_read_result", 0, (test_callback_fn
)mget_read_result
},
5926 {"mget_read_function", 0, (test_callback_fn
)mget_read_function
},
5927 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5928 {"generate_large_pairs", 1, (test_callback_fn
)generate_large_pairs
},
5929 {"generate_data", 1, (test_callback_fn
)generate_data
},
5930 {"generate_buffer_data", 1, (test_callback_fn
)generate_buffer_data
},
5931 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5932 {0, 0, (test_callback_fn
)0}
5935 test_st consistent_tests
[] ={
5936 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
5937 {"generate_data", 1, (test_callback_fn
)generate_data
},
5938 {"get_read", 0, (test_callback_fn
)get_read_count
},
5939 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5940 {0, 0, (test_callback_fn
)0}
5943 test_st consistent_weighted_tests
[] ={
5944 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
5945 {"generate_data", 1, (test_callback_fn
)generate_data_with_stats
},
5946 {"get_read", 0, (test_callback_fn
)get_read_count
},
5947 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
5948 {0, 0, (test_callback_fn
)0}
5951 test_st hsieh_availability
[] ={
5952 {"hsieh_avaibility_test", 0, (test_callback_fn
)hsieh_avaibility_test
},
5953 {0, 0, (test_callback_fn
)0}
5957 test_st hash_sanity
[] ={
5958 {"hash sanity", 0, (test_callback_fn
)hash_sanity_test
},
5959 {0, 0, (test_callback_fn
)0}
5963 test_st ketama_auto_eject_hosts
[] ={
5964 {"auto_eject_hosts", 1, (test_callback_fn
)auto_eject_hosts
},
5965 {"output_ketama_weighted_keys", 1, (test_callback_fn
)output_ketama_weighted_keys
},
5966 {0, 0, (test_callback_fn
)0}
5969 test_st hash_tests
[] ={
5970 {"md5", 0, (test_callback_fn
)md5_run
},
5971 {"crc", 0, (test_callback_fn
)crc_run
},
5972 {"fnv1_64", 0, (test_callback_fn
)fnv1_64_run
},
5973 {"fnv1a_64", 0, (test_callback_fn
)fnv1a_64_run
},
5974 {"fnv1_32", 0, (test_callback_fn
)fnv1_32_run
},
5975 {"fnv1a_32", 0, (test_callback_fn
)fnv1a_32_run
},
5976 {"hsieh", 0, (test_callback_fn
)hsieh_run
},
5977 {"murmur", 0, (test_callback_fn
)murmur_run
},
5978 {"jenkis", 0, (test_callback_fn
)jenkins_run
},
5979 {0, 0, (test_callback_fn
)0}
5982 collection_st collection
[] ={
5984 {"hash_sanity", 0, 0, hash_sanity
},
5986 {"hsieh_availability", 0, 0, hsieh_availability
},
5987 {"udp_setup", (test_callback_fn
)init_udp
, 0, udp_setup_server_tests
},
5988 {"udp_io", (test_callback_fn
)init_udp
, 0, upd_io_tests
},
5989 {"udp_binary_io", (test_callback_fn
)binary_init_udp
, 0, upd_io_tests
},
5990 {"block", 0, 0, tests
},
5991 {"binary", (test_callback_fn
)pre_binary
, 0, tests
},
5992 {"nonblock", (test_callback_fn
)pre_nonblock
, 0, tests
},
5993 {"nodelay", (test_callback_fn
)pre_nodelay
, 0, tests
},
5994 {"settimer", (test_callback_fn
)pre_settimer
, 0, tests
},
5995 {"md5", (test_callback_fn
)pre_md5
, 0, tests
},
5996 {"crc", (test_callback_fn
)pre_crc
, 0, tests
},
5997 {"hsieh", (test_callback_fn
)pre_hsieh
, 0, tests
},
5998 {"jenkins", (test_callback_fn
)pre_jenkins
, 0, tests
},
5999 {"fnv1_64", (test_callback_fn
)pre_hash_fnv1_64
, 0, tests
},
6000 {"fnv1a_64", (test_callback_fn
)pre_hash_fnv1a_64
, 0, tests
},
6001 {"fnv1_32", (test_callback_fn
)pre_hash_fnv1_32
, 0, tests
},
6002 {"fnv1a_32", (test_callback_fn
)pre_hash_fnv1a_32
, 0, tests
},
6003 {"ketama", (test_callback_fn
)pre_behavior_ketama
, 0, tests
},
6004 {"ketama_auto_eject_hosts", (test_callback_fn
)pre_behavior_ketama
, 0, ketama_auto_eject_hosts
},
6005 {"unix_socket", (test_callback_fn
)pre_unix_socket
, 0, tests
},
6006 {"unix_socket_nodelay", (test_callback_fn
)pre_nodelay
, 0, tests
},
6007 {"poll_timeout", (test_callback_fn
)poll_timeout
, 0, tests
},
6008 {"gets", (test_callback_fn
)enable_cas
, 0, tests
},
6009 {"consistent_crc", (test_callback_fn
)enable_consistent_crc
, 0, tests
},
6010 {"consistent_hsieh", (test_callback_fn
)enable_consistent_hsieh
, 0, tests
},
6011 #ifdef MEMCACHED_ENABLE_DEPRECATED
6012 {"deprecated_memory_allocators", (test_callback_fn
)deprecated_set_memory_alloc
, 0, tests
},
6014 {"memory_allocators", (test_callback_fn
)set_memory_alloc
, 0, tests
},
6015 {"prefix", (test_callback_fn
)set_prefix
, 0, tests
},
6016 {"version_1_2_3", (test_callback_fn
)check_for_1_2_3
, 0, version_1_2_3
},
6017 {"string", 0, 0, string_tests
},
6018 {"result", 0, 0, result_tests
},
6019 {"async", (test_callback_fn
)pre_nonblock
, 0, async_tests
},
6020 {"async_binary", (test_callback_fn
)pre_nonblock_binary
, 0, async_tests
},
6021 {"user", 0, 0, user_tests
},
6022 {"generate", 0, 0, generate_tests
},
6023 {"generate_hsieh", (test_callback_fn
)pre_hsieh
, 0, generate_tests
},
6024 {"generate_ketama", (test_callback_fn
)pre_behavior_ketama
, 0, generate_tests
},
6025 {"generate_hsieh_consistent", (test_callback_fn
)enable_consistent_hsieh
, 0, generate_tests
},
6026 {"generate_md5", (test_callback_fn
)pre_md5
, 0, generate_tests
},
6027 {"generate_murmur", (test_callback_fn
)pre_murmur
, 0, generate_tests
},
6028 {"generate_jenkins", (test_callback_fn
)pre_jenkins
, 0, generate_tests
},
6029 {"generate_nonblock", (test_callback_fn
)pre_nonblock
, 0, generate_tests
},
6031 {"generate_corked", (test_callback_fn
)pre_cork
, 0, generate_tests
},
6032 {"generate_corked_and_nonblock", (test_callback_fn
)pre_cork_and_nonblock
, 0, generate_tests
},
6033 {"consistent_not", 0, 0, consistent_tests
},
6034 {"consistent_ketama", (test_callback_fn
)pre_behavior_ketama
, 0, consistent_tests
},
6035 {"consistent_ketama_weighted", (test_callback_fn
)pre_behavior_ketama_weighted
, 0, consistent_weighted_tests
},
6036 {"ketama_compat", 0, 0, ketama_compatibility
},
6037 {"test_hashes", 0, 0, hash_tests
},
6038 {"replication", (test_callback_fn
)pre_replication
, 0, replication_tests
},
6039 {"replication_noblock", (test_callback_fn
)pre_replication_noblock
, 0, replication_tests
},
6040 {"regression", 0, 0, regression_tests
},
6041 {"behaviors", 0, 0, behavior_tests
},
6045 #define SERVERS_TO_CREATE 5
6047 #include "libmemcached_world.h"
6049 void get_world(world_st
*world
)
6051 world
->collections
= collection
;
6053 world
->create
= (test_callback_create_fn
)world_create
;
6054 world
->destroy
= (test_callback_fn
)world_destroy
;
6056 world
->test
.startup
= (test_callback_fn
)world_test_startup
;
6057 world
->test
.flush
= (test_callback_fn
)world_flush
;
6058 world
->test
.pre_run
= (test_callback_fn
)world_pre_run
;
6059 world
->test
.post_run
= (test_callback_fn
)world_post_run
;
6060 world
->test
.on_error
= (test_callback_error_fn
)world_on_error
;
6062 world
->collection
.startup
= (test_callback_fn
)world_container_startup
;
6063 world
->collection
.shutdown
= (test_callback_fn
)world_container_shutdown
;
6065 world
->runner
= &defualt_libmemcached_runner
;