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>
41 #if defined(HAVE_LIBUUID) && HAVE_LIBUUID
42 #include <uuid/uuid.h>
49 #include <libmemcached-1.0/memcached.h>
50 #include <libmemcached/is.h>
51 #include <libmemcached/server_instance.h>
53 #include <libhashkit-1.0/hashkit.h>
55 #include <libtest/memcached.hpp>
60 #include <semaphore.h>
64 #include <sys/types.h>
69 #include <libtest/server.h>
71 #include "clients/generator.h"
73 #define SMALL_STRING_LEN 1024
75 #include <libtest/test.hpp>
77 using namespace libtest
;
79 #include <libmemcached/util.h>
81 #include "tests/hash_results.h"
83 #include "tests/libmemcached-1.0/callback_counter.h"
84 #include "tests/libmemcached-1.0/fetch_all_results.h"
85 #include "tests/libmemcached-1.0/mem_functions.h"
86 #include "tests/libmemcached-1.0/setup_and_teardowns.h"
87 #include "tests/print.h"
88 #include "tests/debug.h"
90 #define UUID_STRING_MAXLENGTH 36
92 #include "tests/keys.hpp"
94 #include "libmemcached/instance.h"
96 static memcached_st
* create_single_instance_memcached(const memcached_st
*original_memc
, const char *options
)
99 If no options are given, copy over at least the binary flag.
101 char options_buffer
[1024]= { 0 };
104 if (memcached_is_binary(original_memc
))
106 snprintf(options_buffer
, sizeof(options_buffer
), "--BINARY");
111 * I only want to hit _one_ server so I know the number of requests I'm
112 * sending in the pipeline.
114 memcached_server_instance_st instance
= memcached_server_instance_by_position(original_memc
, 0);
116 char server_string
[1024];
117 int server_string_length
;
118 if (instance
->type
== MEMCACHED_CONNECTION_UNIX_SOCKET
)
122 server_string_length
= snprintf(server_string
, sizeof(server_string
), "--SOCKET=\"%s\" %s",
123 memcached_server_name(instance
), options
);
127 server_string_length
= snprintf(server_string
, sizeof(server_string
), "--SOCKET=\"%s\"",
128 memcached_server_name(instance
));
135 server_string_length
= snprintf(server_string
, sizeof(server_string
), "--server=%s:%d %s",
136 memcached_server_name(instance
), int(memcached_server_port(instance
)),
141 server_string_length
= snprintf(server_string
, sizeof(server_string
), "--server=%s:%d",
142 memcached_server_name(instance
), int(memcached_server_port(instance
)));
146 if (server_string_length
<= 0)
151 char errror_buffer
[1024];
152 if (memcached_failed(libmemcached_check_configuration(server_string
, server_string_length
, errror_buffer
, sizeof(errror_buffer
))))
154 Error
<< "Failed to parse (" << server_string
<< ") " << errror_buffer
;
158 return memcached(server_string
, server_string_length
);
162 test_return_t
init_test(memcached_st
*not_used
)
167 (void)memcached_create(&memc
);
168 memcached_free(&memc
);
173 #define TEST_PORT_COUNT 7
174 in_port_t test_ports
[TEST_PORT_COUNT
];
176 static memcached_return_t
server_display_function(const memcached_st
*ptr
,
177 memcached_server_instance_st server
,
181 size_t bigger
= *((size_t *)(context
));
183 fatal_assert(bigger
<= memcached_server_port(server
));
184 *((size_t *)(context
))= memcached_server_port(server
);
186 return MEMCACHED_SUCCESS
;
189 static memcached_return_t
dump_server_information(const memcached_st
*ptr
,
190 memcached_server_instance_st instance
,
194 FILE *stream
= (FILE *)context
;
197 fprintf(stream
, "Memcached Server: %s %u Version %u.%u.%u\n",
198 memcached_server_name(instance
),
199 memcached_server_port(instance
),
200 instance
->major_version
,
201 instance
->minor_version
,
202 instance
->micro_version
);
204 return MEMCACHED_SUCCESS
;
207 test_return_t
server_sort_test(memcached_st
*ptr
)
209 size_t bigger
= 0; /* Prime the value for the test_true in server_display_function */
211 memcached_return_t rc
;
212 memcached_server_fn callbacks
[1];
213 memcached_st
*local_memc
;
216 local_memc
= memcached_create(NULL
);
217 test_true(local_memc
);
218 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
220 for (uint32_t x
= 0; x
< TEST_PORT_COUNT
; x
++)
222 test_ports
[x
]= (in_port_t
)random() % 64000;
223 rc
= memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0);
224 test_compare(memcached_server_count(local_memc
), x
+1);
226 test_true(memcached_server_list_count(memcached_server_list(local_memc
)) == x
+1);
228 test_compare(MEMCACHED_SUCCESS
, rc
);
231 callbacks
[0]= server_display_function
;
232 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
235 memcached_free(local_memc
);
240 test_return_t
server_sort2_test(memcached_st
*ptr
)
242 size_t bigger
= 0; /* Prime the value for the test_true in server_display_function */
243 memcached_server_fn callbacks
[1];
244 memcached_st
*local_memc
;
245 memcached_server_instance_st instance
;
248 local_memc
= memcached_create(NULL
);
249 test_true(local_memc
);
250 test_compare(MEMCACHED_SUCCESS
,
251 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1));
253 test_compare(MEMCACHED_SUCCESS
,
254 memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43043, 0));
255 instance
= memcached_server_instance_by_position(local_memc
, 0);
256 test_compare(in_port_t(43043), memcached_server_port(instance
));
258 test_compare(MEMCACHED_SUCCESS
,
259 memcached_server_add_with_weight(local_memc
, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43042, 0));
261 instance
= memcached_server_instance_by_position(local_memc
, 0);
262 test_compare(in_port_t(43042), memcached_server_port(instance
));
264 instance
= memcached_server_instance_by_position(local_memc
, 1);
265 test_compare(in_port_t(43043), memcached_server_port(instance
));
267 callbacks
[0]= server_display_function
;
268 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
271 memcached_free(local_memc
);
276 test_return_t
memcached_server_remove_test(memcached_st
*)
278 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";
281 test_compare(MEMCACHED_SUCCESS
,
282 libmemcached_check_configuration(server_string
, strlen(server_string
), buffer
, sizeof(buffer
)));
283 memcached_st
*memc
= memcached(server_string
, strlen(server_string
));
286 memcached_server_fn callbacks
[1];
287 callbacks
[0]= server_print_callback
;
288 memcached_server_cursor(memc
, callbacks
, NULL
, 1);
290 memcached_free(memc
);
295 static memcached_return_t
server_display_unsort_function(const memcached_st
*,
296 memcached_server_instance_st server
,
300 uint32_t x
= *((uint32_t *)(context
));
302 if (! (test_ports
[x
] == memcached_server_port(server
)))
304 fprintf(stderr
, "%lu -> %lu\n", (unsigned long)test_ports
[x
], (unsigned long)memcached_server_port(server
));
305 return MEMCACHED_FAILURE
;
308 *((uint32_t *)(context
))= ++x
;
310 return MEMCACHED_SUCCESS
;
313 test_return_t
server_unsort_test(memcached_st
*ptr
)
315 size_t counter
= 0; /* Prime the value for the test_true in server_display_function */
316 size_t bigger
= 0; /* Prime the value for the test_true in server_display_function */
317 memcached_server_fn callbacks
[1];
318 memcached_st
*local_memc
;
321 local_memc
= memcached_create(NULL
);
322 test_true(local_memc
);
324 for (uint32_t x
= 0; x
< TEST_PORT_COUNT
; x
++)
326 test_ports
[x
]= (in_port_t
)(random() % 64000);
327 test_compare(MEMCACHED_SUCCESS
,
328 memcached_server_add_with_weight(local_memc
, "localhost", test_ports
[x
], 0));
329 test_compare(memcached_server_count(local_memc
), x
+1);
331 test_true(memcached_server_list_count(memcached_server_list(local_memc
)) == x
+1);
335 callbacks
[0]= server_display_unsort_function
;
336 memcached_server_cursor(local_memc
, callbacks
, (void *)&counter
, 1);
338 /* Now we sort old data! */
339 memcached_behavior_set(local_memc
, MEMCACHED_BEHAVIOR_SORT_HOSTS
, 1);
340 callbacks
[0]= server_display_function
;
341 memcached_server_cursor(local_memc
, callbacks
, (void *)&bigger
, 1);
344 memcached_free(local_memc
);
349 test_return_t
allocation_test(memcached_st
*not_used
)
353 memc
= memcached_create(NULL
);
355 memcached_free(memc
);
360 test_return_t
clone_test(memcached_st
*memc
)
364 memcached_st
*memc_clone
;
365 memc_clone
= memcached_clone(NULL
, NULL
);
366 test_true(memc_clone
);
367 memcached_free(memc_clone
);
370 /* Can we init from null? */
372 memcached_st
*memc_clone
;
373 memc_clone
= memcached_clone(NULL
, memc
);
374 test_true(memc_clone
);
377 test_true(memc_clone
->allocators
.free
== memc
->allocators
.free
);
378 test_true(memc_clone
->allocators
.malloc
== memc
->allocators
.malloc
);
379 test_true(memc_clone
->allocators
.realloc
== memc
->allocators
.realloc
);
380 test_true(memc_clone
->allocators
.calloc
== memc
->allocators
.calloc
);
383 test_true(memc_clone
->connect_timeout
== memc
->connect_timeout
);
384 test_true(memc_clone
->delete_trigger
== memc
->delete_trigger
);
385 test_true(memc_clone
->distribution
== memc
->distribution
);
386 { // Test all of the flags
387 test_true(memc_clone
->flags
.no_block
== memc
->flags
.no_block
);
388 test_true(memc_clone
->flags
.tcp_nodelay
== memc
->flags
.tcp_nodelay
);
389 test_true(memc_clone
->flags
.support_cas
== memc
->flags
.support_cas
);
390 test_true(memc_clone
->flags
.buffer_requests
== memc
->flags
.buffer_requests
);
391 test_true(memc_clone
->flags
.use_sort_hosts
== memc
->flags
.use_sort_hosts
);
392 test_true(memc_clone
->flags
.verify_key
== memc
->flags
.verify_key
);
393 test_true(memc_clone
->ketama
.weighted
== memc
->ketama
.weighted
);
394 test_true(memc_clone
->flags
.binary_protocol
== memc
->flags
.binary_protocol
);
395 test_true(memc_clone
->flags
.hash_with_namespace
== memc
->flags
.hash_with_namespace
);
396 test_true(memc_clone
->flags
.reply
== memc
->flags
.reply
);
397 test_true(memc_clone
->flags
.use_udp
== memc
->flags
.use_udp
);
398 test_true(memc_clone
->flags
.auto_eject_hosts
== memc
->flags
.auto_eject_hosts
);
399 test_true(memc_clone
->flags
.randomize_replica_read
== memc
->flags
.randomize_replica_read
);
401 test_true(memc_clone
->get_key_failure
== memc
->get_key_failure
);
402 test_true(hashkit_compare(&memc_clone
->hashkit
, &memc
->hashkit
));
403 test_true(memc_clone
->io_bytes_watermark
== memc
->io_bytes_watermark
);
404 test_true(memc_clone
->io_msg_watermark
== memc
->io_msg_watermark
);
405 test_true(memc_clone
->io_key_prefetch
== memc
->io_key_prefetch
);
406 test_true(memc_clone
->on_cleanup
== memc
->on_cleanup
);
407 test_true(memc_clone
->on_clone
== memc
->on_clone
);
408 test_true(memc_clone
->poll_timeout
== memc
->poll_timeout
);
409 test_true(memc_clone
->rcv_timeout
== memc
->rcv_timeout
);
410 test_true(memc_clone
->recv_size
== memc
->recv_size
);
411 test_true(memc_clone
->retry_timeout
== memc
->retry_timeout
);
412 test_true(memc_clone
->send_size
== memc
->send_size
);
413 test_true(memc_clone
->server_failure_limit
== memc
->server_failure_limit
);
414 test_true(memc_clone
->snd_timeout
== memc
->snd_timeout
);
415 test_true(memc_clone
->user_data
== memc
->user_data
);
417 memcached_free(memc_clone
);
420 /* Can we init from struct? */
422 memcached_st declared_clone
;
423 memcached_st
*memc_clone
;
424 memset(&declared_clone
, 0 , sizeof(memcached_st
));
425 memc_clone
= memcached_clone(&declared_clone
, NULL
);
426 test_true(memc_clone
);
427 memcached_free(memc_clone
);
430 /* Can we init from struct? */
432 memcached_st declared_clone
;
433 memcached_st
*memc_clone
;
434 memset(&declared_clone
, 0 , sizeof(memcached_st
));
435 memc_clone
= memcached_clone(&declared_clone
, memc
);
436 test_true(memc_clone
);
437 memcached_free(memc_clone
);
443 test_return_t
userdata_test(memcached_st
*memc
)
446 test_false(memcached_set_user_data(memc
, foo
));
447 test_true(memcached_get_user_data(memc
) == foo
);
448 test_true(memcached_set_user_data(memc
, NULL
) == foo
);
453 test_return_t
connection_test(memcached_st
*memc
)
455 test_compare(MEMCACHED_SUCCESS
,
456 memcached_server_add_with_weight(memc
, "localhost", 0, 0));
461 test_return_t
libmemcached_string_behavior_test(memcached_st
*)
463 for (int x
= MEMCACHED_BEHAVIOR_NO_BLOCK
; x
< int(MEMCACHED_BEHAVIOR_MAX
); ++x
)
465 test_true(libmemcached_string_behavior(memcached_behavior_t(x
)));
467 test_compare(37, int(MEMCACHED_BEHAVIOR_MAX
));
472 test_return_t
libmemcached_string_distribution_test(memcached_st
*)
474 for (int x
= MEMCACHED_DISTRIBUTION_MODULA
; x
< int(MEMCACHED_DISTRIBUTION_CONSISTENT_MAX
); ++x
)
476 test_true(libmemcached_string_distribution(memcached_server_distribution_t(x
)));
478 test_compare(7, int(MEMCACHED_DISTRIBUTION_CONSISTENT_MAX
));
483 test_return_t
memcached_return_t_TEST(memcached_st
*memc
)
485 uint32_t values
[] = { 851992627U, 2337886783U, 4109241422U, 4001849190U,
486 982370485U, 1263635348U, 4242906218U, 3829656100U,
487 1891735253U, 334139633U, 2257084983U, 3351789013U,
488 13199785U, 2542027183U, 1097051614U, 199566778U,
489 2748246961U, 2465192557U, 1664094137U, 2405439045U,
490 1842224848U, 692413798U, 3479807801U, 919913813U,
491 4269430871U, 610793021U, 527273862U, 1437122909U,
492 2300930706U, 2943759320U, 674306647U, 2400528935U,
493 54481931U, 4186304426U, 1741088401U, 2979625118U,
494 4159057246U, 3425930182U, 2593724503U, 1868899624U,
495 1769812374U, 2302537950U, 1110330676U, 3365377466U,
496 1336171666U, 3021258493U, 2334992265U, 3861994737U,
497 3582734124U, 3365377466U };
499 // You have updated the memcache_error messages but not updated docs/tests.
500 for (int rc
= int(MEMCACHED_SUCCESS
); rc
< int(MEMCACHED_MAXIMUM_RETURN
); ++rc
)
503 const char *msg
= memcached_strerror(memc
, memcached_return_t(rc
));
504 hash_val
= memcached_generate_hash_value(msg
, strlen(msg
),
505 MEMCACHED_HASH_JENKINS
);
506 if (values
[rc
] != hash_val
)
508 fprintf(stderr
, "\n\nYou have updated memcached_return_t without updating the memcached_return_t_TEST\n");
509 fprintf(stderr
, "%u, %s, (%u)\n\n", (uint32_t)rc
, memcached_strerror(memc
, memcached_return_t(rc
)), hash_val
);
511 test_compare(values
[rc
], hash_val
);
513 test_compare(49, int(MEMCACHED_MAXIMUM_RETURN
));
518 test_return_t
set_test(memcached_st
*memc
)
520 memcached_return_t rc
= memcached_set(memc
,
521 test_literal_param("foo"),
522 test_literal_param("when we sanitize"),
523 time_t(0), (uint32_t)0);
524 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
529 test_return_t
append_test(memcached_st
*memc
)
531 memcached_return_t rc
;
532 const char *in_value
= "we";
536 test_compare(MEMCACHED_SUCCESS
,
537 memcached_flush(memc
, 0));
539 test_compare(MEMCACHED_SUCCESS
,
541 test_literal_param(__func__
),
542 in_value
, strlen(in_value
),
543 time_t(0), uint32_t(0)));
545 test_compare(MEMCACHED_SUCCESS
,
546 memcached_append(memc
,
547 test_literal_param(__func__
),
548 " the", strlen(" the"),
549 time_t(0), uint32_t(0)));
551 test_compare(MEMCACHED_SUCCESS
,
552 memcached_append(memc
,
553 test_literal_param(__func__
),
554 " people", strlen(" people"),
555 time_t(0), uint32_t(0)));
557 char *out_value
= memcached_get(memc
,
558 test_literal_param(__func__
),
559 &value_length
, &flags
, &rc
);
560 test_memcmp(out_value
, "we the people", strlen("we the people"));
561 test_compare(strlen("we the people"), value_length
);
562 test_compare(MEMCACHED_SUCCESS
, rc
);
568 test_return_t
append_binary_test(memcached_st
*memc
)
570 uint32_t store_list
[] = { 23, 56, 499, 98, 32847, 0 };
572 test_compare(MEMCACHED_SUCCESS
,
573 memcached_flush(memc
, 0));
575 test_compare(MEMCACHED_SUCCESS
,
577 test_literal_param(__func__
),
579 time_t(0), uint32_t(0)));
582 for (uint32_t x
= 0; store_list
[x
] ; x
++)
584 test_compare(MEMCACHED_SUCCESS
,
585 memcached_append(memc
,
586 test_literal_param(__func__
),
587 (char *)&store_list
[x
], sizeof(uint32_t),
588 time_t(0), uint32_t(0)));
594 memcached_return_t rc
;
595 uint32_t *value
= (uint32_t *)memcached_get(memc
,
596 test_literal_param(__func__
),
597 &value_length
, &flags
, &rc
);
598 test_compare(value_length
, sizeof(uint32_t) * count
);
599 test_compare(MEMCACHED_SUCCESS
, rc
);
601 for (uint32_t counter
= count
, *ptr
= value
; counter
; counter
--)
603 test_compare(*ptr
, store_list
[count
- counter
]);
611 test_return_t
memcached_mget_mixed_memcached_get_TEST(memcached_st
*memc
)
615 for (libtest::vchar_ptr_t::iterator iter
= keys
.begin();
619 test_compare_hint(MEMCACHED_SUCCESS
,
623 time_t(0), uint32_t(0)),
624 memcached_last_error_message(memc
));
627 for (ptrdiff_t loop
= 0; loop
< 20; loop
++)
631 test_compare(MEMCACHED_SUCCESS
,
632 memcached_mget(memc
, keys
.keys_ptr(), keys
.lengths_ptr(), keys
.size()));
634 memcached_result_st
*results
= memcached_result_create(memc
, NULL
);
637 size_t result_count
= 0;
638 memcached_return_t rc
;
639 while (memcached_fetch_result(memc
, results
, &rc
))
643 test_true(keys
.size() >= result_count
);
647 int which_key
= random() %keys
.size();
650 memcached_return_t rc
;
651 char *out_value
= memcached_get(memc
, keys
.key_at(which_key
), keys
.length_at(which_key
),
652 &value_length
, &flags
, &rc
);
653 if (rc
== MEMCACHED_NOTFOUND
)
654 { } // It is possible that the value has been purged.
657 test_compare(MEMCACHED_SUCCESS
, rc
);
659 test_null(out_value
);
660 test_zero(value_length
);
668 test_return_t
cas2_test(memcached_st
*memc
)
670 const char *keys
[]= {"fudge", "son", "food"};
671 size_t key_length
[]= {5, 3, 4};
672 const char *value
= "we the people";
673 size_t value_length
= strlen("we the people");
675 test_compare(MEMCACHED_SUCCESS
, memcached_flush(memc
, 0));
677 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, true));
679 for (uint32_t x
= 0; x
< 3; x
++)
681 test_compare(MEMCACHED_SUCCESS
,
682 memcached_set(memc
, keys
[x
], key_length
[x
],
683 keys
[x
], key_length
[x
],
684 time_t(50), uint32_t(9)));
687 test_compare(MEMCACHED_SUCCESS
,
688 memcached_mget(memc
, keys
, key_length
, 3));
690 memcached_result_st
*results
= memcached_result_create(memc
, NULL
);
693 memcached_return_t rc
;
694 results
= memcached_fetch_result(memc
, results
, &rc
);
696 test_true(results
->item_cas
);
697 test_compare(MEMCACHED_SUCCESS
, rc
);
698 test_true(memcached_result_cas(results
));
700 test_memcmp(value
, "we the people", strlen("we the people"));
701 test_compare(strlen("we the people"), value_length
);
702 test_compare(MEMCACHED_SUCCESS
, rc
);
704 memcached_result_free(results
);
709 test_return_t
cas_test(memcached_st
*memc
)
711 const char* keys
[2] = { __func__
, NULL
};
712 size_t keylengths
[2] = { strlen(__func__
), 0 };
714 memcached_result_st results_obj
;
716 test_compare(MEMCACHED_SUCCESS
, memcached_flush(memc
, 0));
718 test_skip(true, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, true));
720 test_compare(MEMCACHED_SUCCESS
,
722 test_literal_param(__func__
),
723 test_literal_param("we the people"),
724 (time_t)0, (uint32_t)0));
726 test_compare(MEMCACHED_SUCCESS
,
727 memcached_mget(memc
, keys
, keylengths
, 1));
729 memcached_result_st
*results
= memcached_result_create(memc
, &results_obj
);
732 memcached_return_t rc
;
733 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
735 test_compare(MEMCACHED_SUCCESS
, rc
);
736 test_true(memcached_result_cas(results
));
737 test_memcmp("we the people", memcached_result_value(results
), test_literal_param_size("we the people"));
738 test_compare(test_literal_param_size("we the people"),
739 strlen(memcached_result_value(results
)));
741 uint64_t cas
= memcached_result_cas(results
);
744 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
745 test_true(rc
== MEMCACHED_END
);
746 test_true(results
== NULL
);
749 test_compare(MEMCACHED_SUCCESS
,
751 test_literal_param(__func__
),
752 test_literal_param("change the value"),
756 * The item will have a new cas value, so try to set it again with the old
757 * value. This should fail!
759 test_compare(MEMCACHED_DATA_EXISTS
,
761 test_literal_param(__func__
),
762 test_literal_param("change the value"),
765 memcached_result_free(&results_obj
);
771 test_return_t
prepend_test(memcached_st
*memc
)
773 const char *key
= "fig";
774 const char *value
= "people";
776 test_compare(MEMCACHED_SUCCESS
,
777 memcached_flush(memc
, 0));
779 test_compare(MEMCACHED_SUCCESS
,
780 memcached_set(memc
, key
, strlen(key
),
781 value
, strlen(value
),
782 time_t(0), uint32_t(0)));
784 test_compare(MEMCACHED_SUCCESS
,
785 memcached_prepend(memc
, key
, strlen(key
),
786 "the ", strlen("the "),
787 time_t(0), uint32_t(0)));
789 test_compare(MEMCACHED_SUCCESS
,
790 memcached_prepend(memc
, key
, strlen(key
),
791 "we ", strlen("we "),
792 time_t(0), uint32_t(0)));
796 memcached_return_t rc
;
797 char *out_value
= memcached_get(memc
, key
, strlen(key
),
798 &value_length
, &flags
, &rc
);
799 test_memcmp(out_value
, "we the people", strlen("we the people"));
800 test_compare(strlen("we the people"), value_length
);
801 test_compare(MEMCACHED_SUCCESS
, rc
);
808 Set the value, then quit to make sure it is flushed.
809 Come back in and test that add fails.
811 test_return_t
memcached_add_SUCCESS_TEST(memcached_st
*memc
)
813 memcached_return_t rc
;
814 test_null(memcached_get(memc
, test_literal_param(__func__
), NULL
, NULL
, &rc
));
815 test_compare(MEMCACHED_NOTFOUND
, rc
);
817 test_compare(MEMCACHED_SUCCESS
,
819 test_literal_param(__func__
),
820 test_literal_param("try something else"),
821 time_t(0), uint32_t(0)));
827 Set the value, then quit to make sure it is flushed.
828 Come back in and test that add fails.
830 test_return_t
add_test(memcached_st
*memc
)
832 test_compare(return_value_based_on_buffering(memc
),
834 test_literal_param(__func__
),
835 test_literal_param("when we sanitize"),
836 time_t(0), uint32_t(0)));
838 memcached_quit(memc
);
842 memcached_return_t rc
;
843 char *check_value
= memcached_get(memc
,
844 test_literal_param(__func__
),
845 &value_length
, &flags
, &rc
);
846 test_memcmp(check_value
, "when we sanitize", strlen("when we sanitize"));
847 test_compare(test_literal_param_size("when we sanitize"), value_length
);
848 test_compare(MEMCACHED_SUCCESS
, rc
);
851 test_compare(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) ? MEMCACHED_DATA_EXISTS
: MEMCACHED_NOTSTORED
,
853 test_literal_param(__func__
),
854 test_literal_param("try something else"),
855 time_t(0), uint32_t(0)));
861 ** There was a problem of leaking filedescriptors in the initial release
862 ** of MacOSX 10.5. This test case triggers the problem. On some Solaris
863 ** systems it seems that the kernel is slow on reclaiming the resources
864 ** because the connects starts to time out (the test doesn't do much
865 ** anyway, so just loop 10 iterations)
867 test_return_t
add_wrapper(memcached_st
*memc
)
869 unsigned int max
= 10000;
877 for (uint32_t x
= 0; x
< max
; x
++)
885 test_return_t
replace_test(memcached_st
*memc
)
887 test_compare(return_value_based_on_buffering(memc
),
889 test_literal_param(__func__
),
890 test_literal_param("when we sanitize"),
891 time_t(0), uint32_t(0)));
893 test_compare(MEMCACHED_SUCCESS
,
894 memcached_replace(memc
,
895 test_literal_param(__func__
),
896 test_literal_param("first we insert some data"),
897 time_t(0), uint32_t(0)));
902 test_return_t
delete_test(memcached_st
*memc
)
904 test_compare(return_value_based_on_buffering(memc
),
906 test_literal_param(__func__
),
907 test_literal_param("when we sanitize"),
908 time_t(0), uint32_t(0)));
910 test_compare(return_value_based_on_buffering(memc
),
911 memcached_delete(memc
,
912 test_literal_param(__func__
),
918 test_return_t
flush_test(memcached_st
*memc
)
920 uint64_t query_id
= memcached_query_id(memc
);
921 test_compare(MEMCACHED_SUCCESS
,
922 memcached_flush(memc
, 0));
923 test_compare(query_id
+1, memcached_query_id(memc
));
928 static memcached_return_t
server_function(const memcached_st
*,
929 memcached_server_instance_st
,
933 return MEMCACHED_SUCCESS
;
936 test_return_t
memcached_server_cursor_test(memcached_st
*memc
)
939 strncpy(context
, "foo bad", sizeof(context
));
940 memcached_server_fn callbacks
[1];
942 callbacks
[0]= server_function
;
943 memcached_server_cursor(memc
, callbacks
, context
, 1);
947 test_return_t
bad_key_test(memcached_st
*memc
)
949 memcached_return_t rc
;
950 const char *key
= "foo bad";
953 uint64_t query_id
= memcached_query_id(memc
);
955 // Just skip if we are in binary mode.
956 test_skip(false, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
));
958 test_compare(query_id
, memcached_query_id(memc
)); // We should not increase the query_id for memcached_behavior_get()
960 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
961 test_true(memc_clone
);
963 query_id
= memcached_query_id(memc_clone
);
964 test_compare(MEMCACHED_SUCCESS
,
965 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, true));
966 test_compare(query_id
, memcached_query_id(memc_clone
)); // We should not increase the query_id for memcached_behavior_set()
968 /* All keys are valid in the binary protocol (except for length) */
969 if (memcached_behavior_get(memc_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == false)
971 uint64_t before_query_id
= memcached_query_id(memc_clone
);
973 size_t string_length
;
974 char *string
= memcached_get(memc_clone
, key
, strlen(key
),
975 &string_length
, &flags
, &rc
);
976 test_compare(MEMCACHED_BAD_KEY_PROVIDED
, rc
);
977 test_zero(string_length
);
980 test_compare(before_query_id
+1, memcached_query_id(memc_clone
));
982 query_id
= memcached_query_id(memc_clone
);
983 test_compare(MEMCACHED_SUCCESS
,
984 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, false));
985 test_compare(query_id
, memcached_query_id(memc_clone
)); // We should not increase the query_id for memcached_behavior_set()
987 size_t string_length
;
988 char *string
= memcached_get(memc_clone
, key
, strlen(key
),
989 &string_length
, &flags
, &rc
);
990 test_compare(MEMCACHED_NOTFOUND
, rc
);
991 test_zero(string_length
);
995 /* Test multi key for bad keys */
996 const char *keys
[] = { "GoodKey", "Bad Key", "NotMine" };
997 size_t key_lengths
[] = { 7, 7, 7 };
998 query_id
= memcached_query_id(memc_clone
);
999 test_compare(MEMCACHED_SUCCESS
,
1000 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, true));
1001 test_compare(query_id
, memcached_query_id(memc_clone
));
1003 query_id
= memcached_query_id(memc_clone
);
1004 test_compare(MEMCACHED_BAD_KEY_PROVIDED
,
1005 memcached_mget(memc_clone
, keys
, key_lengths
, 3));
1006 test_compare(query_id
+1, memcached_query_id(memc_clone
));
1008 query_id
= memcached_query_id(memc_clone
);
1009 // Grouping keys are not required to follow normal key behaviors
1010 test_compare(MEMCACHED_SUCCESS
,
1011 memcached_mget_by_key(memc_clone
, "foo daddy", 9, keys
, key_lengths
, 1));
1012 test_compare(query_id
+1, memcached_query_id(memc_clone
));
1014 /* The following test should be moved to the end of this function when the
1015 memcached server is updated to allow max size length of the keys in the
1018 test_compare(MEMCACHED_SUCCESS
,
1019 memcached_callback_set(memc_clone
, MEMCACHED_CALLBACK_NAMESPACE
, NULL
));
1021 libtest::vchar_t longkey
;
1023 libtest::vchar_t::iterator it
= longkey
.begin();
1024 longkey
.insert(it
, MEMCACHED_MAX_KEY
, 'a');
1027 test_compare(longkey
.size(), size_t(MEMCACHED_MAX_KEY
));
1029 size_t string_length
;
1031 test_null(memcached_get(memc_clone
, &longkey
[0], longkey
.size() -1, &string_length
, &flags
, &rc
));
1032 test_compare(MEMCACHED_NOTFOUND
, rc
);
1033 test_zero(string_length
);
1035 test_null(memcached_get(memc_clone
, &longkey
[0], longkey
.size(), &string_length
, &flags
, &rc
));
1036 test_compare(MEMCACHED_BAD_KEY_PROVIDED
, rc
);
1037 test_zero(string_length
);
1041 /* Make sure zero length keys are marked as bad */
1043 test_compare(MEMCACHED_SUCCESS
,
1044 memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, true));
1045 size_t string_length
;
1046 char *string
= memcached_get(memc_clone
, key
, 0,
1047 &string_length
, &flags
, &rc
);
1048 test_compare(MEMCACHED_BAD_KEY_PROVIDED
, rc
);
1049 test_zero(string_length
);
1053 memcached_free(memc_clone
);
1055 return TEST_SUCCESS
;
1058 #define READ_THROUGH_VALUE "set for me"
1059 static memcached_return_t
read_through_trigger(memcached_st
*, // memc
1061 size_t, // key_length,
1062 memcached_result_st
*result
)
1064 return memcached_result_set_value(result
, READ_THROUGH_VALUE
, strlen(READ_THROUGH_VALUE
));
1067 #ifndef __INTEL_COMPILER
1068 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
1071 test_return_t
read_through(memcached_st
*memc
)
1073 memcached_trigger_key_fn cb
= (memcached_trigger_key_fn
)read_through_trigger
;
1075 size_t string_length
;
1077 memcached_return_t rc
;
1078 char *string
= memcached_get(memc
,
1079 test_literal_param(__func__
),
1080 &string_length
, &flags
, &rc
);
1082 test_compare(MEMCACHED_NOTFOUND
, rc
);
1083 test_false(string_length
);
1086 test_compare(MEMCACHED_SUCCESS
,
1087 memcached_callback_set(memc
, MEMCACHED_CALLBACK_GET_FAILURE
, *(void **)&cb
));
1089 string
= memcached_get(memc
,
1090 test_literal_param(__func__
),
1091 &string_length
, &flags
, &rc
);
1093 test_compare(MEMCACHED_SUCCESS
, rc
);
1094 test_compare(sizeof(READ_THROUGH_VALUE
) -1, string_length
);
1095 test_compare(0, string
[sizeof(READ_THROUGH_VALUE
) -1]);
1096 test_strcmp(READ_THROUGH_VALUE
, string
);
1099 string
= memcached_get(memc
,
1100 test_literal_param(__func__
),
1101 &string_length
, &flags
, &rc
);
1103 test_compare(MEMCACHED_SUCCESS
, rc
);
1105 test_compare(string_length
, sizeof(READ_THROUGH_VALUE
) -1);
1106 test_true(string
[sizeof(READ_THROUGH_VALUE
) -1] == 0);
1107 test_strcmp(READ_THROUGH_VALUE
, string
);
1110 return TEST_SUCCESS
;
1113 test_return_t
set_test2(memcached_st
*memc
)
1115 for (uint32_t x
= 0; x
< 10; x
++)
1117 test_compare(return_value_based_on_buffering(memc
),
1119 test_literal_param("foo"),
1120 test_literal_param("train in the brain"),
1121 time_t(0), uint32_t(0)));
1124 return TEST_SUCCESS
;
1127 test_return_t
set_test3(memcached_st
*memc
)
1129 size_t value_length
= 8191;
1131 libtest::vchar_t value
;
1132 value
.reserve(value_length
);
1133 for (uint32_t x
= 0; x
< value_length
; x
++)
1135 value
.push_back(char(x
% 127));
1138 /* The dump test relies on there being at least 32 items in memcached */
1139 for (uint32_t x
= 0; x
< 32; x
++)
1143 snprintf(key
, sizeof(key
), "foo%u", x
);
1145 uint64_t query_id
= memcached_query_id(memc
);
1146 test_compare(return_value_based_on_buffering(memc
),
1147 memcached_set(memc
, key
, strlen(key
),
1148 &value
[0], value
.size(),
1149 time_t(0), uint32_t(0)));
1150 test_compare(query_id
+1, memcached_query_id(memc
));
1153 return TEST_SUCCESS
;
1156 test_return_t
mget_end(memcached_st
*memc
)
1158 const char *keys
[]= { "foo", "foo2" };
1159 size_t lengths
[]= { 3, 4 };
1160 const char *values
[]= { "fjord", "41" };
1163 for (size_t x
= 0; x
< test_array_length(keys
); x
++)
1165 test_compare(MEMCACHED_SUCCESS
,
1167 keys
[x
], lengths
[x
],
1168 values
[x
], strlen(values
[x
]),
1169 time_t(0), uint32_t(0)));
1173 size_t string_length
;
1176 // retrieve both via mget
1177 test_compare(MEMCACHED_SUCCESS
,
1178 memcached_mget(memc
,
1180 test_array_length(keys
)));
1182 char key
[MEMCACHED_MAX_KEY
];
1184 memcached_return_t rc
;
1186 // this should get both
1187 for (size_t x
= 0; x
< test_array_length(keys
); x
++)
1189 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
,
1191 test_compare(MEMCACHED_SUCCESS
, rc
);
1193 if (key_length
== 4)
1198 test_compare(string_length
, strlen(values
[val
]));
1199 test_true(strncmp(values
[val
], string
, string_length
) == 0);
1203 // this should indicate end
1204 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1205 test_compare(MEMCACHED_END
, rc
);
1209 test_compare(MEMCACHED_SUCCESS
,
1210 memcached_mget(memc
, keys
, lengths
, 1));
1212 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1213 test_compare(key_length
, lengths
[0]);
1214 test_true(strncmp(keys
[0], key
, key_length
) == 0);
1215 test_compare(string_length
, strlen(values
[0]));
1216 test_true(strncmp(values
[0], string
, string_length
) == 0);
1217 test_compare(MEMCACHED_SUCCESS
, rc
);
1220 // this should indicate end
1221 string
= memcached_fetch(memc
, key
, &key_length
, &string_length
, &flags
, &rc
);
1222 test_compare(MEMCACHED_END
, rc
);
1225 return TEST_SUCCESS
;
1228 /* Do not copy the style of this code, I just access hosts to testthis function */
1229 test_return_t
stats_servername_test(memcached_st
*memc
)
1231 memcached_stat_st memc_stat
;
1232 memcached_server_instance_st instance
=
1233 memcached_server_instance_by_position(memc
, 0);
1235 if (LIBMEMCACHED_WITH_SASL_SUPPORT
and memcached_get_sasl_callbacks(memc
))
1237 return TEST_SKIPPED
;
1240 test_compare(MEMCACHED_SUCCESS
, memcached_stat_servername(&memc_stat
, NULL
,
1241 memcached_server_name(instance
),
1242 memcached_server_port(instance
)));
1244 return TEST_SUCCESS
;
1247 test_return_t
increment_test(memcached_st
*memc
)
1249 uint64_t new_number
;
1251 test_compare(MEMCACHED_SUCCESS
,
1253 test_literal_param("number"),
1254 test_literal_param("0"),
1255 (time_t)0, (uint32_t)0));
1257 test_compare(MEMCACHED_SUCCESS
,
1258 memcached_increment(memc
, test_literal_param("number"), 1, &new_number
));
1259 test_compare(uint64_t(1), new_number
);
1261 test_compare(MEMCACHED_SUCCESS
,
1262 memcached_increment(memc
, test_literal_param("number"), 1, &new_number
));
1263 test_compare(uint64_t(2), new_number
);
1265 return TEST_SUCCESS
;
1268 test_return_t
increment_with_initial_test(memcached_st
*memc
)
1270 test_skip(true, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
));
1272 uint64_t new_number
;
1273 uint64_t initial
= 0;
1275 test_compare(MEMCACHED_SUCCESS
, memcached_flush_buffers(memc
));
1277 test_compare(MEMCACHED_SUCCESS
,
1278 memcached_increment_with_initial(memc
, test_literal_param("number"), 1, initial
, 0, &new_number
));
1279 test_compare(new_number
, initial
);
1281 test_compare(MEMCACHED_SUCCESS
,
1282 memcached_increment_with_initial(memc
, test_literal_param("number"), 1, initial
, 0, &new_number
));
1283 test_compare(new_number
, (initial
+1));
1285 return TEST_SUCCESS
;
1288 test_return_t
decrement_test(memcached_st
*memc
)
1290 test_compare(return_value_based_on_buffering(memc
),
1292 test_literal_param(__func__
),
1293 test_literal_param("3"),
1294 time_t(0), uint32_t(0)));
1296 // Make sure we flush the value we just set
1297 test_compare(MEMCACHED_SUCCESS
, memcached_flush_buffers(memc
));
1299 uint64_t new_number
;
1300 test_compare(MEMCACHED_SUCCESS
,
1301 memcached_decrement(memc
,
1302 test_literal_param(__func__
),
1304 test_compare(uint64_t(2), new_number
);
1306 test_compare(MEMCACHED_SUCCESS
,
1307 memcached_decrement(memc
,
1308 test_literal_param(__func__
),
1310 test_compare(uint64_t(1), new_number
);
1312 return TEST_SUCCESS
;
1315 test_return_t
decrement_with_initial_test(memcached_st
*memc
)
1317 test_skip(true, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
));
1319 uint64_t initial
= 3;
1321 test_compare(MEMCACHED_SUCCESS
, memcached_flush_buffers(memc
));
1323 uint64_t new_number
;
1324 test_compare(MEMCACHED_SUCCESS
,
1325 memcached_decrement_with_initial(memc
,
1326 test_literal_param(__func__
),
1329 test_compare(new_number
, initial
);
1331 test_compare(MEMCACHED_SUCCESS
,
1332 memcached_decrement_with_initial(memc
,
1333 test_literal_param(__func__
),
1336 test_compare(new_number
, (initial
- 1));
1338 return TEST_SUCCESS
;
1341 test_return_t
increment_by_key_test(memcached_st
*memc
)
1343 const char *master_key
= "foo";
1344 const char *key
= "number";
1345 const char *value
= "0";
1347 test_compare(return_value_based_on_buffering(memc
),
1348 memcached_set_by_key(memc
, master_key
, strlen(master_key
),
1350 value
, strlen(value
),
1351 time_t(0), uint32_t(0)));
1353 // Make sure we flush the value we just set
1354 test_compare(MEMCACHED_SUCCESS
, memcached_flush_buffers(memc
));
1356 uint64_t new_number
;
1357 test_compare(MEMCACHED_SUCCESS
,
1358 memcached_increment_by_key(memc
, master_key
, strlen(master_key
),
1359 key
, strlen(key
), 1, &new_number
));
1360 test_compare(uint64_t(1), new_number
);
1362 test_compare(MEMCACHED_SUCCESS
,
1363 memcached_increment_by_key(memc
, master_key
, strlen(master_key
),
1364 key
, strlen(key
), 1, &new_number
));
1365 test_compare(uint64_t(2), new_number
);
1367 return TEST_SUCCESS
;
1370 test_return_t
increment_with_initial_by_key_test(memcached_st
*memc
)
1372 test_skip(true, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
));
1374 uint64_t new_number
;
1375 const char *master_key
= "foo";
1376 const char *key
= "number";
1377 uint64_t initial
= 0;
1379 test_compare(MEMCACHED_SUCCESS
,
1380 memcached_increment_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1382 1, initial
, 0, &new_number
));
1383 test_compare(new_number
, initial
);
1385 test_compare(MEMCACHED_SUCCESS
,
1386 memcached_increment_with_initial_by_key(memc
, master_key
, strlen(master_key
),
1388 1, initial
, 0, &new_number
));
1389 test_compare(new_number
, (initial
+1));
1391 return TEST_SUCCESS
;
1394 test_return_t
decrement_by_key_test(memcached_st
*memc
)
1396 uint64_t new_number
;
1397 const char *value
= "3";
1399 test_compare(return_value_based_on_buffering(memc
),
1400 memcached_set_by_key(memc
,
1401 test_literal_param("foo"),
1402 test_literal_param("number"),
1403 value
, strlen(value
),
1404 (time_t)0, (uint32_t)0));
1406 test_compare(MEMCACHED_SUCCESS
,
1407 memcached_decrement_by_key(memc
,
1408 test_literal_param("foo"),
1409 test_literal_param("number"),
1411 test_compare(uint64_t(2), new_number
);
1413 test_compare(MEMCACHED_SUCCESS
,
1414 memcached_decrement_by_key(memc
,
1415 test_literal_param("foo"),
1416 test_literal_param("number"),
1418 test_compare(uint64_t(1), new_number
);
1420 return TEST_SUCCESS
;
1423 test_return_t
decrement_with_initial_by_key_test(memcached_st
*memc
)
1425 test_skip(true, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
));
1427 uint64_t new_number
;
1428 uint64_t initial
= 3;
1430 test_compare(MEMCACHED_SUCCESS
,
1431 memcached_decrement_with_initial_by_key(memc
,
1432 test_literal_param("foo"),
1433 test_literal_param("number"),
1434 1, initial
, 0, &new_number
));
1435 test_compare(new_number
, initial
);
1437 test_compare(MEMCACHED_SUCCESS
,
1438 memcached_decrement_with_initial_by_key(memc
,
1439 test_literal_param("foo"),
1440 test_literal_param("number"),
1441 1, initial
, 0, &new_number
));
1442 test_compare(new_number
, (initial
- 1));
1444 return TEST_SUCCESS
;
1446 test_return_t
binary_increment_with_prefix_test(memcached_st
*memc
)
1448 test_skip(true, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
));
1450 test_compare(MEMCACHED_SUCCESS
, memcached_callback_set(memc
, MEMCACHED_CALLBACK_PREFIX_KEY
, (void *)"namespace:"));
1452 test_compare(return_value_based_on_buffering(memc
),
1454 test_literal_param("number"),
1455 test_literal_param("0"),
1456 (time_t)0, (uint32_t)0));
1458 uint64_t new_number
;
1459 test_compare(MEMCACHED_SUCCESS
, memcached_increment(memc
,
1460 test_literal_param("number"),
1462 test_compare(uint64_t(1), new_number
);
1464 test_compare(MEMCACHED_SUCCESS
, memcached_increment(memc
,
1465 test_literal_param("number"),
1467 test_compare(uint64_t(2), new_number
);
1469 return TEST_SUCCESS
;
1472 test_return_t
quit_test(memcached_st
*memc
)
1474 const char *value
= "sanford and sun";
1476 test_compare(return_value_based_on_buffering(memc
),
1478 test_literal_param(__func__
),
1479 value
, strlen(value
),
1480 time_t(10), uint32_t(3)));
1481 memcached_quit(memc
);
1483 test_compare(return_value_based_on_buffering(memc
),
1485 test_literal_param(__func__
),
1486 value
, strlen(value
),
1487 time_t(50), uint32_t(9)));
1489 return TEST_SUCCESS
;
1492 test_return_t
mget_result_test(memcached_st
*memc
)
1494 const char *keys
[]= {"fudge", "son", "food"};
1495 size_t key_length
[]= {5, 3, 4};
1497 memcached_result_st results_obj
;
1498 memcached_result_st
*results
= memcached_result_create(memc
, &results_obj
);
1500 test_true(&results_obj
== results
);
1502 /* We need to empty the server before continueing test */
1503 test_compare(MEMCACHED_SUCCESS
,
1504 memcached_flush(memc
, 0));
1506 test_compare(MEMCACHED_SUCCESS
,
1507 memcached_mget(memc
, keys
, key_length
, 3));
1509 memcached_return_t rc
;
1510 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1515 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
))) { test_true(false); /* We should never see a value returned */ };
1516 test_false(results
);
1517 test_compare(MEMCACHED_NOTFOUND
, rc
);
1519 for (uint32_t x
= 0; x
< 3; x
++)
1521 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1522 keys
[x
], key_length
[x
],
1523 (time_t)50, (uint32_t)9);
1524 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
1527 test_compare(MEMCACHED_SUCCESS
,
1528 memcached_mget(memc
, keys
, key_length
, 3));
1530 while ((results
= memcached_fetch_result(memc
, &results_obj
, &rc
)))
1533 test_true(&results_obj
== results
);
1534 test_compare(MEMCACHED_SUCCESS
, rc
);
1535 test_memcmp(memcached_result_key_value(results
),
1536 memcached_result_value(results
),
1537 memcached_result_length(results
));
1538 test_compare(memcached_result_key_length(results
), memcached_result_length(results
));
1541 memcached_result_free(&results_obj
);
1543 return TEST_SUCCESS
;
1546 test_return_t
mget_result_alloc_test(memcached_st
*memc
)
1548 const char *keys
[]= {"fudge", "son", "food"};
1549 size_t key_length
[]= {5, 3, 4};
1551 memcached_result_st
*results
;
1553 /* We need to empty the server before continueing test */
1554 test_compare(MEMCACHED_SUCCESS
,
1555 memcached_flush(memc
, 0));
1557 test_compare(MEMCACHED_SUCCESS
,
1558 memcached_mget(memc
, keys
, key_length
, 3));
1560 memcached_return_t rc
;
1561 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1565 test_false(results
);
1566 test_compare(MEMCACHED_NOTFOUND
, rc
);
1568 for (uint32_t x
= 0; x
< 3; x
++)
1570 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1571 keys
[x
], key_length
[x
],
1572 (time_t)50, (uint32_t)9);
1573 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
1576 test_compare(MEMCACHED_SUCCESS
,
1577 memcached_mget(memc
, keys
, key_length
, 3));
1580 while ((results
= memcached_fetch_result(memc
, NULL
, &rc
)))
1583 test_compare(MEMCACHED_SUCCESS
, rc
);
1584 test_compare(memcached_result_key_length(results
), memcached_result_length(results
));
1585 test_memcmp(memcached_result_key_value(results
),
1586 memcached_result_value(results
),
1587 memcached_result_length(results
));
1588 memcached_result_free(results
);
1592 return TEST_SUCCESS
;
1595 test_return_t
mget_result_function(memcached_st
*memc
)
1597 const char *keys
[]= {"fudge", "son", "food"};
1598 size_t key_length
[]= {5, 3, 4};
1600 memcached_execute_fn callbacks
[1];
1602 for (uint32_t x
= 0; x
< 3; x
++)
1604 test_compare(return_value_based_on_buffering(memc
),
1605 memcached_set(memc
, keys
[x
], key_length
[x
],
1606 keys
[x
], key_length
[x
],
1607 time_t(50), uint32_t(9)));
1609 test_compare(MEMCACHED_SUCCESS
, memcached_flush_buffers(memc
));
1610 memcached_quit(memc
);
1612 test_compare(MEMCACHED_SUCCESS
,
1613 memcached_mget(memc
, keys
, key_length
, 3));
1615 callbacks
[0]= &callback_counter
;
1618 test_compare(MEMCACHED_SUCCESS
,
1619 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
1621 test_compare(size_t(3), counter
);
1623 return TEST_SUCCESS
;
1626 test_return_t
mget_test(memcached_st
*memc
)
1628 const char *keys
[]= {"fudge", "son", "food"};
1629 size_t key_length
[]= {5, 3, 4};
1631 char return_key
[MEMCACHED_MAX_KEY
];
1632 size_t return_key_length
;
1634 size_t return_value_length
;
1636 test_compare(MEMCACHED_SUCCESS
,
1637 memcached_mget(memc
, keys
, key_length
, 3));
1640 memcached_return_t rc
;
1641 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1642 &return_value_length
, &flags
, &rc
)))
1644 test_true(return_value
);
1646 test_false(return_value
);
1647 test_zero(return_value_length
);
1648 test_compare(MEMCACHED_NOTFOUND
, rc
);
1650 for (uint32_t x
= 0; x
< 3; x
++)
1652 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
1653 keys
[x
], key_length
[x
],
1654 (time_t)50, (uint32_t)9);
1655 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
1657 test_compare(MEMCACHED_SUCCESS
,
1658 memcached_mget(memc
, keys
, key_length
, 3));
1661 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
1662 &return_value_length
, &flags
, &rc
)))
1664 test_true(return_value
);
1665 test_compare(MEMCACHED_SUCCESS
, rc
);
1666 if (not memc
->_namespace
)
1668 test_compare(return_key_length
, return_value_length
);
1669 test_memcmp(return_value
, return_key
, return_value_length
);
1675 return TEST_SUCCESS
;
1678 test_return_t
mget_execute(memcached_st
*original_memc
)
1680 test_skip(true, memcached_behavior_get(original_memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
));
1682 memcached_st
*memc
= create_single_instance_memcached(original_memc
, "--BINARY-PROTOCOL");
1685 keys_st
keys(20480);
1687 /* First add all of the items.. */
1688 char blob
[1024] = {0};
1690 for (size_t x
= 0; x
< keys
.size(); ++x
)
1692 uint64_t query_id
= memcached_query_id(memc
);
1693 memcached_return_t rc
= memcached_add(memc
,
1694 keys
.key_at(x
), keys
.length_at(x
),
1697 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
1698 test_compare(query_id
+1, memcached_query_id(memc
));
1701 /* Try to get all of them with a large multiget */
1703 memcached_execute_fn callbacks
[]= { &callback_counter
};
1704 test_compare(MEMCACHED_SUCCESS
,
1705 memcached_mget_execute(memc
,
1706 keys
.keys_ptr(), keys
.lengths_ptr(),
1707 keys
.size(), callbacks
, &counter
, 1));
1710 uint64_t query_id
= memcached_query_id(memc
);
1711 test_compare(MEMCACHED_SUCCESS
,
1712 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
1713 test_compare(query_id
, memcached_query_id(memc
));
1715 /* Verify that we got all of the items */
1716 test_compare(keys
.size(), counter
);
1719 memcached_free(memc
);
1721 return TEST_SUCCESS
;
1724 #define REGRESSION_BINARY_VS_BLOCK_COUNT 20480
1725 static pairs_st
*global_pairs
= NULL
;
1727 test_return_t
key_setup(memcached_st
*memc
)
1729 test_skip(TEST_SUCCESS
, pre_binary(memc
));
1731 global_pairs
= pairs_generate(REGRESSION_BINARY_VS_BLOCK_COUNT
, 0);
1733 return TEST_SUCCESS
;
1736 test_return_t
key_teardown(memcached_st
*)
1738 pairs_free(global_pairs
);
1741 return TEST_SUCCESS
;
1744 test_return_t
block_add_regression(memcached_st
*memc
)
1746 /* First add all of the items.. */
1747 for (ptrdiff_t x
= 0; x
< REGRESSION_BINARY_VS_BLOCK_COUNT
; ++x
)
1749 libtest::vchar_t blob
;
1750 libtest::vchar::make(blob
, 1024);
1752 memcached_return_t rc
= memcached_add_by_key(memc
,
1753 test_literal_param("bob"),
1754 global_pairs
[x
].key
, global_pairs
[x
].key_length
,
1755 &blob
[0], blob
.size(),
1756 time_t(0), uint32_t(0));
1757 test_compare(*memc
, MEMCACHED_SUCCESS
);
1758 test_compare(rc
, MEMCACHED_SUCCESS
);
1761 return TEST_SUCCESS
;
1764 test_return_t
binary_add_regression(memcached_st
*memc
)
1766 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, true));
1767 return block_add_regression(memc
);
1770 test_return_t
get_stats_keys(memcached_st
*memc
)
1774 memcached_stat_st memc_stat
;
1775 memcached_return_t rc
;
1777 stat_list
= memcached_stat_get_keys(memc
, &memc_stat
, &rc
);
1778 test_compare(MEMCACHED_SUCCESS
, rc
);
1779 for (ptr
= stat_list
; *ptr
; ptr
++)
1784 return TEST_SUCCESS
;
1787 test_return_t
version_string_test(memcached_st
*)
1789 test_strcmp(LIBMEMCACHED_VERSION_STRING
, memcached_lib_version());
1791 return TEST_SUCCESS
;
1794 test_return_t
get_stats(memcached_st
*memc
)
1796 memcached_return_t rc
;
1798 memcached_stat_st
*memc_stat
= memcached_stat(memc
, NULL
, &rc
);
1799 test_compare(MEMCACHED_SUCCESS
, rc
);
1800 test_true(memc_stat
);
1802 for (uint32_t x
= 0; x
< memcached_server_count(memc
); x
++)
1804 char **stat_list
= memcached_stat_get_keys(memc
, memc_stat
+x
, &rc
);
1805 test_compare(MEMCACHED_SUCCESS
, rc
);
1806 for (char **ptr
= stat_list
; *ptr
; ptr
++) {};
1811 memcached_stat_free(NULL
, memc_stat
);
1813 return TEST_SUCCESS
;
1816 test_return_t
add_host_test(memcached_st
*memc
)
1818 char servername
[]= "0.example.com";
1820 memcached_return_t rc
;
1821 memcached_server_st
*servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
1822 test_compare(1U, memcached_server_list_count(servers
));
1824 for (unsigned int x
= 2; x
< 20; x
++)
1826 char buffer
[SMALL_STRING_LEN
];
1828 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
1829 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
1831 test_compare(MEMCACHED_SUCCESS
, rc
);
1832 test_compare(x
, memcached_server_list_count(servers
));
1835 test_compare(MEMCACHED_SUCCESS
, memcached_server_push(memc
, servers
));
1836 test_compare(MEMCACHED_SUCCESS
, memcached_server_push(memc
, servers
));
1838 memcached_server_list_free(servers
);
1840 return TEST_SUCCESS
;
1843 test_return_t
memcached_fetch_result_NOT_FOUND(memcached_st
*memc
)
1845 memcached_return_t rc
;
1847 const char *key
= "not_found";
1848 size_t key_length
= test_literal_param_size("not_found");
1850 test_compare(MEMCACHED_SUCCESS
,
1851 memcached_mget(memc
, &key
, &key_length
, 1));
1853 memcached_result_st
*result
= memcached_fetch_result(memc
, NULL
, &rc
);
1855 test_compare(MEMCACHED_NOTFOUND
, rc
);
1857 memcached_result_free(result
);
1859 return TEST_SUCCESS
;
1862 static memcached_return_t
clone_test_callback(memcached_st
*, memcached_st
*)
1864 return MEMCACHED_SUCCESS
;
1867 static memcached_return_t
cleanup_test_callback(memcached_st
*)
1869 return MEMCACHED_SUCCESS
;
1872 test_return_t
callback_test(memcached_st
*memc
)
1874 /* Test User Data */
1878 memcached_return_t rc
;
1880 test_compare(MEMCACHED_SUCCESS
, memcached_callback_set(memc
, MEMCACHED_CALLBACK_USER_DATA
, &x
));
1881 test_ptr
= (int *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_USER_DATA
, &rc
);
1882 test_true(*test_ptr
== x
);
1885 /* Test Clone Callback */
1887 memcached_clone_fn clone_cb
= (memcached_clone_fn
)clone_test_callback
;
1888 void *clone_cb_ptr
= *(void **)&clone_cb
;
1889 void *temp_function
= NULL
;
1891 test_compare(MEMCACHED_SUCCESS
, memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, clone_cb_ptr
));
1892 memcached_return_t rc
;
1893 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1894 test_true(temp_function
== clone_cb_ptr
);
1895 test_compare(MEMCACHED_SUCCESS
, rc
);
1898 /* Test Cleanup Callback */
1900 memcached_cleanup_fn cleanup_cb
= (memcached_cleanup_fn
)cleanup_test_callback
;
1901 void *cleanup_cb_ptr
= *(void **)&cleanup_cb
;
1902 void *temp_function
= NULL
;
1903 memcached_return_t rc
;
1905 test_compare(MEMCACHED_SUCCESS
, memcached_callback_set(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, cleanup_cb_ptr
));
1906 temp_function
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_CLONE_FUNCTION
, &rc
);
1907 test_true(temp_function
== cleanup_cb_ptr
);
1910 return TEST_SUCCESS
;
1913 /* We don't test the behavior itself, we test the switches */
1914 test_return_t
behavior_test(memcached_st
*memc
)
1916 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 1);
1917 test_compare(true, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
));
1919 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1);
1920 test_compare(true, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
));
1922 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, MEMCACHED_HASH_MD5
);
1923 test_compare(uint64_t(MEMCACHED_HASH_MD5
), memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
));
1925 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 0);
1926 test_zero(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
));
1928 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 0);
1929 test_zero(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
));
1931 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, MEMCACHED_HASH_DEFAULT
);
1932 test_compare(uint64_t(MEMCACHED_HASH_DEFAULT
), memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
));
1934 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, MEMCACHED_HASH_CRC
);
1935 test_compare(uint64_t(MEMCACHED_HASH_CRC
), memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
));
1937 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
));
1939 test_true(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
));
1941 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
);
1942 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, value
+1);
1943 test_compare((value
+1), memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
));
1945 return TEST_SUCCESS
;
1948 test_return_t
MEMCACHED_BEHAVIOR_CORK_test(memcached_st
*memc
)
1950 test_compare(MEMCACHED_DEPRECATED
,
1951 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CORK
, true));
1953 // Platform dependent
1955 bool value
= (bool)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_CORK
);
1959 return TEST_SUCCESS
;
1963 test_return_t
MEMCACHED_BEHAVIOR_TCP_KEEPALIVE_test(memcached_st
*memc
)
1965 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE
, true);
1966 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_NOT_SUPPORTED
);
1968 bool value
= (bool)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE
);
1970 if (memcached_success(rc
))
1979 return TEST_SUCCESS
;
1983 test_return_t
MEMCACHED_BEHAVIOR_TCP_KEEPIDLE_test(memcached_st
*memc
)
1985 memcached_return_t rc
= memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_KEEPIDLE
, true);
1986 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_NOT_SUPPORTED
);
1988 bool value
= (bool)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_KEEPIDLE
);
1990 if (memcached_success(rc
))
1999 return TEST_SUCCESS
;
2002 /* Make sure we behave properly if server list has no values */
2003 test_return_t
user_supplied_bug4(memcached_st
*memc
)
2005 const char *keys
[]= {"fudge", "son", "food"};
2006 size_t key_length
[]= {5, 3, 4};
2008 /* Here we free everything before running a bunch of mget tests */
2009 memcached_servers_reset(memc
);
2012 /* We need to empty the server before continueing test */
2013 test_compare(MEMCACHED_NO_SERVERS
,
2014 memcached_flush(memc
, 0));
2016 test_compare(MEMCACHED_NO_SERVERS
,
2017 memcached_mget(memc
, keys
, key_length
, 3));
2020 unsigned int keys_returned
;
2021 memcached_return_t rc
;
2022 test_compare(TEST_SUCCESS
, fetch_all_results(memc
, keys_returned
, rc
));
2023 test_compare(MEMCACHED_NOTFOUND
, rc
);
2024 test_zero(keys_returned
);
2027 for (uint32_t x
= 0; x
< 3; x
++)
2029 test_compare(MEMCACHED_NO_SERVERS
,
2030 memcached_set(memc
, keys
[x
], key_length
[x
],
2031 keys
[x
], key_length
[x
],
2032 (time_t)50, (uint32_t)9));
2035 test_compare(MEMCACHED_NO_SERVERS
,
2036 memcached_mget(memc
, keys
, key_length
, 3));
2040 char return_key
[MEMCACHED_MAX_KEY
];
2041 memcached_return_t rc
;
2042 size_t return_key_length
;
2043 size_t return_value_length
;
2046 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2047 &return_value_length
, &flags
, &rc
)))
2049 test_true(return_value
);
2050 test_compare(MEMCACHED_SUCCESS
, rc
);
2051 test_true(return_key_length
== return_value_length
);
2052 test_memcmp(return_value
, return_key
, return_value_length
);
2058 return TEST_SUCCESS
;
2061 #define VALUE_SIZE_BUG5 1048064
2062 test_return_t
user_supplied_bug5(memcached_st
*memc
)
2064 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
2065 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
2067 size_t value_length
;
2069 char *insert_data
= new (std::nothrow
) char[VALUE_SIZE_BUG5
];
2071 for (uint32_t x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2073 insert_data
[x
]= (signed char)rand();
2076 test_compare(MEMCACHED_SUCCESS
,
2077 memcached_flush(memc
, 0));
2079 memcached_return_t rc
;
2080 test_null(memcached_get(memc
, keys
[0], key_length
[0], &value_length
, &flags
, &rc
));
2081 test_compare(MEMCACHED_SUCCESS
,
2082 memcached_mget(memc
, keys
, key_length
, 4));
2085 test_compare(TEST_SUCCESS
, fetch_all_results(memc
, count
, rc
));
2086 test_compare(MEMCACHED_NOTFOUND
, rc
);
2089 for (uint32_t x
= 0; x
< 4; x
++)
2091 test_compare(MEMCACHED_SUCCESS
,
2092 memcached_set(memc
, keys
[x
], key_length
[x
],
2093 insert_data
, VALUE_SIZE_BUG5
,
2094 (time_t)0, (uint32_t)0));
2097 for (uint32_t x
= 0; x
< 10; x
++)
2099 value
= memcached_get(memc
, keys
[0], key_length
[0],
2100 &value_length
, &flags
, &rc
);
2101 test_compare(rc
, MEMCACHED_SUCCESS
);
2105 test_compare(MEMCACHED_SUCCESS
,
2106 memcached_mget(memc
, keys
, key_length
, 4));
2108 test_compare(TEST_SUCCESS
, fetch_all_results(memc
, count
));
2109 test_compare(4U, count
);
2111 delete [] insert_data
;
2113 return TEST_SUCCESS
;
2116 test_return_t
user_supplied_bug6(memcached_st
*memc
)
2118 const char *keys
[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
2119 size_t key_length
[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
2120 char return_key
[MEMCACHED_MAX_KEY
];
2121 size_t return_key_length
;
2123 size_t value_length
;
2125 char *insert_data
= new (std::nothrow
) char[VALUE_SIZE_BUG5
];
2127 for (uint32_t x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2129 insert_data
[x
]= (signed char)rand();
2132 test_compare(MEMCACHED_SUCCESS
, memcached_flush(memc
, 0));
2134 test_compare(TEST_SUCCESS
, confirm_keys_dont_exist(memc
, keys
, test_array_length(keys
)));
2136 // We will now confirm that memcached_mget() returns success, but we will
2137 // then check to make sure that no actual keys are returned.
2138 test_compare(MEMCACHED_SUCCESS
,
2139 memcached_mget(memc
, keys
, key_length
, 4));
2141 memcached_return_t rc
;
2143 while ((value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2144 &value_length
, &flags
, &rc
)))
2149 test_compare(MEMCACHED_NOTFOUND
, rc
);
2151 for (uint32_t x
= 0; x
< test_array_length(keys
); x
++)
2153 test_compare(MEMCACHED_SUCCESS
,
2154 memcached_set(memc
, keys
[x
], key_length
[x
],
2155 insert_data
, VALUE_SIZE_BUG5
,
2156 (time_t)0, (uint32_t)0));
2158 test_compare(TEST_SUCCESS
, confirm_keys_exist(memc
, keys
, test_array_length(keys
)));
2160 for (uint32_t x
= 0; x
< 2; x
++)
2162 value
= memcached_get(memc
, keys
[0], key_length
[0],
2163 &value_length
, &flags
, &rc
);
2167 test_compare(MEMCACHED_SUCCESS
,
2168 memcached_mget(memc
, keys
, key_length
, 4));
2169 /* We test for purge of partial complete fetches */
2170 for (count
= 3; count
; count
--)
2172 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2173 &value_length
, &flags
, &rc
);
2174 test_compare(MEMCACHED_SUCCESS
, rc
);
2175 test_memcmp(value
, insert_data
, value_length
);
2176 test_true(value_length
);
2180 delete [] insert_data
;
2182 return TEST_SUCCESS
;
2185 test_return_t
user_supplied_bug8(memcached_st
*)
2187 memcached_return_t rc
;
2189 memcached_st
*memc_clone
;
2191 memcached_server_st
*servers
;
2192 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";
2194 servers
= memcached_servers_parse(server_list
);
2197 mine
= memcached_create(NULL
);
2198 rc
= memcached_server_push(mine
, servers
);
2199 test_compare(MEMCACHED_SUCCESS
, rc
);
2200 memcached_server_list_free(servers
);
2203 memc_clone
= memcached_clone(NULL
, mine
);
2205 memcached_quit(mine
);
2206 memcached_quit(memc_clone
);
2209 memcached_free(mine
);
2210 memcached_free(memc_clone
);
2212 return TEST_SUCCESS
;
2215 /* Test flag store/retrieve */
2216 test_return_t
user_supplied_bug7(memcached_st
*memc
)
2218 char *insert_data
= new (std::nothrow
) char[VALUE_SIZE_BUG5
];
2219 test_true(insert_data
);
2221 for (size_t x
= 0; x
< VALUE_SIZE_BUG5
; x
++)
2223 insert_data
[x
]= (signed char)rand();
2226 memcached_flush(memc
, 0);
2228 const char *keys
= "036790384900";
2229 size_t key_length
= strlen(keys
);
2230 test_compare(MEMCACHED_SUCCESS
, memcached_set(memc
, keys
, key_length
,
2231 insert_data
, VALUE_SIZE_BUG5
,
2234 memcached_return_t rc
;
2235 size_t value_length
;
2237 char *value
= memcached_get(memc
, keys
, key_length
,
2238 &value_length
, &flags
, &rc
);
2239 test_compare(245U, flags
);
2243 test_compare(MEMCACHED_SUCCESS
, memcached_mget(memc
, &keys
, &key_length
, 1));
2245 char return_key
[MEMCACHED_MAX_KEY
];
2246 size_t return_key_length
;
2248 value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2249 &value_length
, &flags
, &rc
);
2250 test_compare(uint32_t(245), flags
);
2253 delete [] insert_data
;
2256 return TEST_SUCCESS
;
2259 test_return_t
user_supplied_bug9(memcached_st
*memc
)
2261 const char *keys
[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
2262 size_t key_length
[3];
2266 char return_key
[MEMCACHED_MAX_KEY
];
2267 size_t return_key_length
;
2269 size_t return_value_length
;
2272 key_length
[0]= strlen("UDATA:edevil@sapo.pt");
2273 key_length
[1]= strlen("fudge&*@#");
2274 key_length
[2]= strlen("for^#@&$not");
2277 for (unsigned int x
= 0; x
< 3; x
++)
2279 memcached_return_t rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
2280 keys
[x
], key_length
[x
],
2281 (time_t)50, (uint32_t)9);
2282 test_compare(MEMCACHED_SUCCESS
, rc
);
2285 memcached_return_t rc
= memcached_mget(memc
, keys
, key_length
, 3);
2286 test_compare(MEMCACHED_SUCCESS
, rc
);
2288 /* We need to empty the server before continueing test */
2289 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2290 &return_value_length
, &flags
, &rc
)) != NULL
)
2292 test_true(return_value
);
2296 test_compare(3U, count
);
2298 return TEST_SUCCESS
;
2301 /* We are testing with aggressive timeout to get failures */
2302 test_return_t
user_supplied_bug10(memcached_st
*memc
)
2304 test_skip(memc
->servers
[0].type
, MEMCACHED_CONNECTION_TCP
);
2306 size_t value_length
= 512;
2307 unsigned int set
= 1;
2308 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2310 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, set
);
2311 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, set
);
2312 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, uint64_t(0));
2314 libtest::vchar_t value
;
2315 value
.reserve(value_length
);
2316 for (uint32_t x
= 0; x
< value_length
; x
++)
2318 value
.push_back(char(x
% 127));
2321 for (unsigned int x
= 1; x
<= 100000; ++x
)
2323 memcached_return_t rc
= memcached_set(mclone
,
2324 test_literal_param("foo"),
2325 &value
[0], value
.size(),
2328 test_true((rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_WRITE_FAILURE
or rc
== MEMCACHED_BUFFERED
or rc
== MEMCACHED_TIMEOUT
or rc
== MEMCACHED_CONNECTION_FAILURE
2329 or rc
== MEMCACHED_SERVER_TEMPORARILY_DISABLED
));
2331 if (rc
== MEMCACHED_WRITE_FAILURE
or rc
== MEMCACHED_TIMEOUT
)
2337 memcached_free(mclone
);
2339 return TEST_SUCCESS
;
2343 We are looking failures in the async protocol
2345 test_return_t
user_supplied_bug11(memcached_st
*memc
)
2347 memcached_st
*mclone
= memcached_clone(NULL
, memc
);
2349 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_NO_BLOCK
, true);
2350 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, true);
2351 memcached_behavior_set(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, size_t(-1));
2353 test_compare(-1, int32_t(memcached_behavior_get(mclone
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
)));
2356 libtest::vchar_t value
;
2358 for (unsigned int x
= 0; x
< 512; x
++)
2360 value
.push_back(char(x
% 127));
2363 for (unsigned int x
= 1; x
<= 100000; ++x
)
2365 memcached_return_t rc
= memcached_set(mclone
, test_literal_param("foo"), &value
[0], value
.size(), 0, 0);
2369 memcached_free(mclone
);
2371 return TEST_SUCCESS
;
2375 Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
2377 test_return_t
user_supplied_bug12(memcached_st
*memc
)
2379 memcached_return_t rc
;
2381 size_t value_length
;
2383 uint64_t number_value
;
2385 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"),
2386 &value_length
, &flags
, &rc
);
2388 test_compare(MEMCACHED_NOTFOUND
, rc
);
2390 rc
= memcached_increment(memc
, "autoincrement", strlen("autoincrement"),
2393 /* The binary protocol will set the key if it doesn't exist */
2394 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) == 1)
2396 test_compare(MEMCACHED_SUCCESS
, rc
);
2400 test_compare(MEMCACHED_NOTFOUND
, rc
);
2403 test_compare(MEMCACHED_SUCCESS
,
2404 memcached_set(memc
, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0));
2406 value
= memcached_get(memc
, "autoincrement", strlen("autoincrement"), &value_length
, &flags
, &rc
);
2410 test_compare(MEMCACHED_SUCCESS
,
2411 memcached_increment(memc
, "autoincrement", strlen("autoincrement"), 1, &number_value
));
2412 test_compare(2UL, number_value
);
2414 return TEST_SUCCESS
;
2418 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2419 set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
2421 test_return_t
user_supplied_bug13(memcached_st
*memc
)
2423 char key
[] = "key34567890";
2425 char commandFirst
[]= "set key34567890 0 0 ";
2426 char commandLast
[] = " \r\n"; /* first line of command sent to server */
2427 size_t commandLength
;
2429 commandLength
= strlen(commandFirst
) + strlen(commandLast
) + 4; /* 4 is number of characters in size, probably 8196 */
2431 size_t overflowSize
= MEMCACHED_MAX_BUFFER
- commandLength
;
2433 for (size_t testSize
= overflowSize
- 1; testSize
< overflowSize
+ 1; testSize
++)
2435 char *overflow
= new (std::nothrow
) char[testSize
];
2436 test_true(overflow
);
2438 memset(overflow
, 'x', testSize
);
2439 test_compare(MEMCACHED_SUCCESS
,
2440 memcached_set(memc
, key
, strlen(key
),
2441 overflow
, testSize
, 0, 0));
2445 return TEST_SUCCESS
;
2450 Test values of many different sizes
2451 Bug found where command total one more than MEMCACHED_MAX_BUFFER
2452 set key34567890 0 0 8169 \r\n
2453 is sent followed by buffer of size 8169, followed by 8169
2455 test_return_t
user_supplied_bug14(memcached_st
*memc
)
2457 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, true);
2459 libtest::vchar_t value
;
2460 value
.reserve(18000);
2461 for (ptrdiff_t x
= 0; x
< 18000; x
++)
2463 value
.push_back((char) (x
% 127));
2466 for (size_t current_length
= 1; current_length
< value
.size(); current_length
++)
2468 memcached_return_t rc
= memcached_set(memc
, test_literal_param("foo"),
2469 &value
[0], current_length
,
2470 (time_t)0, (uint32_t)0);
2471 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
2473 size_t string_length
;
2475 char *string
= memcached_get(memc
, test_literal_param("foo"),
2476 &string_length
, &flags
, &rc
);
2478 test_compare(MEMCACHED_SUCCESS
, rc
);
2479 test_compare(string_length
, current_length
);
2481 snprintf(buffer
, sizeof(buffer
), "%u", uint32_t(string_length
));
2482 test_memcmp(string
, &value
[0], string_length
);
2487 return TEST_SUCCESS
;
2491 Look for zero length value problems
2493 test_return_t
user_supplied_bug15(memcached_st
*memc
)
2495 for (uint32_t x
= 0; x
< 2; x
++)
2497 memcached_return_t rc
= memcached_set(memc
, test_literal_param("mykey"),
2499 (time_t)0, (uint32_t)0);
2501 test_compare(MEMCACHED_SUCCESS
, rc
);
2505 char *value
= memcached_get(memc
, test_literal_param("mykey"),
2506 &length
, &flags
, &rc
);
2508 test_compare(MEMCACHED_SUCCESS
, rc
);
2513 value
= memcached_get(memc
, test_literal_param("mykey"),
2514 &length
, &flags
, &rc
);
2516 test_compare(MEMCACHED_SUCCESS
, rc
);
2522 return TEST_SUCCESS
;
2525 /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
2526 test_return_t
user_supplied_bug16(memcached_st
*memc
)
2528 test_compare(MEMCACHED_SUCCESS
, memcached_set(memc
, test_literal_param("mykey"),
2530 (time_t)0, UINT32_MAX
));
2535 memcached_return_t rc
;
2536 char *value
= memcached_get(memc
, test_literal_param("mykey"),
2537 &length
, &flags
, &rc
);
2539 test_compare(MEMCACHED_SUCCESS
, rc
);
2542 test_compare(flags
, UINT32_MAX
);
2544 return TEST_SUCCESS
;
2547 #if !defined(__sun) && !defined(__OpenBSD__)
2548 /* Check the validity of chinese key*/
2549 test_return_t
user_supplied_bug17(memcached_st
*memc
)
2551 const char *key
= "豆瓣";
2552 const char *value
="我们在炎热抑郁的夏天无法停止豆瓣";
2553 memcached_return_t rc
= memcached_set(memc
, key
, strlen(key
),
2554 value
, strlen(value
),
2557 test_compare(MEMCACHED_SUCCESS
, rc
);
2561 char *value2
= memcached_get(memc
, key
, strlen(key
),
2562 &length
, &flags
, &rc
);
2564 test_compare(length
, strlen(value
));
2565 test_compare(MEMCACHED_SUCCESS
, rc
);
2566 test_memcmp(value
, value2
, length
);
2569 return TEST_SUCCESS
;
2577 test_return_t
user_supplied_bug19(memcached_st
*)
2579 memcached_return_t res
;
2581 memcached_st
*memc
= memcached(test_literal_param("--server=localhost:11311/?100 --server=localhost:11312/?100"));
2583 memcached_server_instance_st server
= memcached_server_by_key(memc
, "a", 1, &res
);
2586 memcached_free(memc
);
2588 return TEST_SUCCESS
;
2591 /* CAS test from Andei */
2592 test_return_t
user_supplied_bug20(memcached_st
*memc
)
2594 const char *key
= "abc";
2595 size_t key_len
= strlen("abc");
2597 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, true));
2599 test_compare(MEMCACHED_SUCCESS
,
2601 test_literal_param("abc"),
2602 test_literal_param("foobar"),
2603 (time_t)0, (uint32_t)0));
2605 test_compare(MEMCACHED_SUCCESS
,
2606 memcached_mget(memc
, &key
, &key_len
, 1));
2608 memcached_result_st result_obj
;
2609 memcached_result_st
*result
= memcached_result_create(memc
, &result_obj
);
2612 memcached_result_create(memc
, &result_obj
);
2613 memcached_return_t status
;
2614 result
= memcached_fetch_result(memc
, &result_obj
, &status
);
2617 test_compare(MEMCACHED_SUCCESS
, status
);
2619 memcached_result_free(result
);
2621 return TEST_SUCCESS
;
2624 /* Large mget() of missing keys with binary proto
2626 * If many binary quiet commands (such as getq's in an mget) fill the output
2627 * buffer and the server chooses not to respond, memcached_flush hangs. See
2628 * http://lists.tangent.org/pipermail/libmemcached/2009-August/000918.html
2631 /* sighandler_t function that always asserts false */
2632 static void fail(int)
2638 test_return_t
_user_supplied_bug21(memcached_st
* memc
, size_t key_count
)
2643 return TEST_SKIPPED
;
2645 void (*oldalarm
)(int);
2647 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
2648 test_true(memc_clone
);
2650 /* only binproto uses getq for mget */
2651 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, true));
2653 /* empty the cache to ensure misses (hence non-responses) */
2654 test_compare(MEMCACHED_SUCCESS
, memcached_flush(memc_clone
, 0));
2656 keys_st
keys(key_count
);
2658 oldalarm
= signal(SIGALRM
, fail
);
2661 test_compare_got(MEMCACHED_SUCCESS
,
2662 memcached_mget(memc_clone
, keys
.keys_ptr(), keys
.lengths_ptr(), keys
.size()),
2663 memcached_last_error_message(memc_clone
));
2666 signal(SIGALRM
, oldalarm
);
2668 memcached_return_t rc
;
2670 char return_key
[MEMCACHED_MAX_KEY
];
2671 size_t return_key_length
;
2673 size_t return_value_length
;
2674 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
2675 &return_value_length
, &flags
, &rc
)))
2677 test_false(return_value
); // There are no keys to fetch, so the value should never be returned
2679 test_compare(MEMCACHED_NOTFOUND
, rc
);
2680 test_zero(return_value_length
);
2681 test_zero(return_key_length
);
2682 test_false(return_key
[0]);
2683 test_false(return_value
);
2685 memcached_free(memc_clone
);
2687 return TEST_SUCCESS
;
2691 test_return_t
user_supplied_bug21(memcached_st
*memc
)
2693 test_skip(TEST_SUCCESS
, pre_binary(memc
));
2695 /* should work as of r580 */
2696 test_compare(TEST_SUCCESS
,
2697 _user_supplied_bug21(memc
, 10));
2699 /* should fail as of r580 */
2700 test_compare(TEST_SUCCESS
,
2701 _user_supplied_bug21(memc
, 1000));
2703 return TEST_SUCCESS
;
2706 test_return_t
output_ketama_weighted_keys(memcached_st
*)
2708 memcached_st
*memc
= memcached_create(NULL
);
2712 test_compare(MEMCACHED_SUCCESS
,
2713 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
, true));
2715 uint64_t value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
);
2716 test_compare(value
, uint64_t(1));
2718 test_compare(MEMCACHED_SUCCESS
,
2719 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
, MEMCACHED_HASH_MD5
));
2721 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_HASH
);
2722 test_true(value
== MEMCACHED_HASH_MD5
);
2725 test_true(memcached_behavior_set_distribution(memc
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY
) == MEMCACHED_SUCCESS
);
2727 memcached_server_st
*server_pool
;
2728 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");
2729 memcached_server_push(memc
, server_pool
);
2731 // @todo this needs to be refactored to actually test something.
2734 if ((fp
= fopen("ketama_keys.txt", "w")))
2738 printf("cannot write to file ketama_keys.txt");
2739 return TEST_FAILURE
;
2742 for (int x
= 0; x
< 10000; x
++)
2745 snprintf(key
, sizeof(key
), "%d", x
);
2747 uint32_t server_idx
= memcached_generate_hash(memc
, key
, strlen(key
));
2748 char *hostname
= memc
->hosts
[server_idx
].hostname
;
2749 in_port_t port
= memc
->hosts
[server_idx
].port
;
2750 fprintf(fp
, "key %s is on host /%s:%u\n", key
, hostname
, port
);
2751 memcached_server_instance_st instance
=
2752 memcached_server_instance_by_position(memc
, host_index
);
2756 memcached_server_list_free(server_pool
);
2757 memcached_free(memc
);
2759 return TEST_SUCCESS
;
2763 test_return_t
result_static(memcached_st
*memc
)
2765 memcached_result_st result
;
2766 memcached_result_st
*result_ptr
= memcached_result_create(memc
, &result
);
2767 test_false(result
.options
.is_allocated
);
2768 test_true(memcached_is_initialized(&result
));
2769 test_true(result_ptr
);
2770 test_true(result_ptr
== &result
);
2772 memcached_result_free(&result
);
2774 test_false(result
.options
.is_allocated
);
2775 test_false(memcached_is_initialized(&result
));
2777 return TEST_SUCCESS
;
2780 test_return_t
result_alloc(memcached_st
*memc
)
2782 memcached_result_st
*result_ptr
= memcached_result_create(memc
, NULL
);
2783 test_true(result_ptr
);
2784 test_true(result_ptr
->options
.is_allocated
);
2785 test_true(memcached_is_initialized(result_ptr
));
2786 memcached_result_free(result_ptr
);
2788 return TEST_SUCCESS
;
2792 test_return_t
add_host_test1(memcached_st
*memc
)
2794 memcached_return_t rc
;
2795 char servername
[]= "0.example.com";
2797 memcached_server_st
*servers
= memcached_server_list_append_with_weight(NULL
, servername
, 400, 0, &rc
);
2799 test_compare(1U, memcached_server_list_count(servers
));
2801 for (uint32_t x
= 2; x
< 20; x
++)
2803 char buffer
[SMALL_STRING_LEN
];
2805 snprintf(buffer
, SMALL_STRING_LEN
, "%lu.example.com", (unsigned long)(400 +x
));
2806 servers
= memcached_server_list_append_with_weight(servers
, buffer
, 401, 0,
2808 test_compare(MEMCACHED_SUCCESS
, rc
);
2809 test_compare(x
, memcached_server_list_count(servers
));
2812 test_compare(MEMCACHED_SUCCESS
, memcached_server_push(memc
, servers
));
2813 test_compare(MEMCACHED_SUCCESS
, memcached_server_push(memc
, servers
));
2815 memcached_server_list_free(servers
);
2817 return TEST_SUCCESS
;
2821 static void my_free(const memcached_st
*ptr
, void *mem
, void *context
)
2825 #ifdef HARD_MALLOC_TESTS
2826 void *real_ptr
= (mem
== NULL
) ? mem
: (void*)((caddr_t
)mem
- 8);
2834 static void *my_malloc(const memcached_st
*ptr
, const size_t size
, void *context
)
2838 #ifdef HARD_MALLOC_TESTS
2839 void *ret
= malloc(size
+ 8);
2842 ret
= (void*)((caddr_t
)ret
+ 8);
2845 void *ret
= malloc(size
);
2850 memset(ret
, 0xff, size
);
2857 static void *my_realloc(const memcached_st
*ptr
, void *mem
, const size_t size
, void *)
2859 #ifdef HARD_MALLOC_TESTS
2860 void *real_ptr
= (mem
== NULL
) ? NULL
: (void*)((caddr_t
)mem
- 8);
2861 void *nmem
= realloc(real_ptr
, size
+ 8);
2866 ret
= (void*)((caddr_t
)nmem
+ 8);
2872 return realloc(mem
, size
);
2877 static void *my_calloc(const memcached_st
*ptr
, size_t nelem
, const size_t size
, void *)
2879 #ifdef HARD_MALLOC_TESTS
2880 void *mem
= my_malloc(ptr
, nelem
* size
);
2883 memset(mem
, 0, nelem
* size
);
2889 return calloc(nelem
, size
);
2893 test_return_t
selection_of_namespace_tests(memcached_st
*memc
)
2895 memcached_return_t rc
;
2896 const char *key
= "mine";
2899 /* Make sure be default none exists */
2900 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
2902 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
2904 /* Test a clean set */
2905 test_compare(MEMCACHED_SUCCESS
,
2906 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, (void *)key
));
2908 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
2910 test_memcmp(value
, key
, 4);
2911 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
2913 /* Test that we can turn it off */
2914 test_compare(MEMCACHED_SUCCESS
,
2915 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, NULL
));
2917 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
2919 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
2921 /* Now setup for main test */
2922 test_compare(MEMCACHED_SUCCESS
,
2923 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, (void *)key
));
2925 value
= (char *)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
2927 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
2928 test_memcmp(value
, key
, 4);
2930 /* Set to Zero, and then Set to something too large */
2933 memset(long_key
, 0, 255);
2935 test_compare(MEMCACHED_SUCCESS
,
2936 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, NULL
));
2938 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
2940 test_compare(MEMCACHED_SUCCESS
, rc
);
2942 /* Test a long key for failure */
2943 /* TODO, extend test to determine based on setting, what result should be */
2944 strncpy(long_key
, "Thisismorethentheallottednumberofcharacters", sizeof(long_key
));
2945 test_compare(MEMCACHED_SUCCESS
,
2946 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, long_key
));
2948 /* Now test a key with spaces (which will fail from long key, since bad key is not set) */
2949 strncpy(long_key
, "This is more then the allotted number of characters", sizeof(long_key
));
2950 test_compare(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) ? MEMCACHED_SUCCESS
: MEMCACHED_BAD_KEY_PROVIDED
,
2951 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, long_key
));
2953 /* Test for a bad prefix, but with a short key */
2954 test_compare(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) ? MEMCACHED_INVALID_ARGUMENTS
: MEMCACHED_SUCCESS
,
2955 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_VERIFY_KEY
, 1));
2957 test_compare(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
) ? MEMCACHED_SUCCESS
: MEMCACHED_BAD_KEY_PROVIDED
,
2958 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, "dog cat"));
2961 return TEST_SUCCESS
;
2964 test_return_t
set_namespace(memcached_st
*memc
)
2966 memcached_return_t rc
;
2967 const char *key
= "mine";
2970 // Make sure we default to a null namespace
2971 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
2973 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
2975 /* Test a clean set */
2976 test_compare(MEMCACHED_SUCCESS
,
2977 memcached_callback_set(memc
, MEMCACHED_CALLBACK_NAMESPACE
, (void *)key
));
2979 value
= (char*)memcached_callback_get(memc
, MEMCACHED_CALLBACK_NAMESPACE
, &rc
);
2981 test_memcmp(value
, key
, 4);
2982 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
2984 return TEST_SUCCESS
;
2987 test_return_t
set_namespace_and_binary(memcached_st
*memc
)
2989 test_return_if(pre_binary(memc
));
2990 test_return_if(set_namespace(memc
));
2992 return TEST_SUCCESS
;
2995 #ifdef MEMCACHED_ENABLE_DEPRECATED
2996 test_return_t
deprecated_set_memory_alloc(memcached_st
*memc
)
2998 void *test_ptr
= NULL
;
3001 memcached_malloc_fn malloc_cb
= (memcached_malloc_fn
)my_malloc
;
3002 cb_ptr
= *(void **)&malloc_cb
;
3003 memcached_return_t rc
;
3005 test_compare(MEMCACHED_SUCCESS
,
3006 memcached_callback_set(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, cb_ptr
));
3007 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_MALLOC_FUNCTION
, &rc
);
3008 test_compare(MEMCACHED_SUCCESS
, rc
);
3009 test_true(test_ptr
== cb_ptr
);
3013 memcached_realloc_fn realloc_cb
=
3014 (memcached_realloc_fn
)my_realloc
;
3015 cb_ptr
= *(void **)&realloc_cb
;
3016 memcached_return_t rc
;
3018 test_compare(MEMCACHED_SUCCESS
,
3019 memcached_callback_set(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, cb_ptr
));
3020 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_REALLOC_FUNCTION
, &rc
);
3021 test_compare(MEMCACHED_SUCCESS
, rc
);
3022 test_true(test_ptr
== cb_ptr
);
3026 memcached_free_fn free_cb
=
3027 (memcached_free_fn
)my_free
;
3028 cb_ptr
= *(void **)&free_cb
;
3029 memcached_return_t rc
;
3031 test_compare(MEMCACHED_SUCCESS
,
3032 memcached_callback_set(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, cb_ptr
));
3033 test_ptr
= memcached_callback_get(memc
, MEMCACHED_CALLBACK_FREE_FUNCTION
, &rc
);
3034 test_compare(MEMCACHED_SUCCESS
, rc
);
3035 test_true(test_ptr
== cb_ptr
);
3038 return TEST_SUCCESS
;
3043 test_return_t
set_memory_alloc(memcached_st
*memc
)
3045 test_compare(MEMCACHED_INVALID_ARGUMENTS
,
3046 memcached_set_memory_allocators(memc
, NULL
, my_free
,
3047 my_realloc
, my_calloc
, NULL
));
3049 test_compare(MEMCACHED_SUCCESS
,
3050 memcached_set_memory_allocators(memc
, my_malloc
, my_free
,
3051 my_realloc
, my_calloc
, NULL
));
3053 memcached_malloc_fn mem_malloc
;
3054 memcached_free_fn mem_free
;
3055 memcached_realloc_fn mem_realloc
;
3056 memcached_calloc_fn mem_calloc
;
3057 memcached_get_memory_allocators(memc
, &mem_malloc
, &mem_free
,
3058 &mem_realloc
, &mem_calloc
);
3060 test_true(mem_malloc
== my_malloc
);
3061 test_true(mem_realloc
== my_realloc
);
3062 test_true(mem_calloc
== my_calloc
);
3063 test_true(mem_free
== my_free
);
3065 return TEST_SUCCESS
;
3068 test_return_t
enable_consistent_crc(memcached_st
*memc
)
3070 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, MEMCACHED_DISTRIBUTION_CONSISTENT
));
3071 test_compare(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
), uint64_t(MEMCACHED_DISTRIBUTION_CONSISTENT
));
3074 if ((rc
= pre_crc(memc
)) != TEST_SUCCESS
)
3079 test_compare(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
), uint64_t(MEMCACHED_DISTRIBUTION_CONSISTENT
));
3081 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
) != MEMCACHED_HASH_CRC
)
3083 return TEST_SKIPPED
;
3086 return TEST_SUCCESS
;
3089 test_return_t
enable_consistent_hsieh(memcached_st
*memc
)
3092 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, MEMCACHED_DISTRIBUTION_CONSISTENT
);
3093 if ((rc
= pre_hsieh(memc
)) != TEST_SUCCESS
)
3098 test_compare(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
), uint64_t(MEMCACHED_DISTRIBUTION_CONSISTENT
));
3100 if (memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
) != MEMCACHED_HASH_HSIEH
)
3102 return TEST_SKIPPED
;
3105 return TEST_SUCCESS
;
3108 test_return_t
enable_cas(memcached_st
*memc
)
3110 if (libmemcached_util_version_check(memc
, 1, 2, 4))
3112 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, true);
3114 return TEST_SUCCESS
;
3117 return TEST_SKIPPED
;
3120 test_return_t
check_for_1_2_3(memcached_st
*memc
)
3122 memcached_version(memc
);
3124 memcached_server_instance_st instance
=
3125 memcached_server_instance_by_position(memc
, 0);
3127 if ((instance
->major_version
>= 1 && (instance
->minor_version
== 2 && instance
->micro_version
>= 4))
3128 or instance
->minor_version
> 2)
3130 return TEST_SUCCESS
;
3133 return TEST_SKIPPED
;
3136 test_return_t
MEMCACHED_BEHAVIOR_POLL_TIMEOUT_test(memcached_st
*memc
)
3138 const uint64_t timeout
= 100; // Not using, just checking that it sets
3140 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, timeout
);
3142 test_compare(timeout
, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
));
3144 return TEST_SUCCESS
;
3147 test_return_t
noreply_test(memcached_st
*memc
)
3149 test_compare(MEMCACHED_SUCCESS
,
3150 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, true));
3151 test_compare(MEMCACHED_SUCCESS
,
3152 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, true));
3153 test_compare(MEMCACHED_SUCCESS
,
3154 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, true));
3155 test_compare(1LLU, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NOREPLY
));
3156 test_compare(1LLU, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
));
3157 test_compare(1LLU, memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
));
3159 memcached_return_t ret
;
3160 for (int count
= 0; count
< 5; ++count
)
3162 for (size_t x
= 0; x
< 100; ++x
)
3164 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1];
3165 int check_length
= (size_t)snprintf(key
, sizeof(key
), "%lu", (unsigned long)x
);
3166 test_false((size_t)check_length
>= sizeof(key
) || check_length
< 0);
3168 size_t len
= (size_t)check_length
;
3173 ret
= memcached_add(memc
, key
, len
, key
, len
, 0, 0);
3176 ret
= memcached_replace(memc
, key
, len
, key
, len
, 0, 0);
3179 ret
= memcached_set(memc
, key
, len
, key
, len
, 0, 0);
3182 ret
= memcached_append(memc
, key
, len
, key
, len
, 0, 0);
3185 ret
= memcached_prepend(memc
, key
, len
, key
, len
, 0, 0);
3191 test_true_got(ret
== MEMCACHED_SUCCESS
or ret
== MEMCACHED_BUFFERED
,
3192 memcached_strerror(NULL
, ret
));
3196 ** NOTE: Don't ever do this in your code! this is not a supported use of the
3197 ** API and is _ONLY_ done this way to verify that the library works the
3198 ** way it is supposed to do!!!!
3202 for (uint32_t x
= 0; x
< memcached_server_count(memc
); ++x
)
3204 memcached_server_instance_st instance
=
3205 memcached_server_instance_by_position(memc
, x
);
3206 no_msg
+=(int)(instance
->cursor_active
);
3209 test_true(no_msg
== 0);
3211 test_compare(MEMCACHED_SUCCESS
, memcached_flush_buffers(memc
));
3214 ** Now validate that all items was set properly!
3216 for (size_t x
= 0; x
< 100; ++x
)
3220 int check_length
= (size_t)snprintf(key
, sizeof(key
), "%lu", (unsigned long)x
);
3222 test_false((size_t)check_length
>= sizeof(key
) || check_length
< 0);
3224 size_t len
= (size_t)check_length
;
3227 char* value
=memcached_get(memc
, key
, strlen(key
),
3228 &length
, &flags
, &ret
);
3229 // For the moment we will just go to the next key
3230 if (MEMCACHED_TIMEOUT
== ret
)
3234 test_true(ret
== MEMCACHED_SUCCESS
and value
!= NULL
);
3237 case 0: /* FALLTHROUGH */
3238 case 1: /* FALLTHROUGH */
3240 test_true(strncmp(value
, key
, len
) == 0);
3241 test_true(len
== length
);
3244 test_true(length
== len
* 2);
3247 test_true(length
== len
* 3);
3257 /* Try setting an illegal cas value (should not return an error to
3258 * the caller (because we don't expect a return message from the server)
3260 const char* keys
[]= {"0"};
3261 size_t lengths
[]= {1};
3264 memcached_result_st results_obj
;
3265 memcached_result_st
*results
;
3266 test_compare(MEMCACHED_SUCCESS
,
3267 memcached_mget(memc
, keys
, lengths
, 1));
3269 results
= memcached_result_create(memc
, &results_obj
);
3271 results
= memcached_fetch_result(memc
, &results_obj
, &ret
);
3273 test_compare(MEMCACHED_SUCCESS
, ret
);
3274 uint64_t cas
= memcached_result_cas(results
);
3275 memcached_result_free(&results_obj
);
3277 test_compare(MEMCACHED_SUCCESS
,
3278 memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
));
3281 * The item will have a new cas value, so try to set it again with the old
3282 * value. This should fail!
3284 test_compare(MEMCACHED_SUCCESS
,
3285 memcached_cas(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0, cas
));
3286 test_true(memcached_flush_buffers(memc
) == MEMCACHED_SUCCESS
);
3287 char* value
=memcached_get(memc
, keys
[0], lengths
[0], &length
, &flags
, &ret
);
3288 test_true(ret
== MEMCACHED_SUCCESS
&& value
!= NULL
);
3291 return TEST_SUCCESS
;
3294 test_return_t
analyzer_test(memcached_st
*memc
)
3296 memcached_analysis_st
*report
;
3297 memcached_return_t rc
;
3299 memcached_stat_st
*memc_stat
= memcached_stat(memc
, NULL
, &rc
);
3300 test_compare(MEMCACHED_SUCCESS
, rc
);
3301 test_true(memc_stat
);
3303 report
= memcached_analyze(memc
, memc_stat
, &rc
);
3304 test_compare(MEMCACHED_SUCCESS
, rc
);
3308 memcached_stat_free(NULL
, memc_stat
);
3310 return TEST_SUCCESS
;
3313 test_return_t
util_version_test(memcached_st
*memc
)
3315 test_compare(MEMCACHED_SUCCESS
, memcached_version(memc
));
3316 test_true(libmemcached_util_version_check(memc
, 0, 0, 0));
3318 bool if_successful
= libmemcached_util_version_check(memc
, 9, 9, 9);
3320 // We expect failure
3323 fprintf(stderr
, "\n----------------------------------------------------------------------\n");
3324 fprintf(stderr
, "\nDumping Server Information\n\n");
3325 memcached_server_fn callbacks
[1];
3327 callbacks
[0]= dump_server_information
;
3328 memcached_server_cursor(memc
, callbacks
, (void *)stderr
, 1);
3329 fprintf(stderr
, "\n----------------------------------------------------------------------\n");
3331 test_true(if_successful
== false);
3333 memcached_server_instance_st instance
=
3334 memcached_server_instance_by_position(memc
, 0);
3336 memcached_version(memc
);
3338 // We only use one binary when we test, so this should be just fine.
3339 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, instance
->minor_version
, instance
->micro_version
);
3340 test_true(if_successful
== true);
3342 if (instance
->micro_version
> 0)
3344 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, instance
->minor_version
, (uint8_t)(instance
->micro_version
-1));
3346 else if (instance
->minor_version
> 0)
3348 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, (uint8_t)(instance
->minor_version
- 1), instance
->micro_version
);
3350 else if (instance
->major_version
> 0)
3352 if_successful
= libmemcached_util_version_check(memc
, (uint8_t)(instance
->major_version
-1), instance
->minor_version
, instance
->micro_version
);
3355 test_true(if_successful
== true);
3357 if (instance
->micro_version
> 0)
3359 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, instance
->minor_version
, (uint8_t)(instance
->micro_version
+1));
3361 else if (instance
->minor_version
> 0)
3363 if_successful
= libmemcached_util_version_check(memc
, instance
->major_version
, (uint8_t)(instance
->minor_version
+1), instance
->micro_version
);
3365 else if (instance
->major_version
> 0)
3367 if_successful
= libmemcached_util_version_check(memc
, (uint8_t)(instance
->major_version
+1), instance
->minor_version
, instance
->micro_version
);
3370 test_true(if_successful
== false);
3372 return TEST_SUCCESS
;
3375 test_return_t
getpid_connection_failure_test(memcached_st
*memc
)
3377 test_skip(memc
->servers
[0].type
, MEMCACHED_CONNECTION_TCP
);
3378 memcached_return_t rc
;
3379 memcached_server_instance_st instance
=
3380 memcached_server_instance_by_position(memc
, 0);
3382 // Test both the version that returns a code, and the one that does not.
3383 test_true(libmemcached_util_getpid(memcached_server_name(instance
),
3384 memcached_server_port(instance
) -1, NULL
) == -1);
3386 test_true(libmemcached_util_getpid(memcached_server_name(instance
),
3387 memcached_server_port(instance
) -1, &rc
) == -1);
3388 test_compare_got(MEMCACHED_CONNECTION_FAILURE
, rc
, memcached_strerror(memc
, rc
));
3390 return TEST_SUCCESS
;
3394 test_return_t
getpid_test(memcached_st
*memc
)
3396 memcached_return_t rc
;
3397 memcached_server_instance_st instance
=
3398 memcached_server_instance_by_position(memc
, 0);
3400 // Test both the version that returns a code, and the one that does not.
3401 test_true(libmemcached_util_getpid(memcached_server_name(instance
),
3402 memcached_server_port(instance
), NULL
) > -1);
3404 test_true(libmemcached_util_getpid(memcached_server_name(instance
),
3405 memcached_server_port(instance
), &rc
) > -1);
3406 test_compare(MEMCACHED_SUCCESS
, rc
);
3408 return TEST_SUCCESS
;
3411 static memcached_return_t
ping_each_server(const memcached_st
*,
3412 memcached_server_instance_st instance
,
3415 // Test both the version that returns a code, and the one that does not.
3416 memcached_return_t rc
;
3417 if (libmemcached_util_ping(memcached_server_name(instance
),
3418 memcached_server_port(instance
), &rc
) == false)
3420 throw libtest::fatal(LIBYATL_DEFAULT_PARAM
, "%s:%d %s", memcached_server_name(instance
),
3421 memcached_server_port(instance
), memcached_strerror(NULL
, rc
));
3424 if (libmemcached_util_ping(memcached_server_name(instance
),
3425 memcached_server_port(instance
), NULL
) == false)
3427 throw libtest::fatal(LIBYATL_DEFAULT_PARAM
, "%s:%d", memcached_server_name(instance
), memcached_server_port(instance
));
3430 return MEMCACHED_SUCCESS
;
3433 test_return_t
libmemcached_util_ping_TEST(memcached_st
*memc
)
3435 memcached_server_fn callbacks
[1]= { ping_each_server
};
3436 memcached_server_cursor(memc
, callbacks
, NULL
, 1);
3438 return TEST_SUCCESS
;
3443 test_return_t
hash_sanity_test (memcached_st
*memc
)
3447 assert(MEMCACHED_HASH_DEFAULT
== MEMCACHED_HASH_DEFAULT
);
3448 assert(MEMCACHED_HASH_MD5
== MEMCACHED_HASH_MD5
);
3449 assert(MEMCACHED_HASH_CRC
== MEMCACHED_HASH_CRC
);
3450 assert(MEMCACHED_HASH_FNV1_64
== MEMCACHED_HASH_FNV1_64
);
3451 assert(MEMCACHED_HASH_FNV1A_64
== MEMCACHED_HASH_FNV1A_64
);
3452 assert(MEMCACHED_HASH_FNV1_32
== MEMCACHED_HASH_FNV1_32
);
3453 assert(MEMCACHED_HASH_FNV1A_32
== MEMCACHED_HASH_FNV1A_32
);
3454 #ifdef HAVE_HSIEH_HASH
3455 assert(MEMCACHED_HASH_HSIEH
== MEMCACHED_HASH_HSIEH
);
3457 assert(MEMCACHED_HASH_MURMUR
== MEMCACHED_HASH_MURMUR
);
3458 assert(MEMCACHED_HASH_JENKINS
== MEMCACHED_HASH_JENKINS
);
3459 assert(MEMCACHED_HASH_MAX
== MEMCACHED_HASH_MAX
);
3461 return TEST_SUCCESS
;
3465 test_return_t
hsieh_avaibility_test (memcached_st
*memc
)
3467 test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_HSIEH
));
3469 test_compare(MEMCACHED_SUCCESS
,
3470 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
,
3471 (uint64_t)MEMCACHED_HASH_HSIEH
));
3473 return TEST_SUCCESS
;
3476 test_return_t
murmur_avaibility_test (memcached_st
*memc
)
3478 test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_MURMUR
));
3480 test_compare(MEMCACHED_SUCCESS
,
3481 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, (uint64_t)MEMCACHED_HASH_MURMUR
));
3483 return TEST_SUCCESS
;
3486 test_return_t
one_at_a_time_run (memcached_st
*)
3491 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
3493 test_compare(one_at_a_time_values
[x
],
3494 memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_DEFAULT
));
3497 return TEST_SUCCESS
;
3500 test_return_t
md5_run (memcached_st
*)
3505 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
3507 test_compare(md5_values
[x
],
3508 memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MD5
));
3511 return TEST_SUCCESS
;
3514 test_return_t
crc_run (memcached_st
*)
3519 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
3521 test_compare(crc_values
[x
],
3522 memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_CRC
));
3525 return TEST_SUCCESS
;
3528 test_return_t
fnv1_64_run (memcached_st
*)
3530 test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_FNV1_64
));
3535 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
3537 test_compare(fnv1_64_values
[x
],
3538 memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_64
));
3541 return TEST_SUCCESS
;
3544 test_return_t
fnv1a_64_run (memcached_st
*)
3546 test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_FNV1A_64
));
3551 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
3553 test_compare(fnv1a_64_values
[x
],
3554 memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_64
));
3557 return TEST_SUCCESS
;
3560 test_return_t
fnv1_32_run (memcached_st
*)
3565 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
3567 test_compare(fnv1_32_values
[x
],
3568 memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1_32
));
3571 return TEST_SUCCESS
;
3574 test_return_t
fnv1a_32_run (memcached_st
*)
3579 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
3581 test_compare(fnv1a_32_values
[x
],
3582 memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_FNV1A_32
));
3585 return TEST_SUCCESS
;
3588 test_return_t
hsieh_run (memcached_st
*)
3590 test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_HSIEH
));
3595 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
3597 test_compare(hsieh_values
[x
],
3598 memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_HSIEH
));
3601 return TEST_SUCCESS
;
3604 test_return_t
murmur_run (memcached_st
*)
3606 test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_MURMUR
));
3608 #ifdef WORDS_BIGENDIAN
3609 (void)murmur_values
;
3610 return TEST_SKIPPED
;
3615 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
3617 test_compare(murmur_values
[x
],
3618 memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_MURMUR
));
3621 return TEST_SUCCESS
;
3625 test_return_t
jenkins_run (memcached_st
*)
3630 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
3632 test_compare(jenkins_values
[x
],
3633 memcached_generate_hash_value(*ptr
, strlen(*ptr
), MEMCACHED_HASH_JENKINS
));
3636 return TEST_SUCCESS
;
3639 static uint32_t hash_md5_test_function(const char *string
, size_t string_length
, void *)
3641 return libhashkit_md5(string
, string_length
);
3644 static uint32_t hash_crc_test_function(const char *string
, size_t string_length
, void *)
3646 return libhashkit_crc32(string
, string_length
);
3649 test_return_t
memcached_get_hashkit_test (memcached_st
*)
3655 memcached_st
*memc
= memcached(test_literal_param("--server=localhost:1 --server=localhost:2 --server=localhost:3 --server=localhost:4 --server=localhost5 --DISTRIBUTION=modula"));
3657 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};
3658 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};
3660 const hashkit_st
*kit
= memcached_get_hashkit(memc
);
3662 hashkit_clone(&new_kit
, kit
);
3663 test_compare(HASHKIT_SUCCESS
, hashkit_set_custom_function(&new_kit
, hash_md5_test_function
, NULL
));
3665 memcached_set_hashkit(memc
, &new_kit
);
3668 Verify Setting the hash.
3670 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
3674 hash_val
= hashkit_digest(kit
, *ptr
, strlen(*ptr
));
3675 test_compare_got(md5_values
[x
], hash_val
, *ptr
);
3680 Now check memcached_st.
3682 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
3686 hash_val
= memcached_generate_hash(memc
, *ptr
, strlen(*ptr
));
3687 test_compare_got(md5_hosts
[x
], hash_val
, *ptr
);
3690 test_compare(HASHKIT_SUCCESS
, hashkit_set_custom_function(&new_kit
, hash_crc_test_function
, NULL
));
3692 memcached_set_hashkit(memc
, &new_kit
);
3695 Verify Setting the hash.
3697 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
3701 hash_val
= hashkit_digest(kit
, *ptr
, strlen(*ptr
));
3702 test_true(crc_values
[x
] == hash_val
);
3705 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
3709 hash_val
= memcached_generate_hash(memc
, *ptr
, strlen(*ptr
));
3710 test_compare(crc_hosts
[x
], hash_val
);
3713 memcached_free(memc
);
3715 return TEST_SUCCESS
;
3719 Test case adapted from John Gorman <johngorman2@gmail.com>
3721 We are testing the error condition when we connect to a server via memcached_get()
3722 but find that the server is not available.
3724 test_return_t
memcached_get_MEMCACHED_ERRNO(memcached_st
*)
3728 memcached_return rc
;
3731 memcached_st
*tl_memc_h
= memcached(test_literal_param("--server=localhost:9898 --server=localhost:9899")); // This server should not exist
3733 // See if memcached is reachable.
3734 char *value
= memcached_get(tl_memc_h
,
3735 test_literal_param(__func__
),
3740 test_true(memcached_failed(rc
));
3742 memcached_free(tl_memc_h
);
3744 return TEST_SUCCESS
;
3748 We connect to a server which exists, but search for a key that does not exist.
3750 test_return_t
memcached_get_MEMCACHED_NOTFOUND(memcached_st
*memc
)
3754 memcached_return rc
;
3756 // See if memcached is reachable.
3757 char *value
= memcached_get(memc
,
3758 test_literal_param(__func__
),
3763 test_compare(MEMCACHED_NOTFOUND
, rc
);
3765 return TEST_SUCCESS
;
3769 Test case adapted from John Gorman <johngorman2@gmail.com>
3771 We are testing the error condition when we connect to a server via memcached_get_by_key()
3772 but find that the server is not available.
3774 test_return_t
memcached_get_by_key_MEMCACHED_ERRNO(memcached_st
*)
3778 memcached_return rc
;
3781 memcached_st
*tl_memc_h
= memcached_create(NULL
);
3782 memcached_server_st
*servers
= memcached_servers_parse("localhost:9898,localhost:9899"); // This server should not exist
3783 memcached_server_push(tl_memc_h
, servers
);
3784 memcached_server_list_free(servers
);
3786 // See if memcached is reachable.
3787 char *value
= memcached_get_by_key(tl_memc_h
,
3788 test_literal_param(__func__
), // Key
3789 test_literal_param(__func__
), // Value
3794 test_true(memcached_failed(rc
));
3796 memcached_free(tl_memc_h
);
3798 return TEST_SUCCESS
;
3802 We connect to a server which exists, but search for a key that does not exist.
3804 test_return_t
memcached_get_by_key_MEMCACHED_NOTFOUND(memcached_st
*memc
)
3808 memcached_return rc
;
3810 // See if memcached is reachable.
3811 char *value
= memcached_get_by_key(memc
,
3812 test_literal_param(__func__
), // Key
3813 test_literal_param(__func__
), // Value
3818 test_compare(MEMCACHED_NOTFOUND
, rc
);
3820 return TEST_SUCCESS
;
3823 test_return_t
regression_bug_434484(memcached_st
*memc
)
3825 test_skip(TEST_SUCCESS
, pre_binary(memc
));
3827 test_compare(MEMCACHED_NOTSTORED
,
3828 memcached_append(memc
,
3829 test_literal_param(__func__
), // Key
3830 test_literal_param(__func__
), // Value
3833 libtest::vchar_t data
;
3834 data
.resize(2048 * 1024);
3835 test_compare(MEMCACHED_E2BIG
,
3837 test_literal_param(__func__
), // Key
3838 &data
[0], data
.size(), 0, 0));
3840 return TEST_SUCCESS
;
3843 test_return_t
regression_bug_434843(memcached_st
*original_memc
)
3845 test_skip(TEST_SUCCESS
, pre_binary(original_memc
));
3847 memcached_return_t rc
;
3849 memcached_execute_fn callbacks
[]= { &callback_counter
};
3852 * I only want to hit only _one_ server so I know the number of requests I'm
3853 * sending in the pipleine to the server. Let's try to do a multiget of
3854 * 1024 (that should satisfy most users don't you think?). Future versions
3855 * will include a mget_execute function call if you need a higher number.
3857 memcached_st
*memc
= create_single_instance_memcached(original_memc
, "--BINARY-PROTOCOL");
3862 * Run two times.. the first time we should have 100% cache miss,
3863 * and the second time we should have 100% cache hits
3865 for (ptrdiff_t y
= 0; y
< 2; y
++)
3867 test_compare(MEMCACHED_SUCCESS
,
3868 memcached_mget(memc
, keys
.keys_ptr(), keys
.lengths_ptr(), keys
.size()));
3870 // One the first run we should get a NOT_FOUND, but on the second some data
3871 // should be returned.
3872 test_compare(y
? MEMCACHED_SUCCESS
: MEMCACHED_NOTFOUND
,
3873 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
3877 /* The first iteration should give me a 100% cache miss. verify that*/
3878 char blob
[1024]= { 0 };
3880 test_false(counter
);
3882 for (size_t x
= 0; x
< keys
.size(); ++x
)
3884 rc
= memcached_add(memc
,
3885 keys
.key_at(x
), keys
.length_at(x
),
3886 blob
, sizeof(blob
), 0, 0);
3887 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
3892 /* Verify that we received all of the key/value pairs */
3893 test_compare(counter
, keys
.size());
3897 memcached_free(memc
);
3899 return TEST_SUCCESS
;
3902 test_return_t
regression_bug_434843_buffered(memcached_st
*memc
)
3904 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, true));
3906 return regression_bug_434843(memc
);
3909 test_return_t
regression_bug_421108(memcached_st
*memc
)
3911 memcached_return_t rc
;
3912 memcached_stat_st
*memc_stat
= memcached_stat(memc
, NULL
, &rc
);
3913 test_compare(MEMCACHED_SUCCESS
, rc
);
3915 char *bytes_str
= memcached_stat_get_value(memc
, memc_stat
, "bytes", &rc
);
3916 test_compare(MEMCACHED_SUCCESS
, rc
);
3917 test_true(bytes_str
);
3918 char *bytes_read_str
= memcached_stat_get_value(memc
, memc_stat
,
3920 test_compare(MEMCACHED_SUCCESS
, rc
);
3921 test_true(bytes_read_str
);
3923 char *bytes_written_str
= memcached_stat_get_value(memc
, memc_stat
,
3924 "bytes_written", &rc
);
3925 test_compare(MEMCACHED_SUCCESS
, rc
);
3926 test_true(bytes_written_str
);
3928 unsigned long long bytes
= strtoull(bytes_str
, 0, 10);
3929 unsigned long long bytes_read
= strtoull(bytes_read_str
, 0, 10);
3930 unsigned long long bytes_written
= strtoull(bytes_written_str
, 0, 10);
3932 test_true(bytes
!= bytes_read
);
3933 test_true(bytes
!= bytes_written
);
3935 /* Release allocated resources */
3937 free(bytes_read_str
);
3938 free(bytes_written_str
);
3939 memcached_stat_free(NULL
, memc_stat
);
3941 return TEST_SUCCESS
;
3945 * The test case isn't obvious so I should probably document why
3946 * it works the way it does. Bug 442914 was caused by a bug
3947 * in the logic in memcached_purge (it did not handle the case
3948 * where the number of bytes sent was equal to the watermark).
3949 * In this test case, create messages so that we hit that case
3950 * and then disable noreply mode and issue a new command to
3951 * verify that it isn't stuck. If we change the format for the
3952 * delete command or the watermarks, we need to update this
3955 test_return_t
regression_bug_442914(memcached_st
*original_memc
)
3957 test_skip(original_memc
->servers
[0].type
, MEMCACHED_CONNECTION_TCP
);
3959 memcached_st
* memc
= create_single_instance_memcached(original_memc
, "--NOREPLY --TCP-NODELAY");
3961 for (uint32_t x
= 0; x
< 250; ++x
)
3964 size_t len
= (size_t)snprintf(key
, sizeof(key
), "%0250u", x
);
3965 memcached_return_t rc
= memcached_delete(memc
, key
, len
, 0);
3966 char error_buffer
[2048]= { 0 };
3967 snprintf(error_buffer
, sizeof(error_buffer
), "%s key: %s", memcached_last_error_message(memc
), key
);
3968 test_true_got(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
, error_buffer
);
3971 // Delete, and then delete again to look for not found
3974 size_t len
= snprintf(key
, sizeof(key
), "%037u", 251U);
3975 memcached_return_t rc
= memcached_delete(memc
, key
, len
, 0);
3976 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
3978 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, false));
3979 test_compare(MEMCACHED_NOTFOUND
, memcached_delete(memc
, key
, len
, 0));
3982 memcached_free(memc
);
3984 return TEST_SUCCESS
;
3987 test_return_t
regression_bug_447342(memcached_st
*memc
)
3989 if (memcached_server_count(memc
) < 3 or pre_replication(memc
) != TEST_SUCCESS
)
3991 return TEST_SKIPPED
;
3994 test_compare(MEMCACHED_SUCCESS
,
3995 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS
, 2));
3999 for (size_t x
= 0; x
< keys
.size(); ++x
)
4001 test_compare(MEMCACHED_SUCCESS
,
4003 keys
.key_at(x
), keys
.length_at(x
), // Keys
4004 keys
.key_at(x
), keys
.length_at(x
), // Values
4009 ** We are using the quiet commands to store the replicas, so we need
4010 ** to ensure that all of them are processed before we can continue.
4011 ** In the test we go directly from storing the object to trying to
4012 ** receive the object from all of the different servers, so we
4013 ** could end up in a race condition (the memcached server hasn't yet
4014 ** processed the quiet command from the replication set when it process
4015 ** the request from the other client (created by the clone)). As a
4016 ** workaround for that we call memcached_quit to send the quit command
4017 ** to the server and wait for the response ;-) If you use the test code
4018 ** as an example for your own code, please note that you shouldn't need
4021 memcached_quit(memc
);
4023 /* Verify that all messages are stored, and we didn't stuff too much
4026 test_compare(MEMCACHED_SUCCESS
,
4027 memcached_mget(memc
,
4028 keys
.keys_ptr(), keys
.lengths_ptr(), keys
.size()));
4030 unsigned int counter
= 0;
4031 memcached_execute_fn callbacks
[]= { &callback_counter
};
4032 test_compare(MEMCACHED_SUCCESS
,
4033 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
4035 /* Verify that we received all of the key/value pairs */
4036 test_compare(counter
, keys
.size());
4038 memcached_quit(memc
);
4040 * Don't do the following in your code. I am abusing the internal details
4041 * within the library, and this is not a supported interface.
4042 * This is to verify correct behavior in the library. Fake that two servers
4045 memcached_server_instance_st instance_one
= memcached_server_instance_by_position(memc
, 0);
4046 memcached_server_instance_st instance_two
= memcached_server_instance_by_position(memc
, 2);
4047 in_port_t port0
= instance_one
->port();
4048 in_port_t port2
= instance_two
->port();
4050 ((memcached_server_write_instance_st
)instance_one
)->port(0);
4051 ((memcached_server_write_instance_st
)instance_two
)->port(0);
4053 test_compare(MEMCACHED_SUCCESS
,
4054 memcached_mget(memc
,
4055 keys
.keys_ptr(), keys
.lengths_ptr(), keys
.size()));
4058 test_compare(MEMCACHED_SUCCESS
,
4059 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
4060 test_compare(counter
, keys
.size());
4062 /* restore the memc handle */
4063 ((memcached_server_write_instance_st
)instance_one
)->port(port0
);
4064 ((memcached_server_write_instance_st
)instance_two
)->port(port2
);
4066 memcached_quit(memc
);
4068 /* Remove half of the objects */
4069 for (size_t x
= 0; x
< keys
.size(); ++x
)
4073 test_compare(MEMCACHED_SUCCESS
,
4074 memcached_delete(memc
, keys
.key_at(x
), keys
.length_at(x
), 0));
4078 memcached_quit(memc
);
4079 ((memcached_server_write_instance_st
)instance_one
)->port(0);
4080 ((memcached_server_write_instance_st
)instance_two
)->port(0);
4082 /* now retry the command, this time we should have cache misses */
4083 test_compare(MEMCACHED_SUCCESS
,
4084 memcached_mget(memc
,
4085 keys
.keys_ptr(), keys
.lengths_ptr(), keys
.size()));
4088 test_compare(MEMCACHED_SUCCESS
,
4089 memcached_fetch_execute(memc
, callbacks
, (void *)&counter
, 1));
4090 test_compare(counter
, (unsigned int)(keys
.size() >> 1));
4092 /* restore the memc handle */
4093 ((memcached_server_write_instance_st
)instance_one
)->port(port0
);
4094 ((memcached_server_write_instance_st
)instance_two
)->port(port2
);
4096 return TEST_SUCCESS
;
4099 test_return_t
regression_bug_463297(memcached_st
*memc
)
4101 test_compare(MEMCACHED_INVALID_ARGUMENTS
, memcached_delete(memc
, "foo", 3, 1));
4103 // Since we blocked timed delete, this test is no longer valid.
4105 memcached_st
*memc_clone
= memcached_clone(NULL
, memc
);
4106 test_true(memc_clone
);
4107 test_true(memcached_version(memc_clone
) == MEMCACHED_SUCCESS
);
4109 memcached_server_instance_st instance
=
4110 memcached_server_instance_by_position(memc_clone
, 0);
4112 if (instance
->major_version
> 1 ||
4113 (instance
->major_version
== 1 &&
4114 instance
->minor_version
> 2))
4116 /* Binary protocol doesn't support deferred delete */
4117 memcached_st
*bin_clone
= memcached_clone(NULL
, memc
);
4118 test_true(bin_clone
);
4119 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(bin_clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1));
4120 test_compare(MEMCACHED_INVALID_ARGUMENTS
, memcached_delete(bin_clone
, "foo", 3, 1));
4121 memcached_free(bin_clone
);
4123 memcached_quit(memc_clone
);
4125 /* If we know the server version, deferred delete should fail
4126 * with invalid arguments */
4127 test_compare(MEMCACHED_INVALID_ARGUMENTS
, memcached_delete(memc_clone
, "foo", 3, 1));
4129 /* If we don't know the server version, we should get a protocol error */
4130 memcached_return_t rc
= memcached_delete(memc
, "foo", 3, 1);
4132 /* but there is a bug in some of the memcached servers (1.4) that treats
4133 * the counter as noreply so it doesn't send the proper error message
4135 test_true_got(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
|| rc
== MEMCACHED_INVALID_ARGUMENTS
, memcached_strerror(NULL
, rc
));
4137 /* And buffered mode should be disabled and we should get protocol error */
4138 test_true(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 1) == MEMCACHED_SUCCESS
);
4139 rc
= memcached_delete(memc
, "foo", 3, 1);
4140 test_true_got(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
|| rc
== MEMCACHED_INVALID_ARGUMENTS
, memcached_strerror(NULL
, rc
));
4142 /* Same goes for noreply... */
4143 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 1));
4144 rc
= memcached_delete(memc
, "foo", 3, 1);
4145 test_true_got(rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_NOTFOUND
|| rc
== MEMCACHED_CLIENT_ERROR
|| rc
== MEMCACHED_INVALID_ARGUMENTS
, memcached_strerror(NULL
, rc
));
4147 /* but a normal request should go through (and be buffered) */
4148 test_compare(MEMCACHED_BUFFERED
, (rc
= memcached_delete(memc
, "foo", 3, 0)));
4149 test_compare(MEMCACHED_SUCCESS
, memcached_flush_buffers(memc
));
4151 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, 0));
4152 /* unbuffered noreply should be success */
4153 test_compare(MEMCACHED_SUCCESS
, memcached_delete(memc
, "foo", 3, 0));
4154 /* unbuffered with reply should be not found... */
4155 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NOREPLY
, 0));
4156 test_compare(MEMCACHED_NOTFOUND
, memcached_delete(memc
, "foo", 3, 0));
4159 memcached_free(memc_clone
);
4162 return TEST_SUCCESS
;
4166 /* Test memcached_server_get_last_disconnect
4167 * For a working server set, shall be NULL
4168 * For a set of non existing server, shall not be NULL
4170 test_return_t
test_get_last_disconnect(memcached_st
*memc
)
4172 memcached_return_t rc
;
4173 memcached_server_instance_st disconnected_server
;
4175 /* With the working set of server */
4176 const char *key
= "marmotte";
4177 const char *value
= "milka";
4179 memcached_reset_last_disconnected_server(memc
);
4180 test_false(memc
->last_disconnected_server
);
4181 rc
= memcached_set(memc
, key
, strlen(key
),
4182 value
, strlen(value
),
4183 (time_t)0, (uint32_t)0);
4184 test_true(rc
== MEMCACHED_SUCCESS
|| rc
== MEMCACHED_BUFFERED
);
4186 disconnected_server
= memcached_server_get_last_disconnect(memc
);
4187 test_false(disconnected_server
);
4189 /* With a non existing server */
4191 memcached_server_st
*servers
;
4193 const char *server_list
= "localhost:9";
4195 servers
= memcached_servers_parse(server_list
);
4197 mine
= memcached_create(NULL
);
4198 rc
= memcached_server_push(mine
, servers
);
4199 test_compare(MEMCACHED_SUCCESS
, rc
);
4200 memcached_server_list_free(servers
);
4203 rc
= memcached_set(mine
, key
, strlen(key
),
4204 value
, strlen(value
),
4205 (time_t)0, (uint32_t)0);
4206 test_true(memcached_failed(rc
));
4208 disconnected_server
= memcached_server_get_last_disconnect(mine
);
4209 test_true_got(disconnected_server
, memcached_strerror(mine
, rc
));
4210 test_compare(in_port_t(9), memcached_server_port(disconnected_server
));
4211 test_false(strncmp(memcached_server_name(disconnected_server
),"localhost",9));
4213 memcached_quit(mine
);
4214 memcached_free(mine
);
4216 return TEST_SUCCESS
;
4219 test_return_t
test_multiple_get_last_disconnect(memcached_st
*)
4221 const char *server_string
= "--server=localhost:8888 --server=localhost:8889 --server=localhost:8890 --server=localhost:8891 --server=localhost:8892";
4222 char buffer
[BUFSIZ
];
4224 test_compare(MEMCACHED_SUCCESS
,
4225 libmemcached_check_configuration(server_string
, strlen(server_string
), buffer
, sizeof(buffer
)));
4227 memcached_st
*memc
= memcached(server_string
, strlen(server_string
));
4230 // We will just use the error strings as our keys
4231 uint32_t counter
= 100;
4234 for (int x
= int(MEMCACHED_SUCCESS
); x
< int(MEMCACHED_MAXIMUM_RETURN
); ++x
)
4236 const char *msg
= memcached_strerror(memc
, memcached_return_t(x
));
4237 memcached_return_t ret
= memcached_set(memc
, msg
, strlen(msg
), NULL
, 0, (time_t)0, (uint32_t)0);
4238 test_true_got((ret
== MEMCACHED_CONNECTION_FAILURE
or ret
== MEMCACHED_SERVER_TEMPORARILY_DISABLED
), memcached_last_error_message(memc
));
4240 memcached_server_instance_st disconnected_server
= memcached_server_get_last_disconnect(memc
);
4241 test_true(disconnected_server
);
4242 test_strcmp("localhost", memcached_server_name(disconnected_server
));
4243 test_true(memcached_server_port(disconnected_server
) >= 8888 and memcached_server_port(disconnected_server
) <= 8892);
4247 memcached_reset_last_disconnected_server(memc
);
4252 memcached_free(memc
);
4254 return TEST_SUCCESS
;
4257 test_return_t
test_verbosity(memcached_st
*memc
)
4259 memcached_verbosity(memc
, 3);
4261 return TEST_SUCCESS
;
4265 static memcached_return_t
stat_printer(memcached_server_instance_st server
,
4266 const char *key
, size_t key_length
,
4267 const char *value
, size_t value_length
,
4277 return MEMCACHED_SUCCESS
;
4280 test_return_t
memcached_stat_execute_test(memcached_st
*memc
)
4282 memcached_return_t rc
= memcached_stat_execute(memc
, NULL
, stat_printer
, NULL
);
4283 test_compare(MEMCACHED_SUCCESS
, rc
);
4285 test_compare(MEMCACHED_SUCCESS
,
4286 memcached_stat_execute(memc
, "slabs", stat_printer
, NULL
));
4288 test_compare(MEMCACHED_SUCCESS
,
4289 memcached_stat_execute(memc
, "items", stat_printer
, NULL
));
4291 test_compare(MEMCACHED_SUCCESS
,
4292 memcached_stat_execute(memc
, "sizes", stat_printer
, NULL
));
4294 return TEST_SUCCESS
;
4298 * This test ensures that the failure counter isn't incremented during
4299 * normal termination of the memcached instance.
4301 test_return_t
wrong_failure_counter_test(memcached_st
*original_memc
)
4303 memcached_st
* memc
= create_single_instance_memcached(original_memc
, NULL
);
4305 /* Ensure that we are connected to the server by setting a value */
4306 memcached_return_t rc
= memcached_set(memc
,
4307 test_literal_param(__func__
), // Key
4308 test_literal_param(__func__
), // Value
4309 time_t(0), uint32_t(0));
4310 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
);
4313 memcached_server_instance_st instance
= memcached_server_instance_by_position(memc
, 0);
4315 /* The test is to see that the memcached_quit doesn't increase the
4316 * the server failure conter, so let's ensure that it is zero
4317 * before sending quit
4319 ((memcached_server_write_instance_st
)instance
)->server_failure_counter
= 0;
4321 memcached_quit(memc
);
4323 /* Verify that it memcached_quit didn't increment the failure counter
4324 * Please note that this isn't bullet proof, because an error could
4327 test_zero(instance
->server_failure_counter
);
4329 memcached_free(memc
);
4331 return TEST_SUCCESS
;
4335 * This tests ensures expected disconnections (for some behavior changes
4336 * for instance) do not wrongly increase failure counter
4338 test_return_t
wrong_failure_counter_two_test(memcached_st
*memc
)
4340 /* Set value to force connection to the server */
4341 const char *key
= "marmotte";
4342 const char *value
= "milka";
4344 test_compare_hint(MEMCACHED_SUCCESS
,
4345 memcached_set(memc
, key
, strlen(key
),
4346 value
, strlen(value
),
4347 (time_t)0, (uint32_t)0),
4348 memcached_last_error_message(memc
));
4351 /* put failure limit to 1 */
4352 test_compare(MEMCACHED_SUCCESS
,
4353 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, true));
4355 /* Put a retry timeout to effectively activate failure_limit effect */
4356 test_compare(MEMCACHED_SUCCESS
,
4357 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, true));
4359 /* change behavior that triggers memcached_quit()*/
4360 test_compare(MEMCACHED_SUCCESS
,
4361 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, true));
4364 /* Check if we still are connected */
4366 size_t string_length
;
4367 memcached_return rc
;
4368 char *string
= memcached_get(memc
, key
, strlen(key
),
4369 &string_length
, &flags
, &rc
);
4371 test_compare_got(MEMCACHED_SUCCESS
, rc
, memcached_strerror(NULL
, rc
));
4375 return TEST_SUCCESS
;
4378 test_return_t
regression_996813_TEST(memcached_st
*)
4380 memcached_st
* memc
= memcached_create(NULL
);
4382 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA
));
4383 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, 1));
4384 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1));
4385 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1));
4386 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, 1));
4387 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT
, 300));
4388 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 30));
4390 // We will never connect to these servers
4391 in_port_t base_port
= 11211;
4392 for (size_t x
= 0; x
< 17; x
++)
4394 test_compare(MEMCACHED_SUCCESS
, memcached_server_add(memc
, "10.2.3.4", base_port
+x
));
4396 test_compare(6U, memcached_generate_hash(memc
, test_literal_param("SZ6hu0SHweFmpwpc0w2R")));
4397 test_compare(1U, memcached_generate_hash(memc
, test_literal_param("SQCK9eiCf53YxHWnYA.o")));
4398 test_compare(9U, memcached_generate_hash(memc
, test_literal_param("SUSDkGXuuZC9t9VhMwa.")));
4399 test_compare(0U, memcached_generate_hash(memc
, test_literal_param("SnnqnJARfaCNT679iAF_")));
4401 memcached_free(memc
);
4403 return TEST_SUCCESS
;
4408 * Test that ensures mget_execute does not end into recursive calls that finally fails
4410 test_return_t
regression_bug_490486(memcached_st
*original_memc
)
4414 return TEST_SKIPPED
; // My MAC can't handle this test
4417 test_skip(TEST_SUCCESS
, pre_binary(original_memc
));
4420 * I only want to hit _one_ server so I know the number of requests I'm
4421 * sending in the pipeline.
4423 memcached_st
*memc
= create_single_instance_memcached(original_memc
, "--BINARY-PROTOCOL --POLL-TIMEOUT=1000 --REMOVE-FAILED-SERVERS=1 --RETRY-TIMEOUT=3600");
4426 keys_st
keys(20480);
4428 /* First add all of the items.. */
4429 char blob
[1024]= { 0 };
4430 for (size_t x
= 0; x
< keys
.size(); ++x
)
4432 memcached_return rc
= memcached_set(memc
,
4433 keys
.key_at(x
), keys
.length_at(x
),
4434 blob
, sizeof(blob
), 0, 0);
4435 test_true(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
); // MEMCACHED_TIMEOUT <-- hash been observed on OSX
4440 /* Try to get all of them with a large multiget */
4442 memcached_execute_function callbacks
[]= { &callback_counter
};
4443 memcached_return_t rc
= memcached_mget_execute(memc
,
4444 keys
.keys_ptr(), keys
.lengths_ptr(), keys
.size(),
4445 callbacks
, &counter
, 1);
4446 test_compare(MEMCACHED_SUCCESS
, rc
);
4448 char* the_value
= NULL
;
4449 char the_key
[MEMCACHED_MAX_KEY
];
4450 size_t the_key_length
;
4451 size_t the_value_length
;
4455 the_value
= memcached_fetch(memc
, the_key
, &the_key_length
, &the_value_length
, &the_flags
, &rc
);
4457 if ((the_value
!= NULL
) && (rc
== MEMCACHED_SUCCESS
))
4463 } while ( (the_value
!= NULL
) && (rc
== MEMCACHED_SUCCESS
));
4466 test_compare(MEMCACHED_END
, rc
);
4468 /* Verify that we got all of the items */
4469 test_compare(counter
, keys
.size());
4472 memcached_free(memc
);
4474 return TEST_SUCCESS
;
4477 test_return_t
regression_bug_583031(memcached_st
*)
4479 memcached_st
*memc
= memcached_create(NULL
);
4481 test_compare(MEMCACHED_SUCCESS
, memcached_server_add(memc
, "10.2.3.4", 11211));
4483 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT
, 1000);
4484 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 1000);
4485 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SND_TIMEOUT
, 1000);
4486 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RCV_TIMEOUT
, 1000);
4487 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, 1000);
4488 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
, 3);
4490 memcached_return_t rc
;
4494 const char *value
= memcached_get(memc
, "dsf", 3, &length
, &flags
, &rc
);
4498 test_compare_got(MEMCACHED_TIMEOUT
, rc
, memcached_last_error_message(memc
));
4500 memcached_free(memc
);
4502 return TEST_SUCCESS
;
4505 test_return_t
regression_bug_581030(memcached_st
*)
4508 memcached_stat_st
*local_stat
= memcached_stat(NULL
, NULL
, NULL
);
4509 test_false(local_stat
);
4511 memcached_stat_free(NULL
, NULL
);
4514 return TEST_SUCCESS
;
4517 #define regression_bug_655423_COUNT 6000
4518 test_return_t
regression_bug_655423(memcached_st
*memc
)
4520 memcached_st
*clone
= memcached_clone(NULL
, memc
);
4521 memc
= NULL
; // Just to make sure it is not used
4526 return TEST_SKIPPED
;
4529 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1));
4530 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, 1));
4531 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, 1));
4532 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(clone
, MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH
, 1));
4534 memset(payload
, int('x'), sizeof(payload
));
4536 keys_st
keys(regression_bug_655423_COUNT
);
4538 for (size_t x
= 0; x
< keys
.size(); x
++)
4540 test_compare(MEMCACHED_SUCCESS
, memcached_set(clone
,
4543 payload
, sizeof(payload
), 0, 0));
4546 for (size_t x
= 0; x
< keys
.size(); x
++)
4548 size_t value_length
;
4549 memcached_return_t rc
;
4550 char *value
= memcached_get(clone
,
4553 &value_length
, NULL
, &rc
);
4555 if (rc
== MEMCACHED_NOTFOUND
)
4558 test_zero(value_length
);
4562 test_compare(MEMCACHED_SUCCESS
, rc
);
4564 test_compare(100LLU, value_length
);
4568 test_compare(MEMCACHED_SUCCESS
,
4569 memcached_mget(clone
,
4570 keys
.keys_ptr(), keys
.lengths_ptr(),
4574 memcached_result_st
*result
= NULL
;
4575 while ((result
= memcached_fetch_result(clone
, result
, NULL
)))
4577 test_compare(size_t(100), memcached_result_length(result
));
4581 test_true(count
> 100); // If we don't get back atleast this, something is up
4583 memcached_free(clone
);
4585 return TEST_SUCCESS
;
4589 * Test that ensures that buffered set to not trigger problems during io_flush
4591 #define regression_bug_490520_COUNT 200480
4592 test_return_t
regression_bug_490520(memcached_st
*original_memc
)
4594 memcached_st
* memc
= create_single_instance_memcached(original_memc
, NULL
);
4596 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
,1);
4597 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
,1);
4598 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_POLL_TIMEOUT
, 1000);
4599 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT
,1);
4600 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
, 3600);
4602 /* First add all of the items.. */
4603 char blob
[3333] = {0};
4604 for (uint32_t x
= 0; x
< regression_bug_490520_COUNT
; ++x
)
4607 int key_length
= snprintf(key
, sizeof(key
), "0200%u", x
);
4609 memcached_return rc
= memcached_set(memc
, key
, key_length
, blob
, sizeof(blob
), 0, 0);
4610 test_true_got(rc
== MEMCACHED_SUCCESS
or rc
== MEMCACHED_BUFFERED
, memcached_last_error_message(memc
));
4613 memcached_free(memc
);
4615 return TEST_SUCCESS
;
4618 test_return_t
regression_1009493_TEST(memcached_st
*)
4620 memcached_st
* memc
= memcached_create(NULL
);
4622 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_KETAMA
, true));
4624 memcached_st
* clone
= memcached_clone(NULL
, memc
);
4627 test_compare(memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
),
4628 memcached_behavior_get(clone
, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
));
4630 memcached_free(memc
);
4631 memcached_free(clone
);
4633 return TEST_SUCCESS
;
4636 test_return_t
regression_994772_TEST(memcached_st
* memc
)
4638 test_skip(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1));
4640 test_compare(MEMCACHED_SUCCESS
,
4642 test_literal_param(__func__
), // Key
4643 test_literal_param(__func__
), // Value
4644 time_t(0), uint32_t(0)));
4646 const char *keys
[] = { __func__
};
4647 size_t key_length
[]= { strlen(__func__
) };
4648 test_compare(MEMCACHED_SUCCESS
,
4649 memcached_mget(memc
, keys
, key_length
, 1));
4651 memcached_return_t rc
;
4652 memcached_result_st
*results
= memcached_fetch_result(memc
, NULL
, &rc
);
4654 test_compare(MEMCACHED_SUCCESS
, rc
);
4656 test_strcmp(__func__
, memcached_result_value(results
));
4657 uint64_t cas_value
= memcached_result_cas(results
);
4658 test_true(cas_value
);
4660 memcached_result_free(results
);
4662 // Bad cas value, sanity check
4663 test_true(cas_value
!= 9999);
4664 test_compare(MEMCACHED_END
,
4666 test_literal_param(__func__
), // Key
4667 test_literal_param(__FILE__
), // Value
4668 time_t(0), uint32_t(0), 9999));
4670 test_compare(MEMCACHED_SUCCESS
, memcached_set(memc
,
4671 "different", strlen("different"), // Key
4672 test_literal_param(__FILE__
), // Value
4673 time_t(0), uint32_t(0)));
4675 return TEST_SUCCESS
;
4678 test_return_t
regression_bug_854604(memcached_st
*)
4682 test_compare(MEMCACHED_INVALID_ARGUMENTS
, libmemcached_check_configuration(0, 0, buffer
, 0));
4684 test_compare(MEMCACHED_PARSE_ERROR
, libmemcached_check_configuration(test_literal_param("syntax error"), buffer
, 0));
4686 test_compare(MEMCACHED_PARSE_ERROR
, libmemcached_check_configuration(test_literal_param("syntax error"), buffer
, 1));
4687 test_compare(buffer
[0], 0);
4689 test_compare(MEMCACHED_PARSE_ERROR
, libmemcached_check_configuration(test_literal_param("syntax error"), buffer
, 10));
4690 test_true(strlen(buffer
));
4692 test_compare(MEMCACHED_PARSE_ERROR
, libmemcached_check_configuration(test_literal_param("syntax error"), buffer
, sizeof(buffer
)));
4693 test_true(strlen(buffer
));
4695 return TEST_SUCCESS
;
4698 static void die_message(memcached_st
* mc
, memcached_return error
, const char* what
, uint32_t it
)
4700 fprintf(stderr
, "Iteration #%u: ", it
);
4702 if (error
== MEMCACHED_ERRNO
)
4704 fprintf(stderr
, "system error %d from %s: %s\n",
4705 errno
, what
, strerror(errno
));
4709 fprintf(stderr
, "error %d from %s: %s\n", error
, what
,
4710 memcached_strerror(mc
, error
));
4714 #define TEST_CONSTANT_CREATION 200
4716 test_return_t
regression_bug_(memcached_st
*memc
)
4718 const char *remote_server
;
4721 if (! (remote_server
= getenv("LIBMEMCACHED_REMOTE_SERVER")))
4723 return TEST_SKIPPED
;
4726 for (uint32_t x
= 0; x
< TEST_CONSTANT_CREATION
; x
++)
4728 memcached_st
* mc
= memcached_create(NULL
);
4729 memcached_return rc
;
4731 rc
= memcached_behavior_set(mc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, 1);
4732 if (rc
!= MEMCACHED_SUCCESS
)
4734 die_message(mc
, rc
, "memcached_behavior_set", x
);
4737 rc
= memcached_behavior_set(mc
, MEMCACHED_BEHAVIOR_CACHE_LOOKUPS
, 1);
4738 if (rc
!= MEMCACHED_SUCCESS
)
4740 die_message(mc
, rc
, "memcached_behavior_set", x
);
4743 rc
= memcached_server_add(mc
, remote_server
, 0);
4744 if (rc
!= MEMCACHED_SUCCESS
)
4746 die_message(mc
, rc
, "memcached_server_add", x
);
4749 const char *set_key
= "akey";
4750 const size_t set_key_len
= strlen(set_key
);
4751 const char *set_value
= "a value";
4752 const size_t set_value_len
= strlen(set_value
);
4754 if (rc
== MEMCACHED_SUCCESS
)
4758 size_t get_value_len
;
4760 uint32_t get_value_flags
;
4762 get_value
= memcached_get(mc
, set_key
, set_key_len
, &get_value_len
,
4763 &get_value_flags
, &rc
);
4764 if (rc
!= MEMCACHED_SUCCESS
)
4766 die_message(mc
, rc
, "memcached_get", x
);
4772 (get_value_len
!= set_value_len
4773 || 0!=strncmp(get_value
, set_value
, get_value_len
)))
4775 fprintf(stderr
, "Values don't match?\n");
4776 rc
= MEMCACHED_FAILURE
;
4782 rc
= memcached_set(mc
,
4783 set_key
, set_key_len
,
4784 set_value
, set_value_len
,
4788 if (rc
!= MEMCACHED_SUCCESS
)
4790 die_message(mc
, rc
, "memcached_set", x
);
4797 if (rc
!= MEMCACHED_SUCCESS
)
4803 return TEST_SUCCESS
;
4806 test_return_t
kill_HUP_TEST(memcached_st
*original_memc
)
4808 memcached_st
*memc
= create_single_instance_memcached(original_memc
, 0);
4811 memcached_server_instance_st instance
= memcached_server_instance_by_position(memc
, 0);
4814 test_true((pid
= libmemcached_util_getpid(memcached_server_name(instance
),
4815 memcached_server_port(instance
), NULL
)) > -1);
4818 test_compare(MEMCACHED_SUCCESS
,
4820 test_literal_param(__func__
), // Keys
4821 test_literal_param(__func__
), // Values
4823 test_true_got(kill(pid
, SIGHUP
) == 0, strerror(errno
));
4825 test_compare(MEMCACHED_CONNECTION_FAILURE
,
4827 test_literal_param(__func__
), // Keys
4828 test_literal_param(__func__
), // Values
4831 memcached_free(memc
);
4833 return TEST_SUCCESS
;