summaryrefslogtreecommitdiff
path: root/cpp/src/tests
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-11-28 15:22:15 +0000
committerAlan Conway <aconway@apache.org>2007-11-28 15:22:15 +0000
commit17e755377850471604644942c22e41d7a27172d0 (patch)
tree37fa4beb35c043d63aa26c2fb0a798b9c99ef8f8 /cpp/src/tests
parent8e3ec1e93a84fcc0dac67639293b6f80bec21417 (diff)
downloadqpid-python-17e755377850471604644942c22e41d7a27172d0.tar.gz
src/tests/perftest.cpp:
- Added help text explaining multi-process use. - Fixed bug in multi-process mode, too many threads were started. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@599025 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests')
-rw-r--r--cpp/src/tests/TestOptions.h25
-rw-r--r--cpp/src/tests/perftest.cpp35
2 files changed, 43 insertions, 17 deletions
diff --git a/cpp/src/tests/TestOptions.h b/cpp/src/tests/TestOptions.h
index 95ebb1e219..e226ebbb68 100644
--- a/cpp/src/tests/TestOptions.h
+++ b/cpp/src/tests/TestOptions.h
@@ -34,7 +34,11 @@ namespace qpid {
struct TestOptions : public qpid::Options
{
- TestOptions() : Options("Test Options"), host("localhost"), port(TcpAddress::DEFAULT_PORT), clientid("cpp"), help(false)
+ TestOptions(const std::string& helpText_=std::string()) :
+ Options("Test Options"),
+ host("localhost"), port(TcpAddress::DEFAULT_PORT),
+ clientid("cpp"), help(false),
+ helpText(helpText_)
{
addOptions()
("host,h", optValue(host, "HOST"), "Broker host to connect to")
@@ -49,23 +53,24 @@ struct TestOptions : public qpid::Options
add(log);
}
- /** As well as parsing, print help & exit if required */
+ /** As well as parsing, throw help message if requested. */
void parse(int argc, char** argv) {
try {
qpid::Options::parse(argc, argv);
} catch (const std::exception& e) {
- std::cout << e.what() << std::endl << *this << std::endl;
- exit(1);
+ std::ostringstream msg;
+ msg << *this << std::endl << std::endl << e.what() << std::endl;
+ throw qpid::Options::Exception(msg.str());
}
+ qpid::log::Logger::instance().configure(log, argv[0]);
if (help) {
- std::cout << *this << std::endl;
- exit(0);
+ std::ostringstream msg;
+ msg << *this << std::endl << std::endl << helpText << std::endl;
+ throw qpid::Options::Exception(msg.str());
}
- trace = log.trace;
- qpid::log::Logger::instance().configure(log, argv[0]);
}
- /** Open a connection usin option values */
+ /** Open a connection using option values */
void open(qpid::client::Connection& connection) {
connection.open(host, port, username, password, virtualhost);
}
@@ -77,9 +82,9 @@ struct TestOptions : public qpid::Options
std::string clientid;
std::string username;
std::string password;
- bool trace;
bool help;
log::Options log;
+ std::string helpText;
};
}
diff --git a/cpp/src/tests/perftest.cpp b/cpp/src/tests/perftest.cpp
index b4eec8468d..958c2b5cb1 100644
--- a/cpp/src/tests/perftest.cpp
+++ b/cpp/src/tests/perftest.cpp
@@ -83,8 +83,11 @@ struct Opts : public TestOptions {
size_t qt;
Mode mode;
bool summary;
+
+ static const std::string helpText;
Opts() :
+ TestOptions(helpText),
setup(false), control(false), publish(false), subscribe(false),
pubs(1), count(500000), size(64), confirm(false), durable(false),
subs(1), ack(0),
@@ -105,7 +108,7 @@ struct Opts : public TestOptions {
("count", optValue(count, "N"), "Each publisher sends N messages.")
("size", optValue(size, "BYTES"), "Size of messages in bytes.")
("pub-confirm", optValue(confirm), "Publisher use confirm-mode.")
- ("durable", optValue(durable, "N"), "Publish messages as durable.")
+ ("durable", optValue(durable, "yes|no"), "Publish messages as durable.")
("nsubs", optValue(subs, "N"), "Create N subscribers.")
("sub-ack", optValue(ack, "N"), "N>0: Subscriber acks batches of N.\n"
@@ -152,6 +155,17 @@ struct Opts : public TestOptions {
}
};
+const std::string Opts::helpText=
+"There are two ways to use perftest: single process or multi-process.\n\n"
+"If none of the --setup, --publish, --subscribe or --control options\n"
+"are given perftest will run a single-process test.\n"
+"For a multi-process test first run:\n"
+" perftest --setup <other options>\n"
+"and wait for it to complete. The remaining process should run concurrently::\n"
+"Run --npubs times: perftest --publish <other options>\n"
+"Run --nsubs times: perftest --subscribe <other options>\n"
+"Run once: perftest --control <other options>\n"
+"Note the <other options> must be identical for all processes.\n";
Opts opts;
@@ -432,6 +446,7 @@ struct SubscribeThread : public Client {
};
int main(int argc, char** argv) {
+
string exchange;
switch (opts.mode) {
case FANOUT: exchange="amq.fanout"; break;
@@ -441,7 +456,9 @@ int main(int argc, char** argv) {
try {
opts.parse(argc, argv);
- if (!opts.setup && !opts.control && !opts.publish && !opts.subscribe)
+ bool singleProcess=
+ (!opts.setup && !opts.control && !opts.publish && !opts.subscribe);
+ if (singleProcess)
opts.setup = opts.control = opts.publish = opts.subscribe = true;
if (opts.setup) Setup().run(); // Set up queues
@@ -454,13 +471,15 @@ int main(int argc, char** argv) {
ostringstream key;
key << "perftest" << i; // Queue or topic name.
if (opts.publish) {
- for (size_t j = 0; j < opts.pubs; ++j) {
+ size_t n = singleProcess ? opts.pubs : 1;
+ for (size_t j = 0; j < n; ++j) {
pubs.push_back(new PublishThread(key.str(), exchange));
pubs.back().thread=Thread(pubs.back());
}
}
if (opts.subscribe) {
- for (size_t j = 0; j < opts.subs; ++j) {
+ size_t n = singleProcess ? opts.subs : 1;
+ for (size_t j = 0; j < n; ++j) {
if (opts.mode==SHARED)
subs.push_back(new SubscribeThread(key.str()));
else
@@ -490,8 +509,10 @@ int main(int argc, char** argv) {
}
return 0;
}
- catch (const std::exception& e) {
- cout << "Unexpected exception: " << e.what() << endl;
- return 1;
+ catch (const qpid::Options::Exception& e) {
+ cout << endl << e.what() << endl;
}
+ return 1;
}
+
+