[hydra-commits] hydra/bridging.git branch "master" updated.

Commits to the Hydra project code repositories hydra-commits at lists.digium.com
Tue Aug 10 03:46:04 CDT 2010


branch "master" has been updated
       via  9ee11387877c253fbb8c83d41be414a733d9b999 (commit)
      from  fa3eeec679e6f051324725fdadcba4d7a5cb08c4 (commit)

Summary of changes:
 slice                     |    2 +-
 src/BridgeFactoryImpl.cpp |   12 +
 src/BridgeImpl.cpp        |   79 +++++--
 test/TestBridging.cpp     |  538 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 606 insertions(+), 25 deletions(-)


- Log -----------------------------------------------------------------
commit 9ee11387877c253fbb8c83d41be414a733d9b999
Author: Brent Eagles <beagles at digium.com>
Date:   Tue Aug 10 06:14:04 2010 -0230

    Adding tests and some tracing.

diff --git a/slice b/slice
index aedc8c1..3caf633 160000
--- a/slice
+++ b/slice
@@ -1 +1 @@
-Subproject commit aedc8c12e431ba663550f722ad8ab1479535590e
+Subproject commit 3caf6332202c33bc3d48d676260bf9a3e1edde9f
diff --git a/src/BridgeFactoryImpl.cpp b/src/BridgeFactoryImpl.cpp
index 3836af0..3845588 100644
--- a/src/BridgeFactoryImpl.cpp
+++ b/src/BridgeFactoryImpl.cpp
@@ -101,6 +101,18 @@ Hydra::Core::Bridging::V1::BridgePrx Hydra::BridgeService::BridgeFactoryImpl::cr
                 throw Hydra::Core::Bridging::V1::EndpointCollision(adminEp->id, t->id); 
             }
         }
+        //
+        // Kind of icky but necessary. The bridge cannot an endpoint registered more than twice.
+        //
+        for(Hydra::Session::V1::SessionEndpointSeq::const_iterator j = eps.begin(); j != eps.end(); ++j)
+        {
+            if((*j)->id->endpointManagerId == t->id->endpointManagerId && (*j)->id->deviceId == t->id->deviceId)
+            {
+                mLogger.getDebugStream() << __FUNCTION__ << ": endpoint id collision between endpoints in initial endpoint set " <<
+                    t->id->endpointManagerId << ":" << t->id->deviceId << std::endl;
+                throw Hydra::Core::Bridging::V1::EndpointCollision((*j)->id, t->id); 
+            }
+        }
         eps.push_back(t);
     }
     mLogger.getDebugStream() << __FUNCTION__ << ": endpoints have been successfully validated." << std::endl;
