[asterisk-scf-commits] asterisk-scf/integration/routing.git branch "route_replica" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Apr 19 18:38:15 CDT 2011


branch "route_replica" has been updated
       via  e78b522254e0cd7cad9957aacd4edfed8186d1f7 (commit)
       via  3193e80aab0aca9b747ec2d4cbe60a755473b6b9 (commit)
      from  b4937c1744de2fb71fc48a364609e14f63462cef (commit)

Summary of changes:
 local-slice/BasicRoutingStateReplicationIf.ice     |   12 +--
 src/BasicRoutingServiceApp.cpp                     |   56 ++++++--
 src/BasicRoutingStateReplicatorApp.cpp             |    9 +-
 src/CMakeLists.txt                                 |    6 +-
 src/ConnectBridgedSessionsOperation.cpp            |   56 ++++----
 src/ConnectBridgedSessionsOperation.h              |    2 +-
 ...nectBridgedSessionsWithDestinationOperation.cpp |   48 ++++----
 src/EndpointRegistry.cpp                           |   51 ++++---
 src/ReplicationContext.cpp                         |   11 ++-
 src/ReplicationContext.h                           |    6 +
 src/RouteSessionOperation.cpp                      |   14 +-
 src/RouteSessionOperation.h                        |    2 +-
 src/RoutingServiceEventPublisher.cpp               |    2 +-
 src/RoutingStateReplicatorListener.cpp             |   14 +--
 src/SessionListener.h                              |   30 ++--
 src/SessionRouterOperation.cpp                     |    4 +-
 src/SessionRouterOperation.h                       |  140 ++++++++++----------
 src/TestContext.cpp                                |   82 ++++++++++++
 src/TestContext.h                                  |   59 ++++++++
 test/TestRouting.cpp                               |   28 ----
 20 files changed, 389 insertions(+), 243 deletions(-)
 create mode 100644 src/TestContext.cpp
 create mode 100644 src/TestContext.h


- Log -----------------------------------------------------------------
commit e78b522254e0cd7cad9957aacd4edfed8186d1f7
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Tue Apr 19 18:37:37 2011 -0500

    Removed replication test for now.

diff --git a/test/TestRouting.cpp b/test/TestRouting.cpp
index acb2f39..291234a 100644
--- a/test/TestRouting.cpp
+++ b/test/TestRouting.cpp
@@ -537,31 +537,3 @@ public:
         }
     }
 };
-
-/**
- * The beginnings of a test of replication...<TBD>
- */
-BOOST_FIXTURE_TEST_CASE(ReplicateEndpointLocator, ReplicationFixture)
-{
-
-   try
-   {
-       // Ice::ObjectAdapterPtr adapter = SharedTestData::instance.communicatorIn->createObjectAdapter("IceBox.ServiceManager");
-
-       Ice::Identity identity = SharedTestData::instance.communicatorOut->stringToIdentity("IceBox/ServiceManager");
-       Ice::ObjectPrx serviceObj = SharedTestData::instance.adapterOut->createDirectProxy(identity);
-
-       IceBox::ServiceManagerPrx serviceManager = IceBox::ServiceManagerPrx::checkedCast(serviceObj);
-      
-       serviceManager->stopService("RoutingService");
-   }
-   catch(const Ice::Exception& e)
-   {
-       BOOST_FAIL(e.what());
-   }
-   catch(...)
-   {
-       BOOST_FAIL("Unable to stop primary routing service.");
-   }
-
-}

commit 3193e80aab0aca9b747ec2d4cbe60a755473b6b9
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Tue Apr 19 18:17:43 2011 -0500

    Some cleanup for review.

diff --git a/local-slice/BasicRoutingStateReplicationIf.ice b/local-slice/BasicRoutingStateReplicationIf.ice
index 01b1579..fc855ee 100644
--- a/local-slice/BasicRoutingStateReplicationIf.ice
+++ b/local-slice/BasicRoutingStateReplicationIf.ice
@@ -176,22 +176,12 @@ module V1
 	 * Represents an added endpoint locator. 
 	 * The key (in the base state item) is the locator id. 
 	 */
-    class EndpointLocatorAdd extends RoutingStateItem
+    class EndpointLocatorState extends RoutingStateItem
     { 
         AsteriskSCF::Core::Routing::V1::RegExSeq regExList;
         AsteriskSCF::Core::Routing::V1::EndpointLocator *locator;
     };
 
-	/**  
-	 * Represents a change of the endpoint locators 
-	 * managed ids. 
-	 * The key (in the base state item) is the locatorId. 
-	 */
-	class EndpointLocatorSetDestIds extends RoutingStateItem
-	{
-	    AsteriskSCF::Core::Routing::V1::RegExSeq regExList;
-	};
-
 
 }; //module V1
 }; //module BasicRouting
diff --git a/src/BasicRoutingServiceApp.cpp b/src/BasicRoutingServiceApp.cpp
index 07031ae..eae4091 100644
--- a/src/BasicRoutingServiceApp.cpp
+++ b/src/BasicRoutingServiceApp.cpp
@@ -38,6 +38,7 @@
 #include "SessionRouter.h"
 #include "OperationReplicaCache.h"
 #include "ReplicationContext.h"
+#include "TestContext.h"
 
 using namespace std;
 using namespace AsteriskSCF::SessionCommunications::V1;
@@ -67,6 +68,7 @@ public:
         : mDone(false), 
           mInitialized(false), 
           mRunning(false),
+          mPublishTestInterface(false),
           mSessionContext(new SessionContext()),
           mWorkQueue( new AsteriskSCF::Threading::SimpleWorkQueue("SessionRouterWorkQueue", lg)),
           mListeningToReplicator(false)
