Merge build trunk.
authorBrian Aker <brian@tangent.org>
Thu, 26 Jan 2012 07:13:53 +0000 (23:13 -0800)
committerBrian Aker <brian@tangent.org>
Thu, 26 Jan 2012 07:13:53 +0000 (23:13 -0800)
28 files changed:
libmemcached-1.0/return.h
libmemcached-1.0/types/return.h
libmemcached/auto.cc
libmemcached/common.h
libmemcached/connect.cc
libmemcached/connect.hpp
libmemcached/delete.cc
libmemcached/do.cc
libmemcached/dump.cc
libmemcached/error.cc
libmemcached/exist.cc
libmemcached/get.cc
libmemcached/io.cc
libmemcached/key.cc
libmemcached/namespace.cc
libmemcached/response.cc
libmemcached/server.cc
libmemcached/stats.cc
libmemcached/strerror.cc
libmemcached/string.cc
tests/libmemcached-1.0/dump.cc
tests/libmemcached-1.0/dump.h
tests/libmemcached-1.0/exist.cc
tests/libmemcached-1.0/include.am
tests/libmemcached-1.0/mem_functions.cc
tests/libmemcached-1.0/stat.cc [new file with mode: 0644]
tests/libmemcached-1.0/stat.h [new file with mode: 0644]
tests/libmemcached-1.0/touch.cc

