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

Commits to the Hydra project code repositories hydra-commits at lists.digium.com
Thu Jul 22 11:49:42 CDT 2010


branch "master" has been updated
       via  ea817113d8c5055b485173ba55c59de56a3d2419 (commit)
      from  a3e3a05f27c51f539029895232762f88ab1e7c47 (commit)

Summary of changes:
 test/TestServiceDiscovery.cpp |  299 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 288 insertions(+), 11 deletions(-)


- Log -----------------------------------------------------------------
commit ea817113d8c5055b485173ba55c59de56a3d2419
Author: Joshua Colp <jcolp at digium.com>
Date:   Thu Jul 22 13:50:20 2010 -0300

    Finish up some more tests. They actually all currently pass, but I have some more I want to add that exercise the locateAll method.

diff --git a/test/TestServiceDiscovery.cpp b/test/TestServiceDiscovery.cpp
index 013ccb0..30b61ed 100644
--- a/test/TestServiceDiscovery.cpp
+++ b/test/TestServiceDiscovery.cpp
@@ -38,8 +38,11 @@ static ArgCacheType mCachedArgs;
 struct SharedTestData
 {
 public:
-	/* Communicator for stuff */
-	Ice::CommunicatorPtr communicator;
+	/* Communicator for outgoing stuff */
+	Ice::CommunicatorPtr communicator_outgoing;
+
+	/* Communicator for incoming stuff */
+	Ice::CommunicatorPtr communicator_incoming;
 
 	/* Actual object adapter used for our compare service */
 	Ice::ObjectAdapterPtr adapter;
@@ -53,8 +56,11 @@ public:
 	/* A proxy to our own compare service, registered as both a compare service and as a regular service */
 	ServiceDiscoveryParamsComparePrx compare;
 
-	/* A proxy to the service specific management interface */
+	/* A proxy to the service specific management interface that was registered without using itself */
 	ServiceManagementPrx compare_management;
+
+	/* A proxy we received from service discovery for our own compare service */
+	ServiceDiscoveryParamsComparePrx found_compare;
 };
 static SharedTestData Testbed;
 
