From 376136a8d95d1942dcdcbf680838750532d20622 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Tue, 7 Feb 2012 23:03:49 -0800 Subject: [PATCH] Adding UUID to generate keys for new test (which tests the removal of the dummy call which is no longer needed in mget()). --- configure.ac | 8 +++ libmemcached/get.cc | 11 --- libtest/string.hpp | 4 ++ tests/libmemcached-1.0/include.am | 1 + tests/libmemcached-1.0/mem_functions.cc | 89 ++++++++++++++++++++++++- 5 files changed, 100 insertions(+), 13 deletions(-) diff --git a/configure.ac b/configure.ac index c13d23cb..d7b45a32 100644 --- a/configure.ac +++ b/configure.ac @@ -166,6 +166,14 @@ AC_C_RESTRICT AX_CXX_GCC_ABI_DEMANGLE +AX_CHECK_LIBRARY([LIBUUID], [uuid/uuid.h], [uuid], + [ + LIBUUID_LDFLAGS="-luuid" + ], + [ + AC_DEFINE([HAVE_LIBUUID], [ 0 ], [Have libuuid]) + ]) + AC_CHECK_LIB([rt], [clock_gettime], [ RT_LIB="-lrt" diff --git a/libmemcached/get.cc b/libmemcached/get.cc index 9ed7296f..1deb3976 100644 --- a/libmemcached/get.cc +++ b/libmemcached/get.cc @@ -168,17 +168,6 @@ char *memcached_get_by_key(memcached_st *ptr, return NULL; } - size_t dummy_length; - uint32_t dummy_flags; - memcached_return_t dummy_error; - - char *dummy_value= memcached_fetch(ptr, NULL, NULL, - &dummy_length, &dummy_flags, - &dummy_error); - assert_msg(dummy_value == 0, "memcached_fetch() returned additional values beyond the single get it expected"); - assert_msg(dummy_length == 0, "memcached_fetch() returned additional values beyond the single get it expected"); - assert_msg(ptr->query_id == query_id +1, "Programmer error, the query_id was not incremented."); - return value; } diff --git a/libtest/string.hpp b/libtest/string.hpp index c79fef26..608572c6 100644 --- a/libtest/string.hpp +++ b/libtest/string.hpp @@ -29,3 +29,7 @@ #define test_literal_param_size util_literal_param_size #define test_string_make_from_cstr util_string_make_from_cstr #define test_array_length util_array_length + +namespace libtest { +typedef std::vector vchar_t; +} diff --git a/tests/libmemcached-1.0/include.am b/tests/libmemcached-1.0/include.am index 373fc6e7..f23bc1d0 100644 --- a/tests/libmemcached-1.0/include.am +++ b/tests/libmemcached-1.0/include.am @@ -73,6 +73,7 @@ tests_libmemcached_1_0_testapp_DEPENDENCIES= \ libmemcached/libmemcachedutil.la tests_libmemcached_1_0_testapp_LDADD= \ + $(LIBUUID_LDFLAGS) \ ${PTHREAD_LIBS} \ libmemcached/libmemcached.la \ libmemcached/libmemcachedutil.la \ diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index dfd7d21e..bbd359db 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 */ @@ -611,6 +615,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) +{ + test_skip(true, HAVE_LIBUUID); + + std::vector key_lengths; + key_lengths.resize(200); + std::vector keys; + keys.resize(key_lengths.size()); + + for (size_t x= 0; x < keys.size(); x++) + { + if (HAVE_LIBUUID) + { + uuid_t out; + uuid_generate(out); + char uuid_string[37]; + + uuid_unparse(out, uuid_string); + uuid_string[36]= 0; + keys[x]= strdup(uuid_string); + key_lengths[x]= 36; + } + } + + for (libtest::vchar_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[0], &key_lengths[0], 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[which_key], 36, + &value_length, &flags, &rc); + test_compare(MEMCACHED_SUCCESS, rc); + test_null(out_value); + test_zero(value_length); + test_zero(flags); + } + } + + for (libtest::vchar_t::iterator iter= keys.begin(); + iter != keys.end(); + iter++) + { + free(*iter); + } + + return TEST_SUCCESS; +} + static test_return_t cas2_test(memcached_st *memc) { const char *keys[]= {"fudge", "son", "food"}; @@ -4002,6 +4084,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) { @@ -4011,6 +4094,7 @@ static test_return_t noreply_test(memcached_st *memc) } test_true(no_msg == 0); +#endif test_compare(MEMCACHED_SUCCESS, memcached_flush_buffers(memc)); /* @@ -5618,7 +5702,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 }, @@ -5630,7 +5714,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 }, -- 2.30.2