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 opts.auth=false;
00051 broker = Broker::create(opts);
00052
00053
00054
00055 broker->getPort();
00056 brokerThread = qpid::sys::Thread(*broker);
00057 };
00058
00059 ~BrokerFixture() {
00060 broker->shutdown();
00061 brokerThread.join();
00062 }
00063
00065 void open(qpid::client::Connection& c) {
00066 c.open("localhost", broker->getPort());
00067 }
00068 };
00069
00070 struct LocalConnection : public qpid::client::Connection {
00071 LocalConnection(uint16_t port) { open("localhost", port); }
00072 };
00073
00075 struct ProxyConnection : public qpid::client::Connection {
00076 SocketProxy proxy;
00077 ProxyConnection(int brokerPort) : proxy(brokerPort) {
00078 open("localhost", proxy.getPort());
00079 }
00080 ~ProxyConnection() { close(); }
00081 };
00082
00087 template <class ConnectionType>
00088 struct SessionFixtureT : BrokerFixture {
00089 ConnectionType connection;
00090 qpid::client::Session session;
00091 qpid::client::SubscriptionManager subs;
00092 qpid::client::LocalQueue lq;
00093
00094 SessionFixtureT() : connection(broker->getPort()),
00095 session(connection.newSession(qpid::client::ASYNC)),
00096 subs(session)
00097 {}
00098
00099 ~SessionFixtureT() {
00100 connection.close();
00101 }
00102 };
00103
00104 typedef SessionFixtureT<LocalConnection> SessionFixture;
00105 typedef SessionFixtureT<ProxyConnection> ProxySessionFixture;
00106
00107
00108 #endif