]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cls_refcount: add type tests
authorSage Weil <sage@inktank.com>
Fri, 12 Jul 2013 18:14:19 +0000 (11:14 -0700)
committerSage Weil <sage@inktank.com>
Fri, 12 Jul 2013 18:14:19 +0000 (11:14 -0700)
Signed-off-by: Sage Weil <sage@inktank.com>
src/Makefile.am
src/cls/refcount/cls_refcount_ops.cc [new file with mode: 0644]
src/cls/refcount/cls_refcount_ops.h
src/common/ceph_json.h
src/test/encoding/ceph_dencoder.cc
src/test/encoding/types.h

index e2e60720dac13e21cde5c24d1382b0231be576c7..64a1da80b48823076a4f125ef4196b832bc769ee 100644 (file)
@@ -153,7 +153,9 @@ rgw_dencoder_src = rgw/rgw_dencoder.cc \
 ceph_dencoder_SOURCES = test/encoding/ceph_dencoder.cc ${rgw_dencoder_src} perfglue/disabled_heap_profiler.cc
 ceph_dencoder_CXXFLAGS = ${AM_CXXFLAGS}
 ceph_dencoder_LDADD = $(LIBGLOBAL_LDA) libcls_lock_client.a \
-                         libcls_rgw_client.a libcls_replica_log_client.a \
+                         libcls_rgw_client.a \
+                         libcls_replica_log_client.a \
+                         libcls_refcount_client.a \
                          libosd.a libmds.a libosdc.la $(LIBOS_LDA) libmon.a
 bin_PROGRAMS += ceph-dencoder
 
@@ -550,7 +552,7 @@ libcls_lock_la_LDFLAGS = ${AM_LDFLAGS} -version-info 1:0:0 -export-symbols-regex
 radoslib_LTLIBRARIES += libcls_lock.la
 
 # refcount class
-libcls_refcount_la_SOURCES = cls/refcount/cls_refcount.cc
+libcls_refcount_la_SOURCES = cls/refcount/cls_refcount.cc cls/refcount/cls_refcount_ops.cc
 libcls_refcount_la_CFLAGS = ${AM_CFLAGS}
 libcls_refcount_la_CXXFLAGS= ${AM_CXXFLAGS}
 libcls_refcount_la_LIBADD = $(PTHREAD_LIBS) $(EXTRALIBS)
@@ -611,7 +613,8 @@ libcls_lock_client_a_SOURCES =  \
 noinst_LIBRARIES += libcls_lock_client.a
 
 libcls_refcount_client_a_SOURCES =  \
-       cls/refcount/cls_refcount_client.cc
+       cls/refcount/cls_refcount_client.cc \
+       cls/refcount/cls_refcount_ops.cc
 noinst_LIBRARIES += libcls_refcount_client.a
 
 libcls_version_client_a_SOURCES =  \
diff --git a/src/cls/refcount/cls_refcount_ops.cc b/src/cls/refcount/cls_refcount_ops.cc
new file mode 100644 (file)
index 0000000..1c6a3b3
--- /dev/null
@@ -0,0 +1,80 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "cls_refcount_ops.h"
+#include "common/Formatter.h"
+#include "common/ceph_json.h"
+
+void cls_refcount_get_op::dump(ceph::Formatter *f) const
+{
+  f->dump_string("tag", tag);
+  f->dump_int("implicit_ref", (int)implicit_ref);
+}
+
+void cls_refcount_get_op::generate_test_instances(list<cls_refcount_get_op*>& ls)
+{
+  ls.push_back(new cls_refcount_get_op);
+  ls.push_back(new cls_refcount_get_op);
+  ls.back()->tag = "foo";
+  ls.back()->implicit_ref = true;
+}
+
+
+void cls_refcount_put_op::dump(ceph::Formatter *f) const
+{
+  f->dump_string("tag", tag);
+  f->dump_int("implicit_ref", (int)implicit_ref);
+}
+
+void cls_refcount_put_op::generate_test_instances(list<cls_refcount_put_op*>& ls)
+{
+  ls.push_back(new cls_refcount_put_op);
+  ls.push_back(new cls_refcount_put_op);
+  ls.back()->tag = "foo";
+  ls.back()->implicit_ref = true;
+}
+
+
+
+void cls_refcount_set_op::dump(ceph::Formatter *f) const
+{
+  encode_json("refs", refs, f);
+}
+
+void cls_refcount_set_op::generate_test_instances(list<cls_refcount_set_op*>& ls)
+{
+  ls.push_back(new cls_refcount_set_op);
+  ls.push_back(new cls_refcount_set_op);
+  ls.back()->refs.push_back("foo");
+  ls.back()->refs.push_back("bar");
+}
+
+
+void cls_refcount_read_op::dump(ceph::Formatter *f) const
+{
+  f->dump_int("implicit_ref", (int)implicit_ref);
+}
+
+void cls_refcount_read_op::generate_test_instances(list<cls_refcount_read_op*>& ls)
+{
+  ls.push_back(new cls_refcount_read_op);
+  ls.push_back(new cls_refcount_read_op);
+  ls.back()->implicit_ref = true;
+}
+
+
+void cls_refcount_read_ret::dump(ceph::Formatter *f) const
+{
+  f->open_array_section("refs");
+  for (list<string>::const_iterator p = refs.begin(); p != refs.end(); ++p)
+    f->dump_string("ref", *p);
+  f->close_section();
+}
+
+void cls_refcount_read_ret::generate_test_instances(list<cls_refcount_read_ret*>& ls)
+{
+  ls.push_back(new cls_refcount_read_ret);
+  ls.push_back(new cls_refcount_read_ret);
+  ls.back()->refs.push_back("foo");
+  ls.back()->refs.push_back("bar");
+}
index 6126b8db46695becc2325b211e1e8ada4c1c542f..813a1c1c96bda50545cd72cdb2c3eb31fbf19e78 100644 (file)
@@ -8,6 +8,8 @@
 
 #include "include/types.h"
 
