/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/tests/BrokerFixture.h

00001 #ifndef TESTS_BROKERFIXTURE_H
00002 #define TESTS_BROKERFIXTURE_H
00003 
00004 /*
00005  *
00006  * Licensed to the Apache Software Foundation (ASF) under one
00007  * or more contributor license agreements.  See the NOTICE file
00008  * distributed with this work for additional information
00009  * regarding copyright ownership.  The ASF licenses this file
00010  * to you under the Apache License, Version 2.0 (the
00011  * "License"); you may not use this file except in compliance
00012  * with the License.  You may obtain a copy of the License at
00013  * 
00014  *   http://www.apache.org/licenses/LICENSE-2.0
00015  * 
00016  * Unless required by applicable law or agreed to in writing,
00017  * software distributed under the License is distributed on an
00018  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00019  * KIND, either express or implied.  See the License for the
00020  * specific language governing permissions and limitations
00021  * under the License.
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         // Management doesn't play well with multiple in-process brokers.
00047         opts.enableMgmt=false;  
00048         opts.workerThreads=1;
00049         opts.dataDir="";
00050         broker = Broker::create(opts);
00051         // TODO aconway 2007-12-05: At one point BrokerFixture
00052         // tests could hang in Connection ctor if the following
00053         // line is removed. This may not be an issue anymore.
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  

Generated on Thu Apr 10 11:08:18 2008 for Qpid by  doxygen 1.4.7