X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Flibmemcached-1.0%2Fmem_functions.cc;h=caac4c0630bdced294e59d745280ab8ed2a7956f;hb=744cca0ac99529b1f5f2629e26fb839a95e67f08;hp=2da5d0467bb6c8513f6621f54c73918c048b6650;hpb=f3883e19f984baa8981326d9e652d49433d49732;p=awesomized%2Flibmemcached diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index 2da5d046..caac4c06 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -38,6 +38,10 @@ #include #include +#if defined(HAVE_LIBUUID) && HAVE_LIBUUID +#include +#endif + /* Test cases */ @@ -64,7 +68,6 @@ #include #include "clients/generator.h" -#include "clients/execute.h" #define SMALL_STRING_LEN 1024 @@ -78,6 +81,12 @@ #include "tests/ketama.h" #include "tests/namespace.h" #include "tests/parser.h" +#include "tests/libmemcached-1.0/callback_counter.h" +#include "tests/libmemcached-1.0/dump.h" +#include "tests/libmemcached-1.0/fetch_all_results.h" +#include "tests/libmemcached-1.0/generate.h" +#include "tests/libmemcached-1.0/haldenbrand.h" +#include "tests/libmemcached-1.0/stat.h" #include "tests/touch.h" #include "tests/callbacks.h" #include "tests/pool.h" @@ -92,14 +101,112 @@ using namespace libtest; #include "tests/hash_results.h" -#define GLOBAL_COUNT 10000 -#define GLOBAL2_COUNT 100 -#define SERVERS_TO_CREATE 5 -static uint32_t global_count= GLOBAL2_COUNT; +#include "tests/libmemcached-1.0/servers_to_create.h" -static pairs_st *global_pairs; -static const char *global_keys[GLOBAL_COUNT]; -static size_t global_keys_length[GLOBAL_COUNT]; +#define UUID_STRING_MAXLENGTH 36 + +struct keys_st { +public: + keys_st(size_t arg) + { + init(arg, UUID_STRING_MAXLENGTH); + } + + keys_st(size_t arg, size_t padding) + { + init(arg, padding); + } + + void init(size_t arg, size_t padding) + { + _lengths.resize(arg); + _keys.resize(arg); + + for (size_t x= 0; x < _keys.size(); x++) + { + libtest::vchar_t key_buffer; + key_buffer.resize(padding +1); + memset(&key_buffer[0], 'x', padding); + + if (HAVE_LIBUUID) + { + uuid_t out; + uuid_generate(out); + + uuid_unparse(out, &key_buffer[0]); + _keys[x]= strdup(&key_buffer[0]); + (_keys[x])[UUID_STRING_MAXLENGTH]= 'x'; + } + else // We just use a number and pad the string if UUID is not available + { + char int_buffer[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1]; + int key_length= snprintf(int_buffer, sizeof(int_buffer), "%u", uint32_t(x)); + memcpy(&key_buffer[0], int_buffer, key_length); + _keys[x]= strdup(&key_buffer[0]); + } + _lengths[x]= padding; + } + } + + ~keys_st() + { + for (libtest::vchar_ptr_t::iterator iter= _keys.begin(); + iter != _keys.end(); + iter++) + { + ::free(*iter); + } + } + + libtest::vchar_ptr_t::iterator begin() + { + return _keys.begin(); + } + + libtest::vchar_ptr_t::iterator end() + { + return _keys.end(); + } + + size_t size() const + { + return _keys.size(); + } + + std::vector& lengths() + { + return _lengths; + } + + libtest::vchar_ptr_t& keys() + { + return _keys; + } + + size_t* lengths_ptr() + { + return &_lengths[0]; + } + + char** keys_ptr() + { + return &_keys[0]; + } + + char* key_at(size_t arg) + { + return _keys[arg]; + } + + size_t length_at(size_t arg) + { + return _lengths[arg]; + } + +private: + libtest::vchar_ptr_t _keys; + std::vector _lengths; +}; /** @note This should be testing to see if the server really supports the binary protocol. @@ -112,7 +219,7 @@ static test_return_t pre_binary(memcached_st *memc) return TEST_SUCCESS; } -static bool return_value_based_on_buffering(memcached_st *memc) +static memcached_return_t return_value_based_on_buffering(memcached_st *memc) { if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS)) { @@ -394,7 +501,7 @@ static test_return_t clone_test(memcached_st *memc) test_true(memc_clone->ketama.weighted == memc->ketama.weighted); test_true(memc_clone->flags.binary_protocol == memc->flags.binary_protocol); test_true(memc_clone->flags.hash_with_namespace == memc->flags.hash_with_namespace); - test_true(memc_clone->flags.no_reply == memc->flags.no_reply); + test_true(memc_clone->flags.reply == memc->flags.reply); test_true(memc_clone->flags.use_udp == memc->flags.use_udp); test_true(memc_clone->flags.auto_eject_hosts == memc->flags.auto_eject_hosts); test_true(memc_clone->flags.randomize_replica_read == memc->flags.randomize_replica_read); @@ -465,7 +572,7 @@ static test_return_t libmemcached_string_behavior_test(memcached_st *) { test_true(libmemcached_string_behavior(memcached_behavior_t(x))); } - test_compare(36, int(MEMCACHED_BEHAVIOR_MAX)); + test_compare(37, int(MEMCACHED_BEHAVIOR_MAX)); return TEST_SUCCESS; } @@ -485,7 +592,7 @@ static test_return_t memcached_return_t_TEST(memcached_st *memc) { uint32_t values[] = { 851992627U, 2337886783U, 4109241422U, 4001849190U, 982370485U, 1263635348U, 4242906218U, 3829656100U, - 1891735253U, 334139633U, 2257084983U, 3088286104U, + 1891735253U, 334139633U, 2257084983U, 3351789013U, 13199785U, 2542027183U, 1097051614U, 199566778U, 2748246961U, 2465192557U, 1664094137U, 2405439045U, 1842224848U, 692413798U, 3479807801U, 919913813U, @@ -522,7 +629,7 @@ static test_return_t set_test(memcached_st *memc) test_literal_param("foo"), test_literal_param("when we sanitize"), time_t(0), (uint32_t)0); - test_true_got(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED, memcached_strerror(NULL, rc)); + test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_strerror(NULL, rc)); return TEST_SUCCESS; } @@ -530,32 +637,34 @@ static test_return_t set_test(memcached_st *memc) static test_return_t append_test(memcached_st *memc) { memcached_return_t rc; - const char *key= "fig"; const char *in_value= "we"; - char *out_value= NULL; size_t value_length; uint32_t flags; - rc= memcached_flush(memc, 0); - test_compare(MEMCACHED_SUCCESS, rc); - - rc= memcached_set(memc, key, strlen(key), - in_value, strlen(in_value), - (time_t)0, (uint32_t)0); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_flush(memc, 0)); - rc= memcached_append(memc, key, strlen(key), - " the", strlen(" the"), - (time_t)0, (uint32_t)0); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_set(memc, + test_literal_param(__func__), + in_value, strlen(in_value), + time_t(0), uint32_t(0))); - rc= memcached_append(memc, key, strlen(key), - " people", strlen(" people"), - (time_t)0, (uint32_t)0); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_append(memc, + test_literal_param(__func__), + " the", strlen(" the"), + time_t(0), uint32_t(0))); - out_value= memcached_get(memc, key, strlen(key), - &value_length, &flags, &rc); + test_compare(MEMCACHED_SUCCESS, + memcached_append(memc, + test_literal_param(__func__), + " people", strlen(" people"), + time_t(0), uint32_t(0))); + + char *out_value= memcached_get(memc, + test_literal_param(__func__), + &value_length, &flags, &rc); test_memcmp(out_value, "we the people", strlen("we the people")); test_compare(strlen("we the people"), value_length); test_compare(MEMCACHED_SUCCESS, rc); @@ -566,40 +675,40 @@ static test_return_t append_test(memcached_st *memc) static test_return_t append_binary_test(memcached_st *memc) { - memcached_return_t rc; - const char *key= "numbers"; uint32_t store_list[] = { 23, 56, 499, 98, 32847, 0 }; - uint32_t *value; - size_t value_length; - uint32_t flags; - uint32_t x; - rc= memcached_flush(memc, 0); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_flush(memc, 0)); - rc= memcached_set(memc, - key, strlen(key), - NULL, 0, - (time_t)0, (uint32_t)0); - test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc)); + test_compare(MEMCACHED_SUCCESS, + memcached_set(memc, + test_literal_param(__func__), + NULL, 0, + time_t(0), uint32_t(0))); - for (x= 0; store_list[x] ; x++) + size_t count= 0; + for (uint32_t x= 0; store_list[x] ; x++) { - rc= memcached_append(memc, - key, strlen(key), + test_compare(MEMCACHED_SUCCESS, + memcached_append(memc, + test_literal_param(__func__), (char *)&store_list[x], sizeof(uint32_t), - (time_t)0, (uint32_t)0); - test_compare(MEMCACHED_SUCCESS, rc); + time_t(0), uint32_t(0))); + count++; } - value= (uint32_t *)memcached_get(memc, key, strlen(key), - &value_length, &flags, &rc); - test_compare(value_length, sizeof(uint32_t) * x); + size_t value_length; + uint32_t flags; + memcached_return_t rc; + uint32_t *value= (uint32_t *)memcached_get(memc, + test_literal_param(__func__), + &value_length, &flags, &rc); + test_compare(value_length, sizeof(uint32_t) * count); test_compare(MEMCACHED_SUCCESS, rc); - for (uint32_t counter= x, *ptr= value; counter; counter--) + for (uint32_t counter= count, *ptr= value; counter; counter--) { - test_compare(*ptr, store_list[x - counter]); + test_compare(*ptr, store_list[count - counter]); ptr++; } free(value); @@ -607,36 +716,84 @@ static test_return_t append_binary_test(memcached_st *memc) return TEST_SUCCESS; } +static test_return_t memcached_mget_mixed_memcached_get_TEST(memcached_st *memc) +{ + keys_st keys(200); + + for (libtest::vchar_ptr_t::iterator iter= keys.begin(); + iter != keys.end(); + iter++) + { + test_compare(MEMCACHED_SUCCESS, + memcached_set(memc, + (*iter), 36, + NULL, 0, + time_t(0), uint32_t(0))); + } + + for (size_t loop= 0; loop < 20; loop++) + { + if (random() %2) + { + test_compare(MEMCACHED_SUCCESS, + memcached_mget(memc, keys.keys_ptr(), keys.lengths_ptr(), keys.size())); + + memcached_result_st *results= memcached_result_create(memc, NULL); + test_true(results); + + size_t result_count= 0; + memcached_return_t rc; + while (memcached_fetch_result(memc, results, &rc)) + { + result_count++; + } + test_compare(keys.size(), result_count); + } + else + { + int which_key= random() %keys.size(); + size_t value_length; + uint32_t flags; + memcached_return_t rc; + char *out_value= memcached_get(memc, keys.key_at(which_key), keys.length_at(which_key), + &value_length, &flags, &rc); + test_compare(MEMCACHED_SUCCESS, rc); + test_null(out_value); + test_zero(value_length); + test_zero(flags); + } + } + + return TEST_SUCCESS; +} + static test_return_t cas2_test(memcached_st *memc) { - memcached_return_t rc; const char *keys[]= {"fudge", "son", "food"}; size_t key_length[]= {5, 3, 4}; const char *value= "we the people"; size_t value_length= strlen("we the people"); - memcached_result_st results_obj; - memcached_result_st *results; - unsigned int set= 1; test_compare(MEMCACHED_SUCCESS, memcached_flush(memc, 0)); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, set); + test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, true)); for (uint32_t x= 0; x < 3; x++) { - rc= memcached_set(memc, keys[x], key_length[x], - keys[x], key_length[x], - (time_t)50, (uint32_t)9); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_set(memc, keys[x], key_length[x], + keys[x], key_length[x], + time_t(50), uint32_t(9))); } test_compare(MEMCACHED_SUCCESS, memcached_mget(memc, keys, key_length, 3)); - results= memcached_result_create(memc, &results_obj); + memcached_result_st *results= memcached_result_create(memc, NULL); test_true(results); - results= memcached_fetch_result(memc, &results_obj, &rc); + memcached_return_t rc; + results= memcached_fetch_result(memc, results, &rc); test_true(results); test_true(results->item_cas); test_compare(MEMCACHED_SUCCESS, rc); @@ -646,51 +803,44 @@ static test_return_t cas2_test(memcached_st *memc) test_compare(strlen("we the people"), value_length); test_compare(MEMCACHED_SUCCESS, rc); - memcached_result_free(&results_obj); + memcached_result_free(results); return TEST_SUCCESS; } static test_return_t cas_test(memcached_st *memc) { - memcached_return_t rc; - const char *key= "fun"; - size_t key_length= strlen(key); - const char *value= "we the people"; - const char* keys[2] = { key, NULL }; - size_t keylengths[2] = { strlen(key), 0 }; - size_t value_length= strlen(value); - const char *value2= "change the value"; - size_t value2_length= strlen(value2); + const char* keys[2] = { __func__, NULL }; + size_t keylengths[2] = { strlen(__func__), 0 }; memcached_result_st results_obj; - memcached_result_st *results; - unsigned int set= 1; - rc= memcached_flush(memc, 0); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, memcached_flush(memc, 0)); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, set); + test_skip(true, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, true)); - rc= memcached_set(memc, key, strlen(key), - value, strlen(value), - (time_t)0, (uint32_t)0); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_set(memc, + test_literal_param(__func__), + test_literal_param("we the people"), + (time_t)0, (uint32_t)0)); test_compare(MEMCACHED_SUCCESS, memcached_mget(memc, keys, keylengths, 1)); - results= memcached_result_create(memc, &results_obj); + memcached_result_st *results= memcached_result_create(memc, &results_obj); test_true(results); + memcached_return_t rc; results= memcached_fetch_result(memc, &results_obj, &rc); test_true(results); test_compare(MEMCACHED_SUCCESS, rc); test_true(memcached_result_cas(results)); - test_memcmp(value, memcached_result_value(results), value_length); - test_compare(strlen(memcached_result_value(results)), value_length); - test_compare(MEMCACHED_SUCCESS, rc); - uint64_t cas = memcached_result_cas(results); + test_memcmp("we the people", memcached_result_value(results), test_literal_param_size("we the people")); + test_compare(test_literal_param_size("we the people"), + strlen(memcached_result_value(results))); + + uint64_t cas= memcached_result_cas(results); #if 0 results= memcached_fetch_result(memc, &results_obj, &rc); @@ -698,15 +848,21 @@ static test_return_t cas_test(memcached_st *memc) test_true(results == NULL); #endif - rc= memcached_cas(memc, key, key_length, value2, value2_length, 0, 0, cas); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_cas(memc, + test_literal_param(__func__), + test_literal_param("change the value"), + 0, 0, cas)); /* * The item will have a new cas value, so try to set it again with the old * value. This should fail! */ - rc= memcached_cas(memc, key, key_length, value2, value2_length, 0, 0, cas); - test_compare(MEMCACHED_DATA_EXISTS, rc); + test_compare(MEMCACHED_DATA_EXISTS, + memcached_cas(memc, + test_literal_param(__func__), + test_literal_param("change the value"), + 0, 0, cas)); memcached_result_free(&results_obj); @@ -715,32 +871,31 @@ static test_return_t cas_test(memcached_st *memc) static test_return_t prepend_test(memcached_st *memc) { - memcached_return_t rc; const char *key= "fig"; const char *value= "people"; - char *out_value= NULL; - size_t value_length; - uint32_t flags; - rc= memcached_flush(memc, 0); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_flush(memc, 0)); - rc= memcached_set(memc, key, strlen(key), - value, strlen(value), - (time_t)0, (uint32_t)0); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_set(memc, key, strlen(key), + value, strlen(value), + time_t(0), uint32_t(0))); - rc= memcached_prepend(memc, key, strlen(key), - "the ", strlen("the "), - (time_t)0, (uint32_t)0); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_prepend(memc, key, strlen(key), + "the ", strlen("the "), + time_t(0), uint32_t(0))); - rc= memcached_prepend(memc, key, strlen(key), - "we ", strlen("we "), - (time_t)0, (uint32_t)0); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_prepend(memc, key, strlen(key), + "we ", strlen("we "), + time_t(0), uint32_t(0))); - out_value= memcached_get(memc, key, strlen(key), + size_t value_length; + uint32_t flags; + memcached_return_t rc; + char *out_value= memcached_get(memc, key, strlen(key), &value_length, &flags, &rc); test_memcmp(out_value, "we the people", strlen("we the people")); test_compare(strlen("we the people"), value_length); @@ -756,31 +911,21 @@ static test_return_t prepend_test(memcached_st *memc) */ static test_return_t add_test(memcached_st *memc) { - memcached_return_t rc; - const char *key= "foo"; - const char *value= "when we sanitize"; - unsigned long long setting_value; - - setting_value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK); + test_compare_hint(return_value_based_on_buffering(memc), + memcached_set(memc, + test_literal_param(__func__), + test_literal_param("when we sanitize"), + time_t(0), uint32_t(0)), + memcached_last_error_message(memc)); - rc= memcached_set(memc, key, strlen(key), - value, strlen(value), - (time_t)0, (uint32_t)0); - test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); memcached_quit(memc); - rc= memcached_add(memc, key, strlen(key), - value, strlen(value), - (time_t)0, (uint32_t)0); - /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */ - if (setting_value) - { - test_true(rc == MEMCACHED_NOTSTORED || rc == MEMCACHED_STORED); - } - else - { - test_true(rc == MEMCACHED_NOTSTORED || rc == MEMCACHED_DATA_EXISTS); - } + test_compare_hint(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) ? MEMCACHED_DATA_EXISTS : MEMCACHED_NOTSTORED, + memcached_add(memc, + test_literal_param(__func__), + test_literal_param("try something else"), + time_t(0), uint32_t(0)), + memcached_last_error_message(memc)); return TEST_SUCCESS; } @@ -810,20 +955,17 @@ static test_return_t add_wrapper(memcached_st *memc) static test_return_t replace_test(memcached_st *memc) { - memcached_return_t rc; - const char *key= "foo"; - const char *value= "when we sanitize"; - const char *original= "first we insert some data"; - - rc= memcached_set(memc, key, strlen(key), - original, strlen(original), - (time_t)0, (uint32_t)0); - test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + test_compare(return_value_based_on_buffering(memc), + memcached_set(memc, + test_literal_param(__func__), + test_literal_param("when we sanitize"), + time_t(0), uint32_t(0))); test_compare(MEMCACHED_SUCCESS, - memcached_replace(memc, key, strlen(key), - value, strlen(value), - (time_t)0, (uint32_t)0)); + memcached_replace(memc, + test_literal_param(__func__), + test_literal_param("first we insert some data"), + time_t(0), uint32_t(0))); return TEST_SUCCESS; } @@ -836,11 +978,10 @@ static test_return_t delete_test(memcached_st *memc) test_literal_param("when we sanitize"), time_t(0), uint32_t(0))); - memcached_return_t rc= memcached_delete(memc, - test_literal_param(__func__), - time_t(0)); - test_compare_hint(MEMCACHED_SUCCESS, - rc, + test_compare_hint(return_value_based_on_buffering(memc), + memcached_delete(memc, + test_literal_param(__func__), + time_t(0)), memcached_last_error_message(memc)); return TEST_SUCCESS; @@ -856,13 +997,11 @@ static test_return_t flush_test(memcached_st *memc) return TEST_SUCCESS; } -static memcached_return_t server_function(const memcached_st *ptr, - const memcached_server_st *server, - void *context) +static memcached_return_t server_function(const memcached_st *, + const memcached_server_st *, + void *) { - (void)ptr; (void)server; (void)context; /* Do Nothing */ - return MEMCACHED_SUCCESS; } @@ -882,7 +1021,6 @@ static test_return_t bad_key_test(memcached_st *memc) memcached_return_t rc; const char *key= "foo bad"; uint32_t flags; - memcached_st *memc_clone; uint64_t query_id= memcached_query_id(memc); @@ -891,7 +1029,7 @@ static test_return_t bad_key_test(memcached_st *memc) test_compare(query_id, memcached_query_id(memc)); // We should not increase the query_id for memcached_behavior_get() - memc_clone= memcached_clone(NULL, memc); + memcached_st *memc_clone= memcached_clone(NULL, memc); test_true(memc_clone); query_id= memcached_query_id(memc_clone); @@ -900,7 +1038,7 @@ static test_return_t bad_key_test(memcached_st *memc) test_compare(query_id, memcached_query_id(memc_clone)); // We should not increase the query_id for memcached_behavior_set() /* All keys are valid in the binary protocol (except for length) */ - if (not memcached_behavior_get(memc_clone, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) + if (memcached_behavior_get(memc_clone, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == false) { uint64_t before_query_id= memcached_query_id(memc_clone); { @@ -940,7 +1078,8 @@ static test_return_t bad_key_test(memcached_st *memc) test_compare(query_id +1, memcached_query_id(memc_clone)); query_id= memcached_query_id(memc_clone); - test_compare(MEMCACHED_BAD_KEY_PROVIDED, + // Grouping keys are not required to follow normal key behaviors + test_compare(MEMCACHED_SUCCESS, memcached_mget_by_key(memc_clone, "foo daddy", 9, keys, key_lengths, 1)); test_compare(query_id +1, memcached_query_id(memc_clone)); @@ -951,9 +1090,9 @@ static test_return_t bad_key_test(memcached_st *memc) test_compare(MEMCACHED_SUCCESS, memcached_callback_set(memc_clone, MEMCACHED_CALLBACK_NAMESPACE, NULL)); - std::vector longkey; + libtest::vchar_t longkey; { - std::vector::iterator it= longkey.begin(); + libtest::vchar_t::iterator it= longkey.begin(); longkey.insert(it, MEMCACHED_MAX_KEY, 'a'); } @@ -1004,24 +1143,24 @@ static memcached_return_t read_through_trigger(memcached_st *memc, static test_return_t read_through(memcached_st *memc) { - memcached_return_t rc; - const char *key= "foo"; - char *string; - size_t string_length; - uint32_t flags; memcached_trigger_key_fn cb= (memcached_trigger_key_fn)read_through_trigger; - string= memcached_get(memc, key, strlen(key), - &string_length, &flags, &rc); + size_t string_length; + uint32_t flags; + memcached_return_t rc; + char *string= memcached_get(memc, + test_literal_param(__func__), + &string_length, &flags, &rc); test_compare(MEMCACHED_NOTFOUND, rc); test_false(string_length); test_false(string); - rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_GET_FAILURE, *(void **)&cb); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_callback_set(memc, MEMCACHED_CALLBACK_GET_FAILURE, *(void **)&cb)); - string= memcached_get(memc, key, strlen(key), + string= memcached_get(memc, + test_literal_param(__func__), &string_length, &flags, &rc); test_compare(MEMCACHED_SUCCESS, rc); @@ -1030,7 +1169,8 @@ static test_return_t read_through(memcached_st *memc) test_strcmp(READ_THROUGH_VALUE, string); free(string); - string= memcached_get(memc, key, strlen(key), + string= memcached_get(memc, + test_literal_param(__func__), &string_length, &flags, &rc); test_compare(MEMCACHED_SUCCESS, rc); @@ -1046,17 +1186,19 @@ static test_return_t read_through(memcached_st *memc) static test_return_t get_test(memcached_st *memc) { memcached_return_t rc; - const char *key= "foo"; char *string; size_t string_length; uint32_t flags; uint64_t query_id= memcached_query_id(memc); - rc= memcached_delete(memc, key, strlen(key), (time_t)0); - test_true_got(rc == MEMCACHED_BUFFERED || rc == MEMCACHED_NOTFOUND, memcached_last_error_message(memc)); + rc= memcached_delete(memc, + test_literal_param(__func__), + time_t(0)); + test_true_got(rc == MEMCACHED_BUFFERED or rc == MEMCACHED_NOTFOUND, memcached_last_error_message(memc)); test_compare(query_id +1, memcached_query_id(memc)); - string= memcached_get(memc, key, strlen(key), + string= memcached_get(memc, + test_literal_param(__func__), &string_length, &flags, &rc); test_compare_got(MEMCACHED_NOTFOUND, rc, memcached_strerror(NULL, rc)); @@ -1068,14 +1210,14 @@ static test_return_t get_test(memcached_st *memc) static test_return_t get_test2(memcached_st *memc) { - const char *key= "foo"; const char *value= "when we sanitize"; uint64_t query_id= memcached_query_id(memc); - memcached_return_t rc= memcached_set(memc, key, strlen(key), - value, strlen(value), - (time_t)0, (uint32_t)0); - test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); + test_compare(return_value_based_on_buffering(memc), + memcached_set(memc, + test_literal_param(__func__), + value, strlen(value), + time_t(0), uint32_t(0))); test_compare(query_id +1, memcached_query_id(memc)); query_id= memcached_query_id(memc); @@ -1083,7 +1225,9 @@ static test_return_t get_test2(memcached_st *memc) uint32_t flags; size_t string_length; - char *string= memcached_get(memc, key, strlen(key), + memcached_return_t rc; + char *string= memcached_get(memc, + test_literal_param(__func__), &string_length, &flags, &rc); test_compare(query_id +1, memcached_query_id(memc)); @@ -1102,11 +1246,11 @@ static test_return_t set_test2(memcached_st *memc) { for (uint32_t x= 0; x < 10; x++) { - memcached_return_t rc= memcached_set(memc, - test_literal_param("foo"), - test_literal_param("train in the brain"), - time_t(0), uint32_t(0)); - test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); + test_compare(return_value_based_on_buffering(memc), + memcached_set(memc, + test_literal_param("foo"), + test_literal_param("train in the brain"), + time_t(0), uint32_t(0))); } return TEST_SUCCESS; @@ -1116,7 +1260,7 @@ static test_return_t set_test3(memcached_st *memc) { size_t value_length= 8191; - std::vector value; + libtest::vchar_t value; value.reserve(value_length); for (uint32_t x= 0; x < value_length; x++) { @@ -1131,10 +1275,11 @@ static test_return_t set_test3(memcached_st *memc) snprintf(key, sizeof(key), "foo%u", x); uint64_t query_id= memcached_query_id(memc); - memcached_return_t rc= memcached_set(memc, key, strlen(key), - &value[0], value.size(), - (time_t)0, (uint32_t)0); - test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_strerror(NULL, rc)); + test_compare_hint(return_value_based_on_buffering(memc), + memcached_set(memc, key, strlen(key), + &value[0], value.size(), + time_t(0), uint32_t(0)), + memcached_last_error_message(memc)); test_compare(query_id +1, memcached_query_id(memc)); } @@ -1143,30 +1288,32 @@ static test_return_t set_test3(memcached_st *memc) static test_return_t get_test3(memcached_st *memc) { - const char *key= "foo"; size_t value_length= 8191; - std::vector value; + libtest::vchar_t value; value.reserve(value_length); for (uint32_t x= 0; x < value_length; x++) { value.push_back(char(x % 127)); } - memcached_return_t rc; - rc= memcached_set(memc, key, strlen(key), - &value[0], value.size(), - (time_t)0, (uint32_t)0); - test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); + test_compare_hint(return_value_based_on_buffering(memc), + memcached_set(memc, + test_literal_param(__func__), + &value[0], value.size(), + time_t(0), uint32_t(0)), + memcached_last_error_message(memc)); size_t string_length; uint32_t flags; - char *string= memcached_get(memc, key, strlen(key), + memcached_return_t rc; + char *string= memcached_get(memc, + test_literal_param(__func__), &string_length, &flags, &rc); test_compare(MEMCACHED_SUCCESS, rc); test_true(string); - test_compare(string_length, value_length); + test_compare(value.size(), string_length); test_memcmp(string, &value[0], string_length); free(string); @@ -1176,31 +1323,34 @@ static test_return_t get_test3(memcached_st *memc) static test_return_t get_test4(memcached_st *memc) { - const char *key= "foo"; size_t value_length= 8191; - std::vector value; + libtest::vchar_t value; value.reserve(value_length); for (uint32_t x= 0; x < value_length; x++) { value.push_back(char(x % 127)); } - memcached_return_t rc= memcached_set(memc, key, strlen(key), - &value[0], value.size(), - (time_t)0, (uint32_t)0); - test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); + test_compare_hint(return_value_based_on_buffering(memc), + memcached_set(memc, + test_literal_param(__func__), + &value[0], value.size(), + time_t(0), uint32_t(0)), + memcached_last_error_message(memc)); for (uint32_t x= 0; x < 10; x++) { uint32_t flags; size_t string_length; - char *string= memcached_get(memc, key, strlen(key), + memcached_return_t rc; + char *string= memcached_get(memc, + test_literal_param(__func__), &string_length, &flags, &rc); test_compare(MEMCACHED_SUCCESS, rc); test_true(string); - test_compare(string_length, value_length); + test_compare(value.size(), string_length); test_memcmp(string, &value[0], string_length); free(string); } @@ -1224,14 +1374,18 @@ static test_return_t get_test5(memcached_st *memc) uint32_t flags; size_t rlen; - memcached_return_t rc= memcached_set(memc, keys[0], lengths[0], - keys[0], lengths[0], 0, 0); + test_compare_hint(return_value_based_on_buffering(memc), + memcached_set(memc, keys[0], lengths[0], + keys[0], lengths[0], + time_t(0), uint32_t(0)), + memcached_last_error_message(memc)); test_compare(MEMCACHED_SUCCESS, memcached_mget(memc, keys, lengths, test_array_length(keys))); memcached_result_st results_obj; memcached_result_st *results= memcached_result_create(memc, &results_obj); test_true(results); + memcached_return_t rc; results= memcached_fetch_result(memc, &results_obj, &rc); test_true(results); @@ -1258,12 +1412,14 @@ static test_return_t mget_end(memcached_st *memc) size_t lengths[]= { 3, 4 }; const char *values[]= { "fjord", "41" }; - memcached_return_t rc; - // Set foo and foo2 for (size_t x= 0; x < test_array_length(keys); x++) { - test_compare(MEMCACHED_SUCCESS, memcached_set(memc, keys[x], lengths[x], values[x], strlen(values[x]), (time_t)0, (uint32_t)0)); + test_compare(MEMCACHED_SUCCESS, + memcached_set(memc, + keys[x], lengths[x], + values[x], strlen(values[x]), + time_t(0), uint32_t(0))); } char *string; @@ -1271,10 +1427,14 @@ static test_return_t mget_end(memcached_st *memc) uint32_t flags; // retrieve both via mget - test_compare(MEMCACHED_SUCCESS, memcached_mget(memc, keys, lengths, test_array_length(keys))); + test_compare(MEMCACHED_SUCCESS, + memcached_mget(memc, + keys, lengths, + test_array_length(keys))); char key[MEMCACHED_MAX_KEY]; size_t key_length; + memcached_return_t rc; // this should get both for (size_t x= 0; x < test_array_length(keys); x++) @@ -1299,8 +1459,8 @@ static test_return_t mget_end(memcached_st *memc) test_null(string); // now get just one - rc= memcached_mget(memc, keys, lengths, 1); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_mget(memc, keys, lengths, 1)); string= memcached_fetch(memc, key, &key_length, &string_length, &flags, &rc); test_compare(key_length, lengths[0]); @@ -1380,25 +1540,24 @@ static test_return_t increment_with_initial_test(memcached_st *memc) static test_return_t decrement_test(memcached_st *memc) { - uint64_t new_number; - memcached_return_t rc; - const char *value= "3"; - - rc= memcached_set(memc, - test_literal_param("number"), - value, strlen(value), - (time_t)0, (uint32_t)0); - test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); + test_compare(return_value_based_on_buffering(memc), + memcached_set(memc, + test_literal_param(__func__), + test_literal_param("3"), + time_t(0), uint32_t(0))); + // Make sure we flush the value we just set + test_compare(MEMCACHED_SUCCESS, memcached_flush_buffers(memc)); + uint64_t new_number; test_compare(MEMCACHED_SUCCESS, memcached_decrement(memc, - test_literal_param("number"), + test_literal_param(__func__), 1, &new_number)); test_compare(uint64_t(2), new_number); test_compare(MEMCACHED_SUCCESS, memcached_decrement(memc, - test_literal_param("number"), + test_literal_param(__func__), 1, &new_number)); test_compare(uint64_t(1), new_number); @@ -1409,21 +1568,23 @@ static test_return_t decrement_with_initial_test(memcached_st *memc) { test_skip(true, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)); - uint64_t new_number; uint64_t initial= 3; test_compare(MEMCACHED_SUCCESS, memcached_flush_buffers(memc)); + uint64_t new_number; test_compare(MEMCACHED_SUCCESS, memcached_decrement_with_initial(memc, - test_literal_param("number"), - 1, initial, 0, &new_number)); + test_literal_param(__func__), + 1, initial, + 0, &new_number)); test_compare(new_number, initial); test_compare(MEMCACHED_SUCCESS, memcached_decrement_with_initial(memc, - test_literal_param("number"), - 1, initial, 0, &new_number)); + test_literal_param(__func__), + 1, initial, + 0, &new_number)); test_compare(new_number, (initial - 1)); return TEST_SUCCESS; @@ -1431,24 +1592,28 @@ static test_return_t decrement_with_initial_test(memcached_st *memc) static test_return_t increment_by_key_test(memcached_st *memc) { - uint64_t new_number; - memcached_return_t rc; const char *master_key= "foo"; const char *key= "number"; const char *value= "0"; - rc= memcached_set_by_key(memc, master_key, strlen(master_key), - key, strlen(key), - value, strlen(value), - (time_t)0, (uint32_t)0); - test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); + test_compare(return_value_based_on_buffering(memc), + memcached_set_by_key(memc, master_key, strlen(master_key), + key, strlen(key), + value, strlen(value), + time_t(0), uint32_t(0))); + + // Make sure we flush the value we just set + test_compare(MEMCACHED_SUCCESS, memcached_flush_buffers(memc)); + uint64_t new_number; test_compare(MEMCACHED_SUCCESS, - memcached_increment_by_key(memc, master_key, strlen(master_key), key, strlen(key), 1, &new_number)); + memcached_increment_by_key(memc, master_key, strlen(master_key), + key, strlen(key), 1, &new_number)); test_compare(uint64_t(1), new_number); test_compare(MEMCACHED_SUCCESS, - memcached_increment_by_key(memc, master_key, strlen(master_key), key, strlen(key), 1, &new_number)); + memcached_increment_by_key(memc, master_key, strlen(master_key), + key, strlen(key), 1, &new_number)); test_compare(uint64_t(2), new_number); return TEST_SUCCESS; @@ -1459,21 +1624,20 @@ static test_return_t increment_with_initial_by_key_test(memcached_st *memc) test_skip(true, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)); uint64_t new_number; - memcached_return_t rc; const char *master_key= "foo"; const char *key= "number"; uint64_t initial= 0; - rc= memcached_increment_with_initial_by_key(memc, master_key, strlen(master_key), - key, strlen(key), - 1, initial, 0, &new_number); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_increment_with_initial_by_key(memc, master_key, strlen(master_key), + key, strlen(key), + 1, initial, 0, &new_number)); test_compare(new_number, initial); - rc= memcached_increment_with_initial_by_key(memc, master_key, strlen(master_key), - key, strlen(key), - 1, initial, 0, &new_number); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_increment_with_initial_by_key(memc, master_key, strlen(master_key), + key, strlen(key), + 1, initial, 0, &new_number)); test_compare(new_number, (initial +1)); return TEST_SUCCESS; @@ -1482,15 +1646,14 @@ static test_return_t increment_with_initial_by_key_test(memcached_st *memc) static test_return_t decrement_by_key_test(memcached_st *memc) { uint64_t new_number; - memcached_return_t rc; const char *value= "3"; - rc= memcached_set_by_key(memc, - test_literal_param("foo"), - test_literal_param("number"), - value, strlen(value), - (time_t)0, (uint32_t)0); - test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); + test_compare(return_value_based_on_buffering(memc), + memcached_set_by_key(memc, + test_literal_param("foo"), + test_literal_param("number"), + value, strlen(value), + (time_t)0, (uint32_t)0)); test_compare(MEMCACHED_SUCCESS, memcached_decrement_by_key(memc, @@ -1532,20 +1695,17 @@ static test_return_t decrement_with_initial_by_key_test(memcached_st *memc) return TEST_SUCCESS; } -static test_return_t binary_increment_with_prefix_test(memcached_st *orig_memc) +static test_return_t binary_increment_with_prefix_test(memcached_st *memc) { - memcached_st *memc= memcached_clone(NULL, orig_memc); - - test_skip(TEST_SUCCESS, pre_binary(memc)); + test_skip(true, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)); test_compare(MEMCACHED_SUCCESS, memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, (void *)"namespace:")); - memcached_return_t rc; - rc= memcached_set(memc, - test_literal_param("number"), - test_literal_param("0"), - (time_t)0, (uint32_t)0); - test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + test_compare(return_value_based_on_buffering(memc), + memcached_set(memc, + test_literal_param("number"), + test_literal_param("0"), + (time_t)0, (uint32_t)0)); uint64_t new_number; test_compare(MEMCACHED_SUCCESS, memcached_increment(memc, @@ -1557,27 +1717,26 @@ static test_return_t binary_increment_with_prefix_test(memcached_st *orig_memc) test_literal_param("number"), 1, &new_number)); test_compare(uint64_t(2), new_number); - memcached_free(memc); return TEST_SUCCESS; } static test_return_t quit_test(memcached_st *memc) { - memcached_return_t rc; - const char *key= "fudge"; const char *value= "sanford and sun"; - rc= memcached_set(memc, key, strlen(key), - value, strlen(value), - (time_t)10, (uint32_t)3); - test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_strerror(NULL, rc)); + test_compare(return_value_based_on_buffering(memc), + memcached_set(memc, + test_literal_param(__func__), + value, strlen(value), + (time_t)10, (uint32_t)3)); memcached_quit(memc); - rc= memcached_set(memc, key, strlen(key), - value, strlen(value), - (time_t)50, (uint32_t)9); - test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); + test_compare(return_value_based_on_buffering(memc), + memcached_set(memc, + test_literal_param(__func__), + value, strlen(value), + (time_t)50, (uint32_t)9)); return TEST_SUCCESS; } @@ -1687,16 +1846,6 @@ static test_return_t mget_result_alloc_test(memcached_st *memc) return TEST_SUCCESS; } -/* Count the results */ -static memcached_return_t callback_counter(const memcached_st*, memcached_result_st*, void *context) -{ - size_t *counter= (size_t *)context; - - *counter= *counter + 1; - - return MEMCACHED_SUCCESS; -} - static test_return_t mget_result_function(memcached_st *memc) { const char *keys[]= {"fudge", "son", "food"}; @@ -1704,16 +1853,15 @@ static test_return_t mget_result_function(memcached_st *memc) size_t counter; memcached_execute_fn callbacks[1]; - /* We need to empty the server before continueing test */ - test_compare(MEMCACHED_SUCCESS, - memcached_flush(memc, 0)); for (uint32_t x= 0; x < 3; x++) { - memcached_return_t rc= memcached_set(memc, keys[x], key_length[x], - keys[x], key_length[x], - (time_t)50, (uint32_t)9); - test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + test_compare(return_value_based_on_buffering(memc), + memcached_set(memc, keys[x], key_length[x], + keys[x], key_length[x], + time_t(50), uint32_t(9))); } + test_compare(MEMCACHED_SUCCESS, memcached_flush_buffers(memc)); + memcached_quit(memc); test_compare(MEMCACHED_SUCCESS, memcached_mget(memc, keys, key_length, 3)); @@ -1739,10 +1887,6 @@ static test_return_t mget_test(memcached_st *memc) char *return_value; size_t return_value_length; - /* We need to empty the server before continueing test */ - test_compare(MEMCACHED_SUCCESS, - memcached_flush(memc, 0)); - test_compare(MEMCACHED_SUCCESS, memcached_mget(memc, keys, key_length, 3)); @@ -1792,25 +1936,20 @@ static test_return_t mget_execute(memcached_st *original_memc) memcached_st *memc= create_single_instance_memcached(original_memc, "--BINARY-PROTOCOL"); test_true(memc); - size_t max_keys= 20480; - - - char **keys= static_cast(calloc(max_keys, sizeof(char*))); - size_t *key_length=static_cast(calloc(max_keys, sizeof(size_t))); + keys_st keys(20480); /* First add all of the items.. */ char blob[1024] = {0}; - for (size_t x= 0; x < max_keys; ++x) + for (size_t x= 0; x < keys.size(); ++x) { - char k[251]; - - key_length[x]= (size_t)snprintf(k, sizeof(k), "0200%lu", (unsigned long)x); - keys[x]= strdup(k); - test_true(keys[x] != NULL); uint64_t query_id= memcached_query_id(memc); - memcached_return_t rc= memcached_add(memc, keys[x], key_length[x], blob, sizeof(blob), 0, 0); - test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_strerror(NULL, rc)); + memcached_return_t rc= memcached_add(memc, + keys.key_at(x), keys.length_at(x), + blob, sizeof(blob), + 0, 0); + test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, + memcached_strerror(NULL, rc)); test_compare(query_id +1, memcached_query_id(memc)); } @@ -1818,8 +1957,9 @@ static test_return_t mget_execute(memcached_st *original_memc) size_t counter= 0; memcached_execute_fn callbacks[]= { &callback_counter }; test_compare(MEMCACHED_SUCCESS, - memcached_mget_execute(memc, (const char**)keys, key_length, - max_keys, callbacks, &counter, 1)); + memcached_mget_execute(memc, + keys.keys_ptr(), keys.lengths_ptr(), + keys.size(), callbacks, &counter, 1)); { uint64_t query_id= memcached_query_id(memc); @@ -1828,23 +1968,16 @@ static test_return_t mget_execute(memcached_st *original_memc) test_compare(query_id, memcached_query_id(memc)); /* Verify that we got all of the items */ - test_true(counter == max_keys); + test_compare(keys.size(), counter); } - /* Release all allocated resources */ - for (size_t x= 0; x < max_keys; ++x) - { - free(keys[x]); - } - free(keys); - free(key_length); - memcached_free(memc); return TEST_SUCCESS; } #define REGRESSION_BINARY_VS_BLOCK_COUNT 20480 +static pairs_st *global_pairs; static test_return_t key_setup(memcached_st *memc) { @@ -1855,9 +1988,8 @@ static test_return_t key_setup(memcached_st *memc) return TEST_SUCCESS; } -static test_return_t key_teardown(memcached_st *memc) +static test_return_t key_teardown(memcached_st *) { - (void)memc; pairs_free(global_pairs); return TEST_SUCCESS; @@ -2117,172 +2249,6 @@ static test_return_t MEMCACHED_BEHAVIOR_TCP_KEEPIDLE_test(memcached_st *memc) return TEST_SUCCESS; } -static test_return_t fetch_all_results(memcached_st *memc, unsigned int &keys_returned, const memcached_return_t expect) -{ - memcached_return_t rc; - char return_key[MEMCACHED_MAX_KEY]; - size_t return_key_length; - char *return_value; - size_t return_value_length; - uint32_t flags; - - keys_returned= 0; - while ((return_value= memcached_fetch(memc, return_key, &return_key_length, - &return_value_length, &flags, &rc))) - { - test_true(return_value); - test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc)); - free(return_value); - keys_returned+= 1; - } - - if (memcached_success(expect) and memcached_success(rc)) - { - return TEST_SUCCESS; - } - else if (expect == rc) - { - return TEST_SUCCESS; - } - fprintf(stderr, "\n%s:%u %s(#%u)\n", __FILE__, __LINE__, memcached_strerror(NULL, rc), keys_returned); - - return TEST_FAILURE; -} - -/* Test case provided by Cal Haldenbrand */ -#define HALDENBRAND_KEY_COUNT 3000U // * 1024576 -#define HALDENBRAND_FLAG_KEY 99 // * 1024576 -static test_return_t user_supplied_bug1(memcached_st *memc) -{ - /* We just keep looking at the same values over and over */ - srandom(10); - - test_compare(MEMCACHED_SUCCESS, - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, true)); - test_compare(MEMCACHED_SUCCESS, - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, true)); - - - /* add key */ - unsigned long long total= 0; - for (uint32_t x= 0 ; total < 20 * 1024576 ; x++ ) - { - uint32_t size= (uint32_t)(rand() % ( 5 * 1024 ) ) + 400; - char randomstuff[6 * 1024]; - memset(randomstuff, 0, 6 * 1024); - test_true(size < 6 * 1024); /* Being safe here */ - - for (uint32_t j= 0 ; j < size ;j++) - { - randomstuff[j] = (signed char) ((rand() % 26) + 97); - } - - total+= size; - char key[22]; - int key_length= snprintf(key, sizeof(key), "%u", x); - test_compare(MEMCACHED_SUCCESS, - memcached_set(memc, key, key_length, randomstuff, strlen(randomstuff), time_t(0), HALDENBRAND_FLAG_KEY)); - } - test_true(total > HALDENBRAND_KEY_COUNT); - - return TEST_SUCCESS; -} - -/* Test case provided by Cal Haldenbrand */ -static test_return_t user_supplied_bug2(memcached_st *memc) -{ - test_compare(MEMCACHED_SUCCESS, - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, true)); - - test_compare(MEMCACHED_SUCCESS, - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, true)); - -#ifdef NOT_YET - test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, 20 * 1024576)); - test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, 20 * 1024576)); - getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE); - getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE); - - for (x= 0, errors= 0; total < 20 * 1024576 ; x++) -#endif - - size_t total_value_length= 0; - for (uint32_t x= 0, errors= 0; total_value_length < 24576 ; x++) - { - uint32_t flags= 0; - size_t val_len= 0; - - char key[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1]; - int key_length= snprintf(key, sizeof(key), "%u", x); - - memcached_return_t rc; - char *getval= memcached_get(memc, key, key_length, &val_len, &flags, &rc); - if (memcached_failed(rc)) - { - if (rc == MEMCACHED_NOTFOUND) - { - errors++; - } - else - { - test_true(rc); - } - - continue; - } - test_compare(uint32_t(HALDENBRAND_FLAG_KEY), flags); - - total_value_length+= val_len; - errors= 0; - free(getval); - } - - return TEST_SUCCESS; -} - -/* Do a large mget() over all the keys we think exist */ -static test_return_t user_supplied_bug3(memcached_st *memc) -{ - test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 1)); - test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, 1)); - -#ifdef NOT_YET - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, 20 * 1024576); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, 20 * 1024576); - getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE); - getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE); -#endif - - std::vector key_lengths; - key_lengths.resize(HALDENBRAND_KEY_COUNT); - std::vector keys; - keys.resize(key_lengths.size()); - for (uint32_t x= 0; x < key_lengths.size(); x++) - { - char key[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1]; - int key_length= snprintf(key, sizeof(key), "%u", x); - test_true(key_length > 0 and key_length < MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1); - keys[x]= strdup(key); - key_lengths[x]= key_length; - } - - test_compare(MEMCACHED_SUCCESS, - memcached_mget(memc, &keys[0], &key_lengths[0], key_lengths.size())); - - unsigned int keys_returned; - test_compare(TEST_SUCCESS, fetch_all_results(memc, keys_returned, MEMCACHED_SUCCESS)); - test_compare(HALDENBRAND_KEY_COUNT, keys_returned); - - for (std::vector::iterator iter= keys.begin(); - iter != keys.end(); - iter++) - { - free(*iter); - } - - return TEST_SUCCESS; -} - /* Make sure we behave properly if server list has no values */ static test_return_t user_supplied_bug4(memcached_st *memc) { @@ -2300,9 +2266,13 @@ static test_return_t user_supplied_bug4(memcached_st *memc) test_compare(MEMCACHED_NO_SERVERS, memcached_mget(memc, keys, key_length, 3)); - unsigned int keys_returned; - test_compare(TEST_SUCCESS, fetch_all_results(memc, keys_returned, MEMCACHED_NOTFOUND)); - test_zero(keys_returned); + { + unsigned int keys_returned; + memcached_return_t rc; + test_compare(TEST_SUCCESS, fetch_all_results(memc, keys_returned, rc)); + test_compare(MEMCACHED_NOTFOUND, rc); + test_zero(keys_returned); + } for (uint32_t x= 0; x < 3; x++) { @@ -2362,7 +2332,8 @@ static test_return_t user_supplied_bug5(memcached_st *memc) memcached_mget(memc, keys, key_length, 4)); unsigned int count; - test_compare(TEST_SUCCESS, fetch_all_results(memc, count, MEMCACHED_NOTFOUND)); + test_compare(TEST_SUCCESS, fetch_all_results(memc, count, rc)); + test_compare(MEMCACHED_NOTFOUND, rc); test_zero(count); for (uint32_t x= 0; x < 4; x++) @@ -2379,12 +2350,12 @@ static test_return_t user_supplied_bug5(memcached_st *memc) &value_length, &flags, &rc); test_compare(rc, MEMCACHED_SUCCESS); test_true(value); - free(value); + ::free(value); test_compare(MEMCACHED_SUCCESS, memcached_mget(memc, keys, key_length, 4)); - test_compare(TEST_SUCCESS, fetch_all_results(memc, count, MEMCACHED_SUCCESS)); + test_compare(TEST_SUCCESS, fetch_all_results(memc, count)); test_compare(4U, count); } delete [] insert_data; @@ -2494,37 +2465,36 @@ static test_return_t user_supplied_bug8(memcached_st *) /* Test flag store/retrieve */ static test_return_t user_supplied_bug7(memcached_st *memc) { - const char *keys= "036790384900"; - size_t key_length= strlen(keys); - char return_key[MEMCACHED_MAX_KEY]; - size_t return_key_length; - char *value; - size_t value_length; - uint32_t flags; char *insert_data= new (std::nothrow) char[VALUE_SIZE_BUG5]; + test_true(insert_data); - for (unsigned int x= 0; x < VALUE_SIZE_BUG5; x++) + for (size_t x= 0; x < VALUE_SIZE_BUG5; x++) { insert_data[x]= (signed char)rand(); } memcached_flush(memc, 0); - flags= 245; - test_compare(MEMCACHED_SUCCESS, memcached_set(memc, keys, key_length, - insert_data, VALUE_SIZE_BUG5, - (time_t)0, flags)); + const char *keys= "036790384900"; + size_t key_length= strlen(keys); + test_compare_hint(MEMCACHED_SUCCESS, memcached_set(memc, keys, key_length, + insert_data, VALUE_SIZE_BUG5, + time_t(0), 245U), + memcached_last_error_message(memc)); memcached_return_t rc; - flags= 0; - value= memcached_get(memc, keys, key_length, - &value_length, &flags, &rc); + size_t value_length; + uint32_t flags= 0; + char *value= memcached_get(memc, keys, key_length, + &value_length, &flags, &rc); test_compare(245U, flags); test_true(value); free(value); test_compare(MEMCACHED_SUCCESS, memcached_mget(memc, &keys, &key_length, 1)); + char return_key[MEMCACHED_MAX_KEY]; + size_t return_key_length; flags= 0; value= memcached_fetch(memc, return_key, &return_key_length, &value_length, &flags, &rc); @@ -2590,7 +2560,7 @@ static test_return_t user_supplied_bug10(memcached_st *memc) memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, set); memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, uint64_t(0)); - std::vector value; + libtest::vchar_t value; value.reserve(value_length); for (uint32_t x= 0; x < value_length; x++) { @@ -2633,7 +2603,7 @@ static test_return_t user_supplied_bug11(memcached_st *memc) test_compare(-1, int32_t(memcached_behavior_get(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT))); - std::vector value; + libtest::vchar_t value; value.reserve(512); for (unsigned int x= 0; x < 512; x++) { @@ -2701,27 +2671,24 @@ static test_return_t user_supplied_bug12(memcached_st *memc) static test_return_t user_supplied_bug13(memcached_st *memc) { char key[] = "key34567890"; - memcached_return_t rc; - size_t overflowSize; char commandFirst[]= "set key34567890 0 0 "; char commandLast[] = " \r\n"; /* first line of command sent to server */ size_t commandLength; - size_t testSize; commandLength = strlen(commandFirst) + strlen(commandLast) + 4; /* 4 is number of characters in size, probably 8196 */ - overflowSize = MEMCACHED_MAX_BUFFER - commandLength; + size_t overflowSize = MEMCACHED_MAX_BUFFER - commandLength; - for (testSize= overflowSize - 1; testSize < overflowSize + 1; testSize++) + for (size_t testSize= overflowSize - 1; testSize < overflowSize + 1; testSize++) { char *overflow= new (std::nothrow) char[testSize]; test_true(overflow); memset(overflow, 'x', testSize); - rc= memcached_set(memc, key, strlen(key), - overflow, testSize, 0, 0); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_set(memc, key, strlen(key), + overflow, testSize, 0, 0)); delete [] overflow; } @@ -2739,7 +2706,7 @@ static test_return_t user_supplied_bug14(memcached_st *memc) { memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, true); - std::vector value; + libtest::vchar_t value; value.reserve(18000); for (size_t x= 0; x < 18000; x++) { @@ -2795,7 +2762,7 @@ static test_return_t user_supplied_bug15(memcached_st *memc) &length, &flags, &rc); test_compare(MEMCACHED_SUCCESS, rc); - test_true(value == NULL); + test_null(value); test_zero(length); test_zero(flags); } @@ -2806,19 +2773,20 @@ static test_return_t user_supplied_bug15(memcached_st *memc) /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */ static test_return_t user_supplied_bug16(memcached_st *memc) { - memcached_return_t rc= memcached_set(memc, test_literal_param("mykey"), - NULL, 0, - (time_t)0, UINT32_MAX); + test_compare_hint(MEMCACHED_SUCCESS, memcached_set(memc, test_literal_param("mykey"), + NULL, 0, + (time_t)0, UINT32_MAX), + memcached_last_error_message(memc)); - test_compare(MEMCACHED_SUCCESS, rc); size_t length; uint32_t flags; + memcached_return_t rc; char *value= memcached_get(memc, test_literal_param("mykey"), &length, &flags, &rc); test_compare(MEMCACHED_SUCCESS, rc); - test_true(value == NULL); + test_null(value); test_zero(length); test_compare(flags, UINT32_MAX); @@ -2934,24 +2902,14 @@ static test_return_t _user_supplied_bug21(memcached_st* memc, size_t key_count) /* empty the cache to ensure misses (hence non-responses) */ test_compare(MEMCACHED_SUCCESS, memcached_flush(memc_clone, 0)); - std::vector key_lengths; - key_lengths.resize(key_count); - std::vector keys; - keys.resize(key_lengths.size()); - for (unsigned int x= 0; x < key_lengths.size(); x++) - { - char key[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1]; - int key_length= snprintf(key, sizeof(key), "%u", x); - test_true(key_length > 0 and key_length < MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1); - keys[x]= strdup(key); - key_lengths[x]= key_length; - } - + keys_st keys(key_count); + oldalarm= signal(SIGALRM, fail); alarm(5); test_compare_got(MEMCACHED_SUCCESS, - memcached_mget(memc_clone, &keys[0], &key_lengths[0], key_count), memcached_last_error_message(memc_clone)); + memcached_mget(memc_clone, keys.keys_ptr(), keys.lengths_ptr(), keys.size()), + memcached_last_error_message(memc_clone)); alarm(0); signal(SIGALRM, oldalarm); @@ -2973,13 +2931,6 @@ static test_return_t _user_supplied_bug21(memcached_st* memc, size_t key_count) test_false(return_key[0]); test_false(return_value); - for (std::vector::iterator iter= keys.begin(); - iter != keys.end(); - iter++) - { - free(*iter); - } - memcached_free(memc_clone); return TEST_SUCCESS; @@ -3086,298 +3037,6 @@ static test_return_t result_alloc(memcached_st *memc) return TEST_SUCCESS; } -static test_return_t cleanup_pairs(memcached_st *memc) -{ - (void)memc; - pairs_free(global_pairs); - - return TEST_SUCCESS; -} - -static test_return_t generate_pairs(memcached_st *) -{ - global_pairs= pairs_generate(GLOBAL_COUNT, 400); - global_count= GLOBAL_COUNT; - - for (size_t x= 0; x < global_count; x++) - { - global_keys[x]= global_pairs[x].key; - global_keys_length[x]= global_pairs[x].key_length; - } - - return TEST_SUCCESS; -} - -static test_return_t generate_large_pairs(memcached_st *) -{ - global_pairs= pairs_generate(GLOBAL2_COUNT, MEMCACHED_MAX_BUFFER+10); - global_count= GLOBAL2_COUNT; - - for (size_t x= 0; x < global_count; x++) - { - global_keys[x]= global_pairs[x].key; - global_keys_length[x]= global_pairs[x].key_length; - } - - return TEST_SUCCESS; -} - -static test_return_t generate_data(memcached_st *memc) -{ - unsigned int check_execute= execute_set(memc, global_pairs, global_count); - - test_compare(global_count, check_execute); - - return TEST_SUCCESS; -} - -static test_return_t generate_data_with_stats(memcached_st *memc) -{ - unsigned int check_execute= execute_set(memc, global_pairs, global_count); - - test_compare(check_execute, global_count); - - // @todo hosts used size stats - memcached_return_t rc; - memcached_stat_st *stat_p= memcached_stat(memc, NULL, &rc); - test_true(stat_p); - - for (uint32_t host_index= 0; host_index < SERVERS_TO_CREATE; host_index++) - { - /* This test was changes so that "make test" would work properlly */ - if (DEBUG) - { - memcached_server_instance_st instance= - memcached_server_instance_by_position(memc, host_index); - - printf("\nserver %u|%s|%u bytes: %llu\n", host_index, instance->hostname, instance->port, (unsigned long long)(stat_p + host_index)->bytes); - } - test_true((unsigned long long)(stat_p + host_index)->bytes); - } - - memcached_stat_free(NULL, stat_p); - - return TEST_SUCCESS; -} -static test_return_t generate_buffer_data(memcached_st *memc) -{ - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, true); - generate_data(memc); - - return TEST_SUCCESS; -} - -static test_return_t get_read_count(memcached_st *memc) -{ - memcached_st *memc_clone= memcached_clone(NULL, memc); - test_true(memc_clone); - - memcached_server_add_with_weight(memc_clone, "localhost", 6666, 0); - - { - char *return_value; - size_t return_value_length; - uint32_t flags; - uint32_t count; - - for (size_t x= count= 0; x < global_count; x++) - { - memcached_return_t rc; - return_value= memcached_get(memc_clone, global_keys[x], global_keys_length[x], - &return_value_length, &flags, &rc); - if (rc == MEMCACHED_SUCCESS) - { - count++; - if (return_value) - { - free(return_value); - } - } - } - } - - memcached_free(memc_clone); - - return TEST_SUCCESS; -} - -static test_return_t get_read(memcached_st *memc) -{ - for (size_t x= 0; x < global_count; x++) - { - size_t return_value_length; - uint32_t flags; - memcached_return_t rc; - char *return_value= memcached_get(memc, global_keys[x], global_keys_length[x], - &return_value_length, &flags, &rc); - /* - test_true(return_value); - test_compare(MEMCACHED_SUCCESS, rc); - */ - if (rc == MEMCACHED_SUCCESS && return_value) - { - free(return_value); - } - } - - return TEST_SUCCESS; -} - -static test_return_t mget_read(memcached_st *memc) -{ - - test_skip(true, bool(libmemcached_util_version_check(memc, 1, 4, 4))); - - test_compare(MEMCACHED_SUCCESS, - memcached_mget(memc, global_keys, global_keys_length, global_count)); - - // Go fetch the keys and test to see if all of them were returned - { - unsigned int keys_returned; - test_compare(TEST_SUCCESS, fetch_all_results(memc, keys_returned, MEMCACHED_SUCCESS)); - test_true(keys_returned > 0); - test_compare_warn_hint(global_count, keys_returned, "Possible false, positive, memcached may have ejected key/value based on memory needs"); - } - - return TEST_SUCCESS; -} - -static test_return_t mget_read_result(memcached_st *memc) -{ - - test_skip(true, bool(libmemcached_util_version_check(memc, 1, 4, 4))); - - test_compare(MEMCACHED_SUCCESS, - memcached_mget(memc, global_keys, global_keys_length, global_count)); - - /* Turn this into a help function */ - { - memcached_result_st results_obj; - memcached_result_st *results= memcached_result_create(memc, &results_obj); - test_true(results); - - memcached_return_t rc; - while ((results= memcached_fetch_result(memc, &results_obj, &rc))) - { - if (rc == MEMCACHED_IN_PROGRESS) - { - continue; - } - - test_true(results); - test_compare(MEMCACHED_SUCCESS, rc); - } - test_compare(MEMCACHED_END, rc); - - memcached_result_free(&results_obj); - } - - return TEST_SUCCESS; -} - -static test_return_t mget_read_internal_result(memcached_st *memc) -{ - - test_skip(true, bool(libmemcached_util_version_check(memc, 1, 4, 4))); - - test_compare(MEMCACHED_SUCCESS, - memcached_mget(memc, global_keys, global_keys_length, global_count)); - { - memcached_result_st *results= NULL; - memcached_return_t rc; - while ((results= memcached_fetch_result(memc, results, &rc))) - { - test_true(results); - test_compare(MEMCACHED_SUCCESS, rc); - } - test_compare(MEMCACHED_END, rc); - - memcached_result_free(results); - } - - return TEST_SUCCESS; -} - -static test_return_t mget_read_partial_result(memcached_st *memc) -{ - - test_skip(true, bool(libmemcached_util_version_check(memc, 1, 4, 4))); - - test_compare(MEMCACHED_SUCCESS, - memcached_mget(memc, global_keys, global_keys_length, global_count)); - - // We will scan for just one key - { - memcached_result_st results_obj; - memcached_result_st *results= memcached_result_create(memc, &results_obj); - - memcached_return_t rc; - results= memcached_fetch_result(memc, results, &rc); - test_true(results); - test_compare(MEMCACHED_SUCCESS, rc); - - memcached_result_free(&results_obj); - } - - // We already have a read happening, lets start up another one. - test_compare(MEMCACHED_SUCCESS, - memcached_mget(memc, global_keys, global_keys_length, global_count)); - { - memcached_result_st results_obj; - memcached_result_st *results= memcached_result_create(memc, &results_obj); - test_true(results); - test_false(memcached_is_allocated(results)); - - memcached_return_t rc; - while ((results= memcached_fetch_result(memc, &results_obj, &rc))) - { - test_true(results); - test_compare(MEMCACHED_SUCCESS, rc); - } - test_compare(MEMCACHED_END, rc); - - memcached_result_free(&results_obj); - } - - return TEST_SUCCESS; -} - -static test_return_t mget_read_function(memcached_st *memc) -{ - test_skip(true, bool(libmemcached_util_version_check(memc, 1, 4, 4))); - - test_compare(MEMCACHED_SUCCESS, - memcached_mget(memc, global_keys, global_keys_length, global_count)); - - memcached_execute_fn callbacks[]= { &callback_counter }; - size_t counter= 0; - test_compare(MEMCACHED_SUCCESS, - memcached_fetch_execute(memc, callbacks, (void *)&counter, 1)); - - return TEST_SUCCESS; -} - -static test_return_t delete_generate(memcached_st *memc) -{ - for (size_t x= 0; x < global_count; x++) - { - (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0); - } - - return TEST_SUCCESS; -} - -static test_return_t delete_buffer_generate(memcached_st *memc) -{ - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, true); - - for (size_t x= 0; x < global_count; x++) - { - (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0); - } - - return TEST_SUCCESS; -} static test_return_t add_host_test1(memcached_st *memc) { @@ -3759,8 +3418,7 @@ static test_return_t deprecated_set_memory_alloc(memcached_st *memc) void *test_ptr= NULL; void *cb_ptr= NULL; { - memcached_malloc_fn malloc_cb= - (memcached_malloc_fn)my_malloc; + memcached_malloc_fn malloc_cb= (memcached_malloc_fn)my_malloc; cb_ptr= *(void **)&malloc_cb; memcached_return_t rc; @@ -3945,11 +3603,11 @@ static test_return_t MEMCACHED_BEHAVIOR_POLL_TIMEOUT_test(memcached_st *memc) static test_return_t noreply_test(memcached_st *memc) { test_compare(MEMCACHED_SUCCESS, - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 1)); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, true)); test_compare(MEMCACHED_SUCCESS, - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1)); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, true)); test_compare(MEMCACHED_SUCCESS, - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, 1)); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, true)); test_compare(1LLU, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NOREPLY)); test_compare(1LLU, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS)); test_compare(1LLU, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS)); @@ -3959,7 +3617,7 @@ static test_return_t noreply_test(memcached_st *memc) { for (size_t x= 0; x < 100; ++x) { - char key[10]; + char key[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1]; int check_length= (size_t)snprintf(key, sizeof(key), "%lu", (unsigned long)x); test_false((size_t)check_length >= sizeof(key) || check_length < 0); @@ -3986,7 +3644,8 @@ static test_return_t noreply_test(memcached_st *memc) test_true(count); break; } - test_true_got(ret == MEMCACHED_SUCCESS or ret == MEMCACHED_BUFFERED, memcached_strerror(NULL, ret)); + test_true_got(ret == MEMCACHED_SUCCESS or ret == MEMCACHED_BUFFERED, + memcached_strerror(NULL, ret)); } /* @@ -3994,6 +3653,7 @@ static test_return_t noreply_test(memcached_st *memc) ** API and is _ONLY_ done this way to verify that the library works the ** way it is supposed to do!!!! */ +#if 0 int no_msg=0; for (uint32_t x= 0; x < memcached_server_count(memc); ++x) { @@ -4003,6 +3663,7 @@ static test_return_t noreply_test(memcached_st *memc) } test_true(no_msg == 0); +#endif test_compare(MEMCACHED_SUCCESS, memcached_flush_buffers(memc)); /* @@ -4083,8 +3744,8 @@ static test_return_t noreply_test(memcached_st *memc) static test_return_t analyzer_test(memcached_st *memc) { - memcached_return_t rc; memcached_analysis_st *report; + memcached_return_t rc; memcached_stat_st *memc_stat= memcached_stat(memc, NULL, &rc); test_compare(MEMCACHED_SUCCESS, rc); @@ -4100,24 +3761,6 @@ static test_return_t analyzer_test(memcached_st *memc) return TEST_SUCCESS; } -/* Count the objects */ - -static test_return_t dump_test(memcached_st *memc) -{ - /* No support for Binary protocol yet */ - test_skip(false, memc->flags.binary_protocol); - - test_compare(TEST_SUCCESS, set_test3(memc)); - - // confirm_key_count() call dump - size_t counter= confirm_key_count(memc); - - /* We may have more then 32 if our previous flush has not completed */ - test_true(counter >= 32); - - return TEST_SUCCESS; -} - static test_return_t util_version_test(memcached_st *memc) { test_compare_hint(MEMCACHED_SUCCESS, memcached_version(memc), memcached_last_error_message(memc)); @@ -4673,6 +4316,8 @@ static test_return_t regression_bug_434843(memcached_st *original_memc) test_compare(MEMCACHED_SUCCESS, memcached_mget(memc, (const char**)keys, key_length, max_keys)); + // One the first run we should get a NOT_FOUND, but on the second some data + // should be returned. test_compare(y ? MEMCACHED_SUCCESS : MEMCACHED_NOTFOUND, memcached_fetch_execute(memc, callbacks, (void *)&counter, 1)); @@ -4783,8 +4428,7 @@ static test_return_t regression_bug_442914(memcached_st *memc) test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); } - (void)snprintf(k, sizeof(k), "%037u", 251U); - len= strlen(k); + len= snprintf(k, sizeof(k), "%037u", 251U); memcached_return_t rc= memcached_delete(memc, k, len, 0); test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); @@ -4921,6 +4565,10 @@ static test_return_t regression_bug_447342(memcached_st *memc) static test_return_t regression_bug_463297(memcached_st *memc) { + test_compare(MEMCACHED_INVALID_ARGUMENTS, memcached_delete(memc, "foo", 3, 1)); + + // Since we blocked timed delete, this test is no longer valid. +#if 0 memcached_st *memc_clone= memcached_clone(NULL, memc); test_true(memc_clone); test_true(memcached_version(memc_clone) == MEMCACHED_SUCCESS); @@ -4976,6 +4624,8 @@ static test_return_t regression_bug_463297(memcached_st *memc) } memcached_free(memc_clone); +#endif + return TEST_SUCCESS; } @@ -5099,14 +4749,14 @@ static test_return_t memcached_stat_execute_test(memcached_st *memc) memcached_return_t rc= memcached_stat_execute(memc, NULL, stat_printer, NULL); test_compare(MEMCACHED_SUCCESS, rc); - rc= memcached_stat_execute(memc, "slabs", stat_printer, NULL); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_stat_execute(memc, "slabs", stat_printer, NULL)); - rc= memcached_stat_execute(memc, "items", stat_printer, NULL); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_stat_execute(memc, "items", stat_printer, NULL)); - rc= memcached_stat_execute(memc, "sizes", stat_printer, NULL); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_stat_execute(memc, "sizes", stat_printer, NULL)); return TEST_SUCCESS; } @@ -5136,7 +4786,7 @@ static test_return_t wrong_failure_counter_test(memcached_st *memc) rc= memcached_set(memc, key, strlen(key), value, strlen(value), (time_t)0, (uint32_t)0); - test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); instance= memcached_server_instance_by_position(memc, 0); @@ -5166,53 +4816,45 @@ static test_return_t wrong_failure_counter_test(memcached_st *memc) */ static test_return_t wrong_failure_counter_two_test(memcached_st *memc) { - memcached_return rc; - - memcached_st *memc_clone; - memc_clone= memcached_clone(NULL, memc); - test_true(memc_clone); - /* Set value to force connection to the server */ const char *key= "marmotte"; const char *value= "milka"; - char *string = NULL; - size_t string_length; - uint32_t flags; - rc= memcached_set(memc_clone, key, strlen(key), - value, strlen(value), - (time_t)0, (uint32_t)0); - test_true_got(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED, memcached_strerror(NULL, rc)); + test_compare_hint(MEMCACHED_SUCCESS, + memcached_set(memc, key, strlen(key), + value, strlen(value), + (time_t)0, (uint32_t)0), + memcached_last_error_message(memc)); /* put failure limit to 1 */ test_compare(MEMCACHED_SUCCESS, - memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, 1)); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, true)); /* Put a retry timeout to effectively activate failure_limit effect */ test_compare(MEMCACHED_SUCCESS, - memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, 1)); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, true)); /* change behavior that triggers memcached_quit()*/ test_compare(MEMCACHED_SUCCESS, - memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_TCP_NODELAY, 1)); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, true)); /* Check if we still are connected */ - string= memcached_get(memc_clone, key, strlen(key), - &string_length, &flags, &rc); + uint32_t flags; + size_t string_length; + memcached_return rc; + char *string= memcached_get(memc, key, strlen(key), + &string_length, &flags, &rc); test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc)); test_true(string); free(string); - memcached_free(memc_clone); return TEST_SUCCESS; } - - /* * Test that ensures mget_execute does not end into recursive calls that finally fails */ @@ -5451,7 +5093,7 @@ static test_return_t regression_bug_490520(memcached_st *memc) test_true(keys[x]); memcached_return rc= memcached_set(memc, keys[x], key_length[x], blob, sizeof(blob), 0, 0); - test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); + test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_last_error_message(memc)); } for (uint32_t x= 0; x < regression_bug_490520_COUNT; ++x) @@ -5608,10 +5250,9 @@ test_st tests[] ={ {"connection_test", false, (test_callback_fn*)connection_test}, {"callback_test", false, (test_callback_fn*)callback_test}, {"userdata_test", false, (test_callback_fn*)userdata_test}, - {"set", false, (test_callback_fn*)set_test }, - {"set2", false, (test_callback_fn*)set_test2 }, - {"set3", false, (test_callback_fn*)set_test3 }, - {"dump", true, (test_callback_fn*)dump_test}, + {"memcached_set()", false, (test_callback_fn*)set_test }, + {"memcached_set() 2", false, (test_callback_fn*)set_test2 }, + {"memcached_set() 3", false, (test_callback_fn*)set_test3 }, {"add", true, (test_callback_fn*)add_test }, {"memcached_fetch_result(MEMCACHED_NOTFOUND)", true, (test_callback_fn*)memcached_fetch_result_NOT_FOUND }, {"replace", true, (test_callback_fn*)replace_test }, @@ -5630,7 +5271,7 @@ test_st tests[] ={ {"increment_with_initial_by_key", true, (test_callback_fn*)increment_with_initial_by_key_test }, {"decrement_by_key", false, (test_callback_fn*)decrement_by_key_test }, {"decrement_with_initial_by_key", true, (test_callback_fn*)decrement_with_initial_by_key_test }, - {"binary_increment_with_prefix", 1, (test_callback_fn*)binary_increment_with_prefix_test }, + {"binary_increment_with_prefix", true, (test_callback_fn*)binary_increment_with_prefix_test }, {"quit", false, (test_callback_fn*)quit_test }, {"mget", true, (test_callback_fn*)mget_test }, {"mget_result", true, (test_callback_fn*)mget_result_test }, @@ -5642,7 +5283,8 @@ test_st tests[] ={ {"add_host_test", false, (test_callback_fn*)add_host_test }, {"add_host_test_1", false, (test_callback_fn*)add_host_test1 }, {"get_stats_keys", false, (test_callback_fn*)get_stats_keys }, - {"version_string_test", false, (test_callback_fn*)version_string_test}, + {"version_string_test", true, (test_callback_fn*)version_string_test}, + {"memcached_mget() mixed memcached_get()", true, (test_callback_fn*)memcached_mget_mixed_memcached_get_TEST}, {"bad_key", true, (test_callback_fn*)bad_key_test }, {"memcached_server_cursor", true, (test_callback_fn*)memcached_server_cursor_test }, {"read_through", true, (test_callback_fn*)read_through }, @@ -5664,6 +5306,10 @@ test_st tests[] ={ {"memcached_exist_by_key(MEMCACHED_SUCCESS)", true, (test_callback_fn*)memcached_exist_by_key_SUCCESS }, {"memcached_touch", 0, (test_callback_fn*)test_memcached_touch}, {"memcached_touch_with_prefix", 0, (test_callback_fn*)test_memcached_touch_by_key}, +#if 0 + {"memcached_dump() no data", true, (test_callback_fn*)memcached_dump_TEST }, +#endif + {"memcached_dump() with data", true, (test_callback_fn*)memcached_dump_TEST2 }, {0, 0, 0} }; @@ -5673,6 +5319,12 @@ test_st touch_tests[] ={ {0, 0, 0} }; +test_st memcached_stat_tests[] ={ + {"memcached_stat() INVALID ARG", 0, (test_callback_fn*)memcached_stat_TEST}, + {"memcached_stat()", 0, (test_callback_fn*)memcached_stat_TEST2}, + {0, 0, 0} +}; + test_st behavior_tests[] ={ {"libmemcached_string_behavior()", false, (test_callback_fn*)libmemcached_string_behavior_test}, {"libmemcached_string_distribution()", false, (test_callback_fn*)libmemcached_string_distribution_test}, @@ -5735,10 +5387,10 @@ test_st version_1_2_3[] ={ {0, 0, (test_callback_fn*)0} }; -test_st haldenbrand_tests[] ={ - {"memcached_set", false, (test_callback_fn*)user_supplied_bug1 }, - {"memcached_get()", false, (test_callback_fn*)user_supplied_bug2 }, - {"memcached_mget()", false, (test_callback_fn*)user_supplied_bug3 }, +test_st haldenbrand_TESTS[] ={ + {"memcached_set", false, (test_callback_fn*)haldenbrand_TEST1 }, + {"memcached_get()", false, (test_callback_fn*)haldenbrand_TEST2 }, + {"memcached_mget()", false, (test_callback_fn*)haldenbrand_TEST3 }, {0, 0, (test_callback_fn*)0} }; @@ -5781,6 +5433,7 @@ test_st replication_tests[]= { {"mget", false, (test_callback_fn*)replication_mget_test }, {"delete", true, (test_callback_fn*)replication_delete_test }, {"rand_mget", false, (test_callback_fn*)replication_randomize_mget_test }, + {"miss", false, (test_callback_fn*)replication_miss_test }, {"fail", false, (test_callback_fn*)replication_randomize_mget_fail_test }, {0, 0, (test_callback_fn*)0} }; @@ -5981,7 +5634,7 @@ collection_st collection[] ={ {"result", 0, 0, result_tests}, {"async", (test_callback_fn*)pre_nonblock, 0, async_tests}, {"async(BINARY)", (test_callback_fn*)pre_nonblock_binary, 0, async_tests}, - {"Cal Haldenbrand's tests", 0, 0, haldenbrand_tests}, + {"Cal Haldenbrand's tests", 0, 0, haldenbrand_TESTS}, {"user written tests", 0, 0, user_tests}, {"generate", 0, 0, generate_tests}, {"generate_hsieh", (test_callback_fn*)pre_hsieh, 0, generate_tests}, @@ -6009,6 +5662,8 @@ collection_st collection[] ={ {"virtual buckets", 0, 0, virtual_bucket_tests}, {"memcached_server_get_last_disconnect", 0, 0, memcached_server_get_last_disconnect_tests}, {"touch", 0, 0, touch_tests}, + {"touch", (test_callback_fn*)pre_binary, 0, touch_tests}, + {"memcached_stat()", 0, 0, memcached_stat_tests}, {0, 0, 0, 0} };