From eabcd5c760c8d3b3e8f6f45a29c19148560f91cd Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Thu, 26 Jun 2008 18:12:12 +0000 Subject: 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 --- cpp/src/tests/BrokerFixture.h | 44 ++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'cpp/src/tests/BrokerFixture.h') 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 /** * A fixture with an in-process broker. */ -struct BrokerFixture { +struct BrokerFixture : private boost::noncopyable { typedef qpid::broker::Broker Broker; typedef boost::shared_ptr 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 -struct SessionFixtureT : BrokerFixture { +template +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 +struct SessionFixtureT : BrokerFixture, ClientT { + + SessionFixtureT(Broker::Options opts=Broker::Options()) : + BrokerFixture(opts), + ClientT(broker->getPort()) {} - ~SessionFixtureT() { - connection.close(); - } }; typedef SessionFixtureT SessionFixture; -- cgit v1.2.1