summaryrefslogtreecommitdiff
path: root/cpp/src/tests
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2010-06-10 21:01:58 +0000
committerAlan Conway <aconway@apache.org>2010-06-10 21:01:58 +0000
commit3215c9de089ca72d327124ba425aa13919da5e35 (patch)
treed5d9687e41a9d911435edde9a33daaee84594881 /cpp/src/tests
parent933658193bf2856c0709bf4265d41e7651ff5fe9 (diff)
downloadqpid-python-3215c9de089ca72d327124ba425aa13919da5e35.tar.gz
Improved qpid_ping - use heartbeat to interrupt connection.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@953454 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests')
-rw-r--r--cpp/src/tests/qpid_ping.cpp81
1 files changed, 18 insertions, 63 deletions
diff --git a/cpp/src/tests/qpid_ping.cpp b/cpp/src/tests/qpid_ping.cpp
index 95c6914b5c..0cb4afa0ee 100644
--- a/cpp/src/tests/qpid_ping.cpp
+++ b/cpp/src/tests/qpid_ping.cpp
@@ -38,9 +38,6 @@ using namespace qpid::framing;
using namespace qpid::client;
using namespace qpid;
-namespace qpid {
-namespace tests {
-
struct PingOptions : public qpid::TestOptions {
int timeout; // Timeout in seconds.
bool quiet; // No output
@@ -51,71 +48,29 @@ struct PingOptions : public qpid::TestOptions {
}
};
-PingOptions opts;
-
-class Ping : public Runnable {
- Connection connection;
- Thread thread;
- Monitor lock;
- enum { WAITING, SUCCESS, ERROR } status;
-
- public:
- Ping() : status(WAITING) {}
-
- void run() {
- try {
- opts.open(connection);
- if (!opts.quiet) cout << "Opened connection." << endl;
- AsyncSession s = connection.newSession();
- string qname(Uuid(true).str());
- s.queueDeclare(arg::queue=qname,arg::autoDelete=true,arg::exclusive=true);
- s.messageTransfer(arg::content=Message("hello", qname));
- if (!opts.quiet) cout << "Sent message." << endl;
- SubscriptionManager subs(s);
- subs.get(qname);
- if (!opts.quiet) cout << "Received message." << endl;
- s.sync();
- s.close();
- connection.close();
- Mutex::ScopedLock l(lock);
- status = SUCCESS;
- lock.notifyAll();
- } catch (const exception& e) {
- cerr << "Unexpected exception: " << e.what() << endl;
- Mutex::ScopedLock l(lock);
- status = ERROR;
- lock.notifyAll();
- }
- }
-
- void start() { thread=Thread(this); }
-
- bool wait() {
- Mutex::ScopedLock l(lock);
- AbsTime deadline(now(), opts.timeout*TIME_SEC);
- while (status == WAITING && lock.wait(deadline))
- ;
- if (status == WAITING && !opts.quiet)
- cerr << "Timed out after " << opts.timeout << " seconds." << endl;
- if (status != WAITING) thread.join();
- return status == SUCCESS;
- }
-};
-
-}} // namespace qpid::tests
-
-using namespace qpid::tests;
-
int main(int argc, char** argv) {
try {
+ PingOptions opts;
opts.parse(argc, argv);
- Ping ping;
- ping.start();
- if (!ping.wait()) return 1;
- if (!opts.quiet) cout << "Success!" << endl;
+ opts.con.heartbeat = (opts.timeout+1)/2;
+ Connection connection;
+ opts.open(connection);
+ if (!opts.quiet) cout << "Opened connection." << endl;
+ AsyncSession s = connection.newSession();
+ string qname(Uuid(true).str());
+ s.queueDeclare(arg::queue=qname,arg::autoDelete=true,arg::exclusive=true);
+ s.messageTransfer(arg::content=Message("hello", qname));
+ if (!opts.quiet) cout << "Sent message." << endl;
+ SubscriptionManager subs(s);
+ subs.get(qname);
+ if (!opts.quiet) cout << "Received message." << endl;
+ s.sync();
+ s.close();
+ connection.close();
+ if (!opts.quiet) cout << "Success." << endl;
return 0;
} catch (const exception& e) {
- cerr << "Unexpected exception: " << e.what() << endl;
+ cerr << "Error: " << e.what() << endl;
return 1;
}
}