[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 28 15:26:43 CDT 2010


branch "master" has been updated
       via  6ff942dd9bd325b628c357a5dfb281138b1c16d8 (commit)
      from  3ef039f098af177552f0a9d2e7c259808ad2bd03 (commit)

Summary of changes:
 src/EndpointRegistry.cpp             |   18 +++++++++++-
 src/RoutingServiceEventPublisher.cpp |   16 ++++++++---
 test/TestRouting.cpp                 |   47 ++++++++++++++++++++++++++++++++-
 3 files changed, 73 insertions(+), 8 deletions(-)


- Log -----------------------------------------------------------------
commit 6ff942dd9bd325b628c357a5dfb281138b1c16d8
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Tue Sep 28 15:22:29 2010 -0500

    Made Routing Service tolarent of Endpoint Locators being re-registered,
    and added tests to verify implementation.

diff --git a/src/EndpointRegistry.cpp b/src/EndpointRegistry.cpp
index f4f0612..ebe6466 100644
--- a/src/EndpointRegistry.cpp
+++ b/src/EndpointRegistry.cpp
@@ -87,8 +87,9 @@ void EndpointRegistry::addEndpointLocator(const ::std::string& locatorId,
       EndpointLocatorMapIterator existing = mImpl->mEndpointLocatorMap.find(locatorId);
       if (existing != mImpl->mEndpointLocatorMap.end())
       {
-         mImpl->mEventPublisher.sendAddEndpointLocatorEvent(locatorId, regexList, Event::FAILURE);
-         throw LocatorAlreadyRegisteredException(); // (locatorId);
+         mImpl->mEndpointLocatorMap.erase(existing);
+         // TBD... Logging!
+         cout << "Received request to add endpoint with id " << locatorId << " which already exists. Replacing with new proxy." << endl;
       }
 
       RegisteredLocator newLocator(locator, regexList);
@@ -113,8 +114,21 @@ void EndpointRegistry::removeEndpointLocator(const ::std::string& locatorId, con
 {
    try
    {
+      EndpointLocatorMapIterator existing = mImpl->mEndpointLocatorMap.find(locatorId);
+      if (existing == mImpl->mEndpointLocatorMap.end())
+      {
+         // TBD... Logging...
+         cerr << "Received request to remove Endpoint Locator not currently registered. Id = " << locatorId << endl;
+
+         mImpl->mEventPublisher.sendRemoveEndpointLocatorEvent(locatorId, Event::FAILURE);
+         return;
+      }
+
+
       mImpl->mEndpointLocatorMap.erase(locatorId);
       mImpl->mEventPublisher.sendRemoveEndpointLocatorEvent(locatorId, Event::SUCCESS);
+
+      cout << "Removed Endpoint Locator with Id = " << locatorId << endl;
    }
    catch(const std::exception &e)
    {
diff --git a/src/RoutingServiceEventPublisher.cpp b/src/RoutingServiceEventPublisher.cpp
index becf19a..71873da 100644
--- a/src/RoutingServiceEventPublisher.cpp
+++ b/src/RoutingServiceEventPublisher.cpp
@@ -47,12 +47,10 @@ public:
            cerr <<  "Invalid proxy to IceStorm. Missing config for TopicManager.Proxy?" << endl;
            return;
          }
-
-         cout << "RoutingServiceEventPublisher::initialize(): Got IceStorm proxy: TopicManager.Proxy" << endl;
       }
       catch(const IceUtil::Exception&)
       {
-         cout << "Can't get IceStorm TopicManager. Check config, and make sure IceStorm is running." << endl;
+         cerr << "Can't get IceStorm TopicManager. Check config, and make sure IceStorm is running." << endl;
          return;
       }
 
@@ -69,6 +67,7 @@ public:
         }
         catch(const IceStorm::TopicExists&)
         {
+           // Topic didn't exist so I tried to create it. But now it exists. Someone else beat me to the punch.
            cerr << "Possible race condition creating IceStorm topic " << Event::TopicId << ". Suggest Restart!" << endl;
            return;
         }
@@ -85,9 +84,18 @@ public:
     */
    bool isInitialized()
    {
+      if (mInitialized)
+      {
+         return true;
+      }
+
+      // Try again to initialize. 
+      initialize();
+
       if (!mInitialized)
       {
-         cout << "Attempting to use RoutingServiceEventPublisher in uninitialized state! IceStorm may be inaccessible." << endl;
+         // TBD...Logging
+         cout << "Routing Service event publishing can't locate IceStorm." << endl;
       }
 
       return mInitialized;
diff --git a/test/TestRouting.cpp b/test/TestRouting.cpp
index 8f36516..4f5157e 100644
--- a/test/TestRouting.cpp
+++ b/test/TestRouting.cpp
@@ -6,7 +6,7 @@
  * All rights reserved.
  */
 #define BOOST_TEST_DYN_LINK
-#define BOOST_TEST_MODULE ServiceLocatorTestSuite
+#define BOOST_TEST_MODULE BasicRoutingServiceTestSuite
 #define BOOST_TEST_NO_MAIN
 
 #include <boost/test/unit_test.hpp>
@@ -222,9 +222,14 @@ public:
          SharedTestData::instance.locatorRegistry->removeEndpointLocator("TestChannel");
          SharedTestData::instance.mEndpointLocator->perTestCleanup();
       }
+      catch(const std::exception &e)
+      {
+         BOOST_TEST_MESSAGE("PerTestFixture can't remove our endpoint locator from the Routing Service: ");
+         BOOST_TEST_MESSAGE(e.what());
+      }
       catch (...)
       {
-         BOOST_TEST_MESSAGE("PerTestFixture can't removing our endpoint locator from the Routing Service..");
+         BOOST_TEST_MESSAGE("Unknown exception. PerTestFixture can't remove our endpoint locator from the Routing Service..");
       }
    }
 };
@@ -265,6 +270,44 @@ BOOST_AUTO_TEST_CASE(AddAndRemoveEndpointLocator)
 }
 
 /**
+ * Test adding a locator twice with the service's Locator Registry.
+ * This was supposed to throw exception in the past, but is now allowed. The second
+ * registration replaces the existing registration. 
+ */
+BOOST_AUTO_TEST_CASE(AddEndpointLocatorTwice)
+{
+   bool addLocatorSucceeded(true);
+	try
+   {
+      SharedTestData::instance.locatorRegistry->addEndpointLocator("TestChannel", SharedTestData::instance.mRegExIds, SharedTestData::instance.mEndpointLocatorPrx);
+      SharedTestData::instance.locatorRegistry->addEndpointLocator("TestChannel", SharedTestData::instance.mRegExIds, SharedTestData::instance.mEndpointLocatorPrx);
+  }
+   catch (...)
+   {
+      addLocatorSucceeded = false;
+      BOOST_TEST_MESSAGE("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_CHECK(removeLocatorSucceeded);
+
+   BOOST_TEST_MESSAGE("Completed AddEndpointLocatorTwice test.");
+
+}
+
+/**
  * Test the lookup interface of the RoutingService.
  */
 BOOST_FIXTURE_TEST_CASE(LookupOwnEndpoint, PerTestFixture)

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


-- 
asterisk-scf/integration/routing.git



More information about the asterisk-scf-commits mailing list