[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
Tue Sep 14 20:20:51 CDT 2010


branch "master" has been updated
       via  ff300369efbbe9fd40017bde0deda206d884d511 (commit)
       via  bc4f8cabee3098b1633e90c281ff632bfdead8b8 (commit)
      from  f2483e8c9e47362d7a4add04c2a81234f3b53046 (commit)

Summary of changes:
 config/README.txt              |   16 +
 config/basicrouting.config     |    7 +-
 config/icestorm.config         |    7 +-
 config/routingtest.config      |   23 ++-
 config/service_locator.config  |   14 +
 src/BasicRoutingServiceApp.cpp |   80 +++++-
 test/CMakeLists.txt            |    2 +
 test/TestRouting.cpp           |  593 +++++++++++++++++++++++++++++++++++-----
 8 files changed, 651 insertions(+), 91 deletions(-)
 create mode 100644 config/README.txt
 create mode 100644 config/service_locator.config


- Log -----------------------------------------------------------------
commit ff300369efbbe9fd40017bde0deda206d884d511
Merge: f2483e8 bc4f8ca
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Tue Sep 14 20:17:07 2010 -0500

    Merge branch 'dev'


commit bc4f8cabee3098b1633e90c281ff632bfdead8b8
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Tue Sep 14 20:14:38 2010 -0500

    First working version with tests.

diff --git a/config/README.txt b/config/README.txt
new file mode 100644
index 0000000..a79aa00
--- /dev/null
+++ b/config/README.txt
@@ -0,0 +1,16 @@
+
+
+Run Order for testing:
+
+  iceboxd --Ice.Config=icestorm.config
+ 
+  service_locator --Ice.Config=test_service_locator.config
+
+  RoutingTest --Ice.Config=routingtest.config
+
+  BasicRoutingService --Ice.Config=basicrouting.config
+
+
+
+  
+
diff --git a/config/basicrouting.config b/config/basicrouting.config
index ca98677..c2bd6c9 100644
--- a/config/basicrouting.config
+++ b/config/basicrouting.config
@@ -3,6 +3,10 @@
 # Endpoints for the adapter
 BasicRoutingServiceAdapter.Endpoints=tcp -p 10050
 
+BasicRoutingServiceAdapter.ThreadPool.Size=4
+BasicRoutingServiceAdapter.ThreadPool.SizeMax=10
+BasicRoutingServiceAdapter.ThreadPool.SizeWarn=9
+
 # Where to find the Service Locator manager. We need the Service Locator in order to be able to plug in to the Asterisk SCF system Discovery mechanisms.
 LocatorServiceManagement.Proxy=LocatorServiceManagement:tcp -p 4422
 
@@ -10,7 +14,8 @@ LocatorServiceManagement.Proxy=LocatorServiceManagement:tcp -p 4422
 LocatorService.Proxy=LocatorService:tcp -p 4411
 
 # Endpoints for Icestorm events
-TopicManager.Proxy=HydraIceStorm/TopicManager:default -p 10000
+TopicManager.Proxy=IceStorm/TopicManager:default -p 10000
 
 # Category for the bridge service
 BridgeManager.ServiceLocatorId=BridgeService
+
diff --git a/config/icestorm.config b/config/icestorm.config
index 62aeb7f..c6768e1 100644
--- a/config/icestorm.config
+++ b/config/icestorm.config
@@ -1,8 +1,11 @@
 # This is a configuration file used in conjunction with the service discovery test driver
 
-IceBox.Service.IceStorm=IceStormService,34:createIceStorm --Ice.Config=../config/test_icestorm.config
+IceBox.Service.IceStorm=IceStormService,34:createIceStorm --Ice.Config=icestorm.config
+
+IceStorm.InstanceName=IceStorm
+
+IceStorm.Transient=1
 
-IceStorm.InstanceName=HydraIceStorm
 #
 # This property defines the endpoints on which the IceStorm
 # TopicManager listens.
diff --git a/config/routingtest.config b/config/routingtest.config
index e05a40d..9d32be7 100644
--- a/config/routingtest.config
+++ b/config/routingtest.config
@@ -1,12 +1,29 @@
 # This is a configuration file for the Routing Service Test driver.
 
 # Test adapter
-TestRoutingAdapterOutgoing.Endpoints=tcp -p 10070
-TestRoutingAdapterIncoming.Endpoints=tcp -p 10071
+TestRoutingAdapterOut.Endpoints=tcp -p 10070
+TestRoutingAdapterIn.Endpoints=tcp -p 10071
+
+
+# Where to find the ServiceLocatorManagement interface. 
+# We need the ServiceLocatorManagement interface in order to register our test version of the BridgeManger. 
+LocatorServiceManagement.Proxy=LocatorServiceManagement:tcp -p 4422
 
 # Where to look for the Routing Service LocatorRegistry interface
 LocatorRegistry.Proxy=RoutingServiceLocatorRegistry:tcp -p 10050
 
+SessionRouter.Proxy=SessionRouter:tcp -p 10050
+
 # Endpoints for Icestorm events
-TopicManager.Proxy=IceStorm/TopicManager:default -p 10012
+TopicManager.Proxy=IceStorm/TopicManager:default -p 10000
+
+# Id to use to lookup the Bridge Manager.
+BridgeManager.ServiceLocatorId=BridgeService
+
+TestRoutingAdapterIn.ThreadPool.Size=4
+TestRoutingAdapterIn.ThreadPool.SizeMax=10
+TestRoutingAdapterIn.ThreadPool.SizeWarn=9
 
+TestRoutingAdapterOut.ThreadPool.Size=4
+TestRoutingAdapterOut.ThreadPool.SizeMax=10
+TestRoutingAdapterOut.ThreadPool.SizeWarn=9
diff --git a/config/service_locator.config b/config/service_locator.config
new file mode 100644
index 0000000..6e04832
--- /dev/null
+++ b/config/service_locator.config
@@ -0,0 +1,14 @@
+# This is a configuration file used in conjunction with the service locator test driver
+
+# Test endpoints for the service locator management adapter
+ServiceLocatorManagementAdapter.Endpoints=tcp -p 4422
+
+ServiceLocatorManagementAdapter.ThreadPool.Size=4
+ServiceLocatorManagementAdapter.ThreadPool.SizeMax=10
+ServiceLocatorManagementAdapter.ThreadPool.SizeWarn=9
+
+# Test endpoints for the service locator adapter
+ServiceLocatorAdapter.Endpoints=tcp -p 4411
+
+# Test endpoints for IceStorm
+TopicManager.Proxy=IceStorm/TopicManager:default -p 10000
diff --git a/src/BasicRoutingServiceApp.cpp b/src/BasicRoutingServiceApp.cpp
index d88ed4a..20d2af2 100644
--- a/src/BasicRoutingServiceApp.cpp
+++ b/src/BasicRoutingServiceApp.cpp
@@ -15,11 +15,13 @@
 #include "ServiceLocatorIf.h"
 #include "BridgingIf.h"
 #include "ComponentServiceIf.h"
+#include "SessionCommunicationsIf.h"
 #include "BasicRoutingServiceDataModel.h"
 #include "LuaScriptProcessor.h"
 #include "RoutingServiceEventPublisher.h"
 #include "EndpointRegistry.h"
 #include "RoutingAdmin.h"
+#include "SessionRouter.h"
 
 using namespace std;
 using namespace AsteriskSCF::BasicRoutingService;
@@ -39,6 +41,11 @@ namespace BasicRoutingService
  */
 class BasicRoutingServiceDataModelImpl : public BasicRoutingServiceDataModel
 {
+public:
+   BasicRoutingServiceDataModelImpl() : mPaused(false), mBridgeManager(0) 
+   {
+   }
+
 public: // Overrides of the BasicRoutingServiceDataModel singleton's public interface. 
 
    virtual const Ice::CommunicatorPtr getCommunicator() 
@@ -63,6 +70,11 @@ public: // Overrides of the BasicRoutingServiceDataModel singleton's public inte
 
    virtual BridgeManagerPrx getBridgeManager()
    {
+      if (mBridgeManager == 0)
+      {
+         locateBridgeManager();
+      }
+
       return mBridgeManager;
    }
 
@@ -81,6 +93,33 @@ public: // Implementation details are visible to this file's classes.
       }
    }
 
