[asterisk-scf-commits] asterisk-scf/integration/bridging.git branch "bridge_creation_extension_points" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Aug 12 14:16:32 CDT 2011


branch "bridge_creation_extension_points" has been updated
       via  1b329fda02cc03322ef8c7fa2e23f7d75b9d0bca (commit)
      from  7b954540616dcb1f81bbb68e0e78e4549064d26d (commit)

Summary of changes:
 config/test_bridging.conf                |    3 +-
 src/BridgeCreationExtensionPointImpl.cpp |    1 +
 src/BridgeManagerImpl.cpp                |   37 +++++++-
 test/BridgeListenerI.cpp                 |   19 ++++
 test/BridgeListenerI.h                   |    2 +
 test/TestBridging.cpp                    |  156 +++++++++++++++++++++++++++++-
 6 files changed, 214 insertions(+), 4 deletions(-)


- Log -----------------------------------------------------------------
commit 1b329fda02cc03322ef8c7fa2e23f7d75b9d0bca
Author: Brent Eagles <beagles at digium.com>
Date:   Fri Aug 12 16:45:01 2011 -0230

    Add small simple test for extension points directly to component test. Also fixed some test bugs
    with respect to waiting for state chnages.

diff --git a/config/test_bridging.conf b/config/test_bridging.conf
index c8cb3c8..4f0d863 100644
--- a/config/test_bridging.conf
+++ b/config/test_bridging.conf
@@ -138,12 +138,13 @@ TestChannel.InstanceName=BridgeTest
 #
 TestBridge.InstanceName=TestBridge
 TestBridge.ManagerId=TestBridgeManager
+TestBridge.Standby=false
 # TestBridge.Endpoints=default -p 57000
 # TestBridge.Backplane.Endpoints=default -p 57001
 
 TestBridge2.InstanceName=TestBridge2
 TestBridge2.ManagerId=TestBridgeManager2
-TestBridge2.Standby=yes
+TestBridge2.Standby=true
 TestBridge2.Endpoints=default -p 57010
 TestBridge2.Backplane.Endpoints=default -p 57011
 
