summaryrefslogtreecommitdiff
path: root/cpp/test/IceStorm/stress/Subscriber.cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2018-06-01 17:41:03 +0200
committerJose <jose@zeroc.com>2018-06-01 17:41:03 +0200
commitcbe92e540a7f02f0bdf93192424bd119189365b7 (patch)
tree411c50dc0ae9c669d31a940b1b4903b5deac4f12 /cpp/test/IceStorm/stress/Subscriber.cpp
parentFixed Util.py check for binary installation directory on Windows (diff)
downloadice-cbe92e540a7f02f0bdf93192424bd119189365b7.tar.bz2
ice-cbe92e540a7f02f0bdf93192424bd119189365b7.tar.xz
ice-cbe92e540a7f02f0bdf93192424bd119189365b7.zip
Do not use Ice::Application for Ice testsuite
Diffstat (limited to 'cpp/test/IceStorm/stress/Subscriber.cpp')
-rw-r--r--cpp/test/IceStorm/stress/Subscriber.cpp101
1 files changed, 41 insertions, 60 deletions
diff --git a/cpp/test/IceStorm/stress/Subscriber.cpp b/cpp/test/IceStorm/stress/Subscriber.cpp
index 05a37454320..59cfb0fabcd 100644
--- a/cpp/test/IceStorm/stress/Subscriber.cpp
+++ b/cpp/test/IceStorm/stress/Subscriber.cpp
@@ -16,7 +16,7 @@
#include <Event.h>
#include <IceUtil/Mutex.h>
#include <IceUtil/MutexPtrLock.h>
-#include <TestCommon.h>
+#include <TestHelper.h>
using namespace std;
using namespace Ice;
@@ -304,9 +304,17 @@ Init init;
}
-int
-run(int argc, 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);
IceUtilInternal::Options opts;
opts.addOpt("", "events", IceUtilInternal::Options::NeedArg);
opts.addOpt("", "qos", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat);
@@ -321,8 +329,9 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
}
catch(const IceUtilInternal::BadOptException& e)
{
- cerr << argv[0] << ": " << e.reason << endl;
- return EXIT_FAILURE;
+ ostringstream os;
+ os << argv[0] << ": " << e.reason;
+ throw invalid_argument(os.str());
}
int events = 1000;
@@ -333,8 +342,9 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
}
if(events <= 0)
{
- cerr << argv[0] << ": events must be > 0." << endl;
- return EXIT_FAILURE;
+ ostringstream os;
+ os << argv[0] << ": events must be > 0.";
+ throw invalid_argument(os.str());
}
IceStorm::QoS cmdLineQos;
@@ -345,8 +355,9 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
string::size_type off = q->find(",");
if(off == string::npos)
{
- cerr << argv[0] << ": parse error: no , in QoS" << endl;
- return EXIT_FAILURE;
+ ostringstream os;
+ os << argv[0] << ": parse error: no , in QoS";
+ throw invalid_argument(os.str());
}
cmdLineQos[q->substr(0, off)] = q->substr(off+1);
}
@@ -364,8 +375,9 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
}
if(events <= 0)
{
- cerr << argv[0] << ": events must be > 0." << endl;
- return EXIT_FAILURE;
+ ostringstream os;
+ os << argv[0] << ": events must be > 0.";
+ throw invalid_argument(os.str());
}
PropertiesPtr properties = communicator->getProperties();
@@ -373,16 +385,18 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
string managerProxy = properties->getProperty(managerProxyProperty);
if(managerProxy.empty())
{
- cerr << argv[0] << ": property `" << managerProxyProperty << "' is not set" << endl;
- return EXIT_FAILURE;
+ ostringstream os;
+ os << argv[0] << ": property `" << managerProxyProperty << "' is not set";
+ throw invalid_argument(os.str());
}
IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(
communicator->stringToProxy(managerProxy));
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());
}
vector<Subscription> subs;
@@ -395,7 +409,7 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
os << "SubscriberAdapter" << i;
Subscription item;
item.adapter = communicator->createObjectAdapterWithEndpoints(os.str(), "default");
- item.servant = new ErraticEventI(communicator, events);
+ item.servant = new ErraticEventI(communicator.communicator(), events);
item.qos["reliability"] = "twoway";
subs.push_back(item);
}
@@ -404,7 +418,7 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
{
Subscription item;
item.adapter = communicator->createObjectAdapterWithEndpoints("SubscriberAdapter", "default");
- item.servant = new SlowEventI(communicator, events);
+ item.servant = new SlowEventI(communicator.communicator(), events);
item.qos = cmdLineQos;
subs.push_back(item);
}
@@ -414,11 +428,11 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
item1.adapter = communicator->createObjectAdapterWithEndpoints("MaxQueueAdapter", "default");
if(maxQueueDropEvents)
{
- item1.servant = new MaxQueueEventI(communicator, maxQueueDropEvents, events, false);
+ item1.servant = new MaxQueueEventI(communicator.communicator(), maxQueueDropEvents, events, false);
}
else
{
- item1.servant = new MaxQueueEventI(communicator, maxQueueRemoveSub, events, true);
+ item1.servant = new MaxQueueEventI(communicator.communicator(), maxQueueRemoveSub, events, true);
}
item1.qos = cmdLineQos;
item1.activate = false;
@@ -426,7 +440,7 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
Subscription item2;
item2.adapter = communicator->createObjectAdapterWithEndpoints("ControllerAdapter", "default");
- item2.servant = new ControllerEventI(communicator, events, item1.adapter);
+ item2.servant = new ControllerEventI(communicator.communicator(), events, item1.adapter);
item2.qos["reliability"] = "oneway";
subs.push_back(item2);
}
@@ -438,25 +452,16 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
map<string, string>::const_iterator p = item.qos.find("reliability");
if(p != item.qos.end() && p->second == "ordered")
{
- item.servant = new OrderEventI(communicator, events);
+ item.servant = new OrderEventI(communicator.communicator(), events);
}
else
{
- item.servant = new CountEventI(communicator, events);
+ item.servant = new CountEventI(communicator.communicator(), events);
}
subs.push_back(item);
}
- TopicPrx topic;
- try
- {
- topic = manager->retrieve("fed1");
- }
- catch(const IceStorm::NoSuchTopic& e)
- {
- cerr << argv[0] << ": NoSuchTopic: " << e.name << endl;
- return EXIT_FAILURE;
- }
+ TopicPrx topic = manager->retrieve("fed1");
{
for(vector<Subscription>::iterator p = subs.begin(); p != subs.end(); ++p)
@@ -509,36 +514,12 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
topic->unsubscribe(p->obj);
if(p->servant->count() != events)
{
- cerr << "expected " << events << " events but got " << p->servant->count() << " events." << endl;
- return EXIT_FAILURE;
+ ostringstream os;
+ os << "expected " << events << " events but got " << p->servant->count() << " events.";
+ throw invalid_argument(os.str());
}
}
}
-
- return EXIT_SUCCESS;
}
-int
-main(int argc, char* argv[])
-{
- int status;
- CommunicatorPtr communicator;
- InitializationData initData = getTestInitData(argc, argv);
- try
- {
- 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)