00001 #ifndef TESTS_BROKERFIXTURE_H
00002 #define TESTS_BROKERFIXTURE_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "SocketProxy.h"
00026 #include "qpid/sys/Thread.h"
00027 #include "qpid/broker/Broker.h"
00028 #include "qpid/client/Connection.h"
00029 #include "qpid/client/ConnectionImpl.h"
00030 #include "qpid/client/Session.h"
00031 #include "qpid/client/SubscriptionManager.h"
00032
00036 struct BrokerFixture {
00037 typedef qpid::broker::Broker Broker;
00038 typedef boost::shared_ptr<Broker> BrokerPtr;
00039
00040 BrokerPtr broker;
00041 qpid::sys::Thread brokerThread;
00042
00043 BrokerFixture() {
00044 Broker::Options opts;
00045 opts.port=0;
00046
00047 opts.enableMgmt=false;
00048 opts.workerThreads=1;
00049 opts.dataDir="";
00050 broker = Broker::create(opts);
00051
00052
00053
00054 broker->getPort();
00055 brokerThread = qpid::sys::Thread(*broker);
00056 };
00057
00058 ~BrokerFixture() {
00059 broker->shutdown();
00060 brokerThread.join();
00061 }
00062
00064 void open(qpid::client::Connection& c) {
00065 c.open("localhost", broker->getPort());
00066 }
00067 };
00068
00069 struct LocalConnection : public qpid::client::Connection {
00070 LocalConnection(uint16_t port) { open("localhost", port); }
00071 };
00072
00074 struct ProxyConnection : public qpid::client::Connection {
00075 SocketProxy proxy;
00076 ProxyConnection(int brokerPort) : proxy(brokerPort) {
00077 open("localhost", proxy.getPort());
00078 }
00079 ~ProxyConnection() { close(); }
00080 };
00081
00086 template <class ConnectionType>
00087 struct SessionFixtureT : BrokerFixture {
00088 ConnectionType connection;
00089 qpid::client::Session session;
00090 qpid::client::SubscriptionManager subs;
00091 qpid::client::LocalQueue lq;
00092
00093 SessionFixtureT() : connection(broker->getPort()),
00094 session(connection.newSession(qpid::client::ASYNC)),
00095 subs(session)
00096 {}
00097
00098 ~SessionFixtureT() {
00099 connection.close();
00100 }
00101 };
00102
00103 typedef SessionFixtureT<LocalConnection> SessionFixture;
00104 typedef SessionFixtureT<ProxyConnection> ProxySessionFixture;
00105
00106
00107 #endif