@@ -102,6 +104,7 @@ private:
     bool mDone;
     bool mInitialized;
     bool mRunning;
+    bool mPublishTestInterface;
     boost::shared_ptr<AsteriskSCF::Threading::SimpleWorkQueue> mWorkQueue;
 
     std::string mAppName;
@@ -177,25 +180,42 @@ private:
     BasicRoutingServiceApp& mApp;
 };
 
+/** 
+ * This interface is published as a facet of the Component Service interface.
+ * It exists to allow more elaborate interaction with a component during testing.
+ */
 class ComponentTestImpl : public ComponentTest
 {
 public:
-    ComponentTestImpl(BasicRoutingServiceApp& app) :
-        mApp(app)
+    ComponentTestImpl(const TestContextPtr& testContext) :
+        mTestContext(testContext)
     {
     }
 
-    void setTestMode(const ::std::string&, const ::Ice::Current&)
+    void setTestMode(const ::std::string& mode, const ::Ice::Current&)
     {
+        mTestContext->setTestMode(mode);
     }
 
     void setTestModeWithArgs(const ::std::string&, 
-                             const ComponentTestParamSeq&, const ::Ice::Current&)
+                             const ComponentTestParamSeq&, 
+                             const ::Ice::Current&)
+    {
+        // NA for this component.
+    }
+
+    void clearTestMode(const string& mode, const ::Ice::Current&)
+    {
+       // NA for this component.
+    }
+
+    void clearTestModes(const ::Ice::Current&)
     {
+        mTestContext->clearTestMode();
     }
 
 private:
-    BasicRoutingServiceApp& mApp;
+    TestContextPtr mTestContext;
 };
 
 /**
@@ -266,6 +286,7 @@ private:
 
 bool BasicRoutingServiceApp::isActive()
 {
+    // The Replication Context is tracking our current status. 
     return mReplicationContext->isComponentActive();
 }
 
@@ -284,7 +305,7 @@ void BasicRoutingServiceApp::onStandby()
 /** 
  * Register as a listener to our state replicator. 
  * A component in standby mode will do this to monitor state changes
- * being sent from the active component. 
+ * being sent from an active component. 
  */
 void BasicRoutingServiceApp::listenToStateReplicator()
 {
@@ -371,10 +392,11 @@ void BasicRoutingServiceApp::registerWithServiceLocator()
 
         setCategory(mComponentServiceManagement, Routing::V1::ComponentServiceDiscoveryCategory);
 
-#ifdef TEST_BUILD
-        // Register our test servant as a facet of the ComponentService interface.
-        mAdapter->addFacet(mComponentTest, componentServicePrx->ice_getIdentity(), AsteriskSCF::System::Component::V1::ComponentTestFacet);
-#endif
+        if (mPublishTestInterface)
+        {
+            // Register our test servant as a facet of the ComponentService interface.
+            mAdapter->addFacet(mComponentTest, componentServicePrx->ice_getIdentity(), AsteriskSCF::System::Component::V1::ComponentTestFacet);
+        }
 
         // Register the SessionRouter interface with the Service Locator.
         Ice::ObjectPrx sessionRouterObjectPrx = mAdapter->createDirectProxy(mCommunicator->stringToIdentity(SessionRouterObjectId));
@@ -473,11 +495,15 @@ void BasicRoutingServiceApp::initialize()
         // Publish the LocatorRegistry interface.
         mAdapter->add(mEndpointRegistry, mCommunicator->stringToIdentity(RegistryLocatorObjectId));
 
-#ifdef TEST_BUILD
-        // Create and publish the ComponentTest servant. This will be exposed
-        // as a facet of ComponentService.
-        mComponentTest = new ComponentTestImpl(*this);
-#endif
+        mPublishTestInterface = (mCommunicator->getProperties()->getPropertyWithDefault(mAppName + ".ComponentTest", "no") == "yes");
+
+        if (mPublishTestInterface)
+        {
+            // Create and publish the ComponentTest servant. This will be exposed
+            // as a facet of ComponentService.
+            mComponentTest = new ComponentTestImpl(mReplicationContext->getTestContext());
+        }
+
         // Create the session context needed to construct operations.
         SessionContext *rawSessionContext(new SessionContext(mAdapter, 
                                                              mEndpointRegistry, 
diff --git a/src/BasicRoutingStateReplicatorApp.cpp b/src/BasicRoutingStateReplicatorApp.cpp
index 909d228..5d644d8 100644
--- a/src/BasicRoutingStateReplicatorApp.cpp
+++ b/src/BasicRoutingStateReplicatorApp.cpp
@@ -54,6 +54,9 @@ typedef IceUtil::Handle<RoutingStateReplicatorI> RoutingStateReplicatorIPtr;
 };
 };
 
+/**
+ * This class implements a very simplistic replication capability using the StateReplicator template.
+ */
 class BasicRoutingStateReplicatorService : public IceBox::Service
 {
 public:
@@ -97,17 +100,17 @@ public:
 public: // Overrides of the ComponentService interface.
     virtual void suspend(const ::Ice::Current& = ::Ice::Current())
     {
-        // TBD
+        // TBD... focussed more on the component than the replicator.
     }
 
     virtual void resume(const ::Ice::Current& = ::Ice::Current())
     {
-        // TBD
+        // TBD...
     }
 
     virtual void shutdown(const ::Ice::Current& = ::Ice::Current())
     {
-        // TBD
+        mService.stop();
     }
 
 private:
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 8c08966..2ef7065 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -40,6 +40,8 @@ asterisk_scf_component_add_file(BasicRoutingService OperationReplicaCache.h)
 asterisk_scf_component_add_file(BasicRoutingService OperationReplicaCache.cpp)
 asterisk_scf_component_add_file(BasicRoutingService ReplicationContext.h)
 asterisk_scf_component_add_file(BasicRoutingService ReplicationContext.cpp)
+asterisk_scf_component_add_file(BasicRoutingService TestContext.h)
+asterisk_scf_component_add_file(BasicRoutingService TestContext.cpp)
 asterisk_scf_component_add_file(BasicRoutingService RoutingStateReplicatorListener.h)
 asterisk_scf_component_add_file(BasicRoutingService RoutingStateReplicatorListener.cpp)
 
@@ -53,6 +55,7 @@ include_directories(${logger_dir}/include)
 include_directories(${API_INCLUDE_DIR})
 
 include_directories(${utils_dir}/SmartProxy/include)
+include_directories(${utils_dir}/AmiCollector/include)
 
 include_directories(${util_cpp_dir}/Threading/include)
 include_directories(${util_cpp_dir}/StateMachine/include)
@@ -63,9 +66,6 @@ target_link_libraries(BasicRoutingService logging-client)
 
 target_link_libraries(BasicRoutingService Threading)
 
-# Enable test instrumentation in the component. 
-add_definitions(-DTEST_BUILD)
-
 #asterisk_scf_component_install(BasicRoutingService RUNTIME bin "Basic Routing Service" Core)
 
 ########################################
diff --git a/src/ConnectBridgedSessionsOperation.cpp b/src/ConnectBridgedSessionsOperation.cpp
index 5cd327d..d9a61b1 100644
--- a/src/ConnectBridgedSessionsOperation.cpp
+++ b/src/ConnectBridgedSessionsOperation.cpp
@@ -118,27 +118,27 @@ void ConnectBridgedSessionsOperation::connectBridgedSessionsState()
     lg(Debug) << "connectBridgedSessions() entered... ";
 
     // Get the bridge being merged into.
-	BridgePrx mergeBridge;
-	try
-	{
+    BridgePrx mergeBridge;
+    try
+    {
         mergeBridge = getBridge(mSessionToReplace);
-	}
-	catch (const Ice::Exception &e)
-	{
-		finishWithException(e);
-		return;
-	}
-
-	SessionSeq preserveSessions;
-	try
-	{
+    }
+    catch (const Ice::Exception &e)
+    {
+        finishWithException(e);
+        return;
+    }
+
+    SessionSeq preserveSessions;
+    try
+    {
         preserveSessions = getSessionsInBridge(mergeBridge, mSessionToReplace);
-	}
-	catch (const Ice::Exception &e)
-	{
-		finishWithException(e);
-		return;
-	}
+    }
+    catch (const Ice::Exception &e)
+    {
+        finishWithException(e);
+        return;
+    }
 
     // Create a listener for the sessions not being replaced to handle early termination.
     lg(Debug) << "connectBridgedSessions(): Adding listener to " << preserveSessions.size() << " session(s)." ;
@@ -146,16 +146,16 @@ void ConnectBridgedSessionsOperation::connectBridgedSessionsState()
     mListenerManager = listener;
 
     // Get the bridge for the sessions being moved.
-	BridgePrx oldBridge;
-	try
-	{
+    BridgePrx oldBridge;
+    try
+    {
         oldBridge = getBridge(mBridgedSession);
-	}
-	catch (const Ice::Exception &e)
-	{
-		finishWithException(e);
-		return;
-	}
+    }
+    catch (const Ice::Exception &e)
+    {
+        finishWithException(e);
+        return;
+    }
 
     SessionSeq migratingSessions = removeSessionsFromBridge(oldBridge, mBridgedSession);
 
diff --git a/src/ConnectBridgedSessionsOperation.h b/src/ConnectBridgedSessionsOperation.h
index bd3e73a..1a87dce 100644
--- a/src/ConnectBridgedSessionsOperation.h
+++ b/src/ConnectBridgedSessionsOperation.h
@@ -93,6 +93,6 @@ private:
      AsteriskSCF::SessionCommunications::V1::SessionPrx mBridgedSession;
 
 }; // class ConnectBridgedSessionsOperation
-	
+
 } // end BasicRoutingService
 } // end AsteriskSCF
diff --git a/src/ConnectBridgedSessionsWithDestinationOperation.cpp b/src/ConnectBridgedSessionsWithDestinationOperation.cpp
index c3f4903..17ac0d8 100644
--- a/src/ConnectBridgedSessionsWithDestinationOperation.cpp
+++ b/src/ConnectBridgedSessionsWithDestinationOperation.cpp
@@ -354,25 +354,25 @@ void ConnectBridgedSessionsWithDestinationOperation::lookupState()
 {
     lg(Debug) << "connectBridgedSessionsWithDestination() entered with destination " << mDestination;
 
-	try
-	{
+    try
+    {
         mBridge = mSessionToReplace->getBridge();
-	}
-	catch (const Ice::Exception &e)
-	{
-		finishWithException(e);
-		return;
-	}
-
-	try
-	{
+    }
+    catch (const Ice::Exception &e)
+    {
+        finishWithException(e);
+        return;
+    }
+
+    try
+    {
         mRemainingSessions = getSessionsInBridge(mBridge, mSessionToReplace);
-	}
-	catch (const Ice::Exception &e)
-	{
-		finishWithException(e);
-		return;
-	}
+    }
+    catch (const Ice::Exception &e)
+    {
+        finishWithException(e);
+        return;
+    }
 
     // Create a listener for the sessions not being replaced to handle early termination.
     // The wrapper we're using will remove the listener and free it when
@@ -464,23 +464,23 @@ void ConnectBridgedSessionsWithDestinationOperation::establishBridgeState()
 
     lg(Debug) << "connectBridgedSessionsWithDestination(): Forwarding start() to new session.";
 
-	try
-	{
+    try
+    {
         forwardStart(newSessions);
-	}
-	catch (const Ice::Exception &e)
-	{
+    }
+    catch (const Ice::Exception &e)
+    {
         lg(Debug) << "routeSession(): Exception forwarding start: " << e.what();
 
         finishWithException(e);
         return;
-	}
+    }
 
     // Set the state handler to exectute once we've looked up our endpoints. 
     mStateMachine.setNextState(ConnectBridgedSessionsWithDestinationOp::STATE_SEND_RESPONSE);
 
     // Keep executing.
-	mOperationsManager->reschedule(this);
+    mOperationsManager->reschedule(this);
 }
 
 void ConnectBridgedSessionsWithDestinationOperation::sendResponseState()