+   /**
+    * Get and cache a refence to the BridgeManager. 
+    */
+   void locateBridgeManager()
+   {
+      string bridgeId = "BridgeService"; 
+
+      try
+      {
+         // Use the locator to find the BridgeManger. 
+         ServiceLocatorParamsPtr nameparam = new ServiceLocatorParams();
+         nameparam->category = BridgeServiceDiscoveryCategory;
+         Ice::ObjectPrx bridgeManagerObject = mServiceLocator->locate(nameparam);
+         mBridgeManager = BridgeManagerPrx::checkedCast(bridgeManagerObject);
+      }
+      catch(const Ice::Exception &e)
+      {
+         cout << "Exception locating " << bridgeId << ": " << e.what() << endl; 
+         return;
+      }
+
+      if (mBridgeManager == 0)
+      {
+         cout << "Unable to locate " << bridgeId << endl;
+      }
+   }
+
    Ice::CommunicatorPtr mCommunicator;
    Ice::ObjectAdapterPtr mAdapter;
    RoutingServiceEventPublisher *mEventPublisher;
@@ -89,8 +128,6 @@ public: // Implementation details are visible to this file's classes.
    BridgeManagerPrx mBridgeManager;
 
    bool mPaused;
-
-   BasicRoutingServiceDataModelImpl() : mPaused(false) {}
 };
 
 BasicRoutingServiceDataModelImpl mDataModelInstance;
@@ -131,7 +168,11 @@ private:
    Discovery::V1::ServiceManagementPrx mRegistryLocatorManagement;
    Discovery::V1::ServiceManagementPrx mAdminManagement;
    Discovery::V1::ServiceManagementPrx mComponentServiceManagement;
+   Discovery::V1::ServiceManagementPrx mSessionRouterManagement;
+
+   // Our published interfaces.
    LocatorRegistryPtr mLocatorRegistry;
+   AsteriskSCF::SessionCommunications::V1::SessionRouterPtr mSessionRouter;
    RoutingServiceAdminPtr mAdminInteface;
    ComponentServicePtr mComponentService;
 };
@@ -139,6 +180,7 @@ private:
 static const string RegistryLocatorObjectId("RoutingServiceLocatorRegistry");
 static const string RoutingAdminObjectId("RoutingAdmin");
 static const string ComponentServiceId("BasicRoutingComponent");