+class Formatter;
+
 struct cls_refcount_get_op {
   string tag;
   bool implicit_ref;
@@ -27,6 +29,8 @@ struct cls_refcount_get_op {
     ::decode(implicit_ref, bl);
     DECODE_FINISH(bl);
   }
+  void dump(ceph::Formatter *f) const;
+  static void generate_test_instances(list<cls_refcount_get_op*>& ls);
 };
 WRITE_CLASS_ENCODER(cls_refcount_get_op)
 
@@ -50,6 +54,9 @@ struct cls_refcount_put_op {
     ::decode(implicit_ref, bl);
     DECODE_FINISH(bl);
   }
+
+  void dump(ceph::Formatter *f) const;
+  static void generate_test_instances(list<cls_refcount_put_op*>& ls);
 };
 WRITE_CLASS_ENCODER(cls_refcount_put_op)
 
@@ -69,6 +76,9 @@ struct cls_refcount_set_op {
     ::decode(refs, bl);
     DECODE_FINISH(bl);
   }
+
+  void dump(ceph::Formatter *f) const;
+  static void generate_test_instances(list<cls_refcount_set_op*>& ls);
 };
 WRITE_CLASS_ENCODER(cls_refcount_set_op)
 
@@ -89,6 +99,9 @@ struct cls_refcount_read_op {
     ::decode(implicit_ref, bl);
     DECODE_FINISH(bl);
   }
+
+  void dump(ceph::Formatter *f) const;
+  static void generate_test_instances(list<cls_refcount_read_op*>& ls);
 };
 WRITE_CLASS_ENCODER(cls_refcount_read_op)
 
@@ -108,6 +121,9 @@ struct cls_refcount_read_ret {
     ::decode(refs, bl);
     DECODE_FINISH(bl);
   }
+
+  void dump(ceph::Formatter *f) const;
+  static void generate_test_instances(list<cls_refcount_read_ret*>& ls);
 };
 WRITE_CLASS_ENCODER(cls_refcount_read_ret)
 
index 67efeae0e2a1388b49b381e46f87bed788e1abcf..32f5dcfc6fed33b0e2afa40e97422188d95dcb34 100644 (file)
@@ -252,7 +252,7 @@ void JSONDecoder::decode_json(const char *name, T& val, T& default_val, JSONObj
 }
 
 template<class T>
