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.
38 #include <libtest/common.h>
44 #define BUILDING_LIBMEMCACHED
45 // !NEVER use common.h, always use memcached.h in your own apps
46 #include <libmemcached/common.h>
53 #include <sys/types.h>
58 #include <libtest/server.h>
60 #include "clients/generator.h"
61 #include "clients/execute.h"
63 #define SMALL_STRING_LEN 1024
65 #include <libtest/test.hpp>
66 #include "tests/deprecated.h"
67 #include "tests/parser.h"
68 #include "tests/pool.h"
69 #include "tests/namespace.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_NAMESPACE
, 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 const char *key
= "foo";
1140 size_t value_length
= 8191;
1142 char *value
= (char*)malloc(value_length
);
1145 for (uint32_t x
= 0; x
< value_length
; x
++)
1147 value
[x
] = (char) (x
% 127);
1150 memcached_return_t rc
= memcached_set(memc
, key
, strlen(key
),
1151 value
, value_length
,
1152 (time_t)0, (uint32_t)0);
1153 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
1155 for (uint32_t x
= 0; x
< 10; x
++)
1158 size_t string_length
;
1159 char *string
= memcached_get(memc
, key
, strlen(key
),
1160 &string_length
, &flags
, &rc
);
1162 test_compare(MEMCACHED_SUCCESS
, rc
);
1164 test_compare(string_length
, value_length
);
1165 test_memcmp(string
, value
, string_length
);
1171 return TEST_SUCCESS
;
1175 * This test verifies that memcached_read_one_response doesn't try to
1176 * dereference a NIL-pointer if you issue a multi-get and don't read out all
1177 * responses before you execute a storage command.
1179 static test_return_t
get_test5(memcached_st
*memc
)
1182 ** Request the same key twice, to ensure that we hash to the same server
1183 ** (so that we have multiple response values queued up) ;-)
1185 const char *keys
[]= { "key", "key" };
1186 size_t lengths
[]= { 3, 3 };
1190 memcached_return_t rc
= memcached_set(memc
, keys
[0], lengths
[0],
1191 keys
[0], lengths
[0], 0, 0);
1192 test_compare(MEMCACHED_SUCCESS
, rc
);
1193 rc
= memcached_mget(memc
, keys
, lengths
, 2);
1195 memcached_result_st results_obj
;
1196 memcached_result_st
*results
;
1197 results
=memcached_result_create(memc
, &results_obj
);
1199 results
=memcached_fetch_result(memc
, &results_obj
, &rc
);
1201 memcached_result_free(&results_obj
);
1203 /* Don't read out the second result, but issue a set instead.. */
1204 rc
= memcached_set(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0);
1205 test_compare(MEMCACHED_SUCCESS
, rc
);
1207 char *val
= memcached_get_by_key(memc
, keys
[0], lengths
[0], "yek", 3,
1208 &rlen
, &flags
, &rc
);
1210 test_compare(MEMCACHED_NOTFOUND
, rc
);
1211 val
= memcached_get(memc
, keys
[0], lengths
[0], &rlen
, &flags
, &rc
);
1213 test_compare(MEMCACHED_SUCCESS
, rc
);
1216 return TEST_SUCCESS
;
1219 static test_return_t
mget_end(memcached_st
*memc
)
1221 const char *keys
[]= { "foo", "foo2" };
1222 size_t lengths
[]= { 3, 4 };
1223 const char *values
[]= { "fjord", "41" };
1225 memcached_return_t rc
;
1228 for (int i
= 0; i
< 2; i
++)
1230 rc
= memcached_set(memc
, keys
[i
], lengths
[i
], values
[i
], strlen(values
[i
]),
1231 (time_t)0, (uint32_t)0);
1232 test_compare(MEMCACHED_SUCCESS
, rc
);
1236 size_t string_length
;
1239 // retrieve both via mget
1240 rc
= memcached_mget(memc
, keys
, lengths
, 2);
1241 test_compare(MEMCACHED_SUCCESS
, rc
);
1243 char key
[MEMCACHED_MAX_KEY
];
1246 // this should get both
1247 for (int i
= 0; i
< 2; i
++)
1249 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
,
1251 test_compare(MEMCACHED_SUCCESS
, rc
);
1253 if (key_length
== 4)
1258 test_compare(string_length
, strlen(values
[val
]));
1259 test_true(strncmp(values
[val
], string
, string_length
) == 0);
1263 // this should indicate end
1264 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1265 test_compare(MEMCACHED_END
, rc
);
1268 rc
= memcached_mget(memc
, keys
, lengths
, 1);
1269 test_compare(MEMCACHED_SUCCESS
, rc
);
1271 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1272 test_compare(key_length
, lengths
[0]);
1273 test_true(strncmp(keys
[0], key
, key_length
) == 0);
1274 test_compare(string_length
, strlen(values
[0]));
1275 test_true(strncmp(values
[0], string
, string_length
) == 0);
1276 test_compare(MEMCACHED_SUCCESS
, rc
);
1279 // this should indicate end
1280 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1281 test_true(rc
== MEMCACHED_END
);
1283 return TEST_SUCCESS
;
1286 /* Do not copy the style of this code, I just access hosts to testthis function */
1287 static test_return_t
stats_servername_test(memcached_st
*memc
)
1289 memcached_return_t rc
;
1290 memcached_stat_st memc_stat
;
1291 memcached_server_instance_st instance
=
1292 memcached_server_instance_by_position(memc
, 0);
1294 #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
1295 if (memcached_get_sasl_callbacks(memc
) != NULL
)
1296 return TEST_SKIPPED
;
1298 rc
= memcached_stat_servername(&memc_stat
, NULL
,
1299 memcached_server_name(instance
),
1300 memcached_server_port(instance
));
1302 return TEST_SUCCESS
;
1305 static test_return_t
increment_test(memcached_st
*memc
)
1307 uint64_t new_number
;
1309 test_compare(MEMCACHED_SUCCESS
,
1311 test_literal_param("number"),
1312 test_literal_param("0"),
1313 (time_t)0, (uint32_t)0));
1315 memcached_return_t rc
;
1316 test_compare_got(MEMCACHED_SUCCESS
,
1317 rc
= memcached_increment(memc
,
1318 test_literal_param("number"),
1320 memcached_strerror(NULL
, rc
));
1321 test_compare(1, new_number
);
1323 test_compare(MEMCACHED_SUCCESS
,
1324 memcached_increment(memc
,
1325 test_literal_param("number"),
1327 test_compare(2, new_number
);
1329 return TEST_SUCCESS
;
1332 static test_return_t
increment_with_initial_test(memcached_st
*memc
)
1334 test_skip(true, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
));
1336 uint64_t new_number
;
1337 uint64_t initial
= 0;
1339 test_compare(MEMCACHED_SUCCESS
, memcached_flush_buffers(memc
));
1341 memcached_return_t rc
;
1342 test_compare_got(MEMCACHED_SUCCESS
,
1343 rc
= memcached_increment_with_initial(memc
,
1344 test_literal_param("number"),
1345 1, initial
, 0, &new_number
),
1346 memcached_strerror(NULL
, rc
));
1347 test_compare(new_number
, initial
);
1349 test_compare(MEMCACHED_SUCCESS
,
1350 memcached_increment_with_initial(memc
,
1351 test_literal_param("number"),
1352 1, initial
, 0, &new_number
));
1353 test_compare(new_number
, (initial
+ 1));
1355 return TEST_SUCCESS
;
1358 static test_return_t
decrement_test(memcached_st
*memc
)
1360 uint64_t new_number
;
1361 memcached_return_t rc
;
1362 const char *value
= "3";
1364 rc
= memcached_set(memc
,
1365 test_literal_param("number"),
1366 value
, strlen(value
),
1367 (time_t)0, (uint32_t)0);
1368 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1370 test_compare(MEMCACHED_SUCCESS
,
1371 memcached_decrement(memc
,
1372 test_literal_param("number"),
1374 test_compare(new_number
, 2);
1376 test_compare(MEMCACHED_SUCCESS
,
1377 memcached_decrement(memc
,
1378 test_literal_param("number"),
1380 test_compare(new_number
, 1);
1382 return TEST_SUCCESS
;
1385 static test_return_t
decrement_with_initial_test(memcached_st
*memc
)
1387 test_skip(true, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
));
1389 uint64_t new_number
;
1390 uint64_t initial
= 3;
1392 test_compare(MEMCACHED_SUCCESS
, memcached_flush_buffers(memc
));
1394 test_compare(MEMCACHED_SUCCESS
,
1395 memcached_decrement_with_initial(memc
,
1396 test_literal_param("number"),
1397 1, initial
, 0, &new_number
));
1398 test_compare(new_number
, initial
);
1400 test_compare(MEMCACHED_SUCCESS
,
1401 memcached_decrement_with_initial(memc
,
1402 test_literal_param("number"),
1403 1, initial
, 0, &new_number
));
1404 test_compare(new_number
, (initial
- 1));
1406 return TEST_SUCCESS
;
1409 static test_return_t
increment_by_key_test(memcached_st
*memc
)
1411 uint64_t new_number
;
1412 memcached_return_t rc
;
1413 const char *master_key
= "foo";
1414 const char *key
= "number";
1415 const char *value
= "0";
1417 rc
= memcached_set_by_key(memc
, master_key
, strlen(master_key
),
1419 value
, strlen(value
),
1420 (time_t)0, (uint32_t)0);
1421 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
1423 test_compare(MEMCACHED_SUCCESS
,
1424 memcached_increment_by_key(memc
, master_key
, strlen(master_key
), key
, strlen(key
),
1426 test_compare(new_number
, 1);
1428 test_compare(MEMCACHED_SUCCESS
,
1429 memcached_increment_by_key(memc
, master_key
, strlen(master_key
), key
, strlen(key
),
1431 test_compare(new_number
, 2);
1433 return TEST_SUCCESS
;
1436 static test_return_t
increment_with_initial_by_key_test(memcached_st
*memc
)
1438 test_skip(true, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
));
1440 uint64_t new_number
;
1441 memcached_return_t rc
;
1442 const char *master_key
= "foo";
1443 const char *key
= "number";
1444 uint64_t initial
= 0;
1446 rc
= memcached_increment_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1448 1, initial
, 0, &new_number
);
1449 test_compare(MEMCACHED_SUCCESS
, rc
);
1450 test_true(new_number
== initial
);
1452 rc
= memcached_increment_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1454 1, initial
, 0, &new_number
);
1455 test_compare(MEMCACHED_SUCCESS
, rc
);
1456 test_true(new_number
== (initial
+ 1));
1458 return TEST_SUCCESS
;
1461 static test_return_t
decrement_by_key_test(memcached_st
*memc
)
1463 uint64_t new_number
;
1464 memcached_return_t rc
;
1465 const char *value
= "3";
1467 rc
= memcached_set_by_key(memc
,
1468 test_literal_param("foo"),
1469 test_literal_param("number"),
1470 value
, strlen(value
),
1471 (time_t)0, (uint32_t)0);
1472 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1474 test_compare(MEMCACHED_SUCCESS
,
1475 memcached_decrement_by_key(memc
,
1476 test_literal_param("foo"),
1477 test_literal_param("number"),
1479 test_compare(new_number
, 2);
1481 test_compare(MEMCACHED_SUCCESS
,
1482 memcached_decrement_by_key(memc
,
1483 test_literal_param("foo"),
1484 test_literal_param("number"),
1486 test_compare(new_number
, 1);
1488 return TEST_SUCCESS
;
1491 static test_return_t
decrement_with_initial_by_key_test(memcached_st
*memc
)
1493 test_skip(true, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
));
1495 uint64_t new_number
;
1496 uint64_t initial
= 3;
1498 test_compare(MEMCACHED_SUCCESS
,
1499 memcached_decrement_with_initial_by_key(memc
,
1500 test_literal_param("foo"),
1501 test_literal_param("number"),
1502 1, initial
, 0, &new_number
));
1503 test_compare(new_number
, initial
);
1505 test_compare(MEMCACHED_SUCCESS
,
1506 memcached_decrement_with_initial_by_key(memc
,
1507 test_literal_param("foo"),
1508 test_literal_param("number"),
1509 1, initial
, 0, &new_number
));
1510 test_compare(new_number
, (initial
- 1));
1512 return TEST_SUCCESS
;
1515 static test_return_t
quit_test(memcached_st
*memc
)
1517 memcached_return_t rc
;
1518 const char *key
= "fudge";
1519 const char *value
= "sanford and sun";
1521 rc
= memcached_set(memc
, key
, strlen(key
),
1522 value
, strlen(value
),
1523 (time_t)10, (uint32_t)3);
1524 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1525 memcached_quit(memc
);
1527 rc
= memcached_set(memc
, key
, strlen(key
),
1528 value
, strlen(value
),
1529 (time_t)50, (uint32_t)9);
1530 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1532 return TEST_SUCCESS
;
1535 static test_return_t
mget_result_test(memcached_st
*memc
)
1537 const char *keys
[]= {"fudge", "son", "food"};
1538 size_t key_length
[]= {5, 3, 4};
1540 memcached_result_st results_obj
;
1541 memcached_result_st
*results
;
1543 results
= memcached_result_create(memc
, &results_obj
);
1545 test_true(&results_obj
== results
);
1547 /* We need to empty the server before continueing test */
1548 test_compare(MEMCACHED_SUCCESS
,
1549 memcached_flush(memc
, 0));
1551 test_compare(MEMCACHED_SUCCESS
,
1552 memcached_mget(memc
, keys
, key_length
, 3));
1554 memcached_return_t rc
;
1555 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1560 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
))) { test_true(false); /* We should never see a value returned */ };
1561 test_false(results
);
1562 test_compare_got(MEMCACHED_NOTFOUND
, rc
, memcached_strerror(NULL
, rc
));
1564 for (uint32_t x
= 0; x
< 3; x
++)
1566 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1567 keys
[x
], key_length
[x
],
1568 (time_t)50, (uint32_t)9);
1569 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1572 test_compare(MEMCACHED_SUCCESS
,
1573 memcached_mget(memc
, keys
, key_length
, 3));
1575 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1578 test_true(&results_obj
== results
);
1579 test_compare(MEMCACHED_SUCCESS
, rc
);
1580 test_memcmp(memcached_result_key_value(results
),
1581 memcached_result_value(results
),
1582 memcached_result_length(results
));
1583 test_compare(memcached_result_key_length(results
), memcached_result_length(results
));
1586 memcached_result_free(&results_obj
);
1588 return TEST_SUCCESS
;
1591 static test_return_t
mget_result_alloc_test(memcached_st
*memc
)
1593 const char *keys
[]= {"fudge", "son", "food"};
1594 size_t key_length
[]= {5, 3, 4};
1596 memcached_result_st
*results
;
1598 /* We need to empty the server before continueing test */
1599 test_compare(MEMCACHED_SUCCESS
,
1600 memcached_flush(memc
, 0));
1602 test_compare(MEMCACHED_SUCCESS
,
1603 memcached_mget(memc
, keys
, key_length
, 3));
1605 memcached_return_t rc
;
1606 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1610 test_false(results
);
1611 test_compare_got(MEMCACHED_NOTFOUND
, rc
, memcached_strerror(NULL
, rc
));
1613 for (uint32_t x
= 0; x
< 3; x
++)
1615 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1616 keys
[x
], key_length
[x
],
1617 (time_t)50, (uint32_t)9);
1618 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1621 test_compare(MEMCACHED_SUCCESS
,
1622 memcached_mget(memc
, keys
, key_length
, 3));
1625 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1628 test_compare(MEMCACHED_SUCCESS
, rc
);
1629 test_compare(memcached_result_key_length(results
), memcached_result_length(results
));
1630 test_memcmp(memcached_result_key_value(results
),
1631 memcached_result_value(results
),
1632 memcached_result_length(results
));
1633 memcached_result_free(results
);
1637 return TEST_SUCCESS
;
1640 /* Count the results */
1641 static memcached_return_t
callback_counter(const memcached_st
*, memcached_result_st
*, void *context
)
1643 size_t *counter
= (size_t *)context
;
1645 *counter
= *counter
+ 1;
1647 return MEMCACHED_SUCCESS
;
1650 static test_return_t
mget_result_function(memcached_st
*memc
)
1652 const char *keys
[]= {"fudge", "son", "food"};
1653 size_t key_length
[]= {5, 3, 4};
1655 memcached_execute_fn callbacks
[1];
1657 /* We need to empty the server before continueing test */
1658 test_compare(MEMCACHED_SUCCESS
,
1659 memcached_flush(memc
, 0));
1660 for (uint32_t x
= 0; x
< 3; x
++)
1662 memcached_return_t rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1663 keys
[x
], key_length
[x
],
1664 (time_t)50, (uint32_t)9);
1665 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1668 test_compare(MEMCACHED_SUCCESS
,
1669 memcached_mget(memc
, keys
, key_length
, 3));
1671 callbacks
[0]= &callback_counter
;
1674 memcached_return_t rc
;
1675 test_compare_got(MEMCACHED_SUCCESS
,
1676 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1),
1677 memcached_strerror(NULL
, rc
));
1679 test_compare(counter
, 3);
1681 return TEST_SUCCESS
;
1684 static test_return_t
mget_test(memcached_st
*memc
)
1686 const char *keys
[]= {"fudge", "son", "food"};
1687 size_t key_length
[]= {5, 3, 4};
1689 char return_key
[MEMCACHED_MAX_KEY
];
1690 size_t return_key_length
;
1692 size_t return_value_length
;
1694 /* We need to empty the server before continueing test */
1695 test_compare(MEMCACHED_SUCCESS
,
1696 memcached_flush(memc
, 0));
1698 test_compare(MEMCACHED_SUCCESS
,
1699 memcached_mget(memc
, keys
, key_length
, 3));
1702 memcached_return_t rc
;
1703 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1704 &return_value_length
, &flags
, &rc
)))
1706 test_true(return_value
);
1708 test_false(return_value
);
1709 test_compare(0, return_value_length
);
1710 test_compare_got(MEMCACHED_NOTFOUND
, rc
, memcached_strerror(NULL
, rc
));
1712 for (uint32_t x
= 0; x
< 3; x
++)
1714 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1715 keys
[x
], key_length
[x
],
1716 (time_t)50, (uint32_t)9);
1717 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1719 test_compare(MEMCACHED_SUCCESS
,
1720 memcached_mget(memc
, keys
, key_length
, 3));
1723 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1724 &return_value_length
, &flags
, &rc
)))
1726 test_true(return_value
);
1727 test_compare(MEMCACHED_SUCCESS
, rc
);
1728 if (not memc
->prefix_key
)
1730 test_compare(return_key_length
, return_value_length
);
1731 test_memcmp(return_value
, return_key
, return_value_length
);
1737 return TEST_SUCCESS
;
1740 static test_return_t
mget_execute(memcached_st
*memc
)
1744 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) != 0)
1748 * I only want to hit _one_ server so I know the number of requests I'm
1749 * sending in the pipeline.
1751 uint32_t number_of_hosts
= memc
->number_of_hosts
;
1752 memc
->number_of_hosts
= 1;
1754 size_t max_keys
= 20480;
1757 char **keys
= static_cast<char **>(calloc(max_keys
, sizeof(char*)));
1758 size_t *key_length
=static_cast<size_t *>(calloc(max_keys
, sizeof(size_t)));
1760 /* First add all of the items.. */
1761 char blob
[1024] = {0};
1762 memcached_return_t rc
;
1764 for (size_t x
= 0; x
< max_keys
; ++x
)
1768 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%lu", (unsigned long)x
);
1770 test_true(keys
[x
] != NULL
);
1771 uint64_t query_id
= memcached_query_id(memc
);
1772 rc
= memcached_add(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
1773 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1774 test_compare(query_id
+1, memcached_query_id(memc
));
1777 /* Try to get all of them with a large multiget */
1779 memcached_execute_fn callbacks
[]= { &callback_counter
};
1780 rc
= memcached_mget_execute(memc
, (const char**)keys
, key_length
,
1781 max_keys
, callbacks
, &counter
, 1);
1783 if (memcached_success(rc
))
1786 uint64_t query_id
= memcached_query_id(memc
);
1787 test_compare(MEMCACHED_SUCCESS
,
1788 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
1789 test_compare(query_id
, memcached_query_id(memc
));
1791 /* Verify that we got all of the items */
1792 test_true(counter
== max_keys
);
1794 else if (rc
== MEMCACHED_NOT_SUPPORTED
)
1796 test_true(counter
== 0);
1800 test_fail("note: this test functions differently when in binary mode");
1803 /* Release all allocated resources */
1804 for (size_t x
= 0; x
< max_keys
; ++x
)
1811 memc
->number_of_hosts
= number_of_hosts
;
1812 return TEST_SUCCESS
;
1815 #define REGRESSION_BINARY_VS_BLOCK_COUNT 20480
1817 static test_return_t
key_setup(memcached_st
*memc
)
1819 test_skip(TEST_SUCCESS
, pre_binary(memc
));
1821 global_pairs
= pairs_generate(REGRESSION_BINARY_VS_BLOCK_COUNT
, 0);
1823 return TEST_SUCCESS
;
1826 static test_return_t
key_teardown(memcached_st
*memc
)
1829 pairs_free(global_pairs
);
1831 return TEST_SUCCESS
;
1834 static test_return_t
block_add_regression(memcached_st
*memc
)
1836 /* First add all of the items.. */
1837 for (size_t x
= 0; x
< REGRESSION_BINARY_VS_BLOCK_COUNT
; ++x
)
1839 memcached_return_t rc
;
1840 char blob
[1024] = {0};
1842 rc
= memcached_add_by_key(memc
, "bob", 3, global_pairs
[x
].key
, global_pairs
[x
].key_length
, blob
, sizeof(blob
), 0, 0);
1843 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1846 return TEST_SUCCESS
;
1849 static test_return_t
binary_add_regression(memcached_st
*memc
)
1851 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
1852 test_return_t rc
= block_add_regression(memc
);
1853 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 0);
1857 static test_return_t
get_stats_keys(memcached_st
*memc
)
1861 memcached_stat_st memc_stat
;
1862 memcached_return_t rc
;
1864 stat_list
= memcached_stat_get_keys(memc
, &memc_stat
, &rc
);
1865 test_compare(MEMCACHED_SUCCESS
, rc
);
1866 for (ptr
= stat_list
; *ptr
; ptr
++)
1871 return TEST_SUCCESS
;
1874 static test_return_t
version_string_test(memcached_st
*memc
)
1876 const char *version_string
;
1879 version_string
= memcached_lib_version();
1881 test_strcmp(version_string
, LIBMEMCACHED_VERSION_STRING
);
1883 return TEST_SUCCESS
;
1886 static test_return_t
get_stats(memcached_st
*memc
)
1888 memcached_return_t rc
;
1890 memcached_stat_st
*memc_stat
= memcached_stat(memc
, NULL
, &rc
);
1891 test_compare(MEMCACHED_SUCCESS
, rc
);
1892 test_true(memc_stat
);
1894 for (uint32_t x
= 0; x
< memcached_server_count(memc
); x
++)
1896 char **stat_list
= memcached_stat_get_keys(memc
, memc_stat
+x
, &rc
);
1897 test_compare(MEMCACHED_SUCCESS
, rc
);
1898 for (char **ptr
= stat_list
; *ptr
; ptr
++) {};
1903 memcached_stat_free(NULL
, memc_stat
);
1905 return TEST_SUCCESS
;
1908 static test_return_t
add_host_test(memcached_st
*memc
)
1911 memcached_server_st
*servers
;
1912 memcached_return_t rc
;
1913 char servername
[]= "0.example.com";
1915 servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
1917 test_true(1 == memcached_server_list_count(servers
));
1919 for (x
= 2; x
< 20; x
++)
1921 char buffer
[SMALL_STRING_LEN
];
1923 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
1924 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
1926 test_compare(MEMCACHED_SUCCESS
, rc
);
1927 test_true(x
== memcached_server_list_count(servers
));
1930 rc
= memcached_server_push(memc
, servers
);
1931 test_compare(MEMCACHED_SUCCESS
, rc
);
1932 rc
= memcached_server_push(memc
, servers
);
1933 test_compare(MEMCACHED_SUCCESS
, rc
);
1935 memcached_server_list_free(servers
);
1937 return TEST_SUCCESS
;
1940 static test_return_t
memcached_fetch_result_NOT_FOUND(memcached_st
*memc
)
1942 memcached_return_t rc
;
1943 const char *key
= "not_found";
1944 size_t key_len
= strlen(key
);
1946 test_compare(MEMCACHED_SUCCESS
,
1947 memcached_mget(memc
, &key
, &key_len
, 1));
1949 memcached_result_st
*result
= NULL
;
1950 result
= memcached_fetch_result(memc
, result
, &rc
);
1952 test_compare_got(MEMCACHED_NOTFOUND
, rc
, memcached_strerror(NULL
, rc
));
1954 memcached_result_free(result
);
1956 return TEST_SUCCESS
;
1959 static memcached_return_t
clone_test_callback(memcached_st
*parent
, memcached_st
*memc_clone
)
1961 (void)parent
;(void)memc_clone
;
1962 return MEMCACHED_SUCCESS
;
1965 static memcached_return_t
cleanup_test_callback(memcached_st
*ptr
)
1968 return MEMCACHED_SUCCESS
;
1971 static test_return_t
callback_test(memcached_st
*memc
)
1973 /* Test User Data */
1977 memcached_return_t rc
;
1979 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_USER_DATA
, &x
);
1980 test_compare(MEMCACHED_SUCCESS
, rc
);
1981 test_ptr
= (int *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_USER_DATA
, &rc
);
1982 test_true(*test_ptr
== x
);
1985 /* Test Clone Callback */
1987 memcached_clone_fn clone_cb
= (memcached_clone_fn
)clone_test_callback
;
1988 void *clone_cb_ptr
= *(void **)&clone_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
== clone_cb_ptr
);
1999 /* Test Cleanup Callback */
2001 memcached_cleanup_fn cleanup_cb
=
2002 (memcached_cleanup_fn
)cleanup_test_callback
;
2003 void *cleanup_cb_ptr
= *(void **)&cleanup_cb
;
2004 void *temp_function
= NULL
;
2005 memcached_return_t rc
;
2007 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
,
2009 test_compare(MEMCACHED_SUCCESS
, rc
);
2010 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
2011 test_true(temp_function
== cleanup_cb_ptr
);
2014 return TEST_SUCCESS
;
2017 /* We don't test the behavior itself, we test the switches */
2018 static test_return_t
behavior_test(memcached_st
*memc
)
2023 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2024 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
2025 test_true(value
== 1);
2027 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2028 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
2029 test_true(value
== 1);
2031 set
= MEMCACHED_HASH_MD5
;
2032 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
2033 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
2034 test_true(value
== MEMCACHED_HASH_MD5
);
2038 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2039 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
2040 test_true(value
== 0);
2042 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2043 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
2044 test_true(value
== 0);
2046 set
= MEMCACHED_HASH_DEFAULT
;
2047 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
2048 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
2049 test_true(value
== MEMCACHED_HASH_DEFAULT
);
2051 set
= MEMCACHED_HASH_CRC
;
2052 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, set
);
2053 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
2054 test_true(value
== MEMCACHED_HASH_CRC
);
2056 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
2057 test_true(value
> 0);
2059 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
2060 test_true(value
> 0);
2062 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
);
2063 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, value
+ 1);
2064 test_true((value
+ 1) == memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
));
2066 return TEST_SUCCESS
;
2069 static test_return_t
MEMCACHED_BEHAVIOR_CORK_test(memcached_st
*memc
)
2071 memcached_return_t rc
;
2074 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CORK
, set
);
2075 test_true(rc
== MEMCACHED_DEPRECATED
);
2077 // Platform dependent
2079 bool value
= (bool)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_CORK
);
2083 return TEST_SUCCESS
;
2087 static test_return_t
MEMCACHED_BEHAVIOR_TCP_KEEPALIVE_test(memcached_st
*memc
)
2089 memcached_return_t rc
;
2093 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE
, set
);
2094 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_NOT_SUPPORTED
);
2096 value
= (bool)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE
);
2098 if (rc
== MEMCACHED_SUCCESS
)
2100 test_true((bool)value
== set
);
2104 test_false((bool)value
== set
);
2107 return TEST_SUCCESS
;
2111 static test_return_t
MEMCACHED_BEHAVIOR_TCP_KEEPIDLE_test(memcached_st
*memc
)
2113 memcached_return_t rc
;
2117 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_KEEPIDLE
, set
);
2118 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_NOT_SUPPORTED
);
2120 value
= (bool)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_KEEPIDLE
);
2122 if (rc
== MEMCACHED_SUCCESS
)
2124 test_true((bool)value
== set
);
2128 test_false((bool)value
== set
);
2131 return TEST_SUCCESS
;
2134 static test_return_t
fetch_all_results(memcached_st
*memc
, size_t &keys_returned
, const memcached_return_t expect
)
2136 memcached_return_t rc
;
2137 char return_key
[MEMCACHED_MAX_KEY
];
2138 size_t return_key_length
;
2140 size_t return_value_length
;
2144 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2145 &return_value_length
, &flags
, &rc
)))
2147 test_true(return_value
);
2148 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
2153 if (memcached_success(expect
) and memcached_success(rc
))
2155 return TEST_SUCCESS
;
2157 else if (expect
== rc
)
2159 return TEST_SUCCESS
;
2161 fprintf(stderr
, "\n%s:%u %s(#%lu)\n", __FILE__
, __LINE__
, memcached_strerror(NULL
, rc
), (unsigned long)(keys_returned
));
2163 return TEST_FAILURE
;
2166 /* Test case provided by Cal Haldenbrand */
2167 #define HALDENBRAND_KEY_COUNT 3000 // * 1024576
2168 #define HALDENBRAND_FLAG_KEY 99 // * 1024576
2169 static test_return_t
user_supplied_bug1(memcached_st
*memc
)
2171 /* We just keep looking at the same values over and over */
2174 unsigned int setter
= 1;
2175 test_compare(MEMCACHED_SUCCESS
,
2176 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
));
2177 test_compare(MEMCACHED_SUCCESS
,
2178 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
));
2182 unsigned long long total
= 0;
2183 for (uint32_t x
= 0 ; total
< 20 * 1024576 ; x
++ )
2185 uint32_t size
= (uint32_t)(rand() % ( 5 * 1024 ) ) + 400;
2186 char randomstuff
[6 * 1024];
2187 memset(randomstuff
, 0, 6 * 1024);
2188 test_true(size
< 6 * 1024); /* Being safe here */
2190 for (uint32_t j
= 0 ; j
< size
;j
++)
2192 randomstuff
[j
] = (signed char) ((rand() % 26) + 97);
2197 int key_length
= snprintf(key
, sizeof(key
), "%u", x
);
2198 memcached_return_t rc
;
2199 test_compare_got(MEMCACHED_SUCCESS
,
2200 rc
= memcached_set(memc
, key
, key_length
, randomstuff
, strlen(randomstuff
), time_t(0), HALDENBRAND_FLAG_KEY
),
2201 memcached_strerror(NULL
, rc
));
2203 test_true(total
> HALDENBRAND_KEY_COUNT
);
2205 return TEST_SUCCESS
;
2208 /* Test case provided by Cal Haldenbrand */
2209 static test_return_t
user_supplied_bug2(memcached_st
*memc
)
2211 unsigned int setter
= 1;
2213 test_compare(MEMCACHED_SUCCESS
,
2214 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
));
2216 test_compare(MEMCACHED_SUCCESS
,
2217 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
));
2220 setter
= 20 * 1024576;
2221 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
2222 setter
= 20 * 1024576;
2223 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
2224 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
2225 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
2227 for (x
= 0, errors
= 0; total
< 20 * 1024576 ; x
++)
2230 size_t total_value_length
= 0;
2231 for (uint32_t x
= 0, errors
= 0; total_value_length
< 24576 ; x
++)
2236 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1];
2237 int key_length
= snprintf(key
, sizeof(key
), "%u", x
);
2239 memcached_return_t rc
;
2240 char *getval
= memcached_get(memc
, key
, key_length
, &val_len
, &flags
, &rc
);
2241 if (memcached_failed(rc
))
2243 if (rc
== MEMCACHED_NOTFOUND
)
2254 test_compare(HALDENBRAND_FLAG_KEY
, flags
);
2256 total_value_length
+= val_len
;
2261 return TEST_SUCCESS
;
2264 /* Do a large mget() over all the keys we think exist */
2265 static test_return_t
user_supplied_bug3(memcached_st
*memc
)
2267 unsigned int setter
= 1;
2268 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, setter
);
2269 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2271 setter
= 20 * 1024576;
2272 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, setter
);
2273 setter
= 20 * 1024576;
2274 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, setter
);
2275 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
2276 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
2279 size_t key_lengths
[HALDENBRAND_KEY_COUNT
];
2280 char **keys
= static_cast<char **>(calloc(HALDENBRAND_KEY_COUNT
, sizeof(char *)));
2282 for (uint32_t x
= 0; x
< HALDENBRAND_KEY_COUNT
; x
++)
2284 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1];
2285 int key_length
= snprintf(key
, sizeof(key
), "%u", x
);
2286 keys
[x
]= strdup(key
);
2288 key_lengths
[x
]= key_length
;
2289 test_compare(size_t(key_length
), strlen(keys
[x
]));
2292 test_compare(MEMCACHED_SUCCESS
,
2293 memcached_mget(memc
, (const char **)keys
, key_lengths
, HALDENBRAND_KEY_COUNT
));
2296 size_t keys_returned
;
2297 test_compare_got(TEST_SUCCESS
, foo
= fetch_all_results(memc
, keys_returned
, MEMCACHED_SUCCESS
), test_strerror(foo
));
2298 test_compare(HALDENBRAND_KEY_COUNT
, keys_returned
);
2300 for (uint32_t x
= 0; x
< HALDENBRAND_KEY_COUNT
; x
++)
2306 return TEST_SUCCESS
;
2309 /* Make sure we behave properly if server list has no values */
2310 static test_return_t
user_supplied_bug4(memcached_st
*memc
)
2312 const char *keys
[]= {"fudge", "son", "food"};
2313 size_t key_length
[]= {5, 3, 4};
2315 /* Here we free everything before running a bunch of mget tests */
2316 memcached_servers_reset(memc
);
2319 /* We need to empty the server before continueing test */
2320 test_compare(MEMCACHED_NO_SERVERS
,
2321 memcached_flush(memc
, 0));
2323 test_compare(MEMCACHED_NO_SERVERS
,
2324 memcached_mget(memc
, keys
, key_length
, 3));
2326 size_t keys_returned
;
2327 test_compare(TEST_SUCCESS
, fetch_all_results(memc
, keys_returned
, MEMCACHED_NOTFOUND
));
2328 test_compare(0, keys_returned
);
2330 for (uint32_t x
= 0; x
< 3; x
++)
2332 test_compare(MEMCACHED_NO_SERVERS
,
2333 memcached_set(memc
, keys
[x
], key_length
[x
],
2334 keys
[x
], key_length
[x
],
2335 (time_t)50, (uint32_t)9));
2338 test_compare(MEMCACHED_NO_SERVERS
,
2339 memcached_mget(memc
, keys
, key_length
, 3));
2343 char return_key
[MEMCACHED_MAX_KEY
];
2344 memcached_return_t rc
;
2345 size_t return_key_length
;
2346 size_t return_value_length
;
2349 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2350 &return_value_length
, &flags
, &rc
)))
2352 test_true(return_value
);
2353 test_compare(MEMCACHED_SUCCESS
, rc
);
2354 test_true(return_key_length
== return_value_length
);
2355 test_memcmp(return_value
, return_key
, return_value_length
);
2361 return TEST_SUCCESS
;
2364 #define VALUE_SIZE_BUG5 1048064
2365 static test_return_t
user_supplied_bug5(memcached_st
*memc
)
2367 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
2368 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
2370 size_t value_length
;
2372 char *insert_data
= new (std::nothrow
) char[VALUE_SIZE_BUG5
];
2374 for (uint32_t x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2376 insert_data
[x
]= (signed char)rand();
2379 test_compare(MEMCACHED_SUCCESS
,
2380 memcached_flush(memc
, 0));
2382 memcached_return_t rc
;
2383 value
= memcached_get(memc
, keys
[0], key_length
[0],
2384 &value_length
, &flags
, &rc
);
2386 test_compare(MEMCACHED_SUCCESS
,
2387 memcached_mget(memc
, keys
, key_length
, 4));
2390 test_compare(TEST_SUCCESS
, fetch_all_results(memc
, count
, MEMCACHED_NOTFOUND
));
2391 test_compare(0, count
);
2393 for (uint32_t x
= 0; x
< 4; x
++)
2395 test_compare(MEMCACHED_SUCCESS
,
2396 memcached_set(memc
, keys
[x
], key_length
[x
],
2397 insert_data
, VALUE_SIZE_BUG5
,
2398 (time_t)0, (uint32_t)0));
2401 for (uint32_t x
= 0; x
< 10; x
++)
2403 value
= memcached_get(memc
, keys
[0], key_length
[0],
2404 &value_length
, &flags
, &rc
);
2405 test_compare(rc
, MEMCACHED_SUCCESS
);
2409 test_compare(MEMCACHED_SUCCESS
,
2410 memcached_mget(memc
, keys
, key_length
, 4));
2412 test_compare(TEST_SUCCESS
, fetch_all_results(memc
, count
, MEMCACHED_SUCCESS
));
2413 test_compare(4, count
);
2415 delete [] insert_data
;
2417 return TEST_SUCCESS
;
2420 static test_return_t
user_supplied_bug6(memcached_st
*memc
)
2422 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
2423 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
2424 char return_key
[MEMCACHED_MAX_KEY
];
2425 size_t return_key_length
;
2427 size_t value_length
;
2429 char *insert_data
= new (std::nothrow
) char[VALUE_SIZE_BUG5
];
2431 for (uint32_t x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2433 insert_data
[x
]= (signed char)rand();
2436 test_compare(MEMCACHED_SUCCESS
,
2437 memcached_flush(memc
, 0));
2439 memcached_return_t rc
;
2440 value
= memcached_get(memc
, keys
[0], key_length
[0],
2441 &value_length
, &flags
, &rc
);
2443 test_compare(MEMCACHED_NOTFOUND
, rc
);
2445 test_compare(MEMCACHED_SUCCESS
,
2446 memcached_mget(memc
, keys
, key_length
, 4));
2449 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2450 &value_length
, &flags
, &rc
)))
2454 test_compare(0, count
);
2455 test_compare_got(MEMCACHED_NOTFOUND
, rc
, memcached_strerror(NULL
, rc
));
2457 for (uint32_t x
= 0; x
< 4; x
++)
2459 test_compare(MEMCACHED_SUCCESS
,
2460 memcached_set(memc
, keys
[x
], key_length
[x
],
2461 insert_data
, VALUE_SIZE_BUG5
,
2462 (time_t)0, (uint32_t)0));
2465 for (uint32_t x
= 0; x
< 2; x
++)
2467 value
= memcached_get(memc
, keys
[0], key_length
[0],
2468 &value_length
, &flags
, &rc
);
2472 test_compare(MEMCACHED_SUCCESS
,
2473 memcached_mget(memc
, keys
, key_length
, 4));
2475 /* We test for purge of partial complete fetches */
2476 for (count
= 3; count
; count
--)
2478 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2479 &value_length
, &flags
, &rc
);
2480 test_compare(MEMCACHED_SUCCESS
, rc
);
2481 test_memcmp(value
, insert_data
, value_length
);
2482 test_true(value_length
);
2486 delete [] insert_data
;
2488 return TEST_SUCCESS
;
2491 static test_return_t
user_supplied_bug8(memcached_st
*)
2493 memcached_return_t rc
;
2495 memcached_st
*memc_clone
;
2497 memcached_server_st
*servers
;
2498 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";
2500 servers
= memcached_servers_parse(server_list
);
2503 mine
= memcached_create(NULL
);
2504 rc
= memcached_server_push(mine
, servers
);
2505 test_compare(MEMCACHED_SUCCESS
, rc
);
2506 memcached_server_list_free(servers
);
2509 memc_clone
= memcached_clone(NULL
, mine
);
2511 memcached_quit(mine
);
2512 memcached_quit(memc_clone
);
2515 memcached_free(mine
);
2516 memcached_free(memc_clone
);
2518 return TEST_SUCCESS
;
2521 /* Test flag store/retrieve */
2522 static test_return_t
user_supplied_bug7(memcached_st
*memc
)
2524 const char *keys
= "036790384900";
2525 size_t key_length
= strlen(keys
);
2526 char return_key
[MEMCACHED_MAX_KEY
];
2527 size_t return_key_length
;
2529 size_t value_length
;
2531 char *insert_data
= new (std::nothrow
) char[VALUE_SIZE_BUG5
];
2533 for (unsigned int x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2534 insert_data
[x
]= (signed char)rand();
2536 memcached_flush(memc
, 0);
2539 memcached_return_t rc
= memcached_set(memc
, keys
, key_length
,
2540 insert_data
, VALUE_SIZE_BUG5
,
2542 test_compare(MEMCACHED_SUCCESS
, rc
);
2545 value
= memcached_get(memc
, keys
, key_length
,
2546 &value_length
, &flags
, &rc
);
2547 test_true(flags
== 245);
2551 rc
= memcached_mget(memc
, &keys
, &key_length
, 1);
2554 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2555 &value_length
, &flags
, &rc
);
2556 test_compare(245, flags
);
2559 delete [] insert_data
;
2562 return TEST_SUCCESS
;
2565 static test_return_t
user_supplied_bug9(memcached_st
*memc
)
2567 const char *keys
[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
2568 size_t key_length
[3];
2572 char return_key
[MEMCACHED_MAX_KEY
];
2573 size_t return_key_length
;
2575 size_t return_value_length
;
2578 key_length
[0]= strlen("UDATA:edevil@sapo.pt");
2579 key_length
[1]= strlen("fudge&*@#");
2580 key_length
[2]= strlen("for^#@&$not");
2583 for (unsigned int x
= 0; x
< 3; x
++)
2585 memcached_return_t rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2586 keys
[x
], key_length
[x
],
2587 (time_t)50, (uint32_t)9);
2588 test_compare(MEMCACHED_SUCCESS
, rc
);
2591 memcached_return_t rc
= memcached_mget(memc
, keys
, key_length
, 3);
2592 test_compare(MEMCACHED_SUCCESS
, rc
);
2594 /* We need to empty the server before continueing test */
2595 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2596 &return_value_length
, &flags
, &rc
)) != NULL
)
2598 test_true(return_value
);
2602 test_compare(3, count
);
2604 return TEST_SUCCESS
;
2607 /* We are testing with aggressive timeout to get failures */
2608 static test_return_t
user_supplied_bug10(memcached_st
*memc
)
2610 const char *key
= "foo";
2611 size_t value_length
= 512;
2613 unsigned int set
= 1;
2614 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2616 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2617 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2619 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, (uint64_t)timeout
);
2621 char *value
= (char*)malloc(value_length
* sizeof(char));
2623 for (unsigned int x
= 0; x
< value_length
; x
++)
2625 value
[x
]= (char) (x
% 127);
2628 for (unsigned int x
= 1; x
<= 100000; ++x
)
2630 memcached_return_t rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2632 test_true_got(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_WRITE_FAILURE
or rc
== MEMCACHED_BUFFERED
or rc
== MEMCACHED_TIMEOUT
or rc
== MEMCACHED_CONNECTION_FAILURE
,
2633 memcached_strerror(NULL
, rc
));
2635 if (rc
== MEMCACHED_WRITE_FAILURE
or rc
== MEMCACHED_TIMEOUT
)
2642 memcached_free(mclone
);
2644 return TEST_SUCCESS
;
2648 We are looking failures in the async protocol
2650 static test_return_t
user_supplied_bug11(memcached_st
*memc
)
2652 const char *key
= "foo";
2653 size_t value_length
= 512;
2655 unsigned int set
= 1;
2656 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2658 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2659 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2660 int32_t timeout
= -1;
2661 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, (size_t)timeout
);
2663 timeout
= (int32_t)memcached_behavior_get(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
2665 test_true(timeout
== -1);
2667 char *value
= (char*)malloc(value_length
* sizeof(char));
2669 for (unsigned int x
= 0; x
< value_length
; x
++)
2671 value
[x
]= (char) (x
% 127);
2674 for (unsigned int x
= 1; x
<= 100000; ++x
)
2676 memcached_return_t rc
= memcached_set(mclone
, key
, key_len
,value
, value_length
, 0, 0);
2681 memcached_free(mclone
);
2683 return TEST_SUCCESS
;
2687 Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
2689 static test_return_t
user_supplied_bug12(memcached_st
*memc
)
2691 memcached_return_t rc
;
2693 size_t value_length
;
2695 uint64_t number_value
;
2697 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2698 &value_length
, &flags
, &rc
);
2699 test_true(value
== NULL
);
2700 test_compare(MEMCACHED_NOTFOUND
, rc
);
2702 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2705 test_true(value
== NULL
);
2706 /* The binary protocol will set the key if it doesn't exist */
2707 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1)
2709 test_compare(MEMCACHED_SUCCESS
, rc
);
2713 test_compare(MEMCACHED_NOTFOUND
, rc
);
2716 rc
= memcached_set(memc
, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
2718 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2719 &value_length
, &flags
, &rc
);
2721 test_compare(MEMCACHED_SUCCESS
, rc
);
2724 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2726 test_true(number_value
== 2);
2727 test_compare(MEMCACHED_SUCCESS
, rc
);
2729 return TEST_SUCCESS
;
2733 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2734 set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
2736 static test_return_t
user_supplied_bug13(memcached_st
*memc
)
2738 char key
[] = "key34567890";
2739 memcached_return_t rc
;
2740 size_t overflowSize
;
2742 char commandFirst
[]= "set key34567890 0 0 ";
2743 char commandLast
[] = " \r\n"; /* first line of command sent to server */
2744 size_t commandLength
;
2747 commandLength
= strlen(commandFirst
) + strlen(commandLast
) + 4; /* 4 is number of characters in size, probably 8196 */
2749 overflowSize
= MEMCACHED_MAX_BUFFER
- commandLength
;
2751 for (testSize
= overflowSize
- 1; testSize
< overflowSize
+ 1; testSize
++)
2753 char *overflow
= new (std::nothrow
) char[testSize
];
2754 test_true(overflow
);
2756 memset(overflow
, 'x', testSize
);
2757 rc
= memcached_set(memc
, key
, strlen(key
),
2758 overflow
, testSize
, 0, 0);
2759 test_compare(MEMCACHED_SUCCESS
, rc
);
2763 return TEST_SUCCESS
;
2768 Test values of many different sizes
2769 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2770 set key34567890 0 0 8169 \r\n
2771 is sent followed by buffer of size 8169, followed by 8169
2773 static test_return_t
user_supplied_bug14(memcached_st
*memc
)
2776 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, setter
);
2777 memcached_return_t rc
;
2778 const char *key
= "foo";
2780 size_t value_length
= 18000;
2782 size_t string_length
;
2785 size_t current_length
;
2787 value
= (char*)malloc(value_length
);
2790 for (x
= 0; x
< value_length
; x
++)
2791 value
[x
] = (char) (x
% 127);
2793 for (current_length
= 0; current_length
< value_length
; current_length
++)
2795 rc
= memcached_set(memc
, key
, strlen(key
),
2796 value
, current_length
,
2797 (time_t)0, (uint32_t)0);
2798 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
2800 string
= memcached_get(memc
, key
, strlen(key
),
2801 &string_length
, &flags
, &rc
);
2803 test_compare(MEMCACHED_SUCCESS
, rc
);
2804 test_true(string_length
== current_length
);
2805 test_memcmp(string
, value
, string_length
);
2812 return TEST_SUCCESS
;
2816 Look for zero length value problems
2818 static test_return_t
user_supplied_bug15(memcached_st
*memc
)
2821 memcached_return_t rc
;
2822 const char *key
= "mykey";
2826 for (x
= 0; x
< 2; x
++)
2828 rc
= memcached_set(memc
, key
, strlen(key
),
2830 (time_t)0, (uint32_t)0);
2832 test_compare(MEMCACHED_SUCCESS
, rc
);
2834 char *value
= memcached_get(memc
, key
, strlen(key
),
2835 &length
, &flags
, &rc
);
2837 test_compare(MEMCACHED_SUCCESS
, rc
);
2842 value
= memcached_get(memc
, key
, strlen(key
),
2843 &length
, &flags
, &rc
);
2845 test_compare(MEMCACHED_SUCCESS
, rc
);
2846 test_true(value
== NULL
);
2847 test_true(length
== 0);
2848 test_true(flags
== 0);
2851 return TEST_SUCCESS
;
2854 /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
2855 static test_return_t
user_supplied_bug16(memcached_st
*memc
)
2857 memcached_return_t rc
;
2858 const char *key
= "mykey";
2863 rc
= memcached_set(memc
, key
, strlen(key
),
2865 (time_t)0, UINT32_MAX
);
2867 test_compare(MEMCACHED_SUCCESS
, rc
);
2869 value
= memcached_get(memc
, key
, strlen(key
),
2870 &length
, &flags
, &rc
);
2872 test_compare(MEMCACHED_SUCCESS
, rc
);
2873 test_true(value
== NULL
);
2874 test_true(length
== 0);
2875 test_true(flags
== UINT32_MAX
);
2877 return TEST_SUCCESS
;
2880 #if !defined(__sun) && !defined(__OpenBSD__)
2881 /* Check the validity of chinese key*/
2882 static test_return_t
user_supplied_bug17(memcached_st
*memc
)
2884 memcached_return_t rc
;
2885 const char *key
= "豆瓣";
2886 const char *value
="我们在炎热抑郁的夏天无法停止豆瓣";
2891 rc
= memcached_set(memc
, key
, strlen(key
),
2892 value
, strlen(value
),
2895 test_compare(MEMCACHED_SUCCESS
, rc
);
2897 value2
= memcached_get(memc
, key
, strlen(key
),
2898 &length
, &flags
, &rc
);
2900 test_true(length
==strlen(value
));
2901 test_compare(MEMCACHED_SUCCESS
, rc
);
2902 test_memcmp(value
, value2
, length
);
2905 return TEST_SUCCESS
;
2913 static test_return_t
user_supplied_bug19(memcached_st
*not_used
)
2916 const memcached_server_st
*server
;
2917 memcached_return_t res
;
2921 memc
= memcached_create(NULL
);
2922 memcached_server_add_with_weight(memc
, "localhost", 11311, 100);
2923 memcached_server_add_with_weight(memc
, "localhost", 11312, 100);
2925 server
= memcached_server_by_key(memc
, "a", 1, &res
);
2927 memcached_free(memc
);
2929 return TEST_SUCCESS
;
2932 /* CAS test from Andei */
2933 static test_return_t
user_supplied_bug20(memcached_st
*memc
)
2935 memcached_return_t status
;
2936 memcached_result_st
*result
, result_obj
;
2937 const char *key
= "abc";
2938 size_t key_len
= strlen("abc");
2939 const char *value
= "foobar";
2940 size_t value_len
= strlen(value
);
2942 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
2944 status
= memcached_set(memc
, key
, key_len
, value
, value_len
, (time_t)0, (uint32_t)0);
2945 test_true(status
== MEMCACHED_SUCCESS
);
2947 status
= memcached_mget(memc
, &key
, &key_len
, 1);
2948 test_true(status
== MEMCACHED_SUCCESS
);
2950 result
= memcached_result_create(memc
, &result_obj
);
2953 memcached_result_create(memc
, &result_obj
);
2954 result
= memcached_fetch_result(memc
, &result_obj
, &status
);
2957 test_true(status
== MEMCACHED_SUCCESS
);
2959 memcached_result_free(result
);
2961 return TEST_SUCCESS
;
2964 #include "ketama_test_cases.h"
2965 static test_return_t
user_supplied_bug18(memcached_st
*trash
)
2967 memcached_return_t rc
;
2974 memc
= memcached_create(NULL
);
2977 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
2978 test_compare(MEMCACHED_SUCCESS
, rc
);
2980 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2981 test_true(value
== 1);
2983 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
2984 test_compare(MEMCACHED_SUCCESS
, rc
);
2986 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2987 test_true(value
== MEMCACHED_HASH_MD5
);
2989 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");
2990 memcached_server_push(memc
, server_pool
);
2992 /* verify that the server list was parsed okay. */
2993 test_true(memcached_server_count(memc
) == 8);
2994 test_strcmp(server_pool
[0].hostname
, "10.0.1.1");
2995 test_true(server_pool
[0].port
== 11211);
2996 test_true(server_pool
[0].weight
== 600);
2997 test_strcmp(server_pool
[2].hostname
, "10.0.1.3");
2998 test_true(server_pool
[2].port
== 11211);
2999 test_true(server_pool
[2].weight
== 200);
3000 test_strcmp(server_pool
[7].hostname
, "10.0.1.8");
3001 test_true(server_pool
[7].port
== 11211);
3002 test_true(server_pool
[7].weight
== 100);
3004 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
3005 * us test the boundary wraparound.
3007 test_true(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->ketama
.continuum
[0].index
);
3009 /* verify the standard ketama set. */
3010 for (x
= 0; x
< 99; x
++)
3012 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
3014 memcached_server_instance_st instance
=
3015 memcached_server_instance_by_position(memc
, server_idx
);
3017 const char *hostname
= memcached_server_name(instance
);
3018 test_strcmp(hostname
, ketama_test_cases
[x
].server
);
3021 memcached_server_list_free(server_pool
);
3022 memcached_free(memc
);
3024 return TEST_SUCCESS
;
3027 /* Large mget() of missing keys with binary proto
3029 * If many binary quiet commands (such as getq's in an mget) fill the output
3030 * buffer and the server chooses not to respond, memcached_flush hangs. See
3031 * http://lists.tangent.org/pipermail/libmemcached/2009-August/000918.html
3034 /* sighandler_t function that always asserts false */
3035 static void fail(int)
3041 static test_return_t
_user_supplied_bug21(memcached_st
* memc
, size_t key_count
)
3046 return TEST_SKIPPED
;
3048 void (*oldalarm
)(int);
3050 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
3051 test_true(memc_clone
);
3053 /* only binproto uses getq for mget */
3054 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1));
3056 /* empty the cache to ensure misses (hence non-responses) */
3057 test_compare(MEMCACHED_SUCCESS
, memcached_flush(memc_clone
, 0));
3059 size_t* key_lengths
= new (std::nothrow
) size_t[key_count
];
3060 test_true(key_lengths
);
3061 char **keys
= static_cast<char **>(calloc(key_count
, sizeof(char *)));
3063 for (unsigned int x
= 0; x
< key_count
; x
++)
3067 snprintf(buffer
, 30, "%u", x
);
3068 keys
[x
]= strdup(buffer
);
3070 key_lengths
[x
]= strlen(keys
[x
]);
3073 oldalarm
= signal(SIGALRM
, fail
);
3076 test_compare_got(MEMCACHED_SUCCESS
,
3077 memcached_mget(memc_clone
, (const char **)keys
, key_lengths
, key_count
), memcached_last_error_message(memc_clone
));
3080 signal(SIGALRM
, oldalarm
);
3082 memcached_return_t rc
;
3084 char return_key
[MEMCACHED_MAX_KEY
];
3085 size_t return_key_length
;
3087 size_t return_value_length
;
3088 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
3089 &return_value_length
, &flags
, &rc
)))
3091 test_false(return_value
); // There are no keys to fetch, so the value should never be returned
3093 test_compare(MEMCACHED_NOTFOUND
, rc
);
3094 test_compare(0, return_value_length
);
3095 test_compare(0, return_key_length
);
3096 test_false(return_key
[0]);
3097 test_false(return_value
);
3099 for (unsigned int x
= 0; x
< key_count
; x
++)
3104 delete [] key_lengths
;
3106 memcached_free(memc_clone
);
3108 return TEST_SUCCESS
;
3112 static test_return_t
user_supplied_bug21(memcached_st
*memc
)
3114 test_return_t test_rc
;
3115 test_rc
= pre_binary(memc
);
3117 if (test_rc
!= TEST_SUCCESS
)
3120 /* should work as of r580 */
3121 test_compare(TEST_SUCCESS
,
3122 _user_supplied_bug21(memc
, 10));
3124 /* should fail as of r580 */
3125 test_compare(TEST_SUCCESS
,
3126 _user_supplied_bug21(memc
, 1000));
3128 return TEST_SUCCESS
;
3131 static test_return_t
auto_eject_hosts(memcached_st
*trash
)
3134 memcached_server_instance_st instance
;
3136 memcached_return_t rc
;
3137 memcached_st
*memc
= memcached_create(NULL
);
3140 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
3141 test_compare(MEMCACHED_SUCCESS
, rc
);
3143 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
3144 test_true(value
== 1);
3146 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
3147 test_compare(MEMCACHED_SUCCESS
, rc
);
3149 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
3150 test_true(value
== MEMCACHED_HASH_MD5
);
3152 /* server should be removed when in delay */
3153 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
, 1);
3154 test_compare(MEMCACHED_SUCCESS
, rc
);
3156 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS
);
3157 test_true(value
== 1);
3159 memcached_server_st
*server_pool
;
3160 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");
3161 memcached_server_push(memc
, server_pool
);
3163 /* verify that the server list was parsed okay. */
3164 test_true(memcached_server_count(memc
) == 8);
3165 test_strcmp(server_pool
[0].hostname
, "10.0.1.1");
3166 test_true(server_pool
[0].port
== 11211);
3167 test_true(server_pool
[0].weight
== 600);
3168 test_strcmp(server_pool
[2].hostname
, "10.0.1.3");
3169 test_true(server_pool
[2].port
== 11211);
3170 test_true(server_pool
[2].weight
== 200);
3171 test_strcmp(server_pool
[7].hostname
, "10.0.1.8");
3172 test_true(server_pool
[7].port
== 11211);
3173 test_true(server_pool
[7].weight
== 100);
3175 instance
= memcached_server_instance_by_position(memc
, 2);
3176 ((memcached_server_write_instance_st
)instance
)->next_retry
= time(NULL
) + 15;
3177 memc
->ketama
.next_distribution_rebuild
= time(NULL
) - 1;
3180 This would not work if there were only two hosts.
3182 for (size_t x
= 0; x
< 99; x
++)
3184 memcached_autoeject(memc
);
3185 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
3186 test_true(server_idx
!= 2);
3189 /* and re-added when it's back. */
3190 ((memcached_server_write_instance_st
)instance
)->next_retry
= time(NULL
) - 1;
3191 memc
->ketama
.next_distribution_rebuild
= time(NULL
) - 1;
3192 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
,
3193 memc
->distribution
);
3194 for (size_t x
= 0; x
< 99; x
++)
3196 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
3197 // We re-use instance from above.
3199 memcached_server_instance_by_position(memc
, server_idx
);
3200 const char *hostname
= memcached_server_name(instance
);
3201 test_strcmp(hostname
, ketama_test_cases
[x
].server
);
3204 memcached_server_list_free(server_pool
);
3205 memcached_free(memc
);
3207 return TEST_SUCCESS
;
3210 static test_return_t
output_ketama_weighted_keys(memcached_st
*trash
)
3214 memcached_return_t rc
;
3215 memcached_st
*memc
= memcached_create(NULL
);
3219 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
3220 test_compare(MEMCACHED_SUCCESS
, rc
);
3222 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
3223 test_true(value
== 1);
3225 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
3226 test_compare(MEMCACHED_SUCCESS
, rc
);
3228 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
3229 test_true(value
== MEMCACHED_HASH_MD5
);
3232 test_true(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
) == MEMCACHED_SUCCESS
);
3234 memcached_server_st
*server_pool
;
3235 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");
3236 memcached_server_push(memc
, server_pool
);
3238 // @todo this needs to be refactored to actually test something.
3241 if ((fp
= fopen("ketama_keys.txt", "w")))
3245 printf("cannot write to file ketama_keys.txt");
3246 return TEST_FAILURE
;
3249 for (int x
= 0; x
< 10000; x
++)
3252 snprintf(key
, sizeof(key
), "%d", x
);
3254 uint32_t server_idx
= memcached_generate_hash(memc
, key
, strlen(key
));
3255 char *hostname
= memc
->hosts
[server_idx
].hostname
;
3256 in_port_t port
= memc
->hosts
[server_idx
].port
;
3257 fprintf(fp
, "key %s is on host /%s:%u\n", key
, hostname
, port
);
3258 memcached_server_instance_st instance
=
3259 memcached_server_instance_by_position(memc
, host_index
);
3263 memcached_server_list_free(server_pool
);
3264 memcached_free(memc
);
3266 return TEST_SUCCESS
;
3270 static test_return_t
result_static(memcached_st
*memc
)
3272 memcached_result_st result
;
3273 memcached_result_st
*result_ptr
;
3275 result_ptr
= memcached_result_create(memc
, &result
);
3276 test_true(result
.options
.is_allocated
== false);
3277 test_true(memcached_is_initialized(&result
) == true);
3278 test_true(result_ptr
);
3279 test_true(result_ptr
== &result
);
3281 memcached_result_free(&result
);
3283 test_true(result
.options
.is_allocated
== false);
3284 test_true(memcached_is_initialized(&result
) == false);
3286 return TEST_SUCCESS
;
3289 static test_return_t
result_alloc(memcached_st
*memc
)
3291 memcached_result_st
*result_ptr
;
3293 result_ptr
= memcached_result_create(memc
, NULL
);
3294 test_true(result_ptr
);
3295 test_true(result_ptr
->options
.is_allocated
== true);
3296 test_true(memcached_is_initialized(result_ptr
) == true);
3297 memcached_result_free(result_ptr
);
3299 return TEST_SUCCESS
;
3302 static test_return_t
cleanup_pairs(memcached_st
*memc
)
3305 pairs_free(global_pairs
);
3307 return TEST_SUCCESS
;
3310 static test_return_t
generate_pairs(memcached_st
*memc
)
3313 global_pairs
= pairs_generate(GLOBAL_COUNT
, 400);
3314 global_count
= GLOBAL_COUNT
;
3316 for (size_t x
= 0; x
< global_count
; x
++)
3318 global_keys
[x
]= global_pairs
[x
].key
;
3319 global_keys_length
[x
]= global_pairs
[x
].key_length
;
3322 return TEST_SUCCESS
;
3325 static test_return_t
generate_large_pairs(memcached_st
*)
3327 global_pairs
= pairs_generate(GLOBAL2_COUNT
, MEMCACHED_MAX_BUFFER
+10);
3328 global_count
= GLOBAL2_COUNT
;
3330 for (size_t x
= 0; x
< global_count
; x
++)
3332 global_keys
[x
]= global_pairs
[x
].key
;
3333 global_keys_length
[x
]= global_pairs
[x
].key_length
;
3336 return TEST_SUCCESS
;
3339 static test_return_t
generate_data(memcached_st
*memc
)
3341 unsigned int check_execute
= execute_set(memc
, global_pairs
, global_count
);
3343 test_true(check_execute
== global_count
);
3345 return TEST_SUCCESS
;
3348 static test_return_t
generate_data_with_stats(memcached_st
*memc
)
3350 uint32_t host_index
= 0;
3351 unsigned int check_execute
= execute_set(memc
, global_pairs
, global_count
);
3353 test_true(check_execute
== global_count
);
3355 // @todo hosts used size stats
3356 memcached_return_t rc
;
3357 memcached_stat_st
*stat_p
= memcached_stat(memc
, NULL
, &rc
);
3360 for (host_index
= 0; host_index
< SERVERS_TO_CREATE
; host_index
++)
3362 /* This test was changes so that "make test" would work properlly */
3364 memcached_server_instance_st instance
=
3365 memcached_server_instance_by_position(memc
, host_index
);
3367 printf("\nserver %u|%s|%u bytes: %llu\n", host_index
, instance
->hostname
, instance
->port
, (unsigned long long)(stat_p
+ host_index
)->bytes
);
3369 test_true((unsigned long long)(stat_p
+ host_index
)->bytes
);
3372 memcached_stat_free(NULL
, stat_p
);
3374 return TEST_SUCCESS
;
3376 static test_return_t
generate_buffer_data(memcached_st
*memc
)
3381 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
3382 generate_data(memc
);
3384 return TEST_SUCCESS
;
3387 static test_return_t
get_read_count(memcached_st
*memc
)
3389 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
3390 test_true(memc_clone
);
3392 memcached_server_add_with_weight(memc_clone
, "localhost", 6666, 0);
3396 size_t return_value_length
;
3400 for (size_t x
= count
= 0; x
< global_count
; x
++)
3402 memcached_return_t rc
;
3403 return_value
= memcached_get(memc_clone
, global_keys
[x
], global_keys_length
[x
],
3404 &return_value_length
, &flags
, &rc
);
3405 if (rc
== MEMCACHED_SUCCESS
)
3414 memcached_free(memc_clone
);
3416 return TEST_SUCCESS
;
3419 static test_return_t
get_read(memcached_st
*memc
)
3421 for (size_t x
= 0; x
< global_count
; x
++)
3423 size_t return_value_length
;
3425 memcached_return_t rc
;
3426 char *return_value
= memcached_get(memc
, global_keys
[x
], global_keys_length
[x
],
3427 &return_value_length
, &flags
, &rc
);
3429 test_true(return_value);
3430 test_compare(MEMCACHED_SUCCESS, rc);
3432 if (rc
== MEMCACHED_SUCCESS
&& return_value
)
3436 return TEST_SUCCESS
;
3439 static test_return_t
mget_read(memcached_st
*memc
)
3442 test_skip(true, bool(libmemcached_util_version_check(memc
, 1, 4, 4)));
3444 memcached_return_t rc
;
3445 test_compare_got(MEMCACHED_SUCCESS
,
3446 rc
= memcached_mget(memc
, global_keys
, global_keys_length
, global_count
),
3447 memcached_strerror(NULL
, rc
));
3449 // Go fetch the keys and test to see if all of them were returned
3451 size_t keys_returned
;
3452 test_compare(TEST_SUCCESS
, fetch_all_results(memc
, keys_returned
, MEMCACHED_SUCCESS
));
3453 test_true(keys_returned
> 0);
3455 snprintf(buffer
, sizeof(buffer
), "%lu", (unsigned long)keys_returned
);
3456 test_compare_got(global_count
, keys_returned
, buffer
);
3459 return TEST_SUCCESS
;
3462 static test_return_t
mget_read_result(memcached_st
*memc
)
3465 test_skip(true, bool(libmemcached_util_version_check(memc
, 1, 4, 4)));
3467 test_compare(MEMCACHED_SUCCESS
,
3468 memcached_mget(memc
, global_keys
, global_keys_length
, global_count
));
3470 /* Turn this into a help function */
3472 memcached_result_st results_obj
;
3473 memcached_result_st
*results
= memcached_result_create(memc
, &results_obj
);
3475 memcached_return_t rc
;
3476 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
3479 test_compare(MEMCACHED_SUCCESS
, rc
);
3481 test_compare(MEMCACHED_END
, rc
);
3483 memcached_result_free(&results_obj
);
3486 return TEST_SUCCESS
;
3489 static test_return_t
mget_read_internal_result(memcached_st
*memc
)
3492 test_skip(true, bool(libmemcached_util_version_check(memc
, 1, 4, 4)));
3494 test_compare(MEMCACHED_SUCCESS
,
3495 memcached_mget(memc
, global_keys
, global_keys_length
, global_count
));
3497 memcached_result_st
*results
= NULL
;
3498 memcached_return_t rc
;
3499 while ((results
= memcached_fetch_result(memc
, results
, &rc
)))
3502 test_compare(MEMCACHED_SUCCESS
, rc
);
3504 test_compare(MEMCACHED_END
, rc
);
3506 memcached_result_free(results
);
3509 return TEST_SUCCESS
;
3512 static test_return_t
mget_read_partial_result(memcached_st
*memc
)
3515 test_skip(true, bool(libmemcached_util_version_check(memc
, 1, 4, 4)));
3517 test_compare(MEMCACHED_SUCCESS
,
3518 memcached_mget(memc
, global_keys
, global_keys_length
, global_count
));
3520 // We will scan for just one key
3522 memcached_result_st results_obj
;
3523 memcached_result_st
*results
= memcached_result_create(memc
, &results_obj
);
3525 memcached_return_t rc
;
3526 results
= memcached_fetch_result(memc
, results
, &rc
);
3528 test_compare(MEMCACHED_SUCCESS
, rc
);
3530 memcached_result_free(&results_obj
);
3533 // We already have a read happening, lets start up another one.
3534 test_compare(MEMCACHED_SUCCESS
,
3535 memcached_mget(memc
, global_keys
, global_keys_length
, global_count
));
3537 memcached_result_st results_obj
;
3538 memcached_result_st
*results
= memcached_result_create(memc
, &results_obj
);
3540 memcached_return_t rc
;
3541 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
3544 test_compare(MEMCACHED_SUCCESS
, rc
);
3546 test_compare(MEMCACHED_END
, rc
);
3548 memcached_result_free(&results_obj
);
3551 return TEST_SUCCESS
;
3554 static test_return_t
mget_read_function(memcached_st
*memc
)
3556 test_skip(true, bool(libmemcached_util_version_check(memc
, 1, 4, 4)));
3558 test_compare(MEMCACHED_SUCCESS
,
3559 memcached_mget(memc
, global_keys
, global_keys_length
, global_count
));
3561 memcached_execute_fn callbacks
[]= { &callback_counter
};
3563 test_compare(MEMCACHED_SUCCESS
,
3564 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
3566 return TEST_SUCCESS
;
3569 static test_return_t
delete_generate(memcached_st
*memc
)
3571 for (size_t x
= 0; x
< global_count
; x
++)
3573 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3576 return TEST_SUCCESS
;
3579 static test_return_t
delete_buffer_generate(memcached_st
*memc
)
3582 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, latch
);
3584 for (size_t x
= 0; x
< global_count
; x
++)
3586 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3589 return TEST_SUCCESS
;
3592 static test_return_t
add_host_test1(memcached_st
*memc
)
3594 memcached_return_t rc
;
3595 char servername
[]= "0.example.com";
3597 memcached_server_st
*servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
3599 test_compare(1, memcached_server_list_count(servers
));
3601 for (size_t x
= 2; x
< 20; x
++)
3603 char buffer
[SMALL_STRING_LEN
];
3605 snprintf(buffer
, SMALL_STRING_LEN
, "%lu.example.com", (unsigned long)(400 +x
));
3606 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
3608 test_compare(MEMCACHED_SUCCESS
, rc
);
3609 test_compare(x
, memcached_server_list_count(servers
));
3612 test_compare(MEMCACHED_SUCCESS
, memcached_server_push(memc
, servers
));
3613 test_compare(MEMCACHED_SUCCESS
, memcached_server_push(memc
, servers
));
3615 memcached_server_list_free(servers
);
3617 return TEST_SUCCESS
;
3620 static test_return_t
pre_nonblock(memcached_st
*memc
)
3622 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3624 return TEST_SUCCESS
;
3627 static test_return_t
pre_cork(memcached_st
*memc
)
3630 return TEST_SKIPPED
;
3633 if (memcached_success(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CORK
, set
)))
3634 return TEST_SUCCESS
;
3636 return TEST_SKIPPED
;
3639 static test_return_t
pre_cork_and_nonblock(memcached_st
*memc
)
3642 return TEST_SKIPPED
;
3644 test_return_t test_rc
;
3645 if ((test_rc
= pre_cork(memc
)) != TEST_SUCCESS
)
3648 return pre_nonblock(memc
);
3651 static test_return_t
pre_nonblock_binary(memcached_st
*memc
)
3653 memcached_return_t rc
= MEMCACHED_FAILURE
;
3654 memcached_st
*memc_clone
;
3656 memc_clone
= memcached_clone(NULL
, memc
);
3657 test_true(memc_clone
);
3658 // The memcached_version needs to be done on a clone, because the server
3659 // will not toggle protocol on an connection.
3660 memcached_version(memc_clone
);
3662 if (libmemcached_util_version_check(memc_clone
, 1, 4, 4))
3664 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3665 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3666 test_compare(MEMCACHED_SUCCESS
, rc
);
3667 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3671 return TEST_SKIPPED
;
3674 memcached_free(memc_clone
);
3676 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3679 static test_return_t
pre_murmur(memcached_st
*memc
)
3681 #ifdef HAVE_MURMUR_HASH
3682 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
3683 return TEST_SUCCESS
;
3686 return TEST_SKIPPED
;
3690 static test_return_t
pre_jenkins(memcached_st
*memc
)
3692 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_JENKINS
);
3694 return TEST_SUCCESS
;
3698 static test_return_t
pre_md5(memcached_st
*memc
)
3700 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MD5
);
3702 return TEST_SUCCESS
;
3705 static test_return_t
pre_crc(memcached_st
*memc
)
3707 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_CRC
);
3709 return TEST_SUCCESS
;
3712 static test_return_t
pre_hsieh(memcached_st
*memc
)
3714 #ifdef HAVE_HSIEH_HASH
3715 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_HSIEH
);
3716 return TEST_SUCCESS
;
3719 return TEST_SKIPPED
;
3723 static test_return_t
pre_hash_fnv1_64(memcached_st
*memc
)
3725 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
);
3727 return TEST_SUCCESS
;
3730 static test_return_t
pre_hash_fnv1a_64(memcached_st
*memc
)
3732 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_64
);
3734 return TEST_SUCCESS
;
3737 static test_return_t
pre_hash_fnv1_32(memcached_st
*memc
)
3739 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_32
);
3741 return TEST_SUCCESS
;
3744 static test_return_t
pre_hash_fnv1a_32(memcached_st
*memc
)
3746 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_32
);
3748 return TEST_SUCCESS
;
3751 static test_return_t
pre_behavior_ketama(memcached_st
*memc
)
3753 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA
, 1);
3754 test_compare(MEMCACHED_SUCCESS
, rc
);
3756 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA
);
3757 test_true(value
== 1);
3759 return TEST_SUCCESS
;
3762 static test_return_t
pre_behavior_ketama_weighted(memcached_st
*memc
)
3764 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
3765 test_compare(MEMCACHED_SUCCESS
, rc
);
3767 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
3768 test_true(value
== 1);
3770 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
);
3771 test_compare(MEMCACHED_SUCCESS
, rc
);
3773 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
3774 test_true(value
== MEMCACHED_HASH_MD5
);
3776 return TEST_SUCCESS
;
3780 @note This should be testing to see if the server really supports the binary protocol.
3782 static test_return_t
pre_binary(memcached_st
*memc
)
3784 memcached_return_t rc
= MEMCACHED_FAILURE
;
3786 if (libmemcached_util_version_check(memc
, 1, 4, 4))
3788 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3789 test_compare(MEMCACHED_SUCCESS
, rc
);
3790 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1);
3793 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3796 static test_return_t
pre_sasl(memcached_st
*memc
)
3798 memcached_return_t rc
= MEMCACHED_FAILURE
;
3800 #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
3801 const char *server
= getenv("LIBMEMCACHED_TEST_SASL_SERVER");
3802 const char *user
= getenv("LIBMEMCACHED_TEST_SASL_USERNAME");
3803 const char *pass
= getenv("LIBMEMCACHED_TEST_SASL_PASSWORD");
3805 if (server
and user
and pass
)
3807 memcached_server_st
*servers
= memcached_servers_parse(server
);
3809 memcached_servers_reset(memc
);
3810 test_true(memcached_server_push(memc
, servers
) == MEMCACHED_SUCCESS
);
3811 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
3812 rc
= memcached_set_sasl_auth_data(memc
, user
, pass
);
3813 test_compare(MEMCACHED_SUCCESS
, rc
);
3819 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3822 static test_return_t
pre_replication(memcached_st
*memc
)
3824 test_skip(TEST_SUCCESS
, pre_binary(memc
));
3827 * Make sure that we store the item on all servers
3828 * (master + replicas == number of servers)
3830 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
,
3831 memcached_server_count(memc
) - 1);
3832 test_compare(MEMCACHED_SUCCESS
, rc
);
3833 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
) == memcached_server_count(memc
) - 1);
3835 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3839 static test_return_t
pre_replication_noblock(memcached_st
*memc
)
3841 test_skip(TEST_SUCCESS
, pre_replication(memc
));
3843 return pre_nonblock(memc
);
3847 static void my_free(const memcached_st
*ptr
, void *mem
, void *context
)
3851 #ifdef HARD_MALLOC_TESTS
3852 void *real_ptr
= (mem
== NULL
) ? mem
: (void*)((caddr_t
)mem
- 8);
3860 static void *my_malloc(const memcached_st
*ptr
, const size_t size
, void *context
)
3864 #ifdef HARD_MALLOC_TESTS
3865 void *ret
= malloc(size
+ 8);
3868 ret
= (void*)((caddr_t
)ret
+ 8);
3871 void *ret
= malloc(size
);
3876 memset(ret
, 0xff, size
);
3883 static void *my_realloc(const memcached_st
*ptr
, void *mem
, const size_t size
, void *)
3885 #ifdef HARD_MALLOC_TESTS
3886 void *real_ptr
= (mem
== NULL
) ? NULL
: (void*)((caddr_t
)mem
- 8);
3887 void *nmem
= realloc(real_ptr
, size
+ 8);
3892 ret
= (void*)((caddr_t
)nmem
+ 8);
3898 return realloc(mem
, size
);
3903 static void *my_calloc(const memcached_st
*ptr
, size_t nelem
, const size_t size
, void *)
3905 #ifdef HARD_MALLOC_TESTS
3906 void *mem
= my_malloc(ptr
, nelem
* size
);
3909 memset(mem
, 0, nelem
* size
);
3915 return calloc(nelem
, size
);
3919 static test_return_t
selection_of_namespace_tests(memcached_st
*memc
)
3921 memcached_return_t rc
;
3922 const char *key
= "mine";
3925 /* Make sure be default none exists */
3926 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
3927 test_compare_got(MEMCACHED_FAILURE
, rc
, memcached_strerror(NULL
, rc
));
3929 /* Test a clean set */
3930 test_compare(MEMCACHED_SUCCESS
,
3931 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, (void *)key
));
3933 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
3935 test_memcmp(value
, key
, 4);
3936 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
3938 /* Test that we can turn it off */
3939 test_compare(MEMCACHED_SUCCESS
,
3940 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, NULL
));
3942 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
3944 test_compare_got(MEMCACHED_FAILURE
, rc
, memcached_strerror(NULL
, rc
));
3946 /* Now setup for main test */
3947 test_compare(MEMCACHED_SUCCESS
,
3948 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, (void *)key
));
3950 value
= (char *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
3952 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
3953 test_memcmp(value
, key
, 4);
3955 /* Set to Zero, and then Set to something too large */
3958 memset(long_key
, 0, 255);
3960 test_compare(MEMCACHED_SUCCESS
,
3961 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, NULL
));
3963 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
3965 test_true(rc
== MEMCACHED_FAILURE
);
3966 test_true(value
== NULL
);
3968 /* Test a long key for failure */
3969 /* TODO, extend test to determine based on setting, what result should be */
3970 strncpy(long_key
, "Thisismorethentheallottednumberofcharacters", sizeof(long_key
));
3971 test_compare(MEMCACHED_SUCCESS
,
3972 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, long_key
));
3974 /* Now test a key with spaces (which will fail from long key, since bad key is not set) */
3975 strncpy(long_key
, "This is more then the allotted number of characters", sizeof(long_key
));
3976 test_compare(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) ? MEMCACHED_SUCCESS
: MEMCACHED_BAD_KEY_PROVIDED
,
3977 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, long_key
));
3979 /* Test for a bad prefix, but with a short key */
3980 test_compare_got(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) ? MEMCACHED_INVALID_ARGUMENTS
: MEMCACHED_SUCCESS
,
3981 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, 1),
3982 memcached_strerror(NULL
, rc
));
3984 test_compare(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) ? MEMCACHED_SUCCESS
: MEMCACHED_BAD_KEY_PROVIDED
,
3985 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, "dog cat"));
3988 return TEST_SUCCESS
;
3991 static test_return_t
set_namespace(memcached_st
*memc
)
3993 memcached_return_t rc
;
3994 const char *key
= "mine";
3997 /* Make sure be default none exists */
3998 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
3999 test_compare_got(MEMCACHED_FAILURE
, rc
, memcached_strerror(NULL
, rc
));
4001 /* Test a clean set */
4002 test_compare(MEMCACHED_SUCCESS
,
4003 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, (void *)key
));
4005 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
4007 test_memcmp(value
, key
, 4);
4008 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
4010 return TEST_SUCCESS
;
4013 static test_return_t
set_namespace_and_binary(memcached_st
*memc
)
4015 test_return_if(pre_binary(memc
));
4016 test_return_if(set_namespace(memc
));
4018 return TEST_SUCCESS
;
4021 #ifdef MEMCACHED_ENABLE_DEPRECATED
4022 static test_return_t
deprecated_set_memory_alloc(memcached_st
*memc
)
4024 void *test_ptr
= NULL
;
4027 memcached_malloc_fn malloc_cb
=
4028 (memcached_malloc_fn
)my_malloc
;
4029 cb_ptr
= *(void **)&malloc_cb
;
4030 memcached_return_t rc
;
4032 test_compare(MEMCACHED_SUCCESS
,
4033 memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, cb_ptr
));
4034 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
4035 test_compare(MEMCACHED_SUCCESS
, rc
);
4036 test_true(test_ptr
== cb_ptr
);
4040 memcached_realloc_fn realloc_cb
=
4041 (memcached_realloc_fn
)my_realloc
;
4042 cb_ptr
= *(void **)&realloc_cb
;
4043 memcached_return_t rc
;
4045 test_compare(MEMCACHED_SUCCESS
,
4046 memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, cb_ptr
));
4047 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
4048 test_compare(MEMCACHED_SUCCESS
, rc
);
4049 test_true(test_ptr
== cb_ptr
);
4053 memcached_free_fn free_cb
=
4054 (memcached_free_fn
)my_free
;
4055 cb_ptr
= *(void **)&free_cb
;
4056 memcached_return_t rc
;
4058 test_compare(MEMCACHED_SUCCESS
,
4059 memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, cb_ptr
));
4060 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
4061 test_compare(MEMCACHED_SUCCESS
, rc
);
4062 test_true(test_ptr
== cb_ptr
);
4065 return TEST_SUCCESS
;
4070 static test_return_t
set_memory_alloc(memcached_st
*memc
)
4072 test_compare(MEMCACHED_FAILURE
,
4073 memcached_set_memory_allocators(memc
, NULL
, my_free
,
4074 my_realloc
, my_calloc
, NULL
));
4076 test_compare(MEMCACHED_SUCCESS
,
4077 memcached_set_memory_allocators(memc
, my_malloc
, my_free
,
4078 my_realloc
, my_calloc
, NULL
));
4080 memcached_malloc_fn mem_malloc
;
4081 memcached_free_fn mem_free
;
4082 memcached_realloc_fn mem_realloc
;
4083 memcached_calloc_fn mem_calloc
;
4084 memcached_get_memory_allocators(memc
, &mem_malloc
, &mem_free
,
4085 &mem_realloc
, &mem_calloc
);
4087 test_true(mem_malloc
== my_malloc
);
4088 test_true(mem_realloc
== my_realloc
);
4089 test_true(mem_calloc
== my_calloc
);
4090 test_true(mem_free
== my_free
);
4092 return TEST_SUCCESS
;
4095 static test_return_t
enable_consistent_crc(memcached_st
*memc
)
4098 memcached_server_distribution_t value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
4099 memcached_hash_t hash
;
4100 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
4101 if ((rc
= pre_crc(memc
)) != TEST_SUCCESS
)
4104 value
= (memcached_server_distribution_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
4105 test_true(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
4107 hash
= (memcached_hash_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
4109 if (hash
!= MEMCACHED_HASH_CRC
)
4110 return TEST_SKIPPED
;
4112 return TEST_SUCCESS
;
4115 static test_return_t
enable_consistent_hsieh(memcached_st
*memc
)
4118 memcached_server_distribution_t value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
4119 memcached_hash_t hash
;
4120 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
4121 if ((rc
= pre_hsieh(memc
)) != TEST_SUCCESS
)
4124 value
= (memcached_server_distribution_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
4125 test_true(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
4127 hash
= (memcached_hash_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
4129 if (hash
!= MEMCACHED_HASH_HSIEH
)
4130 return TEST_SKIPPED
;
4133 return TEST_SUCCESS
;
4136 static test_return_t
enable_cas(memcached_st
*memc
)
4138 unsigned int set
= 1;
4140 if (libmemcached_util_version_check(memc
, 1, 2, 4))
4142 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
4144 return TEST_SUCCESS
;
4147 return TEST_SKIPPED
;
4150 static test_return_t
check_for_1_2_3(memcached_st
*memc
)
4152 memcached_version(memc
);
4154 memcached_server_instance_st instance
=
4155 memcached_server_instance_by_position(memc
, 0);
4157 if ((instance
->major_version
>= 1 && (instance
->minor_version
== 2 && instance
->micro_version
>= 4))
4158 || instance
->minor_version
> 2)
4160 return TEST_SUCCESS
;
4163 return TEST_SKIPPED
;
4166 static test_return_t
pre_unix_socket(memcached_st
*memc
)
4168 memcached_return_t rc
;
4171 memcached_servers_reset(memc
);
4173 if (stat("/tmp/memcached.socket", &buf
))
4174 return TEST_SKIPPED
;
4176 rc
= memcached_server_add_unix_socket_with_weight(memc
, "/tmp/memcached.socket", 0);
4178 return ( rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_FAILURE
);
4181 static test_return_t
pre_nodelay(memcached_st
*memc
)
4183 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
4184 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
4186 return TEST_SUCCESS
;
4189 static test_return_t
pre_settimer(memcached_st
*memc
)
4191 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
4192 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
4194 return TEST_SUCCESS
;
4197 static test_return_t
poll_timeout(memcached_st
*memc
)
4199 size_t timeout
= 100; // Not using, just checking that it sets
4201 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
4203 timeout
= (size_t)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
);
4205 test_compare(100, timeout
);
4207 return TEST_SUCCESS
;
4210 static test_return_t
noreply_test(memcached_st
*memc
)
4212 memcached_return_t ret
;
4213 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1);
4214 test_true(ret
== MEMCACHED_SUCCESS
);
4215 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4216 test_true(ret
== MEMCACHED_SUCCESS
);
4217 ret
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1);
4218 test_true(ret
== MEMCACHED_SUCCESS
);
4219 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NOREPLY
) == 1);
4220 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
) == 1);
4221 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
) == 1);
4223 for (int count
=0; count
< 5; ++count
)
4225 for (size_t x
= 0; x
< 100; ++x
)
4228 int check_length
= (size_t)snprintf(key
, sizeof(key
), "%lu", (unsigned long)x
);
4229 test_false((size_t)check_length
>= sizeof(key
) || check_length
< 0);
4231 size_t len
= (size_t)check_length
;
4236 ret
= memcached_add(memc
, key
, len
, key
, len
, 0, 0);
4239 ret
= memcached_replace(memc
, key
, len
, key
, len
, 0, 0);
4242 ret
= memcached_set(memc
, key
, len
, key
, len
, 0, 0);
4245 ret
= memcached_append(memc
, key
, len
, key
, len
, 0, 0);
4248 ret
= memcached_prepend(memc
, key
, len
, key
, len
, 0, 0);
4254 test_true(ret
== MEMCACHED_SUCCESS
|| ret
== MEMCACHED_BUFFERED
);
4258 ** NOTE: Don't ever do this in your code! this is not a supported use of the
4259 ** API and is _ONLY_ done this way to verify that the library works the
4260 ** way it is supposed to do!!!!
4263 for (uint32_t x
= 0; x
< memcached_server_count(memc
); ++x
)
4265 memcached_server_instance_st instance
=
4266 memcached_server_instance_by_position(memc
, x
);
4267 no_msg
+=(int)(instance
->cursor_active
);
4270 test_true(no_msg
== 0);
4271 test_true(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
4274 ** Now validate that all items was set properly!
4276 for (size_t x
= 0; x
< 100; ++x
)
4280 int check_length
= (size_t)snprintf(key
, sizeof(key
), "%lu", (unsigned long)x
);
4282 test_false((size_t)check_length
>= sizeof(key
) || check_length
< 0);
4284 size_t len
= (size_t)check_length
;
4287 char* value
=memcached_get(memc
, key
, strlen(key
),
4288 &length
, &flags
, &ret
);
4289 test_true(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
4292 case 0: /* FALLTHROUGH */
4293 case 1: /* FALLTHROUGH */
4295 test_true(strncmp(value
, key
, len
) == 0);
4296 test_true(len
== length
);
4299 test_true(length
== len
* 2);
4302 test_true(length
== len
* 3);
4312 /* Try setting an illegal cas value (should not return an error to
4313 * the caller (because we don't expect a return message from the server)
4315 const char* keys
[]= {"0"};
4316 size_t lengths
[]= {1};
4319 memcached_result_st results_obj
;
4320 memcached_result_st
*results
;
4321 ret
= memcached_mget(memc
, keys
, lengths
, 1);
4322 test_true(ret
== MEMCACHED_SUCCESS
);
4324 results
= memcached_result_create(memc
, &results_obj
);
4326 results
= memcached_fetch_result(memc
, &results_obj
, &ret
);
4328 test_true(ret
== MEMCACHED_SUCCESS
);
4329 uint64_t cas
= memcached_result_cas(results
);
4330 memcached_result_free(&results_obj
);
4332 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
4333 test_true(ret
== MEMCACHED_SUCCESS
);
4336 * The item will have a new cas value, so try to set it again with the old
4337 * value. This should fail!
4339 ret
= memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
);
4340 test_true(ret
== MEMCACHED_SUCCESS
);
4341 test_true(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
4342 char* value
=memcached_get(memc
, keys
[0], lengths
[0], &length
, &flags
, &ret
);
4343 test_true(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
4346 return TEST_SUCCESS
;
4349 static test_return_t
analyzer_test(memcached_st
*memc
)
4351 memcached_return_t rc
;
4352 memcached_stat_st
*memc_stat
;
4353 memcached_analysis_st
*report
;
4355 memc_stat
= memcached_stat(memc
, NULL
, &rc
);
4356 test_compare(MEMCACHED_SUCCESS
, rc
);
4357 test_true(memc_stat
);
4359 report
= memcached_analyze(memc
, memc_stat
, &rc
);
4360 test_compare(MEMCACHED_SUCCESS
, rc
);
4364 memcached_stat_free(NULL
, memc_stat
);
4366 return TEST_SUCCESS
;
4369 /* Count the objects */
4370 static memcached_return_t
callback_dump_counter(const memcached_st
*ptr
,
4375 (void)ptr
; (void)key
; (void)key_length
;
4376 size_t *counter
= (size_t *)context
;
4378 *counter
= *counter
+ 1;
4380 return MEMCACHED_SUCCESS
;
4383 static test_return_t
dump_test(memcached_st
*memc
)
4386 memcached_dump_fn callbacks
[1];
4388 callbacks
[0]= &callback_dump_counter
;
4390 /* No support for Binary protocol yet */
4391 test_skip(false, memc
->flags
.binary_protocol
);
4393 test_compare(TEST_SUCCESS
, set_test3(memc
));
4395 test_compare(MEMCACHED_SUCCESS
,
4396 memcached_dump(memc
, callbacks
, (void *)&counter
, 1));
4398 /* We may have more then 32 if our previous flush has not completed */
4399 test_true(counter
>= 32);
4401 return TEST_SUCCESS
;
4404 #ifdef HAVE_LIBMEMCACHEDUTIL
4406 struct test_pool_context_st
{
4407 memcached_pool_st
* pool
;
4411 static void* connection_release(void *arg
)
4413 test_pool_context_st
*resource
= static_cast<test_pool_context_st
*>(arg
);
4416 // Release all of the memc we are holding
4417 assert(memcached_success(memcached_pool_push(resource
->pool
, resource
->mmc
)));
4421 #define POOL_SIZE 10
4422 static test_return_t
connection_pool_test(memcached_st
*memc
)
4424 memcached_pool_st
* pool
= memcached_pool_create(memc
, 5, POOL_SIZE
);
4425 test_true(pool
!= NULL
);
4426 memcached_st
*mmc
[POOL_SIZE
];
4427 memcached_return_t rc
;
4429 // Fill up our array that we will store the memc that are in the pool
4430 for (size_t x
= 0; x
< POOL_SIZE
; ++x
)
4432 mmc
[x
]= memcached_pool_pop(pool
, false, &rc
);
4433 test_true(mmc
[x
] != NULL
);
4434 test_compare(MEMCACHED_SUCCESS
, rc
);
4437 // All memc should be gone
4438 test_true(memcached_pool_pop(pool
, false, &rc
) == NULL
);
4439 test_compare(MEMCACHED_SUCCESS
, rc
);
4442 test_pool_context_st item
= { pool
, mmc
[9] };
4444 pthread_create(&tid
, NULL
, connection_release
, &item
);
4445 mmc
[9]= memcached_pool_pop(pool
, true, &rc
);
4446 test_compare(MEMCACHED_SUCCESS
, rc
);
4447 pthread_join(tid
, NULL
);
4449 const char *key
= "key";
4450 size_t keylen
= strlen(key
);
4452 // verify that I can do ops with all connections
4453 test_compare(MEMCACHED_SUCCESS
,
4454 memcached_set(mmc
[0], key
, keylen
, "0", 1, 0, 0));
4456 for (size_t x
= 0; x
< POOL_SIZE
; ++x
)
4458 uint64_t number_value
;
4459 test_compare(MEMCACHED_SUCCESS
,
4460 memcached_increment(mmc
[x
], key
, keylen
, 1, &number_value
));
4461 test_compare(number_value
, (x
+1));
4465 for (size_t x
= 0; x
< POOL_SIZE
; ++x
)
4467 test_compare(MEMCACHED_SUCCESS
, memcached_pool_push(pool
, mmc
[x
]));
4471 /* verify that I can set behaviors on the pool when I don't have all
4472 * of the connections in the pool. It should however be enabled
4473 * when I push the item into the pool
4475 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
4478 rc
= memcached_pool_behavior_set(pool
, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
, 9999);
4479 test_compare(MEMCACHED_SUCCESS
, rc
);
4481 mmc
[1]= memcached_pool_pop(pool
, false, &rc
);
4484 test_compare(9999, memcached_behavior_get(mmc
[1], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
));
4485 test_compare(MEMCACHED_SUCCESS
, memcached_pool_push(pool
, mmc
[1]));
4486 test_compare(MEMCACHED_SUCCESS
, memcached_pool_push(pool
, mmc
[0]));
4488 mmc
[0]= memcached_pool_pop(pool
, false, &rc
);
4489 test_compare(9999, memcached_behavior_get(mmc
[0], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK
));
4490 test_compare(MEMCACHED_SUCCESS
, memcached_pool_push(pool
, mmc
[0]));
4492 test_true(memcached_pool_destroy(pool
) == memc
);
4494 return TEST_SUCCESS
;
4497 static test_return_t
util_version_test(memcached_st
*memc
)
4499 bool if_successful
= libmemcached_util_version_check(memc
, 0, 0, 0);
4500 test_true(if_successful
);
4502 if_successful
= libmemcached_util_version_check(memc
, 9, 9, 9);
4504 // We expect failure
4507 fprintf(stderr
, "\n----------------------------------------------------------------------\n");
4508 fprintf(stderr
, "\nDumping Server Information\n\n");
4509 memcached_server_fn callbacks
[1];
4511 callbacks
[0]= dump_server_information
;
4512 memcached_server_cursor(memc
, callbacks
, (void *)stderr
, 1);
4513 fprintf(stderr
, "\n----------------------------------------------------------------------\n");
4515 test_true(if_successful
== false);
4517 memcached_server_instance_st instance
=
4518 memcached_server_instance_by_position(memc
, 0);
4520 memcached_version(memc
);
4522 // We only use one binary when we test, so this should be just fine.
4523 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, instance
->minor_version
, instance
->micro_version
);
4524 test_true(if_successful
== true);
4526 if (instance
->micro_version
> 0)
4527 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, instance
->minor_version
, (uint8_t)(instance
->micro_version
-1));
4528 else if (instance
->minor_version
> 0)
4529 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, (uint8_t)(instance
->minor_version
- 1), instance
->micro_version
);
4530 else if (instance
->major_version
> 0)
4531 if_successful
= libmemcached_util_version_check(memc
, (uint8_t)(instance
->major_version
-1), instance
->minor_version
, instance
->micro_version
);
4533 test_true(if_successful
== true);
4535 if (instance
->micro_version
> 0)
4536 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, instance
->minor_version
, (uint8_t)(instance
->micro_version
+1));
4537 else if (instance
->minor_version
> 0)
4538 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, (uint8_t)(instance
->minor_version
+1), instance
->micro_version
);
4539 else if (instance
->major_version
> 0)
4540 if_successful
= libmemcached_util_version_check(memc
, (uint8_t)(instance
->major_version
+1), instance
->minor_version
, instance
->micro_version
);
4542 test_true(if_successful
== false);
4544 return TEST_SUCCESS
;
4547 static test_return_t
ping_test(memcached_st
*memc
)
4549 memcached_return_t rc
;
4550 memcached_server_instance_st instance
=
4551 memcached_server_instance_by_position(memc
, 0);
4553 // Test both the version that returns a code, and the one that does not.
4554 test_true(libmemcached_util_ping(memcached_server_name(instance
),
4555 memcached_server_port(instance
), NULL
));
4557 test_true(libmemcached_util_ping(memcached_server_name(instance
),
4558 memcached_server_port(instance
), &rc
));
4560 test_compare(MEMCACHED_SUCCESS
, rc
);
4562 return TEST_SUCCESS
;
4568 static test_return_t
hash_sanity_test (memcached_st
*memc
)
4572 assert(MEMCACHED_HASH_DEFAULT
== MEMCACHED_HASH_DEFAULT
);
4573 assert(MEMCACHED_HASH_MD5
== MEMCACHED_HASH_MD5
);
4574 assert(MEMCACHED_HASH_CRC
== MEMCACHED_HASH_CRC
);
4575 assert(MEMCACHED_HASH_FNV1_64
== MEMCACHED_HASH_FNV1_64
);
4576 assert(MEMCACHED_HASH_FNV1A_64
== MEMCACHED_HASH_FNV1A_64
);
4577 assert(MEMCACHED_HASH_FNV1_32
== MEMCACHED_HASH_FNV1_32
);
4578 assert(MEMCACHED_HASH_FNV1A_32
== MEMCACHED_HASH_FNV1A_32
);
4579 #ifdef HAVE_HSIEH_HASH
4580 assert(MEMCACHED_HASH_HSIEH
== MEMCACHED_HASH_HSIEH
);
4582 assert(MEMCACHED_HASH_MURMUR
== MEMCACHED_HASH_MURMUR
);
4583 assert(MEMCACHED_HASH_JENKINS
== MEMCACHED_HASH_JENKINS
);
4584 assert(MEMCACHED_HASH_MAX
== MEMCACHED_HASH_MAX
);
4586 return TEST_SUCCESS
;
4590 static test_return_t
hsieh_avaibility_test (memcached_st
*memc
)
4592 memcached_return_t expected_rc
= MEMCACHED_INVALID_ARGUMENTS
;
4593 #ifdef HAVE_HSIEH_HASH
4594 expected_rc
= MEMCACHED_SUCCESS
;
4596 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
,
4597 (uint64_t)MEMCACHED_HASH_HSIEH
);
4598 test_true(rc
== expected_rc
);
4600 return TEST_SUCCESS
;
4603 static test_return_t
murmur_avaibility_test (memcached_st
*memc
)
4605 memcached_return_t expected_rc
= MEMCACHED_INVALID_ARGUMENTS
;
4606 #ifdef HAVE_MURMUR_HASH
4607 expected_rc
= MEMCACHED_SUCCESS
;
4609 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
,
4610 (uint64_t)MEMCACHED_HASH_MURMUR
);
4611 test_true(rc
== expected_rc
);
4613 return TEST_SUCCESS
;
4616 static test_return_t
one_at_a_time_run (memcached_st
*memc
)
4622 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4626 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_DEFAULT
);
4627 test_true(one_at_a_time_values
[x
] == hash_val
);
4630 return TEST_SUCCESS
;
4633 static test_return_t
md5_run (memcached_st
*memc
)
4639 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4643 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MD5
);
4644 test_true(md5_values
[x
] == hash_val
);
4647 return TEST_SUCCESS
;
4650 static test_return_t
crc_run (memcached_st
*memc
)
4656 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4660 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_CRC
);
4661 test_true(crc_values
[x
] == hash_val
);
4664 return TEST_SUCCESS
;
4667 static test_return_t
fnv1_64_run (memcached_st
*memc
)
4673 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4677 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_64
);
4678 test_true(fnv1_64_values
[x
] == hash_val
);
4681 return TEST_SUCCESS
;
4684 static test_return_t
fnv1a_64_run (memcached_st
*memc
)
4690 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4694 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_64
);
4695 test_true(fnv1a_64_values
[x
] == hash_val
);
4698 return TEST_SUCCESS
;
4701 static test_return_t
fnv1_32_run (memcached_st
*memc
)
4707 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4711 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_32
);
4712 test_true(fnv1_32_values
[x
] == hash_val
);
4715 return TEST_SUCCESS
;
4718 static test_return_t
fnv1a_32_run (memcached_st
*memc
)
4724 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4728 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_32
);
4729 test_true(fnv1a_32_values
[x
] == hash_val
);
4732 return TEST_SUCCESS
;
4735 static test_return_t
hsieh_run (memcached_st
*memc
)
4741 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4745 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_HSIEH
);
4746 test_true(hsieh_values
[x
] == hash_val
);
4749 return TEST_SUCCESS
;
4752 static test_return_t
murmur_run (memcached_st
*memc
)
4754 #ifdef WORDS_BIGENDIAN
4755 (void)murmur_values
;
4756 return TEST_SKIPPED
;
4762 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4766 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MURMUR
);
4767 test_true(murmur_values
[x
] == hash_val
);
4770 return TEST_SUCCESS
;
4774 static test_return_t
jenkins_run (memcached_st
*memc
)
4780 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4784 hash_val
= memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_JENKINS
);
4785 test_true(jenkins_values
[x
] == hash_val
);
4788 return TEST_SUCCESS
;
4791 static uint32_t hash_md5_test_function(const char *string
, size_t string_length
, void *context
)
4794 return libhashkit_md5(string
, string_length
);
4797 static uint32_t hash_crc_test_function(const char *string
, size_t string_length
, void *context
)
4800 return libhashkit_crc32(string
, string_length
);
4803 static test_return_t
memcached_get_hashkit_test (memcached_st
*memc
)
4807 const hashkit_st
*kit
;
4809 hashkit_return_t hash_rc
;
4811 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};
4812 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};
4814 kit
= memcached_get_hashkit(memc
);
4816 hashkit_clone(&new_kit
, kit
);
4817 hash_rc
= hashkit_set_custom_function(&new_kit
, hash_md5_test_function
, NULL
);
4818 test_true(hash_rc
== HASHKIT_SUCCESS
);
4820 memcached_set_hashkit(memc
, &new_kit
);
4823 Verify Setting the hash.
4825 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4829 hash_val
= hashkit_digest(kit
, *ptr
, strlen(*ptr
));
4830 test_true(md5_values
[x
] == hash_val
);
4835 Now check memcached_st.
4837 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4841 hash_val
= memcached_generate_hash(memc
, *ptr
, strlen(*ptr
));
4842 test_true(md5_hosts
[x
] == hash_val
);
4845 hash_rc
= hashkit_set_custom_function(&new_kit
, hash_crc_test_function
, NULL
);
4846 test_true(hash_rc
== HASHKIT_SUCCESS
);
4848 memcached_set_hashkit(memc
, &new_kit
);
4851 Verify Setting the hash.
4853 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4857 hash_val
= hashkit_digest(kit
, *ptr
, strlen(*ptr
));
4858 test_true(crc_values
[x
] == hash_val
);
4861 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4865 hash_val
= memcached_generate_hash(memc
, *ptr
, strlen(*ptr
));
4866 test_true(crc_hosts
[x
] == hash_val
);
4869 return TEST_SUCCESS
;
4873 Test case adapted from John Gorman <johngorman2@gmail.com>
4875 We are testing the error condition when we connect to a server via memcached_get()
4876 but find that the server is not available.
4878 static test_return_t
memcached_get_MEMCACHED_ERRNO(memcached_st
*memc
)
4881 memcached_st
*tl_memc_h
;
4883 const char *key
= "MemcachedLives";
4886 memcached_return rc
;
4890 tl_memc_h
= memcached_create(NULL
);
4891 memcached_server_st
*servers
= memcached_servers_parse("localhost:9898,localhost:9899"); // This server should not exist
4893 memcached_server_push(tl_memc_h
, servers
);
4894 memcached_server_list_free(servers
);
4896 // See if memcached is reachable.
4897 value
= memcached_get(tl_memc_h
, key
, strlen(key
), &len
, &flags
, &rc
);
4900 test_compare(0, len
);
4901 test_true(memcached_failed(rc
));
4903 memcached_free(tl_memc_h
);
4905 return TEST_SUCCESS
;
4909 We connect to a server which exists, but search for a key that does not exist.
4911 static test_return_t
memcached_get_MEMCACHED_NOTFOUND(memcached_st
*memc
)
4913 const char *key
= "MemcachedKeyNotEXIST";
4916 memcached_return rc
;
4919 // See if memcached is reachable.
4920 value
= memcached_get(memc
, key
, strlen(key
), &len
, &flags
, &rc
);
4923 test_compare(0, len
);
4924 test_compare(MEMCACHED_NOTFOUND
, rc
);
4926 return TEST_SUCCESS
;
4930 Test case adapted from John Gorman <johngorman2@gmail.com>
4932 We are testing the error condition when we connect to a server via memcached_get_by_key()
4933 but find that the server is not available.
4935 static test_return_t
memcached_get_by_key_MEMCACHED_ERRNO(memcached_st
*memc
)
4938 memcached_st
*tl_memc_h
;
4939 memcached_server_st
*servers
;
4941 const char *key
= "MemcachedLives";
4944 memcached_return rc
;
4948 tl_memc_h
= memcached_create(NULL
);
4949 servers
= memcached_servers_parse("localhost:9898,localhost:9899"); // This server should not exist
4950 memcached_server_push(tl_memc_h
, servers
);
4951 memcached_server_list_free(servers
);
4953 // See if memcached is reachable.
4954 value
= memcached_get_by_key(tl_memc_h
, key
, strlen(key
), key
, strlen(key
), &len
, &flags
, &rc
);
4957 test_compare(0, len
);
4958 test_true(memcached_failed(rc
));
4960 memcached_free(tl_memc_h
);
4962 return TEST_SUCCESS
;
4966 We connect to a server which exists, but search for a key that does not exist.
4968 static test_return_t
memcached_get_by_key_MEMCACHED_NOTFOUND(memcached_st
*memc
)
4970 const char *key
= "MemcachedKeyNotEXIST";
4973 memcached_return rc
;
4976 // See if memcached is reachable.
4977 value
= memcached_get_by_key(memc
, key
, strlen(key
), key
, strlen(key
), &len
, &flags
, &rc
);
4980 test_compare(0, len
);
4981 test_compare(MEMCACHED_NOTFOUND
, rc
);
4983 return TEST_SUCCESS
;
4987 static test_return_t
ketama_compatibility_libmemcached(memcached_st
*)
4989 memcached_st
*memc
= memcached_create(NULL
);
4992 test_compare(MEMCACHED_SUCCESS
,
4993 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1));
4996 test_compare(1, value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
));
4998 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
));
4999 test_compare(MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
, memcached_behavior_get_distribution(memc
));
5002 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");
5003 memcached_server_push(memc
, server_pool
);
5005 /* verify that the server list was parsed okay. */
5006 test_compare(8, memcached_server_count(memc
));
5007 test_strcmp(server_pool
[0].hostname
, "10.0.1.1");
5008 test_compare(11211, server_pool
[0].port
);
5009 test_compare(600, server_pool
[0].weight
);
5010 test_strcmp(server_pool
[2].hostname
, "10.0.1.3");
5011 test_compare(11211, server_pool
[2].port
);
5012 test_compare(200, server_pool
[2].weight
);
5013 test_strcmp(server_pool
[7].hostname
, "10.0.1.8");
5014 test_compare(11211, server_pool
[7].port
);
5015 test_compare(100, server_pool
[7].weight
);
5017 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
5018 * us test the boundary wraparound.
5020 test_true(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->ketama
.continuum
[0].index
);
5022 /* verify the standard ketama set. */
5023 for (uint32_t x
= 0; x
< 99; x
++)
5025 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases
[x
].key
, strlen(ketama_test_cases
[x
].key
));
5026 memcached_server_instance_st instance
=
5027 memcached_server_instance_by_position(memc
, server_idx
);
5028 const char *hostname
= memcached_server_name(instance
);
5030 test_strcmp(hostname
, ketama_test_cases
[x
].server
);
5033 memcached_server_list_free(server_pool
);
5034 memcached_free(memc
);
5036 return TEST_SUCCESS
;
5039 static test_return_t
ketama_compatibility_spymemcached(memcached_st
*)
5043 memcached_st
*memc
= memcached_create(NULL
);
5046 test_compare(MEMCACHED_SUCCESS
,
5047 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1));
5049 test_compare(1, value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
));
5051 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
));
5052 test_compare(MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
, memcached_behavior_get_distribution(memc
));
5054 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");
5055 test_true(server_pool
);
5056 memcached_server_push(memc
, server_pool
);
5058 /* verify that the server list was parsed okay. */
5059 test_compare(8, memcached_server_count(memc
));
5060 test_strcmp(server_pool
[0].hostname
, "10.0.1.1");
5061 test_compare(11211, server_pool
[0].port
);
5062 test_compare(600, server_pool
[0].weight
);
5063 test_strcmp(server_pool
[2].hostname
, "10.0.1.3");
5064 test_compare(11211, server_pool
[2].port
);
5065 test_compare(200, server_pool
[2].weight
);
5066 test_strcmp(server_pool
[7].hostname
, "10.0.1.8");
5067 test_compare(11211, server_pool
[7].port
);
5068 test_compare(100, server_pool
[7].weight
);
5070 /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
5071 * us test the boundary wraparound.
5073 test_true(memcached_generate_hash(memc
, (char *)"VDEAAAAA", 8) == memc
->ketama
.continuum
[0].index
);
5075 /* verify the standard ketama set. */
5076 for (uint32_t x
= 0; x
< 99; x
++)
5078 uint32_t server_idx
= memcached_generate_hash(memc
, ketama_test_cases_spy
[x
].key
, strlen(ketama_test_cases_spy
[x
].key
));
5080 memcached_server_instance_st instance
=
5081 memcached_server_instance_by_position(memc
, server_idx
);
5083 const char *hostname
= memcached_server_name(instance
);
5085 test_strcmp(hostname
, ketama_test_cases_spy
[x
].server
);
5088 memcached_server_list_free(server_pool
);
5089 memcached_free(memc
);
5091 return TEST_SUCCESS
;
5094 static test_return_t
regression_bug_434484(memcached_st
*memc
)
5096 test_return_t test_rc
;
5097 test_rc
= pre_binary(memc
);
5099 if (test_rc
!= TEST_SUCCESS
)
5102 const char *key
= "regression_bug_434484";
5103 size_t keylen
= strlen(key
);
5105 memcached_return_t ret
= memcached_append(memc
, key
, keylen
, key
, keylen
, 0, 0);
5106 test_compare(MEMCACHED_NOTSTORED
, ret
);
5108 size_t size
= 2048 * 1024;
5109 char *data
= (char*)calloc(1, size
);
5111 test_compare(MEMCACHED_E2BIG
,
5112 memcached_set(memc
, key
, keylen
, data
, size
, 0, 0));
5115 return TEST_SUCCESS
;
5118 static test_return_t
regression_bug_434843(memcached_st
*memc
)
5120 test_return_t test_rc
;
5121 test_rc
= pre_binary(memc
);
5123 if (test_rc
!= TEST_SUCCESS
)
5126 memcached_return_t rc
;
5128 memcached_execute_fn callbacks
[]= { &callback_counter
};
5131 * I only want to hit only _one_ server so I know the number of requests I'm
5132 * sending in the pipleine to the server. Let's try to do a multiget of
5133 * 1024 (that should satisfy most users don't you think?). Future versions
5134 * will include a mget_execute function call if you need a higher number.
5136 uint32_t number_of_hosts
= memcached_server_count(memc
);
5137 memc
->number_of_hosts
= 1;
5138 const size_t max_keys
= 1024;
5139 char **keys
= (char**)calloc(max_keys
, sizeof(char*));
5140 size_t *key_length
= (size_t *)calloc(max_keys
, sizeof(size_t));
5142 for (size_t x
= 0; x
< max_keys
; ++x
)
5146 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%lu", (unsigned long)x
);
5152 * Run two times.. the first time we should have 100% cache miss,
5153 * and the second time we should have 100% cache hits
5155 for (size_t y
= 0; y
< 2; y
++)
5157 test_compare(MEMCACHED_SUCCESS
,
5158 memcached_mget(memc
, (const char**)keys
, key_length
, max_keys
));
5160 test_compare(y
? MEMCACHED_SUCCESS
: MEMCACHED_NOTFOUND
,
5161 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
5165 /* The first iteration should give me a 100% cache miss. verify that*/
5166 char blob
[1024]= { 0 };
5168 test_false(counter
);
5170 for (size_t x
= 0; x
< max_keys
; ++x
)
5172 rc
= memcached_add(memc
, keys
[x
], key_length
[x
],
5173 blob
, sizeof(blob
), 0, 0);
5174 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5179 /* Verify that we received all of the key/value pairs */
5180 test_compare(counter
, max_keys
);
5184 /* Release allocated resources */
5185 for (size_t x
= 0; x
< max_keys
; ++x
)
5192 memc
->number_of_hosts
= number_of_hosts
;
5194 return TEST_SUCCESS
;
5197 static test_return_t
regression_bug_434843_buffered(memcached_st
*memc
)
5199 memcached_return_t rc
;
5200 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
5201 test_compare(MEMCACHED_SUCCESS
, rc
);
5203 return regression_bug_434843(memc
);
5206 static test_return_t
regression_bug_421108(memcached_st
*memc
)
5208 memcached_return_t rc
;
5209 memcached_stat_st
*memc_stat
= memcached_stat(memc
, NULL
, &rc
);
5210 test_compare(MEMCACHED_SUCCESS
, rc
);
5212 char *bytes_str
= memcached_stat_get_value(memc
, memc_stat
, "bytes", &rc
);
5213 test_compare(MEMCACHED_SUCCESS
, rc
);
5214 test_true(bytes_str
);
5215 char *bytes_read_str
= memcached_stat_get_value(memc
, memc_stat
,
5217 test_compare(MEMCACHED_SUCCESS
, rc
);
5218 test_true(bytes_read_str
);
5220 char *bytes_written_str
= memcached_stat_get_value(memc
, memc_stat
,
5221 "bytes_written", &rc
);
5222 test_compare(MEMCACHED_SUCCESS
, rc
);
5223 test_true(bytes_written_str
);
5225 unsigned long long bytes
= strtoull(bytes_str
, 0, 10);
5226 unsigned long long bytes_read
= strtoull(bytes_read_str
, 0, 10);
5227 unsigned long long bytes_written
= strtoull(bytes_written_str
, 0, 10);
5229 test_true(bytes
!= bytes_read
);
5230 test_true(bytes
!= bytes_written
);
5232 /* Release allocated resources */
5234 free(bytes_read_str
);
5235 free(bytes_written_str
);
5236 memcached_stat_free(NULL
, memc_stat
);
5238 return TEST_SUCCESS
;
5242 * The test case isn't obvious so I should probably document why
5243 * it works the way it does. Bug 442914 was caused by a bug
5244 * in the logic in memcached_purge (it did not handle the case
5245 * where the number of bytes sent was equal to the watermark).
5246 * In this test case, create messages so that we hit that case
5247 * and then disable noreply mode and issue a new command to
5248 * verify that it isn't stuck. If we change the format for the
5249 * delete command or the watermarks, we need to update this
5252 static test_return_t
regression_bug_442914(memcached_st
*memc
)
5254 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1));
5255 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1);
5257 uint32_t number_of_hosts
= memcached_server_count(memc
);
5258 memc
->number_of_hosts
= 1;
5263 for (uint32_t x
= 0; x
< 250; ++x
)
5265 len
= (size_t)snprintf(k
, sizeof(k
), "%0250u", x
);
5266 memcached_return_t rc
= memcached_delete(memc
, k
, len
, 0);
5267 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5270 (void)snprintf(k
, sizeof(k
), "%037u", 251U);
5273 memcached_return_t rc
= memcached_delete(memc
, k
, len
, 0);
5274 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5276 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0));
5277 test_compare(MEMCACHED_NOTFOUND
, memcached_delete(memc
, k
, len
, 0));
5279 memc
->number_of_hosts
= number_of_hosts
;
5281 return TEST_SUCCESS
;
5284 static test_return_t
regression_bug_447342(memcached_st
*memc
)
5286 memcached_server_instance_st instance_one
;
5287 memcached_server_instance_st instance_two
;
5289 if (memcached_server_count(memc
) < 3 or pre_replication(memc
) != TEST_SUCCESS
)
5290 return TEST_SKIPPED
;
5292 test_compare(MEMCACHED_SUCCESS
,
5293 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 2));
5295 const size_t max_keys
= 100;
5296 char **keys
= (char**)calloc(max_keys
, sizeof(char*));
5297 size_t *key_length
= (size_t *)calloc(max_keys
, sizeof(size_t));
5299 for (size_t x
= 0; x
< max_keys
; ++x
)
5303 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%lu", (unsigned long)x
);
5306 test_compare(MEMCACHED_SUCCESS
,
5307 memcached_set(memc
, k
, key_length
[x
], k
, key_length
[x
], 0, 0));
5311 ** We are using the quiet commands to store the replicas, so we need
5312 ** to ensure that all of them are processed before we can continue.
5313 ** In the test we go directly from storing the object to trying to
5314 ** receive the object from all of the different servers, so we
5315 ** could end up in a race condition (the memcached server hasn't yet
5316 ** processed the quiet command from the replication set when it process
5317 ** the request from the other client (created by the clone)). As a
5318 ** workaround for that we call memcached_quit to send the quit command
5319 ** to the server and wait for the response ;-) If you use the test code
5320 ** as an example for your own code, please note that you shouldn't need
5323 memcached_quit(memc
);
5325 /* Verify that all messages are stored, and we didn't stuff too much
5328 test_compare(MEMCACHED_SUCCESS
,
5329 memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
));
5332 memcached_execute_fn callbacks
[]= { &callback_counter
};
5333 memcached_return_t rc
;
5334 test_compare_got(MEMCACHED_SUCCESS
,
5335 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1),
5336 memcached_strerror(NULL
, rc
));
5338 /* Verify that we received all of the key/value pairs */
5339 test_compare(counter
, max_keys
);
5341 memcached_quit(memc
);
5343 * Don't do the following in your code. I am abusing the internal details
5344 * within the library, and this is not a supported interface.
5345 * This is to verify correct behavior in the library. Fake that two servers
5348 instance_one
= memcached_server_instance_by_position(memc
, 0);
5349 instance_two
= memcached_server_instance_by_position(memc
, 2);
5350 in_port_t port0
= instance_one
->port
;
5351 in_port_t port2
= instance_two
->port
;
5353 ((memcached_server_write_instance_st
)instance_one
)->port
= 0;
5354 ((memcached_server_write_instance_st
)instance_two
)->port
= 0;
5356 test_compare(MEMCACHED_SUCCESS
,
5357 memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
));
5360 test_compare(MEMCACHED_SUCCESS
,
5361 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
5362 test_compare(counter
, (unsigned int)max_keys
);
5364 /* restore the memc handle */
5365 ((memcached_server_write_instance_st
)instance_one
)->port
= port0
;
5366 ((memcached_server_write_instance_st
)instance_two
)->port
= port2
;
5368 memcached_quit(memc
);
5370 /* Remove half of the objects */
5371 for (size_t x
= 0; x
< max_keys
; ++x
)
5375 test_compare(MEMCACHED_SUCCESS
,
5376 memcached_delete(memc
, keys
[x
], key_length
[x
], 0));
5380 memcached_quit(memc
);
5381 ((memcached_server_write_instance_st
)instance_one
)->port
= 0;
5382 ((memcached_server_write_instance_st
)instance_two
)->port
= 0;
5384 /* now retry the command, this time we should have cache misses */
5385 test_compare(MEMCACHED_SUCCESS
,
5386 memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
));
5389 test_compare_got(MEMCACHED_SUCCESS
,
5390 rc
= memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1),
5391 memcached_strerror(NULL
, rc
));
5392 test_compare(counter
, (unsigned int)(max_keys
>> 1));
5394 /* Release allocated resources */
5395 for (size_t x
= 0; x
< max_keys
; ++x
)
5402 /* restore the memc handle */
5403 ((memcached_server_write_instance_st
)instance_one
)->port
= port0
;
5404 ((memcached_server_write_instance_st
)instance_two
)->port
= port2
;
5406 return TEST_SUCCESS
;
5409 static test_return_t
regression_bug_463297(memcached_st
*memc
)
5411 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
5412 test_true(memc_clone
);
5413 test_true(memcached_version(memc_clone
) == MEMCACHED_SUCCESS
);
5415 memcached_server_instance_st instance
=
5416 memcached_server_instance_by_position(memc_clone
, 0);
5418 if (instance
->major_version
> 1 ||
5419 (instance
->major_version
== 1 &&
5420 instance
->minor_version
> 2))
5422 /* Binary protocol doesn't support deferred delete */
5423 memcached_st
*bin_clone
= memcached_clone(NULL
, memc
);
5424 test_true(bin_clone
);
5425 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(bin_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1));
5426 test_compare(MEMCACHED_INVALID_ARGUMENTS
, memcached_delete(bin_clone
, "foo", 3, 1));
5427 memcached_free(bin_clone
);
5429 memcached_quit(memc_clone
);
5431 /* If we know the server version, deferred delete should fail
5432 * with invalid arguments */
5433 test_compare(MEMCACHED_INVALID_ARGUMENTS
, memcached_delete(memc_clone
, "foo", 3, 1));
5435 /* If we don't know the server version, we should get a protocol error */
5436 memcached_return_t rc
= memcached_delete(memc
, "foo", 3, 1);
5438 /* but there is a bug in some of the memcached servers (1.4) that treats
5439 * the counter as noreply so it doesn't send the proper error message
5441 test_true_got(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
|| rc
== MEMCACHED_INVALID_ARGUMENTS
, memcached_strerror(NULL
, rc
));
5443 /* And buffered mode should be disabled and we should get protocol error */
5444 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1) == MEMCACHED_SUCCESS
);
5445 rc
= memcached_delete(memc
, "foo", 3, 1);
5446 test_true_got(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
|| rc
== MEMCACHED_INVALID_ARGUMENTS
, memcached_strerror(NULL
, rc
));
5448 /* Same goes for noreply... */
5449 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1));
5450 rc
= memcached_delete(memc
, "foo", 3, 1);
5451 test_true_got(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
|| rc
== MEMCACHED_INVALID_ARGUMENTS
, memcached_strerror(NULL
, rc
));
5453 /* but a normal request should go through (and be buffered) */
5454 test_compare(MEMCACHED_BUFFERED
, (rc
= memcached_delete(memc
, "foo", 3, 0)));
5455 test_compare(MEMCACHED_SUCCESS
, memcached_flush_buffers(memc
));
5457 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 0));
5458 /* unbuffered noreply should be success */
5459 test_compare(MEMCACHED_SUCCESS
, memcached_delete(memc
, "foo", 3, 0));
5460 /* unbuffered with reply should be not found... */
5461 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0));
5462 test_compare(MEMCACHED_NOTFOUND
, memcached_delete(memc
, "foo", 3, 0));
5465 memcached_free(memc_clone
);
5466 return TEST_SUCCESS
;
5470 /* Test memcached_server_get_last_disconnect
5471 * For a working server set, shall be NULL
5472 * For a set of non existing server, shall not be NULL
5474 static test_return_t
test_get_last_disconnect(memcached_st
*memc
)
5476 memcached_return_t rc
;
5477 memcached_server_instance_st disconnected_server
;
5479 /* With the working set of server */
5480 const char *key
= "marmotte";
5481 const char *value
= "milka";
5483 memcached_reset_last_disconnected_server(memc
);
5484 test_false(memc
->last_disconnected_server
);
5485 rc
= memcached_set(memc
, key
, strlen(key
),
5486 value
, strlen(value
),
5487 (time_t)0, (uint32_t)0);
5488 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5490 disconnected_server
= memcached_server_get_last_disconnect(memc
);
5491 test_false(disconnected_server
);
5493 /* With a non existing server */
5495 memcached_server_st
*servers
;
5497 const char *server_list
= "localhost:9";
5499 servers
= memcached_servers_parse(server_list
);
5501 mine
= memcached_create(NULL
);
5502 rc
= memcached_server_push(mine
, servers
);
5503 test_compare(MEMCACHED_SUCCESS
, rc
);
5504 memcached_server_list_free(servers
);
5507 rc
= memcached_set(mine
, key
, strlen(key
),
5508 value
, strlen(value
),
5509 (time_t)0, (uint32_t)0);
5510 test_true(memcached_failed(rc
));
5512 disconnected_server
= memcached_server_get_last_disconnect(mine
);
5513 test_true_got(disconnected_server
, memcached_strerror(mine
, rc
));
5514 test_compare(9, memcached_server_port(disconnected_server
));
5515 test_false(strncmp(memcached_server_name(disconnected_server
),"localhost",9));
5517 memcached_quit(mine
);
5518 memcached_free(mine
);
5520 return TEST_SUCCESS
;
5523 static test_return_t
test_multiple_get_last_disconnect(memcached_st
*)
5525 const char *server_string
= "--server=localhost:8888 --server=localhost:8889 --server=localhost:8890 --server=localhost:8891 --server=localhost:8892";
5526 char buffer
[BUFSIZ
];
5528 memcached_return_t rc
;
5529 test_compare_got(MEMCACHED_SUCCESS
,
5530 rc
= libmemcached_check_configuration(server_string
, strlen(server_string
), buffer
, sizeof(buffer
)),
5531 memcached_strerror(NULL
, rc
));
5533 memcached_st
*memc
= memcached(server_string
, strlen(server_string
));
5536 // We will just use the error strings as our keys
5537 uint32_t counter
= 100;
5540 for (int x
= int(MEMCACHED_SUCCESS
); x
< int(MEMCACHED_MAXIMUM_RETURN
); ++x
)
5542 const char *msg
= memcached_strerror(memc
, memcached_return_t(x
));
5543 memcached_return_t ret
= memcached_set(memc
, msg
, strlen(msg
), NULL
, 0, (time_t)0, (uint32_t)0);
5544 test_compare_got(MEMCACHED_CONNECTION_FAILURE
, ret
, memcached_last_error_message(memc
));
5546 memcached_server_instance_st disconnected_server
= memcached_server_get_last_disconnect(memc
);
5547 test_true(disconnected_server
);
5548 test_strcmp("localhost", memcached_server_name(disconnected_server
));
5549 test_true(memcached_server_port(disconnected_server
) >= 8888 and memcached_server_port(disconnected_server
) <= 8892);
5553 memcached_reset_last_disconnected_server(memc
);
5558 memcached_free(memc
);
5560 return TEST_SUCCESS
;
5563 static test_return_t
test_verbosity(memcached_st
*memc
)
5565 memcached_verbosity(memc
, 3);
5567 return TEST_SUCCESS
;
5570 static test_return_t
test_server_failure(memcached_st
*memc
)
5572 memcached_server_instance_st instance
= memcached_server_instance_by_position(memc
, 0);
5574 memcached_st
*local_memc
= memcached_create(NULL
);
5576 memcached_server_add(local_memc
, memcached_server_name(instance
), memcached_server_port(instance
));
5577 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, 2);
5579 uint32_t server_count
= memcached_server_count(local_memc
);
5580 test_compare(1, server_count
);
5582 // Disable the server
5583 instance
= memcached_server_instance_by_position(local_memc
, 0);
5584 ((memcached_server_write_instance_st
)instance
)->server_failure_counter
= 2;
5586 memcached_return_t rc
;
5587 test_compare_got(MEMCACHED_SERVER_MARKED_DEAD
,
5588 rc
= memcached_set(local_memc
, "foo", strlen("foo"), NULL
, 0, (time_t)0, (uint32_t)0),
5589 memcached_last_error_message(local_memc
));
5591 ((memcached_server_write_instance_st
)instance
)->server_failure_counter
= 0;
5592 test_compare_got(MEMCACHED_SUCCESS
,
5593 rc
= memcached_set(local_memc
, "foo", strlen("foo"), NULL
, 0, (time_t)0, (uint32_t)0),
5594 memcached_strerror(NULL
, rc
));
5596 memcached_last_error_message(local_memc
));
5600 memcached_free(local_memc
);
5602 return TEST_SUCCESS
;
5605 static test_return_t
test_cull_servers(memcached_st
*memc
)
5607 uint32_t count
= memcached_server_count(memc
);
5609 // Do not do this in your code, it is not supported.
5610 memc
->servers
[1].options
.is_dead
= true;
5611 memc
->state
.is_time_for_rebuild
= true;
5613 uint32_t new_count
= memcached_server_count(memc
);
5614 test_compare(count
, new_count
);
5617 test_true(count
== new_count
+ 1 );
5620 return TEST_SUCCESS
;
5624 static memcached_return_t
stat_printer(memcached_server_instance_st server
,
5625 const char *key
, size_t key_length
,
5626 const char *value
, size_t value_length
,
5636 return MEMCACHED_SUCCESS
;
5639 static test_return_t
memcached_stat_execute_test(memcached_st
*memc
)
5641 memcached_return_t rc
= memcached_stat_execute(memc
, NULL
, stat_printer
, NULL
);
5642 test_compare(MEMCACHED_SUCCESS
, rc
);
5644 rc
= memcached_stat_execute(memc
, "slabs", stat_printer
, NULL
);
5645 test_compare(MEMCACHED_SUCCESS
, rc
);
5647 rc
= memcached_stat_execute(memc
, "items", stat_printer
, NULL
);
5648 test_compare(MEMCACHED_SUCCESS
, rc
);
5650 rc
= memcached_stat_execute(memc
, "sizes", stat_printer
, NULL
);
5651 test_compare(MEMCACHED_SUCCESS
, rc
);
5653 return TEST_SUCCESS
;
5657 * This test ensures that the failure counter isn't incremented during
5658 * normal termination of the memcached instance.
5660 static test_return_t
wrong_failure_counter_test(memcached_st
*memc
)
5662 memcached_return_t rc
;
5663 memcached_server_instance_st instance
;
5665 /* Set value to force connection to the server */
5666 const char *key
= "marmotte";
5667 const char *value
= "milka";
5670 * Please note that I'm abusing the internal structures in libmemcached
5671 * in a non-portable way and you shouldn't be doing this. I'm only
5672 * doing this in order to verify that the library works the way it should
5674 uint32_t number_of_hosts
= memcached_server_count(memc
);
5675 memc
->number_of_hosts
= 1;
5677 /* Ensure that we are connected to the server by setting a value */
5678 rc
= memcached_set(memc
, key
, strlen(key
),
5679 value
, strlen(value
),
5680 (time_t)0, (uint32_t)0);
5681 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5684 instance
= memcached_server_instance_by_position(memc
, 0);
5685 /* The test is to see that the memcached_quit doesn't increase the
5686 * the server failure conter, so let's ensure that it is zero
5687 * before sending quit
5689 ((memcached_server_write_instance_st
)instance
)->server_failure_counter
= 0;
5691 memcached_quit(memc
);
5693 /* Verify that it memcached_quit didn't increment the failure counter
5694 * Please note that this isn't bullet proof, because an error could
5697 test_compare(0, instance
->server_failure_counter
);
5699 /* restore the instance */
5700 memc
->number_of_hosts
= number_of_hosts
;
5702 return TEST_SUCCESS
;
5706 * This tests ensures expected disconnections (for some behavior changes
5707 * for instance) do not wrongly increase failure counter
5709 static test_return_t
wrong_failure_counter_two_test(memcached_st
*memc
)
5711 memcached_return rc
;
5713 memcached_st
*memc_clone
;
5714 memc_clone
= memcached_clone(NULL
, memc
);
5715 test_true(memc_clone
);
5717 /* Set value to force connection to the server */
5718 const char *key
= "marmotte";
5719 const char *value
= "milka";
5720 char *string
= NULL
;
5721 size_t string_length
;
5724 rc
= memcached_set(memc_clone
, key
, strlen(key
),
5725 value
, strlen(value
),
5726 (time_t)0, (uint32_t)0);
5727 test_true_got(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
, memcached_strerror(NULL
, rc
));
5730 /* put failure limit to 1 */
5731 test_compare(MEMCACHED_SUCCESS
,
5732 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, 1));
5734 /* Put a retry timeout to effectively activate failure_limit effect */
5735 test_compare(MEMCACHED_SUCCESS
,
5736 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 1));
5738 /* change behavior that triggers memcached_quit()*/
5739 test_compare(MEMCACHED_SUCCESS
,
5740 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1));
5743 /* Check if we still are connected */
5744 string
= memcached_get(memc_clone
, key
, strlen(key
),
5745 &string_length
, &flags
, &rc
);
5747 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
5750 memcached_free(memc_clone
);
5752 return TEST_SUCCESS
;
5759 * Test that ensures mget_execute does not end into recursive calls that finally fails
5761 static test_return_t
regression_bug_490486(memcached_st
*memc
)
5763 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
5764 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 1);
5765 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, 1000);
5766 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, 1);
5767 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 3600);
5770 return TEST_SKIPPED
; // My MAC can't handle this test
5774 * I only want to hit _one_ server so I know the number of requests I'm
5775 * sending in the pipeline.
5777 uint32_t number_of_hosts
= memc
->number_of_hosts
;
5778 memc
->number_of_hosts
= 1;
5779 size_t max_keys
= 20480;
5782 char **keys
= (char **)calloc(max_keys
, sizeof(char*));
5783 size_t *key_length
= (size_t *)calloc(max_keys
, sizeof(size_t));
5785 /* First add all of the items.. */
5786 char blob
[1024]= { 0 };
5787 for (size_t x
= 0; x
< max_keys
; ++x
)
5790 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%lu", (unsigned long)x
);
5793 memcached_return rc
= memcached_set(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
5794 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
); // MEMCACHED_TIMEOUT <-- hash been observed on OSX
5799 /* Try to get all of them with a large multiget */
5801 memcached_execute_function callbacks
[]= { &callback_counter
};
5802 memcached_return_t rc
= memcached_mget_execute(memc
, (const char**)keys
, key_length
,
5803 (size_t)max_keys
, callbacks
, &counter
, 1);
5804 test_compare(MEMCACHED_SUCCESS
, rc
);
5806 char* the_value
= NULL
;
5807 char the_key
[MEMCACHED_MAX_KEY
];
5808 size_t the_key_length
;
5809 size_t the_value_length
;
5813 the_value
= memcached_fetch(memc
, the_key
, &the_key_length
, &the_value_length
, &the_flags
, &rc
);
5815 if ((the_value
!= NULL
) && (rc
== MEMCACHED_SUCCESS
))
5821 } while ( (the_value
!= NULL
) && (rc
== MEMCACHED_SUCCESS
));
5824 test_compare(MEMCACHED_END
, rc
);
5826 /* Verify that we got all of the items */
5827 test_compare(counter
, max_keys
);
5830 /* Release all allocated resources */
5831 for (size_t x
= 0; x
< max_keys
; ++x
)
5838 memc
->number_of_hosts
= number_of_hosts
;
5840 return TEST_SUCCESS
;
5843 static test_return_t
regression_bug_583031(memcached_st
*)
5845 memcached_st
*memc
= memcached_create(NULL
);
5847 test_compare(MEMCACHED_SUCCESS
, memcached_server_add(memc
, "10.2.3.4", 11211));
5849 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT
, 1000);
5850 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 1000);
5851 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
5852 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
5853 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, 1000);
5854 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, 3);
5856 memcached_return_t rc
;
5860 const char *value
= memcached_get(memc
, "dsf", 3, &length
, &flags
, &rc
);
5862 test_compare(0, length
);
5864 test_compare_got(MEMCACHED_TIMEOUT
, rc
, memcached_strerror(memc
, rc
));
5866 memcached_free(memc
);
5868 return TEST_SUCCESS
;
5871 static test_return_t
regression_bug_581030(memcached_st
*)
5874 memcached_stat_st
*local_stat
= memcached_stat(NULL
, NULL
, NULL
);
5875 test_false(local_stat
);
5877 memcached_stat_free(NULL
, NULL
);
5880 return TEST_SUCCESS
;
5883 #define regression_bug_655423_COUNT 6000
5884 static test_return_t
regression_bug_655423(memcached_st
*memc
)
5886 memcached_st
*clone
= memcached_clone(NULL
, memc
);
5887 memc
= NULL
; // Just to make sure it is not used
5892 return TEST_SKIPPED
;
5895 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1));
5896 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1));
5897 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1));
5898 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH
, 1));
5900 memset(payload
, int('x'), sizeof(payload
));
5902 for (uint32_t x
= 0; x
< regression_bug_655423_COUNT
; x
++)
5904 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1];
5905 snprintf(key
, sizeof(key
), "%u", x
);
5907 test_compare(MEMCACHED_SUCCESS
, memcached_set(clone
, key
, strlen(key
), payload
, sizeof(payload
), 0, 0));
5910 for (uint32_t x
= 0; x
< regression_bug_655423_COUNT
; x
++)
5912 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1];
5913 snprintf(key
, sizeof(key
), "%u", x
);
5915 size_t value_length
;
5916 memcached_return_t rc
;
5917 char *value
= memcached_get(clone
, key
, strlen(key
), &value_length
, NULL
, &rc
);
5919 if (rc
== MEMCACHED_NOTFOUND
)
5922 test_compare(0, value_length
);
5926 test_compare(MEMCACHED_SUCCESS
, rc
);
5928 test_compare(100, value_length
);
5932 char **keys
= (char**)calloc(regression_bug_655423_COUNT
, sizeof(char*));
5933 size_t *key_length
= (size_t *)calloc(regression_bug_655423_COUNT
, sizeof(size_t));
5934 for (uint32_t x
= 0; x
< regression_bug_655423_COUNT
; x
++)
5936 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1];
5937 snprintf(key
, sizeof(key
), "%u", x
);
5939 keys
[x
]= strdup(key
);
5941 key_length
[x
]= strlen(key
);
5942 test_true(key_length
[x
]);
5945 memcached_return_t rc
;
5946 test_compare_got(MEMCACHED_SUCCESS
,
5947 rc
= memcached_mget(clone
, (const char* const *)keys
, key_length
, regression_bug_655423_COUNT
),
5948 memcached_strerror(NULL
, rc
));
5951 memcached_result_st
*result
= NULL
;
5952 while ((result
= memcached_fetch_result(clone
, result
, NULL
)))
5954 test_compare(100, memcached_result_length(result
));
5958 test_true(count
> 100); // If we don't get back atleast this, something is up
5960 /* Release all allocated resources */
5961 for (size_t x
= 0; x
< regression_bug_655423_COUNT
; ++x
)
5969 memcached_free(clone
);
5971 return TEST_SUCCESS
;
5975 * Test that ensures that buffered set to not trigger problems during io_flush
5977 #define regression_bug_490520_COUNT 200480
5978 static test_return_t
regression_bug_490520(memcached_st
*memc
)
5980 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
,1);
5981 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
,1);
5982 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, 1000);
5983 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
,1);
5984 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 3600);
5986 memc
->number_of_hosts
= 1;
5988 char **keys
= (char **)calloc(regression_bug_490520_COUNT
, sizeof(char*));
5989 size_t *key_length
= (size_t *)calloc(regression_bug_490520_COUNT
, sizeof(size_t));
5991 /* First add all of the items.. */
5992 char blob
[3333] = {0};
5993 for (uint32_t x
= 0; x
< regression_bug_490520_COUNT
; ++x
)
5996 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%u", x
);
6000 memcached_return rc
= memcached_set(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
6001 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
6004 for (uint32_t x
= 0; x
< regression_bug_490520_COUNT
; ++x
)
6011 return TEST_SUCCESS
;
6014 static void memcached_die(memcached_st
* mc
, memcached_return error
, const char* what
, uint32_t it
)
6016 fprintf(stderr
, "Iteration #%u: ", it
);
6018 if(error
== MEMCACHED_ERRNO
)
6020 fprintf(stderr
, "system error %d from %s: %s\n",
6021 errno
, what
, strerror(errno
));
6025 fprintf(stderr
, "error %d from %s: %s\n", error
, what
,
6026 memcached_strerror(mc
, error
));
6030 #define TEST_CONSTANT_CREATION 200
6032 static test_return_t
regression_bug_(memcached_st
*memc
)
6034 const char *remote_server
;
6037 if (! (remote_server
= getenv("LIBMEMCACHED_REMOTE_SERVER")))
6039 return TEST_SKIPPED
;
6042 for (uint32_t x
= 0; x
< TEST_CONSTANT_CREATION
; x
++)
6044 memcached_st
* mc
= memcached_create(NULL
);
6045 memcached_return rc
;
6047 rc
= memcached_behavior_set(mc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
6048 if (rc
!= MEMCACHED_SUCCESS
)
6050 memcached_die(mc
, rc
, "memcached_behavior_set", x
);
6053 rc
= memcached_behavior_set(mc
, MEMCACHED_BEHAVIOR_CACHE_LOOKUPS
, 1);
6054 if (rc
!= MEMCACHED_SUCCESS
)
6056 memcached_die(mc
, rc
, "memcached_behavior_set", x
);
6059 rc
= memcached_server_add(mc
, remote_server
, 0);
6060 if (rc
!= MEMCACHED_SUCCESS
)
6062 memcached_die(mc
, rc
, "memcached_server_add", x
);
6065 const char *set_key
= "akey";
6066 const size_t set_key_len
= strlen(set_key
);
6067 const char *set_value
= "a value";
6068 const size_t set_value_len
= strlen(set_value
);
6070 if (rc
== MEMCACHED_SUCCESS
)
6074 size_t get_value_len
;
6076 uint32_t get_value_flags
;
6078 get_value
= memcached_get(mc
, set_key
, set_key_len
, &get_value_len
,
6079 &get_value_flags
, &rc
);
6080 if (rc
!= MEMCACHED_SUCCESS
)
6082 memcached_die(mc
, rc
, "memcached_get", x
);
6088 (get_value_len
!= set_value_len
6089 || 0!=strncmp(get_value
, set_value
, get_value_len
)))
6091 fprintf(stderr
, "Values don't match?\n");
6092 rc
= MEMCACHED_FAILURE
;
6098 rc
= memcached_set(mc
,
6099 set_key
, set_key_len
,
6100 set_value
, set_value_len
,
6104 if (rc
!= MEMCACHED_SUCCESS
)
6106 memcached_die(mc
, rc
, "memcached_set", x
);
6113 if (rc
!= MEMCACHED_SUCCESS
)
6119 return TEST_SUCCESS
;
6123 * Test that the sasl authentication works. We cannot use the default
6124 * pool of servers, because that would require that all servers we want
6125 * to test supports SASL authentication, and that they use the default
6128 static test_return_t
sasl_auth_test(memcached_st
*memc
)
6130 #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
6131 test_compare(MEMCACHED_SUCCESS
, memcached_set(memc
, "foo", 3, "bar", 3, (time_t)0, (uint32_t)0));
6132 test_compare(MEMCACHED_SUCCESS
, memcached_delete(memc
, "foo", 3, 0));
6133 test_compare(MEMCACHED_SUCCESS
, memcached_destroy_sasl_auth_data(memc
));
6134 test_compare(MEMCACHED_FAILURE
, memcached_destroy_sasl_auth_data(memc
));
6135 test_compare(MEMCACHED_FAILURE
, memcached_destroy_sasl_auth_data(NULL
));
6136 memcached_quit(memc
);
6138 test_compare(MEMCACHED_SUCCESS
,
6139 memcached_set_sasl_auth_data(memc
,
6140 getenv("LIBMEMCACHED_TEST_SASL_USERNAME"),
6141 getenv("LIBMEMCACHED_TEST_SASL_SERVER")));
6143 test_compare(MEMCACHED_AUTH_FAILURE
,
6144 memcached_set(memc
, "foo", 3, "bar", 3, (time_t)0, (uint32_t)0));
6145 test_compare(MEMCACHED_SUCCESS
, memcached_destroy_sasl_auth_data(memc
));
6147 memcached_quit(memc
);
6148 return TEST_SUCCESS
;
6151 return TEST_FAILURE
;
6155 /* Clean the server before beginning testing */
6157 {"util_version", 1, (test_callback_fn
*)util_version_test
},
6158 {"flush", 0, (test_callback_fn
*)flush_test
},
6159 {"init", 0, (test_callback_fn
*)init_test
},
6160 {"allocation", 0, (test_callback_fn
*)allocation_test
},
6161 {"server_list_null_test", 0, (test_callback_fn
*)server_list_null_test
},
6162 {"server_unsort", 0, (test_callback_fn
*)server_unsort_test
},
6163 {"server_sort", 0, (test_callback_fn
*)server_sort_test
},
6164 {"server_sort2", 0, (test_callback_fn
*)server_sort2_test
},
6165 {"memcached_server_remove", 0, (test_callback_fn
*)memcached_server_remove_test
},
6166 {"clone_test", 0, (test_callback_fn
*)clone_test
},
6167 {"connection_test", 0, (test_callback_fn
*)connection_test
},
6168 {"callback_test", 0, (test_callback_fn
*)callback_test
},
6169 {"userdata_test", 0, (test_callback_fn
*)userdata_test
},
6170 {"error", 0, (test_callback_fn
*)error_test
},
6171 {"set", 0, (test_callback_fn
*)set_test
},
6172 {"set2", 0, (test_callback_fn
*)set_test2
},
6173 {"set3", 0, (test_callback_fn
*)set_test3
},
6174 {"dump", 1, (test_callback_fn
*)dump_test
},
6175 {"add", 1, (test_callback_fn
*)add_test
},
6176 {"memcached_fetch_result(MEMCACHED_NOTFOUND)", 1, (test_callback_fn
*)memcached_fetch_result_NOT_FOUND
},
6177 {"replace", 1, (test_callback_fn
*)replace_test
},
6178 {"delete", 1, (test_callback_fn
*)delete_test
},
6179 {"get", 1, (test_callback_fn
*)get_test
},
6180 {"get2", 0, (test_callback_fn
*)get_test2
},
6181 {"get3", 0, (test_callback_fn
*)get_test3
},
6182 {"get4", 0, (test_callback_fn
*)get_test4
},
6183 {"partial mget", 0, (test_callback_fn
*)get_test5
},
6184 {"stats_servername", 0, (test_callback_fn
*)stats_servername_test
},
6185 {"increment", 0, (test_callback_fn
*)increment_test
},
6186 {"increment_with_initial", 1, (test_callback_fn
*)increment_with_initial_test
},
6187 {"decrement", 0, (test_callback_fn
*)decrement_test
},
6188 {"decrement_with_initial", 1, (test_callback_fn
*)decrement_with_initial_test
},
6189 {"increment_by_key", 0, (test_callback_fn
*)increment_by_key_test
},
6190 {"increment_with_initial_by_key", 1, (test_callback_fn
*)increment_with_initial_by_key_test
},
6191 {"decrement_by_key", 0, (test_callback_fn
*)decrement_by_key_test
},
6192 {"decrement_with_initial_by_key", 1, (test_callback_fn
*)decrement_with_initial_by_key_test
},
6193 {"quit", 0, (test_callback_fn
*)quit_test
},
6194 {"mget", 1, (test_callback_fn
*)mget_test
},
6195 {"mget_result", 1, (test_callback_fn
*)mget_result_test
},
6196 {"mget_result_alloc", 1, (test_callback_fn
*)mget_result_alloc_test
},
6197 {"mget_result_function", 1, (test_callback_fn
*)mget_result_function
},
6198 {"mget_execute", 1, (test_callback_fn
*)mget_execute
},
6199 {"mget_end", 0, (test_callback_fn
*)mget_end
},
6200 {"get_stats", 0, (test_callback_fn
*)get_stats
},
6201 {"add_host_test", 0, (test_callback_fn
*)add_host_test
},
6202 {"add_host_test_1", 0, (test_callback_fn
*)add_host_test1
},
6203 {"get_stats_keys", 0, (test_callback_fn
*)get_stats_keys
},
6204 {"version_string_test", 0, (test_callback_fn
*)version_string_test
},
6205 {"bad_key", 1, (test_callback_fn
*)bad_key_test
},
6206 {"memcached_server_cursor", 1, (test_callback_fn
*)memcached_server_cursor_test
},
6207 {"read_through", 1, (test_callback_fn
*)read_through
},
6208 {"delete_through", 1, (test_callback_fn
*)delete_through
},
6209 {"noreply", 1, (test_callback_fn
*)noreply_test
},
6210 {"analyzer", 1, (test_callback_fn
*)analyzer_test
},
6211 {"connectionpool", 1, (test_callback_fn
*)connection_pool_test
},
6212 {"memcached_pool_test", 1, (test_callback_fn
*)memcached_pool_test
},
6213 {"ping", 1, (test_callback_fn
*)ping_test
},
6214 {"test_get_last_disconnect", 1, (test_callback_fn
*)test_get_last_disconnect
},
6215 {"verbosity", 1, (test_callback_fn
*)test_verbosity
},
6216 {"test_server_failure", 1, (test_callback_fn
*)test_server_failure
},
6217 {"cull_servers", 1, (test_callback_fn
*)test_cull_servers
},
6218 {"memcached_stat_execute", 1, (test_callback_fn
*)memcached_stat_execute_test
},
6222 test_st behavior_tests
[] ={
6223 {"libmemcached_string_behavior()", 0, (test_callback_fn
*)libmemcached_string_behavior_test
},
6224 {"libmemcached_string_distribution()", 0, (test_callback_fn
*)libmemcached_string_distribution_test
},
6225 {"behavior_test", 0, (test_callback_fn
*)behavior_test
},
6226 {"MEMCACHED_BEHAVIOR_CORK", 0, (test_callback_fn
*)MEMCACHED_BEHAVIOR_CORK_test
},
6227 {"MEMCACHED_BEHAVIOR_TCP_KEEPALIVE", 0, (test_callback_fn
*)MEMCACHED_BEHAVIOR_TCP_KEEPALIVE_test
},
6228 {"MEMCACHED_BEHAVIOR_TCP_KEEPIDLE", 0, (test_callback_fn
*)MEMCACHED_BEHAVIOR_TCP_KEEPIDLE_test
},
6232 test_st basic_tests
[] ={
6233 {"init", 1, (test_callback_fn
*)basic_init_test
},
6234 {"clone", 1, (test_callback_fn
*)basic_clone_test
},
6235 {"reset", 1, (test_callback_fn
*)basic_reset_stack_test
},
6236 {"reset heap", 1, (test_callback_fn
*)basic_reset_heap_test
},
6237 {"reset stack clone", 1, (test_callback_fn
*)basic_reset_stack_clone_test
},
6238 {"reset heap clone", 1, (test_callback_fn
*)basic_reset_heap_clone_test
},
6242 test_st regression_binary_vs_block
[] ={
6243 {"block add", 1, (test_callback_fn
*)block_add_regression
},
6244 {"binary add", 1, (test_callback_fn
*)binary_add_regression
},
6248 test_st async_tests
[] ={
6249 {"add", 1, (test_callback_fn
*)add_wrapper
},
6253 test_st string_tests
[] ={
6254 {"string static with null", 0, (test_callback_fn
*)string_static_null
},
6255 {"string alloc with null", 0, (test_callback_fn
*)string_alloc_null
},
6256 {"string alloc with 1K", 0, (test_callback_fn
*)string_alloc_with_size
},
6257 {"string alloc with malloc failure", 0, (test_callback_fn
*)string_alloc_with_size_toobig
},
6258 {"string append", 0, (test_callback_fn
*)string_alloc_append
},
6259 {"string append failure (too big)", 0, (test_callback_fn
*)string_alloc_append_toobig
},
6260 {"string_alloc_append_multiple", 0, (test_callback_fn
*)string_alloc_append_multiple
},
6261 {0, 0, (test_callback_fn
*)0}
6264 test_st memcached_server_get_last_disconnect_tests
[] ={
6265 {"memcached_server_get_last_disconnect()", 0, (test_callback_fn
*)test_multiple_get_last_disconnect
},
6266 {0, 0, (test_callback_fn
*)0}
6270 test_st result_tests
[] ={
6271 {"result static", 0, (test_callback_fn
*)result_static
},
6272 {"result alloc", 0, (test_callback_fn
*)result_alloc
},
6273 {0, 0, (test_callback_fn
*)0}
6276 test_st version_1_2_3
[] ={
6277 {"append", 0, (test_callback_fn
*)append_test
},
6278 {"prepend", 0, (test_callback_fn
*)prepend_test
},
6279 {"cas", 0, (test_callback_fn
*)cas_test
},
6280 {"cas2", 0, (test_callback_fn
*)cas2_test
},
6281 {"append_binary", 0, (test_callback_fn
*)append_binary_test
},
6282 {0, 0, (test_callback_fn
*)0}
6285 test_st haldenbrand_tests
[] ={
6286 {"memcached_set", 0, (test_callback_fn
*)user_supplied_bug1
},
6287 {"memcached_get()", 0, (test_callback_fn
*)user_supplied_bug2
},
6288 {"memcached_mget()", 0, (test_callback_fn
*)user_supplied_bug3
},
6289 {0, 0, (test_callback_fn
*)0}
6292 test_st user_tests
[] ={
6293 {"user_supplied_bug4", true, (test_callback_fn
*)user_supplied_bug4
},
6294 {"user_supplied_bug5", 1, (test_callback_fn
*)user_supplied_bug5
},
6295 {"user_supplied_bug6", 1, (test_callback_fn
*)user_supplied_bug6
},
6296 {"user_supplied_bug7", 1, (test_callback_fn
*)user_supplied_bug7
},
6297 {"user_supplied_bug8", 1, (test_callback_fn
*)user_supplied_bug8
},
6298 {"user_supplied_bug9", 1, (test_callback_fn
*)user_supplied_bug9
},
6299 {"user_supplied_bug10", 1, (test_callback_fn
*)user_supplied_bug10
},
6300 {"user_supplied_bug11", 1, (test_callback_fn
*)user_supplied_bug11
},
6301 {"user_supplied_bug12", 1, (test_callback_fn
*)user_supplied_bug12
},
6302 {"user_supplied_bug13", 1, (test_callback_fn
*)user_supplied_bug13
},
6303 {"user_supplied_bug14", 1, (test_callback_fn
*)user_supplied_bug14
},
6304 {"user_supplied_bug15", 1, (test_callback_fn
*)user_supplied_bug15
},
6305 {"user_supplied_bug16", 1, (test_callback_fn
*)user_supplied_bug16
},
6306 #if !defined(__sun) && !defined(__OpenBSD__)
6308 ** It seems to be something weird with the character sets..
6309 ** value_fetch is unable to parse the value line (iscntrl "fails"), so I
6310 ** guess I need to find out how this is supposed to work.. Perhaps I need
6311 ** to run the test in a specific locale (I tried zh_CN.UTF-8 without success,
6312 ** so just disable the code for now...).
6314 {"user_supplied_bug17", 1, (test_callback_fn
*)user_supplied_bug17
},
6316 {"user_supplied_bug18", 1, (test_callback_fn
*)user_supplied_bug18
},
6317 {"user_supplied_bug19", 1, (test_callback_fn
*)user_supplied_bug19
},
6318 {"user_supplied_bug20", 1, (test_callback_fn
*)user_supplied_bug20
},
6319 {"user_supplied_bug21", 1, (test_callback_fn
*)user_supplied_bug21
},
6320 {"wrong_failure_counter_test", 1, (test_callback_fn
*)wrong_failure_counter_test
},
6321 {"wrong_failure_counter_two_test", 1, (test_callback_fn
*)wrong_failure_counter_two_test
},
6322 {0, 0, (test_callback_fn
*)0}
6325 test_st replication_tests
[]= {
6326 {"set", 1, (test_callback_fn
*)replication_set_test
},
6327 {"get", 0, (test_callback_fn
*)replication_get_test
},
6328 {"mget", 0, (test_callback_fn
*)replication_mget_test
},
6329 {"delete", 0, (test_callback_fn
*)replication_delete_test
},
6330 {"rand_mget", 0, (test_callback_fn
*)replication_randomize_mget_test
},
6331 {"fail", 0, (test_callback_fn
*)replication_randomize_mget_fail_test
},
6332 {0, 0, (test_callback_fn
*)0}
6336 * The following test suite is used to verify that we don't introduce
6337 * regression bugs. If you want more information about the bug / test,
6338 * you should look in the bug report at
6339 * http://bugs.launchpad.net/libmemcached
6341 test_st regression_tests
[]= {
6342 {"lp:434484", 1, (test_callback_fn
*)regression_bug_434484
},
6343 {"lp:434843", 1, (test_callback_fn
*)regression_bug_434843
},
6344 {"lp:434843-buffered", 1, (test_callback_fn
*)regression_bug_434843_buffered
},
6345 {"lp:421108", 1, (test_callback_fn
*)regression_bug_421108
},
6346 {"lp:442914", 1, (test_callback_fn
*)regression_bug_442914
},
6347 {"lp:447342", 1, (test_callback_fn
*)regression_bug_447342
},
6348 {"lp:463297", 1, (test_callback_fn
*)regression_bug_463297
},
6349 {"lp:490486", 1, (test_callback_fn
*)regression_bug_490486
},
6350 {"lp:583031", 1, (test_callback_fn
*)regression_bug_583031
},
6351 {"lp:?", 1, (test_callback_fn
*)regression_bug_
},
6352 {"lp:728286", 1, (test_callback_fn
*)regression_bug_728286
},
6353 {"lp:581030", 1, (test_callback_fn
*)regression_bug_581030
},
6354 {"lp:71231153 connect()", 1, (test_callback_fn
*)regression_bug_71231153_connect
},
6355 {"lp:71231153 poll()", 1, (test_callback_fn
*)regression_bug_71231153_poll
},
6356 {"lp:655423", 1, (test_callback_fn
*)regression_bug_655423
},
6357 {"lp:490520", 1, (test_callback_fn
*)regression_bug_490520
},
6358 {0, 0, (test_callback_fn
*)0}
6361 test_st sasl_auth_tests
[]= {
6362 {"sasl_auth", 1, (test_callback_fn
*)sasl_auth_test
},
6363 {0, 0, (test_callback_fn
*)0}
6366 test_st ketama_compatibility
[]= {
6367 {"libmemcached", 1, (test_callback_fn
*)ketama_compatibility_libmemcached
},
6368 {"spymemcached", 1, (test_callback_fn
*)ketama_compatibility_spymemcached
},
6369 {0, 0, (test_callback_fn
*)0}
6372 test_st generate_tests
[] ={
6373 {"generate_pairs", 1, (test_callback_fn
*)generate_pairs
},
6374 {"generate_data", 1, (test_callback_fn
*)generate_data
},
6375 {"get_read", 0, (test_callback_fn
*)get_read
},
6376 {"delete_generate", 0, (test_callback_fn
*)delete_generate
},
6377 {"generate_buffer_data", 1, (test_callback_fn
*)generate_buffer_data
},
6378 {"delete_buffer", 0, (test_callback_fn
*)delete_buffer_generate
},
6379 {"generate_data", 1, (test_callback_fn
*)generate_data
},
6380 {"mget_read", 0, (test_callback_fn
*)mget_read
},
6381 {"mget_read_result", 0, (test_callback_fn
*)mget_read_result
},
6382 {"memcached_fetch_result() use internal result", 0, (test_callback_fn
*)mget_read_internal_result
},
6383 {"memcached_fetch_result() partial read", 0, (test_callback_fn
*)mget_read_partial_result
},
6384 {"mget_read_function", 0, (test_callback_fn
*)mget_read_function
},
6385 {"cleanup", 1, (test_callback_fn
*)cleanup_pairs
},
6386 {"generate_large_pairs", 1, (test_callback_fn
*)generate_large_pairs
},
6387 {"generate_data", 1, (test_callback_fn
*)generate_data
},
6388 {"generate_buffer_data", 1, (test_callback_fn
*)generate_buffer_data
},
6389 {"cleanup", 1, (test_callback_fn
*)cleanup_pairs
},
6390 {0, 0, (test_callback_fn
*)0}
6393 test_st consistent_tests
[] ={
6394 {"generate_pairs", 1, (test_callback_fn
*)generate_pairs
},
6395 {"generate_data", 1, (test_callback_fn
*)generate_data
},
6396 {"get_read", 0, (test_callback_fn
*)get_read_count
},
6397 {"cleanup", 1, (test_callback_fn
*)cleanup_pairs
},
6398 {0, 0, (test_callback_fn
*)0}
6401 test_st consistent_weighted_tests
[] ={
6402 {"generate_pairs", 1, (test_callback_fn
*)generate_pairs
},
6403 {"generate_data", 1, (test_callback_fn
*)generate_data_with_stats
},
6404 {"get_read", 0, (test_callback_fn
*)get_read_count
},
6405 {"cleanup", 1, (test_callback_fn
*)cleanup_pairs
},
6406 {0, 0, (test_callback_fn
*)0}
6409 test_st hsieh_availability
[] ={
6410 {"hsieh_avaibility_test", 0, (test_callback_fn
*)hsieh_avaibility_test
},
6411 {0, 0, (test_callback_fn
*)0}
6414 test_st murmur_availability
[] ={
6415 {"murmur_avaibility_test", 0, (test_callback_fn
*)murmur_avaibility_test
},
6416 {0, 0, (test_callback_fn
*)0}
6420 test_st hash_sanity
[] ={
6421 {"hash sanity", 0, (test_callback_fn
*)hash_sanity_test
},
6422 {0, 0, (test_callback_fn
*)0}
6426 test_st ketama_auto_eject_hosts
[] ={
6427 {"auto_eject_hosts", 1, (test_callback_fn
*)auto_eject_hosts
},
6428 {"output_ketama_weighted_keys", 1, (test_callback_fn
*)output_ketama_weighted_keys
},
6429 {0, 0, (test_callback_fn
*)0}
6432 test_st hash_tests
[] ={
6433 {"one_at_a_time_run", 0, (test_callback_fn
*)one_at_a_time_run
},
6434 {"md5", 0, (test_callback_fn
*)md5_run
},
6435 {"crc", 0, (test_callback_fn
*)crc_run
},
6436 {"fnv1_64", 0, (test_callback_fn
*)fnv1_64_run
},
6437 {"fnv1a_64", 0, (test_callback_fn
*)fnv1a_64_run
},
6438 {"fnv1_32", 0, (test_callback_fn
*)fnv1_32_run
},
6439 {"fnv1a_32", 0, (test_callback_fn
*)fnv1a_32_run
},
6440 {"hsieh", 0, (test_callback_fn
*)hsieh_run
},
6441 {"murmur", 0, (test_callback_fn
*)murmur_run
},
6442 {"jenkis", 0, (test_callback_fn
*)jenkins_run
},
6443 {"memcached_get_hashkit", 0, (test_callback_fn
*)memcached_get_hashkit_test
},
6444 {0, 0, (test_callback_fn
*)0}
6447 test_st error_conditions
[] ={
6448 {"memcached_get(MEMCACHED_ERRNO)", 0, (test_callback_fn
*)memcached_get_MEMCACHED_ERRNO
},
6449 {"memcached_get(MEMCACHED_NOTFOUND)", 0, (test_callback_fn
*)memcached_get_MEMCACHED_NOTFOUND
},
6450 {"memcached_get_by_key(MEMCACHED_ERRNO)", 0, (test_callback_fn
*)memcached_get_by_key_MEMCACHED_ERRNO
},
6451 {"memcached_get_by_key(MEMCACHED_NOTFOUND)", 0, (test_callback_fn
*)memcached_get_by_key_MEMCACHED_NOTFOUND
},
6452 {"memcached_get_by_key(MEMCACHED_NOTFOUND)", 0, (test_callback_fn
*)memcached_get_by_key_MEMCACHED_NOTFOUND
},
6453 {"memcached_increment(MEMCACHED_NO_SERVERS)", 0, (test_callback_fn
*)memcached_increment_MEMCACHED_NO_SERVERS
},
6454 {0, 0, (test_callback_fn
*)0}
6458 test_st parser_tests
[] ={
6459 {"behavior", 0, (test_callback_fn
*)behavior_parser_test
},
6460 {"boolean_options", 0, (test_callback_fn
*)parser_boolean_options_test
},
6461 {"configure_file", 0, (test_callback_fn
*)memcached_create_with_options_with_filename
},
6462 {"distribtions", 0, (test_callback_fn
*)parser_distribution_test
},
6463 {"hash", 0, (test_callback_fn
*)parser_hash_test
},
6464 {"libmemcached_check_configuration", 0, (test_callback_fn
*)libmemcached_check_configuration_test
},
6465 {"libmemcached_check_configuration_with_filename", 0, (test_callback_fn
*)libmemcached_check_configuration_with_filename_test
},
6466 {"number_options", 0, (test_callback_fn
*)parser_number_options_test
},
6467 {"randomly generated options", 0, (test_callback_fn
*)random_statement_build_test
},
6468 {"prefix_key", 0, (test_callback_fn
*)parser_key_prefix_test
},
6469 {"server", 0, (test_callback_fn
*)server_test
},
6470 {"bad server strings", 0, (test_callback_fn
*)servers_bad_test
},
6471 {"server with weights", 0, (test_callback_fn
*)server_with_weight_test
},
6472 {"parsing servername, port, and weight", 0, (test_callback_fn
*)test_hostname_port_weight
},
6473 {"--socket=", 0, (test_callback_fn
*)test_parse_socket
},
6474 {0, 0, (test_callback_fn
*)0}
6477 test_st virtual_bucket_tests
[] ={
6478 {"basic", 0, (test_callback_fn
*)virtual_back_map
},
6479 {0, 0, (test_callback_fn
*)0}
6482 test_st namespace_tests
[] ={
6483 {"basic tests", true, (test_callback_fn
*)selection_of_namespace_tests
},
6484 {"increment", true, (test_callback_fn
*)memcached_increment_namespace
},
6485 {0, 0, (test_callback_fn
*)0}
6488 collection_st collection
[] ={
6490 {"hash_sanity", 0, 0, hash_sanity
},
6492 {"basic", 0, 0, basic_tests
},
6493 {"hsieh_availability", 0, 0, hsieh_availability
},
6494 {"murmur_availability", 0, 0, murmur_availability
},
6495 {"block", 0, 0, tests
},
6496 {"binary", (test_callback_fn
*)pre_binary
, 0, tests
},
6497 {"nonblock", (test_callback_fn
*)pre_nonblock
, 0, tests
},
6498 {"nodelay", (test_callback_fn
*)pre_nodelay
, 0, tests
},
6499 {"settimer", (test_callback_fn
*)pre_settimer
, 0, tests
},
6500 {"md5", (test_callback_fn
*)pre_md5
, 0, tests
},
6501 {"crc", (test_callback_fn
*)pre_crc
, 0, tests
},
6502 {"hsieh", (test_callback_fn
*)pre_hsieh
, 0, tests
},
6503 {"jenkins", (test_callback_fn
*)pre_jenkins
, 0, tests
},
6504 {"fnv1_64", (test_callback_fn
*)pre_hash_fnv1_64
, 0, tests
},
6505 {"fnv1a_64", (test_callback_fn
*)pre_hash_fnv1a_64
, 0, tests
},
6506 {"fnv1_32", (test_callback_fn
*)pre_hash_fnv1_32
, 0, tests
},
6507 {"fnv1a_32", (test_callback_fn
*)pre_hash_fnv1a_32
, 0, tests
},
6508 {"ketama", (test_callback_fn
*)pre_behavior_ketama
, 0, tests
},
6509 {"ketama_auto_eject_hosts", (test_callback_fn
*)pre_behavior_ketama
, 0, ketama_auto_eject_hosts
},
6510 {"unix_socket", (test_callback_fn
*)pre_unix_socket
, 0, tests
},
6511 {"unix_socket_nodelay", (test_callback_fn
*)pre_nodelay
, 0, tests
},
6512 {"poll_timeout", (test_callback_fn
*)poll_timeout
, 0, tests
},
6513 {"gets", (test_callback_fn
*)enable_cas
, 0, tests
},
6514 {"consistent_crc", (test_callback_fn
*)enable_consistent_crc
, 0, tests
},
6515 {"consistent_hsieh", (test_callback_fn
*)enable_consistent_hsieh
, 0, tests
},
6516 #ifdef MEMCACHED_ENABLE_DEPRECATED
6517 {"deprecated_memory_allocators", (test_callback_fn
*)deprecated_set_memory_alloc
, 0, tests
},
6519 {"memory_allocators", (test_callback_fn
*)set_memory_alloc
, 0, tests
},
6520 {"namespace", (test_callback_fn
*)set_namespace
, 0, tests
},
6521 {"namespace(BINARY)", (test_callback_fn
*)set_namespace_and_binary
, 0, tests
},
6522 {"specific namespace", 0, 0, namespace_tests
},
6523 {"specific namespace(BINARY)", (test_callback_fn
*)pre_binary
, 0, namespace_tests
},
6524 {"sasl_auth", (test_callback_fn
*)pre_sasl
, 0, sasl_auth_tests
},
6525 {"sasl", (test_callback_fn
*)pre_sasl
, 0, tests
},
6526 {"version_1_2_3", (test_callback_fn
*)check_for_1_2_3
, 0, version_1_2_3
},
6527 {"string", 0, 0, string_tests
},
6528 {"result", 0, 0, result_tests
},
6529 {"async", (test_callback_fn
*)pre_nonblock
, 0, async_tests
},
6530 {"async(BINARY)", (test_callback_fn
*)pre_nonblock_binary
, 0, async_tests
},
6531 {"Cal Haldenbrand's tests", 0, 0, haldenbrand_tests
},
6532 {"user", 0, 0, user_tests
},
6533 {"generate", 0, 0, generate_tests
},
6534 {"generate_hsieh", (test_callback_fn
*)pre_hsieh
, 0, generate_tests
},
6535 {"generate_ketama", (test_callback_fn
*)pre_behavior_ketama
, 0, generate_tests
},
6536 {"generate_hsieh_consistent", (test_callback_fn
*)enable_consistent_hsieh
, 0, generate_tests
},
6537 {"generate_md5", (test_callback_fn
*)pre_md5
, 0, generate_tests
},
6538 {"generate_murmur", (test_callback_fn
*)pre_murmur
, 0, generate_tests
},
6539 {"generate_jenkins", (test_callback_fn
*)pre_jenkins
, 0, generate_tests
},
6540 {"generate_nonblock", (test_callback_fn
*)pre_nonblock
, 0, generate_tests
},
6542 {"generate_corked", (test_callback_fn
*)pre_cork
, 0, generate_tests
},
6543 {"generate_corked_and_nonblock", (test_callback_fn
*)pre_cork_and_nonblock
, 0, generate_tests
},
6544 {"consistent_not", 0, 0, consistent_tests
},
6545 {"consistent_ketama", (test_callback_fn
*)pre_behavior_ketama
, 0, consistent_tests
},
6546 {"consistent_ketama_weighted", (test_callback_fn
*)pre_behavior_ketama_weighted
, 0, consistent_weighted_tests
},
6547 {"ketama_compat", 0, 0, ketama_compatibility
},
6548 {"test_hashes", 0, 0, hash_tests
},
6549 {"replication", (test_callback_fn
*)pre_replication
, 0, replication_tests
},
6550 {"replication_noblock", (test_callback_fn
*)pre_replication_noblock
, 0, replication_tests
},
6551 {"regression", 0, 0, regression_tests
},
6552 {"behaviors", 0, 0, behavior_tests
},
6553 {"regression_binary_vs_block", (test_callback_fn
*)key_setup
, (test_callback_fn
*)key_teardown
, regression_binary_vs_block
},
6554 {"error_conditions", 0, 0, error_conditions
},
6555 {"parser", 0, 0, parser_tests
},
6556 {"virtual buckets", 0, 0, virtual_bucket_tests
},
6557 {"memcached_server_get_last_disconnect", 0, 0, memcached_server_get_last_disconnect_tests
},
6561 #include "tests/libmemcached_world.h"
6563 void get_world(Framework
*world
)
6565 world
->collections
= collection
;
6567 world
->_create
= (test_callback_create_fn
*)world_create
;
6568 world
->_destroy
= (test_callback_fn
*)world_destroy
;
6570 world
->item
._startup
= (test_callback_fn
*)world_test_startup
;
6571 world
->item
._flush
= (test_callback_fn
*)world_flush
;
6572 world
->item
.set_pre((test_callback_fn
*)world_pre_run
);
6573 world
->item
.set_post((test_callback_fn
*)world_post_run
);
6574 world
->_on_error
= (test_callback_error_fn
*)world_on_error
;
6576 world
->collection_startup
= (test_callback_fn
*)world_container_startup
;
6577 world
->collection_shutdown
= (test_callback_fn
*)world_container_shutdown
;
6579 world
->runner
= &defualt_libmemcached_runner
;