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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Jul 19 09:59:32 CDT 2011


branch "basecomponent" has been updated
       via  1dfec49b2055048058eafee06954c2325a18ae3d (commit)
      from  c7526b263e28dbda80f8efb88efae882bcdfffe1 (commit)

Summary of changes:
 config/test_bridging.conf          |    9 ++-
 src/CMakeLists.txt                 |    2 +-
 src/{Service.cpp => Component.cpp} |  133 +++++++++++++++++++++---------------
 test/TestBridging.cpp              |  102 ++++++++++++++++++++--------
 4 files changed, 156 insertions(+), 90 deletions(-)
 rename src/{Service.cpp => Component.cpp} (63%)


- Log -----------------------------------------------------------------
commit 1dfec49b2055048058eafee06954c2325a18ae3d
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Tue Jul 19 09:58:45 2011 -0500

    Updates esp. to test cases for changes due to Component usage.

diff --git a/config/test_bridging.conf b/config/test_bridging.conf
index 6f31fe4..c8cb3c8 100644
--- a/config/test_bridging.conf
+++ b/config/test_bridging.conf
@@ -132,8 +132,9 @@ TestChannel.InstanceName=BridgeTest
 #
 # Configuration for the test bridge instances. There are are two: one master
 # (TestBridge) and one standby (TestBridge2).
-# For testing purposes, you may wish to uncomment the explicit endpoint 
-# specification.
+# For testing purposes we're providing explicit endpoints for the standby 
+# component. Endpoints will be assigned random unused ports if not 
+# explicitly set. 
 #
 TestBridge.InstanceName=TestBridge
 TestBridge.ManagerId=TestBridgeManager
@@ -143,8 +144,8 @@ TestBridge.ManagerId=TestBridgeManager
 TestBridge2.InstanceName=TestBridge2
 TestBridge2.ManagerId=TestBridgeManager2
 TestBridge2.Standby=yes
-# TestBridge2.Endpoints=default -p 57010
-# TestBridge2.Backplane.Endpoints=default -p 57011
+TestBridge2.Endpoints=default -p 57010
+TestBridge2.Backplane.Endpoints=default -p 57011
 
 #
 # Configuration for the bridge state replicator.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0f87b1e..ccc9502 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -5,7 +5,7 @@ include_directories(${ice-util-cpp_dir}/include)
 asterisk_scf_slice_include_directories(${API_SLICE_DIR})
 
 asterisk_scf_component_init(bridgeservice)
-asterisk_scf_component_add_file(bridgeservice Service.cpp)
+asterisk_scf_component_add_file(bridgeservice Component.cpp)
 asterisk_scf_component_add_file(bridgeservice BridgeImpl.h)
 asterisk_scf_component_add_file(bridgeservice BridgeImpl.cpp)
 asterisk_scf_component_add_file(bridgeservice BridgeListenerMgr.h)
diff --git a/src/Service.cpp b/src/Component.cpp
similarity index 63%
rename from src/Service.cpp
rename to src/Component.cpp
index da2c161..8295f00 100644
--- a/src/Service.cpp
+++ b/src/Component.cpp
@@ -36,8 +36,6 @@ using namespace AsteriskSCF::Core::Discovery::V1;
 using namespace AsteriskSCF::System::Component::V1;
 using namespace AsteriskSCF::BridgeService;
 using namespace AsteriskSCF::Bridge::V1;
-using namespace AsteriskSCF;
-using namespace AsteriskSCF::Component;
 using namespace AsteriskSCF::Replication;
 using namespace AsteriskSCF::Discovery;
 using namespace std;