index 28b4a97d3f121adc6873f58a76a691e42ff6a585..65dc63af5eb02cb7783200287f9cb5316dc06a86 100644 (file)
@@ -61,12 +61,20 @@ static inline bool memcached_failed(memcached_return_t rc)
 
 static inline bool memcached_fatal(memcached_return_t rc)
 {
-  return (rc != MEMCACHED_SUCCESS && 
+  return (
+          rc != MEMCACHED_BUFFERED &&
+          rc != MEMCACHED_DATA_EXISTS &&
+          rc != MEMCACHED_DELETED &&
+          rc != MEMCACHED_E2BIG && 
           rc != MEMCACHED_END && 
-          rc != MEMCACHED_STORED && 
+          rc != MEMCACHED_ITEM &&
+          rc != MEMCACHED_ERROR &&
+          rc != MEMCACHED_NOTFOUND && 
+          rc != MEMCACHED_NOTSTORED && 
+          rc != MEMCACHED_SERVER_MEMORY_ALLOCATION_FAILURE && 
           rc != MEMCACHED_STAT && 
-          rc != MEMCACHED_DELETED &&
-          rc != MEMCACHED_BUFFERED &&
+          rc != MEMCACHED_STORED && 
+          rc != MEMCACHED_SUCCESS && 
           rc != MEMCACHED_VALUE);
 }
 
index e57442e4079bc6b3b6f3b7d31a01cb2c020f6b08..f4ec9b088a8460804e4b440035574feb0d35231f 100644 (file)
@@ -47,8 +47,8 @@ enum memcached_return_t {
   MEMCACHED_UNKNOWN_READ_FAILURE,
   MEMCACHED_PROTOCOL_ERROR,
   MEMCACHED_CLIENT_ERROR,
-  MEMCACHED_SERVER_ERROR,
-  MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE, // DEPRECATED
+  MEMCACHED_SERVER_ERROR, // Server returns "SERVER_ERROR"
+  MEMCACHED_ERROR, // Server returns "ERROR"
   MEMCACHED_DATA_EXISTS,
   MEMCACHED_DATA_DOES_NOT_EXIST,
   MEMCACHED_NOTSTORED,
@@ -86,7 +86,8 @@ enum memcached_return_t {
   MEMCACHED_IN_PROGRESS,
   MEMCACHED_SERVER_TEMPORARILY_DISABLED,
   MEMCACHED_SERVER_MEMORY_ALLOCATION_FAILURE,
-  MEMCACHED_MAXIMUM_RETURN /* Always add new error code before */
+  MEMCACHED_MAXIMUM_RETURN, /* Always add new error code before */
+  MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE= MEMCACHED_ERROR
 };
 
 #ifndef __cplusplus
index e5054a0a6513cd6cbe1518c34828b38281d79adc..c64ccda45067d79983f9ceae6e72df5804826822 100644 (file)
@@ -179,7 +179,7 @@ memcached_return_t memcached_increment_by_key(memcached_st *ptr,
 
   if (memcached_failed(rc= memcached_key_test(*ptr, (const char **)&key, &key_length, 1)))
   {
-    return memcached_set_error(*ptr, rc, MEMCACHED_AT);
+    return rc;
   }
 
   uint32_t server_key= memcached_generate_hash_with_redistribution(ptr, group_key, group_key_length);
@@ -226,7 +226,7 @@ memcached_return_t memcached_decrement_by_key(memcached_st *ptr,
 
   if (memcached_failed(rc= memcached_key_test(*ptr, (const char **)&key, &key_length, 1)))
   {
-    return memcached_set_error(*ptr, rc, MEMCACHED_AT);
+    return rc;
   }
 
 
@@ -291,7 +291,7 @@ memcached_return_t memcached_increment_with_initial_by_key(memcached_st *ptr,
 
   if (memcached_failed(rc= memcached_key_test(*ptr, (const char **)&key, &key_length, 1)))
   {
-    return memcached_set_error(*ptr, rc, MEMCACHED_AT);
+    return rc;
   }
 
   uint32_t server_key= memcached_generate_hash_with_redistribution(ptr, group_key, group_key_length);
@@ -356,7 +356,7 @@ memcached_return_t memcached_decrement_with_initial_by_key(memcached_st *ptr,
 
   if (memcached_failed(rc= memcached_key_test(*ptr, (const char **)&key, &key_length, 1)))
   {
-    return memcached_set_error(*ptr, rc, MEMCACHED_AT);
+    return rc;
   }
 
   uint32_t server_key= memcached_generate_hash_with_redistribution(ptr, group_key, group_key_length);
index 0f33a784c42b0b8f87d23e59613cb53676dfff3b..53481880d7cc5281b414c57016a060d7fe236c57 100644 (file)
@@ -158,9 +158,6 @@ memcached_return_t memcached_server_execute(memcached_st *ptr,
 extern "C" {
 #endif
 
-LIBMEMCACHED_LOCAL
-memcached_return_t memcached_connect(memcached_server_write_instance_st ptr);
-
 LIBMEMCACHED_LOCAL
 memcached_return_t run_distribution(memcached_st *ptr);
 
index 42cbe9bc9f502f224237ca3da09d9b336b96bafa..1c7da46547ad910aaf44d18d8e7373f6b0d08221 100644 (file)
@@ -129,8 +129,9 @@ static memcached_return_t connect_poll(memcached_server_st *server)
   return memcached_set_errno(*server, get_socket_errno(), MEMCACHED_AT);
 }
 
-memcached_return_t set_hostinfo(memcached_server_st *server)
+static memcached_return_t set_hostinfo(memcached_server_st *server)
 {
+  assert(server->type != MEMCACHED_CONNECTION_UNIX_SOCKET);
   if (server->address_info)
   {
     freeaddrinfo(server->address_info);
@@ -619,7 +620,7 @@ static memcached_return_t backoff_handling(memcached_server_write_instance_st se
   return MEMCACHED_SUCCESS;
 }
 
-memcached_return_t memcached_connect(memcached_server_write_instance_st server)
+static memcached_return_t _memcached_connect(memcached_server_write_instance_st server, const bool set_last_disconnected)
 {
   if (server->fd != INVALID_SOCKET)
   {
@@ -641,6 +642,11 @@ memcached_return_t memcached_connect(memcached_server_write_instance_st server)
     return memcached_set_error(*server, MEMCACHED_INVALID_HOST_PROTOCOL, MEMCACHED_AT, memcached_literal_param("SASL is not supported for UDP connections"));
   }
 
+  if (server->hostname[0] == '/')
+  {
+    server->type= MEMCACHED_CONNECTION_UNIX_SOCKET;
+  }
+
   /* We need to clean up the multi startup piece */
   switch (server->type)
   {
@@ -673,25 +679,39 @@ memcached_return_t memcached_connect(memcached_server_write_instance_st server)
     memcached_mark_server_as_clean(server);
     return rc;
   }
-
-  set_last_disconnected_host(server);
-  if (memcached_has_current_error(*server))
+  else if (set_last_disconnected)
   {
-    memcached_mark_server_for_timeout(server);
-    assert(memcached_failed(memcached_server_error_return(server)));
-  }
-  else
-  {
-    memcached_set_error(*server, rc, MEMCACHED_AT);
-    memcached_mark_server_for_timeout(server);
-  }
+    set_last_disconnected_host(server);
+    if (memcached_has_current_error(*server))
+    {
+      memcached_mark_server_for_timeout(server);
+      assert(memcached_failed(memcached_server_error_return(server)));
+    }
+    else
+    {
+      memcached_set_error(*server, rc, MEMCACHED_AT);
+      memcached_mark_server_for_timeout(server);
+    }
 
-  LIBMEMCACHED_MEMCACHED_CONNECT_END();
+    LIBMEMCACHED_MEMCACHED_CONNECT_END();
 
-  if (in_timeout)
-  {
-    return memcached_set_error(*server, MEMCACHED_SERVER_TEMPORARILY_DISABLED, MEMCACHED_AT);
+    if (in_timeout)
+    {
+      char buffer[1024];
+      int snprintf_length= snprintf(buffer, sizeof(buffer), "%s:%d", server->hostname, int(server->port));
+      return memcached_set_error(*server, MEMCACHED_SERVER_TEMPORARILY_DISABLED, MEMCACHED_AT, buffer, snprintf_length);
+    }
   }
 
   return rc;
 }
+
+memcached_return_t memcached_connect_try(memcached_server_write_instance_st server)
+{
+  return _memcached_connect(server, false);
+}
+
+memcached_return_t memcached_connect(memcached_server_write_instance_st server)
+{
+  return _memcached_connect(server, true);
+}
index 78ed7960f5e031c5e4cf22c988dad7b60653c315..a37dbd76aaeb4502c8a9fc41ee36a8fed08a0194 100644 (file)
@@ -37,4 +37,6 @@
 
 #pragma once
 
-memcached_return_t set_hostinfo(memcached_server_st *server);
+memcached_return_t memcached_connect_try(memcached_server_write_instance_st ptr);
+memcached_return_t memcached_connect(memcached_server_write_instance_st ptr);
+
index 660a903cd05d6ae6cba6b3468bca7c43ecb0bc30..1ffdbfac336dd0b0438a0d47fa3b29fdcaae9a74 100644 (file)
@@ -146,7 +146,7 @@ memcached_return_t memcached_delete_by_key(memcached_st *ptr,
 
   if (memcached_failed(rc= memcached_key_test(*ptr, (const char **)&key, &key_length, 1)))
   {
-    return memcached_set_error(*ptr, rc, MEMCACHED_AT);
+    return rc;
   }
 
   if (expiration)
index 3c3519c27b9cccb29df440a9e4719735bb3be424..ed66028c3eb2b5458e60adce77ef69630a918e6b 100644 (file)
@@ -50,9 +50,24 @@ memcached_return_t memcached_vdo(memcached_server_write_instance_st instance,
     msg.msg_iov= (struct iovec*)vector;
     msg.msg_iovlen= count;
 
-    if (::sendmsg(instance->fd, &msg, 0) < 1)
+    uint32_t retry= 5;
+    while (--retry)
     {
-      return memcached_set_error(*instance, MEMCACHED_WRITE_FAILURE, MEMCACHED_AT);
+      ssize_t sendmsg_length= ::sendmsg(instance->fd, &msg, 0);
+      if (sendmsg_length > 0)
+      {
+        break;
+      }
+      else if (sendmsg_length < 0)
+      {
+        if (errno == EMSGSIZE)
+        {
+          return memcached_set_error(*instance, MEMCACHED_WRITE_FAILURE, MEMCACHED_AT);
+        }
+
+        perror(__func__);
+        return memcached_set_errno(*instance, errno, MEMCACHED_AT);
+      }
     }
 
     return MEMCACHED_SUCCESS;
index b46ca1795d9f07a2df13b924a236488b7aa7d201..5ba4ce1624c185c6b8e5b8c858fa498c84d512b5 100644 (file)
 
 #include <libmemcached/common.h>
 
-static memcached_return_t ascii_dump(memcached_st *ptr, memcached_dump_fn *callback, void *context, uint32_t number_of_callbacks)
+static memcached_return_t ascii_dump(memcached_st *memc, memcached_dump_fn *callback, void *context, uint32_t number_of_callbacks)
 {
-  memcached_return_t rc= MEMCACHED_SUCCESS;
-
-  for (uint32_t server_key= 0; server_key < memcached_server_count(ptr); server_key++)
+  /* MAX_NUMBER_OF_SLAB_CLASSES is defined to 200 in Memcached 1.4.10 */
+  for (uint32_t x= 0; x < 200; x++)
   {
-    memcached_server_write_instance_st instance;
-    instance= memcached_server_instance_fetch(ptr, server_key);
-
-    /* MAX_NUMBER_OF_SLAB_CLASSESdefined to 200 in Memcached 1.4.10 */
-    for (uint32_t x= 0; x < 200; x++)
+    char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
+    int buffer_length= snprintf(buffer, sizeof(buffer), "%u", x);
+    if (size_t(buffer_length) >= sizeof(buffer) or buffer_length < 0)
     {
-      char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
-      int buffer_length= snprintf(buffer, sizeof(buffer), "%u", x);
-      if (buffer_length >= MEMCACHED_DEFAULT_COMMAND_SIZE or buffer_length < 0)
-      {
-        return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT, 
-                                   memcached_literal_param("snprintf(MEMCACHED_DEFAULT_COMMAND_SIZE)"));
-      }
+      return memcached_set_error(*memc, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT, 
+                                 memcached_literal_param("snprintf(MEMCACHED_DEFAULT_COMMAND_SIZE)"));
+    }
 
-      libmemcached_io_vector_st vector[]=
-      {
-        { memcached_literal_param("stats cachedump ") },
-        { buffer, buffer_length },
-        { memcached_literal_param(" 0 0\r\n") }
-      };
+    // @NOTE the hard coded zero means "no limit"
+    libmemcached_io_vector_st vector[]=
+    {
+      { memcached_literal_param("stats cachedump ") },
+      { buffer, buffer_length },
+      { memcached_literal_param(" 0\r\n") }
+    };
 
-      rc= memcached_vdo(instance, vector, 3, true);
+    // Send message to all servers
+    for (uint32_t server_key= 0; server_key < memcached_server_count(memc); server_key++)
+    {
+      memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, server_key);
 
-      if (rc != MEMCACHED_SUCCESS)
+      memcached_return_t vdo_rc;
+      if (memcached_success((vdo_rc= memcached_vdo(instance, vector, 3, true))))
       {
-        goto error;
+        // We have sent the message to the server successfully
       }
-
-      while (1)
+      else
       {
-        uint32_t callback_counter;
-        rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
+        return memcached_set_error(*instance, vdo_rc, MEMCACHED_AT);
+      }
+    }
 
-        if (rc == MEMCACHED_ITEM)
-        {
-          char *string_ptr, *end_ptr;
+    // Collect the returned items
+    memcached_server_write_instance_st instance;
+    while ((instance= memcached_io_get_readable_server(memc)))
+    {
+      memcached_return_t response_rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
+      if (response_rc == MEMCACHED_ITEM)
+      {
+        char *string_ptr, *end_ptr;
 
-          string_ptr= buffer;
-          string_ptr+= 5; /* Move past ITEM */
+        string_ptr= buffer;
+        string_ptr+= 5; /* Move past ITEM */
 
-          for (end_ptr= string_ptr; isgraph(*end_ptr); end_ptr++) {} ;
+        for (end_ptr= string_ptr; isgraph(*end_ptr); end_ptr++) {} ;
 
-          char *key= string_ptr;
-          key[(size_t)(end_ptr-string_ptr)]= 0;
+        char *key= string_ptr;
+        key[(size_t)(end_ptr-string_ptr)]= 0;
 
-          for (callback_counter= 0; callback_counter < number_of_callbacks; callback_counter++)
+        for (uint32_t callback_counter= 0; callback_counter < number_of_callbacks; callback_counter++)
+        {
+          memcached_return_t callback_rc= (*callback[callback_counter])(memc, key, (size_t)(end_ptr-string_ptr), context);
+          if (callback_rc != MEMCACHED_SUCCESS)
           {
-            rc= (*callback[callback_counter])(ptr, key, (size_t)(end_ptr-string_ptr), context);
-            if (rc != MEMCACHED_SUCCESS)
-            {
-              break;
-            }
+            // @todo build up a message for the error from the value
+            memcached_set_error(*instance, callback_rc, MEMCACHED_AT);
+            break;
           }
         }
-        else if (rc == MEMCACHED_END)
-        {
-          break;
-        }
-        else if (rc == MEMCACHED_SERVER_ERROR or rc == MEMCACHED_CLIENT_ERROR)
-        {
-          /* If we try to request stats cachedump for a slab class that is too big
-           * the server will return an incorrect error message:
-           * "MEMCACHED_SERVER_ERROR failed to allocate memory"
-           * This isn't really a fatal error, so let's just skip it. I want to
-           * fix the return value from the memcached server to a CLIENT_ERROR,
-           * so let's add support for that as well right now.
-         */
-          rc= MEMCACHED_END;
-          break;
-        }
-        else
-        {
-          goto error;
-        }
+      }
+      else if (response_rc == MEMCACHED_END)
+      { 
+        // All items have been returned
+      }
+      else if (response_rc == MEMCACHED_SERVER_ERROR or response_rc == MEMCACHED_CLIENT_ERROR or response_rc == MEMCACHED_ERROR)
+      {
+        /* If we try to request stats cachedump for a slab class that is too big
+         * the server will return an incorrect error message:
+         * "MEMCACHED_SERVER_ERROR failed to allocate memory"
+         * This isn't really a fatal error, so let's just skip it. I want to
+         * fix the return value from the memcached server to a CLIENT_ERROR,
+         * so let's add support for that as well right now.
+       */
+        assert(response_rc == MEMCACHED_SUCCESS); // Just fail
+        return response_rc;
+      }
+      else
+      {
+        // IO error of some sort must have occurred
+        return memcached_set_error(*instance, response_rc, MEMCACHED_AT);
       }
     }
   }
 
-error:
-  if (rc == MEMCACHED_END)
-  {
-    return MEMCACHED_SUCCESS;
-  }
-  else
-  {
-    return rc;
-  }
+  return memcached_has_current_error(*memc) ? MEMCACHED_SOME_ERRORS : MEMCACHED_SUCCESS;
 }
 
 memcached_return_t memcached_dump(memcached_st *ptr, memcached_dump_fn *callback, void *context, uint32_t number_of_callbacks)
index becffd23014b3a10256fa61672f905def9587ab3..1ca355b82231ac424fbbc89fb5bc1d50d9d1c8e4 100644 (file)
@@ -73,6 +73,10 @@ static void _set(memcached_server_st& server, memcached_st& memc)
   server.error_messages= error;
 }
 
+#if 0
+static int error_log_fd= -1;
+#endif
+
 static void _set(memcached_st& memc, memcached_string_t *str, memcached_return_t &rc, const char *at, int local_errno= 0)
 {
   if (memc.error_messages && memc.error_messages->query_id != memc.query_id)
@@ -141,37 +145,56 @@ static void _set(memcached_st& memc, memcached_string_t *str, memcached_return_t
 
   if (str and str->size and local_errno)
   {
-    error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "%s(%s), %.*s -> %s", 
+    error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%lu) %s(%s), %.*s -> %s", 
+                               long(error->root),
                                memcached_strerror(&memc, rc), 
                                errmsg_ptr,
                                memcached_string_printf(*str), at);
   }
   else if (local_errno)
   {
-    error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "%s(%s) -> %s", 
+    error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%lu) %s(%s) -> %s", 
+                               long(error->root),
                                memcached_strerror(&memc, rc), 
                                errmsg_ptr,
                                at);
   }
   else if (rc == MEMCACHED_PARSE_ERROR and str and str->size)
   {
-    error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "%.*s -> %s", 
+    error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%lu) %.*s -> %s", 
+                               long(error->root),
                                int(str->size), str->c_str, at);
   }
   else if (str and str->size)
   {
-    error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "%s, %.*s -> %s", 
+    error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%lu) %s, %.*s -> %s", 
+                               long(error->root),
                                memcached_strerror(&memc, rc), 
                                int(str->size), str->c_str, at);
   }
   else
   {
-    error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "%s -> %s", 
+    error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%lu) %s -> %s", 
+                               long(error->root),
                                memcached_strerror(&memc, rc), at);
   }
 
   error->next= memc.error_messages;
   memc.error_messages= error;
+
+#if 0
+  if (error_log_fd == -1)
+  {
+//    unlink("/tmp/libmemcachd.log");
+    if ((error_log_fd= open("/tmp/libmemcachd.log", O_CREAT | O_WRONLY | O_APPEND, 0644)) < 0)
+    {
+      perror("open");
+      error_log_fd= -1;
+    }
+  }
+  ::write(error_log_fd, error->message, error->size);
+  ::write(error_log_fd, "\n", 1);
+#endif
 }
 
 memcached_return_t memcached_set_error(memcached_st& memc, memcached_return_t rc, const char *at, const char *str, size_t length)
