[asterisk-scf-commits] asterisk-scf/integration/routing.git branch "master" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Sun Oct 17 17:26:23 CDT 2010
branch "master" has been updated
via 3e3d5c98ed885b9fc5b17847ca96dcd11fabd148 (commit)
from a463ab8ecb76e29a31182414770378fd885b01b8 (commit)
Summary of changes:
src/SessionRouter.cpp | 70 ++++++++++++++++++++++++++---------------
test/MockBridge.cpp | 29 ++++++++++-------
test/MockEndpointLocator.cpp | 4 +-
test/MockSession.cpp | 53 +++++++++++++++++++++++++++++--
test/MockSession.h | 2 +
test/MockSessionEndpoint.cpp | 6 ++--
test/MockSessionEndpoint.h | 2 +-
test/TestRouting.cpp | 2 +-
8 files changed, 119 insertions(+), 49 deletions(-)
- Log -----------------------------------------------------------------
commit 3e3d5c98ed885b9fc5b17847ca96dcd11fabd148
Author: Ken Hunt <ken.hunt at digium.com>
Date: Sun Oct 17 17:25:39 2010 -0500
Bug fixes to SessionRouter. Enhanced testing.
diff --git a/src/SessionRouter.cpp b/src/SessionRouter.cpp
index 3f1a501..c33cdec 100644
--- a/src/SessionRouter.cpp
+++ b/src/SessionRouter.cpp
@@ -126,7 +126,7 @@ public:
}
/**
- * git listening to all sessions we're monitoring.
+ * Stop listening to all sessions we're monitoring.
*/
void unregister()
{
@@ -134,6 +134,9 @@ public:
{
(*s)->removeListener(mListenerPrx);
}
+
+ // Since we're through listening to them, we should just drop our references to them.
+ mSessions.clear();
}
SessionListenerPrx getProxy()
@@ -151,7 +154,8 @@ typedef IceInternal::Handle<SessionListenerImpl> SessionListenerImplPtr;
/**
* This class uses RAII to manage the lifecycle of a session listener.
- *
+ * It's sort of a smart pointer for the listener, but it's tightly
+ * coupled to the specifics of our private impl.
*/
class SessionListenerAllocator
{
@@ -170,23 +174,26 @@ public:
~SessionListenerAllocator()
{
- try
- {
- mSessionListener->unregister();
- }
- catch(...)
- {
- }
-
- try
- {
- // Only the adapter holds a smart pointer for this servant, so this will
- // cause it to be delted.
- mAdapter->remove(mSessionListener->getProxy()->ice_getIdentity());
- }
- catch(...)
- {
- }
+ // Our private SessionListener implementation adds itself as a servant. It
+ // can't really undo that without getting itself deleted. So undo it
+ // in proper order.
+ try
+ {
+ mSessionListener->unregister();
+ }
+ catch(...)
+ {
+ }
+
+ try
+ {
+ // Only the adapter holds a smart pointer for this servant, so this will
+ // cause it to be delted.
+ mAdapter->remove(mSessionListener->getProxy()->ice_getIdentity());
+ }
+ catch(...)
+ {
+ }
}
SessionListenerImpl* operator->()
@@ -332,11 +339,21 @@ void SessionRouter::routeSession(const AsteriskSCF::SessionCommunications::V1::S
throw SourceTerminatedPreBridgingException(source->getEndpoint()->getId());
}
+ // We're through listening. And we will probably interfere with the Bridge's functionality if
+ // we keep listening.
+ listener->unregister();
+
// Create the bridge
BridgePrx bridge;
try
{
- bridge = mImpl->mBridgeManagerAccessor->getBridgeManager()->createBridge(listener->getSessions(), 0);
+ SessionSeq bridgedSessions;
+ bridgedSessions.push_back(source);
+
+ bridgedSessions.reserve(bridgedSessions.size() + newSessions.size());
+ bridgedSessions.insert(bridgedSessions.end(), newSessions.begin(), newSessions.end());
+
+ bridge = mImpl->mBridgeManagerAccessor->getBridgeManager()->createBridge(bridgedSessions, 0);
}
catch (const Ice::Exception &)
{
@@ -400,7 +417,6 @@ void SessionRouter::connectBridgedSessionsWithDestination(const SessionPrx& sess
EndpointSeq endpoints = mImpl->lookupEndpoints(destination, current);
// Add a session
- SessionPrx destSession(0);
SessionSeq newSessions;
for (EndpointSeq::iterator e = endpoints.begin(); e != endpoints.end(); ++e)
{
@@ -409,7 +425,7 @@ void SessionRouter::connectBridgedSessionsWithDestination(const SessionPrx& sess
SessionEndpointPrx sessionEndpoint = SessionEndpointPrx::checkedCast(*e);
// Create a session on the destination.
- destSession = sessionEndpoint->createSession(destination, listener->getProxy());
+ SessionPrx destSession = sessionEndpoint->createSession(destination, listener->getProxy());
listener->addSession(destSession);
newSessions.push_back(destSession);
}
@@ -435,9 +451,7 @@ void SessionRouter::connectBridgedSessionsWithDestination(const SessionPrx& sess
// Modify the bridge
try
{
- SessionSeq seq;
- seq.push_back(destSession);
- bridge->replaceSession(sessionToReplace, seq);
+ bridge->replaceSession(sessionToReplace, newSessions);
}
catch (const Ice::Exception &e)
{
@@ -524,6 +538,10 @@ void SessionRouter::connectBridgedSessions(const SessionPrx& sessionToReplace,
throw SourceTerminatedPreBridgingException(preserveSessions[0]->getEndpoint()->getId());
}
+ // We're through listening. And we will probably interfere with the Bridge's functionality if
+ // we keep listening.
+ listener->unregister();
+
SessionSeq migratingSessions;
if (oldBridge != 0)
{
@@ -533,7 +551,7 @@ void SessionRouter::connectBridgedSessions(const SessionPrx& sessionToReplace,
SessionSeq allSessions = oldBridge->listSessions();
for(SessionSeq::iterator s = allSessions.begin(); s != allSessions.end(); ++s)
{
- if ((*s) != bridgedSession)
+ if ((*s)->ice_getIdentity() != bridgedSession->ice_getIdentity())
{
migratingSessions.push_back(*s);
}
diff --git a/test/MockBridge.cpp b/test/MockBridge.cpp
index 7ff928a..db7852d 100644
--- a/test/MockBridge.cpp
+++ b/test/MockBridge.cpp
@@ -26,34 +26,33 @@ public:
{
}
- // The listener overrides...
-
- void connected(const AsteriskSCF::SessionCommunications::V1::SessionPrx& session, const Ice::Current&)
+ // Overrides
+ virtual void connected(const AsteriskSCF::SessionCommunications::V1::SessionPrx& session, const Ice::Current&)
{
mBridge->connected(session);
}
- void flashed(const AsteriskSCF::SessionCommunications::V1::SessionPrx&, const Ice::Current&)
+ virtual void flashed(const AsteriskSCF::SessionCommunications::V1::SessionPrx&, const Ice::Current&)
{
}
- void held(const AsteriskSCF::SessionCommunications::V1::SessionPrx&, const Ice::Current&)
+ virtual void held(const AsteriskSCF::SessionCommunications::V1::SessionPrx&, const Ice::Current&)
{
}
- void progressing(const AsteriskSCF::SessionCommunications::V1::SessionPrx&, const AsteriskSCF::SessionCommunications::V1::ResponseCodePtr&, const Ice::Current&)
+ virtual void progressing(const AsteriskSCF::SessionCommunications::V1::SessionPrx&, const AsteriskSCF::SessionCommunications::V1::ResponseCodePtr&, const Ice::Current&)
{
}
- void ringing(const AsteriskSCF::SessionCommunications::V1::SessionPrx&, const Ice::Current&)
+ virtual void ringing(const AsteriskSCF::SessionCommunications::V1::SessionPrx&, const Ice::Current&)
{
}
- void stopped(const AsteriskSCF::SessionCommunications::V1::SessionPrx&, const AsteriskSCF::SessionCommunications::V1::ResponseCodePtr&, const Ice::Current&)
+ virtual void stopped(const AsteriskSCF::SessionCommunications::V1::SessionPrx&, const AsteriskSCF::SessionCommunications::V1::ResponseCodePtr&, const Ice::Current&)
{
}
- void unheld(const AsteriskSCF::SessionCommunications::V1::SessionPrx&, const Ice::Current&)
+ virtual void unheld(const AsteriskSCF::SessionCommunications::V1::SessionPrx&, const Ice::Current&)
{
}
@@ -77,7 +76,10 @@ MockBridge::MockBridge(const SessionSeq& sessions, const BridgeListenerPrx& list
MockBridge::~MockBridge()
{
- SharedTestData::instance.adapterIn->remove(SharedTestData::instance.communicatorIn->stringToIdentity(mListener->ice_id()));
+ SharedTestData::instance.adapterIn->remove(mListenerPrx->ice_getIdentity());
+ SharedTestData::instance.adapterIn->remove(mBridgePrx->ice_getIdentity());
+
+ mListener = 0;
}
void MockBridge::addSessions(const SessionSeq& newSessions, const Ice::Current&)
@@ -103,10 +105,10 @@ void MockBridge::removeSession(const SessionPrx& session)
{
for(SessionSeq::iterator s = mSessions.begin(); s != mSessions.end(); ++s)
{
- if ((*s) == session)
+ if ((*s)->ice_getIdentity() == session->ice_getIdentity())
{
mSessions.erase(s);
- return;
+ break;
}
}
session->removeBridge(mListenerPrx);
@@ -141,6 +143,9 @@ void MockBridge::replaceSession(const AsteriskSCF::SessionCommunications::V1::Se
removeSession(sessionToReplace);
addSessions(newSessions);
+
+ ResponseCodePtr response = new ResponseCode(1);
+ sessionToReplace->stop(response);
}
void MockBridge::connected(const AsteriskSCF::SessionCommunications::V1::SessionPrx& session)
diff --git a/test/MockEndpointLocator.cpp b/test/MockEndpointLocator.cpp
index 7a8b691..b5a12ba 100644
--- a/test/MockEndpointLocator.cpp
+++ b/test/MockEndpointLocator.cpp
@@ -60,9 +60,9 @@ void MockEndpointLocator::perTestCleanup()
void MockEndpointLocator::clear()
{
- for(vector<MockSessionEndpointPtr>::iterator i = mEndpoints.begin(); i != mEndpoints.end(); ++i)
+ for(vector<BaseEndpointPrx>::iterator i = mEndpointPrxList.begin(); i != mEndpointPrxList.end(); ++i)
{
- SharedTestData::instance.adapterIn->remove(SharedTestData::instance.communicatorIn->stringToIdentity((*i)->ice_id()));
+ SharedTestData::instance.adapterIn->remove((*i)->ice_getIdentity());
}
mEndpointPrxList.clear();
diff --git a/test/MockSession.cpp b/test/MockSession.cpp
index 0de6135..822aa00 100644
--- a/test/MockSession.cpp
+++ b/test/MockSession.cpp
@@ -8,6 +8,7 @@
#define BOOST_TEST_DYN_LINK
#include <Ice/Ice.h>
+#include <boost/test/unit_test.hpp>
#include "MockSession.h"
#include "SharedTestData.h"
@@ -20,7 +21,31 @@ namespace AsteriskSCF
namespace RoutingTest
{
-MockSession::MockSession(const string& legId, const string& sessionId, const AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx& endpointPrx)
+/**
+* A functor to send stop() to a SessionListener.
+*/
+class SendStop
+{
+public:
+ SendStop(const SessionPrx& myProxy, const ResponseCodePtr& response)
+ : mMyProxy(myProxy),
+ mResponse(response)
+ {
+ }
+
+ void operator()(const SessionListenerPrx& l)
+ {
+ l->stopped(mMyProxy, mResponse);
+ }
+
+private:
+ SessionPrx mMyProxy;
+ ResponseCodePtr mResponse;
+};
+
+MockSession::MockSession(const string& legId,
+ const string& sessionId,
+ const AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx& endpointPrx)
: mLegId(legId),
mId(sessionId),
mEndpointPrx(endpointPrx),
@@ -32,10 +57,20 @@ MockSession::MockSession(const string& legId, const string& sessionId, const Ast
mSessionInfo->role = legId; // for testing
}
+MockSession::~MockSession()
+{
+ BOOST_TEST_MESSAGE("Session " + mLegId + " deleted.");
+}
+
SessionInfoPtr MockSession::addListener(const SessionListenerPrx& listener, const Ice::Current&)
{
mListeners.push_back(listener);
+ if (mListeners.size() > 1)
+ {
+ BOOST_TEST_MESSAGE("Session " + mId + " has more than one listener.");
+ }
+
return mSessionInfo;
}
@@ -74,8 +109,16 @@ void MockSession::progress(const ResponseCodePtr&, const Ice::Current&)
{
}
-void MockSession::removeListener(const SessionListenerPrx&, const Ice::Current&)
+void MockSession::removeListener(const SessionListenerPrx& listener, const Ice::Current&)
{
+ for(vector<SessionListenerPrx>::iterator i = mListeners.begin(); i != mListeners.end(); ++i)
+ {
+ if ((*i)->ice_getIdentity() == listener->ice_getIdentity())
+ {
+ mListeners.erase(i);
+ break;
+ }
+ }
}
void MockSession::ring(const Ice::Current&)
@@ -93,9 +136,11 @@ void MockSession::start(const Ice::Current&)
}
}
-void MockSession::stop(const ResponseCodePtr&, const Ice::Current&)
+void MockSession::stop(const ResponseCodePtr& response, const Ice::Current&)
{
- cout << "Session stopped." << endl;
+ BOOST_TEST_MESSAGE("Session " + mLegId + " stopped.");
+
+ std::for_each(mListeners.begin(), mListeners.end(), SendStop(mMyPrx, response));
}
void MockSession::unhold(const Ice::Current&)
diff --git a/test/MockSession.h b/test/MockSession.h
index 1c9dc0b..547c0e3 100644
--- a/test/MockSession.h
+++ b/test/MockSession.h
@@ -19,6 +19,7 @@ class MockSession : public AsteriskSCF::SessionCommunications::V1::Session
{
public:
MockSession(const std::string& legId, const std::string& sessionId, const AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx& endpointPrx);
+ ~MockSession();
public:
// Overrides
@@ -43,6 +44,7 @@ public:
public:
void setProxy(const AsteriskSCF::SessionCommunications::V1::SessionPrx& sessionPrx);
const std::string& getId() const {return mId;}
+ void destroy();
private:
std::string mId;
diff --git a/test/MockSessionEndpoint.cpp b/test/MockSessionEndpoint.cpp
index 510016e..248e10c 100644
--- a/test/MockSessionEndpoint.cpp
+++ b/test/MockSessionEndpoint.cpp
@@ -52,12 +52,12 @@ void MockSessionEndpoint::setProxy(const SessionEndpointPrx& proxy)
void MockSessionEndpoint::perTestCleanup()
{
- for(vector<MockSessionPtr>::iterator i = mSessions.begin(); i != mSessions.end(); ++i)
+ for(SessionSeq::iterator i = mSessionPrxList.begin(); i != mSessionPrxList.end(); ++i)
{
- string id = (*i)->getId();
- SharedTestData::instance.adapterIn->remove(SharedTestData::instance.communicatorIn->stringToIdentity(id));
+ SharedTestData::instance.adapterIn->remove((*i)->ice_getIdentity());
}
+ mSessionPrxList.clear();
mSessions.clear();
}
diff --git a/test/MockSessionEndpoint.h b/test/MockSessionEndpoint.h
index 88d9a4f..8d0070f 100644
--- a/test/MockSessionEndpoint.h
+++ b/test/MockSessionEndpoint.h
@@ -40,7 +40,7 @@ public:
private:
std::vector<MockSessionPtr> mSessions;
- std::vector<AsteriskSCF::SessionCommunications::V1::SessionPrx> mSessionPrxList;
+ AsteriskSCF::SessionCommunications::V1::SessionSeq mSessionPrxList;
std::string mId;
AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx mProxy;
int mCounter;
diff --git a/test/TestRouting.cpp b/test/TestRouting.cpp
index bf51511..9a85488 100644
--- a/test/TestRouting.cpp
+++ b/test/TestRouting.cpp
@@ -403,7 +403,7 @@ BOOST_FIXTURE_TEST_CASE(RouteSession, PerTestFixture)
BOOST_TEST_MESSAGE("Routing the session...");
SharedTestData::instance.sessionRouter->routeSession(session, "102");
-
+
BOOST_CHECK(SharedTestData::instance.mBridgeConnected);
}
catch(const IceUtil::Exception &ie)
-----------------------------------------------------------------------
--
asterisk-scf/integration/routing.git
More information about the asterisk-scf-commits
mailing list