@@ -51,45 +49,43 @@ Logger lg = getLoggerFactory().getLogger("AsteriskSCF.BridgeService");
 namespace
 {
 
-class BridgingApp : public Component
+class Component : public AsteriskSCF::Component::Component
 {
 public:
-    BridgingApp();
+    Component() : 
+        AsteriskSCF::Component::Component(lg, 
+                                          "BridgeService"),
+        mListeningToReplicator(false)   {}
 
-protected:
-    // Optional notification overrides. 
+private:
+    // Optional base Component notification overrides. 
     virtual void onActivated();
     virtual void onPreInitialize();
     virtual void onPostInitialize();
     virtual void onStop();
 
-    // Required Component overrides
+    // Required base Component overrides
     virtual void createPrimaryServices();
-    virtual void registerPrimaryServices();
+    virtual void preparePrimaryServicesForDiscovery();
     virtual void createReplicationStateListeners();
     virtual void stopListeningToStateReplicators();
     virtual void listenToStateReplicators();
     virtual void findRemoteServices() {}
 
-    // Other overrides
+    // Other base Component overrides
     virtual ReplicationContextPtr createReplicationContext(ReplicationStateType state);
 
-private:
     ReplicatorSmartPrx mReplicator;
     BridgeManagerServantPtr mBridgeManager;
     BridgeManagerPrx mBridgeManagerPrx;
     LocatorRegistrationWrapperPtr mBridgeManagerRegistration;
     RegisterThreadPtr mRegisterThread;
     ReplicatorListenerPrx mReplicatorListenerPrx;
+    bool mListeningToReplicator;
+    boost::shared_mutex mReplicatorLock;
 };
 
-BridgingApp::BridgingApp() : 
-    AsteriskSCF::Component::Component(lg, 
-                                      "BridgeService")
-{
-}
-
-ReplicationContextPtr BridgingApp::createReplicationContext(ReplicationStateType state)
+ReplicationContextPtr Component::createReplicationContext(ReplicationStateType state)
 {
     // Find our state replicator. 
     ServiceLocatorParamsPtr searchParams = new ServiceLocatorParams;
@@ -112,7 +108,7 @@ ReplicationContextPtr BridgingApp::createReplicationContext(ReplicationStateType
     return context;
 }
 
-void BridgingApp::onPostInitialize()
+void Component::onPostInitialize()
 {
     if (getReplicationContext()->isActive())
     {
@@ -120,17 +116,17 @@ void BridgingApp::onPostInitialize()
     }
 }
 
-void BridgingApp::onActivated()
+void Component::onActivated()
 {
     mBridgeManager->activate(); // TBD...Is this really needed? Is there really no standby() correlary?
 }
 
-void BridgingApp::onPreInitialize()
+void Component::onPreInitialize()
 {
     lg(Debug) << "Launching AsteriskSCF Session-Oriented Bridging Service " << getName();
 }
 
-void BridgingApp::createPrimaryServices()
+void Component::createPrimaryServices()
 {
      std::string managerName = 
         getCommunicator()->getProperties()->getPropertyWithDefault(getName() + ".ManagerId", "BridgeManager");
@@ -150,72 +146,97 @@ void BridgingApp::createPrimaryServices()
     }
 }
 
-void BridgingApp::registerPrimaryServices()
+void Component::preparePrimaryServicesForDiscovery()
 {
-    bool registered = false;
     try
     {
         std::string serviceName = getCommunicator()->getProperties()->getPropertyWithDefault(
                getName() + ".Service", "default");
 
-        ServiceLocatorParamsPtr parameters(new ServiceLocatorParams);
-        parameters->category = BridgeManagerDiscoveryCategory;
-        parameters->service = serviceName;
-        parameters->id = getName();
-
-        mBridgeManagerRegistration = 
-            new LocatorRegistrationWrapper(getCommunicator(), getServiceLocatorManagementProperty(), mBridgeManagerPrx, 
-               getName(), parameters);
-        registered =  registerPrimaryService(mBridgeManagerRegistration);
+        mBridgeManagerRegistration = this->wrapServiceForRegistration(mBridgeManagerPrx,
+                                                                      BridgeManagerDiscoveryCategory,
+                                                                      serviceName,
+                                                                      getName());
+        managePrimaryService(mBridgeManagerRegistration);
     }
     catch (const Ice::Exception& e)
     {
-        lg(Error) << "Exception registering services in " << BOOST_CURRENT_FUNCTION << e.what(); 
+        lg(Error) << "Exception in " << BOOST_CURRENT_FUNCTION << e.what(); 
         throw;
     }
-
-    if (!registered)
-    {
-        mRegisterThread = new RegisterThread(mBridgeManagerRegistration);
-        mRegisterThread->start();
-    }
 }
 
-void BridgingApp::createReplicationStateListeners()
+void Component::createReplicationStateListeners()
 {
     ReplicatorListenerPtr replicaListener = createStateListener(lg, mBridgeManager);
     mReplicatorListenerPrx = ReplicatorListenerPrx::uncheckedCast(getBackplaneAdapter()->addWithUUID(replicaListener));
 }
 
-void BridgingApp::listenToStateReplicators()
+void Component::listenToStateReplicators()
 {
-    ReplicationContextPtr replication = getReplicationContext();
-    static_pointer_cast<BridgeReplicationContext>(replication)->getReplicator()->addListener(mReplicatorListenerPrx);
+    boost::unique_lock<boost::shared_mutex> lock(mReplicatorLock);
+    BridgeReplicationContextPtr bridgeReplicationContext = 
+        static_pointer_cast<BridgeReplicationContext>(getReplicationContext());
+
+    if (mListeningToReplicator == true)
+    {
+        return;
+    }
+
+    if (!bridgeReplicationContext->getReplicator().isInitialized())
+    {
+        lg(Error) << getName() << ": " << BOOST_CURRENT_FUNCTION << ": State replicator could not be found. Unable to listen for state updates!";
+        return;
+    }
+
+    try
+    {
+        // Are we in standby mode?
+        if (bridgeReplicationContext->getState() == STANDBY_IN_REPLICA_GROUP)
+        {
+            bridgeReplicationContext->getReplicator().tryOneWay()->addListener(mReplicatorListenerPrx);
+            mListeningToReplicator = true;
+        }
+    }
+    catch (const Ice::Exception& e)
+    {
+        lg(Error) << e.what();
+        throw;
+    }
 }
 
-void BridgingApp::stopListeningToStateReplicators()
+void Component::stopListeningToStateReplicators()
 {
-    ReplicationContextPtr replication = getReplicationContext();
-    static_pointer_cast<BridgeReplicationContext>(replication)->getReplicator()->removeListener(mReplicatorListenerPrx);
+    boost::unique_lock<boost::shared_mutex> lock(mReplicatorLock);
+    BridgeReplicationContextPtr bridgeReplicationContext = 
+        static_pointer_cast<BridgeReplicationContext>(getReplicationContext());
+
+    if ((!bridgeReplicationContext->getReplicator().isInitialized()) || (mListeningToReplicator == false))
+    {
+        return;
+    }
+
+    try
+    {
+        bridgeReplicationContext->getReplicator().tryOneWay()->removeListener(mReplicatorListenerPrx);
+        mListeningToReplicator = false;
+    }
+    catch (const Ice::Exception& e)
+    {
+        lg(Error) << e.what();
+        throw;
+    }
 }
 
 /**
  * Override of stop notification. 
  */
-void BridgingApp::onStop()
+void Component::onStop()
 {
     if (mRegisterThread)
     {
         mRegisterThread->stop();
     }
-
-    try
-    {
-        mBridgeManagerRegistration->unregister();
-    }
-    catch (const Ice::Exception&)
-    {
-    }
 }
 
 }
