[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
Thu Aug 19 21:32:45 CDT 2010


branch "master" has been updated
       via  8e9b2827ffe23f38b479a044571477d085beb6ad (commit)
      from  b7071590b6e70351e5432d10620c58a99b10a213 (commit)

Summary of changes:
 config/routingtest.config  |    3 +-
 scripts/routing.lua        |   17 ++++----
 src/EndpointRegistry.cpp   |    9 ++++-
 src/LuaScriptProcessor.cpp |   19 ++++++++-
 test/TestRouting.cpp       |   97 ++++++++++++++++++++++++++++++++++++++------
 5 files changed, 119 insertions(+), 26 deletions(-)


- Log -----------------------------------------------------------------
commit 8e9b2827ffe23f38b479a044571477d085beb6ad
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Thu Aug 19 21:32:20 2010 -0500

    Successful test of a lookup.

diff --git a/config/routingtest.config b/config/routingtest.config
index 9b27cbd..e05a40d 100644
--- a/config/routingtest.config
+++ b/config/routingtest.config
@@ -1,7 +1,8 @@
 # This is a configuration file for the Routing Service Test driver.
 
 # Test adapter
-TestRoutingAdapter=tcp -p 10070
+TestRoutingAdapterOutgoing.Endpoints=tcp -p 10070
+TestRoutingAdapterIncoming.Endpoints=tcp -p 10071
 
 # Where to look for the Routing Service LocatorRegistry interface
 LocatorRegistry.Proxy=RoutingServiceLocatorRegistry:tcp -p 10050
diff --git a/scripts/routing.lua b/scripts/routing.lua
index 3b736df..a0126ca 100644
--- a/scripts/routing.lua
+++ b/scripts/routing.lua
@@ -1,24 +1,23 @@
 
 
--- Sets a site-specific policy. The default implementation only 
+-- Sets a site-specific policy. The default implementation only
 -- supports a "deny" policy which rejects all lookups until
 -- the policy no longer equals "deny".
 function setPolicy(newpolicy)
+    print ("Lua: New policy "..newpolicy)
     policy = newpolicy
 end
 
--- Confirm or deny a lookup() procedure. 
+-- Confirm or deny a lookup() procedure.
 --   @param destination The destination being looked up
 --   @return A (potentially) modified destination to allow rerouting.
---   @return True to allow the lookup or false to deny. 
+--   @return True to allow the lookup or false to deny.
 function confirmLookup(destination)
-    print ("Looking up extension "..destination)
-    return destination
-
-    if (policy == "deny")
-	   return false;
+    print ("Lua: Looking up extension "..destination)
+    if (policy == "deny") then
+	   return destination, false
     else
-           return true
+       return destination, true
     end
 end
 
diff --git a/src/EndpointRegistry.cpp b/src/EndpointRegistry.cpp
index d8ce9e5..85887e0 100644
--- a/src/EndpointRegistry.cpp
+++ b/src/EndpointRegistry.cpp
@@ -177,7 +177,14 @@ void EndpointRegistry::setEndpointLocatorDestinationIds(const ::std::string& loc
       {
          if (boost::regex_match(destination, *reg))
          {
-            endpoints = entry->second.locator->lookup(destination);
+            try
+            {
+              endpoints = entry->second.locator->lookup(destination);
+            }
+            catch (const IceUtil::Exception &e)
+            {
+               cout << "Exception calling registered EndpointLocator: " << e.what() << endl;
+            }
             break;
          }
       }
diff --git a/src/LuaScriptProcessor.cpp b/src/LuaScriptProcessor.cpp
index c920f3d..072a7bf 100644
--- a/src/LuaScriptProcessor.cpp
+++ b/src/LuaScriptProcessor.cpp
@@ -28,8 +28,9 @@ typedef std::vector<RawEndpointId> RawEndpointVector;
 class LuaScriptProcessorPriv
 {
 public:
-   LuaScriptProcessorPriv()
+   LuaScriptProcessorPriv() : mInitialized(false)
    {
+      initialize();
    }
 
    ~LuaScriptProcessorPriv() 
@@ -52,10 +53,17 @@ public:
          cout << lua_tostring(mLuaState, -1) << std::endl;
          return ;
       }
+
+      mInitialized = true;
    }
 
    void setPolicy(const string& policy)
    {
+      if (!mInitialized)
+      {
+         return;
+      }
+
       mCurrentPolicy = policy;
       
       // Call the lua script.
@@ -115,6 +123,12 @@ public:
 
    bool confirmLookup(const string& destination, string &modifiedDestination)
    {
+      if (!mInitialized)
+      {
+         modifiedDestination = destination;
+         return true;
+      }
+
       try
       {
          // Call the lua script.
@@ -125,7 +139,7 @@ public:
 	      lua_pushstring(mLuaState, destination.c_str());
 
          // Call function. One arg, 2 results...
-         lua_call(mLuaState, 1, 1);
+         lua_call(mLuaState, 1, 2);
 
          int allow = (int)lua_toboolean(mLuaState, -1);
 	      lua_pop(mLuaState, 1);
@@ -150,6 +164,7 @@ private:
    // boost::shared_ptr<lua_State> mLuaState;
    lua_State *mLuaState;
 	boost::shared_mutex mLock;
+   bool mInitialized;
 };
 
 /**
diff --git a/test/TestRouting.cpp b/test/TestRouting.cpp
index 4a23243..4017abe 100644
--- a/test/TestRouting.cpp
+++ b/test/TestRouting.cpp
@@ -24,13 +24,17 @@ public:
    EndpointSeq lookup(const ::std::string& destination, const Ice::Current&)
    {
       EndpointSeq endpoints;
- 
+      cout << "TestEndpointLocatorImpl::lookup() entered with destination = " << destination << endl << flush;
+
       for (EndpointIterator e=mEndpoints.begin(); e!= mEndpoints.end(); e++)
       {
+         cout << "TestEndpointLocatorImpl::lookup() comparing destination to " << (*e)->id->destinationId << endl << flush;
+
          BaseEndpointPtr ep = *e;
          if ((*e)->id->destinationId == destination)
          {
-            endpoints.push_back(*e);
+            cout << "TestEndpointLocatorImpl::lookup() found a match." << endl << flush;
+            endpoints.push_back(ep);
          }
       }
 
@@ -67,7 +71,8 @@ public:
 	// Communicator for incoming stuff 
 	Ice::CommunicatorPtr communicator_incoming;
 
-	Ice::ObjectAdapterPtr adapter;
+	Ice::ObjectAdapterPtr adapter_in;
+	Ice::ObjectAdapterPtr adapter_out;
 
 	//A proxy to the actual routing service
 	LocatorRegistryPrx locatorRegistry;
@@ -102,26 +107,33 @@ struct GlobalIceFixture
             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);
 
             string test = props->getProperty("LocatorRegistry.Proxy");
 
-				Testbed.adapter = Testbed.communicator_incoming->createObjectAdapterWithEndpoints("TestRoutingAdapter", "default -p 10070");
+				Testbed.adapter_in = Testbed.communicator_incoming->createObjectAdapterWithEndpoints("TestRoutingAdapterIncoming", "default -p 10070");
 
             // Serve up our own EndpointLocator, since we're emulating a channel. 
             TestEndpointLocatorImpl *locator = new TestEndpointLocatorImpl();
             Testbed.mEndpointLocator = locator;
-            Testbed.adapter->add(Testbed.mEndpointLocator, Testbed.communicator_incoming->stringToIdentity(LocatorObjectId));
+            Testbed.adapter_in->add(Testbed.mEndpointLocator, Testbed.communicator_incoming->stringToIdentity(LocatorObjectId));
 
-				Testbed.adapter->activate();
+				Testbed.adapter_in->activate();
 
             // Now that the adapter has been activated, get a local proxy to our EndpointLocator. 
-            Ice::ObjectPrx locatorObjectPrx = Testbed.adapter->createDirectProxy(Testbed.communicator_incoming->stringToIdentity(LocatorObjectId));
+            Ice::ObjectPrx locatorObjectPrx = Testbed.adapter_in->createDirectProxy(Testbed.communicator_incoming->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");
+
             // 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_incoming->propertyToProxy("LocatorRegistry.Proxy");
+            Ice::ObjectPrx base = Testbed.communicator_outgoing->propertyToProxy("LocatorRegistry.Proxy");
             Testbed.locatorRegistry = LocatorRegistryPrx::checkedCast(base);
 
 				if (!Testbed.locatorRegistry) 
@@ -152,9 +164,11 @@ struct GlobalIceFixture
       endpoint->id = new EndpointId("TestChannel", "101");
       Testbed.mEndpointLocator->mEndpoints.push_back(endpoint);
 
+      endpoint = new BaseEndpoint();
       endpoint->id = new EndpointId("TestChannel", "102");
       Testbed.mEndpointLocator->mEndpoints.push_back(endpoint);
 
+      endpoint = new BaseEndpoint();
       endpoint->id = new EndpointId("TestChannel", "103");
       Testbed.mEndpointLocator->mEndpoints.push_back(endpoint);
 
@@ -198,25 +212,53 @@ int BOOST_TEST_CALL_DECL main( int argc, char* argv[] )
 	return ::boost::unit_test::unit_test_main( &init_unit_test, argc, argv );
 }
 
+struct PerTestFixture
+{
+public: 
+   PerTestFixture() 
+   {
+	   try
+      {
+         Testbed.locatorRegistry->addEndpointLocator("TestChannel", Testbed.mRegExIds, Testbed.mEndpointLocatorPrx);
+      }
+      catch (...)
+      {
+         BOOST_TEST_MESSAGE("PerTestFixture can't add our endpoint locator to the Routing Service.");
+      }
+   }
+
+   ~PerTestFixture()
+   {
+	   try
+      {
+         Testbed.locatorRegistry->removeEndpointLocator("TestChannel");
+      }
+      catch (...)
+      {
+         BOOST_TEST_MESSAGE("PerTestFixture can't removing our endpoint locator from the Routing Service..");
+      }
+   }
+};
+
 /**
  * Test adding and removing a locator with the routing service's Locator Registry.
  */
 BOOST_AUTO_TEST_CASE(AddAndRemoveEndpointLocator)
 {
-   // T
-   bool succeeded(true);
+   bool addLocatorSucceeded(true);
 	try
    {
       Testbed.locatorRegistry->addEndpointLocator("TestChannel", Testbed.mRegExIds, Testbed.mEndpointLocatorPrx);
    }
    catch (...)
    {
-      succeeded = false;
+      addLocatorSucceeded = false;
       BOOST_TEST_MESSAGE("Exception adding EndpointLocator.");
    }
 
-	BOOST_CHECK(succeeded);
+	BOOST_CHECK(addLocatorSucceeded);
 
+   bool removeLocatorSucceeded(true);
 	try
    {
       Testbed.locatorRegistry->removeEndpointLocator("TestChannel");
@@ -224,7 +266,36 @@ BOOST_AUTO_TEST_CASE(AddAndRemoveEndpointLocator)
    }
    catch (...)
    {
-      succeeded = false;
+      removeLocatorSucceeded = false;
       BOOST_TEST_MESSAGE("Exception removing EndpointLocator.");
    }
+	BOOST_CHECK(removeLocatorSucceeded);
 }
+
+BOOST_FIXTURE_TEST_CASE(LookupOwnEndpoint, PerTestFixture)
+{
+   bool lookupSucceeded(true);
+	try
+   {
+      string lookupVal = "102";
+      EndpointSeq seq = Testbed.locatorRegistry->lookup(lookupVal);
+    
+      BOOST_CHECK(seq.size() > 0);
+      BOOST_CHECK(seq[0]->id->destinationId == lookupVal);
+   }
+   catch(const IceUtil::Exception &ie)
+   {
+      bool IceException(false);
+      string msg = "Exception looking up our own endpoint:";
+      msg += ie.what();
+      BOOST_TEST_MESSAGE(msg);
+      BOOST_CHECK(IceException);
+   }
+   catch (...)
+   {
+      bool unknownException(false);
+      BOOST_TEST_MESSAGE("Exception looking up our own endpoint.");
+      BOOST_CHECK(unknownException);
+ }
+	
+}
\ No newline at end of file

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


-- 
asterisk-scf/integration/routing.git



More information about the asterisk-scf-commits mailing list