diff --git a/src/EndpointRegistry.cpp b/src/EndpointRegistry.cpp
index 7075940..cb573f4 100644
--- a/src/EndpointRegistry.cpp
+++ b/src/EndpointRegistry.cpp
@@ -18,7 +18,7 @@
 #include <boost/thread/shared_mutex.hpp>
 
 #include <AsteriskSCF/logger.h>
-#include  <AsteriskSCF/SmartProxy.h>
+#include <AsteriskSCF/SmartProxy.h>
 
 #include "RoutingServiceEventPublisher.h"
 #include "EndpointRegistry.h"
@@ -137,7 +137,7 @@ public:
                 // Push this information to the state replicator.
                 RoutingStateItemSeq removeItems;
 
-                EndpointLocatorAddPtr addEndpointItem(new EndpointLocatorAdd());
+                EndpointLocatorStatePtr addEndpointItem(new EndpointLocatorState());
                 addEndpointItem->key = locatorId;
                 removeItems.push_back(addEndpointItem);
 
@@ -174,7 +174,7 @@ public:
                 // Push this information to the state replicator.
                 RoutingStateItemSeq setItems;
 
-                EndpointLocatorAddPtr addEndpointItem(new EndpointLocatorAdd());
+                EndpointLocatorStatePtr addEndpointItem(new EndpointLocatorState());
                 addEndpointItem->key = locatorId;
                 addEndpointItem->locator = locator;
                 addEndpointItem->regExList = regexList;