+static const string SessionRouterObjectId("SessionRouter");
 
 /**
  * This class provides implementation for the ComponentService interface. 
@@ -210,7 +252,7 @@ void BasicRoutingServiceApp::registerWithServiceLocator()
          return;
       }
 
-      // Get a proxy to our RoutingAdmin interface and add it to the Service Locator. 
+      // Register our RoutingAdmin interface with the Service Locator. 
       Ice::ObjectPrx adminObjectPrx = adapter->createDirectProxy(communicator()->stringToIdentity(RoutingAdminObjectId));
       RoutingServiceAdminPrx adminPrx = RoutingServiceAdminPrx::checkedCast(adminObjectPrx);
       string adminServiceGuid("BasicRoutingServiceAdmin"); // Should be unique for reporting.
@@ -218,7 +260,7 @@ void BasicRoutingServiceApp::registerWithServiceLocator()
 	   
       setCategory(mAdminManagement, Routing::V1::RoutingServiceAdminDiscoveryCategory);
    	
-      // Get a proxy to our RegistryLocator interface and add it to the Service Locator. 
+      // Register our RegistryLocator interface with the Service Locator. 
       Ice::ObjectPrx locatorObjectPrx = adapter->createDirectProxy(communicator()->stringToIdentity(RegistryLocatorObjectId));
       LocatorRegistryPrx locatorRegistryPrx = LocatorRegistryPrx::checkedCast(locatorObjectPrx);
       string locatorServiceGuid("BasicRoutingServiceRegistryLocator");  // Should be unique for reporting.
@@ -226,13 +268,22 @@ void BasicRoutingServiceApp::registerWithServiceLocator()
 	   
       setCategory(mRegistryLocatorManagement, Routing::V1::RoutingServiceLocatorRegistryDiscoveryCategory);
 
-      // Get a proxy to our ComponentService interface and add it to the Service Locator. 
+      // Register the ComponentService interface with the Service Locator. 
       Ice::ObjectPrx componentServiceObjectPrx = adapter->createDirectProxy(communicator()->stringToIdentity(ComponentServiceId));
       ComponentServicePrx componentServicePrx = ComponentServicePrx::checkedCast(componentServiceObjectPrx);
       string componentServiceGuid("BasicRoutingService");   // Should be unique for reporting.
       mComponentServiceManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(componentServicePrx, componentServiceGuid));
 	   
       setCategory(mComponentServiceManagement, Routing::V1::ComponentServiceDiscoveryCategory);
+
+      // Register the SessionRouter interface with the Service Locator.  
+      Ice::ObjectPrx sessionRouterObjectPrx = adapter->createDirectProxy(communicator()->stringToIdentity(SessionRouterObjectId));
+      AsteriskSCF::SessionCommunications::V1::SessionRouterPrx sessionRouterPrx = AsteriskSCF::SessionCommunications::V1::SessionRouterPrx::checkedCast(sessionRouterObjectPrx);
+      string sessionRouterGuid("SessionRouter");   // Should be unique
+      mSessionRouterManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(sessionRouterPrx, sessionRouterGuid));
+	   
+      setCategory(mSessionRouterManagement, Routing::V1::SessionRouterDiscoveryCategory);
+
    }
    catch(...)
    {
@@ -286,28 +337,33 @@ void BasicRoutingServiceApp::initialize(const std::string appName)
       mLocatorRegistry = mDataModelInstance.mEndpointRegistry;
       mDataModelInstance.mAdapter->add(mLocatorRegistry, communicator()->stringToIdentity(RegistryLocatorObjectId));
 
+      // Create publish the SessionRouter interface.
+      mSessionRouter = new SessionRouter();
+      mDataModelInstance.mAdapter->add(mSessionRouter, communicator()->stringToIdentity(SessionRouterObjectId));
+
       // Create and publish the Admin interface support.
       mAdminInteface = new RoutingAdmin();
       mDataModelInstance.mAdapter->add(mAdminInteface, communicator()->stringToIdentity(RoutingAdminObjectId));
 
+      // Create and publish the ComponentService interface.
       mComponentService = new ComponentServiceImpl(*this);
       mDataModelInstance.mAdapter->add(mComponentService, communicator()->stringToIdentity(ComponentServiceId));
 
       mDataModelInstance.mAdapter->activate();
 
-      // Get a proxy to the management interface for the Service Locator.
+      // Get a proxy to the interface for the Service Locator.
 	   mDataModelInstance.mServiceLocator = ServiceLocatorPrx::checkedCast(communicator()->propertyToProxy("LocatorService.Proxy")); 
-
-      // Use the locator to find the BridgeManger. 
-      ServiceLocatorParamsPtr nameparam = new ServiceLocatorParams();
-      nameparam->category = communicator()->getProperties()->getProperty("BridgeManager.ServiceLocatorId");
-      Ice::ObjectPrx bridgeManagerObject = mDataModelInstance.mServiceLocator->locate(nameparam);
-      mDataModelInstance.mBridgeManager = BridgeManagerPrx::checkedCast(bridgeManagerObject);
    }
    catch(const Ice::Exception &exception)
    {
       cout << "Major problems in " << mAppName << " initialization(): " << exception.what() << endl;
    }
+
+   mDataModelInstance.locateBridgeManager();
+   if (mDataModelInstance.mBridgeManager == 0)
+   {
+       cout << "Probabaly safe to ignore ServiceNotFound during startup. Will attempt to locate Bridge Service again when it is needed." << endl;
+   }
 }
 
 /**
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 8d0b1e7..d5abd3a 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -2,6 +2,8 @@
 hydra_component_init(RoutingTest CXX)
 hydra_component_add_slice(RoutingTest RoutingIf)
 hydra_component_add_slice(RoutingTest ServiceLocatorIf)
+hydra_component_add_slice(RoutingTest SessionCommunicationsIf)
+hydra_component_add_slice(RoutingTest BridgingIf)
 hydra_component_add_file(RoutingTest TestRouting.cpp)
 hydra_component_add_ice_libraries(RoutingTest IceStorm)
 hydra_component_add_boost_libraries(RoutingTest unit_test_framework)
diff --git a/test/TestRouting.cpp b/test/TestRouting.cpp
index a475595..6ada93d 100644
--- a/test/TestRouting.cpp
+++ b/test/TestRouting.cpp
@@ -1,49 +1,408 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
 #define BOOST_TEST_DYN_LINK
 #define BOOST_TEST_MODULE ServiceLocatorTestSuite
 #define BOOST_TEST_NO_MAIN
 
+#include <boost/lexical_cast.hpp>
 #include <boost/test/unit_test.hpp>
 #include <boost/test/debug.hpp>
 
 #include <Ice/Ice.h>
 
+#include "ServiceLocatorIf.h"
 #include "Core/Routing/RoutingIf.h"
+#include "SessionCommunications/Bridging/BridgingIf.h"
 #include "Core/Discovery/ServiceLocatorIf.h"
+#include "SessionCommunications/SessionCommunicationsIf.h"
 
 using namespace std;
 using namespace AsteriskSCF::Core::Routing::V1;
 using namespace AsteriskSCF::Core::Endpoint::V1;
+using namespace AsteriskSCF::SessionCommunications::V1;
+using namespace AsteriskSCF::SessionCommunications::Bridging::V1;
+using namespace AsteriskSCF::Core::Discovery::V1;
+
+class TestEndpointLocatorImpl;
+typedef ::IceInternal::Handle<TestEndpointLocatorImpl> TestEndpointLocatorImplPtr;
+
+class BridgeSessionListener;
+typedef IceUtil::Handle<BridgeSessionListener> BridgeSessionListenerPtr;
+
+class BridgeManagerImpl;
+typedef IceUtil::Handle<BridgeManagerImpl> BridgeManagerImplPtr;
+
+class BridgeImpl;
 
 /**
- * A BaseEndpoint implemenation.
+ * Sharing global setup stuff here.
  */
