diff options
| author | Alan Conway <aconway@apache.org> | 2008-06-26 18:12:12 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2008-06-26 18:12:12 +0000 |
| commit | eabcd5c760c8d3b3e8f6f45a29c19148560f91cd (patch) | |
| tree | a3f7e152d7ef07d8507136bb35f8a814b1db65c5 /cpp/src/tests/BrokerFixture.h | |
| parent | a705fb49d4571b3b22ffd597c07e42a1b43e9322 (diff) | |
| download | qpid-python-eabcd5c760c8d3b3e8f6f45a29c19148560f91cd.tar.gz | |
Consolidated cluster tests in cluster_test.cpp
Improvements to BrokerFixture for testing.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@671969 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests/BrokerFixture.h')
| -rw-r--r-- | cpp/src/tests/BrokerFixture.h | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/cpp/src/tests/BrokerFixture.h b/cpp/src/tests/BrokerFixture.h index 31f63d71a0..b6837f6553 100644 --- a/cpp/src/tests/BrokerFixture.h +++ b/cpp/src/tests/BrokerFixture.h @@ -29,19 +29,19 @@ #include "qpid/client/ConnectionImpl.h" #include "qpid/client/Session.h" #include "qpid/client/SubscriptionManager.h" +#include <boost/noncopyable.hpp> /** * A fixture with an in-process broker. */ -struct BrokerFixture { +struct BrokerFixture : private boost::noncopyable { typedef qpid::broker::Broker Broker; typedef boost::shared_ptr<Broker> BrokerPtr; BrokerPtr broker; qpid::sys::Thread brokerThread; - BrokerFixture() { - Broker::Options opts; + BrokerFixture(Broker::Options opts=Broker::Options()) { opts.port=0; // Management doesn't play well with multiple in-process brokers. opts.enableMgmt=false; @@ -65,8 +65,11 @@ struct BrokerFixture { void open(qpid::client::Connection& c) { c.open("localhost", broker->getPort()); } + + uint16_t getPort() { return broker->getPort(); } }; +/** Connection that opens in its constructor */ struct LocalConnection : public qpid::client::Connection { LocalConnection(uint16_t port) { open("localhost", port); } }; @@ -80,25 +83,36 @@ struct ProxyConnection : public qpid::client::Connection { ~ProxyConnection() { close(); } }; -/** - * A BrokerFixture with open Connection, Session and - * SubscriptionManager and LocalQueue for convenience. +/** Convenience class to create and open a connection and session + * and some related useful objects. */ -template <class ConnectionType> -struct SessionFixtureT : BrokerFixture { +template <class ConnectionType=ProxyConnection, class SessionType=qpid::client::Session> +struct ClientT { ConnectionType connection; - qpid::client::Session session; + SessionType session; qpid::client::SubscriptionManager subs; qpid::client::LocalQueue lq; + ClientT(uint16_t port) : connection(port), + session(connection.newSession("Client")), + subs(session) + {} + + ~ClientT() { connection.close(); } +}; - SessionFixtureT() : connection(broker->getPort()), - session(connection.newSession("SessionFixture")), - subs(session) +typedef ClientT<> Client; + +/** + * A BrokerFixture and ready-connected BrokerFixture::Client all in one. + */ +template <class ConnectionType, class SessionType=qpid::client::Session> +struct SessionFixtureT : BrokerFixture, ClientT<ConnectionType,SessionType> { + + SessionFixtureT(Broker::Options opts=Broker::Options()) : + BrokerFixture(opts), + ClientT<ConnectionType,SessionType>(broker->getPort()) {} - ~SessionFixtureT() { - connection.close(); - } }; typedef SessionFixtureT<LocalConnection> SessionFixture; |
