[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
Sat Apr 16 21:17:23 CDT 2011


branch "route_replica" has been updated
       via  3565da61eef05819148debaa444cf4cef47601cd (commit)
      from  911fe40828872c429d3b56a9f713f72cb70d6783 (commit)

Summary of changes:
 ...nectBridgedSessionsWithDestinationOperation.cpp |   46 ++++++++----
 ...onnectBridgedSessionsWithDestinationOperation.h |    1 +
 src/RouteSessionOperation.cpp                      |   55 +++++++++-----
 src/RouteSessionOperation.h                        |    2 +
 src/SessionRouterOperation.h                       |    7 +-
 test/TestRouting.cpp                               |   78 +++++++-------------
 6 files changed, 99 insertions(+), 90 deletions(-)


- Log -----------------------------------------------------------------
commit 3565da61eef05819148debaa444cf4cef47601cd
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Sat Apr 16 21:16:18 2011 -0500

    Fixes that allow the existing tests to execute / pass as expected.

diff --git a/src/ConnectBridgedSessionsWithDestinationOperation.cpp b/src/ConnectBridgedSessionsWithDestinationOperation.cpp
index eba6e25..3901dd0 100644
--- a/src/ConnectBridgedSessionsWithDestinationOperation.cpp
+++ b/src/ConnectBridgedSessionsWithDestinationOperation.cpp
@@ -45,11 +45,18 @@ class ConnectBridgedSessionsWithDestReplicatingListener : public SimpleStateMach
 {
 public:
     ConnectBridgedSessionsWithDestReplicatingListener(ConnectBridgedSessionsWithDestinationOperationPtr op, 
-                          const ReplicationContextPtr& replication)  
-                            : mOperation(op), mReplicationContext(replication)
+                                                      const ReplicationContextPtr& replication)  
+                                                         : mOperation(op), 
+                                                           mReplicationContext(replication), 
+                                                           mTransactionId(op->getTransactionId())
     {
     }
 
+    ~ConnectBridgedSessionsWithDestReplicatingListener()
+    {
+        lg(Debug) << "ConnectBridgedSessionsWithDestReplicatingListener() being destroyed for transaction " << mTransactionId;
+    }
+
     /**
      * This callback is called just before the execution of a state machine's current state handler. 
      */
@@ -135,14 +142,18 @@ public:
      */
     void shutdown()
     {
-        if (!mReplicationContext->isReplicating())
+        try
+        {
+            if (mReplicationContext->isReplicating())
+            {
+                // We just completed the entire operation. 
+                // Remove the items that represented this operation's state transitions from the state replicator.
+                mReplicationContext->getReplicatorService()->removeState(mReplicatedStateKeys);
+            }
+        }
+        catch(...)
         {
-            return;
         }
-
-        // We just completed the entire operation. 
-        // Remove the items that represented this operation's state transitions from the state replicator.
-        mReplicationContext->getReplicatorService()->removeState(mReplicatedStateKeys);
 
         // Release our reference to the operation. 
         mOperation.reset();
@@ -158,11 +169,20 @@ public:
 
 private:
     Ice::StringSeq mReplicatedStateKeys;
+    std::string mTransactionId;
     ConnectBridgedSessionsWithDestinationOperationPtr mOperation;
     ReplicationContextPtr mReplicationContext;
 
 }; // end ConnectBridgedSessionsWithDestReplicatingListener
 
+void ConnectBridgedSessionsWithDestinationOperation::initStateMachine()
+{
+    mStateMachine.addState(ConnectBridgedSessionsWithDestinationOp::STATE_LOOKUP, boost::bind(&ConnectBridgedSessionsWithDestinationOperation::lookupState, this));
+    mStateMachine.addState(ConnectBridgedSessionsWithDestinationOp::STATE_WAIT_LOOKUP_RESULTS, boost::bind(&ConnectBridgedSessionsWithDestinationOperation::waitOnLookupState, this));
+    mStateMachine.addState(ConnectBridgedSessionsWithDestinationOp::STATE_BRIDGING, boost::bind(&ConnectBridgedSessionsWithDestinationOperation::establishBridgeState, this));
+    mStateMachine.addState(ConnectBridgedSessionsWithDestinationOp::STATE_SEND_RESPONSE, boost::bind(&ConnectBridgedSessionsWithDestinationOperation::sendResponseState, this));
+}
+
 /**
  * Primary constructor. This class represents an operation that replaces one session in a 
  * Bridge with a new session routable by the destination param. 
@@ -185,10 +205,7 @@ ConnectBridgedSessionsWithDestinationOperation::ConnectBridgedSessionsWithDestin
         mSessionToReplace(sessionToReplace),
         mDestination(destination)
 {
-    mStateMachine.addState(ConnectBridgedSessionsWithDestinationOp::STATE_LOOKUP, boost::bind(&ConnectBridgedSessionsWithDestinationOperation::lookupState, this));
-    mStateMachine.addState(ConnectBridgedSessionsWithDestinationOp::STATE_WAIT_LOOKUP_RESULTS, boost::bind(&ConnectBridgedSessionsWithDestinationOperation::waitOnLookupState, this));
-    mStateMachine.addState(ConnectBridgedSessionsWithDestinationOp::STATE_BRIDGING, boost::bind(&ConnectBridgedSessionsWithDestinationOperation::establishBridgeState, this));
-    mStateMachine.addState(ConnectBridgedSessionsWithDestinationOp::STATE_SEND_RESPONSE, boost::bind(&ConnectBridgedSessionsWithDestinationOperation::sendResponseState, this));
+    initStateMachine();
 }
 
 /**
@@ -233,10 +250,7 @@ ConnectBridgedSessionsWithDestinationOperation::ConnectBridgedSessionsWithDestin
                                 ConnectBridgedSessionsWithDestinationOp::STATE_LOOKUP
                                 )
 {
-    mStateMachine.addState(ConnectBridgedSessionsWithDestinationOp::STATE_LOOKUP, boost::bind(&ConnectBridgedSessionsWithDestinationOperation::lookupState, this));
-    mStateMachine.addState(ConnectBridgedSessionsWithDestinationOp::STATE_WAIT_LOOKUP_RESULTS, boost::bind(&ConnectBridgedSessionsWithDestinationOperation::waitOnLookupState, this));
-    mStateMachine.addState(ConnectBridgedSessionsWithDestinationOp::STATE_BRIDGING, boost::bind(&ConnectBridgedSessionsWithDestinationOperation::establishBridgeState, this));
-    mStateMachine.addState(ConnectBridgedSessionsWithDestinationOp::STATE_SEND_RESPONSE, boost::bind(&ConnectBridgedSessionsWithDestinationOperation::sendResponseState, this));
+    initStateMachine();
 }
 
 /**
diff --git a/src/ConnectBridgedSessionsWithDestinationOperation.h b/src/ConnectBridgedSessionsWithDestinationOperation.h
index 7052b48..dd38cd8 100644
--- a/src/ConnectBridgedSessionsWithDestinationOperation.h
+++ b/src/ConnectBridgedSessionsWithDestinationOperation.h
@@ -112,6 +112,7 @@ protected:
     ConnectBridgedSessionsWithDestinationOperation(const SessionContextPtr& context);
 
 private:
+    void initStateMachine();
 
     void reflectUpdate(AsteriskSCF::BasicRoutingService::V1::ConnectBridgedSessionsWithDestinationOpStartPtr stateItem);
     void reflectUpdate(AsteriskSCF::BasicRoutingService::V1::ConnectBridgedSessionsWithDestinationOpWaitLookupStatePtr stateItem);
diff --git a/src/RouteSessionOperation.cpp b/src/RouteSessionOperation.cpp
index feb44ac..4c3dcc6 100644
--- a/src/RouteSessionOperation.cpp
+++ b/src/RouteSessionOperation.cpp
@@ -45,11 +45,18 @@ class RouteSessionReplicatingListener : public SimpleStateMachine<RouteSessionOp
 {
 public:
     RouteSessionReplicatingListener(RouteSessionOperationPtr op, 
-                          const ReplicationContextPtr& replicationContext)  
-                            : mOperation(op), mReplicationContext(replicationContext)
+                                    const ReplicationContextPtr& replicationContext)  
+                                       : mOperation(op), 
+                                         mReplicationContext(replicationContext), 
+                                         mTransactionId(op->getTransactionId())
     {
     }
 
+    ~RouteSessionReplicatingListener()
+    {
+        lg(Debug) << "RouteSessionReplicatingListener() being destroyed for transaction " << mTransactionId;
+    }
+
     /**
      * This callback is called just before the execution of a state machine's current state handler. 
      */
@@ -137,14 +144,18 @@ public:
      */
     void shutdown()
     {
-        if (!mReplicationContext->isReplicating())
+        try
+        {
+            if (mReplicationContext->isReplicating())
+            {
+                // We just completed the entire operation. 
+                // Remove the items that represented this operation's state transitions.
+                mReplicationContext->getReplicatorService()->removeState(mReplicatedStateKeys);
+            }
+        }
+        catch(...)
         {
-            return;
         }
-
-        // We just completed the entire operation. 
-        // Remove the items that represented this operation's state transitions.
-        mReplicationContext->getReplicatorService()->removeState(mReplicatedStateKeys);
 
         // Release our reference to the operation. 
         mOperation.reset();
@@ -159,11 +170,23 @@ public:
 
 private:
     Ice::StringSeq mReplicatedStateKeys;
+    std::string mTransactionId;
     RouteSessionOperationPtr mOperation;
     ReplicationContextPtr mReplicationContext;
 };
 
 /**
+ * Configure this operation's state machine with state handlers. 
+ */
+void RouteSessionOperation::initStateMachine()
+{
+    mStateMachine.addState(RouteSessionOp::STATE_LOOKUP, boost::bind(&RouteSessionOperation::lookupState, this));
+    mStateMachine.addState(RouteSessionOp::STATE_WAIT_LOOKUP_RESULTS, boost::bind(&RouteSessionOperation::waitOnLookupState, this));
+    mStateMachine.addState(RouteSessionOp::STATE_BRIDGING, boost::bind(&RouteSessionOperation::establishBridgeState, this));
+    mStateMachine.addState(RouteSessionOp::STATE_SEND_RESPONSE, boost::bind(&RouteSessionOperation::sendResponseState, this));
+}
+
+/**
  * Constructor. This class is a specialization of the SessionRouterOperation<T> to handle the
  * routeSession() operation. 
  * 
@@ -186,11 +209,7 @@ RouteSessionOperation::RouteSessionOperation(const AMD_SessionRouter_routeSessio
                 mSource(source),
                 mDestination(destination)
 {
-    // Configure the state machine with state handlers. 
-    mStateMachine.addState(RouteSessionOp::STATE_LOOKUP, boost::bind(&RouteSessionOperation::lookupState, this));
-    mStateMachine.addState(RouteSessionOp::STATE_WAIT_LOOKUP_RESULTS, boost::bind(&RouteSessionOperation::waitOnLookupState, this));
-    mStateMachine.addState(RouteSessionOp::STATE_BRIDGING, boost::bind(&RouteSessionOperation::establishBridgeState, this));
-    mStateMachine.addState(RouteSessionOp::STATE_SEND_RESPONSE, boost::bind(&RouteSessionOperation::sendResponseState, this));
+    initStateMachine();
 }
 
 /**
@@ -232,11 +251,7 @@ RouteSessionOperationPtr RouteSessionOperation::create(const AMD_SessionRouter_r
 RouteSessionOperation::RouteSessionOperation(const SessionContextPtr& sessionContext) 
                 : SessionRouterOperation<AMD_SessionRouter_routeSessionPtr, RouteSessionOp::OperationState>(sessionContext, RouteSessionOp::STATE_LOOKUP)
 {
-    // Configure the state machine with state handlers. 
-    mStateMachine.addState(RouteSessionOp::STATE_LOOKUP, boost::bind(&RouteSessionOperation::lookupState, this));
-    mStateMachine.addState(RouteSessionOp::STATE_WAIT_LOOKUP_RESULTS, boost::bind(&RouteSessionOperation::waitOnLookupState, this));
-    mStateMachine.addState(RouteSessionOp::STATE_BRIDGING, boost::bind(&RouteSessionOperation::establishBridgeState, this));
-    mStateMachine.addState(RouteSessionOp::STATE_SEND_RESPONSE, boost::bind(&RouteSessionOperation::sendResponseState, this));
+    initStateMachine();
 }
 
 /**
@@ -331,7 +346,7 @@ bool RouteSessionOperation::fastForwardReplica()
 
 RouteSessionOperation::~RouteSessionOperation() 
 {
-        lg(Debug) << "RouteSessionOperation() being destroyed for " << mDestination ;
+    lg(Debug) << "RouteSessionOperation() being destroyed for " << mDestination ;
 }
 
 /**
@@ -380,7 +395,7 @@ void RouteSessionOperation::waitOnLookupState()
         return;
     }
 
-    // Set the state handler to exectute once we've looked up our endpoints. 
+    // Set the state machine to next state.
     mStateMachine.setNextState(RouteSessionOp::STATE_BRIDGING);
 }
 
diff --git a/src/RouteSessionOperation.h b/src/RouteSessionOperation.h
index ea4a058..4934cef 100644
--- a/src/RouteSessionOperation.h
+++ b/src/RouteSessionOperation.h
@@ -110,6 +110,8 @@ protected:
    RouteSessionOperation(const SessionContextPtr& context);
 
 private:
+    void initStateMachine();
+
     /**
      * Update a replica object with new state information of a specific type.
      */
diff --git a/src/SessionRouterOperation.h b/src/SessionRouterOperation.h
index c6d486c..6e3f0df 100644
--- a/src/SessionRouterOperation.h
+++ b/src/SessionRouterOperation.h
@@ -226,6 +226,9 @@ public:
 
 			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);
 		}