-class BaseEndpointImpl : public BaseEndpoint
+struct SharedTestData
+{
+public:
+	// Communicator for outgoing stuff 
+	Ice::CommunicatorPtr communicator_out;
+
+	// Communicator for incoming stuff 
+	Ice::CommunicatorPtr communicator_in;
+
+	Ice::ObjectAdapterPtr adapter_in;
+	Ice::ObjectAdapterPtr adapter_out;
+
+	//A proxy to the actual routing service
+	LocatorRegistryPrx locatorRegistry;
+   SessionRouterPrx sessionRouter;
+
+   // Our own EndpointLocator to server up endpoints to the RoutingService, emulating a channel. 
+   TestEndpointLocatorImplPtr mEndpointLocator;
+   EndpointLocatorPrx mEndpointLocatorPrx;
+   RegExSeq mRegExIds;
+
+   ServiceLocatorPrx mServiceLocator;
+   ServiceLocatorManagementPrx mServiceLocatorManagement;
+
+   BridgeManagerImplPtr mBridgeManager;
+
+   bool mConnected;
+};
+static SharedTestData Testbed;
+
+
+class BridgeImpl : public Bridge
+{
+public:
+   BridgeImpl(SessionSeq sessions, BridgeListenerPrx listener);
+   ~BridgeImpl();
+
+   virtual void addSessions(const SessionSeq& newSessions, const ::Ice::Current&);
+   virtual void destroy(const ::Ice::Current& ) {}
+   virtual void removeSessions(const SessionSeq&, const ::Ice::Current&) {}
+
+   virtual SessionSeq listSessions(const ::Ice::Current&)
+   {
+      return mSessions;
+   }
+
+   virtual void shutdown(const ::Ice::Current&) {}
+   virtual void addListener(const BridgeListenerPrx&, const ::Ice::Current& ) {}
+   virtual void removeListener(const BridgeListenerPrx&, const ::Ice::Current& ) {}
+
+   void connected(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx& session);
+
+private:
+   SessionSeq mSessions;
+   BridgeSessionListenerPtr mListener;
+};
+
+class BridgeSessionListener : public SessionListener
+{
+public:
+   BridgeSessionListener(BridgeImpl *bridge) 
+   {
+   }
+
+  // The listener overrides...
+
+  virtual void connected(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx& session, const ::Ice::Current& = ::Ice::Current())
+  {
+     mBridge->connected(session);
+  }
+
+  virtual void flashed(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx&, const ::Ice::Current& = ::Ice::Current())
+  {
+  }
+
+  virtual void held(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx&, const ::Ice::Current& = ::Ice::Current())
+  {
+  }
+
+  virtual void progressing(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx&, const ::AsteriskSCF::SessionCommunications::V1::ResponseCodePtr&, const ::Ice::Current& = ::Ice::Current())
+  {
+  }
+
+  virtual void ringing(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx&, const ::Ice::Current& = ::Ice::Current())
+  {
+  }
+
+  virtual void stopped(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx&, const ::AsteriskSCF::SessionCommunications::V1::ResponseCodePtr&, const ::Ice::Current& = ::Ice::Current())
+  {
+  }
+
+  virtual void unheld(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx&, const ::Ice::Current& = ::Ice::Current())
+  {
+  }
+
+private:
+   BridgeImpl *mBridge;
+};
+typedef IceUtil::Handle<BridgeSessionListener> BridgeSessionListenerPtr;
+
+
+BridgeImpl::BridgeImpl(SessionSeq sessions, BridgeListenerPrx listener) : mSessions(sessions)
+{
+   mListener = new BridgeSessionListener(this);
+   Ice::ObjectPrx objectPrx = Testbed.adapter_in->addWithUUID(mListener);
+   SessionListenerPrx listenerPrx = SessionListenerPrx::checkedCast(objectPrx);
+
+   SessionSeq::iterator s;
+   for (s = mSessions.begin(); s != mSessions.end(); ++s)
+   {
+      (*s)->addListener(listenerPrx);
+   }
+}
+
+BridgeImpl::~BridgeImpl()
+{
+   Testbed.adapter_in->remove(Testbed.communicator_in->stringToIdentity(mListener->ice_id()));
+}
+
+void BridgeImpl::addSessions(const SessionSeq& newSessions, const ::Ice::Current&)
+{
+   mSessions.reserve( mSessions.size() + newSessions.size());
+   mSessions.insert( mSessions.end(), newSessions.begin(), newSessions.end());
+}
+
+
+void BridgeImpl::connected(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx& session)
+{
+   Testbed.mConnected = true;
+}
+
+class BridgeManagerImpl : public BridgeManager
 {
 public:
-   BaseEndpointImpl(const std::string& id) : mId(id) {}
+   BridgeManagerImpl()
+   {
+   }
+
+   virtual void addListener(const BridgeManagerListenerPrx&, const ::Ice::Current& )
+   {
+   }
+
+   virtual BridgePrx createBridge(const SessionSeq& sessions, const BridgeListenerPrx& listener, const ::Ice::Current&) 
+   {
+      BridgePtr bridge = new BridgeImpl(sessions, listener);
+      mBridgeServants.push_back(bridge);
+
+      Ice::ObjectPrx objectPrx = Testbed.adapter_in->addWithUUID(bridge);
+      BridgePrx bridgePrx = BridgePrx::checkedCast(objectPrx);
+      mBridges.push_back(bridgePrx);
+
+      return bridgePrx;
+   }
+
+   virtual void removeListener(const BridgeManagerListenerPrx&, const ::Ice::Current& )
+   {
+   }
+
+   virtual BridgeSeq listBridges(const ::Ice::Current& = ::Ice::Current()) 
+   {
+      return mBridges;
+   }
+
+   virtual void shutdown(const ::Ice::Current& = ::Ice::Current())
+   {
+   }
 
-   std::string getId(const Ice::Current&) {return mId;}
 private:
+   vector<BridgePtr> mBridgeServants;
+   BridgeSeq mBridges;
+};
+
+typedef AsteriskSCF::Core::Endpoint::V1::EndpointSeq::iterator EndpointIterator;
+
+class SessionEndpointImpl;
+typedef IceUtil::Handle<SessionEndpointImpl> SessionEndpointImplPtr;
+
+/* Cache the command line arguments so that Ice can be initialized within the global fixture. */
+struct ArgCacheType
+{
+public:
+	int argc;
+	char **argv;
+};
+static ArgCacheType mCachedArgs;
+
+const string LocatorObjectId("TestLocator");
+
+class SessionEndpointImpl;
+
+class SessionImpl : public Session
+{
+public:
+   SessionImpl(string sessionId, SessionEndpointPrx endpointPrx) 
+        : mId(sessionId), mEndpointPrx(endpointPrx), mSessionInfo(new SessionInfo())
+   {
+   }
+
+public:
+   // Overrides 
+
+   virtual SessionInfoPtr addListener(const SessionListenerPrx& listener, const Ice::Current&)
+   {
+      mListeners.push_back(listener);
+      
+      return mSessionInfo;
+   }
+
+   virtual void connect(const Ice::Current&)
+   {
+      vector<SessionListenerPrx>::iterator i;
+      for(i = mListeners.begin(); i != mListeners.end(); ++i)
+      {
+         (*i)->connected(mMyPrx);
+      }
+   }
+
+   virtual void flash(const Ice::Current&)
+   {
+   }
+
+   virtual SessionEndpointPrx getEndpoint(const Ice::Current&) 
+   {
+      return mEndpointPrx;
+   }
+
+   virtual SessionInfoPtr getInfo(const Ice::Current&)
+   {
+      return mSessionInfo;
+   }
+
+   virtual AsteriskSCF::Media::V1::SessionPrx getMediaSession(const Ice::Current&)
+   {
+      return 0;
+   }
+
+   virtual void hold(const ::Ice::Current&)
+   {
+   }
+
+   virtual void progress(const ResponseCodePtr&, const ::Ice::Current&)
+   {
+   }
+
+   virtual void removeListener(const SessionListenerPrx&, const ::Ice::Current&)
+   {
+   }
+
+   virtual void ring(const ::Ice::Current&)
+   {
+   }
+
+   virtual void start(const ::Ice::Current&)
+   {
+      cout << "Session started." << endl;
+
+      vector<SessionListenerPrx>::iterator i;
+      for(i = mListeners.begin(); i != mListeners.end(); ++i)
+      {
+         // Auto-answer! 
+         (*i)->connected(mMyPrx);
+      }
+   }
+
+   virtual void stop(const ResponseCodePtr&, const ::Ice::Current&)
+   {
+      cout << "Session stopped." << endl;
+   }
+
+   virtual void unhold(const ::Ice::Current&)
+   {
+   }
+
+   void setProxy(SessionPrx sessionPrx)
+   {
+      mMyPrx = sessionPrx;
+   }
+
+private:
+   string mId;
+   SessionPrx mMyPrx;
+   SessionEndpointPrx mEndpointPrx;
+   vector<SessionListenerPrx> mListeners;
+   SessionInfoPtr mSessionInfo;
+};
+typedef IceUtil::Handle<SessionImpl> SessionImplPtr;
+
+/**
+ * A simple endpoint implemenation.
+ */
+class SessionEndpointImpl : public SessionEndpoint
+{
+public:
+   SessionEndpointImpl(const std::string& id) : mCounter(0), mId(id) {}
+
+   virtual SessionPrx createSession(const string& dest, const SessionListenerPrx& listener, const ::Ice::Current& = ::Ice::Current())
+   {
+      string sessionId = dest + "_" + mId + "_" + boost::lexical_cast<string>(++mCounter);
+
+      BOOST_MESSAGE("SessionEndpoint creating session with Id=" + sessionId);
+
+      SessionImplPtr session = new SessionImpl(sessionId, mProxy);
+      mSessions.push_back(session);
+
+      Ice::ObjectPrx prx = Testbed.adapter_in->add(session, Testbed.communicator_in->stringToIdentity(sessionId));
+      SessionPrx sessionPrx = SessionPrx::checkedCast(prx);
+      mSessionPrxList.push_back(sessionPrx);
+
+      session->setProxy(sessionPrx);
+
+      return sessionPrx; 
+   }
+
+   virtual SessionSeq getSessions(const ::Ice::Current&)
+   {
+      return mSessionPrxList;
+   }
+
+   void setProxy(SessionEndpointPrx proxy)
+   {
+      mProxy = proxy;
+   }
+
+   std::string getId(const Ice::Current& = ::Ice::Current()) {return mId;}
+
+   void perTestCleanup()
+   {
+      vector<SessionImplPtr>::iterator i;
+      for(i = mSessions.begin(); i != mSessions.end(); ++i)
+      {
+         string id = (*i)->ice_id();
+         Testbed.adapter_in->remove(Testbed.communicator_in->stringToIdentity(id));
+      }
+
+      mSessions.clear();
+   }
+
+private:
+   vector<SessionImplPtr> mSessions;
+   vector<SessionPrx> mSessionPrxList;
    std::string mId;
+   SessionEndpointPrx mProxy;
+   int mCounter;
 };
 
 /**
  * A locator for our test channel's endpoints.
  */
