[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
Mon Apr 25 10:31:31 CDT 2011


branch "route_replica" has been updated
       via  724ffef296439e5123235c391af6b07d6e079336 (commit)
      from  02898d23714f5b898b5ed870b91ed10b479ca625 (commit)

Summary of changes:
 config/routingtest-integ.config.in     |   17 +++-
 src/BasicRoutingServiceApp.cpp         |   40 ++++++--
 src/RoutingStateReplicatorListener.cpp |    8 +-
 test/SharedTestData.h                  |    9 ++-
 test/TestRouting.cpp                   |  173 +++++++++++++++++++++++++++-----
 5 files changed, 206 insertions(+), 41 deletions(-)


- Log -----------------------------------------------------------------
commit 724ffef296439e5123235c391af6b07d6e079336
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Mon Apr 25 10:30:15 2011 -0500

    Adding tests for replication.
      - New tests.
      - One-way calls to add/remove replication listener.

diff --git a/config/routingtest-integ.config.in b/config/routingtest-integ.config.in
index 5945cf2..9ecd42b 100644
--- a/config/routingtest-integ.config.in
+++ b/config/routingtest-integ.config.in
@@ -39,7 +39,7 @@ BridgeManager.ServiceLocatorId=BridgeService
 
 RoutingService.Endpoints=tcp -p 10050
 RoutingService.ComponentService.Endpoints=tcp -p 10051
-RoutingService.ThreadPool.Size=4
+RoutingService.ThreadPool.Size=6
 RoutingService.ThreadPool.SizeMax=10
 RoutingService.ThreadPool.SizeWarn=9
 RoutingService.Standby=no
@@ -47,7 +47,7 @@ RoutingService.StateReplicatorName=Replicator
 
 RoutingService2.Endpoints=tcp -p 10052
 RoutingService2.ComponentService.Endpoints=tcp -p 10053
-RoutingService2.ThreadPool.Size=4
+RoutingService2.ThreadPool.Size=6
 RoutingService2.ThreadPool.SizeMax=10
 RoutingService2.ThreadPool.SizeWarn=9
 RoutingService2.Standby=yes
@@ -56,7 +56,9 @@ RoutingService2.StateReplicatorName=Replicator
 Replicator.InstanceName=Replicator
 Replicator.Endpoints=default -p 10054
 Replicator.ComponentService.Endpoints=default -p 10055
-Replicator.ThreadPool.Size=4
+Replicator.ThreadPool.Size=6
+Replicator.ThreadPool.SizeMax=10
+Replicator.ThreadPool.SizeWarn=9
 
 # AsteriskSCF.RoutingService.logger=Debug
 
@@ -67,10 +69,18 @@ Replicator.ThreadPool.Size=4
 TestRoutingAdapterOut.Endpoints=tcp -p 10070
 TestRoutingAdapterIn.Endpoints=tcp -p 10071
 
+# NOTE: For testing, we grab direct proxy to the same servant on 
+# backup service.
+
 # Where to look for the Routing Service LocatorRegistry interface
 LocatorRegistry.Proxy=RoutingServiceLocatorRegistry:tcp -p 10050
+BackupLocatorRegistry.Proxy=RoutingServiceLocatorRegistry:tcp -p 10052
 
 SessionRouter.Proxy=SessionRouter:tcp -p 10050
+BackupSessionRouter.Proxy=SessionRouter:tcp -p 10052
+
+Replica.Proxy=BasicRoutingServiceReplica:tcp -p 10050
+BackupReplica.Proxy=BasicRoutingServiceReplica:tcp -p 10052
 
 TestRoutingAdapterIn.ThreadPool.Size=4
 TestRoutingAdapterIn.ThreadPool.SizeMax=10
@@ -121,3 +131,4 @@ ServiceLocatorAdapter.Endpoints=tcp -p 4411
 
 # Logger configuration
 LoggerAdapter.Endpoints=default
+AsteriskSCF.Logging.logger.AsteriskSCF=Error
diff --git a/src/BasicRoutingServiceApp.cpp b/src/BasicRoutingServiceApp.cpp
index 84e35cb..64d8397 100644
--- a/src/BasicRoutingServiceApp.cpp
+++ b/src/BasicRoutingServiceApp.cpp
@@ -329,17 +329,27 @@ void BasicRoutingServiceApp::onStandby()
  */
 void BasicRoutingServiceApp::listenToStateReplicator()
 {
-    // Do we have a reference to our state replicator?
-    if (mReplicationContext->getReplicatorService() == 0)
+    if ((mReplicationContext->getReplicatorService() == 0) || (mListeningToReplicator == true))
     {
         return;
     }
 
-    // Are we in standby mode?
-    if (mReplicationContext->isComponentActive() == false)
+    try
     {
-        mReplicationContext->getReplicatorService()->addListener(mReplicatorListenerProxy);
-        mListeningToReplicator = true;
+        // Are we in standby mode?
+        if (mReplicationContext->isComponentActive() == false)
+        {
+            AsteriskSCF::BasicRoutingService::V1::RoutingStateReplicatorPrx oneWayStateReplicator = 
+                  AsteriskSCF::BasicRoutingService::V1::RoutingStateReplicatorPrx::uncheckedCast(mReplicationContext->getReplicatorService()->ice_oneway());
+
+            oneWayStateReplicator->addListener(mReplicatorListenerProxy);
+            mListeningToReplicator = true;
+        }
+    }
+    catch (const Ice::Exception& e)
+    {
+        lg(Error) << e.what();
+        throw;
     }
 }
 
@@ -350,13 +360,25 @@ void BasicRoutingServiceApp::listenToStateReplicator()
  */
 void BasicRoutingServiceApp::stopListeningToStateReplicator()
 {
-    if (!mListeningToReplicator)
+    if ((mReplicationContext->getReplicatorService() == 0) || (mListeningToReplicator == false))
     {
         return;
     }
 
-    mReplicationContext->getReplicatorService()->removeListener(mReplicatorListenerProxy);
-    mListeningToReplicator = false;
+    try
+    {
+        AsteriskSCF::BasicRoutingService::V1::RoutingStateReplicatorPrx oneWayStateReplicator = 
+                AsteriskSCF::BasicRoutingService::V1::RoutingStateReplicatorPrx::uncheckedCast(mReplicationContext->getReplicatorService()->ice_oneway());
+
+        oneWayStateReplicator->removeListener(mReplicatorListenerProxy);
+
+        mListeningToReplicator = false;
+    }
+    catch (const Ice::Exception& e)
+    {
+        lg(Error) << e.what();
+        throw;
+    }
 }
 
 /**
diff --git a/src/RoutingStateReplicatorListener.cpp b/src/RoutingStateReplicatorListener.cpp
index a1c5d64..dc48b3c 100644
--- a/src/RoutingStateReplicatorListener.cpp
+++ b/src/RoutingStateReplicatorListener.cpp
@@ -122,12 +122,14 @@ public:
 	    class visitor : public AsteriskSCF::BasicRoutingService::V1::RoutingStateItemVisitor
 	    {
 	    public:
-	        visitor(RoutingStateReplicatorListenerPriv *impl) : mImpl(impl)
+	        visitor(RoutingStateReplicatorListenerPriv *impl, const Ice::Current& current)  
+                        :  mImpl(impl), mCurrent(current)
 	        {
 	        }
 
 	    private:
 	        RoutingStateReplicatorListenerPriv *mImpl;
+            const Ice::Current& mCurrent;
 
             void visitRouteSessionOpStart(const ::AsteriskSCF::BasicRoutingService::V1::RouteSessionOpStartPtr& opState)
             {
@@ -161,13 +163,13 @@ public:
 
             void visitEndpointLocatorState(const ::AsteriskSCF::BasicRoutingService::V1::EndpointLocatorStatePtr& item)
             {
-                mImpl->mEndpointRegistry->addEndpointLocator(item->key, item->regExList, item->locator, ::Ice::Current());
+                mImpl->mEndpointRegistry->addEndpointLocator(item->key, item->regExList, item->locator, mCurrent);
             }
 
         }; // end method-local visitor def
 
         // Create the visitor. Smart pointer will cleanup when this method exits. 
-        AsteriskSCF::BasicRoutingService::V1::RoutingStateItemVisitorPtr v = new visitor(this);
+        AsteriskSCF::BasicRoutingService::V1::RoutingStateItemVisitorPtr v = new visitor(this, current);
 
         for (RoutingStateItemSeq::const_iterator item = items.begin(); item != items.end(); ++item)
         {
diff --git a/test/SharedTestData.h b/test/SharedTestData.h
index dd7d145..a82c213 100644
--- a/test/SharedTestData.h
+++ b/test/SharedTestData.h
@@ -20,6 +20,7 @@
 #include <AsteriskSCF/Core/Routing/RoutingIf.h>
 #include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
 #include <AsteriskSCF/SessionCommunications/SessionCommunicationsIf.h>
+#include <AsteriskSCF/System/Component/ReplicaIf.h>
 
 #include "MockBridgeManager.h"
 #include "MockEndpointLocator.h"
@@ -44,9 +45,15 @@ struct SharedTestData
     Ice::ObjectAdapterPtr adapterIn;
     Ice::ObjectAdapterPtr adapterOut;
 
-    //A proxy to the actual routing service
+    // Proxies to the routing service
     AsteriskSCF::Core::Routing::V1::LocatorRegistryPrx locatorRegistry;
     AsteriskSCF::SessionCommunications::V1::SessionRouterPrx sessionRouter;
+    AsteriskSCF::System::Component::V1::ReplicaPrx serviceReplicaMgmt;
+
+    // Proxies to the backup instance's routing service interfaces.
+    AsteriskSCF::Core::Routing::V1::LocatorRegistryPrx backupLocatorRegistry;
+    AsteriskSCF::SessionCommunications::V1::SessionRouterPrx backupSessionRouter;
+    AsteriskSCF::System::Component::V1::ReplicaPrx backupServiceReplicaMgmt;
 
     // Our own EndpointLocator to server up endpoints to the RoutingService, emulating a channel.
     MockEndpointLocatorPtr endpointLocator;
diff --git a/test/TestRouting.cpp b/test/TestRouting.cpp
index b4e28c1..0c5c548 100644
--- a/test/TestRouting.cpp
+++ b/test/TestRouting.cpp
@@ -41,6 +41,7 @@ using namespace AsteriskSCF::Core::Endpoint::V1;
 using namespace AsteriskSCF::SessionCommunications::V1;
 using namespace AsteriskSCF::Core::Discovery::V1;
 using namespace AsteriskSCF::RoutingTest;
+using namespace AsteriskSCF::System::Component::V1;
 
 /**
  * Instantiate our shared data.
@@ -90,20 +91,26 @@ struct GlobalIceFixture
             SharedTestData::instance.communicatorOut = Ice::initialize(initData);
             SharedTestData::instance.adapterOut = SharedTestData::instance.communicatorOut->createObjectAdapterWithEndpoints("TestRoutingAdapterOut", "default -p 10071");
 
-            // Get ref to Routing Service so we can test it. Getting direct for now, but
+            // Get ref to Routing Service EndpointLocator so we can test it. Getting direct for now, but
             // need to test acquiring reference via ServiceLocator as well.
-            Ice::PropertiesPtr communicatorProps = SharedTestData::instance.communicatorOut->getProperties();
             Ice::ObjectPrx locatorObj = SharedTestData::instance.communicatorOut->propertyToProxy("LocatorRegistry.Proxy");
             SharedTestData::instance.locatorRegistry = LocatorRegistryPrx::uncheckedCast(locatorObj);
 
-            // Get the ServiceLocator and ServiceLocator manager
-            // <TBD>
-
             if (!SharedTestData::instance.locatorRegistry)
             {
                 throw "Invalid LocatorRegistry";
             }
 
+            // Get ref to Backup Routing Services EndpointLocator we can test it. 
+            Ice::ObjectPrx locatorObj2 = SharedTestData::instance.communicatorOut->propertyToProxy("BackupLocatorRegistry.Proxy");
+            SharedTestData::instance.backupLocatorRegistry = LocatorRegistryPrx::uncheckedCast(locatorObj2);
+
+            if (!SharedTestData::instance.backupLocatorRegistry)
+            {
+                throw "Invalid Backup LocatorRegistry";
+            }
+
+            // Get a ref to the SessionRouter interface and cache it for testing.
             Ice::ObjectPrx routerObj = SharedTestData::instance.communicatorOut->propertyToProxy("SessionRouter.Proxy");
             SharedTestData::instance.sessionRouter = SessionRouterPrx::checkedCast(routerObj);
 
@@ -112,8 +119,34 @@ struct GlobalIceFixture
                 throw "Invalid SessionRouter";
             }
 
-            PopulateEndpoints();
+            // Get a ref to the Backup SessionRouter interface and cache it for testing.
+            Ice::ObjectPrx routerObj2 = SharedTestData::instance.communicatorOut->propertyToProxy("BackupSessionRouter.Proxy");
+            SharedTestData::instance.backupSessionRouter = SessionRouterPrx::checkedCast(routerObj2);
+
+            if (!SharedTestData::instance.backupSessionRouter)
+            {
+                throw "Invalid Backup SessionRouter";
+            }
+
+            // Get a ref to the Replica interface and cache it for testing.
+            Ice::ObjectPrx replicaObj = SharedTestData::instance.communicatorOut->propertyToProxy("Replica.Proxy");
+            SharedTestData::instance.serviceReplicaMgmt = ReplicaPrx::checkedCast(replicaObj);
+
+            if (!SharedTestData::instance.serviceReplicaMgmt)
+            {
+                throw "Invalid Replica";
+            }
 
+            // Get a ref to the Replica interface and cache it for testing.
+            Ice::ObjectPrx replicaObj2 = SharedTestData::instance.communicatorOut->propertyToProxy("BackupReplica.Proxy");
+            SharedTestData::instance.backupServiceReplicaMgmt = ReplicaPrx::checkedCast(replicaObj2);
+
+            if (!SharedTestData::instance.backupServiceReplicaMgmt)
+            {
+                throw "Invalid Backup Replica";
+            }
+
+            PopulateEndpoints();
             RegisterWithServiceLocator();
         }
         catch (const Ice::Exception& ex)
@@ -228,6 +261,34 @@ public:
 };
 
 /**
+ * A fixture for replication testing.
+ * Provides setup/teardown for a specific set of tests.
+ */
+struct ReplicationFixture : public PerTestFixture
+{
+public:
+    ReplicationFixture()
+    {
+        try
+        {
+        }
+        catch (...)
+        {
+        }
+    }
+
+    ~ReplicationFixture()
+    {
+        try
+        {
+        }
+        catch (...)
+        {
+        }
+    }
+};
+
+/**
  * Test adding and removing a locator with the routing service's Locator Registry.
  */
 BOOST_AUTO_TEST_CASE(AddAndRemoveEndpointLocator)
@@ -493,29 +554,91 @@ BOOST_FIXTURE_TEST_CASE(AttendedTransfer, PerTestFixture)
 }
 
 /**
- * A fixture for replication testing.
- * Provides setup/teardown for a specific set of tests.
+ * See if we can do a lookup of the endpoint locator on the backup
+ * service while it is still in standby mode. 
+ * There's nothing to prevent this from working, although in practice, 
+ * we'd expect other components to not have a proxy to the backup component's interfaces. 
  */