@@ -195,6 +195,7 @@ public:
 
     void forwardEndpointLocatorDestIdChange(const std::string& locatorId,
                                             const RegExSeq& regexList, 
+                                            const EndpointLocatorPrx& locator, 
                                             OperationResult result)
     {
         if (!mReplicationContext->isComponentActive())
@@ -209,14 +210,22 @@ public:
             {
                 if (mReplicationContext->isReplicating())
                 {
-                    // Push this information to the state replicator.
-                    RoutingStateItemSeq setItems;
+                    // Remove the item with the old value.
+                    RoutingStateItemSeq removeItems;
+                    EndpointLocatorStatePtr removeItem(new EndpointLocatorState());
+                    removeItem->key = locatorId;
+                    removeItems.push_back(removeItem);
+
+                    mReplicationContext->getReplicatorService()->removeStateForItems(removeItems);
 
-                    EndpointLocatorSetDestIdsPtr setDestIdsItem(new EndpointLocatorSetDestIds());
-                    setDestIdsItem->key = locatorId;
-                    setDestIdsItem->regExList = regexList;
+                    // Now add the item with the new values. 
+                    RoutingStateItemSeq setItems;
+                    EndpointLocatorStatePtr addEndpointItem(new EndpointLocatorState());
+                    addEndpointItem->key = locatorId;
+                    addEndpointItem->locator = locator;
+                    addEndpointItem->regExList = regexList;
 
-                    setItems.push_back(setDestIdsItem);
+                    setItems.push_back(addEndpointItem);
 
                     mReplicationContext->getReplicatorService()->setState(setItems);
                 }
@@ -240,6 +249,9 @@ public:
 
 /**
  * A collector for lookup() operation AMI replies. 
+ * This collector waits for the first reply, and ignores
+ * subsequent replies. An exception is raised if all 
+ * outgoing requests throw an exception.
  */
 class LookupResultCollector : public IceUtil::Shared
 {
@@ -275,7 +287,7 @@ public:
      * Collect results of AMI lookups from multiple EndpointLocators. 
      */
     void lookupResult(const EndpointSeq& endpoints)
-	{
+    {
         boost::lock_guard<boost::mutex> guard(mLock);
 
         if ((endpoints.size() > 0) && mCallback)
@@ -332,7 +344,6 @@ private:
 };
 typedef IceUtil::Handle<LookupResultCollector> LookupResultCollectorPtr;
 
-
 /**
  * Constructor.
  */
@@ -404,7 +415,6 @@ void EndpointRegistry::lookup_async(const ::AsteriskSCF::Core::Routing::V1::AMD_
         lg(Debug) << "EndpointRegistry::lookup() invoke a lookup for " << destination;
         (*locator)->begin_lookup(destination, lookupCallback);
     }
-
 }
 
 /**
@@ -421,11 +431,11 @@ bool locatorExists(const EndpointLocatorMap& map, const std::string& locatorId,
             end = map.end();
         }
 
-		if (existing == end)
-		{
-			return false;
-		}
-		return true;
+        if (existing == end)
+        {
+            return false;
+        }
+        return true;
 }
 
 /**
@@ -512,22 +522,21 @@ void EndpointRegistry::setEndpointLocatorDestinationIds(const std::string& locat
 
         if (!exists)
         {
-            mImpl->forwardEndpointLocatorDestIdChange(locatorId, regExList, Event::FAILURE);
+            mImpl->forwardEndpointLocatorDestIdChange(locatorId, regExList, 0, Event::FAILURE);
             throw DestinationNotFoundException(locatorId);
         }
 
         // Replace the regular expression.
         existing->second.setRegEx(regExList);
-        mImpl->forwardEndpointLocatorDestIdChange(locatorId, regExList, Event::SUCCESS);
+        mImpl->forwardEndpointLocatorDestIdChange(locatorId, regExList, existing->second.locator, Event::SUCCESS);
 
     }
     catch(const std::exception &e)
     {
-        mImpl->forwardEndpointLocatorDestIdChange(locatorId, regExList, Event::FAILURE);
+        mImpl->forwardEndpointLocatorDestIdChange(locatorId, regExList, 0, Event::FAILURE);
         lg(Error) << "Exception modifying the destination specifications for EndpointLocator " << locatorId;
         lg(Error) << "   - " << e.what();
     }
-
 }
 
 /**
diff --git a/src/ReplicationContext.cpp b/src/ReplicationContext.cpp
index 803a562..ab29728 100644
--- a/src/ReplicationContext.cpp
+++ b/src/ReplicationContext.cpp
@@ -28,13 +28,17 @@ namespace BasicRoutingService
 class ReplicationContextPriv
 {
 public:
-    ReplicationContextPriv(bool componentIsActive) : mActive(componentIsActive)
+    ReplicationContextPriv(bool componentIsActive) : 
+                    mActive(componentIsActive),
+                    mTestContext(new TestContext())
     {
     }
 
     ReplicatorServicePrx mReplicatorService;
     bool mActive;
 
+    TestContextPtr mTestContext;
+
     boost::shared_mutex mLock;
 };
 
@@ -86,5 +90,10 @@ void ReplicationContext::setReplicatorService(const ReplicatorServicePrx& servic
     mImpl->mReplicatorService = service;
 }
 
+TestContextPtr ReplicationContext::getTestContext()
+{
+   return mImpl->mTestContext;
+}
+
 } // end BasicRoutingService
 } // end AsteriskSCF
diff --git a/src/ReplicationContext.h b/src/ReplicationContext.h
index d3a6769..167063d 100644
--- a/src/ReplicationContext.h
+++ b/src/ReplicationContext.h
@@ -19,6 +19,7 @@
 
 #include <AsteriskSCF/SmartProxy.h>
 #include "BasicRoutingStateReplicationIf.h"
+#include "TestContext.h"
 
 namespace AsteriskSCF
 {
@@ -60,6 +61,11 @@ public:
      */
     void setReplicatorService(const ReplicatorServicePrx& service);
 
+    /**
+     * Access to a test context to support advanced unit tests.
+     */
+    TestContextPtr getTestContext();
+
 private:
     boost::shared_ptr<ReplicationContextPriv> mImpl;
 };
diff --git a/src/RouteSessionOperation.cpp b/src/RouteSessionOperation.cpp
index 46ba0b6..2a563b0 100644
--- a/src/RouteSessionOperation.cpp
+++ b/src/RouteSessionOperation.cpp
@@ -464,23 +464,23 @@ void RouteSessionOperation::establishBridgeState()
     // Forward the start to all the destinations routed to.
     lg(Debug) << "routeSession(): Sending start() to newly routed destination.";
 
-	try
-	{
+    try
+    {
         forwardStart(newSessions);
-	}
-	catch (const Ice::Exception &e)
-	{
+    }
+    catch (const Ice::Exception &e)
+    {
         lg(Debug) << "routeSession(): Exception forwarding start: " << e.what();
 
         finishWithException(e);
         return;
-	}
+    }
 
     // Set the state handler to exectute once we've looked up our endpoints. 
     mStateMachine.setNextState(RouteSessionOp::STATE_SEND_RESPONSE);
 
     // Keep executing.
-	mOperationsManager->reschedule(this);
+    mOperationsManager->reschedule(this);
 }
 
 void RouteSessionOperation::sendResponseState()
diff --git a/src/RouteSessionOperation.h b/src/RouteSessionOperation.h
index 4934cef..48b5f64 100644
--- a/src/RouteSessionOperation.h
+++ b/src/RouteSessionOperation.h
@@ -171,6 +171,6 @@ private:
 
 }; // class RouteSessionOperation
 
-	
+
 } // end BasicRoutingService
 } // end AsteriskSCF
diff --git a/src/RoutingServiceEventPublisher.cpp b/src/RoutingServiceEventPublisher.cpp
index 221ba85..57283b2 100644
--- a/src/RoutingServiceEventPublisher.cpp
+++ b/src/RoutingServiceEventPublisher.cpp
@@ -114,7 +114,7 @@ public:
      */
     bool isInitialized()
     {
-		boost::lock_guard<boost::mutex> lock(mLock); 
+        boost::lock_guard<boost::mutex> lock(mLock); 
 
         if (mInitialized)
         {
diff --git a/src/RoutingStateReplicatorListener.cpp b/src/RoutingStateReplicatorListener.cpp
index 7232d85..c62cee1 100644
--- a/src/RoutingStateReplicatorListener.cpp
+++ b/src/RoutingStateReplicatorListener.cpp
@@ -94,16 +94,11 @@ public:
                 // Removing the Start state for this operation will clean it up. 
             }
 
-            void visitEndpointLocatorAdd(const ::AsteriskSCF::BasicRoutingService::V1::EndpointLocatorAddPtr& item)
+            void visitEndpointLocatorState(const ::AsteriskSCF::BasicRoutingService::V1::EndpointLocatorStatePtr& item)
             {
                 mImpl->mEndpointRegistry->removeEndpointLocator(item->key, ::Ice::Current());
             }
 
-            void visitEndpointLocatorSetDestIds(const ::AsteriskSCF::BasicRoutingService::V1::EndpointLocatorSetDestIdsPtr& item)
-            {
-                // Nothing much can be done here without some type of rollback facility. 
-            }
-
         }; // end method-local visitor def
 
         // Create the visitor. Smart pointer will cleanup when this method exits. 
