diff options
| author | Alan Conway <aconway@apache.org> | 2007-12-07 19:13:09 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2007-12-07 19:13:09 +0000 |
| commit | 93a87010ba58b42e2fe153504b4781978d128a6c (patch) | |
| tree | 27c545a130a3ed4c83472db2c2ae07306c862e5a /qpid/cpp/src/tests/BrokerFixture.h | |
| parent | 506d0479f23c39f75dc03a22f4b8adf52d281022 (diff) | |
| download | qpid-python-93a87010ba58b42e2fe153504b4781978d128a6c.tar.gz | |
Summary:
- Replaced InProcessBroker with BrokerFixture, uses a full loopback
broker for more realistic tests.
- Extracted non-generated parts of Session_0_10 into SessionBase.
- Sundry small fixes.
src/tests/BrokerFixture.h
- in process broker with loopback connections.
- tests can force a disorderly disconnect.
src/qpid/client/Connector.h
- back door to private members for BrokerFixture.
- close() in destructor to avoid leaks.
src/qpid/client/ConnectionImpl.h,cpp:
- close() in destructor, to fix hang when destroyed without being closed.
src/qpid/client/CompletionTracker.h,.cpp:
- Fixed race in close/add.
src/qpid/client/SessionBase.h,cpp:
- Extracted all non-generated code from Session_0_10 into SessionBase
- Added sync()
src/tests/exception_test.cpp: Converted to boost & BrokerFixture
src/tests/ClientChannelTest.cpp, ClientSessionTest.cpp: Use BrokerFixture
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@602182 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src/tests/BrokerFixture.h')
| -rw-r--r-- | qpid/cpp/src/tests/BrokerFixture.h | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/qpid/cpp/src/tests/BrokerFixture.h b/qpid/cpp/src/tests/BrokerFixture.h new file mode 100644 index 0000000000..ceb8ecb4e6 --- /dev/null +++ b/qpid/cpp/src/tests/BrokerFixture.h @@ -0,0 +1,101 @@ +#ifndef TESTS_BROKERFIXTURE_H +#define TESTS_BROKERFIXTURE_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/sys/Thread.h" +#include "qpid/broker/Broker.h" +#include "qpid/client/Connection.h" +#include "qpid/client/ConnectionImpl.h" +#include "qpid/client/Session_0_10.h" +#include "qpid/client/SubscriptionManager.h" + +namespace qpid { namespace client { +/** Back door into private Connector stuff */ +struct TestConnector { + static void disconnect(qpid::client::Connector& c) { + c.socket.close(); + c.handleClosed(); + } +}; +}} + +/** + * A fixture to create an in-process broker and connect to it for tests. + */ +struct BrokerFixture { + typedef qpid::broker::Broker Broker; + typedef boost::shared_ptr<Broker> BrokerPtr; + + struct OpenConnection : public qpid::client::Connection { + OpenConnection(int port) { open("localhost", port); } + }; + + BrokerPtr broker; + qpid::sys::Thread brokerThread; + OpenConnection connection; + qpid::client::Session_0_10 session; + qpid::client::SubscriptionManager subs; + qpid::client::LocalQueue lq; + + BrokerPtr newBroker() { + Broker::Options opts; + opts.port=0; + opts.workerThreads=1; + BrokerPtr b=Broker::create(opts); + // TODO aconway 2007-12-05: Without the following line + // the test can hang in the connection ctor. This is + // a race condition that should be fixed. + b->getPort(); + return b; + }; + + BrokerFixture() : broker(newBroker()), + brokerThread(*broker), + connection(broker->getPort()), + session(connection.newSession()), + subs(session) + {} + + ~BrokerFixture() { + connection.close(); + broker->shutdown(); + brokerThread.join(); + } + + /** Open a connection to the local broker */ + void open(qpid::client::Connection& c) { + c.open("localhost", broker->getPort()); + } + + /** Close a connection's socket */ + static void disconnect(qpid::client::Connection& c) { + struct Expose : public qpid::client::Connection { + void disconnect() { + qpid::client::TestConnector::disconnect(*impl->getConnector()); + } + }; + static_cast<Expose&>(c).disconnect(); + } +}; + +#endif /*!TESTS_BROKERFIXTURE_H*/ |