-static void encode_json(const char *name, const T& val, Formatter *f)
+static void encode_json(const char *name, const T& val, ceph::Formatter *f)
 {
   f->open_object_section(name);
   val.dump(f);
@@ -261,21 +261,21 @@ static void encode_json(const char *name, const T& val, Formatter *f)
 
 class utime_t;
 
-void encode_json(const char *name, const string& val, Formatter *f);
-void encode_json(const char *name, const char *val, Formatter *f);
-void encode_json(const char *name, bool val, Formatter *f);
-void encode_json(const char *name, int val, Formatter *f);
-void encode_json(const char *name, unsigned val, Formatter *f);
-void encode_json(const char *name, long val, Formatter *f);
-void encode_json(const char *name, unsigned long val, Formatter *f);
-void encode_json(const char *name, long long val, Formatter *f);
-void encode_json(const char *name, const utime_t& val, Formatter *f);
-void encode_json(const char *name, const bufferlist& bl, Formatter *f);
-void encode_json(const char *name, long long val, Formatter *f);
-void encode_json(const char *name, long long unsigned val, Formatter *f);
+void encode_json(const char *name, const string& val, ceph::Formatter *f);
+void encode_json(const char *name, const char *val, ceph::Formatter *f);
+void encode_json(const char *name, bool val, ceph::Formatter *f);
+void encode_json(const char *name, int val, ceph::Formatter *f);
+void encode_json(const char *name, unsigned val, ceph::Formatter *f);
+void encode_json(const char *name, long val, ceph::Formatter *f);
+void encode_json(const char *name, unsigned long val, ceph::Formatter *f);
+void encode_json(const char *name, long long val, ceph::Formatter *f);
+void encode_json(const char *name, const utime_t& val, ceph::Formatter *f);
+void encode_json(const char *name, const bufferlist& bl, ceph::Formatter *f);
+void encode_json(const char *name, long long val, ceph::Formatter *f);
+void encode_json(const char *name, long long unsigned val, ceph::Formatter *f);
 
 template<class K, class V>
-static void encode_json(const char *name, const std::map<K, V>& m, Formatter *f)
+static void encode_json(const char *name, const std::map<K, V>& m, ceph::Formatter *f)
 {
   f->open_array_section(name);
   for (typename std::map<K, V>::const_iterator i = m.begin(); i != m.end(); ++i) {
@@ -288,7 +288,7 @@ static void encode_json(const char *name, const std::map<K, V>& m, Formatter *f)
 }
 
 template<class T>
-static void encode_json(const char *name, const std::list<T>& l, Formatter *f)
+static void encode_json(const char *name, const std::list<T>& l, ceph::Formatter *f)
 {
   f->open_array_section(name);
   for (typename std::list<T>::const_iterator iter = l.begin(); iter != l.end(); ++iter) {
@@ -298,7 +298,7 @@ static void encode_json(const char *name, const std::list<T>& l, Formatter *f)
 }
 
 template<class K, class V>
-void encode_json_map(const char *name, const map<K, V>& m, Formatter *f)
+void encode_json_map(const char *name, const map<K, V>& m, ceph::Formatter *f)
 {
   f->open_array_section(name);
   typename map<K,V>::const_iterator iter;
@@ -312,8 +312,8 @@ void encode_json_map(const char *name, const map<K, V>& m, Formatter *f)
 template<class K, class V>
 void encode_json_map(const char *name, const char *index_name,
                      const char *object_name, const char *value_name,
-                     void (*cb)(const char *, const V&, Formatter *, void *), void *parent,
-                     const map<K, V>& m, Formatter *f)
+                     void (*cb)(const char *, const V&, ceph::Formatter *, void *), void *parent,
+                     const map<K, V>& m, ceph::Formatter *f)
 {
   f->open_array_section(name);
   typename map<K,V>::const_iterator iter;
@@ -346,14 +346,14 @@ void encode_json_map(const char *name, const char *index_name,
 template<class K, class V>
 void encode_json_map(const char *name, const char *index_name,
                      const char *object_name, const char *value_name,
-                     const map<K, V>& m, Formatter *f)
+                     const map<K, V>& m, ceph::Formatter *f)
 {
   encode_json_map<K, V>(name, index_name, object_name, value_name, NULL, NULL, m, f);
 }
 
 template<class K, class V>
 void encode_json_map(const char *name, const char *index_name, const char *value_name,
-                     const map<K, V>& m, Formatter *f)
+                     const map<K, V>& m, ceph::Formatter *f)
 {
   encode_json_map<K, V>(name, index_name, NULL, value_name, NULL, NULL, m, f);
 }
index b98edcb61eecf275b1a8c0a7497e1b37561920e1..81abcd1de9e3b9d151e06feb6a1f429799050457 100644 (file)
@@ -44,7 +44,7 @@ struct Dencoder {
   virtual ~Dencoder() {}
   virtual string decode(bufferlist bl) = 0;
   virtual void encode(bufferlist& out, uint64_t features) = 0;
-  virtual void dump(Formatter *f) = 0;
+  virtual void dump(ceph::Formatter *f) = 0;
   virtual void generate() = 0;
   virtual int num_generated() = 0;
   virtual string select_generated(unsigned n) = 0;
@@ -79,7 +79,7 @@ public:
 
   virtual void encode(bufferlist& out, uint64_t features) = 0;
 
-  void dump(Formatter *f) {
+  void dump(ceph::Formatter *f) {
     m_object->dump(f);
   }
 
@@ -163,7 +163,7 @@ public:
     encode_message(m_object, features, out);
   }
 
-  void dump(Formatter *f) {
+  void dump(ceph::Formatter *f) {
     m_object->dump(f);
   }
 
index e3349a02f0b0a446fcc05081829bf6ccccee5520..ee389d653d2121d16424a24c5c36cba47b64b0ef 100644 (file)
@@ -250,6 +250,14 @@ TYPE(cls_replica_log_set_marker_op)
 TYPE(cls_replica_log_get_bounds_op)
 TYPE(cls_replica_log_get_bounds_ret)
 
+#include "cls/refcount/cls_refcount_ops.h"
+TYPE(cls_refcount_get_op)
+TYPE(cls_refcount_put_op)
+TYPE(cls_refcount_read_op)
+TYPE(cls_refcount_read_ret)
+TYPE(cls_refcount_set_op)
+
+
 // --- messages ---
 #include "messages/MAuth.h"
 MESSAGE(MAuth)