@@ -164,16 +159,11 @@ public:
                 mImpl->mOperationReplicaCache->cacheOperation(CONNECT_BRIDGED_SESSIONS_WITH_DEST_OP, opState);
             }
 
-            void visitEndpointLocatorAdd(const ::AsteriskSCF::BasicRoutingService::V1::EndpointLocatorAddPtr& item)
+            void visitEndpointLocatorState(const ::AsteriskSCF::BasicRoutingService::V1::EndpointLocatorStatePtr& item)
             {
                 mImpl->mEndpointRegistry->addEndpointLocator(item->key, item->regExList, item->locator, ::Ice::Current());
             }
 
-            void visitEndpointLocatorSetDestIds(const ::AsteriskSCF::BasicRoutingService::V1::EndpointLocatorSetDestIdsPtr& item)
-            {
-                mImpl->mEndpointRegistry->setEndpointLocatorDestinationIds(item->key, item->regExList, ::Ice::Current());
-            }
-
         }; // end method-local visitor def
 
         // Create the visitor. Smart pointer will cleanup when this method exits. 
diff --git a/src/SessionListener.h b/src/SessionListener.h
index a0cbc0f..72e118b 100644
--- a/src/SessionListener.h
+++ b/src/SessionListener.h
@@ -39,28 +39,28 @@ public:
 
 public: // Overrides for SessionListener
 
-	void connected(const AsteriskSCF::SessionCommunications::V1::SessionPrx& session, 
-		           const Ice::Current&) {}     // No-op
+    void connected(const AsteriskSCF::SessionCommunications::V1::SessionPrx& session, 
+                   const Ice::Current&) {}     // No-op
 
-	void flashed(const AsteriskSCF::SessionCommunications::V1::SessionPrx& session, 
-		         const Ice::Current&) {}       // No-op
+    void flashed(const AsteriskSCF::SessionCommunications::V1::SessionPrx& session, 
+                 const Ice::Current&) {}       // No-op
 
     void held(const AsteriskSCF::SessionCommunications::V1::SessionPrx& session, 
-		      const Ice::Current&) {}          // No-op
+              const Ice::Current&) {}          // No-op
 
     void progressing(const AsteriskSCF::SessionCommunications::V1::SessionPrx& session, 
-		             const AsteriskSCF::SessionCommunications::V1::ResponseCodePtr&, 
-					 const Ice::Current&) {}   // No-op
+                     const AsteriskSCF::SessionCommunications::V1::ResponseCodePtr&, 
+                     const Ice::Current&) {}   // No-op
 
     void ringing(const AsteriskSCF::SessionCommunications::V1::SessionPrx& session, 
-		         const Ice::Current&) {}       // No op
+                 const Ice::Current&) {}       // No op
 
     void unheld(const AsteriskSCF::SessionCommunications::V1::SessionPrx& session, 
-		        const Ice::Current&) {}        // No op
+                const Ice::Current&) {}        // No op
 
-	void stopped(const AsteriskSCF::SessionCommunications::V1::SessionPrx& session, 
-		         const AsteriskSCF::SessionCommunications::V1::ResponseCodePtr& responseCode, 
-				 const Ice::Current&);
+    void stopped(const AsteriskSCF::SessionCommunications::V1::SessionPrx& session, 
+                 const AsteriskSCF::SessionCommunications::V1::ResponseCodePtr& responseCode, 
+                 const Ice::Current&);
 
 public: // Impl operations
 
@@ -100,10 +100,10 @@ typedef IceInternal::Handle<SessionListenerImpl> SessionListenerImplPtr;
 class SessionListenerManager
 {
 public:
-	SessionListenerManager(Ice::ObjectAdapterPtr adapter, const AsteriskSCF::SessionCommunications::V1::SessionPrx& session);
-	SessionListenerManager(Ice::ObjectAdapterPtr adapter, const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessionSequence);
+    SessionListenerManager(Ice::ObjectAdapterPtr adapter, const AsteriskSCF::SessionCommunications::V1::SessionPrx& session);
+    SessionListenerManager(Ice::ObjectAdapterPtr adapter, const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessionSequence);
 
-	~SessionListenerManager();
+    ~SessionListenerManager();
     SessionListenerImpl* getListener() const;
 
 private:
diff --git a/src/SessionRouterOperation.cpp b/src/SessionRouterOperation.cpp
index f4bbc4c..ef8fd66 100644
--- a/src/SessionRouterOperation.cpp
+++ b/src/SessionRouterOperation.cpp
@@ -154,8 +154,8 @@ BridgePrx getBridge(SessionPrx session)
  * newly added sessions. 
  */
 SessionSeq createSessionForEndpoints(const EndpointSeq& endpoints, 
-									 const std::string& destination, 
-									 const SessionListenerManagerPtr& listenerManager)
+                                     const std::string& destination, 
+                                     const SessionListenerManagerPtr& listenerManager)
 {
     // Add a session
     SessionSeq newSessions;
diff --git a/src/SessionRouterOperation.h b/src/SessionRouterOperation.h
index 6e3f0df..6cebe56 100644
--- a/src/SessionRouterOperation.h
+++ b/src/SessionRouterOperation.h
@@ -47,14 +47,14 @@ public:
      * later via a setter due to component initialization sequence. 
      */
     SessionContext(const Ice::ObjectAdapterPtr& adapter,
-					const EndpointRegistryPtr& registry,
-					const AsteriskSCF::Core::Routing::V1::Event::RoutingEventsPtr& publisher,
-					const boost::shared_ptr<AsteriskSCF::Threading::WorkQueue>& workQueue,
+                    const EndpointRegistryPtr& registry,
+                    const AsteriskSCF::Core::Routing::V1::Event::RoutingEventsPtr& publisher,
+                    const boost::shared_ptr<AsteriskSCF::Threading::WorkQueue>& workQueue,
                     const ReplicationContextPtr& replicationContext)
-						  :  adapter(adapter),
-							 endpointRegistry(registry),
-							 eventPublisher(publisher),
-							 workQueue(workQueue),
+                          :  adapter(adapter),
+                             endpointRegistry(registry),
+                             eventPublisher(publisher),
+                             workQueue(workQueue),
                              replicationContext(replicationContext)
     {
     }
@@ -67,7 +67,7 @@ public:
     const boost::shared_ptr<AsteriskSCF::Threading::WorkQueue> workQueue;
     const ReplicationContextPtr replicationContext;
 
-	AsteriskSCF::SmartProxy::SmartProxy<AsteriskSCF::SessionCommunications::V1::BridgeManagerPrx> bridgeManager;
+    AsteriskSCF::SmartProxy::SmartProxy<AsteriskSCF::SessionCommunications::V1::BridgeManagerPrx> bridgeManager;
 
 };
 
