From: Michael Wallner Date: Mon, 28 Sep 2020 15:34:59 +0000 (+0200) Subject: testing: flush X-Git-Tag: 1.1.0-beta1~236^2~44 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=36c2351bfeb343f4d6da922cdee58f4bcdcd7e08;p=m6w6%2Flibmemcached testing: flush --- diff --git a/TODO b/TODO index 622fed71..013aa85d 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,8 @@ - Clients (src/bin): - consolidate CLI - convert to proper C++ where applicable +- Stats: + - redo ## Legacy: diff --git a/src/libmemcached/csl/common.h b/src/libmemcached/csl/common.h index 85881c18..067c2428 100644 --- a/src/libmemcached/csl/common.h +++ b/src/libmemcached/csl/common.h @@ -37,6 +37,7 @@ #pragma once +#define YYDEBUG 1 #ifndef YY_EXTRA_TYPE # define YY_EXTRA_TYPE Context* diff --git a/src/libmemcached/csl/context.cc b/src/libmemcached/csl/context.cc index 1fd25212..713912c6 100644 --- a/src/libmemcached/csl/context.cc +++ b/src/libmemcached/csl/context.cc @@ -77,7 +77,7 @@ void Context::error(const char *error_arg, config_tokentype last_token, const ch // return a generic message if (strcmp(error_arg, "syntax error") != 0) { - memcached_set_parser_error(*memc, MEMCACHED_AT, "Error occured during parsing (%s)", error_arg); + memcached_set_parser_error(*memc, MEMCACHED_AT, "Error occured during parsing (%s): last_token=%s(%d)", error_arg, last_token_str, last_token); return; } diff --git a/src/libmemcached/csl/scanner.l b/src/libmemcached/csl/scanner.l index af1d2bf8..d0d79a67 100644 --- a/src/libmemcached/csl/scanner.l +++ b/src/libmemcached/csl/scanner.l @@ -83,7 +83,8 @@ } #define YY_FATAL_ERROR(msg) \ -{ \ +{\ + fprintf(stderr, "%s\n", msg); \ } #define YYSTYPE CONFIG_STYPE diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index dbc7aecb..ebb39afe 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -19,7 +19,7 @@ target_include_directories(runtests PRIVATE ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR}/src) -target_link_libraries(runtests PRIVATE libhashkit libmemcached libmemcachedutil) +target_link_libraries(runtests PRIVATE libhashkit libmemcachedinternal libmemcachedutil) add_dependencies(runtests ${CLIENTS}) catch_discover_tests(runtests diff --git a/test/fixtures/options.config b/test/fixtures/options.config new file mode 100644 index 00000000..923ad352 --- /dev/null +++ b/test/fixtures/options.config @@ -0,0 +1 @@ +--SOCKET="/var/run/memcached/memcached.sock" diff --git a/test/lib/Cluster.cpp b/test/lib/Cluster.cpp index c3c625cf..ee7fcbf2 100644 --- a/test/lib/Cluster.cpp +++ b/test/lib/Cluster.cpp @@ -8,7 +8,10 @@ Cluster::Cluster(Server serv, uint16_t cnt) , proto{move(serv)} { if (!cnt) { - count = thread::hardware_concurrency()/2 ?: 4; + count = thread::hardware_concurrency()/2; + if (count < 4) { + count = 4; + } } reset(); } diff --git a/test/lib/common.hpp b/test/lib/common.hpp index 0deb247b..24ec3a48 100644 --- a/test/lib/common.hpp +++ b/test/lib/common.hpp @@ -100,6 +100,9 @@ public: memcached_st *operator * () { return memc; } + auto operator ->() { + return memc; + } }; template diff --git a/test/tests/memcached/behavior.cpp b/test/tests/memcached/behavior.cpp new file mode 100644 index 00000000..1ee58370 --- /dev/null +++ b/test/tests/memcached/behavior.cpp @@ -0,0 +1 @@ +#warning TODO diff --git a/test/tests/memcached/exist.cpp b/test/tests/memcached/exist.cpp index 7c89d7d0..07758150 100644 --- a/test/tests/memcached/exist.cpp +++ b/test/tests/memcached/exist.cpp @@ -2,45 +2,40 @@ #include "test/lib/MemcachedCluster.hpp" TEST_CASE("memcached_exist") { - pair tests[]{ - {"bin_mixed", MemcachedCluster::mixed()}, - {"network", MemcachedCluster::network()}, - {"socket", MemcachedCluster::socket()} - }; + MemcachedCluster test; + auto memc = &test.memc; + auto binary = GENERATE(0, 1); - tests[0].second.enableBinaryProto(); + test.enableBinaryProto(binary); + INFO("binary: " << binary); - LOOPED_SECTION(tests) { - auto memc = &test.memc; + SECTION("initial not found") { + REQUIRE_RC(MEMCACHED_NOTFOUND,memcached_exist(memc, S("frog"))); + } + + SECTION("set found") { + REQUIRE_SUCCESS(memcached_set(memc, S("frog"), S("frog"), 0, 0)); + REQUIRE_SUCCESS(memcached_exist(memc, S("frog"))); + + SECTION("deleted not found") { + REQUIRE_SUCCESS(memcached_delete(memc, S("frog"), 0)); + REQUIRE_RC(MEMCACHED_NOTFOUND, memcached_exist(memc, S("frog"))); + } + } + SECTION("by key") { SECTION("initial not found") { - REQUIRE_RC(MEMCACHED_NOTFOUND,memcached_exist(memc, S("frog"))); + REQUIRE_RC(MEMCACHED_NOTFOUND, memcached_exist_by_key(memc, S("master"), S("frog"))); } SECTION("set found") { - REQUIRE_SUCCESS(memcached_set(memc, S("frog"), S("frog"), 0, 0)); - REQUIRE_SUCCESS(memcached_exist(memc, S("frog"))); + REQUIRE_SUCCESS(memcached_set_by_key(memc, S("master"), S("frog"), S("frog"), 0, 0)); + REQUIRE_SUCCESS(memcached_exist_by_key(memc, S("master"), S("frog"))); - SECTION("deleted not found") { - REQUIRE_SUCCESS(memcached_delete(memc, S("frog"), 0)); - REQUIRE_RC(MEMCACHED_NOTFOUND, memcached_exist(memc, S("frog"))); - } - } - - SECTION("by key") { - SECTION("initial not found") { + SECTION("deleted not found") { + REQUIRE_SUCCESS(memcached_delete_by_key(memc, S("master"), S("frog"), 0)); REQUIRE_RC(MEMCACHED_NOTFOUND, memcached_exist_by_key(memc, S("master"), S("frog"))); } - - SECTION("set found") { - REQUIRE_SUCCESS(memcached_set_by_key(memc, S("master"), S("frog"), S("frog"), 0, 0)); - REQUIRE_SUCCESS(memcached_exist_by_key(memc, S("master"), S("frog"))); - - SECTION("deleted not found") { - REQUIRE_SUCCESS(memcached_delete_by_key(memc, S("master"), S("frog"), 0)); - REQUIRE_RC(MEMCACHED_NOTFOUND, memcached_exist_by_key(memc, S("master"), S("frog"))); - } - } } } diff --git a/test/tests/memcached/ketama.cpp b/test/tests/memcached/ketama.cpp index 3fec19c6..75d18c2c 100644 --- a/test/tests/memcached/ketama.cpp +++ b/test/tests/memcached/ketama.cpp @@ -1,7 +1,7 @@ #include "test/lib/common.hpp" #include "test/lib/MemcachedCluster.hpp" -#include "testing/fixtures/ketama.hpp" +#include "test/fixtures/ketama.hpp" #include "libmemcached/continuum.hpp" #include "libmemcached/instance.hpp" diff --git a/test/tests/memcached/options.cpp b/test/tests/memcached/options.cpp new file mode 100644 index 00000000..06eb34fa --- /dev/null +++ b/test/tests/memcached/options.cpp @@ -0,0 +1,28 @@ +#include "test/lib/common.hpp" +#include "test/lib/MemcachedCluster.hpp" + +#include "libmemcached/options.hpp" +#include "libmemcached/common.h" +#include "libmemcached/array.h" + + +#include + +#define FIXTURES_OPTIONS_CONFIG "/../../fixtures/options.config" + +TEST_CASE("memcached_options") { + MemcachedPtr memc; + LoneReturnMatcher test{*memc}; + + char cpp_file[] = __FILE__, buf[1024], *dir = dirname(cpp_file); + auto file = string(dir) + FIXTURES_OPTIONS_CONFIG; + auto config = "--CONFIGURE-FILE=\"" + file + "\""; + + REQUIRE_RC(MEMCACHED_INVALID_ARGUMENTS, memcached_parse_configure_file(**memc, nullptr, 123)); + REQUIRE_RC(MEMCACHED_INVALID_ARGUMENTS, memcached_parse_configure_file(**memc, file.c_str(), 0)); + REQUIRE_RC(MEMCACHED_ERRNO, memcached_parse_configure_file(**memc, S("foobar.baz"))); + REQUIRE_SUCCESS(memcached_parse_configure_file(**memc, file.c_str(), file.length())); + + REQUIRE_SUCCESS(libmemcached_check_configuration(config.c_str(), config.length(), buf, sizeof(buf) - 1)); + REQUIRE_RC(MEMCACHED_PARSE_ERROR, libmemcached_check_configuration(S("foo bar"), nullptr, 0)); +} diff --git a/test/tests/memcached/regression/lp_000-854-604.cpp b/test/tests/memcached/regression/lp_000-854-604.cpp new file mode 100644 index 00000000..f8067e87 --- /dev/null +++ b/test/tests/memcached/regression/lp_000-854-604.cpp @@ -0,0 +1,13 @@ +#include "test/lib/common.hpp" + +#define NULL_CSTR nullptr,0 + +TEST_CASE("memcached_regression_lp854604") { + char buffer[1024]; + + REQUIRE(MEMCACHED_INVALID_ARGUMENTS == libmemcached_check_configuration(NULL_CSTR, NULL_CSTR)); + REQUIRE(MEMCACHED_INVALID_ARGUMENTS == libmemcached_check_configuration(NULL_CSTR, buffer, 0)); + for (auto i = 0; i < 100; ++i) { + REQUIRE(MEMCACHED_PARSE_ERROR == libmemcached_check_configuration(S("syntax error"), buffer, random_num(0,1024))); + } +} diff --git a/test/tests/memcached/stat.cpp b/test/tests/memcached/stat.cpp new file mode 100644 index 00000000..92682f57 --- /dev/null +++ b/test/tests/memcached/stat.cpp @@ -0,0 +1,75 @@ +#include "test/lib/common.hpp" +#include "test/lib/MemcachedCluster.hpp" + +static memcached_return_t item_counter(const memcached_instance_st *, const char *key, size_t, const char *value, size_t, void *context) +{ + if (key == "curr_items"s) { + auto counter = static_cast(context); + *counter += stoul(value); + } + + return MEMCACHED_SUCCESS; +} + +TEST_CASE("memcached_stat") { + MemcachedCluster test; + auto memc = &test.memc; + + SECTION("invalid arguments") { + size_t count = 0; + REQUIRE_RC(MEMCACHED_INVALID_ARGUMENTS, memcached_stat_execute(memc, "BAD_ARG", item_counter, &count)); + } + + SECTION("execute") { + for (auto i = 0; i < 64; ++i) { + auto key = random_ascii_string(32); + REQUIRE_SUCCESS(memcached_set(memc, key.c_str(), key.length(), nullptr, 0, 0, 0)); + } + + memcached_quit(memc); + + size_t count = 0; + REQUIRE_SUCCESS(memcached_stat_execute(memc, nullptr, item_counter, &count)); + REQUIRE(count == 64); + } + + SECTION("servername") { + for (auto &server : test.cluster.getServers()) { + auto port = server.getSocketOrPort(); + if (holds_alternative(port)) { + memcached_stat_st stats; + REQUIRE_SUCCESS(memcached_stat_servername(&stats, nullptr, "localhost", get(port))); + REQUIRE(stats.pid); + } + } + } + + SECTION("get_keys/get_value") { // oh my + memcached_return_t rc; + auto servers = test.cluster.getServers(); + Malloced stats(memcached_stat(memc, nullptr, &rc)); + Malloced keys(memcached_stat_get_keys(memc, nullptr, nullptr)); + + REQUIRE_SUCCESS(rc); + REQUIRE(*stats); + REQUIRE(*keys); + + for (auto i = 0U; i < memcached_server_count(memc); ++i) { + auto this_stat = &(*stats)[i]; + + for (auto key = *keys; *key; ++key) { + Malloced val(memcached_stat_get_value(memc, this_stat, *key, &rc)); + REQUIRE_SUCCESS(rc); + REQUIRE(*val); + } + for (auto &server : test.cluster.getServers()) { + if (this_stat->pid == server.getPid()) { + goto found; + } + } + + FAIL("no server matches pid " << this_stat->pid); + found:; + } + } +} diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index 51fe1eb6..abc93835 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -224,25 +224,6 @@ test_return_t mget_end(memcached_st *memc) return TEST_SUCCESS; } -/* Do not copy the style of this code, I just access hosts to testthis function */ -test_return_t stats_servername_test(memcached_st *memc) -{ - memcached_stat_st memc_stat; - const memcached_instance_st * instance= - memcached_server_instance_by_position(memc, 0); - - if (LIBMEMCACHED_WITH_SASL_SUPPORT and memcached_get_sasl_callbacks(memc)) - { - return TEST_SKIPPED; - } - - test_compare(MEMCACHED_SUCCESS, memcached_stat_servername(&memc_stat, NULL, - memcached_server_name(instance), - memcached_server_port(instance))); - - return TEST_SUCCESS; -} - test_return_t mget_result_test(memcached_st *memc) { const char *keys[]= {"fudge", "son", "food"}; @@ -523,47 +504,6 @@ test_return_t MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH_TEST(memcached_st *original_mem return TEST_SUCCESS; } - -test_return_t get_stats_keys(memcached_st *memc) -{ - char **stat_list; - char **ptr; - memcached_stat_st memc_stat; - memcached_return_t rc; - - stat_list= memcached_stat_get_keys(memc, &memc_stat, &rc); - test_compare(MEMCACHED_SUCCESS, rc); - for (ptr= stat_list; *ptr; ptr++) - test_true(*ptr); - - free(stat_list); - - return TEST_SUCCESS; -} - - -test_return_t get_stats(memcached_st *memc) -{ - memcached_return_t rc; - - memcached_stat_st *memc_stat= memcached_stat(memc, NULL, &rc); - test_compare(MEMCACHED_SUCCESS, rc); - test_true(memc_stat); - - for (uint32_t x= 0; x < memcached_server_count(memc); x++) - { - char **stat_list= memcached_stat_get_keys(memc, memc_stat+x, &rc); - test_compare(MEMCACHED_SUCCESS, rc); - for (char **ptr= stat_list; *ptr; ptr++) {}; - - free(stat_list); - } - - memcached_stat_free(NULL, memc_stat); - - return TEST_SUCCESS; -} - test_return_t memcached_fetch_result_NOT_FOUND(memcached_st *memc) { memcached_return_t rc; @@ -1420,35 +1360,6 @@ test_return_t result_alloc(memcached_st *memc) } -test_return_t add_host_test1(memcached_st *memc) -{ - memcached_return_t rc; - char servername[]= "0.example.com"; - - memcached_server_st *servers= memcached_server_list_append_with_weight(NULL, servername, 400, 0, &rc); - test_true(servers); - test_compare(1U, memcached_server_list_count(servers)); - - for (uint32_t x= 2; x < 20; x++) - { - char buffer[SMALL_STRING_LEN]; - - snprintf(buffer, SMALL_STRING_LEN, "%lu.example.com", (unsigned long)(400 +x)); - servers= memcached_server_list_append_with_weight(servers, buffer, 401, 0, - &rc); - test_compare(MEMCACHED_SUCCESS, rc); - test_compare(x, memcached_server_list_count(servers)); - } - - test_compare(MEMCACHED_SUCCESS, memcached_server_push(memc, servers)); - test_compare(MEMCACHED_SUCCESS, memcached_server_push(memc, servers)); - - memcached_server_list_free(servers); - - return TEST_SUCCESS; -} - - static void my_free(const memcached_st *ptr, void *mem, void *context) { (void)context; @@ -1594,74 +1505,6 @@ test_return_t set_memory_alloc(memcached_st *memc) return TEST_SUCCESS; } -test_return_t enable_consistent_crc(memcached_st *memc) -{ - test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_CONSISTENT)); - test_compare(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION), uint64_t(MEMCACHED_DISTRIBUTION_CONSISTENT)); - - test_return_t rc; - if ((rc= pre_crc(memc)) != TEST_SUCCESS) - { - return rc; - } - - test_compare(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION), uint64_t(MEMCACHED_DISTRIBUTION_CONSISTENT)); - - if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH) != MEMCACHED_HASH_CRC) - { - return TEST_SKIPPED; - } - - return TEST_SUCCESS; -} - -test_return_t enable_consistent_hsieh(memcached_st *memc) -{ - test_return_t rc; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_CONSISTENT); - if ((rc= pre_hsieh(memc)) != TEST_SUCCESS) - { - return rc; - } - - test_compare(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION), uint64_t(MEMCACHED_DISTRIBUTION_CONSISTENT)); - - if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH) != MEMCACHED_HASH_HSIEH) - { - return TEST_SKIPPED; - } - - return TEST_SUCCESS; -} - -test_return_t enable_cas(memcached_st *memc) -{ - if (libmemcached_util_version_check(memc, 1, 2, 4)) - { - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, true); - - return TEST_SUCCESS; - } - - return TEST_SKIPPED; -} - -test_return_t check_for_1_2_3(memcached_st *memc) -{ - memcached_version(memc); - - const memcached_instance_st * instance= - memcached_server_instance_by_position(memc, 0); - - if ((instance->major_version >= 1 && (instance->minor_version == 2 && instance->micro_version >= 4)) - or instance->minor_version > 2) - { - return TEST_SUCCESS; - } - - return TEST_SKIPPED; -} - test_return_t MEMCACHED_BEHAVIOR_POLL_TIMEOUT_test(memcached_st *memc) { const uint64_t timeout= 100; // Not using, just checking that it sets diff --git a/tests/libmemcached-1.0/namespace.cc b/tests/libmemcached-1.0/namespace.cc deleted file mode 100644 index 29548b9e..00000000 --- a/tests/libmemcached-1.0/namespace.cc +++ /dev/null @@ -1,109 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached Client and Server - * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "mem_config.h" -#include "libtest/test.hpp" - -using namespace libtest; - -#include "libmemcached-1.0/memcached.h" - -#include "tests/namespace.h" - -test_return_t memcached_increment_namespace(memcached_st *memc) -{ - uint64_t new_number; - - test_compare(MEMCACHED_SUCCESS, - memcached_set(memc, - test_literal_param("number"), - test_literal_param("0"), - (time_t)0, (uint32_t)0)); - - test_compare(MEMCACHED_SUCCESS, - memcached_increment(memc, - test_literal_param("number"), - 1, &new_number)); - test_compare(uint64_t(1), new_number); - - test_compare(MEMCACHED_SUCCESS, - memcached_increment(memc, - test_literal_param("number"), - 1, &new_number)); - test_compare(uint64_t(2), new_number); - - memcached_st *clone= memcached_clone(NULL, memc); - - test_compare(MEMCACHED_SUCCESS, - memcached_callback_set(clone, MEMCACHED_CALLBACK_NAMESPACE, "all_your_bases")); - - test_compare(MEMCACHED_NOTFOUND, - memcached_increment(clone, - test_literal_param("number"), - 1, &new_number)); - - test_compare(MEMCACHED_SUCCESS, - memcached_add(clone, - test_literal_param("number"), - test_literal_param("10"), - (time_t)0, (uint32_t)0)); - - char *value= memcached_get(clone, - test_literal_param("number"), - 0, 0, 0); - test_true(value); - test_compare(2UL, strlen(value)); - test_strcmp("10", value); - free(value); - - test_compare(MEMCACHED_SUCCESS, - memcached_increment(clone, - test_literal_param("number"), - 1, &new_number)); - test_compare(uint64_t(11), new_number); - - test_compare(MEMCACHED_SUCCESS, - memcached_increment(memc, - test_literal_param("number"), - 1, &new_number)); - test_compare(uint64_t(3), new_number); - - memcached_free(clone); - - return TEST_SUCCESS; -} - diff --git a/tests/libmemcached-1.0/stat.cc b/tests/libmemcached-1.0/stat.cc deleted file mode 100644 index f65dea5f..00000000 --- a/tests/libmemcached-1.0/stat.cc +++ /dev/null @@ -1,102 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "mem_config.h" - -#include -#include - -#include "libtest/test.hpp" - -#include "libmemcached-1.0/memcached.h" -#include "libmemcachedutil-1.0/util.h" - -using namespace libtest; - -#include "tests/libmemcached-1.0/stat.h" - -static memcached_return_t item_counter(const memcached_instance_st * , - const char *key, size_t key_length, - const char *value, size_t, // value_length, - void *context) -{ - if ((key_length == (sizeof("curr_items") -1)) and (strncmp("curr_items", key, (sizeof("curr_items") -1)) == 0)) - { - uint64_t* counter= (uint64_t*)context; - unsigned long number_value= strtoul(value, (char **)NULL, 10); - ASSERT_NEQ(number_value, ULONG_MAX); - *counter= *counter +number_value; - } - - return MEMCACHED_SUCCESS; -} - -test_return_t memcached_stat_TEST(memcached_st *memc) -{ - uint64_t counter= 0; - test_compare(MEMCACHED_INVALID_ARGUMENTS, - memcached_stat_execute(memc, "BAD_ARG_VALUE", item_counter, &counter)); - - return TEST_SUCCESS; -} - -#define memcached_dump_TEST2_COUNT 64 -test_return_t memcached_stat_TEST2(memcached_st *memc) -{ - test_skip(false, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)); - - /* The dump test relies on there being at least 32 items in memcached */ - for (uint32_t x= 0; x < memcached_dump_TEST2_COUNT; x++) - { - char key[1024]; - int length= snprintf(key, sizeof(key), "%s%u", __func__, x); - - ASSERT_TRUE(length > 0); - - test_compare(MEMCACHED_SUCCESS, - memcached_set(memc, key, length, - NULL, 0, // Zero length values - time_t(0), uint32_t(0))); - } - memcached_quit(memc); - - uint64_t counter= 0; - ASSERT_EQ(MEMCACHED_SUCCESS, - memcached_stat_execute(memc, NULL, item_counter, &counter)); - ASSERT_TRUE(counter); - - return TEST_SUCCESS; -} diff --git a/tests/libmemcached-1.0/stat.h b/tests/libmemcached-1.0/stat.h deleted file mode 100644 index 3b85ba9c..00000000 --- a/tests/libmemcached-1.0/stat.h +++ /dev/null @@ -1,40 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -test_return_t memcached_stat_TEST(memcached_st *); -test_return_t memcached_stat_TEST2(memcached_st *);