-struct ReplicationFixture
+BOOST_FIXTURE_TEST_CASE(BackupEndpointLocatorInStandby, PerTestFixture)
 {
-public:
-    ReplicationFixture()
+    try
     {
-        try
-        {
-        }
-        catch (...)
-        {
-        }
+        // Give the state replicator time to push the EndpointLocator to the standby component. 
+        IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500));
+
+        // Do a lookup on the backup while it is in standby mode. 
+        // There's nothing to prevent this from working, although in practice, 
+        // we'd expect other components to not have a proxy to the backup component's interfaces. 
+        BOOST_TEST_MESSAGE("Looking up endpoint via the Backup Routing Service...");
+        string lookupVal = "102";
+        AsteriskSCF::Core::Endpoint::V1::EndpointSeq seq = SharedTestData::instance.backupLocatorRegistry->lookup(lookupVal);
+
+        BOOST_CHECK(seq.size() > 0);
+        BOOST_CHECK(seq[0]->getId() == lookupVal);
+    }
+    catch(const std::exception &e)
+    {
+        string msg = "Exception looking up endpoint via Backup Service Locator: ";
+        msg += e.what();
+        BOOST_FAIL(msg);
     }
+}
+/**
+ * See if we can do a lookup of the endpoint locator on the backup
+ * after it's activated.
+ */
+BOOST_FIXTURE_TEST_CASE(BackupEndpointLocatorActive, PerTestFixture)
+{
+    try
+    {
+        // Give the state replicator time to push the EndpointLocator to the standby component. 
+        IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1000));
 