@@ -223,6 +244,6 @@ void BridgingApp::onStop()
 extern "C" {
 ASTERISK_SCF_ICEBOX_EXPORT ::IceBox::Service* create(Ice::CommunicatorPtr)
 {
-    return new BridgingApp;
+    return new Component;
 }
 }
diff --git a/test/TestBridging.cpp b/test/TestBridging.cpp
index aa6f328..bf88553 100644
--- a/test/TestBridging.cpp
+++ b/test/TestBridging.cpp
@@ -21,6 +21,7 @@
 #include <boost/test/debug.hpp>
 #include <AsteriskSCF/SessionCommunications/SessionCommunicationsIf.h>
 #include <AsteriskSCF/Media/MediaIf.h>
+#include <AsteriskSCF/System/Component/ReplicaIf.h>
 #include <IceUtil/UUID.h>
 
 #include "BridgeManagerListenerI.h"
@@ -39,6 +40,7 @@ using namespace AsteriskSCF::BridgingTest;
 using namespace AsteriskSCF::SessionCommunications::V1;
 using namespace AsteriskSCF::Core::Discovery::V1;
 using namespace AsteriskSCF::Core::Routing::V1;
+using namespace AsteriskSCF::System::Component::V1;
 using namespace std;
 
 /* Cache the command line arguments so that Ice can be initialized within the global fixture. */
@@ -108,7 +110,17 @@ public:
 
     BridgeManagerPrx standbyBridgeManager()
     {
-        return mStandby;
+        return BridgeManagerPrx::uncheckedCast(mCommunicator->stringToProxy("TestBridgeManager2:default -p 57010"));
+    }
+
+    ReplicaPrx primaryReplicaControl()
+    {
+        return mPrimaryReplica;
+    }
+
+    ReplicaPrx secondaryReplicaControl()
+    {
+        return mSecondaryReplica;
     }
 
 private:
@@ -127,42 +139,49 @@ private:
         //
         ServiceLocatorParamsPtr searchParams(new ServiceLocatorParams);
         searchParams->category = BridgeManagerDiscoveryCategory;
