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

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


branch "master" has been updated
       via  222043ce497a3bbb7521f25643dc6bda5e150bd8 (commit)
       via  729d90ad84839b7a2113d07b9d1b60de57ea76b7 (commit)
      from  ea817113d8c5055b485173ba55c59de56a3d2419 (commit)

Summary of changes:
 test/TestServiceDiscovery.cpp |  255 +++++++++++++----------------------------
 1 files changed, 80 insertions(+), 175 deletions(-)


- Log -----------------------------------------------------------------
commit 222043ce497a3bbb7521f25643dc6bda5e150bd8
Author: Joshua Colp <jcolp at digium.com>
Date:   Thu Jul 22 15:48:16 2010 -0300

    Reduce some code duplication by providing two functions that handle locate and locateAll.

diff --git a/test/TestServiceDiscovery.cpp b/test/TestServiceDiscovery.cpp
index 170096f..70798b4 100644
--- a/test/TestServiceDiscovery.cpp
+++ b/test/TestServiceDiscovery.cpp
@@ -61,6 +61,55 @@ public:
 
 	/* A proxy we received from service discovery for our own compare service */
 	ServiceDiscoveryParamsComparePrx found_compare;
+
+	/* Common implementation for locating a service */
+	bool FindService(string category) {
+		bool found = true;
+
+		try {
+			/* Setup our parameters, for now we are simply using test as the category */
+			ServiceDiscoveryParamsPtr params = new ServiceDiscoveryParams;
+			params->category = category;
+
+			/* Actually do the locate request */
+			found_compare = ServiceDiscoveryParamsComparePrx::uncheckedCast(discovery->locate(params));
+
+			/* If we get here we didn't get an exception back telling us no service found... which is wrong! */
+		} catch (const ServiceNotFound&) {
+			found = false;
+		} catch (const Ice::Exception &e) {
+			BOOST_TEST_MESSAGE(e.ice_name());
+			BOOST_TEST_MESSAGE(e.what());
+			found = false;
+		}
+
+		return found;
+	}
+
+	/* Common implementation for finding multiple services */
+	bool FindServices(string category, unsigned int expected_num_of_results) {
+		bool found = true;
+
+		try {
+			ServiceDiscoveryParamsPtr params = new ServiceDiscoveryParams;
+			params->category = category;
+
+			Ice::ObjectProxySeq services = discovery->locateAll(params);
+
+			if (services.size() != expected_num_of_results) {
+				found = false;
+			}
+		} catch (const ServiceNotFound&) {
+			found = false;
+		} catch (const Ice::Exception &e) {
+			BOOST_TEST_MESSAGE(e.ice_name());
+			BOOST_TEST_MESSAGE(e.what());
+			found = false;
+		} catch (...) {
+		}
+
+		return found;
+	}
 };
 static SharedTestData Testbed;
 
@@ -153,25 +202,7 @@ int BOOST_TEST_CALL_DECL main( int argc, char* argv[] )
  */
 BOOST_AUTO_TEST_CASE(ServiceNotFoundBeforeAdd)
 {
-	/* Assume the worst until proven otherwise */
-	bool found = true;
-
-	try {
-		/* Setup our parameters, for now we are simply using test as the category */
-		ServiceDiscoveryParamsPtr params = new ServiceDiscoveryParams;
-		params->category = "test";
-
-		/* Actually do the locate request */
-		Ice::ObjectPrx service = Testbed.discovery->locate(params);
-
-		/* If we get here we didn't get an exception back telling us no service found... which is wrong! */
-	} catch (const ServiceNotFound&) {
-		found = false;
-	} catch (const Ice::Exception &e) {
-		BOOST_TEST_MESSAGE(e.ice_name());
-		BOOST_TEST_MESSAGE(e.what());
-		found = false;
-	}
+	bool found = Testbed.FindService("test");
 
 	BOOST_CHECK(!found);
 }
@@ -181,21 +212,7 @@ BOOST_AUTO_TEST_CASE(ServiceNotFoundBeforeAdd)
  */
 BOOST_AUTO_TEST_CASE(ServicesNotFoundBeforeAdd)
 {
-	bool found = true;
-
-	try {
-		ServiceDiscoveryParamsPtr params = new ServiceDiscoveryParams;
-		params->category = "test";
-
-		Ice::ObjectProxySeq services = Testbed.discovery->locateAll(params);
-	} catch (const ServiceNotFound&) {
-		found = false;
-	} catch (const Ice::Exception &e) {
-		BOOST_TEST_MESSAGE(e.ice_name());
-		BOOST_TEST_MESSAGE(e.what());
-		found = false;
-	} catch (...) {
-	}
+	bool found = Testbed.FindServices("test", 1);
 
 	BOOST_CHECK(!found);
 }
@@ -228,21 +245,7 @@ BOOST_AUTO_TEST_CASE(AddService)
  */
 BOOST_AUTO_TEST_CASE(ServiceNotFoundAfterAdd)
 {
-	bool found = true;
-
-	try {
-		ServiceDiscoveryParamsPtr params = new ServiceDiscoveryParams;
-		params->category = "test";
-
-		Ice::ObjectPrx service = Testbed.discovery->locate(params);
-	} catch (const ServiceNotFound&) {
-		found = false;
-	} catch (const Ice::Exception &e) {
-		BOOST_TEST_MESSAGE(e.ice_name());
-		BOOST_TEST_MESSAGE(e.what());
-		found = false;
-	} catch (...) {
-	}
+	bool found = Testbed.FindService("test");
 
 	BOOST_CHECK(!found);
 }