@@ -121,15 +121,15 @@ public:
                            OperationsManager* manager, 
                            S defaultState,
                            std::string transactionId) 
-		: mInitiatorCallback(amdCallback),
+        : mInitiatorCallback(amdCallback),
           mSessionContext(context),
           mIceCurrent(current),
           mFinished(false),
-		  mOperationsManager(manager),
+          mOperationsManager(manager),
           mStateMachine(defaultState),
           mTransactionId(transactionId)
-	{
-	}
+    {
+    }
 
     /**
      * Constructor for inactive replicas. 
@@ -141,73 +141,73 @@ public:
      */
     SessionRouterOperation(const SessionContextPtr& context,
                            S defaultState) 
-		: mFinished(false),
+        : mFinished(false),
           mSessionContext(context),
           mStateMachine(defaultState)
-	{
-	}
+    {
+    }
 
     virtual ~SessionRouterOperation()
-	{
-	}
+    {
+    }
 
     /** 
      * An implementation of the WorkQueue::Work interface. 
      */
     virtual void doWork()
-	{
+    {
         try
         {
-		    mStateMachine.execute();
+            mStateMachine.execute();
         }
         catch (const ::std::exception& e)
         {
             finishWithException (e);
         }
-	}
+    }
 
     /**
      * Inform initiator that this operation finished with 
      * the specified exception. 
      */
     void finishWithException(const ::std::exception& e)
-	{
-		// Forward to this operation's initiator.
-		mInitiatorCallback->ice_exception(e);
-		finish();
-	}
+    {
+        // Forward to this operation's initiator.
+        mInitiatorCallback->ice_exception(e);
+        finish();
+    }
 
     /**
      * Inform initiator that this operation finished with 
      * an unspecified exception. 
      */
     void finishWithException()
-	{
-		mInitiatorCallback->ice_exception();
-		finish();
-	}
+    {
+        mInitiatorCallback->ice_exception();
+        finish();
+    }
 
     /**
      * Inform initiator that this operation finished with 
      * an unspecified exception. 
      */
     void finishAndSendResult()
-	{
-		mInitiatorCallback->ice_response();
-		finish();
-	}
+    {
+        mInitiatorCallback->ice_response();
+        finish();
+    }
     
     /**
      * Common completion code. 
      */
     void finish()
-	{
-		// Mark internal state as finished. 
-		mFinished = true;
+    {
+        // Mark internal state as finished. 
+        mFinished = true;
 
-		// Inform our container that we are complete. 
-		mOperationsManager->finished(this);
-	}
+        // Inform our container that we are complete. 
+        mOperationsManager->finished(this);
+    }
 
     /**
      * Initiate a lookup of the requested endpoint.
@@ -215,48 +215,48 @@ public:
      *  @param current The Ice::Current reference. 
      */
     void lookupEndpoints(const std::string& destination, const ::Ice::Current current)
-	{
-		try
-		{
-			// This component's own lookup interface is implemented as AMD, so
-			// we provide our override of the appropriate AMD callback. 
+    {
+        try
+        {
+            // This component's own lookup interface is implemented as AMD, so
+            // we provide our override of the appropriate AMD callback. 
             // For state machine, note that this means the result will "callback" on the same thread
             // that called this method.
-			AMD_EndpointLocator_lookupPtr lookupCallback;
+            AMD_EndpointLocator_lookupPtr lookupCallback;
 
-			lookupCallback = new LookupCallback<T, S>(this);
+            lookupCallback = new LookupCallback<T, S>(this);
 
             // Go ahead and queue up the wait state. 
             mOperationsManager->reschedule(this);
 
-			// Lookup the destination.
-			mSessionContext->endpointRegistry->lookup_async(lookupCallback, destination, current);
-		}
-		catch (...)
-		{
-			finishWithException();
-		}
-	}
+            // Lookup the destination.
+            mSessionContext->endpointRegistry->lookup_async(lookupCallback, destination, current);
+        }
+        catch (...)
+        {
+            finishWithException();
+        }
+    }
 
     /**
      * This operation is called via a LookupCallback as a result of AMI calls 
      * to the SessionManagers' EndpointLocators. 
      */
     void setLookupResult(const AsteriskSCF::Core::Endpoint::V1::EndpointSeq& endpoints)
