[asterisk-scf-commits] asterisk-scf/integration/servicediscovery.git branch "icebox" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Tue Sep 28 14:43:16 CDT 2010
branch "icebox" has been created
at 69e4dc18e2a2664848e1bfb9b0ee68ec0dacd46e (commit)
- Log -----------------------------------------------------------------
commit 69e4dc18e2a2664848e1bfb9b0ee68ec0dacd46e
Author: David M. Lee <dlee at digium.com>
Date: Mon Sep 27 16:51:37 2010 -0500
Running unit tests in icebox.
diff --git a/config/test_component.config b/config/test_component.config
index 2e4e63d..1d7e6ba 100644
--- a/config/test_component.config
+++ b/config/test_component.config
@@ -33,7 +33,6 @@ IceStorm.Flush.Timeout=2000
#
# ServiceDiscovery configuration
#
-
IceBox.Service.ServiceDiscovery=service_locator:create --Ice.Config=config/test_component.config
# Test endpoints for the service locator management adapter
@@ -45,3 +44,10 @@ ServiceLocatorAdapter.Endpoints=tcp -p 4411
# Test endpoints for IceStorm
TopicManager.Proxy=HydraIceStorm/TopicManager:default -p 10000
+#
+# test configuration
+#
+IceBox.Service.ServiceDiscoveryTest=service_locator_test:create --Ice.Config=config/test_component.config --report_sink=${CMAKE_BINARY_DIR}/service_locator_test-result.xml --report_format=XML --report_level=detailed
+
+LocatorService.Proxy=LocatorService:tcp -p 4411
+ServiceLocatorManagement.proxy=ServiceLocatorManagement:tcp -p 4422
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 7038c2d..6173dde 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -13,5 +13,12 @@ hydra_component_add_slice(service_locator_test ServiceLocatorEventsIf)
hydra_component_add_file(service_locator_test TestServiceLocator.cpp)
hydra_component_add_ice_libraries(service_locator_test IceStorm)
hydra_component_add_boost_libraries(service_locator_test unit_test_framework)
-hydra_component_build_standalone(service_locator_test)
-hydra_component_install(service_locator_test RUNTIME bin "Service Locator Test Driver." Core)
+hydra_component_build_icebox(service_locator_test)
+#hydra_component_install(service_locator_test RUNTIME bin "Service Locator Test Driver." Core)
+
+icebox_add_test(service_locator_test config/test_component.config)
+
+file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/IceStorm)
+
+# Copy our test config file to make it available in the test directory.
+configure_file(../config/test_component.config ${CMAKE_CURRENT_BINARY_DIR}/config/test_component.config)
diff --git a/test/TestServiceLocator.cpp b/test/TestServiceLocator.cpp
index 6f6bffc..e37fea4 100644
--- a/test/TestServiceLocator.cpp
+++ b/test/TestServiceLocator.cpp
@@ -14,6 +14,7 @@
#include <boost/test/debug.hpp>
#include <Ice/Ice.h>
+#include <IceBox/IceBox.h>
#include "Core/Discovery/ServiceLocatorIf.h"
#include "Core/Discovery/ServiceLocatorEventsIf.h"
@@ -21,6 +22,18 @@
using namespace std;
using namespace AsteriskSCF::Core::Discovery::V1;
+/**
+ * Test service, for loading into icebox
+ */
+class ServiceLocatorTest : public IceBox::Service
+{
+public:
+ void start(const std::string&,
+ const Ice::CommunicatorPtr&,
+ const Ice::StringSeq&);
+ void stop();
+};
+
/* A basic compare service implementation that always returns true, this is registered as both a compare service
* and a regular service during testing.
*/
@@ -196,18 +209,6 @@ private:
BOOST_GLOBAL_FIXTURE(GlobalIceFixture);
/**
- * Implement our own main to intercept the command line args.
- * (A default main() is provided if we hadn't set BOOST_TEST_NO_MAIN at the top of file.)
- * NOTE: Pass in --log_level=message to see the debug print statements.
- */
-int BOOST_TEST_CALL_DECL main( int argc, char* argv[] )
-{
- mCachedArgs.argc = argc;
- mCachedArgs.argv = argv;
- return ::boost::unit_test::unit_test_main( &init_unit_test, argc, argv );
-}
-
-/**
* Confirm that we find no service using locate before we have added one.
*/
BOOST_AUTO_TEST_CASE(ServiceNotFoundBeforeAdd)
@@ -631,3 +632,37 @@ BOOST_AUTO_TEST_CASE(FindServiceAfterUnregister)
BOOST_CHECK(!found);
}
+
+void ServiceLocatorTest::start(std::string const &name,
+ Ice::CommunicatorPtr const &communicator,
+ Ice::StringSeq const &args)
+{
+ std::vector<char const *> argv;
+ argv.push_back(name.c_str());
+ for (Ice::StringSeq::const_iterator i = args.begin();
+ i != args.end();
+ ++i)
+ {
+ argv.push_back(i->c_str());
+ }
+ // null terminated list
+ argv.push_back(0);
+
+ mCachedArgs.argc = argv.size() - 1;
+ mCachedArgs.argv = (char**)&argv[0];
+
+ int r = ::boost::unit_test::unit_test_main(&init_unit_test, mCachedArgs.argc, mCachedArgs.argv);
+ exit(r);
+}
+
+void ServiceLocatorTest::stop()
+{
+}
+
+extern "C"
+{
+ IceBox::Service* create(Ice::CommunicatorPtr communicator)
+ {
+ return new ServiceLocatorTest;
+ }
+}
commit b9c6c2ab587a65c2607d3303951400ed9e3b255c
Author: David M. Lee <dlee at digium.com>
Date: Mon Sep 27 15:09:34 2010 -0500
Building servicedicovery as an icebox component.
diff --git a/config/test_component.config b/config/test_component.config
new file mode 100644
index 0000000..2e4e63d
--- /dev/null
+++ b/config/test_component.config
@@ -0,0 +1,47 @@
+# This is a configuration file used in conjunction with the service discovery test driver
+
+IceBox.Service.IceStorm=IceStormService,34:createIceStorm --Ice.Config=config/test_component.config
+
+IceStorm.InstanceName=HydraIceStorm
+
+#
+# This property defines the endpoints on which the IceStorm
+# TopicManager listens.
+#
+IceStorm.TopicManager.Endpoints=default -p 10000
+
+#
+# This property defines the endpoints on which the topic
+# publisher objects listen. If you want to federate
+# IceStorm instances this must run on a fixed port (or use
+# IceGrid).
+#
+IceStorm.Publish.Endpoints=tcp -p 10001:udp -p 10001
+
+#
+# TopicManager Tracing
+#
+# 0 = no tracing
+# 1 = trace topic creation, subscription, unsubscription
+# 2 = like 1, but with more detailed subscription information
+#
+IceStorm.Trace.TopicManager=2
+
+#
+IceStorm.Flush.Timeout=2000
+
+#
+# ServiceDiscovery configuration
+#
+
+IceBox.Service.ServiceDiscovery=service_locator:create --Ice.Config=config/test_component.config
+
+# Test endpoints for the service locator management adapter
+ServiceLocatorManagementAdapter.Endpoints=tcp -p 4422
+
+# Test endpoints for the service locator adapter
+ServiceLocatorAdapter.Endpoints=tcp -p 4411
+
+# Test endpoints for IceStorm
+TopicManager.Proxy=HydraIceStorm/TopicManager:default -p 10000
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f1d74e1..da579bd 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -15,5 +15,5 @@ hydra_component_add_file(service_locator ServiceLocatorManagement.cpp)
hydra_component_add_file(service_locator ServiceManagement.cpp)
hydra_component_add_ice_libraries(service_locator IceStorm)
hydra_component_add_boost_libraries(service_locator core thread)
-hydra_component_build_standalone(service_locator)
-hydra_component_install(service_locator RUNTIME bin "Service Locator." Core)
+hydra_component_build_icebox(service_locator)
+#hydra_component_install(service_locator RUNTIME bin "Service Locator." Core)
diff --git a/src/ServiceLocator.cpp b/src/ServiceLocator.cpp
index 1a7d1b7..f166ad6 100644
--- a/src/ServiceLocator.cpp
+++ b/src/ServiceLocator.cpp
@@ -8,6 +8,7 @@
#include <Ice/Ice.h>
#include <IceStorm/IceStorm.h>
+#include <IceBox/IceBox.h>
#include "Core/Discovery/ServiceLocatorIf.h"
#include "Core/Discovery/ServiceLocatorEventsIf.h"
@@ -22,13 +23,16 @@ using namespace AsteriskSCF::Core::Discovery::V1;
/**
* Implementation of the Ice::Application class
*/
-class ServiceLocatorApp : public Ice::Application
+class ServiceLocatorApp : public IceBox::Service
{
public:
- int run(int, char*[]);
- void interruptCallback(int);
+ void start(const std::string&,
+ const Ice::CommunicatorPtr&,
+ const Ice::StringSeq&);
+ void stop();
private:
+ Ice::ObjectAdapterPtr discovery_adapter;
};
/**
@@ -49,16 +53,6 @@ private:
};
/**
- * Main entry point for our service locator application.
- */
-int main(int argc, char* argv[])
-{
- ServiceLocatorApp app;
- app.callbackOnInterrupt();
- return app.main(argc, argv);
-}
-
-/**
* Implementation of the locate method as defined in service_locator.ice
*/
Ice::ObjectPrx ServiceLocatorImpl::locate(const ServiceLocatorParamsPtr& params, const Ice::Current&)
@@ -76,21 +70,21 @@ Ice::ObjectProxySeq ServiceLocatorImpl::locateAll(const ServiceLocatorParamsPtr&
return mLocatorServiceManagement->locateAll(params);
}
-/**
- * Overload of the Ice::Application::run method.
- */
-int ServiceLocatorApp::run(int argc, char* argv[])
+void ServiceLocatorApp::start(
+ const string& name,
+ const Ice::CommunicatorPtr& communicator,
+ const Ice::StringSeq& args)
{
cout << "[INFO] Initializing service discovery component" << endl;
/* Talk to the topic manager to either create or get the service discovery topic, configured or default */
- IceStorm::TopicManagerPrx topicManager = IceStorm::TopicManagerPrx::checkedCast(communicator()->propertyToProxy("TopicManager.Proxy"));
+ IceStorm::TopicManagerPrx topicManager = IceStorm::TopicManagerPrx::checkedCast(communicator->propertyToProxy("TopicManager.Proxy"));
EventsPrx service_discovery_topic;
if (topicManager)
{
- Ice::PropertiesPtr props = communicator()->getProperties();
+ Ice::PropertiesPtr props = communicator->getProperties();
string topicName = props->getProperty("ServiceLocator.TopicName");
if (topicName.empty())
@@ -112,7 +106,7 @@ int ServiceLocatorApp::run(int argc, char* argv[])
catch (const IceStorm::TopicExists&)
{
cerr << "Oh snap! Race condition creating topic, aborting" << endl;
- return 0;
+ return;
}
cout << "[INFO] Created service discovery event topic" << endl;
}
@@ -127,35 +121,38 @@ int ServiceLocatorApp::run(int argc, char* argv[])
/* Management and discovery use separate adapters to provide a level of security, management may want to be protected so arbitrary
* people can't inject bad services into the infrastructure while discovery as a read only function may be allowed to all.
*/
- Ice::ObjectAdapterPtr management_adapter = communicator()->createObjectAdapter("ServiceLocatorManagementAdapter");
+ Ice::ObjectAdapterPtr management_adapter = communicator->createObjectAdapter("ServiceLocatorManagementAdapter");
ServiceLocatorManagementImpl* LocatorServiceManagement = new ServiceLocatorManagementImpl(management_adapter, service_discovery_topic);
- management_adapter->add(LocatorServiceManagement, communicator()->stringToIdentity("LocatorServiceManagement"));
+ management_adapter->add(LocatorServiceManagement, communicator->stringToIdentity("LocatorServiceManagement"));
management_adapter->activate();
cout << "[INFO] Activated service discovery management." << endl;
- Ice::ObjectAdapterPtr discovery_adapter = communicator()->createObjectAdapter("ServiceLocatorAdapter");
+ discovery_adapter = communicator->createObjectAdapter("ServiceLocatorAdapter");
ServiceLocatorPtr LocatorService = new ServiceLocatorImpl(LocatorServiceManagement);
- discovery_adapter->add(LocatorService, communicator()->stringToIdentity("LocatorService"));
+ discovery_adapter->add(LocatorService, communicator->stringToIdentity("LocatorService"));
discovery_adapter->activate();
cout << "[INFO] Activated service discovery." << endl;
cout << "[INFO] Waiting for requests." << endl;
+}
- /* Now that management and discovery are active we just sit here waiting until we shutdown */
- communicator()->waitForShutdown();
-
- return EXIT_SUCCESS;
+void ServiceLocatorApp::stop()
+{
+ discovery_adapter->deactivate();
}
-void ServiceLocatorApp::interruptCallback(int val)
+extern "C"
{
- _exit(EXIT_SUCCESS);
+ IceBox::Service* create(Ice::CommunicatorPtr communicator)
+ {
+ return new ServiceLocatorApp;
+ }
}
-----------------------------------------------------------------------
--
asterisk-scf/integration/servicediscovery.git
More information about the asterisk-scf-commits
mailing list