Bug 421108: memstat reports same value for bytes, bytes_read and bytes_written
authorTrond Norbye <trond.norbye@sun.com>
Tue, 6 Oct 2009 13:59:34 +0000 (15:59 +0200)
committerTrond Norbye <trond.norbye@sun.com>
Tue, 6 Oct 2009 13:59:34 +0000 (15:59 +0200)
libmemcached/memcached_stats.c
tests/function.c

index 0f4a97f75675446f1e5f8e00c06494f47c166634..04928f042eeeb799617a92fdeb14ea3362fd29f0 100644 (file)
@@ -185,8 +185,6 @@ char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *memc_stat,
     length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->curr_items);
   else if (!memcmp("total_items", key, strlen("total_items")))
     length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->total_items);
-  else if (!memcmp("bytes", key, strlen("bytes")))
-    length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->bytes);
   else if (!memcmp("curr_connections", key, strlen("curr_connections")))
     length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->curr_connections);
   else if (!memcmp("total_connections", key, strlen("total_connections")))
@@ -207,6 +205,8 @@ char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *memc_stat,
     length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->bytes_read);
   else if (!memcmp("bytes_written", key, strlen("bytes_written")))
     length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->bytes_written);
+  else if (!memcmp("bytes", key, strlen("bytes")))
+    length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->bytes);
   else if (!memcmp("limit_maxbytes", key, strlen("limit_maxbytes")))
     length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->limit_maxbytes);
   else if (!memcmp("threads", key, strlen("threads")))
index 66f819ded46c087f369c5afec045651d61b35686..e87aa28a26dcfdd20506d7de1b62cc02024ba0b0 100644 (file)
@@ -4580,6 +4580,41 @@ static test_return regression_bug_434843_buffered(memcached_st *memc)
   return regression_bug_434843(memc);
 }
 
+static test_return regression_bug_421108(memcached_st *memc)
+{
+  memcached_return rc;
+  memcached_stat_st *memc_stat= memcached_stat(memc, NULL, &rc);
+  assert(rc == MEMCACHED_SUCCESS);
+
+  char *bytes= memcached_stat_get_value(memc, memc_stat, "bytes", &rc);
+  assert(rc == MEMCACHED_SUCCESS);
+  assert(bytes != NULL);
+  char *bytes_read= memcached_stat_get_value(memc, memc_stat,
+                                             "bytes_read", &rc);
+  assert(rc == MEMCACHED_SUCCESS);
+  assert(bytes_read != NULL);
+
+  char *bytes_written= memcached_stat_get_value(memc, memc_stat,
+                                                "bytes_written", &rc);
+  assert(rc == MEMCACHED_SUCCESS);
+  assert(bytes_written != NULL);
+
+  /*
+   * We did a flush before running the test, so bytes should be 0, but
+   * bytes_read and butes_written cannot be zero ;-)
+   */
+  assert(strcmp(bytes, "0") == 0);
+  assert(strcmp(bytes, bytes_read) != 0);
+  assert(strcmp(bytes, bytes_written) != 0);
+
+  /* Release allocated resources */
+  free(bytes);
+  free(bytes_read);
+  free(bytes_written);
+  memcached_stat_free(NULL, memc_stat);
+  return TEST_SUCCESS;
+}
+
 test_st udp_setup_server_tests[] ={
   {"set_udp_behavior_test", 0, set_udp_behavior_test},
   {"add_tcp_server_udp_client_test", 0, add_tcp_server_udp_client_test},
@@ -4743,6 +4778,7 @@ test_st regression_tests[]= {
   {"lp:434484", 1, regression_bug_434484 },
   {"lp:434843", 1, regression_bug_434843 },
   {"lp:434843 buffered", 1, regression_bug_434843_buffered },
+  {"lp:421108", 1, regression_bug_421108 },
   {0, 0, 0}
 };