@@ -246,9 +249,7 @@ public:
 		// Reschedule this operation to complete.
 		try
 		{
-            // Get the state machine transitioned to next state. 
-            doWork(); 
-
+            // Let the operation continue on its way. 
 			mOperationsManager->reschedule(this);
 		}
 		catch(const Ice::Exception& e)
diff --git a/test/TestRouting.cpp b/test/TestRouting.cpp
index f4a2ae1..7213d63 100644
--- a/test/TestRouting.cpp
+++ b/test/TestRouting.cpp
@@ -293,34 +293,25 @@ public:
  */
 BOOST_AUTO_TEST_CASE(AddAndRemoveEndpointLocator)
 {
-    bool addLocatorSucceeded(true);
     try
     {
         SharedTestData::instance.locatorRegistry->addEndpointLocator("TestChannel", SharedTestData::instance.regExIds, SharedTestData::instance.endpointLocatorPrx);
     }
     catch (...)
     {
-        addLocatorSucceeded = false;
-        BOOST_TEST_MESSAGE("Exception adding EndpointLocator.");
+        BOOST_FAIL("Exception adding EndpointLocator.");
     }
 
-    BOOST_CHECK(addLocatorSucceeded);
-
-    bool removeLocatorSucceeded(true);
     try
     {
         SharedTestData::instance.locatorRegistry->removeEndpointLocator("TestChannel");
-
     }
     catch (...)
     {
-        removeLocatorSucceeded = false;
-        BOOST_TEST_MESSAGE("Exception removing EndpointLocator.");
+        BOOST_FAIL("Exception removing EndpointLocator.");
     }
-    BOOST_CHECK(removeLocatorSucceeded);
 
     BOOST_TEST_MESSAGE("Completed AddAndRemoveEndpointLocator test.");
-
 }
 
 /**
@@ -330,7 +321,6 @@ BOOST_AUTO_TEST_CASE(AddAndRemoveEndpointLocator)
  */
 BOOST_AUTO_TEST_CASE(AddEndpointLocatorTwice)
 {
-    bool addLocatorSucceeded(true);
     try
     {
         SharedTestData::instance.locatorRegistry->addEndpointLocator("TestChannel", SharedTestData::instance.regExIds, SharedTestData::instance.endpointLocatorPrx);
@@ -338,27 +328,19 @@ BOOST_AUTO_TEST_CASE(AddEndpointLocatorTwice)
     }
     catch (...)
     {
-        addLocatorSucceeded = false;
-        BOOST_TEST_MESSAGE("Exception adding EndpointLocator the second time.");
+        BOOST_FAIL("Exception adding EndpointLocator the second time.");
     }
 
-    BOOST_CHECK(addLocatorSucceeded);
-
-    bool removeLocatorSucceeded(true);
     try
     {
         SharedTestData::instance.locatorRegistry->removeEndpointLocator("TestChannel");
-
     }
     catch (...)
     {
-        removeLocatorSucceeded = false;
-        BOOST_TEST_MESSAGE("Exception removing EndpointLocator.");
+         BOOST_FAIL("Exception removing EndpointLocator.");
     }
-    BOOST_CHECK(removeLocatorSucceeded);
 
     BOOST_TEST_MESSAGE("Completed AddEndpointLocatorTwice test.");
-
 }
 
 /**
@@ -379,17 +361,13 @@ BOOST_FIXTURE_TEST_CASE(LookupOwnEndpoint, PerTestFixture)
     }
     catch(const IceUtil::Exception &ie)
     {
-        bool IceException(false);
-        string msg = "Exception looking up our own endpoint:";
+        string msg = "Exception looking up our own endpoint: ";
         msg += ie.what();
-        BOOST_TEST_MESSAGE(msg);
-        BOOST_CHECK(IceException);
+        BOOST_FAIL(msg);
     }
     catch (...)
     {
-        bool unknownException(false);
-        BOOST_TEST_MESSAGE("Exception looking up our own endpoint.");
-        BOOST_CHECK(unknownException);
+        BOOST_FAIL("Unknown exception looking up our own endpoint.");
     }
 
     BOOST_TEST_MESSAGE("Completed LookupOwnEndpoint test.");
@@ -442,17 +420,13 @@ BOOST_FIXTURE_TEST_CASE(RouteSession, PerTestFixture)
     }
     catch(const IceUtil::Exception &ie)
     {
-        bool IceException(false);
-        string msg = "Exception in RouteSession:";
+        string msg = "Exception in RouteSession: ";
         msg += ie.what();
-        BOOST_TEST_MESSAGE(msg);
-        BOOST_CHECK(IceException);
+        BOOST_FAIL(msg);
     }
     catch (...)
     {
-        bool unknownException(false);
-        BOOST_TEST_MESSAGE("Exception in RouteSession:");
-        BOOST_CHECK(unknownException);
+        BOOST_FAIL("Unknown exception in RouteSession:");
     }
 }
 
@@ -476,16 +450,22 @@ BOOST_FIXTURE_TEST_CASE(BlindTransfer, PerTestFixture)
         SharedTestData::instance.mSessionReplaced = false;
 
         BOOST_TEST_MESSAGE("Routing the session...");
+        {
         Ice::Context iceContext;
         iceContext[AsteriskSCF::SessionCommunications::V1::TransactionKey] = "Test_BlindTransfer_" + IceUtil::generateUUID();
         SharedTestData::instance.sessionRouter->routeSession(session, "102", iceContext);
+        }
 
         BridgePrx bridge = session->getBridge();
         BOOST_CHECK(bridge != 0);
         BOOST_CHECK(SharedTestData::instance.mBridgeConnected);
 
         // Now transfer to a new extension.
-        SharedTestData::instance.sessionRouter->connectBridgedSessionsWithDestination(session, "103");
+        {
+        Ice::Context iceContext;
+        iceContext[AsteriskSCF::SessionCommunications::V1::TransactionKey] = "Test_BlindTransfer_" + IceUtil::generateUUID();
+        SharedTestData::instance.sessionRouter->connectBridgedSessionsWithDestination(session, "103", iceContext);
+        }
 
         BOOST_CHECK(SharedTestData::instance.mSessionReplaced);
 
@@ -506,17 +486,13 @@ BOOST_FIXTURE_TEST_CASE(BlindTransfer, PerTestFixture)
     }
     catch(const IceUtil::Exception &ie)
     {
-        bool IceException(false);
-        string msg = "Exception routing session:";
+        string msg = "Exception routing session: ";
         msg += ie.what();
-        BOOST_TEST_MESSAGE(msg);
-        BOOST_CHECK(IceException);
+        BOOST_FAIL(msg);
     }
     catch (...)
     {
-        bool unknownException(false);
-        BOOST_TEST_MESSAGE("Exception routing session.");
-        BOOST_CHECK(unknownException);
+        BOOST_FAIL("Unknown exception routing session.");
     }
 }
 
@@ -565,7 +541,11 @@ BOOST_FIXTURE_TEST_CASE(AttendedTransfer, PerTestFixture)
 
         // Now bridge 102 and 104 into the first pair's bridge
         BridgePrx survivingBridge = session101->getBridge(); // Cache for testing.
-        SharedTestData::instance.sessionRouter->connectBridgedSessions(session101, session103);
+        {
+        Ice::Context iceContext;
+        iceContext[AsteriskSCF::SessionCommunications::V1::TransactionKey] = "Test_BlindTransfer_" + IceUtil::generateUUID();
+        SharedTestData::instance.sessionRouter->connectBridgedSessions(session101, session103, iceContext);
+        }
 
         BOOST_CHECK(SharedTestData::instance.mSessionReplaced);
 
@@ -586,16 +566,12 @@ BOOST_FIXTURE_TEST_CASE(AttendedTransfer, PerTestFixture)
     }
     catch(const IceUtil::Exception &ie)
     {
-        bool IceException(false);
         string msg = "Exception in AttendedTransfer:";
         msg += ie.what();
-        BOOST_TEST_MESSAGE(msg);
-        BOOST_CHECK(IceException);
+        BOOST_FAIL(msg);
     }
     catch (...)
     {
-        bool unknownException(false);
-        BOOST_TEST_MESSAGE("Exception in AttendedTransfer:");
-        BOOST_CHECK(unknownException);
+        BOOST_FAIL("Unknown exception in AttendedTransfer:");
     }
 }

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


-- 
asterisk-scf/integration/routing.git



More information about the asterisk-scf-commits mailing list