-    ~ReplicationFixture()
+        // Make the backup active. 
+        SharedTestData::instance.backupServiceReplicaMgmt->activate();
+        BOOST_CHECK(SharedTestData::instance.backupServiceReplicaMgmt->isActive() == true);
+
+        // Do a lookup on it now that it's active. 
+        BOOST_TEST_MESSAGE("Looking up endpoint via the Backup Routing Service...");
+        string lookupVal = "102";
+        AsteriskSCF::Core::Endpoint::V1::EndpointSeq seq = SharedTestData::instance.backupLocatorRegistry->lookup(lookupVal);
+
+        BOOST_CHECK(seq.size() > 0);
+        BOOST_CHECK(seq[0]->getId() == lookupVal);
+
+        // Set the backup back into standby mode.
+        SharedTestData::instance.backupServiceReplicaMgmt->standby();
+        BOOST_CHECK(SharedTestData::instance.backupServiceReplicaMgmt->isActive() == false);
+
+    }
+    catch(const std::exception &e)
     {
-        try
-        {
-        }
-        catch (...)
-        {
-        }
+        string msg = "Exception looking up endpoint via Backup Service Locator: ";
+        msg += e.what();
+        BOOST_FAIL(msg);
     }
-};
+}
+
+BOOST_FIXTURE_TEST_CASE(SwitchActiveAndStandby, PerTestFixture)
+{
+    try
+    {
+        // Verify that both the active and standby services report the correct state.
+        BOOST_CHECK(SharedTestData::instance.serviceReplicaMgmt->isActive() == true);
+        BOOST_CHECK(SharedTestData::instance.backupServiceReplicaMgmt->isActive() == false);
+
+        // Switch the active to standby. 
+        SharedTestData::instance.serviceReplicaMgmt->standby();
+        BOOST_CHECK(SharedTestData::instance.serviceReplicaMgmt->isActive() == false);
+
+        // Switch back to active. 
+        SharedTestData::instance.serviceReplicaMgmt->activate();
+        BOOST_CHECK(SharedTestData::instance.serviceReplicaMgmt->isActive() == true);
+    }
+    catch (...)
+    {
+        BOOST_FAIL("Exception switching component between active and standby.");
+    }
+
+}
+

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


-- 
asterisk-scf/integration/routing.git



More information about the asterisk-scf-commits mailing list