diff --git a/src/BridgeImpl.cpp b/src/BridgeImpl.cpp
index 505ae06..3e8214f 100644
--- a/src/BridgeImpl.cpp
+++ b/src/BridgeImpl.cpp
@@ -10,34 +10,37 @@ namespace Hydra
 {
 namespace BridgeService
 {
-   class BridgeShutdownFunctor : public std::unary_function<Session::V1::SessionEndpointPtr, void>
-   {
-   public:
-      BridgeShutdownFunctor(const Core::Endpoint::V1::EndpointIdPtr& id, const Session::V1::ResponseCodePtr& responseCode) : 
-         mId(id),
-         mResponseCode(responseCode)
-      {
-      }
-
-      void operator()(const Hydra::Core::Endpoint::V1::BaseEndpointPtr b) 
-      { 
-         if(!b)
-         {
-            Hydra::Session::V1::SessionEndpointPtr p(Hydra::Session::V1::SessionEndpointPtr::dynamicCast(b));
-            assert(p != 0);
-            if(p->callback)
+    //
+    // Functor to support using for_each on shutdown.
+    //
+    class BridgeShutdownFunctor : public std::unary_function<Session::V1::SessionEndpointPtr, void>
+    {
+    public:
+        BridgeShutdownFunctor(const Core::Endpoint::V1::EndpointIdPtr& id, const Session::V1::ResponseCodePtr& responseCode) : 
+            mId(id),
+            mResponseCode(responseCode)
+        {
+        }
+
+        void operator()(const Hydra::Core::Endpoint::V1::BaseEndpointPtr b) 
+        { 
+            if(!b)
             {
-               Hydra::Session::V1::SessionEndpointPtr::dynamicCast(b)->callback->terminated(mId, mResponseCode);
+                Hydra::Session::V1::SessionEndpointPtr p(Hydra::Session::V1::SessionEndpointPtr::dynamicCast(b));
+                assert(p != 0);
+                if(p->callback)
+                {
+                    Hydra::Session::V1::SessionEndpointPtr::dynamicCast(b)->callback->terminated(mId, mResponseCode);
+                }
             }
-         }
-      }
-   private:
-      Core::Endpoint::V1::EndpointIdPtr mId;
-      Session::V1::ResponseCodePtr mResponseCode;
-   };
+        }
+    private:
+        Core::Endpoint::V1::EndpointIdPtr mId;
+        Session::V1::ResponseCodePtr mResponseCode;
+    };
 
-}; // End of namespace BridgeService
-};// End of namespace Hydra
+} // End of namespace BridgeService
+} // End of namespace Hydra
 
 Hydra::BridgeService::BridgeImpl::BridgeImpl(
   const Hydra::Session::V1::SessionEndpointPtr& adminEp,
@@ -56,17 +59,20 @@ void Hydra::BridgeService::BridgeImpl::addEndpoint(const Hydra::Core::Endpoint::
     mLogger.getTraceStream() << __FUNCTION__ << ":" << current.adapter->getCommunicator()->identityToString(current.id) << std::endl;
     if(ep == 0 || ep->id == 0)
     {
+        mLogger.getDebugStream() << __FUNCTION__ << ": attempting to null endpoint or endpoint with invalid id." << std::endl;
         throw Hydra::Core::Endpoint::V1::InvalidEndpointId(new Hydra::Core::Endpoint::V1::EndpointId);
     }
 
     if(!checkEndpointId(*ep->id))
     {
+        mLogger.getDebugStream() << __FUNCTION__ << ": attempting to add endpoint with invalid id " << ep->id->endpointManagerId << ":" << ep->id->deviceId << "."  << std::endl;
         throw Hydra::Core::Endpoint::V1::InvalidEndpointId(ep->id);
     }
 
     Hydra::Session::V1::SessionEndpointPtr newEndpoint(Hydra::Session::V1::SessionEndpointPtr::dynamicCast(ep));
     if(!newEndpoint)
     {
+        mLogger.getDebugStream() << __FUNCTION__ << ": endpoint with id " << ep->id->endpointManagerId << ":" << ep->id->deviceId << " failed dynamic cast." << std::endl;
         throw Hydra::Core::Bridging::V1::UnsupportedEndpoint(ep->id);
     }
     boost::unique_lock<boost::shared_mutex> lock(mLock);
@@ -74,9 +80,12 @@ void Hydra::BridgeService::BridgeImpl::addEndpoint(const Hydra::Core::Endpoint::
     Hydra::Session::V1::SessionEndpointSeq::iterator  i = find(ep->id);
     if(i != mEndpoints.end())
     {
+        mLogger.getDebugStream() << __FUNCTION__ << ": endpoint with id " << ep->id->endpointManagerId << ":" << ep->id->deviceId << " already registered." << std::endl;
         throw Hydra::Core::Bridging::V1::EndpointAlreadyRegistered();
     }
     mEndpoints.push_back(newEndpoint);
+    mLogger.getDebugStream() << __FUNCTION__ << ": bridge " << current.adapter->getCommunicator()->identityToString(current.id) <<
+         " now has " << mEndpoints.size() << " endpoints." << std::endl;
 }
 
 void Hydra::BridgeService::BridgeImpl::removeEndpoint(const Hydra::Core::Endpoint::V1::EndpointIdPtr& ep, const Ice::Current& current)
@@ -84,13 +93,35 @@ void Hydra::BridgeService::BridgeImpl::removeEndpoint(const Hydra::Core::Endpoin
     mLogger.getTraceStream() << __FUNCTION__ << ":" << current.adapter->getCommunicator()->identityToString(current.id) << std::endl;
     boost::unique_lock<boost::shared_mutex> lock(mLock);
     statePreCheck();
+    if(ep == 0)
+    {
+        throw Hydra::Core::Endpoint::V1::InvalidEndpointId(0);
+    }
+    if(!checkEndpointId(*ep))
+    {
+        throw Hydra::Core::Endpoint::V1::InvalidEndpointId(ep);
+    }
     Hydra::Session::V1::SessionEndpointSeq::iterator  i = find(ep);
+    if(i == mEndpoints.end())
+    {
+        throw Hydra::Core::Bridging::V1::UnknownEndpoint(ep);
+    }
 
     if(mManager && !mManager->onRemoveEndpoint(*i))
     {
+        mLogger.getDebugStream() << __FUNCTION__ << ": bridge monitor rejects removal of endpoint with id " << ep->endpointManagerId << ":" << ep->deviceId << "." << std::endl;
+        //
+        // TODO: This seems unlikely to be correct. Either some kind of
+        // exception needs to be thrown or this kind of thing should not be
+        // allowed.  Silently doing nothing is likely to cause all sorts of
+        // confusion.
+        //
         return;
     }
     mEndpoints.erase(i);
+
+    mLogger.getDebugStream() << __FUNCTION__ << ": bridge " << current.adapter->getCommunicator()->identityToString(current.id) <<
+         " now has " << mEndpoints.size() << " endpoints." << std::endl;
 }
 
 Hydra::Core::Endpoint::V1::EndpointSeq Hydra::BridgeService::BridgeImpl::listEndpoints(const Ice::Current& current)
diff --git a/test/TestBridging.cpp b/test/TestBridging.cpp
index 2d2d658..1b34009 100644
--- a/test/TestBridging.cpp
+++ b/test/TestBridging.cpp
@@ -568,3 +568,541 @@ BOOST_AUTO_TEST_CASE(BridgeFactoryCreateBridgeWithCollidingAdminAndInitialEndpoi
     }
     adapter->destroy();
 }
+
+BOOST_AUTO_TEST_CASE(BridgeFactoryCreateBridgeWithCollisions)
+{
+    Ice::InitializationData initData;
+    initData.properties = Ice::createProperties(0);
+    initData.properties->setProperty("TestBridging.Endpoints", "default -p 33333 -t 1000");
+    Ice::CommunicatorPtr comm = Ice::initialize(initData);
+    Ice::ObjectAdapterPtr adapter = comm->createObjectAdapter("TestBridging");
+    Ice::Current dummy;
+    dummy.adapter = adapter;
+    dummy.id = comm->stringToIdentity("testobject");
+    try
+    {
+        Hydra::BridgeService::BridgeFactoryImplPtr factory(new Hydra::BridgeService::BridgeFactoryImpl(adapter));
+        Hydra::Core::Endpoint::V1::BaseEndpointPtr p(new Hydra::Session::V1::SessionEndpoint);
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "foo";
+        p->id->deviceId = "bar";
+        Hydra::Core::Endpoint::V1::EndpointSeq eps;
+        eps.push_back(p);
+        p = new Hydra::Session::V1::SessionEndpoint;
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "foo";
+        p->id->deviceId = "bar";
+        eps.push_back(p);
+        Hydra::Core::Bridging::V1::BridgePrx b =  factory->createBridge(0, eps, 0, dummy);
+        BOOST_CHECK("Should not have succeeded." == 0);
+    }
+    catch(const Hydra::Core::Bridging::V1::EndpointCollision& ex)
+    {
+        BOOST_CHECK(ex.first->endpointManagerId == "foo" && ex.first->deviceId == "bar");
+        BOOST_CHECK(ex.second->endpointManagerId == "foo" && ex.second->deviceId == "bar");
+    }
+    catch(...)
+    {
+        adapter->destroy();
+        throw;
+    }
+    adapter->destroy();
+}
+
+BOOST_AUTO_TEST_CASE(BridgeFactoryCreateBridgeWithValidInitialSet)
+{
+    Ice::InitializationData initData;
+    initData.properties = Ice::createProperties(0);
+    initData.properties->setProperty("TestBridging.Endpoints", "default -p 33333 -t 1000");
+    Ice::CommunicatorPtr comm = Ice::initialize(initData);
+    Ice::ObjectAdapterPtr adapter = comm->createObjectAdapter("TestBridging");
+    Ice::Current dummy;
+    dummy.adapter = adapter;
+    dummy.id = comm->stringToIdentity("testobject");
+    try
+    {
+        Hydra::BridgeService::BridgeFactoryImplPtr factory(new Hydra::BridgeService::BridgeFactoryImpl(adapter));
+        Hydra::Core::Endpoint::V1::BaseEndpointPtr p(new Hydra::Session::V1::SessionEndpoint);
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "foo";
+        p->id->deviceId = "bar";
+        Hydra::Core::Endpoint::V1::EndpointSeq eps;
+        eps.push_back(p);
+        p = new Hydra::Session::V1::SessionEndpoint;
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "foo1";
+        p->id->deviceId = "bar";
+        eps.push_back(p);
+        p = new Hydra::Session::V1::SessionEndpoint;
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "foo";
+        p->id->deviceId = "bar1";
+        eps.push_back(p);
+        p = new Hydra::Session::V1::SessionEndpoint;
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "fooa";
+        p->id->deviceId = "bar";
+        Hydra::Core::Bridging::V1::BridgePrx b =  factory->createBridge(p, eps, 0, dummy);
+        BOOST_CHECK(b);
+        Hydra::Core::Endpoint::V1::EndpointSeq endpoints = b->listEndpoints();
+        BOOST_CHECK(endpoints.size() == 4);
+
+        //
+        // It so happens that we know the admin endpoint is inserted at the beginning of
+        // the result. If this changes, then so will the test.
+        //
+        eps.insert(eps.begin(), p);
+        Hydra::Core::Endpoint::V1::EndpointSeq::const_iterator j = endpoints.begin(); 
+        for(Hydra::Core::Endpoint::V1::EndpointSeq::const_iterator i = eps.begin(); i != eps.end(); ++i, ++j)
+        {
+            BOOST_CHECK((*i)->id->endpointManagerId == (*j)->id->endpointManagerId);
+            BOOST_CHECK((*i)->id->deviceId == (*j)->id->deviceId);
+            Hydra::Session::V1::SessionEndpointPtr sp(Hydra::Session::V1::SessionEndpointPtr::dynamicCast(*j));
+            BOOST_CHECK(sp);
+        }
+    }
+    catch(const Hydra::Core::Bridging::V1::EndpointCollision& ex)
+    {
+        BOOST_CHECK(ex.first->endpointManagerId == "foo" && ex.first->deviceId == "bar");
+        BOOST_CHECK(ex.second->endpointManagerId == "foo" && ex.second->deviceId == "bar");
+    }
+    catch(...)
+    {
+        adapter->destroy();
+        throw;
+    }
+    adapter->destroy();
+}
+
+BOOST_AUTO_TEST_CASE(BridgeAddEndpoint)
+{
+    Ice::InitializationData initData;
+    initData.properties = Ice::createProperties(0);
+    initData.properties->setProperty("TestBridging.Endpoints", "default -p 33333 -t 1000");
+    Ice::CommunicatorPtr comm = Ice::initialize(initData);
+    Ice::ObjectAdapterPtr adapter = comm->createObjectAdapter("TestBridging");
+    Ice::Current dummy;
+    dummy.adapter = adapter;
+    dummy.id = comm->stringToIdentity("testobject");
+    try
+    {
+        Hydra::Session::V1::SessionEndpointPtr p(new Hydra::Session::V1::SessionEndpoint);
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "foo";
+        p->id->deviceId = "bar";
+        Hydra::Session::V1::SessionEndpointSeq eps;
+        eps.push_back(p);
+        p = new Hydra::Session::V1::SessionEndpoint;
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "foo1";
+        p->id->deviceId = "bar";
+        eps.push_back(p);
+        p = new Hydra::Session::V1::SessionEndpoint;
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "foo";
+        p->id->deviceId = "bar1";
+        eps.push_back(p);
+        p = new Hydra::Session::V1::SessionEndpoint;
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "fooa";
+        p->id->deviceId = "bar";
+        Hydra::BridgeService::BridgeImplPtr bridge(new Hydra::BridgeService::BridgeImpl(p, eps, 0));
+        eps.insert(eps.begin(), p);
+        p = new Hydra::Session::V1::SessionEndpoint;
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "foo2";
+        p->id->deviceId = "bar";
+        bridge->addEndpoint(p, dummy);
+        eps.push_back(p);
+        Hydra::Core::Endpoint::V1::EndpointSeq endpoints = bridge->listEndpoints(dummy);
+        BOOST_CHECK(endpoints.size() == 5);
+
+        //
+        // It so happens that we know the admin endpoint is inserted at the beginning of
+        // the result. If this changes, then so will the test.
+        //
+        Hydra::Core::Endpoint::V1::EndpointSeq::const_iterator j = endpoints.begin(); 
+        for(Hydra::Session::V1::SessionEndpointSeq::const_iterator i = eps.begin(); i != eps.end(); ++i, ++j)
+        {
+            BOOST_CHECK((*i)->id->endpointManagerId == (*j)->id->endpointManagerId);
+            BOOST_CHECK((*i)->id->deviceId == (*j)->id->deviceId);
+            Hydra::Session::V1::SessionEndpointPtr sp(Hydra::Session::V1::SessionEndpointPtr::dynamicCast(*j));
+            BOOST_CHECK(sp);
+        }
+    }
+    catch(...)
+    {
+        adapter->destroy();
+        throw;
+    }
+    adapter->destroy();
+}
+
+BOOST_AUTO_TEST_CASE(BridgeAddInvalidEndpoint)
+{
+    Ice::InitializationData initData;
+    initData.properties = Ice::createProperties(0);
+    initData.properties->setProperty("TestBridging.Endpoints", "default -p 33333 -t 1000");
+    Ice::CommunicatorPtr comm = Ice::initialize(initData);
+    Ice::ObjectAdapterPtr adapter = comm->createObjectAdapter("TestBridging");
+    Ice::Current dummy;
+    dummy.adapter = adapter;
+    dummy.id = comm->stringToIdentity("testobject");
+    try
+    {
+        Hydra::Session::V1::SessionEndpointSeq eps;
+        Hydra::BridgeService::BridgeImplPtr bridge(new Hydra::BridgeService::BridgeImpl(0, eps, 0));
+        Hydra::Core::Endpoint::V1::BaseEndpointPtr p(new Hydra::Core::Endpoint::V1::BaseEndpoint);
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "foo";
+        p->id->deviceId = "foo";
+        bridge->addEndpoint(p, dummy);
+        BOOST_CHECK("Should not have succeeded." == 0);
+    }
+    catch(const Hydra::Core::Bridging::V1::UnsupportedEndpoint& ex)
+    {
+        BOOST_CHECK(ex.ep->endpointManagerId == "foo" && ex.ep->deviceId == "foo");
+    }
+    catch(...)
+    {
+        adapter->destroy();
+        throw;
+    }
+    adapter->destroy();
+}
+
+BOOST_AUTO_TEST_CASE(BridgeAddInvalidId1)
+{
+    Ice::InitializationData initData;
+    initData.properties = Ice::createProperties(0);
+    initData.properties->setProperty("TestBridging.Endpoints", "default -p 33333 -t 1000");
+    Ice::CommunicatorPtr comm = Ice::initialize(initData);
+    Ice::ObjectAdapterPtr adapter = comm->createObjectAdapter("TestBridging");
+    Ice::Current dummy;
+    dummy.adapter = adapter;
+    dummy.id = comm->stringToIdentity("testobject");
+    try
+    {
+        Hydra::Session::V1::SessionEndpointSeq eps;
+        Hydra::BridgeService::BridgeImplPtr bridge(new Hydra::BridgeService::BridgeImpl(0, eps, 0));
+        Hydra::Core::Endpoint::V1::BaseEndpointPtr p(new Hydra::Session::V1::SessionEndpoint);
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "";
+        p->id->deviceId = "";
+        bridge->addEndpoint(p, dummy);
+        BOOST_CHECK("Should not have succeeded." == 0);
+    }
+    catch(const Hydra::Core::Endpoint::V1::InvalidEndpointId& ex)
+    {
+        BOOST_CHECK(ex.badId->endpointManagerId.size() == 0 && ex.badId->deviceId.size() == 0);
+    }
+    catch(...)
+    {
+        adapter->destroy();
+        throw;
+    }
+    adapter->destroy();
+}
+
+BOOST_AUTO_TEST_CASE(BridgeAddInvalidId2)
+{
+    Ice::InitializationData initData;
+    initData.properties = Ice::createProperties(0);
+    initData.properties->setProperty("TestBridging.Endpoints", "default -p 33333 -t 1000");
+    Ice::CommunicatorPtr comm = Ice::initialize(initData);
+    Ice::ObjectAdapterPtr adapter = comm->createObjectAdapter("TestBridging");
+    Ice::Current dummy;
+    dummy.adapter = adapter;
+    dummy.id = comm->stringToIdentity("testobject");
+    try
+    {
+        Hydra::Session::V1::SessionEndpointSeq eps;
+        Hydra::BridgeService::BridgeImplPtr bridge(new Hydra::BridgeService::BridgeImpl(0, eps, 0));
+        Hydra::Core::Endpoint::V1::BaseEndpointPtr p(new Hydra::Session::V1::SessionEndpoint);
+        bridge->addEndpoint(p, dummy);
+        BOOST_CHECK("Should not have succeeded." == 0);
+    }
+    catch(const Hydra::Core::Endpoint::V1::InvalidEndpointId& ex)
+    {
+        BOOST_CHECK(ex.badId->endpointManagerId.size() == 0 && ex.badId->deviceId.size() == 0);
+    }
+    catch(...)
+    {
+        adapter->destroy();
+        throw;
+    }
+    adapter->destroy();
+}
+
+BOOST_AUTO_TEST_CASE(BridgeRemoveEndpoint)
+{
+    Ice::InitializationData initData;
+    initData.properties = Ice::createProperties(0);
+    initData.properties->setProperty("TestBridging.Endpoints", "default -p 33333 -t 1000");
+    Ice::CommunicatorPtr comm = Ice::initialize(initData);
+    Ice::ObjectAdapterPtr adapter = comm->createObjectAdapter("TestBridging");
+    Ice::Current dummy;
+    dummy.adapter = adapter;
+    dummy.id = comm->stringToIdentity("testobject");
+    try
+    {
+        Hydra::Session::V1::SessionEndpointPtr p(new Hydra::Session::V1::SessionEndpoint);
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "foo";
+        p->id->deviceId = "bar";
+        Hydra::Session::V1::SessionEndpointSeq eps;
+        eps.push_back(p);
+        p = new Hydra::Session::V1::SessionEndpoint;
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "foo1";
+        p->id->deviceId = "bar";
+        eps.push_back(p);
+        p = new Hydra::Session::V1::SessionEndpoint;
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "foo";
+        p->id->deviceId = "bar1";
+        eps.push_back(p);
+        p = new Hydra::Session::V1::SessionEndpoint;
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "fooa";
+        p->id->deviceId = "bar";
+        Hydra::BridgeService::BridgeImplPtr bridge(new Hydra::BridgeService::BridgeImpl(p, eps, 0));
+        eps.insert(eps.begin(), p);
+        Hydra::Core::Endpoint::V1::EndpointIdPtr id(new Hydra::Core::Endpoint::V1::EndpointId);
+        id->endpointManagerId = "foo1";
+        id->deviceId = "bar";
+        Hydra::Core::Endpoint::V1::EndpointSeq endpoints = bridge->listEndpoints(dummy);
+        BOOST_CHECK(endpoints.size() == 4);
+        bridge->removeEndpoint(id, dummy);
+        endpoints = bridge->listEndpoints(dummy);
+        BOOST_CHECK(endpoints.size() == 3);
+
+
+        //
+        // It so happens that we know the admin endpoint is inserted at the beginning of
+        // the result. If this changes, then so will the test.
+        //
+        for(Hydra::Core::Endpoint::V1::EndpointSeq::const_iterator j = endpoints.begin(); j != endpoints.end(); ++j)
+        {
+            BOOST_CHECK((*j)->id->endpointManagerId != id->endpointManagerId || (*j)->id->deviceId != id->deviceId);
+        }
+    }
+    catch(...)
+    {
+        adapter->destroy();
+        throw;
+    }
+    adapter->destroy();
+}
+
+BOOST_AUTO_TEST_CASE(BridgeRemoveEndpointUnknownEndpoint)
+{
+    Ice::InitializationData initData;
+    initData.properties = Ice::createProperties(0);
+    initData.properties->setProperty("TestBridging.Endpoints", "default -p 33333 -t 1000");
+    Ice::CommunicatorPtr comm = Ice::initialize(initData);
+    Ice::ObjectAdapterPtr adapter = comm->createObjectAdapter("TestBridging");
+    Ice::Current dummy;
+    dummy.adapter = adapter;
+    dummy.id = comm->stringToIdentity("testobject");
+    try
+    {
+        Hydra::Session::V1::SessionEndpointPtr p(new Hydra::Session::V1::SessionEndpoint);
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "foo";
+        p->id->deviceId = "bar";
+        Hydra::Session::V1::SessionEndpointSeq eps;
+        eps.push_back(p);
+        p = new Hydra::Session::V1::SessionEndpoint;
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "foo1";
+        p->id->deviceId = "bar";
+        eps.push_back(p);
+        p = new Hydra::Session::V1::SessionEndpoint;
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "foo";
+        p->id->deviceId = "bar1";
+        eps.push_back(p);
+        p = new Hydra::Session::V1::SessionEndpoint;
+        p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+        p->id->endpointManagerId = "fooa";
+        p->id->deviceId = "bar";
+        Hydra::BridgeService::BridgeImplPtr bridge(new Hydra::BridgeService::BridgeImpl(p, eps, 0));
+        Hydra::Core::Endpoint::V1::EndpointIdPtr id(new Hydra::Core::Endpoint::V1::EndpointId);
+        id->endpointManagerId = "foo1";
+        id->deviceId = "unknown";
+        bridge->removeEndpoint(id, dummy);
+        BOOST_CHECK("Should not have succeeded." == 0);
+    }
+    catch(const Hydra::Core::Bridging::V1::UnknownEndpoint& ex)
+    {
+        BOOST_CHECK(ex.ep->endpointManagerId == "foo1" && ex.ep->deviceId == "unknown");
+    }
+    catch(...)
+    {
+        adapter->destroy();
+        throw;
+    }
+    adapter->destroy();
+}
+
+BOOST_AUTO_TEST_CASE(BridgeRemoveEndpointNullId)
+{
+    Ice::InitializationData initData;
+    initData.properties = Ice::createProperties(0);
+    initData.properties->setProperty("TestBridging.Endpoints", "default -p 33333 -t 1000");
+    Ice::CommunicatorPtr comm = Ice::initialize(initData);
+    Ice::ObjectAdapterPtr adapter = comm->createObjectAdapter("TestBridging");
+    Ice::Current dummy;
+    dummy.adapter = adapter;
+    dummy.id = comm->stringToIdentity("testobject");
+    try
+    {
+        Hydra::Session::V1::SessionEndpointSeq eps;
+        Hydra::BridgeService::BridgeImplPtr bridge(new Hydra::BridgeService::BridgeImpl(0, eps, 0));
+        bridge->removeEndpoint(0, dummy);
+        BOOST_CHECK("Should not have succeeded." == 0);
+    }
+    catch(const Hydra::Core::Endpoint::V1::InvalidEndpointId& ex)
+    {
+        BOOST_CHECK(ex.badId == 0);
+    }
+    catch(...)
+    {
+        adapter->destroy();
+        throw;
+    }
+    adapter->destroy();
+}
+
+BOOST_AUTO_TEST_CASE(BridgeRemoveEndpointInvalidId)
+{
+    Ice::InitializationData initData;
+    initData.properties = Ice::createProperties(0);
+    initData.properties->setProperty("TestBridging.Endpoints", "default -p 33333 -t 1000");
+    Ice::CommunicatorPtr comm = Ice::initialize(initData);
+    Ice::ObjectAdapterPtr adapter = comm->createObjectAdapter("TestBridging");
+    Ice::Current dummy;
+    dummy.adapter = adapter;
+    dummy.id = comm->stringToIdentity("testobject");
+    try
+    {
+        Hydra::Session::V1::SessionEndpointSeq eps;
+        Hydra::BridgeService::BridgeImplPtr bridge(new Hydra::BridgeService::BridgeImpl(0, eps, 0));
+        Hydra::Core::Endpoint::V1::EndpointIdPtr id(new Hydra::Core::Endpoint::V1::EndpointId);
+        id->endpointManagerId = "";
+        id->deviceId = "";
+        bridge->removeEndpoint(id, dummy);
+        BOOST_CHECK("Should not have succeeded." == 0);
+    }
+    catch(const Hydra::Core::Endpoint::V1::InvalidEndpointId& ex)
+    {
+        BOOST_CHECK(ex.badId->endpointManagerId.size() == 0 && ex.badId->deviceId.size() == 0);
+    }
+    catch(...)
+    {
+        adapter->destroy();
+        throw;
+    }
+    adapter->destroy();
+}
+
+BOOST_AUTO_TEST_CASE(BridgeOperationsAfterShutdown)
+{
+    Ice::InitializationData initData;
+    initData.properties = Ice::createProperties(0);
+    initData.properties->setProperty("TestBridging.Endpoints", "default -p 33333 -t 1000");
+    Ice::CommunicatorPtr comm = Ice::initialize(initData);
+    Ice::ObjectAdapterPtr adapter = comm->createObjectAdapter("TestBridging");
+    Ice::Current dummy;
+    dummy.adapter = adapter;
+    dummy.id = comm->stringToIdentity("testobject");
+    try
+    {
+        Hydra::Session::V1::SessionEndpointSeq eps;
+        Hydra::BridgeService::BridgeImplPtr bridge(new Hydra::BridgeService::BridgeImpl(0, eps, 0));
+        bridge->shutdown(dummy);
+        //
+        // Calling shutdown while in the process of shutting down is permitted but is a no-op.
+        //
+        bridge->shutdown(dummy);
+        BOOST_CHECK("Calling shutdown while in the process of shutting down" != 0);
+        try
+        {
+            bridge->listEndpoints(dummy);
+            BOOST_CHECK("should not have succeeded." == 0);
+        }
+        catch(const Hydra::System::Component::V1::ShuttingDown&)
+        {
+        }
+        try
+        {
+            Hydra::Session::V1::SessionEndpointPtr p(new Hydra::Session::V1::SessionEndpoint);
+            p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+            p->id->endpointManagerId = "foo";
+            p->id->deviceId = "bar";
+            bridge->addEndpoint(p, dummy);
+            BOOST_CHECK("should not have succeeded." == 0);
+        }
+        catch(const Hydra::System::Component::V1::ShuttingDown&)
+        {
+        }
+        try
+        {
+            Hydra::Session::V1::SessionEndpointPtr p(new Hydra::Session::V1::SessionEndpoint);
+            p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+            p->id->endpointManagerId = "foo";
+            p->id->deviceId = "bar";
+            bridge->removeEndpoint(p->id, dummy);
+            BOOST_CHECK("should not have succeeded." == 0);
+        }
+        catch(const Hydra::System::Component::V1::ShuttingDown&)
+        {
+        }
+        try
+        {
+            bridge->destroy(dummy);
+            BOOST_CHECK("should not have succeeded." == 0);
+        }
+        catch(const Hydra::System::Component::V1::ShuttingDown&)
+        {
+        }
+        try
+        {
+            Hydra::Core::Endpoint::V1::BaseEndpointPtr p(new Hydra::Core::Endpoint::V1::BaseEndpoint);
+            p->id = new Hydra::Core::Endpoint::V1::EndpointId;
+            p->id->endpointManagerId = "foo";
+            p->id->deviceId = "bar";
+            bridge->addEndpoint(p, dummy);
+            BOOST_CHECK("should not have succeeded." == 0);
+        }
+        catch(const Hydra::Core::Bridging::V1::UnsupportedEndpoint&)
+        {
+            BOOST_CHECK("this occurs fo the time being" != 0);
+        }
+        catch(const Hydra::System::Component::V1::ShuttingDown&)
+        {
+            BOOST_CHECK("but this might happen in the future" != 0);
+        }
+        try
+        {
+            Hydra::Core::Endpoint::V1::BaseEndpointPtr p(new Hydra::Core::Endpoint::V1::BaseEndpoint);
+            bridge->addEndpoint(p, dummy);
+            BOOST_CHECK("should not have succeeded." == 0);
+        }
+        catch(const Hydra::Core::Endpoint::V1::InvalidEndpointId&)
+        {
+            BOOST_CHECK("this occurs fo the time being" != 0);
+        }
+        catch(const Hydra::System::Component::V1::ShuttingDown&)
+        {
+            BOOST_CHECK("but this might happen in the future" != 0);
+        }
+    }
+    catch(...)
+    {
+        adapter->destroy();
+        throw;
+    }
+    adapter->destroy();
+}

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


-- 
hydra/bridging.git




More information about the asterisk-scf-commits mailing list