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.hpp>
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(size_t(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_internal_result(memcached_st
*memc
)
3477 test_skip(true, bool(libmemcached_util_version_check(memc
, 1, 4, 4)));
3479 test_compare(MEMCACHED_SUCCESS
,
3480 memcached_mget(memc
, global_keys
, global_keys_length
, global_count
));
3482 memcached_result_st
*results
= NULL
;
3483 memcached_return_t rc
;
3484 while ((results
= memcached_fetch_result(memc
, results
, &rc
)))
3487 test_compare(MEMCACHED_SUCCESS
, rc
);
3489 test_compare(MEMCACHED_END
, rc
);
3491 memcached_result_free(results
);
3494 return TEST_SUCCESS
;
3497 static test_return_t
mget_read_partial_result(memcached_st
*memc
)
3500 test_skip(true, bool(libmemcached_util_version_check(memc
, 1, 4, 4)));
3502 test_compare(MEMCACHED_SUCCESS
,
3503 memcached_mget(memc
, global_keys
, global_keys_length
, global_count
));
3505 // We will scan for just one key
3507 memcached_result_st results_obj
;
3508 memcached_result_st
*results
= memcached_result_create(memc
, &results_obj
);
3510 memcached_return_t rc
;
3511 results
= memcached_fetch_result(memc
, results
, &rc
);
3513 test_compare(MEMCACHED_SUCCESS
, rc
);
3515 memcached_result_free(&results_obj
);
3518 // We already have a read happening, lets start up another one.
3519 test_compare(MEMCACHED_SUCCESS
,
3520 memcached_mget(memc
, global_keys
, global_keys_length
, global_count
));
3522 memcached_result_st results_obj
;
3523 memcached_result_st
*results
= memcached_result_create(memc
, &results_obj
);
3525 memcached_return_t rc
;
3526 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
3529 test_compare(MEMCACHED_SUCCESS
, rc
);
3531 test_compare(MEMCACHED_END
, rc
);
3533 memcached_result_free(&results_obj
);
3536 return TEST_SUCCESS
;
3539 static test_return_t
mget_read_function(memcached_st
*memc
)
3541 test_skip(true, bool(libmemcached_util_version_check(memc
, 1, 4, 4)));
3543 test_compare(MEMCACHED_SUCCESS
,
3544 memcached_mget(memc
, global_keys
, global_keys_length
, global_count
));
3546 memcached_execute_fn callbacks
[]= { &callback_counter
};
3548 test_compare(MEMCACHED_SUCCESS
,
3549 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
3551 return TEST_SUCCESS
;
3554 static test_return_t
delete_generate(memcached_st
*memc
)
3556 for (size_t x
= 0; x
< global_count
; x
++)
3558 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3561 return TEST_SUCCESS
;
3564 static test_return_t
delete_buffer_generate(memcached_st
*memc
)
3567 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
3569 for (size_t x
= 0; x
< global_count
; x
++)
3571 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3574 return TEST_SUCCESS
;
3577 static test_return_t
add_host_test1(memcached_st
*memc
)
3579 memcached_return_t rc
;
3580 char servername
[]= "0.example.com";
3582 memcached_server_st
*servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
3584 test_compare(1, memcached_server_list_count(servers
));
3586 for (size_t x
= 2; x
< 20; x
++)
3588 char buffer
[SMALL_STRING_LEN
];
3590 snprintf(buffer
, SMALL_STRING_LEN
, "%lu.example.com", (unsigned long)(400 +x
));
3591 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
3593 test_compare(MEMCACHED_SUCCESS
, rc
);
3594 test_compare(x
, memcached_server_list_count(servers
));
3597 test_compare(MEMCACHED_SUCCESS
, memcached_server_push(memc
, servers
));
3598 test_compare(MEMCACHED_SUCCESS
, memcached_server_push(memc
, servers
));
3600 memcached_server_list_free(servers
);
3602 return TEST_SUCCESS
;
3605 static test_return_t
pre_nonblock(memcached_st
*memc
)
3607 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3609 return TEST_SUCCESS
;
3612 static test_return_t
pre_cork(memcached_st
*memc
)
3615 return TEST_SKIPPED
;
3618 if (memcached_success(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CORK
, set
)))
3619 return TEST_SUCCESS
;
3621 return TEST_SKIPPED
;
3624 static test_return_t
pre_cork_and_nonblock(memcached_st
*memc
)
3627 return TEST_SKIPPED
;
3629 test_return_t test_rc
;
3630 if ((test_rc
= pre_cork(memc
)) != TEST_SUCCESS
)
3633 return pre_nonblock(memc
);
3636 static test_return_t
pre_nonblock_binary(memcached_st
*memc
)
3638 memcached_return_t rc
= MEMCACHED_FAILURE
;
3639 memcached_st
*memc_clone
;
3641 memc_clone
= memcached_clone(NULL
, memc
);
3642 test_true(memc_clone
);
3643 // The memcached_version needs to be done on a clone, because the server
3644 // will not toggle protocol on an connection.
3645 memcached_version(memc_clone
);
3647 if (libmemcached_util_version_check(memc_clone
, 1, 4, 4))
3649 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3650 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3651 test_compare(MEMCACHED_SUCCESS
, rc
);
3652 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3656 return TEST_SKIPPED
;
3659 memcached_free(memc_clone
);
3661 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3664 static test_return_t
pre_murmur(memcached_st
*memc
)
3666 #ifdef HAVE_MURMUR_HASH
3667 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
3668 return TEST_SUCCESS
;
3671 return TEST_SKIPPED
;
3675 static test_return_t
pre_jenkins(memcached_st
*memc
)
3677 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_JENKINS
);
3679 return TEST_SUCCESS
;
3683 static test_return_t
pre_md5(memcached_st
*memc
)
3685 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MD5
);
3687 return TEST_SUCCESS
;
3690 static test_return_t
pre_crc(memcached_st
*memc
)
3692 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_CRC
);
3694 return TEST_SUCCESS
;
3697 static test_return_t
pre_hsieh(memcached_st
*memc
)
3699 #ifdef HAVE_HSIEH_HASH
3700 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_HSIEH
);
3701 return TEST_SUCCESS
;
3704 return TEST_SKIPPED
;
3708 static test_return_t
pre_hash_fnv1_64(memcached_st
*memc
)
3710 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
3712 return TEST_SUCCESS
;
3715 static test_return_t
pre_hash_fnv1a_64(memcached_st
*memc
)
3717 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_64
);
3719 return TEST_SUCCESS
;
3722 static test_return_t
pre_hash_fnv1_32(memcached_st
*memc
)
3724 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_32
);
3726 return TEST_SUCCESS
;
3729 static test_return_t
pre_hash_fnv1a_32(memcached_st
*memc
)
3731 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_32
);
3733 return TEST_SUCCESS
;
3736 static test_return_t
pre_behavior_ketama(memcached_st
*memc
)
3738 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA
, 1);
3739 test_compare(MEMCACHED_SUCCESS
, rc
);
3741 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA
);
3742 test_true(value
== 1);
3744 return TEST_SUCCESS
;
3747 static test_return_t
pre_behavior_ketama_weighted(memcached_st
*memc
)
3749 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
3750 test_compare(MEMCACHED_SUCCESS
, rc
);
3752 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
3753 test_true(value
== 1);
3755 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
3756 test_compare(MEMCACHED_SUCCESS
, rc
);
3758 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
3759 test_true(value
== MEMCACHED_HASH_MD5
);
3761 return TEST_SUCCESS
;
3765 @note This should be testing to see if the server really supports the binary protocol.
3767 static test_return_t
pre_binary(memcached_st
*memc
)
3769 memcached_return_t rc
= MEMCACHED_FAILURE
;
3771 if (libmemcached_util_version_check(memc
, 1, 4, 4))
3773 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3774 test_compare(MEMCACHED_SUCCESS
, rc
);
3775 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3778 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3781 static test_return_t
pre_sasl(memcached_st
*memc
)
3783 memcached_return_t rc
= MEMCACHED_FAILURE
;
3785 #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
3786 const char *server
= getenv("LIBMEMCACHED_TEST_SASL_SERVER");
3787 const char *user
= getenv("LIBMEMCACHED_TEST_SASL_USERNAME");
3788 const char *pass
= getenv("LIBMEMCACHED_TEST_SASL_PASSWORD");
3790 if (server
and user
and pass
)
3792 memcached_server_st
*servers
= memcached_servers_parse(server
);
3794 memcached_servers_reset(memc
);
3795 test_true(memcached_server_push(memc
, servers
) == MEMCACHED_SUCCESS
);
3796 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3797 rc
= memcached_set_sasl_auth_data(memc
, user
, pass
);
3798 test_compare(MEMCACHED_SUCCESS
, rc
);
3804 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3807 static test_return_t
pre_replication(memcached_st
*memc
)
3809 test_skip(TEST_SUCCESS
, pre_binary(memc
));
3812 * Make sure that we store the item on all servers
3813 * (master + replicas == number of servers)
3815 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
,
3816 memcached_server_count(memc
) - 1);
3817 test_compare(MEMCACHED_SUCCESS
, rc
);
3818 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
) == memcached_server_count(memc
) - 1);
3820 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3824 static test_return_t
pre_replication_noblock(memcached_st
*memc
)
3826 test_skip(TEST_SUCCESS
, pre_replication(memc
));
3828 return pre_nonblock(memc
);
3832 static void my_free(const memcached_st
*ptr
, void *mem
, void *context
)
3836 #ifdef HARD_MALLOC_TESTS
3837 void *real_ptr
= (mem
== NULL
) ? mem
: (void*)((caddr_t
)mem
- 8);
3845 static void *my_malloc(const memcached_st
*ptr
, const size_t size
, void *context
)
3849 #ifdef HARD_MALLOC_TESTS
3850 void *ret
= malloc(size
+ 8);
3853 ret
= (void*)((caddr_t
)ret
+ 8);
3856 void *ret
= malloc(size
);
3861 memset(ret
, 0xff, size
);
3868 static void *my_realloc(const memcached_st
*ptr
, void *mem
, const size_t size
, void *)
3870 #ifdef HARD_MALLOC_TESTS
3871 void *real_ptr
= (mem
== NULL
) ? NULL
: (void*)((caddr_t
)mem
- 8);
3872 void *nmem
= realloc(real_ptr
, size
+ 8);
3877 ret
= (void*)((caddr_t
)nmem
+ 8);
3883 return realloc(mem
, size
);
3888 static void *my_calloc(const memcached_st
*ptr
, size_t nelem
, const size_t size
, void *)
3890 #ifdef HARD_MALLOC_TESTS
3891 void *mem
= my_malloc(ptr
, nelem
* size
);
3894 memset(mem
, 0, nelem
* size
);
3900 return calloc(nelem
, size
);
3904 static test_return_t
set_prefix(memcached_st
*memc
)
3906 memcached_return_t rc
;
3907 const char *key
= "mine";
3910 /* Make sure be default none exists */
3911 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3912 test_compare_got(MEMCACHED_FAILURE
, rc
, memcached_strerror(NULL
, rc
));
3914 /* Test a clean set */
3915 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3916 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_last_error_message(memc
));
3918 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3920 test_memcmp(value
, key
, 4);
3921 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
3923 /* Test that we can turn it off */
3924 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3925 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
3927 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3929 test_compare_got(MEMCACHED_FAILURE
, rc
, memcached_strerror(NULL
, rc
));
3931 /* Now setup for main test */
3932 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)key
);
3933 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
3935 value
= (char *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3937 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
3938 test_memcmp(value
, key
, 4);
3940 /* Set to Zero, and then Set to something too large */
3943 memset(long_key
, 0, 255);
3945 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, NULL
);
3946 test_compare(MEMCACHED_SUCCESS
, rc
);
3948 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, &rc
);
3950 test_true(rc
== MEMCACHED_FAILURE
);
3951 test_true(value
== NULL
);
3953 /* Test a long key for failure */
3954 /* TODO, extend test to determine based on setting, what result should be */
3955 strncpy(long_key
, "Thisismorethentheallottednumberofcharacters", sizeof(long_key
));
3956 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
);
3957 //test_compare(MEMCACHED_BAD_KEY_PROVIDED, rc);
3958 test_compare(MEMCACHED_SUCCESS
, rc
);
3960 /* Now test a key with spaces (which will fail from long key, since bad key is not set) */
3961 strncpy(long_key
, "This is more then the allotted number of characters", sizeof(long_key
));
3962 test_compare(MEMCACHED_BAD_KEY_PROVIDED
,
3963 memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
));
3965 /* Test for a bad prefix, but with a short key */
3966 test_compare(MEMCACHED_SUCCESS
,
3967 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, 1));
3969 strncpy(long_key
, "dog cat", sizeof(long_key
));
3970 test_compare(MEMCACHED_BAD_KEY_PROVIDED
,
3971 memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, long_key
));
3974 return TEST_SUCCESS
;
3978 #ifdef MEMCACHED_ENABLE_DEPRECATED
3979 static test_return_t
deprecated_set_memory_alloc(memcached_st
*memc
)
3981 void *test_ptr
= NULL
;
3984 memcached_malloc_fn malloc_cb
=
3985 (memcached_malloc_fn
)my_malloc
;
3986 cb_ptr
= *(void **)&malloc_cb
;
3987 memcached_return_t rc
;
3989 test_compare(MEMCACHED_SUCCESS
,
3990 memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, cb_ptr
));
3991 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
3992 test_compare(MEMCACHED_SUCCESS
, rc
);
3993 test_true(test_ptr
== cb_ptr
);
3997 memcached_realloc_fn realloc_cb
=
3998 (memcached_realloc_fn
)my_realloc
;
3999 cb_ptr
= *(void **)&realloc_cb
;
4000 memcached_return_t rc
;
4002 test_compare(MEMCACHED_SUCCESS
,
4003 memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, cb_ptr
));
4004 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
4005 test_compare(MEMCACHED_SUCCESS
, rc
);
4006 test_true(test_ptr
== cb_ptr
);
4010 memcached_free_fn free_cb
=
4011 (memcached_free_fn
)my_free
;
4012 cb_ptr
= *(void **)&free_cb
;
4013 memcached_return_t rc
;
4015 test_compare(MEMCACHED_SUCCESS
,
4016 memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, cb_ptr
));
4017 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
4018 test_compare(MEMCACHED_SUCCESS
, rc
);
4019 test_true(test_ptr
== cb_ptr
);
4022 return TEST_SUCCESS
;
4027 static test_return_t
set_memory_alloc(memcached_st
*memc
)
4029 test_compare(MEMCACHED_FAILURE
,
4030 memcached_set_memory_allocators(memc
, NULL
, my_free
,
4031 my_realloc
, my_calloc
, NULL
));
4033 test_compare(MEMCACHED_SUCCESS
,
4034 memcached_set_memory_allocators(memc
, my_malloc
, my_free
,
4035 my_realloc
, my_calloc
, NULL
));
4037 memcached_malloc_fn mem_malloc
;
4038 memcached_free_fn mem_free
;
4039 memcached_realloc_fn mem_realloc
;
4040 memcached_calloc_fn mem_calloc
;
4041 memcached_get_memory_allocators(memc
, &mem_malloc
, &mem_free
,
4042 &mem_realloc
, &mem_calloc
);
4044 test_true(mem_malloc
== my_malloc
);
4045 test_true(mem_realloc
== my_realloc
);
4046 test_true(mem_calloc
== my_calloc
);
4047 test_true(mem_free
== my_free
);
4049 return TEST_SUCCESS
;
4052 static test_return_t
enable_consistent_crc(memcached_st
*memc
)
4055 memcached_server_distribution_t value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
4056 memcached_hash_t hash
;
4057 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
4058 if ((rc
= pre_crc(memc
)) != TEST_SUCCESS
)
4061 value
= (memcached_server_distribution_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
4062 test_true(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
4064 hash
= (memcached_hash_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
4066 if (hash
!= MEMCACHED_HASH_CRC
)
4067 return TEST_SKIPPED
;
4069 return TEST_SUCCESS
;
4072 static test_return_t
enable_consistent_hsieh(memcached_st
*memc
)
4075 memcached_server_distribution_t value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
4076 memcached_hash_t hash
;
4077 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
4078 if ((rc
= pre_hsieh(memc
)) != TEST_SUCCESS
)
4081 value
= (memcached_server_distribution_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
4082 test_true(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
4084 hash
= (memcached_hash_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
4086 if (hash
!= MEMCACHED_HASH_HSIEH
)
4087 return TEST_SKIPPED
;
4090 return TEST_SUCCESS
;
4093 static test_return_t
enable_cas(memcached_st
*memc
)
4095 unsigned int set
= 1;
4097 if (libmemcached_util_version_check(memc
, 1, 2, 4))
4099 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
4101 return TEST_SUCCESS
;
4104 return TEST_SKIPPED
;
4107 static test_return_t
check_for_1_2_3(memcached_st
*memc
)
4109 memcached_version(memc
);
4111 memcached_server_instance_st instance
=
4112 memcached_server_instance_by_position(memc
, 0);
4114 if ((instance
->major_version
>= 1 && (instance
->minor_version
== 2 && instance
->micro_version
>= 4))
4115 || instance
->minor_version
> 2)
4117 return TEST_SUCCESS
;
4120 return TEST_SKIPPED
;
4123 static test_return_t
pre_unix_socket(memcached_st
*memc
)
4125 memcached_return_t rc
;
4128 memcached_servers_reset(memc
);
4130 if (stat("/tmp/memcached.socket", &buf
))
4131 return TEST_SKIPPED
;
4133 rc
= memcached_server_add_unix_socket_with_weight(memc
, "/tmp/memcached.socket", 0);
4135 return ( rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_FAILURE
);
4138 static test_return_t
pre_nodelay(memcached_st
*memc
)
4140 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
4141 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
4143 return TEST_SUCCESS
;
4146 static test_return_t
pre_settimer(memcached_st
*memc
)
4148 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
4149 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
4151 return TEST_SUCCESS
;
4154 static test_return_t
poll_timeout(memcached_st
*memc
)
4156 size_t timeout
= 100; // Not using, just checking that it sets
4158 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
4160 timeout
= (size_t)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
4162 test_compare(100, timeout
);
4164 return TEST_SUCCESS
;
4167 static test_return_t
noreply_test(memcached_st
*memc
)
4169 memcached_return_t ret
;
4170 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
4171 test_true(ret
== MEMCACHED_SUCCESS
);
4172 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4173 test_true(ret
== MEMCACHED_SUCCESS
);
4174 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
4175 test_true(ret
== MEMCACHED_SUCCESS
);
4176 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NOREPLY
) == 1);
4177 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
) == 1);
4178 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
) == 1);
4180 for (int count
=0; count
< 5; ++count
)
4182 for (size_t x
= 0; x
< 100; ++x
)
4185 int check_length
= (size_t)snprintf(key
, sizeof(key
), "%lu", (unsigned long)x
);
4186 test_false((size_t)check_length
>= sizeof(key
) || check_length
< 0);
4188 size_t len
= (size_t)check_length
;
4193 ret
= memcached_add(memc
, key
, len
, key
, len
, 0, 0);
4196 ret
= memcached_replace(memc
, key
, len
, key
, len
, 0, 0);
4199 ret
= memcached_set(memc
, key
, len
, key
, len
, 0, 0);
4202 ret
= memcached_append(memc
, key
, len
, key
, len
, 0, 0);
4205 ret
= memcached_prepend(memc
, key
, len
, key
, len
, 0, 0);
4211 test_true(ret
== MEMCACHED_SUCCESS
|| ret
== MEMCACHED_BUFFERED
);
4215 ** NOTE: Don't ever do this in your code! this is not a supported use of the
4216 ** API and is _ONLY_ done this way to verify that the library works the
4217 ** way it is supposed to do!!!!
4220 for (uint32_t x
= 0; x
< memcached_server_count(memc
); ++x
)
4222 memcached_server_instance_st instance
=
4223 memcached_server_instance_by_position(memc
, x
);
4224 no_msg
+=(int)(instance
->cursor_active
);
4227 test_true(no_msg
== 0);
4228 test_true(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
4231 ** Now validate that all items was set properly!
4233 for (size_t x
= 0; x
< 100; ++x
)
4237 int check_length
= (size_t)snprintf(key
, sizeof(key
), "%lu", (unsigned long)x
);
4239 test_false((size_t)check_length
>= sizeof(key
) || check_length
< 0);
4241 size_t len
= (size_t)check_length
;
4244 char* value
=memcached_get(memc
, key
, strlen(key
),
4245 &length
, &flags
, &ret
);
4246 test_true(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
4249 case 0: /* FALLTHROUGH */
4250 case 1: /* FALLTHROUGH */
4252 test_true(strncmp(value
, key
, len
) == 0);
4253 test_true(len
== length
);
4256 test_true(length
== len
* 2);
4259 test_true(length
== len
* 3);
4269 /* Try setting an illegal cas value (should not return an error to
4270 * the caller (because we don't expect a return message from the server)
4272 const char* keys
[]= {"0"};
4273 size_t lengths
[]= {1};
4276 memcached_result_st results_obj
;
4277 memcached_result_st
*results
;
4278 ret
= memcached_mget(memc
, keys
, lengths
, 1);
4279 test_true(ret
== MEMCACHED_SUCCESS
);
4281 results
= memcached_result_create(memc
, &results_obj
);
4283 results
= memcached_fetch_result(memc
, &results_obj
, &ret
);
4285 test_true(ret
== MEMCACHED_SUCCESS
);
4286 uint64_t cas
= memcached_result_cas(results
);
4287 memcached_result_free(&results_obj
);
4289 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
4290 test_true(ret
== MEMCACHED_SUCCESS
);
4293 * The item will have a new cas value, so try to set it again with the old
4294 * value. This should fail!
4296 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
4297 test_true(ret
== MEMCACHED_SUCCESS
);
4298 test_true(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
4299 char* value
=memcached_get(memc
, keys
[0], lengths
[0], &length
, &flags
, &ret
);
4300 test_true(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
4303 return TEST_SUCCESS
;
4306 static test_return_t
analyzer_test(memcached_st
*memc
)
4308 memcached_return_t rc
;
4309 memcached_stat_st
*memc_stat
;
4310 memcached_analysis_st
*report
;
4312 memc_stat
= memcached_stat(memc
, NULL
, &rc
);
4313 test_compare(MEMCACHED_SUCCESS
, rc
);
4314 test_true(memc_stat
);
4316 report
= memcached_analyze(memc
, memc_stat
, &rc
);
4317 test_compare(MEMCACHED_SUCCESS
, rc
);
4321 memcached_stat_free(NULL
, memc_stat
);
4323 return TEST_SUCCESS
;
4326 /* Count the objects */
4327 static memcached_return_t
callback_dump_counter(const memcached_st
*ptr
,
4332 (void)ptr
; (void)key
; (void)key_length
;
4333 size_t *counter
= (size_t *)context
;
4335 *counter
= *counter
+ 1;
4337 return MEMCACHED_SUCCESS
;
4340 static test_return_t
dump_test(memcached_st
*memc
)
4343 memcached_dump_fn callbacks
[1];
4345 callbacks
[0]= &callback_dump_counter
;
4347 /* No support for Binary protocol yet */
4348 test_skip(false, memc
->flags
.binary_protocol
);
4350 test_compare(TEST_SUCCESS
, set_test3(memc
));
4352 test_compare(MEMCACHED_SUCCESS
,
4353 memcached_dump(memc
, callbacks
, (void *)&counter
, 1));
4355 /* We may have more then 32 if our previous flush has not completed */
4356 test_true(counter
>= 32);
4358 return TEST_SUCCESS
;
4361 #ifdef HAVE_LIBMEMCACHEDUTIL
4363 struct test_pool_context_st
{
4364 memcached_pool_st
* pool
;
4368 static void* connection_release(void *arg
)
4370 test_pool_context_st
*resource
= static_cast<test_pool_context_st
*>(arg
);
4373 // Release all of the memc we are holding
4374 assert(memcached_success(memcached_pool_push(resource
->pool
, resource
->mmc
)));
4378 #define POOL_SIZE 10
4379 static test_return_t
connection_pool_test(memcached_st
*memc
)
4381 memcached_pool_st
* pool
= memcached_pool_create(memc
, 5, POOL_SIZE
);
4382 test_true(pool
!= NULL
);
4383 memcached_st
*mmc
[POOL_SIZE
];
4384 memcached_return_t rc
;
4386 // Fill up our array that we will store the memc that are in the pool
4387 for (size_t x
= 0; x
< POOL_SIZE
; ++x
)
4389 mmc
[x
]= memcached_pool_pop(pool
, false, &rc
);
4390 test_true(mmc
[x
] != NULL
);
4391 test_compare(MEMCACHED_SUCCESS
, rc
);
4394 // All memc should be gone
4395 test_true(memcached_pool_pop(pool
, false, &rc
) == NULL
);
4396 test_compare(MEMCACHED_SUCCESS
, rc
);
4399 test_pool_context_st item
= { pool
, mmc
[9] };
4401 pthread_create(&tid
, NULL
, connection_release
, &item
);
4402 mmc
[9]= memcached_pool_pop(pool
, true, &rc
);
4403 test_compare(MEMCACHED_SUCCESS
, rc
);
4404 pthread_join(tid
, NULL
);
4406 const char *key
= "key";
4407 size_t keylen
= strlen(key
);
4409 // verify that I can do ops with all connections
4410 test_compare(MEMCACHED_SUCCESS
,
4411 memcached_set(mmc
[0], key
, keylen
, "0", 1, 0, 0));
4413 for (size_t x
= 0; x
< POOL_SIZE
; ++x
)
4415 uint64_t number_value
;
4416 test_compare(MEMCACHED_SUCCESS
,
4417 memcached_increment(mmc
[x
], key
, keylen
, 1, &number_value
));
4418 test_compare(number_value
, (x
+1));
4422 for (size_t x
= 0; x
< POOL_SIZE
; ++x
)
4424 test_compare(MEMCACHED_SUCCESS
, memcached_pool_push(pool
, mmc
[x
]));
4428 /* verify that I can set behaviors on the pool when I don't have all
4429 * of the connections in the pool. It should however be enabled
4430 * when I push the item into the pool
4432 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
4435 rc
= memcached_pool_behavior_set(pool
, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
, 9999);
4436 test_compare(MEMCACHED_SUCCESS
, rc
);
4438 mmc
[1]= memcached_pool_pop(pool
, false, &rc
);
4441 test_compare(9999, memcached_behavior_get(mmc
[1], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
));
4442 test_compare(MEMCACHED_SUCCESS
, memcached_pool_push(pool
, mmc
[1]));
4443 test_compare(MEMCACHED_SUCCESS
, memcached_pool_push(pool
, mmc
[0]));
4445 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
4446 test_compare(9999, memcached_behavior_get(mmc
[0], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
));
4447 test_compare(MEMCACHED_SUCCESS
, memcached_pool_push(pool
, mmc
[0]));
4449 test_true(memcached_pool_destroy(pool
) == memc
);
4451 return TEST_SUCCESS
;
4454 static test_return_t
util_version_test(memcached_st
*memc
)
4456 bool if_successful
= libmemcached_util_version_check(memc
, 0, 0, 0);
4457 test_true(if_successful
);
4459 if_successful
= libmemcached_util_version_check(memc
, 9, 9, 9);
4461 // We expect failure
4464 fprintf(stderr
, "\n----------------------------------------------------------------------\n");
4465 fprintf(stderr
, "\nDumping Server Information\n\n");
4466 memcached_server_fn callbacks
[1];
4468 callbacks
[0]= dump_server_information
;
4469 memcached_server_cursor(memc
, callbacks
, (void *)stderr
, 1);
4470 fprintf(stderr
, "\n----------------------------------------------------------------------\n");
4472 test_true(if_successful
== false);
4474 memcached_server_instance_st instance
=
4475 memcached_server_instance_by_position(memc
, 0);
4477 memcached_version(memc
);
4479 // We only use one binary when we test, so this should be just fine.
4480 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, instance
->minor_version
, instance
->micro_version
);
4481 test_true(if_successful
== true);
4483 if (instance
->micro_version
> 0)
4484 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, instance
->minor_version
, (uint8_t)(instance
->micro_version
-1));
4485 else if (instance
->minor_version
> 0)
4486 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, (uint8_t)(instance
->minor_version
- 1), instance
->micro_version
);
4487 else if (instance
->major_version
> 0)
4488 if_successful
= libmemcached_util_version_check(memc
, (uint8_t)(instance
->major_version
-1), instance
->minor_version
, instance
->micro_version
);
4490 test_true(if_successful
== true);
4492 if (instance
->micro_version
> 0)
4493 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, instance
->minor_version
, (uint8_t)(instance
->micro_version
+1));
4494 else if (instance
->minor_version
> 0)
4495 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, (uint8_t)(instance
->minor_version
+1), instance
->micro_version
);
4496 else if (instance
->major_version
> 0)
4497 if_successful
= libmemcached_util_version_check(memc
, (uint8_t)(instance
->major_version
+1), instance
->minor_version
, instance
->micro_version
);
4499 test_true(if_successful
== false);
4501 return TEST_SUCCESS
;
4504 static test_return_t
ping_test(memcached_st
*memc
)
4506 memcached_return_t rc
;
4507 memcached_server_instance_st instance
=
4508 memcached_server_instance_by_position(memc
, 0);
4510 // Test both the version that returns a code, and the one that does not.
4511 test_true(libmemcached_util_ping(memcached_server_name(instance
),
4512 memcached_server_port(instance
), NULL
));
4514 test_true(libmemcached_util_ping(memcached_server_name(instance
),
4515 memcached_server_port(instance
), &rc
));
4517 test_compare(MEMCACHED_SUCCESS
, rc
);
4519 return TEST_SUCCESS
;
4525 static test_return_t
hash_sanity_test (memcached_st
*memc
)
4529 assert(MEMCACHED_HASH_DEFAULT
== MEMCACHED_HASH_DEFAULT
);
4530 assert(MEMCACHED_HASH_MD5
== MEMCACHED_HASH_MD5
);
4531 assert(MEMCACHED_HASH_CRC
== MEMCACHED_HASH_CRC
);
4532 assert(MEMCACHED_HASH_FNV1_64
== MEMCACHED_HASH_FNV1_64
);
4533 assert(MEMCACHED_HASH_FNV1A_64
== MEMCACHED_HASH_FNV1A_64
);
4534 assert(MEMCACHED_HASH_FNV1_32
== MEMCACHED_HASH_FNV1_32
);
4535 assert(MEMCACHED_HASH_FNV1A_32
== MEMCACHED_HASH_FNV1A_32
);
4536 #ifdef HAVE_HSIEH_HASH
4537 assert(MEMCACHED_HASH_HSIEH
== MEMCACHED_HASH_HSIEH
);
4539 assert(MEMCACHED_HASH_MURMUR
== MEMCACHED_HASH_MURMUR
);
4540 assert(MEMCACHED_HASH_JENKINS
== MEMCACHED_HASH_JENKINS
);
4541 assert(MEMCACHED_HASH_MAX
== MEMCACHED_HASH_MAX
);
4543 return TEST_SUCCESS
;
4547 static test_return_t
hsieh_avaibility_test (memcached_st
*memc
)
4549 memcached_return_t expected_rc
= MEMCACHED_INVALID_ARGUMENTS
;
4550 #ifdef HAVE_HSIEH_HASH
4551 expected_rc
= MEMCACHED_SUCCESS
;
4553 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
,
4554 (uint64_t)MEMCACHED_HASH_HSIEH
);
4555 test_true(rc
== expected_rc
);
4557 return TEST_SUCCESS
;
4560 static test_return_t
murmur_avaibility_test (memcached_st
*memc
)
4562 memcached_return_t expected_rc
= MEMCACHED_INVALID_ARGUMENTS
;
4563 #ifdef HAVE_MURMUR_HASH
4564 expected_rc
= MEMCACHED_SUCCESS
;
4566 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
,
4567 (uint64_t)MEMCACHED_HASH_MURMUR
);
4568 test_true(rc
== expected_rc
);
4570 return TEST_SUCCESS
;
4573 static test_return_t
one_at_a_time_run (memcached_st
*memc
)
4579 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4583 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_DEFAULT
);
4584 test_true(one_at_a_time_values
[x
] == hash_val
);
4587 return TEST_SUCCESS
;
4590 static test_return_t
md5_run (memcached_st
*memc
)
4596 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4600 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MD5
);
4601 test_true(md5_values
[x
] == hash_val
);
4604 return TEST_SUCCESS
;
4607 static test_return_t
crc_run (memcached_st
*memc
)
4613 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4617 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_CRC
);
4618 test_true(crc_values
[x
] == hash_val
);
4621 return TEST_SUCCESS
;
4624 static test_return_t
fnv1_64_run (memcached_st
*memc
)
4630 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4634 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_64
);
4635 test_true(fnv1_64_values
[x
] == hash_val
);
4638 return TEST_SUCCESS
;
4641 static test_return_t
fnv1a_64_run (memcached_st
*memc
)
4647 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4651 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_64
);
4652 test_true(fnv1a_64_values
[x
] == hash_val
);
4655 return TEST_SUCCESS
;
4658 static test_return_t
fnv1_32_run (memcached_st
*memc
)
4664 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4668 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_32
);
4669 test_true(fnv1_32_values
[x
] == hash_val
);
4672 return TEST_SUCCESS
;
4675 static test_return_t
fnv1a_32_run (memcached_st
*memc
)
4681 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4685 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_32
);
4686 test_true(fnv1a_32_values
[x
] == hash_val
);
4689 return TEST_SUCCESS
;
4692 static test_return_t
hsieh_run (memcached_st
*memc
)
4698 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4702 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_HSIEH
);
4703 test_true(hsieh_values
[x
] == hash_val
);
4706 return TEST_SUCCESS
;
4709 static test_return_t
murmur_run (memcached_st
*memc
)
4711 #ifdef WORDS_BIGENDIAN
4712 (void)murmur_values
;
4713 return TEST_SKIPPED
;
4719 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4723 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MURMUR
);
4724 test_true(murmur_values
[x
] == hash_val
);
4727 return TEST_SUCCESS
;
4731 static test_return_t
jenkins_run (memcached_st
*memc
)
4737 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4741 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_JENKINS
);
4742 test_true(jenkins_values
[x
] == hash_val
);
4745 return TEST_SUCCESS
;
4748 static uint32_t hash_md5_test_function(const char *string
, size_t string_length
, void *context
)
4751 return libhashkit_md5(string
, string_length
);
4754 static uint32_t hash_crc_test_function(const char *string
, size_t string_length
, void *context
)
4757 return libhashkit_crc32(string
, string_length
);
4760 static test_return_t
memcached_get_hashkit_test (memcached_st
*memc
)
4764 const hashkit_st
*kit
;
4766 hashkit_return_t hash_rc
;
4768 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};
4769 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};
4771 kit
= memcached_get_hashkit(memc
);
4773 hashkit_clone(&new_kit
, kit
);
4774 hash_rc
= hashkit_set_custom_function(&new_kit
, hash_md5_test_function
, NULL
);
4775 test_true(hash_rc
== HASHKIT_SUCCESS
);
4777 memcached_set_hashkit(memc
, &new_kit
);
4780 Verify Setting the hash.
4782 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4786 hash_val
= hashkit_digest(kit
, *ptr
, strlen(*ptr
));
4787 test_true(md5_values
[x
] == hash_val
);
4792 Now check memcached_st.
4794 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4798 hash_val
= memcached_generate_hash(memc
, *ptr
, strlen(*ptr
));
4799 test_true(md5_hosts
[x
] == hash_val
);
4802 hash_rc
= hashkit_set_custom_function(&new_kit
, hash_crc_test_function
, NULL
);
4803 test_true(hash_rc
== HASHKIT_SUCCESS
);
4805 memcached_set_hashkit(memc
, &new_kit
);
4808 Verify Setting the hash.
4810 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4814 hash_val
= hashkit_digest(kit
, *ptr
, strlen(*ptr
));
4815 test_true(crc_values
[x
] == hash_val
);
4818 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4822 hash_val
= memcached_generate_hash(memc
, *ptr
, strlen(*ptr
));
4823 test_true(crc_hosts
[x
] == hash_val
);
4826 return TEST_SUCCESS
;
4830 Test case adapted from John Gorman <johngorman2@gmail.com>
4832 We are testing the error condition when we connect to a server via memcached_get()
4833 but find that the server is not available.
4835 static test_return_t
memcached_get_MEMCACHED_ERRNO(memcached_st
*memc
)
4838 memcached_st
*tl_memc_h
;
4840 const char *key
= "MemcachedLives";
4843 memcached_return rc
;
4847 tl_memc_h
= memcached_create(NULL
);
4848 memcached_server_st
*servers
= memcached_servers_parse("localhost:9898,localhost:9899"); // This server should not exist
4850 memcached_server_push(tl_memc_h
, servers
);
4851 memcached_server_list_free(servers
);
4853 // See if memcached is reachable.
4854 value
= memcached_get(tl_memc_h
, key
, strlen(key
), &len
, &flags
, &rc
);
4857 test_compare(0, len
);
4858 test_true(memcached_failed(rc
));
4860 memcached_free(tl_memc_h
);
4862 return TEST_SUCCESS
;
4866 We connect to a server which exists, but search for a key that does not exist.
4868 static test_return_t
memcached_get_MEMCACHED_NOTFOUND(memcached_st
*memc
)
4870 const char *key
= "MemcachedKeyNotEXIST";
4873 memcached_return rc
;
4876 // See if memcached is reachable.
4877 value
= memcached_get(memc
, key
, strlen(key
), &len
, &flags
, &rc
);
4880 test_compare(0, len
);
4881 test_compare(MEMCACHED_NOTFOUND
, rc
);
4883 return TEST_SUCCESS
;
4887 Test case adapted from John Gorman <johngorman2@gmail.com>
4889 We are testing the error condition when we connect to a server via memcached_get_by_key()
4890 but find that the server is not available.
4892 static test_return_t
memcached_get_by_key_MEMCACHED_ERRNO(memcached_st
*memc
)
4895 memcached_st
*tl_memc_h
;
4896 memcached_server_st
*servers
;
4898 const char *key
= "MemcachedLives";
4901 memcached_return rc
;
4905 tl_memc_h
= memcached_create(NULL
);
4906 servers
= memcached_servers_parse("localhost:9898,localhost:9899"); // This server should not exist
4907 memcached_server_push(tl_memc_h
, servers
);
4908 memcached_server_list_free(servers
);
4910 // See if memcached is reachable.
4911 value
= memcached_get_by_key(tl_memc_h
, key
, strlen(key
), key
, strlen(key
), &len
, &flags
, &rc
);
4914 test_compare(0, len
);
4915 test_true(memcached_failed(rc
));
4917 memcached_free(tl_memc_h
);
4919 return TEST_SUCCESS
;
4923 We connect to a server which exists, but search for a key that does not exist.
4925 static test_return_t
memcached_get_by_key_MEMCACHED_NOTFOUND(memcached_st
*memc
)
4927 const char *key
= "MemcachedKeyNotEXIST";
4930 memcached_return rc
;
4933 // See if memcached is reachable.
4934 value
= memcached_get_by_key(memc
, key
, strlen(key
), key
, strlen(key
), &len
, &flags
, &rc
);
4937 test_compare(0, len
);
4938 test_compare(MEMCACHED_NOTFOUND
, rc
);
4940 return TEST_SUCCESS
;
4944 static test_return_t
ketama_compatibility_libmemcached(memcached_st
*)
4946 memcached_st
*memc
= memcached_create(NULL
);
4949 test_compare(MEMCACHED_SUCCESS
,
4950 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1));
4953 test_compare(1, value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
));
4955 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
));
4956 test_compare(MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
, memcached_behavior_get_distribution(memc
));
4959 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");
4960 memcached_server_push(memc
, server_pool
);
4962 /* verify that the server list was parsed okay. */
4963 test_compare(8, memcached_server_count(memc
));
4964 test_strcmp(server_pool
[0].hostname
, "10.0.1.1");
4965 test_compare(11211, server_pool
[0].port
);
4966 test_compare(600, server_pool
[0].weight
);
4967 test_strcmp(server_pool
[2].hostname
, "10.0.1.3");
4968 test_compare(11211, server_pool
[2].port
);
4969 test_compare(200, server_pool
[2].weight
);
4970 test_strcmp(server_pool
[7].hostname
, "10.0.1.8");
4971 test_compare(11211, server_pool
[7].port
);
4972 test_compare(100, server_pool
[7].weight
);
4974 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
4975 * us test the boundary wraparound.
4977 test_true(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->ketama
.continuum
[0].index
);
4979 /* verify the standard ketama set. */
4980 for (uint32_t x
= 0; x
< 99; x
++)
4982 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
4983 memcached_server_instance_st instance
=
4984 memcached_server_instance_by_position(memc
, server_idx
);
4985 const char *hostname
= memcached_server_name(instance
);
4987 test_strcmp(hostname
, ketama_test_cases
[x
].server
);
4990 memcached_server_list_free(server_pool
);
4991 memcached_free(memc
);
4993 return TEST_SUCCESS
;
4996 static test_return_t
ketama_compatibility_spymemcached(memcached_st
*)
5000 memcached_st
*memc
= memcached_create(NULL
);
5003 test_compare(MEMCACHED_SUCCESS
,
5004 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1));
5006 test_compare(1, value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
));
5008 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
));
5009 test_compare(MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
, memcached_behavior_get_distribution(memc
));
5011 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");
5012 test_true(server_pool
);
5013 memcached_server_push(memc
, server_pool
);
5015 /* verify that the server list was parsed okay. */
5016 test_compare(8, memcached_server_count(memc
));
5017 test_strcmp(server_pool
[0].hostname
, "10.0.1.1");
5018 test_compare(11211, server_pool
[0].port
);
5019 test_compare(600, server_pool
[0].weight
);
5020 test_strcmp(server_pool
[2].hostname
, "10.0.1.3");
5021 test_compare(11211, server_pool
[2].port
);
5022 test_compare(200, server_pool
[2].weight
);
5023 test_strcmp(server_pool
[7].hostname
, "10.0.1.8");
5024 test_compare(11211, server_pool
[7].port
);
5025 test_compare(100, server_pool
[7].weight
);
5027 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
5028 * us test the boundary wraparound.
5030 test_true(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->ketama
.continuum
[0].index
);
5032 /* verify the standard ketama set. */
5033 for (uint32_t x
= 0; x
< 99; x
++)
5035 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases_spy
[x
].key
, strlen(ketama_test_cases_spy
[x
].key
));
5037 memcached_server_instance_st instance
=
5038 memcached_server_instance_by_position(memc
, server_idx
);
5040 const char *hostname
= memcached_server_name(instance
);
5042 test_strcmp(hostname
, ketama_test_cases_spy
[x
].server
);
5045 memcached_server_list_free(server_pool
);
5046 memcached_free(memc
);
5048 return TEST_SUCCESS
;
5051 static test_return_t
regression_bug_434484(memcached_st
*memc
)
5053 test_return_t test_rc
;
5054 test_rc
= pre_binary(memc
);
5056 if (test_rc
!= TEST_SUCCESS
)
5059 const char *key
= "regression_bug_434484";
5060 size_t keylen
= strlen(key
);
5062 memcached_return_t ret
= memcached_append(memc
, key
, keylen
, key
, keylen
, 0, 0);
5063 test_compare(MEMCACHED_NOTSTORED
, ret
);
5065 size_t size
= 2048 * 1024;
5066 char *data
= (char*)calloc(1, size
);
5068 test_compare(MEMCACHED_E2BIG
,
5069 memcached_set(memc
, key
, keylen
, data
, size
, 0, 0));
5072 return TEST_SUCCESS
;
5075 static test_return_t
regression_bug_434843(memcached_st
*memc
)
5077 test_return_t test_rc
;
5078 test_rc
= pre_binary(memc
);
5080 if (test_rc
!= TEST_SUCCESS
)
5083 memcached_return_t rc
;
5085 memcached_execute_fn callbacks
[]= { &callback_counter
};
5088 * I only want to hit only _one_ server so I know the number of requests I'm
5089 * sending in the pipleine to the server. Let's try to do a multiget of
5090 * 1024 (that should satisfy most users don't you think?). Future versions
5091 * will include a mget_execute function call if you need a higher number.
5093 uint32_t number_of_hosts
= memcached_server_count(memc
);
5094 memc
->number_of_hosts
= 1;
5095 const size_t max_keys
= 1024;
5096 char **keys
= (char**)calloc(max_keys
, sizeof(char*));
5097 size_t *key_length
= (size_t *)calloc(max_keys
, sizeof(size_t));
5099 for (size_t x
= 0; x
< max_keys
; ++x
)
5103 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%lu", (unsigned long)x
);
5109 * Run two times.. the first time we should have 100% cache miss,
5110 * and the second time we should have 100% cache hits
5112 for (size_t y
= 0; y
< 2; y
++)
5114 test_compare(MEMCACHED_SUCCESS
,
5115 memcached_mget(memc
, (const char**)keys
, key_length
, max_keys
));
5117 test_compare(y
? MEMCACHED_SUCCESS
: MEMCACHED_NOTFOUND
,
5118 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
5122 /* The first iteration should give me a 100% cache miss. verify that*/
5123 char blob
[1024]= { 0 };
5125 test_false(counter
);
5127 for (size_t x
= 0; x
< max_keys
; ++x
)
5129 rc
= memcached_add(memc
, keys
[x
], key_length
[x
],
5130 blob
, sizeof(blob
), 0, 0);
5131 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5136 /* Verify that we received all of the key/value pairs */
5137 test_compare(counter
, max_keys
);
5141 /* Release allocated resources */
5142 for (size_t x
= 0; x
< max_keys
; ++x
)
5149 memc
->number_of_hosts
= number_of_hosts
;
5151 return TEST_SUCCESS
;
5154 static test_return_t
regression_bug_434843_buffered(memcached_st
*memc
)
5156 memcached_return_t rc
;
5157 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
5158 test_compare(MEMCACHED_SUCCESS
, rc
);
5160 return regression_bug_434843(memc
);
5163 static test_return_t
regression_bug_421108(memcached_st
*memc
)
5165 memcached_return_t rc
;
5166 memcached_stat_st
*memc_stat
= memcached_stat(memc
, NULL
, &rc
);
5167 test_compare(MEMCACHED_SUCCESS
, rc
);
5169 char *bytes_str
= memcached_stat_get_value(memc
, memc_stat
, "bytes", &rc
);
5170 test_compare(MEMCACHED_SUCCESS
, rc
);
5171 test_true(bytes_str
);
5172 char *bytes_read_str
= memcached_stat_get_value(memc
, memc_stat
,
5174 test_compare(MEMCACHED_SUCCESS
, rc
);
5175 test_true(bytes_read_str
);
5177 char *bytes_written_str
= memcached_stat_get_value(memc
, memc_stat
,
5178 "bytes_written", &rc
);
5179 test_compare(MEMCACHED_SUCCESS
, rc
);
5180 test_true(bytes_written_str
);
5182 unsigned long long bytes
= strtoull(bytes_str
, 0, 10);
5183 unsigned long long bytes_read
= strtoull(bytes_read_str
, 0, 10);
5184 unsigned long long bytes_written
= strtoull(bytes_written_str
, 0, 10);
5186 test_true(bytes
!= bytes_read
);
5187 test_true(bytes
!= bytes_written
);
5189 /* Release allocated resources */
5191 free(bytes_read_str
);
5192 free(bytes_written_str
);
5193 memcached_stat_free(NULL
, memc_stat
);
5195 return TEST_SUCCESS
;
5199 * The test case isn't obvious so I should probably document why
5200 * it works the way it does. Bug 442914 was caused by a bug
5201 * in the logic in memcached_purge (it did not handle the case
5202 * where the number of bytes sent was equal to the watermark).
5203 * In this test case, create messages so that we hit that case
5204 * and then disable noreply mode and issue a new command to
5205 * verify that it isn't stuck. If we change the format for the
5206 * delete command or the watermarks, we need to update this
5209 static test_return_t
regression_bug_442914(memcached_st
*memc
)
5211 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1));
5212 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1);
5214 uint32_t number_of_hosts
= memcached_server_count(memc
);
5215 memc
->number_of_hosts
= 1;
5220 for (uint32_t x
= 0; x
< 250; ++x
)
5222 len
= (size_t)snprintf(k
, sizeof(k
), "%0250u", x
);
5223 memcached_return_t rc
= memcached_delete(memc
, k
, len
, 0);
5224 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5227 (void)snprintf(k
, sizeof(k
), "%037u", 251U);
5230 memcached_return_t rc
= memcached_delete(memc
, k
, len
, 0);
5231 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5233 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0));
5234 test_compare(MEMCACHED_NOTFOUND
, memcached_delete(memc
, k
, len
, 0));
5236 memc
->number_of_hosts
= number_of_hosts
;
5238 return TEST_SUCCESS
;
5241 static test_return_t
regression_bug_447342(memcached_st
*memc
)
5243 memcached_server_instance_st instance_one
;
5244 memcached_server_instance_st instance_two
;
5246 if (memcached_server_count(memc
) < 3 or pre_replication(memc
) != TEST_SUCCESS
)
5247 return TEST_SKIPPED
;
5249 test_compare(MEMCACHED_SUCCESS
,
5250 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 2));
5252 const size_t max_keys
= 100;
5253 char **keys
= (char**)calloc(max_keys
, sizeof(char*));
5254 size_t *key_length
= (size_t *)calloc(max_keys
, sizeof(size_t));
5256 for (size_t x
= 0; x
< max_keys
; ++x
)
5260 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%lu", (unsigned long)x
);
5263 test_compare(MEMCACHED_SUCCESS
,
5264 memcached_set(memc
, k
, key_length
[x
], k
, key_length
[x
], 0, 0));
5268 ** We are using the quiet commands to store the replicas, so we need
5269 ** to ensure that all of them are processed before we can continue.
5270 ** In the test we go directly from storing the object to trying to
5271 ** receive the object from all of the different servers, so we
5272 ** could end up in a race condition (the memcached server hasn't yet
5273 ** processed the quiet command from the replication set when it process
5274 ** the request from the other client (created by the clone)). As a
5275 ** workaround for that we call memcached_quit to send the quit command
5276 ** to the server and wait for the response ;-) If you use the test code
5277 ** as an example for your own code, please note that you shouldn't need
5280 memcached_quit(memc
);
5282 /* Verify that all messages are stored, and we didn't stuff too much
5285 test_compare(MEMCACHED_SUCCESS
,
5286 memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
));
5289 memcached_execute_fn callbacks
[]= { &callback_counter
};
5290 memcached_return_t rc
;
5291 test_compare_got(MEMCACHED_SUCCESS
,
5292 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1),
5293 memcached_strerror(NULL
, rc
));
5295 /* Verify that we received all of the key/value pairs */
5296 test_compare(counter
, max_keys
);
5298 memcached_quit(memc
);
5300 * Don't do the following in your code. I am abusing the internal details
5301 * within the library, and this is not a supported interface.
5302 * This is to verify correct behavior in the library. Fake that two servers
5305 instance_one
= memcached_server_instance_by_position(memc
, 0);
5306 instance_two
= memcached_server_instance_by_position(memc
, 2);
5307 in_port_t port0
= instance_one
->port
;
5308 in_port_t port2
= instance_two
->port
;
5310 ((memcached_server_write_instance_st
)instance_one
)->port
= 0;
5311 ((memcached_server_write_instance_st
)instance_two
)->port
= 0;
5313 test_compare(MEMCACHED_SUCCESS
,
5314 memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
));
5317 test_compare(MEMCACHED_SUCCESS
,
5318 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
5319 test_compare(counter
, (unsigned int)max_keys
);
5321 /* restore the memc handle */
5322 ((memcached_server_write_instance_st
)instance_one
)->port
= port0
;
5323 ((memcached_server_write_instance_st
)instance_two
)->port
= port2
;
5325 memcached_quit(memc
);
5327 /* Remove half of the objects */
5328 for (size_t x
= 0; x
< max_keys
; ++x
)
5332 test_compare(MEMCACHED_SUCCESS
,
5333 memcached_delete(memc
, keys
[x
], key_length
[x
], 0));
5337 memcached_quit(memc
);
5338 ((memcached_server_write_instance_st
)instance_one
)->port
= 0;
5339 ((memcached_server_write_instance_st
)instance_two
)->port
= 0;
5341 /* now retry the command, this time we should have cache misses */
5342 test_compare(MEMCACHED_SUCCESS
,
5343 memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
));
5346 test_compare_got(MEMCACHED_SUCCESS
,
5347 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1),
5348 memcached_strerror(NULL
, rc
));
5349 test_compare(counter
, (unsigned int)(max_keys
>> 1));
5351 /* Release allocated resources */
5352 for (size_t x
= 0; x
< max_keys
; ++x
)
5359 /* restore the memc handle */
5360 ((memcached_server_write_instance_st
)instance_one
)->port
= port0
;
5361 ((memcached_server_write_instance_st
)instance_two
)->port
= port2
;
5363 return TEST_SUCCESS
;
5366 static test_return_t
regression_bug_463297(memcached_st
*memc
)
5368 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
5369 test_true(memc_clone
);
5370 test_true(memcached_version(memc_clone
) == MEMCACHED_SUCCESS
);
5372 memcached_server_instance_st instance
=
5373 memcached_server_instance_by_position(memc_clone
, 0);
5375 if (instance
->major_version
> 1 ||
5376 (instance
->major_version
== 1 &&
5377 instance
->minor_version
> 2))
5379 /* Binary protocol doesn't support deferred delete */
5380 memcached_st
*bin_clone
= memcached_clone(NULL
, memc
);
5381 test_true(bin_clone
);
5382 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(bin_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1));
5383 test_compare(MEMCACHED_INVALID_ARGUMENTS
, memcached_delete(bin_clone
, "foo", 3, 1));
5384 memcached_free(bin_clone
);
5386 memcached_quit(memc_clone
);
5388 /* If we know the server version, deferred delete should fail
5389 * with invalid arguments */
5390 test_compare(MEMCACHED_INVALID_ARGUMENTS
, memcached_delete(memc_clone
, "foo", 3, 1));
5392 /* If we don't know the server version, we should get a protocol error */
5393 memcached_return_t rc
= memcached_delete(memc
, "foo", 3, 1);
5395 /* but there is a bug in some of the memcached servers (1.4) that treats
5396 * the counter as noreply so it doesn't send the proper error message
5398 test_true_got(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
|| rc
== MEMCACHED_INVALID_ARGUMENTS
, memcached_strerror(NULL
, rc
));
5400 /* And buffered mode should be disabled and we should get protocol error */
5401 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1) == MEMCACHED_SUCCESS
);
5402 rc
= memcached_delete(memc
, "foo", 3, 1);
5403 test_true_got(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
|| rc
== MEMCACHED_INVALID_ARGUMENTS
, memcached_strerror(NULL
, rc
));
5405 /* Same goes for noreply... */
5406 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1));
5407 rc
= memcached_delete(memc
, "foo", 3, 1);
5408 test_true_got(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
|| rc
== MEMCACHED_INVALID_ARGUMENTS
, memcached_strerror(NULL
, rc
));
5410 /* but a normal request should go through (and be buffered) */
5411 test_compare(MEMCACHED_BUFFERED
, (rc
= memcached_delete(memc
, "foo", 3, 0)));
5412 test_compare(MEMCACHED_SUCCESS
, memcached_flush_buffers(memc
));
5414 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 0));
5415 /* unbuffered noreply should be success */
5416 test_compare(MEMCACHED_SUCCESS
, memcached_delete(memc
, "foo", 3, 0));
5417 /* unbuffered with reply should be not found... */
5418 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0));
5419 test_compare(MEMCACHED_NOTFOUND
, memcached_delete(memc
, "foo", 3, 0));
5422 memcached_free(memc_clone
);
5423 return TEST_SUCCESS
;
5427 /* Test memcached_server_get_last_disconnect
5428 * For a working server set, shall be NULL
5429 * For a set of non existing server, shall not be NULL
5431 static test_return_t
test_get_last_disconnect(memcached_st
*memc
)
5433 memcached_return_t rc
;
5434 memcached_server_instance_st disconnected_server
;
5436 /* With the working set of server */
5437 const char *key
= "marmotte";
5438 const char *value
= "milka";
5440 memcached_reset_last_disconnected_server(memc
);
5441 test_false(memc
->last_disconnected_server
);
5442 rc
= memcached_set(memc
, key
, strlen(key
),
5443 value
, strlen(value
),
5444 (time_t)0, (uint32_t)0);
5445 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5447 disconnected_server
= memcached_server_get_last_disconnect(memc
);
5448 test_false(disconnected_server
);
5450 /* With a non existing server */
5452 memcached_server_st
*servers
;
5454 const char *server_list
= "localhost:9";
5456 servers
= memcached_servers_parse(server_list
);
5458 mine
= memcached_create(NULL
);
5459 rc
= memcached_server_push(mine
, servers
);
5460 test_compare(MEMCACHED_SUCCESS
, rc
);
5461 memcached_server_list_free(servers
);
5464 rc
= memcached_set(mine
, key
, strlen(key
),
5465 value
, strlen(value
),
5466 (time_t)0, (uint32_t)0);
5467 test_true(memcached_failed(rc
));
5469 disconnected_server
= memcached_server_get_last_disconnect(mine
);
5470 test_true_got(disconnected_server
, memcached_strerror(mine
, rc
));
5471 test_compare(9, memcached_server_port(disconnected_server
));
5472 test_false(strncmp(memcached_server_name(disconnected_server
),"localhost",9));
5474 memcached_quit(mine
);
5475 memcached_free(mine
);
5477 return TEST_SUCCESS
;
5480 static test_return_t
test_multiple_get_last_disconnect(memcached_st
*)
5482 const char *server_string
= "--server=localhost:8888 --server=localhost:8889 --server=localhost:8890 --server=localhost:8891 --server=localhost:8892";
5483 char buffer
[BUFSIZ
];
5485 memcached_return_t rc
;
5486 test_compare_got(MEMCACHED_SUCCESS
,
5487 rc
= libmemcached_check_configuration(server_string
, strlen(server_string
), buffer
, sizeof(buffer
)),
5488 memcached_strerror(NULL
, rc
));
5490 memcached_st
*memc
= memcached(server_string
, strlen(server_string
));
5493 // We will just use the error strings as our keys
5494 uint32_t counter
= 100;
5497 for (int x
= int(MEMCACHED_SUCCESS
); x
< int(MEMCACHED_MAXIMUM_RETURN
); ++x
)
5499 const char *msg
= memcached_strerror(memc
, memcached_return_t(x
));
5500 memcached_return_t ret
= memcached_set(memc
, msg
, strlen(msg
), NULL
, 0, (time_t)0, (uint32_t)0);
5501 test_compare_got(MEMCACHED_CONNECTION_FAILURE
, ret
, memcached_last_error_message(memc
));
5503 memcached_server_instance_st disconnected_server
= memcached_server_get_last_disconnect(memc
);
5504 test_true(disconnected_server
);
5505 test_strcmp("localhost", memcached_server_name(disconnected_server
));
5506 test_true(memcached_server_port(disconnected_server
) >= 8888 and memcached_server_port(disconnected_server
) <= 8892);
5510 memcached_reset_last_disconnected_server(memc
);
5515 memcached_free(memc
);
5517 return TEST_SUCCESS
;
5520 static test_return_t
test_verbosity(memcached_st
*memc
)
5522 memcached_verbosity(memc
, 3);
5524 return TEST_SUCCESS
;
5527 static test_return_t
test_server_failure(memcached_st
*memc
)
5529 memcached_server_instance_st instance
= memcached_server_instance_by_position(memc
, 0);
5531 memcached_st
*local_memc
= memcached_create(NULL
);
5533 memcached_server_add(local_memc
, memcached_server_name(instance
), memcached_server_port(instance
));
5534 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, 2);
5536 uint32_t server_count
= memcached_server_count(local_memc
);
5537 test_compare(1, server_count
);
5539 // Disable the server
5540 instance
= memcached_server_instance_by_position(local_memc
, 0);
5541 ((memcached_server_write_instance_st
)instance
)->server_failure_counter
= 2;
5543 memcached_return_t rc
;
5544 test_compare_got(MEMCACHED_SERVER_MARKED_DEAD
,
5545 rc
= memcached_set(local_memc
, "foo", strlen("foo"), NULL
, 0, (time_t)0, (uint32_t)0),
5546 memcached_last_error_message(local_memc
));
5548 ((memcached_server_write_instance_st
)instance
)->server_failure_counter
= 0;
5549 test_compare_got(MEMCACHED_SUCCESS
,
5550 rc
= memcached_set(local_memc
, "foo", strlen("foo"), NULL
, 0, (time_t)0, (uint32_t)0),
5551 memcached_strerror(NULL
, rc
));
5553 memcached_last_error_message(local_memc
));
5557 memcached_free(local_memc
);
5559 return TEST_SUCCESS
;
5562 static test_return_t
test_cull_servers(memcached_st
*memc
)
5564 uint32_t count
= memcached_server_count(memc
);
5566 // Do not do this in your code, it is not supported.
5567 memc
->servers
[1].options
.is_dead
= true;
5568 memc
->state
.is_time_for_rebuild
= true;
5570 uint32_t new_count
= memcached_server_count(memc
);
5571 test_compare(count
, new_count
);
5574 test_true(count
== new_count
+ 1 );
5577 return TEST_SUCCESS
;
5581 static memcached_return_t
stat_printer(memcached_server_instance_st server
,
5582 const char *key
, size_t key_length
,
5583 const char *value
, size_t value_length
,
5593 return MEMCACHED_SUCCESS
;
5596 static test_return_t
memcached_stat_execute_test(memcached_st
*memc
)
5598 memcached_return_t rc
= memcached_stat_execute(memc
, NULL
, stat_printer
, NULL
);
5599 test_compare(MEMCACHED_SUCCESS
, rc
);
5601 rc
= memcached_stat_execute(memc
, "slabs", stat_printer
, NULL
);
5602 test_compare(MEMCACHED_SUCCESS
, rc
);
5604 rc
= memcached_stat_execute(memc
, "items", stat_printer
, NULL
);
5605 test_compare(MEMCACHED_SUCCESS
, rc
);
5607 rc
= memcached_stat_execute(memc
, "sizes", stat_printer
, NULL
);
5608 test_compare(MEMCACHED_SUCCESS
, rc
);
5610 return TEST_SUCCESS
;
5614 * This test ensures that the failure counter isn't incremented during
5615 * normal termination of the memcached instance.
5617 static test_return_t
wrong_failure_counter_test(memcached_st
*memc
)
5619 memcached_return_t rc
;
5620 memcached_server_instance_st instance
;
5622 /* Set value to force connection to the server */
5623 const char *key
= "marmotte";
5624 const char *value
= "milka";
5627 * Please note that I'm abusing the internal structures in libmemcached
5628 * in a non-portable way and you shouldn't be doing this. I'm only
5629 * doing this in order to verify that the library works the way it should
5631 uint32_t number_of_hosts
= memcached_server_count(memc
);
5632 memc
->number_of_hosts
= 1;
5634 /* Ensure that we are connected to the server by setting a value */
5635 rc
= memcached_set(memc
, key
, strlen(key
),
5636 value
, strlen(value
),
5637 (time_t)0, (uint32_t)0);
5638 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5641 instance
= memcached_server_instance_by_position(memc
, 0);
5642 /* The test is to see that the memcached_quit doesn't increase the
5643 * the server failure conter, so let's ensure that it is zero
5644 * before sending quit
5646 ((memcached_server_write_instance_st
)instance
)->server_failure_counter
= 0;
5648 memcached_quit(memc
);
5650 /* Verify that it memcached_quit didn't increment the failure counter
5651 * Please note that this isn't bullet proof, because an error could
5654 test_compare(0, instance
->server_failure_counter
);
5656 /* restore the instance */
5657 memc
->number_of_hosts
= number_of_hosts
;
5659 return TEST_SUCCESS
;
5663 * This tests ensures expected disconnections (for some behavior changes
5664 * for instance) do not wrongly increase failure counter
5666 static test_return_t
wrong_failure_counter_two_test(memcached_st
*memc
)
5668 memcached_return rc
;
5670 memcached_st
*memc_clone
;
5671 memc_clone
= memcached_clone(NULL
, memc
);
5672 test_true(memc_clone
);
5674 /* Set value to force connection to the server */
5675 const char *key
= "marmotte";
5676 const char *value
= "milka";
5677 char *string
= NULL
;
5678 size_t string_length
;
5681 rc
= memcached_set(memc_clone
, key
, strlen(key
),
5682 value
, strlen(value
),
5683 (time_t)0, (uint32_t)0);
5684 test_true_got(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
, memcached_strerror(NULL
, rc
));
5687 /* put failure limit to 1 */
5688 test_compare(MEMCACHED_SUCCESS
,
5689 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, 1));
5691 /* Put a retry timeout to effectively activate failure_limit effect */
5692 test_compare(MEMCACHED_SUCCESS
,
5693 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 1));
5695 /* change behavior that triggers memcached_quit()*/
5696 test_compare(MEMCACHED_SUCCESS
,
5697 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1));
5700 /* Check if we still are connected */
5701 string
= memcached_get(memc_clone
, key
, strlen(key
),
5702 &string_length
, &flags
, &rc
);
5704 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
5707 memcached_free(memc_clone
);
5709 return TEST_SUCCESS
;
5716 * Test that ensures mget_execute does not end into recursive calls that finally fails
5718 static test_return_t
regression_bug_490486(memcached_st
*memc
)
5720 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
5721 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 1);
5722 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, 1000);
5723 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, 1);
5724 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 3600);
5727 return TEST_SKIPPED
; // My MAC can't handle this test
5731 * I only want to hit _one_ server so I know the number of requests I'm
5732 * sending in the pipeline.
5734 uint32_t number_of_hosts
= memc
->number_of_hosts
;
5735 memc
->number_of_hosts
= 1;
5736 size_t max_keys
= 20480;
5739 char **keys
= (char **)calloc(max_keys
, sizeof(char*));
5740 size_t *key_length
= (size_t *)calloc(max_keys
, sizeof(size_t));
5742 /* First add all of the items.. */
5743 char blob
[1024]= { 0 };
5744 for (size_t x
= 0; x
< max_keys
; ++x
)
5747 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%lu", (unsigned long)x
);
5750 memcached_return rc
= memcached_set(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
5751 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
); // MEMCACHED_TIMEOUT <-- hash been observed on OSX
5756 /* Try to get all of them with a large multiget */
5758 memcached_execute_function callbacks
[]= { &callback_counter
};
5759 memcached_return_t rc
= memcached_mget_execute(memc
, (const char**)keys
, key_length
,
5760 (size_t)max_keys
, callbacks
, &counter
, 1);
5761 test_compare(MEMCACHED_SUCCESS
, rc
);
5763 char* the_value
= NULL
;
5764 char the_key
[MEMCACHED_MAX_KEY
];
5765 size_t the_key_length
;
5766 size_t the_value_length
;
5770 the_value
= memcached_fetch(memc
, the_key
, &the_key_length
, &the_value_length
, &the_flags
, &rc
);
5772 if ((the_value
!= NULL
) && (rc
== MEMCACHED_SUCCESS
))
5778 } while ( (the_value
!= NULL
) && (rc
== MEMCACHED_SUCCESS
));
5781 test_compare(MEMCACHED_END
, rc
);
5783 /* Verify that we got all of the items */
5784 test_compare(counter
, max_keys
);
5787 /* Release all allocated resources */
5788 for (size_t x
= 0; x
< max_keys
; ++x
)
5795 memc
->number_of_hosts
= number_of_hosts
;
5797 return TEST_SUCCESS
;
5800 static test_return_t
regression_bug_583031(memcached_st
*)
5802 memcached_st
*memc
= memcached_create(NULL
);
5804 test_compare(MEMCACHED_SUCCESS
, memcached_server_add(memc
, "10.2.3.4", 11211));
5806 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT
, 1000);
5807 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 1000);
5808 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
5809 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
5810 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, 1000);
5811 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, 3);
5813 memcached_return_t rc
;
5817 const char *value
= memcached_get(memc
, "dsf", 3, &length
, &flags
, &rc
);
5819 test_compare(0, length
);
5821 test_compare_got(MEMCACHED_TIMEOUT
, rc
, memcached_strerror(memc
, rc
));
5823 memcached_free(memc
);
5825 return TEST_SUCCESS
;
5828 static test_return_t
regression_bug_581030(memcached_st
*)
5831 memcached_stat_st
*local_stat
= memcached_stat(NULL
, NULL
, NULL
);
5832 test_false(local_stat
);
5834 memcached_stat_free(NULL
, NULL
);
5837 return TEST_SUCCESS
;
5840 #define regression_bug_655423_COUNT 6000
5841 static test_return_t
regression_bug_655423(memcached_st
*memc
)
5843 memcached_st
*clone
= memcached_clone(NULL
, memc
);
5844 memc
= NULL
; // Just to make sure it is not used
5849 return TEST_SKIPPED
;
5852 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1));
5853 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1));
5854 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1));
5855 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH
, 1));
5857 memset(payload
, int('x'), sizeof(payload
));
5859 for (uint32_t x
= 0; x
< regression_bug_655423_COUNT
; x
++)
5861 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1];
5862 snprintf(key
, sizeof(key
), "%u", x
);
5864 test_compare(MEMCACHED_SUCCESS
, memcached_set(clone
, key
, strlen(key
), payload
, sizeof(payload
), 0, 0));
5867 for (uint32_t x
= 0; x
< regression_bug_655423_COUNT
; x
++)
5869 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1];
5870 snprintf(key
, sizeof(key
), "%u", x
);
5872 size_t value_length
;
5873 memcached_return_t rc
;
5874 char *value
= memcached_get(clone
, key
, strlen(key
), &value_length
, NULL
, &rc
);
5876 if (rc
== MEMCACHED_NOTFOUND
)
5879 test_compare(0, value_length
);
5883 test_compare(MEMCACHED_SUCCESS
, rc
);
5885 test_compare(100, value_length
);
5889 char **keys
= (char**)calloc(regression_bug_655423_COUNT
, sizeof(char*));
5890 size_t *key_length
= (size_t *)calloc(regression_bug_655423_COUNT
, sizeof(size_t));
5891 for (uint32_t x
= 0; x
< regression_bug_655423_COUNT
; x
++)
5893 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1];
5894 snprintf(key
, sizeof(key
), "%u", x
);
5896 keys
[x
]= strdup(key
);
5898 key_length
[x
]= strlen(key
);
5899 test_true(key_length
[x
]);
5902 memcached_return_t rc
;
5903 test_compare_got(MEMCACHED_SUCCESS
,
5904 rc
= memcached_mget(clone
, (const char* const *)keys
, key_length
, regression_bug_655423_COUNT
),
5905 memcached_strerror(NULL
, rc
));
5908 memcached_result_st
*result
= NULL
;
5909 while ((result
= memcached_fetch_result(clone
, result
, NULL
)))
5911 test_compare(100, memcached_result_length(result
));
5915 test_true(count
> 100); // If we don't get back atleast this, something is up
5917 /* Release all allocated resources */
5918 for (size_t x
= 0; x
< regression_bug_655423_COUNT
; ++x
)
5926 memcached_free(clone
);
5928 return TEST_SUCCESS
;
5932 * Test that ensures that buffered set to not trigger problems during io_flush
5934 #define regression_bug_490520_COUNT 200480
5935 static test_return_t
regression_bug_490520(memcached_st
*memc
)
5937 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
,1);
5938 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
,1);
5939 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, 1000);
5940 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
,1);
5941 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 3600);
5943 memc
->number_of_hosts
= 1;
5945 char **keys
= (char **)calloc(regression_bug_490520_COUNT
, sizeof(char*));
5946 size_t *key_length
= (size_t *)calloc(regression_bug_490520_COUNT
, sizeof(size_t));
5948 /* First add all of the items.. */
5949 char blob
[3333] = {0};
5950 for (uint32_t x
= 0; x
< regression_bug_490520_COUNT
; ++x
)
5953 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%u", x
);
5957 memcached_return rc
= memcached_set(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
5958 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
5961 for (uint32_t x
= 0; x
< regression_bug_490520_COUNT
; ++x
)
5968 return TEST_SUCCESS
;
5971 static void memcached_die(memcached_st
* mc
, memcached_return error
, const char* what
, uint32_t it
)
5973 fprintf(stderr
, "Iteration #%u: ", it
);
5975 if(error
== MEMCACHED_ERRNO
)
5977 fprintf(stderr
, "system error %d from %s: %s\n",
5978 errno
, what
, strerror(errno
));
5982 fprintf(stderr
, "error %d from %s: %s\n", error
, what
,
5983 memcached_strerror(mc
, error
));
5987 #define TEST_CONSTANT_CREATION 200
5989 static test_return_t
regression_bug_(memcached_st
*memc
)
5991 const char *remote_server
;
5994 if (! (remote_server
= getenv("LIBMEMCACHED_REMOTE_SERVER")))
5996 return TEST_SKIPPED
;
5999 for (uint32_t x
= 0; x
< TEST_CONSTANT_CREATION
; x
++)
6001 memcached_st
* mc
= memcached_create(NULL
);
6002 memcached_return rc
;
6004 rc
= memcached_behavior_set(mc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
6005 if (rc
!= MEMCACHED_SUCCESS
)
6007 memcached_die(mc
, rc
, "memcached_behavior_set", x
);
6010 rc
= memcached_behavior_set(mc
, MEMCACHED_BEHAVIOR_CACHE_LOOKUPS
, 1);
6011 if (rc
!= MEMCACHED_SUCCESS
)
6013 memcached_die(mc
, rc
, "memcached_behavior_set", x
);
6016 rc
= memcached_server_add(mc
, remote_server
, 0);
6017 if (rc
!= MEMCACHED_SUCCESS
)
6019 memcached_die(mc
, rc
, "memcached_server_add", x
);
6022 const char *set_key
= "akey";
6023 const size_t set_key_len
= strlen(set_key
);
6024 const char *set_value
= "a value";
6025 const size_t set_value_len
= strlen(set_value
);
6027 if (rc
== MEMCACHED_SUCCESS
)
6031 size_t get_value_len
;
6033 uint32_t get_value_flags
;
6035 get_value
= memcached_get(mc
, set_key
, set_key_len
, &get_value_len
,
6036 &get_value_flags
, &rc
);
6037 if (rc
!= MEMCACHED_SUCCESS
)
6039 memcached_die(mc
, rc
, "memcached_get", x
);
6045 (get_value_len
!= set_value_len
6046 || 0!=strncmp(get_value
, set_value
, get_value_len
)))
6048 fprintf(stderr
, "Values don't match?\n");
6049 rc
= MEMCACHED_FAILURE
;
6055 rc
= memcached_set(mc
,
6056 set_key
, set_key_len
,
6057 set_value
, set_value_len
,
6061 if (rc
!= MEMCACHED_SUCCESS
)
6063 memcached_die(mc
, rc
, "memcached_set", x
);
6070 if (rc
!= MEMCACHED_SUCCESS
)
6076 return TEST_SUCCESS
;
6080 * Test that the sasl authentication works. We cannot use the default
6081 * pool of servers, because that would require that all servers we want
6082 * to test supports SASL authentication, and that they use the default
6085 static test_return_t
sasl_auth_test(memcached_st
*memc
)
6087 #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
6088 test_compare(MEMCACHED_SUCCESS
, memcached_set(memc
, "foo", 3, "bar", 3, (time_t)0, (uint32_t)0));
6089 test_compare(MEMCACHED_SUCCESS
, memcached_delete(memc
, "foo", 3, 0));
6090 test_compare(MEMCACHED_SUCCESS
, memcached_destroy_sasl_auth_data(memc
));
6091 test_compare(MEMCACHED_FAILURE
, memcached_destroy_sasl_auth_data(memc
));
6092 test_compare(MEMCACHED_FAILURE
, memcached_destroy_sasl_auth_data(NULL
));
6093 memcached_quit(memc
);
6095 test_compare(MEMCACHED_SUCCESS
,
6096 memcached_set_sasl_auth_data(memc
,
6097 getenv("LIBMEMCACHED_TEST_SASL_USERNAME"),
6098 getenv("LIBMEMCACHED_TEST_SASL_SERVER")));
6100 test_compare(MEMCACHED_AUTH_FAILURE
,
6101 memcached_set(memc
, "foo", 3, "bar", 3, (time_t)0, (uint32_t)0));
6102 test_compare(MEMCACHED_SUCCESS
, memcached_destroy_sasl_auth_data(memc
));
6104 memcached_quit(memc
);
6105 return TEST_SUCCESS
;
6108 return TEST_FAILURE
;
6112 /* Clean the server before beginning testing */
6114 {"util_version", 1, (test_callback_fn
*)util_version_test
},
6115 {"flush", 0, (test_callback_fn
*)flush_test
},
6116 {"init", 0, (test_callback_fn
*)init_test
},
6117 {"allocation", 0, (test_callback_fn
*)allocation_test
},
6118 {"server_list_null_test", 0, (test_callback_fn
*)server_list_null_test
},
6119 {"server_unsort", 0, (test_callback_fn
*)server_unsort_test
},
6120 {"server_sort", 0, (test_callback_fn
*)server_sort_test
},
6121 {"server_sort2", 0, (test_callback_fn
*)server_sort2_test
},
6122 {"memcached_server_remove", 0, (test_callback_fn
*)memcached_server_remove_test
},
6123 {"clone_test", 0, (test_callback_fn
*)clone_test
},
6124 {"connection_test", 0, (test_callback_fn
*)connection_test
},
6125 {"callback_test", 0, (test_callback_fn
*)callback_test
},
6126 {"userdata_test", 0, (test_callback_fn
*)userdata_test
},
6127 {"error", 0, (test_callback_fn
*)error_test
},
6128 {"set", 0, (test_callback_fn
*)set_test
},
6129 {"set2", 0, (test_callback_fn
*)set_test2
},
6130 {"set3", 0, (test_callback_fn
*)set_test3
},
6131 {"dump", 1, (test_callback_fn
*)dump_test
},
6132 {"add", 1, (test_callback_fn
*)add_test
},
6133 {"memcached_fetch_result(MEMCACHED_NOTFOUND)", 1, (test_callback_fn
*)memcached_fetch_result_NOT_FOUND
},
6134 {"replace", 1, (test_callback_fn
*)replace_test
},
6135 {"delete", 1, (test_callback_fn
*)delete_test
},
6136 {"get", 1, (test_callback_fn
*)get_test
},
6137 {"get2", 0, (test_callback_fn
*)get_test2
},
6138 {"get3", 0, (test_callback_fn
*)get_test3
},
6139 {"get4", 0, (test_callback_fn
*)get_test4
},
6140 {"partial mget", 0, (test_callback_fn
*)get_test5
},
6141 {"stats_servername", 0, (test_callback_fn
*)stats_servername_test
},
6142 {"increment", 0, (test_callback_fn
*)increment_test
},
6143 {"increment_with_initial", 1, (test_callback_fn
*)increment_with_initial_test
},
6144 {"decrement", 0, (test_callback_fn
*)decrement_test
},
6145 {"decrement_with_initial", 1, (test_callback_fn
*)decrement_with_initial_test
},
6146 {"increment_by_key", 0, (test_callback_fn
*)increment_by_key_test
},
6147 {"increment_with_initial_by_key", 1, (test_callback_fn
*)increment_with_initial_by_key_test
},
6148 {"decrement_by_key", 0, (test_callback_fn
*)decrement_by_key_test
},
6149 {"decrement_with_initial_by_key", 1, (test_callback_fn
*)decrement_with_initial_by_key_test
},
6150 {"quit", 0, (test_callback_fn
*)quit_test
},
6151 {"mget", 1, (test_callback_fn
*)mget_test
},
6152 {"mget_result", 1, (test_callback_fn
*)mget_result_test
},
6153 {"mget_result_alloc", 1, (test_callback_fn
*)mget_result_alloc_test
},
6154 {"mget_result_function", 1, (test_callback_fn
*)mget_result_function
},
6155 {"mget_execute", 1, (test_callback_fn
*)mget_execute
},
6156 {"mget_end", 0, (test_callback_fn
*)mget_end
},
6157 {"get_stats", 0, (test_callback_fn
*)get_stats
},
6158 {"add_host_test", 0, (test_callback_fn
*)add_host_test
},
6159 {"add_host_test_1", 0, (test_callback_fn
*)add_host_test1
},
6160 {"get_stats_keys", 0, (test_callback_fn
*)get_stats_keys
},
6161 {"version_string_test", 0, (test_callback_fn
*)version_string_test
},
6162 {"bad_key", 1, (test_callback_fn
*)bad_key_test
},
6163 {"memcached_server_cursor", 1, (test_callback_fn
*)memcached_server_cursor_test
},
6164 {"read_through", 1, (test_callback_fn
*)read_through
},
6165 {"delete_through", 1, (test_callback_fn
*)delete_through
},
6166 {"noreply", 1, (test_callback_fn
*)noreply_test
},
6167 {"analyzer", 1, (test_callback_fn
*)analyzer_test
},
6168 {"connectionpool", 1, (test_callback_fn
*)connection_pool_test
},
6169 {"memcached_pool_test", 1, (test_callback_fn
*)memcached_pool_test
},
6170 {"ping", 1, (test_callback_fn
*)ping_test
},
6171 {"test_get_last_disconnect", 1, (test_callback_fn
*)test_get_last_disconnect
},
6172 {"verbosity", 1, (test_callback_fn
*)test_verbosity
},
6173 {"test_server_failure", 1, (test_callback_fn
*)test_server_failure
},
6174 {"cull_servers", 1, (test_callback_fn
*)test_cull_servers
},
6175 {"memcached_stat_execute", 1, (test_callback_fn
*)memcached_stat_execute_test
},
6179 test_st behavior_tests
[] ={
6180 {"libmemcached_string_behavior()", 0, (test_callback_fn
*)libmemcached_string_behavior_test
},
6181 {"libmemcached_string_distribution()", 0, (test_callback_fn
*)libmemcached_string_distribution_test
},
6182 {"behavior_test", 0, (test_callback_fn
*)behavior_test
},
6183 {"MEMCACHED_BEHAVIOR_CORK", 0, (test_callback_fn
*)MEMCACHED_BEHAVIOR_CORK_test
},
6184 {"MEMCACHED_BEHAVIOR_TCP_KEEPALIVE", 0, (test_callback_fn
*)MEMCACHED_BEHAVIOR_TCP_KEEPALIVE_test
},
6185 {"MEMCACHED_BEHAVIOR_TCP_KEEPIDLE", 0, (test_callback_fn
*)MEMCACHED_BEHAVIOR_TCP_KEEPIDLE_test
},
6189 test_st basic_tests
[] ={
6190 {"init", 1, (test_callback_fn
*)basic_init_test
},
6191 {"clone", 1, (test_callback_fn
*)basic_clone_test
},
6192 {"reset", 1, (test_callback_fn
*)basic_reset_stack_test
},
6193 {"reset heap", 1, (test_callback_fn
*)basic_reset_heap_test
},
6194 {"reset stack clone", 1, (test_callback_fn
*)basic_reset_stack_clone_test
},
6195 {"reset heap clone", 1, (test_callback_fn
*)basic_reset_heap_clone_test
},
6199 test_st regression_binary_vs_block
[] ={
6200 {"block add", 1, (test_callback_fn
*)block_add_regression
},
6201 {"binary add", 1, (test_callback_fn
*)binary_add_regression
},
6205 test_st async_tests
[] ={
6206 {"add", 1, (test_callback_fn
*)add_wrapper
},
6210 test_st string_tests
[] ={
6211 {"string static with null", 0, (test_callback_fn
*)string_static_null
},
6212 {"string alloc with null", 0, (test_callback_fn
*)string_alloc_null
},
6213 {"string alloc with 1K", 0, (test_callback_fn
*)string_alloc_with_size
},
6214 {"string alloc with malloc failure", 0, (test_callback_fn
*)string_alloc_with_size_toobig
},
6215 {"string append", 0, (test_callback_fn
*)string_alloc_append
},
6216 {"string append failure (too big)", 0, (test_callback_fn
*)string_alloc_append_toobig
},
6217 {"string_alloc_append_multiple", 0, (test_callback_fn
*)string_alloc_append_multiple
},
6218 {0, 0, (test_callback_fn
*)0}
6221 test_st memcached_server_get_last_disconnect_tests
[] ={
6222 {"memcached_server_get_last_disconnect()", 0, (test_callback_fn
*)test_multiple_get_last_disconnect
},
6223 {0, 0, (test_callback_fn
*)0}
6227 test_st result_tests
[] ={
6228 {"result static", 0, (test_callback_fn
*)result_static
},
6229 {"result alloc", 0, (test_callback_fn
*)result_alloc
},
6230 {0, 0, (test_callback_fn
*)0}
6233 test_st version_1_2_3
[] ={
6234 {"append", 0, (test_callback_fn
*)append_test
},
6235 {"prepend", 0, (test_callback_fn
*)prepend_test
},
6236 {"cas", 0, (test_callback_fn
*)cas_test
},
6237 {"cas2", 0, (test_callback_fn
*)cas2_test
},
6238 {"append_binary", 0, (test_callback_fn
*)append_binary_test
},
6239 {0, 0, (test_callback_fn
*)0}
6242 test_st haldenbrand_tests
[] ={
6243 {"memcached_set", 0, (test_callback_fn
*)user_supplied_bug1
},
6244 {"memcached_get()", 0, (test_callback_fn
*)user_supplied_bug2
},
6245 {"memcached_mget()", 0, (test_callback_fn
*)user_supplied_bug3
},
6246 {0, 0, (test_callback_fn
*)0}
6249 test_st user_tests
[] ={
6250 {"user_supplied_bug4", true, (test_callback_fn
*)user_supplied_bug4
},
6251 {"user_supplied_bug5", 1, (test_callback_fn
*)user_supplied_bug5
},
6252 {"user_supplied_bug6", 1, (test_callback_fn
*)user_supplied_bug6
},
6253 {"user_supplied_bug7", 1, (test_callback_fn
*)user_supplied_bug7
},
6254 {"user_supplied_bug8", 1, (test_callback_fn
*)user_supplied_bug8
},
6255 {"user_supplied_bug9", 1, (test_callback_fn
*)user_supplied_bug9
},
6256 {"user_supplied_bug10", 1, (test_callback_fn
*)user_supplied_bug10
},
6257 {"user_supplied_bug11", 1, (test_callback_fn
*)user_supplied_bug11
},
6258 {"user_supplied_bug12", 1, (test_callback_fn
*)user_supplied_bug12
},
6259 {"user_supplied_bug13", 1, (test_callback_fn
*)user_supplied_bug13
},
6260 {"user_supplied_bug14", 1, (test_callback_fn
*)user_supplied_bug14
},
6261 {"user_supplied_bug15", 1, (test_callback_fn
*)user_supplied_bug15
},
6262 {"user_supplied_bug16", 1, (test_callback_fn
*)user_supplied_bug16
},
6263 #if !defined(__sun) && !defined(__OpenBSD__)
6265 ** It seems to be something weird with the character sets..
6266 ** value_fetch is unable to parse the value line (iscntrl "fails"), so I
6267 ** guess I need to find out how this is supposed to work.. Perhaps I need
6268 ** to run the test in a specific locale (I tried zh_CN.UTF-8 without success,
6269 ** so just disable the code for now...).
6271 {"user_supplied_bug17", 1, (test_callback_fn
*)user_supplied_bug17
},
6273 {"user_supplied_bug18", 1, (test_callback_fn
*)user_supplied_bug18
},
6274 {"user_supplied_bug19", 1, (test_callback_fn
*)user_supplied_bug19
},
6275 {"user_supplied_bug20", 1, (test_callback_fn
*)user_supplied_bug20
},
6276 {"user_supplied_bug21", 1, (test_callback_fn
*)user_supplied_bug21
},
6277 {"wrong_failure_counter_test", 1, (test_callback_fn
*)wrong_failure_counter_test
},
6278 {"wrong_failure_counter_two_test", 1, (test_callback_fn
*)wrong_failure_counter_two_test
},
6279 {0, 0, (test_callback_fn
*)0}
6282 test_st replication_tests
[]= {
6283 {"set", 1, (test_callback_fn
*)replication_set_test
},
6284 {"get", 0, (test_callback_fn
*)replication_get_test
},
6285 {"mget", 0, (test_callback_fn
*)replication_mget_test
},
6286 {"delete", 0, (test_callback_fn
*)replication_delete_test
},
6287 {"rand_mget", 0, (test_callback_fn
*)replication_randomize_mget_test
},
6288 {"fail", 0, (test_callback_fn
*)replication_randomize_mget_fail_test
},
6289 {0, 0, (test_callback_fn
*)0}
6293 * The following test suite is used to verify that we don't introduce
6294 * regression bugs. If you want more information about the bug / test,
6295 * you should look in the bug report at
6296 * http://bugs.launchpad.net/libmemcached
6298 test_st regression_tests
[]= {
6299 {"lp:434484", 1, (test_callback_fn
*)regression_bug_434484
},
6300 {"lp:434843", 1, (test_callback_fn
*)regression_bug_434843
},
6301 {"lp:434843-buffered", 1, (test_callback_fn
*)regression_bug_434843_buffered
},
6302 {"lp:421108", 1, (test_callback_fn
*)regression_bug_421108
},
6303 {"lp:442914", 1, (test_callback_fn
*)regression_bug_442914
},
6304 {"lp:447342", 1, (test_callback_fn
*)regression_bug_447342
},
6305 {"lp:463297", 1, (test_callback_fn
*)regression_bug_463297
},
6306 {"lp:490486", 1, (test_callback_fn
*)regression_bug_490486
},
6307 {"lp:583031", 1, (test_callback_fn
*)regression_bug_583031
},
6308 {"lp:?", 1, (test_callback_fn
*)regression_bug_
},
6309 {"lp:728286", 1, (test_callback_fn
*)regression_bug_728286
},
6310 {"lp:581030", 1, (test_callback_fn
*)regression_bug_581030
},
6311 {"lp:71231153 connect()", 1, (test_callback_fn
*)regression_bug_71231153_connect
},
6312 {"lp:71231153 poll()", 1, (test_callback_fn
*)regression_bug_71231153_poll
},
6313 {"lp:655423", 1, (test_callback_fn
*)regression_bug_655423
},
6314 {"lp:490520", 1, (test_callback_fn
*)regression_bug_490520
},
6315 {0, 0, (test_callback_fn
*)0}
6318 test_st sasl_auth_tests
[]= {
6319 {"sasl_auth", 1, (test_callback_fn
*)sasl_auth_test
},
6320 {0, 0, (test_callback_fn
*)0}
6323 test_st ketama_compatibility
[]= {
6324 {"libmemcached", 1, (test_callback_fn
*)ketama_compatibility_libmemcached
},
6325 {"spymemcached", 1, (test_callback_fn
*)ketama_compatibility_spymemcached
},
6326 {0, 0, (test_callback_fn
*)0}
6329 test_st generate_tests
[] ={
6330 {"generate_pairs", 1, (test_callback_fn
*)generate_pairs
},
6331 {"generate_data", 1, (test_callback_fn
*)generate_data
},
6332 {"get_read", 0, (test_callback_fn
*)get_read
},
6333 {"delete_generate", 0, (test_callback_fn
*)delete_generate
},
6334 {"generate_buffer_data", 1, (test_callback_fn
*)generate_buffer_data
},
6335 {"delete_buffer", 0, (test_callback_fn
*)delete_buffer_generate
},
6336 {"generate_data", 1, (test_callback_fn
*)generate_data
},
6337 {"mget_read", 0, (test_callback_fn
*)mget_read
},
6338 {"mget_read_result", 0, (test_callback_fn
*)mget_read_result
},
6339 {"memcached_fetch_result() use internal result", 0, (test_callback_fn
*)mget_read_internal_result
},
6340 {"memcached_fetch_result() partial read", 0, (test_callback_fn
*)mget_read_partial_result
},
6341 {"mget_read_function", 0, (test_callback_fn
*)mget_read_function
},
6342 {"cleanup", 1, (test_callback_fn
*)cleanup_pairs
},
6343 {"generate_large_pairs", 1, (test_callback_fn
*)generate_large_pairs
},
6344 {"generate_data", 1, (test_callback_fn
*)generate_data
},
6345 {"generate_buffer_data", 1, (test_callback_fn
*)generate_buffer_data
},
6346 {"cleanup", 1, (test_callback_fn
*)cleanup_pairs
},
6347 {0, 0, (test_callback_fn
*)0}
6350 test_st consistent_tests
[] ={
6351 {"generate_pairs", 1, (test_callback_fn
*)generate_pairs
},
6352 {"generate_data", 1, (test_callback_fn
*)generate_data
},
6353 {"get_read", 0, (test_callback_fn
*)get_read_count
},
6354 {"cleanup", 1, (test_callback_fn
*)cleanup_pairs
},
6355 {0, 0, (test_callback_fn
*)0}
6358 test_st consistent_weighted_tests
[] ={
6359 {"generate_pairs", 1, (test_callback_fn
*)generate_pairs
},
6360 {"generate_data", 1, (test_callback_fn
*)generate_data_with_stats
},
6361 {"get_read", 0, (test_callback_fn
*)get_read_count
},
6362 {"cleanup", 1, (test_callback_fn
*)cleanup_pairs
},
6363 {0, 0, (test_callback_fn
*)0}
6366 test_st hsieh_availability
[] ={
6367 {"hsieh_avaibility_test", 0, (test_callback_fn
*)hsieh_avaibility_test
},
6368 {0, 0, (test_callback_fn
*)0}
6371 test_st murmur_availability
[] ={
6372 {"murmur_avaibility_test", 0, (test_callback_fn
*)murmur_avaibility_test
},
6373 {0, 0, (test_callback_fn
*)0}
6377 test_st hash_sanity
[] ={
6378 {"hash sanity", 0, (test_callback_fn
*)hash_sanity_test
},
6379 {0, 0, (test_callback_fn
*)0}
6383 test_st ketama_auto_eject_hosts
[] ={
6384 {"auto_eject_hosts", 1, (test_callback_fn
*)auto_eject_hosts
},
6385 {"output_ketama_weighted_keys", 1, (test_callback_fn
*)output_ketama_weighted_keys
},
6386 {0, 0, (test_callback_fn
*)0}
6389 test_st hash_tests
[] ={
6390 {"one_at_a_time_run", 0, (test_callback_fn
*)one_at_a_time_run
},
6391 {"md5", 0, (test_callback_fn
*)md5_run
},
6392 {"crc", 0, (test_callback_fn
*)crc_run
},
6393 {"fnv1_64", 0, (test_callback_fn
*)fnv1_64_run
},
6394 {"fnv1a_64", 0, (test_callback_fn
*)fnv1a_64_run
},
6395 {"fnv1_32", 0, (test_callback_fn
*)fnv1_32_run
},
6396 {"fnv1a_32", 0, (test_callback_fn
*)fnv1a_32_run
},
6397 {"hsieh", 0, (test_callback_fn
*)hsieh_run
},
6398 {"murmur", 0, (test_callback_fn
*)murmur_run
},
6399 {"jenkis", 0, (test_callback_fn
*)jenkins_run
},
6400 {"memcached_get_hashkit", 0, (test_callback_fn
*)memcached_get_hashkit_test
},
6401 {0, 0, (test_callback_fn
*)0}
6404 test_st error_conditions
[] ={
6405 {"memcached_get(MEMCACHED_ERRNO)", 0, (test_callback_fn
*)memcached_get_MEMCACHED_ERRNO
},
6406 {"memcached_get(MEMCACHED_NOTFOUND)", 0, (test_callback_fn
*)memcached_get_MEMCACHED_NOTFOUND
},
6407 {"memcached_get_by_key(MEMCACHED_ERRNO)", 0, (test_callback_fn
*)memcached_get_by_key_MEMCACHED_ERRNO
},
6408 {"memcached_get_by_key(MEMCACHED_NOTFOUND)", 0, (test_callback_fn
*)memcached_get_by_key_MEMCACHED_NOTFOUND
},
6409 {"memcached_get_by_key(MEMCACHED_NOTFOUND)", 0, (test_callback_fn
*)memcached_get_by_key_MEMCACHED_NOTFOUND
},
6410 {"memcached_increment(MEMCACHED_NO_SERVERS)", 0, (test_callback_fn
*)memcached_increment_MEMCACHED_NO_SERVERS
},
6411 {0, 0, (test_callback_fn
*)0}
6415 test_st parser_tests
[] ={
6416 {"behavior", 0, (test_callback_fn
*)behavior_parser_test
},
6417 {"boolean_options", 0, (test_callback_fn
*)parser_boolean_options_test
},
6418 {"configure_file", 0, (test_callback_fn
*)memcached_create_with_options_with_filename
},
6419 {"distribtions", 0, (test_callback_fn
*)parser_distribution_test
},
6420 {"hash", 0, (test_callback_fn
*)parser_hash_test
},
6421 {"libmemcached_check_configuration", 0, (test_callback_fn
*)libmemcached_check_configuration_test
},
6422 {"libmemcached_check_configuration_with_filename", 0, (test_callback_fn
*)libmemcached_check_configuration_with_filename_test
},
6423 {"number_options", 0, (test_callback_fn
*)parser_number_options_test
},
6424 {"randomly generated options", 0, (test_callback_fn
*)random_statement_build_test
},
6425 {"prefix_key", 0, (test_callback_fn
*)parser_key_prefix_test
},
6426 {"server", 0, (test_callback_fn
*)server_test
},
6427 {"bad server strings", 0, (test_callback_fn
*)servers_bad_test
},
6428 {"server with weights", 0, (test_callback_fn
*)server_with_weight_test
},
6429 {"parsing servername, port, and weight", 0, (test_callback_fn
*)test_hostname_port_weight
},
6430 {0, 0, (test_callback_fn
*)0}
6433 test_st virtual_bucket_tests
[] ={
6434 {"basic", 0, (test_callback_fn
*)virtual_back_map
},
6435 {0, 0, (test_callback_fn
*)0}
6438 collection_st collection
[] ={
6440 {"hash_sanity", 0, 0, hash_sanity
},
6442 {"basic", 0, 0, basic_tests
},
6443 {"hsieh_availability", 0, 0, hsieh_availability
},
6444 {"murmur_availability", 0, 0, murmur_availability
},
6445 {"block", 0, 0, tests
},
6446 {"binary", (test_callback_fn
*)pre_binary
, 0, tests
},
6447 {"nonblock", (test_callback_fn
*)pre_nonblock
, 0, tests
},
6448 {"nodelay", (test_callback_fn
*)pre_nodelay
, 0, tests
},
6449 {"settimer", (test_callback_fn
*)pre_settimer
, 0, tests
},
6450 {"md5", (test_callback_fn
*)pre_md5
, 0, tests
},
6451 {"crc", (test_callback_fn
*)pre_crc
, 0, tests
},
6452 {"hsieh", (test_callback_fn
*)pre_hsieh
, 0, tests
},
6453 {"jenkins", (test_callback_fn
*)pre_jenkins
, 0, tests
},
6454 {"fnv1_64", (test_callback_fn
*)pre_hash_fnv1_64
, 0, tests
},
6455 {"fnv1a_64", (test_callback_fn
*)pre_hash_fnv1a_64
, 0, tests
},
6456 {"fnv1_32", (test_callback_fn
*)pre_hash_fnv1_32
, 0, tests
},
6457 {"fnv1a_32", (test_callback_fn
*)pre_hash_fnv1a_32
, 0, tests
},
6458 {"ketama", (test_callback_fn
*)pre_behavior_ketama
, 0, tests
},
6459 {"ketama_auto_eject_hosts", (test_callback_fn
*)pre_behavior_ketama
, 0, ketama_auto_eject_hosts
},
6460 {"unix_socket", (test_callback_fn
*)pre_unix_socket
, 0, tests
},
6461 {"unix_socket_nodelay", (test_callback_fn
*)pre_nodelay
, 0, tests
},
6462 {"poll_timeout", (test_callback_fn
*)poll_timeout
, 0, tests
},
6463 {"gets", (test_callback_fn
*)enable_cas
, 0, tests
},
6464 {"consistent_crc", (test_callback_fn
*)enable_consistent_crc
, 0, tests
},
6465 {"consistent_hsieh", (test_callback_fn
*)enable_consistent_hsieh
, 0, tests
},
6466 #ifdef MEMCACHED_ENABLE_DEPRECATED
6467 {"deprecated_memory_allocators", (test_callback_fn
*)deprecated_set_memory_alloc
, 0, tests
},
6469 {"memory_allocators", (test_callback_fn
*)set_memory_alloc
, 0, tests
},
6470 {"prefix", (test_callback_fn
*)set_prefix
, 0, tests
},
6471 {"sasl_auth", (test_callback_fn
*)pre_sasl
, 0, sasl_auth_tests
},
6472 {"sasl", (test_callback_fn
*)pre_sasl
, 0, tests
},
6473 {"version_1_2_3", (test_callback_fn
*)check_for_1_2_3
, 0, version_1_2_3
},
6474 {"string", 0, 0, string_tests
},
6475 {"result", 0, 0, result_tests
},
6476 {"async", (test_callback_fn
*)pre_nonblock
, 0, async_tests
},
6477 {"async_binary", (test_callback_fn
*)pre_nonblock_binary
, 0, async_tests
},
6478 {"Cal Haldenbrand's tests", 0, 0, haldenbrand_tests
},
6479 {"user", 0, 0, user_tests
},
6480 {"generate", 0, 0, generate_tests
},
6481 {"generate_hsieh", (test_callback_fn
*)pre_hsieh
, 0, generate_tests
},
6482 {"generate_ketama", (test_callback_fn
*)pre_behavior_ketama
, 0, generate_tests
},
6483 {"generate_hsieh_consistent", (test_callback_fn
*)enable_consistent_hsieh
, 0, generate_tests
},
6484 {"generate_md5", (test_callback_fn
*)pre_md5
, 0, generate_tests
},
6485 {"generate_murmur", (test_callback_fn
*)pre_murmur
, 0, generate_tests
},
6486 {"generate_jenkins", (test_callback_fn
*)pre_jenkins
, 0, generate_tests
},
6487 {"generate_nonblock", (test_callback_fn
*)pre_nonblock
, 0, generate_tests
},
6489 {"generate_corked", (test_callback_fn
*)pre_cork
, 0, generate_tests
},
6490 {"generate_corked_and_nonblock", (test_callback_fn
*)pre_cork_and_nonblock
, 0, generate_tests
},
6491 {"consistent_not", 0, 0, consistent_tests
},
6492 {"consistent_ketama", (test_callback_fn
*)pre_behavior_ketama
, 0, consistent_tests
},
6493 {"consistent_ketama_weighted", (test_callback_fn
*)pre_behavior_ketama_weighted
, 0, consistent_weighted_tests
},
6494 {"ketama_compat", 0, 0, ketama_compatibility
},
6495 {"test_hashes", 0, 0, hash_tests
},
6496 {"replication", (test_callback_fn
*)pre_replication
, 0, replication_tests
},
6497 {"replication_noblock", (test_callback_fn
*)pre_replication_noblock
, 0, replication_tests
},
6498 {"regression", 0, 0, regression_tests
},
6499 {"behaviors", 0, 0, behavior_tests
},
6500 {"regression_binary_vs_block", (test_callback_fn
*)key_setup
, (test_callback_fn
*)key_teardown
, regression_binary_vs_block
},
6501 {"error_conditions", 0, 0, error_conditions
},
6502 {"parser", 0, 0, parser_tests
},
6503 {"virtual buckets", 0, 0, virtual_bucket_tests
},
6504 {"memcached_server_get_last_disconnect", 0, 0, memcached_server_get_last_disconnect_tests
},
6508 #include "tests/libmemcached_world.h"
6510 void get_world(Framework
*world
)
6512 world
->collections
= collection
;
6514 world
->_create
= (test_callback_create_fn
*)world_create
;
6515 world
->_destroy
= (test_callback_fn
*)world_destroy
;
6517 world
->item
._startup
= (test_callback_fn
*)world_test_startup
;
6518 world
->item
._flush
= (test_callback_fn
*)world_flush
;
6519 world
->item
.set_pre((test_callback_fn
*)world_pre_run
);
6520 world
->item
.set_post((test_callback_fn
*)world_post_run
);
6521 world
->_on_error
= (test_callback_error_fn
*)world_on_error
;
6523 world
->collection_startup
= (test_callback_fn
*)world_container_startup
;
6524 world
->collection_shutdown
= (test_callback_fn
*)world_container_shutdown
;
6526 world
->runner
= &defualt_libmemcached_runner
;