-typedef EndpointSeq::iterator EndpointIterator;
 class TestEndpointLocatorImpl : public EndpointLocator
 {
 public:
-   EndpointSeq lookup(const ::std::string& destination, const Ice::Current&)
+   virtual AsteriskSCF::Core::Endpoint::V1::EndpointSeq lookup(const ::std::string& destination, const ::Ice::Current&)
    {
-      EndpointSeq endpoints;
+      AsteriskSCF::Core::Endpoint::V1::EndpointSeq endpoints;
       cout << "TestEndpointLocatorImpl::lookup() entered with destination = " << destination << endl << flush;
 
-      for (EndpointIterator e=mEndpoints.begin(); e!= mEndpoints.end(); e++)
+      for (EndpointIterator e=mEndpointPrxList.begin(); e!= mEndpointPrxList.end();++e)
       {
          cout << "TestEndpointLocatorImpl::lookup() comparing destination to " << (*e)->getId() << endl << flush;
 
-         BaseEndpointPtr ep = *e;
+         BaseEndpointPrx ep = *e;
          if ((*e)->getId() == destination)
          {
             cout << "TestEndpointLocatorImpl::lookup() found a match." << endl << flush;
@@ -58,47 +417,56 @@ public:
       return endpoints;
    }
 
-   EndpointSeq mEndpoints;
-};
-typedef ::IceInternal::Handle<TestEndpointLocatorImpl> TestEndpointLocatorImplPtr;
-
-/* Cache the command line arguments so that Ice can be initialized within the global fixture. */
-struct ArgCacheType
-{
-public:
-	int argc;
-	char **argv;
-};
-static ArgCacheType mCachedArgs;
+   void perTestCleanup()
+   {
+      vector<SessionEndpointImplPtr>::iterator i;
+      for(i = mEndpoints.begin(); i != mEndpoints.end(); ++i)
+      {
+         (*i)->perTestCleanup();
+      }
+   }
 
-/**
- * It seems odd that boost doesn't provide an easy way to access the GLOBAL_FIXTURE members.
- * But it doesn't seem to, so I'm sharing global setup stuff here.
- */
-struct SharedTestData
-{
-public:
-	// Communicator for outgoing stuff 
-	Ice::CommunicatorPtr communicator_outgoing;
+   void clear()
+   {
+      vector<SessionEndpointImplPtr>::iterator i;
+      for(i = mEndpoints.begin(); i != mEndpoints.end(); ++i)
+      {
+         Testbed.adapter_in->remove(Testbed.communicator_in->stringToIdentity((*i)->ice_id()));
+      }
 
-	// Communicator for incoming stuff 
-	Ice::CommunicatorPtr communicator_incoming;
+      mEndpointPrxList.clear();
+      mEndpoints.clear();
+   }
 
-	Ice::ObjectAdapterPtr adapter_in;
-	Ice::ObjectAdapterPtr adapter_out;
+   SessionEndpointImplPtr addEndpoint(string id)
+   {
+      SessionEndpointImplPtr endpoint = new SessionEndpointImpl(id);
+      mEndpoints.push_back(endpoint);
+      Ice::ObjectPrx prx = Testbed.adapter_in->addWithUUID(endpoint);
+      mEndpointPrxList.push_back(BaseEndpointPrx::checkedCast(prx));
+      return endpoint;
+   }
 
-	//A proxy to the actual routing service
-	LocatorRegistryPrx locatorRegistry;
+   /**
+    * Like lookup, but for the local channel we are simulating. 
+    */
+   SessionEndpointImplPtr localLookup(string id)
+   {
+      vector<SessionEndpointImplPtr>::iterator i;
+      for(i = mEndpoints.begin(); i != mEndpoints.end(); ++i)
+      {
+         if ((*i)->getId() == id)
+         {
+            return (*i);
+         }
+      }
+      return 0;
+   }
 
-   // Our own EndpointLocator to server up endpoints to the RoutingService, emulating a channel. 
-   TestEndpointLocatorImplPtr mEndpointLocator;
-   EndpointLocatorPrx mEndpointLocatorPrx;
-   //std::vector<const std::string> mRegExIds;
-   RegExSeq mRegExIds;
+   AsteriskSCF::Core::Endpoint::V1::EndpointSeq mEndpointPrxList;
+   vector<SessionEndpointImplPtr> mEndpoints;
 };
-static SharedTestData Testbed;
-
-const string LocatorObjectId("TestLocator");
+typedef ::IceInternal::Handle<TestEndpointLocatorImpl> TestEndpointLocatorImplPtr;
 
 /**
  * A global fixture for Ice initialization.
@@ -116,45 +484,57 @@ struct GlobalIceFixture
 			int status = 0;
 			try
 			{
-				// Testbed.communicator_incoming = Ice::initialize(mCachedArgs.argc, mCachedArgs.argv);
             Ice::PropertiesPtr props = Ice::createProperties(mCachedArgs.argc, mCachedArgs.argv);
             Ice::InitializationData initData;
             initData.properties = props;
 
             // Set up incoming adapter. This is where we'll publish our proxies.
-            Testbed.communicator_incoming = Ice::initialize(initData);
+            Testbed.communicator_in = Ice::initialize(initData);
 
             string test = props->getProperty("LocatorRegistry.Proxy");
 
-				Testbed.adapter_in = Testbed.communicator_incoming->createObjectAdapterWithEndpoints("TestRoutingAdapterIncoming", "default -p 10070");
+				Testbed.adapter_in = Testbed.communicator_in->createObjectAdapterWithEndpoints("TestRoutingAdapterIn", "default -p 10070");
 
             // Serve up our own EndpointLocator, since we're emulating a channel. 
             TestEndpointLocatorImpl *locator = new TestEndpointLocatorImpl();
             Testbed.mEndpointLocator = locator;
-            Testbed.adapter_in->add(Testbed.mEndpointLocator, Testbed.communicator_incoming->stringToIdentity(LocatorObjectId));
+            Testbed.adapter_in->add(Testbed.mEndpointLocator, Testbed.communicator_in->stringToIdentity(LocatorObjectId));
 
 				Testbed.adapter_in->activate();
 
             // Now that the adapter has been activated, get a local proxy to our EndpointLocator. 
-            Ice::ObjectPrx locatorObjectPrx = Testbed.adapter_in->createDirectProxy(Testbed.communicator_incoming->stringToIdentity(LocatorObjectId));
+            Ice::ObjectPrx locatorObjectPrx = Testbed.adapter_in->createDirectProxy(Testbed.communicator_in->stringToIdentity(LocatorObjectId));
             Testbed.mEndpointLocatorPrx = EndpointLocatorPrx::checkedCast(locatorObjectPrx);
 
             // Now set up outgoing adapter. This will be used for proxies we want to call out to the
             // the unit under test on. 
-            Testbed.communicator_outgoing = Ice::initialize(initData);
-				Testbed.adapter_out = Testbed.communicator_outgoing->createObjectAdapterWithEndpoints("TestRoutingAdapterOutgoing", "default -p 10071");
+            Testbed.communicator_out = Ice::initialize(initData);
+				Testbed.adapter_out = Testbed.communicator_out->createObjectAdapterWithEndpoints("TestRoutingAdapterOut", "default -p 10071");
 
             // Get ref to Routing Service so we can test it. Getting direct for now, but
             // need to test acquiring reference via ServiceLocator as well. 
-            Ice::ObjectPrx base = Testbed.communicator_outgoing->propertyToProxy("LocatorRegistry.Proxy");
-            Testbed.locatorRegistry = LocatorRegistryPrx::checkedCast(base);
+            Ice::ObjectPrx locatorObj = Testbed.communicator_out->propertyToProxy("LocatorRegistry.Proxy");
+            Testbed.locatorRegistry = LocatorRegistryPrx::checkedCast(locatorObj);
+
+            // Get the ServiceLocator and ServiceLocator manager
+
 
 				if (!Testbed.locatorRegistry) 
             {
-					throw "Invalid service proxy";
+					throw "Invalid LocatorRegistry";
+				}
+
+            Ice::ObjectPrx routerObj = Testbed.communicator_out->propertyToProxy("SessionRouter.Proxy");
+            Testbed.sessionRouter = SessionRouterPrx::checkedCast(routerObj);
+
+				if (!Testbed.sessionRouter) 
+            {
+					throw "Invalid SessionRouter";
 				}
 
             PopulateEndpoints();
+
+            RegisterWithServiceLocator();
 			}
 			catch (const Ice::Exception& ex)
 			{
@@ -169,18 +549,36 @@ struct GlobalIceFixture
 
 		} // end Fixture() constructor
 
-   void PopulateEndpoints()
+   void RegisterWithServiceLocator()
    {
-      Testbed.mEndpointLocator->mEndpoints.clear();
+      // Get a proxy to the management interface for the Service Locator, so we can add 
+      // our mock BridgeManager to the system. 
+	   Testbed.mServiceLocatorManagement = ServiceLocatorManagementPrx::checkedCast(Testbed.communicator_in->propertyToProxy("LocatorServiceManagement.Proxy")); 
 
-      BaseEndpointPtr endpoint = new BaseEndpointImpl("101");
-      Testbed.mEndpointLocator->mEndpoints.push_back(endpoint);
+      if (Testbed.mServiceLocatorManagement == 0)
+      {
+         cout << "Unable to obtain proxy to ServiceLocatorManagement interface. Check config file. Tests can't run without it. (not yet, anyway)" << endl;
+         return;
+      }
 
-      endpoint = new BaseEndpointImpl("102");
-      Testbed.mEndpointLocator->mEndpoints.push_back(endpoint);
+      Testbed.mBridgeManager = new BridgeManagerImpl();
 
-      endpoint = new BaseEndpointImpl("103");
-      Testbed.mEndpointLocator->mEndpoints.push_back(endpoint);
+      Ice::ObjectPrx bridgeManagerObject = Testbed.adapter_in->add(Testbed.mBridgeManager, Testbed.communicator_in->stringToIdentity(Testbed.communicator_in->getProperties()->getProperty("BridgeManager.ServiceLocatorId")));
+      BridgeManagerPrx bridgeManagerPrx = BridgeManagerPrx::checkedCast(bridgeManagerObject);
+      ServiceManagementPrx management = ServiceManagementPrx::uncheckedCast(Testbed.mServiceLocatorManagement->addService(bridgeManagerPrx, "BridgeService"));
+	   
+      ServiceLocatorParamsPtr genericparams = new ServiceLocatorParams();
+      genericparams->category = BridgeServiceDiscoveryCategory;
+      management->addLocatorParams(genericparams, "");
+   }
+
+   void PopulateEndpoints()
+   {
+      Testbed.mEndpointLocator->clear();
+
+      Testbed.mEndpointLocator->addEndpoint("101");
+      Testbed.mEndpointLocator->addEndpoint("102");
+      Testbed.mEndpointLocator->addEndpoint("103");
 
       // Initialize the regular expressions for the ids that this channel will support.
       // Use two strings just for kicks. 
@@ -193,15 +591,15 @@ struct GlobalIceFixture
 		BOOST_TEST_MESSAGE("Tearing down service discovery test fixture");
 
 
-		if (Testbed.communicator_incoming) 
+		if (Testbed.communicator_in) 
       {
-			Testbed.communicator_incoming->shutdown();
-			Testbed.communicator_incoming = 0;
+			Testbed.communicator_in->shutdown();
+			Testbed.communicator_in = 0;
 		}
-		if (Testbed.communicator_outgoing) 
+		if (Testbed.communicator_out) 
       {
-			Testbed.communicator_outgoing->shutdown();
-			Testbed.communicator_outgoing = 0;
+			Testbed.communicator_out->shutdown();
+			Testbed.communicator_out = 0;
 		}
 		}
 private:
@@ -242,6 +640,7 @@ public:
 	   try
       {
          Testbed.locatorRegistry->removeEndpointLocator("TestChannel");
+         Testbed.mEndpointLocator->perTestCleanup();
       }
       catch (...)
       {
@@ -280,17 +679,24 @@ BOOST_AUTO_TEST_CASE(AddAndRemoveEndpointLocator)
       BOOST_TEST_MESSAGE("Exception removing EndpointLocator.");
    }
 	BOOST_CHECK(removeLocatorSucceeded);
+
+   BOOST_TEST_MESSAGE("Completed AddAndRemoveEndpointLocator test.");
+
 }
 
+/**
+ * Test the lookup interface of the RoutingService.
+ */
 BOOST_FIXTURE_TEST_CASE(LookupOwnEndpoint, PerTestFixture)
 {
-	// KEN: This isn't actually used, should it be? */
-//   bool lookupSucceeded(true);
 	try
    {
+      BOOST_TEST_MESSAGE("Looking up endpoint via Routing Service...");
       string lookupVal = "102";
-      EndpointSeq seq = Testbed.locatorRegistry->lookup(lookupVal);
+      AsteriskSCF::Core::Endpoint::V1::EndpointSeq seq = Testbed.locatorRegistry->lookup(lookupVal);
     
+      BOOST_TEST_MESSAGE(" ...lookup completed.");
+
       BOOST_CHECK(seq.size() > 0);
       BOOST_CHECK(seq[0]->getId() == lookupVal);
    }
@@ -307,6 +713,47 @@ BOOST_FIXTURE_TEST_CASE(LookupOwnEndpoint, PerTestFixture)
       bool unknownException(false);
       BOOST_TEST_MESSAGE("Exception looking up our own endpoint.");
       BOOST_CHECK(unknownException);
- }
-	
+   }
+
+  BOOST_TEST_MESSAGE("Completed LookupOwnEndpoint test.");
+
 }
