]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/rados-api/stat.cc: implement C++ tests
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Wed, 17 Aug 2011 00:30:34 +0000 (17:30 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Wed, 17 Aug 2011 00:30:34 +0000 (17:30 -0700)
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/test/rados-api/stat.cc

index bd1bafc5a02d7de4040387bcbdc9c48f40713ea2..d2f482675c4fffcd9462e1010de2eb48899259d6 100644 (file)
@@ -1,10 +1,12 @@
 #include "include/rados/librados.h"
+#include "include/rados/librados.hpp"
 #include "test/rados-api/test.h"
 
+#include <algorithm>
 #include <errno.h>
 #include "gtest/gtest.h"
 
-/* cluster info */
+using namespace librados;
 
 TEST(LibRadosStat, Stat) {
   char buf[128];
@@ -24,6 +26,26 @@ TEST(LibRadosStat, Stat) {
   ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
 }
 
+TEST(LibRadosStat, StatPP) {
+  char buf[128];
+  Rados cluster;
+  std::string pool_name = get_temp_pool_name();
+  ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
+  IoCtx ioctx;
+  cluster.ioctx_create(pool_name.c_str(), ioctx);
+  memset(buf, 0xcc, sizeof(buf));
+  bufferlist bl;
+  bl.append(buf, sizeof(buf));
+  ASSERT_EQ((int)sizeof(buf), ioctx.write("foo", bl, sizeof(buf), 0));
+  uint64_t size;
+  time_t mtime;
+  ASSERT_EQ(0, ioctx.stat("foo", &size, &mtime));
+  ASSERT_EQ(sizeof(buf), size);
+  ASSERT_EQ(-ENOENT, ioctx.stat("nonexistent", &size, &mtime));
+  ioctx.close();
+  ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
+}
+
 TEST(LibRadosStat, ClusterStat) {
   rados_t cluster;
   std::string pool_name = get_temp_pool_name();
@@ -33,6 +55,15 @@ TEST(LibRadosStat, ClusterStat) {
   ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
 }
 
+TEST(LibRadosStat, ClusterStatPP) {
+  Rados cluster;
+  cluster_stat_t cstat;
+  std::string pool_name = get_temp_pool_name();
+  ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
+  ASSERT_EQ(0, cluster.cluster_stat(cstat));
+  ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
+}
+
 TEST(LibRadosStat, PoolStat) {
   char buf[128];
   rados_t cluster;
@@ -45,7 +76,24 @@ TEST(LibRadosStat, PoolStat) {
   struct rados_pool_stat_t stats;
   memset(&stats, 0, sizeof(stats));
   ASSERT_EQ(0, rados_ioctx_pool_stat(ioctx, &stats));
-  ASSERT_EQ(stats.num_objects, 1u);
   rados_ioctx_destroy(ioctx);
   ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
 }
+
+TEST(LibRadosStat, PoolStatPP) {
+  Rados cluster;
+  std::string pool_name = get_temp_pool_name();
+  ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
+  IoCtx ioctx;
+  cluster.ioctx_create(pool_name.c_str(), ioctx);
+  char buf[128];
+  memset(buf, 0xff, sizeof(buf));
+  bufferlist bl1;
+  bl1.append(buf, sizeof(buf));
+  ASSERT_EQ((int)sizeof(buf), ioctx.write("foo", bl1, sizeof(buf), 0));
+  std::list<std::string> v;
+  std::map<std::string,pool_stat_t> stats;
+  ASSERT_EQ(0, cluster.get_pool_stats(v, stats));
+  ioctx.close();
+  ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
+}