1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
6 * Copyright (C) 2006-2009 Brian Aker All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following disclaimer
17 * in the documentation and/or other materials provided with the
20 * * The names of its contributors may not be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 #define BUILDING_LIBMEMCACHED
44 // !NEVER use common.h, always use memcached.h in your own apps
45 #include <libmemcached/common.h>
54 #include <sys/types.h>
59 #include <libtest/server.h>
61 #include "clients/generator.h"
62 #include "clients/execute.h"
64 #define SMALL_STRING_LEN 1024
66 #include <libtest/test.h>
67 #include "tests/deprecated.h"
68 #include "tests/parser.h"
69 #include "tests/pool.h"
70 #include "tests/string.h"
71 #include "tests/replication.h"
72 #include "tests/basic.h"
73 #include "tests/error_conditions.h"
74 #include "tests/print.h"
75 #include "tests/virtual_buckets.h"
78 #ifdef HAVE_LIBMEMCACHEDUTIL
80 #include "libmemcached/memcached_util.h"
83 #include "hash_results.h"
85 #define GLOBAL_COUNT 10000
86 #define GLOBAL2_COUNT 100
87 #define SERVERS_TO_CREATE 5
88 static uint32_t global_count
;
90 static pairs_st
*global_pairs
;
91 static const char *global_keys
[GLOBAL_COUNT
];
92 static size_t global_keys_length
[GLOBAL_COUNT
];
95 static test_return_t
pre_binary(memcached_st
*memc
);
98 static test_return_t
init_test(memcached_st
*not_used
)
103 (void)memcached_create(&memc
);
104 memcached_free(&memc
);
109 #define TEST_PORT_COUNT 7
110 in_port_t test_ports
[TEST_PORT_COUNT
];
112 static memcached_return_t
server_display_function(const memcached_st
*ptr
,
113 const memcached_server_st
*server
,
117 size_t bigger
= *((size_t *)(context
));
119 assert(bigger
<= memcached_server_port(server
));
120 *((size_t *)(context
))= memcached_server_port(server
);
122 return MEMCACHED_SUCCESS
;
125 static memcached_return_t
dump_server_information(const memcached_st
*ptr
,
126 const memcached_server_st
*instance
,
130 FILE *stream
= (FILE *)context
;
133 fprintf(stream
, "Memcached Server: %s %u Version %u.%u.%u\n",
134 memcached_server_name(instance
),
135 memcached_server_port(instance
),
136 instance
->major_version
,
137 instance
->minor_version
,
138 instance
->micro_version
);
140 return MEMCACHED_SUCCESS
;
143 static test_return_t
server_sort_test(memcached_st
*ptr
)
145 size_t bigger
= 0; /* Prime the value for the test_true in server_display_function */
147 memcached_return_t rc
;
148 memcached_server_fn callbacks
[1];
149 memcached_st
*local_memc
;
152 local_memc
= memcached_create(NULL
);
153 test_true(local_memc
);
154 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
156 for (size_t x
= 0; x
< TEST_PORT_COUNT
; x
++)
158 test_ports
[x
]= (in_port_t
)random() % 64000;
159 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
160 test_compare(memcached_server_count(local_memc
), x
+1);
162 test_true(memcached_server_list_count(memcached_server_list(local_memc
)) == x
+1);
164 test_compare(MEMCACHED_SUCCESS
, rc
);
167 callbacks
[0]= server_display_function
;
168 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
171 memcached_free(local_memc
);
176 static test_return_t
server_sort2_test(memcached_st
*ptr
)
178 size_t bigger
= 0; /* Prime the value for the test_true in server_display_function */
179 memcached_server_fn callbacks
[1];
180 memcached_st
*local_memc
;
181 memcached_server_instance_st instance
;
184 local_memc
= memcached_create(NULL
);
185 test_true(local_memc
);
186 test_compare(MEMCACHED_SUCCESS
,
187 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1));
189 test_compare(MEMCACHED_SUCCESS
,
190 memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43043, 0));
191 instance
= memcached_server_instance_by_position(local_memc
, 0);
192 test_compare(43043, memcached_server_port(instance
));
194 test_compare(MEMCACHED_SUCCESS
,
195 memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43042, 0));
197 instance
= memcached_server_instance_by_position(local_memc
, 0);
198 test_compare(43042, memcached_server_port(instance
));
200 instance
= memcached_server_instance_by_position(local_memc
, 1);
201 test_compare(43043, memcached_server_port(instance
));
203 callbacks
[0]= server_display_function
;
204 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
207 memcached_free(local_memc
);
212 static test_return_t
memcached_server_remove_test(memcached_st
*)
214 const char *server_string
= "--server=localhost:4444 --server=localhost:4445 --server=localhost:4446 --server=localhost:4447 --server=localhost --server=memcache1.memcache.bk.sapo.pt:11211 --server=memcache1.memcache.bk.sapo.pt:11212 --server=memcache1.memcache.bk.sapo.pt:11213 --server=memcache1.memcache.bk.sapo.pt:11214 --server=memcache2.memcache.bk.sapo.pt:11211 --server=memcache2.memcache.bk.sapo.pt:11212 --server=memcache2.memcache.bk.sapo.pt:11213 --server=memcache2.memcache.bk.sapo.pt:11214";
217 memcached_return_t rc
;
218 test_compare_got(MEMCACHED_SUCCESS
,
219 rc
= libmemcached_check_configuration(server_string
, strlen(server_string
), buffer
, sizeof(buffer
)),
220 memcached_strerror(NULL
, rc
));
221 memcached_st
*memc
= memcached(server_string
, strlen(server_string
));
224 memcached_server_fn callbacks
[1];
225 callbacks
[0]= server_print_callback
;
226 memcached_server_cursor(memc
, callbacks
, NULL
, 1);
228 memcached_free(memc
);
233 static memcached_return_t
server_display_unsort_function(const memcached_st
*,
234 const memcached_server_st
*server
,
238 uint32_t x
= *((uint32_t *)(context
));
240 if (! (test_ports
[x
] == server
->port
))
242 fprintf(stderr
, "%lu -> %lu\n", (unsigned long)test_ports
[x
], (unsigned long)server
->port
);
243 return MEMCACHED_FAILURE
;
246 *((uint32_t *)(context
))= ++x
;
248 return MEMCACHED_SUCCESS
;
251 static test_return_t
server_unsort_test(memcached_st
*ptr
)
253 size_t counter
= 0; /* Prime the value for the test_true in server_display_function */
254 size_t bigger
= 0; /* Prime the value for the test_true in server_display_function */
255 memcached_server_fn callbacks
[1];
256 memcached_st
*local_memc
;
259 local_memc
= memcached_create(NULL
);
260 test_true(local_memc
);
262 for (size_t x
= 0; x
< TEST_PORT_COUNT
; x
++)
264 test_ports
[x
]= (in_port_t
)(random() % 64000);
265 test_compare(MEMCACHED_SUCCESS
,
266 memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0));
267 test_compare(memcached_server_count(local_memc
), x
+1);
269 test_true(memcached_server_list_count(memcached_server_list(local_memc
)) == x
+1);
273 callbacks
[0]= server_display_unsort_function
;
274 memcached_server_cursor(local_memc
, callbacks
, (void *)&counter
, 1);
276 /* Now we sort old data! */
277 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
278 callbacks
[0]= server_display_function
;
279 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
282 memcached_free(local_memc
);
287 static test_return_t
allocation_test(memcached_st
*not_used
)
291 memc
= memcached_create(NULL
);
293 memcached_free(memc
);
298 static test_return_t
clone_test(memcached_st
*memc
)
302 memcached_st
*memc_clone
;
303 memc_clone
= memcached_clone(NULL
, NULL
);
304 test_true(memc_clone
);
305 memcached_free(memc_clone
);
308 /* Can we init from null? */
310 memcached_st
*memc_clone
;
311 memc_clone
= memcached_clone(NULL
, memc
);
312 test_true(memc_clone
);
315 test_true(memc_clone
->allocators
.free
== memc
->allocators
.free
);
316 test_true(memc_clone
->allocators
.malloc
== memc
->allocators
.malloc
);
317 test_true(memc_clone
->allocators
.realloc
== memc
->allocators
.realloc
);
318 test_true(memc_clone
->allocators
.calloc
== memc
->allocators
.calloc
);
321 test_true(memc_clone
->connect_timeout
== memc
->connect_timeout
);
322 test_true(memc_clone
->delete_trigger
== memc
->delete_trigger
);
323 test_true(memc_clone
->distribution
== memc
->distribution
);
324 { // Test all of the flags
325 test_true(memc_clone
->flags
.no_block
== memc
->flags
.no_block
);
326 test_true(memc_clone
->flags
.tcp_nodelay
== memc
->flags
.tcp_nodelay
);
327 test_true(memc_clone
->flags
.support_cas
== memc
->flags
.support_cas
);
328 test_true(memc_clone
->flags
.buffer_requests
== memc
->flags
.buffer_requests
);
329 test_true(memc_clone
->flags
.use_sort_hosts
== memc
->flags
.use_sort_hosts
);
330 test_true(memc_clone
->flags
.verify_key
== memc
->flags
.verify_key
);
331 test_true(memc_clone
->ketama
.weighted
== memc
->ketama
.weighted
);
332 test_true(memc_clone
->flags
.binary_protocol
== memc
->flags
.binary_protocol
);
333 test_true(memc_clone
->flags
.hash_with_prefix_key
== memc
->flags
.hash_with_prefix_key
);
334 test_true(memc_clone
->flags
.no_reply
== memc
->flags
.no_reply
);
335 test_true(memc_clone
->flags
.use_udp
== memc
->flags
.use_udp
);
336 test_true(memc_clone
->flags
.auto_eject_hosts
== memc
->flags
.auto_eject_hosts
);
337 test_true(memc_clone
->flags
.randomize_replica_read
== memc
->flags
.randomize_replica_read
);
339 test_true(memc_clone
->get_key_failure
== memc
->get_key_failure
);
340 test_true(hashkit_compare(&memc_clone
->hashkit
, &memc
->hashkit
));
341 test_true(memc_clone
->io_bytes_watermark
== memc
->io_bytes_watermark
);
342 test_true(memc_clone
->io_msg_watermark
== memc
->io_msg_watermark
);
343 test_true(memc_clone
->io_key_prefetch
== memc
->io_key_prefetch
);
344 test_true(memc_clone
->on_cleanup
== memc
->on_cleanup
);
345 test_true(memc_clone
->on_clone
== memc
->on_clone
);
346 test_true(memc_clone
->poll_timeout
== memc
->poll_timeout
);
347 test_true(memc_clone
->rcv_timeout
== memc
->rcv_timeout
);
348 test_true(memc_clone
->recv_size
== memc
->recv_size
);
349 test_true(memc_clone
->retry_timeout
== memc
->retry_timeout
);
350 test_true(memc_clone
->send_size
== memc
->send_size
);
351 test_true(memc_clone
->server_failure_limit
== memc
->server_failure_limit
);
352 test_true(memc_clone
->snd_timeout
== memc
->snd_timeout
);
353 test_true(memc_clone
->user_data
== memc
->user_data
);
355 memcached_free(memc_clone
);
358 /* Can we init from struct? */
360 memcached_st declared_clone
;
361 memcached_st
*memc_clone
;
362 memset(&declared_clone
, 0 , sizeof(memcached_st
));
363 memc_clone
= memcached_clone(&declared_clone
, NULL
);
364 test_true(memc_clone
);
365 memcached_free(memc_clone
);
368 /* Can we init from struct? */
370 memcached_st declared_clone
;
371 memcached_st
*memc_clone
;
372 memset(&declared_clone
, 0 , sizeof(memcached_st
));
373 memc_clone
= memcached_clone(&declared_clone
, memc
);
374 test_true(memc_clone
);
375 memcached_free(memc_clone
);
381 static test_return_t
userdata_test(memcached_st
*memc
)
384 test_false(memcached_set_user_data(memc
, foo
));
385 test_true(memcached_get_user_data(memc
) == foo
);
386 test_true(memcached_set_user_data(memc
, NULL
) == foo
);
391 static test_return_t
connection_test(memcached_st
*memc
)
393 test_compare(MEMCACHED_SUCCESS
,
394 memcached_server_add_with_weight(memc
, "localhost", 0, 0));
399 static test_return_t
libmemcached_string_behavior_test(memcached_st
*)
401 for (int x
= MEMCACHED_BEHAVIOR_NO_BLOCK
; x
< int(MEMCACHED_BEHAVIOR_MAX
); ++x
)
403 test_true(libmemcached_string_behavior(memcached_behavior_t(x
)));
405 test_compare(36, MEMCACHED_BEHAVIOR_MAX
);
410 static test_return_t
libmemcached_string_distribution_test(memcached_st
*)
412 for (int x
= MEMCACHED_DISTRIBUTION_MODULA
; x
< int(MEMCACHED_DISTRIBUTION_CONSISTENT_MAX
); ++x
)
414 test_true(libmemcached_string_distribution(memcached_server_distribution_t(x
)));
416 test_compare(7, MEMCACHED_DISTRIBUTION_CONSISTENT_MAX
);
421 static test_return_t
error_test(memcached_st
*memc
)
423 uint32_t values
[] = { 851992627U, 2337886783U, 4109241422U, 4001849190U,
424 982370485U, 1263635348U, 4242906218U, 3829656100U,
425 1891735253U, 334139633U, 2257084983U, 3088286104U,
426 13199785U, 2542027183U, 1097051614U, 199566778U,
427 2748246961U, 2465192557U, 1664094137U, 2405439045U,
428 1842224848U, 692413798U, 3479807801U, 919913813U,
429 4269430871U, 610793021U, 527273862U, 1437122909U,
430 2300930706U, 2943759320U, 674306647U, 2400528935U,
431 54481931U, 4186304426U, 1741088401U, 2979625118U,
432 4159057246U, 3425930182U, 2593724503U, 1868899624U,
433 1769812374U, 2302537950U, 1110330676U, 3365377466U,
434 1336171666U, 3021258493U, 2334992265U, 3365377466U };
436 // You have updated the memcache_error messages but not updated docs/tests.
437 for (int rc
= int(MEMCACHED_SUCCESS
); rc
< int(MEMCACHED_MAXIMUM_RETURN
); ++rc
)
440 const char *msg
= memcached_strerror(memc
, memcached_return_t(rc
));
441 hash_val
= memcached_generate_hash_value(msg
, strlen(msg
),
442 MEMCACHED_HASH_JENKINS
);
443 if (values
[rc
] != hash_val
)
445 fprintf(stderr
, "\n\nYou have updated memcached_return_t without updating the error_test\n");
446 fprintf(stderr
, "%u, %s, (%u)\n\n", (uint32_t)rc
, memcached_strerror(memc
, memcached_return_t(rc
)), hash_val
);
448 test_compare(values
[rc
], hash_val
);
450 test_compare(MEMCACHED_MAXIMUM_RETURN
, 47);
455 static test_return_t
set_test(memcached_st
*memc
)
457 memcached_return_t rc
= memcached_set(memc
,
458 memcached_literal_param("foo"),
459 memcached_literal_param("when we sanitize"),
460 time_t(0), (uint32_t)0);
461 test_true_got(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
, memcached_strerror(NULL
, rc
));
466 static test_return_t
append_test(memcached_st
*memc
)
468 memcached_return_t rc
;
469 const char *key
= "fig";
470 const char *in_value
= "we";
471 char *out_value
= NULL
;
475 rc
= memcached_flush(memc
, 0);
476 test_compare(MEMCACHED_SUCCESS
, rc
);
478 rc
= memcached_set(memc
, key
, strlen(key
),
479 in_value
, strlen(in_value
),
480 (time_t)0, (uint32_t)0);
481 test_compare(MEMCACHED_SUCCESS
, rc
);
483 rc
= memcached_append(memc
, key
, strlen(key
),
484 " the", strlen(" the"),
485 (time_t)0, (uint32_t)0);
486 test_compare(MEMCACHED_SUCCESS
, rc
);
488 rc
= memcached_append(memc
, key
, strlen(key
),
489 " people", strlen(" people"),
490 (time_t)0, (uint32_t)0);
491 test_compare(MEMCACHED_SUCCESS
, rc
);
493 out_value
= memcached_get(memc
, key
, strlen(key
),
494 &value_length
, &flags
, &rc
);
495 test_memcmp(out_value
, "we the people", strlen("we the people"));
496 test_compare(strlen("we the people"), value_length
);
497 test_compare(MEMCACHED_SUCCESS
, rc
);
503 static test_return_t
append_binary_test(memcached_st
*memc
)
505 memcached_return_t rc
;
506 const char *key
= "numbers";
507 uint32_t store_list
[] = { 23, 56, 499, 98, 32847, 0 };
513 rc
= memcached_flush(memc
, 0);
514 test_compare(MEMCACHED_SUCCESS
, rc
);
516 rc
= memcached_set(memc
,
519 (time_t)0, (uint32_t)0);
520 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
522 for (x
= 0; store_list
[x
] ; x
++)
524 rc
= memcached_append(memc
,
526 (char *)&store_list
[x
], sizeof(uint32_t),
527 (time_t)0, (uint32_t)0);
528 test_compare(MEMCACHED_SUCCESS
, rc
);
531 value
= (uint32_t *)memcached_get(memc
, key
, strlen(key
),
532 &value_length
, &flags
, &rc
);
533 test_compare(value_length
, sizeof(uint32_t) * x
);
534 test_compare(MEMCACHED_SUCCESS
, rc
);
536 for (uint32_t counter
= x
, *ptr
= value
; counter
; counter
--)
538 test_compare(*ptr
, store_list
[x
- counter
]);
546 static test_return_t
cas2_test(memcached_st
*memc
)
548 memcached_return_t rc
;
549 const char *keys
[]= {"fudge", "son", "food"};
550 size_t key_length
[]= {5, 3, 4};
551 const char *value
= "we the people";
552 size_t value_length
= strlen("we the people");
553 memcached_result_st results_obj
;
554 memcached_result_st
*results
;
557 test_compare(MEMCACHED_SUCCESS
, memcached_flush(memc
, 0));
559 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
561 for (uint32_t x
= 0; x
< 3; x
++)
563 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
564 keys
[x
], key_length
[x
],
565 (time_t)50, (uint32_t)9);
566 test_compare(MEMCACHED_SUCCESS
, rc
);
569 rc
= memcached_mget(memc
, keys
, key_length
, 3);
571 results
= memcached_result_create(memc
, &results_obj
);
573 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
575 test_true(results
->item_cas
);
576 test_compare(MEMCACHED_SUCCESS
, rc
);
577 test_true(memcached_result_cas(results
));
579 test_memcmp(value
, "we the people", strlen("we the people"));
580 test_compare(strlen("we the people"), value_length
);
581 test_compare(MEMCACHED_SUCCESS
, rc
);
583 memcached_result_free(&results_obj
);
588 static test_return_t
cas_test(memcached_st
*memc
)
590 memcached_return_t rc
;
591 const char *key
= "fun";
592 size_t key_length
= strlen(key
);
593 const char *value
= "we the people";
594 const char* keys
[2] = { key
, NULL
};
595 size_t keylengths
[2] = { strlen(key
), 0 };
596 size_t value_length
= strlen(value
);
597 const char *value2
= "change the value";
598 size_t value2_length
= strlen(value2
);
600 memcached_result_st results_obj
;
601 memcached_result_st
*results
;
604 rc
= memcached_flush(memc
, 0);
605 test_compare(MEMCACHED_SUCCESS
, rc
);
607 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
609 rc
= memcached_set(memc
, key
, strlen(key
),
610 value
, strlen(value
),
611 (time_t)0, (uint32_t)0);
612 test_compare(MEMCACHED_SUCCESS
, rc
);
614 rc
= memcached_mget(memc
, keys
, keylengths
, 1);
616 results
= memcached_result_create(memc
, &results_obj
);
618 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
620 test_compare(MEMCACHED_SUCCESS
, rc
);
621 test_true(memcached_result_cas(results
));
622 test_memcmp(value
, memcached_result_value(results
), value_length
);
623 test_compare(strlen(memcached_result_value(results
)), value_length
);
624 test_compare(MEMCACHED_SUCCESS
, rc
);
625 uint64_t cas
= memcached_result_cas(results
);
628 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
629 test_true(rc
== MEMCACHED_END
);
630 test_true(results
== NULL
);
633 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
634 test_compare(MEMCACHED_SUCCESS
, rc
);
637 * The item will have a new cas value, so try to set it again with the old
638 * value. This should fail!
640 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
641 test_compare(MEMCACHED_DATA_EXISTS
, rc
);
643 memcached_result_free(&results_obj
);
648 static test_return_t
prepend_test(memcached_st
*memc
)
650 memcached_return_t rc
;
651 const char *key
= "fig";
652 const char *value
= "people";
653 char *out_value
= NULL
;
657 rc
= memcached_flush(memc
, 0);
658 test_compare(MEMCACHED_SUCCESS
, rc
);
660 rc
= memcached_set(memc
, key
, strlen(key
),
661 value
, strlen(value
),
662 (time_t)0, (uint32_t)0);
663 test_compare(MEMCACHED_SUCCESS
, rc
);
665 rc
= memcached_prepend(memc
, key
, strlen(key
),
666 "the ", strlen("the "),
667 (time_t)0, (uint32_t)0);
668 test_compare(MEMCACHED_SUCCESS
, rc
);
670 rc
= memcached_prepend(memc
, key
, strlen(key
),
671 "we ", strlen("we "),
672 (time_t)0, (uint32_t)0);
673 test_compare(MEMCACHED_SUCCESS
, rc
);
675 out_value
= memcached_get(memc
, key
, strlen(key
),
676 &value_length
, &flags
, &rc
);
677 test_memcmp(out_value
, "we the people", strlen("we the people"));
678 test_compare(strlen("we the people"), value_length
);
679 test_compare(MEMCACHED_SUCCESS
, rc
);
686 Set the value, then quit to make sure it is flushed.
687 Come back in and test that add fails.
689 static test_return_t
add_test(memcached_st
*memc
)
691 memcached_return_t rc
;
692 const char *key
= "foo";
693 const char *value
= "when we sanitize";
694 unsigned long long setting_value
;
696 setting_value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
698 rc
= memcached_set(memc
, key
, strlen(key
),
699 value
, strlen(value
),
700 (time_t)0, (uint32_t)0);
701 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
702 memcached_quit(memc
);
703 rc
= memcached_add(memc
, key
, strlen(key
),
704 value
, strlen(value
),
705 (time_t)0, (uint32_t)0);
707 /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */
710 test_true(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_STORED
);
714 test_true(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_DATA_EXISTS
);
721 ** There was a problem of leaking filedescriptors in the initial release
722 ** of MacOSX 10.5. This test case triggers the problem. On some Solaris
723 ** systems it seems that the kernel is slow on reclaiming the resources
724 ** because the connects starts to time out (the test doesn't do much
725 ** anyway, so just loop 10 iterations)
727 static test_return_t
add_wrapper(memcached_st
*memc
)
729 unsigned int max
= 10000;
737 for (uint32_t x
= 0; x
< max
; x
++)
743 static test_return_t
replace_test(memcached_st
*memc
)
745 memcached_return_t rc
;
746 const char *key
= "foo";
747 const char *value
= "when we sanitize";
748 const char *original
= "first we insert some data";
750 rc
= memcached_set(memc
, key
, strlen(key
),
751 original
, strlen(original
),
752 (time_t)0, (uint32_t)0);
753 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
755 test_compare(MEMCACHED_SUCCESS
,
756 memcached_replace(memc
, key
, strlen(key
),
757 value
, strlen(value
),
758 (time_t)0, (uint32_t)0));
763 static test_return_t
delete_test(memcached_st
*memc
)
765 memcached_return_t rc
;
766 const char *key
= "foo";
767 const char *value
= "when we sanitize";
769 rc
= memcached_set(memc
, key
, strlen(key
),
770 value
, strlen(value
),
771 (time_t)0, (uint32_t)0);
772 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
774 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
775 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
780 static test_return_t
flush_test(memcached_st
*memc
)
782 uint64_t query_id
= memcached_query_id(memc
);
783 test_compare(MEMCACHED_SUCCESS
,
784 memcached_flush(memc
, 0));
785 test_compare(query_id
+1, memcached_query_id(memc
));
790 static memcached_return_t
server_function(const memcached_st
*ptr
,
791 const memcached_server_st
*server
,
794 (void)ptr
; (void)server
; (void)context
;
797 return MEMCACHED_SUCCESS
;
800 static test_return_t
memcached_server_cursor_test(memcached_st
*memc
)
803 strncpy(context
, "foo bad", sizeof(context
));
804 memcached_server_fn callbacks
[1];
806 callbacks
[0]= server_function
;
807 memcached_server_cursor(memc
, callbacks
, context
, 1);
811 static test_return_t
bad_key_test(memcached_st
*memc
)
813 memcached_return_t rc
;
814 const char *key
= "foo bad";
816 size_t string_length
;
818 memcached_st
*memc_clone
;
820 size_t max_keylen
= 0xffff;
822 // Just skip if we are in binary mode.
823 uint64_t query_id
= memcached_query_id(memc
);
824 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
))
826 test_compare(query_id
, memcached_query_id(memc
)); // We should not increase the query_id for memcached_behavior_get()
828 memc_clone
= memcached_clone(NULL
, memc
);
829 test_true(memc_clone
);
831 query_id
= memcached_query_id(memc_clone
);
832 test_compare(MEMCACHED_SUCCESS
,
833 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
));
834 test_compare(query_id
, memcached_query_id(memc_clone
)); // We should not increase the query_id for memcached_behavior_set()
836 /* All keys are valid in the binary protocol (except for length) */
837 if (not memcached_behavior_get(memc_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
))
839 query_id
= memcached_query_id(memc_clone
);
840 string
= memcached_get(memc_clone
, key
, strlen(key
),
841 &string_length
, &flags
, &rc
);
842 test_compare(MEMCACHED_BAD_KEY_PROVIDED
, rc
);
843 test_compare(0, string_length
);
847 query_id
= memcached_query_id(memc_clone
);
848 test_compare(MEMCACHED_SUCCESS
,
849 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
));
850 test_compare(query_id
, memcached_query_id(memc_clone
)); // We should not increase the query_id for memcached_behavior_set()
851 string
= memcached_get(memc_clone
, key
, strlen(key
),
852 &string_length
, &flags
, &rc
);
853 test_compare_got(MEMCACHED_NOTFOUND
, rc
, memcached_strerror(NULL
, rc
));
854 test_compare(0, string_length
);
857 /* Test multi key for bad keys */
858 const char *keys
[] = { "GoodKey", "Bad Key", "NotMine" };
859 size_t key_lengths
[] = { 7, 7, 7 };
861 query_id
= memcached_query_id(memc_clone
);
862 test_compare(MEMCACHED_SUCCESS
,
863 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
));
864 test_compare(query_id
, memcached_query_id(memc_clone
));
866 query_id
= memcached_query_id(memc_clone
);
867 test_compare(MEMCACHED_BAD_KEY_PROVIDED
,
868 memcached_mget(memc_clone
, keys
, key_lengths
, 3));
869 test_compare(query_id
+1, memcached_query_id(memc_clone
));
871 query_id
= memcached_query_id(memc_clone
);
872 test_compare(MEMCACHED_BAD_KEY_PROVIDED
,
873 memcached_mget_by_key(memc_clone
, "foo daddy", 9, keys
, key_lengths
, 1));
874 test_compare(query_id
+1, memcached_query_id(memc_clone
));
878 /* The following test should be moved to the end of this function when the
879 memcached server is updated to allow max size length of the keys in the
882 test_compare(MEMCACHED_SUCCESS
,
883 memcached_callback_set(memc_clone
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
));
885 char *longkey
= (char *)malloc(max_keylen
+ 1);
888 memset(longkey
, 'a', max_keylen
+ 1);
889 string
= memcached_get(memc_clone
, longkey
, max_keylen
,
890 &string_length
, &flags
, &rc
);
891 test_compare(MEMCACHED_NOTFOUND
, rc
);
892 test_compare(0, string_length
);
895 string
= memcached_get(memc_clone
, longkey
, max_keylen
+ 1,
896 &string_length
, &flags
, &rc
);
897 test_compare(MEMCACHED_BAD_KEY_PROVIDED
, rc
);
898 test_compare(0, string_length
);
905 /* Make sure zero length keys are marked as bad */
907 test_compare(MEMCACHED_SUCCESS
,
908 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, set
));
909 string
= memcached_get(memc_clone
, key
, 0,
910 &string_length
, &flags
, &rc
);
911 test_compare(MEMCACHED_BAD_KEY_PROVIDED
, rc
);
912 test_compare(0, string_length
);
915 memcached_free(memc_clone
);
920 #define READ_THROUGH_VALUE "set for me"
921 static memcached_return_t
read_through_trigger(memcached_st
*memc
,
924 memcached_result_st
*result
)
926 (void)memc
;(void)key
;(void)key_length
;
927 return memcached_result_set_value(result
, READ_THROUGH_VALUE
, strlen(READ_THROUGH_VALUE
));
930 #ifndef __INTEL_COMPILER
931 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
934 static test_return_t
read_through(memcached_st
*memc
)
936 memcached_return_t rc
;
937 const char *key
= "foo";
939 size_t string_length
;
941 memcached_trigger_key_fn cb
= (memcached_trigger_key_fn
)read_through_trigger
;
943 string
= memcached_get(memc
, key
, strlen(key
),
944 &string_length
, &flags
, &rc
);
946 test_compare(MEMCACHED_NOTFOUND
, rc
);
947 test_false(string_length
);
950 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_GET_FAILURE
, *(void **)&cb
);
951 test_compare(MEMCACHED_SUCCESS
, rc
);
953 string
= memcached_get(memc
, key
, strlen(key
),
954 &string_length
, &flags
, &rc
);
956 test_compare(MEMCACHED_SUCCESS
, rc
);
957 test_compare(string_length
, sizeof(READ_THROUGH_VALUE
) -1);
958 test_true(string
[sizeof(READ_THROUGH_VALUE
) -1] == 0);
959 test_strcmp(READ_THROUGH_VALUE
, string
);
962 string
= memcached_get(memc
, key
, strlen(key
),
963 &string_length
, &flags
, &rc
);
965 test_compare(MEMCACHED_SUCCESS
, rc
);
967 test_compare(string_length
, sizeof(READ_THROUGH_VALUE
) -1);
968 test_true(string
[sizeof(READ_THROUGH_VALUE
) -1] == 0);
969 test_strcmp(READ_THROUGH_VALUE
, string
);
975 static memcached_return_t
delete_trigger(memcached_st
*,
982 return MEMCACHED_SUCCESS
;
985 static test_return_t
delete_through(memcached_st
*memc
)
987 memcached_trigger_delete_key_fn callback
;
988 memcached_return_t rc
;
990 callback
= (memcached_trigger_delete_key_fn
)delete_trigger
;
992 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_DELETE_TRIGGER
, *(void**)&callback
);
993 test_compare(MEMCACHED_SUCCESS
, rc
);
998 static test_return_t
get_test(memcached_st
*memc
)
1000 memcached_return_t rc
;
1001 const char *key
= "foo";
1003 size_t string_length
;
1006 uint64_t query_id
= memcached_query_id(memc
);
1007 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
1008 test_true(rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_NOTFOUND
);
1009 test_compare(query_id
+1, memcached_query_id(memc
));
1011 string
= memcached_get(memc
, key
, strlen(key
),
1012 &string_length
, &flags
, &rc
);
1014 test_compare_got(MEMCACHED_NOTFOUND
, rc
, memcached_strerror(NULL
, rc
));
1015 test_false(string_length
);
1018 return TEST_SUCCESS
;
1021 static test_return_t
get_test2(memcached_st
*memc
)
1023 const char *key
= "foo";
1024 const char *value
= "when we sanitize";
1026 uint64_t query_id
= memcached_query_id(memc
);
1027 memcached_return_t rc
= memcached_set(memc
, key
, strlen(key
),
1028 value
, strlen(value
),
1029 (time_t)0, (uint32_t)0);
1030 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
1031 test_compare(query_id
+1, memcached_query_id(memc
));
1033 query_id
= memcached_query_id(memc
);
1034 test_true(query_id
);
1037 size_t string_length
;
1038 char *string
= memcached_get(memc
, key
, strlen(key
),
1039 &string_length
, &flags
, &rc
);
1040 test_compare(query_id
+1, memcached_query_id(memc
));
1042 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
1043 test_compare_got(MEMCACHED_SUCCESS
, memcached_last_error(memc
), memcached_last_error_message(memc
));
1045 test_compare(strlen(value
), string_length
);
1046 test_memcmp(string
, value
, string_length
);
1050 return TEST_SUCCESS
;
1053 static test_return_t
set_test2(memcached_st
*memc
)
1055 const char *key
= "foo";
1056 const char *value
= "train in the brain";
1057 size_t value_length
= strlen(value
);
1059 for (uint32_t x
= 0; x
< 10; x
++)
1061 memcached_return_t rc
= memcached_set(memc
, key
, strlen(key
),
1062 value
, value_length
,
1063 (time_t)0, (uint32_t)0);
1064 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
1067 return TEST_SUCCESS
;
1070 static test_return_t
set_test3(memcached_st
*memc
)
1072 size_t value_length
= 8191;
1074 char *value
= (char*)malloc(value_length
);
1077 for (uint32_t x
= 0; x
< value_length
; x
++)
1079 value
[x
] = (char) (x
% 127);
1082 /* The dump test relies on there being at least 32 items in memcached */
1083 for (uint32_t x
= 0; x
< 32; x
++)
1087 snprintf(key
, sizeof(key
), "foo%u", x
);
1089 uint64_t query_id
= memcached_query_id(memc
);
1090 memcached_return_t rc
= memcached_set(memc
, key
, strlen(key
),
1091 value
, value_length
,
1092 (time_t)0, (uint32_t)0);
1093 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1094 test_compare(query_id
+1, memcached_query_id(memc
));
1099 return TEST_SUCCESS
;
1102 static test_return_t
get_test3(memcached_st
*memc
)
1104 const char *key
= "foo";
1105 size_t value_length
= 8191;
1107 char *value
= (char*)malloc(value_length
);
1110 for (uint32_t x
= 0; x
< value_length
; x
++)
1112 value
[x
] = (char) (x
% 127);
1115 memcached_return_t rc
;
1116 rc
= memcached_set(memc
, key
, strlen(key
),
1117 value
, value_length
,
1118 (time_t)0, (uint32_t)0);
1119 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
1121 size_t string_length
;
1123 char *string
= memcached_get(memc
, key
, strlen(key
),
1124 &string_length
, &flags
, &rc
);
1126 test_compare(MEMCACHED_SUCCESS
, rc
);
1128 test_compare(string_length
, value_length
);
1129 test_memcmp(string
, value
, string_length
);
1134 return TEST_SUCCESS
;
1137 static test_return_t
get_test4(memcached_st
*memc
)
1139 memcached_return_t rc
;
1140 const char *key
= "foo";
1142 size_t value_length
= 8191;
1144 size_t string_length
;
1148 value
= (char*)malloc(value_length
);
1151 for (x
= 0; x
< value_length
; x
++)
1152 value
[x
] = (char) (x
% 127);
1154 rc
= memcached_set(memc
, key
, strlen(key
),
1155 value
, value_length
,
1156 (time_t)0, (uint32_t)0);
1157 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1159 for (x
= 0; x
< 10; x
++)
1161 string
= memcached_get(memc
, key
, strlen(key
),
1162 &string_length
, &flags
, &rc
);
1164 test_compare(MEMCACHED_SUCCESS
, rc
);
1166 test_compare(string_length
, value_length
);
1167 test_memcmp(string
, value
, string_length
);
1173 return TEST_SUCCESS
;
1177 * This test verifies that memcached_read_one_response doesn't try to
1178 * dereference a NIL-pointer if you issue a multi-get and don't read out all
1179 * responses before you execute a storage command.
1181 static test_return_t
get_test5(memcached_st
*memc
)
1184 ** Request the same key twice, to ensure that we hash to the same server
1185 ** (so that we have multiple response values queued up) ;-)
1187 const char *keys
[]= { "key", "key" };
1188 size_t lengths
[]= { 3, 3 };
1192 memcached_return_t rc
= memcached_set(memc
, keys
[0], lengths
[0],
1193 keys
[0], lengths
[0], 0, 0);
1194 test_compare(MEMCACHED_SUCCESS
, rc
);
1195 rc
= memcached_mget(memc
, keys
, lengths
, 2);
1197 memcached_result_st results_obj
;
1198 memcached_result_st
*results
;
1199 results
=memcached_result_create(memc
, &results_obj
);
1201 results
=memcached_fetch_result(memc
, &results_obj
, &rc
);
1203 memcached_result_free(&results_obj
);
1205 /* Don't read out the second result, but issue a set instead.. */
1206 rc
= memcached_set(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0);
1207 test_compare(MEMCACHED_SUCCESS
, rc
);
1209 char *val
= memcached_get_by_key(memc
, keys
[0], lengths
[0], "yek", 3,
1210 &rlen
, &flags
, &rc
);
1212 test_compare(MEMCACHED_NOTFOUND
, rc
);
1213 val
= memcached_get(memc
, keys
[0], lengths
[0], &rlen
, &flags
, &rc
);
1215 test_compare(MEMCACHED_SUCCESS
, rc
);
1218 return TEST_SUCCESS
;
1221 static test_return_t
mget_end(memcached_st
*memc
)
1223 const char *keys
[]= { "foo", "foo2" };
1224 size_t lengths
[]= { 3, 4 };
1225 const char *values
[]= { "fjord", "41" };
1227 memcached_return_t rc
;
1230 for (int i
= 0; i
< 2; i
++)
1232 rc
= memcached_set(memc
, keys
[i
], lengths
[i
], values
[i
], strlen(values
[i
]),
1233 (time_t)0, (uint32_t)0);
1234 test_compare(MEMCACHED_SUCCESS
, rc
);
1238 size_t string_length
;
1241 // retrieve both via mget
1242 rc
= memcached_mget(memc
, keys
, lengths
, 2);
1243 test_compare(MEMCACHED_SUCCESS
, rc
);
1245 char key
[MEMCACHED_MAX_KEY
];
1248 // this should get both
1249 for (int i
= 0; i
< 2; i
++)
1251 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
,
1253 test_compare(MEMCACHED_SUCCESS
, rc
);
1255 if (key_length
== 4)
1257 test_compare(string_length
, strlen(values
[val
]));
1258 test_true(strncmp(values
[val
], string
, string_length
) == 0);
1262 // this should indicate end
1263 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1264 test_compare(MEMCACHED_END
, rc
);
1267 rc
= memcached_mget(memc
, keys
, lengths
, 1);
1268 test_compare(MEMCACHED_SUCCESS
, rc
);
1270 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1271 test_compare(key_length
, lengths
[0]);
1272 test_true(strncmp(keys
[0], key
, key_length
) == 0);
1273 test_compare(string_length
, strlen(values
[0]));
1274 test_true(strncmp(values
[0], string
, string_length
) == 0);
1275 test_compare(MEMCACHED_SUCCESS
, rc
);
1278 // this should indicate end
1279 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1280 test_true(rc
== MEMCACHED_END
);
1282 return TEST_SUCCESS
;
1285 /* Do not copy the style of this code, I just access hosts to testthis function */
1286 static test_return_t
stats_servername_test(memcached_st
*memc
)
1288 memcached_return_t rc
;
1289 memcached_stat_st memc_stat
;
1290 memcached_server_instance_st instance
=
1291 memcached_server_instance_by_position(memc
, 0);
1293 #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
1294 if (memcached_get_sasl_callbacks(memc
) != NULL
)
1295 return TEST_SKIPPED
;
1297 rc
= memcached_stat_servername(&memc_stat
, NULL
,
1298 memcached_server_name(instance
),
1299 memcached_server_port(instance
));
1301 return TEST_SUCCESS
;
1304 static test_return_t
increment_test(memcached_st
*memc
)
1306 uint64_t new_number
;
1307 memcached_return_t rc
;
1308 const char *key
= "number";
1309 const char *value
= "0";
1311 rc
= memcached_set(memc
, key
, strlen(key
),
1312 value
, strlen(value
),
1313 (time_t)0, (uint32_t)0);
1314 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1316 rc
= memcached_increment(memc
, key
, strlen(key
),
1318 test_compare(MEMCACHED_SUCCESS
, rc
);
1319 test_true(new_number
== 1);
1321 rc
= memcached_increment(memc
, key
, strlen(key
),
1323 test_compare(MEMCACHED_SUCCESS
, rc
);
1324 test_true(new_number
== 2);
1326 return TEST_SUCCESS
;
1329 static test_return_t
increment_with_initial_test(memcached_st
*memc
)
1331 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1333 uint64_t new_number
;
1334 memcached_return_t rc
;
1335 const char *key
= "number";
1336 uint64_t initial
= 0;
1338 rc
= memcached_increment_with_initial(memc
, key
, strlen(key
),
1339 1, initial
, 0, &new_number
);
1340 test_compare(MEMCACHED_SUCCESS
, rc
);
1341 test_true(new_number
== initial
);
1343 rc
= memcached_increment_with_initial(memc
, key
, strlen(key
),
1344 1, initial
, 0, &new_number
);
1345 test_compare(MEMCACHED_SUCCESS
, rc
);
1346 test_true(new_number
== (initial
+ 1));
1348 return TEST_SUCCESS
;
1351 static test_return_t
decrement_test(memcached_st
*memc
)
1353 uint64_t new_number
;
1354 memcached_return_t rc
;
1355 const char *key
= "number";
1356 const char *value
= "3";
1358 rc
= memcached_set(memc
, key
, strlen(key
),
1359 value
, strlen(value
),
1360 (time_t)0, (uint32_t)0);
1361 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1363 rc
= memcached_decrement(memc
, key
, strlen(key
),
1365 test_compare(MEMCACHED_SUCCESS
, rc
);
1366 test_true(new_number
== 2);
1368 rc
= memcached_decrement(memc
, key
, strlen(key
),
1370 test_compare(MEMCACHED_SUCCESS
, rc
);
1371 test_true(new_number
== 1);
1373 return TEST_SUCCESS
;
1376 static test_return_t
decrement_with_initial_test(memcached_st
*memc
)
1378 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1380 uint64_t new_number
;
1381 memcached_return_t rc
;
1382 const char *key
= "number";
1383 uint64_t initial
= 3;
1385 rc
= memcached_decrement_with_initial(memc
, key
, strlen(key
),
1386 1, initial
, 0, &new_number
);
1387 test_compare(MEMCACHED_SUCCESS
, rc
);
1388 test_true(new_number
== initial
);
1390 rc
= memcached_decrement_with_initial(memc
, key
, strlen(key
),
1391 1, initial
, 0, &new_number
);
1392 test_compare(MEMCACHED_SUCCESS
, rc
);
1393 test_true(new_number
== (initial
- 1));
1395 return TEST_SUCCESS
;
1398 static test_return_t
increment_by_key_test(memcached_st
*memc
)
1400 uint64_t new_number
;
1401 memcached_return_t rc
;
1402 const char *master_key
= "foo";
1403 const char *key
= "number";
1404 const char *value
= "0";
1406 rc
= memcached_set_by_key(memc
, master_key
, strlen(master_key
),
1408 value
, strlen(value
),
1409 (time_t)0, (uint32_t)0);
1410 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1412 rc
= memcached_increment_by_key(memc
, master_key
, strlen(master_key
), key
, strlen(key
),
1414 test_compare(MEMCACHED_SUCCESS
, rc
);
1415 test_true(new_number
== 1);
1417 rc
= memcached_increment_by_key(memc
, master_key
, strlen(master_key
), key
, strlen(key
),
1419 test_compare(MEMCACHED_SUCCESS
, rc
);
1420 test_true(new_number
== 2);
1422 return TEST_SUCCESS
;
1425 static test_return_t
increment_with_initial_by_key_test(memcached_st
*memc
)
1427 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1429 uint64_t new_number
;
1430 memcached_return_t rc
;
1431 const char *master_key
= "foo";
1432 const char *key
= "number";
1433 uint64_t initial
= 0;
1435 rc
= memcached_increment_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1437 1, initial
, 0, &new_number
);
1438 test_compare(MEMCACHED_SUCCESS
, rc
);
1439 test_true(new_number
== initial
);
1441 rc
= memcached_increment_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1443 1, initial
, 0, &new_number
);
1444 test_compare(MEMCACHED_SUCCESS
, rc
);
1445 test_true(new_number
== (initial
+ 1));
1447 return TEST_SUCCESS
;
1450 static test_return_t
decrement_by_key_test(memcached_st
*memc
)
1452 uint64_t new_number
;
1453 memcached_return_t rc
;
1454 const char *master_key
= "foo";
1455 const char *key
= "number";
1456 const char *value
= "3";
1458 rc
= memcached_set_by_key(memc
, master_key
, strlen(master_key
),
1460 value
, strlen(value
),
1461 (time_t)0, (uint32_t)0);
1462 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1464 rc
= memcached_decrement_by_key(memc
, master_key
, strlen(master_key
),
1467 test_compare(MEMCACHED_SUCCESS
, rc
);
1468 test_true(new_number
== 2);
1470 rc
= memcached_decrement_by_key(memc
, master_key
, strlen(master_key
),
1473 test_compare(MEMCACHED_SUCCESS
, rc
);
1474 test_true(new_number
== 1);
1476 return TEST_SUCCESS
;
1479 static test_return_t
decrement_with_initial_by_key_test(memcached_st
*memc
)
1481 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1483 uint64_t new_number
;
1484 const char *master_key
= "foo";
1485 const char *key
= "number";
1486 uint64_t initial
= 3;
1488 test_compare(MEMCACHED_SUCCESS
,
1489 memcached_decrement_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1491 1, initial
, 0, &new_number
));
1492 test_compare(new_number
, initial
);
1494 test_compare(MEMCACHED_SUCCESS
,
1495 memcached_decrement_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1497 1, initial
, 0, &new_number
));
1498 test_compare(new_number
, (initial
- 1));
1500 return TEST_SUCCESS
;
1503 static test_return_t
quit_test(memcached_st
*memc
)
1505 memcached_return_t rc
;
1506 const char *key
= "fudge";
1507 const char *value
= "sanford and sun";
1509 rc
= memcached_set(memc
, key
, strlen(key
),
1510 value
, strlen(value
),
1511 (time_t)10, (uint32_t)3);
1512 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1513 memcached_quit(memc
);
1515 rc
= memcached_set(memc
, key
, strlen(key
),
1516 value
, strlen(value
),
1517 (time_t)50, (uint32_t)9);
1518 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1520 return TEST_SUCCESS
;
1523 static test_return_t
mget_result_test(memcached_st
*memc
)
1525 const char *keys
[]= {"fudge", "son", "food"};
1526 size_t key_length
[]= {5, 3, 4};
1528 memcached_result_st results_obj
;
1529 memcached_result_st
*results
;
1531 results
= memcached_result_create(memc
, &results_obj
);
1533 test_true(&results_obj
== results
);
1535 /* We need to empty the server before continueing test */
1536 test_compare(MEMCACHED_SUCCESS
,
1537 memcached_flush(memc
, 0));
1539 test_compare(MEMCACHED_SUCCESS
,
1540 memcached_mget(memc
, keys
, key_length
, 3));
1542 memcached_return_t rc
;
1543 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1548 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
))) { test_true(false); /* We should never see a value returned */ };
1549 test_false(results
);
1550 test_compare_got(MEMCACHED_NOTFOUND
, rc
, memcached_strerror(NULL
, rc
));
1552 for (uint32_t x
= 0; x
< 3; x
++)
1554 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1555 keys
[x
], key_length
[x
],
1556 (time_t)50, (uint32_t)9);
1557 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1560 test_compare(MEMCACHED_SUCCESS
,
1561 memcached_mget(memc
, keys
, key_length
, 3));
1563 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1566 test_true(&results_obj
== results
);
1567 test_compare(MEMCACHED_SUCCESS
, rc
);
1568 test_compare(memcached_result_key_length(results
), memcached_result_length(results
));
1569 test_memcmp(memcached_result_key_value(results
),
1570 memcached_result_value(results
),
1571 memcached_result_length(results
));
1574 memcached_result_free(&results_obj
);
1576 return TEST_SUCCESS
;
1579 static test_return_t
mget_result_alloc_test(memcached_st
*memc
)
1581 const char *keys
[]= {"fudge", "son", "food"};
1582 size_t key_length
[]= {5, 3, 4};
1584 memcached_result_st
*results
;
1586 /* We need to empty the server before continueing test */
1587 test_compare(MEMCACHED_SUCCESS
,
1588 memcached_flush(memc
, 0));
1590 test_compare(MEMCACHED_SUCCESS
,
1591 memcached_mget(memc
, keys
, key_length
, 3));
1593 memcached_return_t rc
;
1594 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1598 test_false(results
);
1599 test_compare_got(MEMCACHED_NOTFOUND
, rc
, memcached_strerror(NULL
, rc
));
1601 for (uint32_t x
= 0; x
< 3; x
++)
1603 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1604 keys
[x
], key_length
[x
],
1605 (time_t)50, (uint32_t)9);
1606 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1609 test_compare(MEMCACHED_SUCCESS
,
1610 memcached_mget(memc
, keys
, key_length
, 3));
1613 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1616 test_compare(MEMCACHED_SUCCESS
, rc
);
1617 test_true(memcached_result_key_length(results
) == memcached_result_length(results
));
1618 test_memcmp(memcached_result_key_value(results
),
1619 memcached_result_value(results
),
1620 memcached_result_length(results
));
1621 memcached_result_free(results
);
1625 return TEST_SUCCESS
;
1628 /* Count the results */
1629 static memcached_return_t
callback_counter(const memcached_st
*, memcached_result_st
*, void *context
)
1631 size_t *counter
= (size_t *)context
;
1633 *counter
= *counter
+ 1;
1635 return MEMCACHED_SUCCESS
;
1638 static test_return_t
mget_result_function(memcached_st
*memc
)
1640 const char *keys
[]= {"fudge", "son", "food"};
1641 size_t key_length
[]= {5, 3, 4};
1643 memcached_execute_fn callbacks
[1];
1645 /* We need to empty the server before continueing test */
1646 test_compare(MEMCACHED_SUCCESS
,
1647 memcached_flush(memc
, 0));
1648 for (uint32_t x
= 0; x
< 3; x
++)
1650 memcached_return_t rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1651 keys
[x
], key_length
[x
],
1652 (time_t)50, (uint32_t)9);
1653 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1656 test_compare(MEMCACHED_SUCCESS
,
1657 memcached_mget(memc
, keys
, key_length
, 3));
1659 callbacks
[0]= &callback_counter
;
1662 memcached_return_t rc
;
1663 test_compare_got(MEMCACHED_SUCCESS
,
1664 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1),
1665 memcached_strerror(NULL
, rc
));
1667 test_compare(counter
, 3);
1669 return TEST_SUCCESS
;
1672 static test_return_t
mget_test(memcached_st
*memc
)
1674 const char *keys
[]= {"fudge", "son", "food"};
1675 size_t key_length
[]= {5, 3, 4};
1677 char return_key
[MEMCACHED_MAX_KEY
];
1678 size_t return_key_length
;
1680 size_t return_value_length
;
1682 /* We need to empty the server before continueing test */
1683 test_compare(MEMCACHED_SUCCESS
,
1684 memcached_flush(memc
, 0));
1686 test_compare(MEMCACHED_SUCCESS
,
1687 memcached_mget(memc
, keys
, key_length
, 3));
1690 memcached_return_t rc
;
1691 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1692 &return_value_length
, &flags
, &rc
)))
1694 test_true(return_value
);
1696 test_false(return_value
);
1697 test_compare(0, return_value_length
);
1698 test_compare_got(MEMCACHED_NOTFOUND
, rc
, memcached_strerror(NULL
, rc
));
1700 for (uint32_t x
= 0; x
< 3; x
++)
1702 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1703 keys
[x
], key_length
[x
],
1704 (time_t)50, (uint32_t)9);
1705 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1707 test_compare(MEMCACHED_SUCCESS
,
1708 memcached_mget(memc
, keys
, key_length
, 3));
1711 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1712 &return_value_length
, &flags
, &rc
)))
1714 test_true(return_value
);
1715 test_compare(MEMCACHED_SUCCESS
, rc
);
1716 test_true(return_key_length
== return_value_length
);
1717 test_memcmp(return_value
, return_key
, return_value_length
);
1722 return TEST_SUCCESS
;
1725 static test_return_t
mget_execute(memcached_st
*memc
)
1729 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1733 * I only want to hit _one_ server so I know the number of requests I'm
1734 * sending in the pipeline.
1736 uint32_t number_of_hosts
= memc
->number_of_hosts
;
1737 memc
->number_of_hosts
= 1;
1739 size_t max_keys
= 20480;
1742 char **keys
= static_cast<char **>(calloc(max_keys
, sizeof(char*)));
1743 size_t *key_length
=static_cast<size_t *>(calloc(max_keys
, sizeof(size_t)));
1745 /* First add all of the items.. */
1746 char blob
[1024] = {0};
1747 memcached_return_t rc
;
1749 for (size_t x
= 0; x
< max_keys
; ++x
)
1753 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%lu", (unsigned long)x
);
1755 test_true(keys
[x
] != NULL
);
1756 uint64_t query_id
= memcached_query_id(memc
);
1757 rc
= memcached_add(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
1758 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1759 test_compare(query_id
+1, memcached_query_id(memc
));
1762 /* Try to get all of them with a large multiget */
1764 memcached_execute_fn callbacks
[]= { &callback_counter
};
1765 rc
= memcached_mget_execute(memc
, (const char**)keys
, key_length
,
1766 max_keys
, callbacks
, &counter
, 1);
1768 if (memcached_success(rc
))
1771 uint64_t query_id
= memcached_query_id(memc
);
1772 test_compare(MEMCACHED_SUCCESS
,
1773 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
1774 test_compare(query_id
, memcached_query_id(memc
));
1776 /* Verify that we got all of the items */
1777 test_true(counter
== max_keys
);
1779 else if (rc
== MEMCACHED_NOT_SUPPORTED
)
1781 test_true(counter
== 0);
1785 test_fail("note: this test functions differently when in binary mode");
1788 /* Release all allocated resources */
1789 for (size_t x
= 0; x
< max_keys
; ++x
)
1796 memc
->number_of_hosts
= number_of_hosts
;
1797 return TEST_SUCCESS
;
1800 #define REGRESSION_BINARY_VS_BLOCK_COUNT 20480
1802 static test_return_t
key_setup(memcached_st
*memc
)
1804 test_skip(TEST_SUCCESS
, pre_binary(memc
));
1806 global_pairs
= pairs_generate(REGRESSION_BINARY_VS_BLOCK_COUNT
, 0);
1808 return TEST_SUCCESS
;
1811 static test_return_t
key_teardown(memcached_st
*memc
)
1814 pairs_free(global_pairs
);
1816 return TEST_SUCCESS
;
1819 static test_return_t
block_add_regression(memcached_st
*memc
)
1821 /* First add all of the items.. */
1822 for (size_t x
= 0; x
< REGRESSION_BINARY_VS_BLOCK_COUNT
; ++x
)
1824 memcached_return_t rc
;
1825 char blob
[1024] = {0};
1827 rc
= memcached_add_by_key(memc
, "bob", 3, global_pairs
[x
].key
, global_pairs
[x
].key_length
, blob
, sizeof(blob
), 0, 0);
1828 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1831 return TEST_SUCCESS
;
1834 static test_return_t
binary_add_regression(memcached_st
*memc
)
1836 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
1837 test_return_t rc
= block_add_regression(memc
);
1838 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 0);
1842 static test_return_t
get_stats_keys(memcached_st
*memc
)
1846 memcached_stat_st memc_stat
;
1847 memcached_return_t rc
;
1849 stat_list
= memcached_stat_get_keys(memc
, &memc_stat
, &rc
);
1850 test_compare(MEMCACHED_SUCCESS
, rc
);
1851 for (ptr
= stat_list
; *ptr
; ptr
++)
1856 return TEST_SUCCESS
;
1859 static test_return_t
version_string_test(memcached_st
*memc
)
1861 const char *version_string
;
1864 version_string
= memcached_lib_version();
1866 test_strcmp(version_string
, LIBMEMCACHED_VERSION_STRING
);
1868 return TEST_SUCCESS
;
1871 static test_return_t
get_stats(memcached_st
*memc
)
1873 memcached_return_t rc
;
1875 memcached_stat_st
*memc_stat
= memcached_stat(memc
, NULL
, &rc
);
1876 test_compare(MEMCACHED_SUCCESS
, rc
);
1877 test_true(memc_stat
);
1879 for (uint32_t x
= 0; x
< memcached_server_count(memc
); x
++)
1881 char **stat_list
= memcached_stat_get_keys(memc
, memc_stat
+x
, &rc
);
1882 test_compare(MEMCACHED_SUCCESS
, rc
);
1883 for (char **ptr
= stat_list
; *ptr
; ptr
++);
1888 memcached_stat_free(NULL
, memc_stat
);
1890 return TEST_SUCCESS
;
1893 static test_return_t
add_host_test(memcached_st
*memc
)
1896 memcached_server_st
*servers
;
1897 memcached_return_t rc
;
1898 char servername
[]= "0.example.com";
1900 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
1902 test_true(1 == memcached_server_list_count(servers
));
1904 for (x
= 2; x
< 20; x
++)
1906 char buffer
[SMALL_STRING_LEN
];
1908 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
1909 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
1911 test_compare(MEMCACHED_SUCCESS
, rc
);
1912 test_true(x
== memcached_server_list_count(servers
));
1915 rc
= memcached_server_push(memc
, servers
);
1916 test_compare(MEMCACHED_SUCCESS
, rc
);
1917 rc
= memcached_server_push(memc
, servers
);
1918 test_compare(MEMCACHED_SUCCESS
, rc
);
1920 memcached_server_list_free(servers
);
1922 return TEST_SUCCESS
;
1925 static test_return_t
memcached_fetch_result_NOT_FOUND(memcached_st
*memc
)
1927 memcached_return_t rc
;
1928 const char *key
= "not_found";
1929 size_t key_len
= strlen(key
);
1931 test_compare(MEMCACHED_SUCCESS
,
1932 memcached_mget(memc
, &key
, &key_len
, 1));
1934 memcached_result_st
*result
= NULL
;
1935 result
= memcached_fetch_result(memc
, result
, &rc
);
1937 test_compare_got(MEMCACHED_NOTFOUND
, rc
, memcached_strerror(NULL
, rc
));
1939 memcached_result_free(result
);
1941 return TEST_SUCCESS
;
1944 static memcached_return_t
clone_test_callback(memcached_st
*parent
, memcached_st
*memc_clone
)
1946 (void)parent
;(void)memc_clone
;
1947 return MEMCACHED_SUCCESS
;
1950 static memcached_return_t
cleanup_test_callback(memcached_st
*ptr
)
1953 return MEMCACHED_SUCCESS
;
1956 static test_return_t
callback_test(memcached_st
*memc
)
1958 /* Test User Data */
1962 memcached_return_t rc
;
1964 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_USER_DATA
, &x
);
1965 test_compare(MEMCACHED_SUCCESS
, rc
);
1966 test_ptr
= (int *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_USER_DATA
, &rc
);
1967 test_true(*test_ptr
== x
);
1970 /* Test Clone Callback */
1972 memcached_clone_fn clone_cb
= (memcached_clone_fn
)clone_test_callback
;
1973 void *clone_cb_ptr
= *(void **)&clone_cb
;
1974 void *temp_function
= NULL
;
1975 memcached_return_t rc
;
1977 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
,
1979 test_compare(MEMCACHED_SUCCESS
, rc
);
1980 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1981 test_true(temp_function
== clone_cb_ptr
);
1984 /* Test Cleanup Callback */
1986 memcached_cleanup_fn cleanup_cb
=
1987 (memcached_cleanup_fn
)cleanup_test_callback
;
1988 void *cleanup_cb_ptr
= *(void **)&cleanup_cb
;
1989 void *temp_function
= NULL
;
1990 memcached_return_t rc
;
1992 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
,
1994 test_compare(MEMCACHED_SUCCESS
, rc
);
1995 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1996 test_true(temp_function
== cleanup_cb_ptr
);
1999 return TEST_SUCCESS
;
2002 /* We don't test the behavior itself, we test the switches */
2003 static test_return_t
behavior_test(memcached_st
*memc
)
2008 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2009 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
2010 test_true(value
== 1);
2012 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2013 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
2014 test_true(value
== 1);
2016 set
= MEMCACHED_HASH_MD5
;
2017 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
2018 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
2019 test_true(value
== MEMCACHED_HASH_MD5
);
2023 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2024 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
2025 test_true(value
== 0);
2027 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2028 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
2029 test_true(value
== 0);
2031 set
= MEMCACHED_HASH_DEFAULT
;
2032 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
2033 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
2034 test_true(value
== MEMCACHED_HASH_DEFAULT
);
2036 set
= MEMCACHED_HASH_CRC
;
2037 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
2038 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
2039 test_true(value
== MEMCACHED_HASH_CRC
);
2041 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
2042 test_true(value
> 0);
2044 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
2045 test_true(value
> 0);
2047 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
);
2048 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, value
+ 1);
2049 test_true((value
+ 1) == memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
));
2051 return TEST_SUCCESS
;
2054 static test_return_t
MEMCACHED_BEHAVIOR_CORK_test(memcached_st
*memc
)
2056 memcached_return_t rc
;
2059 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CORK
, set
);
2060 test_true(rc
== MEMCACHED_DEPRECATED
);
2062 // Platform dependent
2064 bool value
= (bool)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_CORK
);
2068 return TEST_SUCCESS
;
2072 static test_return_t
MEMCACHED_BEHAVIOR_TCP_KEEPALIVE_test(memcached_st
*memc
)
2074 memcached_return_t rc
;
2078 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE
, set
);
2079 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_NOT_SUPPORTED
);
2081 value
= (bool)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE
);
2083 if (rc
== MEMCACHED_SUCCESS
)
2085 test_true((bool)value
== set
);
2089 test_false((bool)value
== set
);
2092 return TEST_SUCCESS
;
2096 static test_return_t
MEMCACHED_BEHAVIOR_TCP_KEEPIDLE_test(memcached_st
*memc
)
2098 memcached_return_t rc
;
2102 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_KEEPIDLE
, set
);
2103 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_NOT_SUPPORTED
);
2105 value
= (bool)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_KEEPIDLE
);
2107 if (rc
== MEMCACHED_SUCCESS
)
2109 test_true((bool)value
== set
);
2113 test_false((bool)value
== set
);
2116 return TEST_SUCCESS
;
2119 static test_return_t
fetch_all_results(memcached_st
*memc
, size_t &keys_returned
, const memcached_return_t expect
)
2121 memcached_return_t rc
;
2122 char return_key
[MEMCACHED_MAX_KEY
];
2123 size_t return_key_length
;
2125 size_t return_value_length
;
2129 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2130 &return_value_length
, &flags
, &rc
)))
2132 test_true(return_value
);
2133 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
2138 if (memcached_success(expect
) and memcached_success(rc
))
2140 return TEST_SUCCESS
;
2142 else if (expect
== rc
)
2144 return TEST_SUCCESS
;
2146 fprintf(stderr
, "\n%s:%u %s(#%lu)\n", __FILE__
, __LINE__
, memcached_strerror(NULL
, rc
), (unsigned long)(keys_returned
));
2148 return TEST_FAILURE
;
2151 /* Test case provided by Cal Haldenbrand */
2152 #define HALDENBRAND_KEY_COUNT 3000 // * 1024576
2153 #define HALDENBRAND_FLAG_KEY 99 // * 1024576
2154 static test_return_t
user_supplied_bug1(memcached_st
*memc
)
2156 /* We just keep looking at the same values over and over */
2159 unsigned int setter
= 1;
2160 test_compare(MEMCACHED_SUCCESS
,
2161 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
));
2162 test_compare(MEMCACHED_SUCCESS
,
2163 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
));
2167 unsigned long long total
= 0;
2168 for (uint32_t x
= 0 ; total
< 20 * 1024576 ; x
++ )
2170 uint32_t size
= (uint32_t)(rand() % ( 5 * 1024 ) ) + 400;
2171 char randomstuff
[6 * 1024];
2172 memset(randomstuff
, 0, 6 * 1024);
2173 test_true(size
< 6 * 1024); /* Being safe here */
2175 for (uint32_t j
= 0 ; j
< size
;j
++)
2177 randomstuff
[j
] = (signed char) ((rand() % 26) + 97);
2182 int key_length
= snprintf(key
, sizeof(key
), "%u", x
);
2183 memcached_return_t rc
;
2184 test_compare_got(MEMCACHED_SUCCESS
,
2185 rc
= memcached_set(memc
, key
, key_length
, randomstuff
, strlen(randomstuff
), time_t(0), HALDENBRAND_FLAG_KEY
),
2186 memcached_strerror(NULL
, rc
));
2188 test_true(total
> HALDENBRAND_KEY_COUNT
);
2190 return TEST_SUCCESS
;
2193 /* Test case provided by Cal Haldenbrand */
2194 static test_return_t
user_supplied_bug2(memcached_st
*memc
)
2196 unsigned int setter
= 1;
2198 test_compare(MEMCACHED_SUCCESS
,
2199 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
));
2201 test_compare(MEMCACHED_SUCCESS
,
2202 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
));
2205 setter
= 20 * 1024576;
2206 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
2207 setter
= 20 * 1024576;
2208 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
2209 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
2210 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
2212 for (x
= 0, errors
= 0; total
< 20 * 1024576 ; x
++)
2215 size_t total_value_length
= 0;
2216 for (uint32_t x
= 0, errors
= 0; total_value_length
< 24576 ; x
++)
2221 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1];
2222 int key_length
= snprintf(key
, sizeof(key
), "%u", x
);
2224 memcached_return_t rc
;
2225 char *getval
= memcached_get(memc
, key
, key_length
, &val_len
, &flags
, &rc
);
2226 if (memcached_failed(rc
))
2228 if (rc
== MEMCACHED_NOTFOUND
)
2239 test_compare(HALDENBRAND_FLAG_KEY
, flags
);
2241 total_value_length
+= val_len
;
2246 return TEST_SUCCESS
;
2249 /* Do a large mget() over all the keys we think exist */
2250 static test_return_t
user_supplied_bug3(memcached_st
*memc
)
2252 unsigned int setter
= 1;
2253 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
2254 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2256 setter
= 20 * 1024576;
2257 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
2258 setter
= 20 * 1024576;
2259 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
2260 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
2261 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
2264 size_t key_lengths
[HALDENBRAND_KEY_COUNT
];
2265 char **keys
= static_cast<char **>(calloc(HALDENBRAND_KEY_COUNT
, sizeof(char *)));
2267 for (uint32_t x
= 0; x
< HALDENBRAND_KEY_COUNT
; x
++)
2269 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1];
2270 int key_length
= snprintf(key
, sizeof(key
), "%u", x
);
2271 keys
[x
]= strdup(key
);
2273 key_lengths
[x
]= key_length
;
2274 test_compare(key_length
, strlen(keys
[x
]));
2277 test_compare(MEMCACHED_SUCCESS
,
2278 memcached_mget(memc
, (const char **)keys
, key_lengths
, HALDENBRAND_KEY_COUNT
));
2281 size_t keys_returned
;
2282 test_compare_got(TEST_SUCCESS
, foo
= fetch_all_results(memc
, keys_returned
, MEMCACHED_SUCCESS
), test_strerror(foo
));
2283 test_compare(HALDENBRAND_KEY_COUNT
, keys_returned
);
2285 for (uint32_t x
= 0; x
< HALDENBRAND_KEY_COUNT
; x
++)
2291 return TEST_SUCCESS
;
2294 /* Make sure we behave properly if server list has no values */
2295 static test_return_t
user_supplied_bug4(memcached_st
*memc
)
2297 const char *keys
[]= {"fudge", "son", "food"};
2298 size_t key_length
[]= {5, 3, 4};
2300 /* Here we free everything before running a bunch of mget tests */
2301 memcached_servers_reset(memc
);
2304 /* We need to empty the server before continueing test */
2305 test_compare(MEMCACHED_NO_SERVERS
,
2306 memcached_flush(memc
, 0));
2308 test_compare(MEMCACHED_NO_SERVERS
,
2309 memcached_mget(memc
, keys
, key_length
, 3));
2311 size_t keys_returned
;
2312 test_compare(TEST_SUCCESS
, fetch_all_results(memc
, keys_returned
, MEMCACHED_NOTFOUND
));
2313 test_compare(0, keys_returned
);
2315 for (uint32_t x
= 0; x
< 3; x
++)
2317 test_compare(MEMCACHED_NO_SERVERS
,
2318 memcached_set(memc
, keys
[x
], key_length
[x
],
2319 keys
[x
], key_length
[x
],
2320 (time_t)50, (uint32_t)9));
2323 test_compare(MEMCACHED_NO_SERVERS
,
2324 memcached_mget(memc
, keys
, key_length
, 3));
2328 char return_key
[MEMCACHED_MAX_KEY
];
2329 memcached_return_t rc
;
2330 size_t return_key_length
;
2331 size_t return_value_length
;
2334 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2335 &return_value_length
, &flags
, &rc
)))
2337 test_true(return_value
);
2338 test_compare(MEMCACHED_SUCCESS
, rc
);
2339 test_true(return_key_length
== return_value_length
);
2340 test_memcmp(return_value
, return_key
, return_value_length
);
2346 return TEST_SUCCESS
;
2349 #define VALUE_SIZE_BUG5 1048064
2350 static test_return_t
user_supplied_bug5(memcached_st
*memc
)
2352 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
2353 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
2355 size_t value_length
;
2357 char *insert_data
= new (std::nothrow
) char[VALUE_SIZE_BUG5
];
2359 for (uint32_t x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2361 insert_data
[x
]= (signed char)rand();
2364 test_compare(MEMCACHED_SUCCESS
,
2365 memcached_flush(memc
, 0));
2367 memcached_return_t rc
;
2368 value
= memcached_get(memc
, keys
[0], key_length
[0],
2369 &value_length
, &flags
, &rc
);
2371 test_compare(MEMCACHED_SUCCESS
,
2372 memcached_mget(memc
, keys
, key_length
, 4));
2375 test_compare(TEST_SUCCESS
, fetch_all_results(memc
, count
, MEMCACHED_NOTFOUND
));
2376 test_compare(0, count
);
2378 for (uint32_t x
= 0; x
< 4; x
++)
2380 test_compare(MEMCACHED_SUCCESS
,
2381 memcached_set(memc
, keys
[x
], key_length
[x
],
2382 insert_data
, VALUE_SIZE_BUG5
,
2383 (time_t)0, (uint32_t)0));
2386 for (uint32_t x
= 0; x
< 10; x
++)
2388 value
= memcached_get(memc
, keys
[0], key_length
[0],
2389 &value_length
, &flags
, &rc
);
2390 test_compare(rc
, MEMCACHED_SUCCESS
);
2394 test_compare(MEMCACHED_SUCCESS
,
2395 memcached_mget(memc
, keys
, key_length
, 4));
2397 test_compare(TEST_SUCCESS
, fetch_all_results(memc
, count
, MEMCACHED_SUCCESS
));
2398 test_compare(4, count
);
2400 delete [] insert_data
;
2402 return TEST_SUCCESS
;
2405 static test_return_t
user_supplied_bug6(memcached_st
*memc
)
2407 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
2408 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
2409 char return_key
[MEMCACHED_MAX_KEY
];
2410 size_t return_key_length
;
2412 size_t value_length
;
2414 char *insert_data
= new (std::nothrow
) char[VALUE_SIZE_BUG5
];
2416 for (uint32_t x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2418 insert_data
[x
]= (signed char)rand();
2421 test_compare(MEMCACHED_SUCCESS
,
2422 memcached_flush(memc
, 0));
2424 memcached_return_t rc
;
2425 value
= memcached_get(memc
, keys
[0], key_length
[0],
2426 &value_length
, &flags
, &rc
);
2428 test_compare(MEMCACHED_NOTFOUND
, rc
);
2430 test_compare(MEMCACHED_SUCCESS
,
2431 memcached_mget(memc
, keys
, key_length
, 4));
2434 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2435 &value_length
, &flags
, &rc
)))
2439 test_compare(0, count
);
2440 test_compare_got(MEMCACHED_NOTFOUND
, rc
, memcached_strerror(NULL
, rc
));
2442 for (uint32_t x
= 0; x
< 4; x
++)
2444 test_compare(MEMCACHED_SUCCESS
,
2445 memcached_set(memc
, keys
[x
], key_length
[x
],
2446 insert_data
, VALUE_SIZE_BUG5
,
2447 (time_t)0, (uint32_t)0));
2450 for (uint32_t x
= 0; x
< 2; x
++)
2452 value
= memcached_get(memc
, keys
[0], key_length
[0],
2453 &value_length
, &flags
, &rc
);
2457 test_compare(MEMCACHED_SUCCESS
,
2458 memcached_mget(memc
, keys
, key_length
, 4));
2460 /* We test for purge of partial complete fetches */
2461 for (count
= 3; count
; count
--)
2463 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2464 &value_length
, &flags
, &rc
);
2465 test_compare(MEMCACHED_SUCCESS
, rc
);
2466 test_memcmp(value
, insert_data
, value_length
);
2467 test_true(value_length
);
2471 delete [] insert_data
;
2473 return TEST_SUCCESS
;
2476 static test_return_t
user_supplied_bug8(memcached_st
*)
2478 memcached_return_t rc
;
2480 memcached_st
*memc_clone
;
2482 memcached_server_st
*servers
;
2483 const char *server_list
= "memcache1.memcache.bk.sapo.pt:11211, memcache1.memcache.bk.sapo.pt:11212, memcache1.memcache.bk.sapo.pt:11213, memcache1.memcache.bk.sapo.pt:11214, memcache2.memcache.bk.sapo.pt:11211, memcache2.memcache.bk.sapo.pt:11212, memcache2.memcache.bk.sapo.pt:11213, memcache2.memcache.bk.sapo.pt:11214";
2485 servers
= memcached_servers_parse(server_list
);
2488 mine
= memcached_create(NULL
);
2489 rc
= memcached_server_push(mine
, servers
);
2490 test_compare(MEMCACHED_SUCCESS
, rc
);
2491 memcached_server_list_free(servers
);
2494 memc_clone
= memcached_clone(NULL
, mine
);
2496 memcached_quit(mine
);
2497 memcached_quit(memc_clone
);
2500 memcached_free(mine
);
2501 memcached_free(memc_clone
);
2503 return TEST_SUCCESS
;
2506 /* Test flag store/retrieve */
2507 static test_return_t
user_supplied_bug7(memcached_st
*memc
)
2509 const char *keys
= "036790384900";
2510 size_t key_length
= strlen(keys
);
2511 char return_key
[MEMCACHED_MAX_KEY
];
2512 size_t return_key_length
;
2514 size_t value_length
;
2516 char *insert_data
= new (std::nothrow
) char[VALUE_SIZE_BUG5
];
2518 for (unsigned int x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2519 insert_data
[x
]= (signed char)rand();
2521 memcached_flush(memc
, 0);
2524 memcached_return_t rc
= memcached_set(memc
, keys
, key_length
,
2525 insert_data
, VALUE_SIZE_BUG5
,
2527 test_compare(MEMCACHED_SUCCESS
, rc
);
2530 value
= memcached_get(memc
, keys
, key_length
,
2531 &value_length
, &flags
, &rc
);
2532 test_true(flags
== 245);
2536 rc
= memcached_mget(memc
, &keys
, &key_length
, 1);
2539 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2540 &value_length
, &flags
, &rc
);
2541 test_compare(245, flags
);
2544 delete [] insert_data
;
2547 return TEST_SUCCESS
;
2550 static test_return_t
user_supplied_bug9(memcached_st
*memc
)
2552 const char *keys
[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
2553 size_t key_length
[3];
2557 char return_key
[MEMCACHED_MAX_KEY
];
2558 size_t return_key_length
;
2560 size_t return_value_length
;
2563 key_length
[0]= strlen("UDATA:edevil@sapo.pt");
2564 key_length
[1]= strlen("fudge&*@#");
2565 key_length
[2]= strlen("for^#@&$not");
2568 for (unsigned int x
= 0; x
< 3; x
++)
2570 memcached_return_t rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2571 keys
[x
], key_length
[x
],
2572 (time_t)50, (uint32_t)9);
2573 test_compare(MEMCACHED_SUCCESS
, rc
);
2576 memcached_return_t rc
= memcached_mget(memc
, keys
, key_length
, 3);
2577 test_compare(MEMCACHED_SUCCESS
, rc
);
2579 /* We need to empty the server before continueing test */
2580 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2581 &return_value_length
, &flags
, &rc
)) != NULL
)
2583 test_true(return_value
);
2587 test_compare(3, count
);
2589 return TEST_SUCCESS
;
2592 /* We are testing with aggressive timeout to get failures */
2593 static test_return_t
user_supplied_bug10(memcached_st
*memc
)
2595 const char *key
= "foo";
2596 size_t value_length
= 512;
2598 unsigned int set
= 1;
2599 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2601 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2602 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2604 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, (uint64_t)timeout
);
2606 char *value
= (char*)malloc(value_length
* sizeof(char));
2608 for (unsigned int x
= 0; x
< value_length
; x
++)
2610 value
[x
]= (char) (x
% 127);
2613 for (unsigned int x
= 1; x
<= 100000; ++x
)
2615 memcached_return_t rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2617 test_true_got(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_WRITE_FAILURE
or rc
== MEMCACHED_BUFFERED
or rc
== MEMCACHED_TIMEOUT
or rc
== MEMCACHED_CONNECTION_FAILURE
,
2618 memcached_strerror(NULL
, rc
));
2620 if (rc
== MEMCACHED_WRITE_FAILURE
or rc
== MEMCACHED_TIMEOUT
)
2627 memcached_free(mclone
);
2629 return TEST_SUCCESS
;
2633 We are looking failures in the async protocol
2635 static test_return_t
user_supplied_bug11(memcached_st
*memc
)
2637 const char *key
= "foo";
2638 size_t value_length
= 512;
2640 unsigned int set
= 1;
2641 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2643 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2644 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2645 int32_t timeout
= -1;
2646 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, (size_t)timeout
);
2648 timeout
= (int32_t)memcached_behavior_get(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
2650 test_true(timeout
== -1);
2652 char *value
= (char*)malloc(value_length
* sizeof(char));
2654 for (unsigned int x
= 0; x
< value_length
; x
++)
2656 value
[x
]= (char) (x
% 127);
2659 for (unsigned int x
= 1; x
<= 100000; ++x
)
2661 memcached_return_t rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2666 memcached_free(mclone
);
2668 return TEST_SUCCESS
;
2672 Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
2674 static test_return_t
user_supplied_bug12(memcached_st
*memc
)
2676 memcached_return_t rc
;
2678 size_t value_length
;
2680 uint64_t number_value
;
2682 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2683 &value_length
, &flags
, &rc
);
2684 test_true(value
== NULL
);
2685 test_compare(MEMCACHED_NOTFOUND
, rc
);
2687 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2690 test_true(value
== NULL
);
2691 /* The binary protocol will set the key if it doesn't exist */
2692 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1)
2694 test_compare(MEMCACHED_SUCCESS
, rc
);
2698 test_compare(MEMCACHED_NOTFOUND
, rc
);
2701 rc
= memcached_set(memc
, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
2703 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2704 &value_length
, &flags
, &rc
);
2706 test_compare(MEMCACHED_SUCCESS
, rc
);
2709 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2711 test_true(number_value
== 2);
2712 test_compare(MEMCACHED_SUCCESS
, rc
);
2714 return TEST_SUCCESS
;
2718 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2719 set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
2721 static test_return_t
user_supplied_bug13(memcached_st
*memc
)
2723 char key
[] = "key34567890";
2724 memcached_return_t rc
;
2725 size_t overflowSize
;
2727 char commandFirst
[]= "set key34567890 0 0 ";
2728 char commandLast
[] = " \r\n"; /* first line of command sent to server */
2729 size_t commandLength
;
2732 commandLength
= strlen(commandFirst
) + strlen(commandLast
) + 4; /* 4 is number of characters in size, probably 8196 */
2734 overflowSize
= MEMCACHED_MAX_BUFFER
- commandLength
;
2736 for (testSize
= overflowSize
- 1; testSize
< overflowSize
+ 1; testSize
++)
2738 char *overflow
= new (std::nothrow
) char[testSize
];
2739 test_true(overflow
);
2741 memset(overflow
, 'x', testSize
);
2742 rc
= memcached_set(memc
, key
, strlen(key
),
2743 overflow
, testSize
, 0, 0);
2744 test_compare(MEMCACHED_SUCCESS
, rc
);
2748 return TEST_SUCCESS
;
2753 Test values of many different sizes
2754 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2755 set key34567890 0 0 8169 \r\n
2756 is sent followed by buffer of size 8169, followed by 8169
2758 static test_return_t
user_supplied_bug14(memcached_st
*memc
)
2761 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2762 memcached_return_t rc
;
2763 const char *key
= "foo";
2765 size_t value_length
= 18000;
2767 size_t string_length
;
2770 size_t current_length
;
2772 value
= (char*)malloc(value_length
);
2775 for (x
= 0; x
< value_length
; x
++)
2776 value
[x
] = (char) (x
% 127);
2778 for (current_length
= 0; current_length
< value_length
; current_length
++)
2780 rc
= memcached_set(memc
, key
, strlen(key
),
2781 value
, current_length
,
2782 (time_t)0, (uint32_t)0);
2783 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
2785 string
= memcached_get(memc
, key
, strlen(key
),
2786 &string_length
, &flags
, &rc
);
2788 test_compare(MEMCACHED_SUCCESS
, rc
);
2789 test_true(string_length
== current_length
);
2790 test_memcmp(string
, value
, string_length
);
2797 return TEST_SUCCESS
;
2801 Look for zero length value problems
2803 static test_return_t
user_supplied_bug15(memcached_st
*memc
)
2806 memcached_return_t rc
;
2807 const char *key
= "mykey";
2811 for (x
= 0; x
< 2; x
++)
2813 rc
= memcached_set(memc
, key
, strlen(key
),
2815 (time_t)0, (uint32_t)0);
2817 test_compare(MEMCACHED_SUCCESS
, rc
);
2819 char *value
= memcached_get(memc
, key
, strlen(key
),
2820 &length
, &flags
, &rc
);
2822 test_compare(MEMCACHED_SUCCESS
, rc
);
2827 value
= memcached_get(memc
, key
, strlen(key
),
2828 &length
, &flags
, &rc
);
2830 test_compare(MEMCACHED_SUCCESS
, rc
);
2831 test_true(value
== NULL
);
2832 test_true(length
== 0);
2833 test_true(flags
== 0);
2836 return TEST_SUCCESS
;
2839 /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
2840 static test_return_t
user_supplied_bug16(memcached_st
*memc
)
2842 memcached_return_t rc
;
2843 const char *key
= "mykey";
2848 rc
= memcached_set(memc
, key
, strlen(key
),
2850 (time_t)0, UINT32_MAX
);
2852 test_compare(MEMCACHED_SUCCESS
, rc
);
2854 value
= memcached_get(memc
, key
, strlen(key
),
2855 &length
, &flags
, &rc
);
2857 test_compare(MEMCACHED_SUCCESS
, rc
);
2858 test_true(value
== NULL
);
2859 test_true(length
== 0);
2860 test_true(flags
== UINT32_MAX
);
2862 return TEST_SUCCESS
;
2865 #if !defined(__sun) && !defined(__OpenBSD__)
2866 /* Check the validity of chinese key*/
2867 static test_return_t
user_supplied_bug17(memcached_st
*memc
)
2869 memcached_return_t rc
;
2870 const char *key
= "豆瓣";
2871 const char *value
="我们在炎热抑郁的夏天无法停止豆瓣";
2876 rc
= memcached_set(memc
, key
, strlen(key
),
2877 value
, strlen(value
),
2880 test_compare(MEMCACHED_SUCCESS
, rc
);
2882 value2
= memcached_get(memc
, key
, strlen(key
),
2883 &length
, &flags
, &rc
);
2885 test_true(length
==strlen(value
));
2886 test_compare(MEMCACHED_SUCCESS
, rc
);
2887 test_memcmp(value
, value2
, length
);
2890 return TEST_SUCCESS
;
2898 static test_return_t
user_supplied_bug19(memcached_st
*not_used
)
2901 const memcached_server_st
*server
;
2902 memcached_return_t res
;
2906 memc
= memcached_create(NULL
);
2907 memcached_server_add_with_weight(memc
, "localhost", 11311, 100);
2908 memcached_server_add_with_weight(memc
, "localhost", 11312, 100);
2910 server
= memcached_server_by_key(memc
, "a", 1, &res
);
2912 memcached_free(memc
);
2914 return TEST_SUCCESS
;
2917 /* CAS test from Andei */
2918 static test_return_t
user_supplied_bug20(memcached_st
*memc
)
2920 memcached_return_t status
;
2921 memcached_result_st
*result
, result_obj
;
2922 const char *key
= "abc";
2923 size_t key_len
= strlen("abc");
2924 const char *value
= "foobar";
2925 size_t value_len
= strlen(value
);
2927 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
2929 status
= memcached_set(memc
, key
, key_len
, value
, value_len
, (time_t)0, (uint32_t)0);
2930 test_true(status
== MEMCACHED_SUCCESS
);
2932 status
= memcached_mget(memc
, &key
, &key_len
, 1);
2933 test_true(status
== MEMCACHED_SUCCESS
);
2935 result
= memcached_result_create(memc
, &result_obj
);
2938 memcached_result_create(memc
, &result_obj
);
2939 result
= memcached_fetch_result(memc
, &result_obj
, &status
);
2942 test_true(status
== MEMCACHED_SUCCESS
);
2944 memcached_result_free(result
);
2946 return TEST_SUCCESS
;
2949 #include "ketama_test_cases.h"
2950 static test_return_t
user_supplied_bug18(memcached_st
*trash
)
2952 memcached_return_t rc
;
2959 memc
= memcached_create(NULL
);
2962 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2963 test_compare(MEMCACHED_SUCCESS
, rc
);
2965 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2966 test_true(value
== 1);
2968 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2969 test_compare(MEMCACHED_SUCCESS
, rc
);
2971 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2972 test_true(value
== MEMCACHED_HASH_MD5
);
2974 memcached_server_st
*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");
2975 memcached_server_push(memc
, server_pool
);
2977 /* verify that the server list was parsed okay. */
2978 test_true(memcached_server_count(memc
) == 8);
2979 test_strcmp(server_pool
[0].hostname
, "10.0.1.1");
2980 test_true(server_pool
[0].port
== 11211);
2981 test_true(server_pool
[0].weight
== 600);
2982 test_strcmp(server_pool
[2].hostname
, "10.0.1.3");
2983 test_true(server_pool
[2].port
== 11211);
2984 test_true(server_pool
[2].weight
== 200);
2985 test_strcmp(server_pool
[7].hostname
, "10.0.1.8");
2986 test_true(server_pool
[7].port
== 11211);
2987 test_true(server_pool
[7].weight
== 100);
2989 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
2990 * us test the boundary wraparound.
2992 test_true(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->ketama
.continuum
[0].index
);
2994 /* verify the standard ketama set. */
2995 for (x
= 0; x
< 99; x
++)
2997 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
2999 memcached_server_instance_st instance
=
3000 memcached_server_instance_by_position(memc
, server_idx
);
3002 const char *hostname
= memcached_server_name(instance
);
3003 test_strcmp(hostname
, ketama_test_cases
[x
].server
);
3006 memcached_server_list_free(server_pool
);
3007 memcached_free(memc
);
3009 return TEST_SUCCESS
;
3012 /* Large mget() of missing keys with binary proto
3014 * If many binary quiet commands (such as getq's in an mget) fill the output
3015 * buffer and the server chooses not to respond, memcached_flush hangs. See
3016 * http://lists.tangent.org/pipermail/libmemcached/2009-August/000918.html
3019 /* sighandler_t function that always asserts false */
3020 static void fail(int)
3026 static test_return_t
_user_supplied_bug21(memcached_st
* memc
, size_t key_count
)
3031 return TEST_SKIPPED
;
3033 void (*oldalarm
)(int);
3035 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
3036 test_true(memc_clone
);
3038 /* only binproto uses getq for mget */
3039 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1));
3041 /* empty the cache to ensure misses (hence non-responses) */
3042 test_compare(MEMCACHED_SUCCESS
, memcached_flush(memc_clone
, 0));
3044 size_t* key_lengths
= new (std::nothrow
) size_t[key_count
];
3045 test_true(key_lengths
);
3046 char **keys
= static_cast<char **>(calloc(key_count
, sizeof(char *)));
3048 for (unsigned int x
= 0; x
< key_count
; x
++)
3052 snprintf(buffer
, 30, "%u", x
);
3053 keys
[x
]= strdup(buffer
);
3055 key_lengths
[x
]= strlen(keys
[x
]);
3058 oldalarm
= signal(SIGALRM
, fail
);
3061 test_compare_got(MEMCACHED_SUCCESS
,
3062 memcached_mget(memc_clone
, (const char **)keys
, key_lengths
, key_count
), memcached_last_error_message(memc_clone
));
3065 signal(SIGALRM
, oldalarm
);
3067 memcached_return_t rc
;
3069 char return_key
[MEMCACHED_MAX_KEY
];
3070 size_t return_key_length
;
3072 size_t return_value_length
;
3073 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
3074 &return_value_length
, &flags
, &rc
)))
3076 test_false(return_value
); // There are no keys to fetch, so the value should never be returned
3078 test_compare(MEMCACHED_NOTFOUND
, rc
);
3079 test_compare(0, return_value_length
);
3080 test_compare(0, return_key_length
);
3081 test_false(return_key
[0]);
3082 test_false(return_value
);
3084 for (unsigned int x
= 0; x
< key_count
; x
++)
3089 delete [] key_lengths
;
3091 memcached_free(memc_clone
);
3093 return TEST_SUCCESS
;
3097 static test_return_t
user_supplied_bug21(memcached_st
*memc
)
3099 test_return_t test_rc
;
3100 test_rc
= pre_binary(memc
);
3102 if (test_rc
!= TEST_SUCCESS
)
3105 /* should work as of r580 */
3106 test_compare(TEST_SUCCESS
,
3107 _user_supplied_bug21(memc
, 10));
3109 /* should fail as of r580 */
3110 test_compare(TEST_SUCCESS
,
3111 _user_supplied_bug21(memc
, 1000));
3113 return TEST_SUCCESS
;
3116 static test_return_t
auto_eject_hosts(memcached_st
*trash
)
3119 memcached_server_instance_st instance
;
3121 memcached_return_t rc
;
3122 memcached_st
*memc
= memcached_create(NULL
);
3125 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
3126 test_compare(MEMCACHED_SUCCESS
, rc
);
3128 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
3129 test_true(value
== 1);
3131 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
3132 test_compare(MEMCACHED_SUCCESS
, rc
);
3134 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
3135 test_true(value
== MEMCACHED_HASH_MD5
);
3137 /* server should be removed when in delay */
3138 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
, 1);
3139 test_compare(MEMCACHED_SUCCESS
, rc
);
3141 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
);
3142 test_true(value
== 1);
3144 memcached_server_st
*server_pool
;
3145 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");
3146 memcached_server_push(memc
, server_pool
);
3148 /* verify that the server list was parsed okay. */
3149 test_true(memcached_server_count(memc
) == 8);
3150 test_strcmp(server_pool
[0].hostname
, "10.0.1.1");
3151 test_true(server_pool
[0].port
== 11211);
3152 test_true(server_pool
[0].weight
== 600);
3153 test_strcmp(server_pool
[2].hostname
, "10.0.1.3");
3154 test_true(server_pool
[2].port
== 11211);
3155 test_true(server_pool
[2].weight
== 200);
3156 test_strcmp(server_pool
[7].hostname
, "10.0.1.8");
3157 test_true(server_pool
[7].port
== 11211);
3158 test_true(server_pool
[7].weight
== 100);
3160 instance
= memcached_server_instance_by_position(memc
, 2);
3161 ((memcached_server_write_instance_st
)instance
)->next_retry
= time(NULL
) + 15;
3162 memc
->ketama
.next_distribution_rebuild
= time(NULL
) - 1;
3165 This would not work if there were only two hosts.
3167 for (size_t x
= 0; x
< 99; x
++)
3169 memcached_autoeject(memc
);
3170 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
3171 test_true(server_idx
!= 2);
3174 /* and re-added when it's back. */
3175 ((memcached_server_write_instance_st
)instance
)->next_retry
= time(NULL
) - 1;
3176 memc
->ketama
.next_distribution_rebuild
= time(NULL
) - 1;
3177 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
,
3178 memc
->distribution
);
3179 for (size_t x
= 0; x
< 99; x
++)
3181 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
3182 // We re-use instance from above.
3184 memcached_server_instance_by_position(memc
, server_idx
);
3185 const char *hostname
= memcached_server_name(instance
);
3186 test_strcmp(hostname
, ketama_test_cases
[x
].server
);
3189 memcached_server_list_free(server_pool
);
3190 memcached_free(memc
);
3192 return TEST_SUCCESS
;
3195 static test_return_t
output_ketama_weighted_keys(memcached_st
*trash
)
3199 memcached_return_t rc
;
3200 memcached_st
*memc
= memcached_create(NULL
);
3204 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
3205 test_compare(MEMCACHED_SUCCESS
, rc
);
3207 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
3208 test_true(value
== 1);
3210 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
3211 test_compare(MEMCACHED_SUCCESS
, rc
);
3213 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
3214 test_true(value
== MEMCACHED_HASH_MD5
);
3217 test_true(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
) == MEMCACHED_SUCCESS
);
3219 memcached_server_st
*server_pool
;
3220 server_pool
= memcached_servers_parse("10.0.1.1:11211,10.0.1.2:11211,10.0.1.3:11211,10.0.1.4:11211,10.0.1.5:11211,10.0.1.6:11211,10.0.1.7:11211,10.0.1.8:11211,192.168.1.1:11211,192.168.100.1:11211");
3221 memcached_server_push(memc
, server_pool
);
3223 // @todo this needs to be refactored to actually test something.
3226 if ((fp
= fopen("ketama_keys.txt", "w")))
3230 printf("cannot write to file ketama_keys.txt");
3231 return TEST_FAILURE
;
3234 for (int x
= 0; x
< 10000; x
++)
3237 snprintf(key
, sizeof(key
), "%d", x
);
3239 uint32_t server_idx
= memcached_generate_hash(memc
, key
, strlen(key
));
3240 char *hostname
= memc
->hosts
[server_idx
].hostname
;
3241 in_port_t port
= memc
->hosts
[server_idx
].port
;
3242 fprintf(fp
, "key %s is on host /%s:%u\n", key
, hostname
, port
);
3243 memcached_server_instance_st instance
=
3244 memcached_server_instance_by_position(memc
, host_index
);
3248 memcached_server_list_free(server_pool
);
3249 memcached_free(memc
);
3251 return TEST_SUCCESS
;
3255 static test_return_t
result_static(memcached_st
*memc
)
3257 memcached_result_st result
;
3258 memcached_result_st
*result_ptr
;
3260 result_ptr
= memcached_result_create(memc
, &result
);
3261 test_true(result
.options
.is_allocated
== false);
3262 test_true(memcached_is_initialized(&result
) == true);
3263 test_true(result_ptr
);
3264 test_true(result_ptr
== &result
);
3266 memcached_result_free(&result
);
3268 test_true(result
.options
.is_allocated
== false);
3269 test_true(memcached_is_initialized(&result
) == false);
3271 return TEST_SUCCESS
;
3274 static test_return_t
result_alloc(memcached_st
*memc
)
3276 memcached_result_st
*result_ptr
;
3278 result_ptr
= memcached_result_create(memc
, NULL
);
3279 test_true(result_ptr
);
3280 test_true(result_ptr
->options
.is_allocated
== true);
3281 test_true(memcached_is_initialized(result_ptr
) == true);
3282 memcached_result_free(result_ptr
);
3284 return TEST_SUCCESS
;
3287 static test_return_t
cleanup_pairs(memcached_st
*memc
)
3290 pairs_free(global_pairs
);
3292 return TEST_SUCCESS
;
3295 static test_return_t
generate_pairs(memcached_st
*memc
)
3298 global_pairs
= pairs_generate(GLOBAL_COUNT
, 400);
3299 global_count
= GLOBAL_COUNT
;
3301 for (size_t x
= 0; x
< global_count
; x
++)
3303 global_keys
[x
]= global_pairs
[x
].key
;
3304 global_keys_length
[x
]= global_pairs
[x
].key_length
;
3307 return TEST_SUCCESS
;
3310 static test_return_t
generate_large_pairs(memcached_st
*)
3312 global_pairs
= pairs_generate(GLOBAL2_COUNT
, MEMCACHED_MAX_BUFFER
+10);
3313 global_count
= GLOBAL2_COUNT
;
3315 for (size_t x
= 0; x
< global_count
; x
++)
3317 global_keys
[x
]= global_pairs
[x
].key
;
3318 global_keys_length
[x
]= global_pairs
[x
].key_length
;
3321 return TEST_SUCCESS
;
3324 static test_return_t
generate_data(memcached_st
*memc
)
3326 unsigned int check_execute
= execute_set(memc
, global_pairs
, global_count
);
3328 test_true(check_execute
== global_count
);
3330 return TEST_SUCCESS
;
3333 static test_return_t
generate_data_with_stats(memcached_st
*memc
)
3335 uint32_t host_index
= 0;
3336 unsigned int check_execute
= execute_set(memc
, global_pairs
, global_count
);
3338 test_true(check_execute
== global_count
);
3340 // @todo hosts used size stats
3341 memcached_return_t rc
;
3342 memcached_stat_st
*stat_p
= memcached_stat(memc
, NULL
, &rc
);
3345 for (host_index
= 0; host_index
< SERVERS_TO_CREATE
; host_index
++)
3347 /* This test was changes so that "make test" would work properlly */
3349 memcached_server_instance_st instance
=
3350 memcached_server_instance_by_position(memc
, host_index
);
3352 printf("\nserver %u|%s|%u bytes: %llu\n", host_index
, instance
->hostname
, instance
->port
, (unsigned long long)(stat_p
+ host_index
)->bytes
);
3354 test_true((unsigned long long)(stat_p
+ host_index
)->bytes
);
3357 memcached_stat_free(NULL
, stat_p
);
3359 return TEST_SUCCESS
;
3361 static test_return_t
generate_buffer_data(memcached_st
*memc
)
3366 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
3367 generate_data(memc
);
3369 return TEST_SUCCESS
;
3372 static test_return_t
get_read_count(memcached_st
*memc
)
3374 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
3375 test_true(memc_clone
);
3377 memcached_server_add_with_weight(memc_clone
, "localhost", 6666, 0);
3381 size_t return_value_length
;
3385 for (size_t x
= count
= 0; x
< global_count
; x
++)
3387 memcached_return_t rc
;
3388 return_value
= memcached_get(memc_clone
, global_keys
[x
], global_keys_length
[x
],
3389 &return_value_length
, &flags
, &rc
);
3390 if (rc
== MEMCACHED_SUCCESS
)
3399 memcached_free(memc_clone
);
3401 return TEST_SUCCESS
;
3404 static test_return_t
get_read(memcached_st
*memc
)
3406 for (size_t x
= 0; x
< global_count
; x
++)
3408 size_t return_value_length
;
3410 memcached_return_t rc
;
3411 char *return_value
= memcached_get(memc
, global_keys
[x
], global_keys_length
[x
],
3412 &return_value_length
, &flags
, &rc
);
3414 test_true(return_value);
3415 test_compare(MEMCACHED_SUCCESS, rc);
3417 if (rc
== MEMCACHED_SUCCESS
&& return_value
)
3421 return TEST_SUCCESS
;
3424 static test_return_t
mget_read(memcached_st
*memc
)
3427 test_skip(true, bool(libmemcached_util_version_check(memc
, 1, 4, 4)));
3429 memcached_return_t rc
;
3430 test_compare_got(MEMCACHED_SUCCESS
,
3431 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
),
3432 memcached_strerror(NULL
, rc
));
3434 // Go fetch the keys and test to see if all of them were returned
3436 size_t keys_returned
;
3437 test_compare(TEST_SUCCESS
, fetch_all_results(memc
, keys_returned
, MEMCACHED_SUCCESS
));
3438 test_true(keys_returned
> 0);
3440 snprintf(buffer
, sizeof(buffer
), "%lu", (unsigned long)keys_returned
);
3441 test_compare_got(global_count
, keys_returned
, buffer
);
3444 return TEST_SUCCESS
;
3447 static test_return_t
mget_read_result(memcached_st
*memc
)
3450 test_skip(true, bool(libmemcached_util_version_check(memc
, 1, 4, 4)));
3452 test_compare(MEMCACHED_SUCCESS
,
3453 memcached_mget(memc
, global_keys
, global_keys_length
, global_count
));
3455 /* Turn this into a help function */
3457 memcached_result_st results_obj
;
3458 memcached_result_st
*results
= memcached_result_create(memc
, &results_obj
);
3460 memcached_return_t rc
;
3461 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
3464 test_compare(MEMCACHED_SUCCESS
, rc
);
3466 test_compare(MEMCACHED_END
, rc
);
3468 memcached_result_free(&results_obj
);
3471 return TEST_SUCCESS
;
3474 static test_return_t
mget_read_function(memcached_st
*memc
)
3476 test_skip(true, bool(libmemcached_util_version_check(memc
, 1, 4, 4)));
3478 test_compare(MEMCACHED_SUCCESS
,
3479 memcached_mget(memc
, global_keys
, global_keys_length
, global_count
));
3481 memcached_execute_fn callbacks
[]= { &callback_counter
};
3483 test_compare(MEMCACHED_SUCCESS
,
3484 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
3486 return TEST_SUCCESS
;
3489 static test_return_t
delete_generate(memcached_st
*memc
)
3491 for (size_t x
= 0; x
< global_count
; x
++)
3493 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3496 return TEST_SUCCESS
;
3499 static test_return_t
delete_buffer_generate(memcached_st
*memc
)
3502 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
3504 for (size_t x
= 0; x
< global_count
; x
++)
3506 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3509 return TEST_SUCCESS
;
3512 static test_return_t
add_host_test1(memcached_st
*memc
)
3514 memcached_return_t rc
;
3515 char servername
[]= "0.example.com";
3517 memcached_server_st
*servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
3519 test_compare(1, memcached_server_list_count(servers
));
3521 for (size_t x
= 2; x
< 20; x
++)
3523 char buffer
[SMALL_STRING_LEN
];
3525 snprintf(buffer
, SMALL_STRING_LEN
, "%lu.example.com", (unsigned long)(400 +x
));
3526 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
3528 test_compare(MEMCACHED_SUCCESS
, rc
);
3529 test_compare(x
, memcached_server_list_count(servers
));
3532 test_compare(MEMCACHED_SUCCESS
, memcached_server_push(memc
, servers
));
3533 test_compare(MEMCACHED_SUCCESS
, memcached_server_push(memc
, servers
));
3535 memcached_server_list_free(servers
);
3537 return TEST_SUCCESS
;
3540 static test_return_t
pre_nonblock(memcached_st
*memc
)
3542 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3544 return TEST_SUCCESS
;
3547 static test_return_t
pre_cork(memcached_st
*memc
)
3550 return TEST_SKIPPED
;
3553 if (memcached_success(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CORK
, set
)))
3554 return TEST_SUCCESS
;
3556 return TEST_SKIPPED
;
3559 static test_return_t
pre_cork_and_nonblock(memcached_st
*memc
)
3562 return TEST_SKIPPED
;
3564 test_return_t test_rc
;
3565 if ((test_rc
= pre_cork(memc
)) != TEST_SUCCESS
)
3568 return pre_nonblock(memc
);
3571 static test_return_t
pre_nonblock_binary(memcached_st
*memc
)
3573 memcached_return_t rc
= MEMCACHED_FAILURE
;
3574 memcached_st
*memc_clone
;
3576 memc_clone
= memcached_clone(NULL
, memc
);
3577 test_true(memc_clone
);
3578 // The memcached_version needs to be done on a clone, because the server
3579 // will not toggle protocol on an connection.
3580 memcached_version(memc_clone
);
3582 if (libmemcached_util_version_check(memc_clone
, 1, 4, 4))
3584 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3585 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3586 test_compare(MEMCACHED_SUCCESS
, rc
);
3587 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3591 return TEST_SKIPPED
;
3594 memcached_free(memc_clone
);
3596 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3599 static test_return_t
pre_murmur(memcached_st
*memc
)
3601 #ifdef HAVE_MURMUR_HASH
3602 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
3603 return TEST_SUCCESS
;
3606 return TEST_SKIPPED
;
3610 static test_return_t
pre_jenkins(memcached_st
*memc
)
3612 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_JENKINS
);
3614 return TEST_SUCCESS
;
3618 static test_return_t
pre_md5(memcached_st
*memc
)
3620 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MD5
);
3622 return TEST_SUCCESS
;
3625 static test_return_t
pre_crc(memcached_st
*memc
)
3627 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_CRC
);
3629 return TEST_SUCCESS
;
3632 static test_return_t
pre_hsieh(memcached_st
*memc
)
3634 #ifdef HAVE_HSIEH_HASH
3635 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_HSIEH
);
3636 return TEST_SUCCESS
;
3639 return TEST_SKIPPED
;
3643 static test_return_t
pre_hash_fnv1_64(memcached_st
*memc
)
3645 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
3647 return TEST_SUCCESS
;
3650 static test_return_t
pre_hash_fnv1a_64(memcached_st
*memc
)
3652 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_64
);
3654 return TEST_SUCCESS
;
3657 static test_return_t
pre_hash_fnv1_32(memcached_st
*memc
)
3659 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_32
);
3661 return TEST_SUCCESS
;
3664 static test_return_t
pre_hash_fnv1a_32(memcached_st
*memc
)
3666 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_32
);
3668 return TEST_SUCCESS
;
3671 static test_return_t
pre_behavior_ketama(memcached_st
*memc
)
3673 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA
, 1);
3674 test_compare(MEMCACHED_SUCCESS
, rc
);
3676 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA
);
3677 test_true(value
== 1);
3679 return TEST_SUCCESS
;
3682 static test_return_t
pre_behavior_ketama_weighted(memcached_st
*memc
)
3684 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
3685 test_compare(MEMCACHED_SUCCESS
, rc
);
3687 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
3688 test_true(value
== 1);
3690 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
3691 test_compare(MEMCACHED_SUCCESS
, rc
);
3693 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
3694 test_true(value
== MEMCACHED_HASH_MD5
);
3696 return TEST_SUCCESS
;
3700 @note This should be testing to see if the server really supports the binary protocol.
3702 static test_return_t
pre_binary(memcached_st
*memc
)
3704 memcached_return_t rc
= MEMCACHED_FAILURE
;
3706 if (libmemcached_util_version_check(memc
, 1, 4, 4))
3708 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3709 test_compare(MEMCACHED_SUCCESS
, rc
);
3710 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3713 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3716 static test_return_t
pre_sasl(memcached_st
*memc
)
3718 memcached_return_t rc
= MEMCACHED_FAILURE
;
3720 #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
3721 const char *server
= getenv("LIBMEMCACHED_TEST_SASL_SERVER");
3722 const char *user
= getenv("LIBMEMCACHED_TEST_SASL_USERNAME");
3723 const char *pass
= getenv("LIBMEMCACHED_TEST_SASL_PASSWORD");
3725 if (server
and user
and pass
)
3727 memcached_server_st
*servers
= memcached_servers_parse(server
);
3729 memcached_servers_reset(memc
);
3730 test_true(memcached_server_push(memc
, servers
) == MEMCACHED_SUCCESS
);
3731 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3732 rc
= memcached_set_sasl_auth_data(memc
, user
, pass
);
3733 test_compare(MEMCACHED_SUCCESS
, rc
);
3739 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3742 static test_return_t
pre_replication(memcached_st
*memc
)
3744 test_skip(TEST_SUCCESS
, pre_binary(memc
));
3747 * Make sure that we store the item on all servers
3748 * (master + replicas == number of servers)
3750 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
,
3751 memcached_server_count(memc
) - 1);
3752 test_compare(MEMCACHED_SUCCESS
, rc
);
3753 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
) == memcached_server_count(memc
) - 1);
3755 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3759 static test_return_t
pre_replication_noblock(memcached_st
*memc
)
3761 test_skip(TEST_SUCCESS
, pre_replication(memc
));
3763 return pre_nonblock(memc
);
3767 static void my_free(const memcached_st
*ptr
, void *mem
, void *context
)
3771 #ifdef HARD_MALLOC_TESTS
3772 void *real_ptr
= (mem
== NULL
) ? mem
: (void*)((caddr_t
)mem
- 8);
3780 static void *my_malloc(const memcached_st
*ptr
, const size_t size
, void *context
)
3784 #ifdef HARD_MALLOC_TESTS
3785 void *ret
= malloc(size
+ 8);
3788 ret
= (void*)((caddr_t
)ret
+ 8);
3791 void *ret
= malloc(size
);
3796 memset(ret
, 0xff, size
);
3803 static void *my_realloc(const memcached_st
*ptr
, void *mem
, const size_t size
, void *)
3805 #ifdef HARD_MALLOC_TESTS
3806 void *real_ptr
= (mem
== NULL
) ? NULL
: (void*)((caddr_t
)mem
- 8);
3807 void *nmem
= realloc(real_ptr
, size
+ 8);
3812 ret
= (void*)((caddr_t
)nmem
+ 8);
3818 return realloc(mem
, size
);
3823 static void *my_calloc(const memcached_st
*ptr
, size_t nelem
, const size_t size
, void *)
3825 #ifdef HARD_MALLOC_TESTS
3826 void *mem
= my_malloc(ptr
, nelem
* size
);
3829 memset(mem
, 0, nelem
* size
);
3835 return calloc(nelem
, size
);
3839 static test_return_t
set_prefix(memcached_st
*memc
)
3841 memcached_return_t rc
;
3842 const char *key
= "mine";
3845 /* Make sure be default none exists */
3846 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3847 test_true(rc
== MEMCACHED_FAILURE
);
3849 /* Test a clean set */
3850 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3851 test_true_got(rc
== MEMCACHED_SUCCESS
, memcached_last_error_message(memc
));
3853 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3855 test_memcmp(value
, key
, 4);
3856 test_compare(MEMCACHED_SUCCESS
, rc
);
3858 /* Test that we can turn it off */
3859 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3860 test_compare(MEMCACHED_SUCCESS
, rc
);
3862 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3864 test_true(rc
== MEMCACHED_FAILURE
);
3866 /* Now setup for main test */
3867 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3868 test_compare(MEMCACHED_SUCCESS
, rc
);
3870 value
= (char *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3872 test_compare(MEMCACHED_SUCCESS
, rc
);
3873 test_memcmp(value
, key
, 4);
3875 /* Set to Zero, and then Set to something too large */
3878 memset(long_key
, 0, 255);
3880 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3881 test_compare(MEMCACHED_SUCCESS
, rc
);
3883 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3885 test_true(rc
== MEMCACHED_FAILURE
);
3886 test_true(value
== NULL
);
3888 /* Test a long key for failure */
3889 /* TODO, extend test to determine based on setting, what result should be */
3890 strncpy(long_key
, "Thisismorethentheallottednumberofcharacters", sizeof(long_key
));
3891 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3892 //test_compare(MEMCACHED_BAD_KEY_PROVIDED, rc);
3893 test_compare(MEMCACHED_SUCCESS
, rc
);
3895 /* Now test a key with spaces (which will fail from long key, since bad key is not set) */
3896 strncpy(long_key
, "This is more then the allotted number of characters", sizeof(long_key
));
3897 test_compare(MEMCACHED_BAD_KEY_PROVIDED
,
3898 memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
));
3900 /* Test for a bad prefix, but with a short key */
3901 test_compare(MEMCACHED_SUCCESS
,
3902 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, 1));
3904 strncpy(long_key
, "dog cat", sizeof(long_key
));
3905 test_compare(MEMCACHED_BAD_KEY_PROVIDED
,
3906 memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
));
3909 return TEST_SUCCESS
;
3913 #ifdef MEMCACHED_ENABLE_DEPRECATED
3914 static test_return_t
deprecated_set_memory_alloc(memcached_st
*memc
)
3916 void *test_ptr
= NULL
;
3919 memcached_malloc_fn malloc_cb
=
3920 (memcached_malloc_fn
)my_malloc
;
3921 cb_ptr
= *(void **)&malloc_cb
;
3922 memcached_return_t rc
;
3924 test_compare(MEMCACHED_SUCCESS
,
3925 memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, cb_ptr
));
3926 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
3927 test_compare(MEMCACHED_SUCCESS
, rc
);
3928 test_true(test_ptr
== cb_ptr
);
3932 memcached_realloc_fn realloc_cb
=
3933 (memcached_realloc_fn
)my_realloc
;
3934 cb_ptr
= *(void **)&realloc_cb
;
3935 memcached_return_t rc
;
3937 test_compare(MEMCACHED_SUCCESS
,
3938 memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, cb_ptr
));
3939 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
3940 test_compare(MEMCACHED_SUCCESS
, rc
);
3941 test_true(test_ptr
== cb_ptr
);
3945 memcached_free_fn free_cb
=
3946 (memcached_free_fn
)my_free
;
3947 cb_ptr
= *(void **)&free_cb
;
3948 memcached_return_t rc
;
3950 test_compare(MEMCACHED_SUCCESS
,
3951 memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, cb_ptr
));
3952 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
3953 test_compare(MEMCACHED_SUCCESS
, rc
);
3954 test_true(test_ptr
== cb_ptr
);
3957 return TEST_SUCCESS
;
3962 static test_return_t
set_memory_alloc(memcached_st
*memc
)
3964 test_compare(MEMCACHED_FAILURE
,
3965 memcached_set_memory_allocators(memc
, NULL
, my_free
,
3966 my_realloc
, my_calloc
, NULL
));
3968 test_compare(MEMCACHED_SUCCESS
,
3969 memcached_set_memory_allocators(memc
, my_malloc
, my_free
,
3970 my_realloc
, my_calloc
, NULL
));
3972 memcached_malloc_fn mem_malloc
;
3973 memcached_free_fn mem_free
;
3974 memcached_realloc_fn mem_realloc
;
3975 memcached_calloc_fn mem_calloc
;
3976 memcached_get_memory_allocators(memc
, &mem_malloc
, &mem_free
,
3977 &mem_realloc
, &mem_calloc
);
3979 test_true(mem_malloc
== my_malloc
);
3980 test_true(mem_realloc
== my_realloc
);
3981 test_true(mem_calloc
== my_calloc
);
3982 test_true(mem_free
== my_free
);
3984 return TEST_SUCCESS
;
3987 static test_return_t
enable_consistent_crc(memcached_st
*memc
)
3990 memcached_server_distribution_t value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
3991 memcached_hash_t hash
;
3992 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
3993 if ((rc
= pre_crc(memc
)) != TEST_SUCCESS
)
3996 value
= (memcached_server_distribution_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
3997 test_true(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
3999 hash
= (memcached_hash_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
4001 if (hash
!= MEMCACHED_HASH_CRC
)
4002 return TEST_SKIPPED
;
4004 return TEST_SUCCESS
;
4007 static test_return_t
enable_consistent_hsieh(memcached_st
*memc
)
4010 memcached_server_distribution_t value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
4011 memcached_hash_t hash
;
4012 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
4013 if ((rc
= pre_hsieh(memc
)) != TEST_SUCCESS
)
4016 value
= (memcached_server_distribution_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
4017 test_true(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
4019 hash
= (memcached_hash_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
4021 if (hash
!= MEMCACHED_HASH_HSIEH
)
4022 return TEST_SKIPPED
;
4025 return TEST_SUCCESS
;
4028 static test_return_t
enable_cas(memcached_st
*memc
)
4030 unsigned int set
= 1;
4032 if (libmemcached_util_version_check(memc
, 1, 2, 4))
4034 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
4036 return TEST_SUCCESS
;
4039 return TEST_SKIPPED
;
4042 static test_return_t
check_for_1_2_3(memcached_st
*memc
)
4044 memcached_version(memc
);
4046 memcached_server_instance_st instance
=
4047 memcached_server_instance_by_position(memc
, 0);
4049 if ((instance
->major_version
>= 1 && (instance
->minor_version
== 2 && instance
->micro_version
>= 4))
4050 || instance
->minor_version
> 2)
4052 return TEST_SUCCESS
;
4055 return TEST_SKIPPED
;
4058 static test_return_t
pre_unix_socket(memcached_st
*memc
)
4060 memcached_return_t rc
;
4063 memcached_servers_reset(memc
);
4065 if (stat("/tmp/memcached.socket", &buf
))
4066 return TEST_SKIPPED
;
4068 rc
= memcached_server_add_unix_socket_with_weight(memc
, "/tmp/memcached.socket", 0);
4070 return ( rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_FAILURE
);
4073 static test_return_t
pre_nodelay(memcached_st
*memc
)
4075 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
4076 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
4078 return TEST_SUCCESS
;
4081 static test_return_t
pre_settimer(memcached_st
*memc
)
4083 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
4084 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
4086 return TEST_SUCCESS
;
4089 static test_return_t
poll_timeout(memcached_st
*memc
)
4091 size_t timeout
= 100; // Not using, just checking that it sets
4093 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
4095 timeout
= (size_t)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
4097 test_compare(100, timeout
);
4099 return TEST_SUCCESS
;
4102 static test_return_t
noreply_test(memcached_st
*memc
)
4104 memcached_return_t ret
;
4105 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
4106 test_true(ret
== MEMCACHED_SUCCESS
);
4107 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4108 test_true(ret
== MEMCACHED_SUCCESS
);
4109 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
4110 test_true(ret
== MEMCACHED_SUCCESS
);
4111 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NOREPLY
) == 1);
4112 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
) == 1);
4113 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
) == 1);
4115 for (int count
=0; count
< 5; ++count
)
4117 for (size_t x
= 0; x
< 100; ++x
)
4120 int check_length
= (size_t)snprintf(key
, sizeof(key
), "%lu", (unsigned long)x
);
4121 test_false((size_t)check_length
>= sizeof(key
) || check_length
< 0);
4123 size_t len
= (size_t)check_length
;
4128 ret
= memcached_add(memc
, key
, len
, key
, len
, 0, 0);
4131 ret
= memcached_replace(memc
, key
, len
, key
, len
, 0, 0);
4134 ret
= memcached_set(memc
, key
, len
, key
, len
, 0, 0);
4137 ret
= memcached_append(memc
, key
, len
, key
, len
, 0, 0);
4140 ret
= memcached_prepend(memc
, key
, len
, key
, len
, 0, 0);
4146 test_true(ret
== MEMCACHED_SUCCESS
|| ret
== MEMCACHED_BUFFERED
);
4150 ** NOTE: Don't ever do this in your code! this is not a supported use of the
4151 ** API and is _ONLY_ done this way to verify that the library works the
4152 ** way it is supposed to do!!!!
4155 for (uint32_t x
= 0; x
< memcached_server_count(memc
); ++x
)
4157 memcached_server_instance_st instance
=
4158 memcached_server_instance_by_position(memc
, x
);
4159 no_msg
+=(int)(instance
->cursor_active
);
4162 test_true(no_msg
== 0);
4163 test_true(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
4166 ** Now validate that all items was set properly!
4168 for (size_t x
= 0; x
< 100; ++x
)
4172 int check_length
= (size_t)snprintf(key
, sizeof(key
), "%lu", (unsigned long)x
);
4174 test_false((size_t)check_length
>= sizeof(key
) || check_length
< 0);
4176 size_t len
= (size_t)check_length
;
4179 char* value
=memcached_get(memc
, key
, strlen(key
),
4180 &length
, &flags
, &ret
);
4181 test_true(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
4184 case 0: /* FALLTHROUGH */
4185 case 1: /* FALLTHROUGH */
4187 test_true(strncmp(value
, key
, len
) == 0);
4188 test_true(len
== length
);
4191 test_true(length
== len
* 2);
4194 test_true(length
== len
* 3);
4204 /* Try setting an illegal cas value (should not return an error to
4205 * the caller (because we don't expect a return message from the server)
4207 const char* keys
[]= {"0"};
4208 size_t lengths
[]= {1};
4211 memcached_result_st results_obj
;
4212 memcached_result_st
*results
;
4213 ret
= memcached_mget(memc
, keys
, lengths
, 1);
4214 test_true(ret
== MEMCACHED_SUCCESS
);
4216 results
= memcached_result_create(memc
, &results_obj
);
4218 results
= memcached_fetch_result(memc
, &results_obj
, &ret
);
4220 test_true(ret
== MEMCACHED_SUCCESS
);
4221 uint64_t cas
= memcached_result_cas(results
);
4222 memcached_result_free(&results_obj
);
4224 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
4225 test_true(ret
== MEMCACHED_SUCCESS
);
4228 * The item will have a new cas value, so try to set it again with the old
4229 * value. This should fail!
4231 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
4232 test_true(ret
== MEMCACHED_SUCCESS
);
4233 test_true(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
4234 char* value
=memcached_get(memc
, keys
[0], lengths
[0], &length
, &flags
, &ret
);
4235 test_true(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
4238 return TEST_SUCCESS
;
4241 static test_return_t
analyzer_test(memcached_st
*memc
)
4243 memcached_return_t rc
;
4244 memcached_stat_st
*memc_stat
;
4245 memcached_analysis_st
*report
;
4247 memc_stat
= memcached_stat(memc
, NULL
, &rc
);
4248 test_compare(MEMCACHED_SUCCESS
, rc
);
4249 test_true(memc_stat
);
4251 report
= memcached_analyze(memc
, memc_stat
, &rc
);
4252 test_compare(MEMCACHED_SUCCESS
, rc
);
4256 memcached_stat_free(NULL
, memc_stat
);
4258 return TEST_SUCCESS
;
4261 /* Count the objects */
4262 static memcached_return_t
callback_dump_counter(const memcached_st
*ptr
,
4267 (void)ptr
; (void)key
; (void)key_length
;
4268 size_t *counter
= (size_t *)context
;
4270 *counter
= *counter
+ 1;
4272 return MEMCACHED_SUCCESS
;
4275 static test_return_t
dump_test(memcached_st
*memc
)
4278 memcached_dump_fn callbacks
[1];
4280 callbacks
[0]= &callback_dump_counter
;
4282 /* No support for Binary protocol yet */
4283 test_skip(false, memc
->flags
.binary_protocol
);
4285 test_compare(TEST_SUCCESS
, set_test3(memc
));
4287 test_compare(MEMCACHED_SUCCESS
,
4288 memcached_dump(memc
, callbacks
, (void *)&counter
, 1));
4290 /* We may have more then 32 if our previous flush has not completed */
4291 test_true(counter
>= 32);
4293 return TEST_SUCCESS
;
4296 #ifdef HAVE_LIBMEMCACHEDUTIL
4298 struct test_pool_context_st
{
4299 memcached_pool_st
* pool
;
4303 static void* connection_release(void *arg
)
4305 test_pool_context_st
*resource
= static_cast<test_pool_context_st
*>(arg
);
4308 // Release all of the memc we are holding
4309 assert(memcached_success(memcached_pool_push(resource
->pool
, resource
->mmc
)));
4313 #define POOL_SIZE 10
4314 static test_return_t
connection_pool_test(memcached_st
*memc
)
4316 memcached_pool_st
* pool
= memcached_pool_create(memc
, 5, POOL_SIZE
);
4317 test_true(pool
!= NULL
);
4318 memcached_st
*mmc
[POOL_SIZE
];
4319 memcached_return_t rc
;
4321 // Fill up our array that we will store the memc that are in the pool
4322 for (size_t x
= 0; x
< POOL_SIZE
; ++x
)
4324 mmc
[x
]= memcached_pool_pop(pool
, false, &rc
);
4325 test_true(mmc
[x
] != NULL
);
4326 test_compare(MEMCACHED_SUCCESS
, rc
);
4329 // All memc should be gone
4330 test_true(memcached_pool_pop(pool
, false, &rc
) == NULL
);
4331 test_compare(MEMCACHED_SUCCESS
, rc
);
4334 test_pool_context_st item
= { pool
, mmc
[9] };
4336 pthread_create(&tid
, NULL
, connection_release
, &item
);
4337 mmc
[9]= memcached_pool_pop(pool
, true, &rc
);
4338 test_compare(MEMCACHED_SUCCESS
, rc
);
4339 pthread_join(tid
, NULL
);
4341 const char *key
= "key";
4342 size_t keylen
= strlen(key
);
4344 // verify that I can do ops with all connections
4345 test_compare(MEMCACHED_SUCCESS
,
4346 memcached_set(mmc
[0], key
, keylen
, "0", 1, 0, 0));
4348 for (size_t x
= 0; x
< POOL_SIZE
; ++x
)
4350 uint64_t number_value
;
4351 test_compare(MEMCACHED_SUCCESS
,
4352 memcached_increment(mmc
[x
], key
, keylen
, 1, &number_value
));
4353 test_compare(number_value
, (x
+1));
4357 for (size_t x
= 0; x
< POOL_SIZE
; ++x
)
4359 test_compare(MEMCACHED_SUCCESS
, memcached_pool_push(pool
, mmc
[x
]));
4363 /* verify that I can set behaviors on the pool when I don't have all
4364 * of the connections in the pool. It should however be enabled
4365 * when I push the item into the pool
4367 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
4370 rc
= memcached_pool_behavior_set(pool
, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
, 9999);
4371 test_compare(MEMCACHED_SUCCESS
, rc
);
4373 mmc
[1]= memcached_pool_pop(pool
, false, &rc
);
4376 test_compare(9999, memcached_behavior_get(mmc
[1], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
));
4377 test_compare(MEMCACHED_SUCCESS
, memcached_pool_push(pool
, mmc
[1]));
4378 test_compare(MEMCACHED_SUCCESS
, memcached_pool_push(pool
, mmc
[0]));
4380 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
4381 test_compare(9999, memcached_behavior_get(mmc
[0], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
));
4382 test_compare(MEMCACHED_SUCCESS
, memcached_pool_push(pool
, mmc
[0]));
4384 test_true(memcached_pool_destroy(pool
) == memc
);
4386 return TEST_SUCCESS
;
4389 static test_return_t
util_version_test(memcached_st
*memc
)
4391 bool if_successful
= libmemcached_util_version_check(memc
, 0, 0, 0);
4392 test_true(if_successful
);
4394 if_successful
= libmemcached_util_version_check(memc
, 9, 9, 9);
4396 // We expect failure
4399 fprintf(stderr
, "\n----------------------------------------------------------------------\n");
4400 fprintf(stderr
, "\nDumping Server Information\n\n");
4401 memcached_server_fn callbacks
[1];
4403 callbacks
[0]= dump_server_information
;
4404 memcached_server_cursor(memc
, callbacks
, (void *)stderr
, 1);
4405 fprintf(stderr
, "\n----------------------------------------------------------------------\n");
4407 test_true(if_successful
== false);
4409 memcached_server_instance_st instance
=
4410 memcached_server_instance_by_position(memc
, 0);
4412 memcached_version(memc
);
4414 // We only use one binary when we test, so this should be just fine.
4415 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, instance
->minor_version
, instance
->micro_version
);
4416 test_true(if_successful
== true);
4418 if (instance
->micro_version
> 0)
4419 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, instance
->minor_version
, (uint8_t)(instance
->micro_version
-1));
4420 else if (instance
->minor_version
> 0)
4421 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, (uint8_t)(instance
->minor_version
- 1), instance
->micro_version
);
4422 else if (instance
->major_version
> 0)
4423 if_successful
= libmemcached_util_version_check(memc
, (uint8_t)(instance
->major_version
-1), instance
->minor_version
, instance
->micro_version
);
4425 test_true(if_successful
== true);
4427 if (instance
->micro_version
> 0)
4428 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, instance
->minor_version
, (uint8_t)(instance
->micro_version
+1));
4429 else if (instance
->minor_version
> 0)
4430 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, (uint8_t)(instance
->minor_version
+1), instance
->micro_version
);
4431 else if (instance
->major_version
> 0)
4432 if_successful
= libmemcached_util_version_check(memc
, (uint8_t)(instance
->major_version
+1), instance
->minor_version
, instance
->micro_version
);
4434 test_true(if_successful
== false);
4436 return TEST_SUCCESS
;
4439 static test_return_t
ping_test(memcached_st
*memc
)
4441 memcached_return_t rc
;
4442 memcached_server_instance_st instance
=
4443 memcached_server_instance_by_position(memc
, 0);
4445 // Test both the version that returns a code, and the one that does not.
4446 test_true(libmemcached_util_ping(memcached_server_name(instance
),
4447 memcached_server_port(instance
), NULL
));
4449 test_true(libmemcached_util_ping(memcached_server_name(instance
),
4450 memcached_server_port(instance
), &rc
));
4452 test_compare(MEMCACHED_SUCCESS
, rc
);
4454 return TEST_SUCCESS
;
4460 static test_return_t
hash_sanity_test (memcached_st
*memc
)
4464 assert(MEMCACHED_HASH_DEFAULT
== MEMCACHED_HASH_DEFAULT
);
4465 assert(MEMCACHED_HASH_MD5
== MEMCACHED_HASH_MD5
);
4466 assert(MEMCACHED_HASH_CRC
== MEMCACHED_HASH_CRC
);
4467 assert(MEMCACHED_HASH_FNV1_64
== MEMCACHED_HASH_FNV1_64
);
4468 assert(MEMCACHED_HASH_FNV1A_64
== MEMCACHED_HASH_FNV1A_64
);
4469 assert(MEMCACHED_HASH_FNV1_32
== MEMCACHED_HASH_FNV1_32
);
4470 assert(MEMCACHED_HASH_FNV1A_32
== MEMCACHED_HASH_FNV1A_32
);
4471 #ifdef HAVE_HSIEH_HASH
4472 assert(MEMCACHED_HASH_HSIEH
== MEMCACHED_HASH_HSIEH
);
4474 assert(MEMCACHED_HASH_MURMUR
== MEMCACHED_HASH_MURMUR
);
4475 assert(MEMCACHED_HASH_JENKINS
== MEMCACHED_HASH_JENKINS
);
4476 assert(MEMCACHED_HASH_MAX
== MEMCACHED_HASH_MAX
);
4478 return TEST_SUCCESS
;
4482 static test_return_t
hsieh_avaibility_test (memcached_st
*memc
)
4484 memcached_return_t expected_rc
= MEMCACHED_INVALID_ARGUMENTS
;
4485 #ifdef HAVE_HSIEH_HASH
4486 expected_rc
= MEMCACHED_SUCCESS
;
4488 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
,
4489 (uint64_t)MEMCACHED_HASH_HSIEH
);
4490 test_true(rc
== expected_rc
);
4492 return TEST_SUCCESS
;
4495 static test_return_t
murmur_avaibility_test (memcached_st
*memc
)
4497 memcached_return_t expected_rc
= MEMCACHED_INVALID_ARGUMENTS
;
4498 #ifdef HAVE_MURMUR_HASH
4499 expected_rc
= MEMCACHED_SUCCESS
;
4501 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
,
4502 (uint64_t)MEMCACHED_HASH_MURMUR
);
4503 test_true(rc
== expected_rc
);
4505 return TEST_SUCCESS
;
4508 static test_return_t
one_at_a_time_run (memcached_st
*memc
)
4514 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4518 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_DEFAULT
);
4519 test_true(one_at_a_time_values
[x
] == hash_val
);
4522 return TEST_SUCCESS
;
4525 static test_return_t
md5_run (memcached_st
*memc
)
4531 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4535 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MD5
);
4536 test_true(md5_values
[x
] == hash_val
);
4539 return TEST_SUCCESS
;
4542 static test_return_t
crc_run (memcached_st
*memc
)
4548 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4552 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_CRC
);
4553 test_true(crc_values
[x
] == hash_val
);
4556 return TEST_SUCCESS
;
4559 static test_return_t
fnv1_64_run (memcached_st
*memc
)
4565 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4569 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_64
);
4570 test_true(fnv1_64_values
[x
] == hash_val
);
4573 return TEST_SUCCESS
;
4576 static test_return_t
fnv1a_64_run (memcached_st
*memc
)
4582 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4586 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_64
);
4587 test_true(fnv1a_64_values
[x
] == hash_val
);
4590 return TEST_SUCCESS
;
4593 static test_return_t
fnv1_32_run (memcached_st
*memc
)
4599 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4603 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_32
);
4604 test_true(fnv1_32_values
[x
] == hash_val
);
4607 return TEST_SUCCESS
;
4610 static test_return_t
fnv1a_32_run (memcached_st
*memc
)
4616 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4620 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_32
);
4621 test_true(fnv1a_32_values
[x
] == hash_val
);
4624 return TEST_SUCCESS
;
4627 static test_return_t
hsieh_run (memcached_st
*memc
)
4633 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4637 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_HSIEH
);
4638 test_true(hsieh_values
[x
] == hash_val
);
4641 return TEST_SUCCESS
;
4644 static test_return_t
murmur_run (memcached_st
*memc
)
4646 #ifdef WORDS_BIGENDIAN
4647 (void)murmur_values
;
4648 return TEST_SKIPPED
;
4654 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4658 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MURMUR
);
4659 test_true(murmur_values
[x
] == hash_val
);
4662 return TEST_SUCCESS
;
4666 static test_return_t
jenkins_run (memcached_st
*memc
)
4672 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4676 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_JENKINS
);
4677 test_true(jenkins_values
[x
] == hash_val
);
4680 return TEST_SUCCESS
;
4683 static uint32_t hash_md5_test_function(const char *string
, size_t string_length
, void *context
)
4686 return libhashkit_md5(string
, string_length
);
4689 static uint32_t hash_crc_test_function(const char *string
, size_t string_length
, void *context
)
4692 return libhashkit_crc32(string
, string_length
);
4695 static test_return_t
memcached_get_hashkit_test (memcached_st
*memc
)
4699 const hashkit_st
*kit
;
4701 hashkit_return_t hash_rc
;
4703 uint32_t md5_hosts
[]= {4U, 1U, 0U, 1U, 4U, 2U, 0U, 3U, 0U, 0U, 3U, 1U, 0U, 0U, 1U, 3U, 0U, 0U, 0U, 3U, 1U, 0U, 4U, 4U, 3U};
4704 uint32_t crc_hosts
[]= {2U, 4U, 1U, 0U, 2U, 4U, 4U, 4U, 1U, 2U, 3U, 4U, 3U, 4U, 1U, 3U, 3U, 2U, 0U, 0U, 0U, 1U, 2U, 4U, 0U};
4706 kit
= memcached_get_hashkit(memc
);
4708 hashkit_clone(&new_kit
, kit
);
4709 hash_rc
= hashkit_set_custom_function(&new_kit
, hash_md5_test_function
, NULL
);
4710 test_true(hash_rc
== HASHKIT_SUCCESS
);
4712 memcached_set_hashkit(memc
, &new_kit
);
4715 Verify Setting the hash.
4717 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4721 hash_val
= hashkit_digest(kit
, *ptr
, strlen(*ptr
));
4722 test_true(md5_values
[x
] == hash_val
);
4727 Now check memcached_st.
4729 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4733 hash_val
= memcached_generate_hash(memc
, *ptr
, strlen(*ptr
));
4734 test_true(md5_hosts
[x
] == hash_val
);
4737 hash_rc
= hashkit_set_custom_function(&new_kit
, hash_crc_test_function
, NULL
);
4738 test_true(hash_rc
== HASHKIT_SUCCESS
);
4740 memcached_set_hashkit(memc
, &new_kit
);
4743 Verify Setting the hash.
4745 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4749 hash_val
= hashkit_digest(kit
, *ptr
, strlen(*ptr
));
4750 test_true(crc_values
[x
] == hash_val
);
4753 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4757 hash_val
= memcached_generate_hash(memc
, *ptr
, strlen(*ptr
));
4758 test_true(crc_hosts
[x
] == hash_val
);
4761 return TEST_SUCCESS
;
4765 Test case adapted from John Gorman <johngorman2@gmail.com>
4767 We are testing the error condition when we connect to a server via memcached_get()
4768 but find that the server is not available.
4770 static test_return_t
memcached_get_MEMCACHED_ERRNO(memcached_st
*memc
)
4773 memcached_st
*tl_memc_h
;
4775 const char *key
= "MemcachedLives";
4778 memcached_return rc
;
4782 tl_memc_h
= memcached_create(NULL
);
4783 memcached_server_st
*servers
= memcached_servers_parse("localhost:9898,localhost:9899"); // This server should not exist
4785 memcached_server_push(tl_memc_h
, servers
);
4786 memcached_server_list_free(servers
);
4788 // See if memcached is reachable.
4789 value
= memcached_get(tl_memc_h
, key
, strlen(key
), &len
, &flags
, &rc
);
4792 test_compare(0, len
);
4793 test_true(memcached_failed(rc
));
4795 memcached_free(tl_memc_h
);
4797 return TEST_SUCCESS
;
4801 We connect to a server which exists, but search for a key that does not exist.
4803 static test_return_t
memcached_get_MEMCACHED_NOTFOUND(memcached_st
*memc
)
4805 const char *key
= "MemcachedKeyNotEXIST";
4808 memcached_return rc
;
4811 // See if memcached is reachable.
4812 value
= memcached_get(memc
, key
, strlen(key
), &len
, &flags
, &rc
);
4815 test_compare(0, len
);
4816 test_compare(MEMCACHED_NOTFOUND
, rc
);
4818 return TEST_SUCCESS
;
4822 Test case adapted from John Gorman <johngorman2@gmail.com>
4824 We are testing the error condition when we connect to a server via memcached_get_by_key()
4825 but find that the server is not available.
4827 static test_return_t
memcached_get_by_key_MEMCACHED_ERRNO(memcached_st
*memc
)
4830 memcached_st
*tl_memc_h
;
4831 memcached_server_st
*servers
;
4833 const char *key
= "MemcachedLives";
4836 memcached_return rc
;
4840 tl_memc_h
= memcached_create(NULL
);
4841 servers
= memcached_servers_parse("localhost:9898,localhost:9899"); // This server should not exist
4842 memcached_server_push(tl_memc_h
, servers
);
4843 memcached_server_list_free(servers
);
4845 // See if memcached is reachable.
4846 value
= memcached_get_by_key(tl_memc_h
, key
, strlen(key
), key
, strlen(key
), &len
, &flags
, &rc
);
4849 test_compare(0, len
);
4850 test_true(memcached_failed(rc
));
4852 memcached_free(tl_memc_h
);
4854 return TEST_SUCCESS
;
4858 We connect to a server which exists, but search for a key that does not exist.
4860 static test_return_t
memcached_get_by_key_MEMCACHED_NOTFOUND(memcached_st
*memc
)
4862 const char *key
= "MemcachedKeyNotEXIST";
4865 memcached_return rc
;
4868 // See if memcached is reachable.
4869 value
= memcached_get_by_key(memc
, key
, strlen(key
), key
, strlen(key
), &len
, &flags
, &rc
);
4872 test_compare(0, len
);
4873 test_compare(MEMCACHED_NOTFOUND
, rc
);
4875 return TEST_SUCCESS
;
4879 static test_return_t
ketama_compatibility_libmemcached(memcached_st
*)
4881 memcached_st
*memc
= memcached_create(NULL
);
4884 test_compare(MEMCACHED_SUCCESS
,
4885 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1));
4888 test_compare(1, value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
));
4890 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
));
4891 test_compare(MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
, memcached_behavior_get_distribution(memc
));
4894 memcached_server_st
*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");
4895 memcached_server_push(memc
, server_pool
);
4897 /* verify that the server list was parsed okay. */
4898 test_compare(8, memcached_server_count(memc
));
4899 test_strcmp(server_pool
[0].hostname
, "10.0.1.1");
4900 test_compare(11211, server_pool
[0].port
);
4901 test_compare(600, server_pool
[0].weight
);
4902 test_strcmp(server_pool
[2].hostname
, "10.0.1.3");
4903 test_compare(11211, server_pool
[2].port
);
4904 test_compare(200, server_pool
[2].weight
);
4905 test_strcmp(server_pool
[7].hostname
, "10.0.1.8");
4906 test_compare(11211, server_pool
[7].port
);
4907 test_compare(100, server_pool
[7].weight
);
4909 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
4910 * us test the boundary wraparound.
4912 test_true(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->ketama
.continuum
[0].index
);
4914 /* verify the standard ketama set. */
4915 for (uint32_t x
= 0; x
< 99; x
++)
4917 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
4918 memcached_server_instance_st instance
=
4919 memcached_server_instance_by_position(memc
, server_idx
);
4920 const char *hostname
= memcached_server_name(instance
);
4922 test_strcmp(hostname
, ketama_test_cases
[x
].server
);
4925 memcached_server_list_free(server_pool
);
4926 memcached_free(memc
);
4928 return TEST_SUCCESS
;
4931 static test_return_t
ketama_compatibility_spymemcached(memcached_st
*)
4935 memcached_st
*memc
= memcached_create(NULL
);
4938 test_compare(MEMCACHED_SUCCESS
,
4939 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1));
4941 test_compare(1, value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
));
4943 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
));
4944 test_compare(MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
, memcached_behavior_get_distribution(memc
));
4946 memcached_server_st
*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");
4947 test_true(server_pool
);
4948 memcached_server_push(memc
, server_pool
);
4950 /* verify that the server list was parsed okay. */
4951 test_compare(8, memcached_server_count(memc
));
4952 test_strcmp(server_pool
[0].hostname
, "10.0.1.1");
4953 test_compare(11211, server_pool
[0].port
);
4954 test_compare(600, server_pool
[0].weight
);
4955 test_strcmp(server_pool
[2].hostname
, "10.0.1.3");
4956 test_compare(11211, server_pool
[2].port
);
4957 test_compare(200, server_pool
[2].weight
);
4958 test_strcmp(server_pool
[7].hostname
, "10.0.1.8");
4959 test_compare(11211, server_pool
[7].port
);
4960 test_compare(100, server_pool
[7].weight
);
4962 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
4963 * us test the boundary wraparound.
4965 test_true(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->ketama
.continuum
[0].index
);
4967 /* verify the standard ketama set. */
4968 for (uint32_t x
= 0; x
< 99; x
++)
4970 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases_spy
[x
].key
, strlen(ketama_test_cases_spy
[x
].key
));
4972 memcached_server_instance_st instance
=
4973 memcached_server_instance_by_position(memc
, server_idx
);
4975 const char *hostname
= memcached_server_name(instance
);
4977 test_strcmp(hostname
, ketama_test_cases_spy
[x
].server
);
4980 memcached_server_list_free(server_pool
);
4981 memcached_free(memc
);
4983 return TEST_SUCCESS
;
4986 static test_return_t
regression_bug_434484(memcached_st
*memc
)
4988 test_return_t test_rc
;
4989 test_rc
= pre_binary(memc
);
4991 if (test_rc
!= TEST_SUCCESS
)
4994 const char *key
= "regression_bug_434484";
4995 size_t keylen
= strlen(key
);
4997 memcached_return_t ret
= memcached_append(memc
, key
, keylen
, key
, keylen
, 0, 0);
4998 test_compare(MEMCACHED_NOTSTORED
, ret
);
5000 size_t size
= 2048 * 1024;
5001 char *data
= (char*)calloc(1, size
);
5003 test_compare(MEMCACHED_E2BIG
,
5004 memcached_set(memc
, key
, keylen
, data
, size
, 0, 0));
5007 return TEST_SUCCESS
;
5010 static test_return_t
regression_bug_434843(memcached_st
*memc
)
5012 test_return_t test_rc
;
5013 test_rc
= pre_binary(memc
);
5015 if (test_rc
!= TEST_SUCCESS
)
5018 memcached_return_t rc
;
5020 memcached_execute_fn callbacks
[]= { &callback_counter
};
5023 * I only want to hit only _one_ server so I know the number of requests I'm
5024 * sending in the pipleine to the server. Let's try to do a multiget of
5025 * 1024 (that should satisfy most users don't you think?). Future versions
5026 * will include a mget_execute function call if you need a higher number.
5028 uint32_t number_of_hosts
= memcached_server_count(memc
);
5029 memc
->number_of_hosts
= 1;
5030 const size_t max_keys
= 1024;
5031 char **keys
= (char**)calloc(max_keys
, sizeof(char*));
5032 size_t *key_length
= (size_t *)calloc(max_keys
, sizeof(size_t));
5034 for (size_t x
= 0; x
< max_keys
; ++x
)
5038 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%lu", (unsigned long)x
);
5044 * Run two times.. the first time we should have 100% cache miss,
5045 * and the second time we should have 100% cache hits
5047 for (size_t y
= 0; y
< 2; y
++)
5049 test_compare(MEMCACHED_SUCCESS
,
5050 memcached_mget(memc
, (const char**)keys
, key_length
, max_keys
));
5052 test_compare(y
? MEMCACHED_SUCCESS
: MEMCACHED_NOTFOUND
,
5053 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
5057 /* The first iteration should give me a 100% cache miss. verify that*/
5058 char blob
[1024]= { 0 };
5060 test_false(counter
);
5062 for (size_t x
= 0; x
< max_keys
; ++x
)
5064 rc
= memcached_add(memc
, keys
[x
], key_length
[x
],
5065 blob
, sizeof(blob
), 0, 0);
5066 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5071 /* Verify that we received all of the key/value pairs */
5072 test_compare(counter
, max_keys
);
5076 /* Release allocated resources */
5077 for (size_t x
= 0; x
< max_keys
; ++x
)
5084 memc
->number_of_hosts
= number_of_hosts
;
5086 return TEST_SUCCESS
;
5089 static test_return_t
regression_bug_434843_buffered(memcached_st
*memc
)
5091 memcached_return_t rc
;
5092 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
5093 test_compare(MEMCACHED_SUCCESS
, rc
);
5095 return regression_bug_434843(memc
);
5098 static test_return_t
regression_bug_421108(memcached_st
*memc
)
5100 memcached_return_t rc
;
5101 memcached_stat_st
*memc_stat
= memcached_stat(memc
, NULL
, &rc
);
5102 test_compare(MEMCACHED_SUCCESS
, rc
);
5104 char *bytes_str
= memcached_stat_get_value(memc
, memc_stat
, "bytes", &rc
);
5105 test_compare(MEMCACHED_SUCCESS
, rc
);
5106 test_true(bytes_str
);
5107 char *bytes_read_str
= memcached_stat_get_value(memc
, memc_stat
,
5109 test_compare(MEMCACHED_SUCCESS
, rc
);
5110 test_true(bytes_read_str
);
5112 char *bytes_written_str
= memcached_stat_get_value(memc
, memc_stat
,
5113 "bytes_written", &rc
);
5114 test_compare(MEMCACHED_SUCCESS
, rc
);
5115 test_true(bytes_written_str
);
5117 unsigned long long bytes
= strtoull(bytes_str
, 0, 10);
5118 unsigned long long bytes_read
= strtoull(bytes_read_str
, 0, 10);
5119 unsigned long long bytes_written
= strtoull(bytes_written_str
, 0, 10);
5121 test_true(bytes
!= bytes_read
);
5122 test_true(bytes
!= bytes_written
);
5124 /* Release allocated resources */
5126 free(bytes_read_str
);
5127 free(bytes_written_str
);
5128 memcached_stat_free(NULL
, memc_stat
);
5130 return TEST_SUCCESS
;
5134 * The test case isn't obvious so I should probably document why
5135 * it works the way it does. Bug 442914 was caused by a bug
5136 * in the logic in memcached_purge (it did not handle the case
5137 * where the number of bytes sent was equal to the watermark).
5138 * In this test case, create messages so that we hit that case
5139 * and then disable noreply mode and issue a new command to
5140 * verify that it isn't stuck. If we change the format for the
5141 * delete command or the watermarks, we need to update this
5144 static test_return_t
regression_bug_442914(memcached_st
*memc
)
5146 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1));
5147 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1);
5149 uint32_t number_of_hosts
= memcached_server_count(memc
);
5150 memc
->number_of_hosts
= 1;
5155 for (uint32_t x
= 0; x
< 250; ++x
)
5157 len
= (size_t)snprintf(k
, sizeof(k
), "%0250u", x
);
5158 memcached_return_t rc
= memcached_delete(memc
, k
, len
, 0);
5159 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5162 (void)snprintf(k
, sizeof(k
), "%037u", 251U);
5165 memcached_return_t rc
= memcached_delete(memc
, k
, len
, 0);
5166 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5168 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0));
5169 test_compare(MEMCACHED_NOTFOUND
, memcached_delete(memc
, k
, len
, 0));
5171 memc
->number_of_hosts
= number_of_hosts
;
5173 return TEST_SUCCESS
;
5176 static test_return_t
regression_bug_447342(memcached_st
*memc
)
5178 memcached_server_instance_st instance_one
;
5179 memcached_server_instance_st instance_two
;
5181 if (memcached_server_count(memc
) < 3 or pre_replication(memc
) != TEST_SUCCESS
)
5182 return TEST_SKIPPED
;
5184 test_compare(MEMCACHED_SUCCESS
,
5185 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 2));
5187 const size_t max_keys
= 100;
5188 char **keys
= (char**)calloc(max_keys
, sizeof(char*));
5189 size_t *key_length
= (size_t *)calloc(max_keys
, sizeof(size_t));
5191 for (size_t x
= 0; x
< max_keys
; ++x
)
5195 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%lu", (unsigned long)x
);
5198 test_compare(MEMCACHED_SUCCESS
,
5199 memcached_set(memc
, k
, key_length
[x
], k
, key_length
[x
], 0, 0));
5203 ** We are using the quiet commands to store the replicas, so we need
5204 ** to ensure that all of them are processed before we can continue.
5205 ** In the test we go directly from storing the object to trying to
5206 ** receive the object from all of the different servers, so we
5207 ** could end up in a race condition (the memcached server hasn't yet
5208 ** processed the quiet command from the replication set when it process
5209 ** the request from the other client (created by the clone)). As a
5210 ** workaround for that we call memcached_quit to send the quit command
5211 ** to the server and wait for the response ;-) If you use the test code
5212 ** as an example for your own code, please note that you shouldn't need
5215 memcached_quit(memc
);
5217 /* Verify that all messages are stored, and we didn't stuff too much
5220 test_compare(MEMCACHED_SUCCESS
,
5221 memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
));
5224 memcached_execute_fn callbacks
[]= { &callback_counter
};
5225 memcached_return_t rc
;
5226 test_compare_got(MEMCACHED_SUCCESS
,
5227 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1),
5228 memcached_strerror(NULL
, rc
));
5230 /* Verify that we received all of the key/value pairs */
5231 test_compare(counter
, max_keys
);
5233 memcached_quit(memc
);
5235 * Don't do the following in your code. I am abusing the internal details
5236 * within the library, and this is not a supported interface.
5237 * This is to verify correct behavior in the library. Fake that two servers
5240 instance_one
= memcached_server_instance_by_position(memc
, 0);
5241 instance_two
= memcached_server_instance_by_position(memc
, 2);
5242 in_port_t port0
= instance_one
->port
;
5243 in_port_t port2
= instance_two
->port
;
5245 ((memcached_server_write_instance_st
)instance_one
)->port
= 0;
5246 ((memcached_server_write_instance_st
)instance_two
)->port
= 0;
5248 test_compare(MEMCACHED_SUCCESS
,
5249 memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
));
5252 test_compare(MEMCACHED_SUCCESS
,
5253 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
5254 test_compare(counter
, (unsigned int)max_keys
);
5256 /* restore the memc handle */
5257 ((memcached_server_write_instance_st
)instance_one
)->port
= port0
;
5258 ((memcached_server_write_instance_st
)instance_two
)->port
= port2
;
5260 memcached_quit(memc
);
5262 /* Remove half of the objects */
5263 for (size_t x
= 0; x
< max_keys
; ++x
)
5267 test_compare(MEMCACHED_SUCCESS
,
5268 memcached_delete(memc
, keys
[x
], key_length
[x
], 0));
5272 memcached_quit(memc
);
5273 ((memcached_server_write_instance_st
)instance_one
)->port
= 0;
5274 ((memcached_server_write_instance_st
)instance_two
)->port
= 0;
5276 /* now retry the command, this time we should have cache misses */
5277 test_compare(MEMCACHED_SUCCESS
,
5278 memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
));
5281 test_compare_got(MEMCACHED_SUCCESS
,
5282 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1),
5283 memcached_strerror(NULL
, rc
));
5284 test_compare(counter
, (unsigned int)(max_keys
>> 1));
5286 /* Release allocated resources */
5287 for (size_t x
= 0; x
< max_keys
; ++x
)
5294 /* restore the memc handle */
5295 ((memcached_server_write_instance_st
)instance_one
)->port
= port0
;
5296 ((memcached_server_write_instance_st
)instance_two
)->port
= port2
;
5298 return TEST_SUCCESS
;
5301 static test_return_t
regression_bug_463297(memcached_st
*memc
)
5303 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
5304 test_true(memc_clone
);
5305 test_true(memcached_version(memc_clone
) == MEMCACHED_SUCCESS
);
5307 memcached_server_instance_st instance
=
5308 memcached_server_instance_by_position(memc_clone
, 0);
5310 if (instance
->major_version
> 1 ||
5311 (instance
->major_version
== 1 &&
5312 instance
->minor_version
> 2))
5314 /* Binary protocol doesn't support deferred delete */
5315 memcached_st
*bin_clone
= memcached_clone(NULL
, memc
);
5316 test_true(bin_clone
);
5317 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(bin_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1));
5318 test_compare(MEMCACHED_INVALID_ARGUMENTS
, memcached_delete(bin_clone
, "foo", 3, 1));
5319 memcached_free(bin_clone
);
5321 memcached_quit(memc_clone
);
5323 /* If we know the server version, deferred delete should fail
5324 * with invalid arguments */
5325 test_compare(MEMCACHED_INVALID_ARGUMENTS
, memcached_delete(memc_clone
, "foo", 3, 1));
5327 /* If we don't know the server version, we should get a protocol error */
5328 memcached_return_t rc
= memcached_delete(memc
, "foo", 3, 1);
5330 /* but there is a bug in some of the memcached servers (1.4) that treats
5331 * the counter as noreply so it doesn't send the proper error message
5333 test_true_got(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
|| rc
== MEMCACHED_INVALID_ARGUMENTS
, memcached_strerror(NULL
, rc
));
5335 /* And buffered mode should be disabled and we should get protocol error */
5336 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1) == MEMCACHED_SUCCESS
);
5337 rc
= memcached_delete(memc
, "foo", 3, 1);
5338 test_true_got(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
|| rc
== MEMCACHED_INVALID_ARGUMENTS
, memcached_strerror(NULL
, rc
));
5340 /* Same goes for noreply... */
5341 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1));
5342 rc
= memcached_delete(memc
, "foo", 3, 1);
5343 test_true_got(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
|| rc
== MEMCACHED_INVALID_ARGUMENTS
, memcached_strerror(NULL
, rc
));
5345 /* but a normal request should go through (and be buffered) */
5346 test_compare(MEMCACHED_BUFFERED
, (rc
= memcached_delete(memc
, "foo", 3, 0)));
5347 test_compare(MEMCACHED_SUCCESS
, memcached_flush_buffers(memc
));
5349 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 0));
5350 /* unbuffered noreply should be success */
5351 test_compare(MEMCACHED_SUCCESS
, memcached_delete(memc
, "foo", 3, 0));
5352 /* unbuffered with reply should be not found... */
5353 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0));
5354 test_compare(MEMCACHED_NOTFOUND
, memcached_delete(memc
, "foo", 3, 0));
5357 memcached_free(memc_clone
);
5358 return TEST_SUCCESS
;
5362 /* Test memcached_server_get_last_disconnect
5363 * For a working server set, shall be NULL
5364 * For a set of non existing server, shall not be NULL
5366 static test_return_t
test_get_last_disconnect(memcached_st
*memc
)
5368 memcached_return_t rc
;
5369 memcached_server_instance_st disconnected_server
;
5371 /* With the working set of server */
5372 const char *key
= "marmotte";
5373 const char *value
= "milka";
5375 memcached_reset_last_disconnected_server(memc
);
5376 test_false(memc
->last_disconnected_server
);
5377 rc
= memcached_set(memc
, key
, strlen(key
),
5378 value
, strlen(value
),
5379 (time_t)0, (uint32_t)0);
5380 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5382 disconnected_server
= memcached_server_get_last_disconnect(memc
);
5383 test_false(disconnected_server
);
5385 /* With a non existing server */
5387 memcached_server_st
*servers
;
5389 const char *server_list
= "localhost:9";
5391 servers
= memcached_servers_parse(server_list
);
5393 mine
= memcached_create(NULL
);
5394 rc
= memcached_server_push(mine
, servers
);
5395 test_compare(MEMCACHED_SUCCESS
, rc
);
5396 memcached_server_list_free(servers
);
5399 rc
= memcached_set(mine
, key
, strlen(key
),
5400 value
, strlen(value
),
5401 (time_t)0, (uint32_t)0);
5402 test_true(memcached_failed(rc
));
5404 disconnected_server
= memcached_server_get_last_disconnect(mine
);
5405 test_true_got(disconnected_server
, memcached_strerror(mine
, rc
));
5406 test_compare(9, memcached_server_port(disconnected_server
));
5407 test_false(strncmp(memcached_server_name(disconnected_server
),"localhost",9));
5409 memcached_quit(mine
);
5410 memcached_free(mine
);
5412 return TEST_SUCCESS
;
5415 static test_return_t
test_multiple_get_last_disconnect(memcached_st
*)
5417 const char *server_string
= "--server=localhost:8888 --server=localhost:8889 --server=localhost:8890 --server=localhost:8891 --server=localhost:8892";
5418 char buffer
[BUFSIZ
];
5420 memcached_return_t rc
;
5421 test_compare_got(MEMCACHED_SUCCESS
,
5422 rc
= libmemcached_check_configuration(server_string
, strlen(server_string
), buffer
, sizeof(buffer
)),
5423 memcached_strerror(NULL
, rc
));
5425 memcached_st
*memc
= memcached(server_string
, strlen(server_string
));
5428 // We will just use the error strings as our keys
5429 uint32_t counter
= 100;
5432 for (int x
= int(MEMCACHED_SUCCESS
); x
< int(MEMCACHED_MAXIMUM_RETURN
); ++x
)
5434 const char *msg
= memcached_strerror(memc
, memcached_return_t(x
));
5435 memcached_return_t ret
= memcached_set(memc
, msg
, strlen(msg
), NULL
, 0, (time_t)0, (uint32_t)0);
5436 test_compare_got(MEMCACHED_CONNECTION_FAILURE
, ret
, memcached_last_error_message(memc
));
5438 memcached_server_instance_st disconnected_server
= memcached_server_get_last_disconnect(memc
);
5439 test_true(disconnected_server
);
5440 test_strcmp("localhost", memcached_server_name(disconnected_server
));
5441 test_true(memcached_server_port(disconnected_server
) >= 8888 and memcached_server_port(disconnected_server
) <= 8892);
5445 memcached_reset_last_disconnected_server(memc
);
5450 memcached_free(memc
);
5452 return TEST_SUCCESS
;
5455 static test_return_t
test_verbosity(memcached_st
*memc
)
5457 memcached_verbosity(memc
, 3);
5459 return TEST_SUCCESS
;
5462 static test_return_t
test_server_failure(memcached_st
*memc
)
5464 memcached_server_instance_st instance
= memcached_server_instance_by_position(memc
, 0);
5466 memcached_st
*local_memc
= memcached_create(NULL
);
5468 memcached_server_add(local_memc
, memcached_server_name(instance
), memcached_server_port(instance
));
5469 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, 2);
5471 uint32_t server_count
= memcached_server_count(local_memc
);
5472 test_compare(1, server_count
);
5474 // Disable the server
5475 instance
= memcached_server_instance_by_position(local_memc
, 0);
5476 ((memcached_server_write_instance_st
)instance
)->server_failure_counter
= 2;
5478 memcached_return_t rc
;
5479 test_compare_got(MEMCACHED_SERVER_MARKED_DEAD
,
5480 rc
= memcached_set(local_memc
, "foo", strlen("foo"), NULL
, 0, (time_t)0, (uint32_t)0),
5481 memcached_last_error_message(local_memc
));
5483 ((memcached_server_write_instance_st
)instance
)->server_failure_counter
= 0;
5484 test_compare_got(MEMCACHED_SUCCESS
,
5485 rc
= memcached_set(local_memc
, "foo", strlen("foo"), NULL
, 0, (time_t)0, (uint32_t)0),
5486 memcached_strerror(NULL
, rc
));
5488 memcached_last_error_message(local_memc
));
5492 memcached_free(local_memc
);
5494 return TEST_SUCCESS
;
5497 static test_return_t
test_cull_servers(memcached_st
*memc
)
5499 uint32_t count
= memcached_server_count(memc
);
5501 // Do not do this in your code, it is not supported.
5502 memc
->servers
[1].options
.is_dead
= true;
5503 memc
->state
.is_time_for_rebuild
= true;
5505 uint32_t new_count
= memcached_server_count(memc
);
5506 test_compare(count
, new_count
);
5509 test_true(count
== new_count
+ 1 );
5512 return TEST_SUCCESS
;
5516 static memcached_return_t
stat_printer(memcached_server_instance_st server
,
5517 const char *key
, size_t key_length
,
5518 const char *value
, size_t value_length
,
5528 return MEMCACHED_SUCCESS
;
5531 static test_return_t
memcached_stat_execute_test(memcached_st
*memc
)
5533 memcached_return_t rc
= memcached_stat_execute(memc
, NULL
, stat_printer
, NULL
);
5534 test_compare(MEMCACHED_SUCCESS
, rc
);
5536 rc
= memcached_stat_execute(memc
, "slabs", stat_printer
, NULL
);
5537 test_compare(MEMCACHED_SUCCESS
, rc
);
5539 rc
= memcached_stat_execute(memc
, "items", stat_printer
, NULL
);
5540 test_compare(MEMCACHED_SUCCESS
, rc
);
5542 rc
= memcached_stat_execute(memc
, "sizes", stat_printer
, NULL
);
5543 test_compare(MEMCACHED_SUCCESS
, rc
);
5545 return TEST_SUCCESS
;
5549 * This test ensures that the failure counter isn't incremented during
5550 * normal termination of the memcached instance.
5552 static test_return_t
wrong_failure_counter_test(memcached_st
*memc
)
5554 memcached_return_t rc
;
5555 memcached_server_instance_st instance
;
5557 /* Set value to force connection to the server */
5558 const char *key
= "marmotte";
5559 const char *value
= "milka";
5562 * Please note that I'm abusing the internal structures in libmemcached
5563 * in a non-portable way and you shouldn't be doing this. I'm only
5564 * doing this in order to verify that the library works the way it should
5566 uint32_t number_of_hosts
= memcached_server_count(memc
);
5567 memc
->number_of_hosts
= 1;
5569 /* Ensure that we are connected to the server by setting a value */
5570 rc
= memcached_set(memc
, key
, strlen(key
),
5571 value
, strlen(value
),
5572 (time_t)0, (uint32_t)0);
5573 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5576 instance
= memcached_server_instance_by_position(memc
, 0);
5577 /* The test is to see that the memcached_quit doesn't increase the
5578 * the server failure conter, so let's ensure that it is zero
5579 * before sending quit
5581 ((memcached_server_write_instance_st
)instance
)->server_failure_counter
= 0;
5583 memcached_quit(memc
);
5585 /* Verify that it memcached_quit didn't increment the failure counter
5586 * Please note that this isn't bullet proof, because an error could
5589 test_compare(0, instance
->server_failure_counter
);
5591 /* restore the instance */
5592 memc
->number_of_hosts
= number_of_hosts
;
5594 return TEST_SUCCESS
;
5598 * This tests ensures expected disconnections (for some behavior changes
5599 * for instance) do not wrongly increase failure counter
5601 static test_return_t
wrong_failure_counter_two_test(memcached_st
*memc
)
5603 memcached_return rc
;
5605 memcached_st
*memc_clone
;
5606 memc_clone
= memcached_clone(NULL
, memc
);
5607 test_true(memc_clone
);
5609 /* Set value to force connection to the server */
5610 const char *key
= "marmotte";
5611 const char *value
= "milka";
5612 char *string
= NULL
;
5613 size_t string_length
;
5616 rc
= memcached_set(memc_clone
, key
, strlen(key
),
5617 value
, strlen(value
),
5618 (time_t)0, (uint32_t)0);
5619 test_true_got(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
, memcached_strerror(NULL
, rc
));
5622 /* put failure limit to 1 */
5623 test_compare(MEMCACHED_SUCCESS
,
5624 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, 1));
5626 /* Put a retry timeout to effectively activate failure_limit effect */
5627 test_compare(MEMCACHED_SUCCESS
,
5628 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 1));
5630 /* change behavior that triggers memcached_quit()*/
5631 test_compare(MEMCACHED_SUCCESS
,
5632 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1));
5635 /* Check if we still are connected */
5636 string
= memcached_get(memc_clone
, key
, strlen(key
),
5637 &string_length
, &flags
, &rc
);
5639 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
5642 memcached_free(memc_clone
);
5644 return TEST_SUCCESS
;
5651 * Test that ensures mget_execute does not end into recursive calls that finally fails
5653 static test_return_t
regression_bug_490486(memcached_st
*memc
)
5655 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
5656 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 1);
5657 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, 1000);
5658 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, 1);
5659 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 3600);
5662 return TEST_SKIPPED
; // My MAC can't handle this test
5666 * I only want to hit _one_ server so I know the number of requests I'm
5667 * sending in the pipeline.
5669 uint32_t number_of_hosts
= memc
->number_of_hosts
;
5670 memc
->number_of_hosts
= 1;
5671 size_t max_keys
= 20480;
5674 char **keys
= (char **)calloc(max_keys
, sizeof(char*));
5675 size_t *key_length
= (size_t *)calloc(max_keys
, sizeof(size_t));
5677 /* First add all of the items.. */
5678 char blob
[1024]= { 0 };
5679 for (size_t x
= 0; x
< max_keys
; ++x
)
5682 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%lu", (unsigned long)x
);
5685 memcached_return rc
= memcached_set(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
5686 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
); // MEMCACHED_TIMEOUT <-- hash been observed on OSX
5691 /* Try to get all of them with a large multiget */
5693 memcached_execute_function callbacks
[]= { &callback_counter
};
5694 memcached_return_t rc
= memcached_mget_execute(memc
, (const char**)keys
, key_length
,
5695 (size_t)max_keys
, callbacks
, &counter
, 1);
5696 test_compare(MEMCACHED_SUCCESS
, rc
);
5698 char* the_value
= NULL
;
5699 char the_key
[MEMCACHED_MAX_KEY
];
5700 size_t the_key_length
;
5701 size_t the_value_length
;
5705 the_value
= memcached_fetch(memc
, the_key
, &the_key_length
, &the_value_length
, &the_flags
, &rc
);
5707 if ((the_value
!= NULL
) && (rc
== MEMCACHED_SUCCESS
))
5713 } while ( (the_value
!= NULL
) && (rc
== MEMCACHED_SUCCESS
));
5716 test_compare(MEMCACHED_END
, rc
);
5718 /* Verify that we got all of the items */
5719 test_compare(counter
, max_keys
);
5722 /* Release all allocated resources */
5723 for (size_t x
= 0; x
< max_keys
; ++x
)
5730 memc
->number_of_hosts
= number_of_hosts
;
5732 return TEST_SUCCESS
;
5735 static test_return_t
regression_bug_583031(memcached_st
*)
5737 memcached_st
*memc
= memcached_create(NULL
);
5739 test_compare(MEMCACHED_SUCCESS
, memcached_server_add(memc
, "10.2.3.4", 11211));
5741 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT
, 1000);
5742 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 1000);
5743 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
5744 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
5745 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, 1000);
5746 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, 3);
5748 memcached_return_t rc
;
5752 const char *value
= memcached_get(memc
, "dsf", 3, &length
, &flags
, &rc
);
5754 test_compare(0, length
);
5756 test_compare_got(MEMCACHED_TIMEOUT
, rc
, memcached_strerror(memc
, rc
));
5758 memcached_free(memc
);
5760 return TEST_SUCCESS
;
5763 static test_return_t
regression_bug_581030(memcached_st
*)
5766 memcached_stat_st
*local_stat
= memcached_stat(NULL
, NULL
, NULL
);
5767 test_false(local_stat
);
5769 memcached_stat_free(NULL
, NULL
);
5772 return TEST_SUCCESS
;
5775 #define regression_bug_655423_COUNT 6000
5776 static test_return_t
regression_bug_655423(memcached_st
*memc
)
5778 memcached_st
*clone
= memcached_clone(NULL
, memc
);
5779 memc
= NULL
; // Just to make sure it is not used
5783 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1));
5784 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1));
5785 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1));
5786 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH
, 1));
5788 memset(payload
, int('x'), sizeof(payload
));
5790 for (uint32_t x
= 0; x
< regression_bug_655423_COUNT
; x
++)
5793 snprintf(key
, sizeof(key
), "%u", x
);
5795 test_compare(MEMCACHED_SUCCESS
, memcached_set(clone
, key
, strlen(key
), payload
, sizeof(payload
), 0, 0));
5798 for (uint32_t x
= 0; x
< regression_bug_655423_COUNT
; x
++)
5801 snprintf(key
, sizeof(key
), "%u", x
);
5803 size_t value_length
;
5804 memcached_return_t rc
;
5805 char *value
= memcached_get(clone
, key
, strlen(key
), &value_length
, NULL
, &rc
);
5807 if (rc
== MEMCACHED_NOTFOUND
)
5810 test_compare(0, value_length
);
5814 test_compare(MEMCACHED_SUCCESS
, rc
);
5816 test_compare(100, value_length
);
5820 char **keys
= (char**)calloc(regression_bug_655423_COUNT
, sizeof(char*));
5821 size_t *key_length
= (size_t *)calloc(regression_bug_655423_COUNT
, sizeof(size_t));
5822 for (uint32_t x
= 0; x
< regression_bug_655423_COUNT
; x
++)
5825 snprintf(key
, sizeof(key
), "%u", x
);
5827 keys
[x
]= strdup(key
);
5828 key_length
[x
]= strlen(key
);
5831 memcached_return_t rc
;
5832 test_compare_got(MEMCACHED_SUCCESS
,
5833 rc
= memcached_mget(clone
, (const char* const *)keys
, key_length
, regression_bug_655423_COUNT
),
5834 memcached_strerror(NULL
, rc
));
5837 memcached_result_st
*result
= NULL
;
5838 while ((result
= memcached_fetch_result(clone
, result
, NULL
)))
5840 test_compare(100, memcached_result_length(result
));
5844 test_true(count
> 100); // If we don't get back atleast this, something is up
5846 /* Release all allocated resources */
5847 for (size_t x
= 0; x
< regression_bug_655423_COUNT
; ++x
)
5855 memcached_free(clone
);
5857 return TEST_SUCCESS
;
5861 * Test that ensures that buffered set to not trigger problems during io_flush
5863 #define regression_bug_490520_COUNT 200480
5864 static test_return_t
regression_bug_490520(memcached_st
*memc
)
5866 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
,1);
5867 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
,1);
5868 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, 1000);
5869 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
,1);
5870 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 3600);
5872 memc
->number_of_hosts
= 1;
5874 char **keys
= (char **)calloc(regression_bug_490520_COUNT
, sizeof(char*));
5875 size_t *key_length
= (size_t *)calloc(regression_bug_490520_COUNT
, sizeof(size_t));
5877 /* First add all of the items.. */
5878 char blob
[3333] = {0};
5879 for (uint32_t x
= 0; x
< regression_bug_490520_COUNT
; ++x
)
5882 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%u", x
);
5886 memcached_return rc
= memcached_set(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
5887 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
5890 for (uint32_t x
= 0; x
< regression_bug_490520_COUNT
; ++x
)
5897 return TEST_SUCCESS
;
5900 static void memcached_die(memcached_st
* mc
, memcached_return error
, const char* what
, uint32_t it
)
5902 fprintf(stderr
, "Iteration #%u: ", it
);
5904 if(error
== MEMCACHED_ERRNO
)
5906 fprintf(stderr
, "system error %d from %s: %s\n",
5907 errno
, what
, strerror(errno
));
5911 fprintf(stderr
, "error %d from %s: %s\n", error
, what
,
5912 memcached_strerror(mc
, error
));
5916 #define TEST_CONSTANT_CREATION 200
5918 static test_return_t
regression_bug_(memcached_st
*memc
)
5920 const char *remote_server
;
5923 if (! (remote_server
= getenv("LIBMEMCACHED_REMOTE_SERVER")))
5925 return TEST_SKIPPED
;
5928 for (uint32_t x
= 0; x
< TEST_CONSTANT_CREATION
; x
++)
5930 memcached_st
* mc
= memcached_create(NULL
);
5931 memcached_return rc
;
5933 rc
= memcached_behavior_set(mc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
5934 if (rc
!= MEMCACHED_SUCCESS
)
5936 memcached_die(mc
, rc
, "memcached_behavior_set", x
);
5939 rc
= memcached_behavior_set(mc
, MEMCACHED_BEHAVIOR_CACHE_LOOKUPS
, 1);
5940 if (rc
!= MEMCACHED_SUCCESS
)
5942 memcached_die(mc
, rc
, "memcached_behavior_set", x
);
5945 rc
= memcached_server_add(mc
, remote_server
, 0);
5946 if (rc
!= MEMCACHED_SUCCESS
)
5948 memcached_die(mc
, rc
, "memcached_server_add", x
);
5951 const char *set_key
= "akey";
5952 const size_t set_key_len
= strlen(set_key
);
5953 const char *set_value
= "a value";
5954 const size_t set_value_len
= strlen(set_value
);
5956 if (rc
== MEMCACHED_SUCCESS
)
5960 size_t get_value_len
;
5962 uint32_t get_value_flags
;
5964 get_value
= memcached_get(mc
, set_key
, set_key_len
, &get_value_len
,
5965 &get_value_flags
, &rc
);
5966 if (rc
!= MEMCACHED_SUCCESS
)
5968 memcached_die(mc
, rc
, "memcached_get", x
);
5974 (get_value_len
!= set_value_len
5975 || 0!=strncmp(get_value
, set_value
, get_value_len
)))
5977 fprintf(stderr
, "Values don't match?\n");
5978 rc
= MEMCACHED_FAILURE
;
5984 rc
= memcached_set(mc
,
5985 set_key
, set_key_len
,
5986 set_value
, set_value_len
,
5990 if (rc
!= MEMCACHED_SUCCESS
)
5992 memcached_die(mc
, rc
, "memcached_set", x
);
5999 if (rc
!= MEMCACHED_SUCCESS
)
6005 return TEST_SUCCESS
;
6009 * Test that the sasl authentication works. We cannot use the default
6010 * pool of servers, because that would require that all servers we want
6011 * to test supports SASL authentication, and that they use the default
6014 static test_return_t
sasl_auth_test(memcached_st
*memc
)
6016 #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
6017 test_compare(MEMCACHED_SUCCESS
, memcached_set(memc
, "foo", 3, "bar", 3, (time_t)0, (uint32_t)0));
6018 test_compare(MEMCACHED_SUCCESS
, memcached_delete(memc
, "foo", 3, 0));
6019 test_compare(MEMCACHED_SUCCESS
, memcached_destroy_sasl_auth_data(memc
));
6020 test_compare(MEMCACHED_FAILURE
, memcached_destroy_sasl_auth_data(memc
));
6021 test_compare(MEMCACHED_FAILURE
, memcached_destroy_sasl_auth_data(NULL
));
6022 memcached_quit(memc
);
6024 test_compare(MEMCACHED_SUCCESS
,
6025 memcached_set_sasl_auth_data(memc
,
6026 getenv("LIBMEMCACHED_TEST_SASL_USERNAME"),
6027 getenv("LIBMEMCACHED_TEST_SASL_SERVER")));
6029 test_compare(MEMCACHED_AUTH_FAILURE
,
6030 memcached_set(memc
, "foo", 3, "bar", 3, (time_t)0, (uint32_t)0));
6031 test_compare(MEMCACHED_SUCCESS
, memcached_destroy_sasl_auth_data(memc
));
6033 memcached_quit(memc
);
6034 return TEST_SUCCESS
;
6037 return TEST_FAILURE
;
6041 /* Clean the server before beginning testing */
6043 {"util_version", 1, (test_callback_fn
)util_version_test
},
6044 {"flush", 0, (test_callback_fn
)flush_test
},
6045 {"init", 0, (test_callback_fn
)init_test
},
6046 {"allocation", 0, (test_callback_fn
)allocation_test
},
6047 {"server_list_null_test", 0, (test_callback_fn
)server_list_null_test
},
6048 {"server_unsort", 0, (test_callback_fn
)server_unsort_test
},
6049 {"server_sort", 0, (test_callback_fn
)server_sort_test
},
6050 {"server_sort2", 0, (test_callback_fn
)server_sort2_test
},
6051 {"memcached_server_remove", 0, (test_callback_fn
)memcached_server_remove_test
},
6052 {"clone_test", 0, (test_callback_fn
)clone_test
},
6053 {"connection_test", 0, (test_callback_fn
)connection_test
},
6054 {"callback_test", 0, (test_callback_fn
)callback_test
},
6055 {"userdata_test", 0, (test_callback_fn
)userdata_test
},
6056 {"error", 0, (test_callback_fn
)error_test
},
6057 {"set", 0, (test_callback_fn
)set_test
},
6058 {"set2", 0, (test_callback_fn
)set_test2
},
6059 {"set3", 0, (test_callback_fn
)set_test3
},
6060 {"dump", 1, (test_callback_fn
)dump_test
},
6061 {"add", 1, (test_callback_fn
)add_test
},
6062 {"memcached_fetch_result(MEMCACHED_NOTFOUND)", 1, (test_callback_fn
)memcached_fetch_result_NOT_FOUND
},
6063 {"replace", 1, (test_callback_fn
)replace_test
},
6064 {"delete", 1, (test_callback_fn
)delete_test
},
6065 {"get", 1, (test_callback_fn
)get_test
},
6066 {"get2", 0, (test_callback_fn
)get_test2
},
6067 {"get3", 0, (test_callback_fn
)get_test3
},
6068 {"get4", 0, (test_callback_fn
)get_test4
},
6069 {"partial mget", 0, (test_callback_fn
)get_test5
},
6070 {"stats_servername", 0, (test_callback_fn
)stats_servername_test
},
6071 {"increment", 0, (test_callback_fn
)increment_test
},
6072 {"increment_with_initial", 1, (test_callback_fn
)increment_with_initial_test
},
6073 {"decrement", 0, (test_callback_fn
)decrement_test
},
6074 {"decrement_with_initial", 1, (test_callback_fn
)decrement_with_initial_test
},
6075 {"increment_by_key", 0, (test_callback_fn
)increment_by_key_test
},
6076 {"increment_with_initial_by_key", 1, (test_callback_fn
)increment_with_initial_by_key_test
},
6077 {"decrement_by_key", 0, (test_callback_fn
)decrement_by_key_test
},
6078 {"decrement_with_initial_by_key", 1, (test_callback_fn
)decrement_with_initial_by_key_test
},
6079 {"quit", 0, (test_callback_fn
)quit_test
},
6080 {"mget", 1, (test_callback_fn
)mget_test
},
6081 {"mget_result", 1, (test_callback_fn
)mget_result_test
},
6082 {"mget_result_alloc", 1, (test_callback_fn
)mget_result_alloc_test
},
6083 {"mget_result_function", 1, (test_callback_fn
)mget_result_function
},
6084 {"mget_execute", 1, (test_callback_fn
)mget_execute
},
6085 {"mget_end", 0, (test_callback_fn
)mget_end
},
6086 {"get_stats", 0, (test_callback_fn
)get_stats
},
6087 {"add_host_test", 0, (test_callback_fn
)add_host_test
},
6088 {"add_host_test_1", 0, (test_callback_fn
)add_host_test1
},
6089 {"get_stats_keys", 0, (test_callback_fn
)get_stats_keys
},
6090 {"version_string_test", 0, (test_callback_fn
)version_string_test
},
6091 {"bad_key", 1, (test_callback_fn
)bad_key_test
},
6092 {"memcached_server_cursor", 1, (test_callback_fn
)memcached_server_cursor_test
},
6093 {"read_through", 1, (test_callback_fn
)read_through
},
6094 {"delete_through", 1, (test_callback_fn
)delete_through
},
6095 {"noreply", 1, (test_callback_fn
)noreply_test
},
6096 {"analyzer", 1, (test_callback_fn
)analyzer_test
},
6097 {"connectionpool", 1, (test_callback_fn
)connection_pool_test
},
6098 {"memcached_pool_test", 1, (test_callback_fn
)memcached_pool_test
},
6099 {"ping", 1, (test_callback_fn
)ping_test
},
6100 {"test_get_last_disconnect", 1, (test_callback_fn
)test_get_last_disconnect
},
6101 {"verbosity", 1, (test_callback_fn
)test_verbosity
},
6102 {"test_server_failure", 1, (test_callback_fn
)test_server_failure
},
6103 {"cull_servers", 1, (test_callback_fn
)test_cull_servers
},
6104 {"memcached_stat_execute", 1, (test_callback_fn
)memcached_stat_execute_test
},
6108 test_st behavior_tests
[] ={
6109 {"libmemcached_string_behavior()", 0, (test_callback_fn
)libmemcached_string_behavior_test
},
6110 {"libmemcached_string_distribution()", 0, (test_callback_fn
)libmemcached_string_distribution_test
},
6111 {"behavior_test", 0, (test_callback_fn
)behavior_test
},
6112 {"MEMCACHED_BEHAVIOR_CORK", 0, (test_callback_fn
)MEMCACHED_BEHAVIOR_CORK_test
},
6113 {"MEMCACHED_BEHAVIOR_TCP_KEEPALIVE", 0, (test_callback_fn
)MEMCACHED_BEHAVIOR_TCP_KEEPALIVE_test
},
6114 {"MEMCACHED_BEHAVIOR_TCP_KEEPIDLE", 0, (test_callback_fn
)MEMCACHED_BEHAVIOR_TCP_KEEPIDLE_test
},
6118 test_st basic_tests
[] ={
6119 {"init", 1, (test_callback_fn
)basic_init_test
},
6120 {"clone", 1, (test_callback_fn
)basic_clone_test
},
6121 {"reset", 1, (test_callback_fn
)basic_reset_stack_test
},
6122 {"reset heap", 1, (test_callback_fn
)basic_reset_heap_test
},
6123 {"reset stack clone", 1, (test_callback_fn
)basic_reset_stack_clone_test
},
6124 {"reset heap clone", 1, (test_callback_fn
)basic_reset_heap_clone_test
},
6128 test_st regression_binary_vs_block
[] ={
6129 {"block add", 1, (test_callback_fn
)block_add_regression
},
6130 {"binary add", 1, (test_callback_fn
)binary_add_regression
},
6134 test_st async_tests
[] ={
6135 {"add", 1, (test_callback_fn
)add_wrapper
},
6139 test_st string_tests
[] ={
6140 {"string static with null", 0, (test_callback_fn
)string_static_null
},
6141 {"string alloc with null", 0, (test_callback_fn
)string_alloc_null
},
6142 {"string alloc with 1K", 0, (test_callback_fn
)string_alloc_with_size
},
6143 {"string alloc with malloc failure", 0, (test_callback_fn
)string_alloc_with_size_toobig
},
6144 {"string append", 0, (test_callback_fn
)string_alloc_append
},
6145 {"string append failure (too big)", 0, (test_callback_fn
)string_alloc_append_toobig
},
6146 {"string_alloc_append_multiple", 0, (test_callback_fn
)string_alloc_append_multiple
},
6147 {0, 0, (test_callback_fn
)0}
6150 test_st memcached_server_get_last_disconnect_tests
[] ={
6151 {"memcached_server_get_last_disconnect()", 0, (test_callback_fn
)test_multiple_get_last_disconnect
},
6152 {0, 0, (test_callback_fn
)0}
6156 test_st result_tests
[] ={
6157 {"result static", 0, (test_callback_fn
)result_static
},
6158 {"result alloc", 0, (test_callback_fn
)result_alloc
},
6159 {0, 0, (test_callback_fn
)0}
6162 test_st version_1_2_3
[] ={
6163 {"append", 0, (test_callback_fn
)append_test
},
6164 {"prepend", 0, (test_callback_fn
)prepend_test
},
6165 {"cas", 0, (test_callback_fn
)cas_test
},
6166 {"cas2", 0, (test_callback_fn
)cas2_test
},
6167 {"append_binary", 0, (test_callback_fn
)append_binary_test
},
6168 {0, 0, (test_callback_fn
)0}
6171 test_st haldenbrand_tests
[] ={
6172 {"memcached_set", 0, (test_callback_fn
)user_supplied_bug1
},
6173 {"memcached_get()", 0, (test_callback_fn
)user_supplied_bug2
},
6174 {"memcached_mget()", 0, (test_callback_fn
)user_supplied_bug3
},
6175 {0, 0, (test_callback_fn
)0}
6178 test_st user_tests
[] ={
6179 {"user_supplied_bug4", true, (test_callback_fn
)user_supplied_bug4
},
6180 {"user_supplied_bug5", 1, (test_callback_fn
)user_supplied_bug5
},
6181 {"user_supplied_bug6", 1, (test_callback_fn
)user_supplied_bug6
},
6182 {"user_supplied_bug7", 1, (test_callback_fn
)user_supplied_bug7
},
6183 {"user_supplied_bug8", 1, (test_callback_fn
)user_supplied_bug8
},
6184 {"user_supplied_bug9", 1, (test_callback_fn
)user_supplied_bug9
},
6185 {"user_supplied_bug10", 1, (test_callback_fn
)user_supplied_bug10
},
6186 {"user_supplied_bug11", 1, (test_callback_fn
)user_supplied_bug11
},
6187 {"user_supplied_bug12", 1, (test_callback_fn
)user_supplied_bug12
},
6188 {"user_supplied_bug13", 1, (test_callback_fn
)user_supplied_bug13
},
6189 {"user_supplied_bug14", 1, (test_callback_fn
)user_supplied_bug14
},
6190 {"user_supplied_bug15", 1, (test_callback_fn
)user_supplied_bug15
},
6191 {"user_supplied_bug16", 1, (test_callback_fn
)user_supplied_bug16
},
6192 #if !defined(__sun) && !defined(__OpenBSD__)
6194 ** It seems to be something weird with the character sets..
6195 ** value_fetch is unable to parse the value line (iscntrl "fails"), so I
6196 ** guess I need to find out how this is supposed to work.. Perhaps I need
6197 ** to run the test in a specific locale (I tried zh_CN.UTF-8 without success,
6198 ** so just disable the code for now...).
6200 {"user_supplied_bug17", 1, (test_callback_fn
)user_supplied_bug17
},
6202 {"user_supplied_bug18", 1, (test_callback_fn
)user_supplied_bug18
},
6203 {"user_supplied_bug19", 1, (test_callback_fn
)user_supplied_bug19
},
6204 {"user_supplied_bug20", 1, (test_callback_fn
)user_supplied_bug20
},
6205 {"user_supplied_bug21", 1, (test_callback_fn
)user_supplied_bug21
},
6206 {"wrong_failure_counter_test", 1, (test_callback_fn
)wrong_failure_counter_test
},
6207 {"wrong_failure_counter_two_test", 1, (test_callback_fn
)wrong_failure_counter_two_test
},
6208 {0, 0, (test_callback_fn
)0}
6211 test_st replication_tests
[]= {
6212 {"set", 1, (test_callback_fn
)replication_set_test
},
6213 {"get", 0, (test_callback_fn
)replication_get_test
},
6214 {"mget", 0, (test_callback_fn
)replication_mget_test
},
6215 {"delete", 0, (test_callback_fn
)replication_delete_test
},
6216 {"rand_mget", 0, (test_callback_fn
)replication_randomize_mget_test
},
6217 {"fail", 0, (test_callback_fn
)replication_randomize_mget_fail_test
},
6218 {0, 0, (test_callback_fn
)0}
6222 * The following test suite is used to verify that we don't introduce
6223 * regression bugs. If you want more information about the bug / test,
6224 * you should look in the bug report at
6225 * http://bugs.launchpad.net/libmemcached
6227 test_st regression_tests
[]= {
6228 {"lp:434484", 1, (test_callback_fn
)regression_bug_434484
},
6229 {"lp:434843", 1, (test_callback_fn
)regression_bug_434843
},
6230 {"lp:434843-buffered", 1, (test_callback_fn
)regression_bug_434843_buffered
},
6231 {"lp:421108", 1, (test_callback_fn
)regression_bug_421108
},
6232 {"lp:442914", 1, (test_callback_fn
)regression_bug_442914
},
6233 {"lp:447342", 1, (test_callback_fn
)regression_bug_447342
},
6234 {"lp:463297", 1, (test_callback_fn
)regression_bug_463297
},
6235 {"lp:490486", 1, (test_callback_fn
)regression_bug_490486
},
6236 {"lp:583031", 1, (test_callback_fn
)regression_bug_583031
},
6237 {"lp:?", 1, (test_callback_fn
)regression_bug_
},
6238 {"lp:728286", 1, (test_callback_fn
)regression_bug_728286
},
6239 {"lp:581030", 1, (test_callback_fn
)regression_bug_581030
},
6240 {"lp:71231153 connect()", 1, (test_callback_fn
)regression_bug_71231153_connect
},
6241 {"lp:71231153 poll()", 1, (test_callback_fn
)regression_bug_71231153_poll
},
6242 {"lp:655423", 1, (test_callback_fn
)regression_bug_655423
},
6243 {"lp:490520", 1, (test_callback_fn
)regression_bug_490520
},
6244 {0, 0, (test_callback_fn
)0}
6247 test_st sasl_auth_tests
[]= {
6248 {"sasl_auth", 1, (test_callback_fn
)sasl_auth_test
},
6249 {0, 0, (test_callback_fn
)0}
6252 test_st ketama_compatibility
[]= {
6253 {"libmemcached", 1, (test_callback_fn
)ketama_compatibility_libmemcached
},
6254 {"spymemcached", 1, (test_callback_fn
)ketama_compatibility_spymemcached
},
6255 {0, 0, (test_callback_fn
)0}
6258 test_st generate_tests
[] ={
6259 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
6260 {"generate_data", 1, (test_callback_fn
)generate_data
},
6261 {"get_read", 0, (test_callback_fn
)get_read
},
6262 {"delete_generate", 0, (test_callback_fn
)delete_generate
},
6263 {"generate_buffer_data", 1, (test_callback_fn
)generate_buffer_data
},
6264 {"delete_buffer", 0, (test_callback_fn
)delete_buffer_generate
},
6265 {"generate_data", 1, (test_callback_fn
)generate_data
},
6266 {"mget_read", 0, (test_callback_fn
)mget_read
},
6267 {"mget_read_result", 0, (test_callback_fn
)mget_read_result
},
6268 {"mget_read_function", 0, (test_callback_fn
)mget_read_function
},
6269 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
6270 {"generate_large_pairs", 1, (test_callback_fn
)generate_large_pairs
},
6271 {"generate_data", 1, (test_callback_fn
)generate_data
},
6272 {"generate_buffer_data", 1, (test_callback_fn
)generate_buffer_data
},
6273 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
6274 {0, 0, (test_callback_fn
)0}
6277 test_st consistent_tests
[] ={
6278 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
6279 {"generate_data", 1, (test_callback_fn
)generate_data
},
6280 {"get_read", 0, (test_callback_fn
)get_read_count
},
6281 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
6282 {0, 0, (test_callback_fn
)0}
6285 test_st consistent_weighted_tests
[] ={
6286 {"generate_pairs", 1, (test_callback_fn
)generate_pairs
},
6287 {"generate_data", 1, (test_callback_fn
)generate_data_with_stats
},
6288 {"get_read", 0, (test_callback_fn
)get_read_count
},
6289 {"cleanup", 1, (test_callback_fn
)cleanup_pairs
},
6290 {0, 0, (test_callback_fn
)0}
6293 test_st hsieh_availability
[] ={
6294 {"hsieh_avaibility_test", 0, (test_callback_fn
)hsieh_avaibility_test
},
6295 {0, 0, (test_callback_fn
)0}
6298 test_st murmur_availability
[] ={
6299 {"murmur_avaibility_test", 0, (test_callback_fn
)murmur_avaibility_test
},
6300 {0, 0, (test_callback_fn
)0}
6304 test_st hash_sanity
[] ={
6305 {"hash sanity", 0, (test_callback_fn
)hash_sanity_test
},
6306 {0, 0, (test_callback_fn
)0}
6310 test_st ketama_auto_eject_hosts
[] ={
6311 {"auto_eject_hosts", 1, (test_callback_fn
)auto_eject_hosts
},
6312 {"output_ketama_weighted_keys", 1, (test_callback_fn
)output_ketama_weighted_keys
},
6313 {0, 0, (test_callback_fn
)0}
6316 test_st hash_tests
[] ={
6317 {"one_at_a_time_run", 0, (test_callback_fn
)one_at_a_time_run
},
6318 {"md5", 0, (test_callback_fn
)md5_run
},
6319 {"crc", 0, (test_callback_fn
)crc_run
},
6320 {"fnv1_64", 0, (test_callback_fn
)fnv1_64_run
},
6321 {"fnv1a_64", 0, (test_callback_fn
)fnv1a_64_run
},
6322 {"fnv1_32", 0, (test_callback_fn
)fnv1_32_run
},
6323 {"fnv1a_32", 0, (test_callback_fn
)fnv1a_32_run
},
6324 {"hsieh", 0, (test_callback_fn
)hsieh_run
},
6325 {"murmur", 0, (test_callback_fn
)murmur_run
},
6326 {"jenkis", 0, (test_callback_fn
)jenkins_run
},
6327 {"memcached_get_hashkit", 0, (test_callback_fn
)memcached_get_hashkit_test
},
6328 {0, 0, (test_callback_fn
)0}
6331 test_st error_conditions
[] ={
6332 {"memcached_get(MEMCACHED_ERRNO)", 0, (test_callback_fn
)memcached_get_MEMCACHED_ERRNO
},
6333 {"memcached_get(MEMCACHED_NOTFOUND)", 0, (test_callback_fn
)memcached_get_MEMCACHED_NOTFOUND
},
6334 {"memcached_get_by_key(MEMCACHED_ERRNO)", 0, (test_callback_fn
)memcached_get_by_key_MEMCACHED_ERRNO
},
6335 {"memcached_get_by_key(MEMCACHED_NOTFOUND)", 0, (test_callback_fn
)memcached_get_by_key_MEMCACHED_NOTFOUND
},
6336 {"memcached_get_by_key(MEMCACHED_NOTFOUND)", 0, (test_callback_fn
)memcached_get_by_key_MEMCACHED_NOTFOUND
},
6337 {"memcached_increment(MEMCACHED_NO_SERVERS)", 0, (test_callback_fn
)memcached_increment_MEMCACHED_NO_SERVERS
},
6338 {0, 0, (test_callback_fn
)0}
6342 test_st parser_tests
[] ={
6343 {"behavior", 0, (test_callback_fn
)behavior_parser_test
},
6344 {"boolean_options", 0, (test_callback_fn
)parser_boolean_options_test
},
6345 {"configure_file", 0, (test_callback_fn
)memcached_create_with_options_with_filename
},
6346 {"distribtions", 0, (test_callback_fn
)parser_distribution_test
},
6347 {"hash", 0, (test_callback_fn
)parser_hash_test
},
6348 {"libmemcached_check_configuration", 0, (test_callback_fn
)libmemcached_check_configuration_test
},
6349 {"libmemcached_check_configuration_with_filename", 0, (test_callback_fn
)libmemcached_check_configuration_with_filename_test
},
6350 {"number_options", 0, (test_callback_fn
)parser_number_options_test
},
6351 {"randomly generated options", 0, (test_callback_fn
)random_statement_build_test
},
6352 {"prefix_key", 0, (test_callback_fn
)parser_key_prefix_test
},
6353 {"server", 0, (test_callback_fn
)server_test
},
6354 {"bad server strings", 0, (test_callback_fn
)servers_bad_test
},
6355 {"server with weights", 0, (test_callback_fn
)server_with_weight_test
},
6356 {"parsing servername, port, and weight", 0, (test_callback_fn
)test_hostname_port_weight
},
6357 {0, 0, (test_callback_fn
)0}
6360 test_st virtual_bucket_tests
[] ={
6361 {"basic", 0, (test_callback_fn
)virtual_back_map
},
6362 {0, 0, (test_callback_fn
)0}
6365 collection_st collection
[] ={
6367 {"hash_sanity", 0, 0, hash_sanity
},
6369 {"basic", 0, 0, basic_tests
},
6370 {"hsieh_availability", 0, 0, hsieh_availability
},
6371 {"murmur_availability", 0, 0, murmur_availability
},
6372 {"block", 0, 0, tests
},
6373 {"binary", (test_callback_fn
)pre_binary
, 0, tests
},
6374 {"nonblock", (test_callback_fn
)pre_nonblock
, 0, tests
},
6375 {"nodelay", (test_callback_fn
)pre_nodelay
, 0, tests
},
6376 {"settimer", (test_callback_fn
)pre_settimer
, 0, tests
},
6377 {"md5", (test_callback_fn
)pre_md5
, 0, tests
},
6378 {"crc", (test_callback_fn
)pre_crc
, 0, tests
},
6379 {"hsieh", (test_callback_fn
)pre_hsieh
, 0, tests
},
6380 {"jenkins", (test_callback_fn
)pre_jenkins
, 0, tests
},
6381 {"fnv1_64", (test_callback_fn
)pre_hash_fnv1_64
, 0, tests
},
6382 {"fnv1a_64", (test_callback_fn
)pre_hash_fnv1a_64
, 0, tests
},
6383 {"fnv1_32", (test_callback_fn
)pre_hash_fnv1_32
, 0, tests
},
6384 {"fnv1a_32", (test_callback_fn
)pre_hash_fnv1a_32
, 0, tests
},
6385 {"ketama", (test_callback_fn
)pre_behavior_ketama
, 0, tests
},
6386 {"ketama_auto_eject_hosts", (test_callback_fn
)pre_behavior_ketama
, 0, ketama_auto_eject_hosts
},
6387 {"unix_socket", (test_callback_fn
)pre_unix_socket
, 0, tests
},
6388 {"unix_socket_nodelay", (test_callback_fn
)pre_nodelay
, 0, tests
},
6389 {"poll_timeout", (test_callback_fn
)poll_timeout
, 0, tests
},
6390 {"gets", (test_callback_fn
)enable_cas
, 0, tests
},
6391 {"consistent_crc", (test_callback_fn
)enable_consistent_crc
, 0, tests
},
6392 {"consistent_hsieh", (test_callback_fn
)enable_consistent_hsieh
, 0, tests
},
6393 #ifdef MEMCACHED_ENABLE_DEPRECATED
6394 {"deprecated_memory_allocators", (test_callback_fn
)deprecated_set_memory_alloc
, 0, tests
},
6396 {"memory_allocators", (test_callback_fn
)set_memory_alloc
, 0, tests
},
6397 {"prefix", (test_callback_fn
)set_prefix
, 0, tests
},
6398 {"sasl_auth", (test_callback_fn
)pre_sasl
, 0, sasl_auth_tests
},
6399 {"sasl", (test_callback_fn
)pre_sasl
, 0, tests
},
6400 {"version_1_2_3", (test_callback_fn
)check_for_1_2_3
, 0, version_1_2_3
},
6401 {"string", 0, 0, string_tests
},
6402 {"result", 0, 0, result_tests
},
6403 {"async", (test_callback_fn
)pre_nonblock
, 0, async_tests
},
6404 {"async_binary", (test_callback_fn
)pre_nonblock_binary
, 0, async_tests
},
6405 {"Cal Haldenbrand's tests", 0, 0, haldenbrand_tests
},
6406 {"user", 0, 0, user_tests
},
6407 {"generate", 0, 0, generate_tests
},
6408 {"generate_hsieh", (test_callback_fn
)pre_hsieh
, 0, generate_tests
},
6409 {"generate_ketama", (test_callback_fn
)pre_behavior_ketama
, 0, generate_tests
},
6410 {"generate_hsieh_consistent", (test_callback_fn
)enable_consistent_hsieh
, 0, generate_tests
},
6411 {"generate_md5", (test_callback_fn
)pre_md5
, 0, generate_tests
},
6412 {"generate_murmur", (test_callback_fn
)pre_murmur
, 0, generate_tests
},
6413 {"generate_jenkins", (test_callback_fn
)pre_jenkins
, 0, generate_tests
},
6414 {"generate_nonblock", (test_callback_fn
)pre_nonblock
, 0, generate_tests
},
6416 {"generate_corked", (test_callback_fn
)pre_cork
, 0, generate_tests
},
6417 {"generate_corked_and_nonblock", (test_callback_fn
)pre_cork_and_nonblock
, 0, generate_tests
},
6418 {"consistent_not", 0, 0, consistent_tests
},
6419 {"consistent_ketama", (test_callback_fn
)pre_behavior_ketama
, 0, consistent_tests
},
6420 {"consistent_ketama_weighted", (test_callback_fn
)pre_behavior_ketama_weighted
, 0, consistent_weighted_tests
},
6421 {"ketama_compat", 0, 0, ketama_compatibility
},
6422 {"test_hashes", 0, 0, hash_tests
},
6423 {"replication", (test_callback_fn
)pre_replication
, 0, replication_tests
},
6424 {"replication_noblock", (test_callback_fn
)pre_replication_noblock
, 0, replication_tests
},
6425 {"regression", 0, 0, regression_tests
},
6426 {"behaviors", 0, 0, behavior_tests
},
6427 {"regression_binary_vs_block", (test_callback_fn
)key_setup
, (test_callback_fn
)key_teardown
, regression_binary_vs_block
},
6428 {"error_conditions", 0, 0, error_conditions
},
6429 {"parser", 0, 0, parser_tests
},
6430 {"virtual buckets", 0, 0, virtual_bucket_tests
},
6431 {"memcached_server_get_last_disconnect", 0, 0, memcached_server_get_last_disconnect_tests
},
6435 #include "tests/libmemcached_world.h"
6437 void get_world(world_st
*world
)
6439 world
->collections
= collection
;
6441 world
->create
= (test_callback_create_fn
)world_create
;
6442 world
->destroy
= (test_callback_fn
)world_destroy
;
6444 world
->test
.startup
= (test_callback_fn
)world_test_startup
;
6445 world
->test
.flush
= (test_callback_fn
)world_flush
;
6446 world
->test
.pre_run
= (test_callback_fn
)world_pre_run
;
6447 world
->test
.post_run
= (test_callback_fn
)world_post_run
;
6448 world
->test
.on_error
= (test_callback_error_fn
)world_on_error
;
6450 world
->collection
.startup
= (test_callback_fn
)world_container_startup
;
6451 world
->collection
.shutdown
= (test_callback_fn
)world_container_shutdown
;
6453 world
->runner
= &defualt_libmemcached_runner
;