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 return calloc(1, size
);
3049 static void *my_realloc(memcached_st
*ptr
__attribute__((unused
)), void *mem
, const size_t size
)
3051 return realloc(mem
, size
);
3054 static memcached_return
set_prefix(memcached_st
*memc
)
3056 memcached_return rc
;
3057 const char *key
= "mine";
3060 /* Make sure be default none exists */
3061 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3062 assert(rc
== MEMCACHED_FAILURE
);
3064 /* Test a clean set */
3065 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3066 assert(rc
== MEMCACHED_SUCCESS
);
3068 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3069 assert(memcmp(value
, key
, 4) == 0);
3070 assert(rc
== MEMCACHED_SUCCESS
);
3072 /* Test that we can turn it off */
3073 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3074 assert(rc
== MEMCACHED_SUCCESS
);
3076 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3077 assert(rc
== MEMCACHED_FAILURE
);
3079 /* Now setup for main test */
3080 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3081 assert(rc
== MEMCACHED_SUCCESS
);
3083 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3084 assert(rc
== MEMCACHED_SUCCESS
);
3085 assert(memcmp(value
, key
, 4) == 0);
3087 /* Set to Zero, and then Set to something too large */
3090 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3091 assert(rc
== MEMCACHED_SUCCESS
);
3093 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3094 assert(rc
== MEMCACHED_FAILURE
);
3095 assert(value
== NULL
);
3097 /* Test a long key for failure */
3098 /* TODO, extend test to determine based on setting, what result should be */
3099 long_key
= "Thisismorethentheallottednumberofcharacters";
3100 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3101 //assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
3102 assert(rc
== MEMCACHED_SUCCESS
);
3104 /* Now test a key with spaces (which will fail from long key, since bad key is not set) */
3105 long_key
= "This is more then the allotted number of characters";
3106 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3107 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3109 /* Test for a bad prefix, but with a short key */
3110 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, 1);
3111 assert(rc
== MEMCACHED_SUCCESS
);
3113 long_key
= "dog cat";
3114 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3115 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3118 return MEMCACHED_SUCCESS
;
3121 static memcached_return
set_memory_alloc(memcached_st
*memc
)
3123 void *test_ptr
= NULL
;
3126 memcached_malloc_function malloc_cb
=
3127 (memcached_malloc_function
)my_malloc
;
3128 cb_ptr
= *(void **)&malloc_cb
;
3129 memcached_return rc
;
3131 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, cb_ptr
);
3132 assert(rc
== MEMCACHED_SUCCESS
);
3133 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
3134 assert(rc
== MEMCACHED_SUCCESS
);
3135 assert(test_ptr
== cb_ptr
);
3139 memcached_realloc_function realloc_cb
=
3140 (memcached_realloc_function
)my_realloc
;
3141 cb_ptr
= *(void **)&realloc_cb
;
3142 memcached_return rc
;
3144 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, cb_ptr
);
3145 assert(rc
== MEMCACHED_SUCCESS
);
3146 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
3147 assert(rc
== MEMCACHED_SUCCESS
);
3148 assert(test_ptr
== cb_ptr
);
3152 memcached_free_function free_cb
=
3153 (memcached_free_function
)my_free
;
3154 cb_ptr
= *(void **)&free_cb
;
3155 memcached_return rc
;
3157 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, cb_ptr
);
3158 assert(rc
== MEMCACHED_SUCCESS
);
3159 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
3160 assert(rc
== MEMCACHED_SUCCESS
);
3161 assert(test_ptr
== cb_ptr
);
3164 return MEMCACHED_SUCCESS
;
3167 static memcached_return
enable_consistent(memcached_st
*memc
)
3169 memcached_server_distribution value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
3170 memcached_hash hash
;
3171 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
3172 if (pre_hsieh(memc
) != MEMCACHED_SUCCESS
)
3173 return MEMCACHED_FAILURE
;
3175 value
= (memcached_server_distribution
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
3176 assert(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
3178 hash
= (memcached_hash
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
3179 assert(hash
== MEMCACHED_HASH_HSIEH
);
3182 return MEMCACHED_SUCCESS
;
3185 static memcached_return
enable_cas(memcached_st
*memc
)
3187 unsigned int set
= 1;
3189 memcached_version(memc
);
3191 if ((memc
->hosts
[0].major_version
>= 1 && (memc
->hosts
[0].minor_version
== 2 && memc
->hosts
[0].micro_version
>= 4))
3192 || memc
->hosts
[0].minor_version
> 2)
3194 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
3196 return MEMCACHED_SUCCESS
;
3199 return MEMCACHED_FAILURE
;
3202 static memcached_return
check_for_1_2_3(memcached_st
*memc
)
3204 memcached_version(memc
);
3206 if ((memc
->hosts
[0].major_version
>= 1 && (memc
->hosts
[0].minor_version
== 2 && memc
->hosts
[0].micro_version
>= 4))
3207 || memc
->hosts
[0].minor_version
> 2)
3208 return MEMCACHED_SUCCESS
;
3210 return MEMCACHED_FAILURE
;
3213 static memcached_return
pre_unix_socket(memcached_st
*memc
)
3215 memcached_return rc
;
3218 memcached_server_list_free(memc
->hosts
);
3220 memc
->number_of_hosts
= 0;
3222 if (stat("/tmp/memcached.socket", &buf
))
3223 return MEMCACHED_FAILURE
;
3225 rc
= memcached_server_add_unix_socket_with_weight(memc
, "/tmp/memcached.socket", 0);
3230 static memcached_return
pre_nodelay(memcached_st
*memc
)
3232 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3233 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
3235 return MEMCACHED_SUCCESS
;
3238 static memcached_return
pre_settimer(memcached_st
*memc
)
3240 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
3241 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
3243 return MEMCACHED_SUCCESS
;
3246 static memcached_return
poll_timeout(memcached_st
*memc
)
3252 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
3254 timeout
= (int32_t)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
3256 assert(timeout
== 100);
3258 return MEMCACHED_SUCCESS
;
3261 static test_return
noreply_test(memcached_st
*memc
)
3263 memcached_return ret
;
3264 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
3265 assert(ret
== MEMCACHED_SUCCESS
);
3266 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
3267 assert(ret
== MEMCACHED_SUCCESS
);
3268 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
3269 assert(ret
== MEMCACHED_SUCCESS
);
3270 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NOREPLY
) == 1);
3271 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
) == 1);
3272 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
) == 1);
3274 for (int count
=0; count
< 5; ++count
)
3276 for (int x
=0; x
< 100; ++x
)
3279 size_t len
= sprintf(key
, "%d", x
);
3283 ret
=memcached_add(memc
, key
, len
, key
, len
, 0, 0);
3286 ret
=memcached_replace(memc
, key
, len
, key
, len
, 0, 0);
3289 ret
=memcached_set(memc
, key
, len
, key
, len
, 0, 0);
3292 ret
=memcached_append(memc
, key
, len
, key
, len
, 0, 0);
3295 ret
=memcached_prepend(memc
, key
, len
, key
, len
, 0, 0);
3298 assert(ret
== MEMCACHED_SUCCESS
|| ret
== MEMCACHED_BUFFERED
);
3302 ** NOTE: Don't ever do this in your code! this is not a supported use of the
3303 ** API and is _ONLY_ done this way to verify that the library works the
3304 ** way it is supposed to do!!!!
3307 for (uint32_t x
=0; x
< memc
->number_of_hosts
; ++x
)
3308 no_msg
+=memc
->hosts
[x
].cursor_active
;
3310 assert(no_msg
== 0);
3311 assert(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
3314 ** Now validate that all items was set properly!
3316 for (int x
=0; x
< 100; ++x
)
3319 size_t len
= sprintf(key
, "%d", x
);
3322 char* value
=memcached_get(memc
, key
, strlen(key
),
3323 &length
, &flags
, &ret
);
3324 assert(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
3327 case 0: /* FALLTHROUGH */
3328 case 1: /* FALLTHROUGH */
3330 assert(strncmp(value
, key
, len
) == 0);
3331 assert(len
== length
);
3334 assert(length
== len
* 2);
3337 assert(length
== len
* 3);
3344 /* Try setting an illegal cas value (should not return an error to
3345 * the caller (because we don't expect a return message from the server)
3347 char* keys
[]= {"0"};
3348 size_t lengths
[]= {1};
3351 memcached_result_st results_obj
;
3352 memcached_result_st
*results
;
3353 ret
= memcached_mget(memc
, keys
, lengths
, 1);
3354 assert(ret
== MEMCACHED_SUCCESS
);
3356 results
= memcached_result_create(memc
, &results_obj
);
3358 results
= memcached_fetch_result(memc
, &results_obj
, &ret
);
3360 assert(ret
== MEMCACHED_SUCCESS
);
3361 uint64_t cas
= memcached_result_cas(results
);
3362 memcached_result_free(&results_obj
);
3364 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
3365 assert(ret
== MEMCACHED_SUCCESS
);
3368 * The item will have a new cas value, so try to set it again with the old
3369 * value. This should fail!
3371 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
3372 assert(ret
== MEMCACHED_SUCCESS
);
3373 assert(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
3374 char* value
=memcached_get(memc
, keys
[0], lengths
[0], &length
, &flags
, &ret
);
3375 assert(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
3378 return TEST_SUCCESS
;
3381 static test_return
analyzer_test(memcached_st
*memc
)
3383 memcached_return rc
;
3384 memcached_stat_st
*stat
;
3385 memcached_analysis_st
*report
;
3387 stat
= memcached_stat(memc
, NULL
, &rc
);
3388 assert(rc
== MEMCACHED_SUCCESS
);
3391 report
= memcached_analyze(memc
, stat
, &rc
);
3392 assert(rc
== MEMCACHED_SUCCESS
);
3396 memcached_stat_free(NULL
, stat
);
3398 return TEST_SUCCESS
;
3401 /* Count the objects */
3402 static memcached_return
callback_dump_counter(memcached_st
*ptr
__attribute__((unused
)),
3403 const char *key
__attribute__((unused
)),
3404 size_t key_length
__attribute__((unused
)),
3407 uint32_t *counter
= (uint32_t *)context
;
3409 *counter
= *counter
+ 1;
3411 return MEMCACHED_SUCCESS
;
3414 static test_return
dump_test(memcached_st
*memc
)
3416 memcached_return rc
;
3417 uint32_t counter
= 0;
3418 memcached_dump_func callbacks
[1];
3419 test_return main_rc
;
3421 callbacks
[0]= &callback_dump_counter
;
3423 /* No support for Binary protocol yet */
3424 if (memc
->flags
& MEM_BINARY_PROTOCOL
)
3425 return TEST_SUCCESS
;
3427 main_rc
= set_test3(memc
);
3429 assert (main_rc
== TEST_SUCCESS
);
3431 rc
= memcached_dump(memc
, callbacks
, (void *)&counter
, 1);
3432 assert(rc
== MEMCACHED_SUCCESS
);
3434 /* We may have more then 32 if our previous flush has not completed */
3435 assert(counter
>= 32);
3437 return TEST_SUCCESS
;
3440 #ifdef HAVE_LIBMEMCACHEDUTIL
3441 static void* connection_release(void *arg
) {
3443 memcached_pool_st
* pool
;
3448 assert(memcached_pool_push(resource
->pool
, resource
->mmc
) == MEMCACHED_SUCCESS
);
3452 static test_return
connection_pool_test(memcached_st
*memc
)
3454 memcached_pool_st
* pool
= memcached_pool_create(memc
, 5, 10);
3455 assert(pool
!= NULL
);
3456 memcached_st
* mmc
[10];
3457 memcached_return rc
;
3459 for (int x
= 0; x
< 10; ++x
) {
3460 mmc
[x
]= memcached_pool_pop(pool
, false, &rc
);
3461 assert(mmc
[x
] != NULL
);
3462 assert(rc
== MEMCACHED_SUCCESS
);
3465 assert(memcached_pool_pop(pool
, false, &rc
) == NULL
);
3466 assert(rc
== MEMCACHED_SUCCESS
);
3470 memcached_pool_st
* pool
;
3472 } item
= { .pool
= pool
, .mmc
= mmc
[9] };
3473 pthread_create(&tid
, NULL
, connection_release
, &item
);
3474 mmc
[9]= memcached_pool_pop(pool
, true, &rc
);
3475 assert(rc
== MEMCACHED_SUCCESS
);
3476 pthread_join(tid
, NULL
);
3477 assert(mmc
[9] == item
.mmc
);
3478 const char *key
= "key";
3479 size_t keylen
= strlen(key
);
3481 // verify that I can do ops with all connections
3482 rc
= memcached_set(mmc
[0], key
, keylen
, "0", 1, 0, 0);
3483 assert(rc
== MEMCACHED_SUCCESS
);
3485 for (unsigned int x
= 0; x
< 10; ++x
) {
3486 uint64_t number_value
;
3487 rc
= memcached_increment(mmc
[x
], key
, keylen
, 1, &number_value
);
3488 assert(rc
== MEMCACHED_SUCCESS
);
3489 assert(number_value
== (x
+1));
3493 for (int x
= 0; x
< 10; ++x
)
3494 assert(memcached_pool_push(pool
, mmc
[x
]) == MEMCACHED_SUCCESS
);
3496 assert(memcached_pool_destroy(pool
) == memc
);
3497 return TEST_SUCCESS
;
3501 static void increment_request_id(uint16_t *id
)
3504 if ((*id
& UDP_REQUEST_ID_THREAD_MASK
) != 0)
3508 static uint16_t *get_udp_request_ids(memcached_st
*memc
)
3510 uint16_t *ids
= malloc(sizeof(uint16_t) * memc
->number_of_hosts
);
3511 assert(ids
!= NULL
);
3513 for (x
= 0; x
< memc
->number_of_hosts
; x
++)
3514 ids
[x
]= get_udp_datagram_request_id((struct udp_datagram_header_st
*) memc
->hosts
[x
].write_buffer
);
3519 static test_return
post_udp_op_check(memcached_st
*memc
, uint16_t *expected_req_ids
)
3522 memcached_server_st
*cur_server
= memc
->hosts
;
3523 uint16_t *cur_req_ids
= get_udp_request_ids(memc
);
3524 for (x
= 0; x
< memc
->number_of_hosts
; x
++)
3526 assert(cur_server
[x
].cursor_active
== 0);
3527 assert(cur_req_ids
[x
] == expected_req_ids
[x
]);
3529 free(expected_req_ids
);
3531 return TEST_SUCCESS
;
3535 ** There is a little bit of a hack here, instead of removing
3536 ** the servers, I just set num host to 0 and them add then new udp servers
3538 static memcached_return
init_udp(memcached_st
*memc
)
3540 memcached_version(memc
);
3541 /* For the time being, only support udp test for >= 1.2.6 && < 1.3 */
3542 if (memc
->hosts
[0].major_version
!= 1 || memc
->hosts
[0].minor_version
!= 2
3543 || memc
->hosts
[0].micro_version
< 6)
3544 return MEMCACHED_FAILURE
;
3546 uint32_t num_hosts
= memc
->number_of_hosts
;
3548 memcached_server_st servers
[num_hosts
];
3549 memcpy(servers
, memc
->hosts
, sizeof(memcached_server_st
) * num_hosts
);
3550 for (x
= 0; x
< num_hosts
; x
++)
3551 memcached_server_free(&memc
->hosts
[x
]);
3552 memc
->number_of_hosts
= 0;
3553 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
, 1);
3554 for (x
= 0; x
< num_hosts
; x
++)
3556 assert(memcached_server_add_udp(memc
, servers
[x
].hostname
, servers
[x
].port
) == MEMCACHED_SUCCESS
);
3557 assert(memc
->hosts
[x
].write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
3559 return MEMCACHED_SUCCESS
;
3562 static memcached_return
binary_init_udp(memcached_st
*memc
)
3565 return init_udp(memc
);
3568 /* Make sure that I cant add a tcp server to a udp client */
3569 static test_return
add_tcp_server_udp_client_test(memcached_st
*memc
)
3571 memcached_server_st server
;
3572 memcached_server_clone(&server
, &memc
->hosts
[0]);
3573 assert(memcached_server_remove(&(memc
->hosts
[0])) == MEMCACHED_SUCCESS
);
3574 assert(memcached_server_add(memc
, server
.hostname
, server
.port
) == MEMCACHED_INVALID_HOST_PROTOCOL
);
3575 return TEST_SUCCESS
;
3578 /* Make sure that I cant add a udp server to a tcp client */
3579 static test_return
add_udp_server_tcp_client_test(memcached_st
*memc
)
3581 memcached_server_st server
;
3582 memcached_server_clone(&server
, &memc
->hosts
[0]);
3583 assert(memcached_server_remove(&(memc
->hosts
[0])) == MEMCACHED_SUCCESS
);
3585 memcached_st tcp_client
;
3586 memcached_create(&tcp_client
);
3587 assert(memcached_server_add_udp(&tcp_client
, server
.hostname
, server
.port
) == MEMCACHED_INVALID_HOST_PROTOCOL
);
3588 return TEST_SUCCESS
;
3591 static test_return
set_udp_behavior_test(memcached_st
*memc
)
3594 memcached_quit(memc
);
3595 memc
->number_of_hosts
= 0;
3596 run_distribution(memc
);
3597 assert(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
, 1) == MEMCACHED_SUCCESS
);
3598 assert(memc
->flags
& MEM_USE_UDP
);
3599 assert(memc
->flags
& MEM_NOREPLY
);;
3601 assert(memc
->number_of_hosts
== 0);
3603 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
,0);
3604 assert(!(memc
->flags
& MEM_USE_UDP
));
3605 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
,0);
3606 assert(!(memc
->flags
& MEM_NOREPLY
));
3607 return TEST_SUCCESS
;
3610 static test_return
udp_set_test(memcached_st
*memc
)
3613 unsigned int num_iters
= 1025; //request id rolls over at 1024
3614 for (x
= 0; x
< num_iters
;x
++)
3616 memcached_return rc
;
3618 char *value
= "when we sanitize";
3619 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3620 unsigned int server_key
= memcached_generate_hash(memc
,key
,strlen(key
));
3621 size_t init_offset
= memc
->hosts
[server_key
].write_buffer_offset
;
3622 rc
= memcached_set(memc
, key
, strlen(key
),
3623 value
, strlen(value
),
3624 (time_t)0, (uint32_t)0);
3625 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
3626 /** NB, the check below assumes that if new write_ptr is less than
3627 * the original write_ptr that we have flushed. For large payloads, this
3628 * maybe an invalid assumption, but for the small payload we have it is OK
3630 if (rc
== MEMCACHED_SUCCESS
||
3631 memc
->hosts
[server_key
].write_buffer_offset
< init_offset
)
3632 increment_request_id(&expected_ids
[server_key
]);
3634 if (rc
== MEMCACHED_SUCCESS
)
3636 assert(memc
->hosts
[server_key
].write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
3640 assert(memc
->hosts
[server_key
].write_buffer_offset
!= UDP_DATAGRAM_HEADER_LENGTH
);
3641 assert(memc
->hosts
[server_key
].write_buffer_offset
<= MAX_UDP_DATAGRAM_LENGTH
);
3643 assert(post_udp_op_check(memc
,expected_ids
) == TEST_SUCCESS
);
3645 return TEST_SUCCESS
;
3648 static test_return
udp_buffered_set_test(memcached_st
*memc
)
3650 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
3651 return udp_set_test(memc
);
3654 static test_return
udp_set_too_big_test(memcached_st
*memc
)
3656 memcached_return rc
;
3658 char value
[MAX_UDP_DATAGRAM_LENGTH
];
3659 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3660 rc
= memcached_set(memc
, key
, strlen(key
),
3661 value
, MAX_UDP_DATAGRAM_LENGTH
,
3662 (time_t)0, (uint32_t)0);
3663 assert(rc
== MEMCACHED_WRITE_FAILURE
);
3664 return post_udp_op_check(memc
,expected_ids
);
3667 static test_return
udp_delete_test(memcached_st
*memc
)
3670 unsigned int num_iters
= 1025; //request id rolls over at 1024
3671 for (x
= 0; x
< num_iters
;x
++)
3673 memcached_return rc
;
3675 uint16_t *expected_ids
=get_udp_request_ids(memc
);
3676 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
3677 size_t init_offset
= memc
->hosts
[server_key
].write_buffer_offset
;
3678 rc
= memcached_delete(memc
, key
, strlen(key
), 0);
3679 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
3680 if (rc
== MEMCACHED_SUCCESS
|| memc
->hosts
[server_key
].write_buffer_offset
< init_offset
)
3681 increment_request_id(&expected_ids
[server_key
]);
3682 if (rc
== MEMCACHED_SUCCESS
)
3683 assert(memc
->hosts
[server_key
].write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
3686 assert(memc
->hosts
[server_key
].write_buffer_offset
!= UDP_DATAGRAM_HEADER_LENGTH
);
3687 assert(memc
->hosts
[server_key
].write_buffer_offset
<= MAX_UDP_DATAGRAM_LENGTH
);
3689 assert(post_udp_op_check(memc
,expected_ids
) == TEST_SUCCESS
);
3691 return TEST_SUCCESS
;
3694 static test_return
udp_buffered_delete_test(memcached_st
*memc
)
3696 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
3697 return udp_delete_test(memc
);
3700 static test_return
udp_verbosity_test(memcached_st
*memc
)
3702 memcached_return rc
;
3703 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3705 for (x
= 0; x
< memc
->number_of_hosts
;x
++)
3706 increment_request_id(&expected_ids
[x
]);
3708 rc
= memcached_verbosity(memc
,3);
3709 assert(rc
== MEMCACHED_SUCCESS
);
3710 return post_udp_op_check(memc
,expected_ids
);
3713 static test_return
udp_quit_test(memcached_st
*memc
)
3715 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3716 memcached_quit(memc
);
3717 return post_udp_op_check(memc
, expected_ids
);
3720 static test_return
udp_flush_test(memcached_st
*memc
)
3722 memcached_return rc
;
3723 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3725 for (x
= 0; x
< memc
->number_of_hosts
;x
++)
3726 increment_request_id(&expected_ids
[x
]);
3728 rc
= memcached_flush(memc
,0);
3729 assert(rc
== MEMCACHED_SUCCESS
);
3730 return post_udp_op_check(memc
,expected_ids
);
3733 static test_return
udp_incr_test(memcached_st
*memc
)
3735 memcached_return rc
;
3738 rc
= memcached_set(memc
, key
, strlen(key
),
3739 value
, strlen(value
),
3740 (time_t)0, (uint32_t)0);
3742 assert(rc
== MEMCACHED_SUCCESS
);
3743 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3744 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
3745 increment_request_id(&expected_ids
[server_key
]);
3747 rc
= memcached_increment(memc
, key
, strlen(key
), 1, &newvalue
);
3748 assert(rc
== MEMCACHED_SUCCESS
);
3749 return post_udp_op_check(memc
, expected_ids
);
3752 static test_return
udp_decr_test(memcached_st
*memc
)
3754 memcached_return rc
;
3757 rc
= memcached_set(memc
, key
, strlen(key
),
3758 value
, strlen(value
),
3759 (time_t)0, (uint32_t)0);
3761 assert(rc
== MEMCACHED_SUCCESS
);
3762 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3763 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
3764 increment_request_id(&expected_ids
[server_key
]);
3766 rc
= memcached_decrement(memc
, key
, strlen(key
), 1, &newvalue
);
3767 assert(rc
== MEMCACHED_SUCCESS
);
3768 return post_udp_op_check(memc
, expected_ids
);
3772 static test_return
udp_stat_test(memcached_st
*memc
)
3774 memcached_stat_st
* rv
= NULL
;
3775 memcached_return rc
;
3777 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3778 rv
= memcached_stat(memc
, args
, &rc
);
3780 assert(rc
== MEMCACHED_NOT_SUPPORTED
);
3781 return post_udp_op_check(memc
, expected_ids
);
3784 static test_return
udp_version_test(memcached_st
*memc
)
3786 memcached_return rc
;
3787 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3788 rc
= memcached_version(memc
);
3789 assert(rc
== MEMCACHED_NOT_SUPPORTED
);
3790 return post_udp_op_check(memc
, expected_ids
);
3793 static test_return
udp_get_test(memcached_st
*memc
)
3795 memcached_return rc
;
3798 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3799 char *val
= memcached_get(memc
, key
, strlen(key
), &vlen
, (uint32_t)0, &rc
);
3800 assert(rc
== MEMCACHED_NOT_SUPPORTED
);
3801 assert(val
== NULL
);
3802 return post_udp_op_check(memc
, expected_ids
);
3805 static test_return
udp_mixed_io_test(memcached_st
*memc
)
3808 test_st mixed_io_ops
[] ={
3809 {"udp_set_test", 0, udp_set_test
},
3810 {"udp_set_too_big_test", 0, udp_set_too_big_test
},
3811 {"udp_delete_test", 0, udp_delete_test
},
3812 {"udp_verbosity_test", 0, udp_verbosity_test
},
3813 {"udp_quit_test", 0, udp_quit_test
},
3814 {"udp_flush_test", 0, udp_flush_test
},
3815 {"udp_incr_test", 0, udp_incr_test
},
3816 {"udp_decr_test", 0, udp_decr_test
},
3817 {"udp_version_test", 0, udp_version_test
}
3820 for (x
= 0; x
< 500; x
++)
3822 current_op
= mixed_io_ops
[random() % 9];
3823 assert(current_op
.function(memc
) == TEST_SUCCESS
);
3825 return TEST_SUCCESS
;
3828 static test_return
hsieh_avaibility_test (memcached_st
*memc
)
3830 memcached_return expected_rc
= MEMCACHED_FAILURE
;
3831 #ifdef HAVE_HSIEH_HASH
3832 expected_rc
= MEMCACHED_SUCCESS
;
3834 memcached_return rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
,
3835 (uint64_t)MEMCACHED_HASH_HSIEH
);
3836 assert(rc
== expected_rc
);
3837 return TEST_SUCCESS
;
3840 static char *list
[]=
3870 static test_return
md5_run (memcached_st
*memc
__attribute__((unused
)))
3874 uint32_t values
[]= { 3195025439, 2556848621, 3724893440, 3332385401, 245758794, 2550894432,
3875 121710495, 3053817768, 1250994555, 1862072655, 2631955953, 2951528551,
3876 1451250070, 2820856945, 2060845566, 3646985608, 2138080750, 217675895,
3877 2230934345, 1234361223, 3968582726, 2455685270, 1293568479, 199067604,
3881 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
3885 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MD5
);
3886 assert(values
[x
] == hash_val
);
3889 return TEST_SUCCESS
;
3892 static test_return
crc_run (memcached_st
*memc
__attribute__((unused
)))
3896 uint32_t values
[]= { 10542, 22009, 14526, 19510, 19432, 10199, 20634, 9369, 11511, 10362,
3897 7893, 31289, 11313, 9354, 7621, 30628, 15218, 25967, 2695, 9380,
3898 17300, 28156, 9192, 20484, 16925 };
3900 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
3904 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_CRC
);
3905 assert(values
[x
] == hash_val
);
3908 return TEST_SUCCESS
;
3911 static test_return
fnv1_64_run (memcached_st
*memc
__attribute__((unused
)))
3915 uint32_t values
[]= { 473199127, 4148981457, 3971873300, 3257986707, 1722477987, 2991193800,
3916 4147007314, 3633179701, 1805162104, 3503289120, 3395702895, 3325073042,
3917 2345265314, 3340346032, 2722964135, 1173398992, 2815549194, 2562818319,
3918 224996066, 2680194749, 3035305390, 246890365, 2395624193, 4145193337,
3921 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
3925 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_64
);
3926 assert(values
[x
] == hash_val
);
3929 return TEST_SUCCESS
;
3932 static test_return
fnv1a_64_run (memcached_st
*memc
__attribute__((unused
)))
3936 uint32_t values
[]= { 1488911807, 2500855813, 1510099634, 1390325195, 3647689787, 3241528582,
3937 1669328060, 2604311949, 734810122, 1516407546, 560948863, 1767346780,
3938 561034892, 4156330026, 3716417003, 3475297030, 1518272172, 227211583,
3939 3938128828, 126112909, 3043416448, 3131561933, 1328739897, 2455664041,
3942 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
3946 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_64
);
3947 assert(values
[x
] == hash_val
);
3950 return TEST_SUCCESS
;
3953 static test_return
fnv1_32_run (memcached_st
*memc
__attribute__((unused
)))
3957 uint32_t values
[]= { 67176023, 1190179409, 2043204404, 3221866419, 2567703427, 3787535528, 4147287986,
3958 3500475733, 344481048, 3865235296, 2181839183, 119581266, 510234242, 4248244304,
3959 1362796839, 103389328, 1449620010, 182962511, 3554262370, 3206747549, 1551306158,
3960 4127558461, 1889140833, 2774173721, 1180552018 };
3963 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
3967 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_32
);
3968 assert(values
[x
] == hash_val
);
3971 return TEST_SUCCESS
;
3974 static test_return
fnv1a_32_run (memcached_st
*memc
__attribute__((unused
)))
3978 uint32_t values
[]= { 280767167, 2421315013, 3072375666, 855001899, 459261019, 3521085446, 18738364,
3979 1625305005, 2162232970, 777243802, 3323728671, 132336572, 3654473228, 260679466,
3980 1169454059, 2698319462, 1062177260, 235516991, 2218399068, 405302637, 1128467232,
3981 3579622413, 2138539289, 96429129, 2877453236 };
3983 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
3987 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_32
);
3988 assert(values
[x
] == hash_val
);
3991 return TEST_SUCCESS
;
3994 static test_return
hsieh_run (memcached_st
*memc
__attribute__((unused
)))
3998 #ifdef HAVE_HSIEH_HASH
3999 uint32_t values
[]= { 3738850110, 3636226060, 3821074029, 3489929160, 3485772682, 80540287,
4000 1805464076, 1895033657, 409795758, 979934958, 3634096985, 1284445480,
4001 2265380744, 707972988, 353823508, 1549198350, 1327930172, 9304163,
4002 4220749037, 2493964934, 2777873870, 2057831732, 1510213931, 2027828987,
4005 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 };
4008 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4012 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_HSIEH
);
4013 assert(values
[x
] == hash_val
);
4016 return TEST_SUCCESS
;
4019 static test_return
murmur_run (memcached_st
*memc
__attribute__((unused
)))
4023 uint32_t values
[]= { 473199127, 4148981457, 3971873300, 3257986707, 1722477987, 2991193800,
4024 4147007314, 3633179701, 1805162104, 3503289120, 3395702895, 3325073042,
4025 2345265314, 3340346032, 2722964135, 1173398992, 2815549194, 2562818319,
4026 224996066, 2680194749, 3035305390, 246890365, 2395624193, 4145193337,
4029 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4033 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_64
);
4034 assert(values
[x
] == hash_val
);
4037 return TEST_SUCCESS
;
4040 static test_return
jenkins_run (memcached_st
*memc
__attribute__((unused
)))
4044 uint32_t values
[]= { 1442444624, 4253821186, 1885058256, 2120131735, 3261968576, 3515188778,
4045 4232909173, 4288625128, 1812047395, 3689182164, 2502979932, 1214050606,
4046 2415988847, 1494268927, 1025545760, 3920481083, 4153263658, 3824871822,
4047 3072759809, 798622255, 3065432577, 1453328165, 2691550971, 3408888387,
4051 for (ptr
= list
, x
= 0; *ptr
; ptr
++, x
++)
4055 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_JENKINS
);
4056 assert(values
[x
] == hash_val
);
4059 return TEST_SUCCESS
;
4062 test_st udp_setup_server_tests
[] ={
4063 {"set_udp_behavior_test", 0, set_udp_behavior_test
},
4064 {"add_tcp_server_udp_client_test", 0, add_tcp_server_udp_client_test
},
4065 {"add_udp_server_tcp_client_test", 0, add_udp_server_tcp_client_test
},
4069 test_st upd_io_tests
[] ={
4070 {"udp_set_test", 0, udp_set_test
},
4071 {"udp_buffered_set_test", 0, udp_buffered_set_test
},
4072 {"udp_set_too_big_test", 0, udp_set_too_big_test
},
4073 {"udp_delete_test", 0, udp_delete_test
},
4074 {"udp_buffered_delete_test", 0, udp_buffered_delete_test
},
4075 {"udp_verbosity_test", 0, udp_verbosity_test
},
4076 {"udp_quit_test", 0, udp_quit_test
},
4077 {"udp_flush_test", 0, udp_flush_test
},
4078 {"udp_incr_test", 0, udp_incr_test
},
4079 {"udp_decr_test", 0, udp_decr_test
},
4080 {"udp_stat_test", 0, udp_stat_test
},
4081 {"udp_version_test", 0, udp_version_test
},
4082 {"udp_get_test", 0, udp_get_test
},
4083 {"udp_mixed_io_test", 0, udp_mixed_io_test
},
4087 /* Clean the server before beginning testing */
4089 {"flush", 0, flush_test
},
4090 {"init", 0, init_test
},
4091 {"allocation", 0, allocation_test
},
4092 {"server_list_null_test", 0, server_list_null_test
},
4093 {"server_unsort", 0, server_unsort_test
},
4094 {"server_sort", 0, server_sort_test
},
4095 {"server_sort2", 0, server_sort2_test
},
4096 {"clone_test", 0, clone_test
},
4097 {"connection_test", 0, connection_test
},
4098 {"callback_test", 0, callback_test
},
4099 {"behavior_test", 0, behavior_test
},
4100 {"error", 0, error_test
},
4101 {"set", 0, set_test
},
4102 {"set2", 0, set_test2
},
4103 {"set3", 0, set_test3
},
4104 {"dump", 1, dump_test
},
4105 {"add", 1, add_test
},
4106 {"replace", 1, replace_test
},
4107 {"delete", 1, delete_test
},
4108 {"get", 1, get_test
},
4109 {"get2", 0, get_test2
},
4110 {"get3", 0, get_test3
},
4111 {"get4", 0, get_test4
},
4112 {"partial mget", 0, get_test5
},
4113 {"stats_servername", 0, stats_servername_test
},
4114 {"increment", 0, increment_test
},
4115 {"increment_with_initial", 1, increment_with_initial_test
},
4116 {"decrement", 0, decrement_test
},
4117 {"decrement_with_initial", 1, decrement_with_initial_test
},
4118 {"quit", 0, quit_test
},
4119 {"mget", 1, mget_test
},
4120 {"mget_result", 1, mget_result_test
},
4121 {"mget_result_alloc", 1, mget_result_alloc_test
},
4122 {"mget_result_function", 1, mget_result_function
},
4123 {"get_stats", 0, get_stats
},
4124 {"add_host_test", 0, add_host_test
},
4125 {"add_host_test_1", 0, add_host_test1
},
4126 {"get_stats_keys", 0, get_stats_keys
},
4127 {"behavior_test", 0, get_stats_keys
},
4128 {"callback_test", 0, get_stats_keys
},
4129 {"version_string_test", 0, version_string_test
},
4130 {"bad_key", 1, bad_key_test
},
4131 {"memcached_server_cursor", 1, memcached_server_cursor_test
},
4132 {"read_through", 1, read_through
},
4133 {"delete_through", 1, delete_through
},
4134 {"noreply", 1, noreply_test
},
4135 {"analyzer", 1, analyzer_test
},
4136 #ifdef HAVE_LIBMEMCACHEDUTIL
4137 {"connectionpool", 1, connection_pool_test
},
4142 test_st async_tests
[] ={
4143 {"add", 1, add_wrapper
},
4147 test_st string_tests
[] ={
4148 {"string static with null", 0, string_static_null
},
4149 {"string alloc with null", 0, string_alloc_null
},
4150 {"string alloc with 1K", 0, string_alloc_with_size
},
4151 {"string alloc with malloc failure", 0, string_alloc_with_size_toobig
},
4152 {"string append", 0, string_alloc_append
},
4153 {"string append failure (too big)", 0, string_alloc_append_toobig
},
4157 test_st result_tests
[] ={
4158 {"result static", 0, result_static
},
4159 {"result alloc", 0, result_alloc
},
4163 test_st version_1_2_3
[] ={
4164 {"append", 0, append_test
},
4165 {"prepend", 0, prepend_test
},
4166 {"cas", 0, cas_test
},
4167 {"cas2", 0, cas2_test
},
4168 {"append_binary", 0, append_binary_test
},
4172 test_st user_tests
[] ={
4173 {"user_supplied_bug1", 0, user_supplied_bug1
},
4174 {"user_supplied_bug2", 0, user_supplied_bug2
},
4175 {"user_supplied_bug3", 0, user_supplied_bug3
},
4176 {"user_supplied_bug4", 0, user_supplied_bug4
},
4177 {"user_supplied_bug5", 1, user_supplied_bug5
},
4178 {"user_supplied_bug6", 1, user_supplied_bug6
},
4179 {"user_supplied_bug7", 1, user_supplied_bug7
},
4180 {"user_supplied_bug8", 1, user_supplied_bug8
},
4181 {"user_supplied_bug9", 1, user_supplied_bug9
},
4182 {"user_supplied_bug10", 1, user_supplied_bug10
},
4183 {"user_supplied_bug11", 1, user_supplied_bug11
},
4184 {"user_supplied_bug12", 1, user_supplied_bug12
},
4185 {"user_supplied_bug13", 1, user_supplied_bug13
},
4186 {"user_supplied_bug14", 1, user_supplied_bug14
},
4187 {"user_supplied_bug15", 1, user_supplied_bug15
},
4188 {"user_supplied_bug16", 1, user_supplied_bug16
},
4191 ** It seems to be something weird with the character sets..
4192 ** value_fetch is unable to parse the value line (iscntrl "fails"), so I
4193 ** guess I need to find out how this is supposed to work.. Perhaps I need
4194 ** to run the test in a specific locale (I tried zh_CN.UTF-8 without success,
4195 ** so just disable the code for now...).
4197 {"user_supplied_bug17", 1, user_supplied_bug17
},
4199 {"user_supplied_bug18", 1, user_supplied_bug18
},
4200 {"user_supplied_bug19", 1, user_supplied_bug19
},
4201 {"user_supplied_bug20", 1, user_supplied_bug20
},
4205 test_st generate_tests
[] ={
4206 {"generate_pairs", 1, generate_pairs
},
4207 {"generate_data", 1, generate_data
},
4208 {"get_read", 0, get_read
},
4209 {"delete_generate", 0, delete_generate
},
4210 {"generate_buffer_data", 1, generate_buffer_data
},
4211 {"delete_buffer", 0, delete_buffer_generate
},
4212 {"generate_data", 1, generate_data
},
4213 {"mget_read", 0, mget_read
},
4214 {"mget_read_result", 0, mget_read_result
},
4215 {"mget_read_function", 0, mget_read_function
},
4216 {"cleanup", 1, cleanup_pairs
},
4217 {"generate_large_pairs", 1, generate_large_pairs
},
4218 {"generate_data", 1, generate_data
},
4219 {"generate_buffer_data", 1, generate_buffer_data
},
4220 {"cleanup", 1, cleanup_pairs
},
4224 test_st consistent_tests
[] ={
4225 {"generate_pairs", 1, generate_pairs
},
4226 {"generate_data", 1, generate_data
},
4227 {"get_read", 0, get_read_count
},
4228 {"cleanup", 1, cleanup_pairs
},
4232 test_st consistent_weighted_tests
[] ={
4233 {"generate_pairs", 1, generate_pairs
},
4234 {"generate_data", 1, generate_data_with_stats
},
4235 {"get_read", 0, get_read_count
},
4236 {"cleanup", 1, cleanup_pairs
},
4240 test_st hsieh_availability
[] ={
4241 {"hsieh_avaibility_test",0,hsieh_avaibility_test
},
4245 test_st ketama_auto_eject_hosts
[] ={
4246 {"auto_eject_hosts", 1, auto_eject_hosts
},
4250 test_st hash_tests
[] ={
4251 {"md5", 0, md5_run
},
4252 {"crc", 0, crc_run
},
4253 {"fnv1_64", 0, fnv1_64_run
},
4254 {"fnv1a_64", 0, fnv1a_64_run
},
4255 {"fnv1_32", 0, fnv1_32_run
},
4256 {"fnv1a_32", 0, fnv1a_32_run
},
4257 {"hsieh", 0, hsieh_run
},
4258 {"murmur", 0, murmur_run
},
4259 {"jenkis", 0, jenkins_run
},
4263 collection_st collection
[] ={
4264 {"hsieh_availability",0,0,hsieh_availability
},
4265 {"udp_setup", init_udp
, 0, udp_setup_server_tests
},
4266 {"udp_io", init_udp
, 0, upd_io_tests
},
4267 {"udp_binary_io", binary_init_udp
, 0, upd_io_tests
},
4268 {"block", 0, 0, tests
},
4269 {"binary", pre_binary
, 0, tests
},
4270 {"nonblock", pre_nonblock
, 0, tests
},
4271 {"nodelay", pre_nodelay
, 0, tests
},
4272 {"settimer", pre_settimer
, 0, tests
},
4273 {"md5", pre_md5
, 0, tests
},
4274 {"crc", pre_crc
, 0, tests
},
4275 {"hsieh", pre_hsieh
, 0, tests
},
4276 {"jenkins", pre_jenkins
, 0, tests
},
4277 {"fnv1_64", pre_hash_fnv1_64
, 0, tests
},
4278 {"fnv1a_64", pre_hash_fnv1a_64
, 0, tests
},
4279 {"fnv1_32", pre_hash_fnv1_32
, 0, tests
},
4280 {"fnv1a_32", pre_hash_fnv1a_32
, 0, tests
},
4281 {"ketama", pre_behavior_ketama
, 0, tests
},
4282 {"ketama_auto_eject_hosts", pre_behavior_ketama
, 0, ketama_auto_eject_hosts
},
4283 {"unix_socket", pre_unix_socket
, 0, tests
},
4284 {"unix_socket_nodelay", pre_nodelay
, 0, tests
},
4285 {"poll_timeout", poll_timeout
, 0, tests
},
4286 {"gets", enable_cas
, 0, tests
},
4287 {"consistent", enable_consistent
, 0, tests
},
4288 {"memory_allocators", set_memory_alloc
, 0, tests
},
4289 {"prefix", set_prefix
, 0, tests
},
4290 {"version_1_2_3", check_for_1_2_3
, 0, version_1_2_3
},
4291 {"string", 0, 0, string_tests
},
4292 {"result", 0, 0, result_tests
},
4293 {"async", pre_nonblock
, 0, async_tests
},
4294 {"async_binary", pre_nonblock_binary
, 0, async_tests
},
4295 {"user", 0, 0, user_tests
},
4296 {"generate", 0, 0, generate_tests
},
4297 {"generate_hsieh", pre_hsieh
, 0, generate_tests
},
4298 {"generate_ketama", pre_behavior_ketama
, 0, generate_tests
},
4299 {"generate_hsieh_consistent", enable_consistent
, 0, generate_tests
},
4300 {"generate_md5", pre_md5
, 0, generate_tests
},
4301 {"generate_murmur", pre_murmur
, 0, generate_tests
},
4302 {"generate_jenkins", pre_jenkins
, 0, generate_tests
},
4303 {"generate_nonblock", pre_nonblock
, 0, generate_tests
},
4304 {"consistent_not", 0, 0, consistent_tests
},
4305 {"consistent_ketama", pre_behavior_ketama
, 0, consistent_tests
},
4306 {"consistent_ketama_weighted", pre_behavior_ketama_weighted
, 0, consistent_weighted_tests
},
4307 {"test_hashes", 0, 0, hash_tests
},
4311 #define SERVERS_TO_CREATE 5
4313 /* Prototypes for functions we will pass to test framework */
4314 void *world_create(void);
4315 void world_destroy(void *p
);
4317 void *world_create(void)
4319 server_startup_st
*construct
;
4321 construct
= (server_startup_st
*)malloc(sizeof(server_startup_st
));
4322 memset(construct
, 0, sizeof(server_startup_st
));
4323 construct
->count
= SERVERS_TO_CREATE
;
4325 server_startup(construct
);
4331 void world_destroy(void *p
)
4333 server_startup_st
*construct
= (server_startup_st
*)p
;
4334 memcached_server_st
*servers
= (memcached_server_st
*)construct
->servers
;
4335 memcached_server_list_free(servers
);
4337 server_shutdown(construct
);
4341 void get_world(world_st
*world
)
4343 world
->collections
= collection
;
4344 world
->create
= world_create
;
4345 world
->destroy
= world_destroy
;