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.
39 #include <libtest/test.hpp>
45 #include <libmemcached-1.0/memcached.h>
46 #include <libmemcached/is.h>
47 #include <libmemcached/server_instance.h>
49 #include <libhashkit-1.0/hashkit.h>
55 #include <semaphore.h>
59 #include <sys/types.h>
64 #include <libtest/server.h>
66 #include "clients/generator.h"
67 #include "clients/execute.h"
69 #define SMALL_STRING_LEN 1024
71 #include <libtest/test.hpp>
73 #include "tests/basic.h"
74 #include "tests/debug.h"
75 #include "tests/deprecated.h"
76 #include "tests/error_conditions.h"
77 #include "tests/exist.h"
78 #include "tests/ketama.h"
79 #include "tests/namespace.h"
80 #include "tests/parser.h"
81 #include "tests/touch.h"
82 #include "tests/callbacks.h"
83 #include "tests/pool.h"
84 #include "tests/print.h"
85 #include "tests/replication.h"
86 #include "tests/server_add.h"
87 #include "tests/virtual_buckets.h"
89 using namespace libtest
;
91 #include <libmemcached/util.h>
93 #include "tests/hash_results.h"
95 #define GLOBAL_COUNT 10000
96 #define GLOBAL2_COUNT 100
97 #define SERVERS_TO_CREATE 5
98 static uint32_t global_count
;
100 static pairs_st
*global_pairs
;
101 static const char *global_keys
[GLOBAL_COUNT
];
102 static size_t global_keys_length
[GLOBAL_COUNT
];
105 @note This should be testing to see if the server really supports the binary protocol.
107 static test_return_t
pre_binary(memcached_st
*memc
)
109 test_skip(true, libmemcached_util_version_check(memc
, 1, 4, 4));
110 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, true));
115 static bool return_value_based_on_buffering(memcached_st
*memc
)
117 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
))
119 return MEMCACHED_BUFFERED
;
122 return MEMCACHED_SUCCESS
;
125 static memcached_st
* create_single_instance_memcached(const memcached_st
*original_memc
, const char *options
)
128 * I only want to hit _one_ server so I know the number of requests I'm
129 * sending in the pipeline.
131 memcached_server_instance_st instance
= memcached_server_instance_by_position(original_memc
, 0);
133 char server_string
[1024];
134 int server_string_length
;
137 server_string_length
= snprintf(server_string
, sizeof(server_string
), "--server=%s:%d %s",
138 memcached_server_name(instance
), int(memcached_server_port(instance
)),
143 server_string_length
= snprintf(server_string
, sizeof(server_string
), "--server=%s:%d",
144 memcached_server_name(instance
), int(memcached_server_port(instance
)));
147 if (server_string_length
<= 0)
153 if (memcached_failed(libmemcached_check_configuration(server_string
, server_string_length
, buffer
, sizeof(buffer
))))
155 Error
<< "Failed to parse " << server_string_length
;
159 return memcached(server_string
, server_string_length
);
163 static test_return_t
init_test(memcached_st
*not_used
)
168 (void)memcached_create(&memc
);
169 memcached_free(&memc
);
174 #define TEST_PORT_COUNT 7
175 in_port_t test_ports
[TEST_PORT_COUNT
];
177 static memcached_return_t
server_display_function(const memcached_st
*ptr
,
178 const memcached_server_st
*server
,
182 size_t bigger
= *((size_t *)(context
));
184 assert(bigger
<= memcached_server_port(server
));
185 *((size_t *)(context
))= memcached_server_port(server
);
187 return MEMCACHED_SUCCESS
;
190 static memcached_return_t
dump_server_information(const memcached_st
*ptr
,
191 const memcached_server_st
*instance
,
195 FILE *stream
= (FILE *)context
;
198 fprintf(stream
, "Memcached Server: %s %u Version %u.%u.%u\n",
199 memcached_server_name(instance
),
200 memcached_server_port(instance
),
201 instance
->major_version
,
202 instance
->minor_version
,
203 instance
->micro_version
);
205 return MEMCACHED_SUCCESS
;
208 static test_return_t
server_sort_test(memcached_st
*ptr
)
210 size_t bigger
= 0; /* Prime the value for the test_true in server_display_function */
212 memcached_return_t rc
;
213 memcached_server_fn callbacks
[1];
214 memcached_st
*local_memc
;
217 local_memc
= memcached_create(NULL
);
218 test_true(local_memc
);
219 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
221 for (uint32_t x
= 0; x
< TEST_PORT_COUNT
; x
++)
223 test_ports
[x
]= (in_port_t
)random() % 64000;
224 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
225 test_compare(memcached_server_count(local_memc
), x
+1);
227 test_true(memcached_server_list_count(memcached_server_list(local_memc
)) == x
+1);
229 test_compare(MEMCACHED_SUCCESS
, rc
);
232 callbacks
[0]= server_display_function
;
233 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
236 memcached_free(local_memc
);
241 static test_return_t
server_sort2_test(memcached_st
*ptr
)
243 size_t bigger
= 0; /* Prime the value for the test_true in server_display_function */
244 memcached_server_fn callbacks
[1];
245 memcached_st
*local_memc
;
246 memcached_server_instance_st instance
;
249 local_memc
= memcached_create(NULL
);
250 test_true(local_memc
);
251 test_compare(MEMCACHED_SUCCESS
,
252 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1));
254 test_compare(MEMCACHED_SUCCESS
,
255 memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43043, 0));
256 instance
= memcached_server_instance_by_position(local_memc
, 0);
257 test_compare(in_port_t(43043), memcached_server_port(instance
));
259 test_compare(MEMCACHED_SUCCESS
,
260 memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43042, 0));
262 instance
= memcached_server_instance_by_position(local_memc
, 0);
263 test_compare(in_port_t(43042), memcached_server_port(instance
));
265 instance
= memcached_server_instance_by_position(local_memc
, 1);
266 test_compare(in_port_t(43043), memcached_server_port(instance
));
268 callbacks
[0]= server_display_function
;
269 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
272 memcached_free(local_memc
);
277 static test_return_t
memcached_server_remove_test(memcached_st
*)
279 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";
282 test_compare(MEMCACHED_SUCCESS
,
283 libmemcached_check_configuration(server_string
, strlen(server_string
), buffer
, sizeof(buffer
)));
284 memcached_st
*memc
= memcached(server_string
, strlen(server_string
));
287 memcached_server_fn callbacks
[1];
288 callbacks
[0]= server_print_callback
;
289 memcached_server_cursor(memc
, callbacks
, NULL
, 1);
291 memcached_free(memc
);
296 static memcached_return_t
server_display_unsort_function(const memcached_st
*,
297 const memcached_server_st
*server
,
301 uint32_t x
= *((uint32_t *)(context
));
303 if (! (test_ports
[x
] == server
->port
))
305 fprintf(stderr
, "%lu -> %lu\n", (unsigned long)test_ports
[x
], (unsigned long)server
->port
);
306 return MEMCACHED_FAILURE
;
309 *((uint32_t *)(context
))= ++x
;
311 return MEMCACHED_SUCCESS
;
314 static test_return_t
server_unsort_test(memcached_st
*ptr
)
316 size_t counter
= 0; /* Prime the value for the test_true in server_display_function */
317 size_t bigger
= 0; /* Prime the value for the test_true in server_display_function */
318 memcached_server_fn callbacks
[1];
319 memcached_st
*local_memc
;
322 local_memc
= memcached_create(NULL
);
323 test_true(local_memc
);
325 for (uint32_t x
= 0; x
< TEST_PORT_COUNT
; x
++)
327 test_ports
[x
]= (in_port_t
)(random() % 64000);
328 test_compare(MEMCACHED_SUCCESS
,
329 memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0));
330 test_compare(memcached_server_count(local_memc
), x
+1);
332 test_true(memcached_server_list_count(memcached_server_list(local_memc
)) == x
+1);
336 callbacks
[0]= server_display_unsort_function
;
337 memcached_server_cursor(local_memc
, callbacks
, (void *)&counter
, 1);
339 /* Now we sort old data! */
340 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
341 callbacks
[0]= server_display_function
;
342 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
345 memcached_free(local_memc
);
350 static test_return_t
allocation_test(memcached_st
*not_used
)
354 memc
= memcached_create(NULL
);
356 memcached_free(memc
);
361 static test_return_t
clone_test(memcached_st
*memc
)
365 memcached_st
*memc_clone
;
366 memc_clone
= memcached_clone(NULL
, NULL
);
367 test_true(memc_clone
);
368 memcached_free(memc_clone
);
371 /* Can we init from null? */
373 memcached_st
*memc_clone
;
374 memc_clone
= memcached_clone(NULL
, memc
);
375 test_true(memc_clone
);
378 test_true(memc_clone
->allocators
.free
== memc
->allocators
.free
);
379 test_true(memc_clone
->allocators
.malloc
== memc
->allocators
.malloc
);
380 test_true(memc_clone
->allocators
.realloc
== memc
->allocators
.realloc
);
381 test_true(memc_clone
->allocators
.calloc
== memc
->allocators
.calloc
);
384 test_true(memc_clone
->connect_timeout
== memc
->connect_timeout
);
385 test_true(memc_clone
->delete_trigger
== memc
->delete_trigger
);
386 test_true(memc_clone
->distribution
== memc
->distribution
);
387 { // Test all of the flags
388 test_true(memc_clone
->flags
.no_block
== memc
->flags
.no_block
);
389 test_true(memc_clone
->flags
.tcp_nodelay
== memc
->flags
.tcp_nodelay
);
390 test_true(memc_clone
->flags
.support_cas
== memc
->flags
.support_cas
);
391 test_true(memc_clone
->flags
.buffer_requests
== memc
->flags
.buffer_requests
);
392 test_true(memc_clone
->flags
.use_sort_hosts
== memc
->flags
.use_sort_hosts
);
393 test_true(memc_clone
->flags
.verify_key
== memc
->flags
.verify_key
);
394 test_true(memc_clone
->ketama
.weighted
== memc
->ketama
.weighted
);
395 test_true(memc_clone
->flags
.binary_protocol
== memc
->flags
.binary_protocol
);
396 test_true(memc_clone
->flags
.hash_with_namespace
== memc
->flags
.hash_with_namespace
);
397 test_true(memc_clone
->flags
.no_reply
== memc
->flags
.no_reply
);
398 test_true(memc_clone
->flags
.use_udp
== memc
->flags
.use_udp
);
399 test_true(memc_clone
->flags
.auto_eject_hosts
== memc
->flags
.auto_eject_hosts
);
400 test_true(memc_clone
->flags
.randomize_replica_read
== memc
->flags
.randomize_replica_read
);
402 test_true(memc_clone
->get_key_failure
== memc
->get_key_failure
);
403 test_true(hashkit_compare(&memc_clone
->hashkit
, &memc
->hashkit
));
404 test_true(memc_clone
->io_bytes_watermark
== memc
->io_bytes_watermark
);
405 test_true(memc_clone
->io_msg_watermark
== memc
->io_msg_watermark
);
406 test_true(memc_clone
->io_key_prefetch
== memc
->io_key_prefetch
);
407 test_true(memc_clone
->on_cleanup
== memc
->on_cleanup
);
408 test_true(memc_clone
->on_clone
== memc
->on_clone
);
409 test_true(memc_clone
->poll_timeout
== memc
->poll_timeout
);
410 test_true(memc_clone
->rcv_timeout
== memc
->rcv_timeout
);
411 test_true(memc_clone
->recv_size
== memc
->recv_size
);
412 test_true(memc_clone
->retry_timeout
== memc
->retry_timeout
);
413 test_true(memc_clone
->send_size
== memc
->send_size
);
414 test_true(memc_clone
->server_failure_limit
== memc
->server_failure_limit
);
415 test_true(memc_clone
->snd_timeout
== memc
->snd_timeout
);
416 test_true(memc_clone
->user_data
== memc
->user_data
);
418 memcached_free(memc_clone
);
421 /* Can we init from struct? */
423 memcached_st declared_clone
;
424 memcached_st
*memc_clone
;
425 memset(&declared_clone
, 0 , sizeof(memcached_st
));
426 memc_clone
= memcached_clone(&declared_clone
, NULL
);
427 test_true(memc_clone
);
428 memcached_free(memc_clone
);
431 /* Can we init from struct? */
433 memcached_st declared_clone
;
434 memcached_st
*memc_clone
;
435 memset(&declared_clone
, 0 , sizeof(memcached_st
));
436 memc_clone
= memcached_clone(&declared_clone
, memc
);
437 test_true(memc_clone
);
438 memcached_free(memc_clone
);
444 static test_return_t
userdata_test(memcached_st
*memc
)
447 test_false(memcached_set_user_data(memc
, foo
));
448 test_true(memcached_get_user_data(memc
) == foo
);
449 test_true(memcached_set_user_data(memc
, NULL
) == foo
);
454 static test_return_t
connection_test(memcached_st
*memc
)
456 test_compare(MEMCACHED_SUCCESS
,
457 memcached_server_add_with_weight(memc
, "localhost", 0, 0));
462 static test_return_t
libmemcached_string_behavior_test(memcached_st
*)
464 for (int x
= MEMCACHED_BEHAVIOR_NO_BLOCK
; x
< int(MEMCACHED_BEHAVIOR_MAX
); ++x
)
466 test_true(libmemcached_string_behavior(memcached_behavior_t(x
)));
468 test_compare(36, int(MEMCACHED_BEHAVIOR_MAX
));
473 static test_return_t
libmemcached_string_distribution_test(memcached_st
*)
475 for (int x
= MEMCACHED_DISTRIBUTION_MODULA
; x
< int(MEMCACHED_DISTRIBUTION_CONSISTENT_MAX
); ++x
)
477 test_true(libmemcached_string_distribution(memcached_server_distribution_t(x
)));
479 test_compare(7, int(MEMCACHED_DISTRIBUTION_CONSISTENT_MAX
));
484 static test_return_t
memcached_return_t_TEST(memcached_st
*memc
)
486 uint32_t values
[] = { 851992627U, 2337886783U, 4109241422U, 4001849190U,
487 982370485U, 1263635348U, 4242906218U, 3829656100U,
488 1891735253U, 334139633U, 2257084983U, 3088286104U,
489 13199785U, 2542027183U, 1097051614U, 199566778U,
490 2748246961U, 2465192557U, 1664094137U, 2405439045U,
491 1842224848U, 692413798U, 3479807801U, 919913813U,
492 4269430871U, 610793021U, 527273862U, 1437122909U,
493 2300930706U, 2943759320U, 674306647U, 2400528935U,
494 54481931U, 4186304426U, 1741088401U, 2979625118U,
495 4159057246U, 3425930182U, 2593724503U, 1868899624U,
496 1769812374U, 2302537950U, 1110330676U, 3365377466U,
497 1336171666U, 3021258493U, 2334992265U, 3861994737U,
498 3582734124U, 3365377466U };
500 // You have updated the memcache_error messages but not updated docs/tests.
501 for (int rc
= int(MEMCACHED_SUCCESS
); rc
< int(MEMCACHED_MAXIMUM_RETURN
); ++rc
)
504 const char *msg
= memcached_strerror(memc
, memcached_return_t(rc
));
505 hash_val
= memcached_generate_hash_value(msg
, strlen(msg
),
506 MEMCACHED_HASH_JENKINS
);
507 if (values
[rc
] != hash_val
)
509 fprintf(stderr
, "\n\nYou have updated memcached_return_t without updating the memcached_return_t_TEST\n");
510 fprintf(stderr
, "%u, %s, (%u)\n\n", (uint32_t)rc
, memcached_strerror(memc
, memcached_return_t(rc
)), hash_val
);
512 test_compare(values
[rc
], hash_val
);
514 test_compare(49, int(MEMCACHED_MAXIMUM_RETURN
));
519 static test_return_t
set_test(memcached_st
*memc
)
521 memcached_return_t rc
= memcached_set(memc
,
522 test_literal_param("foo"),
523 test_literal_param("when we sanitize"),
524 time_t(0), (uint32_t)0);
525 test_true_got(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
, memcached_strerror(NULL
, rc
));
530 static test_return_t
append_test(memcached_st
*memc
)
532 memcached_return_t rc
;
533 const char *key
= "fig";
534 const char *in_value
= "we";
535 char *out_value
= NULL
;
539 rc
= memcached_flush(memc
, 0);
540 test_compare(MEMCACHED_SUCCESS
, rc
);
542 rc
= memcached_set(memc
, key
, strlen(key
),
543 in_value
, strlen(in_value
),
544 (time_t)0, (uint32_t)0);
545 test_compare(MEMCACHED_SUCCESS
, rc
);
547 rc
= memcached_append(memc
, key
, strlen(key
),
548 " the", strlen(" the"),
549 (time_t)0, (uint32_t)0);
550 test_compare(MEMCACHED_SUCCESS
, rc
);
552 rc
= memcached_append(memc
, key
, strlen(key
),
553 " people", strlen(" people"),
554 (time_t)0, (uint32_t)0);
555 test_compare(MEMCACHED_SUCCESS
, rc
);
557 out_value
= memcached_get(memc
, key
, strlen(key
),
558 &value_length
, &flags
, &rc
);
559 test_memcmp(out_value
, "we the people", strlen("we the people"));
560 test_compare(strlen("we the people"), value_length
);
561 test_compare(MEMCACHED_SUCCESS
, rc
);
567 static test_return_t
append_binary_test(memcached_st
*memc
)
569 memcached_return_t rc
;
570 const char *key
= "numbers";
571 uint32_t store_list
[] = { 23, 56, 499, 98, 32847, 0 };
577 rc
= memcached_flush(memc
, 0);
578 test_compare(MEMCACHED_SUCCESS
, rc
);
580 rc
= memcached_set(memc
,
583 (time_t)0, (uint32_t)0);
584 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
586 for (x
= 0; store_list
[x
] ; x
++)
588 rc
= memcached_append(memc
,
590 (char *)&store_list
[x
], sizeof(uint32_t),
591 (time_t)0, (uint32_t)0);
592 test_compare(MEMCACHED_SUCCESS
, rc
);
595 value
= (uint32_t *)memcached_get(memc
, key
, strlen(key
),
596 &value_length
, &flags
, &rc
);
597 test_compare(value_length
, sizeof(uint32_t) * x
);
598 test_compare(MEMCACHED_SUCCESS
, rc
);
600 for (uint32_t counter
= x
, *ptr
= value
; counter
; counter
--)
602 test_compare(*ptr
, store_list
[x
- counter
]);
610 static test_return_t
cas2_test(memcached_st
*memc
)
612 memcached_return_t rc
;
613 const char *keys
[]= {"fudge", "son", "food"};
614 size_t key_length
[]= {5, 3, 4};
615 const char *value
= "we the people";
616 size_t value_length
= strlen("we the people");
617 memcached_result_st results_obj
;
618 memcached_result_st
*results
;
621 test_compare(MEMCACHED_SUCCESS
, memcached_flush(memc
, 0));
623 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
625 for (uint32_t x
= 0; x
< 3; x
++)
627 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
628 keys
[x
], key_length
[x
],
629 (time_t)50, (uint32_t)9);
630 test_compare(MEMCACHED_SUCCESS
, rc
);
633 test_compare(MEMCACHED_SUCCESS
,
634 memcached_mget(memc
, keys
, key_length
, 3));
636 results
= memcached_result_create(memc
, &results_obj
);
639 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
641 test_true(results
->item_cas
);
642 test_compare(MEMCACHED_SUCCESS
, rc
);
643 test_true(memcached_result_cas(results
));
645 test_memcmp(value
, "we the people", strlen("we the people"));
646 test_compare(strlen("we the people"), value_length
);
647 test_compare(MEMCACHED_SUCCESS
, rc
);
649 memcached_result_free(&results_obj
);
654 static test_return_t
cas_test(memcached_st
*memc
)
656 memcached_return_t rc
;
657 const char *key
= "fun";
658 size_t key_length
= strlen(key
);
659 const char *value
= "we the people";
660 const char* keys
[2] = { key
, NULL
};
661 size_t keylengths
[2] = { strlen(key
), 0 };
662 size_t value_length
= strlen(value
);
663 const char *value2
= "change the value";
664 size_t value2_length
= strlen(value2
);
666 memcached_result_st results_obj
;
667 memcached_result_st
*results
;
670 rc
= memcached_flush(memc
, 0);
671 test_compare(MEMCACHED_SUCCESS
, rc
);
673 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
675 rc
= memcached_set(memc
, key
, strlen(key
),
676 value
, strlen(value
),
677 (time_t)0, (uint32_t)0);
678 test_compare(MEMCACHED_SUCCESS
, rc
);
680 test_compare(MEMCACHED_SUCCESS
,
681 memcached_mget(memc
, keys
, keylengths
, 1));
683 results
= memcached_result_create(memc
, &results_obj
);
686 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
688 test_compare(MEMCACHED_SUCCESS
, rc
);
689 test_true(memcached_result_cas(results
));
690 test_memcmp(value
, memcached_result_value(results
), value_length
);
691 test_compare(strlen(memcached_result_value(results
)), value_length
);
692 test_compare(MEMCACHED_SUCCESS
, rc
);
693 uint64_t cas
= memcached_result_cas(results
);
696 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
697 test_true(rc
== MEMCACHED_END
);
698 test_true(results
== NULL
);
701 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
702 test_compare(MEMCACHED_SUCCESS
, rc
);
705 * The item will have a new cas value, so try to set it again with the old
706 * value. This should fail!
708 rc
= memcached_cas(memc
, key
, key_length
, value2
, value2_length
, 0, 0, cas
);
709 test_compare(MEMCACHED_DATA_EXISTS
, rc
);
711 memcached_result_free(&results_obj
);
716 static test_return_t
prepend_test(memcached_st
*memc
)
718 memcached_return_t rc
;
719 const char *key
= "fig";
720 const char *value
= "people";
721 char *out_value
= NULL
;
725 rc
= memcached_flush(memc
, 0);
726 test_compare(MEMCACHED_SUCCESS
, rc
);
728 rc
= memcached_set(memc
, key
, strlen(key
),
729 value
, strlen(value
),
730 (time_t)0, (uint32_t)0);
731 test_compare(MEMCACHED_SUCCESS
, rc
);
733 rc
= memcached_prepend(memc
, key
, strlen(key
),
734 "the ", strlen("the "),
735 (time_t)0, (uint32_t)0);
736 test_compare(MEMCACHED_SUCCESS
, rc
);
738 rc
= memcached_prepend(memc
, key
, strlen(key
),
739 "we ", strlen("we "),
740 (time_t)0, (uint32_t)0);
741 test_compare(MEMCACHED_SUCCESS
, rc
);
743 out_value
= memcached_get(memc
, key
, strlen(key
),
744 &value_length
, &flags
, &rc
);
745 test_memcmp(out_value
, "we the people", strlen("we the people"));
746 test_compare(strlen("we the people"), value_length
);
747 test_compare(MEMCACHED_SUCCESS
, rc
);
754 Set the value, then quit to make sure it is flushed.
755 Come back in and test that add fails.
757 static test_return_t
add_test(memcached_st
*memc
)
759 memcached_return_t rc
;
760 const char *key
= "foo";
761 const char *value
= "when we sanitize";
762 unsigned long long setting_value
;
764 setting_value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
766 rc
= memcached_set(memc
, key
, strlen(key
),
767 value
, strlen(value
),
768 (time_t)0, (uint32_t)0);
769 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
770 memcached_quit(memc
);
771 rc
= memcached_add(memc
, key
, strlen(key
),
772 value
, strlen(value
),
773 (time_t)0, (uint32_t)0);
775 /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */
778 test_true(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_STORED
);
782 test_true(rc
== MEMCACHED_NOTSTORED
|| rc
== MEMCACHED_DATA_EXISTS
);
789 ** There was a problem of leaking filedescriptors in the initial release
790 ** of MacOSX 10.5. This test case triggers the problem. On some Solaris
791 ** systems it seems that the kernel is slow on reclaiming the resources
792 ** because the connects starts to time out (the test doesn't do much
793 ** anyway, so just loop 10 iterations)
795 static test_return_t
add_wrapper(memcached_st
*memc
)
797 unsigned int max
= 10000;
805 for (uint32_t x
= 0; x
< max
; x
++)
811 static test_return_t
replace_test(memcached_st
*memc
)
813 memcached_return_t rc
;
814 const char *key
= "foo";
815 const char *value
= "when we sanitize";
816 const char *original
= "first we insert some data";
818 rc
= memcached_set(memc
, key
, strlen(key
),
819 original
, strlen(original
),
820 (time_t)0, (uint32_t)0);
821 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
823 test_compare(MEMCACHED_SUCCESS
,
824 memcached_replace(memc
, key
, strlen(key
),
825 value
, strlen(value
),
826 (time_t)0, (uint32_t)0));
831 static test_return_t
delete_test(memcached_st
*memc
)
833 test_compare(return_value_based_on_buffering(memc
),
835 test_literal_param(__func__
),
836 test_literal_param("when we sanitize"),
837 time_t(0), uint32_t(0)));
839 memcached_return_t rc
= memcached_delete(memc
,
840 test_literal_param(__func__
),
842 test_compare_hint(MEMCACHED_SUCCESS
,
844 memcached_last_error_message(memc
));
849 static test_return_t
flush_test(memcached_st
*memc
)
851 uint64_t query_id
= memcached_query_id(memc
);
852 test_compare(MEMCACHED_SUCCESS
,
853 memcached_flush(memc
, 0));
854 test_compare(query_id
+1, memcached_query_id(memc
));
859 static memcached_return_t
server_function(const memcached_st
*ptr
,
860 const memcached_server_st
*server
,
863 (void)ptr
; (void)server
; (void)context
;
866 return MEMCACHED_SUCCESS
;
869 static test_return_t
memcached_server_cursor_test(memcached_st
*memc
)
872 strncpy(context
, "foo bad", sizeof(context
));
873 memcached_server_fn callbacks
[1];
875 callbacks
[0]= server_function
;
876 memcached_server_cursor(memc
, callbacks
, context
, 1);
880 static test_return_t
bad_key_test(memcached_st
*memc
)
882 memcached_return_t rc
;
883 const char *key
= "foo bad";
885 memcached_st
*memc_clone
;
887 uint64_t query_id
= memcached_query_id(memc
);
889 // Just skip if we are in binary mode.
890 test_skip(false, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
));
892 test_compare(query_id
, memcached_query_id(memc
)); // We should not increase the query_id for memcached_behavior_get()
894 memc_clone
= memcached_clone(NULL
, memc
);
895 test_true(memc_clone
);
897 query_id
= memcached_query_id(memc_clone
);
898 test_compare(MEMCACHED_SUCCESS
,
899 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, true));
900 test_compare(query_id
, memcached_query_id(memc_clone
)); // We should not increase the query_id for memcached_behavior_set()
902 /* All keys are valid in the binary protocol (except for length) */
903 if (not memcached_behavior_get(memc_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
))
905 uint64_t before_query_id
= memcached_query_id(memc_clone
);
907 size_t string_length
;
908 char *string
= memcached_get(memc_clone
, key
, strlen(key
),
909 &string_length
, &flags
, &rc
);
910 test_compare(MEMCACHED_BAD_KEY_PROVIDED
, rc
);
911 test_zero(string_length
);
914 test_compare(before_query_id
+1, memcached_query_id(memc_clone
));
916 query_id
= memcached_query_id(memc_clone
);
917 test_compare(MEMCACHED_SUCCESS
,
918 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, false));
919 test_compare(query_id
, memcached_query_id(memc_clone
)); // We should not increase the query_id for memcached_behavior_set()
921 size_t string_length
;
922 char *string
= memcached_get(memc_clone
, key
, strlen(key
),
923 &string_length
, &flags
, &rc
);
924 test_compare_got(MEMCACHED_NOTFOUND
, rc
, memcached_strerror(NULL
, rc
));
925 test_zero(string_length
);
929 /* Test multi key for bad keys */
930 const char *keys
[] = { "GoodKey", "Bad Key", "NotMine" };
931 size_t key_lengths
[] = { 7, 7, 7 };
932 query_id
= memcached_query_id(memc_clone
);
933 test_compare(MEMCACHED_SUCCESS
,
934 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, true));
935 test_compare(query_id
, memcached_query_id(memc_clone
));
937 query_id
= memcached_query_id(memc_clone
);
938 test_compare(MEMCACHED_BAD_KEY_PROVIDED
,
939 memcached_mget(memc_clone
, keys
, key_lengths
, 3));
940 test_compare(query_id
+1, memcached_query_id(memc_clone
));
942 query_id
= memcached_query_id(memc_clone
);
943 test_compare(MEMCACHED_BAD_KEY_PROVIDED
,
944 memcached_mget_by_key(memc_clone
, "foo daddy", 9, keys
, key_lengths
, 1));
945 test_compare(query_id
+1, memcached_query_id(memc_clone
));
947 /* The following test should be moved to the end of this function when the
948 memcached server is updated to allow max size length of the keys in the
951 test_compare(MEMCACHED_SUCCESS
,
952 memcached_callback_set(memc_clone
, MEMCACHED_CALLBACK_NAMESPACE
, NULL
));
954 std::vector
<char> longkey
;
956 std::vector
<char>::iterator it
= longkey
.begin();
957 longkey
.insert(it
, MEMCACHED_MAX_KEY
, 'a');
960 test_compare(longkey
.size(), size_t(MEMCACHED_MAX_KEY
));
962 size_t string_length
;
964 test_null(memcached_get(memc_clone
, &longkey
[0], longkey
.size() -1, &string_length
, &flags
, &rc
));
965 test_compare(MEMCACHED_NOTFOUND
, rc
);
966 test_zero(string_length
);
968 test_null(memcached_get(memc_clone
, &longkey
[0], longkey
.size(), &string_length
, &flags
, &rc
));
969 test_compare(MEMCACHED_BAD_KEY_PROVIDED
, rc
);
970 test_zero(string_length
);
974 /* Make sure zero length keys are marked as bad */
976 test_compare(MEMCACHED_SUCCESS
,
977 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, true));
978 size_t string_length
;
979 char *string
= memcached_get(memc_clone
, key
, 0,
980 &string_length
, &flags
, &rc
);
981 test_compare(MEMCACHED_BAD_KEY_PROVIDED
, rc
);
982 test_zero(string_length
);
986 memcached_free(memc_clone
);
991 #define READ_THROUGH_VALUE "set for me"
992 static memcached_return_t
read_through_trigger(memcached_st
*memc
,
995 memcached_result_st
*result
)
997 (void)memc
;(void)key
;(void)key_length
;
998 return memcached_result_set_value(result
, READ_THROUGH_VALUE
, strlen(READ_THROUGH_VALUE
));
1001 #ifndef __INTEL_COMPILER
1002 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
1005 static test_return_t
read_through(memcached_st
*memc
)
1007 memcached_return_t rc
;
1008 const char *key
= "foo";
1010 size_t string_length
;
1012 memcached_trigger_key_fn cb
= (memcached_trigger_key_fn
)read_through_trigger
;
1014 string
= memcached_get(memc
, key
, strlen(key
),
1015 &string_length
, &flags
, &rc
);
1017 test_compare(MEMCACHED_NOTFOUND
, rc
);
1018 test_false(string_length
);
1021 rc
= memcached_callback_set(memc
, MEMCACHED_CALLBACK_GET_FAILURE
, *(void **)&cb
);
1022 test_compare(MEMCACHED_SUCCESS
, rc
);
1024 string
= memcached_get(memc
, key
, strlen(key
),
1025 &string_length
, &flags
, &rc
);
1027 test_compare(MEMCACHED_SUCCESS
, rc
);
1028 test_compare(string_length
, sizeof(READ_THROUGH_VALUE
) -1);
1029 test_true(string
[sizeof(READ_THROUGH_VALUE
) -1] == 0);
1030 test_strcmp(READ_THROUGH_VALUE
, string
);
1033 string
= memcached_get(memc
, key
, strlen(key
),
1034 &string_length
, &flags
, &rc
);
1036 test_compare(MEMCACHED_SUCCESS
, rc
);
1038 test_compare(string_length
, sizeof(READ_THROUGH_VALUE
) -1);
1039 test_true(string
[sizeof(READ_THROUGH_VALUE
) -1] == 0);
1040 test_strcmp(READ_THROUGH_VALUE
, string
);
1043 return TEST_SUCCESS
;
1046 static test_return_t
get_test(memcached_st
*memc
)
1048 memcached_return_t rc
;
1049 const char *key
= "foo";
1051 size_t string_length
;
1054 uint64_t query_id
= memcached_query_id(memc
);
1055 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
1056 test_true_got(rc
== MEMCACHED_BUFFERED
|| rc
== MEMCACHED_NOTFOUND
, memcached_last_error_message(memc
));
1057 test_compare(query_id
+1, memcached_query_id(memc
));
1059 string
= memcached_get(memc
, key
, strlen(key
),
1060 &string_length
, &flags
, &rc
);
1062 test_compare_got(MEMCACHED_NOTFOUND
, rc
, memcached_strerror(NULL
, rc
));
1063 test_false(string_length
);
1066 return TEST_SUCCESS
;
1069 static test_return_t
get_test2(memcached_st
*memc
)
1071 const char *key
= "foo";
1072 const char *value
= "when we sanitize";
1074 uint64_t query_id
= memcached_query_id(memc
);
1075 memcached_return_t rc
= memcached_set(memc
, key
, strlen(key
),
1076 value
, strlen(value
),
1077 (time_t)0, (uint32_t)0);
1078 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
1079 test_compare(query_id
+1, memcached_query_id(memc
));
1081 query_id
= memcached_query_id(memc
);
1082 test_true(query_id
);
1085 size_t string_length
;
1086 char *string
= memcached_get(memc
, key
, strlen(key
),
1087 &string_length
, &flags
, &rc
);
1088 test_compare(query_id
+1, memcached_query_id(memc
));
1090 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
1091 test_compare_got(MEMCACHED_SUCCESS
, memcached_last_error(memc
), memcached_last_error_message(memc
));
1093 test_compare(strlen(value
), string_length
);
1094 test_memcmp(string
, value
, string_length
);
1098 return TEST_SUCCESS
;
1101 static test_return_t
set_test2(memcached_st
*memc
)
1103 for (uint32_t x
= 0; x
< 10; x
++)
1105 memcached_return_t rc
= memcached_set(memc
,
1106 test_literal_param("foo"),
1107 test_literal_param("train in the brain"),
1108 time_t(0), uint32_t(0));
1109 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
1112 return TEST_SUCCESS
;
1115 static test_return_t
set_test3(memcached_st
*memc
)
1117 size_t value_length
= 8191;
1119 std::vector
<char> value
;
1120 value
.reserve(value_length
);
1121 for (uint32_t x
= 0; x
< value_length
; x
++)
1123 value
.push_back(char(x
% 127));
1126 /* The dump test relies on there being at least 32 items in memcached */
1127 for (uint32_t x
= 0; x
< 32; x
++)
1131 snprintf(key
, sizeof(key
), "foo%u", x
);
1133 uint64_t query_id
= memcached_query_id(memc
);
1134 memcached_return_t rc
= memcached_set(memc
, key
, strlen(key
),
1135 &value
[0], value
.size(),
1136 (time_t)0, (uint32_t)0);
1137 test_true_got(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
, memcached_strerror(NULL
, rc
));
1138 test_compare(query_id
+1, memcached_query_id(memc
));
1141 return TEST_SUCCESS
;
1144 static test_return_t
get_test3(memcached_st
*memc
)
1146 const char *key
= "foo";
1147 size_t value_length
= 8191;
1149 std::vector
<char> value
;
1150 value
.reserve(value_length
);
1151 for (uint32_t x
= 0; x
< value_length
; x
++)
1153 value
.push_back(char(x
% 127));
1156 memcached_return_t rc
;
1157 rc
= memcached_set(memc
, key
, strlen(key
),
1158 &value
[0], value
.size(),
1159 (time_t)0, (uint32_t)0);
1160 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
1162 size_t string_length
;
1164 char *string
= memcached_get(memc
, key
, strlen(key
),
1165 &string_length
, &flags
, &rc
);
1167 test_compare(MEMCACHED_SUCCESS
, rc
);
1169 test_compare(string_length
, value_length
);
1170 test_memcmp(string
, &value
[0], string_length
);
1174 return TEST_SUCCESS
;
1177 static test_return_t
get_test4(memcached_st
*memc
)
1179 const char *key
= "foo";
1180 size_t value_length
= 8191;
1182 std::vector
<char> value
;
1183 value
.reserve(value_length
);
1184 for (uint32_t x
= 0; x
< value_length
; x
++)
1186 value
.push_back(char(x
% 127));
1189 memcached_return_t rc
= memcached_set(memc
, key
, strlen(key
),
1190 &value
[0], value
.size(),
1191 (time_t)0, (uint32_t)0);
1192 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
1194 for (uint32_t x
= 0; x
< 10; x
++)
1197 size_t string_length
;
1198 char *string
= memcached_get(memc
, key
, strlen(key
),
1199 &string_length
, &flags
, &rc
);
1201 test_compare(MEMCACHED_SUCCESS
, rc
);
1203 test_compare(string_length
, value_length
);
1204 test_memcmp(string
, &value
[0], string_length
);
1208 return TEST_SUCCESS
;
1212 * This test verifies that memcached_read_one_response doesn't try to
1213 * dereference a NIL-pointer if you issue a multi-get and don't read out all
1214 * responses before you execute a storage command.
1216 static test_return_t
get_test5(memcached_st
*memc
)
1219 ** Request the same key twice, to ensure that we hash to the same server
1220 ** (so that we have multiple response values queued up) ;-)
1222 const char *keys
[]= { "key", "key" };
1223 size_t lengths
[]= { 3, 3 };
1227 memcached_return_t rc
= memcached_set(memc
, keys
[0], lengths
[0],
1228 keys
[0], lengths
[0], 0, 0);
1229 test_compare(MEMCACHED_SUCCESS
, memcached_mget(memc
, keys
, lengths
, test_array_length(keys
)));
1231 memcached_result_st results_obj
;
1232 memcached_result_st
*results
= memcached_result_create(memc
, &results_obj
);
1235 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
1238 memcached_result_free(&results_obj
);
1240 /* Don't read out the second result, but issue a set instead.. */
1241 test_compare(MEMCACHED_SUCCESS
, memcached_set(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0));
1243 char *val
= memcached_get_by_key(memc
, keys
[0], lengths
[0], "yek", 3,
1244 &rlen
, &flags
, &rc
);
1246 test_compare(MEMCACHED_NOTFOUND
, rc
);
1247 val
= memcached_get(memc
, keys
[0], lengths
[0], &rlen
, &flags
, &rc
);
1249 test_compare(MEMCACHED_SUCCESS
, rc
);
1252 return TEST_SUCCESS
;
1255 static test_return_t
mget_end(memcached_st
*memc
)
1257 const char *keys
[]= { "foo", "foo2" };
1258 size_t lengths
[]= { 3, 4 };
1259 const char *values
[]= { "fjord", "41" };
1261 memcached_return_t rc
;
1264 for (size_t x
= 0; x
< test_array_length(keys
); x
++)
1266 test_compare(MEMCACHED_SUCCESS
, memcached_set(memc
, keys
[x
], lengths
[x
], values
[x
], strlen(values
[x
]), (time_t)0, (uint32_t)0));
1270 size_t string_length
;
1273 // retrieve both via mget
1274 test_compare(MEMCACHED_SUCCESS
, memcached_mget(memc
, keys
, lengths
, test_array_length(keys
)));
1276 char key
[MEMCACHED_MAX_KEY
];
1279 // this should get both
1280 for (size_t x
= 0; x
< test_array_length(keys
); x
++)
1282 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
,
1284 test_compare(MEMCACHED_SUCCESS
, rc
);
1286 if (key_length
== 4)
1291 test_compare(string_length
, strlen(values
[val
]));
1292 test_true(strncmp(values
[val
], string
, string_length
) == 0);
1296 // this should indicate end
1297 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1298 test_compare(MEMCACHED_END
, rc
);
1302 rc
= memcached_mget(memc
, keys
, lengths
, 1);
1303 test_compare(MEMCACHED_SUCCESS
, rc
);
1305 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1306 test_compare(key_length
, lengths
[0]);
1307 test_true(strncmp(keys
[0], key
, key_length
) == 0);
1308 test_compare(string_length
, strlen(values
[0]));
1309 test_true(strncmp(values
[0], string
, string_length
) == 0);
1310 test_compare(MEMCACHED_SUCCESS
, rc
);
1313 // this should indicate end
1314 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1315 test_compare(MEMCACHED_END
, rc
);
1318 return TEST_SUCCESS
;
1321 /* Do not copy the style of this code, I just access hosts to testthis function */
1322 static test_return_t
stats_servername_test(memcached_st
*memc
)
1324 memcached_stat_st memc_stat
;
1325 memcached_server_instance_st instance
=
1326 memcached_server_instance_by_position(memc
, 0);
1328 if (LIBMEMCACHED_WITH_SASL_SUPPORT
and memcached_get_sasl_callbacks(memc
))
1330 return TEST_SKIPPED
;
1333 test_compare(MEMCACHED_SUCCESS
, memcached_stat_servername(&memc_stat
, NULL
,
1334 memcached_server_name(instance
),
1335 memcached_server_port(instance
)));
1337 return TEST_SUCCESS
;
1340 static test_return_t
increment_test(memcached_st
*memc
)
1342 uint64_t new_number
;
1344 test_compare(MEMCACHED_SUCCESS
,
1346 test_literal_param("number"),
1347 test_literal_param("0"),
1348 (time_t)0, (uint32_t)0));
1350 test_compare(MEMCACHED_SUCCESS
,
1351 memcached_increment(memc
, test_literal_param("number"), 1, &new_number
));
1352 test_compare(uint64_t(1), new_number
);
1354 test_compare(MEMCACHED_SUCCESS
,
1355 memcached_increment(memc
, test_literal_param("number"), 1, &new_number
));
1356 test_compare(uint64_t(2), new_number
);
1358 return TEST_SUCCESS
;
1361 static test_return_t
increment_with_initial_test(memcached_st
*memc
)
1363 test_skip(true, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
));
1365 uint64_t new_number
;
1366 uint64_t initial
= 0;
1368 test_compare(MEMCACHED_SUCCESS
, memcached_flush_buffers(memc
));
1370 test_compare(MEMCACHED_SUCCESS
,
1371 memcached_increment_with_initial(memc
, test_literal_param("number"), 1, initial
, 0, &new_number
));
1372 test_compare(new_number
, initial
);
1374 test_compare(MEMCACHED_SUCCESS
,
1375 memcached_increment_with_initial(memc
, test_literal_param("number"), 1, initial
, 0, &new_number
));
1376 test_compare(new_number
, (initial
+1));
1378 return TEST_SUCCESS
;
1381 static test_return_t
decrement_test(memcached_st
*memc
)
1383 uint64_t new_number
;
1384 memcached_return_t rc
;
1385 const char *value
= "3";
1387 rc
= memcached_set(memc
,
1388 test_literal_param("number"),
1389 value
, strlen(value
),
1390 (time_t)0, (uint32_t)0);
1391 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
1393 test_compare(MEMCACHED_SUCCESS
,
1394 memcached_decrement(memc
,
1395 test_literal_param("number"),
1397 test_compare(uint64_t(2), new_number
);
1399 test_compare(MEMCACHED_SUCCESS
,
1400 memcached_decrement(memc
,
1401 test_literal_param("number"),
1403 test_compare(uint64_t(1), new_number
);
1405 return TEST_SUCCESS
;
1408 static test_return_t
decrement_with_initial_test(memcached_st
*memc
)
1410 test_skip(true, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
));
1412 uint64_t new_number
;
1413 uint64_t initial
= 3;
1415 test_compare(MEMCACHED_SUCCESS
, memcached_flush_buffers(memc
));
1417 test_compare(MEMCACHED_SUCCESS
,
1418 memcached_decrement_with_initial(memc
,
1419 test_literal_param("number"),
1420 1, initial
, 0, &new_number
));
1421 test_compare(new_number
, initial
);
1423 test_compare(MEMCACHED_SUCCESS
,
1424 memcached_decrement_with_initial(memc
,
1425 test_literal_param("number"),
1426 1, initial
, 0, &new_number
));
1427 test_compare(new_number
, (initial
- 1));
1429 return TEST_SUCCESS
;
1432 static test_return_t
increment_by_key_test(memcached_st
*memc
)
1434 uint64_t new_number
;
1435 memcached_return_t rc
;
1436 const char *master_key
= "foo";
1437 const char *key
= "number";
1438 const char *value
= "0";
1440 rc
= memcached_set_by_key(memc
, master_key
, strlen(master_key
),
1442 value
, strlen(value
),
1443 (time_t)0, (uint32_t)0);
1444 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
1446 test_compare(MEMCACHED_SUCCESS
,
1447 memcached_increment_by_key(memc
, master_key
, strlen(master_key
), key
, strlen(key
), 1, &new_number
));
1448 test_compare(uint64_t(1), new_number
);
1450 test_compare(MEMCACHED_SUCCESS
,
1451 memcached_increment_by_key(memc
, master_key
, strlen(master_key
), key
, strlen(key
), 1, &new_number
));
1452 test_compare(uint64_t(2), new_number
);
1454 return TEST_SUCCESS
;
1457 static test_return_t
increment_with_initial_by_key_test(memcached_st
*memc
)
1459 test_skip(true, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
));
1461 uint64_t new_number
;
1462 memcached_return_t rc
;
1463 const char *master_key
= "foo";
1464 const char *key
= "number";
1465 uint64_t initial
= 0;
1467 rc
= memcached_increment_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1469 1, initial
, 0, &new_number
);
1470 test_compare(MEMCACHED_SUCCESS
, rc
);
1471 test_compare(new_number
, initial
);
1473 rc
= memcached_increment_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1475 1, initial
, 0, &new_number
);
1476 test_compare(MEMCACHED_SUCCESS
, rc
);
1477 test_compare(new_number
, (initial
+1));
1479 return TEST_SUCCESS
;
1482 static test_return_t
decrement_by_key_test(memcached_st
*memc
)
1484 uint64_t new_number
;
1485 memcached_return_t rc
;
1486 const char *value
= "3";
1488 rc
= memcached_set_by_key(memc
,
1489 test_literal_param("foo"),
1490 test_literal_param("number"),
1491 value
, strlen(value
),
1492 (time_t)0, (uint32_t)0);
1493 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
1495 test_compare(MEMCACHED_SUCCESS
,
1496 memcached_decrement_by_key(memc
,
1497 test_literal_param("foo"),
1498 test_literal_param("number"),
1500 test_compare(uint64_t(2), new_number
);
1502 test_compare(MEMCACHED_SUCCESS
,
1503 memcached_decrement_by_key(memc
,
1504 test_literal_param("foo"),
1505 test_literal_param("number"),
1507 test_compare(uint64_t(1), new_number
);
1509 return TEST_SUCCESS
;
1512 static test_return_t
decrement_with_initial_by_key_test(memcached_st
*memc
)
1514 test_skip(true, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
));
1516 uint64_t new_number
;
1517 uint64_t initial
= 3;
1519 test_compare(MEMCACHED_SUCCESS
,
1520 memcached_decrement_with_initial_by_key(memc
,
1521 test_literal_param("foo"),
1522 test_literal_param("number"),
1523 1, initial
, 0, &new_number
));
1524 test_compare(new_number
, initial
);
1526 test_compare(MEMCACHED_SUCCESS
,
1527 memcached_decrement_with_initial_by_key(memc
,
1528 test_literal_param("foo"),
1529 test_literal_param("number"),
1530 1, initial
, 0, &new_number
));
1531 test_compare(new_number
, (initial
- 1));
1533 return TEST_SUCCESS
;
1535 static test_return_t
binary_increment_with_prefix_test(memcached_st
*orig_memc
)
1537 memcached_st
*memc
= memcached_clone(NULL
, orig_memc
);
1539 test_skip(TEST_SUCCESS
, pre_binary(memc
));
1541 test_compare(MEMCACHED_SUCCESS
, memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)"namespace:"));
1543 memcached_return_t rc
;
1544 rc
= memcached_set(memc
,
1545 test_literal_param("number"),
1546 test_literal_param("0"),
1547 (time_t)0, (uint32_t)0);
1548 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1550 uint64_t new_number
;
1551 test_compare(MEMCACHED_SUCCESS
, memcached_increment(memc
,
1552 test_literal_param("number"),
1554 test_compare(uint64_t(1), new_number
);
1556 test_compare(MEMCACHED_SUCCESS
, memcached_increment(memc
,
1557 test_literal_param("number"),
1559 test_compare(uint64_t(2), new_number
);
1560 memcached_free(memc
);
1562 return TEST_SUCCESS
;
1565 static test_return_t
quit_test(memcached_st
*memc
)
1567 memcached_return_t rc
;
1568 const char *key
= "fudge";
1569 const char *value
= "sanford and sun";
1571 rc
= memcached_set(memc
, key
, strlen(key
),
1572 value
, strlen(value
),
1573 (time_t)10, (uint32_t)3);
1574 test_true_got(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
, memcached_strerror(NULL
, rc
));
1575 memcached_quit(memc
);
1577 rc
= memcached_set(memc
, key
, strlen(key
),
1578 value
, strlen(value
),
1579 (time_t)50, (uint32_t)9);
1580 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
1582 return TEST_SUCCESS
;
1585 static test_return_t
mget_result_test(memcached_st
*memc
)
1587 const char *keys
[]= {"fudge", "son", "food"};
1588 size_t key_length
[]= {5, 3, 4};
1590 memcached_result_st results_obj
;
1591 memcached_result_st
*results
;
1593 results
= memcached_result_create(memc
, &results_obj
);
1595 test_true(&results_obj
== results
);
1597 /* We need to empty the server before continueing test */
1598 test_compare(MEMCACHED_SUCCESS
,
1599 memcached_flush(memc
, 0));
1601 test_compare(MEMCACHED_SUCCESS
,
1602 memcached_mget(memc
, keys
, key_length
, 3));
1604 memcached_return_t rc
;
1605 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1610 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
))) { test_true(false); /* We should never see a value returned */ };
1611 test_false(results
);
1612 test_compare_got(MEMCACHED_NOTFOUND
, rc
, memcached_strerror(NULL
, rc
));
1614 for (uint32_t x
= 0; x
< 3; x
++)
1616 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1617 keys
[x
], key_length
[x
],
1618 (time_t)50, (uint32_t)9);
1619 test_true_got(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
, memcached_strerror(NULL
, rc
));
1622 test_compare(MEMCACHED_SUCCESS
,
1623 memcached_mget(memc
, keys
, key_length
, 3));
1625 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1628 test_true(&results_obj
== results
);
1629 test_compare(MEMCACHED_SUCCESS
, rc
);
1630 test_memcmp(memcached_result_key_value(results
),
1631 memcached_result_value(results
),
1632 memcached_result_length(results
));
1633 test_compare(memcached_result_key_length(results
), memcached_result_length(results
));
1636 memcached_result_free(&results_obj
);
1638 return TEST_SUCCESS
;
1641 static test_return_t
mget_result_alloc_test(memcached_st
*memc
)
1643 const char *keys
[]= {"fudge", "son", "food"};
1644 size_t key_length
[]= {5, 3, 4};
1646 memcached_result_st
*results
;
1648 /* We need to empty the server before continueing test */
1649 test_compare(MEMCACHED_SUCCESS
,
1650 memcached_flush(memc
, 0));
1652 test_compare(MEMCACHED_SUCCESS
,
1653 memcached_mget(memc
, keys
, key_length
, 3));
1655 memcached_return_t rc
;
1656 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1660 test_false(results
);
1661 test_compare_got(MEMCACHED_NOTFOUND
, rc
, memcached_strerror(NULL
, rc
));
1663 for (uint32_t x
= 0; x
< 3; x
++)
1665 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1666 keys
[x
], key_length
[x
],
1667 (time_t)50, (uint32_t)9);
1668 test_true_got(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
, memcached_strerror(NULL
, rc
));
1671 test_compare(MEMCACHED_SUCCESS
,
1672 memcached_mget(memc
, keys
, key_length
, 3));
1675 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1678 test_compare(MEMCACHED_SUCCESS
, rc
);
1679 test_compare(memcached_result_key_length(results
), memcached_result_length(results
));
1680 test_memcmp(memcached_result_key_value(results
),
1681 memcached_result_value(results
),
1682 memcached_result_length(results
));
1683 memcached_result_free(results
);
1687 return TEST_SUCCESS
;
1690 /* Count the results */
1691 static memcached_return_t
callback_counter(const memcached_st
*, memcached_result_st
*, void *context
)
1693 size_t *counter
= (size_t *)context
;
1695 *counter
= *counter
+ 1;
1697 return MEMCACHED_SUCCESS
;
1700 static test_return_t
mget_result_function(memcached_st
*memc
)
1702 const char *keys
[]= {"fudge", "son", "food"};
1703 size_t key_length
[]= {5, 3, 4};
1705 memcached_execute_fn callbacks
[1];
1707 /* We need to empty the server before continueing test */
1708 test_compare(MEMCACHED_SUCCESS
,
1709 memcached_flush(memc
, 0));
1710 for (uint32_t x
= 0; x
< 3; x
++)
1712 memcached_return_t rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1713 keys
[x
], key_length
[x
],
1714 (time_t)50, (uint32_t)9);
1715 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
1718 test_compare(MEMCACHED_SUCCESS
,
1719 memcached_mget(memc
, keys
, key_length
, 3));
1721 callbacks
[0]= &callback_counter
;
1724 test_compare(MEMCACHED_SUCCESS
,
1725 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
1727 test_compare(size_t(3), counter
);
1729 return TEST_SUCCESS
;
1732 static test_return_t
mget_test(memcached_st
*memc
)
1734 const char *keys
[]= {"fudge", "son", "food"};
1735 size_t key_length
[]= {5, 3, 4};
1737 char return_key
[MEMCACHED_MAX_KEY
];
1738 size_t return_key_length
;
1740 size_t return_value_length
;
1742 /* We need to empty the server before continueing test */
1743 test_compare(MEMCACHED_SUCCESS
,
1744 memcached_flush(memc
, 0));
1746 test_compare(MEMCACHED_SUCCESS
,
1747 memcached_mget(memc
, keys
, key_length
, 3));
1750 memcached_return_t rc
;
1751 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1752 &return_value_length
, &flags
, &rc
)))
1754 test_true(return_value
);
1756 test_false(return_value
);
1757 test_zero(return_value_length
);
1758 test_compare(MEMCACHED_NOTFOUND
, rc
);
1760 for (uint32_t x
= 0; x
< 3; x
++)
1762 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1763 keys
[x
], key_length
[x
],
1764 (time_t)50, (uint32_t)9);
1765 test_true_got(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
, memcached_strerror(NULL
, rc
));
1767 test_compare(MEMCACHED_SUCCESS
,
1768 memcached_mget(memc
, keys
, key_length
, 3));
1771 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1772 &return_value_length
, &flags
, &rc
)))
1774 test_true(return_value
);
1775 test_compare(MEMCACHED_SUCCESS
, rc
);
1776 if (not memc
->_namespace
)
1778 test_compare(return_key_length
, return_value_length
);
1779 test_memcmp(return_value
, return_key
, return_value_length
);
1785 return TEST_SUCCESS
;
1788 static test_return_t
mget_execute(memcached_st
*original_memc
)
1790 test_skip(true, memcached_behavior_get(original_memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
));
1792 memcached_st
*memc
= create_single_instance_memcached(original_memc
, "--BINARY-PROTOCOL");
1795 size_t max_keys
= 20480;
1798 char **keys
= static_cast<char **>(calloc(max_keys
, sizeof(char*)));
1799 size_t *key_length
=static_cast<size_t *>(calloc(max_keys
, sizeof(size_t)));
1801 /* First add all of the items.. */
1802 char blob
[1024] = {0};
1804 for (size_t x
= 0; x
< max_keys
; ++x
)
1808 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%lu", (unsigned long)x
);
1810 test_true(keys
[x
] != NULL
);
1811 uint64_t query_id
= memcached_query_id(memc
);
1812 memcached_return_t rc
= memcached_add(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
1813 test_true_got(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
, memcached_strerror(NULL
, rc
));
1814 test_compare(query_id
+1, memcached_query_id(memc
));
1817 /* Try to get all of them with a large multiget */
1819 memcached_execute_fn callbacks
[]= { &callback_counter
};
1820 test_compare(MEMCACHED_SUCCESS
,
1821 memcached_mget_execute(memc
, (const char**)keys
, key_length
,
1822 max_keys
, callbacks
, &counter
, 1));
1825 uint64_t query_id
= memcached_query_id(memc
);
1826 test_compare(MEMCACHED_SUCCESS
,
1827 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
1828 test_compare(query_id
, memcached_query_id(memc
));
1830 /* Verify that we got all of the items */
1831 test_true(counter
== max_keys
);
1834 /* Release all allocated resources */
1835 for (size_t x
= 0; x
< max_keys
; ++x
)
1842 memcached_free(memc
);
1844 return TEST_SUCCESS
;
1847 #define REGRESSION_BINARY_VS_BLOCK_COUNT 20480
1849 static test_return_t
key_setup(memcached_st
*memc
)
1851 test_skip(TEST_SUCCESS
, pre_binary(memc
));
1853 global_pairs
= pairs_generate(REGRESSION_BINARY_VS_BLOCK_COUNT
, 0);
1855 return TEST_SUCCESS
;
1858 static test_return_t
key_teardown(memcached_st
*memc
)
1861 pairs_free(global_pairs
);
1863 return TEST_SUCCESS
;
1866 static test_return_t
block_add_regression(memcached_st
*memc
)
1868 /* First add all of the items.. */
1869 for (size_t x
= 0; x
< REGRESSION_BINARY_VS_BLOCK_COUNT
; ++x
)
1871 char blob
[1024] = {0};
1873 memcached_return_t rc
= memcached_add_by_key(memc
, "bob", 3, global_pairs
[x
].key
, global_pairs
[x
].key_length
, blob
, sizeof(blob
), 0, 0);
1874 test_true_got(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_SERVER_MEMORY_ALLOCATION_FAILURE
, memcached_strerror(NULL
, rc
));
1877 return TEST_SUCCESS
;
1880 static test_return_t
binary_add_regression(memcached_st
*memc
)
1882 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, true));
1883 test_return_t rc
= block_add_regression(memc
);
1888 static test_return_t
get_stats_keys(memcached_st
*memc
)
1892 memcached_stat_st memc_stat
;
1893 memcached_return_t rc
;
1895 stat_list
= memcached_stat_get_keys(memc
, &memc_stat
, &rc
);
1896 test_compare(MEMCACHED_SUCCESS
, rc
);
1897 for (ptr
= stat_list
; *ptr
; ptr
++)
1902 return TEST_SUCCESS
;
1905 static test_return_t
version_string_test(memcached_st
*)
1907 test_strcmp(LIBMEMCACHED_VERSION_STRING
, memcached_lib_version());
1909 return TEST_SUCCESS
;
1912 static test_return_t
get_stats(memcached_st
*memc
)
1914 memcached_return_t rc
;
1916 memcached_stat_st
*memc_stat
= memcached_stat(memc
, NULL
, &rc
);
1917 test_compare(MEMCACHED_SUCCESS
, rc
);
1918 test_true(memc_stat
);
1920 for (uint32_t x
= 0; x
< memcached_server_count(memc
); x
++)
1922 char **stat_list
= memcached_stat_get_keys(memc
, memc_stat
+x
, &rc
);
1923 test_compare(MEMCACHED_SUCCESS
, rc
);
1924 for (char **ptr
= stat_list
; *ptr
; ptr
++) {};
1929 memcached_stat_free(NULL
, memc_stat
);
1931 return TEST_SUCCESS
;
1934 static test_return_t
add_host_test(memcached_st
*memc
)
1936 char servername
[]= "0.example.com";
1938 memcached_return_t rc
;
1939 memcached_server_st
*servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
1940 test_compare(1U, memcached_server_list_count(servers
));
1942 for (unsigned int x
= 2; x
< 20; x
++)
1944 char buffer
[SMALL_STRING_LEN
];
1946 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
1947 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
1949 test_compare(MEMCACHED_SUCCESS
, rc
);
1950 test_compare(x
, memcached_server_list_count(servers
));
1953 test_compare(MEMCACHED_SUCCESS
, memcached_server_push(memc
, servers
));
1954 test_compare(MEMCACHED_SUCCESS
, memcached_server_push(memc
, servers
));
1956 memcached_server_list_free(servers
);
1958 return TEST_SUCCESS
;
1961 static test_return_t
memcached_fetch_result_NOT_FOUND(memcached_st
*memc
)
1963 memcached_return_t rc
;
1965 const char *key
= "not_found";
1966 size_t key_length
= test_literal_param_size("not_found");
1968 test_compare(MEMCACHED_SUCCESS
,
1969 memcached_mget(memc
, &key
, &key_length
, 1));
1971 memcached_result_st
*result
= memcached_fetch_result(memc
, NULL
, &rc
);
1973 test_compare_got(MEMCACHED_NOTFOUND
, rc
, memcached_strerror(NULL
, rc
));
1975 memcached_result_free(result
);
1977 return TEST_SUCCESS
;
1980 static memcached_return_t
clone_test_callback(memcached_st
*, memcached_st
*)
1982 return MEMCACHED_SUCCESS
;
1985 static memcached_return_t
cleanup_test_callback(memcached_st
*)
1987 return MEMCACHED_SUCCESS
;
1990 static test_return_t
callback_test(memcached_st
*memc
)
1992 /* Test User Data */
1996 memcached_return_t rc
;
1998 test_compare(MEMCACHED_SUCCESS
, memcached_callback_set(memc
, MEMCACHED_CALLBACK_USER_DATA
, &x
));
1999 test_ptr
= (int *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_USER_DATA
, &rc
);
2000 test_true(*test_ptr
== x
);
2003 /* Test Clone Callback */
2005 memcached_clone_fn clone_cb
= (memcached_clone_fn
)clone_test_callback
;
2006 void *clone_cb_ptr
= *(void **)&clone_cb
;
2007 void *temp_function
= NULL
;
2009 test_compare(MEMCACHED_SUCCESS
, memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, clone_cb_ptr
));
2010 memcached_return_t rc
;
2011 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
2012 test_true(temp_function
== clone_cb_ptr
);
2013 test_compare(MEMCACHED_SUCCESS
, rc
);
2016 /* Test Cleanup Callback */
2018 memcached_cleanup_fn cleanup_cb
= (memcached_cleanup_fn
)cleanup_test_callback
;
2019 void *cleanup_cb_ptr
= *(void **)&cleanup_cb
;
2020 void *temp_function
= NULL
;
2021 memcached_return_t rc
;
2023 test_compare(MEMCACHED_SUCCESS
, memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, cleanup_cb_ptr
));
2024 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
2025 test_true(temp_function
== cleanup_cb_ptr
);
2028 return TEST_SUCCESS
;
2031 /* We don't test the behavior itself, we test the switches */
2032 static test_return_t
behavior_test(memcached_st
*memc
)
2034 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 1);
2035 test_compare(true, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
));
2037 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1);
2038 test_compare(true, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
));
2040 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, MEMCACHED_HASH_MD5
);
2041 test_compare(uint64_t(MEMCACHED_HASH_MD5
), memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
));
2043 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
2044 test_zero(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
));
2046 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
2047 test_zero(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
));
2049 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, MEMCACHED_HASH_DEFAULT
);
2050 test_compare(uint64_t(MEMCACHED_HASH_DEFAULT
), memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
));
2052 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, MEMCACHED_HASH_CRC
);
2053 test_compare(uint64_t(MEMCACHED_HASH_CRC
), memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
));
2055 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
));
2057 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
));
2059 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
);
2060 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, value
+1);
2061 test_compare((value
+1), memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
));
2063 return TEST_SUCCESS
;
2066 static test_return_t
MEMCACHED_BEHAVIOR_CORK_test(memcached_st
*memc
)
2068 test_compare(MEMCACHED_DEPRECATED
,
2069 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CORK
, true));
2071 // Platform dependent
2073 bool value
= (bool)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_CORK
);
2077 return TEST_SUCCESS
;
2081 static test_return_t
MEMCACHED_BEHAVIOR_TCP_KEEPALIVE_test(memcached_st
*memc
)
2083 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE
, true);
2084 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_NOT_SUPPORTED
);
2086 bool value
= (bool)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE
);
2088 if (memcached_success(rc
))
2097 return TEST_SUCCESS
;
2101 static test_return_t
MEMCACHED_BEHAVIOR_TCP_KEEPIDLE_test(memcached_st
*memc
)
2103 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_KEEPIDLE
, true);
2104 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_NOT_SUPPORTED
);
2106 bool value
= (bool)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_KEEPIDLE
);
2108 if (memcached_success(rc
))
2117 return TEST_SUCCESS
;
2120 static test_return_t
fetch_all_results(memcached_st
*memc
, unsigned int &keys_returned
, const memcached_return_t expect
)
2122 memcached_return_t rc
;
2123 char return_key
[MEMCACHED_MAX_KEY
];
2124 size_t return_key_length
;
2126 size_t return_value_length
;
2130 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2131 &return_value_length
, &flags
, &rc
)))
2133 test_true(return_value
);
2134 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
2139 if (memcached_success(expect
) and memcached_success(rc
))
2141 return TEST_SUCCESS
;
2143 else if (expect
== rc
)
2145 return TEST_SUCCESS
;
2147 fprintf(stderr
, "\n%s:%u %s(#%u)\n", __FILE__
, __LINE__
, memcached_strerror(NULL
, rc
), keys_returned
);
2149 return TEST_FAILURE
;
2152 /* Test case provided by Cal Haldenbrand */
2153 #define HALDENBRAND_KEY_COUNT 3000U // * 1024576
2154 #define HALDENBRAND_FLAG_KEY 99 // * 1024576
2155 static test_return_t
user_supplied_bug1(memcached_st
*memc
)
2157 /* We just keep looking at the same values over and over */
2160 test_compare(MEMCACHED_SUCCESS
,
2161 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, true));
2162 test_compare(MEMCACHED_SUCCESS
,
2163 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, true));
2167 unsigned long long total
= 0;
2168 for (uint32_t x
= 0 ; total
< 20 * 1024576 ; x
++ )
2170 uint32_t size
= (uint32_t)(rand() % ( 5 * 1024 ) ) + 400;
2171 char randomstuff
[6 * 1024];
2172 memset(randomstuff
, 0, 6 * 1024);
2173 test_true(size
< 6 * 1024); /* Being safe here */
2175 for (uint32_t j
= 0 ; j
< size
;j
++)
2177 randomstuff
[j
] = (signed char) ((rand() % 26) + 97);
2182 int key_length
= snprintf(key
, sizeof(key
), "%u", x
);
2183 test_compare(MEMCACHED_SUCCESS
,
2184 memcached_set(memc
, key
, key_length
, randomstuff
, strlen(randomstuff
), time_t(0), HALDENBRAND_FLAG_KEY
));
2186 test_true(total
> HALDENBRAND_KEY_COUNT
);
2188 return TEST_SUCCESS
;
2191 /* Test case provided by Cal Haldenbrand */
2192 static test_return_t
user_supplied_bug2(memcached_st
*memc
)
2194 test_compare(MEMCACHED_SUCCESS
,
2195 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, true));
2197 test_compare(MEMCACHED_SUCCESS
,
2198 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, true));
2201 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, 20 * 1024576));
2202 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, 20 * 1024576));
2203 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
2204 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
2206 for (x
= 0, errors
= 0; total
< 20 * 1024576 ; x
++)
2209 size_t total_value_length
= 0;
2210 for (uint32_t x
= 0, errors
= 0; total_value_length
< 24576 ; x
++)
2215 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1];
2216 int key_length
= snprintf(key
, sizeof(key
), "%u", x
);
2218 memcached_return_t rc
;
2219 char *getval
= memcached_get(memc
, key
, key_length
, &val_len
, &flags
, &rc
);
2220 if (memcached_failed(rc
))
2222 if (rc
== MEMCACHED_NOTFOUND
)
2233 test_compare(uint32_t(HALDENBRAND_FLAG_KEY
), flags
);
2235 total_value_length
+= val_len
;
2240 return TEST_SUCCESS
;
2243 /* Do a large mget() over all the keys we think exist */
2244 static test_return_t
user_supplied_bug3(memcached_st
*memc
)
2246 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 1));
2247 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1));
2250 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, 20 * 1024576);
2251 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, 20 * 1024576);
2252 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
2253 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
2256 std::vector
<size_t> key_lengths
;
2257 key_lengths
.resize(HALDENBRAND_KEY_COUNT
);
2258 std::vector
<char *> keys
;
2259 keys
.resize(key_lengths
.size());
2260 for (uint32_t x
= 0; x
< key_lengths
.size(); x
++)
2262 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1];
2263 int key_length
= snprintf(key
, sizeof(key
), "%u", x
);
2264 test_true(key_length
> 0 and key_length
< MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1);
2265 keys
[x
]= strdup(key
);
2266 key_lengths
[x
]= key_length
;
2269 test_compare(MEMCACHED_SUCCESS
,
2270 memcached_mget(memc
, &keys
[0], &key_lengths
[0], key_lengths
.size()));
2272 unsigned int keys_returned
;
2273 test_compare(TEST_SUCCESS
, fetch_all_results(memc
, keys_returned
, MEMCACHED_SUCCESS
));
2274 test_compare(HALDENBRAND_KEY_COUNT
, keys_returned
);
2276 for (std::vector
<char *>::iterator iter
= keys
.begin();
2283 return TEST_SUCCESS
;
2286 /* Make sure we behave properly if server list has no values */
2287 static test_return_t
user_supplied_bug4(memcached_st
*memc
)
2289 const char *keys
[]= {"fudge", "son", "food"};
2290 size_t key_length
[]= {5, 3, 4};
2292 /* Here we free everything before running a bunch of mget tests */
2293 memcached_servers_reset(memc
);
2296 /* We need to empty the server before continueing test */
2297 test_compare(MEMCACHED_NO_SERVERS
,
2298 memcached_flush(memc
, 0));
2300 test_compare(MEMCACHED_NO_SERVERS
,
2301 memcached_mget(memc
, keys
, key_length
, 3));
2303 unsigned int keys_returned
;
2304 test_compare(TEST_SUCCESS
, fetch_all_results(memc
, keys_returned
, MEMCACHED_NOTFOUND
));
2305 test_zero(keys_returned
);
2307 for (uint32_t x
= 0; x
< 3; x
++)
2309 test_compare(MEMCACHED_NO_SERVERS
,
2310 memcached_set(memc
, keys
[x
], key_length
[x
],
2311 keys
[x
], key_length
[x
],
2312 (time_t)50, (uint32_t)9));
2315 test_compare(MEMCACHED_NO_SERVERS
,
2316 memcached_mget(memc
, keys
, key_length
, 3));
2320 char return_key
[MEMCACHED_MAX_KEY
];
2321 memcached_return_t rc
;
2322 size_t return_key_length
;
2323 size_t return_value_length
;
2326 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2327 &return_value_length
, &flags
, &rc
)))
2329 test_true(return_value
);
2330 test_compare(MEMCACHED_SUCCESS
, rc
);
2331 test_true(return_key_length
== return_value_length
);
2332 test_memcmp(return_value
, return_key
, return_value_length
);
2338 return TEST_SUCCESS
;
2341 #define VALUE_SIZE_BUG5 1048064
2342 static test_return_t
user_supplied_bug5(memcached_st
*memc
)
2344 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
2345 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
2347 size_t value_length
;
2349 char *insert_data
= new (std::nothrow
) char[VALUE_SIZE_BUG5
];
2351 for (uint32_t x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2353 insert_data
[x
]= (signed char)rand();
2356 test_compare(MEMCACHED_SUCCESS
,
2357 memcached_flush(memc
, 0));
2359 memcached_return_t rc
;
2360 test_null(memcached_get(memc
, keys
[0], key_length
[0], &value_length
, &flags
, &rc
));
2361 test_compare(MEMCACHED_SUCCESS
,
2362 memcached_mget(memc
, keys
, key_length
, 4));
2365 test_compare(TEST_SUCCESS
, fetch_all_results(memc
, count
, MEMCACHED_NOTFOUND
));
2368 for (uint32_t x
= 0; x
< 4; x
++)
2370 test_compare(MEMCACHED_SUCCESS
,
2371 memcached_set(memc
, keys
[x
], key_length
[x
],
2372 insert_data
, VALUE_SIZE_BUG5
,
2373 (time_t)0, (uint32_t)0));
2376 for (uint32_t x
= 0; x
< 10; x
++)
2378 value
= memcached_get(memc
, keys
[0], key_length
[0],
2379 &value_length
, &flags
, &rc
);
2380 test_compare(rc
, MEMCACHED_SUCCESS
);
2384 test_compare(MEMCACHED_SUCCESS
,
2385 memcached_mget(memc
, keys
, key_length
, 4));
2387 test_compare(TEST_SUCCESS
, fetch_all_results(memc
, count
, MEMCACHED_SUCCESS
));
2388 test_compare(4U, count
);
2390 delete [] insert_data
;
2392 return TEST_SUCCESS
;
2395 static test_return_t
user_supplied_bug6(memcached_st
*memc
)
2397 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
2398 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
2399 char return_key
[MEMCACHED_MAX_KEY
];
2400 size_t return_key_length
;
2402 size_t value_length
;
2404 char *insert_data
= new (std::nothrow
) char[VALUE_SIZE_BUG5
];
2406 for (uint32_t x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2408 insert_data
[x
]= (signed char)rand();
2411 test_compare(MEMCACHED_SUCCESS
, memcached_flush(memc
, 0));
2413 test_compare(TEST_SUCCESS
, confirm_keys_dont_exist(memc
, keys
, test_array_length(keys
)));
2415 // We will now confirm that memcached_mget() returns success, but we will
2416 // then check to make sure that no actual keys are returned.
2417 test_compare(MEMCACHED_SUCCESS
,
2418 memcached_mget(memc
, keys
, key_length
, 4));
2420 memcached_return_t rc
;
2422 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2423 &value_length
, &flags
, &rc
)))
2428 test_compare_got(MEMCACHED_NOTFOUND
, rc
, memcached_strerror(NULL
, rc
));
2430 for (uint32_t x
= 0; x
< test_array_length(keys
); x
++)
2432 test_compare(MEMCACHED_SUCCESS
,
2433 memcached_set(memc
, keys
[x
], key_length
[x
],
2434 insert_data
, VALUE_SIZE_BUG5
,
2435 (time_t)0, (uint32_t)0));
2437 test_compare(TEST_SUCCESS
, confirm_keys_exist(memc
, keys
, test_array_length(keys
)));
2439 for (uint32_t x
= 0; x
< 2; x
++)
2441 value
= memcached_get(memc
, keys
[0], key_length
[0],
2442 &value_length
, &flags
, &rc
);
2446 test_compare(MEMCACHED_SUCCESS
,
2447 memcached_mget(memc
, keys
, key_length
, 4));
2448 /* We test for purge of partial complete fetches */
2449 for (count
= 3; count
; count
--)
2451 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2452 &value_length
, &flags
, &rc
);
2453 test_compare(MEMCACHED_SUCCESS
, rc
);
2454 test_memcmp(value
, insert_data
, value_length
);
2455 test_true(value_length
);
2459 delete [] insert_data
;
2461 return TEST_SUCCESS
;
2464 static test_return_t
user_supplied_bug8(memcached_st
*)
2466 memcached_return_t rc
;
2468 memcached_st
*memc_clone
;
2470 memcached_server_st
*servers
;
2471 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";
2473 servers
= memcached_servers_parse(server_list
);
2476 mine
= memcached_create(NULL
);
2477 rc
= memcached_server_push(mine
, servers
);
2478 test_compare(MEMCACHED_SUCCESS
, rc
);
2479 memcached_server_list_free(servers
);
2482 memc_clone
= memcached_clone(NULL
, mine
);
2484 memcached_quit(mine
);
2485 memcached_quit(memc_clone
);
2488 memcached_free(mine
);
2489 memcached_free(memc_clone
);
2491 return TEST_SUCCESS
;
2494 /* Test flag store/retrieve */
2495 static test_return_t
user_supplied_bug7(memcached_st
*memc
)
2497 const char *keys
= "036790384900";
2498 size_t key_length
= strlen(keys
);
2499 char return_key
[MEMCACHED_MAX_KEY
];
2500 size_t return_key_length
;
2502 size_t value_length
;
2504 char *insert_data
= new (std::nothrow
) char[VALUE_SIZE_BUG5
];
2506 for (unsigned int x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2508 insert_data
[x
]= (signed char)rand();
2511 memcached_flush(memc
, 0);
2514 test_compare(MEMCACHED_SUCCESS
, memcached_set(memc
, keys
, key_length
,
2515 insert_data
, VALUE_SIZE_BUG5
,
2518 memcached_return_t rc
;
2520 value
= memcached_get(memc
, keys
, key_length
,
2521 &value_length
, &flags
, &rc
);
2522 test_compare(245U, flags
);
2526 test_compare(MEMCACHED_SUCCESS
, memcached_mget(memc
, &keys
, &key_length
, 1));
2529 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2530 &value_length
, &flags
, &rc
);
2531 test_compare(uint32_t(245), flags
);
2534 delete [] insert_data
;
2537 return TEST_SUCCESS
;
2540 static test_return_t
user_supplied_bug9(memcached_st
*memc
)
2542 const char *keys
[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
2543 size_t key_length
[3];
2547 char return_key
[MEMCACHED_MAX_KEY
];
2548 size_t return_key_length
;
2550 size_t return_value_length
;
2553 key_length
[0]= strlen("UDATA:edevil@sapo.pt");
2554 key_length
[1]= strlen("fudge&*@#");
2555 key_length
[2]= strlen("for^#@&$not");
2558 for (unsigned int x
= 0; x
< 3; x
++)
2560 memcached_return_t rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2561 keys
[x
], key_length
[x
],
2562 (time_t)50, (uint32_t)9);
2563 test_compare(MEMCACHED_SUCCESS
, rc
);
2566 memcached_return_t rc
= memcached_mget(memc
, keys
, key_length
, 3);
2567 test_compare(MEMCACHED_SUCCESS
, rc
);
2569 /* We need to empty the server before continueing test */
2570 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2571 &return_value_length
, &flags
, &rc
)) != NULL
)
2573 test_true(return_value
);
2577 test_compare(3U, count
);
2579 return TEST_SUCCESS
;
2582 /* We are testing with aggressive timeout to get failures */
2583 static test_return_t
user_supplied_bug10(memcached_st
*memc
)
2585 size_t value_length
= 512;
2586 unsigned int set
= 1;
2587 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2589 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2590 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2591 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, uint64_t(0));
2593 std::vector
<char> value
;
2594 value
.reserve(value_length
);
2595 for (uint32_t x
= 0; x
< value_length
; x
++)
2597 value
.push_back(char(x
% 127));
2600 for (unsigned int x
= 1; x
<= 100000; ++x
)
2602 memcached_return_t rc
= memcached_set(mclone
,
2603 test_literal_param("foo"),
2604 &value
[0], value
.size(),
2607 test_true_got((rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_WRITE_FAILURE
or rc
== MEMCACHED_BUFFERED
or rc
== MEMCACHED_TIMEOUT
or rc
== MEMCACHED_CONNECTION_FAILURE
2608 or rc
== MEMCACHED_SERVER_TEMPORARILY_DISABLED
),
2609 memcached_strerror(NULL
, rc
));
2611 if (rc
== MEMCACHED_WRITE_FAILURE
or rc
== MEMCACHED_TIMEOUT
)
2617 memcached_free(mclone
);
2619 return TEST_SUCCESS
;
2623 We are looking failures in the async protocol
2625 static test_return_t
user_supplied_bug11(memcached_st
*memc
)
2627 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2629 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, true);
2630 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, true);
2631 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, size_t(-1));
2633 test_compare(-1, int32_t(memcached_behavior_get(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
)));
2636 std::vector
<char> value
;
2638 for (unsigned int x
= 0; x
< 512; x
++)
2640 value
.push_back(char(x
% 127));
2643 for (unsigned int x
= 1; x
<= 100000; ++x
)
2645 memcached_return_t rc
= memcached_set(mclone
, test_literal_param("foo"), &value
[0], value
.size(), 0, 0);
2649 memcached_free(mclone
);
2651 return TEST_SUCCESS
;
2655 Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
2657 static test_return_t
user_supplied_bug12(memcached_st
*memc
)
2659 memcached_return_t rc
;
2661 size_t value_length
;
2663 uint64_t number_value
;
2665 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2666 &value_length
, &flags
, &rc
);
2668 test_compare(MEMCACHED_NOTFOUND
, rc
);
2670 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2673 /* The binary protocol will set the key if it doesn't exist */
2674 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1)
2676 test_compare(MEMCACHED_SUCCESS
, rc
);
2680 test_compare(MEMCACHED_NOTFOUND
, rc
);
2683 test_compare(MEMCACHED_SUCCESS
,
2684 memcached_set(memc
, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0));
2686 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"), &value_length
, &flags
, &rc
);
2690 test_compare(MEMCACHED_SUCCESS
,
2691 memcached_increment(memc
, "autoincrement", strlen("autoincrement"), 1, &number_value
));
2692 test_compare(2UL, number_value
);
2694 return TEST_SUCCESS
;
2698 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2699 set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
2701 static test_return_t
user_supplied_bug13(memcached_st
*memc
)
2703 char key
[] = "key34567890";
2704 memcached_return_t rc
;
2705 size_t overflowSize
;
2707 char commandFirst
[]= "set key34567890 0 0 ";
2708 char commandLast
[] = " \r\n"; /* first line of command sent to server */
2709 size_t commandLength
;
2712 commandLength
= strlen(commandFirst
) + strlen(commandLast
) + 4; /* 4 is number of characters in size, probably 8196 */
2714 overflowSize
= MEMCACHED_MAX_BUFFER
- commandLength
;
2716 for (testSize
= overflowSize
- 1; testSize
< overflowSize
+ 1; testSize
++)
2718 char *overflow
= new (std::nothrow
) char[testSize
];
2719 test_true(overflow
);
2721 memset(overflow
, 'x', testSize
);
2722 rc
= memcached_set(memc
, key
, strlen(key
),
2723 overflow
, testSize
, 0, 0);
2724 test_compare(MEMCACHED_SUCCESS
, rc
);
2728 return TEST_SUCCESS
;
2733 Test values of many different sizes
2734 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2735 set key34567890 0 0 8169 \r\n
2736 is sent followed by buffer of size 8169, followed by 8169
2738 static test_return_t
user_supplied_bug14(memcached_st
*memc
)
2740 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, true);
2742 std::vector
<char> value
;
2743 value
.reserve(18000);
2744 for (size_t x
= 0; x
< 18000; x
++)
2746 value
.push_back((char) (x
% 127));
2749 for (size_t current_length
= 0; current_length
< value
.size(); current_length
++)
2751 memcached_return_t rc
= memcached_set(memc
, test_literal_param("foo"),
2752 &value
[0], current_length
,
2753 (time_t)0, (uint32_t)0);
2754 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
2756 size_t string_length
;
2758 char *string
= memcached_get(memc
, test_literal_param("foo"),
2759 &string_length
, &flags
, &rc
);
2761 test_compare(MEMCACHED_SUCCESS
, rc
);
2762 test_compare(string_length
, current_length
);
2763 test_memcmp(string
, &value
[0], string_length
);
2768 return TEST_SUCCESS
;
2772 Look for zero length value problems
2774 static test_return_t
user_supplied_bug15(memcached_st
*memc
)
2776 for (uint32_t x
= 0; x
< 2; x
++)
2778 memcached_return_t rc
= memcached_set(memc
, test_literal_param("mykey"),
2780 (time_t)0, (uint32_t)0);
2782 test_compare(MEMCACHED_SUCCESS
, rc
);
2786 char *value
= memcached_get(memc
, test_literal_param("mykey"),
2787 &length
, &flags
, &rc
);
2789 test_compare(MEMCACHED_SUCCESS
, rc
);
2794 value
= memcached_get(memc
, test_literal_param("mykey"),
2795 &length
, &flags
, &rc
);
2797 test_compare(MEMCACHED_SUCCESS
, rc
);
2798 test_true(value
== NULL
);
2803 return TEST_SUCCESS
;
2806 /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
2807 static test_return_t
user_supplied_bug16(memcached_st
*memc
)
2809 memcached_return_t rc
= memcached_set(memc
, test_literal_param("mykey"),
2811 (time_t)0, UINT32_MAX
);
2813 test_compare(MEMCACHED_SUCCESS
, rc
);
2817 char *value
= memcached_get(memc
, test_literal_param("mykey"),
2818 &length
, &flags
, &rc
);
2820 test_compare(MEMCACHED_SUCCESS
, rc
);
2821 test_true(value
== NULL
);
2823 test_compare(flags
, UINT32_MAX
);
2825 return TEST_SUCCESS
;
2828 #if !defined(__sun) && !defined(__OpenBSD__)
2829 /* Check the validity of chinese key*/
2830 static test_return_t
user_supplied_bug17(memcached_st
*memc
)
2832 const char *key
= "豆瓣";
2833 const char *value
="我们在炎热抑郁的夏天无法停止豆瓣";
2834 memcached_return_t rc
= memcached_set(memc
, key
, strlen(key
),
2835 value
, strlen(value
),
2838 test_compare(MEMCACHED_SUCCESS
, rc
);
2842 char *value2
= memcached_get(memc
, key
, strlen(key
),
2843 &length
, &flags
, &rc
);
2845 test_true(length
==strlen(value
));
2846 test_compare(MEMCACHED_SUCCESS
, rc
);
2847 test_memcmp(value
, value2
, length
);
2850 return TEST_SUCCESS
;
2858 static test_return_t
user_supplied_bug19(memcached_st
*)
2860 memcached_return_t res
;
2862 memcached_st
*memc
= memcached(test_literal_param("--server=localhost:11311/?100 --server=localhost:11312/?100"));
2864 const memcached_server_st
*server
= memcached_server_by_key(memc
, "a", 1, &res
);
2867 memcached_free(memc
);
2869 return TEST_SUCCESS
;
2872 /* CAS test from Andei */
2873 static test_return_t
user_supplied_bug20(memcached_st
*memc
)
2875 const char *key
= "abc";
2876 size_t key_len
= strlen("abc");
2878 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, true));
2880 test_compare(MEMCACHED_SUCCESS
,
2882 test_literal_param("abc"),
2883 test_literal_param("foobar"),
2884 (time_t)0, (uint32_t)0));
2886 test_compare(MEMCACHED_SUCCESS
,
2887 memcached_mget(memc
, &key
, &key_len
, 1));
2889 memcached_result_st result_obj
;
2890 memcached_result_st
*result
= memcached_result_create(memc
, &result_obj
);
2893 memcached_result_create(memc
, &result_obj
);
2894 memcached_return_t status
;
2895 result
= memcached_fetch_result(memc
, &result_obj
, &status
);
2898 test_compare(MEMCACHED_SUCCESS
, status
);
2900 memcached_result_free(result
);
2902 return TEST_SUCCESS
;
2905 /* Large mget() of missing keys with binary proto
2907 * If many binary quiet commands (such as getq's in an mget) fill the output
2908 * buffer and the server chooses not to respond, memcached_flush hangs. See
2909 * http://lists.tangent.org/pipermail/libmemcached/2009-August/000918.html
2912 /* sighandler_t function that always asserts false */
2913 static void fail(int)
2919 static test_return_t
_user_supplied_bug21(memcached_st
* memc
, size_t key_count
)
2924 return TEST_SKIPPED
;
2926 void (*oldalarm
)(int);
2928 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
2929 test_true(memc_clone
);
2931 /* only binproto uses getq for mget */
2932 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, true));
2934 /* empty the cache to ensure misses (hence non-responses) */
2935 test_compare(MEMCACHED_SUCCESS
, memcached_flush(memc_clone
, 0));
2937 std::vector
<size_t> key_lengths
;
2938 key_lengths
.resize(key_count
);
2939 std::vector
<char *> keys
;
2940 keys
.resize(key_lengths
.size());
2941 for (unsigned int x
= 0; x
< key_lengths
.size(); x
++)
2943 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1];
2944 int key_length
= snprintf(key
, sizeof(key
), "%u", x
);
2945 test_true(key_length
> 0 and key_length
< MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1);
2946 keys
[x
]= strdup(key
);
2947 key_lengths
[x
]= key_length
;
2950 oldalarm
= signal(SIGALRM
, fail
);
2953 test_compare_got(MEMCACHED_SUCCESS
,
2954 memcached_mget(memc_clone
, &keys
[0], &key_lengths
[0], key_count
), memcached_last_error_message(memc_clone
));
2957 signal(SIGALRM
, oldalarm
);
2959 memcached_return_t rc
;
2961 char return_key
[MEMCACHED_MAX_KEY
];
2962 size_t return_key_length
;
2964 size_t return_value_length
;
2965 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2966 &return_value_length
, &flags
, &rc
)))
2968 test_false(return_value
); // There are no keys to fetch, so the value should never be returned
2970 test_compare(MEMCACHED_NOTFOUND
, rc
);
2971 test_zero(return_value_length
);
2972 test_zero(return_key_length
);
2973 test_false(return_key
[0]);
2974 test_false(return_value
);
2976 for (std::vector
<char *>::iterator iter
= keys
.begin();
2983 memcached_free(memc_clone
);
2985 return TEST_SUCCESS
;
2989 static test_return_t
user_supplied_bug21(memcached_st
*memc
)
2991 test_skip(TEST_SUCCESS
, pre_binary(memc
));
2993 /* should work as of r580 */
2994 test_compare(TEST_SUCCESS
,
2995 _user_supplied_bug21(memc
, 10));
2997 /* should fail as of r580 */
2998 test_compare(TEST_SUCCESS
,
2999 _user_supplied_bug21(memc
, 1000));
3001 return TEST_SUCCESS
;
3004 static test_return_t
output_ketama_weighted_keys(memcached_st
*)
3006 memcached_st
*memc
= memcached_create(NULL
);
3010 test_compare(MEMCACHED_SUCCESS
,
3011 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, true));
3013 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
3014 test_compare(value
, uint64_t(1));
3016 test_compare(MEMCACHED_SUCCESS
,
3017 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
));
3019 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
3020 test_true(value
== MEMCACHED_HASH_MD5
);
3023 test_true(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
) == MEMCACHED_SUCCESS
);
3025 memcached_server_st
*server_pool
;
3026 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");
3027 memcached_server_push(memc
, server_pool
);
3029 // @todo this needs to be refactored to actually test something.
3032 if ((fp
= fopen("ketama_keys.txt", "w")))
3036 printf("cannot write to file ketama_keys.txt");
3037 return TEST_FAILURE
;
3040 for (int x
= 0; x
< 10000; x
++)
3043 snprintf(key
, sizeof(key
), "%d", x
);
3045 uint32_t server_idx
= memcached_generate_hash(memc
, key
, strlen(key
));
3046 char *hostname
= memc
->hosts
[server_idx
].hostname
;
3047 in_port_t port
= memc
->hosts
[server_idx
].port
;
3048 fprintf(fp
, "key %s is on host /%s:%u\n", key
, hostname
, port
);
3049 memcached_server_instance_st instance
=
3050 memcached_server_instance_by_position(memc
, host_index
);
3054 memcached_server_list_free(server_pool
);
3055 memcached_free(memc
);
3057 return TEST_SUCCESS
;
3061 static test_return_t
result_static(memcached_st
*memc
)
3063 memcached_result_st result
;
3064 memcached_result_st
*result_ptr
= memcached_result_create(memc
, &result
);
3065 test_false(result
.options
.is_allocated
);
3066 test_true(memcached_is_initialized(&result
));
3067 test_true(result_ptr
);
3068 test_true(result_ptr
== &result
);
3070 memcached_result_free(&result
);
3072 test_false(result
.options
.is_allocated
);
3073 test_false(memcached_is_initialized(&result
));
3075 return TEST_SUCCESS
;
3078 static test_return_t
result_alloc(memcached_st
*memc
)
3080 memcached_result_st
*result_ptr
= memcached_result_create(memc
, NULL
);
3081 test_true(result_ptr
);
3082 test_true(result_ptr
->options
.is_allocated
);
3083 test_true(memcached_is_initialized(result_ptr
));
3084 memcached_result_free(result_ptr
);
3086 return TEST_SUCCESS
;
3089 static test_return_t
cleanup_pairs(memcached_st
*memc
)
3092 pairs_free(global_pairs
);
3094 return TEST_SUCCESS
;
3097 static test_return_t
generate_pairs(memcached_st
*)
3099 global_pairs
= pairs_generate(GLOBAL_COUNT
, 400);
3100 global_count
= GLOBAL_COUNT
;
3102 for (size_t x
= 0; x
< global_count
; x
++)
3104 global_keys
[x
]= global_pairs
[x
].key
;
3105 global_keys_length
[x
]= global_pairs
[x
].key_length
;
3108 return TEST_SUCCESS
;
3111 static test_return_t
generate_large_pairs(memcached_st
*)
3113 global_pairs
= pairs_generate(GLOBAL2_COUNT
, MEMCACHED_MAX_BUFFER
+10);
3114 global_count
= GLOBAL2_COUNT
;
3116 for (size_t x
= 0; x
< global_count
; x
++)
3118 global_keys
[x
]= global_pairs
[x
].key
;
3119 global_keys_length
[x
]= global_pairs
[x
].key_length
;
3122 return TEST_SUCCESS
;
3125 static test_return_t
generate_data(memcached_st
*memc
)
3127 unsigned int check_execute
= execute_set(memc
, global_pairs
, global_count
);
3129 test_compare(check_execute
, global_count
);
3131 return TEST_SUCCESS
;
3134 static test_return_t
generate_data_with_stats(memcached_st
*memc
)
3136 unsigned int check_execute
= execute_set(memc
, global_pairs
, global_count
);
3138 test_compare(check_execute
, global_count
);
3140 // @todo hosts used size stats
3141 memcached_return_t rc
;
3142 memcached_stat_st
*stat_p
= memcached_stat(memc
, NULL
, &rc
);
3145 for (uint32_t host_index
= 0; host_index
< SERVERS_TO_CREATE
; host_index
++)
3147 /* This test was changes so that "make test" would work properlly */
3150 memcached_server_instance_st instance
=
3151 memcached_server_instance_by_position(memc
, host_index
);
3153 printf("\nserver %u|%s|%u bytes: %llu\n", host_index
, instance
->hostname
, instance
->port
, (unsigned long long)(stat_p
+ host_index
)->bytes
);
3155 test_true((unsigned long long)(stat_p
+ host_index
)->bytes
);
3158 memcached_stat_free(NULL
, stat_p
);
3160 return TEST_SUCCESS
;
3162 static test_return_t
generate_buffer_data(memcached_st
*memc
)
3164 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, true);
3165 generate_data(memc
);
3167 return TEST_SUCCESS
;
3170 static test_return_t
get_read_count(memcached_st
*memc
)
3172 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
3173 test_true(memc_clone
);
3175 memcached_server_add_with_weight(memc_clone
, "localhost", 6666, 0);
3179 size_t return_value_length
;
3183 for (size_t x
= count
= 0; x
< global_count
; x
++)
3185 memcached_return_t rc
;
3186 return_value
= memcached_get(memc_clone
, global_keys
[x
], global_keys_length
[x
],
3187 &return_value_length
, &flags
, &rc
);
3188 if (rc
== MEMCACHED_SUCCESS
)
3199 memcached_free(memc_clone
);
3201 return TEST_SUCCESS
;
3204 static test_return_t
get_read(memcached_st
*memc
)
3206 for (size_t x
= 0; x
< global_count
; x
++)
3208 size_t return_value_length
;
3210 memcached_return_t rc
;
3211 char *return_value
= memcached_get(memc
, global_keys
[x
], global_keys_length
[x
],
3212 &return_value_length
, &flags
, &rc
);
3214 test_true(return_value);
3215 test_compare(MEMCACHED_SUCCESS, rc);
3217 if (rc
== MEMCACHED_SUCCESS
&& return_value
)
3223 return TEST_SUCCESS
;
3226 static test_return_t
mget_read(memcached_st
*memc
)
3229 test_skip(true, bool(libmemcached_util_version_check(memc
, 1, 4, 4)));
3231 test_compare(MEMCACHED_SUCCESS
,
3232 memcached_mget(memc
, global_keys
, global_keys_length
, global_count
));
3234 // Go fetch the keys and test to see if all of them were returned
3236 unsigned int keys_returned
;
3237 test_compare(TEST_SUCCESS
, fetch_all_results(memc
, keys_returned
, MEMCACHED_SUCCESS
));
3238 test_true(keys_returned
> 0);
3239 test_compare_warn_hint(global_count
, keys_returned
, "Possible false, positive, memcached may have ejected key/value based on memory needs");
3242 return TEST_SUCCESS
;
3245 static test_return_t
mget_read_result(memcached_st
*memc
)
3248 test_skip(true, bool(libmemcached_util_version_check(memc
, 1, 4, 4)));
3250 test_compare(MEMCACHED_SUCCESS
,
3251 memcached_mget(memc
, global_keys
, global_keys_length
, global_count
));
3253 /* Turn this into a help function */
3255 memcached_result_st results_obj
;
3256 memcached_result_st
*results
= memcached_result_create(memc
, &results_obj
);
3259 memcached_return_t rc
;
3260 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
3262 if (rc
== MEMCACHED_IN_PROGRESS
)
3268 test_compare(MEMCACHED_SUCCESS
, rc
);
3270 test_compare(MEMCACHED_END
, rc
);
3272 memcached_result_free(&results_obj
);
3275 return TEST_SUCCESS
;
3278 static test_return_t
mget_read_internal_result(memcached_st
*memc
)
3281 test_skip(true, bool(libmemcached_util_version_check(memc
, 1, 4, 4)));
3283 test_compare(MEMCACHED_SUCCESS
,
3284 memcached_mget(memc
, global_keys
, global_keys_length
, global_count
));
3286 memcached_result_st
*results
= NULL
;
3287 memcached_return_t rc
;
3288 while ((results
= memcached_fetch_result(memc
, results
, &rc
)))
3291 test_compare(MEMCACHED_SUCCESS
, rc
);
3293 test_compare(MEMCACHED_END
, rc
);
3295 memcached_result_free(results
);
3298 return TEST_SUCCESS
;
3301 static test_return_t
mget_read_partial_result(memcached_st
*memc
)
3304 test_skip(true, bool(libmemcached_util_version_check(memc
, 1, 4, 4)));
3306 test_compare(MEMCACHED_SUCCESS
,
3307 memcached_mget(memc
, global_keys
, global_keys_length
, global_count
));
3309 // We will scan for just one key
3311 memcached_result_st results_obj
;
3312 memcached_result_st
*results
= memcached_result_create(memc
, &results_obj
);
3314 memcached_return_t rc
;
3315 results
= memcached_fetch_result(memc
, results
, &rc
);
3317 test_compare(MEMCACHED_SUCCESS
, rc
);
3319 memcached_result_free(&results_obj
);
3322 // We already have a read happening, lets start up another one.
3323 test_compare(MEMCACHED_SUCCESS
,
3324 memcached_mget(memc
, global_keys
, global_keys_length
, global_count
));
3326 memcached_result_st results_obj
;
3327 memcached_result_st
*results
= memcached_result_create(memc
, &results_obj
);
3329 test_false(memcached_is_allocated(results
));
3331 memcached_return_t rc
;
3332 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
3335 test_compare(MEMCACHED_SUCCESS
, rc
);
3337 test_compare(MEMCACHED_END
, rc
);
3339 memcached_result_free(&results_obj
);
3342 return TEST_SUCCESS
;
3345 static test_return_t
mget_read_function(memcached_st
*memc
)
3347 test_skip(true, bool(libmemcached_util_version_check(memc
, 1, 4, 4)));
3349 test_compare(MEMCACHED_SUCCESS
,
3350 memcached_mget(memc
, global_keys
, global_keys_length
, global_count
));
3352 memcached_execute_fn callbacks
[]= { &callback_counter
};
3354 test_compare(MEMCACHED_SUCCESS
,
3355 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
3357 return TEST_SUCCESS
;
3360 static test_return_t
delete_generate(memcached_st
*memc
)
3362 for (size_t x
= 0; x
< global_count
; x
++)
3364 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3367 return TEST_SUCCESS
;
3370 static test_return_t
delete_buffer_generate(memcached_st
*memc
)
3372 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, true);
3374 for (size_t x
= 0; x
< global_count
; x
++)
3376 (void)memcached_delete(memc
, global_keys
[x
], global_keys_length
[x
], (time_t)0);
3379 return TEST_SUCCESS
;
3382 static test_return_t
add_host_test1(memcached_st
*memc
)
3384 memcached_return_t rc
;
3385 char servername
[]= "0.example.com";
3387 memcached_server_st
*servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
3389 test_compare(1U, memcached_server_list_count(servers
));
3391 for (uint32_t x
= 2; x
< 20; x
++)
3393 char buffer
[SMALL_STRING_LEN
];
3395 snprintf(buffer
, SMALL_STRING_LEN
, "%lu.example.com", (unsigned long)(400 +x
));
3396 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
3398 test_compare(MEMCACHED_SUCCESS
, rc
);
3399 test_compare(x
, memcached_server_list_count(servers
));
3402 test_compare(MEMCACHED_SUCCESS
, memcached_server_push(memc
, servers
));
3403 test_compare(MEMCACHED_SUCCESS
, memcached_server_push(memc
, servers
));
3405 memcached_server_list_free(servers
);
3407 return TEST_SUCCESS
;
3410 static test_return_t
pre_nonblock(memcached_st
*memc
)
3412 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3414 return TEST_SUCCESS
;
3417 static test_return_t
pre_cork(memcached_st
*memc
)
3420 return TEST_SKIPPED
;
3423 if (memcached_success(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CORK
, set
)))
3424 return TEST_SUCCESS
;
3426 return TEST_SKIPPED
;
3429 static test_return_t
pre_cork_and_nonblock(memcached_st
*memc
)
3432 return TEST_SKIPPED
;
3434 test_return_t test_rc
;
3435 if ((test_rc
= pre_cork(memc
)) != TEST_SUCCESS
)
3438 return pre_nonblock(memc
);
3441 static test_return_t
pre_nonblock_binary(memcached_st
*memc
)
3443 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
3444 test_true(memc_clone
);
3446 // The memcached_version needs to be done on a clone, because the server
3447 // will not toggle protocol on an connection.
3448 memcached_version(memc_clone
);
3450 memcached_return_t rc
= MEMCACHED_FAILURE
;
3451 if (libmemcached_util_version_check(memc_clone
, 1, 4, 4))
3453 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3454 test_compare(MEMCACHED_SUCCESS
,
3455 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1));
3456 test_compare(uint64_t(1), memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
));
3460 memcached_free(memc_clone
);
3461 return TEST_SKIPPED
;
3464 memcached_free(memc_clone
);
3466 return rc
== MEMCACHED_SUCCESS
? TEST_SUCCESS
: TEST_SKIPPED
;
3469 static test_return_t
pre_murmur(memcached_st
*memc
)
3471 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
));
3472 return TEST_SUCCESS
;
3475 static test_return_t
pre_jenkins(memcached_st
*memc
)
3477 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_JENKINS
);
3479 return TEST_SKIPPED
;
3483 static test_return_t
pre_md5(memcached_st
*memc
)
3485 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MD5
);
3487 return TEST_SUCCESS
;
3490 static test_return_t
pre_crc(memcached_st
*memc
)
3492 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_CRC
);
3494 return TEST_SUCCESS
;
3497 static test_return_t
pre_hsieh(memcached_st
*memc
)
3499 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_HSIEH
));
3500 return TEST_SUCCESS
;
3503 static test_return_t
pre_hash_fnv1_64(memcached_st
*memc
)
3505 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
));
3507 return TEST_SUCCESS
;
3510 static test_return_t
pre_hash_fnv1a_64(memcached_st
*memc
)
3512 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_64
));
3514 return TEST_SUCCESS
;
3517 static test_return_t
pre_hash_fnv1_32(memcached_st
*memc
)
3519 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1_32
);
3521 return TEST_SUCCESS
;
3524 static test_return_t
pre_hash_fnv1a_32(memcached_st
*memc
)
3526 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_FNV1A_32
);
3528 return TEST_SUCCESS
;
3531 static test_return_t
pre_behavior_ketama(memcached_st
*memc
)
3533 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA
, 1);
3534 test_compare(MEMCACHED_SUCCESS
, rc
);
3536 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA
);
3537 test_compare(value
, uint64_t(1));
3539 return TEST_SUCCESS
;
3542 static test_return_t
pre_behavior_ketama_weighted(memcached_st
*memc
)
3544 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, 1);
3545 test_compare(MEMCACHED_SUCCESS
, rc
);
3547 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
3548 test_compare(value
, uint64_t(1));
3550 test_compare(MEMCACHED_SUCCESS
,
3551 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
));
3553 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
3554 test_compare(MEMCACHED_HASH_MD5
, memcached_hash_t(value
));
3556 return TEST_SUCCESS
;
3559 static test_return_t
pre_replication(memcached_st
*memc
)
3561 test_skip(TEST_SUCCESS
, pre_binary(memc
));
3564 * Make sure that we store the item on all servers
3565 * (master + replicas == number of servers)
3567 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, memcached_server_count(memc
) - 1));
3568 test_compare(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
), uint64_t(memcached_server_count(memc
) - 1));
3570 return TEST_SUCCESS
;
3574 static test_return_t
pre_replication_noblock(memcached_st
*memc
)
3576 test_skip(TEST_SUCCESS
, pre_replication(memc
));
3578 return pre_nonblock(memc
);
3582 static void my_free(const memcached_st
*ptr
, void *mem
, void *context
)
3586 #ifdef HARD_MALLOC_TESTS
3587 void *real_ptr
= (mem
== NULL
) ? mem
: (void*)((caddr_t
)mem
- 8);
3595 static void *my_malloc(const memcached_st
*ptr
, const size_t size
, void *context
)
3599 #ifdef HARD_MALLOC_TESTS
3600 void *ret
= malloc(size
+ 8);
3603 ret
= (void*)((caddr_t
)ret
+ 8);
3606 void *ret
= malloc(size
);
3611 memset(ret
, 0xff, size
);
3618 static void *my_realloc(const memcached_st
*ptr
, void *mem
, const size_t size
, void *)
3620 #ifdef HARD_MALLOC_TESTS
3621 void *real_ptr
= (mem
== NULL
) ? NULL
: (void*)((caddr_t
)mem
- 8);
3622 void *nmem
= realloc(real_ptr
, size
+ 8);
3627 ret
= (void*)((caddr_t
)nmem
+ 8);
3633 return realloc(mem
, size
);
3638 static void *my_calloc(const memcached_st
*ptr
, size_t nelem
, const size_t size
, void *)
3640 #ifdef HARD_MALLOC_TESTS
3641 void *mem
= my_malloc(ptr
, nelem
* size
);
3644 memset(mem
, 0, nelem
* size
);
3650 return calloc(nelem
, size
);
3654 static test_return_t
selection_of_namespace_tests(memcached_st
*memc
)
3656 memcached_return_t rc
;
3657 const char *key
= "mine";
3660 /* Make sure be default none exists */
3661 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
3663 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
3665 /* Test a clean set */
3666 test_compare(MEMCACHED_SUCCESS
,
3667 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, (void *)key
));
3669 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
3671 test_memcmp(value
, key
, 4);
3672 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
3674 /* Test that we can turn it off */
3675 test_compare(MEMCACHED_SUCCESS
,
3676 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, NULL
));
3678 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
3680 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
3682 /* Now setup for main test */
3683 test_compare(MEMCACHED_SUCCESS
,
3684 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, (void *)key
));
3686 value
= (char *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
3688 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
3689 test_memcmp(value
, key
, 4);
3691 /* Set to Zero, and then Set to something too large */
3694 memset(long_key
, 0, 255);
3696 test_compare(MEMCACHED_SUCCESS
,
3697 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, NULL
));
3699 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
3701 test_compare(MEMCACHED_SUCCESS
, rc
);
3703 /* Test a long key for failure */
3704 /* TODO, extend test to determine based on setting, what result should be */
3705 strncpy(long_key
, "Thisismorethentheallottednumberofcharacters", sizeof(long_key
));
3706 test_compare(MEMCACHED_SUCCESS
,
3707 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, long_key
));
3709 /* Now test a key with spaces (which will fail from long key, since bad key is not set) */
3710 strncpy(long_key
, "This is more then the allotted number of characters", sizeof(long_key
));
3711 test_compare(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) ? MEMCACHED_SUCCESS
: MEMCACHED_BAD_KEY_PROVIDED
,
3712 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, long_key
));
3714 /* Test for a bad prefix, but with a short key */
3715 test_compare(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) ? MEMCACHED_INVALID_ARGUMENTS
: MEMCACHED_SUCCESS
,
3716 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, 1));
3718 test_compare(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) ? MEMCACHED_SUCCESS
: MEMCACHED_BAD_KEY_PROVIDED
,
3719 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, "dog cat"));
3722 return TEST_SUCCESS
;
3725 static test_return_t
set_namespace(memcached_st
*memc
)
3727 memcached_return_t rc
;
3728 const char *key
= "mine";
3731 // Make sure we default to a null namespace
3732 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
3734 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
3736 /* Test a clean set */
3737 test_compare(MEMCACHED_SUCCESS
,
3738 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, (void *)key
));
3740 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
3742 test_memcmp(value
, key
, 4);
3743 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
3745 return TEST_SUCCESS
;
3748 static test_return_t
set_namespace_and_binary(memcached_st
*memc
)
3750 test_return_if(pre_binary(memc
));
3751 test_return_if(set_namespace(memc
));
3753 return TEST_SUCCESS
;
3756 #ifdef MEMCACHED_ENABLE_DEPRECATED
3757 static test_return_t
deprecated_set_memory_alloc(memcached_st
*memc
)
3759 void *test_ptr
= NULL
;
3762 memcached_malloc_fn malloc_cb
=
3763 (memcached_malloc_fn
)my_malloc
;
3764 cb_ptr
= *(void **)&malloc_cb
;
3765 memcached_return_t rc
;
3767 test_compare(MEMCACHED_SUCCESS
,
3768 memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, cb_ptr
));
3769 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
3770 test_compare(MEMCACHED_SUCCESS
, rc
);
3771 test_true(test_ptr
== cb_ptr
);
3775 memcached_realloc_fn realloc_cb
=
3776 (memcached_realloc_fn
)my_realloc
;
3777 cb_ptr
= *(void **)&realloc_cb
;
3778 memcached_return_t rc
;
3780 test_compare(MEMCACHED_SUCCESS
,
3781 memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, cb_ptr
));
3782 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
3783 test_compare(MEMCACHED_SUCCESS
, rc
);
3784 test_true(test_ptr
== cb_ptr
);
3788 memcached_free_fn free_cb
=
3789 (memcached_free_fn
)my_free
;
3790 cb_ptr
= *(void **)&free_cb
;
3791 memcached_return_t rc
;
3793 test_compare(MEMCACHED_SUCCESS
,
3794 memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, cb_ptr
));
3795 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
3796 test_compare(MEMCACHED_SUCCESS
, rc
);
3797 test_true(test_ptr
== cb_ptr
);
3800 return TEST_SUCCESS
;
3805 static test_return_t
set_memory_alloc(memcached_st
*memc
)
3807 test_compare(MEMCACHED_INVALID_ARGUMENTS
,
3808 memcached_set_memory_allocators(memc
, NULL
, my_free
,
3809 my_realloc
, my_calloc
, NULL
));
3811 test_compare(MEMCACHED_SUCCESS
,
3812 memcached_set_memory_allocators(memc
, my_malloc
, my_free
,
3813 my_realloc
, my_calloc
, NULL
));
3815 memcached_malloc_fn mem_malloc
;
3816 memcached_free_fn mem_free
;
3817 memcached_realloc_fn mem_realloc
;
3818 memcached_calloc_fn mem_calloc
;
3819 memcached_get_memory_allocators(memc
, &mem_malloc
, &mem_free
,
3820 &mem_realloc
, &mem_calloc
);
3822 test_true(mem_malloc
== my_malloc
);
3823 test_true(mem_realloc
== my_realloc
);
3824 test_true(mem_calloc
== my_calloc
);
3825 test_true(mem_free
== my_free
);
3827 return TEST_SUCCESS
;
3830 static test_return_t
enable_consistent_crc(memcached_st
*memc
)
3833 memcached_server_distribution_t value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
3834 memcached_hash_t hash
;
3835 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
3836 if ((rc
= pre_crc(memc
)) != TEST_SUCCESS
)
3839 value
= (memcached_server_distribution_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
3840 test_true(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
3842 hash
= (memcached_hash_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
3844 if (hash
!= MEMCACHED_HASH_CRC
)
3845 return TEST_SKIPPED
;
3847 return TEST_SUCCESS
;
3850 static test_return_t
enable_consistent_hsieh(memcached_st
*memc
)
3853 memcached_server_distribution_t value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
3854 memcached_hash_t hash
;
3855 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, value
);
3856 if ((rc
= pre_hsieh(memc
)) != TEST_SUCCESS
)
3861 value
= (memcached_server_distribution_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
3862 test_true(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
3864 hash
= (memcached_hash_t
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
3866 if (hash
!= MEMCACHED_HASH_HSIEH
)
3867 return TEST_SKIPPED
;
3870 return TEST_SUCCESS
;
3873 static test_return_t
enable_cas(memcached_st
*memc
)
3875 unsigned int set
= 1;
3877 if (libmemcached_util_version_check(memc
, 1, 2, 4))
3879 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, set
);
3881 return TEST_SUCCESS
;
3884 return TEST_SKIPPED
;
3887 static test_return_t
check_for_1_2_3(memcached_st
*memc
)
3889 memcached_version(memc
);
3891 memcached_server_instance_st instance
=
3892 memcached_server_instance_by_position(memc
, 0);
3894 if ((instance
->major_version
>= 1 && (instance
->minor_version
== 2 && instance
->micro_version
>= 4))
3895 or instance
->minor_version
> 2)
3897 return TEST_SUCCESS
;
3900 return TEST_SKIPPED
;
3903 static test_return_t
pre_unix_socket(memcached_st
*memc
)
3907 memcached_servers_reset(memc
);
3908 const char *socket_file
= default_socket();
3910 test_skip(0, stat(socket_file
, &buf
));
3912 test_compare(MEMCACHED_SUCCESS
,
3913 memcached_server_add_unix_socket_with_weight(memc
, socket_file
, 0));
3915 return TEST_SUCCESS
;
3918 static test_return_t
pre_nodelay(memcached_st
*memc
)
3920 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
3921 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
3923 return TEST_SUCCESS
;
3926 static test_return_t
pre_settimer(memcached_st
*memc
)
3928 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
3929 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
3931 return TEST_SUCCESS
;
3934 static test_return_t
MEMCACHED_BEHAVIOR_POLL_TIMEOUT_test(memcached_st
*memc
)
3936 const uint64_t timeout
= 100; // Not using, just checking that it sets
3938 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
3940 test_compare(timeout
, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
));
3942 return TEST_SUCCESS
;
3945 static test_return_t
noreply_test(memcached_st
*memc
)
3947 test_compare(MEMCACHED_SUCCESS
,
3948 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1));
3949 test_compare(MEMCACHED_SUCCESS
,
3950 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1));
3951 test_compare(MEMCACHED_SUCCESS
,
3952 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1));
3953 test_compare(1LLU, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NOREPLY
));
3954 test_compare(1LLU, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
));
3955 test_compare(1LLU, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
));
3957 memcached_return_t ret
;
3958 for (int count
= 0; count
< 5; ++count
)
3960 for (size_t x
= 0; x
< 100; ++x
)
3963 int check_length
= (size_t)snprintf(key
, sizeof(key
), "%lu", (unsigned long)x
);
3964 test_false((size_t)check_length
>= sizeof(key
) || check_length
< 0);
3966 size_t len
= (size_t)check_length
;
3971 ret
= memcached_add(memc
, key
, len
, key
, len
, 0, 0);
3974 ret
= memcached_replace(memc
, key
, len
, key
, len
, 0, 0);
3977 ret
= memcached_set(memc
, key
, len
, key
, len
, 0, 0);
3980 ret
= memcached_append(memc
, key
, len
, key
, len
, 0, 0);
3983 ret
= memcached_prepend(memc
, key
, len
, key
, len
, 0, 0);
3989 test_true_got(ret
== MEMCACHED_SUCCESS
or ret
== MEMCACHED_BUFFERED
, memcached_strerror(NULL
, ret
));
3993 ** NOTE: Don't ever do this in your code! this is not a supported use of the
3994 ** API and is _ONLY_ done this way to verify that the library works the
3995 ** way it is supposed to do!!!!
3998 for (uint32_t x
= 0; x
< memcached_server_count(memc
); ++x
)
4000 memcached_server_instance_st instance
=
4001 memcached_server_instance_by_position(memc
, x
);
4002 no_msg
+=(int)(instance
->cursor_active
);
4005 test_true(no_msg
== 0);
4006 test_compare(MEMCACHED_SUCCESS
, memcached_flush_buffers(memc
));
4009 ** Now validate that all items was set properly!
4011 for (size_t x
= 0; x
< 100; ++x
)
4015 int check_length
= (size_t)snprintf(key
, sizeof(key
), "%lu", (unsigned long)x
);
4017 test_false((size_t)check_length
>= sizeof(key
) || check_length
< 0);
4019 size_t len
= (size_t)check_length
;
4022 char* value
=memcached_get(memc
, key
, strlen(key
),
4023 &length
, &flags
, &ret
);
4024 test_true_got(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
, memcached_strerror(NULL
, ret
));
4027 case 0: /* FALLTHROUGH */
4028 case 1: /* FALLTHROUGH */
4030 test_true(strncmp(value
, key
, len
) == 0);
4031 test_true(len
== length
);
4034 test_true(length
== len
* 2);
4037 test_true(length
== len
* 3);
4047 /* Try setting an illegal cas value (should not return an error to
4048 * the caller (because we don't expect a return message from the server)
4050 const char* keys
[]= {"0"};
4051 size_t lengths
[]= {1};
4054 memcached_result_st results_obj
;
4055 memcached_result_st
*results
;
4056 test_compare(MEMCACHED_SUCCESS
,
4057 memcached_mget(memc
, keys
, lengths
, 1));
4059 results
= memcached_result_create(memc
, &results_obj
);
4061 results
= memcached_fetch_result(memc
, &results_obj
, &ret
);
4063 test_compare(MEMCACHED_SUCCESS
, ret
);
4064 uint64_t cas
= memcached_result_cas(results
);
4065 memcached_result_free(&results_obj
);
4067 test_compare(MEMCACHED_SUCCESS
,
4068 memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
));
4071 * The item will have a new cas value, so try to set it again with the old
4072 * value. This should fail!
4074 test_compare(MEMCACHED_SUCCESS
,
4075 memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
));
4076 test_true(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
4077 char* value
=memcached_get(memc
, keys
[0], lengths
[0], &length
, &flags
, &ret
);
4078 test_true(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
4081 return TEST_SUCCESS
;
4084 static test_return_t
analyzer_test(memcached_st
*memc
)
4086 memcached_return_t rc
;
4087 memcached_analysis_st
*report
;
4089 memcached_stat_st
*memc_stat
= memcached_stat(memc
, NULL
, &rc
);
4090 test_compare(MEMCACHED_SUCCESS
, rc
);
4091 test_true(memc_stat
);
4093 report
= memcached_analyze(memc
, memc_stat
, &rc
);
4094 test_compare(MEMCACHED_SUCCESS
, rc
);
4098 memcached_stat_free(NULL
, memc_stat
);
4100 return TEST_SUCCESS
;
4103 /* Count the objects */
4105 static test_return_t
dump_test(memcached_st
*memc
)
4107 /* No support for Binary protocol yet */
4108 test_skip(false, memc
->flags
.binary_protocol
);
4110 test_compare(TEST_SUCCESS
, set_test3(memc
));
4112 // confirm_key_count() call dump
4113 size_t counter
= confirm_key_count(memc
);
4115 /* We may have more then 32 if our previous flush has not completed */
4116 test_true(counter
>= 32);
4118 return TEST_SUCCESS
;
4121 static test_return_t
util_version_test(memcached_st
*memc
)
4123 test_compare_hint(MEMCACHED_SUCCESS
, memcached_version(memc
), memcached_last_error_message(memc
));
4124 test_true(libmemcached_util_version_check(memc
, 0, 0, 0));
4126 bool if_successful
= libmemcached_util_version_check(memc
, 9, 9, 9);
4128 // We expect failure
4131 fprintf(stderr
, "\n----------------------------------------------------------------------\n");
4132 fprintf(stderr
, "\nDumping Server Information\n\n");
4133 memcached_server_fn callbacks
[1];
4135 callbacks
[0]= dump_server_information
;
4136 memcached_server_cursor(memc
, callbacks
, (void *)stderr
, 1);
4137 fprintf(stderr
, "\n----------------------------------------------------------------------\n");
4139 test_true(if_successful
== false);
4141 memcached_server_instance_st instance
=
4142 memcached_server_instance_by_position(memc
, 0);
4144 memcached_version(memc
);
4146 // We only use one binary when we test, so this should be just fine.
4147 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, instance
->minor_version
, instance
->micro_version
);
4148 test_true(if_successful
== true);
4150 if (instance
->micro_version
> 0)
4152 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, instance
->minor_version
, (uint8_t)(instance
->micro_version
-1));
4154 else if (instance
->minor_version
> 0)
4156 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, (uint8_t)(instance
->minor_version
- 1), instance
->micro_version
);
4158 else if (instance
->major_version
> 0)
4160 if_successful
= libmemcached_util_version_check(memc
, (uint8_t)(instance
->major_version
-1), instance
->minor_version
, instance
->micro_version
);
4163 test_true(if_successful
== true);
4165 if (instance
->micro_version
> 0)
4167 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, instance
->minor_version
, (uint8_t)(instance
->micro_version
+1));
4169 else if (instance
->minor_version
> 0)
4171 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, (uint8_t)(instance
->minor_version
+1), instance
->micro_version
);
4173 else if (instance
->major_version
> 0)
4175 if_successful
= libmemcached_util_version_check(memc
, (uint8_t)(instance
->major_version
+1), instance
->minor_version
, instance
->micro_version
);
4178 test_true(if_successful
== false);
4180 return TEST_SUCCESS
;
4183 static test_return_t
getpid_connection_failure_test(memcached_st
*memc
)
4185 memcached_return_t rc
;
4186 memcached_server_instance_st instance
=
4187 memcached_server_instance_by_position(memc
, 0);
4189 // Test both the version that returns a code, and the one that does not.
4190 test_true(libmemcached_util_getpid(memcached_server_name(instance
),
4191 memcached_server_port(instance
) -1, NULL
) == -1);
4193 test_true(libmemcached_util_getpid(memcached_server_name(instance
),
4194 memcached_server_port(instance
) -1, &rc
) == -1);
4195 test_compare_got(MEMCACHED_CONNECTION_FAILURE
, rc
, memcached_strerror(memc
, rc
));
4197 return TEST_SUCCESS
;
4201 static test_return_t
getpid_test(memcached_st
*memc
)
4203 memcached_return_t rc
;
4204 memcached_server_instance_st instance
=
4205 memcached_server_instance_by_position(memc
, 0);
4207 // Test both the version that returns a code, and the one that does not.
4208 test_true(libmemcached_util_getpid(memcached_server_name(instance
),
4209 memcached_server_port(instance
), NULL
) > -1);
4211 test_true(libmemcached_util_getpid(memcached_server_name(instance
),
4212 memcached_server_port(instance
), &rc
) > -1);
4213 test_compare(MEMCACHED_SUCCESS
, rc
);
4215 return TEST_SUCCESS
;
4218 static test_return_t
ping_test(memcached_st
*memc
)
4220 memcached_return_t rc
;
4221 memcached_server_instance_st instance
=
4222 memcached_server_instance_by_position(memc
, 0);
4224 // Test both the version that returns a code, and the one that does not.
4225 test_true(libmemcached_util_ping(memcached_server_name(instance
),
4226 memcached_server_port(instance
), NULL
));
4228 test_true(libmemcached_util_ping(memcached_server_name(instance
),
4229 memcached_server_port(instance
), &rc
));
4231 test_compare(MEMCACHED_SUCCESS
, rc
);
4233 return TEST_SUCCESS
;
4238 static test_return_t
hash_sanity_test (memcached_st
*memc
)
4242 assert(MEMCACHED_HASH_DEFAULT
== MEMCACHED_HASH_DEFAULT
);
4243 assert(MEMCACHED_HASH_MD5
== MEMCACHED_HASH_MD5
);
4244 assert(MEMCACHED_HASH_CRC
== MEMCACHED_HASH_CRC
);
4245 assert(MEMCACHED_HASH_FNV1_64
== MEMCACHED_HASH_FNV1_64
);
4246 assert(MEMCACHED_HASH_FNV1A_64
== MEMCACHED_HASH_FNV1A_64
);
4247 assert(MEMCACHED_HASH_FNV1_32
== MEMCACHED_HASH_FNV1_32
);
4248 assert(MEMCACHED_HASH_FNV1A_32
== MEMCACHED_HASH_FNV1A_32
);
4249 #ifdef HAVE_HSIEH_HASH
4250 assert(MEMCACHED_HASH_HSIEH
== MEMCACHED_HASH_HSIEH
);
4252 assert(MEMCACHED_HASH_MURMUR
== MEMCACHED_HASH_MURMUR
);
4253 assert(MEMCACHED_HASH_JENKINS
== MEMCACHED_HASH_JENKINS
);
4254 assert(MEMCACHED_HASH_MAX
== MEMCACHED_HASH_MAX
);
4256 return TEST_SUCCESS
;
4260 static test_return_t
hsieh_avaibility_test (memcached_st
*memc
)
4262 test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_HSIEH
));
4264 test_compare(MEMCACHED_SUCCESS
,
4265 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
,
4266 (uint64_t)MEMCACHED_HASH_HSIEH
));
4268 return TEST_SUCCESS
;
4271 static test_return_t
murmur_avaibility_test (memcached_st
*memc
)
4273 test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_MURMUR
));
4275 test_compare(MEMCACHED_SUCCESS
,
4276 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
));
4278 return TEST_SUCCESS
;
4281 static test_return_t
one_at_a_time_run (memcached_st
*)
4286 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4288 test_compare(one_at_a_time_values
[x
],
4289 memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_DEFAULT
));
4292 return TEST_SUCCESS
;
4295 static test_return_t
md5_run (memcached_st
*)
4300 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4302 test_compare(md5_values
[x
],
4303 memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MD5
));
4306 return TEST_SUCCESS
;
4309 static test_return_t
crc_run (memcached_st
*)
4314 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4316 test_compare(crc_values
[x
],
4317 memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_CRC
));
4320 return TEST_SUCCESS
;
4323 static test_return_t
fnv1_64_run (memcached_st
*)
4325 test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_FNV1_64
));
4330 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4332 test_compare(fnv1_64_values
[x
],
4333 memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_64
));
4336 return TEST_SUCCESS
;
4339 static test_return_t
fnv1a_64_run (memcached_st
*)
4341 test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_FNV1A_64
));
4346 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4348 test_compare(fnv1a_64_values
[x
],
4349 memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_64
));
4352 return TEST_SUCCESS
;
4355 static test_return_t
fnv1_32_run (memcached_st
*)
4360 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4362 test_compare(fnv1_32_values
[x
],
4363 memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_32
));
4366 return TEST_SUCCESS
;
4369 static test_return_t
fnv1a_32_run (memcached_st
*)
4374 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4376 test_compare(fnv1a_32_values
[x
],
4377 memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_32
));
4380 return TEST_SUCCESS
;
4383 static test_return_t
hsieh_run (memcached_st
*)
4385 test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_HSIEH
));
4390 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4392 test_compare(hsieh_values
[x
],
4393 memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_HSIEH
));
4396 return TEST_SUCCESS
;
4399 static test_return_t
murmur_run (memcached_st
*)
4401 test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_MURMUR
));
4403 #ifdef WORDS_BIGENDIAN
4404 (void)murmur_values
;
4405 return TEST_SKIPPED
;
4410 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4412 test_compare(murmur_values
[x
],
4413 memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MURMUR
));
4416 return TEST_SUCCESS
;
4420 static test_return_t
jenkins_run (memcached_st
*)
4425 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4427 test_compare(jenkins_values
[x
],
4428 memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_JENKINS
));
4431 return TEST_SUCCESS
;
4434 static uint32_t hash_md5_test_function(const char *string
, size_t string_length
, void *)
4436 return libhashkit_md5(string
, string_length
);
4439 static uint32_t hash_crc_test_function(const char *string
, size_t string_length
, void *)
4441 return libhashkit_crc32(string
, string_length
);
4444 static test_return_t
memcached_get_hashkit_test (memcached_st
*)
4450 memcached_st
*memc
= memcached(test_literal_param("--server=localhost:1 --server=localhost:2 --server=localhost:3 --server=localhost:4 --server=localhost5 --DISTRIBUTION=modula"));
4452 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};
4453 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};
4455 const hashkit_st
*kit
= memcached_get_hashkit(memc
);
4457 hashkit_clone(&new_kit
, kit
);
4458 test_compare(HASHKIT_SUCCESS
, hashkit_set_custom_function(&new_kit
, hash_md5_test_function
, NULL
));
4460 memcached_set_hashkit(memc
, &new_kit
);
4463 Verify Setting the hash.
4465 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4469 hash_val
= hashkit_digest(kit
, *ptr
, strlen(*ptr
));
4470 test_compare_got(md5_values
[x
], hash_val
, *ptr
);
4475 Now check memcached_st.
4477 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4481 hash_val
= memcached_generate_hash(memc
, *ptr
, strlen(*ptr
));
4482 test_compare_got(md5_hosts
[x
], hash_val
, *ptr
);
4485 test_compare(HASHKIT_SUCCESS
, hashkit_set_custom_function(&new_kit
, hash_crc_test_function
, NULL
));
4487 memcached_set_hashkit(memc
, &new_kit
);
4490 Verify Setting the hash.
4492 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4496 hash_val
= hashkit_digest(kit
, *ptr
, strlen(*ptr
));
4497 test_true(crc_values
[x
] == hash_val
);
4500 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
4504 hash_val
= memcached_generate_hash(memc
, *ptr
, strlen(*ptr
));
4505 test_compare(crc_hosts
[x
], hash_val
);
4508 memcached_free(memc
);
4510 return TEST_SUCCESS
;
4514 Test case adapted from John Gorman <johngorman2@gmail.com>
4516 We are testing the error condition when we connect to a server via memcached_get()
4517 but find that the server is not available.
4519 static test_return_t
memcached_get_MEMCACHED_ERRNO(memcached_st
*)
4521 const char *key
= "MemcachedLives";
4524 memcached_return rc
;
4527 memcached_st
*tl_memc_h
= memcached(test_literal_param("--server=localhost:9898 --server=localhost:9899")); // This server should not exist
4529 // See if memcached is reachable.
4530 char *value
= memcached_get(tl_memc_h
, key
, strlen(key
), &len
, &flags
, &rc
);
4534 test_true(memcached_failed(rc
));
4536 memcached_free(tl_memc_h
);
4538 return TEST_SUCCESS
;
4542 We connect to a server which exists, but search for a key that does not exist.
4544 static test_return_t
memcached_get_MEMCACHED_NOTFOUND(memcached_st
*memc
)
4546 const char *key
= "MemcachedKeyNotEXIST";
4549 memcached_return rc
;
4551 // See if memcached is reachable.
4552 char *value
= memcached_get(memc
, key
, strlen(key
), &len
, &flags
, &rc
);
4556 test_compare(MEMCACHED_NOTFOUND
, rc
);
4558 return TEST_SUCCESS
;
4562 Test case adapted from John Gorman <johngorman2@gmail.com>
4564 We are testing the error condition when we connect to a server via memcached_get_by_key()
4565 but find that the server is not available.
4567 static test_return_t
memcached_get_by_key_MEMCACHED_ERRNO(memcached_st
*memc
)
4570 memcached_st
*tl_memc_h
;
4571 memcached_server_st
*servers
;
4573 const char *key
= "MemcachedLives";
4576 memcached_return rc
;
4580 tl_memc_h
= memcached_create(NULL
);
4581 servers
= memcached_servers_parse("localhost:9898,localhost:9899"); // This server should not exist
4582 memcached_server_push(tl_memc_h
, servers
);
4583 memcached_server_list_free(servers
);
4585 // See if memcached is reachable.
4586 value
= memcached_get_by_key(tl_memc_h
, key
, strlen(key
), key
, strlen(key
), &len
, &flags
, &rc
);
4590 test_true(memcached_failed(rc
));
4592 memcached_free(tl_memc_h
);
4594 return TEST_SUCCESS
;
4598 We connect to a server which exists, but search for a key that does not exist.
4600 static test_return_t
memcached_get_by_key_MEMCACHED_NOTFOUND(memcached_st
*memc
)
4602 const char *key
= "MemcachedKeyNotEXIST";
4605 memcached_return rc
;
4608 // See if memcached is reachable.
4609 value
= memcached_get_by_key(memc
, key
, strlen(key
), key
, strlen(key
), &len
, &flags
, &rc
);
4613 test_compare(MEMCACHED_NOTFOUND
, rc
);
4615 return TEST_SUCCESS
;
4618 static test_return_t
regression_bug_434484(memcached_st
*memc
)
4620 test_skip(TEST_SUCCESS
, pre_binary(memc
));
4622 const char *key
= "regression_bug_434484";
4623 size_t keylen
= strlen(key
);
4625 memcached_return_t ret
= memcached_append(memc
, key
, keylen
, key
, keylen
, 0, 0);
4626 test_compare(MEMCACHED_NOTSTORED
, ret
);
4628 size_t size
= 2048 * 1024;
4629 char *data
= (char*)calloc(1, size
);
4631 test_compare(MEMCACHED_E2BIG
,
4632 memcached_set(memc
, key
, keylen
, data
, size
, 0, 0));
4635 return TEST_SUCCESS
;
4638 static test_return_t
regression_bug_434843(memcached_st
*original_memc
)
4640 test_skip(TEST_SUCCESS
, pre_binary(original_memc
));
4642 memcached_return_t rc
;
4644 memcached_execute_fn callbacks
[]= { &callback_counter
};
4647 * I only want to hit only _one_ server so I know the number of requests I'm
4648 * sending in the pipleine to the server. Let's try to do a multiget of
4649 * 1024 (that should satisfy most users don't you think?). Future versions
4650 * will include a mget_execute function call if you need a higher number.
4652 memcached_st
*memc
= create_single_instance_memcached(original_memc
, "--BINARY-PROTOCOL");
4654 const size_t max_keys
= 1024;
4655 char **keys
= (char**)calloc(max_keys
, sizeof(char*));
4656 size_t *key_length
= (size_t *)calloc(max_keys
, sizeof(size_t));
4658 for (size_t x
= 0; x
< max_keys
; ++x
)
4662 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%lu", (unsigned long)x
);
4668 * Run two times.. the first time we should have 100% cache miss,
4669 * and the second time we should have 100% cache hits
4671 for (size_t y
= 0; y
< 2; y
++)
4673 test_compare(MEMCACHED_SUCCESS
,
4674 memcached_mget(memc
, (const char**)keys
, key_length
, max_keys
));
4676 test_compare(y
? MEMCACHED_SUCCESS
: MEMCACHED_NOTFOUND
,
4677 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
4681 /* The first iteration should give me a 100% cache miss. verify that*/
4682 char blob
[1024]= { 0 };
4684 test_false(counter
);
4686 for (size_t x
= 0; x
< max_keys
; ++x
)
4688 rc
= memcached_add(memc
, keys
[x
], key_length
[x
],
4689 blob
, sizeof(blob
), 0, 0);
4690 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4695 /* Verify that we received all of the key/value pairs */
4696 test_compare(counter
, max_keys
);
4700 /* Release allocated resources */
4701 for (size_t x
= 0; x
< max_keys
; ++x
)
4708 memcached_free(memc
);
4710 return TEST_SUCCESS
;
4713 static test_return_t
regression_bug_434843_buffered(memcached_st
*memc
)
4715 memcached_return_t rc
;
4716 rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1);
4717 test_compare(MEMCACHED_SUCCESS
, rc
);
4719 return regression_bug_434843(memc
);
4722 static test_return_t
regression_bug_421108(memcached_st
*memc
)
4724 memcached_return_t rc
;
4725 memcached_stat_st
*memc_stat
= memcached_stat(memc
, NULL
, &rc
);
4726 test_compare(MEMCACHED_SUCCESS
, rc
);
4728 char *bytes_str
= memcached_stat_get_value(memc
, memc_stat
, "bytes", &rc
);
4729 test_compare(MEMCACHED_SUCCESS
, rc
);
4730 test_true(bytes_str
);
4731 char *bytes_read_str
= memcached_stat_get_value(memc
, memc_stat
,
4733 test_compare(MEMCACHED_SUCCESS
, rc
);
4734 test_true(bytes_read_str
);
4736 char *bytes_written_str
= memcached_stat_get_value(memc
, memc_stat
,
4737 "bytes_written", &rc
);
4738 test_compare(MEMCACHED_SUCCESS
, rc
);
4739 test_true(bytes_written_str
);
4741 unsigned long long bytes
= strtoull(bytes_str
, 0, 10);
4742 unsigned long long bytes_read
= strtoull(bytes_read_str
, 0, 10);
4743 unsigned long long bytes_written
= strtoull(bytes_written_str
, 0, 10);
4745 test_true(bytes
!= bytes_read
);
4746 test_true(bytes
!= bytes_written
);
4748 /* Release allocated resources */
4750 free(bytes_read_str
);
4751 free(bytes_written_str
);
4752 memcached_stat_free(NULL
, memc_stat
);
4754 return TEST_SUCCESS
;
4758 * The test case isn't obvious so I should probably document why
4759 * it works the way it does. Bug 442914 was caused by a bug
4760 * in the logic in memcached_purge (it did not handle the case
4761 * where the number of bytes sent was equal to the watermark).
4762 * In this test case, create messages so that we hit that case
4763 * and then disable noreply mode and issue a new command to
4764 * verify that it isn't stuck. If we change the format for the
4765 * delete command or the watermarks, we need to update this
4768 static test_return_t
regression_bug_442914(memcached_st
*memc
)
4770 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1));
4771 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1);
4773 uint32_t number_of_hosts
= memcached_server_count(memc
);
4774 memc
->number_of_hosts
= 1;
4779 for (uint32_t x
= 0; x
< 250; ++x
)
4781 len
= (size_t)snprintf(k
, sizeof(k
), "%0250u", x
);
4782 memcached_return_t rc
= memcached_delete(memc
, k
, len
, 0);
4783 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4786 (void)snprintf(k
, sizeof(k
), "%037u", 251U);
4789 memcached_return_t rc
= memcached_delete(memc
, k
, len
, 0);
4790 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4792 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0));
4793 test_compare(MEMCACHED_NOTFOUND
, memcached_delete(memc
, k
, len
, 0));
4795 memc
->number_of_hosts
= number_of_hosts
;
4797 return TEST_SUCCESS
;
4800 static test_return_t
regression_bug_447342(memcached_st
*memc
)
4802 memcached_server_instance_st instance_one
;
4803 memcached_server_instance_st instance_two
;
4805 if (memcached_server_count(memc
) < 3 or pre_replication(memc
) != TEST_SUCCESS
)
4806 return TEST_SKIPPED
;
4808 test_compare(MEMCACHED_SUCCESS
,
4809 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 2));
4811 const unsigned int max_keys
= 100;
4812 char **keys
= (char**)calloc(max_keys
, sizeof(char*));
4813 size_t *key_length
= (size_t *)calloc(max_keys
, sizeof(size_t));
4815 for (unsigned int x
= 0; x
< max_keys
; ++x
)
4819 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%lu", (unsigned long)x
);
4822 test_compare(MEMCACHED_SUCCESS
,
4823 memcached_set(memc
, k
, key_length
[x
], k
, key_length
[x
], 0, 0));
4827 ** We are using the quiet commands to store the replicas, so we need
4828 ** to ensure that all of them are processed before we can continue.
4829 ** In the test we go directly from storing the object to trying to
4830 ** receive the object from all of the different servers, so we
4831 ** could end up in a race condition (the memcached server hasn't yet
4832 ** processed the quiet command from the replication set when it process
4833 ** the request from the other client (created by the clone)). As a
4834 ** workaround for that we call memcached_quit to send the quit command
4835 ** to the server and wait for the response ;-) If you use the test code
4836 ** as an example for your own code, please note that you shouldn't need
4839 memcached_quit(memc
);
4841 /* Verify that all messages are stored, and we didn't stuff too much
4844 test_compare(MEMCACHED_SUCCESS
,
4845 memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
));
4847 unsigned int counter
= 0;
4848 memcached_execute_fn callbacks
[]= { &callback_counter
};
4849 test_compare(MEMCACHED_SUCCESS
,
4850 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
4852 /* Verify that we received all of the key/value pairs */
4853 test_compare(counter
, max_keys
);
4855 memcached_quit(memc
);
4857 * Don't do the following in your code. I am abusing the internal details
4858 * within the library, and this is not a supported interface.
4859 * This is to verify correct behavior in the library. Fake that two servers
4862 instance_one
= memcached_server_instance_by_position(memc
, 0);
4863 instance_two
= memcached_server_instance_by_position(memc
, 2);
4864 in_port_t port0
= instance_one
->port
;
4865 in_port_t port2
= instance_two
->port
;
4867 ((memcached_server_write_instance_st
)instance_one
)->port
= 0;
4868 ((memcached_server_write_instance_st
)instance_two
)->port
= 0;
4870 test_compare(MEMCACHED_SUCCESS
,
4871 memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
));
4874 test_compare(MEMCACHED_SUCCESS
,
4875 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
4876 test_compare(counter
, (unsigned int)max_keys
);
4878 /* restore the memc handle */
4879 ((memcached_server_write_instance_st
)instance_one
)->port
= port0
;
4880 ((memcached_server_write_instance_st
)instance_two
)->port
= port2
;
4882 memcached_quit(memc
);
4884 /* Remove half of the objects */
4885 for (size_t x
= 0; x
< max_keys
; ++x
)
4889 test_compare(MEMCACHED_SUCCESS
,
4890 memcached_delete(memc
, keys
[x
], key_length
[x
], 0));
4894 memcached_quit(memc
);
4895 ((memcached_server_write_instance_st
)instance_one
)->port
= 0;
4896 ((memcached_server_write_instance_st
)instance_two
)->port
= 0;
4898 /* now retry the command, this time we should have cache misses */
4899 test_compare(MEMCACHED_SUCCESS
,
4900 memcached_mget(memc
, (const char* const *)keys
, key_length
, max_keys
));
4903 test_compare(MEMCACHED_SUCCESS
,
4904 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
4905 test_compare(counter
, (unsigned int)(max_keys
>> 1));
4907 /* Release allocated resources */
4908 for (size_t x
= 0; x
< max_keys
; ++x
)
4915 /* restore the memc handle */
4916 ((memcached_server_write_instance_st
)instance_one
)->port
= port0
;
4917 ((memcached_server_write_instance_st
)instance_two
)->port
= port2
;
4919 return TEST_SUCCESS
;
4922 static test_return_t
regression_bug_463297(memcached_st
*memc
)
4924 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4925 test_true(memc_clone
);
4926 test_true(memcached_version(memc_clone
) == MEMCACHED_SUCCESS
);
4928 memcached_server_instance_st instance
=
4929 memcached_server_instance_by_position(memc_clone
, 0);
4931 if (instance
->major_version
> 1 ||
4932 (instance
->major_version
== 1 &&
4933 instance
->minor_version
> 2))
4935 /* Binary protocol doesn't support deferred delete */
4936 memcached_st
*bin_clone
= memcached_clone(NULL
, memc
);
4937 test_true(bin_clone
);
4938 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(bin_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1));
4939 test_compare(MEMCACHED_INVALID_ARGUMENTS
, memcached_delete(bin_clone
, "foo", 3, 1));
4940 memcached_free(bin_clone
);
4942 memcached_quit(memc_clone
);
4944 /* If we know the server version, deferred delete should fail
4945 * with invalid arguments */
4946 test_compare(MEMCACHED_INVALID_ARGUMENTS
, memcached_delete(memc_clone
, "foo", 3, 1));
4948 /* If we don't know the server version, we should get a protocol error */
4949 memcached_return_t rc
= memcached_delete(memc
, "foo", 3, 1);
4951 /* but there is a bug in some of the memcached servers (1.4) that treats
4952 * the counter as noreply so it doesn't send the proper error message
4954 test_true_got(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
|| rc
== MEMCACHED_INVALID_ARGUMENTS
, memcached_strerror(NULL
, rc
));
4956 /* And buffered mode should be disabled and we should get protocol error */
4957 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1) == MEMCACHED_SUCCESS
);
4958 rc
= memcached_delete(memc
, "foo", 3, 1);
4959 test_true_got(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
|| rc
== MEMCACHED_INVALID_ARGUMENTS
, memcached_strerror(NULL
, rc
));
4961 /* Same goes for noreply... */
4962 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1));
4963 rc
= memcached_delete(memc
, "foo", 3, 1);
4964 test_true_got(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
|| rc
== MEMCACHED_INVALID_ARGUMENTS
, memcached_strerror(NULL
, rc
));
4966 /* but a normal request should go through (and be buffered) */
4967 test_compare(MEMCACHED_BUFFERED
, (rc
= memcached_delete(memc
, "foo", 3, 0)));
4968 test_compare(MEMCACHED_SUCCESS
, memcached_flush_buffers(memc
));
4970 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 0));
4971 /* unbuffered noreply should be success */
4972 test_compare(MEMCACHED_SUCCESS
, memcached_delete(memc
, "foo", 3, 0));
4973 /* unbuffered with reply should be not found... */
4974 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0));
4975 test_compare(MEMCACHED_NOTFOUND
, memcached_delete(memc
, "foo", 3, 0));
4978 memcached_free(memc_clone
);
4979 return TEST_SUCCESS
;
4983 /* Test memcached_server_get_last_disconnect
4984 * For a working server set, shall be NULL
4985 * For a set of non existing server, shall not be NULL
4987 static test_return_t
test_get_last_disconnect(memcached_st
*memc
)
4989 memcached_return_t rc
;
4990 memcached_server_instance_st disconnected_server
;
4992 /* With the working set of server */
4993 const char *key
= "marmotte";
4994 const char *value
= "milka";
4996 memcached_reset_last_disconnected_server(memc
);
4997 test_false(memc
->last_disconnected_server
);
4998 rc
= memcached_set(memc
, key
, strlen(key
),
4999 value
, strlen(value
),
5000 (time_t)0, (uint32_t)0);
5001 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5003 disconnected_server
= memcached_server_get_last_disconnect(memc
);
5004 test_false(disconnected_server
);
5006 /* With a non existing server */
5008 memcached_server_st
*servers
;
5010 const char *server_list
= "localhost:9";
5012 servers
= memcached_servers_parse(server_list
);
5014 mine
= memcached_create(NULL
);
5015 rc
= memcached_server_push(mine
, servers
);
5016 test_compare(MEMCACHED_SUCCESS
, rc
);
5017 memcached_server_list_free(servers
);
5020 rc
= memcached_set(mine
, key
, strlen(key
),
5021 value
, strlen(value
),
5022 (time_t)0, (uint32_t)0);
5023 test_true(memcached_failed(rc
));
5025 disconnected_server
= memcached_server_get_last_disconnect(mine
);
5026 test_true_got(disconnected_server
, memcached_strerror(mine
, rc
));
5027 test_compare(in_port_t(9), memcached_server_port(disconnected_server
));
5028 test_false(strncmp(memcached_server_name(disconnected_server
),"localhost",9));
5030 memcached_quit(mine
);
5031 memcached_free(mine
);
5033 return TEST_SUCCESS
;
5036 static test_return_t
test_multiple_get_last_disconnect(memcached_st
*)
5038 const char *server_string
= "--server=localhost:8888 --server=localhost:8889 --server=localhost:8890 --server=localhost:8891 --server=localhost:8892";
5039 char buffer
[BUFSIZ
];
5041 test_compare(MEMCACHED_SUCCESS
,
5042 libmemcached_check_configuration(server_string
, strlen(server_string
), buffer
, sizeof(buffer
)));
5044 memcached_st
*memc
= memcached(server_string
, strlen(server_string
));
5047 // We will just use the error strings as our keys
5048 uint32_t counter
= 100;
5051 for (int x
= int(MEMCACHED_SUCCESS
); x
< int(MEMCACHED_MAXIMUM_RETURN
); ++x
)
5053 const char *msg
= memcached_strerror(memc
, memcached_return_t(x
));
5054 memcached_return_t ret
= memcached_set(memc
, msg
, strlen(msg
), NULL
, 0, (time_t)0, (uint32_t)0);
5055 test_true_got((ret
== MEMCACHED_CONNECTION_FAILURE
or ret
== MEMCACHED_SERVER_TEMPORARILY_DISABLED
), memcached_last_error_message(memc
));
5057 memcached_server_instance_st disconnected_server
= memcached_server_get_last_disconnect(memc
);
5058 test_true(disconnected_server
);
5059 test_strcmp("localhost", memcached_server_name(disconnected_server
));
5060 test_true(memcached_server_port(disconnected_server
) >= 8888 and memcached_server_port(disconnected_server
) <= 8892);
5064 memcached_reset_last_disconnected_server(memc
);
5069 memcached_free(memc
);
5071 return TEST_SUCCESS
;
5074 static test_return_t
test_verbosity(memcached_st
*memc
)
5076 memcached_verbosity(memc
, 3);
5078 return TEST_SUCCESS
;
5082 static memcached_return_t
stat_printer(memcached_server_instance_st server
,
5083 const char *key
, size_t key_length
,
5084 const char *value
, size_t value_length
,
5094 return MEMCACHED_SUCCESS
;
5097 static test_return_t
memcached_stat_execute_test(memcached_st
*memc
)
5099 memcached_return_t rc
= memcached_stat_execute(memc
, NULL
, stat_printer
, NULL
);
5100 test_compare(MEMCACHED_SUCCESS
, rc
);
5102 rc
= memcached_stat_execute(memc
, "slabs", stat_printer
, NULL
);
5103 test_compare(MEMCACHED_SUCCESS
, rc
);
5105 rc
= memcached_stat_execute(memc
, "items", stat_printer
, NULL
);
5106 test_compare(MEMCACHED_SUCCESS
, rc
);
5108 rc
= memcached_stat_execute(memc
, "sizes", stat_printer
, NULL
);
5109 test_compare(MEMCACHED_SUCCESS
, rc
);
5111 return TEST_SUCCESS
;
5115 * This test ensures that the failure counter isn't incremented during
5116 * normal termination of the memcached instance.
5118 static test_return_t
wrong_failure_counter_test(memcached_st
*memc
)
5120 memcached_return_t rc
;
5121 memcached_server_instance_st instance
;
5123 /* Set value to force connection to the server */
5124 const char *key
= "marmotte";
5125 const char *value
= "milka";
5128 * Please note that I'm abusing the internal structures in libmemcached
5129 * in a non-portable way and you shouldn't be doing this. I'm only
5130 * doing this in order to verify that the library works the way it should
5132 uint32_t number_of_hosts
= memcached_server_count(memc
);
5133 memc
->number_of_hosts
= 1;
5135 /* Ensure that we are connected to the server by setting a value */
5136 rc
= memcached_set(memc
, key
, strlen(key
),
5137 value
, strlen(value
),
5138 (time_t)0, (uint32_t)0);
5139 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
5142 instance
= memcached_server_instance_by_position(memc
, 0);
5143 /* The test is to see that the memcached_quit doesn't increase the
5144 * the server failure conter, so let's ensure that it is zero
5145 * before sending quit
5147 ((memcached_server_write_instance_st
)instance
)->server_failure_counter
= 0;
5149 memcached_quit(memc
);
5151 /* Verify that it memcached_quit didn't increment the failure counter
5152 * Please note that this isn't bullet proof, because an error could
5155 test_zero(instance
->server_failure_counter
);
5157 /* restore the instance */
5158 memc
->number_of_hosts
= number_of_hosts
;
5160 return TEST_SUCCESS
;
5164 * This tests ensures expected disconnections (for some behavior changes
5165 * for instance) do not wrongly increase failure counter
5167 static test_return_t
wrong_failure_counter_two_test(memcached_st
*memc
)
5169 memcached_return rc
;
5171 memcached_st
*memc_clone
;
5172 memc_clone
= memcached_clone(NULL
, memc
);
5173 test_true(memc_clone
);
5175 /* Set value to force connection to the server */
5176 const char *key
= "marmotte";
5177 const char *value
= "milka";
5178 char *string
= NULL
;
5179 size_t string_length
;
5182 rc
= memcached_set(memc_clone
, key
, strlen(key
),
5183 value
, strlen(value
),
5184 (time_t)0, (uint32_t)0);
5185 test_true_got(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
, memcached_strerror(NULL
, rc
));
5188 /* put failure limit to 1 */
5189 test_compare(MEMCACHED_SUCCESS
,
5190 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, 1));
5192 /* Put a retry timeout to effectively activate failure_limit effect */
5193 test_compare(MEMCACHED_SUCCESS
,
5194 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 1));
5196 /* change behavior that triggers memcached_quit()*/
5197 test_compare(MEMCACHED_SUCCESS
,
5198 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1));
5201 /* Check if we still are connected */
5202 string
= memcached_get(memc_clone
, key
, strlen(key
),
5203 &string_length
, &flags
, &rc
);
5205 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
5208 memcached_free(memc_clone
);
5210 return TEST_SUCCESS
;
5217 * Test that ensures mget_execute does not end into recursive calls that finally fails
5219 static test_return_t
regression_bug_490486(memcached_st
*original_memc
)
5223 return TEST_SKIPPED
; // My MAC can't handle this test
5226 test_skip(TEST_SUCCESS
, pre_binary(original_memc
));
5229 * I only want to hit _one_ server so I know the number of requests I'm
5230 * sending in the pipeline.
5232 memcached_st
*memc
= create_single_instance_memcached(original_memc
, "--BINARY-PROTOCOL --POLL-TIMEOUT=1000 --REMOVE-FAILED-SERVERS=1 --RETRY-TIMEOUT=3600");
5235 size_t max_keys
= 20480;
5237 char **keys
= (char **)calloc(max_keys
, sizeof(char*));
5238 size_t *key_length
= (size_t *)calloc(max_keys
, sizeof(size_t));
5240 /* First add all of the items.. */
5241 char blob
[1024]= { 0 };
5242 for (size_t x
= 0; x
< max_keys
; ++x
)
5245 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%lu", (unsigned long)x
);
5248 memcached_return rc
= memcached_set(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
5249 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
); // MEMCACHED_TIMEOUT <-- hash been observed on OSX
5254 /* Try to get all of them with a large multiget */
5256 memcached_execute_function callbacks
[]= { &callback_counter
};
5257 memcached_return_t rc
= memcached_mget_execute(memc
, (const char**)keys
, key_length
,
5258 (size_t)max_keys
, callbacks
, &counter
, 1);
5259 test_compare(MEMCACHED_SUCCESS
, rc
);
5261 char* the_value
= NULL
;
5262 char the_key
[MEMCACHED_MAX_KEY
];
5263 size_t the_key_length
;
5264 size_t the_value_length
;
5268 the_value
= memcached_fetch(memc
, the_key
, &the_key_length
, &the_value_length
, &the_flags
, &rc
);
5270 if ((the_value
!= NULL
) && (rc
== MEMCACHED_SUCCESS
))
5276 } while ( (the_value
!= NULL
) && (rc
== MEMCACHED_SUCCESS
));
5279 test_compare(MEMCACHED_END
, rc
);
5281 /* Verify that we got all of the items */
5282 test_compare(counter
, max_keys
);
5285 /* Release all allocated resources */
5286 for (size_t x
= 0; x
< max_keys
; ++x
)
5293 memcached_free(memc
);
5295 return TEST_SUCCESS
;
5298 static test_return_t
regression_bug_583031(memcached_st
*)
5300 memcached_st
*memc
= memcached_create(NULL
);
5302 test_compare(MEMCACHED_SUCCESS
, memcached_server_add(memc
, "10.2.3.4", 11211));
5304 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT
, 1000);
5305 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 1000);
5306 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
5307 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
5308 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, 1000);
5309 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, 3);
5311 memcached_return_t rc
;
5315 const char *value
= memcached_get(memc
, "dsf", 3, &length
, &flags
, &rc
);
5319 test_compare_got(MEMCACHED_TIMEOUT
, rc
, memcached_last_error_message(memc
));
5321 memcached_free(memc
);
5323 return TEST_SUCCESS
;
5326 static test_return_t
regression_bug_581030(memcached_st
*)
5329 memcached_stat_st
*local_stat
= memcached_stat(NULL
, NULL
, NULL
);
5330 test_false(local_stat
);
5332 memcached_stat_free(NULL
, NULL
);
5335 return TEST_SUCCESS
;
5338 #define regression_bug_655423_COUNT 6000
5339 static test_return_t
regression_bug_655423(memcached_st
*memc
)
5341 memcached_st
*clone
= memcached_clone(NULL
, memc
);
5342 memc
= NULL
; // Just to make sure it is not used
5347 return TEST_SKIPPED
;
5350 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1));
5351 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1));
5352 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1));
5353 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH
, 1));
5355 memset(payload
, int('x'), sizeof(payload
));
5357 for (uint32_t x
= 0; x
< regression_bug_655423_COUNT
; x
++)
5359 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1];
5360 snprintf(key
, sizeof(key
), "%u", x
);
5362 test_compare(MEMCACHED_SUCCESS
, memcached_set(clone
, key
, strlen(key
), payload
, sizeof(payload
), 0, 0));
5365 for (uint32_t x
= 0; x
< regression_bug_655423_COUNT
; x
++)
5367 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1];
5368 snprintf(key
, sizeof(key
), "%u", x
);
5370 size_t value_length
;
5371 memcached_return_t rc
;
5372 char *value
= memcached_get(clone
, key
, strlen(key
), &value_length
, NULL
, &rc
);
5374 if (rc
== MEMCACHED_NOTFOUND
)
5377 test_zero(value_length
);
5381 test_compare(MEMCACHED_SUCCESS
, rc
);
5383 test_compare(100LLU, value_length
);
5387 char **keys
= (char**)calloc(regression_bug_655423_COUNT
, sizeof(char*));
5388 size_t *key_length
= (size_t *)calloc(regression_bug_655423_COUNT
, sizeof(size_t));
5389 for (uint32_t x
= 0; x
< regression_bug_655423_COUNT
; x
++)
5391 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1];
5392 snprintf(key
, sizeof(key
), "%u", x
);
5394 keys
[x
]= strdup(key
);
5396 key_length
[x
]= strlen(key
);
5397 test_true(key_length
[x
]);
5400 test_compare(MEMCACHED_SUCCESS
,
5401 memcached_mget(clone
, (const char* const *)keys
, key_length
, regression_bug_655423_COUNT
));
5404 memcached_result_st
*result
= NULL
;
5405 while ((result
= memcached_fetch_result(clone
, result
, NULL
)))
5407 test_compare(size_t(100), memcached_result_length(result
));
5411 test_true(count
> 100); // If we don't get back atleast this, something is up
5413 /* Release all allocated resources */
5414 for (size_t x
= 0; x
< regression_bug_655423_COUNT
; ++x
)
5422 memcached_free(clone
);
5424 return TEST_SUCCESS
;
5428 * Test that ensures that buffered set to not trigger problems during io_flush
5430 #define regression_bug_490520_COUNT 200480
5431 static test_return_t
regression_bug_490520(memcached_st
*memc
)
5433 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
,1);
5434 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
,1);
5435 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, 1000);
5436 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
,1);
5437 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 3600);
5439 memc
->number_of_hosts
= 1;
5441 char **keys
= (char **)calloc(regression_bug_490520_COUNT
, sizeof(char*));
5442 size_t *key_length
= (size_t *)calloc(regression_bug_490520_COUNT
, sizeof(size_t));
5444 /* First add all of the items.. */
5445 char blob
[3333] = {0};
5446 for (uint32_t x
= 0; x
< regression_bug_490520_COUNT
; ++x
)
5449 key_length
[x
]= (size_t)snprintf(k
, sizeof(k
), "0200%u", x
);
5453 memcached_return rc
= memcached_set(memc
, keys
[x
], key_length
[x
], blob
, sizeof(blob
), 0, 0);
5454 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
5457 for (uint32_t x
= 0; x
< regression_bug_490520_COUNT
; ++x
)
5464 return TEST_SUCCESS
;
5468 static test_return_t
regression_bug_854604(memcached_st
*)
5472 test_compare(MEMCACHED_INVALID_ARGUMENTS
, libmemcached_check_configuration(0, 0, buffer
, 0));
5474 test_compare(MEMCACHED_PARSE_ERROR
, libmemcached_check_configuration(test_literal_param("syntax error"), buffer
, 0));
5476 test_compare(MEMCACHED_PARSE_ERROR
, libmemcached_check_configuration(test_literal_param("syntax error"), buffer
, 1));
5477 test_compare(buffer
[0], 0);
5479 test_compare(MEMCACHED_PARSE_ERROR
, libmemcached_check_configuration(test_literal_param("syntax error"), buffer
, 10));
5480 test_true(strlen(buffer
));
5482 test_compare(MEMCACHED_PARSE_ERROR
, libmemcached_check_configuration(test_literal_param("syntax error"), buffer
, sizeof(buffer
)));
5483 test_true(strlen(buffer
));
5485 return TEST_SUCCESS
;
5488 static void memcached_die(memcached_st
* mc
, memcached_return error
, const char* what
, uint32_t it
)
5490 fprintf(stderr
, "Iteration #%u: ", it
);
5492 if (error
== MEMCACHED_ERRNO
)
5494 fprintf(stderr
, "system error %d from %s: %s\n",
5495 errno
, what
, strerror(errno
));
5499 fprintf(stderr
, "error %d from %s: %s\n", error
, what
,
5500 memcached_strerror(mc
, error
));
5504 #define TEST_CONSTANT_CREATION 200
5506 static test_return_t
regression_bug_(memcached_st
*memc
)
5508 const char *remote_server
;
5511 if (! (remote_server
= getenv("LIBMEMCACHED_REMOTE_SERVER")))
5513 return TEST_SKIPPED
;
5516 for (uint32_t x
= 0; x
< TEST_CONSTANT_CREATION
; x
++)
5518 memcached_st
* mc
= memcached_create(NULL
);
5519 memcached_return rc
;
5521 rc
= memcached_behavior_set(mc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
5522 if (rc
!= MEMCACHED_SUCCESS
)
5524 memcached_die(mc
, rc
, "memcached_behavior_set", x
);
5527 rc
= memcached_behavior_set(mc
, MEMCACHED_BEHAVIOR_CACHE_LOOKUPS
, 1);
5528 if (rc
!= MEMCACHED_SUCCESS
)
5530 memcached_die(mc
, rc
, "memcached_behavior_set", x
);
5533 rc
= memcached_server_add(mc
, remote_server
, 0);
5534 if (rc
!= MEMCACHED_SUCCESS
)
5536 memcached_die(mc
, rc
, "memcached_server_add", x
);
5539 const char *set_key
= "akey";
5540 const size_t set_key_len
= strlen(set_key
);
5541 const char *set_value
= "a value";
5542 const size_t set_value_len
= strlen(set_value
);
5544 if (rc
== MEMCACHED_SUCCESS
)
5548 size_t get_value_len
;
5550 uint32_t get_value_flags
;
5552 get_value
= memcached_get(mc
, set_key
, set_key_len
, &get_value_len
,
5553 &get_value_flags
, &rc
);
5554 if (rc
!= MEMCACHED_SUCCESS
)
5556 memcached_die(mc
, rc
, "memcached_get", x
);
5562 (get_value_len
!= set_value_len
5563 || 0!=strncmp(get_value
, set_value
, get_value_len
)))
5565 fprintf(stderr
, "Values don't match?\n");
5566 rc
= MEMCACHED_FAILURE
;
5572 rc
= memcached_set(mc
,
5573 set_key
, set_key_len
,
5574 set_value
, set_value_len
,
5578 if (rc
!= MEMCACHED_SUCCESS
)
5580 memcached_die(mc
, rc
, "memcached_set", x
);
5587 if (rc
!= MEMCACHED_SUCCESS
)
5593 return TEST_SUCCESS
;
5596 /* Clean the server before beginning testing */
5598 {"util_version", true, (test_callback_fn
*)util_version_test
},
5599 {"flush", false, (test_callback_fn
*)flush_test
},
5600 {"init", false, (test_callback_fn
*)init_test
},
5601 {"allocation", false, (test_callback_fn
*)allocation_test
},
5602 {"server_list_null_test", false, (test_callback_fn
*)server_list_null_test
},
5603 {"server_unsort", false, (test_callback_fn
*)server_unsort_test
},
5604 {"server_sort", false, (test_callback_fn
*)server_sort_test
},
5605 {"server_sort2", false, (test_callback_fn
*)server_sort2_test
},
5606 {"memcached_server_remove", false, (test_callback_fn
*)memcached_server_remove_test
},
5607 {"clone_test", false, (test_callback_fn
*)clone_test
},
5608 {"connection_test", false, (test_callback_fn
*)connection_test
},
5609 {"callback_test", false, (test_callback_fn
*)callback_test
},
5610 {"userdata_test", false, (test_callback_fn
*)userdata_test
},
5611 {"set", false, (test_callback_fn
*)set_test
},
5612 {"set2", false, (test_callback_fn
*)set_test2
},
5613 {"set3", false, (test_callback_fn
*)set_test3
},
5614 {"dump", true, (test_callback_fn
*)dump_test
},
5615 {"add", true, (test_callback_fn
*)add_test
},
5616 {"memcached_fetch_result(MEMCACHED_NOTFOUND)", true, (test_callback_fn
*)memcached_fetch_result_NOT_FOUND
},
5617 {"replace", true, (test_callback_fn
*)replace_test
},
5618 {"delete", true, (test_callback_fn
*)delete_test
},
5619 {"get", true, (test_callback_fn
*)get_test
},
5620 {"get2", false, (test_callback_fn
*)get_test2
},
5621 {"get3", false, (test_callback_fn
*)get_test3
},
5622 {"get4", false, (test_callback_fn
*)get_test4
},
5623 {"partial mget", false, (test_callback_fn
*)get_test5
},
5624 {"stats_servername", false, (test_callback_fn
*)stats_servername_test
},
5625 {"increment", false, (test_callback_fn
*)increment_test
},
5626 {"increment_with_initial", true, (test_callback_fn
*)increment_with_initial_test
},
5627 {"decrement", false, (test_callback_fn
*)decrement_test
},
5628 {"decrement_with_initial", true, (test_callback_fn
*)decrement_with_initial_test
},
5629 {"increment_by_key", false, (test_callback_fn
*)increment_by_key_test
},
5630 {"increment_with_initial_by_key", true, (test_callback_fn
*)increment_with_initial_by_key_test
},
5631 {"decrement_by_key", false, (test_callback_fn
*)decrement_by_key_test
},
5632 {"decrement_with_initial_by_key", true, (test_callback_fn
*)decrement_with_initial_by_key_test
},
5633 {"binary_increment_with_prefix", 1, (test_callback_fn
*)binary_increment_with_prefix_test
},
5634 {"quit", false, (test_callback_fn
*)quit_test
},
5635 {"mget", true, (test_callback_fn
*)mget_test
},
5636 {"mget_result", true, (test_callback_fn
*)mget_result_test
},
5637 {"mget_result_alloc", true, (test_callback_fn
*)mget_result_alloc_test
},
5638 {"mget_result_function", true, (test_callback_fn
*)mget_result_function
},
5639 {"mget_execute", true, (test_callback_fn
*)mget_execute
},
5640 {"mget_end", false, (test_callback_fn
*)mget_end
},
5641 {"get_stats", false, (test_callback_fn
*)get_stats
},
5642 {"add_host_test", false, (test_callback_fn
*)add_host_test
},
5643 {"add_host_test_1", false, (test_callback_fn
*)add_host_test1
},
5644 {"get_stats_keys", false, (test_callback_fn
*)get_stats_keys
},
5645 {"version_string_test", false, (test_callback_fn
*)version_string_test
},
5646 {"bad_key", true, (test_callback_fn
*)bad_key_test
},
5647 {"memcached_server_cursor", true, (test_callback_fn
*)memcached_server_cursor_test
},
5648 {"read_through", true, (test_callback_fn
*)read_through
},
5649 {"delete_through", true, (test_callback_fn
*)test_MEMCACHED_CALLBACK_DELETE_TRIGGER
},
5650 {"noreply", true, (test_callback_fn
*)noreply_test
},
5651 {"analyzer", true, (test_callback_fn
*)analyzer_test
},
5652 {"memcached_pool_st", true, (test_callback_fn
*)connection_pool_test
},
5653 {"memcached_pool_st #2", true, (test_callback_fn
*)connection_pool2_test
},
5655 {"memcached_pool_st #3", true, (test_callback_fn
*)connection_pool3_test
},
5657 {"memcached_pool_test", true, (test_callback_fn
*)memcached_pool_test
},
5658 {"test_get_last_disconnect", true, (test_callback_fn
*)test_get_last_disconnect
},
5659 {"verbosity", true, (test_callback_fn
*)test_verbosity
},
5660 {"memcached_stat_execute", true, (test_callback_fn
*)memcached_stat_execute_test
},
5661 {"memcached_exist(MEMCACHED_NOTFOUND)", true, (test_callback_fn
*)memcached_exist_NOTFOUND
},
5662 {"memcached_exist(MEMCACHED_SUCCESS)", true, (test_callback_fn
*)memcached_exist_SUCCESS
},
5663 {"memcached_exist_by_key(MEMCACHED_NOTFOUND)", true, (test_callback_fn
*)memcached_exist_by_key_NOTFOUND
},
5664 {"memcached_exist_by_key(MEMCACHED_SUCCESS)", true, (test_callback_fn
*)memcached_exist_by_key_SUCCESS
},
5665 {"memcached_touch", 0, (test_callback_fn
*)test_memcached_touch
},
5666 {"memcached_touch_with_prefix", 0, (test_callback_fn
*)test_memcached_touch_by_key
},
5670 test_st touch_tests
[] ={
5671 {"memcached_touch", 0, (test_callback_fn
*)test_memcached_touch
},
5672 {"memcached_touch_with_prefix", 0, (test_callback_fn
*)test_memcached_touch_by_key
},
5676 test_st behavior_tests
[] ={
5677 {"libmemcached_string_behavior()", false, (test_callback_fn
*)libmemcached_string_behavior_test
},
5678 {"libmemcached_string_distribution()", false, (test_callback_fn
*)libmemcached_string_distribution_test
},
5679 {"behavior_test", false, (test_callback_fn
*)behavior_test
},
5680 {"MEMCACHED_BEHAVIOR_CORK", false, (test_callback_fn
*)MEMCACHED_BEHAVIOR_CORK_test
},
5681 {"MEMCACHED_BEHAVIOR_TCP_KEEPALIVE", false, (test_callback_fn
*)MEMCACHED_BEHAVIOR_TCP_KEEPALIVE_test
},
5682 {"MEMCACHED_BEHAVIOR_TCP_KEEPIDLE", false, (test_callback_fn
*)MEMCACHED_BEHAVIOR_TCP_KEEPIDLE_test
},
5683 {"MEMCACHED_BEHAVIOR_POLL_TIMEOUT", false, (test_callback_fn
*)MEMCACHED_BEHAVIOR_POLL_TIMEOUT_test
},
5684 {"MEMCACHED_CALLBACK_DELETE_TRIGGER_and_MEMCACHED_BEHAVIOR_NOREPLY", false, (test_callback_fn
*)test_MEMCACHED_CALLBACK_DELETE_TRIGGER_and_MEMCACHED_BEHAVIOR_NOREPLY
},
5688 test_st libmemcachedutil_tests
[] ={
5689 {"libmemcached_util_ping()", true, (test_callback_fn
*)ping_test
},
5690 {"libmemcached_util_getpid()", true, (test_callback_fn
*)getpid_test
},
5691 {"libmemcached_util_getpid(MEMCACHED_CONNECTION_FAILURE)", true, (test_callback_fn
*)getpid_connection_failure_test
},
5695 test_st basic_tests
[] ={
5696 {"init", true, (test_callback_fn
*)basic_init_test
},
5697 {"clone", true, (test_callback_fn
*)basic_clone_test
},
5698 {"reset", true, (test_callback_fn
*)basic_reset_stack_test
},
5699 {"reset heap", true, (test_callback_fn
*)basic_reset_heap_test
},
5700 {"reset stack clone", true, (test_callback_fn
*)basic_reset_stack_clone_test
},
5701 {"reset heap clone", true, (test_callback_fn
*)basic_reset_heap_clone_test
},
5702 {"memcached_return_t", false, (test_callback_fn
*)memcached_return_t_TEST
},
5706 test_st regression_binary_vs_block
[] ={
5707 {"block add", true, (test_callback_fn
*)block_add_regression
},
5708 {"binary add", true, (test_callback_fn
*)binary_add_regression
},
5712 test_st async_tests
[] ={
5713 {"add", true, (test_callback_fn
*)add_wrapper
},
5717 test_st memcached_server_get_last_disconnect_tests
[] ={
5718 {"memcached_server_get_last_disconnect()", false, (test_callback_fn
*)test_multiple_get_last_disconnect
},
5719 {0, 0, (test_callback_fn
*)0}
5723 test_st result_tests
[] ={
5724 {"result static", false, (test_callback_fn
*)result_static
},
5725 {"result alloc", false, (test_callback_fn
*)result_alloc
},
5726 {0, 0, (test_callback_fn
*)0}
5729 test_st version_1_2_3
[] ={
5730 {"append", false, (test_callback_fn
*)append_test
},
5731 {"prepend", false, (test_callback_fn
*)prepend_test
},
5732 {"cas", false, (test_callback_fn
*)cas_test
},
5733 {"cas2", false, (test_callback_fn
*)cas2_test
},
5734 {"append_binary", false, (test_callback_fn
*)append_binary_test
},
5735 {0, 0, (test_callback_fn
*)0}
5738 test_st haldenbrand_tests
[] ={
5739 {"memcached_set", false, (test_callback_fn
*)user_supplied_bug1
},
5740 {"memcached_get()", false, (test_callback_fn
*)user_supplied_bug2
},
5741 {"memcached_mget()", false, (test_callback_fn
*)user_supplied_bug3
},
5742 {0, 0, (test_callback_fn
*)0}
5745 test_st user_tests
[] ={
5746 {"user_supplied_bug4", true, (test_callback_fn
*)user_supplied_bug4
},
5747 {"user_supplied_bug5", true, (test_callback_fn
*)user_supplied_bug5
},
5748 {"user_supplied_bug6", true, (test_callback_fn
*)user_supplied_bug6
},
5749 {"user_supplied_bug7", true, (test_callback_fn
*)user_supplied_bug7
},
5750 {"user_supplied_bug8", true, (test_callback_fn
*)user_supplied_bug8
},
5751 {"user_supplied_bug9", true, (test_callback_fn
*)user_supplied_bug9
},
5752 {"user_supplied_bug10", true, (test_callback_fn
*)user_supplied_bug10
},
5753 {"user_supplied_bug11", true, (test_callback_fn
*)user_supplied_bug11
},
5754 {"user_supplied_bug12", true, (test_callback_fn
*)user_supplied_bug12
},
5755 {"user_supplied_bug13", true, (test_callback_fn
*)user_supplied_bug13
},
5756 {"user_supplied_bug14", true, (test_callback_fn
*)user_supplied_bug14
},
5757 {"user_supplied_bug15", true, (test_callback_fn
*)user_supplied_bug15
},
5758 {"user_supplied_bug16", true, (test_callback_fn
*)user_supplied_bug16
},
5759 #if !defined(__sun) && !defined(__OpenBSD__)
5761 ** It seems to be something weird with the character sets..
5762 ** value_fetch is unable to parse the value line (iscntrl "fails"), so I
5763 ** guess I need to find out how this is supposed to work.. Perhaps I need
5764 ** to run the test in a specific locale (I tried zh_CN.UTF-8 without success,
5765 ** so just disable the code for now...).
5767 {"user_supplied_bug17", true, (test_callback_fn
*)user_supplied_bug17
},
5769 {"user_supplied_bug18", true, (test_callback_fn
*)user_supplied_bug18
},
5770 {"user_supplied_bug19", true, (test_callback_fn
*)user_supplied_bug19
},
5771 {"user_supplied_bug20", true, (test_callback_fn
*)user_supplied_bug20
},
5772 {"user_supplied_bug21", true, (test_callback_fn
*)user_supplied_bug21
},
5773 {"wrong_failure_counter_test", true, (test_callback_fn
*)wrong_failure_counter_test
},
5774 {"wrong_failure_counter_two_test", true, (test_callback_fn
*)wrong_failure_counter_two_test
},
5775 {0, 0, (test_callback_fn
*)0}
5778 test_st replication_tests
[]= {
5779 {"set", true, (test_callback_fn
*)replication_set_test
},
5780 {"get", false, (test_callback_fn
*)replication_get_test
},
5781 {"mget", false, (test_callback_fn
*)replication_mget_test
},
5782 {"delete", true, (test_callback_fn
*)replication_delete_test
},
5783 {"rand_mget", false, (test_callback_fn
*)replication_randomize_mget_test
},
5784 {"fail", false, (test_callback_fn
*)replication_randomize_mget_fail_test
},
5785 {0, 0, (test_callback_fn
*)0}
5789 * The following test suite is used to verify that we don't introduce
5790 * regression bugs. If you want more information about the bug / test,
5791 * you should look in the bug report at
5792 * http://bugs.launchpad.net/libmemcached
5794 test_st regression_tests
[]= {
5795 {"lp:434484", true, (test_callback_fn
*)regression_bug_434484
},
5796 {"lp:434843", true, (test_callback_fn
*)regression_bug_434843
},
5797 {"lp:434843-buffered", true, (test_callback_fn
*)regression_bug_434843_buffered
},
5798 {"lp:421108", true, (test_callback_fn
*)regression_bug_421108
},
5799 {"lp:442914", true, (test_callback_fn
*)regression_bug_442914
},
5800 {"lp:447342", true, (test_callback_fn
*)regression_bug_447342
},
5801 {"lp:463297", true, (test_callback_fn
*)regression_bug_463297
},
5802 {"lp:490486", true, (test_callback_fn
*)regression_bug_490486
},
5803 {"lp:583031", true, (test_callback_fn
*)regression_bug_583031
},
5804 {"lp:?", true, (test_callback_fn
*)regression_bug_
},
5805 {"lp:728286", true, (test_callback_fn
*)regression_bug_728286
},
5806 {"lp:581030", true, (test_callback_fn
*)regression_bug_581030
},
5807 {"lp:71231153 connect()", true, (test_callback_fn
*)regression_bug_71231153_connect
},
5808 {"lp:71231153 poll()", true, (test_callback_fn
*)regression_bug_71231153_poll
},
5809 {"lp:655423", true, (test_callback_fn
*)regression_bug_655423
},
5810 {"lp:490520", true, (test_callback_fn
*)regression_bug_490520
},
5811 {"lp:854604", true, (test_callback_fn
*)regression_bug_854604
},
5812 {0, false, (test_callback_fn
*)0}
5815 test_st ketama_compatibility
[]= {
5816 {"libmemcached", true, (test_callback_fn
*)ketama_compatibility_libmemcached
},
5817 {"spymemcached", true, (test_callback_fn
*)ketama_compatibility_spymemcached
},
5818 {0, 0, (test_callback_fn
*)0}
5821 test_st generate_tests
[] ={
5822 {"generate_pairs", true, (test_callback_fn
*)generate_pairs
},
5823 {"generate_data", true, (test_callback_fn
*)generate_data
},
5824 {"get_read", false, (test_callback_fn
*)get_read
},
5825 {"delete_generate", false, (test_callback_fn
*)delete_generate
},
5826 {"generate_buffer_data", true, (test_callback_fn
*)generate_buffer_data
},
5827 {"delete_buffer", false, (test_callback_fn
*)delete_buffer_generate
},
5828 {"generate_data", true, (test_callback_fn
*)generate_data
},
5829 {"mget_read", false, (test_callback_fn
*)mget_read
},
5830 {"mget_read_result", false, (test_callback_fn
*)mget_read_result
},
5831 {"memcached_fetch_result() use internal result", false, (test_callback_fn
*)mget_read_internal_result
},
5832 {"memcached_fetch_result() partial read", false, (test_callback_fn
*)mget_read_partial_result
},
5833 {"mget_read_function", false, (test_callback_fn
*)mget_read_function
},
5834 {"cleanup", true, (test_callback_fn
*)cleanup_pairs
},
5835 {"generate_large_pairs", true, (test_callback_fn
*)generate_large_pairs
},
5836 {"generate_data", true, (test_callback_fn
*)generate_data
},
5837 {"generate_buffer_data", true, (test_callback_fn
*)generate_buffer_data
},
5838 {"cleanup", true, (test_callback_fn
*)cleanup_pairs
},
5839 {0, 0, (test_callback_fn
*)0}
5842 test_st consistent_tests
[] ={
5843 {"generate_pairs", true, (test_callback_fn
*)generate_pairs
},
5844 {"generate_data", true, (test_callback_fn
*)generate_data
},
5845 {"get_read", 0, (test_callback_fn
*)get_read_count
},
5846 {"cleanup", true, (test_callback_fn
*)cleanup_pairs
},
5847 {0, 0, (test_callback_fn
*)0}
5850 test_st consistent_weighted_tests
[] ={
5851 {"generate_pairs", true, (test_callback_fn
*)generate_pairs
},
5852 {"generate_data", true, (test_callback_fn
*)generate_data_with_stats
},
5853 {"get_read", false, (test_callback_fn
*)get_read_count
},
5854 {"cleanup", true, (test_callback_fn
*)cleanup_pairs
},
5855 {0, 0, (test_callback_fn
*)0}
5858 test_st hsieh_availability
[] ={
5859 {"hsieh_avaibility_test", false, (test_callback_fn
*)hsieh_avaibility_test
},
5860 {0, 0, (test_callback_fn
*)0}
5863 test_st murmur_availability
[] ={
5864 {"murmur_avaibility_test", false, (test_callback_fn
*)murmur_avaibility_test
},
5865 {0, 0, (test_callback_fn
*)0}
5869 test_st hash_sanity
[] ={
5870 {"hash sanity", 0, (test_callback_fn
*)hash_sanity_test
},
5871 {0, 0, (test_callback_fn
*)0}
5875 test_st ketama_auto_eject_hosts
[] ={
5876 {"auto_eject_hosts", true, (test_callback_fn
*)auto_eject_hosts
},
5877 {"output_ketama_weighted_keys", true, (test_callback_fn
*)output_ketama_weighted_keys
},
5878 {0, 0, (test_callback_fn
*)0}
5881 test_st hash_tests
[] ={
5882 {"one_at_a_time_run", false, (test_callback_fn
*)one_at_a_time_run
},
5883 {"md5", false, (test_callback_fn
*)md5_run
},
5884 {"crc", false, (test_callback_fn
*)crc_run
},
5885 {"fnv1_64", false, (test_callback_fn
*)fnv1_64_run
},
5886 {"fnv1a_64", false, (test_callback_fn
*)fnv1a_64_run
},
5887 {"fnv1_32", false, (test_callback_fn
*)fnv1_32_run
},
5888 {"fnv1a_32", false, (test_callback_fn
*)fnv1a_32_run
},
5889 {"hsieh", false, (test_callback_fn
*)hsieh_run
},
5890 {"murmur", false, (test_callback_fn
*)murmur_run
},
5891 {"jenkis", false, (test_callback_fn
*)jenkins_run
},
5892 {"memcached_get_hashkit", false, (test_callback_fn
*)memcached_get_hashkit_test
},
5893 {0, 0, (test_callback_fn
*)0}
5896 test_st error_conditions
[] ={
5897 {"memcached_get(MEMCACHED_ERRNO)", false, (test_callback_fn
*)memcached_get_MEMCACHED_ERRNO
},
5898 {"memcached_get(MEMCACHED_NOTFOUND)", false, (test_callback_fn
*)memcached_get_MEMCACHED_NOTFOUND
},
5899 {"memcached_get_by_key(MEMCACHED_ERRNO)", false, (test_callback_fn
*)memcached_get_by_key_MEMCACHED_ERRNO
},
5900 {"memcached_get_by_key(MEMCACHED_NOTFOUND)", false, (test_callback_fn
*)memcached_get_by_key_MEMCACHED_NOTFOUND
},
5901 {"memcached_get_by_key(MEMCACHED_NOTFOUND)", false, (test_callback_fn
*)memcached_get_by_key_MEMCACHED_NOTFOUND
},
5902 {"memcached_increment(MEMCACHED_NO_SERVERS)", false, (test_callback_fn
*)memcached_increment_MEMCACHED_NO_SERVERS
},
5903 {0, 0, (test_callback_fn
*)0}
5906 test_st parser_tests
[] ={
5907 {"behavior", false, (test_callback_fn
*)behavior_parser_test
},
5908 {"boolean_options", false, (test_callback_fn
*)parser_boolean_options_test
},
5909 {"configure_file", false, (test_callback_fn
*)memcached_create_with_options_with_filename
},
5910 {"distribtions", false, (test_callback_fn
*)parser_distribution_test
},
5911 {"hash", false, (test_callback_fn
*)parser_hash_test
},
5912 {"libmemcached_check_configuration", false, (test_callback_fn
*)libmemcached_check_configuration_test
},
5913 {"libmemcached_check_configuration_with_filename", false, (test_callback_fn
*)libmemcached_check_configuration_with_filename_test
},
5914 {"number_options", false, (test_callback_fn
*)parser_number_options_test
},
5915 {"randomly generated options", false, (test_callback_fn
*)random_statement_build_test
},
5916 {"namespace", false, (test_callback_fn
*)parser_key_prefix_test
},
5917 {"server", false, (test_callback_fn
*)server_test
},
5918 {"bad server strings", false, (test_callback_fn
*)servers_bad_test
},
5919 {"server with weights", false, (test_callback_fn
*)server_with_weight_test
},
5920 {"parsing servername, port, and weight", false, (test_callback_fn
*)test_hostname_port_weight
},
5921 {"--socket=", false, (test_callback_fn
*)test_parse_socket
},
5922 {"--namespace=", false, (test_callback_fn
*)test_namespace_keyword
},
5923 {0, 0, (test_callback_fn
*)0}
5926 test_st virtual_bucket_tests
[] ={
5927 {"basic", false, (test_callback_fn
*)virtual_back_map
},
5928 {0, 0, (test_callback_fn
*)0}
5931 test_st memcached_server_add_tests
[] ={
5932 {"memcached_server_add(\"\")", false, (test_callback_fn
*)memcached_server_add_empty_test
},
5933 {"memcached_server_add(NULL)", false, (test_callback_fn
*)memcached_server_add_null_test
},
5934 {0, 0, (test_callback_fn
*)0}
5937 test_st namespace_tests
[] ={
5938 {"basic tests", true, (test_callback_fn
*)selection_of_namespace_tests
},
5939 {"increment", true, (test_callback_fn
*)memcached_increment_namespace
},
5940 {0, 0, (test_callback_fn
*)0}
5943 collection_st collection
[] ={
5945 {"hash_sanity", 0, 0, hash_sanity
},
5947 {"libmemcachedutil", 0, 0, libmemcachedutil_tests
},
5948 {"basic", 0, 0, basic_tests
},
5949 {"hsieh_availability", 0, 0, hsieh_availability
},
5950 {"murmur_availability", 0, 0, murmur_availability
},
5951 {"memcached_server_add", 0, 0, memcached_server_add_tests
},
5952 {"block", 0, 0, tests
},
5953 {"binary", (test_callback_fn
*)pre_binary
, 0, tests
},
5954 {"nonblock", (test_callback_fn
*)pre_nonblock
, 0, tests
},
5955 {"nodelay", (test_callback_fn
*)pre_nodelay
, 0, tests
},
5956 {"settimer", (test_callback_fn
*)pre_settimer
, 0, tests
},
5957 {"md5", (test_callback_fn
*)pre_md5
, 0, tests
},
5958 {"crc", (test_callback_fn
*)pre_crc
, 0, tests
},
5959 {"hsieh", (test_callback_fn
*)pre_hsieh
, 0, tests
},
5960 {"jenkins", (test_callback_fn
*)pre_jenkins
, 0, tests
},
5961 {"fnv1_64", (test_callback_fn
*)pre_hash_fnv1_64
, 0, tests
},
5962 {"fnv1a_64", (test_callback_fn
*)pre_hash_fnv1a_64
, 0, tests
},
5963 {"fnv1_32", (test_callback_fn
*)pre_hash_fnv1_32
, 0, tests
},
5964 {"fnv1a_32", (test_callback_fn
*)pre_hash_fnv1a_32
, 0, tests
},
5965 {"ketama", (test_callback_fn
*)pre_behavior_ketama
, 0, tests
},
5966 {"ketama_auto_eject_hosts", (test_callback_fn
*)pre_behavior_ketama
, 0, ketama_auto_eject_hosts
},
5967 {"unix_socket", (test_callback_fn
*)pre_unix_socket
, 0, tests
},
5968 {"unix_socket_nodelay", (test_callback_fn
*)pre_nodelay
, 0, tests
},
5969 {"gets", (test_callback_fn
*)enable_cas
, 0, tests
},
5970 {"consistent_crc", (test_callback_fn
*)enable_consistent_crc
, 0, tests
},
5971 {"consistent_hsieh", (test_callback_fn
*)enable_consistent_hsieh
, 0, tests
},
5972 #ifdef MEMCACHED_ENABLE_DEPRECATED
5973 {"deprecated_memory_allocators", (test_callback_fn
*)deprecated_set_memory_alloc
, 0, tests
},
5975 {"memory_allocators", (test_callback_fn
*)set_memory_alloc
, 0, tests
},
5976 {"namespace", (test_callback_fn
*)set_namespace
, 0, tests
},
5977 {"namespace(BINARY)", (test_callback_fn
*)set_namespace_and_binary
, 0, tests
},
5978 {"specific namespace", 0, 0, namespace_tests
},
5979 {"specific namespace(BINARY)", (test_callback_fn
*)pre_binary
, 0, namespace_tests
},
5980 {"version_1_2_3", (test_callback_fn
*)check_for_1_2_3
, 0, version_1_2_3
},
5981 {"result", 0, 0, result_tests
},
5982 {"async", (test_callback_fn
*)pre_nonblock
, 0, async_tests
},
5983 {"async(BINARY)", (test_callback_fn
*)pre_nonblock_binary
, 0, async_tests
},
5984 {"Cal Haldenbrand's tests", 0, 0, haldenbrand_tests
},
5985 {"user written tests", 0, 0, user_tests
},
5986 {"generate", 0, 0, generate_tests
},
5987 {"generate_hsieh", (test_callback_fn
*)pre_hsieh
, 0, generate_tests
},
5988 {"generate_ketama", (test_callback_fn
*)pre_behavior_ketama
, 0, generate_tests
},
5989 {"generate_hsieh_consistent", (test_callback_fn
*)enable_consistent_hsieh
, 0, generate_tests
},
5990 {"generate_md5", (test_callback_fn
*)pre_md5
, 0, generate_tests
},
5991 {"generate_murmur", (test_callback_fn
*)pre_murmur
, 0, generate_tests
},
5992 {"generate_jenkins", (test_callback_fn
*)pre_jenkins
, 0, generate_tests
},
5993 {"generate_nonblock", (test_callback_fn
*)pre_nonblock
, 0, generate_tests
},
5995 {"generate_corked", (test_callback_fn
*)pre_cork
, 0, generate_tests
},
5996 {"generate_corked_and_nonblock", (test_callback_fn
*)pre_cork_and_nonblock
, 0, generate_tests
},
5997 {"consistent_not", 0, 0, consistent_tests
},
5998 {"consistent_ketama", (test_callback_fn
*)pre_behavior_ketama
, 0, consistent_tests
},
5999 {"consistent_ketama_weighted", (test_callback_fn
*)pre_behavior_ketama_weighted
, 0, consistent_weighted_tests
},
6000 {"ketama_compat", 0, 0, ketama_compatibility
},
6001 {"test_hashes", 0, 0, hash_tests
},
6002 {"replication", (test_callback_fn
*)pre_replication
, 0, replication_tests
},
6003 {"replication_noblock", (test_callback_fn
*)pre_replication_noblock
, 0, replication_tests
},
6004 {"regression", 0, 0, regression_tests
},
6005 {"behaviors", 0, 0, behavior_tests
},
6006 {"regression_binary_vs_block", (test_callback_fn
*)key_setup
, (test_callback_fn
*)key_teardown
, regression_binary_vs_block
},
6007 {"error_conditions", 0, 0, error_conditions
},
6008 {"parser", 0, 0, parser_tests
},
6009 {"virtual buckets", 0, 0, virtual_bucket_tests
},
6010 {"memcached_server_get_last_disconnect", 0, 0, memcached_server_get_last_disconnect_tests
},
6011 {"touch", 0, 0, touch_tests
},
6015 #define TEST_PORT_BASE MEMCACHED_DEFAULT_PORT +10
6017 #include "tests/libmemcached_world.h"
6019 void get_world(Framework
*world
)
6021 world
->collections
= collection
;
6023 world
->_create
= (test_callback_create_fn
*)world_create
;
6024 world
->_destroy
= (test_callback_destroy_fn
*)world_destroy
;
6026 world
->item
._startup
= (test_callback_fn
*)world_test_startup
;
6027 world
->item
.set_pre((test_callback_fn
*)world_pre_run
);
6028 world
->item
.set_flush((test_callback_fn
*)world_flush
);
6029 world
->item
.set_post((test_callback_fn
*)world_post_run
);
6030 world
->_on_error
= (test_callback_error_fn
*)world_on_error
;
6032 world
->collection_startup
= (test_callback_fn
*)world_container_startup
;
6033 world
->collection_shutdown
= (test_callback_fn
*)world_container_shutdown
;
6035 world
->set_runner(&defualt_libmemcached_runner
);
6037 world
->set_socket();