Browse Source

[2862] Subscribe and unsubscribe on MCCS

Michal 'vorner' Vaner 11 years ago
parent
commit
87c3781cf9
2 changed files with 25 additions and 0 deletions
  1. 14 0
      src/lib/config/ccsession.h
  2. 11 0
      src/lib/config/tests/ccsession_unittests.cc

+ 14 - 0
src/lib/config/ccsession.h

@@ -575,6 +575,20 @@ public:
     /// \param id The id of request as returned by groupRecvMsgAsync.
     /// \param id The id of request as returned by groupRecvMsgAsync.
     void cancelAsyncRecv(const AsyncRecvRequestID& id);
     void cancelAsyncRecv(const AsyncRecvRequestID& id);
 
 
+    /// \brief Subscribe to a group
+    ///
+    /// Wrapper around the CCSession::subscribe.
+    void subscribe(const std::string& group) {
+        session_.subscribe(group, isc::cc::CC_INSTANCE_WILDCARD);
+    }
+
+    /// \brief Unsubscribe from a group.
+    ///
+    /// Wrapper around the CCSession::unsubscribe.
+    void unsubscribe(const std::string& group) {
+        session_.unsubscribe(group, isc::cc::CC_INSTANCE_WILDCARD);
+    }
+
 private:
 private:
     ModuleSpec readModuleSpecification(const std::string& filename);
     ModuleSpec readModuleSpecification(const std::string& filename);
     void startCheck();
     void startCheck();

+ 11 - 0
src/lib/config/tests/ccsession_unittests.cc

@@ -157,6 +157,17 @@ TEST_F(CCSessionTest, notifyNoParams) {
             session.getMsgQueue()->get(1)->toWire();
             session.getMsgQueue()->get(1)->toWire();
 }
 }
 
 
+// Try to subscribe and unsubscribe once again
+TEST_F(CCSessionTest, subscribe) {
+    ModuleCCSession mccs(ccspecfile("spec1.spec"), session, NULL, NULL, false,
+                         false);
+    EXPECT_FALSE(session.haveSubscription("A group", "*"));
+    mccs.subscribe("A group");
+    EXPECT_TRUE(session.haveSubscription("A group", "*"));
+    mccs.unsubscribe("A group");
+    EXPECT_FALSE(session.haveSubscription("A group", "*"));
+}
+
 TEST_F(CCSessionTest, createAnswer) {
 TEST_F(CCSessionTest, createAnswer) {
     ConstElementPtr answer;
     ConstElementPtr answer;
     answer = createAnswer();
     answer = createAnswer();