From: Brian Aker Date: Sun, 27 May 2012 02:52:40 +0000 (-0400) Subject: Fix server messages (clean up errors in general). X-Git-Tag: 1.0.9~34^2~3 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=5c09a7ed2edbb9876493f30d59433331b63f6bfc;p=awesomized%2Flibmemcached Fix server messages (clean up errors in general). --- diff --git a/libmemcached-1.0/error.h b/libmemcached-1.0/error.h index 8b04e09b..81492597 100644 --- a/libmemcached-1.0/error.h +++ b/libmemcached-1.0/error.h @@ -42,22 +42,22 @@ extern "C" { #endif LIBMEMCACHED_API - const char *memcached_last_error_message(memcached_st *); + const char *memcached_last_error_message(const memcached_st *); LIBMEMCACHED_API void memcached_error_print(const memcached_st *); LIBMEMCACHED_API - memcached_return_t memcached_last_error(memcached_st *); + memcached_return_t memcached_last_error(const memcached_st *); LIBMEMCACHED_API - int memcached_last_error_errno(memcached_st *); + int memcached_last_error_errno(const memcached_st *); LIBMEMCACHED_API - const char *memcached_server_error(memcached_server_instance_st ptr); + const char *memcached_server_error(const memcached_server_instance_st ptr); LIBMEMCACHED_API - memcached_return_t memcached_server_error_return(memcached_server_instance_st ptr); + memcached_return_t memcached_server_error_return(const memcached_server_instance_st ptr); #ifdef __cplusplus } // extern "C" diff --git a/libmemcached-1.0/strerror.h b/libmemcached-1.0/strerror.h index 8e1e0fa2..16bf424a 100644 --- a/libmemcached-1.0/strerror.h +++ b/libmemcached-1.0/strerror.h @@ -2,7 +2,7 @@ * * Libmemcached library * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/ * Copyright (C) 2010 Brian Aker All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -43,7 +43,7 @@ extern "C" { #endif LIBMEMCACHED_API -const char *memcached_strerror(memcached_st *ptr, memcached_return_t rc); +const char *memcached_strerror(const memcached_st *ptr, memcached_return_t rc); #ifdef __cplusplus } diff --git a/libmemcached-1.0/struct/server.h b/libmemcached-1.0/struct/server.h index a1ed7389..b5bd1ca7 100644 --- a/libmemcached-1.0/struct/server.h +++ b/libmemcached-1.0/struct/server.h @@ -83,6 +83,7 @@ struct memcached_server_st { uint32_t read; uint32_t write; uint32_t timeouts; + size_t _bytes_read; } io_wait_count; uint8_t major_version; // Default definition of UINT8_MAX means that it has not been set. uint8_t micro_version; // ditto, and note that this is the third, not second version bit diff --git a/libmemcached/error.cc b/libmemcached/error.cc index b2af961a..96a5532b 100644 --- a/libmemcached/error.cc +++ b/libmemcached/error.cc @@ -52,7 +52,7 @@ struct memcached_error_t static void _set(memcached_server_st& server, memcached_st& memc) { - if (server.error_messages && server.error_messages->query_id != server.root->query_id) + if (server.error_messages and server.error_messages->query_id != server.root->query_id) { memcached_error_free(server); } @@ -240,6 +240,26 @@ memcached_return_t memcached_set_parser_error(memcached_st& memc, return memcached_set_error(memc, MEMCACHED_PARSE_ERROR, at, buffer, length); } +static inline size_t append_host_to_string(memcached_server_st& self, char* buffer, const size_t buffer_length) +{ + size_t size= 0; + switch (self.type) + { + case MEMCACHED_CONNECTION_TCP: + case MEMCACHED_CONNECTION_UDP: + size+= snprintf(buffer, buffer_length, " host: %s:%d", + self.hostname, int(self.port)); + break; + + case MEMCACHED_CONNECTION_UNIX_SOCKET: + size+= snprintf(buffer, buffer_length, " socket: %s", + self.hostname); + break; + } + + return size; +} + memcached_return_t memcached_set_error(memcached_server_st& self, memcached_return_t rc, const char *at, memcached_string_t& str) { assert_msg(rc != MEMCACHED_ERRNO, "Programmer error, MEMCACHED_ERRNO was set to be returned to client"); @@ -250,19 +270,17 @@ memcached_return_t memcached_set_error(memcached_server_st& self, memcached_retu } char hostname_port_message[MAX_ERROR_LENGTH]; - int size; + char* hostname_port_message_ptr= hostname_port_message; + int size= 0; if (str.size) { - size= snprintf(hostname_port_message, sizeof(hostname_port_message), "%.*s, host: %s:%d", - memcached_string_printf(str), - self.hostname, int(self.port)); - } - else - { - size= snprintf(hostname_port_message, sizeof(hostname_port_message), "host: %s:%d", - self.hostname, int(self.port)); + size= snprintf(hostname_port_message_ptr, sizeof(hostname_port_message), "%.*s, ", + memcached_string_printf(str)); + hostname_port_message_ptr+= size; } + size+= append_host_to_string(self, hostname_port_message_ptr, sizeof(hostname_port_message) -size); + memcached_string_t error_host= { hostname_port_message, size }; assert(self.root); @@ -288,7 +306,7 @@ memcached_return_t memcached_set_error(memcached_server_st& self, memcached_retu } char hostname_port[NI_MAXHOST +NI_MAXSERV + sizeof("host : ")]; - int size= snprintf(hostname_port, sizeof(hostname_port), "host: %s:%d", self.hostname, int(self.port)); + size_t size= append_host_to_string(self, hostname_port, sizeof(hostname_port)); memcached_string_t error_host= { hostname_port, size}; @@ -362,18 +380,13 @@ memcached_return_t memcached_set_errno(memcached_server_st& self, int local_errn } char hostname_port_message[MAX_ERROR_LENGTH]; - int size; + char* hostname_port_message_ptr= hostname_port_message; + size_t size= 0; if (str.size) { - size= snprintf(hostname_port_message, sizeof(hostname_port_message), "%.*s, host: %s:%d", - memcached_string_printf(str), - self.hostname, int(self.port)); - } - else - { - size= snprintf(hostname_port_message, sizeof(hostname_port_message), "host: %s:%d", - self.hostname, int(self.port)); + size= snprintf(hostname_port_message_ptr, sizeof(hostname_port_message), "%.*s, ", memcached_string_printf(str)); } + size+= append_host_to_string(self, hostname_port_message_ptr, sizeof(hostname_port_message) -size); memcached_string_t error_host= { hostname_port_message, size }; @@ -397,8 +410,7 @@ memcached_return_t memcached_set_errno(memcached_server_st& self, int local_errn } char hostname_port_message[MAX_ERROR_LENGTH]; - int size = snprintf(hostname_port_message, sizeof(hostname_port_message), "host: %s:%d", - self.hostname, int(self.port)); + size_t size= append_host_to_string(self, hostname_port_message, sizeof(hostname_port_message)); memcached_string_t error_host= { hostname_port_message, size }; @@ -481,7 +493,7 @@ void memcached_error_free(memcached_server_st& self) self.error_messages= NULL; } -const char *memcached_last_error_message(memcached_st *memc) +const char *memcached_last_error_message(const memcached_st *memc) { if (memc == NULL) { @@ -518,7 +530,7 @@ bool memcached_has_current_error(memcached_server_st& server) return memcached_has_current_error(*(server.root)); } -memcached_return_t memcached_last_error(memcached_st *memc) +memcached_return_t memcached_last_error(const memcached_st *memc) { if (memc == NULL) { @@ -533,7 +545,7 @@ memcached_return_t memcached_last_error(memcached_st *memc) return memc->error_messages->rc; } -int memcached_last_error_errno(memcached_st *memc) +int memcached_last_error_errno(const memcached_st *memc) { if (memc == NULL) { @@ -548,7 +560,7 @@ int memcached_last_error_errno(memcached_st *memc) return memc->error_messages->local_errno; } -const char *memcached_server_error(memcached_server_instance_st server) +const char *memcached_server_error(const memcached_server_instance_st server) { if (server == NULL) { diff --git a/libmemcached/io.cc b/libmemcached/io.cc index ed33f05a..77db241e 100644 --- a/libmemcached/io.cc +++ b/libmemcached/io.cc @@ -450,15 +450,15 @@ memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr, for blocking I/O we do not return 0 and for non-blocking case it will return EGAIN if data is not immediatly available. */ - WATCHPOINT_STRING("We had a zero length recv()"); memcached_quit_server(ptr, true); nread= -1; return memcached_set_error(*ptr, MEMCACHED_CONNECTION_FAILURE, MEMCACHED_AT, memcached_literal_param("::rec() returned zero, server has disconnected")); } + ptr->io_wait_count._bytes_read+= data_read; } while (data_read <= 0); - ptr->io_bytes_sent = 0; + ptr->io_bytes_sent= 0; ptr->read_data_length= (size_t) data_read; ptr->read_buffer_length= (size_t) data_read; ptr->read_ptr= ptr->read_buffer; diff --git a/libmemcached/server.cc b/libmemcached/server.cc index f2f78211..8aba7576 100644 --- a/libmemcached/server.cc +++ b/libmemcached/server.cc @@ -58,6 +58,7 @@ static inline void _server_init(memcached_server_st *self, memcached_st *root, self->io_wait_count.read= 0; self->io_wait_count.write= 0; self->io_wait_count.timeouts= 0; + self->io_wait_count._bytes_read= 0; self->major_version= UINT8_MAX; self->micro_version= UINT8_MAX; self->minor_version= UINT8_MAX; @@ -352,7 +353,9 @@ in_port_t memcached_server_port(const memcached_server_instance_st self) { WATCHPOINT_ASSERT(self); if (self == NULL) + { return 0; + } return self->port; } @@ -361,7 +364,9 @@ uint32_t memcached_server_response_count(const memcached_server_instance_st self { WATCHPOINT_ASSERT(self); if (self == NULL) + { return 0; + } return self->cursor_active; } diff --git a/libmemcached/strerror.cc b/libmemcached/strerror.cc index 7cd2ff2f..7a4e0a82 100644 --- a/libmemcached/strerror.cc +++ b/libmemcached/strerror.cc @@ -37,7 +37,7 @@ #include -const char *memcached_strerror(memcached_st *, memcached_return_t rc) +const char *memcached_strerror(const memcached_st *, memcached_return_t rc) { switch (rc) { diff --git a/libmemcachedutil-1.0/ostream.hpp b/libmemcachedutil-1.0/ostream.hpp index 41134140..cce7bfcd 100644 --- a/libmemcachedutil-1.0/ostream.hpp +++ b/libmemcachedutil-1.0/ostream.hpp @@ -41,3 +41,10 @@ static inline std::ostream& operator<<(std::ostream& output, const enum memcache output << memcached_strerror(NULL, arg); return output; } + +static inline std::ostream& operator<<(std::ostream& output, const memcached_st &arg) +{ + output << " query_id: " << memcached_query_id(&arg); + output << " error: " << memcached_last_error_message(&arg); + return output; +} diff --git a/libtest/collection.cc b/libtest/collection.cc index 5814c2f4..1de74ade 100644 --- a/libtest/collection.cc +++ b/libtest/collection.cc @@ -121,6 +121,7 @@ test_return_t Collection::exec() catch (libtest::fatal &e) { Error << "Fatal exception was thrown: " << e.what(); + stream::cerr(__FILE__, __LINE__, __func__) << e.what(); _failed++; throw; } diff --git a/libtest/fatal.cc b/libtest/fatal.cc index a4355920..288d53a4 100644 --- a/libtest/fatal.cc +++ b/libtest/fatal.cc @@ -54,7 +54,7 @@ fatal::fatal(const char *file_arg, int line_arg, const char *func_arg, const cha strncpy(_mesg, last_error, sizeof(_mesg)); - snprintf(_error_message, sizeof(_error_message), "%s:%d FATAL:%s (%s)", _file, int(_line), last_error, _func); + snprintf(_error_message, sizeof(_error_message), "%s:%d FATAL:%s (%s)", _file, _line, last_error, _func); } static bool _disabled= false; @@ -85,9 +85,14 @@ void fatal::increment_disabled_counter() _counter++; } -disconnected::disconnected(const char *file, int line, const char *func, const char *instance, const in_port_t port, const char *format, ...) : +disconnected::disconnected(const char *file_arg, int line_arg, const char *func_arg, + const char *instance, const in_port_t port, + const char *format, ...) : + std::runtime_error(func_arg), _port(port), - std::runtime_error(func) + _line(line_arg), + _file(file_arg), + _func(func_arg) { strncpy(_instance, instance, sizeof(_instance)); va_list args; @@ -96,7 +101,7 @@ disconnected::disconnected(const char *file, int line, const char *func, const c (void)vsnprintf(last_error, sizeof(last_error), format, args); va_end(args); - snprintf(_error_message, sizeof(_error_message), "%s:%d FATAL:%s (%s)", file, int(line), last_error, func); + snprintf(_error_message, sizeof(_error_message), "%s:%d FATAL:%s (%s)", _file, _line, last_error, _func); } } // namespace libtest diff --git a/libtest/fatal.hpp b/libtest/fatal.hpp index 54f672b6..f0ee0813 100644 --- a/libtest/fatal.hpp +++ b/libtest/fatal.hpp @@ -108,10 +108,28 @@ public: static uint32_t disabled_counter(); static void increment_disabled_counter(); + int line() + { + return _line; + } + + const char* file() + { + return _file; + } + + const char* func() + { + return _func; + } + private: char _error_message[BUFSIZ]; in_port_t _port; char _instance[1024]; + int _line; + const char* _file; + const char* _func; }; diff --git a/libtest/has.cc b/libtest/has.cc index 17427d41..7cc93370 100644 --- a/libtest/has.cc +++ b/libtest/has.cc @@ -117,17 +117,19 @@ bool has_memcached() { std::stringstream arg_buffer; - if (getenv("PWD")) + if (getenv("PWD") and strcmp(MEMCACHED_BINARY, "memcached/memcached") == 0) { arg_buffer << getenv("PWD"); arg_buffer << "/"; } arg_buffer << MEMCACHED_BINARY; + std::cout << "Value: " << arg_buffer.str() << std::endl; if (access(arg_buffer.str().c_str(), X_OK) == 0) { return true; } + std::cout << "Access was not 0 : " << strerror(errno) << std::endl; } return false; diff --git a/libtest/main.cc b/libtest/main.cc index 0c876286..6597f84b 100644 --- a/libtest/main.cc +++ b/libtest/main.cc @@ -250,7 +250,6 @@ int main(int argc, char *argv[]) break; case TEST_SKIPPED: - Out << "SKIP " << argv[0]; return EXIT_SKIP; case TEST_FAILURE: diff --git a/libtest/test.h b/libtest/test.h index 117e59ce..42443d9a 100644 --- a/libtest/test.h +++ b/libtest/test.h @@ -196,7 +196,7 @@ do \ #define test_compare_got(__expected, __actual, __hint) \ do \ { \ - if (not libtest::_compare_hint(__FILE__, __LINE__, __func__, (__expected), (__actual), (__hint))) \ + if (libtest::_compare_hint(__FILE__, __LINE__, __func__, (__expected), (__actual), (__hint)) == false) \ { \ libtest::create_core(); \ return TEST_FAILURE; \ diff --git a/tests/libmemcached-1.0/all_tests.h b/tests/libmemcached-1.0/all_tests.h index f5ca5927..92db0b8b 100644 --- a/tests/libmemcached-1.0/all_tests.h +++ b/tests/libmemcached-1.0/all_tests.h @@ -37,7 +37,7 @@ #pragma once -#include +#include "tests/libmemcached-1.0/memcached_get.h" /* Clean the server before beginning testing */ @@ -58,6 +58,7 @@ test_st tests[] ={ {"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 }, + {"memcached_add(SUCCESS)", true, (test_callback_fn*)memcached_add_SUCCESS_TEST }, {"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 }, @@ -148,7 +149,7 @@ test_st behavior_tests[] ={ }; test_st libmemcachedutil_tests[] ={ - {"libmemcached_util_ping()", true, (test_callback_fn*)ping_test }, + {"libmemcached_util_ping()", true, (test_callback_fn*)libmemcached_util_ping_TEST }, {"libmemcached_util_getpid()", true, (test_callback_fn*)getpid_test }, {"libmemcached_util_getpid(MEMCACHED_CONNECTION_FAILURE)", true, (test_callback_fn*)getpid_connection_failure_test }, {0, 0, 0} diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index cb4666c3..83ea1317 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -800,27 +800,55 @@ test_return_t prepend_test(memcached_st *memc) return TEST_SUCCESS; } +/* + Set the value, then quit to make sure it is flushed. + Come back in and test that add fails. +*/ +test_return_t memcached_add_SUCCESS_TEST(memcached_st *memc) +{ + memcached_return_t rc; + test_null(memcached_get(memc, test_literal_param(__func__), NULL, NULL, &rc)); + test_compare(MEMCACHED_NOTFOUND, rc); + + test_compare(MEMCACHED_SUCCESS, + memcached_add(memc, + test_literal_param(__func__), + test_literal_param("try something else"), + time_t(0), uint32_t(0))); + + return TEST_SUCCESS; +} + /* Set the value, then quit to make sure it is flushed. Come back in and test that add fails. */ test_return_t add_test(memcached_st *memc) { - 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)); + 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))); memcached_quit(memc); - 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)); + size_t value_length; + uint32_t flags; + memcached_return_t rc; + char *check_value= memcached_get(memc, + test_literal_param(__func__), + &value_length, &flags, &rc); + test_memcmp(check_value, "when we sanitize", strlen("when we sanitize")); + test_compare(test_literal_param_size("when we sanitize"), value_length); + test_compare(MEMCACHED_SUCCESS, rc); + free(check_value); + + test_compare(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))); return TEST_SUCCESS; } @@ -843,44 +871,42 @@ test_return_t add_wrapper(memcached_st *memc) #endif for (uint32_t x= 0; x < max; x++) + { add_test(memc); + } return TEST_SUCCESS; } test_return_t replace_test(memcached_st *memc) { - 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)); + 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_hint(MEMCACHED_SUCCESS, - memcached_replace(memc, - test_literal_param(__func__), - test_literal_param("first we insert some data"), - time_t(0), uint32_t(0)), - memcached_last_error_message(memc)); + test_compare(MEMCACHED_SUCCESS, + memcached_replace(memc, + test_literal_param(__func__), + test_literal_param("first we insert some data"), + time_t(0), uint32_t(0))); return TEST_SUCCESS; } test_return_t delete_test(memcached_st *memc) { - 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)); + 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_hint(return_value_based_on_buffering(memc), - memcached_delete(memc, - test_literal_param(__func__), - time_t(0)), - memcached_last_error_message(memc)); + test_compare(return_value_based_on_buffering(memc), + memcached_delete(memc, + test_literal_param(__func__), + time_t(0))); return TEST_SUCCESS; } @@ -1084,12 +1110,11 @@ test_return_t set_test2(memcached_st *memc) { for (uint32_t x= 0; x < 10; x++) { - test_compare_hint(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)), - memcached_last_error_message(memc)); + 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; @@ -1114,11 +1139,10 @@ test_return_t set_test3(memcached_st *memc) snprintf(key, sizeof(key), "foo%u", x); uint64_t query_id= memcached_query_id(memc); - 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(return_value_based_on_buffering(memc), + memcached_set(memc, key, strlen(key), + &value[0], value.size(), + time_t(0), uint32_t(0))); test_compare(query_id +1, memcached_query_id(memc)); } @@ -1264,6 +1288,7 @@ test_return_t decrement_test(memcached_st *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)); @@ -1444,20 +1469,18 @@ test_return_t quit_test(memcached_st *memc) { const char *value= "sanford and sun"; - test_compare_hint(return_value_based_on_buffering(memc), - memcached_set(memc, - test_literal_param(__func__), - value, strlen(value), - (time_t)10, (uint32_t)3), - memcached_last_error_message(memc)); + 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); - test_compare_hint(return_value_based_on_buffering(memc), - memcached_set(memc, - test_literal_param(__func__), - value, strlen(value), - (time_t)50, (uint32_t)9), - memcached_last_error_message(memc)); + 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; } @@ -1468,9 +1491,7 @@ test_return_t mget_result_test(memcached_st *memc) size_t key_length[]= {5, 3, 4}; memcached_result_st results_obj; - memcached_result_st *results; - - results= memcached_result_create(memc, &results_obj); + memcached_result_st *results= memcached_result_create(memc, &results_obj); test_true(results); test_true(&results_obj == results); @@ -2204,10 +2225,9 @@ test_return_t user_supplied_bug7(memcached_st *memc) 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)); + test_compare(MEMCACHED_SUCCESS, memcached_set(memc, keys, key_length, + insert_data, VALUE_SIZE_BUG5, + time_t(0), 245U)); memcached_return_t rc; size_t value_length; @@ -2541,7 +2561,7 @@ test_return_t user_supplied_bug17(memcached_st *memc) char *value2= memcached_get(memc, key, strlen(key), &length, &flags, &rc); - test_true(length==strlen(value)); + test_compare(length, strlen(value)); test_compare(MEMCACHED_SUCCESS, rc); test_memcmp(value, value2, length); free(value2); @@ -3393,20 +3413,32 @@ test_return_t getpid_test(memcached_st *memc) return TEST_SUCCESS; } -test_return_t ping_test(memcached_st *memc) +static memcached_return_t ping_each_server(const memcached_st*, + const memcached_server_st *instance, + void*) { + // Test both the version that returns a code, and the one that does not. memcached_return_t rc; - memcached_server_instance_st instance= - memcached_server_instance_by_position(memc, 0); + if (libmemcached_util_ping(memcached_server_name(instance), + memcached_server_port(instance), &rc) == false) + { + throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "%s:%d %s", memcached_server_name(instance), + memcached_server_port(instance), memcached_strerror(NULL, rc)); + } - // Test both the version that returns a code, and the one that does not. - test_true(libmemcached_util_ping(memcached_server_name(instance), - memcached_server_port(instance), NULL)); + if (libmemcached_util_ping(memcached_server_name(instance), + memcached_server_port(instance), NULL) == false) + { + throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "%s:%d", memcached_server_name(instance), memcached_server_port(instance)); + } - test_true(libmemcached_util_ping(memcached_server_name(instance), - memcached_server_port(instance), &rc)); + return MEMCACHED_SUCCESS; +} - test_compare(MEMCACHED_SUCCESS, rc); +test_return_t libmemcached_util_ping_TEST(memcached_st *memc) +{ + memcached_server_fn callbacks[1]= { ping_each_server }; + memcached_server_cursor(memc, callbacks, NULL, 1); return TEST_SUCCESS; } diff --git a/tests/libmemcached-1.0/mem_functions.h b/tests/libmemcached-1.0/mem_functions.h index 4dca710b..b037b86e 100644 --- a/tests/libmemcached-1.0/mem_functions.h +++ b/tests/libmemcached-1.0/mem_functions.h @@ -44,6 +44,7 @@ test_return_t MEMCACHED_BEHAVIOR_TCP_KEEPIDLE_test(memcached_st *memc); test_return_t _user_supplied_bug21(memcached_st* memc, size_t key_count); test_return_t add_host_test(memcached_st *memc); test_return_t add_host_test1(memcached_st *memc); +test_return_t memcached_add_SUCCESS_TEST(memcached_st*); test_return_t add_test(memcached_st *memc); test_return_t add_wrapper(memcached_st *memc); test_return_t allocation_test(memcached_st *not_used); @@ -116,7 +117,7 @@ test_return_t murmur_run (memcached_st *); test_return_t noreply_test(memcached_st *memc); test_return_t one_at_a_time_run (memcached_st *); test_return_t output_ketama_weighted_keys(memcached_st *); -test_return_t ping_test(memcached_st *memc); +test_return_t libmemcached_util_ping_TEST(memcached_st*); test_return_t prepend_test(memcached_st *memc); test_return_t quit_test(memcached_st *memc); test_return_t read_through(memcached_st *memc); diff --git a/tests/libmemcached-1.0/memcached_get.cc b/tests/libmemcached-1.0/memcached_get.cc index 2636ecdb..1a6e2a70 100644 --- a/tests/libmemcached-1.0/memcached_get.cc +++ b/tests/libmemcached-1.0/memcached_get.cc @@ -189,11 +189,10 @@ test_return_t get_test5(memcached_st *memc) uint32_t flags; size_t rlen; - test_compare_hint(return_value_based_on_buffering(memc), + test_compare(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)); + time_t(0), uint32_t(0))); test_compare(MEMCACHED_SUCCESS, memcached_mget(memc, keys, lengths, test_array_length(keys))); memcached_result_st results_obj;