-	{
-		mLookupResult = endpoints;
+    {
+        mLookupResult = endpoints;
 
-		// Reschedule this operation to complete.
-		try
-		{
+        // Reschedule this operation to complete.
+        try
+        {
             // Let the operation continue on its way. 
-			mOperationsManager->reschedule(this);
-		}
-		catch(const Ice::Exception& e)
-		{
-			finishWithException(e);
-		}
-	}
+            mOperationsManager->reschedule(this);
+        }
+        catch(const Ice::Exception& e)
+        {
+            finishWithException(e);
+        }
+    }
 
     AsteriskSCF::Core::Endpoint::V1::EndpointSeq getLookupResult()
     {
@@ -368,8 +368,8 @@ AsteriskSCF::SessionCommunications::V1::BridgePrx getBridge(AsteriskSCF::Session
  * newly added sessions. 
  */
 AsteriskSCF::SessionCommunications::V1::SessionSeq createSessionForEndpoints(const AsteriskSCF::Core::Endpoint::V1::EndpointSeq& endpoints, 
-	                                                                         const std::string& destination,
-																			 const SessionListenerManagerPtr& listenerManager);
+                                                                             const std::string& destination,
+                                                                             const SessionListenerManagerPtr& listenerManager);
 
 /**
  * Accessor for the sessions in a bridge.
@@ -383,14 +383,14 @@ AsteriskSCF::SessionCommunications::V1::SessionSeq getSessionsInBridge(const Ast
  *   @except Session proxy to be excluded from the list of sessions. 
  */
 AsteriskSCF::SessionCommunications::V1::SessionSeq getSessionsInBridge(const AsteriskSCF::SessionCommunications::V1::BridgePrx& bridge, 
-	                                                                   const AsteriskSCF::SessionCommunications::V1::SessionPrx& except);
+                                                                       const AsteriskSCF::SessionCommunications::V1::SessionPrx& except);
 /**
  * Removes sessions from a bridge.
  *   @param bridge The bridge whose sessions are to be removed.
  *   @param except The only session to be left in the bridge. 
  */
 AsteriskSCF::SessionCommunications::V1::SessionSeq removeSessionsFromBridge(AsteriskSCF::SessionCommunications::V1::BridgePrx bridge, 
-	                                                                        AsteriskSCF::SessionCommunications::V1::SessionPrx except);
+                                                                            AsteriskSCF::SessionCommunications::V1::SessionPrx except);
 
 } // end BasicRoutingService
 } // end AsteriskSCF
diff --git a/src/TestContext.cpp b/src/TestContext.cpp
new file mode 100644
index 0000000..0d13006
--- /dev/null
+++ b/src/TestContext.cpp
@@ -0,0 +1,82 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010-2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/thread/locks.hpp>
+
+#include "TestContext.h"
+
+namespace AsteriskSCF
+{
+namespace BasicRoutingService
+{
+
+class TestContextPriv
+{
+public:
+    TestContextPriv() : mTestSet(false)
+    {
+    }
+
+    bool mTestSet;
+    std::string mTestMode;
+
+    boost::shared_mutex mLock;
+};
+
+TestContext::TestContext() : mImpl(new TestContextPriv()) 
+{
+}
+
+/**
+ * Indicates whether a test mode has been set for unit testing. 
+ */
+bool TestContext::hasTestMode() 
+{
+    boost::shared_lock<boost::shared_mutex> lock(mImpl->mLock);
+    return mImpl->mTestSet;
+}
+
+/**
+ * Gets the current test mode.
+ */
+std::string TestContext::getTestMode() 
+{
+    boost::shared_lock<boost::shared_mutex> lock(mImpl->mLock);
+    return mImpl->mTestMode;
+}
+
+/**
+ * Sets the current test mode. 
+ */
+void TestContext::setTestMode(std::string mode) 
+{
+    boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
+    mImpl->mTestSet = true; 
+    mImpl->mTestMode = mode;
+}
+
+/**
+ * Clears testing mode.
+ */
+void TestContext::clearTestMode()
+{
+    boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
+    mImpl->mTestSet = false;
+    mImpl->mTestMode = "";
+}
+
+} // end BasicRoutingService
+} // end AsteriskSCF
diff --git a/src/TestContext.h b/src/TestContext.h
new file mode 100644
index 0000000..9a2973c
--- /dev/null
+++ b/src/TestContext.h
@@ -0,0 +1,59 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010-2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+#pragma once
+
+
+namespace AsteriskSCF
+{
+namespace BasicRoutingService
+{
+class TestContextPriv;
+
+/** 
+ * This class provides the component's classes with the context needed for testing.
+ */
+class TestContext 
+{
+public:
+    TestContext() ;
+
+    /**
+     * Indicates whether a test mode has been set for unit testing. 
+     */
+    bool hasTestMode();
+
+    /**
+     * Gets the current test mode.
+     */
+    std::string getTestMode();
+
+    /**
+     * Sets the current test mode. 
+     */
+    void setTestMode(std::string mode);
+
+    /**
+     * Clears testing mode.
+     */
+    void clearTestMode();
+
+private:
+    boost::shared_ptr<TestContextPriv> mImpl;
+};
+typedef boost::shared_ptr<TestContext> TestContextPtr;
+
+} // end BasicRoutingService
+} // end AsteriskSCF

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


-- 
asterisk-scf/integration/routing.git



More information about the asterisk-scf-commits mailing list