@@ -252,21 +255,7 @@ BOOST_AUTO_TEST_CASE(ServiceNotFoundAfterAdd)
  */
 BOOST_AUTO_TEST_CASE(ServicesNotFoundAfterAdd)
 {
-	bool found = true;
-
-	try {
-		ServiceDiscoveryParamsPtr params = new ServiceDiscoveryParams;
-		params->category = "test";
-
-		Ice::ObjectProxySeq services = Testbed.discovery->locateAll(params);
-	} catch (const ServiceNotFound&) {
-		found = false;
-	} catch (const Ice::Exception &e) {
-		BOOST_TEST_MESSAGE(e.ice_name());
-		BOOST_TEST_MESSAGE(e.what());
-		found = false;
-	} catch (...) {
-	}
+	bool found = Testbed.FindServices("test", 0);
 
 	BOOST_CHECK(!found);
 }
@@ -299,21 +288,7 @@ BOOST_AUTO_TEST_CASE(AddDiscoveryParamsWithoutCompareService)
  */
 BOOST_AUTO_TEST_CASE(FindServiceWithoutCompareService)
 {
-	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 (...) {
-	}
+	bool found = Testbed.FindService("test");
 
 	BOOST_CHECK(found);
 }
@@ -323,26 +298,7 @@ BOOST_AUTO_TEST_CASE(FindServiceWithoutCompareService)
  */
 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 (...) {
-	}
+	bool found = Testbed.FindServices("test", 1);
 
 	BOOST_CHECK(found);
 }
@@ -438,21 +394,7 @@ 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 (...) {
-	}
+	bool found = Testbed.FindService("test2");
 
 	BOOST_CHECK(found);
 }
@@ -482,7 +424,6 @@ BOOST_AUTO_TEST_CASE(UseServiceFoundWithCompareService)
  */
 BOOST_AUTO_TEST_CASE(FindMultipleServices)
 {
-	bool found = false;
 	ServiceDiscoveryParamsPtr params = new ServiceDiscoveryParams;
 	ServiceManagementPrx compare_management = Testbed.management->addService(Testbed.compare, "testcompare2");
 
@@ -490,19 +431,7 @@ BOOST_AUTO_TEST_CASE(FindMultipleServices)
 
 	compare_management->addDiscoveryParams(params, "");
 
-	try {
-		Ice::ObjectProxySeq services = Testbed.discovery->locateAll(params);
-
-		/* We previously added a service and now we just added another, so we fully expect to find exactly two services */
-		if (services.size() == 2) {
-			found = true;
-		}
-	} catch (const ServiceNotFound&) {
-	} catch (const Ice::Exception &e) {
-		BOOST_TEST_MESSAGE(e.ice_name());
-		BOOST_TEST_MESSAGE(e.what());
-	} catch (...) {
-	}
+	bool found = Testbed.FindServices("test", 2);
 
 	compare_management->unregister();
 
@@ -534,21 +463,7 @@ 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 (...) {
-	}
+	bool found = Testbed.FindService("test");
 
 	BOOST_CHECK(!found);
 }
@@ -578,21 +493,7 @@ 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 (...) {
-	}
+	bool found = Testbed.FindService("test");
 
 	BOOST_CHECK(found);
 }
@@ -662,21 +563,7 @@ 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 (...) {
-	}
+	bool found = Testbed.FindService("test2");
 
 	BOOST_CHECK(!found);
 }
@@ -706,21 +593,7 @@ 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 (...) {
-	}
+	bool found = Testbed.FindService("test");
 
 	BOOST_CHECK(!found);
 }

commit 729d90ad84839b7a2113d07b9d1b60de57ea76b7
Author: Joshua Colp <jcolp at digium.com>
Date:   Thu Jul 22 14:06:36 2010 -0300

    Clarify a comment and add a test which confirms that locateAll returns multiple results.

diff --git a/test/TestServiceDiscovery.cpp b/test/TestServiceDiscovery.cpp
index 30b61ed..170096f 100644
--- a/test/TestServiceDiscovery.cpp
+++ b/test/TestServiceDiscovery.cpp
@@ -56,7 +56,7 @@ 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 that was registered without using itself */
+	/* A proxy to the service specific management interface for our compare service we registered */
 	ServiceManagementPrx compare_management;
 
 	/* A proxy we received from service discovery for our own compare service */
@@ -478,6 +478,38 @@ BOOST_AUTO_TEST_CASE(UseServiceFoundWithCompareService)
 }
 
 /**
+ * Confirm that we get multiple services when we ask for them
+ */
+BOOST_AUTO_TEST_CASE(FindMultipleServices)
+{
+	bool found = false;
+	ServiceDiscoveryParamsPtr params = new ServiceDiscoveryParams;
+	ServiceManagementPrx compare_management = Testbed.management->addService(Testbed.compare, "testcompare2");
+
+	params->category = "test";
+
+	compare_management->addDiscoveryParams(params, "");
+
+	try {
+		Ice::ObjectProxySeq services = Testbed.discovery->locateAll(params);
+
+		/* We previously added a service and now we just added another, so we fully expect to find exactly two services */
+		if (services.size() == 2) {
+			found = true;
+		}
+	} catch (const ServiceNotFound&) {
+	} catch (const Ice::Exception &e) {
+		BOOST_TEST_MESSAGE(e.ice_name());
+		BOOST_TEST_MESSAGE(e.what());
+	} catch (...) {
+	}
+
+	compare_management->unregister();
+
+	BOOST_CHECK(found);
+}
+
+/**
  * Confirm that we can suspend a service.
  */
 BOOST_AUTO_TEST_CASE(ServiceSuspend)

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


-- 
hydra/servicediscovery.git




More information about the asterisk-scf-commits mailing list