@@ -74,21 +80,25 @@ struct GlobalIceFixture
 			int status = 0;
 			try
 				{
-					Testbed.communicator = Ice::initialize(mCachedArgs.argc, mCachedArgs.argv);
+					Testbed.communicator_incoming = Ice::initialize(mCachedArgs.argc, mCachedArgs.argv);
 
-					Testbed.adapter = Testbed.communicator->createObjectAdapterWithEndpoints("CompareServiceAdapter", "default");
+					Testbed.adapter = Testbed.communicator_incoming->createObjectAdapterWithEndpoints("CompareServiceAdapter", "default");
 
 					ServiceDiscoveryParamsComparePtr CompareService = new TestCompareServiceImpl();
 
 					Testbed.compare = ServiceDiscoveryParamsComparePrx::uncheckedCast(Testbed.adapter->addWithUUID(CompareService));
 
-					Testbed.management = ServiceDiscoveryManagementPrx::checkedCast(Testbed.communicator->stringToProxy("DiscoveryServiceManagement:tcp -p 5674"));
+					Testbed.adapter->activate();
+
+					Testbed.communicator_outgoing = Ice::initialize(mCachedArgs.argc, mCachedArgs.argv);
+
+					Testbed.management = ServiceDiscoveryManagementPrx::checkedCast(Testbed.communicator_outgoing->stringToProxy("DiscoveryServiceManagement:tcp -p 5674"));
 
 					if (!Testbed.management) {
 						throw "Invalid service discovery management proxy";
 					}
 
-					Testbed.discovery = ServiceDiscoveryPrx::checkedCast(Testbed.communicator->stringToProxy("DiscoveryService:tcp -p 2657"));
+					Testbed.discovery = ServiceDiscoveryPrx::checkedCast(Testbed.communicator_outgoing->stringToProxy("DiscoveryService:tcp -p 2657"));
 
 					if (!Testbed.discovery) {
 						throw "Invalid service discovery proxy";
@@ -112,9 +122,13 @@ struct GlobalIceFixture
 			BOOST_TEST_MESSAGE("Tearing down service discovery test fixture");
 
 
-			if (Testbed.communicator) {
-				Testbed.communicator->shutdown();
-				Testbed.communicator = 0;
+			if (Testbed.communicator_incoming) {
+				Testbed.communicator_incoming->shutdown();
+				Testbed.communicator_incoming = 0;
+			}
+			if (Testbed.communicator_outgoing) {
+				Testbed.communicator_outgoing->shutdown();
+				Testbed.communicator_outgoing = 0;
 			}
 		}
 private:
@@ -291,7 +305,7 @@ BOOST_AUTO_TEST_CASE(FindServiceWithoutCompareService)
 		ServiceDiscoveryParamsPtr params = new ServiceDiscoveryParams;
 		params->category = "test";
 
-		Ice::ObjectPrx service = Testbed.discovery->locate(params);
+		Testbed.found_compare = ServiceDiscoveryParamsComparePrx::uncheckedCast(Testbed.discovery->locate(params));
 
 		found = true;
 	} catch (const ServiceNotFound&) {
@@ -305,10 +319,53 @@ BOOST_AUTO_TEST_CASE(FindServiceWithoutCompareService)
 }
 
 /**
+ * Confirm that we can find a service using locateAll after we add discovery params that do not use a compare service.
+ */
+BOOST_AUTO_TEST_CASE(FindServicesWithoutCompareService)
+{
+	bool found = false;
+
+	try {
+		ServiceDiscoveryParamsPtr params = new ServiceDiscoveryParams;
+		params->category = "test";
+
+		Ice::ObjectProxySeq services = Testbed.discovery->locateAll(params);
+
+		/* It's possible for some implementation to lie and give us an empty sequence, so check for that
+		 * possibility. They should have raised an exception.
+		 */
+		if (!services.empty()) {
+			found = true;
+		}
+	} catch (const ServiceNotFound&) {
+	} catch (const Ice::Exception &e) {
+		BOOST_TEST_MESSAGE(e.ice_name());
+		BOOST_TEST_MESSAGE(e.what());
+	} catch (...) {
+	}
+
+	BOOST_CHECK(found);
+}
+
+/**
  * Confirm that the service we got back is usable.
  */
 BOOST_AUTO_TEST_CASE(UseServiceFoundWithoutCompareService)
 {
+	bool usable = false;
+
+	try {
+		/* We can do a comparison of the proxy against local to confirm it's proper so we don't have to call back into ourselves */
+		if (Testbed.found_compare == Testbed.compare) {
+			usable = true;
+		}
+	} catch (const Ice::Exception &e) {
+		BOOST_TEST_MESSAGE(e.ice_name());
+		BOOST_TEST_MESSAGE(e.what());
+	} catch (...) {
+	}
+
+	BOOST_CHECK(usable);
 }
 
 /**
@@ -316,6 +373,20 @@ BOOST_AUTO_TEST_CASE(UseServiceFoundWithoutCompareService)
  */
 BOOST_AUTO_TEST_CASE(AddCompare)
 {
+	bool added = false;
+
+	try {
+		Testbed.management->addCompare("testcompare", Testbed.compare);
+
+		added = true;
+	} catch (const DuplicateCompare&) {
+	} catch (Ice::Exception &e) {
+		BOOST_TEST_MESSAGE(e.ice_name());
+		BOOST_TEST_MESSAGE(e.what());
+	} catch (...) {
+	}
+
+	BOOST_CHECK(added);
 }
 
 /**
@@ -323,6 +394,20 @@ BOOST_AUTO_TEST_CASE(AddCompare)
  */
 BOOST_AUTO_TEST_CASE(AddDuplicateCompare)
 {
+	bool added = false;
+
+	try {
+		Testbed.management->addCompare("testcompare", Testbed.compare);
+
+		added = true;
+	} catch (const DuplicateCompare&) {
+	} catch (Ice::Exception &e) {
+		BOOST_TEST_MESSAGE(e.ice_name());
+		BOOST_TEST_MESSAGE(e.what());
+	} catch (...) {
+	}
+
+	BOOST_CHECK(!added);
 }
 
 /**
@@ -330,6 +415,22 @@ BOOST_AUTO_TEST_CASE(AddDuplicateCompare)
  */
 BOOST_AUTO_TEST_CASE(AddDiscoveryParamsWithCompareService)
 {
+	bool added = false;
+
+	try {
+		ServiceDiscoveryParamsPtr params = new ServiceDiscoveryParams;
+		params->category = "test2";
+
+		Testbed.compare_management->addDiscoveryParams(params, "testcompare");
+
+		added = true;
+	} catch (const Ice::Exception &e) {
+		BOOST_TEST_MESSAGE(e.ice_name());
+		BOOST_TEST_MESSAGE(e.what());
+	} catch (...) {
+	}
+
+	BOOST_CHECK(added);
 }
 
 /**
@@ -337,6 +438,23 @@ BOOST_AUTO_TEST_CASE(AddDiscoveryParamsWithCompareService)
  */
 BOOST_AUTO_TEST_CASE(FindServiceWithCompareService)
 {
+	bool found = false;
+
+	try {
+		ServiceDiscoveryParamsPtr params = new ServiceDiscoveryParams;
+		params->category = "test2";
+
+		Testbed.found_compare = ServiceDiscoveryParamsComparePrx::uncheckedCast(Testbed.discovery->locate(params));
+
+		found = true;
+	} catch (const ServiceNotFound&) {
+	} catch (const Ice::Exception &e) {
+		BOOST_TEST_MESSAGE(e.ice_name());
+		BOOST_TEST_MESSAGE(e.what());
+	} catch (...) {
+	}
+
+	BOOST_CHECK(found);
 }
 
 /**
@@ -344,6 +462,19 @@ BOOST_AUTO_TEST_CASE(FindServiceWithCompareService)
  */
 BOOST_AUTO_TEST_CASE(UseServiceFoundWithCompareService)
 {
+	bool usable = false;
+
+	try {
+		if (Testbed.found_compare == Testbed.compare) {
+			usable = true;
+		}
+	} catch (const Ice::Exception &e) {
+		BOOST_TEST_MESSAGE(e.ice_name());
+		BOOST_TEST_MESSAGE(e.what());
+	} catch (...) {
+	}
+
+	BOOST_CHECK(usable);
 }
 
 /**
@@ -351,6 +482,19 @@ BOOST_AUTO_TEST_CASE(UseServiceFoundWithCompareService)
  */
 BOOST_AUTO_TEST_CASE(ServiceSuspend)
 {
+	bool suspended = false;
+
+	try {
+		Testbed.compare_management->suspend();
+
+		suspended = true;
+	} catch (const Ice::Exception &e) {
+		BOOST_TEST_MESSAGE(e.ice_name());
+		BOOST_TEST_MESSAGE(e.what());
+	} catch (...) {
+	}
+
+	BOOST_CHECK(suspended);
 }
 
 /**
@@ -358,6 +502,23 @@ BOOST_AUTO_TEST_CASE(ServiceSuspend)
  */
 BOOST_AUTO_TEST_CASE(FindServiceAfterSuspend)
 {
+	bool found = false;
+
+	try {
+		ServiceDiscoveryParamsPtr params = new ServiceDiscoveryParams;
+		params->category = "test";
+
+		Testbed.found_compare = ServiceDiscoveryParamsComparePrx::uncheckedCast(Testbed.discovery->locate(params));
+
+		found = true;
+	} catch (const ServiceNotFound&) {
+	} catch (const Ice::Exception &e) {
+		BOOST_TEST_MESSAGE(e.ice_name());
+		BOOST_TEST_MESSAGE(e.what());
+	} catch (...) {
+	}
+
+	BOOST_CHECK(!found);
 }
 
 /**
@@ -365,6 +526,19 @@ BOOST_AUTO_TEST_CASE(FindServiceAfterSuspend)
  */
 BOOST_AUTO_TEST_CASE(ServiceUnsuspend)
 {
+	bool unsuspended = false;
+
+	try {
+		Testbed.compare_management->unsuspend();
+
+		unsuspended = true;
+	} catch (const Ice::Exception &e) {
+		BOOST_TEST_MESSAGE(e.ice_name());
+		BOOST_TEST_MESSAGE(e.what());
+	} catch (...) {
+	}
+
+	BOOST_CHECK(unsuspended);
 }
 
 /**
@@ -372,6 +546,23 @@ BOOST_AUTO_TEST_CASE(ServiceUnsuspend)
  */
 BOOST_AUTO_TEST_CASE(FindServiceAfterUnsuspend)
 {
+	bool found = false;
+
+	try {
+		ServiceDiscoveryParamsPtr params = new ServiceDiscoveryParams;
+		params->category = "test";
+
+		Testbed.found_compare = ServiceDiscoveryParamsComparePrx::uncheckedCast(Testbed.discovery->locate(params));
+
+		found = true;
+	} catch (const ServiceNotFound&) {
+	} catch (const Ice::Exception &e) {
+		BOOST_TEST_MESSAGE(e.ice_name());
+		BOOST_TEST_MESSAGE(e.what());
+	} catch (...) {
+	}
+
+	BOOST_CHECK(found);
 }
 
 /**
@@ -379,6 +570,19 @@ BOOST_AUTO_TEST_CASE(FindServiceAfterUnsuspend)
  */
 BOOST_AUTO_TEST_CASE(RemoveNonexistentCompareService)
 {
+	bool removed = false;
+
+	try {
+		Testbed.management->removeCompare("testcompare2");
+		removed = true;
+	} catch (const CompareNotFound&) {
+	} catch (const Ice::Exception &e) {
+		BOOST_TEST_MESSAGE(e.ice_name());
+		BOOST_TEST_MESSAGE(e.what());
+	} catch (...) {
+	}
+
+	BOOST_CHECK(!removed);
 }
 
 /**
@@ -386,6 +590,19 @@ BOOST_AUTO_TEST_CASE(RemoveNonexistentCompareService)
  */
 BOOST_AUTO_TEST_CASE(RemoveCompareService)
 {
+	bool removed = false;
+
+	try {
+		Testbed.management->removeCompare("testcompare");
+		removed = true;
+	} catch (const CompareNotFound&) {
+	} catch (const Ice::Exception &e) {
+		BOOST_TEST_MESSAGE(e.ice_name());
+		BOOST_TEST_MESSAGE(e.what());
+	} catch (...) {
+	}
+
+	BOOST_CHECK(removed);
 }
 
 /**
@@ -393,6 +610,19 @@ BOOST_AUTO_TEST_CASE(RemoveCompareService)
  */
 BOOST_AUTO_TEST_CASE(RemoveAlreadyRemovedCompareService)
 {
+	bool removed = false;
+
+	try {
+		Testbed.management->removeCompare("testcompare");
+		removed = true;
+	} catch (const CompareNotFound&) {
+	} catch (const Ice::Exception &e) {
+		BOOST_TEST_MESSAGE(e.ice_name());
+		BOOST_TEST_MESSAGE(e.what());
+	} catch (...) {
+	}
+
+	BOOST_CHECK(!removed);
 }
 
 /**
@@ -400,6 +630,23 @@ BOOST_AUTO_TEST_CASE(RemoveAlreadyRemovedCompareService)
  */
 BOOST_AUTO_TEST_CASE(FindServiceAfterCompareServiceRemoved)
 {
+	bool found = false;
+
+	try {
+		ServiceDiscoveryParamsPtr params = new ServiceDiscoveryParams;
+		params->category = "test2";
+
+		Testbed.found_compare = ServiceDiscoveryParamsComparePrx::uncheckedCast(Testbed.discovery->locate(params));
+
+		found = true;
+	} catch (const ServiceNotFound&) {
+	} catch (const Ice::Exception &e) {
+		BOOST_TEST_MESSAGE(e.ice_name());
+		BOOST_TEST_MESSAGE(e.what());
+	} catch (...) {
+	}
+
+	BOOST_CHECK(!found);
 }
 
 /**
@@ -407,6 +654,19 @@ BOOST_AUTO_TEST_CASE(FindServiceAfterCompareServiceRemoved)
  */
 BOOST_AUTO_TEST_CASE(ServiceUnregister)
 {
+	bool unregistered = false;
+
+	try {
+		Testbed.compare_management->unregister();
+
+		unregistered = true;
+	} catch (const Ice::Exception &e) {
+		BOOST_TEST_MESSAGE(e.ice_name());
+		BOOST_TEST_MESSAGE(e.what());
+	} catch (...) {
+	}
+
+	BOOST_CHECK(unregistered);
 }
 
 /**
@@ -414,4 +674,21 @@ BOOST_AUTO_TEST_CASE(ServiceUnregister)
  */
 BOOST_AUTO_TEST_CASE(FindServiceAfterUnregister)
 {
+	bool found = false;
+
+	try {
+		ServiceDiscoveryParamsPtr params = new ServiceDiscoveryParams;
+		params->category = "test";
+
+		Testbed.found_compare = ServiceDiscoveryParamsComparePrx::uncheckedCast(Testbed.discovery->locate(params));
+
+		found = true;
+	} catch (const ServiceNotFound&) {
+	} catch (const Ice::Exception &e) {
+		BOOST_TEST_MESSAGE(e.ice_name());
+		BOOST_TEST_MESSAGE(e.what());
+	} catch (...) {
+	}
+
+	BOOST_CHECK(!found);
 }

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


-- 
hydra/servicediscovery.git




More information about the asterisk-scf-commits mailing list