diff --git a/src/BridgeCreationExtensionPointImpl.cpp b/src/BridgeCreationExtensionPointImpl.cpp
index bc7c01e..6a4ab31 100755
--- a/src/BridgeCreationExtensionPointImpl.cpp
+++ b/src/BridgeCreationExtensionPointImpl.cpp
@@ -74,6 +74,7 @@ namespace
 
         BridgeCreationHookDataPtr runHooks(const BridgeCreationHookDataPtr& originalData)
         {
+            mLogger(Debug) << "executing hooks";
             BridgeCreationHookSeq hooks = getHooks();
             BridgeCreationHookSeq deadHooks;
             BridgeCreationHookDataPtr tokenData = BridgeCreationHookDataPtr::dynamicCast(originalData->ice_clone());
diff --git a/src/BridgeManagerImpl.cpp b/src/BridgeManagerImpl.cpp
index b86241a..64a3ad6 100644
--- a/src/BridgeManagerImpl.cpp
+++ b/src/BridgeManagerImpl.cpp
@@ -42,6 +42,38 @@ using namespace std;
 namespace 
 {
 
+#ifndef _NDEBUG
+void dump(const Logger& logger, const BridgeCreationHookDataPtr& hookData)
+{
+    ostringstream os;
+    os << "Hook data:";
+    string indent = "   ";
+    string prefix = "\n";
+    os <<  prefix << indent << "decorator/original proxy: " << hookData->bridge;
+    os <<  prefix << indent << "listeners (" << hookData->listeners.size() << ')';
+
+    for (BridgeListenerSeq::const_iterator i = hookData->listeners.begin(); i != hookData->listeners.end(); ++i)
+    {
+        os << prefix << indent << indent << *i;
+    }
+    os <<  prefix << indent << "cookies (" << hookData->cookies.size() << ')';
+    for (BridgeCookies::const_iterator i = hookData->cookies.begin(); i != hookData->cookies.end(); ++i)
+    {
+        os << prefix << indent << indent << (*i)->ice_id();
+    }
+    os <<  prefix << indent << "sessions (" << hookData->initialSessions.size() << ')';
+    for (SessionSeq::const_iterator i = hookData->initialSessions.begin(); i != hookData->initialSessions.end(); ++i)
+    {
+        os << prefix << indent << indent << (*i);
+    }
+    logger(Debug) << os.str();
+}
+#else
+void dump(const Logger&, const BridgeCreationHookDataPtr&)
+{
+}
+#endif
+
 class BridgeManagerImpl : public BridgeManagerServant
 {
 public:
@@ -196,7 +228,7 @@ void BridgeManagerImpl::createBridge_async(const AMD_BridgeManager_createBridgeP
             listeners.push_back(listener);
         }
 
-        SessionSeq initialSessions;
+        SessionSeq initialSessions(sessions);
         BridgeCreationHookDataPtr originalData;
         BridgeInfo info;
         info.proxy = prx;
@@ -210,6 +242,7 @@ void BridgeManagerImpl::createBridge_async(const AMD_BridgeManager_createBridgeP
             listeners = originalData->listeners;
             initialSessions = originalData->initialSessions;
             info.decoratingPrx = originalData->bridge;
+            dump(mLogger, originalData);
         }
         BridgeListenerMgrPtr mgr(new BridgeListenerMgr(mAdapter->getCommunicator(), stringId, info.decoratingPrx));
 
@@ -235,7 +268,7 @@ void BridgeManagerImpl::createBridge_async(const AMD_BridgeManager_createBridgeP
         }
 
         QueuedTasks tasks;
-        if (!sessions.empty())
+        if (!initialSessions.empty())
         {
             bridge->getAddSessionsTasks(tasks, initialSessions);
         }
diff --git a/test/BridgeListenerI.cpp b/test/BridgeListenerI.cpp
index 8a95767..83b659f 100644
--- a/test/BridgeListenerI.cpp
+++ b/test/BridgeListenerI.cpp
@@ -28,6 +28,7 @@ void BridgeListenerI::sessionsAdded(const AsteriskSCF::SessionCommunications::V1
     const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions, 
     const AsteriskSCF::SessionCommunications::V1::BridgeCookies& cookies, const Ice::Current&)
 {
+    cerr << "xxx added" << endl;
     updateCookieMap("sessionsAdded", cookies);
     IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mAddMonitor);
     mAdded =sessions;
@@ -38,6 +39,7 @@ void BridgeListenerI::sessionsRemoved(const AsteriskSCF::SessionCommunications::
     const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions, 
     const AsteriskSCF::SessionCommunications::V1::BridgeCookies& cookies, const Ice::Current&)
 {
+    cerr << "xxx removed" << endl;
     updateCookieMap("sessionsRemoved", cookies);
     IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mRemoveMonitor);
     mRemoved = sessions;
@@ -47,6 +49,7 @@ void BridgeListenerI::sessionsRemoved(const AsteriskSCF::SessionCommunications::
 void BridgeListenerI::stopping(const AsteriskSCF::SessionCommunications::V1::BridgePrx&, 
     const AsteriskSCF::SessionCommunications::V1::BridgeCookies& cookies, const Ice::Current&)
 {
+    cerr << "xxx stopping" << endl;
     updateCookieMap("stopping", cookies);
     IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mStateMonitor);
     mShuttingDown = true;
@@ -56,6 +59,7 @@ void BridgeListenerI::stopping(const AsteriskSCF::SessionCommunications::V1::Bri
 void BridgeListenerI::stopped(const AsteriskSCF::SessionCommunications::V1::BridgePrx&, 
     const AsteriskSCF::SessionCommunications::V1::BridgeCookies& cookies, const Ice::Current&)
 {
+    cerr << "xxx stopped" << endl;
     updateCookieMap("stopped", cookies);
     IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mStateMonitor);
     mStopped = true;
@@ -96,9 +100,24 @@ bool BridgeListenerI::waitForRemoved(unsigned long milliseconds, AsteriskSCF::Se
     return !removed.empty();
 }
 
+bool BridgeListenerI::waitForStopping(unsigned long milliseconds)
+{
+    IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mStateMonitor);
+    if (mShuttingDown)
+    {
+        return true;
+    }
+    mStateMonitor.timedWait(IceUtil::Time::milliSeconds(milliseconds));
+    return mShuttingDown;
+}
+
 bool BridgeListenerI::waitForStopped(unsigned long milliseconds)
 {
     IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mStateMonitor);
+    if (mStopped)
+    {
+        return true;
+    }
     mStateMonitor.timedWait(IceUtil::Time::milliSeconds(milliseconds));
     return mStopped;
 }
diff --git a/test/BridgeListenerI.h b/test/BridgeListenerI.h
index 881de6b..ebe6eba 100644
--- a/test/BridgeListenerI.h
+++ b/test/BridgeListenerI.h
@@ -44,6 +44,7 @@ public:
 
     bool waitForAdded(unsigned long milliseconds, AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions);
     bool waitForRemoved(unsigned long milliseconds, AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions);
+    bool waitForStopping(unsigned long milliseconds);
     bool waitForStopped(unsigned long milliseconds);
 
     size_t addedCount();
@@ -54,6 +55,7 @@ public:
 private:
     bool mShuttingDown;
     bool mStopped;
+    bool mStopping;
 
     IceUtil::Monitor<IceUtil::Mutex> mAddMonitor;
     IceUtil::Monitor<IceUtil::Mutex> mRemoveMonitor;
diff --git a/test/TestBridging.cpp b/test/TestBridging.cpp
index f23c73c..fc6c6c7 100644
--- a/test/TestBridging.cpp
+++ b/test/TestBridging.cpp
@@ -20,6 +20,7 @@
 #include <boost/test/unit_test.hpp>
 #include <boost/test/debug.hpp>
 #include <AsteriskSCF/SessionCommunications/SessionCommunicationsIf.h>
+#include <AsteriskSCF/SessionCommunications/SessionCommunicationsExtensionPointsIf.h>
 #include <AsteriskSCF/Media/MediaIf.h>
 #include <AsteriskSCF/System/Component/ReplicaIf.h>
 #include <IceUtil/UUID.h>
@@ -40,6 +41,7 @@
 
 using namespace AsteriskSCF::BridgingTest;
 using namespace AsteriskSCF::SessionCommunications::V1;
+using namespace AsteriskSCF::SessionCommunications::ExtensionPoints::V1;
 using namespace AsteriskSCF::Core::Discovery::V1;
 using namespace AsteriskSCF::Core::Routing::V1;
 using namespace AsteriskSCFTest;
@@ -50,6 +52,51 @@ using namespace std;
 namespace
 {
 
+class TestCreationHook : public BridgeCreationHook
+{
+public:
+
+    void addCookies(const BridgeCookies& cookies)
+    {
+        mCookies = cookies;
+    }
+
+    void addListeners(const BridgeListenerSeq& listeners)
+    {
+        mListeners = listeners;
+    }
+    
+    void addSessions(const SessionSeq& sessions)
+    {
+        mSessions = sessions;
+    }
+
+    void setResult(AsteriskSCF::System::Hook::V1::HookResult resultValue)
+    {
+        mResult = resultValue;
+    }
+
+    AsteriskSCF::System::Hook::V1::HookResult execute(const BridgeCreationHookDataPtr& originalData, 
+        BridgeCreationHookDataPtr& newData, const Ice::Current&)
+    {
+        newData = BridgeCreationHookDataPtr::dynamicCast(originalData->ice_clone());
+        newData->cookies.insert(newData->cookies.end(), mCookies.begin(), mCookies.end());
+        newData->listeners.insert(newData->listeners.end(), mListeners.begin(), mListeners.end());
+        newData->initialSessions.insert(newData->initialSessions.end(), mSessions.begin(), mSessions.end());
+        cerr << "XXX " << newData->cookies.size() << endl;
+        cerr << "XXX " << newData->listeners.size() << endl;
+        cerr << "XXX " << newData->initialSessions.size() << endl;
+        return mResult;
+    }
+
+private:
+    BridgeCookies mCookies;
+    BridgeListenerSeq mListeners;
+    SessionSeq mSessions;
+    AsteriskSCF::System::Hook::V1::HookResult mResult;
+};
+typedef IceUtil::Handle<TestCreationHook> TestCreationHookPtr;
+
 BridgeCookies bakeTestCookies()
 {
     BridgeCookies result;
@@ -1069,11 +1116,12 @@ public:
                 returnedCookies = cookieMap["sessionsRemoved"];
                 tasteCookies(returnedCookies);
 
-                BOOST_REQUIRE(bridgeListener->waitForStopped(5000));
+                BOOST_REQUIRE(bridgeListener->waitForStopping(5000));
                 cookieMap = bridgeListener->getCookieMap();
                 BOOST_REQUIRE(cookieMap.find("stopping") != cookieMap.end());
                 returnedCookies = cookieMap["stopping"];
                 tasteCookies(returnedCookies);
+                BOOST_REQUIRE(bridgeListener->waitForStopped(5000));
                 BOOST_REQUIRE(cookieMap.find("stopped") != cookieMap.end());
                 returnedCookies = cookieMap["stopped"];
                 BOOST_REQUIRE(!returnedCookies.empty());
@@ -1198,6 +1246,110 @@ public:
         }
     }
 
+    void extensionPointTest()
+    {
+        try
+        {
+            IceEnvironment testEnv(env()->properties());
+            try
+            {
+                Ice::ObjectAdapterPtr testAdapter =  testEnv.communicator()->createObjectAdapter("TestUtilAdapter");
+                testAdapter->activate();
+                BridgeManagerListenerIPtr servant = new BridgeManagerListenerI;
+                AsteriskSCF::SessionCommunications::V1::BridgeManagerListenerPrx listenerPrx;
+                addServant(listenerPrx, testAdapter, servant, testEnv.strToIdent(IceUtil::generateUUID()));
+
+                AsteriskSCF::SessionCommunications::V1::BridgeManagerPrx mgrPrx = env()->primaryBridgeManager();
+                BOOST_CHECK(mgrPrx);
+                mgrPrx->addListener(listenerPrx);
+                BOOST_CHECK(servant->stoppingCalls() == 0);
+                BOOST_CHECK(servant->stoppedCalls() == 0);
+                BOOST_CHECK(servant->createCalls() == 0);
+
+                AsteriskSCF::SessionCommunications::ExtensionPoints::V1::BridgeCreationExtensionPointPrx 
+                    extPoint = AsteriskSCF::SessionCommunications::ExtensionPoints::V1::
+                    BridgeCreationExtensionPointPrx::checkedCast(mgrPrx,
+                        AsteriskSCF::SessionCommunications::ExtensionPoints::V1::BridgeCreationExtensionPointFacet);
+                BOOST_REQUIRE(extPoint);
+
+                TestCreationHookPtr hook(new TestCreationHook);
+                AsteriskSCF::SessionCommunications::ExtensionPoints::V1::BridgeCreationHookPrx hookPrx;
+                addServant(hookPrx, testAdapter, hook, testEnv.strToIdent(IceUtil::generateUUID()));
+                extPoint->addHook(hookPrx);
+
+                TestChannelWrapper channel(env()->properties());
+                AsteriskSCF::SessionCommunications::V1::SessionSeq sessions;
+                AsteriskSCF::SessionCommunications::V1::SessionPrx a = channel.getSession("311");
+                AsteriskSCF::SessionCommunications::V1::SessionPrx b = channel.getSession("312");
+                sessions.push_back(a);
+                sessions.push_back(b);
+                hook->addSessions(sessions);
+                sessions.clear();
+
+                AsteriskSCF::BridgingTest::BridgeListenerPtr bridgeListener = new BridgeListenerI;
+                AsteriskSCF::SessionCommunications::V1::BridgeListenerPrx bridgeListenerPrx;
+                addServant(bridgeListenerPrx, testAdapter, bridgeListener, testEnv.strToIdent(IceUtil::generateUUID()));
+                BridgeListenerSeq listeners;
+                listeners.push_back(bridgeListenerPrx);
+                hook->addListeners(listeners);
+
+                BridgeCookies testCookies = bakeTestCookies();
+                hook->addCookies(testCookies);
+
+                AsteriskSCF::SessionCommunications::V1::BridgePrx bridge(mgrPrx->createBridge(sessions, 0));
+
+                //
+                // precondition checks for test validity.
+                //
+                std::string idA = testEnv.communicator()->identityToString(a->ice_getIdentity());
+                std::string idB = testEnv.communicator()->identityToString(b->ice_getIdentity());
+                std::vector<std::string> log;
+                channel.commands()->getlog(idA, log);
+                BOOST_CHECK(!find(log, "start"));
+                channel.commands()->getlog(idB, log);
+                BOOST_CHECK(!find(log, "start"));
+
+                AsteriskSCF::SessionCommunications::V1::SessionSeq eventSessions;
+                BridgeCookies returnedCookies = bridge->getCookies(testCookies);
+                tasteCookies(returnedCookies);
+
+                sessions.push_back(b);
+                eventSessions.clear();
+                bridge->removeSessions(sessions);
+                BOOST_REQUIRE(bridgeListener->waitForRemoved(5000, eventSessions));
+                CookieMap cookieMap = bridgeListener->getCookieMap();
+                BOOST_REQUIRE(!cookieMap.empty());
+                BOOST_REQUIRE(cookieMap.find("sessionsRemoved") != cookieMap.end());
+                returnedCookies = cookieMap["sessionsRemoved"];
+                tasteCookies(returnedCookies);
+
+                BOOST_REQUIRE(bridgeListener->waitForStopped(5000));
+                cookieMap = bridgeListener->getCookieMap();
+                BOOST_REQUIRE(cookieMap.find("stopping") != cookieMap.end());
+                returnedCookies = cookieMap["stopping"];
+                tasteCookies(returnedCookies);
+                BOOST_REQUIRE(cookieMap.find("stopped") != cookieMap.end());
+                returnedCookies = cookieMap["stopped"];
+                BOOST_REQUIRE(!returnedCookies.empty());
+                tasteCookies(returnedCookies);
+            }
+            catch (const Ice::Exception& ex)
+            {
+                std::ostringstream msg;
+                msg << "Unexpected Ice exception " << ex.what();
+                BOOST_FAIL(msg.str());
+            }
+            catch (...)
+            {
+                BOOST_FAIL("Unexpected exception");
+            }
+        }
+        catch (...)
+        {
+            BOOST_FAIL("Unexpected exception");
+        }
+    }
+
 private:
     TestEnvironmentPtr mTestEnvironment;
 };
@@ -1225,6 +1377,8 @@ bool init_unit_test()
         add(BOOST_TEST_CASE(boost::bind(&BridgeTester::simpleCookieAddTest, bridgeTester)));
     framework::master_test_suite().
         add(BOOST_TEST_CASE(boost::bind(&BridgeTester::cookieAddRemoveTest, bridgeTester)));
+    framework::master_test_suite().
+        add(BOOST_TEST_CASE(boost::bind(&BridgeTester::extensionPointTest, bridgeTester)));
     return true;
 }
 

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


-- 
asterisk-scf/integration/bridging.git



More information about the asterisk-scf-commits mailing list