BIND 10 trac1914, updated. 7919cceebc8fbeb56e7808133880aeba14b79217 [1924] Send the want_answer header from C++

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Jan 31 14:05:41 UTC 2013


The branch, trac1914 has been updated
       via  7919cceebc8fbeb56e7808133880aeba14b79217 (commit)
       via  e220a4ed9277845220c8550f24e87c16422d9dee (commit)
      from  9e8e9cb336031bf88a5f458d9c96afb0549f3042 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 7919cceebc8fbeb56e7808133880aeba14b79217
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Thu Jan 31 15:05:23 2013 +0100

    [1924] Send the want_answer header from C++

commit e220a4ed9277845220c8550f24e87c16422d9dee
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Thu Jan 31 15:01:57 2013 +0100

    [1924] Test for the C++ want_answer parameter

-----------------------------------------------------------------------

Summary of changes:
 src/lib/cc/session.cc                 |    3 +-
 src/lib/cc/session.h                  |   19 ++++++++-
 src/lib/cc/tests/session_unittests.cc |   74 ++++++++++++++++++++++++---------
 3 files changed, 73 insertions(+), 23 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/cc/session.cc b/src/lib/cc/session.cc
index 57c88ab..47923f0 100644
--- a/src/lib/cc/session.cc
+++ b/src/lib/cc/session.cc
@@ -473,7 +473,7 @@ Session::unsubscribe(std::string group, std::string instance) {
 
 int
 Session::group_sendmsg(ConstElementPtr msg, std::string group,
-                       std::string instance, std::string to)
+                       std::string instance, std::string to, bool want_answer)
 {
     LOG_DEBUG(logger, DBG_TRACE_DETAILED, CC_GROUP_SEND).arg(msg->str()).
         arg(group);
@@ -486,6 +486,7 @@ Session::group_sendmsg(ConstElementPtr msg, std::string group,
     env->set("group", Element::create(group));
     env->set("instance", Element::create(instance));
     env->set("seq", Element::create(nseq));
+    env->set("want_answer", Element::create(want_answer));
 
     sendmsg(env, msg);
     return (nseq);
diff --git a/src/lib/cc/session.h b/src/lib/cc/session.h
index a818291..e0ece56 100644
--- a/src/lib/cc/session.h
+++ b/src/lib/cc/session.h
@@ -82,7 +82,8 @@ namespace isc {
             virtual int group_sendmsg(isc::data::ConstElementPtr msg,
                                       std::string group,
                                       std::string instance = "*",
-                                      std::string to = "*") = 0;
+                                      std::string to = "*",
+                                      bool want_answer = false) = 0;
             virtual bool group_recvmsg(isc::data::ConstElementPtr& envelope,
                                        isc::data::ConstElementPtr& msg,
                                        bool nonblock = true,
@@ -128,10 +129,24 @@ namespace isc {
                                    std::string instance = "*");
             virtual void unsubscribe(std::string group,
                              std::string instance = "*");
+            /// \brief Send a message to a group.
+            ///
+            /// \todo Can someone explain how the group, instance and to work?
+            ///     What is the desired semantics here?
+            /// \param msg The message to send.
+            /// \param group Part of addressing.
+            /// \param instance Part of addressing.
+            /// \param to Part of addressing.
+            /// \param want_answer Require an answer? If it is true and there's
+            ///     no recipient, the message queue answers by an error
+            ///     instead.
+            /// \return The squence number of the message sent. It can be used
+            ///     to wait for an answer by group_recvmsg.
             virtual int group_sendmsg(isc::data::ConstElementPtr msg,
                                       std::string group,
                                       std::string instance = "*",
-                                      std::string to = "*");
+                                      std::string to = "*",
+                                      bool want_answer = false);
             virtual bool group_recvmsg(isc::data::ConstElementPtr& envelope,
                                        isc::data::ConstElementPtr& msg,
                                        bool nonblock = true,
diff --git a/src/lib/cc/tests/session_unittests.cc b/src/lib/cc/tests/session_unittests.cc
index 630c884..eb7101a 100644
--- a/src/lib/cc/tests/session_unittests.cc
+++ b/src/lib/cc/tests/session_unittests.cc
@@ -40,6 +40,8 @@ using std::string;
 using isc::data::ConstElementPtr;
 using isc::data::Element;
 
+namespace {
+
 TEST(AsioSession, establish) {
     asio::io_service io_service_;
     Session sess(io_service_);
@@ -204,6 +206,7 @@ protected:
         alarm(0);
     }
 
+    // Check two elements are equal
     void elementsEqual(const ConstElementPtr& expected,
                        const ConstElementPtr& actual)
     {
@@ -212,6 +215,7 @@ protected:
             ", got: " << actual->toWire();
     }
 
+    // The same, but with one specified as string
     void elementsEqual(const string& expected,
                        const ConstElementPtr& actual)
     {
@@ -219,6 +223,17 @@ protected:
         elementsEqual(expected_el, actual);
     }
 
+    // Check the session sent a message with the given header. The
+    // message is hardcoded.
+    void checkSentMessage(const string& expected_hdr,
+                          const char* description)
+    {
+        SCOPED_TRACE(description);
+        const SentMessage msg(tds->readmsg());
+        elementsEqual(expected_hdr, msg.first);
+        elementsEqual("{\"test\": 42}", msg.second);
+    }
+
 public:
     // used in the handler test
     // This handler first reads (and ignores) whatever message caused
@@ -344,26 +359,45 @@ TEST_F(SessionTest, group_sendmsg) {
 
     const ConstElementPtr msg(Element::fromJSON("{\"test\": 42}"));
     sess.group_sendmsg(msg, "group");
-    const SentMessage m1(tds->readmsg());
-    elementsEqual("{"
-                  "   \"from\": \"foobar\","
-                  "   \"group\": \"group\","
-                  "   \"instance\": \"*\","
-                  "   \"seq\": 0,"
-                  "   \"to\": \"*\","
-                  "   \"type\": \"send\""
-                  "}", m1.first);
-    elementsEqual(msg, m1.second);
+    checkSentMessage("{"
+                     "   \"from\": \"foobar\","
+                     "   \"group\": \"group\","
+                     "   \"instance\": \"*\","
+                     "   \"seq\": 0,"
+                     "   \"to\": \"*\","
+                     "   \"type\": \"send\","
+                     "   \"want_answer\": False"
+                     "}", "No instance");
     sess.group_sendmsg(msg, "group", "instance", "recipient");
-    const SentMessage m2(tds->readmsg());
-    elementsEqual("{"
-                  "   \"from\": \"foobar\","
-                  "   \"group\": \"group\","
-                  "   \"instance\": \"instance\","
-                  "   \"seq\": 1,"
-                  "   \"to\": \"recipient\","
-                  "   \"type\": \"send\""
-                  "}", m2.first);
-    elementsEqual(msg, m2.second);
+    checkSentMessage("{"
+                     "   \"from\": \"foobar\","
+                     "   \"group\": \"group\","
+                     "   \"instance\": \"instance\","
+                     "   \"seq\": 1,"
+                     "   \"to\": \"recipient\","
+                     "   \"type\": \"send\","
+                     "   \"want_answer\": False"
+                     "}", "With instance");
+    sess.group_sendmsg(msg, "group", "*", "*", true);
+    checkSentMessage("{"
+                     "   \"from\": \"foobar\","
+                     "   \"group\": \"group\","
+                     "   \"instance\": \"*\","
+                     "   \"seq\": 2,"
+                     "   \"to\": \"*\","
+                     "   \"type\": \"send\","
+                     "   \"want_answer\": True"
+                     "}", "Want answer");
+    sess.group_sendmsg(msg, "group", "*", "*", false);
+    checkSentMessage("{"
+                     "   \"from\": \"foobar\","
+                     "   \"group\": \"group\","
+                     "   \"instance\": \"*\","
+                     "   \"seq\": 3,"
+                     "   \"to\": \"*\","
+                     "   \"type\": \"send\","
+                     "   \"want_answer\": False"
+                     "}", "Doesn't want answer");
 }
 
+}



More information about the bind10-changes mailing list