-        Ice::ObjectProxySeq results = locator->locateAll(searchParams);
-        if (results.size() < 2)
+        try
         {
-            throw IceBox::FailureException(__FILE__, __LINE__, 
-                "Configuration Error: Unable to find test bridge managers");
+            mPrimary = BridgeManagerPrx::uncheckedCast(locator->locate(searchParams));
+        }
+        catch(const AsteriskSCF::Core::Discovery::V1::ServiceNotFound&)
+        {
+            throw;
         }
 
-        for (Ice::ObjectProxySeq::const_iterator i = results.begin(); i != results.end(); ++i)
+        ServiceLocatorParamsPtr primaryReplicaParams(new ServiceLocatorParams);
+        primaryReplicaParams->category = "BridgeService.Replica";
+        primaryReplicaParams->service = "default";
+        primaryReplicaParams->id = "TestBridge";
+        try
         {
-            string idString = mCommunicator->identityToString((*i)->ice_getIdentity());
-            if (idString == "TestBridgeManager")
-            {
-                mPrimary = BridgeManagerPrx::checkedCast((*i));
-                if (!mPrimary)
-                {
-                    throw IceBox::FailureException(__FILE__, __LINE__, 
-                        "Configuration Error: Lookup for primary bridge manager failed");
-                }
-            }
-            else if (idString == "TestBridgeManager2")
-            {
-                mStandby = BridgeManagerPrx::checkedCast((*i));
-                if (!mStandby)
-                {
-                    throw IceBox::FailureException(__FILE__, __LINE__, 
-                        "Configuration Error: Lookup for standby bridge manager failed");
-                }
-            }
+            mPrimaryReplica = ReplicaPrx::uncheckedCast(locator->locate(primaryReplicaParams));
+        }
+        catch(const AsteriskSCF::Core::Discovery::V1::ServiceNotFound&)
+        {
+            throw;
+        }
+
+        ServiceLocatorParamsPtr secondaryReplicaParams(new ServiceLocatorParams);
+        secondaryReplicaParams->category = "BridgeService.Replica";
+        secondaryReplicaParams->service = "default";
+        secondaryReplicaParams->id = "TestBridge2";
+        try
+        {
+            mSecondaryReplica = ReplicaPrx::uncheckedCast(locator->locate(secondaryReplicaParams));
+        }
+        catch(const AsteriskSCF::Core::Discovery::V1::ServiceNotFound&)
+        {
+            throw;
         }
     }
 
     BridgeManagerPrx mPrimary;
-    BridgeManagerPrx mStandby;
     Ice::CommunicatorPtr mCommunicator;
     Ice::StringSeq mArgs;
     vector<char const *> mArgv;
+
+    ReplicaPrx mPrimaryReplica;
+    ReplicaPrx mSecondaryReplica;
 };
 typedef IceUtil::Handle<TestEnvironment> TestEnvironmentPtr;
 
@@ -825,15 +844,40 @@ public:
                     BOOST_MESSAGE("Wait for event expired");
                 }
                 BOOST_CHECK(servant->createCalls() == 1);
-                BridgeSeq bridges = mgrPrx2->listBridges();
-                BridgeSeq bridges2 = mgrPrx->listBridges();
-                BOOST_CHECK(bridges.size() == bridges2.size()); // XXX
+
                 mgrPrx->addListener(listenerPrx);
                 bridge = mgrPrx->createBridge(sessions, 0);
                 servant->wait(5000);
                 BOOST_CHECK(servant->createCalls() == 2);
                 bridge->shutdown();
                 mgrPrx->removeListener(listenerPrx);
+
+                BridgeSeq bridges = mgrPrx->listBridges();
+
+                // Activate the secondary component so we can 
+                // query it. 
+                ReplicaPrx secondaryReplica = env()->secondaryReplicaControl();
+                ReplicaPrx primaryReplica = env()->primaryReplicaControl();
+                BOOST_CHECK(primaryReplica->isActive() == true);
+                BOOST_CHECK(secondaryReplica->isActive() == false);
+
+                primaryReplica->standby();
+                BOOST_CHECK(primaryReplica->isActive() == false);
+
+                secondaryReplica->activate();
+                BOOST_CHECK(secondaryReplica->isActive() == true);
+
+                BridgeSeq bridges2 = mgrPrx2->listBridges();
+
+                BOOST_CHECK(bridges.size() == bridges2.size()); // XXX
+
+                // Set the components back to original state.
+                secondaryReplica->standby();
+                primaryReplica->activate();
+
+                BOOST_CHECK(primaryReplica->isActive() == true);
+                BOOST_CHECK(secondaryReplica->isActive() == false);
+
             }
             catch (const Ice::Exception& ex)
             {

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


-- 
asterisk-scf/integration/bridging.git



More information about the asterisk-scf-commits mailing list