+
+/** 
+ * This tests if we can route a session. 
+ */
+BOOST_FIXTURE_TEST_CASE(RouteSession, PerTestFixture)
+{
+	try
+   {
+      BOOST_TEST_MESSAGE("Local lookup of an endpoint...");
+
+      // Get our local 101 endpoint
+      SessionEndpointImplPtr session101Endpoint = Testbed.mEndpointLocator->localLookup("101");
+
+      BOOST_TEST_MESSAGE("Creating a session on our test endpoint...");
+      SessionPrx session = session101Endpoint->createSession("102", 0);
+      BOOST_CHECK(session != 0);
+
+      Testbed.mConnected = false;
+
+      BOOST_TEST_MESSAGE("Routing the session...");
+      Testbed.sessionRouter->routeSession(session, "102");
+
+      BOOST_CHECK(Testbed.mConnected);
+   }
+   catch(const IceUtil::Exception &ie)
+   {
+      bool IceException(false);
+      string msg = "Exception routing session:";
+      msg += ie.what();
+      BOOST_TEST_MESSAGE(msg);
+      BOOST_CHECK(IceException);
+   }
+   catch (...)
+   {
+      bool unknownException(false);
+      BOOST_TEST_MESSAGE("Exception routing session.");
+      BOOST_CHECK(unknownException);
+   }
+}
\ No newline at end of file

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


-- 
asterisk-scf/integration/routing.git



More information about the asterisk-scf-commits mailing list