2 Sample test application.
14 #include "../clients/generator.h"
15 #include "../clients/execute.h"
18 #define INT64_MAX LONG_MAX
21 #define INT32_MAX INT_MAX
27 #define GLOBAL_COUNT 10000
28 #define GLOBAL2_COUNT 100
29 #define SERVERS_TO_CREATE 5
30 static uint32_t global_count
;
32 static pairs_st
*global_pairs
;
33 static char *global_keys
[GLOBAL_COUNT
];
34 static size_t global_keys_length
[GLOBAL_COUNT
];
36 static test_return
init_test(memcached_st
*not_used
__attribute__((unused
)))
40 (void)memcached_create(&memc
);
41 memcached_free(&memc
);
46 static test_return
server_list_null_test(memcached_st
*ptr
__attribute__((unused
)))
48 memcached_server_st
*server_list
;
51 server_list
= memcached_server_list_append_with_weight(NULL
, NULL
, 0, 0, NULL
);
52 assert(server_list
== NULL
);
54 server_list
= memcached_server_list_append_with_weight(NULL
, "localhost", 0, 0, NULL
);
55 assert(server_list
== NULL
);
57 server_list
= memcached_server_list_append_with_weight(NULL
, NULL
, 0, 0, &rc
);
58 assert(server_list
== NULL
);
63 #define TEST_PORT_COUNT 7
64 uint32_t test_ports
[TEST_PORT_COUNT
];
66 static memcached_return
server_display_function(memcached_st
*ptr
__attribute__((unused
)), memcached_server_st
*server
, void *context
)
69 uint32_t bigger
= *((uint32_t *)(context
));
70 assert(bigger
<= server
->port
);
71 *((uint32_t *)(context
))= server
->port
;
73 return MEMCACHED_SUCCESS
;
76 static test_return
server_sort_test(memcached_st
*ptr
__attribute__((unused
)))
79 uint32_t bigger
= 0; /* Prime the value for the assert in server_display_function */
81 memcached_server_function callbacks
[1];
82 memcached_st
*local_memc
;
84 local_memc
= memcached_create(NULL
);
86 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
88 for (x
= 0; x
< TEST_PORT_COUNT
; x
++)
90 test_ports
[x
]= random() % 64000;
91 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
92 assert(local_memc
->number_of_hosts
== x
+ 1);
93 assert(local_memc
->hosts
[0].count
== x
+1);
94 assert(rc
== MEMCACHED_SUCCESS
);
97 callbacks
[0]= server_display_function
;
98 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
101 memcached_free(local_memc
);
106 static test_return
server_sort2_test(memcached_st
*ptr
__attribute__((unused
)))
108 uint32_t bigger
= 0; /* Prime the value for the assert in server_display_function */
110 memcached_server_function callbacks
[1];
111 memcached_st
*local_memc
;
113 local_memc
= memcached_create(NULL
);
115 rc
= memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
116 assert(rc
== MEMCACHED_SUCCESS
);
118 rc
= memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43043, 0);
119 assert(rc
== MEMCACHED_SUCCESS
);
120 assert(local_memc
->hosts
[0].port
== 43043);
122 rc
= memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43042, 0);
123 assert(rc
== MEMCACHED_SUCCESS
);
124 assert(local_memc
->hosts
[0].port
== 43042);
125 assert(local_memc
->hosts
[1].port
== 43043);
127 callbacks
[0]= server_display_function
;
128 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
131 memcached_free(local_memc
);
136 static memcached_return
server_display_unsort_function(memcached_st
*ptr
__attribute__((unused
)), memcached_server_st
*server
, void *context
)
139 uint32_t x
= *((uint32_t *)(context
));
141 assert(test_ports
[x
] == server
->port
);
142 *((uint32_t *)(context
))= ++x
;
144 return MEMCACHED_SUCCESS
;
147 static test_return
server_unsort_test(memcached_st
*ptr
__attribute__((unused
)))
150 uint32_t counter
= 0; /* Prime the value for the assert in server_display_function */
151 uint32_t bigger
= 0; /* Prime the value for the assert in server_display_function */
153 memcached_server_function callbacks
[1];
154 memcached_st
*local_memc
;
156 local_memc
= memcached_create(NULL
);
159 for (x
= 0; x
< TEST_PORT_COUNT
; x
++)
161 test_ports
[x
]= random() % 64000;
162 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
163 assert(local_memc
->number_of_hosts
== x
+1);
164 assert(local_memc
->hosts
[0].count
== x
+1);
165 assert(rc
== MEMCACHED_SUCCESS
);
168 callbacks
[0]= server_display_unsort_function
;
169 memcached_server_cursor(local_memc
, callbacks
, (void *)&counter
, 1);
171 /* Now we sort old data! */
172 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
173 callbacks
[0]= server_display_function
;
174 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
177 memcached_free(local_memc
);
182 static test_return
allocation_test(memcached_st
*not_used
__attribute__((unused
)))
185 memc
= memcached_create(NULL
);
187 memcached_free(memc
);
192 static test_return
clone_test(memcached_st
*memc
)
197 clone
= memcached_clone(NULL
, NULL
);
199 memcached_free(clone
);
202 /* Can we init from null? */
205 clone
= memcached_clone(NULL
, memc
);
208 assert(clone
->call_free
== memc
->call_free
);
209 assert(clone
->call_malloc
== memc
->call_malloc
);
210 assert(clone
->call_realloc
== memc
->call_realloc
);
211 assert(clone
->connect_timeout
== memc
->connect_timeout
);
212 assert(clone
->delete_trigger
== memc
->delete_trigger
);
213 assert(clone
->distribution
== memc
->distribution
);
214 assert(clone
->flags
== memc
->flags
);
215 assert(clone
->get_key_failure
== memc
->get_key_failure
);
216 assert(clone
->hash
== memc
->hash
);
217 assert(clone
->hash_continuum
== memc
->hash_continuum
);
218 assert(clone
->io_bytes_watermark
== memc
->io_bytes_watermark
);
219 assert(clone
->io_msg_watermark
== memc
->io_msg_watermark
);
220 assert(clone
->on_cleanup
== memc
->on_cleanup
);
221 assert(clone
->on_clone
== memc
->on_clone
);
222 assert(clone
->poll_timeout
== memc
->poll_timeout
);
223 assert(clone
->rcv_timeout
== memc
->rcv_timeout
);
224 assert(clone
->recv_size
== memc
->recv_size
);
225 assert(clone
->retry_timeout
== memc
->retry_timeout
);
226 assert(clone
->send_size
== memc
->send_size
);
227 assert(clone
->server_failure_limit
== memc
->server_failure_limit
);
228 assert(clone
->snd_timeout
== memc
->snd_timeout
);
229 assert(clone
->user_data
== memc
->user_data
);
231 memcached_free(clone
);
234 /* Can we init from struct? */
236 memcached_st declared_clone
;
238 memset(&declared_clone
, 0 , sizeof(memcached_st
));
239 clone
= memcached_clone(&declared_clone
, NULL
);
241 memcached_free(clone
);
244 /* Can we init from struct? */
246 memcached_st declared_clone
;
248 memset(&declared_clone
, 0 , sizeof(memcached_st
));
249 clone
= memcached_clone(&declared_clone
, memc
);
251 memcached_free(clone
);
257 static test_return
connection_test(memcached_st
*memc
)
261 rc
= memcached_server_add_with_weight(memc
, "localhost", 0, 0);
262 assert(rc
== MEMCACHED_SUCCESS
);
267 static test_return
error_test(memcached_st
*memc
)
271 for (rc
= MEMCACHED_SUCCESS
; rc
< MEMCACHED_MAXIMUM_RETURN
; rc
++)
273 printf("Error %d -> %s\n", rc
, memcached_strerror(memc
, rc
));
279 static test_return
set_test(memcached_st
*memc
)
283 char *value
= "when we sanitize";
285 rc
= memcached_set(memc
, key
, strlen(key
),
286 value
, strlen(value
),
287 (time_t)0, (uint32_t)0);
288 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
293 static test_return
append_test(memcached_st
*memc
)
301 rc
= memcached_flush(memc
, 0);
302 assert(rc
== MEMCACHED_SUCCESS
);
304 rc
= memcached_set(memc
, key
, strlen(key
),
305 value
, strlen(value
),
306 (time_t)0, (uint32_t)0);
307 assert(rc
== MEMCACHED_SUCCESS
);
309 rc
= memcached_append(memc
, key
, strlen(key
),
310 " the", strlen(" the"),
311 (time_t)0, (uint32_t)0);
312 assert(rc
== MEMCACHED_SUCCESS
);
314 rc
= memcached_append(memc
, key
, strlen(key
),
315 " people", strlen(" people"),
316 (time_t)0, (uint32_t)0);
317 assert(rc
== MEMCACHED_SUCCESS
);
319 value
= memcached_get(memc
, key
, strlen(key
),
320 &value_length
, &flags
, &rc
);
321 assert(!memcmp(value
, "we the people", strlen("we the people")));
322 assert(strlen("we the people") == value_length
);
323 assert(rc
== MEMCACHED_SUCCESS
);
329 static test_return
append_binary_test(memcached_st
*memc
)
332 char *key
= "numbers";
333 unsigned int *store_ptr
;
334 unsigned int store_list
[] = { 23, 56, 499, 98, 32847, 0 };
340 rc
= memcached_flush(memc
, 0);
341 assert(rc
== MEMCACHED_SUCCESS
);
343 rc
= memcached_set(memc
,
346 (time_t)0, (uint32_t)0);
347 assert(rc
== MEMCACHED_SUCCESS
);
349 for (x
= 0; store_list
[x
] ; x
++)
351 rc
= memcached_append(memc
,
353 (char *)&store_list
[x
], sizeof(unsigned int),
354 (time_t)0, (uint32_t)0);
355 assert(rc
== MEMCACHED_SUCCESS
);
358 value
= memcached_get(memc
, key
, strlen(key
),
359 &value_length
, &flags
, &rc
);
360 assert((value_length
== (sizeof(unsigned int) * x
)));
361 assert(rc
== MEMCACHED_SUCCESS
);
363 store_ptr
= (unsigned int *)value
;
365 while ((size_t)store_ptr
< (size_t)(value
+ value_length
))
367 assert(*store_ptr
== store_list
[x
++]);
375 static test_return
cas2_test(memcached_st
*memc
)
378 char *keys
[]= {"fudge", "son", "food"};
379 size_t key_length
[]= {5, 3, 4};
380 char *value
= "we the people";
381 size_t value_length
= strlen("we the people");
383 memcached_result_st results_obj
;
384 memcached_result_st
*results
;
387 rc
= memcached_flush(memc
, 0);
388 assert(rc
== MEMCACHED_SUCCESS
);
390 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
392 for (x
= 0; x
< 3; x
++)
394 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
395 keys
[x
], key_length
[x
],
396 (time_t)50, (uint32_t)9);
397 assert(rc
== MEMCACHED_SUCCESS
);
400 rc
= memcached_mget(memc
, keys
, key_length
, 3);
402 results
= memcached_result_create(memc
, &results_obj
);
404 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
406 assert(results
->cas
);
407 assert(rc
== MEMCACHED_SUCCESS
);
408 WATCHPOINT_ASSERT(memcached_result_cas(results
));
410 assert(!memcmp(value
, "we the people", strlen("we the people")));
411 assert(strlen("we the people") == value_length
);
412 assert(rc
== MEMCACHED_SUCCESS
);
414 memcached_result_free(&results_obj
);
419 static test_return
cas_test(memcached_st
*memc
)
422 const char *key
= "fun";
423 size_t key_length
= strlen(key
);
424 const char *value
= "we the people";
425 char* keys
[2] = { (char*)key
, NULL
};
426 size_t keylengths
[2] = { strlen(key
), 0 };
427 size_t value_length
= strlen(value
);
428 const char *value2
= "change the value";
429 size_t value2_length
= strlen(value2
);
431 memcached_result_st results_obj
;
432 memcached_result_st
*results
;
435 rc
= memcached_flush(memc
, 0);
436 assert(rc
== MEMCACHED_SUCCESS
);
438 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
440 rc
= memcached_set(memc
, key
, strlen(key
),
441 value
, strlen(value
),
442 (time_t)0, (uint32_t)0);
443 assert(rc
== MEMCACHED_SUCCESS
);
445 rc
= memcached_mget(memc
, keys
, keylengths
, 1);
447 results
= memcached_result_create(memc
, &results_obj
);
449 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
451 assert(rc
== MEMCACHED_SUCCESS
);
452 WATCHPOINT_ASSERT(memcached_result_cas(results
));
453 assert(!memcmp(value
, memcached_result_value(results
), value_length
));
454 assert(strlen(memcached_result_value(results
)) == value_length
);
455 assert(rc
== MEMCACHED_SUCCESS
);
456 uint64_t cas
= memcached_result_cas(results
);
459 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
460 assert(rc
== MEMCACHED_END
);
461 assert(results
== NULL
);
464 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
465 assert(rc
== MEMCACHED_SUCCESS
);
468 * The item will have a new cas value, so try to set it again with the old
469 * value. This should fail!
471 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
472 assert(rc
== MEMCACHED_DATA_EXISTS
);
474 memcached_result_free(&results_obj
);
479 static test_return
prepend_test(memcached_st
*memc
)
483 char *value
= "people";
487 rc
= memcached_flush(memc
, 0);
488 assert(rc
== MEMCACHED_SUCCESS
);
490 rc
= memcached_set(memc
, key
, strlen(key
),
491 value
, strlen(value
),
492 (time_t)0, (uint32_t)0);
493 assert(rc
== MEMCACHED_SUCCESS
);
495 rc
= memcached_prepend(memc
, key
, strlen(key
),
496 "the ", strlen("the "),
497 (time_t)0, (uint32_t)0);
498 assert(rc
== MEMCACHED_SUCCESS
);
500 rc
= memcached_prepend(memc
, key
, strlen(key
),
501 "we ", strlen("we "),
502 (time_t)0, (uint32_t)0);
503 assert(rc
== MEMCACHED_SUCCESS
);
505 value
= memcached_get(memc
, key
, strlen(key
),
506 &value_length
, &flags
, &rc
);
507 assert(!memcmp(value
, "we the people", strlen("we the people")));
508 assert(strlen("we the people") == value_length
);
509 assert(rc
== MEMCACHED_SUCCESS
);
516 Set the value, then quit to make sure it is flushed.
517 Come back in and test that add fails.
519 static test_return
add_test(memcached_st
*memc
)
523 char *value
= "when we sanitize";
524 unsigned long long setting_value
;
526 setting_value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
528 rc
= memcached_set(memc
, key
, strlen(key
),
529 value
, strlen(value
),
530 (time_t)0, (uint32_t)0);
531 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
532 memcached_quit(memc
);
533 rc
= memcached_add(memc
, key
, strlen(key
),
534 value
, strlen(value
),
535 (time_t)0, (uint32_t)0);
537 /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */
539 assert(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_STORED
);
541 assert(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_DATA_EXISTS
);
547 ** There was a problem of leaking filedescriptors in the initial release
548 ** of MacOSX 10.5. This test case triggers the problem. On some Solaris
549 ** systems it seems that the kernel is slow on reclaiming the resources
550 ** because the connects starts to time out (the test doesn't do much
551 ** anyway, so just loop 10 iterations)
553 static test_return
add_wrapper(memcached_st
*memc
)
556 unsigned int max
= 10000;
561 for (x
= 0; x
< max
; x
++)
567 static test_return
replace_test(memcached_st
*memc
)
571 char *value
= "when we sanitize";
572 char *original
= "first we insert some data";
574 rc
= memcached_set(memc
, key
, strlen(key
),
575 original
, strlen(original
),
576 (time_t)0, (uint32_t)0);
577 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
579 rc
= memcached_replace(memc
, key
, strlen(key
),
580 value
, strlen(value
),
581 (time_t)0, (uint32_t)0);
582 assert(rc
== MEMCACHED_SUCCESS
);
587 static test_return
delete_test(memcached_st
*memc
)
591 char *value
= "when we sanitize";
593 rc
= memcached_set(memc
, key
, strlen(key
),
594 value
, strlen(value
),
595 (time_t)0, (uint32_t)0);
596 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
598 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
599 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
604 static test_return
flush_test(memcached_st
*memc
)
608 rc
= memcached_flush(memc
, 0);
609 assert(rc
== MEMCACHED_SUCCESS
);
614 static memcached_return
server_function(memcached_st
*ptr
__attribute__((unused
)),
615 memcached_server_st
*server
__attribute__((unused
)),
616 void *context
__attribute__((unused
)))
620 return MEMCACHED_SUCCESS
;
623 static test_return
memcached_server_cursor_test(memcached_st
*memc
)
625 char *context
= "foo bad";
626 memcached_server_function callbacks
[1];
628 callbacks
[0]= server_function
;
629 memcached_server_cursor(memc
, callbacks
, context
, 1);
634 static test_return
bad_key_test(memcached_st
*memc
)
637 char *key
= "foo bad";
639 size_t string_length
;
643 size_t max_keylen
= 0xffff;
645 clone
= memcached_clone(NULL
, memc
);
648 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
649 assert(rc
== MEMCACHED_SUCCESS
);
651 /* All keys are valid in the binary protocol (except for length) */
652 if (memcached_behavior_get(clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 0)
654 string
= memcached_get(clone
, key
, strlen(key
),
655 &string_length
, &flags
, &rc
);
656 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
657 assert(string_length
== 0);
661 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
662 assert(rc
== MEMCACHED_SUCCESS
);
663 string
= memcached_get(clone
, key
, strlen(key
),
664 &string_length
, &flags
, &rc
);
665 assert(rc
== MEMCACHED_NOTFOUND
);
666 assert(string_length
== 0);
669 /* Test multi key for bad keys */
670 char *keys
[] = { "GoodKey", "Bad Key", "NotMine" };
671 size_t key_lengths
[] = { 7, 7, 7 };
673 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
674 assert(rc
== MEMCACHED_SUCCESS
);
676 rc
= memcached_mget(clone
, keys
, key_lengths
, 3);
677 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
679 rc
= memcached_mget_by_key(clone
, "foo daddy", 9, keys
, key_lengths
, 1);
680 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
684 /* The following test should be moved to the end of this function when the
685 memcached server is updated to allow max size length of the keys in the
688 rc
= memcached_callback_set(clone
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
689 assert(rc
== MEMCACHED_SUCCESS
);
691 char *longkey
= malloc(max_keylen
+ 1);
694 memset(longkey
, 'a', max_keylen
+ 1);
695 string
= memcached_get(clone
, longkey
, max_keylen
,
696 &string_length
, &flags
, &rc
);
697 assert(rc
== MEMCACHED_NOTFOUND
);
698 assert(string_length
== 0);
701 string
= memcached_get(clone
, longkey
, max_keylen
+ 1,
702 &string_length
, &flags
, &rc
);
703 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
704 assert(string_length
== 0);
711 /* Make sure zero length keys are marked as bad */
713 rc
= memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
);
714 assert(rc
== MEMCACHED_SUCCESS
);
715 string
= memcached_get(clone
, key
, 0,
716 &string_length
, &flags
, &rc
);
717 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
718 assert(string_length
== 0);
721 memcached_free(clone
);
726 #define READ_THROUGH_VALUE "set for me"
727 static memcached_return
read_through_trigger(memcached_st
*memc
__attribute__((unused
)),
728 char *key
__attribute__((unused
)),
729 size_t key_length
__attribute__((unused
)),
730 memcached_result_st
*result
)
733 return memcached_result_set_value(result
, READ_THROUGH_VALUE
, strlen(READ_THROUGH_VALUE
));
736 static test_return
read_through(memcached_st
*memc
)
741 size_t string_length
;
744 string
= memcached_get(memc
, key
, strlen(key
),
745 &string_length
, &flags
, &rc
);
747 assert(rc
== MEMCACHED_NOTFOUND
);
748 assert(string_length
== 0);
751 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_GET_FAILURE
, (void *)read_through_trigger
);
752 assert(rc
== MEMCACHED_SUCCESS
);
754 string
= memcached_get(memc
, key
, strlen(key
),
755 &string_length
, &flags
, &rc
);
757 assert(rc
== MEMCACHED_SUCCESS
);
758 assert(string_length
== strlen(READ_THROUGH_VALUE
));
759 assert(!strcmp(READ_THROUGH_VALUE
, string
));
762 string
= memcached_get(memc
, key
, strlen(key
),
763 &string_length
, &flags
, &rc
);
765 assert(rc
== MEMCACHED_SUCCESS
);
766 assert(string_length
== strlen(READ_THROUGH_VALUE
));
767 assert(!strcmp(READ_THROUGH_VALUE
, string
));
773 static memcached_return
delete_trigger(memcached_st
*ptr
__attribute__((unused
)),
775 size_t key_length
__attribute__((unused
)))
779 return MEMCACHED_SUCCESS
;
782 static test_return
delete_through(memcached_st
*memc
)
784 memcached_trigger_delete_key callback
;
787 callback
= delete_trigger
;
789 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_DELETE_TRIGGER
, (void*)callback
);
790 assert(rc
== MEMCACHED_SUCCESS
);
795 static test_return
get_test(memcached_st
*memc
)
800 size_t string_length
;
803 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
804 assert(rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_NOTFOUND
);
806 string
= memcached_get(memc
, key
, strlen(key
),
807 &string_length
, &flags
, &rc
);
809 assert(rc
== MEMCACHED_NOTFOUND
);
810 assert(string_length
== 0);
816 static test_return
get_test2(memcached_st
*memc
)
820 char *value
= "when we sanitize";
822 size_t string_length
;
825 rc
= memcached_set(memc
, key
, strlen(key
),
826 value
, strlen(value
),
827 (time_t)0, (uint32_t)0);
828 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
830 string
= memcached_get(memc
, key
, strlen(key
),
831 &string_length
, &flags
, &rc
);
834 assert(rc
== MEMCACHED_SUCCESS
);
835 assert(string_length
== strlen(value
));
836 assert(!memcmp(string
, value
, string_length
));
843 static test_return
set_test2(memcached_st
*memc
)
847 char *value
= "train in the brain";
848 size_t value_length
= strlen(value
);
851 for (x
= 0; x
< 10; x
++)
853 rc
= memcached_set(memc
, key
, strlen(key
),
855 (time_t)0, (uint32_t)0);
856 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
862 static test_return
set_test3(memcached_st
*memc
)
867 size_t value_length
= 8191;
870 value
= (char*)malloc(value_length
);
873 for (x
= 0; x
< value_length
; x
++)
874 value
[x
] = (char) (x
% 127);
876 for (x
= 0; x
< 1; x
++)
878 rc
= memcached_set(memc
, key
, strlen(key
),
880 (time_t)0, (uint32_t)0);
881 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
889 static test_return
get_test3(memcached_st
*memc
)
894 size_t value_length
= 8191;
896 size_t string_length
;
900 value
= (char*)malloc(value_length
);
903 for (x
= 0; x
< value_length
; x
++)
904 value
[x
] = (char) (x
% 127);
906 rc
= memcached_set(memc
, key
, strlen(key
),
908 (time_t)0, (uint32_t)0);
909 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
911 string
= memcached_get(memc
, key
, strlen(key
),
912 &string_length
, &flags
, &rc
);
914 assert(rc
== MEMCACHED_SUCCESS
);
916 assert(string_length
== value_length
);
917 assert(!memcmp(string
, value
, string_length
));
925 static test_return
get_test4(memcached_st
*memc
)
930 size_t value_length
= 8191;
932 size_t string_length
;
936 value
= (char*)malloc(value_length
);
939 for (x
= 0; x
< value_length
; x
++)
940 value
[x
] = (char) (x
% 127);
942 rc
= memcached_set(memc
, key
, strlen(key
),
944 (time_t)0, (uint32_t)0);
945 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
947 for (x
= 0; x
< 10; x
++)
949 string
= memcached_get(memc
, key
, strlen(key
),
950 &string_length
, &flags
, &rc
);
952 assert(rc
== MEMCACHED_SUCCESS
);
954 assert(string_length
== value_length
);
955 assert(!memcmp(string
, value
, string_length
));
965 * This test verifies that memcached_read_one_response doesn't try to
966 * dereference a NIL-pointer if you issue a multi-get and don't read out all
967 * responses before you execute a storage command.
969 static test_return
get_test5(memcached_st
*memc
)
972 ** Request the same key twice, to ensure that we hash to the same server
973 ** (so that we have multiple response values queued up) ;-)
975 char *keys
[]= { "key", "key" };
976 size_t lengths
[]= { 3, 3 };
980 memcached_return rc
= memcached_set(memc
, keys
[0], lengths
[0],
981 keys
[0], lengths
[0], 0, 0);
982 assert(rc
== MEMCACHED_SUCCESS
);
983 rc
= memcached_mget(memc
, keys
, lengths
, 2);
985 memcached_result_st results_obj
;
986 memcached_result_st
*results
;
987 results
=memcached_result_create(memc
, &results_obj
);
989 results
=memcached_fetch_result(memc
, &results_obj
, &rc
);
991 memcached_result_free(&results_obj
);
993 /* Don't read out the second result, but issue a set instead.. */
994 rc
= memcached_set(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0);
995 assert(rc
== MEMCACHED_SUCCESS
);
997 char *val
= memcached_get_by_key(memc
, keys
[0], lengths
[0], "yek", 3,
1000 assert(rc
== MEMCACHED_NOTFOUND
);
1001 val
= memcached_get(memc
, keys
[0], lengths
[0], &rlen
, &flags
, &rc
);
1002 assert(val
!= NULL
);
1003 assert(rc
== MEMCACHED_SUCCESS
);
1006 return TEST_SUCCESS
;
1009 /* Do not copy the style of this code, I just access hosts to testthis function */
1010 static test_return
stats_servername_test(memcached_st
*memc
)
1012 memcached_return rc
;
1013 memcached_stat_st stat
;
1014 rc
= memcached_stat_servername(&stat
, NULL
,
1015 memc
->hosts
[0].hostname
,
1016 memc
->hosts
[0].port
);
1021 static test_return
increment_test(memcached_st
*memc
)
1023 uint64_t new_number
;
1024 memcached_return rc
;
1025 char *key
= "number";
1028 rc
= memcached_set(memc
, key
, strlen(key
),
1029 value
, strlen(value
),
1030 (time_t)0, (uint32_t)0);
1031 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1033 rc
= memcached_increment(memc
, key
, strlen(key
),
1035 assert(rc
== MEMCACHED_SUCCESS
);
1036 assert(new_number
== 1);
1038 rc
= memcached_increment(memc
, key
, strlen(key
),
1040 assert(rc
== MEMCACHED_SUCCESS
);
1041 assert(new_number
== 2);
1046 static test_return
increment_with_initial_test(memcached_st
*memc
)
1048 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1050 uint64_t new_number
;
1051 memcached_return rc
;
1052 char *key
= "number";
1053 uint64_t initial
= 0;
1055 rc
= memcached_increment_with_initial(memc
, key
, strlen(key
),
1056 1, initial
, 0, &new_number
);
1057 assert(rc
== MEMCACHED_SUCCESS
);
1058 assert(new_number
== initial
);
1060 rc
= memcached_increment_with_initial(memc
, key
, strlen(key
),
1061 1, initial
, 0, &new_number
);
1062 assert(rc
== MEMCACHED_SUCCESS
);
1063 assert(new_number
== (initial
+ 1));
1068 static test_return
decrement_test(memcached_st
*memc
)
1070 uint64_t new_number
;
1071 memcached_return rc
;
1072 char *key
= "number";
1075 rc
= memcached_set(memc
, key
, strlen(key
),
1076 value
, strlen(value
),
1077 (time_t)0, (uint32_t)0);
1078 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1080 rc
= memcached_decrement(memc
, key
, strlen(key
),
1082 assert(rc
== MEMCACHED_SUCCESS
);
1083 assert(new_number
== 2);
1085 rc
= memcached_decrement(memc
, key
, strlen(key
),
1087 assert(rc
== MEMCACHED_SUCCESS
);
1088 assert(new_number
== 1);
1093 static test_return
decrement_with_initial_test(memcached_st
*memc
)
1095 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1097 uint64_t new_number
;
1098 memcached_return rc
;
1099 char *key
= "number";
1100 uint64_t initial
= 3;
1102 rc
= memcached_decrement_with_initial(memc
, key
, strlen(key
),
1103 1, initial
, 0, &new_number
);
1104 assert(rc
== MEMCACHED_SUCCESS
);
1105 assert(new_number
== initial
);
1107 rc
= memcached_decrement_with_initial(memc
, key
, strlen(key
),
1108 1, initial
, 0, &new_number
);
1109 assert(rc
== MEMCACHED_SUCCESS
);
1110 assert(new_number
== (initial
- 1));
1115 static test_return
quit_test(memcached_st
*memc
)
1117 memcached_return rc
;
1119 char *value
= "sanford and sun";
1121 rc
= memcached_set(memc
, key
, strlen(key
),
1122 value
, strlen(value
),
1123 (time_t)10, (uint32_t)3);
1124 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1125 memcached_quit(memc
);
1127 rc
= memcached_set(memc
, key
, strlen(key
),
1128 value
, strlen(value
),
1129 (time_t)50, (uint32_t)9);
1130 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1135 static test_return
mget_result_test(memcached_st
*memc
)
1137 memcached_return rc
;
1138 char *keys
[]= {"fudge", "son", "food"};
1139 size_t key_length
[]= {5, 3, 4};
1142 memcached_result_st results_obj
;
1143 memcached_result_st
*results
;
1145 results
= memcached_result_create(memc
, &results_obj
);
1147 assert(&results_obj
== results
);
1149 /* We need to empty the server before continueing test */
1150 rc
= memcached_flush(memc
, 0);
1151 assert(rc
== MEMCACHED_SUCCESS
);
1153 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1154 assert(rc
== MEMCACHED_SUCCESS
);
1156 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1161 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)) != NULL
)
1163 assert(rc
== MEMCACHED_END
);
1165 for (x
= 0; x
< 3; x
++)
1167 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1168 keys
[x
], key_length
[x
],
1169 (time_t)50, (uint32_t)9);
1170 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1173 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1174 assert(rc
== MEMCACHED_SUCCESS
);
1176 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1179 assert(&results_obj
== results
);
1180 assert(rc
== MEMCACHED_SUCCESS
);
1181 assert(memcached_result_key_length(results
) == memcached_result_length(results
));
1182 assert(!memcmp(memcached_result_key_value(results
),
1183 memcached_result_value(results
),
1184 memcached_result_length(results
)));
1187 memcached_result_free(&results_obj
);
1192 static test_return
mget_result_alloc_test(memcached_st
*memc
)
1194 memcached_return rc
;
1195 char *keys
[]= {"fudge", "son", "food"};
1196 size_t key_length
[]= {5, 3, 4};
1199 memcached_result_st
*results
;
1201 /* We need to empty the server before continueing test */
1202 rc
= memcached_flush(memc
, 0);
1203 assert(rc
== MEMCACHED_SUCCESS
);
1205 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1206 assert(rc
== MEMCACHED_SUCCESS
);
1208 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)) != NULL
)
1213 assert(rc
== MEMCACHED_END
);
1215 for (x
= 0; x
< 3; x
++)
1217 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1218 keys
[x
], key_length
[x
],
1219 (time_t)50, (uint32_t)9);
1220 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1223 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1224 assert(rc
== MEMCACHED_SUCCESS
);
1227 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1230 assert(rc
== MEMCACHED_SUCCESS
);
1231 assert(memcached_result_key_length(results
) == memcached_result_length(results
));
1232 assert(!memcmp(memcached_result_key_value(results
),
1233 memcached_result_value(results
),
1234 memcached_result_length(results
)));
1235 memcached_result_free(results
);
1242 /* Count the results */
1243 static memcached_return
callback_counter(memcached_st
*ptr
__attribute__((unused
)),
1244 memcached_result_st
*result
__attribute__((unused
)),
1247 unsigned int *counter
= (unsigned int *)context
;
1249 *counter
= *counter
+ 1;
1251 return MEMCACHED_SUCCESS
;
1254 static test_return
mget_result_function(memcached_st
*memc
)
1256 memcached_return rc
;
1257 char *keys
[]= {"fudge", "son", "food"};
1258 size_t key_length
[]= {5, 3, 4};
1260 unsigned int counter
;
1261 memcached_execute_function callbacks
[1];
1263 /* We need to empty the server before continueing test */
1264 rc
= memcached_flush(memc
, 0);
1265 for (x
= 0; x
< 3; x
++)
1267 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1268 keys
[x
], key_length
[x
],
1269 (time_t)50, (uint32_t)9);
1270 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1273 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1274 assert(rc
== MEMCACHED_SUCCESS
);
1276 callbacks
[0]= &callback_counter
;
1278 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
1280 assert(counter
== 3);
1285 static test_return
mget_test(memcached_st
*memc
)
1287 memcached_return rc
;
1288 char *keys
[]= {"fudge", "son", "food"};
1289 size_t key_length
[]= {5, 3, 4};
1293 char return_key
[MEMCACHED_MAX_KEY
];
1294 size_t return_key_length
;
1296 size_t return_value_length
;
1298 /* We need to empty the server before continueing test */
1299 rc
= memcached_flush(memc
, 0);
1300 assert(rc
== MEMCACHED_SUCCESS
);
1302 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1303 assert(rc
== MEMCACHED_SUCCESS
);
1305 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1306 &return_value_length
, &flags
, &rc
)) != NULL
)
1308 assert(return_value
);
1310 assert(!return_value
);
1311 assert(return_value_length
== 0);
1312 assert(rc
== MEMCACHED_END
);
1314 for (x
= 0; x
< 3; x
++)
1316 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1317 keys
[x
], key_length
[x
],
1318 (time_t)50, (uint32_t)9);
1319 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1322 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1323 assert(rc
== MEMCACHED_SUCCESS
);
1326 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1327 &return_value_length
, &flags
, &rc
)))
1329 assert(return_value
);
1330 assert(rc
== MEMCACHED_SUCCESS
);
1331 assert(return_key_length
== return_value_length
);
1332 assert(!memcmp(return_value
, return_key
, return_value_length
));
1340 static test_return
get_stats_keys(memcached_st
*memc
)
1344 memcached_stat_st stat
;
1345 memcached_return rc
;
1347 list
= memcached_stat_get_keys(memc
, &stat
, &rc
);
1348 assert(rc
== MEMCACHED_SUCCESS
);
1349 for (ptr
= list
; *ptr
; ptr
++)
1358 static test_return
version_string_test(memcached_st
*memc
__attribute__((unused
)))
1360 const char *version_string
;
1362 version_string
= memcached_lib_version();
1364 assert(!strcmp(version_string
, LIBMEMCACHED_VERSION_STRING
));
1369 static test_return
get_stats(memcached_st
*memc
)
1374 memcached_return rc
;
1375 memcached_stat_st
*stat
;
1377 stat
= memcached_stat(memc
, NULL
, &rc
);
1378 assert(rc
== MEMCACHED_SUCCESS
);
1380 assert(rc
== MEMCACHED_SUCCESS
);
1383 for (x
= 0; x
< memcached_server_count(memc
); x
++)
1385 list
= memcached_stat_get_keys(memc
, stat
+x
, &rc
);
1386 assert(rc
== MEMCACHED_SUCCESS
);
1387 for (ptr
= list
; *ptr
; ptr
++);
1392 memcached_stat_free(NULL
, stat
);
1397 static test_return
add_host_test(memcached_st
*memc
)
1400 memcached_server_st
*servers
;
1401 memcached_return rc
;
1402 char servername
[]= "0.example.com";
1404 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
1406 assert(1 == memcached_server_list_count(servers
));
1408 for (x
= 2; x
< 20; x
++)
1410 char buffer
[SMALL_STRING_LEN
];
1412 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
1413 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
1415 assert(rc
== MEMCACHED_SUCCESS
);
1416 assert(x
== memcached_server_list_count(servers
));
1419 rc
= memcached_server_push(memc
, servers
);
1420 assert(rc
== MEMCACHED_SUCCESS
);
1421 rc
= memcached_server_push(memc
, servers
);
1422 assert(rc
== MEMCACHED_SUCCESS
);
1424 memcached_server_list_free(servers
);
1429 static memcached_return
clone_test_callback(memcached_st
*parent
__attribute__((unused
)), memcached_st
*clone
__attribute__((unused
)))
1431 return MEMCACHED_SUCCESS
;
1434 static memcached_return
cleanup_test_callback(memcached_st
*ptr
__attribute__((unused
)))
1436 return MEMCACHED_SUCCESS
;
1439 static test_return
callback_test(memcached_st
*memc
)
1441 /* Test User Data */
1445 memcached_return rc
;
1447 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_USER_DATA
, &x
);
1448 assert(rc
== MEMCACHED_SUCCESS
);
1449 test_ptr
= (int *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_USER_DATA
, &rc
);
1450 assert(*test_ptr
== x
);
1453 /* Test Clone Callback */
1455 memcached_clone_func temp_function
;
1456 memcached_return rc
;
1458 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, (void*)clone_test_callback
);
1459 assert(rc
== MEMCACHED_SUCCESS
);
1460 temp_function
= (memcached_clone_func
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1461 assert(temp_function
== clone_test_callback
);
1464 /* Test Cleanup Callback */
1466 memcached_cleanup_func temp_function
;
1467 memcached_return rc
;
1469 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, (void*)cleanup_test_callback
);
1470 assert(rc
== MEMCACHED_SUCCESS
);
1471 temp_function
= (memcached_cleanup_func
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1472 assert(temp_function
== cleanup_test_callback
);
1478 /* We don't test the behavior itself, we test the switches */
1479 static test_return
behavior_test(memcached_st
*memc
)
1484 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1485 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1488 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1489 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1492 set
= MEMCACHED_HASH_MD5
;
1493 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1494 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1495 assert(value
== MEMCACHED_HASH_MD5
);
1499 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
1500 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
1503 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
1504 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
1507 set
= MEMCACHED_HASH_DEFAULT
;
1508 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1509 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1510 assert(value
== MEMCACHED_HASH_DEFAULT
);
1512 set
= MEMCACHED_HASH_CRC
;
1513 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
1514 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
1515 assert(value
== MEMCACHED_HASH_CRC
);
1517 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1520 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1526 /* Test case provided by Cal Haldenbrand */
1527 static test_return
user_supplied_bug1(memcached_st
*memc
)
1529 unsigned int setter
= 1;
1532 unsigned long long total
= 0;
1535 char randomstuff
[6 * 1024];
1536 memcached_return rc
;
1538 memset(randomstuff
, 0, 6 * 1024);
1540 /* We just keep looking at the same values over and over */
1543 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1544 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1548 for (x
= 0 ; total
< 20 * 1024576 ; x
++ )
1552 size
= (rand() % ( 5 * 1024 ) ) + 400;
1553 memset(randomstuff
, 0, 6 * 1024);
1554 assert(size
< 6 * 1024); /* Being safe here */
1556 for (j
= 0 ; j
< size
;j
++)
1557 randomstuff
[j
] = (char) (rand() % 26) + 97;
1560 sprintf(key
, "%d", x
);
1561 rc
= memcached_set(memc
, key
, strlen(key
),
1562 randomstuff
, strlen(randomstuff
), 10, 0);
1563 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1564 /* If we fail, lets try again */
1565 if (rc
!= MEMCACHED_SUCCESS
&& rc
!= MEMCACHED_BUFFERED
)
1566 rc
= memcached_set(memc
, key
, strlen(key
),
1567 randomstuff
, strlen(randomstuff
), 10, 0);
1568 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1574 /* Test case provided by Cal Haldenbrand */
1575 static test_return
user_supplied_bug2(memcached_st
*memc
)
1578 unsigned int setter
;
1580 unsigned long long total
;
1583 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1584 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1586 setter
= 20 * 1024576;
1587 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1588 setter
= 20 * 1024576;
1589 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1590 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1591 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1593 for (x
= 0, errors
= 0, total
= 0 ; total
< 20 * 1024576 ; x
++)
1596 for (x
= 0, errors
= 0, total
= 0 ; total
< 24576 ; x
++)
1598 memcached_return rc
= MEMCACHED_SUCCESS
;
1599 char buffer
[SMALL_STRING_LEN
];
1604 memset(buffer
, 0, SMALL_STRING_LEN
);
1606 snprintf(buffer
, SMALL_STRING_LEN
, "%u", x
);
1607 getval
= memcached_get(memc
, buffer
, strlen(buffer
),
1608 &val_len
, &flags
, &rc
);
1609 if (rc
!= MEMCACHED_SUCCESS
)
1611 if (rc
== MEMCACHED_NOTFOUND
)
1615 WATCHPOINT_ERROR(rc
);
1629 /* Do a large mget() over all the keys we think exist */
1630 #define KEY_COUNT 3000 // * 1024576
1631 static test_return
user_supplied_bug3(memcached_st
*memc
)
1633 memcached_return rc
;
1634 unsigned int setter
;
1637 size_t key_lengths
[KEY_COUNT
];
1640 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
1641 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
1643 setter
= 20 * 1024576;
1644 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
1645 setter
= 20 * 1024576;
1646 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
1647 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
1648 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
1651 keys
= (char **)malloc(sizeof(char *) * KEY_COUNT
);
1653 memset(keys
, 0, (sizeof(char *) * KEY_COUNT
));
1654 for (x
= 0; x
< KEY_COUNT
; x
++)
1658 snprintf(buffer
, 30, "%u", x
);
1659 keys
[x
]= strdup(buffer
);
1660 key_lengths
[x
]= strlen(keys
[x
]);
1663 rc
= memcached_mget(memc
, keys
, key_lengths
, KEY_COUNT
);
1664 assert(rc
== MEMCACHED_SUCCESS
);
1666 /* Turn this into a help function */
1668 char return_key
[MEMCACHED_MAX_KEY
];
1669 size_t return_key_length
;
1671 size_t return_value_length
;
1674 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1675 &return_value_length
, &flags
, &rc
)))
1677 assert(return_value
);
1678 assert(rc
== MEMCACHED_SUCCESS
);
1683 for (x
= 0; x
< KEY_COUNT
; x
++)
1690 /* Make sure we behave properly if server list has no values */
1691 static test_return
user_supplied_bug4(memcached_st
*memc
)
1693 memcached_return rc
;
1694 char *keys
[]= {"fudge", "son", "food"};
1695 size_t key_length
[]= {5, 3, 4};
1698 char return_key
[MEMCACHED_MAX_KEY
];
1699 size_t return_key_length
;
1701 size_t return_value_length
;
1703 /* Here we free everything before running a bunch of mget tests */
1705 memcached_server_list_free(memc
->hosts
);
1707 memc
->number_of_hosts
= 0;
1711 /* We need to empty the server before continueing test */
1712 rc
= memcached_flush(memc
, 0);
1713 assert(rc
== MEMCACHED_NO_SERVERS
);
1715 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1716 assert(rc
== MEMCACHED_NO_SERVERS
);
1718 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1719 &return_value_length
, &flags
, &rc
)) != NULL
)
1721 assert(return_value
);
1723 assert(!return_value
);
1724 assert(return_value_length
== 0);
1725 assert(rc
== MEMCACHED_NO_SERVERS
);
1727 for (x
= 0; x
< 3; x
++)
1729 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1730 keys
[x
], key_length
[x
],
1731 (time_t)50, (uint32_t)9);
1732 assert(rc
== MEMCACHED_NO_SERVERS
);
1735 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1736 assert(rc
== MEMCACHED_NO_SERVERS
);
1739 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1740 &return_value_length
, &flags
, &rc
)))
1742 assert(return_value
);
1743 assert(rc
== MEMCACHED_SUCCESS
);
1744 assert(return_key_length
== return_value_length
);
1745 assert(!memcmp(return_value
, return_key
, return_value_length
));
1753 #define VALUE_SIZE_BUG5 1048064
1754 static test_return
user_supplied_bug5(memcached_st
*memc
)
1756 memcached_return rc
;
1757 char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1758 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1759 char return_key
[MEMCACHED_MAX_KEY
];
1760 size_t return_key_length
;
1762 size_t value_length
;
1766 char insert_data
[VALUE_SIZE_BUG5
];
1768 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1769 insert_data
[x
]= rand();
1771 memcached_flush(memc
, 0);
1772 value
= memcached_get(memc
, keys
[0], key_length
[0],
1773 &value_length
, &flags
, &rc
);
1774 assert(value
== NULL
);
1775 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1778 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1779 &value_length
, &flags
, &rc
)))
1783 for (x
= 0; x
< 4; x
++)
1785 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1786 insert_data
, VALUE_SIZE_BUG5
,
1787 (time_t)0, (uint32_t)0);
1788 assert(rc
== MEMCACHED_SUCCESS
);
1791 for (x
= 0; x
< 10; x
++)
1793 value
= memcached_get(memc
, keys
[0], key_length
[0],
1794 &value_length
, &flags
, &rc
);
1798 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1800 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1801 &value_length
, &flags
, &rc
)))
1812 static test_return
user_supplied_bug6(memcached_st
*memc
)
1814 memcached_return rc
;
1815 char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1816 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1817 char return_key
[MEMCACHED_MAX_KEY
];
1818 size_t return_key_length
;
1820 size_t value_length
;
1824 char insert_data
[VALUE_SIZE_BUG5
];
1826 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1827 insert_data
[x
]= rand();
1829 memcached_flush(memc
, 0);
1830 value
= memcached_get(memc
, keys
[0], key_length
[0],
1831 &value_length
, &flags
, &rc
);
1832 assert(value
== NULL
);
1833 assert(rc
== MEMCACHED_NOTFOUND
);
1834 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1835 assert(rc
== MEMCACHED_SUCCESS
);
1838 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1839 &value_length
, &flags
, &rc
)))
1842 assert(rc
== MEMCACHED_END
);
1844 for (x
= 0; x
< 4; x
++)
1846 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1847 insert_data
, VALUE_SIZE_BUG5
,
1848 (time_t)0, (uint32_t)0);
1849 assert(rc
== MEMCACHED_SUCCESS
);
1852 for (x
= 0; x
< 2; x
++)
1854 value
= memcached_get(memc
, keys
[0], key_length
[0],
1855 &value_length
, &flags
, &rc
);
1859 rc
= memcached_mget(memc
, keys
, key_length
, 4);
1860 assert(rc
== MEMCACHED_SUCCESS
);
1862 /* We test for purge of partial complete fetches */
1863 for (count
= 3; count
; count
--)
1865 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1866 &value_length
, &flags
, &rc
);
1867 assert(rc
== MEMCACHED_SUCCESS
);
1868 assert(!(memcmp(value
, insert_data
, value_length
)));
1869 assert(value_length
);
1877 static test_return
user_supplied_bug8(memcached_st
*memc
__attribute__((unused
)))
1879 memcached_return rc
;
1881 memcached_st
*clone
;
1883 memcached_server_st
*servers
;
1884 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";
1886 servers
= memcached_servers_parse(server_list
);
1889 mine
= memcached_create(NULL
);
1890 rc
= memcached_server_push(mine
, servers
);
1891 assert(rc
== MEMCACHED_SUCCESS
);
1892 memcached_server_list_free(servers
);
1895 clone
= memcached_clone(NULL
, mine
);
1897 memcached_quit(mine
);
1898 memcached_quit(clone
);
1901 memcached_free(mine
);
1902 memcached_free(clone
);
1907 /* Test flag store/retrieve */
1908 static test_return
user_supplied_bug7(memcached_st
*memc
)
1910 memcached_return rc
;
1911 char *keys
= "036790384900";
1912 size_t key_length
= strlen("036790384900");
1913 char return_key
[MEMCACHED_MAX_KEY
];
1914 size_t return_key_length
;
1916 size_t value_length
;
1919 char insert_data
[VALUE_SIZE_BUG5
];
1921 for (x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
1922 insert_data
[x
]= rand();
1924 memcached_flush(memc
, 0);
1927 rc
= memcached_set(memc
, keys
, key_length
,
1928 insert_data
, VALUE_SIZE_BUG5
,
1930 assert(rc
== MEMCACHED_SUCCESS
);
1933 value
= memcached_get(memc
, keys
, key_length
,
1934 &value_length
, &flags
, &rc
);
1935 assert(flags
== 245);
1939 rc
= memcached_mget(memc
, &keys
, &key_length
, 1);
1942 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1943 &value_length
, &flags
, &rc
);
1944 assert(flags
== 245);
1952 static test_return
user_supplied_bug9(memcached_st
*memc
)
1954 memcached_return rc
;
1955 char *keys
[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
1956 size_t key_length
[3];
1961 char return_key
[MEMCACHED_MAX_KEY
];
1962 size_t return_key_length
;
1964 size_t return_value_length
;
1967 key_length
[0]= strlen("UDATA:edevil@sapo.pt");
1968 key_length
[1]= strlen("fudge&*@#");
1969 key_length
[2]= strlen("for^#@&$not");
1972 for (x
= 0; x
< 3; x
++)
1974 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1975 keys
[x
], key_length
[x
],
1976 (time_t)50, (uint32_t)9);
1977 assert(rc
== MEMCACHED_SUCCESS
);
1980 rc
= memcached_mget(memc
, keys
, key_length
, 3);
1981 assert(rc
== MEMCACHED_SUCCESS
);
1983 /* We need to empty the server before continueing test */
1984 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1985 &return_value_length
, &flags
, &rc
)) != NULL
)
1987 assert(return_value
);
1996 /* We are testing with aggressive timeout to get failures */
1997 static test_return
user_supplied_bug10(memcached_st
*memc
)
2001 size_t value_length
= 512;
2004 memcached_return rc
;
2005 unsigned int set
= 1;
2006 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2009 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2010 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2012 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
2014 value
= (char*)malloc(value_length
* sizeof(char));
2016 for (x
= 0; x
< value_length
; x
++)
2017 value
[x
]= (char) (x
% 127);
2019 for (x
= 1; x
<= 100000; ++x
)
2021 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2023 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_WRITE_FAILURE
|| rc
== MEMCACHED_BUFFERED
);
2025 if (rc
== MEMCACHED_WRITE_FAILURE
)
2030 memcached_free(mclone
);
2036 We are looking failures in the async protocol
2038 static test_return
user_supplied_bug11(memcached_st
*memc
)
2042 size_t value_length
= 512;
2045 memcached_return rc
;
2046 unsigned int set
= 1;
2048 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2050 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2051 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2053 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
2055 timeout
= (int32_t)memcached_behavior_get(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
2057 assert(timeout
== -1);
2059 value
= (char*)malloc(value_length
* sizeof(char));
2061 for (x
= 0; x
< value_length
; x
++)
2062 value
[x
]= (char) (x
% 127);
2064 for (x
= 1; x
<= 100000; ++x
)
2066 rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2070 memcached_free(mclone
);
2076 Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
2078 static test_return
user_supplied_bug12(memcached_st
*memc
)
2080 memcached_return rc
;
2082 size_t value_length
;
2084 uint64_t number_value
;
2086 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2087 &value_length
, &flags
, &rc
);
2088 assert(value
== NULL
);
2089 assert(rc
== MEMCACHED_NOTFOUND
);
2091 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2094 assert(value
== NULL
);
2095 /* The binary protocol will set the key if it doesn't exist */
2096 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1)
2097 assert(rc
== MEMCACHED_SUCCESS
);
2099 assert(rc
== MEMCACHED_NOTFOUND
);
2101 rc
= memcached_set(memc
, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
2103 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2104 &value_length
, &flags
, &rc
);
2106 assert(rc
== MEMCACHED_SUCCESS
);
2109 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2111 assert(number_value
== 2);
2112 assert(rc
== MEMCACHED_SUCCESS
);
2118 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2119 set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
2121 static test_return
user_supplied_bug13(memcached_st
*memc
)
2123 char key
[] = "key34567890";
2125 memcached_return rc
;
2126 size_t overflowSize
;
2128 char commandFirst
[]= "set key34567890 0 0 ";
2129 char commandLast
[] = " \r\n"; /* first line of command sent to server */
2130 size_t commandLength
;
2133 commandLength
= strlen(commandFirst
) + strlen(commandLast
) + 4; /* 4 is number of characters in size, probably 8196 */
2135 overflowSize
= MEMCACHED_MAX_BUFFER
- commandLength
;
2137 for (testSize
= overflowSize
- 1; testSize
< overflowSize
+ 1; testSize
++)
2139 overflow
= malloc(testSize
);
2140 assert(overflow
!= NULL
);
2142 memset(overflow
, 'x', testSize
);
2143 rc
= memcached_set(memc
, key
, strlen(key
),
2144 overflow
, testSize
, 0, 0);
2145 assert(rc
== MEMCACHED_SUCCESS
);
2154 Test values of many different sizes
2155 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2156 set key34567890 0 0 8169 \r\n
2157 is sent followed by buffer of size 8169, followed by 8169
2159 static test_return
user_supplied_bug14(memcached_st
*memc
)
2162 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2163 memcached_return rc
;
2166 size_t value_length
= 18000;
2168 size_t string_length
;
2171 size_t current_length
;
2173 value
= (char*)malloc(value_length
);
2176 for (x
= 0; x
< value_length
; x
++)
2177 value
[x
] = (char) (x
% 127);
2179 for (current_length
= 0; current_length
< value_length
; current_length
++)
2181 rc
= memcached_set(memc
, key
, strlen(key
),
2182 value
, current_length
,
2183 (time_t)0, (uint32_t)0);
2184 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
2186 string
= memcached_get(memc
, key
, strlen(key
),
2187 &string_length
, &flags
, &rc
);
2189 assert(rc
== MEMCACHED_SUCCESS
);
2190 assert(string_length
== current_length
);
2191 assert(!memcmp(string
, value
, string_length
));
2202 Look for zero length value problems
2204 static test_return
user_supplied_bug15(memcached_st
*memc
)
2207 memcached_return rc
;
2213 for (x
= 0; x
< 2; x
++)
2215 rc
= memcached_set(memc
, key
, strlen(key
),
2217 (time_t)0, (uint32_t)0);
2219 assert(rc
== MEMCACHED_SUCCESS
);
2221 value
= memcached_get(memc
, key
, strlen(key
),
2222 &length
, &flags
, &rc
);
2224 assert(rc
== MEMCACHED_SUCCESS
);
2225 assert(value
== NULL
);
2226 assert(length
== 0);
2229 value
= memcached_get(memc
, key
, strlen(key
),
2230 &length
, &flags
, &rc
);
2232 assert(rc
== MEMCACHED_SUCCESS
);
2233 assert(value
== NULL
);
2234 assert(length
== 0);
2241 /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
2242 static test_return
user_supplied_bug16(memcached_st
*memc
)
2244 memcached_return rc
;
2250 rc
= memcached_set(memc
, key
, strlen(key
),
2252 (time_t)0, UINT32_MAX
);
2254 assert(rc
== MEMCACHED_SUCCESS
);
2256 value
= memcached_get(memc
, key
, strlen(key
),
2257 &length
, &flags
, &rc
);
2259 assert(rc
== MEMCACHED_SUCCESS
);
2260 assert(value
== NULL
);
2261 assert(length
== 0);
2262 assert(flags
== UINT32_MAX
);
2267 /* Check the validity of chinese key*/
2268 static test_return
user_supplied_bug17(memcached_st
*memc
)
2270 memcached_return rc
;
2272 char *value
="我们在炎热抑郁的夏天无法停止豆瓣";
2277 rc
= memcached_set(memc
, key
, strlen(key
),
2278 value
, strlen(value
),
2281 assert(rc
== MEMCACHED_SUCCESS
);
2283 value2
= memcached_get(memc
, key
, strlen(key
),
2284 &length
, &flags
, &rc
);
2286 assert(length
==strlen(value
));
2287 assert(rc
== MEMCACHED_SUCCESS
);
2288 assert(memcmp(value
, value2
, length
)==0);
2298 test_return
user_supplied_bug19(memcached_st
*memc
)
2301 memcached_server_st
*s
;
2302 memcached_return res
;
2306 m
= memcached_create(NULL
);
2307 memcached_server_add_with_weight(m
, "localhost", 11311, 100);
2308 memcached_server_add_with_weight(m
, "localhost", 11312, 100);
2310 s
= memcached_server_by_key(m
, "a", 1, &res
);
2311 memcached_server_free(s
);
2318 /* CAS test from Andei */
2319 test_return
user_supplied_bug20(memcached_st
*memc
)
2321 memcached_return status
;
2322 memcached_result_st
*result
, result_obj
;
2324 size_t key_len
= strlen("abc");
2325 char *value
= "foobar";
2326 size_t value_len
= strlen(value
);
2328 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
2330 status
= memcached_set(memc
, key
, key_len
, value
, value_len
, (time_t)0, (uint32_t)0);
2331 assert(status
== MEMCACHED_SUCCESS
);
2333 status
= memcached_mget(memc
, &key
, &key_len
, 1);
2334 assert(status
== MEMCACHED_SUCCESS
);
2336 result
= memcached_result_create(memc
, &result_obj
);
2339 memcached_result_create(memc
, &result_obj
);
2340 result
= memcached_fetch_result(memc
, &result_obj
, &status
);
2343 assert(status
== MEMCACHED_SUCCESS
);
2345 memcached_result_free(result
);
2350 #include "ketama_test_cases.h"
2351 test_return
user_supplied_bug18(memcached_st
*trash
)
2353 memcached_return rc
;
2356 memcached_server_st
*server_pool
;
2361 memc
= memcached_create(NULL
);
2364 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2365 assert(rc
== MEMCACHED_SUCCESS
);
2367 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2370 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2371 assert(rc
== MEMCACHED_SUCCESS
);
2373 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2374 assert(value
== MEMCACHED_HASH_MD5
);
2376 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");
2377 memcached_server_push(memc
, server_pool
);
2379 /* verify that the server list was parsed okay. */
2380 assert(memc
->number_of_hosts
== 8);
2381 assert(strcmp(server_pool
[0].hostname
, "10.0.1.1") == 0);
2382 assert(server_pool
[0].port
== 11211);
2383 assert(server_pool
[0].weight
== 600);
2384 assert(strcmp(server_pool
[2].hostname
, "10.0.1.3") == 0);
2385 assert(server_pool
[2].port
== 11211);
2386 assert(server_pool
[2].weight
== 200);
2387 assert(strcmp(server_pool
[7].hostname
, "10.0.1.8") == 0);
2388 assert(server_pool
[7].port
== 11211);
2389 assert(server_pool
[7].weight
== 100);
2391 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
2392 * us test the boundary wraparound.
2394 assert(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->continuum
[0].index
);
2396 /* verify the standard ketama set. */
2397 for (x
= 0; x
< 99; x
++)
2399 uint32_t server_idx
= memcached_generate_hash(memc
, test_cases
[x
].key
, strlen(test_cases
[x
].key
));
2400 char *hostname
= memc
->hosts
[server_idx
].hostname
;
2401 assert(strcmp(hostname
, test_cases
[x
].server
) == 0);
2404 memcached_server_list_free(server_pool
);
2405 memcached_free(memc
);
2410 static test_return
result_static(memcached_st
*memc
)
2412 memcached_result_st result
;
2413 memcached_result_st
*result_ptr
;
2415 result_ptr
= memcached_result_create(memc
, &result
);
2416 assert(result
.is_allocated
== false);
2418 memcached_result_free(&result
);
2423 static test_return
result_alloc(memcached_st
*memc
)
2425 memcached_result_st
*result
;
2427 result
= memcached_result_create(memc
, NULL
);
2429 memcached_result_free(result
);
2434 static test_return
string_static_null(memcached_st
*memc
)
2436 memcached_string_st string
;
2437 memcached_string_st
*string_ptr
;
2439 string_ptr
= memcached_string_create(memc
, &string
, 0);
2440 assert(string
.is_allocated
== false);
2442 memcached_string_free(&string
);
2447 static test_return
string_alloc_null(memcached_st
*memc
)
2449 memcached_string_st
*string
;
2451 string
= memcached_string_create(memc
, NULL
, 0);
2453 memcached_string_free(string
);
2458 static test_return
string_alloc_with_size(memcached_st
*memc
)
2460 memcached_string_st
*string
;
2462 string
= memcached_string_create(memc
, NULL
, 1024);
2464 memcached_string_free(string
);
2469 static test_return
string_alloc_with_size_toobig(memcached_st
*memc
)
2471 memcached_string_st
*string
;
2473 string
= memcached_string_create(memc
, NULL
, INT64_MAX
);
2474 assert(string
== NULL
);
2479 static test_return
string_alloc_append(memcached_st
*memc
)
2482 char buffer
[SMALL_STRING_LEN
];
2483 memcached_string_st
*string
;
2485 /* Ring the bell! */
2486 memset(buffer
, 6, SMALL_STRING_LEN
);
2488 string
= memcached_string_create(memc
, NULL
, 100);
2491 for (x
= 0; x
< 1024; x
++)
2493 memcached_return rc
;
2494 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
2495 assert(rc
== MEMCACHED_SUCCESS
);
2497 memcached_string_free(string
);
2502 static test_return
string_alloc_append_toobig(memcached_st
*memc
)
2504 memcached_return rc
;
2506 char buffer
[SMALL_STRING_LEN
];
2507 memcached_string_st
*string
;
2509 /* Ring the bell! */
2510 memset(buffer
, 6, SMALL_STRING_LEN
);
2512 string
= memcached_string_create(memc
, NULL
, 100);
2515 for (x
= 0; x
< 1024; x
++)
2517 rc
= memcached_string_append(string
, buffer
, SMALL_STRING_LEN
);
2518 assert(rc
== MEMCACHED_SUCCESS
);
2520 rc
= memcached_string_append(string
, buffer
, INT64_MAX
);
2521 assert(rc
== MEMCACHED_MEMORY_ALLOCATION_FAILURE
);
2522 memcached_string_free(string
);
2527 static test_return
cleanup_pairs(memcached_st
*memc
__attribute__((unused
)))
2529 pairs_free(global_pairs
);
2534 static test_return
generate_pairs(memcached_st
*memc
__attribute__((unused
)))
2536 unsigned long long x
;
2537 global_pairs
= pairs_generate(GLOBAL_COUNT
, 400);
2538 global_count
= GLOBAL_COUNT
;
2540 for (x
= 0; x
< global_count
; x
++)
2542 global_keys
[x
]= global_pairs
[x
].key
;
2543 global_keys_length
[x
]= global_pairs
[x
].key_length
;
2549 static test_return
generate_large_pairs(memcached_st
*memc
__attribute__((unused
)))
2551 unsigned long long x
;
2552 global_pairs
= pairs_generate(GLOBAL2_COUNT
, MEMCACHED_MAX_BUFFER
+10);
2553 global_count
= GLOBAL2_COUNT
;
2555 for (x
= 0; x
< global_count
; x
++)
2557 global_keys
[x
]= global_pairs
[x
].key
;
2558 global_keys_length
[x
]= global_pairs
[x
].key_length
;
2564 static test_return
generate_data(memcached_st
*memc
)
2566 execute_set(memc
, global_pairs
, global_count
);
2571 static test_return
generate_data_with_stats(memcached_st
*memc
)
2573 memcached_stat_st
*stat_p
;
2574 memcached_return rc
;
2575 uint32_t host_index
= 0;
2576 execute_set(memc
, global_pairs
, global_count
);
2578 //TODO: hosts used size stats
2579 stat_p
= memcached_stat(memc
, NULL
, &rc
);
2582 for (host_index
= 0; host_index
< SERVERS_TO_CREATE
; host_index
++)
2584 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
);
2587 memcached_stat_free(NULL
, stat_p
);
2591 static test_return
generate_buffer_data(memcached_st
*memc
)
2596 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
2597 generate_data(memc
);
2602 static test_return
get_read_count(memcached_st
*memc
)
2605 memcached_return rc
;
2606 memcached_st
*clone
;
2608 clone
= memcached_clone(NULL
, memc
);
2611 memcached_server_add_with_weight(clone
, "localhost", 6666, 0);
2615 size_t return_value_length
;
2619 for (x
= count
= 0; x
< global_count
; x
++)
2621 return_value
= memcached_get(clone
, global_keys
[x
], global_keys_length
[x
],
2622 &return_value_length
, &flags
, &rc
);
2623 if (rc
== MEMCACHED_SUCCESS
)
2630 fprintf(stderr
, "\t%u -> %u", global_count
, count
);
2633 memcached_free(clone
);
2638 static test_return
get_read(memcached_st
*memc
)
2641 memcached_return rc
;
2645 size_t return_value_length
;
2648 for (x
= 0; x
< global_count
; x
++)
2650 return_value
= memcached_get(memc
, global_keys
[x
], global_keys_length
[x
],
2651 &return_value_length
, &flags
, &rc
);
2653 assert(return_value);
2654 assert(rc == MEMCACHED_SUCCESS);
2656 if (rc
== MEMCACHED_SUCCESS
&& return_value
)
2664 static test_return
mget_read(memcached_st
*memc
)
2666 memcached_return rc
;
2668 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2669 assert(rc
== MEMCACHED_SUCCESS
);
2670 /* Turn this into a help function */
2672 char return_key
[MEMCACHED_MAX_KEY
];
2673 size_t return_key_length
;
2675 size_t return_value_length
;
2678 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2679 &return_value_length
, &flags
, &rc
)))
2681 assert(return_value
);
2682 assert(rc
== MEMCACHED_SUCCESS
);
2690 static test_return
mget_read_result(memcached_st
*memc
)
2692 memcached_return rc
;
2694 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2695 assert(rc
== MEMCACHED_SUCCESS
);
2696 /* Turn this into a help function */
2698 memcached_result_st results_obj
;
2699 memcached_result_st
*results
;
2701 results
= memcached_result_create(memc
, &results_obj
);
2703 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
2706 assert(rc
== MEMCACHED_SUCCESS
);
2709 memcached_result_free(&results_obj
);
2715 static test_return
mget_read_function(memcached_st
*memc
)
2717 memcached_return rc
;
2718 unsigned int counter
;
2719 memcached_execute_function callbacks
[1];
2721 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
);
2722 assert(rc
== MEMCACHED_SUCCESS
);
2724 callbacks
[0]= &callback_counter
;
2726 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1);
2731 static test_return
delete_generate(memcached_st
*memc
)
2735 for (x
= 0; x
< global_count
; x
++)
2737 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
2743 static test_return
delete_buffer_generate(memcached_st
*memc
)
2749 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
2751 for (x
= 0; x
< global_count
; x
++)
2753 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
2759 static test_return
free_data(memcached_st
*memc
__attribute__((unused
)))
2761 pairs_free(global_pairs
);
2766 static test_return
add_host_test1(memcached_st
*memc
)
2769 memcached_return rc
;
2770 char servername
[]= "0.example.com";
2771 memcached_server_st
*servers
;
2773 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
2775 assert(1 == memcached_server_list_count(servers
));
2777 for (x
= 2; x
< 20; x
++)
2779 char buffer
[SMALL_STRING_LEN
];
2781 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
2782 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
2784 assert(rc
== MEMCACHED_SUCCESS
);
2785 assert(x
== memcached_server_list_count(servers
));
2788 rc
= memcached_server_push(memc
, servers
);
2789 assert(rc
== MEMCACHED_SUCCESS
);
2790 rc
= memcached_server_push(memc
, servers
);
2791 assert(rc
== MEMCACHED_SUCCESS
);
2793 memcached_server_list_free(servers
);
2798 static memcached_return
pre_nonblock(memcached_st
*memc
)
2800 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
2802 return MEMCACHED_SUCCESS
;
2805 static memcached_return
pre_nonblock_binary(memcached_st
*memc
)
2807 memcached_return rc
= MEMCACHED_FAILURE
;
2808 memcached_st
*clone
;
2810 clone
= memcached_clone(NULL
, memc
);
2812 // The memcached_version needs to be done on a clone, because the server
2813 // will not toggle protocol on an connection.
2814 memcached_version(clone
);
2816 if (clone
->hosts
[0].major_version
>= 1 && clone
->hosts
[0].minor_version
> 2)
2818 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
2819 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
2820 assert(rc
== MEMCACHED_SUCCESS
);
2821 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
2824 memcached_free(clone
);
2828 static memcached_return
pre_murmur(memcached_st
*memc
)
2830 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
2832 return MEMCACHED_SUCCESS
;
2835 static memcached_return
pre_jenkins(memcached_st
*memc
)
2837 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_JENKINS
);
2839 return MEMCACHED_SUCCESS
;
2843 static memcached_return
pre_md5(memcached_st
*memc
)
2845 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MD5
);
2847 return MEMCACHED_SUCCESS
;
2850 static memcached_return
pre_crc(memcached_st
*memc
)
2852 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_CRC
);
2854 return MEMCACHED_SUCCESS
;
2857 static memcached_return
pre_hsieh(memcached_st
*memc
)
2859 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_HSIEH
);
2861 return MEMCACHED_SUCCESS
;
2864 static memcached_return
pre_hash_fnv1_64(memcached_st
*memc
)
2866 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_64
);
2868 return MEMCACHED_SUCCESS
;
2871 static memcached_return
pre_hash_fnv1a_64(memcached_st
*memc
)
2873 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_64
);
2875 return MEMCACHED_SUCCESS
;
2878 static memcached_return
pre_hash_fnv1_32(memcached_st
*memc
)
2880 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_32
);
2882 return MEMCACHED_SUCCESS
;
2885 static memcached_return
pre_hash_fnv1a_32(memcached_st
*memc
)
2887 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_32
);
2889 return MEMCACHED_SUCCESS
;
2892 static memcached_return
pre_behavior_ketama(memcached_st
*memc
)
2894 memcached_return rc
;
2897 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA
, 1);
2898 assert(rc
== MEMCACHED_SUCCESS
);
2900 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA
);
2903 return MEMCACHED_SUCCESS
;
2906 static memcached_return
pre_behavior_ketama_weighted(memcached_st
*memc
)
2908 memcached_return rc
;
2911 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2912 assert(rc
== MEMCACHED_SUCCESS
);
2914 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2917 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2918 assert(rc
== MEMCACHED_SUCCESS
);
2920 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2921 assert(value
== MEMCACHED_HASH_MD5
);
2922 return MEMCACHED_SUCCESS
;
2925 static memcached_return
pre_binary(memcached_st
*memc
)
2927 memcached_return rc
= MEMCACHED_FAILURE
;
2928 memcached_st
*clone
;
2930 clone
= memcached_clone(NULL
, memc
);
2932 // The memcached_version needs to be done on a clone, because the server
2933 // will not toggle protocol on an connection.
2934 memcached_version(clone
);
2936 if (clone
->hosts
[0].major_version
>= 1 && clone
->hosts
[0].minor_version
> 2)
2938 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
2939 assert(rc
== MEMCACHED_SUCCESS
);
2940 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
2943 memcached_free(clone
);
2947 static void my_free(memcached_st
*ptr
__attribute__((unused
)), void *mem
)
2952 static void *my_malloc(memcached_st
*ptr
__attribute__((unused
)), const size_t size
)
2954 return malloc(size
);
2957 static void *my_realloc(memcached_st
*ptr
__attribute__((unused
)), void *mem
, const size_t size
)
2959 return realloc(mem
, size
);
2962 static memcached_return
set_prefix(memcached_st
*memc
)
2964 memcached_return rc
;
2965 const char *key
= "mine";
2968 /* Make sure be default none exists */
2969 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2970 assert(rc
== MEMCACHED_FAILURE
);
2972 /* Test a clean set */
2973 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
2974 assert(rc
== MEMCACHED_SUCCESS
);
2976 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2977 assert(memcmp(value
, key
, 4) == 0);
2978 assert(rc
== MEMCACHED_SUCCESS
);
2980 /* Test that we can turn it off */
2981 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
2982 assert(rc
== MEMCACHED_SUCCESS
);
2984 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2985 assert(rc
== MEMCACHED_FAILURE
);
2987 /* Now setup for main test */
2988 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
2989 assert(rc
== MEMCACHED_SUCCESS
);
2991 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
2992 assert(rc
== MEMCACHED_SUCCESS
);
2993 assert(memcmp(value
, key
, 4) == 0);
2995 /* Set to Zero, and then Set to something too large */
2998 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
2999 assert(rc
== MEMCACHED_SUCCESS
);
3001 value
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3002 assert(rc
== MEMCACHED_FAILURE
);
3003 assert(value
== NULL
);
3005 /* Test a long key for failure */
3006 /* TODO, extend test to determine based on setting, what result should be */
3007 long_key
= "Thisismorethentheallottednumberofcharacters";
3008 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3009 //assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
3010 assert(rc
== MEMCACHED_SUCCESS
);
3012 /* Now test a key with spaces (which will fail from long key, since bad key is not set) */
3013 long_key
= "This is more then the allotted number of characters";
3014 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3015 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3017 /* Test for a bad prefix, but with a short key */
3018 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, 1);
3019 assert(rc
== MEMCACHED_SUCCESS
);
3021 long_key
= "dog cat";
3022 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3023 assert(rc
== MEMCACHED_BAD_KEY_PROVIDED
);
3026 return MEMCACHED_SUCCESS
;
3029 static memcached_return
set_memory_alloc(memcached_st
*memc
)
3032 memcached_malloc_function test_ptr
;
3033 memcached_return rc
;
3035 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, (void*)&my_malloc
);
3036 assert(rc
== MEMCACHED_SUCCESS
);
3037 test_ptr
= (memcached_malloc_function
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
3038 assert(rc
== MEMCACHED_SUCCESS
);
3039 assert(test_ptr
== my_malloc
);
3043 memcached_realloc_function test_ptr
;
3044 memcached_return rc
;
3046 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, (void*)&my_realloc
);
3047 assert(rc
== MEMCACHED_SUCCESS
);
3048 test_ptr
= (memcached_realloc_function
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
3049 assert(rc
== MEMCACHED_SUCCESS
);
3050 assert(test_ptr
== my_realloc
);
3054 memcached_free_function test_ptr
;
3055 memcached_return rc
;
3057 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, (void*)my_free
);
3058 assert(rc
== MEMCACHED_SUCCESS
);
3059 test_ptr
= (memcached_free_function
)memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
3060 assert(rc
== MEMCACHED_SUCCESS
);
3061 assert(test_ptr
== my_free
);
3064 return MEMCACHED_SUCCESS
;
3067 static memcached_return
enable_consistent(memcached_st
*memc
)
3069 memcached_server_distribution value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
3070 memcached_hash hash
;
3071 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
3074 value
= (memcached_server_distribution
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
3075 assert(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
3077 hash
= (memcached_hash
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
3078 assert(hash
== MEMCACHED_HASH_HSIEH
);
3081 return MEMCACHED_SUCCESS
;
3084 static memcached_return
enable_cas(memcached_st
*memc
)
3086 unsigned int set
= 1;
3088 memcached_version(memc
);
3090 if ((memc
->hosts
[0].major_version
>= 1 && (memc
->hosts
[0].minor_version
== 2 && memc
->hosts
[0].micro_version
>= 4))
3091 || memc
->hosts
[0].minor_version
> 2)
3093 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
3095 return MEMCACHED_SUCCESS
;
3098 return MEMCACHED_FAILURE
;
3101 static memcached_return
check_for_1_2_3(memcached_st
*memc
)
3103 memcached_version(memc
);
3105 if ((memc
->hosts
[0].major_version
>= 1 && (memc
->hosts
[0].minor_version
== 2 && memc
->hosts
[0].micro_version
>= 4))
3106 || memc
->hosts
[0].minor_version
> 2)
3107 return MEMCACHED_SUCCESS
;
3109 return MEMCACHED_FAILURE
;
3112 static memcached_return
pre_unix_socket(memcached_st
*memc
)
3114 memcached_return rc
;
3117 memcached_server_list_free(memc
->hosts
);
3119 memc
->number_of_hosts
= 0;
3121 if (stat("/tmp/memcached.socket", &buf
))
3122 return MEMCACHED_FAILURE
;
3124 rc
= memcached_server_add_unix_socket_with_weight(memc
, "/tmp/memcached.socket", 0);
3129 static memcached_return
pre_nodelay(memcached_st
*memc
)
3131 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3132 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
3134 return MEMCACHED_SUCCESS
;
3137 static memcached_return
pre_settimer(memcached_st
*memc
)
3139 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
3140 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
3142 return MEMCACHED_SUCCESS
;
3145 static memcached_return
poll_timeout(memcached_st
*memc
)
3151 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
3153 timeout
= (int32_t)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
3155 assert(timeout
== 100);
3157 return MEMCACHED_SUCCESS
;
3160 static test_return
noreply_test(memcached_st
*memc
)
3162 memcached_return ret
;
3163 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
3164 assert(ret
== MEMCACHED_SUCCESS
);
3165 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
3166 assert(ret
== MEMCACHED_SUCCESS
);
3167 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
3168 assert(ret
== MEMCACHED_SUCCESS
);
3169 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NOREPLY
) == 1);
3170 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
) == 1);
3171 assert(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
) == 1);
3173 for (int count
=0; count
< 5; ++count
)
3175 for (int x
=0; x
< 100; ++x
)
3178 size_t len
=sprintf(key
, "%d", x
);
3182 ret
=memcached_add(memc
, key
, len
, key
, len
, 0, 0);
3185 ret
=memcached_replace(memc
, key
, len
, key
, len
, 0, 0);
3188 ret
=memcached_set(memc
, key
, len
, key
, len
, 0, 0);
3191 ret
=memcached_append(memc
, key
, len
, key
, len
, 0, 0);
3194 ret
=memcached_prepend(memc
, key
, len
, key
, len
, 0, 0);
3197 assert(ret
== MEMCACHED_SUCCESS
|| ret
== MEMCACHED_BUFFERED
);
3201 ** NOTE: Don't ever do this in your code! this is not a supported use of the
3202 ** API and is _ONLY_ done this way to verify that the library works the
3203 ** way it is supposed to do!!!!
3206 for (int x
=0; x
< memc
->number_of_hosts
; ++x
)
3207 no_msg
+=memc
->hosts
[x
].cursor_active
;
3209 assert(no_msg
== 0);
3210 assert(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
3213 ** Now validate that all items was set properly!
3215 for (int x
=0; x
< 100; ++x
)
3218 size_t len
=sprintf(key
, "%d", x
);
3221 char* value
=memcached_get(memc
, key
, strlen(key
),
3222 &length
, &flags
, &ret
);
3223 assert(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
3226 case 0: /* FALLTHROUGH */
3227 case 1: /* FALLTHROUGH */
3229 assert(strncmp(value
, key
, len
) == 0);
3230 assert(len
== length
);
3233 assert(length
== len
* 2);
3236 assert(length
== len
* 3);
3243 /* Try setting an illegal cas value (should not return an error to
3244 * the caller (because we don't expect a return message from the server)
3246 char* keys
[]= {"0"};
3247 size_t lengths
[]= {1};
3250 memcached_result_st results_obj
;
3251 memcached_result_st
*results
;
3252 ret
=memcached_mget(memc
, keys
, lengths
, 1);
3253 assert(ret
== MEMCACHED_SUCCESS
);
3255 results
=memcached_result_create(memc
, &results_obj
);
3257 results
=memcached_fetch_result(memc
, &results_obj
, &ret
);
3259 assert(ret
== MEMCACHED_SUCCESS
);
3260 uint64_t cas
= memcached_result_cas(results
);
3261 memcached_result_free(&results_obj
);
3263 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
3264 assert(ret
== MEMCACHED_SUCCESS
);
3267 * The item will have a new cas value, so try to set it again with the old
3268 * value. This should fail!
3270 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
3271 assert(ret
== MEMCACHED_SUCCESS
);
3272 assert(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
3273 char* value
=memcached_get(memc
, keys
[0], lengths
[0], &length
, &flags
, &ret
);
3274 assert(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
3277 return TEST_SUCCESS
;
3280 static test_return
analyzer_test(memcached_st
*memc
)
3282 memcached_return rc
;
3283 memcached_stat_st
*stat
;
3284 memcached_analysis_st
*report
;
3286 stat
= memcached_stat(memc
, NULL
, &rc
);
3287 assert(rc
== MEMCACHED_SUCCESS
);
3290 report
= memcached_analyze(memc
, stat
, &rc
);
3291 assert(rc
== MEMCACHED_SUCCESS
);
3295 memcached_stat_free(NULL
, stat
);
3297 return TEST_SUCCESS
;
3300 static void increment_request_id(uint16_t *id
)
3303 if ((*id
& UDP_REQUEST_ID_THREAD_MASK
) != 0)
3307 static uint16_t *get_udp_request_ids(memcached_st
*memc
)
3309 uint16_t *ids
= malloc(sizeof(uint16_t) * memc
->number_of_hosts
);
3310 assert(ids
!= NULL
);
3312 for (x
= 0; x
< memc
->number_of_hosts
; x
++)
3313 ids
[x
]= get_udp_datagram_request_id((struct udp_datagram_header_st
*) memc
->hosts
[x
].write_buffer
);
3318 static test_return
post_udp_op_check(memcached_st
*memc
, uint16_t *expected_req_ids
)
3321 memcached_server_st
*cur_server
= memc
->hosts
;
3322 uint16_t *cur_req_ids
= get_udp_request_ids(memc
);
3323 for (x
= 0; x
< memc
->number_of_hosts
; x
++)
3325 assert(cur_server
[x
].cursor_active
== 0);
3326 assert(cur_req_ids
[x
] == expected_req_ids
[x
]);
3328 free(expected_req_ids
);
3330 return TEST_SUCCESS
;
3334 ** There is a little bit of a hack here, instead of removing
3335 ** the servers, I just set num host to 0 and them add then new udp servers
3337 static memcached_return
init_udp(memcached_st
*memc
)
3339 memcached_version(memc
);
3340 /* For the time being, only support udp test for >= 1.2.6 && < 1.3 */
3341 if (memc
->hosts
[0].major_version
!= 1 || memc
->hosts
[0].minor_version
!= 2
3342 || memc
->hosts
[0].micro_version
< 6)
3343 return MEMCACHED_FAILURE
;
3345 uint32_t num_hosts
= memc
->number_of_hosts
;
3347 memcached_server_st servers
[num_hosts
];
3348 memcpy(servers
, memc
->hosts
, sizeof(memcached_server_st
) * num_hosts
);
3349 for (x
= 0; x
< num_hosts
; x
++)
3350 memcached_server_free(&memc
->hosts
[x
]);
3351 memc
->number_of_hosts
= 0;
3352 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
, 1);
3353 for (x
= 0; x
< num_hosts
; x
++)
3355 assert(memcached_server_add_udp(memc
, servers
[x
].hostname
, servers
[x
].port
) == MEMCACHED_SUCCESS
);
3356 assert(memc
->hosts
[x
].write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
3358 return MEMCACHED_SUCCESS
;
3361 static memcached_return
binary_init_udp(memcached_st
*memc
)
3364 return init_udp(memc
);
3367 /* Make sure that I cant add a tcp server to a udp client */
3368 static test_return
add_tcp_server_udp_client_test(memcached_st
*memc
)
3370 memcached_server_st server
;
3371 memcached_server_clone(&server
, &memc
->hosts
[0]);
3372 assert(memcached_server_remove(&(memc
->hosts
[0])) == MEMCACHED_SUCCESS
);
3373 assert(memcached_server_add(memc
, server
.hostname
, server
.port
) == MEMCACHED_INVALID_HOST_PROTOCOL
);
3374 return TEST_SUCCESS
;
3377 /* Make sure that I cant add a udp server to a tcp client */
3378 static test_return
add_udp_server_tcp_client_test(memcached_st
*memc
)
3380 memcached_server_st server
;
3381 memcached_server_clone(&server
, &memc
->hosts
[0]);
3382 assert(memcached_server_remove(&(memc
->hosts
[0])) == MEMCACHED_SUCCESS
);
3384 memcached_st tcp_client
;
3385 memcached_create(&tcp_client
);
3386 assert(memcached_server_add_udp(&tcp_client
, server
.hostname
, server
.port
) == MEMCACHED_INVALID_HOST_PROTOCOL
);
3387 return TEST_SUCCESS
;
3390 static test_return
set_udp_behavior_test(memcached_st
*memc
)
3393 memcached_quit(memc
);
3394 memc
->number_of_hosts
= 0;
3395 run_distribution(memc
);
3396 assert(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
, 1) == MEMCACHED_SUCCESS
);
3397 assert(memc
->flags
& MEM_USE_UDP
);
3398 assert(memc
->flags
& MEM_NOREPLY
);;
3400 assert(memc
->number_of_hosts
== 0);
3402 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_USE_UDP
,0);
3403 assert(!(memc
->flags
& MEM_USE_UDP
));
3404 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
,0);
3405 assert(!(memc
->flags
& MEM_NOREPLY
));
3406 return TEST_SUCCESS
;
3409 static test_return
udp_set_test(memcached_st
*memc
)
3412 unsigned int num_iters
= 1025; //request id rolls over at 1024
3413 for (x
= 0; x
< num_iters
;x
++)
3415 memcached_return rc
;
3417 char *value
= "when we sanitize";
3418 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3419 unsigned int server_key
= memcached_generate_hash(memc
,key
,strlen(key
));
3420 size_t init_offset
= memc
->hosts
[server_key
].write_buffer_offset
;
3421 rc
= memcached_set(memc
, key
, strlen(key
),
3422 value
, strlen(value
),
3423 (time_t)0, (uint32_t)0);
3424 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
3425 /** NB, the check below assumes that if new write_ptr is less than
3426 * the original write_ptr that we have flushed. For large payloads, this
3427 * maybe an invalid assumption, but for the small payload we have it is OK
3429 if (rc
== MEMCACHED_SUCCESS
||
3430 memc
->hosts
[server_key
].write_buffer_offset
< init_offset
)
3431 increment_request_id(&expected_ids
[server_key
]);
3433 if (rc
== MEMCACHED_SUCCESS
)
3435 assert(memc
->hosts
[server_key
].write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
3439 assert(memc
->hosts
[server_key
].write_buffer_offset
!= UDP_DATAGRAM_HEADER_LENGTH
);
3440 assert(memc
->hosts
[server_key
].write_buffer_offset
<= MAX_UDP_DATAGRAM_LENGTH
);
3442 assert(post_udp_op_check(memc
,expected_ids
) == TEST_SUCCESS
);
3444 return TEST_SUCCESS
;
3447 static test_return
udp_buffered_set_test(memcached_st
*memc
)
3449 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
3450 return udp_set_test(memc
);
3453 static test_return
udp_set_too_big_test(memcached_st
*memc
)
3455 memcached_return rc
;
3457 char value
[MAX_UDP_DATAGRAM_LENGTH
];
3458 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3459 rc
= memcached_set(memc
, key
, strlen(key
),
3460 value
, MAX_UDP_DATAGRAM_LENGTH
,
3461 (time_t)0, (uint32_t)0);
3462 assert(rc
== MEMCACHED_WRITE_FAILURE
);
3463 return post_udp_op_check(memc
,expected_ids
);
3466 test_return
udp_delete_test(memcached_st
*memc
)
3469 unsigned int num_iters
= 1025; //request id rolls over at 1024
3470 for (x
= 0; x
< num_iters
;x
++)
3472 memcached_return rc
;
3474 uint16_t *expected_ids
=get_udp_request_ids(memc
);
3475 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
3476 size_t init_offset
= memc
->hosts
[server_key
].write_buffer_offset
;
3477 rc
= memcached_delete(memc
, key
, strlen(key
), 0);
3478 assert(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
3479 if (rc
== MEMCACHED_SUCCESS
|| memc
->hosts
[server_key
].write_buffer_offset
< init_offset
)
3480 increment_request_id(&expected_ids
[server_key
]);
3481 if (rc
== MEMCACHED_SUCCESS
)
3482 assert(memc
->hosts
[server_key
].write_buffer_offset
== UDP_DATAGRAM_HEADER_LENGTH
);
3485 assert(memc
->hosts
[server_key
].write_buffer_offset
!= UDP_DATAGRAM_HEADER_LENGTH
);
3486 assert(memc
->hosts
[server_key
].write_buffer_offset
<= MAX_UDP_DATAGRAM_LENGTH
);
3488 assert(post_udp_op_check(memc
,expected_ids
) == TEST_SUCCESS
);
3490 return TEST_SUCCESS
;
3493 static test_return
udp_buffered_delete_test(memcached_st
*memc
)
3495 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
3496 return udp_delete_test(memc
);
3499 test_return
udp_verbosity_test(memcached_st
*memc
)
3501 memcached_return rc
;
3502 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3504 for (x
= 0; x
< memc
->number_of_hosts
;x
++)
3505 increment_request_id(&expected_ids
[x
]);
3507 rc
= memcached_verbosity(memc
,3);
3508 assert(rc
== MEMCACHED_SUCCESS
);
3509 return post_udp_op_check(memc
,expected_ids
);
3512 test_return
udp_quit_test(memcached_st
*memc
)
3514 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3515 memcached_quit(memc
);
3516 return post_udp_op_check(memc
, expected_ids
);
3519 test_return
udp_flush_test(memcached_st
*memc
)
3521 memcached_return rc
;
3522 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3524 for (x
= 0; x
< memc
->number_of_hosts
;x
++)
3525 increment_request_id(&expected_ids
[x
]);
3527 rc
= memcached_flush(memc
,0);
3528 assert(rc
== MEMCACHED_SUCCESS
);
3529 return post_udp_op_check(memc
,expected_ids
);
3532 test_return
udp_incr_test(memcached_st
*memc
)
3534 memcached_return rc
;
3537 rc
= memcached_set(memc
, key
, strlen(key
),
3538 value
, strlen(value
),
3539 (time_t)0, (uint32_t)0);
3541 assert(rc
== MEMCACHED_SUCCESS
);
3542 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3543 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
3544 increment_request_id(&expected_ids
[server_key
]);
3546 rc
= memcached_increment(memc
, key
, strlen(key
), 1, &newvalue
);
3547 assert(rc
== MEMCACHED_SUCCESS
);
3548 return post_udp_op_check(memc
, expected_ids
);
3551 test_return
udp_decr_test(memcached_st
*memc
)
3553 memcached_return rc
;
3556 rc
= memcached_set(memc
, key
, strlen(key
),
3557 value
, strlen(value
),
3558 (time_t)0, (uint32_t)0);
3560 assert(rc
== MEMCACHED_SUCCESS
);
3561 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3562 unsigned int server_key
= memcached_generate_hash(memc
, key
, strlen(key
));
3563 increment_request_id(&expected_ids
[server_key
]);
3565 rc
= memcached_decrement(memc
, key
, strlen(key
), 1, &newvalue
);
3566 assert(rc
== MEMCACHED_SUCCESS
);
3567 return post_udp_op_check(memc
, expected_ids
);
3571 test_return
udp_stat_test(memcached_st
*memc
)
3573 memcached_stat_st
* rv
= NULL
;
3574 memcached_return rc
;
3576 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3577 rv
= memcached_stat(memc
, args
, &rc
);
3579 assert(rc
== MEMCACHED_NOT_SUPPORTED
);
3580 return post_udp_op_check(memc
, expected_ids
);
3583 test_return
udp_version_test(memcached_st
*memc
)
3585 memcached_return rc
;
3586 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3587 rc
= memcached_version(memc
);
3588 assert(rc
== MEMCACHED_NOT_SUPPORTED
);
3589 return post_udp_op_check(memc
, expected_ids
);
3592 test_return
udp_get_test(memcached_st
*memc
)
3594 memcached_return rc
;
3597 uint16_t *expected_ids
= get_udp_request_ids(memc
);
3598 char *val
= memcached_get(memc
, key
, strlen(key
), &vlen
, (uint32_t)0, &rc
);
3599 assert(rc
== MEMCACHED_NOT_SUPPORTED
);
3600 assert(val
== NULL
);
3601 return post_udp_op_check(memc
, expected_ids
);
3604 test_return
udp_mixed_io_test(memcached_st
*memc
)
3607 test_st mixed_io_ops
[] ={
3608 {"udp_set_test", 0, udp_set_test
},
3609 {"udp_set_too_big_test", 0, udp_set_too_big_test
},
3610 {"udp_delete_test", 0, udp_delete_test
},
3611 {"udp_verbosity_test", 0, udp_verbosity_test
},
3612 {"udp_quit_test", 0, udp_quit_test
},
3613 {"udp_flush_test", 0, udp_flush_test
},
3614 {"udp_incr_test", 0, udp_incr_test
},
3615 {"udp_decr_test", 0, udp_decr_test
},
3616 {"udp_version_test", 0, udp_version_test
}
3619 for (x
= 0; x
< 500; x
++)
3621 current_op
= mixed_io_ops
[random() % 9];
3622 assert(current_op
.function(memc
) == TEST_SUCCESS
);
3624 return TEST_SUCCESS
;
3627 test_st udp_setup_server_tests
[] ={
3628 {"set_udp_behavior_test", 0, set_udp_behavior_test
},
3629 {"add_tcp_server_udp_client_test", 0, add_tcp_server_udp_client_test
},
3630 {"add_udp_server_tcp_client_test", 0, add_udp_server_tcp_client_test
},
3634 test_st upd_io_tests
[] ={
3635 {"udp_set_test", 0, udp_set_test
},
3636 {"udp_buffered_set_test", 0, udp_buffered_set_test
},
3637 {"udp_set_too_big_test", 0, udp_set_too_big_test
},
3638 {"udp_delete_test", 0, udp_delete_test
},
3639 {"udp_buffered_delete_test", 0, udp_buffered_delete_test
},
3640 {"udp_verbosity_test", 0, udp_verbosity_test
},
3641 {"udp_quit_test", 0, udp_quit_test
},
3642 {"udp_flush_test", 0, udp_flush_test
},
3643 {"udp_incr_test", 0, udp_incr_test
},
3644 {"udp_decr_test", 0, udp_decr_test
},
3645 {"udp_stat_test", 0, udp_stat_test
},
3646 {"udp_version_test", 0, udp_version_test
},
3647 {"udp_get_test", 0, udp_get_test
},
3648 {"udp_mixed_io_test", 0, udp_mixed_io_test
},
3652 /* Clean the server before beginning testing */
3654 {"flush", 0, flush_test
},
3655 {"init", 0, init_test
},
3656 {"allocation", 0, allocation_test
},
3657 {"server_list_null_test", 0, server_list_null_test
},
3658 {"server_unsort", 0, server_unsort_test
},
3659 {"server_sort", 0, server_sort_test
},
3660 {"server_sort2", 0, server_sort2_test
},
3661 {"clone_test", 0, clone_test
},
3662 {"error", 0, error_test
},
3663 {"set", 0, set_test
},
3664 {"set2", 0, set_test2
},
3665 {"set3", 0, set_test3
},
3666 {"add", 1, add_test
},
3667 {"replace", 1, replace_test
},
3668 {"delete", 1, delete_test
},
3669 {"get", 1, get_test
},
3670 {"get2", 0, get_test2
},
3671 {"get3", 0, get_test3
},
3672 {"get4", 0, get_test4
},
3673 {"partial mget", 0, get_test5
},
3674 {"stats_servername", 0, stats_servername_test
},
3675 {"increment", 0, increment_test
},
3676 {"increment_with_initial", 1, increment_with_initial_test
},
3677 {"decrement", 0, decrement_test
},
3678 {"decrement_with_initial", 1, decrement_with_initial_test
},
3679 {"quit", 0, quit_test
},
3680 {"mget", 1, mget_test
},
3681 {"mget_result", 1, mget_result_test
},
3682 {"mget_result_alloc", 1, mget_result_alloc_test
},
3683 {"mget_result_function", 1, mget_result_function
},
3684 {"get_stats", 0, get_stats
},
3685 {"add_host_test", 0, add_host_test
},
3686 {"add_host_test_1", 0, add_host_test1
},
3687 {"get_stats_keys", 0, get_stats_keys
},
3688 {"behavior_test", 0, get_stats_keys
},
3689 {"callback_test", 0, get_stats_keys
},
3690 {"version_string_test", 0, version_string_test
},
3691 {"bad_key", 1, bad_key_test
},
3692 {"memcached_server_cursor", 1, memcached_server_cursor_test
},
3693 {"read_through", 1, read_through
},
3694 {"delete_through", 1, delete_through
},
3695 {"noreply", 1, noreply_test
},
3696 {"analyzer", 1, analyzer_test
},
3700 test_st async_tests
[] ={
3701 {"add", 1, add_wrapper
},
3705 test_st string_tests
[] ={
3706 {"string static with null", 0, string_static_null
},
3707 {"string alloc with null", 0, string_alloc_null
},
3708 {"string alloc with 1K", 0, string_alloc_with_size
},
3709 {"string alloc with malloc failure", 0, string_alloc_with_size_toobig
},
3710 {"string append", 0, string_alloc_append
},
3711 {"string append failure (too big)", 0, string_alloc_append_toobig
},
3715 test_st result_tests
[] ={
3716 {"result static", 0, result_static
},
3717 {"result alloc", 0, result_alloc
},
3721 test_st version_1_2_3
[] ={
3722 {"append", 0, append_test
},
3723 {"prepend", 0, prepend_test
},
3724 {"cas", 0, cas_test
},
3725 {"cas2", 0, cas2_test
},
3726 {"append_binary", 0, append_binary_test
},
3730 test_st user_tests
[] ={
3731 {"user_supplied_bug1", 0, user_supplied_bug1
},
3732 {"user_supplied_bug2", 0, user_supplied_bug2
},
3733 {"user_supplied_bug3", 0, user_supplied_bug3
},
3734 {"user_supplied_bug4", 0, user_supplied_bug4
},
3735 {"user_supplied_bug5", 1, user_supplied_bug5
},
3736 {"user_supplied_bug6", 1, user_supplied_bug6
},
3737 {"user_supplied_bug7", 1, user_supplied_bug7
},
3738 {"user_supplied_bug8", 1, user_supplied_bug8
},
3739 {"user_supplied_bug9", 1, user_supplied_bug9
},
3740 {"user_supplied_bug10", 1, user_supplied_bug10
},
3741 {"user_supplied_bug11", 1, user_supplied_bug11
},
3742 {"user_supplied_bug12", 1, user_supplied_bug12
},
3743 {"user_supplied_bug13", 1, user_supplied_bug13
},
3744 {"user_supplied_bug14", 1, user_supplied_bug14
},
3745 {"user_supplied_bug15", 1, user_supplied_bug15
},
3746 {"user_supplied_bug16", 1, user_supplied_bug16
},
3749 ** It seems to be something weird with the character sets..
3750 ** value_fetch is unable to parse the value line (iscntrl "fails"), so I
3751 ** guess I need to find out how this is supposed to work.. Perhaps I need
3752 ** to run the test in a specific locale (I tried zh_CN.UTF-8 without success,
3753 ** so just disable the code for now...).
3755 {"user_supplied_bug17", 1, user_supplied_bug17
},
3757 {"user_supplied_bug18", 1, user_supplied_bug18
},
3758 {"user_supplied_bug19", 1, user_supplied_bug19
},
3759 {"user_supplied_bug20", 1, user_supplied_bug20
},
3763 test_st generate_tests
[] ={
3764 {"generate_pairs", 1, generate_pairs
},
3765 {"generate_data", 1, generate_data
},
3766 {"get_read", 0, get_read
},
3767 {"delete_generate", 0, delete_generate
},
3768 {"generate_buffer_data", 1, generate_buffer_data
},
3769 {"delete_buffer", 0, delete_buffer_generate
},
3770 {"generate_data", 1, generate_data
},
3771 {"mget_read", 0, mget_read
},
3772 {"mget_read_result", 0, mget_read_result
},
3773 {"mget_read_function", 0, mget_read_function
},
3774 {"cleanup", 1, cleanup_pairs
},
3775 {"generate_large_pairs", 1, generate_large_pairs
},
3776 {"generate_data", 1, generate_data
},
3777 {"generate_buffer_data", 1, generate_buffer_data
},
3778 {"cleanup", 1, cleanup_pairs
},
3782 test_st consistent_tests
[] ={
3783 {"generate_pairs", 1, generate_pairs
},
3784 {"generate_data", 1, generate_data
},
3785 {"get_read", 0, get_read_count
},
3786 {"cleanup", 1, cleanup_pairs
},
3790 test_st consistent_weighted_tests
[] ={
3791 {"generate_pairs", 1, generate_pairs
},
3792 {"generate_data", 1, generate_data_with_stats
},
3793 {"get_read", 0, get_read_count
},
3794 {"cleanup", 1, cleanup_pairs
},
3798 collection_st collection
[] ={
3799 {"udp_setup", init_udp
, 0, udp_setup_server_tests
},
3800 {"udp_io", init_udp
, 0, upd_io_tests
},
3801 {"udp_binary_io", binary_init_udp
, 0, upd_io_tests
},
3802 {"block", 0, 0, tests
},
3803 {"binary", pre_binary
, 0, tests
},
3804 {"nonblock", pre_nonblock
, 0, tests
},
3805 {"nodelay", pre_nodelay
, 0, tests
},
3806 {"settimer", pre_settimer
, 0, tests
},
3807 {"md5", pre_md5
, 0, tests
},
3808 {"crc", pre_crc
, 0, tests
},
3809 {"hsieh", pre_hsieh
, 0, tests
},
3810 {"jenkins", pre_jenkins
, 0, tests
},
3811 {"fnv1_64", pre_hash_fnv1_64
, 0, tests
},
3812 {"fnv1a_64", pre_hash_fnv1a_64
, 0, tests
},
3813 {"fnv1_32", pre_hash_fnv1_32
, 0, tests
},
3814 {"fnv1a_32", pre_hash_fnv1a_32
, 0, tests
},
3815 {"ketama", pre_behavior_ketama
, 0, tests
},
3816 {"unix_socket", pre_unix_socket
, 0, tests
},
3817 {"unix_socket_nodelay", pre_nodelay
, 0, tests
},
3818 {"poll_timeout", poll_timeout
, 0, tests
},
3819 {"gets", enable_cas
, 0, tests
},
3820 {"consistent", enable_consistent
, 0, tests
},
3821 {"memory_allocators", set_memory_alloc
, 0, tests
},
3822 {"prefix", set_prefix
, 0, tests
},
3823 {"version_1_2_3", check_for_1_2_3
, 0, version_1_2_3
},
3824 {"string", 0, 0, string_tests
},
3825 {"result", 0, 0, result_tests
},
3826 {"async", pre_nonblock
, 0, async_tests
},
3827 {"async_binary", pre_nonblock_binary
, 0, async_tests
},
3828 {"user", 0, 0, user_tests
},
3829 {"generate", 0, 0, generate_tests
},
3830 {"generate_hsieh", pre_hsieh
, 0, generate_tests
},
3831 {"generate_ketama", pre_behavior_ketama
, 0, generate_tests
},
3832 {"generate_hsieh_consistent", enable_consistent
, 0, generate_tests
},
3833 {"generate_md5", pre_md5
, 0, generate_tests
},
3834 {"generate_murmur", pre_murmur
, 0, generate_tests
},
3835 {"generate_jenkins", pre_jenkins
, 0, generate_tests
},
3836 {"generate_nonblock", pre_nonblock
, 0, generate_tests
},
3837 {"consistent_not", 0, 0, consistent_tests
},
3838 {"consistent_ketama", pre_behavior_ketama
, 0, consistent_tests
},
3839 {"consistent_ketama_weighted", pre_behavior_ketama_weighted
, 0, consistent_weighted_tests
},
3843 #define SERVERS_TO_CREATE 5
3845 /* Prototypes for functions we will pass to test framework */
3846 void *world_create(void);
3847 void world_destroy(void *p
);
3849 void *world_create(void)
3851 server_startup_st
*construct
;
3853 construct
= (server_startup_st
*)malloc(sizeof(server_startup_st
));
3854 memset(construct
, 0, sizeof(server_startup_st
));
3855 construct
->count
= SERVERS_TO_CREATE
;
3857 server_startup(construct
);
3863 void world_destroy(void *p
)
3865 server_startup_st
*construct
= (server_startup_st
*)p
;
3866 memcached_server_st
*servers
= (memcached_server_st
*)construct
->servers
;
3867 memcached_server_list_free(servers
);
3869 server_shutdown(construct
);
3873 void get_world(world_st
*world
)
3875 world
->collections
= collection
;
3876 world
->create
= world_create
;
3877 world
->destroy
= world_destroy
;