2 Sample test application.
4 #include "libmemcached/common.h"
11 #include <sys/types.h>
16 #include "clients/generator.h"
17 #include "clients/execute.h"
20 #define INT64_MAX LONG_MAX
23 #define INT32_MAX INT_MAX
29 #ifdef HAVE_LIBMEMCACHEDUTIL
31 #include "libmemcached/memcached_util.h"
34 #define GLOBAL_COUNT 10000
35 #define GLOBAL2_COUNT 100
36 #define SERVERS_TO_CREATE 5
37 static uint32_t global_count
;
39 static pairs_st
*global_pairs
;
40 static char *global_keys
[GLOBAL_COUNT
];
41 static size_t global_keys_length
[GLOBAL_COUNT
];
43 static test_return
init_test(memcached_st
*not_used
__attribute__((unused
)))
47 (void)memcached_create(&memc
);
48 memcached_free(&memc
);
53 static test_return
server_list_null_test(memcached_st
*ptr
__attribute__((unused
)))
55 memcached_server_st
*server_list
;
58 server_list
= memcached_server_list_append_with_weight(NULL
, NULL
, 0, 0, NULL
);
59 assert(server_list
== NULL
);
61 server_list
= memcached_server_list_append_with_weight(NULL
, "localhost", 0, 0, NULL
);
62 assert(server_list
== NULL
);
64 server_list
= memcached_server_list_append_with_weight(NULL
, NULL
, 0, 0, &rc
);
65 assert(server_list
== NULL
);
70 #define TEST_PORT_COUNT 7
71 uint32_t test_ports
[TEST_PORT_COUNT
];
73 static memcached_return
server_display_function(memcached_st
*ptr
__attribute__((unused
)), memcached_server_st
*server
, void *context
)
76 uint32_t bigger
= *((uint32_t *)(context
));
77 assert(bigger
<= server
->port
);
78 *((uint32_t *)(context
))= server
->port
;
80 return MEMCACHED_SUCCESS
;
83 static test_return
server_sort_test(memcached_st
*ptr
__attribute__((unused
)))
86 uint32_t bigger
= 0; /* Prime the value for the assert in server_display_function */
88 memcached_server_function callbacks
[1];
89 memcached_st
*local_memc
;
91 local_memc
= memcached_create(NULL
);
93 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
95 for (x
= 0; x
< TEST_PORT_COUNT
; x
++)
97 test_ports
[x
]= random() % 64000;
98 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
99 assert(local_memc
->number_of_hosts
== x
+ 1);
100 assert(local_memc
->hosts
[0].count
== x
+1);
101 assert(rc
== MEMCACHED_SUCCESS
);
104 callbacks
[0]= server_display_function
;
105 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
108 memcached_free(local_memc
);
113 static test_return
server_sort2_test(memcached_st
*ptr
__attribute__((unused
)))
115 uint32_t bigger
= 0; /* Prime the value for the assert in server_display_function */
117 memcached_server_function callbacks
[1];
118 memcached_st
*local_memc
;
120 local_memc
= memcached_create(NULL
);
122 rc
= memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
123 assert(rc
== MEMCACHED_SUCCESS
);
125 rc
= memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43043, 0);
126 assert(rc
== MEMCACHED_SUCCESS
);
127 assert(local_memc
->hosts
[0].port
== 43043);
129 rc
= memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43042, 0);
130 assert(rc
== MEMCACHED_SUCCESS
);
131 assert(local_memc
->hosts
[0].port
== 43042);
132 assert(local_memc
->hosts
[1].port
== 43043);
134 callbacks
[0]= server_display_function
;
135 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
138 memcached_free(local_memc
);
143 static memcached_return
server_display_unsort_function(memcached_st
*ptr
__attribute__((unused
)), memcached_server_st
*server
, void *context
)
146 uint32_t x
= *((uint32_t *)(context
));
148 assert(test_ports
[x
] == server
->port
);
149 *((uint32_t *)(context
))= ++x
;
151 return MEMCACHED_SUCCESS
;
154 static test_return
server_unsort_test(memcached_st
*ptr
__attribute__((unused
)))
157 uint32_t counter
= 0; /* Prime the value for the assert in server_display_function */
158 uint32_t bigger
= 0; /* Prime the value for the assert in server_display_function */
160 memcached_server_function callbacks
[1];
161 memcached_st
*local_memc
;
163 local_memc
= memcached_create(NULL
);
166 for (x
= 0; x
< TEST_PORT_COUNT
; x
++)
168 test_ports
[x
]= random() % 64000;
169 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
170 assert(local_memc
->number_of_hosts
== x
+1);
171 assert(local_memc
->hosts
[0].count
== x
+1);
172 assert(rc
== MEMCACHED_SUCCESS
);
175 callbacks
[0]= server_display_unsort_function
;
176 memcached_server_cursor(local_memc
, callbacks
, (void *)&counter
, 1);
178 /* Now we sort old data! */
179 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
180 callbacks
[0]= server_display_function
;
181 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
184 memcached_free(local_memc
);
189 static test_return
allocation_test(memcached_st
*not_used
__attribute__((unused
)))
192 memc
= memcached_create(NULL
);
194 memcached_free(memc
);
199 static test_return
clone_test(memcached_st
*memc
)
204 clone
= memcached_clone(NULL
, NULL
);
206 memcached_free(clone
);
209 /* Can we init from null? */
212 clone
= memcached_clone(NULL
, memc
);
215 assert(clone
->call_free
== memc
->call_free
);
216 assert(clone
->call_malloc
== memc
->call_malloc
);
217 assert(clone
->call_realloc
== memc
->call_realloc
);
218 assert(clone
->connect_timeout
== memc
->connect_timeout
);
219 assert(clone
->delete_trigger
== memc
->delete_trigger
);
220 assert(clone
->distribution
== memc
->distribution
);
221 assert(clone
->flags
== memc
->flags
);
222 assert(clone
->get_key_failure
== memc
->get_key_failure
);
223 assert(clone
->hash
== memc
->hash
);
224 assert(clone
->hash_continuum
== memc
->hash_continuum
);
225 assert(clone
->io_bytes_watermark
== memc
->io_bytes_watermark
);
226 assert(clone
->io_msg_watermark
== memc
->io_msg_watermark
);
227 assert(clone
->io_key_prefetch
== memc
->io_key_prefetch
);
228 assert(clone
->on_cleanup
== memc
->on_cleanup
);
229 assert(clone
->on_clone
== memc
->on_clone
);
230 assert(clone
->poll_timeout
== memc
->poll_timeout
);
231 assert(clone
->rcv_timeout
== memc
->rcv_timeout
);
232 assert(clone
->recv_size
== memc
->recv_size
);
233 assert(clone
->retry_timeout
== memc
->retry_timeout
);
234 assert(clone
->send_size
== memc
->send_size
);
235 assert(clone
->server_failure_limit
== memc
->server_failure_limit
);
236 assert(clone
->snd_timeout
== memc
->snd_timeout
);
237 assert(clone
->user_data
== memc
->user_data
);
239 memcached_free(clone
);
242 /* Can we init from struct? */
244 memcached_st declared_clone
;
246 memset(&declared_clone
, 0 , sizeof(memcached_st
));
247 clone
= memcached_clone(&declared_clone
, NULL
);
249 memcached_free(clone
);
252 /* Can we init from struct? */
254 memcached_st declared_clone
;
256 memset(&declared_clone
, 0 , sizeof(memcached_st
));
257 clone
= memcached_clone(&declared_clone
, memc
);
259 memcached_free(clone
);
265 static test_return
connection_test(memcached_st
*memc
)
269 rc
= memcached_server_add_with_weight(memc
, "localhost", 0, 0);
270 assert(rc
== MEMCACHED_SUCCESS
);
275 static test_return
error_test(memcached_st
*memc
)
279 for (rc
= MEMCACHED_SUCCESS
; rc
< MEMCACHED_MAXIMUM_RETURN
; rc
++)
281 printf("Error %d -> %s\n", rc
, memcached_strerror(memc
, rc
));
287 static test_return
set_test(memcached_st
*memc
)
291 char *value
= "when we sanitize";
293 rc
= memcached_set(memc
, key
, strlen(key
),
294 value
, strlen(value
),
295 (time_t)0, (uint32_t)0);
296 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
301 static test_return
append_test(memcached_st
*memc
)
309 rc
= memcached_flush(memc
, 0);
310 assert(rc
== MEMCACHED_SUCCESS
);
312 rc
= memcached_set(memc
, key
, strlen(key
),
313 value
, strlen(value
),
314 (time_t)0, (uint32_t)0);
315 assert(rc
== MEMCACHED_SUCCESS
);
317 rc
= memcached_append(memc
, key
, strlen(key
),
318 " the", strlen(" the"),
319 (time_t)0, (uint32_t)0);
320 assert(rc
== MEMCACHED_SUCCESS
);
322 rc
= memcached_append(memc
, key
, strlen(key
),
323 " people", strlen(" people"),
324 (time_t)0, (uint32_t)0);
325 assert(rc
== MEMCACHED_SUCCESS
);
327 value
= memcached_get(memc
, key
, strlen(key
),
328 &value_length
, &flags
, &rc
);
329 assert(!memcmp(value
, "we the people", strlen("we the people")));
330 assert(strlen("we the people") == value_length
);
331 assert(rc
== MEMCACHED_SUCCESS
);
337 static test_return
append_binary_test(memcached_st
*memc
)
340 char *key
= "numbers";
341 unsigned int *store_ptr
;
342 unsigned int store_list
[] = { 23, 56, 499, 98, 32847, 0 };
348 rc
= memcached_flush(memc
, 0);
349 assert(rc
== MEMCACHED_SUCCESS
);
351 rc
= memcached_set(memc
,
354 (time_t)0, (uint32_t)0);
355 assert(rc
== MEMCACHED_SUCCESS
);
357 for (x
= 0; store_list
[x
] ; x
++)
359 rc
= memcached_append(memc
,
361 (char *)&store_list
[x
], sizeof(unsigned int),
362 (time_t)0, (uint32_t)0);
363 assert(rc
== MEMCACHED_SUCCESS
);
366 value
= memcached_get(memc
, key
, strlen(key
),
367 &value_length
, &flags
, &rc
);
368 assert((value_length
== (sizeof(unsigned int) * x
)));
369 assert(rc
== MEMCACHED_SUCCESS
);
371 store_ptr
= (unsigned int *)value
;
373 while ((size_t)store_ptr
< (size_t)(value
+ value_length
))
375 assert(*store_ptr
== store_list
[x
++]);
383 static test_return
cas2_test(memcached_st
*memc
)
386 char *keys
[]= {"fudge", "son", "food"};
387 size_t key_length
[]= {5, 3, 4};
388 char *value
= "we the people";
389 size_t value_length
= strlen("we the people");
391 memcached_result_st results_obj
;
392 memcached_result_st
*results
;
395 rc
= memcached_flush(memc
, 0);
396 assert(rc
== MEMCACHED_SUCCESS
);
398 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
400 for (x
= 0; x
< 3; x
++)
402 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
403 keys
[x
], key_length
[x
],
404 (time_t)50, (uint32_t)9);
405 assert(rc
== MEMCACHED_SUCCESS
);
408 rc
= memcached_mget(memc
, keys
, key_length
, 3);
410 results
= memcached_result_create(memc
, &results_obj
);
412 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
414 assert(results
->cas
);
415 assert(rc
== MEMCACHED_SUCCESS
);
416 WATCHPOINT_ASSERT(memcached_result_cas(results
));
418 assert(!memcmp(value
, "we the people", strlen("we the people")));
419 assert(strlen("we the people") == value_length
);
420 assert(rc
== MEMCACHED_SUCCESS
);
422 memcached_result_free(&results_obj
);
427 static test_return
cas_test(memcached_st
*memc
)
430 const char *key
= "fun";
431 size_t key_length
= strlen(key
);
432 const char *value
= "we the people";
433 char* keys
[2] = { (char*)key
, NULL
};
434 size_t keylengths
[2] = { strlen(key
), 0 };
435 size_t value_length
= strlen(value
);
436 const char *value2
= "change the value";
437 size_t value2_length
= strlen(value2
);
439 memcached_result_st results_obj
;
440 memcached_result_st
*results
;
443 rc
= memcached_flush(memc
, 0);
444 assert(rc
== MEMCACHED_SUCCESS
);
446 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
448 rc
= memcached_set(memc
, key
, strlen(key
),
449 value
, strlen(value
),
450 (time_t)0, (uint32_t)0);
451 assert(rc
== MEMCACHED_SUCCESS
);
453 rc
= memcached_mget(memc
, keys
, keylengths
, 1);
455 results
= memcached_result_create(memc
, &results_obj
);
457 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
459 assert(rc
== MEMCACHED_SUCCESS
);
460 WATCHPOINT_ASSERT(memcached_result_cas(results
));
461 assert(!memcmp(value
, memcached_result_value(results
), value_length
));
462 assert(strlen(memcached_result_value(results
)) == value_length
);
463 assert(rc
== MEMCACHED_SUCCESS
);
464 uint64_t cas
= memcached_result_cas(results
);
467 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
468 assert(rc
== MEMCACHED_END
);
469 assert(results
== NULL
);
472 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
473 assert(rc
== MEMCACHED_SUCCESS
);
476 * The item will have a new cas value, so try to set it again with the old
477 * value. This should fail!
479 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
480 assert(rc
== MEMCACHED_DATA_EXISTS
);
482 memcached_result_free(&results_obj
);
487 static test_return
prepend_test(memcached_st
*memc
)
491 char *value
= "people";
495 rc
= memcached_flush(memc
, 0);
496 assert(rc
== MEMCACHED_SUCCESS
);
498 rc
= memcached_set(memc
, key
, strlen(key
),
499 value
, strlen(value
),
500 (time_t)0, (uint32_t)0);
501 assert(rc
== MEMCACHED_SUCCESS
);
503 rc
= memcached_prepend(memc
, key
, strlen(key
),
504 "the ", strlen("the "),
505 (time_t)0, (uint32_t)0);
506 assert(rc
== MEMCACHED_SUCCESS
);
508 rc
= memcached_prepend(memc
, key
, strlen(key
),
509 "we ", strlen("we "),
510 (time_t)0, (uint32_t)0);
511 assert(rc
== MEMCACHED_SUCCESS
);
513 value
= memcached_get(memc
, key
, strlen(key
),
514 &value_length
, &flags
, &rc
);
515 assert(!memcmp(value
, "we the people", strlen("we the people")));
516 assert(strlen("we the people") == value_length
);
517 assert(rc
== MEMCACHED_SUCCESS
);
524 Set the value, then quit to make sure it is flushed.
525 Come back in and test that add fails.
527 static test_return
add_test(memcached_st
*memc
)
531 char *value
= "when we sanitize";
532 unsigned long long setting_value
;
534 setting_value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
536 rc
= memcached_set(memc
, key
, strlen(key
),
537 value
, strlen(value
),
538 (time_t)0, (uint32_t)0);
539 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
540 memcached_quit(memc
);
541 rc
= memcached_add(memc
, key
, strlen(key
),
542 value
, strlen(value
),
543 (time_t)0, (uint32_t)0);
545 /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */
547 assert(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_STORED
);
549 assert(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_DATA_EXISTS
);
555 ** There was a problem of leaking filedescriptors in the initial release
556 ** of MacOSX 10.5. This test case triggers the problem. On some Solaris
557 ** systems it seems that the kernel is slow on reclaiming the resources
558 ** because the connects starts to time out (the test doesn't do much
559 ** anyway, so just loop 10 iterations)
561 static test_return
add_wrapper(memcached_st
*memc
)
564 unsigned int max
= 10000;
569 for (x
= 0; x
< max
; x
++)
575 static test_return
replace_test(memcached_st
*memc
)
579 char *value
= "when we sanitize";
580 char *original
= "first we insert some data";
582 rc
= memcached_set(memc
, key
, strlen(key
),
583 original
, strlen(original
),
584 (time_t)0, (uint32_t)0);
585 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
587 rc
= memcached_replace(memc
, key
, strlen(key
),
588 value
, strlen(value
),
589 (time_t)0, (uint32_t)0);
590 assert(rc
== MEMCACHED_SUCCESS
);
595 static test_return
delete_test(memcached_st
*memc
)
599 char *value
= "when we sanitize";
601 rc
= memcached_set(memc
, key
, strlen(key
),
602 value
, strlen(value
),
603 (time_t)0, (uint32_t)0);
604 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
606 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
607 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
612 static test_return
flush_test(memcached_st
*memc
)
616 rc
= memcached_flush(memc
, 0);
617 assert(rc
== MEMCACHED_SUCCESS
);
622 static memcached_return
server_function(memcached_st
*ptr
__attribute__((unused
)),
623 memcached_server_st
*server
__attribute__((unused
)),
624 void *context
__attribute__((unused
)))
628 return MEMCACHED_SUCCESS
;
631 static test_return
memcached_server_cursor_test(memcached_st
*memc
)
633 char *context
= "foo bad";
634 memcached_server_function callbacks
[1];
636 callbacks
[0]= server_function
;
637 memcached_server_cursor(memc
, callbacks
, context
, 1);
642 static test_return
bad_key_test(memcached_st
*memc
)
645 char *key
= "foo bad";
647 size_t string_length
;
651 size_t max_keylen
= 0xffff;
653 clone
= memcached_clone(NULL
, memc
);
656 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
657 assert(rc
== MEMCACHED_SUCCESS
);
659 /* All keys are valid in the binary protocol (except for length) */
660 if (memcached_behavior_get(clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 0)
662 string
= memcached_get(clone
, key
, strlen(key
),
663 &string_length
, &flags
, &rc
);
664 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
665 assert(string_length
== 0);
669 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
670 assert(rc
== MEMCACHED_SUCCESS
);
671 string
= memcached_get(clone
, key
, strlen(key
),
672 &string_length
, &flags
, &rc
);
673 assert(rc
== MEMCACHED_NOTFOUND
);
674 assert(string_length
== 0);
677 /* Test multi key for bad keys */
678 char *keys
[] = { "GoodKey", "Bad Key", "NotMine" };
679 size_t key_lengths
[] = { 7, 7, 7 };
681 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
682 assert(rc
== MEMCACHED_SUCCESS
);
684 rc
= memcached_mget(clone
, keys
, key_lengths
, 3);
685 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
687 rc
= memcached_mget_by_key(clone
, "foo daddy", 9, keys
, key_lengths
, 1);
688 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
692 /* The following test should be moved to the end of this function when the
693 memcached server is updated to allow max size length of the keys in the
696 rc
= memcached_callback_set(clone
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
697 assert(rc
== MEMCACHED_SUCCESS
);
699 char *longkey
= malloc(max_keylen
+ 1);
702 memset(longkey
, 'a', max_keylen
+ 1);
703 string
= memcached_get(clone
, longkey
, max_keylen
,
704 &string_length
, &flags
, &rc
);
705 assert(rc
== MEMCACHED_NOTFOUND
);
706 assert(string_length
== 0);
709 string
= memcached_get(clone
, longkey
, max_keylen
+ 1,
710 &string_length
, &flags
, &rc
);
711 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
712 assert(string_length
== 0);
719 /* Make sure zero length keys are marked as bad */
721 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
722 assert(rc
== MEMCACHED_SUCCESS
);
723 string
= memcached_get(clone
, key
, 0,
724 &string_length
, &flags
, &rc
);
725 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
726 assert(string_length
== 0);
729 memcached_free(clone
);
734 #define READ_THROUGH_VALUE "set for me"
735 static memcached_return
read_through_trigger(memcached_st
*memc
__attribute__((unused
)),
736 char *key
__attribute__((unused
)),
737 size_t key_length
__attribute__((unused
)),
738 memcached_result_st
*result
)
741 return memcached_result_set_value(result
, READ_THROUGH_VALUE
, strlen(READ_THROUGH_VALUE
));
744 static test_return
read_through(memcached_st
*memc
)
749 size_t string_length
;
751 memcached_trigger_key cb
= (memcached_trigger_key
)read_through_trigger
;
753 string
= memcached_get(memc
, key
, strlen(key
),
754 &string_length
, &flags
, &rc
);
756 assert(rc
== MEMCACHED_NOTFOUND
);
757 assert(string_length
== 0);
760 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_GET_FAILURE
,
762 assert(rc
== MEMCACHED_SUCCESS
);
764 string
= memcached_get(memc
, key
, strlen(key
),
765 &string_length
, &flags
, &rc
);
767 assert(rc
== MEMCACHED_SUCCESS
);
768 assert(string_length
== strlen(READ_THROUGH_VALUE
));
769 assert(!strcmp(READ_THROUGH_VALUE
, string
));
772 string
= memcached_get(memc
, key
, strlen(key
),
773 &string_length
, &flags
, &rc
);
775 assert(rc
== MEMCACHED_SUCCESS
);
776 assert(string_length
== strlen(READ_THROUGH_VALUE
));
777 assert(!strcmp(READ_THROUGH_VALUE
, string
));
783 static memcached_return
delete_trigger(memcached_st
*ptr
__attribute__((unused
)),
785 size_t key_length
__attribute__((unused
)))
789 return MEMCACHED_SUCCESS
;
792 static test_return
delete_through(memcached_st
*memc
)
794 memcached_trigger_delete_key callback
;
797 callback
= (memcached_trigger_delete_key
)delete_trigger
;
799 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_DELETE_TRIGGER
, *(void**)&callback
);
800 assert(rc
== MEMCACHED_SUCCESS
);
805 static test_return
get_test(memcached_st
*memc
)
810 size_t string_length
;
813 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
814 assert(rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_NOTFOUND
);
816 string
= memcached_get(memc
, key
, strlen(key
),
817 &string_length
, &flags
, &rc
);
819 assert(rc
== MEMCACHED_NOTFOUND
);
820 assert(string_length
== 0);
826 static test_return
get_test2(memcached_st
*memc
)
830 char *value
= "when we sanitize";
832 size_t string_length
;
835 rc
= memcached_set(memc
, key
, strlen(key
),
836 value
, strlen(value
),
837 (time_t)0, (uint32_t)0);
838 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
840 string
= memcached_get(memc
, key
, strlen(key
),
841 &string_length
, &flags
, &rc
);
844 assert(rc
== MEMCACHED_SUCCESS
);
845 assert(string_length
== strlen(value
));
846 assert(!memcmp(string
, value
, string_length
));
853 static test_return
set_test2(memcached_st
*memc
)
857 char *value
= "train in the brain";
858 size_t value_length
= strlen(value
);
861 for (x
= 0; x
< 10; x
++)
863 rc
= memcached_set(memc
, key
, strlen(key
),
865 (time_t)0, (uint32_t)0);
866 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
872 static test_return
set_test3(memcached_st
*memc
)
876 size_t value_length
= 8191;
879 value
= (char*)malloc(value_length
);
882 for (x
= 0; x
< value_length
; x
++)
883 value
[x
] = (char) (x
% 127);
885 /* The dump test relies on there being at least 32 items in memcached */
886 for (x
= 0; x
< 32; x
++)
890 sprintf(key
, "foo%u", x
);
892 rc
= memcached_set(memc
, key
, strlen(key
),
894 (time_t)0, (uint32_t)0);
895 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
903 static test_return
get_test3(memcached_st
*memc
)
908 size_t value_length
= 8191;
910 size_t string_length
;
914 value
= (char*)malloc(value_length
);
917 for (x
= 0; x
< value_length
; x
++)
918 value
[x
] = (char) (x
% 127);
920 rc
= memcached_set(memc
, key
, strlen(key
),
922 (time_t)0, (uint32_t)0);
923 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
925 string
= memcached_get(memc
, key
, strlen(key
),
926 &string_length
, &flags
, &rc
);
928 assert(rc
== MEMCACHED_SUCCESS
);
930 assert(string_length
== value_length
);
931 assert(!memcmp(string
, value
, string_length
));
939 static test_return
get_test4(memcached_st
*memc
)
944 size_t value_length
= 8191;
946 size_t string_length
;
950 value
= (char*)malloc(value_length
);
953 for (x
= 0; x
< value_length
; x
++)
954 value
[x
] = (char) (x
% 127);
956 rc
= memcached_set(memc
, key
, strlen(key
),
958 (time_t)0, (uint32_t)0);
959 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
961 for (x
= 0; x
< 10; x
++)
963 string
= memcached_get(memc
, key
, strlen(key
),
964 &string_length
, &flags
, &rc
);
966 assert(rc
== MEMCACHED_SUCCESS
);
968 assert(string_length
== value_length
);
969 assert(!memcmp(string
, value
, string_length
));
979 * This test verifies that memcached_read_one_response doesn't try to
980 * dereference a NIL-pointer if you issue a multi-get and don't read out all
981 * responses before you execute a storage command.
983 static test_return
get_test5(memcached_st
*memc
)
986 ** Request the same key twice, to ensure that we hash to the same server
987 ** (so that we have multiple response values queued up) ;-)
989 char *keys
[]= { "key", "key" };
990 size_t lengths
[]= { 3, 3 };
994 memcached_return rc
= memcached_set(memc
, keys
[0], lengths
[0],
995 keys
[0], lengths
[0], 0, 0);
996 assert(rc
== MEMCACHED_SUCCESS
);
997 rc
= memcached_mget(memc
, keys
, lengths
, 2);
999 memcached_result_st results_obj
;
1000 memcached_result_st
*results
;
1001 results
=memcached_result_create(memc
, &results_obj
);
1003 results
=memcached_fetch_result(memc
, &results_obj
, &rc
);
1005 memcached_result_free(&results_obj
);
1007 /* Don't read out the second result, but issue a set instead.. */
1008 rc
= memcached_set(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0);
1009 assert(rc
== MEMCACHED_SUCCESS
);
1011 char *val
= memcached_get_by_key(memc
, keys
[0], lengths
[0], "yek", 3,
1012 &rlen
, &flags
, &rc
);
1013 assert(val
== NULL
);
1014 assert(rc
== MEMCACHED_NOTFOUND
);
1015 val
= memcached_get(memc
, keys
[0], lengths
[0], &rlen
, &flags
, &rc
);
1016 assert(val
!= NULL
);
1017 assert(rc
== MEMCACHED_SUCCESS
);
1020 return TEST_SUCCESS
;
1023 /* Do not copy the style of this code, I just access hosts to testthis function */
1024 static test_return
stats_servername_test(memcached_st
*memc
)
1026 memcached_return rc
;
1027 memcached_stat_st stat
;
1028 rc
= memcached_stat_servername(&stat
, NULL
,
1029 memc
->hosts
[0].hostname
,
1030 memc
->hosts
[0].port
);
1035 static test_return
increment_test(memcached_st
*memc
)
1037 uint64_t new_number
;
1038 memcached_return rc
;
1039 char *key
= "number";
1042 rc
= memcached_set(memc
, key
, strlen(key
),
1043 value
, strlen(value
),
1044 (time_t)0, (uint32_t)0);
1045 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1047 rc
= memcached_increment(memc
, key
, strlen(key
),
1049 assert(rc
== MEMCACHED_SUCCESS
);
1050 assert(new_number
== 1);
1052 rc
= memcached_increment(memc
, key
, strlen(key
),
1054 assert(rc
== MEMCACHED_SUCCESS
);
1055 assert(new_number
== 2);
1060 static test_return
increment_with_initial_test(memcached_st
*memc
)
1062 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1064 uint64_t new_number
;
1065 memcached_return rc
;
1066 char *key
= "number";
1067 uint64_t initial
= 0;
1069 rc
= memcached_increment_with_initial(memc
, key
, strlen(key
),
1070 1, initial
, 0, &new_number
);
1071 assert(rc
== MEMCACHED_SUCCESS
);
1072 assert(new_number
== initial
);
1074 rc
= memcached_increment_with_initial(memc
, key
, strlen(key
),
1075 1, initial
, 0, &new_number
);
1076 assert(rc
== MEMCACHED_SUCCESS
);
1077 assert(new_number
== (initial
+ 1));
1082 static test_return
decrement_test(memcached_st
*memc
)
1084 uint64_t new_number
;
1085 memcached_return rc
;
1086 char *key
= "number";
1089 rc
= memcached_set(memc
, key
, strlen(key
),
1090 value
, strlen(value
),
1091 (time_t)0, (uint32_t)0);
1092 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1094 rc
= memcached_decrement(memc
, key
, strlen(key
),
1096 assert(rc
== MEMCACHED_SUCCESS
);
1097 assert(new_number
== 2);
1099 rc
= memcached_decrement(memc
, key
, strlen(key
),
1101 assert(rc
== MEMCACHED_SUCCESS
);
1102 assert(new_number
== 1);
1107 static test_return
decrement_with_initial_test(memcached_st
*memc
)
1109 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1111 uint64_t new_number
;
1112 memcached_return rc
;
1113 char *key
= "number";
1114 uint64_t initial
= 3;
1116 rc
= memcached_decrement_with_initial(memc
, key
, strlen(key
),
1117 1, initial
, 0, &new_number
);
1118 assert(rc
== MEMCACHED_SUCCESS
);
1119 assert(new_number
== initial
);
1121 rc
= memcached_decrement_with_initial(memc
, key
, strlen(key
),
1122 1, initial
, 0, &new_number
);
1123 assert(rc
== MEMCACHED_SUCCESS
);
1124 assert(new_number
== (initial
- 1));
1129 static test_return
quit_test(memcached_st
*memc
)
1131 memcached_return rc
;
1133 char *value
= "sanford and sun";
1135 rc
= memcached_set(memc
, key
, strlen(key
),
1136 value
, strlen(value
),
1137 (time_t)10, (uint32_t)3);
1138 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1139 memcached_quit(memc
);
1141 rc
= memcached_set(memc
, key
, strlen(key
),
1142 value
, strlen(value
),
1143 (time_t)50, (uint32_t)9);
1144 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1149 static test_return
mget_result_test(memcached_st
*memc
)
1151 memcached_return rc
;
1152 char *keys
[]= {"fudge", "son", "food"};
1153 size_t key_length
[]= {5, 3, 4};
1156 memcached_result_st results_obj
;
1157 memcached_result_st
*results
;
1159 results
= memcached_result_create(memc
, &results_obj
);
1161 assert(&results_obj
== results
);
1163 /* We need to empty the server before continueing test */
1164 rc
= memcached_flush(memc
, 0);
1165 assert(rc
== MEMCACHED_SUCCESS
);
1167 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1168 assert(rc
== MEMCACHED_SUCCESS
);
1170 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1175 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1177 assert(rc
== MEMCACHED_END
);
1179 for (x
= 0; x
< 3; x
++)
1181 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1182 keys
[x
], key_length
[x
],
1183 (time_t)50, (uint32_t)9);
1184 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1187 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1188 assert(rc
== MEMCACHED_SUCCESS
);
1190 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1193 assert(&results_obj
== results
);
1194 assert(rc
== MEMCACHED_SUCCESS
);
1195 assert(memcached_result_key_length(results
) == memcached_result_length(results
));
1196 assert(!memcmp(memcached_result_key_value(results
),
1197 memcached_result_value(results
),
1198 memcached_result_length(results
)));
1201 memcached_result_free(&results_obj
);
1206 static test_return
mget_result_alloc_test(memcached_st
*memc
)
1208 memcached_return rc
;
1209 char *keys
[]= {"fudge", "son", "food"};
1210 size_t key_length
[]= {5, 3, 4};
1213 memcached_result_st
*results
;
1215 /* We need to empty the server before continueing test */
1216 rc
= memcached_flush(memc
, 0);
1217 assert(rc
== MEMCACHED_SUCCESS
);
1219 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1220 assert(rc
== MEMCACHED_SUCCESS
);
1222 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)) != NULL
)
1227 assert(rc
== MEMCACHED_END
);
1229 for (x
= 0; x
< 3; x
++)
1231 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1232 keys
[x
], key_length
[x
],
1233 (time_t)50, (uint32_t)9);
1234 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1237 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1238 assert(rc
== MEMCACHED_SUCCESS
);
1241 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1244 assert(rc
== MEMCACHED_SUCCESS
);
1245 assert(memcached_result_key_length(results
) == memcached_result_length(results
));
1246 assert(!memcmp(memcached_result_key_value(results
),
1247 memcached_result_value(results
),
1248 memcached_result_length(results
)));
1249 memcached_result_free(results
);
1256 /* Count the results */
1257 static memcached_return
callback_counter(memcached_st
*ptr
__attribute__((unused
)),
1258 memcached_result_st
*result
__attribute__((unused
)),
1261 unsigned int *counter
= (unsigned int *)context
;
1263 *counter
= *counter
+ 1;
1265 return MEMCACHED_SUCCESS
;
1268 static test_return
mget_result_function(memcached_st
*memc
)
1270 memcached_return rc
;
1271 char *keys
[]= {"fudge", "son", "food"};
1272 size_t key_length
[]= {5, 3, 4};
1274 unsigned int counter
;
1275 memcached_execute_function callbacks
[1];
1277 /* We need to empty the server before continueing test */
1278 rc
= memcached_flush(memc
, 0);
1279 for (x
= 0; x
< 3; x
++)
1281 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1282 keys
[x
], key_length
[x
],
1283 (time_t)50, (uint32_t)9);
1284 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1287 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1288 assert(rc
== MEMCACHED_SUCCESS
);
1290 callbacks
[0]= &callback_counter
;
1292 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
1294 assert(counter
== 3);
1299 static test_return
mget_test(memcached_st
*memc
)
1301 memcached_return rc
;
1302 char *keys
[]= {"fudge", "son", "food"};
1303 size_t key_length
[]= {5, 3, 4};
1307 char return_key
[MEMCACHED_MAX_KEY
];
1308 size_t return_key_length
;
1310 size_t return_value_length
;
1312 /* We need to empty the server before continueing test */
1313 rc
= memcached_flush(memc
, 0);
1314 assert(rc
== MEMCACHED_SUCCESS
);
1316 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1317 assert(rc
== MEMCACHED_SUCCESS
);
1319 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1320 &return_value_length
, &flags
, &rc
)) != NULL
)
1322 assert(return_value
);
1324 assert(!return_value
);
1325 assert(return_value_length
== 0);
1326 assert(rc
== MEMCACHED_END
);
1328 for (x
= 0; x
< 3; x
++)
1330 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1331 keys
[x
], key_length
[x
],
1332 (time_t)50, (uint32_t)9);
1333 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1336 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1337 assert(rc
== MEMCACHED_SUCCESS
);
1340 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1341 &return_value_length
, &flags
, &rc
)))
1343 assert(return_value
);
1344 assert(rc
== MEMCACHED_SUCCESS
);
1345 assert(return_key_length
== return_value_length
);
1346 assert(!memcmp(return_value
, return_key
, return_value_length
));
1354 static test_return
get_stats_keys(memcached_st
*memc
)
1358 memcached_stat_st stat
;
1359 memcached_return rc
;
1361 list
= memcached_stat_get_keys(memc
, &stat
, &rc
);
1362 assert(rc
== MEMCACHED_SUCCESS
);
1363 for (ptr
= list
; *ptr
; ptr
++)
1372 static test_return
version_string_test(memcached_st
*memc
__attribute__((unused
)))
1374 const char *version_string
;
1376 version_string
= memcached_lib_version();
1378 assert(!strcmp(version_string
, LIBMEMCACHED_VERSION_STRING
));
1383 static test_return
get_stats(memcached_st
*memc
)
1388 memcached_return rc
;
1389 memcached_stat_st
*stat
;
1391 stat
= memcached_stat(memc
, NULL
, &rc
);
1392 assert(rc
== MEMCACHED_SUCCESS
);
1394 assert(rc
== MEMCACHED_SUCCESS
);
1397 for (x
= 0; x
< memcached_server_count(memc
); x
++)
1399 list
= memcached_stat_get_keys(memc
, stat
+x
, &rc
);
1400 assert(rc
== MEMCACHED_SUCCESS
);
1401 for (ptr
= list
; *ptr
; ptr
++);
1406 memcached_stat_free(NULL
, stat
);
1411 static test_return
add_host_test(memcached_st
*memc
)
1414 memcached_server_st
*servers
;
1415 memcached_return rc
;
1416 char servername
[]= "0.example.com";
1418 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
1420 assert(1 == memcached_server_list_count(servers
));
1422 for (x
= 2; x
< 20; x
++)
1424 char buffer
[SMALL_STRING_LEN
];
1426 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
1427 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
1429 assert(rc
== MEMCACHED_SUCCESS
);
1430 assert(x
== memcached_server_list_count(servers
));
1433 rc
= memcached_server_push(memc
, servers
);
1434 assert(rc
== MEMCACHED_SUCCESS
);
1435 rc
= memcached_server_push(memc
, servers
);
1436 assert(rc
== MEMCACHED_SUCCESS
);
1438 memcached_server_list_free(servers
);
1443 static memcached_return
clone_test_callback(memcached_st
*parent
__attribute__((unused
)), memcached_st
*clone
__attribute__((unused
)))
1445 return MEMCACHED_SUCCESS
;
1448 static memcached_return
cleanup_test_callback(memcached_st
*ptr
__attribute__((unused
)))
1450 return MEMCACHED_SUCCESS
;
1453 static test_return
callback_test(memcached_st
*memc
)
1455 /* Test User Data */
1459 memcached_return rc
;
1461 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_USER_DATA
, &x
);
1462 assert(rc
== MEMCACHED_SUCCESS
);
1463 test_ptr
= (int *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_USER_DATA
, &rc
);
1464 assert(*test_ptr
== x
);
1467 /* Test Clone Callback */
1469 memcached_clone_func clone_cb
= (memcached_clone_func
)clone_test_callback
;
1470 void *clone_cb_ptr
= *(void **)&clone_cb
;
1471 void *temp_function
= NULL
;
1472 memcached_return rc
;
1474 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
,
1476 assert(rc
== MEMCACHED_SUCCESS
);
1477 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1478 assert(temp_function
== clone_cb_ptr
);
1481 /* Test Cleanup Callback */
1483 memcached_cleanup_func cleanup_cb
=
1484 (memcached_cleanup_func
)cleanup_test_callback
;
1485 void *cleanup_cb_ptr
= *(void **)&cleanup_cb
;
1486 void *temp_function
= NULL
;
1487 memcached_return rc
;
1489 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
,
1491 assert(rc
== MEMCACHED_SUCCESS
);
1492 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1493 assert(temp_function
== cleanup_cb_ptr
);
1499 /* We don't test the behavior itself, we test the switches */
1500 static test_return
behavior_test(memcached_st
*memc
)
1505 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1506 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1509 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1510 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1513 set
= MEMCACHED_HASH_MD5
;
1514 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1515 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1516 assert(value
== MEMCACHED_HASH_MD5
);
1520 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1521 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1524 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1525 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1528 set
= MEMCACHED_HASH_DEFAULT
;
1529 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1530 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1531 assert(value
== MEMCACHED_HASH_DEFAULT
);
1533 set
= MEMCACHED_HASH_CRC
;
1534 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1535 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1536 assert(value
== MEMCACHED_HASH_CRC
);
1538 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1541 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1547 /* Test case provided by Cal Haldenbrand */
1548 static test_return
user_supplied_bug1(memcached_st
*memc
)
1550 unsigned int setter
= 1;
1553 unsigned long long total
= 0;
1556 char randomstuff
[6 * 1024];
1557 memcached_return rc
;
1559 memset(randomstuff
, 0, 6 * 1024);
1561 /* We just keep looking at the same values over and over */
1564 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1565 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1569 for (x
= 0 ; total
< 20 * 1024576 ; x
++ )
1573 size
= (rand() % ( 5 * 1024 ) ) + 400;
1574 memset(randomstuff
, 0, 6 * 1024);
1575 assert(size
< 6 * 1024); /* Being safe here */
1577 for (j
= 0 ; j
< size
;j
++)
1578 randomstuff
[j
] = (char) (rand() % 26) + 97;
1581 sprintf(key
, "%d", x
);
1582 rc
= memcached_set(memc
, key
, strlen(key
),
1583 randomstuff
, strlen(randomstuff
), 10, 0);
1584 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1585 /* If we fail, lets try again */
1586 if (rc
!= MEMCACHED_SUCCESS
&& rc
!= MEMCACHED_BUFFERED
)
1587 rc
= memcached_set(memc
, key
, strlen(key
),
1588 randomstuff
, strlen(randomstuff
), 10, 0);
1589 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1595 /* Test case provided by Cal Haldenbrand */
1596 static test_return
user_supplied_bug2(memcached_st
*memc
)
1599 unsigned int setter
;
1601 unsigned long long total
;
1604 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1605 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1607 setter
= 20 * 1024576;
1608 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1609 setter
= 20 * 1024576;
1610 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1611 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1612 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1614 for (x
= 0, errors
= 0, total
= 0 ; total
< 20 * 1024576 ; x
++)
1617 for (x
= 0, errors
= 0, total
= 0 ; total
< 24576 ; x
++)
1619 memcached_return rc
= MEMCACHED_SUCCESS
;
1620 char buffer
[SMALL_STRING_LEN
];
1625 memset(buffer
, 0, SMALL_STRING_LEN
);
1627 snprintf(buffer
, SMALL_STRING_LEN
, "%u", x
);
1628 getval
= memcached_get(memc
, buffer
, strlen(buffer
),
1629 &val_len
, &flags
, &rc
);
1630 if (rc
!= MEMCACHED_SUCCESS
)
1632 if (rc
== MEMCACHED_NOTFOUND
)
1636 WATCHPOINT_ERROR(rc
);
1650 /* Do a large mget() over all the keys we think exist */
1651 #define KEY_COUNT 3000 // * 1024576
1652 static test_return
user_supplied_bug3(memcached_st
*memc
)
1654 memcached_return rc
;
1655 unsigned int setter
;
1658 size_t key_lengths
[KEY_COUNT
];
1661 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1662 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1664 setter
= 20 * 1024576;
1665 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1666 setter
= 20 * 1024576;
1667 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1668 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1669 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1672 keys
= (char **)malloc(sizeof(char *) * KEY_COUNT
);
1674 memset(keys
, 0, (sizeof(char *) * KEY_COUNT
));
1675 for (x
= 0; x
< KEY_COUNT
; x
++)
1679 snprintf(buffer
, 30, "%u", x
);
1680 keys
[x
]= strdup(buffer
);
1681 key_lengths
[x
]= strlen(keys
[x
]);
1684 rc
= memcached_mget(memc
, keys
, key_lengths
, KEY_COUNT
);
1685 assert(rc
== MEMCACHED_SUCCESS
);
1687 /* Turn this into a help function */
1689 char return_key
[MEMCACHED_MAX_KEY
];
1690 size_t return_key_length
;
1692 size_t return_value_length
;
1695 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1696 &return_value_length
, &flags
, &rc
)))
1698 assert(return_value
);
1699 assert(rc
== MEMCACHED_SUCCESS
);
1704 for (x
= 0; x
< KEY_COUNT
; x
++)
1711 /* Make sure we behave properly if server list has no values */
1712 static test_return
user_supplied_bug4(memcached_st
*memc
)
1714 memcached_return rc
;
1715 char *keys
[]= {"fudge", "son", "food"};
1716 size_t key_length
[]= {5, 3, 4};
1719 char return_key
[MEMCACHED_MAX_KEY
];
1720 size_t return_key_length
;
1722 size_t return_value_length
;
1724 /* Here we free everything before running a bunch of mget tests */
1726 memcached_server_list_free(memc
->hosts
);
1728 memc
->number_of_hosts
= 0;
1732 /* We need to empty the server before continueing test */
1733 rc
= memcached_flush(memc
, 0);
1734 assert(rc
== MEMCACHED_NO_SERVERS
);
1736 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1737 assert(rc
== MEMCACHED_NO_SERVERS
);
1739 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1740 &return_value_length
, &flags
, &rc
)) != NULL
)
1742 assert(return_value
);
1744 assert(!return_value
);
1745 assert(return_value_length
== 0);
1746 assert(rc
== MEMCACHED_NO_SERVERS
);
1748 for (x
= 0; x
< 3; x
++)
1750 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1751 keys
[x
], key_length
[x
],
1752 (time_t)50, (uint32_t)9);
1753 assert(rc
== MEMCACHED_NO_SERVERS
);
1756 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1757 assert(rc
== MEMCACHED_NO_SERVERS
);
1760 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1761 &return_value_length
, &flags
, &rc
)))
1763 assert(return_value
);
1764 assert(rc
== MEMCACHED_SUCCESS
);
1765 assert(return_key_length
== return_value_length
);
1766 assert(!memcmp(return_value
, return_key
, return_value_length
));
1774 #define VALUE_SIZE_BUG5 1048064
1775 static test_return
user_supplied_bug5(memcached_st
*memc
)
1777 memcached_return rc
;
1778 char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1779 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1780 char return_key
[MEMCACHED_MAX_KEY
];
1781 size_t return_key_length
;
1783 size_t value_length
;
1787 char insert_data
[VALUE_SIZE_BUG5
];
1789 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1790 insert_data
[x
]= rand();
1792 memcached_flush(memc
, 0);
1793 value
= memcached_get(memc
, keys
[0], key_length
[0],
1794 &value_length
, &flags
, &rc
);
1795 assert(value
== NULL
);
1796 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1799 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1800 &value_length
, &flags
, &rc
)))
1804 for (x
= 0; x
< 4; x
++)
1806 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1807 insert_data
, VALUE_SIZE_BUG5
,
1808 (time_t)0, (uint32_t)0);
1809 assert(rc
== MEMCACHED_SUCCESS
);
1812 for (x
= 0; x
< 10; x
++)
1814 value
= memcached_get(memc
, keys
[0], key_length
[0],
1815 &value_length
, &flags
, &rc
);
1819 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1821 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1822 &value_length
, &flags
, &rc
)))
1833 static test_return
user_supplied_bug6(memcached_st
*memc
)
1835 memcached_return rc
;
1836 char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1837 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1838 char return_key
[MEMCACHED_MAX_KEY
];
1839 size_t return_key_length
;
1841 size_t value_length
;
1845 char insert_data
[VALUE_SIZE_BUG5
];
1847 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1848 insert_data
[x
]= rand();
1850 memcached_flush(memc
, 0);
1851 value
= memcached_get(memc
, keys
[0], key_length
[0],
1852 &value_length
, &flags
, &rc
);
1853 assert(value
== NULL
);
1854 assert(rc
== MEMCACHED_NOTFOUND
);
1855 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1856 assert(rc
== MEMCACHED_SUCCESS
);
1859 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1860 &value_length
, &flags
, &rc
)))
1863 assert(rc
== MEMCACHED_END
);
1865 for (x
= 0; x
< 4; x
++)
1867 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1868 insert_data
, VALUE_SIZE_BUG5
,
1869 (time_t)0, (uint32_t)0);
1870 assert(rc
== MEMCACHED_SUCCESS
);
1873 for (x
= 0; x
< 2; x
++)
1875 value
= memcached_get(memc
, keys
[0], key_length
[0],
1876 &value_length
, &flags
, &rc
);
1880 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1881 assert(rc
== MEMCACHED_SUCCESS
);
1883 /* We test for purge of partial complete fetches */
1884 for (count
= 3; count
; count
--)
1886 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1887 &value_length
, &flags
, &rc
);
1888 assert(rc
== MEMCACHED_SUCCESS
);
1889 assert(!(memcmp(value
, insert_data
, value_length
)));
1890 assert(value_length
);
1898 static test_return
user_supplied_bug8(memcached_st
*memc
__attribute__((unused
)))
1900 memcached_return rc
;
1902 memcached_st
*clone
;
1904 memcached_server_st
*servers
;
1905 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";
1907 servers
= memcached_servers_parse(server_list
);
1910 mine
= memcached_create(NULL
);
1911 rc
= memcached_server_push(mine
, servers
);
1912 assert(rc
== MEMCACHED_SUCCESS
);
1913 memcached_server_list_free(servers
);
1916 clone
= memcached_clone(NULL
, mine
);
1918 memcached_quit(mine
);
1919 memcached_quit(clone
);
1922 memcached_free(mine
);
1923 memcached_free(clone
);
1928 /* Test flag store/retrieve */
1929 static test_return
user_supplied_bug7(memcached_st
*memc
)
1931 memcached_return rc
;
1932 char *keys
= "036790384900";
1933 size_t key_length
= strlen("036790384900");
1934 char return_key
[MEMCACHED_MAX_KEY
];
1935 size_t return_key_length
;
1937 size_t value_length
;
1940 char insert_data
[VALUE_SIZE_BUG5
];
1942 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1943 insert_data
[x
]= rand();
1945 memcached_flush(memc
, 0);
1948 rc
= memcached_set(memc
, keys
, key_length
,
1949 insert_data
, VALUE_SIZE_BUG5
,
1951 assert(rc
== MEMCACHED_SUCCESS
);
1954 value
= memcached_get(memc
, keys
, key_length
,
1955 &value_length
, &flags
, &rc
);
1956 assert(flags
== 245);
1960 rc
= memcached_mget(memc
, &keys
, &key_length
, 1);
1963 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1964 &value_length
, &flags
, &rc
);
1965 assert(flags
== 245);
1973 static test_return
user_supplied_bug9(memcached_st
*memc
)
1975 memcached_return rc
;
1976 char *keys
[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
1977 size_t key_length
[3];
1982 char return_key
[MEMCACHED_MAX_KEY
];
1983 size_t return_key_length
;
1985 size_t return_value_length
;
1988 key_length
[0]= strlen("UDATA:edevil@sapo.pt");
1989 key_length
[1]= strlen("fudge&*@#");
1990 key_length
[2]= strlen("for^#@&$not");
1993 for (x
= 0; x
< 3; x
++)
1995 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1996 keys
[x
], key_length
[x
],
1997 (time_t)50, (uint32_t)9);
1998 assert(rc
== MEMCACHED_SUCCESS
);
2001 rc
= memcached_mget(memc
, keys
, key_length
, 3);
2002 assert(rc
== MEMCACHED_SUCCESS
);
2004 /* We need to empty the server before continueing test */
2005 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2006 &return_value_length
, &flags
, &rc
)) != NULL
)
2008 assert(return_value
);
2017 /* We are testing with aggressive timeout to get failures */
2018 static test_return
user_supplied_bug10(memcached_st
*memc
)
2022 size_t value_length
= 512;
2025 memcached_return rc
;
2026 unsigned int set
= 1;
2027 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2030 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2031 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2033 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
2035 value
= (char*)malloc(value_length
* sizeof(char));
2037 for (x
= 0; x
< value_length
; x
++)
2038 value
[x
]= (char) (x
% 127);
2040 for (x
= 1; x
<= 100000; ++x
)
2042 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2044 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_WRITE_FAILURE
||
2045 rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_TIMEOUT
);
2047 if (rc
== MEMCACHED_WRITE_FAILURE
|| rc
== MEMCACHED_TIMEOUT
)
2052 memcached_free(mclone
);
2058 We are looking failures in the async protocol
2060 static test_return
user_supplied_bug11(memcached_st
*memc
)
2064 size_t value_length
= 512;
2067 memcached_return rc
;
2068 unsigned int set
= 1;
2070 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2072 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2073 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2075 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
2077 timeout
= (int32_t)memcached_behavior_get(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
2079 assert(timeout
== -1);
2081 value
= (char*)malloc(value_length
* sizeof(char));
2083 for (x
= 0; x
< value_length
; x
++)
2084 value
[x
]= (char) (x
% 127);
2086 for (x
= 1; x
<= 100000; ++x
)
2088 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2092 memcached_free(mclone
);
2098 Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
2100 static test_return
user_supplied_bug12(memcached_st
*memc
)
2102 memcached_return rc
;
2104 size_t value_length
;
2106 uint64_t number_value
;
2108 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2109 &value_length
, &flags
, &rc
);
2110 assert(value
== NULL
);
2111 assert(rc
== MEMCACHED_NOTFOUND
);
2113 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2116 assert(value
== NULL
);
2117 /* The binary protocol will set the key if it doesn't exist */
2118 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1)
2119 assert(rc
== MEMCACHED_SUCCESS
);
2121 assert(rc
== MEMCACHED_NOTFOUND
);
2123 rc
= memcached_set(memc
, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
2125 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2126 &value_length
, &flags
, &rc
);
2128 assert(rc
== MEMCACHED_SUCCESS
);
2131 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2133 assert(number_value
== 2);
2134 assert(rc
== MEMCACHED_SUCCESS
);
2140 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2141 set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
2143 static test_return
user_supplied_bug13(memcached_st
*memc
)
2145 char key
[] = "key34567890";
2147 memcached_return rc
;
2148 size_t overflowSize
;
2150 char commandFirst
[]= "set key34567890 0 0 ";
2151 char commandLast
[] = " \r\n"; /* first line of command sent to server */
2152 size_t commandLength
;
2155 commandLength
= strlen(commandFirst
) + strlen(commandLast
) + 4; /* 4 is number of characters in size, probably 8196 */
2157 overflowSize
= MEMCACHED_MAX_BUFFER
- commandLength
;
2159 for (testSize
= overflowSize
- 1; testSize
< overflowSize
+ 1; testSize
++)
2161 overflow
= malloc(testSize
);
2162 assert(overflow
!= NULL
);
2164 memset(overflow
, 'x', testSize
);
2165 rc
= memcached_set(memc
, key
, strlen(key
),
2166 overflow
, testSize
, 0, 0);
2167 assert(rc
== MEMCACHED_SUCCESS
);
2176 Test values of many different sizes
2177 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2178 set key34567890 0 0 8169 \r\n
2179 is sent followed by buffer of size 8169, followed by 8169
2181 static test_return
user_supplied_bug14(memcached_st
*memc
)
2184 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2185 memcached_return rc
;
2188 size_t value_length
= 18000;
2190 size_t string_length
;
2193 size_t current_length
;
2195 value
= (char*)malloc(value_length
);
2198 for (x
= 0; x
< value_length
; x
++)
2199 value
[x
] = (char) (x
% 127);
2201 for (current_length
= 0; current_length
< value_length
; current_length
++)
2203 rc
= memcached_set(memc
, key
, strlen(key
),
2204 value
, current_length
,
2205 (time_t)0, (uint32_t)0);
2206 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
2208 string
= memcached_get(memc
, key
, strlen(key
),
2209 &string_length
, &flags
, &rc
);
2211 assert(rc
== MEMCACHED_SUCCESS
);
2212 assert(string_length
== current_length
);
2213 assert(!memcmp(string
, value
, string_length
));
2224 Look for zero length value problems
2226 static test_return
user_supplied_bug15(memcached_st
*memc
)
2229 memcached_return rc
;
2235 for (x
= 0; x
< 2; x
++)
2237 rc
= memcached_set(memc
, key
, strlen(key
),
2239 (time_t)0, (uint32_t)0);
2241 assert(rc
== MEMCACHED_SUCCESS
);
2243 value
= memcached_get(memc
, key
, strlen(key
),
2244 &length
, &flags
, &rc
);
2246 assert(rc
== MEMCACHED_SUCCESS
);
2247 assert(value
== NULL
);
2248 assert(length
== 0);
2251 value
= memcached_get(memc
, key
, strlen(key
),
2252 &length
, &flags
, &rc
);
2254 assert(rc
== MEMCACHED_SUCCESS
);
2255 assert(value
== NULL
);
2256 assert(length
== 0);
2263 /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
2264 static test_return
user_supplied_bug16(memcached_st
*memc
)
2266 memcached_return rc
;
2272 rc
= memcached_set(memc
, key
, strlen(key
),
2274 (time_t)0, UINT32_MAX
);
2276 assert(rc
== MEMCACHED_SUCCESS
);
2278 value
= memcached_get(memc
, key
, strlen(key
),
2279 &length
, &flags
, &rc
);
2281 assert(rc
== MEMCACHED_SUCCESS
);
2282 assert(value
== NULL
);
2283 assert(length
== 0);
2284 assert(flags
== UINT32_MAX
);
2289 /* Check the validity of chinese key*/
2290 static test_return
user_supplied_bug17(memcached_st
*memc
)
2292 memcached_return rc
;
2294 char *value
="我们在炎热抑郁的夏天无法停止豆瓣";
2299 rc
= memcached_set(memc
, key
, strlen(key
),
2300 value
, strlen(value
),
2303 assert(rc
== MEMCACHED_SUCCESS
);
2305 value2
= memcached_get(memc
, key
, strlen(key
),
2306 &length
, &flags
, &rc
);
2308 assert(length
==strlen(value
));
2309 assert(rc
== MEMCACHED_SUCCESS
);
2310 assert(memcmp(value
, value2
, length
)==0);
2320 static test_return
user_supplied_bug19(memcached_st
*memc
)
2323 memcached_server_st
*s
;
2324 memcached_return res
;
2328 m
= memcached_create(NULL
);
2329 memcached_server_add_with_weight(m
, "localhost", 11311, 100);
2330 memcached_server_add_with_weight(m
, "localhost", 11312, 100);
2332 s
= memcached_server_by_key(m
, "a", 1, &res
);
2333 memcached_server_free(s
);
2340 /* CAS test from Andei */
2341 static test_return
user_supplied_bug20(memcached_st
*memc
)
2343 memcached_return status
;
2344 memcached_result_st
*result
, result_obj
;
2346 size_t key_len
= strlen("abc");
2347 char *value
= "foobar";
2348 size_t value_len
= strlen(value
);
2350 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
2352 status
= memcached_set(memc
, key
, key_len
, value
, value_len
, (time_t)0, (uint32_t)0);
2353 assert(status
== MEMCACHED_SUCCESS
);
2355 status
= memcached_mget(memc
, &key
, &key_len
, 1);
2356 assert(status
== MEMCACHED_SUCCESS
);
2358 result
= memcached_result_create(memc
, &result_obj
);
2361 memcached_result_create(memc
, &result_obj
);
2362 result
= memcached_fetch_result(memc
, &result_obj
, &status
);
2365 assert(status
== MEMCACHED_SUCCESS
);
2367 memcached_result_free(result
);
2372 #include "ketama_test_cases.h"
2373 static test_return
user_supplied_bug18(memcached_st
*trash
)
2375 memcached_return rc
;
2378 memcached_server_st
*server_pool
;
2383 memc
= memcached_create(NULL
);
2386 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2387 assert(rc
== MEMCACHED_SUCCESS
);
2389 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2392 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2393 assert(rc
== MEMCACHED_SUCCESS
);
2395 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2396 assert(value
== MEMCACHED_HASH_MD5
);
2398 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");
2399 memcached_server_push(memc
, server_pool
);
2401 /* verify that the server list was parsed okay. */
2402 assert(memc
->number_of_hosts
== 8);
2403 assert(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
2404 assert(server_pool
[0].port
== 11211);
2405 assert(server_pool
[0].weight
== 600);
2406 assert(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
2407 assert(server_pool
[2].port
== 11211);
2408 assert(server_pool
[2].weight
== 200);
2409 assert(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
2410 assert(server_pool
[7].port
== 11211);
2411 assert(server_pool
[7].weight
== 100);
2413 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
2414 * us test the boundary wraparound.
2416 assert(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
2418 /* verify the standard ketama set. */
2419 for (x
= 0; x
< 99; x
++)
2421 uint32_t server_idx
= memcached_generate_hash(memc
, test_cases
[x
].key
, strlen(test_cases
[x
].key
));
2422 char *hostname
= memc
->hosts
[server_idx
].hostname
;
2423 assert(strcmp(hostname
, test_cases
[x
].server
) == 0);
2426 memcached_server_list_free(server_pool
);
2427 memcached_free(memc
);
2432 static test_return
auto_eject_hosts(memcached_st
*trash
)
2436 memcached_return rc
;
2437 memcached_st
*memc
= memcached_create(NULL
);
2440 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2441 assert(rc
== MEMCACHED_SUCCESS
);
2443 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2446 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2447 assert(rc
== MEMCACHED_SUCCESS
);
2449 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2450 assert(value
== MEMCACHED_HASH_MD5
);
2452 /* server should be removed when in delay */
2453 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
, 1);
2454 assert(rc
== MEMCACHED_SUCCESS
);
2456 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
);
2459 memcached_server_st
*server_pool
;
2460 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");
2461 memcached_server_push(memc
, server_pool
);
2463 /* verify that the server list was parsed okay. */
2464 assert(memc
->number_of_hosts
== 8);
2465 assert(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
2466 assert(server_pool
[0].port
== 11211);
2467 assert(server_pool
[0].weight
== 600);
2468 assert(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
2469 assert(server_pool
[2].port
== 11211);
2470 assert(server_pool
[2].weight
== 200);
2471 assert(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
2472 assert(server_pool
[7].port
== 11211);
2473 assert(server_pool
[7].weight
== 100);
2475 memc
->hosts
[2].next_retry
= time(NULL
) + 15;
2476 memc
->next_distribution_rebuild
= time(NULL
) - 1;
2478 for (int x
= 0; x
< 99; x
++)
2480 uint32_t server_idx
= memcached_generate_hash(memc
, test_cases
[x
].key
, strlen(test_cases
[x
].key
));
2481 assert(server_idx
!= 2);
2484 /* and re-added when it's back. */
2485 memc
->hosts
[2].next_retry
= time(NULL
) - 1;
2486 memc
->next_distribution_rebuild
= time(NULL
) - 1;
2487 run_distribution(memc
);
2488 for (int x
= 0; x
< 99; x
++)
2490 uint32_t server_idx
= memcached_generate_hash(memc
, test_cases
[x
].key
, strlen(test_cases
[x
].key
));
2491 char *hostname
= memc
->hosts
[server_idx
].hostname
;
2492 assert(strcmp(hostname
, test_cases
[x
].server
) == 0);
2495 memcached_server_list_free(server_pool
);
2496 memcached_free(memc
);
2498 return TEST_SUCCESS
;
2501 static test_return
result_static(memcached_st
*memc
)
2503 memcached_result_st result
;
2504 memcached_result_st
*result_ptr
;
2506 result_ptr
= memcached_result_create(memc
, &result
);
2507 assert(result
.is_allocated
== false);
2509 memcached_result_free(&result
);
2514 static test_return
result_alloc(memcached_st
*memc
)
2516 memcached_result_st
*result
;
2518 result
= memcached_result_create(memc
, NULL
);
2520 memcached_result_free(result
);
2525 static test_return
string_static_null(memcached_st
*memc
)
2527 memcached_string_st string
;
2528 memcached_string_st
*string_ptr
;
2530 string_ptr
= memcached_string_create(memc
, &string
, 0);
2531 assert(string
.is_allocated
== false);
2533 memcached_string_free(&string
);
2538 static test_return
string_alloc_null(memcached_st
*memc
)
2540 memcached_string_st
*string
;
2542 string
= memcached_string_create(memc
, NULL
, 0);
2544 memcached_string_free(string
);
2549 static test_return
string_alloc_with_size(memcached_st
*memc
)
2551 memcached_string_st
*string
;
2553 string
= memcached_string_create(memc
, NULL
, 1024);
2555 memcached_string_free(string
);
2560 static test_return
string_alloc_with_size_toobig(memcached_st
*memc
)
2562 memcached_string_st
*string
;
2564 string
= memcached_string_create(memc
, NULL
, SIZE_MAX
);
2565 assert(string
== NULL
);
2570 static test_return
string_alloc_append(memcached_st
*memc
)
2573 char buffer
[SMALL_STRING_LEN
];
2574 memcached_string_st
*string
;
2576 /* Ring the bell! */
2577 memset(buffer
, 6, SMALL_STRING_LEN
);
2579 string
= memcached_string_create(memc
, NULL
, 100);
2582 for (x
= 0; x
< 1024; x
++)
2584 memcached_return rc
;
2585 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
2586 assert(rc
== MEMCACHED_SUCCESS
);
2588 memcached_string_free(string
);
2593 static test_return
string_alloc_append_toobig(memcached_st
*memc
)
2595 memcached_return rc
;
2597 char buffer
[SMALL_STRING_LEN
];
2598 memcached_string_st
*string
;
2600 /* Ring the bell! */
2601 memset(buffer
, 6, SMALL_STRING_LEN
);
2603 string
= memcached_string_create(memc
, NULL
, 100);
2606 for (x
= 0; x
< 1024; x
++)
2608 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
2609 assert(rc
== MEMCACHED_SUCCESS
);
2611 rc
= memcached_string_append(string
, buffer
, SIZE_MAX
);
2612 assert(rc
== MEMCACHED_MEMORY_ALLOCATION_FAILURE
);
2613 memcached_string_free(string
);
2618 static test_return
cleanup_pairs(memcached_st
*memc
__attribute__((unused
)))
2620 pairs_free(global_pairs
);
2625 static test_return
generate_pairs(memcached_st
*memc
__attribute__((unused
)))
2627 unsigned long long x
;
2628 global_pairs
= pairs_generate(GLOBAL_COUNT
, 400);
2629 global_count
= GLOBAL_COUNT
;
2631 for (x
= 0; x
< global_count
; x
++)
2633 global_keys
[x
]= global_pairs
[x
].key
;
2634 global_keys_length
[x
]= global_pairs
[x
].key_length
;
2640 static test_return
generate_large_pairs(memcached_st
*memc
__attribute__((unused
)))
2642 unsigned long long x
;
2643 global_pairs
= pairs_generate(GLOBAL2_COUNT
, MEMCACHED_MAX_BUFFER
+10);
2644 global_count
= GLOBAL2_COUNT
;
2646 for (x
= 0; x
< global_count
; x
++)
2648 global_keys
[x
]= global_pairs
[x
].key
;
2649 global_keys_length
[x
]= global_pairs
[x
].key_length
;
2655 static test_return
generate_data(memcached_st
*memc
)
2657 execute_set(memc
, global_pairs
, global_count
);
2662 static test_return
generate_data_with_stats(memcached_st
*memc
)
2664 memcached_stat_st
*stat_p
;
2665 memcached_return rc
;
2666 uint32_t host_index
= 0;
2667 execute_set(memc
, global_pairs
, global_count
);
2669 //TODO: hosts used size stats
2670 stat_p
= memcached_stat(memc
, NULL
, &rc
);
2673 for (host_index
= 0; host_index
< SERVERS_TO_CREATE
; host_index
++)
2675 /* This test was changes so that "make test" would work properlly */
2677 printf("\nserver %u|%s|%u bytes: %llu\n", host_index
, (memc
->hosts
)[host_index
].hostname
, (memc
->hosts
)[host_index
].port
, (unsigned long long)(stat_p
+ host_index
)->bytes
);
2679 assert((unsigned long long)(stat_p
+ host_index
)->bytes
);
2682 memcached_stat_free(NULL
, stat_p
);
2686 static test_return
generate_buffer_data(memcached_st
*memc
)
2691 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
2692 generate_data(memc
);
2697 static test_return
get_read_count(memcached_st
*memc
)
2700 memcached_return rc
;
2701 memcached_st
*clone
;
2703 clone
= memcached_clone(NULL
, memc
);
2706 memcached_server_add_with_weight(clone
, "localhost", 6666, 0);
2710 size_t return_value_length
;
2714 for (x
= count
= 0; x
< global_count
; x
++)
2716 return_value
= memcached_get(clone
, global_keys
[x
], global_keys_length
[x
],
2717 &return_value_length
, &flags
, &rc
);
2718 if (rc
== MEMCACHED_SUCCESS
)
2725 fprintf(stderr
, "\t%u -> %u", global_count
, count
);
2728 memcached_free(clone
);
2733 static test_return
get_read(memcached_st
*memc
)
2736 memcached_return rc
;
2740 size_t return_value_length
;
2743 for (x
= 0; x
< global_count
; x
++)
2745 return_value
= memcached_get(memc
, global_keys
[x
], global_keys_length
[x
],
2746 &return_value_length
, &flags
, &rc
);
2748 assert(return_value);
2749 assert(rc == MEMCACHED_SUCCESS);
2751 if (rc
== MEMCACHED_SUCCESS
&& return_value
)
2759 static test_return
mget_read(memcached_st
*memc
)
2761 memcached_return rc
;
2763 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2764 assert(rc
== MEMCACHED_SUCCESS
);
2765 /* Turn this into a help function */
2767 char return_key
[MEMCACHED_MAX_KEY
];
2768 size_t return_key_length
;
2770 size_t return_value_length
;
2773 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2774 &return_value_length
, &flags
, &rc
)))
2776 assert(return_value
);
2777 assert(rc
== MEMCACHED_SUCCESS
);
2785 static test_return
mget_read_result(memcached_st
*memc
)
2787 memcached_return rc
;
2789 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2790 assert(rc
== MEMCACHED_SUCCESS
);
2791 /* Turn this into a help function */
2793 memcached_result_st results_obj
;
2794 memcached_result_st
*results
;
2796 results
= memcached_result_create(memc
, &results_obj
);
2798 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
2801 assert(rc
== MEMCACHED_SUCCESS
);
2804 memcached_result_free(&results_obj
);
2810 static test_return
mget_read_function(memcached_st
*memc
)
2812 memcached_return rc
;
2813 unsigned int counter
;
2814 memcached_execute_function callbacks
[1];
2816 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2817 assert(rc
== MEMCACHED_SUCCESS
);
2819 callbacks
[0]= &callback_counter
;
2821 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
2826 static test_return
delete_generate(memcached_st
*memc
)
2830 for (x
= 0; x
< global_count
; x
++)
2832 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
2838 static test_return
delete_buffer_generate(memcached_st
*memc
)
2844 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
2846 for (x
= 0; x
< global_count
; x
++)
2848 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
2854 static test_return
add_host_test1(memcached_st
*memc
)
2857 memcached_return rc
;
2858 char servername
[]= "0.example.com";
2859 memcached_server_st
*servers
;
2861 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
2863 assert(1 == memcached_server_list_count(servers
));
2865 for (x
= 2; x
< 20; x
++)
2867 char buffer
[SMALL_STRING_LEN
];
2869 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
2870 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
2872 assert(rc
== MEMCACHED_SUCCESS
);
2873 assert(x
== memcached_server_list_count(servers
));
2876 rc
= memcached_server_push(memc
, servers
);
2877 assert(rc
== MEMCACHED_SUCCESS
);
2878 rc
= memcached_server_push(memc
, servers
);
2879 assert(rc
== MEMCACHED_SUCCESS
);
2881 memcached_server_list_free(servers
);
2886 static memcached_return
pre_nonblock(memcached_st
*memc
)
2888 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
2890 return MEMCACHED_SUCCESS
;
2893 static memcached_return
pre_nonblock_binary(memcached_st
*memc
)
2895 memcached_return rc
= MEMCACHED_FAILURE
;
2896 memcached_st
*clone
;
2898 clone
= memcached_clone(NULL
, memc
);
2900 // The memcached_version needs to be done on a clone, because the server
2901 // will not toggle protocol on an connection.
2902 memcached_version(clone
);
2904 if (clone
->hosts
[0].major_version
>= 1 && clone
->hosts
[0].minor_version
> 2)
2906 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
2907 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
2908 assert(rc
== MEMCACHED_SUCCESS
);
2909 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
2912 memcached_free(clone
);
2916 static memcached_return
pre_murmur(memcached_st
*memc
)
2918 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
2920 return MEMCACHED_SUCCESS
;
2923 static memcached_return
pre_jenkins(memcached_st
*memc
)
2925 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_JENKINS
);
2927 return MEMCACHED_SUCCESS
;
2931 static memcached_return
pre_md5(memcached_st
*memc
)
2933 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MD5
);
2935 return MEMCACHED_SUCCESS
;
2938 static memcached_return
pre_crc(memcached_st
*memc
)
2940 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_CRC
);
2942 return MEMCACHED_SUCCESS
;
2945 static memcached_return
pre_hsieh(memcached_st
*memc
)
2947 #ifdef HAVE_HSIEH_HASH
2948 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_HSIEH
);
2949 return MEMCACHED_SUCCESS
;
2952 return MEMCACHED_FAILURE
;
2956 static memcached_return
pre_hash_fnv1_64(memcached_st
*memc
)
2958 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_64
);
2960 return MEMCACHED_SUCCESS
;
2963 static memcached_return
pre_hash_fnv1a_64(memcached_st
*memc
)
2965 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_64
);
2967 return MEMCACHED_SUCCESS
;
2970 static memcached_return
pre_hash_fnv1_32(memcached_st
*memc
)
2972 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_32
);
2974 return MEMCACHED_SUCCESS
;
2977 static memcached_return
pre_hash_fnv1a_32(memcached_st
*memc
)
2979 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_32
);
2981 return MEMCACHED_SUCCESS
;
2984 static memcached_return
pre_behavior_ketama(memcached_st
*memc
)
2986 memcached_return rc
;
2989 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA
, 1);
2990 assert(rc
== MEMCACHED_SUCCESS
);
2992 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA
);
2995 return MEMCACHED_SUCCESS
;
2998 static memcached_return
pre_behavior_ketama_weighted(memcached_st
*memc
)
3000 memcached_return rc
;
3003 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
3004 assert(rc
== MEMCACHED_SUCCESS
);
3006 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
3009 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
3010 assert(rc
== MEMCACHED_SUCCESS
);
3012 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
3013 assert(value
== MEMCACHED_HASH_MD5
);
3014 return MEMCACHED_SUCCESS
;
3017 static memcached_return
pre_binary(memcached_st
*memc
)
3019 memcached_return rc
= MEMCACHED_FAILURE
;
3020 memcached_st
*clone
;
3022 clone
= memcached_clone(NULL
, memc
);
3024 // The memcached_version needs to be done on a clone, because the server
3025 // will not toggle protocol on an connection.
3026 memcached_version(clone
);
3028 if (clone
->hosts
[0].major_version
>= 1 && clone
->hosts
[0].minor_version
> 2)
3030 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3031 assert(rc
== MEMCACHED_SUCCESS
);
3032 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3035 memcached_free(clone
);
3039 static void my_free(memcached_st
*ptr
__attribute__((unused
)), void *mem
)
3044 static void *my_malloc(memcached_st
*ptr
__attribute__((unused
)), const size_t size
)
3046 void *ret
= malloc(size
);
3048 memset(ret
, 0xff, size
);
3053 static void *my_realloc(memcached_st
*ptr
__attribute__((unused
)), void *mem
, const size_t size
)
3055 return realloc(mem
, size
);
3058 static void *my_calloc(memcached_st
*ptr
__attribute__((unused
)), size_t nelem
, const size_t size
)
3060 return calloc(nelem
, size
);
3063 static memcached_return
set_prefix(memcached_st
*memc
)
3065 memcached_return rc
;
3066 const char *key
= "mine";
3069 /* Make sure be default none exists */
3070 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3071 assert(rc
== MEMCACHED_FAILURE
);
3073 /* Test a clean set */
3074 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3075 assert(rc
== MEMCACHED_SUCCESS
);
3077 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3078 assert(memcmp(value
, key
, 4) == 0);
3079 assert(rc
== MEMCACHED_SUCCESS
);
3081 /* Test that we can turn it off */
3082 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3083 assert(rc
== MEMCACHED_SUCCESS
);
3085 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3086 assert(rc
== MEMCACHED_FAILURE
);
3088 /* Now setup for main test */
3089 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3090 assert(rc
== MEMCACHED_SUCCESS
);
3092 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3093 assert(rc
== MEMCACHED_SUCCESS
);
3094 assert(memcmp(value
, key
, 4) == 0);
3096 /* Set to Zero, and then Set to something too large */
3099 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3100 assert(rc
== MEMCACHED_SUCCESS
);
3102 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3103 assert(rc
== MEMCACHED_FAILURE
);
3104 assert(value
== NULL
);
3106 /* Test a long key for failure */
3107 /* TODO, extend test to determine based on setting, what result should be */
3108 long_key
= "Thisismorethentheallottednumberofcharacters";
3109 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3110 //assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
3111 assert(rc
== MEMCACHED_SUCCESS
);
3113 /* Now test a key with spaces (which will fail from long key, since bad key is not set) */
3114 long_key
= "This is more then the allotted number of characters";
3115 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3116 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3118 /* Test for a bad prefix, but with a short key */
3119 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, 1);
3120 assert(rc
== MEMCACHED_SUCCESS
);
3122 long_key
= "dog cat";
3123 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3124 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3127 return MEMCACHED_SUCCESS
;
3130 static memcached_return
deprecated_set_memory_alloc(memcached_st
*memc
)
3132 void *test_ptr
= NULL
;
3135 memcached_malloc_function malloc_cb
=
3136 (memcached_malloc_function
)my_malloc
;
3137 cb_ptr
= *(void **)&malloc_cb
;
3138 memcached_return rc
;
3140 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, cb_ptr
);
3141 assert(rc
== MEMCACHED_SUCCESS
);
3142 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
3143 assert(rc
== MEMCACHED_SUCCESS
);
3144 assert(test_ptr
== cb_ptr
);
3148 memcached_realloc_function realloc_cb
=
3149 (memcached_realloc_function
)my_realloc
;
3150 cb_ptr
= *(void **)&realloc_cb
;
3151 memcached_return rc
;
3153 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, cb_ptr
);
3154 assert(rc
== MEMCACHED_SUCCESS
);
3155 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
3156 assert(rc
== MEMCACHED_SUCCESS
);
3157 assert(test_ptr
== cb_ptr
);
3161 memcached_free_function free_cb
=
3162 (memcached_free_function
)my_free
;
3163 cb_ptr
= *(void **)&free_cb
;
3164 memcached_return rc
;
3166 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, cb_ptr
);
3167 assert(rc
== MEMCACHED_SUCCESS
);
3168 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
3169 assert(rc
== MEMCACHED_SUCCESS
);
3170 assert(test_ptr
== cb_ptr
);
3172 return MEMCACHED_SUCCESS
;
3175 static memcached_return
set_memory_alloc(memcached_st
*memc
)
3177 memcached_return rc
;
3178 rc
= memcached_set_memory_allocators(memc
, NULL
, my_free
,
3179 my_realloc
, my_calloc
);
3180 assert(rc
== MEMCACHED_FAILURE
);
3182 rc
= memcached_set_memory_allocators(memc
, my_malloc
, my_free
,
3183 my_realloc
, my_calloc
);
3185 memcached_malloc_function mem_malloc
;
3186 memcached_free_function mem_free
;
3187 memcached_realloc_function mem_realloc
;
3188 memcached_calloc_function mem_calloc
;
3189 memcached_get_memory_allocators(memc
, &mem_malloc
, &mem_free
,
3190 &mem_realloc
, &mem_calloc
);
3192 assert(mem_malloc
== my_malloc
);
3193 assert(mem_realloc
== my_realloc
);
3194 assert(mem_calloc
== my_calloc
);
3195 assert(mem_free
== my_free
);
3197 return MEMCACHED_SUCCESS
;
3200 static memcached_return
enable_consistent(memcached_st
*memc
)
3202 memcached_server_distribution value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
3203 memcached_hash hash
;
3204 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
3205 if (pre_hsieh(memc
) != MEMCACHED_SUCCESS
)
3206 return MEMCACHED_FAILURE
;
3208 value
= (memcached_server_distribution
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
3209 assert(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
3211 hash
= (memcached_hash
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
3212 assert(hash
== MEMCACHED_HASH_HSIEH
);
3215 return MEMCACHED_SUCCESS
;
3218 static memcached_return
enable_cas(memcached_st
*memc
)
3220 unsigned int set
= 1;
3222 memcached_version(memc
);
3224 if ((memc
->hosts
[0].major_version
>= 1 && (memc
->hosts
[0].minor_version
== 2 && memc
->hosts
[0].micro_version
>= 4))
3225 || memc
->hosts
[0].minor_version
> 2)
3227 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
3229 return MEMCACHED_SUCCESS
;
3232 return MEMCACHED_FAILURE
;
3235 static memcached_return
check_for_1_2_3(memcached_st
*memc
)
3237 memcached_version(memc
);
3239 if ((memc
->hosts
[0].major_version
>= 1 && (memc
->hosts
[0].minor_version
== 2 && memc
->hosts
[0].micro_version
>= 4))
3240 || memc
->hosts
[0].minor_version
> 2)
3241 return MEMCACHED_SUCCESS
;
3243 return MEMCACHED_FAILURE
;
3246 static memcached_return
pre_unix_socket(memcached_st
*memc
)
3248 memcached_return rc
;
3251 memcached_server_list_free(memc
->hosts
);
3253 memc
->number_of_hosts
= 0;
3255 if (stat("/tmp/memcached.socket", &buf
))
3256 return MEMCACHED_FAILURE
;
3258 rc
= memcached_server_add_unix_socket_with_weight(memc
, "/tmp/memcached.socket", 0);
3263 static memcached_return
pre_nodelay(memcached_st
*memc
)
3265 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3266 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
3268 return MEMCACHED_SUCCESS
;
3271 static memcached_return
pre_settimer(memcached_st
*memc
)
3273 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
3274 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
3276 return MEMCACHED_SUCCESS
;
3279 static memcached_return
poll_timeout(memcached_st
*memc
)
3285 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
3287 timeout
= (int32_t)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
3289 assert(timeout
== 100);
3291 return MEMCACHED_SUCCESS
;
3294 static test_return
noreply_test(memcached_st
*memc
)
3296 memcached_return ret
;
3297 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
3298 assert(ret
== MEMCACHED_SUCCESS
);
3299 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
3300 assert(ret
== MEMCACHED_SUCCESS
);
3301 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
3302 assert(ret
== MEMCACHED_SUCCESS
);
3303 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NOREPLY
) == 1);
3304 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
) == 1);
3305 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
) == 1);
3307 for (int count
=0; count
< 5; ++count
)
3309 for (int x
=0; x
< 100; ++x
)
3312 size_t len
= sprintf(key
, "%d", x
);
3316 ret
=memcached_add(memc
, key
, len
, key
, len
, 0, 0);
3319 ret
=memcached_replace(memc
, key
, len
, key
, len
, 0, 0);
3322 ret
=memcached_set(memc
, key
, len
, key
, len
, 0, 0);
3325 ret
=memcached_append(memc
, key
, len
, key
, len
, 0, 0);
3328 ret
=memcached_prepend(memc
, key
, len
, key
, len
, 0, 0);
3331 assert(ret
== MEMCACHED_SUCCESS
|| ret
== MEMCACHED_BUFFERED
);
3335 ** NOTE: Don't ever do this in your code! this is not a supported use of the
3336 ** API and is _ONLY_ done this way to verify that the library works the
3337 ** way it is supposed to do!!!!
3340 for (uint32_t x
=0; x
< memc
->number_of_hosts
; ++x
)
3341 no_msg
+=memc
->hosts
[x
].cursor_active
;
3343 assert(no_msg
== 0);
3344 assert(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
3347 ** Now validate that all items was set properly!
3349 for (int x
=0; x
< 100; ++x
)
3352 size_t len
= sprintf(key
, "%d", x
);
3355 char* value
=memcached_get(memc
, key
, strlen(key
),
3356 &length
, &flags
, &ret
);
3357 assert(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
3360 case 0: /* FALLTHROUGH */
3361 case 1: /* FALLTHROUGH */
3363 assert(strncmp(value
, key
, len
) == 0);
3364 assert(len
== length
);
3367 assert(length
== len
* 2);
3370 assert(length
== len
* 3);
3377 /* Try setting an illegal cas value (should not return an error to
3378 * the caller (because we don't expect a return message from the server)
3380 char* keys
[]= {"0"};
3381 size_t lengths
[]= {1};
3384 memcached_result_st results_obj
;
3385 memcached_result_st
*results
;
3386 ret
= memcached_mget(memc
, keys
, lengths
, 1);
3387 assert(ret
== MEMCACHED_SUCCESS
);
3389 results
= memcached_result_create(memc
, &results_obj
);
3391 results
= memcached_fetch_result(memc
, &results_obj
, &ret
);
3393 assert(ret
== MEMCACHED_SUCCESS
);
3394 uint64_t cas
= memcached_result_cas(results
);
3395 memcached_result_free(&results_obj
);
3397 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
3398 assert(ret
== MEMCACHED_SUCCESS
);
3401 * The item will have a new cas value, so try to set it again with the old
3402 * value. This should fail!
3404 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
3405 assert(ret
== MEMCACHED_SUCCESS
);
3406 assert(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
3407 char* value
=memcached_get(memc
, keys
[0], lengths
[0], &length
, &flags
, &ret
);
3408 assert(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
3411 return TEST_SUCCESS
;
3414 static test_return
analyzer_test(memcached_st
*memc
)
3416 memcached_return rc
;
3417 memcached_stat_st
*stat
;
3418 memcached_analysis_st
*report
;
3420 stat
= memcached_stat(memc
, NULL
, &rc
);
3421 assert(rc
== MEMCACHED_SUCCESS
);
3424 report
= memcached_analyze(memc
, stat
, &rc
);
3425 assert(rc
== MEMCACHED_SUCCESS
);
3429 memcached_stat_free(NULL
, stat
);
3431 return TEST_SUCCESS
;
3434 /* Count the objects */
3435 static memcached_return
callback_dump_counter(memcached_st
*ptr
__attribute__((unused
)),
3436 const char *key
__attribute__((unused
)),
3437 size_t key_length
__attribute__((unused
)),
3440 uint32_t *counter
= (uint32_t *)context
;
3442 *counter
= *counter
+ 1;
3444 return MEMCACHED_SUCCESS
;
3447 static test_return
dump_test(memcached_st
*memc
)
3449 memcached_return rc
;
3450 uint32_t counter
= 0;
3451 memcached_dump_func callbacks
[1];
3452 test_return main_rc
;
3454 callbacks
[0]= &callback_dump_counter
;
3456 /* No support for Binary protocol yet */
3457 if (memc
->flags
& MEM_BINARY_PROTOCOL
)
3458 return TEST_SUCCESS
;
3460 main_rc
= set_test3(memc
);
3462 assert (main_rc
== TEST_SUCCESS
);
3464 rc
= memcached_dump(memc
, callbacks
, (void *)&counter
, 1);
3465 assert(rc
== MEMCACHED_SUCCESS
);
3467 /* We may have more then 32 if our previous flush has not completed */
3468 assert(counter
>= 32);
3470 return TEST_SUCCESS
;
3473 #ifdef HAVE_LIBMEMCACHEDUTIL
3474 static void* connection_release(void *arg
) {
3476 memcached_pool_st
* pool
;
3481 assert(memcached_pool_push(resource
->pool
, resource
->mmc
) == MEMCACHED_SUCCESS
);
3485 static test_return
connection_pool_test(memcached_st
*memc
)
3487 memcached_pool_st
* pool
= memcached_pool_create(memc
, 5, 10);
3488 assert(pool
!= NULL
);
3489 memcached_st
* mmc
[10];
3490 memcached_return rc
;
3492 for (int x
= 0; x
< 10; ++x
) {
3493 mmc
[x
]= memcached_pool_pop(pool
, false, &rc
);
3494 assert(mmc
[x
] != NULL
);
3495 assert(rc
== MEMCACHED_SUCCESS
);
3498 assert(memcached_pool_pop(pool
, false, &rc
) == NULL
);
3499 assert(rc
== MEMCACHED_SUCCESS
);
3503 memcached_pool_st
* pool
;
3505 } item
= { .pool
= pool
, .mmc
= mmc
[9] };
3506 pthread_create(&tid
, NULL
, connection_release
, &item
);
3507 mmc
[9]= memcached_pool_pop(pool
, true, &rc
);
3508 assert(rc
== MEMCACHED_SUCCESS
);
3509 pthread_join(tid
, NULL
);
3510 assert(mmc
[9] == item
.mmc
);
3511 const char *key
= "key";
3512 size_t keylen
= strlen(key
);
3514 // verify that I can do ops with all connections
3515 rc
= memcached_set(mmc
[0], key
, keylen
, "0", 1, 0, 0);
3516 assert(rc
== MEMCACHED_SUCCESS
);
3518 for (unsigned int x
= 0; x
< 10; ++x
) {
3519 uint64_t number_value
;
3520 rc
= memcached_increment(mmc
[x
], key
, keylen
, 1, &number_value
);
3521 assert(rc
== MEMCACHED_SUCCESS
);
3522 assert(number_value
== (x
+1));
3526 for (int x
= 0; x
< 10; ++x
)
3527 assert(memcached_pool_push(pool
, mmc
[x
]) == MEMCACHED_SUCCESS
);
3529 assert(memcached_pool_destroy(pool
) == memc
);
3530 return TEST_SUCCESS
;
3534 static void increment_request_id(uint16_t *id
)
3537 if ((*id
& UDP_REQUEST_ID_THREAD_MASK
) != 0)
3541 static uint16_t *get_udp_request_ids(memcached_st
*memc
)
3543 uint16_t *ids
= malloc(sizeof(uint16_t) * memc
->number_of_hosts
);
3544 assert(ids
!= NULL
);
3546 for (x
= 0; x
< memc
->number_of_hosts
; x
++)
3547 ids
[x
]= get_udp_datagram_request_id((struct udp_datagram_header_st
*) memc
->hosts
[x
].write_buffer
);
3552 static test_return
post_udp_op_check(memcached_st
*memc
, uint16_t *expected_req_ids
)
3555 memcached_server_st
*cur_server
= memc
->hosts
;
3556 uint16_t *cur_req_ids
= get_udp_request_ids(memc
);
3557 for (x
= 0; x
< memc
->number_of_hosts
; x
++)
3559 assert(cur_server
[x
].cursor_active
== 0);
3560 assert(cur_req_ids
[x
] == expected_req_ids
[x
]);
3562 free(expected_req_ids
);
3564 return TEST_SUCCESS
;
3568 ** There is a little bit of a hack here, instead of removing
3569 ** the servers, I just set num host to 0 and them add then new udp servers
3571 static memcached_return
init_udp(memcached_st
*memc
)
3573 memcached_version(memc
);
3574 /* For the time being, only support udp test for >= 1.2.6 && < 1.3 */
3575 if (memc
->hosts
[0].major_version
!= 1 || memc
->hosts
[0].minor_version
!= 2
3576 || memc
->hosts
[0].micro_version
< 6)
3577 return MEMCACHED_FAILURE
;
3579 uint32_t num_hosts
= memc
->number_of_hosts
;
3581 memcached_server_st servers
[num_hosts
];
3582 memcpy(servers
, memc
->hosts
, sizeof(memcached_server_st
) * num_hosts
);
3583 for (x
= 0; x
< num_hosts
; x
++)
3584 memcached_server_free(&memc
->hosts
[x
]);
3585 memc
->number_of_hosts
= 0;
3586 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
, 1);
3587 for (x
= 0; x
< num_hosts
; x
++)
3589 assert(memcached_server_add_udp(memc
, servers
[x
].hostname
, servers
[x
].port
) == MEMCACHED_SUCCESS
);
3590 assert(memc
->hosts
[x
].write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
3592 return MEMCACHED_SUCCESS
;
3595 static memcached_return
binary_init_udp(memcached_st
*memc
)
3598 return init_udp(memc
);
3601 /* Make sure that I cant add a tcp server to a udp client */
3602 static test_return
add_tcp_server_udp_client_test(memcached_st
*memc
)
3604 memcached_server_st server
;
3605 memcached_server_clone(&server
, &memc
->hosts
[0]);
3606 assert(memcached_server_remove(&(memc
->hosts
[0])) == MEMCACHED_SUCCESS
);
3607 assert(memcached_server_add(memc
, server
.hostname
, server
.port
) == MEMCACHED_INVALID_HOST_PROTOCOL
);
3608 return TEST_SUCCESS
;
3611 /* Make sure that I cant add a udp server to a tcp client */
3612 static test_return
add_udp_server_tcp_client_test(memcached_st
*memc
)
3614 memcached_server_st server
;
3615 memcached_server_clone(&server
, &memc
->hosts
[0]);
3616 assert(memcached_server_remove(&(memc
->hosts
[0])) == MEMCACHED_SUCCESS
);
3618 memcached_st tcp_client
;
3619 memcached_create(&tcp_client
);
3620 assert(memcached_server_add_udp(&tcp_client
, server
.hostname
, server
.port
) == MEMCACHED_INVALID_HOST_PROTOCOL
);
3621 return TEST_SUCCESS
;
3624 static test_return
set_udp_behavior_test(memcached_st
*memc
)
3627 memcached_quit(memc
);
3628 memc
->number_of_hosts
= 0;
3629 run_distribution(memc
);
3630 assert(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
, 1) == MEMCACHED_SUCCESS
);
3631 assert(memc
->flags
& MEM_USE_UDP
);
3632 assert(memc
->flags
& MEM_NOREPLY
);;
3634 assert(memc
->number_of_hosts
== 0);
3636 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
,0);
3637 assert(!(memc
->flags
& MEM_USE_UDP
));
3638 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
,0);
3639 assert(!(memc
->flags
& MEM_NOREPLY
));
3640 return TEST_SUCCESS
;
3643 static test_return
udp_set_test(memcached_st
*memc
)
3646 unsigned int num_iters
= 1025; //request id rolls over at 1024
3647 for (x
= 0; x
< num_iters
;x
++)
3649 memcached_return rc
;
3651 char *value
= "when we sanitize";
3652 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3653 unsigned int server_key
= memcached_generate_hash(memc
,key
,strlen(key
));
3654 size_t init_offset
= memc
->hosts
[server_key
].write_buffer_offset
;
3655 rc
= memcached_set(memc
, key
, strlen(key
),
3656 value
, strlen(value
),
3657 (time_t)0, (uint32_t)0);
3658 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
3659 /** NB, the check below assumes that if new write_ptr is less than
3660 * the original write_ptr that we have flushed. For large payloads, this
3661 * maybe an invalid assumption, but for the small payload we have it is OK
3663 if (rc
== MEMCACHED_SUCCESS
||
3664 memc
->hosts
[server_key
].write_buffer_offset
< init_offset
)
3665 increment_request_id(&expected_ids
[server_key
]);
3667 if (rc
== MEMCACHED_SUCCESS
)
3669 assert(memc
->hosts
[server_key
].write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
3673 assert(memc
->hosts
[server_key
].write_buffer_offset
!= UDP_DATAGRAM_HEADER_LENGTH
);
3674 assert(memc
->hosts
[server_key
].write_buffer_offset
<= MAX_UDP_DATAGRAM_LENGTH
);
3676 assert(post_udp_op_check(memc
,expected_ids
) == TEST_SUCCESS
);
3678 return TEST_SUCCESS
;
3681 static test_return
udp_buffered_set_test(memcached_st
*memc
)
3683 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
3684 return udp_set_test(memc
);
3687 static test_return
udp_set_too_big_test(memcached_st
*memc
)
3689 memcached_return rc
;
3691 char value
[MAX_UDP_DATAGRAM_LENGTH
];
3692 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3693 rc
= memcached_set(memc
, key
, strlen(key
),
3694 value
, MAX_UDP_DATAGRAM_LENGTH
,
3695 (time_t)0, (uint32_t)0);
3696 assert(rc
== MEMCACHED_WRITE_FAILURE
);
3697 return post_udp_op_check(memc
,expected_ids
);
3700 static test_return
udp_delete_test(memcached_st
*memc
)
3703 unsigned int num_iters
= 1025; //request id rolls over at 1024
3704 for (x
= 0; x
< num_iters
;x
++)
3706 memcached_return rc
;
3708 uint16_t *expected_ids
=get_udp_request_ids(memc
);
3709 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
3710 size_t init_offset
= memc
->hosts
[server_key
].write_buffer_offset
;
3711 rc
= memcached_delete(memc
, key
, strlen(key
), 0);
3712 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
3713 if (rc
== MEMCACHED_SUCCESS
|| memc
->hosts
[server_key
].write_buffer_offset
< init_offset
)
3714 increment_request_id(&expected_ids
[server_key
]);
3715 if (rc
== MEMCACHED_SUCCESS
)
3716 assert(memc
->hosts
[server_key
].write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
3719 assert(memc
->hosts
[server_key
].write_buffer_offset
!= UDP_DATAGRAM_HEADER_LENGTH
);
3720 assert(memc
->hosts
[server_key
].write_buffer_offset
<= MAX_UDP_DATAGRAM_LENGTH
);
3722 assert(post_udp_op_check(memc
,expected_ids
) == TEST_SUCCESS
);
3724 return TEST_SUCCESS
;
3727 static test_return
udp_buffered_delete_test(memcached_st
*memc
)
3729 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
3730 return udp_delete_test(memc
);
3733 static test_return
udp_verbosity_test(memcached_st
*memc
)
3735 memcached_return rc
;
3736 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3738 for (x
= 0; x
< memc
->number_of_hosts
;x
++)
3739 increment_request_id(&expected_ids
[x
]);
3741 rc
= memcached_verbosity(memc
,3);
3742 assert(rc
== MEMCACHED_SUCCESS
);
3743 return post_udp_op_check(memc
,expected_ids
);
3746 static test_return
udp_quit_test(memcached_st
*memc
)
3748 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3749 memcached_quit(memc
);
3750 return post_udp_op_check(memc
, expected_ids
);
3753 static test_return
udp_flush_test(memcached_st
*memc
)
3755 memcached_return rc
;
3756 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3758 for (x
= 0; x
< memc
->number_of_hosts
;x
++)
3759 increment_request_id(&expected_ids
[x
]);
3761 rc
= memcached_flush(memc
,0);
3762 assert(rc
== MEMCACHED_SUCCESS
);
3763 return post_udp_op_check(memc
,expected_ids
);
3766 static test_return
udp_incr_test(memcached_st
*memc
)
3768 memcached_return rc
;
3771 rc
= memcached_set(memc
, key
, strlen(key
),
3772 value
, strlen(value
),
3773 (time_t)0, (uint32_t)0);
3775 assert(rc
== MEMCACHED_SUCCESS
);
3776 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3777 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
3778 increment_request_id(&expected_ids
[server_key
]);
3780 rc
= memcached_increment(memc
, key
, strlen(key
), 1, &newvalue
);
3781 assert(rc
== MEMCACHED_SUCCESS
);
3782 return post_udp_op_check(memc
, expected_ids
);
3785 static test_return
udp_decr_test(memcached_st
*memc
)
3787 memcached_return rc
;
3790 rc
= memcached_set(memc
, key
, strlen(key
),
3791 value
, strlen(value
),
3792 (time_t)0, (uint32_t)0);
3794 assert(rc
== MEMCACHED_SUCCESS
);
3795 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3796 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
3797 increment_request_id(&expected_ids
[server_key
]);
3799 rc
= memcached_decrement(memc
, key
, strlen(key
), 1, &newvalue
);
3800 assert(rc
== MEMCACHED_SUCCESS
);
3801 return post_udp_op_check(memc
, expected_ids
);
3805 static test_return
udp_stat_test(memcached_st
*memc
)
3807 memcached_stat_st
* rv
= NULL
;
3808 memcached_return rc
;
3810 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3811 rv
= memcached_stat(memc
, args
, &rc
);
3813 assert(rc
== MEMCACHED_NOT_SUPPORTED
);
3814 return post_udp_op_check(memc
, expected_ids
);
3817 static test_return
udp_version_test(memcached_st
*memc
)
3819 memcached_return rc
;
3820 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3821 rc
= memcached_version(memc
);
3822 assert(rc
== MEMCACHED_NOT_SUPPORTED
);
3823 return post_udp_op_check(memc
, expected_ids
);
3826 static test_return
udp_get_test(memcached_st
*memc
)
3828 memcached_return rc
;
3831 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3832 char *val
= memcached_get(memc
, key
, strlen(key
), &vlen
, (uint32_t)0, &rc
);
3833 assert(rc
== MEMCACHED_NOT_SUPPORTED
);
3834 assert(val
== NULL
);
3835 return post_udp_op_check(memc
, expected_ids
);
3838 static test_return
udp_mixed_io_test(memcached_st
*memc
)
3841 test_st mixed_io_ops
[] ={
3842 {"udp_set_test", 0, udp_set_test
},
3843 {"udp_set_too_big_test", 0, udp_set_too_big_test
},
3844 {"udp_delete_test", 0, udp_delete_test
},
3845 {"udp_verbosity_test", 0, udp_verbosity_test
},
3846 {"udp_quit_test", 0, udp_quit_test
},
3847 {"udp_flush_test", 0, udp_flush_test
},
3848 {"udp_incr_test", 0, udp_incr_test
},
3849 {"udp_decr_test", 0, udp_decr_test
},
3850 {"udp_version_test", 0, udp_version_test
}
3853 for (x
= 0; x
< 500; x
++)
3855 current_op
= mixed_io_ops
[random() % 9];
3856 assert(current_op
.function(memc
) == TEST_SUCCESS
);
3858 return TEST_SUCCESS
;
3861 static test_return
hsieh_avaibility_test (memcached_st
*memc
)
3863 memcached_return expected_rc
= MEMCACHED_FAILURE
;
3864 #ifdef HAVE_HSIEH_HASH
3865 expected_rc
= MEMCACHED_SUCCESS
;
3867 memcached_return rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
,
3868 (uint64_t)MEMCACHED_HASH_HSIEH
);
3869 assert(rc
== expected_rc
);
3870 return TEST_SUCCESS
;
3873 static char *list
[]=
3903 static test_return
md5_run (memcached_st
*memc
__attribute__((unused
)))
3907 uint32_t values
[]= { 3195025439, 2556848621, 3724893440, 3332385401, 245758794, 2550894432,
3908 121710495, 3053817768, 1250994555, 1862072655, 2631955953, 2951528551,
3909 1451250070, 2820856945, 2060845566, 3646985608, 2138080750, 217675895,
3910 2230934345, 1234361223, 3968582726, 2455685270, 1293568479, 199067604,
3914 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
3918 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MD5
);
3919 assert(values
[x
] == hash_val
);
3922 return TEST_SUCCESS
;
3925 static test_return
crc_run (memcached_st
*memc
__attribute__((unused
)))
3929 uint32_t values
[]= { 10542, 22009, 14526, 19510, 19432, 10199, 20634, 9369, 11511, 10362,
3930 7893, 31289, 11313, 9354, 7621, 30628, 15218, 25967, 2695, 9380,
3931 17300, 28156, 9192, 20484, 16925 };
3933 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
3937 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_CRC
);
3938 assert(values
[x
] == hash_val
);
3941 return TEST_SUCCESS
;
3944 static test_return
fnv1_64_run (memcached_st
*memc
__attribute__((unused
)))
3948 uint32_t values
[]= { 473199127, 4148981457, 3971873300, 3257986707, 1722477987, 2991193800,
3949 4147007314, 3633179701, 1805162104, 3503289120, 3395702895, 3325073042,
3950 2345265314, 3340346032, 2722964135, 1173398992, 2815549194, 2562818319,
3951 224996066, 2680194749, 3035305390, 246890365, 2395624193, 4145193337,
3954 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
3958 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_64
);
3959 assert(values
[x
] == hash_val
);
3962 return TEST_SUCCESS
;
3965 static test_return
fnv1a_64_run (memcached_st
*memc
__attribute__((unused
)))
3969 uint32_t values
[]= { 1488911807, 2500855813, 1510099634, 1390325195, 3647689787, 3241528582,
3970 1669328060, 2604311949, 734810122, 1516407546, 560948863, 1767346780,
3971 561034892, 4156330026, 3716417003, 3475297030, 1518272172, 227211583,
3972 3938128828, 126112909, 3043416448, 3131561933, 1328739897, 2455664041,
3975 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
3979 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_64
);
3980 assert(values
[x
] == hash_val
);
3983 return TEST_SUCCESS
;
3986 static test_return
fnv1_32_run (memcached_st
*memc
__attribute__((unused
)))
3990 uint32_t values
[]= { 67176023, 1190179409, 2043204404, 3221866419, 2567703427, 3787535528, 4147287986,
3991 3500475733, 344481048, 3865235296, 2181839183, 119581266, 510234242, 4248244304,
3992 1362796839, 103389328, 1449620010, 182962511, 3554262370, 3206747549, 1551306158,
3993 4127558461, 1889140833, 2774173721, 1180552018 };
3996 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4000 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_32
);
4001 assert(values
[x
] == hash_val
);
4004 return TEST_SUCCESS
;
4007 static test_return
fnv1a_32_run (memcached_st
*memc
__attribute__((unused
)))
4011 uint32_t values
[]= { 280767167, 2421315013, 3072375666, 855001899, 459261019, 3521085446, 18738364,
4012 1625305005, 2162232970, 777243802, 3323728671, 132336572, 3654473228, 260679466,
4013 1169454059, 2698319462, 1062177260, 235516991, 2218399068, 405302637, 1128467232,
4014 3579622413, 2138539289, 96429129, 2877453236 };
4016 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4020 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_32
);
4021 assert(values
[x
] == hash_val
);
4024 return TEST_SUCCESS
;
4027 static test_return
hsieh_run (memcached_st
*memc
__attribute__((unused
)))
4031 #ifdef HAVE_HSIEH_HASH
4032 uint32_t values
[]= { 3738850110, 3636226060, 3821074029, 3489929160, 3485772682, 80540287,
4033 1805464076, 1895033657, 409795758, 979934958, 3634096985, 1284445480,
4034 2265380744, 707972988, 353823508, 1549198350, 1327930172, 9304163,
4035 4220749037, 2493964934, 2777873870, 2057831732, 1510213931, 2027828987,
4038 uint32_t values
[]= { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
4041 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4045 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_HSIEH
);
4046 assert(values
[x
] == hash_val
);
4049 return TEST_SUCCESS
;
4052 static test_return
murmur_run (memcached_st
*memc
__attribute__((unused
)))
4056 uint32_t values
[]= { 473199127, 4148981457, 3971873300, 3257986707, 1722477987, 2991193800,
4057 4147007314, 3633179701, 1805162104, 3503289120, 3395702895, 3325073042,
4058 2345265314, 3340346032, 2722964135, 1173398992, 2815549194, 2562818319,
4059 224996066, 2680194749, 3035305390, 246890365, 2395624193, 4145193337,
4062 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4066 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_64
);
4067 assert(values
[x
] == hash_val
);
4070 return TEST_SUCCESS
;
4073 static test_return
jenkins_run (memcached_st
*memc
__attribute__((unused
)))
4077 uint32_t values
[]= { 1442444624, 4253821186, 1885058256, 2120131735, 3261968576, 3515188778,
4078 4232909173, 4288625128, 1812047395, 3689182164, 2502979932, 1214050606,
4079 2415988847, 1494268927, 1025545760, 3920481083, 4153263658, 3824871822,
4080 3072759809, 798622255, 3065432577, 1453328165, 2691550971, 3408888387,
4084 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4088 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_JENKINS
);
4089 assert(values
[x
] == hash_val
);
4092 return TEST_SUCCESS
;
4095 test_st udp_setup_server_tests
[] ={
4096 {"set_udp_behavior_test", 0, set_udp_behavior_test
},
4097 {"add_tcp_server_udp_client_test", 0, add_tcp_server_udp_client_test
},
4098 {"add_udp_server_tcp_client_test", 0, add_udp_server_tcp_client_test
},
4102 test_st upd_io_tests
[] ={
4103 {"udp_set_test", 0, udp_set_test
},
4104 {"udp_buffered_set_test", 0, udp_buffered_set_test
},
4105 {"udp_set_too_big_test", 0, udp_set_too_big_test
},
4106 {"udp_delete_test", 0, udp_delete_test
},
4107 {"udp_buffered_delete_test", 0, udp_buffered_delete_test
},
4108 {"udp_verbosity_test", 0, udp_verbosity_test
},
4109 {"udp_quit_test", 0, udp_quit_test
},
4110 {"udp_flush_test", 0, udp_flush_test
},
4111 {"udp_incr_test", 0, udp_incr_test
},
4112 {"udp_decr_test", 0, udp_decr_test
},
4113 {"udp_stat_test", 0, udp_stat_test
},
4114 {"udp_version_test", 0, udp_version_test
},
4115 {"udp_get_test", 0, udp_get_test
},
4116 {"udp_mixed_io_test", 0, udp_mixed_io_test
},
4120 /* Clean the server before beginning testing */
4122 {"flush", 0, flush_test
},
4123 {"init", 0, init_test
},
4124 {"allocation", 0, allocation_test
},
4125 {"server_list_null_test", 0, server_list_null_test
},
4126 {"server_unsort", 0, server_unsort_test
},
4127 {"server_sort", 0, server_sort_test
},
4128 {"server_sort2", 0, server_sort2_test
},
4129 {"clone_test", 0, clone_test
},
4130 {"connection_test", 0, connection_test
},
4131 {"callback_test", 0, callback_test
},
4132 {"behavior_test", 0, behavior_test
},
4133 {"error", 0, error_test
},
4134 {"set", 0, set_test
},
4135 {"set2", 0, set_test2
},
4136 {"set3", 0, set_test3
},
4137 {"dump", 1, dump_test
},
4138 {"add", 1, add_test
},
4139 {"replace", 1, replace_test
},
4140 {"delete", 1, delete_test
},
4141 {"get", 1, get_test
},
4142 {"get2", 0, get_test2
},
4143 {"get3", 0, get_test3
},
4144 {"get4", 0, get_test4
},
4145 {"partial mget", 0, get_test5
},
4146 {"stats_servername", 0, stats_servername_test
},
4147 {"increment", 0, increment_test
},
4148 {"increment_with_initial", 1, increment_with_initial_test
},
4149 {"decrement", 0, decrement_test
},
4150 {"decrement_with_initial", 1, decrement_with_initial_test
},
4151 {"quit", 0, quit_test
},
4152 {"mget", 1, mget_test
},
4153 {"mget_result", 1, mget_result_test
},
4154 {"mget_result_alloc", 1, mget_result_alloc_test
},
4155 {"mget_result_function", 1, mget_result_function
},
4156 {"get_stats", 0, get_stats
},
4157 {"add_host_test", 0, add_host_test
},
4158 {"add_host_test_1", 0, add_host_test1
},
4159 {"get_stats_keys", 0, get_stats_keys
},
4160 {"behavior_test", 0, get_stats_keys
},
4161 {"callback_test", 0, get_stats_keys
},
4162 {"version_string_test", 0, version_string_test
},
4163 {"bad_key", 1, bad_key_test
},
4164 {"memcached_server_cursor", 1, memcached_server_cursor_test
},
4165 {"read_through", 1, read_through
},
4166 {"delete_through", 1, delete_through
},
4167 {"noreply", 1, noreply_test
},
4168 {"analyzer", 1, analyzer_test
},
4169 #ifdef HAVE_LIBMEMCACHEDUTIL
4170 {"connectionpool", 1, connection_pool_test
},
4175 test_st async_tests
[] ={
4176 {"add", 1, add_wrapper
},
4180 test_st string_tests
[] ={
4181 {"string static with null", 0, string_static_null
},
4182 {"string alloc with null", 0, string_alloc_null
},
4183 {"string alloc with 1K", 0, string_alloc_with_size
},
4184 {"string alloc with malloc failure", 0, string_alloc_with_size_toobig
},
4185 {"string append", 0, string_alloc_append
},
4186 {"string append failure (too big)", 0, string_alloc_append_toobig
},
4190 test_st result_tests
[] ={
4191 {"result static", 0, result_static
},
4192 {"result alloc", 0, result_alloc
},
4196 test_st version_1_2_3
[] ={
4197 {"append", 0, append_test
},
4198 {"prepend", 0, prepend_test
},
4199 {"cas", 0, cas_test
},
4200 {"cas2", 0, cas2_test
},
4201 {"append_binary", 0, append_binary_test
},
4205 test_st user_tests
[] ={
4206 {"user_supplied_bug1", 0, user_supplied_bug1
},
4207 {"user_supplied_bug2", 0, user_supplied_bug2
},
4208 {"user_supplied_bug3", 0, user_supplied_bug3
},
4209 {"user_supplied_bug4", 0, user_supplied_bug4
},
4210 {"user_supplied_bug5", 1, user_supplied_bug5
},
4211 {"user_supplied_bug6", 1, user_supplied_bug6
},
4212 {"user_supplied_bug7", 1, user_supplied_bug7
},
4213 {"user_supplied_bug8", 1, user_supplied_bug8
},
4214 {"user_supplied_bug9", 1, user_supplied_bug9
},
4215 {"user_supplied_bug10", 1, user_supplied_bug10
},
4216 {"user_supplied_bug11", 1, user_supplied_bug11
},
4217 {"user_supplied_bug12", 1, user_supplied_bug12
},
4218 {"user_supplied_bug13", 1, user_supplied_bug13
},
4219 {"user_supplied_bug14", 1, user_supplied_bug14
},
4220 {"user_supplied_bug15", 1, user_supplied_bug15
},
4221 {"user_supplied_bug16", 1, user_supplied_bug16
},
4224 ** It seems to be something weird with the character sets..
4225 ** value_fetch is unable to parse the value line (iscntrl "fails"), so I
4226 ** guess I need to find out how this is supposed to work.. Perhaps I need
4227 ** to run the test in a specific locale (I tried zh_CN.UTF-8 without success,
4228 ** so just disable the code for now...).
4230 {"user_supplied_bug17", 1, user_supplied_bug17
},
4232 {"user_supplied_bug18", 1, user_supplied_bug18
},
4233 {"user_supplied_bug19", 1, user_supplied_bug19
},
4234 {"user_supplied_bug20", 1, user_supplied_bug20
},
4238 test_st generate_tests
[] ={
4239 {"generate_pairs", 1, generate_pairs
},
4240 {"generate_data", 1, generate_data
},
4241 {"get_read", 0, get_read
},
4242 {"delete_generate", 0, delete_generate
},
4243 {"generate_buffer_data", 1, generate_buffer_data
},
4244 {"delete_buffer", 0, delete_buffer_generate
},
4245 {"generate_data", 1, generate_data
},
4246 {"mget_read", 0, mget_read
},
4247 {"mget_read_result", 0, mget_read_result
},
4248 {"mget_read_function", 0, mget_read_function
},
4249 {"cleanup", 1, cleanup_pairs
},
4250 {"generate_large_pairs", 1, generate_large_pairs
},
4251 {"generate_data", 1, generate_data
},
4252 {"generate_buffer_data", 1, generate_buffer_data
},
4253 {"cleanup", 1, cleanup_pairs
},
4257 test_st consistent_tests
[] ={
4258 {"generate_pairs", 1, generate_pairs
},
4259 {"generate_data", 1, generate_data
},
4260 {"get_read", 0, get_read_count
},
4261 {"cleanup", 1, cleanup_pairs
},
4265 test_st consistent_weighted_tests
[] ={
4266 {"generate_pairs", 1, generate_pairs
},
4267 {"generate_data", 1, generate_data_with_stats
},
4268 {"get_read", 0, get_read_count
},
4269 {"cleanup", 1, cleanup_pairs
},
4273 test_st hsieh_availability
[] ={
4274 {"hsieh_avaibility_test",0,hsieh_avaibility_test
},
4278 test_st ketama_auto_eject_hosts
[] ={
4279 {"auto_eject_hosts", 1, auto_eject_hosts
},
4283 test_st hash_tests
[] ={
4284 {"md5", 0, md5_run
},
4285 {"crc", 0, crc_run
},
4286 {"fnv1_64", 0, fnv1_64_run
},
4287 {"fnv1a_64", 0, fnv1a_64_run
},
4288 {"fnv1_32", 0, fnv1_32_run
},
4289 {"fnv1a_32", 0, fnv1a_32_run
},
4290 {"hsieh", 0, hsieh_run
},
4291 {"murmur", 0, murmur_run
},
4292 {"jenkis", 0, jenkins_run
},
4296 collection_st collection
[] ={
4297 {"hsieh_availability",0,0,hsieh_availability
},
4298 {"udp_setup", init_udp
, 0, udp_setup_server_tests
},
4299 {"udp_io", init_udp
, 0, upd_io_tests
},
4300 {"udp_binary_io", binary_init_udp
, 0, upd_io_tests
},
4301 {"block", 0, 0, tests
},
4302 {"binary", pre_binary
, 0, tests
},
4303 {"nonblock", pre_nonblock
, 0, tests
},
4304 {"nodelay", pre_nodelay
, 0, tests
},
4305 {"settimer", pre_settimer
, 0, tests
},
4306 {"md5", pre_md5
, 0, tests
},
4307 {"crc", pre_crc
, 0, tests
},
4308 {"hsieh", pre_hsieh
, 0, tests
},
4309 {"jenkins", pre_jenkins
, 0, tests
},
4310 {"fnv1_64", pre_hash_fnv1_64
, 0, tests
},
4311 {"fnv1a_64", pre_hash_fnv1a_64
, 0, tests
},
4312 {"fnv1_32", pre_hash_fnv1_32
, 0, tests
},
4313 {"fnv1a_32", pre_hash_fnv1a_32
, 0, tests
},
4314 {"ketama", pre_behavior_ketama
, 0, tests
},
4315 {"ketama_auto_eject_hosts", pre_behavior_ketama
, 0, ketama_auto_eject_hosts
},
4316 {"unix_socket", pre_unix_socket
, 0, tests
},
4317 {"unix_socket_nodelay", pre_nodelay
, 0, tests
},
4318 {"poll_timeout", poll_timeout
, 0, tests
},
4319 {"gets", enable_cas
, 0, tests
},
4320 {"consistent", enable_consistent
, 0, tests
},
4321 {"deprecated_memory_allocators", deprecated_set_memory_alloc
, 0, tests
},
4322 {"memory_allocators", set_memory_alloc
, 0, tests
},
4323 {"prefix", set_prefix
, 0, tests
},
4324 {"version_1_2_3", check_for_1_2_3
, 0, version_1_2_3
},
4325 {"string", 0, 0, string_tests
},
4326 {"result", 0, 0, result_tests
},
4327 {"async", pre_nonblock
, 0, async_tests
},
4328 {"async_binary", pre_nonblock_binary
, 0, async_tests
},
4329 {"user", 0, 0, user_tests
},
4330 {"generate", 0, 0, generate_tests
},
4331 {"generate_hsieh", pre_hsieh
, 0, generate_tests
},
4332 {"generate_ketama", pre_behavior_ketama
, 0, generate_tests
},
4333 {"generate_hsieh_consistent", enable_consistent
, 0, generate_tests
},
4334 {"generate_md5", pre_md5
, 0, generate_tests
},
4335 {"generate_murmur", pre_murmur
, 0, generate_tests
},
4336 {"generate_jenkins", pre_jenkins
, 0, generate_tests
},
4337 {"generate_nonblock", pre_nonblock
, 0, generate_tests
},
4338 {"consistent_not", 0, 0, consistent_tests
},
4339 {"consistent_ketama", pre_behavior_ketama
, 0, consistent_tests
},
4340 {"consistent_ketama_weighted", pre_behavior_ketama_weighted
, 0, consistent_weighted_tests
},
4341 {"test_hashes", 0, 0, hash_tests
},
4345 #define SERVERS_TO_CREATE 5
4347 /* Prototypes for functions we will pass to test framework */
4348 void *world_create(void);
4349 void world_destroy(void *p
);
4351 void *world_create(void)
4353 server_startup_st
*construct
;
4355 construct
= (server_startup_st
*)malloc(sizeof(server_startup_st
));
4356 memset(construct
, 0, sizeof(server_startup_st
));
4357 construct
->count
= SERVERS_TO_CREATE
;
4359 server_startup(construct
);
4365 void world_destroy(void *p
)
4367 server_startup_st
*construct
= (server_startup_st
*)p
;
4368 memcached_server_st
*servers
= (memcached_server_st
*)construct
->servers
;
4369 memcached_server_list_free(servers
);
4371 server_shutdown(construct
);
4375 void get_world(world_st
*world
)
4377 world
->collections
= collection
;
4378 world
->create
= world_create
;
4379 world
->destroy
= world_destroy
;