diff options
author | Jose <jose@zeroc.com> | 2018-06-01 17:41:03 +0200 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2018-06-01 17:41:03 +0200 |
commit | cbe92e540a7f02f0bdf93192424bd119189365b7 (patch) | |
tree | 411c50dc0ae9c669d31a940b1b4903b5deac4f12 /cpp/test/IceStorm/single/Subscriber.cpp | |
parent | Fixed Util.py check for binary installation directory on Windows (diff) | |
download | ice-cbe92e540a7f02f0bdf93192424bd119189365b7.tar.bz2 ice-cbe92e540a7f02f0bdf93192424bd119189365b7.tar.xz ice-cbe92e540a7f02f0bdf93192424bd119189365b7.zip |
Do not use Ice::Application for Ice testsuite
Diffstat (limited to 'cpp/test/IceStorm/single/Subscriber.cpp')
-rw-r--r-- | cpp/test/IceStorm/single/Subscriber.cpp | 86 |
1 files changed, 29 insertions, 57 deletions
diff --git a/cpp/test/IceStorm/single/Subscriber.cpp b/cpp/test/IceStorm/single/Subscriber.cpp index 4bf4881ce6d..cce387c0b97 100644 --- a/cpp/test/IceStorm/single/Subscriber.cpp +++ b/cpp/test/IceStorm/single/Subscriber.cpp @@ -10,7 +10,7 @@ #include <Ice/Ice.h> #include <IceStorm/IceStorm.h> #include <Single.h> -#include <TestCommon.h> +#include <TestHelper.h> using namespace std; using namespace Ice; @@ -21,8 +21,7 @@ class SingleI : public Single, public IceUtil::Monitor<IceUtil::Mutex> { public: - SingleI(const CommunicatorPtr& communicator, const string& name) : - _communicator(communicator), + SingleI(const string& name) : _name(name), _count(0), _last(0) @@ -102,7 +101,6 @@ public: private: - CommunicatorPtr _communicator; const string _name; int _count; int _last; @@ -110,24 +108,33 @@ private: }; typedef IceUtil::Handle<SingleI> SingleIPtr; -int -run(int, char* argv[], const CommunicatorPtr& communicator) +class Subscriber : public Test::TestHelper { +public: + + void run(int, char**); +}; + +void +Subscriber::run(int argc, char** argv) +{ + Ice::CommunicatorHolder communicator = initialize(argc, argv); PropertiesPtr properties = communicator->getProperties(); - const char* managerProxyProperty = "IceStormAdmin.TopicManager.Default"; - string managerProxy = properties->getProperty(managerProxyProperty); + string managerProxy = properties->getProperty("IceStormAdmin.TopicManager.Default"); if(managerProxy.empty()) { - cerr << argv[0] << ": property `" << managerProxyProperty << "' is not set" << endl; - return EXIT_FAILURE; + ostringstream os; + os << argv[0] << ": property `IceStormAdmin.TopicManager.Default' is not set"; + throw invalid_argument(os.str()); } ObjectPrx base = communicator->stringToProxy(managerProxy); IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(base); if(!manager) { - cerr << argv[0] << ": `" << managerProxy << "' is not running" << endl; - return EXIT_FAILURE; + ostringstream os; + os << argv[0] << ": `" << managerProxy << "' is not running"; + throw invalid_argument(os.str()); } // Use 2 default endpoints to test per-request load balancing @@ -148,16 +155,7 @@ run(int, char* argv[], const CommunicatorPtr& communicator) } } - TopicPrx topic; - try - { - topic = manager->retrieve("single"); - } - catch(const IceStorm::NoSuchTopic& e) - { - cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; - return EXIT_FAILURE; - } + TopicPrx topic = manager->retrieve("single"); // // Test subscriber identity that is too long @@ -182,31 +180,31 @@ run(int, char* argv[], const CommunicatorPtr& communicator) vector<Ice::Identity> subscriberIdentities; { - subscribers.push_back(new SingleI(communicator, "default")); + subscribers.push_back(new SingleI("default")); Ice::ObjectPrx object = adapter->addWithUUID(subscribers.back())->ice_oneway(); subscriberIdentities.push_back(object->ice_getIdentity()); topic->subscribeAndGetPublisher(IceStorm::QoS(), object); } { - subscribers.push_back(new SingleI(communicator, "oneway")); + subscribers.push_back(new SingleI("oneway")); Ice::ObjectPrx object = adapter->addWithUUID(subscribers.back())->ice_oneway(); subscriberIdentities.push_back(object->ice_getIdentity()); topic->subscribeAndGetPublisher(IceStorm::QoS(), object); } { - subscribers.push_back(new SingleI(communicator, "twoway")); + subscribers.push_back(new SingleI("twoway")); Ice::ObjectPrx object = adapter->addWithUUID(subscribers.back()); subscriberIdentities.push_back(object->ice_getIdentity()); topic->subscribeAndGetPublisher(IceStorm::QoS(), object); } { - subscribers.push_back(new SingleI(communicator, "batch")); + subscribers.push_back(new SingleI("batch")); Ice::ObjectPrx object = adapter->addWithUUID(subscribers.back())->ice_batchOneway(); subscriberIdentities.push_back(object->ice_getIdentity()); topic->subscribeAndGetPublisher(IceStorm::QoS(), object); } { - subscribers.push_back(new SingleI(communicator, "twoway ordered")); // Ordered + subscribers.push_back(new SingleI("twoway ordered")); // Ordered IceStorm::QoS qos; qos["reliability"] = "ordered"; Ice::ObjectPrx object = adapter->addWithUUID(subscribers.back()); @@ -215,7 +213,7 @@ run(int, char* argv[], const CommunicatorPtr& communicator) } { - subscribers.push_back(new SingleI(communicator, "per-request load balancing")); + subscribers.push_back(new SingleI("per-request load balancing")); IceStorm::QoS qos; qos["locatorCacheTimeout"] = "10"; qos["connectionCached"] = "0"; @@ -229,7 +227,7 @@ run(int, char* argv[], const CommunicatorPtr& communicator) // packet loss, see bug 1784). communicator->getProperties()->setProperty("UdpAdapter3.ThreadPool.Size", "1"); ObjectAdapterPtr adpt = communicator->createObjectAdapterWithEndpoints("UdpAdapter3", "udp"); - subscribers.push_back(new SingleI(communicator, "datagram")); + subscribers.push_back(new SingleI("datagram")); Ice::ObjectPrx object = adpt->addWithUUID(subscribers.back())->ice_datagram(); subscriberIdentities.push_back(object->ice_getIdentity()); adpt->activate(); @@ -241,7 +239,7 @@ run(int, char* argv[], const CommunicatorPtr& communicator) // packet loss, see bug 1784). communicator->getProperties()->setProperty("UdpAdapter4.ThreadPool.Size", "1"); ObjectAdapterPtr adpt = communicator->createObjectAdapterWithEndpoints("UdpAdapter4", "udp"); - subscribers.push_back(new SingleI(communicator, "batch datagram")); + subscribers.push_back(new SingleI("batch datagram")); Ice::ObjectPrx object = adpt->addWithUUID(subscribers.back())->ice_batchDatagram(); subscriberIdentities.push_back(object->ice_getIdentity()); adpt->activate(); @@ -261,32 +259,6 @@ run(int, char* argv[], const CommunicatorPtr& communicator) { (*p)->waitForEvents(); } - - return EXIT_SUCCESS; } -int -main(int argc, char* argv[]) -{ - int status; - CommunicatorPtr communicator; - - try - { - Ice::InitializationData initData = getTestInitData(argc, argv); - communicator = initialize(argc, argv, initData); - status = run(argc, argv, communicator); - } - catch(const Exception& ex) - { - cerr << ex << endl; - status = EXIT_FAILURE; - } - - if(communicator) - { - communicator->destroy(); - } - - return status; -} +DEFINE_TEST(Subscriber) |