@@ -192,7 +215,7 @@ memcached_return_t memcached_set_error(memcached_server_st& self, memcached_retu
 memcached_return_t memcached_set_error(memcached_st& memc, 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");
-  if (memcached_success(rc))
+  if (memcached_fatal(rc) == false)
   {
     return rc;
   }
@@ -220,7 +243,7 @@ memcached_return_t memcached_set_error(memcached_server_st& self, memcached_retu
 {
   assert_msg(rc != MEMCACHED_ERRNO, "Programmer error, MEMCACHED_ERRNO was set to be returned to client");
   assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a memcached_server_st");
-  if (memcached_success(rc))
+  if (memcached_fatal(rc) == false)
   {
     return rc;
   }
@@ -258,7 +281,7 @@ memcached_return_t memcached_set_error(memcached_server_st& self, memcached_retu
 memcached_return_t memcached_set_error(memcached_server_st& self, memcached_return_t rc, const char *at)
 {
   assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a memcached_server_st");
-  if (memcached_success(rc))
+  if (memcached_fatal(rc) == false)
   {
     return rc;
   }
@@ -282,7 +305,7 @@ memcached_return_t memcached_set_error(memcached_server_st& self, memcached_retu
 memcached_return_t memcached_set_error(memcached_st& self, memcached_return_t rc, const char *at)
 {
   assert_msg(rc != MEMCACHED_ERRNO, "Programmer error, MEMCACHED_ERRNO was set to be returned to client");
-  if (memcached_success(rc))
+  if (memcached_fatal(rc) == false)
   {
     return rc;
   }
@@ -354,8 +377,10 @@ memcached_return_t memcached_set_errno(memcached_server_st& self, int local_errn
   memcached_string_t error_host= { hostname_port_message, size };
 
   memcached_return_t rc= MEMCACHED_ERRNO;
-  if (not self.root)
+  if (self.root == NULL)
+  {
     return rc;
+  }
 
   _set(*self.root, &error_host, rc, at, local_errno);
   _set(self, (*self.root));
@@ -377,8 +402,10 @@ memcached_return_t memcached_set_errno(memcached_server_st& self, int local_errn
   memcached_string_t error_host= { hostname_port_message, size };
 
   memcached_return_t rc= MEMCACHED_ERRNO;
-  if (not self.root)
+  if (self.root == NULL)
+  {
     return rc;
+  }
 
   _set(*self.root, &error_host, rc, at, local_errno);
   _set(self, (*self.root));
@@ -498,7 +525,9 @@ memcached_return_t memcached_last_error(memcached_st *memc)
   }
 
   if (not memc->error_messages)
+  {
     return MEMCACHED_SUCCESS;
+  }
 
   return memc->error_messages->rc;
 }
@@ -526,10 +555,14 @@ const char *memcached_server_error(memcached_server_instance_st server)
   }
 
   if (not server->error_messages)
+  {
     return memcached_strerror(server->root, MEMCACHED_SUCCESS);
+  }
 
   if (not server->error_messages->size)
+  {
     return memcached_strerror(server->root, server->error_messages->rc);
+  }
 
   return server->error_messages->message;
 }
index d2dc34dd6a1126f7e8afc463405d82a0da698525..67c6902eca9bb5eddc51ef265284bef0ed582b15 100644 (file)
@@ -52,26 +52,23 @@ static memcached_return_t ascii_exist(memcached_st *memc, memcached_server_write
   };
 
   /* Send command header */
-  memcached_return_t rc=  memcached_vdo(instance, vector, 9, true);
-  if (rc == MEMCACHED_SUCCESS)
+  memcached_return_t rc;
+  if (memcached_fatal(rc= memcached_vdo(instance, vector, 9, true)))
   {
-    char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
-    rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
-
-    if (rc == MEMCACHED_NOTSTORED)
-    {
-      rc= MEMCACHED_SUCCESS;
-    }
-
-    if (rc == MEMCACHED_STORED)
-    {
-      rc= MEMCACHED_NOTFOUND;
-    }
+    return rc;
   }
 
-  if (rc == MEMCACHED_WRITE_FAILURE)
+  char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
+  rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
+
+  if (rc == MEMCACHED_NOTSTORED)
   {
-    memcached_io_reset(instance);
+    rc= MEMCACHED_SUCCESS;
+  }
+
+  if (rc == MEMCACHED_STORED)
+  {
+    rc= MEMCACHED_NOTFOUND;
   }
 
   return rc;
@@ -104,19 +101,22 @@ static memcached_return_t binary_exist(memcached_st *memc, memcached_server_writ
 
   /* write the header */
   memcached_return_t rc;
-  if ((rc= memcached_vdo(instance, vector, 4, true)) != MEMCACHED_SUCCESS)
+  if (memcached_fatal(rc= memcached_vdo(instance, vector, 4, true)))
   {
-    memcached_io_reset(instance);
-    return (rc == MEMCACHED_SUCCESS) ? MEMCACHED_WRITE_FAILURE : rc;
+    return rc;
   }
 
   rc= memcached_response(instance, NULL, 0, NULL);
 
   if (rc == MEMCACHED_SUCCESS)
+  {
     rc= MEMCACHED_NOTFOUND;
+  }
 
   if (rc == MEMCACHED_DATA_EXISTS)
+  {
     rc= MEMCACHED_SUCCESS;
+  }
 
   return rc;
 }
@@ -138,19 +138,25 @@ memcached_return_t memcached_exist_by_key(memcached_st *memc,
 
   if (memcached_is_udp(memc))
   {
-    return MEMCACHED_NOT_SUPPORTED;
+    return memcached_set_error(*memc, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT);
   }
 
   uint32_t server_key= memcached_generate_hash_with_redistribution(memc, group_key, group_key_length);
-  memcached_server_write_instance_st instance;
-  instance= memcached_server_instance_fetch(memc, server_key);
+  memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, server_key);
 
-  if (memc->flags.binary_protocol)
+  if (memcached_is_binary(memc))
   {
-    return binary_exist(memc, instance, key, key_length);
+    rc= binary_exist(memc, instance, key, key_length);
   }
   else
   {
-    return ascii_exist(memc, instance, key, key_length);
+    rc= ascii_exist(memc, instance, key, key_length);
   }
+
+  if (memcached_fatal(rc))
+  {
+    memcached_io_reset(instance);
+  }
+
+  return rc;
 }
index fa76adae7b3de6e9cc071cf6a2f26da06ab71b0d..a6fe4034e7a4416caa23005e01cf86668f5b2a27 100644 (file)
@@ -111,7 +111,9 @@ char *memcached_get_by_key(memcached_st *ptr,
 
   /* This is for historical reasons */
   if (*error == MEMCACHED_END)
+  {
     *error= MEMCACHED_NOTFOUND;
+  }
 
   if (value == NULL)
   {
@@ -121,14 +123,16 @@ char *memcached_get_by_key(memcached_st *ptr,
       memcached_return_t rc= ptr->get_key_failure(ptr, key, key_length, &ptr->result);
 
       /* On all failure drop to returning NULL */
-      if (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED)
+      if (rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED)
       {
         if (rc == MEMCACHED_BUFFERED)
         {
           uint64_t latch; /* We use latch to track the state of the original socket */
           latch= memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS);
           if (latch == 0)
+          {
             memcached_behavior_set(ptr, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1);
+          }
 
           rc= memcached_set(ptr, key, key_length,
                             (memcached_result_value(&ptr->result)),
@@ -227,7 +231,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr,
 
   if (memcached_failed(memcached_key_test(*ptr, keys, key_length, number_of_keys)))
   {
-    return memcached_set_error(*ptr, MEMCACHED_BAD_KEY_PROVIDED, MEMCACHED_AT, memcached_literal_param("A bad key value was provided"));
+    return memcached_last_error(ptr);
   }
 
   bool is_group_key_set= false;
index ab98e4864aac9ff4024a09bde28833740ec37373..8b297a7acaed71215d0c9624f632f91c4909bf7f 100644 (file)
@@ -319,7 +319,6 @@ static bool io_flush(memcached_server_write_instance_st ptr,
 
     if (sent_length == SOCKET_ERROR)
     {
-      memcached_set_errno(*ptr, get_socket_errno(), MEMCACHED_AT);
 #if 0 // @todo I should look at why we hit this bit of code hard frequently
       WATCHPOINT_ERRNO(get_socket_errno());
       WATCHPOINT_NUMBER(get_socket_errno());
index e92468811ccf8b80ca3338eb7fffad7c9bb22b9c..39c1455be67b51d02260a7ea02b0492bc86a461b 100644 (file)
@@ -44,7 +44,7 @@ memcached_return_t memcached_key_test(memcached_st &memc,
 {
   if (keys == NULL or key_length == NULL)
   {
-    return memcached_set_error(memc, MEMCACHED_BAD_KEY_PROVIDED, MEMCACHED_AT);
+    return memcached_set_error(memc, MEMCACHED_BAD_KEY_PROVIDED, MEMCACHED_AT, memcached_literal_param("Key was NULL or length of key was zero."));
   }
 
   // If we don't need to verify the key, or we are using the binary protoocol,
@@ -58,7 +58,7 @@ memcached_return_t memcached_key_test(memcached_st &memc,
       memcached_return_t rc= memcached_validate_key_length(*(key_length +x), false /* memc.flags.binary_protocol */);
       if (memcached_failed(rc))
       {
-        return rc;
+        return memcached_set_error(memc, rc, MEMCACHED_AT, memcached_literal_param("Key provided was too long."));
       }
     }
 
@@ -70,14 +70,14 @@ memcached_return_t memcached_key_test(memcached_st &memc,
     memcached_return_t rc= memcached_validate_key_length(*(key_length + x), false);
     if (memcached_failed(rc))
     {
-      return rc;
+      return memcached_set_error(memc, rc, MEMCACHED_AT, memcached_literal_param("Key provided was too long."));
     }
  
     for (size_t y= 0; y < *(key_length + x); y++)
     {
       if ((isgraph(keys[x][y])) == 0)
       {
-        return MEMCACHED_BAD_KEY_PROVIDED;
+        return memcached_set_error(memc, MEMCACHED_BAD_KEY_PROVIDED, MEMCACHED_AT, memcached_literal_param("Key provided had invalid character."));
       }
     }
   }
index 5cefae56f47981427885265cb0dc93c6bd06f597..8278dd56337606cfa8dad3d4a803bd62ecf626ca 100644 (file)
@@ -58,7 +58,7 @@ memcached_return_t memcached_set_namespace(memcached_st *self, const char *key,
     if (memcached_failed(memcached_key_test(*self, (const char **)&key, &key_length, 1)))
     {
       self->flags.verify_key= orig;
-      return memcached_set_error(*self, MEMCACHED_BAD_KEY_PROVIDED, MEMCACHED_AT);
+      return memcached_last_error(self);
     }
     self->flags.verify_key= orig;
 
index e876123d4290ef9a468ac1ff7946a29875c2b777..ac1fb057124b59360b65652b4b38415315e09825 100644 (file)
@@ -242,12 +242,18 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta
           return MEMCACHED_SERVER_ERROR;
         }
 
-        if (total_read > memcached_literal_param_size("SERVER_ERROR object too large for cache") and
+        if (total_read >= memcached_literal_param_size("SERVER_ERROR object too large for cache") and
             (memcmp(buffer, memcached_literal_param("SERVER_ERROR object too large for cache")) == 0))
         {
           return MEMCACHED_E2BIG;
         }
 
+        if (total_read >= memcached_literal_param_size("SERVER_ERROR out of memory storing object") and
+            (memcmp(buffer, memcached_literal_param("SERVER_ERROR out of memory storing object")) == 0))
+        {
+          return MEMCACHED_SERVER_MEMORY_ALLOCATION_FAILURE;
+        }
+
         // Move past the basic error message and whitespace
         char *startptr= buffer + memcached_literal_param_size("SERVER_ERROR");
         if (startptr[0] == ' ')
@@ -313,6 +319,11 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta
         return MEMCACHED_PROTOCOL_ERROR;
       }
 #endif
+      // ERROR
+      else if (buffer[1] == 'R' and buffer[2] == 'R' and buffer[3] == 'O' and buffer[4] == 'R')
+      {
+        return MEMCACHED_ERROR;
+      }
       // EXISTS
       else if (buffer[1] == 'X' and buffer[2] == 'I' and buffer[3] == 'S' and buffer[4] == 'T' and buffer[5] == 'S')
       {
@@ -705,11 +716,7 @@ static memcached_return_t _read_one_response(memcached_server_write_instance_st
     assert(rc != MEMCACHED_PROTOCOL_ERROR);
   }
 
-  if (rc == MEMCACHED_UNKNOWN_READ_FAILURE or
-      rc == MEMCACHED_READ_FAILURE or
-      rc == MEMCACHED_PROTOCOL_ERROR or
-      rc == MEMCACHED_CLIENT_ERROR or
-      rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE)
+  if (memcached_fatal(rc))
   {
     memcached_io_reset(ptr);
   }
@@ -774,14 +781,22 @@ memcached_return_t memcached_response(memcached_server_write_instance_st ptr,
       memcached_return_t rc= _read_one_response(ptr, buffer, buffer_length, junked_result_ptr, numeric_value);
 
       // @TODO should we return an error on another but a bad read case?
-      if (rc != MEMCACHED_END and
-          rc != MEMCACHED_STORED and
-          rc != MEMCACHED_SUCCESS and
-          rc != MEMCACHED_STAT and
+      if (
+          rc != MEMCACHED_DATA_EXISTS and
           rc != MEMCACHED_DELETED and
+          rc != MEMCACHED_E2BIG and
+          rc != MEMCACHED_END and
+          rc != MEMCACHED_ERROR and
+          rc != MEMCACHED_ITEM and
           rc != MEMCACHED_NOTFOUND and
           rc != MEMCACHED_NOTSTORED and
-          rc != MEMCACHED_DATA_EXISTS)
+          rc != MEMCACHED_SERVER_ERROR and
+          rc != MEMCACHED_SERVER_MEMORY_ALLOCATION_FAILURE and
+          rc != MEMCACHED_STAT and
+          rc != MEMCACHED_STORED and
+          rc != MEMCACHED_SUCCESS and
+          rc != MEMCACHED_VALUE
+          )
       {
         memcached_result_free(junked_result_ptr);
         return rc;
index 85ce83810299babdc1c21ab44eb00c59f2230feb..2f41584419ad337d35d6c6b3572453b405b5506e 100644 (file)
@@ -139,7 +139,7 @@ memcached_server_st *__server_create_with(memcached_st *memc,
 
   if (memc)
   {
-    set_hostinfo(self);
+    memcached_connect_try(self);
   }
 
   return self;
@@ -241,18 +241,28 @@ memcached_return_t memcached_server_execute(memcached_st *ptr,
                                             memcached_server_execute_fn callback,
                                             void *context)
 {
+  if (callback == NULL)
+  {
+    return MEMCACHED_INVALID_ARGUMENTS;
+  }
+
+  bool some_errors= false;;
   for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
   {
     memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x);
 
-    unsigned int iferror= (*callback)(ptr, instance, context);
-
-    if (iferror)
+    memcached_return_t rc= (*callback)(ptr, instance, context);
+    if (rc == MEMCACHED_INVALID_ARGUMENTS)
+    {
+      return rc;
+    }
+    else if (memcached_fatal(rc))
     {
-      continue;
+      some_errors= true;
     }
   }
 
+  (void)some_errors;
   return MEMCACHED_SUCCESS;
 }
 
index d5d1c234b589f18d205b158d42eee31e1ccaad7c..49dfab018e4ac37cddf3891ece763670902a15de 100644 (file)
@@ -81,7 +81,7 @@ struct local_context
 };
 
 
-static memcached_return_t set_data(memcached_stat_st *memc_stat, char *key, char *value)
+static memcached_return_t set_data(memcached_stat_st *memc_stat, const char *key, const char *value)
 {
 
   if (strlen(key) < 1)
@@ -127,7 +127,7 @@ static memcached_return_t set_data(memcached_stat_st *memc_stat, char *key, char
   else if (not strcmp("rusage_user", key))
   {
     char *walk_ptr;
-    for (walk_ptr= value; (!ispunct(*walk_ptr)); walk_ptr++) {};
+    for (walk_ptr= (char*)value; (!ispunct(*walk_ptr)); walk_ptr++) {};
     *walk_ptr= 0;
     walk_ptr++;
     memc_stat->rusage_user_seconds= strtoul(value, (char **)NULL, 10);
@@ -136,7 +136,7 @@ static memcached_return_t set_data(memcached_stat_st *memc_stat, char *key, char
   else if (not strcmp("rusage_system", key))
   {
     char *walk_ptr;
-    for (walk_ptr= value; (!ispunct(*walk_ptr)); walk_ptr++) {};
+    for (walk_ptr= (char*)value; (!ispunct(*walk_ptr)); walk_ptr++) {};
     *walk_ptr= 0;
     walk_ptr++;
     memc_stat->rusage_system_seconds= strtoul(value, (char **)NULL, 10);
@@ -402,15 +402,6 @@ static memcached_return_t binary_stats_fetch(memcached_stat_st *memc_stat,
       return rc;
     }
 
-    if (memc_stat)
-    {
-      if ((set_data(memc_stat, buffer, buffer + strlen(buffer) + 1)) == MEMCACHED_UNKNOWN_STAT_KEY)
-      {
-        WATCHPOINT_ERROR(MEMCACHED_UNKNOWN_STAT_KEY);
-        WATCHPOINT_ASSERT(0);
-      }
-    }
-
     if (check && check->func)
     {
       size_t key_length= strlen(buffer);
@@ -420,6 +411,15 @@ static memcached_return_t binary_stats_fetch(memcached_stat_st *memc_stat,
                   buffer+key_length+1, strlen(buffer+key_length+1),
                   check->context);
     }
+
+    if (memc_stat)
+    {
+      if ((set_data(memc_stat, buffer, buffer + strlen(buffer) + 1)) == MEMCACHED_UNKNOWN_STAT_KEY)
+      {
+        WATCHPOINT_ERROR(MEMCACHED_UNKNOWN_STAT_KEY);
+        WATCHPOINT_ASSERT(0);
+      }
+    }
   } while (1);
 
   /* 
@@ -448,40 +448,50 @@ static memcached_return_t ascii_stats_fetch(memcached_stat_st *memc_stat,
   if (memcached_success(rc))
   {
     char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
-    while ((rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL)) == MEMCACHED_STAT)
+    while ((rc= memcached_response(instance, buffer, sizeof(buffer), NULL)) == MEMCACHED_STAT)
     {
-      char *string_ptr, *end_ptr;
-      char *key, *value;
-
-      string_ptr= buffer;
+      char *string_ptr= buffer;
       string_ptr+= 5; /* Move past STAT */
+
+      char *end_ptr;
       for (end_ptr= string_ptr; isgraph(*end_ptr); end_ptr++) {};
-      key= string_ptr;
-      key[(size_t)(end_ptr-string_ptr)]= 0;
+      char *key= string_ptr;
+      key[size_t(end_ptr-string_ptr)]= 0;
 
       string_ptr= end_ptr + 1;
       for (end_ptr= string_ptr; !(isspace(*end_ptr)); end_ptr++) {};
-      value= string_ptr;
+      char *value= string_ptr;
       value[(size_t)(end_ptr -string_ptr)]= 0;
-      if (memc_stat)
-      {
-        unlikely((set_data(memc_stat, key, value)) == MEMCACHED_UNKNOWN_STAT_KEY)
-        {
-          WATCHPOINT_ERROR(MEMCACHED_UNKNOWN_STAT_KEY);
-          WATCHPOINT_ASSERT(0);
-        }
-      }
+#if 0
+      bool check_bool= bool(check);
+      bool check_func_bool= bool(check) ? bool(check->func) : false;
+      fprintf(stderr, "%s:%d %s %s %d:%d\n", __FILE__, __LINE__, key, value, check_bool, check_func_bool);
+#endif
 
-      if (check && check->func)
+      if (check and check->func)
       {
         check->func(instance,
                     key, strlen(key),
                     value, strlen(value),
                     check->context);
       }
+
+      if (memc_stat)
+      {
+        if((set_data(memc_stat, key, value)) == MEMCACHED_UNKNOWN_STAT_KEY)
+        {
+          WATCHPOINT_ERROR(MEMCACHED_UNKNOWN_STAT_KEY);
+          WATCHPOINT_ASSERT(0);
+        }
+      }
     }
   }
 
+  if (rc == MEMCACHED_ERROR)
+  {
+    return MEMCACHED_INVALID_ARGUMENTS;
+  }
+
   if (rc == MEMCACHED_END)
   {
     return MEMCACHED_SUCCESS;
@@ -552,6 +562,13 @@ memcached_stat_st *memcached_stat(memcached_st *self, char *args, memcached_retu
       temp_return= ascii_stats_fetch(stat_instance, args, args_length, instance, NULL);
     }
 
+    // Special case where "args" is invalid
+    if (temp_return == MEMCACHED_INVALID_ARGUMENTS)
+    {
+      rc= MEMCACHED_INVALID_ARGUMENTS;
+      break;
+    }
+
     if (memcached_failed(temp_return))
     {
       rc= MEMCACHED_SOME_ERRORS;
@@ -619,8 +636,10 @@ char ** memcached_stat_get_keys(memcached_st *ptr,
                                 memcached_stat_st *,
                                 memcached_return_t *error)
 {
-  if (not ptr)
+  if (ptr == NULL)
+  {
     return NULL;
+  }
 
   char **list= static_cast<char **>(libmemcached_malloc(ptr, sizeof(memcached_stat_keys)));
   if (not list)
@@ -658,9 +677,9 @@ static memcached_return_t call_stat_fn(memcached_st *ptr,
                                        void *context)
 {
   memcached_return_t rc;
-  struct local_context *check= (struct local_context *)context;
+  local_context *check= (struct local_context *)context;
 
-  if (ptr->flags.binary_protocol)
+  if (memcached_is_binary(ptr))
   {
     rc= binary_stats_fetch(NULL, check->args, check->args_length, instance, check);
   }
@@ -676,7 +695,7 @@ memcached_return_t memcached_stat_execute(memcached_st *memc, const char *args,
 {
   memcached_version(memc);
 
struct local_context check(func, context, args, args ? strlen(args) : 0);
+ local_context check(func, context, args, args ? strlen(args) : 0);
 
  return memcached_server_execute(memc, call_stat_fn, (void *)&check);
 }
index b70a60b9e6b1ba6085b79645a3aaa516de59cff8..7cd2ff2ffff9b65a861f82699a19597de565b40e 100644 (file)
@@ -74,8 +74,8 @@ const char *memcached_strerror(memcached_st *, memcached_return_t rc)
   case MEMCACHED_WRITE_FAILURE:
     return "WRITE FAILURE";
 
-  case MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE: // DEPRECATED
-    return "CONNECTION SOCKET CREATE FAILURE";
+  case MEMCACHED_ERROR:
+    return "ERROR was returned by server";
 
   case MEMCACHED_DATA_EXISTS:
     return "CONNECTION DATA EXISTS";
index a94d442111da9abd37e8ed1fbba4cb0373b464a9..c7a47827decfae6ba6e0392c762864cc3ac86b55 100644 (file)
@@ -43,17 +43,19 @@ inline static memcached_return_t _string_check(memcached_string_st *string, size
   if (need && need > (size_t)(string->current_size - (size_t)(string->end - string->string)))
   {
     size_t current_offset= (size_t) (string->end - string->string);
-    size_t adjust;
-    size_t new_size;
 
     /* This is the block multiplier. To keep it larger and surive division errors we must round it up */
-    adjust= (need - (size_t)(string->current_size - (size_t)(string->end - string->string))) / MEMCACHED_BLOCK_SIZE;
+    size_t adjust= (need - (size_t)(string->current_size - (size_t)(string->end - string->string))) / MEMCACHED_BLOCK_SIZE;
     adjust++;
 
-    new_size= sizeof(char) * (size_t)((adjust * MEMCACHED_BLOCK_SIZE) + string->current_size);
+    size_t new_size= sizeof(char) * (size_t)((adjust * MEMCACHED_BLOCK_SIZE) + string->current_size);
     /* Test for overflow */
     if (new_size < need)
-      return memcached_set_error(*string->root, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
+    {
+      char error_message[1024];
+      int error_message_length= snprintf(error_message, sizeof(error_message),"Needed %ld, got %ld", (long)need, (long)new_size);
+      return memcached_set_error(*string->root, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT, error_message, error_message_length);
+    }
 
     char *new_value= libmemcached_xrealloc(string->root, string->string, new_size, char);
 
index 44391eff06034f9cdbaaa435f0c1224ee8c42b1f..c0f8658a6629c81a1fce3d3fe21759561a66c55e 100644 (file)
  */
 
 #include <config.h>
+
+#include <cstdlib>
+#include <climits>
+
 #include <libtest/test.hpp>
 
 #include <libmemcached-1.0/memcached.h>
@@ -45,17 +49,41 @@ using namespace libtest;
 #include "tests/libmemcached-1.0/dump.h"
 
 static memcached_return_t callback_dump_counter(const memcached_st *,
-                                                const char *,
-                                                size_t ,
+                                                const char*, // key,
+                                                size_t, // length,
                                                 void *context)
 {
   size_t *counter= (size_t *)context;
 
+#if 0
+  std::cerr.write(key, length);
+  std::cerr << std::endl;
+#endif
+
   *counter= *counter +1;
 
   return MEMCACHED_SUCCESS;
 }
 
+static memcached_return_t item_counter(memcached_server_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);
+    if (number_value == ULONG_MAX)
+    {
+      return MEMCACHED_FAILURE;
+    }
+    *counter= *counter +number_value;
+  }
+
+  return MEMCACHED_SUCCESS;
+}
+
 test_return_t memcached_dump_TEST(memcached_st *memc)
 {
   test_skip(false, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
@@ -64,7 +92,54 @@ test_return_t memcached_dump_TEST(memcached_st *memc)
   memcached_dump_fn callbacks[1];
   callbacks[0]= &callback_dump_counter;
 
-  test_compare_hint(MEMCACHED_SUCCESS, memcached_dump(memc, callbacks, &count, 1), memcached_last_error_message(memc));
+  uint64_t counter= 0;
+  test_compare_got(MEMCACHED_SUCCESS,
+                   memcached_stat_execute(memc, NULL, item_counter, &counter),
+                   memcached_last_error_message(memc));
+  test_zero(counter);
+
+  test_compare_got(MEMCACHED_SUCCESS, memcached_dump(memc, callbacks, &count, 1), memcached_last_error_message(memc));
+
+  return TEST_SUCCESS;
+}
+
+#define memcached_dump_TEST2_COUNT 64
+test_return_t memcached_dump_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);
+
+    test_true(length > 0);
+
+    test_compare_hint(MEMCACHED_SUCCESS,
+                      memcached_set(memc, key, length,
+                                    NULL, 0, // Zero length values
+                                    time_t(0), uint32_t(0)),
+                      memcached_last_error_message(memc));
+  }
+  memcached_quit(memc);
+
+  uint64_t counter= 0;
+  test_compare_got(MEMCACHED_SUCCESS,
+                   memcached_stat_execute(memc, NULL, item_counter, &counter),
+                   memcached_last_error_message(memc));
+  test_true_got(counter > 0, counter);
+
+  size_t count= 0;
+  memcached_dump_fn callbacks[1];
+  callbacks[0]= &callback_dump_counter;
+
+  test_compare_got(MEMCACHED_SUCCESS,
+                   memcached_dump(memc, callbacks, &count, 1),
+                   memcached_last_error_message(memc));
+
+  test_compare(size_t(memcached_dump_TEST2_COUNT), count);
 
   return TEST_SUCCESS;
 }
index 37c4d5a2c505fc7942073bc4baa44a0f98743aae..2a6b69d6f142bb09a5c28dd7bc86c99d9ba4dd71 100644 (file)
@@ -37,3 +37,4 @@
 #pragma once
 
 test_return_t memcached_dump_TEST(memcached_st *);
+test_return_t memcached_dump_TEST2(memcached_st *);
index 7d1178ff8062308778d24ecb2f0240f2a7413b97..5815d6cb0414dbd9acf9f16d2a52df8dcfa5d537 100644 (file)
@@ -49,10 +49,10 @@ test_return_t memcached_exist_NOTFOUND(memcached_st *memc)
 
 test_return_t memcached_exist_SUCCESS(memcached_st *memc)
 {
-  test_compare(MEMCACHED_SUCCESS, memcached_set(memc, test_literal_param("frog"), 0, 0, 0, 0));
-  test_compare(MEMCACHED_SUCCESS, memcached_exist(memc, test_literal_param("frog")));
-  test_compare(MEMCACHED_SUCCESS, memcached_delete(memc, test_literal_param("frog"), 0));
-  test_compare(MEMCACHED_NOTFOUND, memcached_exist(memc, test_literal_param("frog")));
+  test_compare_got(MEMCACHED_SUCCESS, memcached_set(memc, test_literal_param("frog"), 0, 0, 0, 0), memcached_last_error_message(memc));
+  test_compare_got(MEMCACHED_SUCCESS, memcached_exist(memc, test_literal_param("frog")), memcached_last_error_message(memc));
+  test_compare_got(MEMCACHED_SUCCESS, memcached_delete(memc, test_literal_param("frog"), 0), memcached_last_error_message(memc));
+  test_compare_got(MEMCACHED_NOTFOUND, memcached_exist(memc, test_literal_param("frog")), memcached_last_error_message(memc));
 
   return TEST_SUCCESS;
 }
@@ -65,10 +65,10 @@ test_return_t memcached_exist_by_key_NOTFOUND(memcached_st *memc)
 
 test_return_t memcached_exist_by_key_SUCCESS(memcached_st *memc)
 {
-  test_compare(MEMCACHED_SUCCESS, memcached_set_by_key(memc, test_literal_param("master"), test_literal_param("frog"), 0, 0, 0, 0));
-  test_compare(MEMCACHED_SUCCESS, memcached_exist_by_key(memc, test_literal_param("master"), test_literal_param("frog")));
-  test_compare(MEMCACHED_SUCCESS, memcached_delete_by_key(memc, test_literal_param("master"), test_literal_param("frog"), 0));
-  test_compare(MEMCACHED_NOTFOUND, memcached_exist_by_key(memc, test_literal_param("master"), test_literal_param("frog")));
+  test_compare_got(MEMCACHED_SUCCESS, memcached_set_by_key(memc, test_literal_param("master"), test_literal_param("frog"), 0, 0, 0, 0), memcached_last_error_message(memc));
+  test_compare_got(MEMCACHED_SUCCESS, memcached_exist_by_key(memc, test_literal_param("master"), test_literal_param("frog")), memcached_last_error_message(memc));
+  test_compare_got(MEMCACHED_SUCCESS, memcached_delete_by_key(memc, test_literal_param("master"), test_literal_param("frog"), 0), memcached_last_error_message(memc));
+  test_compare_got(MEMCACHED_NOTFOUND, memcached_exist_by_key(memc, test_literal_param("master"), test_literal_param("frog")), memcached_last_error_message(memc));
 
   return TEST_SUCCESS;
 }
index 88bdeb1d8224f126d678bcb653265b74d2841564..373fc6e79bc28c615bdf8dbcbd4d80930a3f0499 100644 (file)
@@ -12,21 +12,22 @@ noinst_HEADERS+= \
                 tests/basic.h \
                 tests/callbacks.h \
                 tests/debug.h \
+                tests/deprecated.h \
                 tests/error_conditions.h \
                 tests/exist.h \
                 tests/ketama.h \
                 tests/ketama_test_cases.h \
                 tests/ketama_test_cases_spy.h \
                 tests/libmemcached-1.0/dump.h \
+                tests/libmemcached-1.0/stat.h \
                 tests/namespace.h \
                 tests/parser.h \
-                tests/touch.h \
-                tests/deprecated.h \
                 tests/pool.h \
                 tests/print.h \
                 tests/replication.h \
                 tests/server_add.h \
                 tests/string.h \
+                tests/touch.h \
                 tests/virtual_buckets.h
 
 # Test internals
@@ -45,6 +46,9 @@ noinst_PROGRAMS+= tests/libmemcached-1.0/internals
 tests_libmemcached_1_0_testapp_CXXFLAGS =  $(AM_CXXFLAGS) ${PTHREAD_CFLAGS}
 tests_libmemcached_1_0_testapp_CFLAGS= $(AM_CFLAGS) $(NO_CONVERSION) $(NO_STRICT_ALIASING)
 tests_libmemcached_1_0_testapp_SOURCES= \
+                                       tests/libmemcached-1.0/pool.cc \
+                                       tests/libmemcached-1.0/print.cc \
+                                       tests/libmemcached-1.0/replication.cc \
                                         tests/libmemcached-1.0/basic.cc \
                                         tests/libmemcached-1.0/callbacks.cc \
                                         tests/libmemcached-1.0/debug.cc \
@@ -55,11 +59,9 @@ tests_libmemcached_1_0_testapp_SOURCES= \
                                         tests/libmemcached-1.0/ketama.cc \
                                         tests/libmemcached-1.0/mem_functions.cc \
                                         tests/libmemcached-1.0/namespace.cc \
-                                       tests/libmemcached-1.0/pool.cc \
-                                       tests/libmemcached-1.0/print.cc \
-                                       tests/libmemcached-1.0/replication.cc \
                                         tests/libmemcached-1.0/parser.cc \
                                         tests/libmemcached-1.0/server_add.cc \
+                                        tests/libmemcached-1.0/stat.cc \
                                         tests/libmemcached-1.0/touch.cc \
                                         tests/libmemcached-1.0/virtual_buckets.cc
 
index ac88ee50fbde9a10d3e7adc89439af93d59b67d3..a31438937c04e8892ffe63644b23927b0d8c31c1 100644 (file)
@@ -79,6 +79,7 @@
 #include "tests/namespace.h"
 #include "tests/parser.h"
 #include "tests/libmemcached-1.0/dump.h"
+#include "tests/libmemcached-1.0/stat.h"
 #include "tests/touch.h"
 #include "tests/callbacks.h"
 #include "tests/pool.h"
@@ -486,7 +487,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,
@@ -881,7 +882,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);
     {
@@ -1537,11 +1538,9 @@ 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:"));
 
@@ -1561,7 +1560,6 @@ 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;
 }
@@ -3968,7 +3966,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);
 
@@ -4092,8 +4090,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);
@@ -4109,24 +4107,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));
@@ -4682,6 +4662,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));
 
@@ -4792,8 +4774,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);
@@ -4930,6 +4911,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);
@@ -4985,6 +4970,8 @@ static test_return_t regression_bug_463297(memcached_st *memc)
   }
 
   memcached_free(memc_clone);
+#endif
+
   return TEST_SUCCESS;
 }
 
@@ -5452,7 +5439,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)
@@ -5609,10 +5596,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 },
@@ -5665,7 +5651,8 @@ 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},
-  {"memcached_dump()", 0, (test_callback_fn*)memcached_dump_TEST },
+  {"memcached_dump() no data", true, (test_callback_fn*)memcached_dump_TEST },
+  {"memcached_dump() with data", true, (test_callback_fn*)memcached_dump_TEST2 },
   {0, 0, 0}
 };
 
@@ -5675,6 +5662,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},
@@ -6011,6 +6004,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}
 };
 
diff --git a/tests/libmemcached-1.0/stat.cc b/tests/libmemcached-1.0/stat.cc
new file mode 100644 (file)
index 0000000..209b70a
--- /dev/null
@@ -0,0 +1,109 @@
+/*  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 <config.h>
+
+#include <cstdlib>
+#include <climits>
+
+#include <libtest/test.hpp>
+
+#include <libmemcached-1.0/memcached.h>
+#include <libmemcached/util.h>
+
+using namespace libtest;
+
+#include "tests/libmemcached-1.0/stat.h"
+
+static memcached_return_t item_counter(memcached_server_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);
+    if (number_value == ULONG_MAX)
+    {
+      return MEMCACHED_FAILURE;
+    }
+    *counter= *counter +number_value;
+  }
+
+  return MEMCACHED_SUCCESS;
+}
+
+test_return_t memcached_stat_TEST(memcached_st *memc)
+{
+  uint64_t counter= 0;
+  test_compare_got(MEMCACHED_INVALID_ARGUMENTS,
+                   memcached_stat_execute(memc, "BAD_ARG_VALUE", item_counter, &counter),
+                   memcached_last_error_message(memc));
+
+  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);
+
+    test_true(length > 0);
+
+    test_compare_hint(MEMCACHED_SUCCESS,
+                      memcached_set(memc, key, length,
+                                    NULL, 0, // Zero length values
+                                    time_t(0), uint32_t(0)),
+                      memcached_last_error_message(memc));
+  }
+  memcached_quit(memc);
+
+  uint64_t counter= 0;
+  test_compare_got(MEMCACHED_SUCCESS,
+                   memcached_stat_execute(memc, NULL, item_counter, &counter),
+                   memcached_last_error_message(memc));
+  test_true_got(counter > 0, counter);
+
+  return TEST_SUCCESS;
+}
diff --git a/tests/libmemcached-1.0/stat.h b/tests/libmemcached-1.0/stat.h
new file mode 100644 (file)
index 0000000..3b85ba9
--- /dev/null
@@ -0,0 +1,40 @@
+/*  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 *);
index 50e6a3599b0924ab4896af582d5aa2a55cdd2fd1..425e308cc3a7593849e2b1b018a7918d0fac384b 100644 (file)
@@ -63,20 +63,20 @@ test_return_t test_memcached_touch(memcached_st *memc)
   memcached_return rc;
 
   test_null(memcached_get(memc, 
-                          test_literal_param("touchkey"),
+                          test_literal_param(__func__),
                           &len, &flags, &rc));
   test_zero(len);
   test_compare(MEMCACHED_NOTFOUND, rc);
 
   test_compare(MEMCACHED_SUCCESS, 
                memcached_set(memc,
-                             test_literal_param("touchkey"),
+                             test_literal_param(__func__),
                              test_literal_param("touchval"),
                              2, 0));
 
   {
     char *value= memcached_get(memc, 
-                               test_literal_param("touchkey"),
+                               test_literal_param(__func__),
                                &len, &flags, &rc);
     test_compare(8U, test_literal_param_size("touchval"));
     test_true(value);
@@ -86,15 +86,15 @@ test_return_t test_memcached_touch(memcached_st *memc)
   }
 
   test_compare(MEMCACHED_SUCCESS,
-               memcached_touch(memc, test_literal_param("touchkey"), 60 *60));
+               memcached_touch(memc, test_literal_param(__func__), 60 *60));
 
   test_skip(false ,memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
 
-  rc= memcached_touch(memc, test_literal_param("touchkey"), 60 *60 *24 *60);
+  rc= memcached_touch(memc, test_literal_param(__func__), 60 *60 *24 *60);
   test_compare_hint(MEMCACHED_SUCCESS, rc, memcached_last_error_message(memc));
 
   test_compare(MEMCACHED_NOTFOUND,
-               memcached_exist(memc, test_literal_param("touchkey")));
+               memcached_exist(memc, test_literal_param(__func__)));
 
   return TEST_SUCCESS;
 }
@@ -110,7 +110,7 @@ test_return_t test_memcached_touch_by_key(memcached_st *memc)
 
   test_null(memcached_get_by_key(memc, 
                                  test_literal_param("grouping_key"),
-                                 test_literal_param("touchkey"),
+                                 test_literal_param(__func__),
                                  &len, &flags, &rc));
   test_zero(len);
   test_compare(MEMCACHED_NOTFOUND, rc);
@@ -118,14 +118,14 @@ test_return_t test_memcached_touch_by_key(memcached_st *memc)
   test_compare(MEMCACHED_SUCCESS, 
                memcached_set_by_key(memc,
                                     test_literal_param("grouping_key"),
-                                    test_literal_param("touchkey"),
+                                    test_literal_param(__func__),
                                     test_literal_param("touchval"),
                                     2, 0));
 
   {
     char *value= memcached_get_by_key(memc, 
                                       test_literal_param("grouping_key"),
-                                      test_literal_param("touchkey"),
+                                      test_literal_param(__func__),
                                       &len, &flags, &rc);
     test_compare(8U, test_literal_param_size("touchval"));
     test_true(value);
@@ -137,17 +137,17 @@ test_return_t test_memcached_touch_by_key(memcached_st *memc)
   test_compare(MEMCACHED_SUCCESS,
                memcached_touch_by_key(memc,
                                       test_literal_param("grouping_key"),
-                                      test_literal_param("touchkey"),
+                                      test_literal_param(__func__),
                                       60 *60));
 
   test_skip(false ,memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
   test_compare(MEMCACHED_SUCCESS,
                memcached_touch_by_key(memc,
                                       test_literal_param("grouping_key"),
-                                      test_literal_param("touchkey"),
+                                      test_literal_param(__func__),
                                       60 *60 *24 *60));
   test_compare(MEMCACHED_NOTFOUND,
-               memcached_exist_by_key(memc, test_literal_param("grouping_key"),test_literal_param("touchkey")));
+               memcached_exist_by_key(memc, test_literal_param("grouping_key"),test_literal_param(__func__)));
 
   return TEST_SUCCESS;
 }